Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes + Housekeeping + Explosion + Position Observer #78

Merged
merged 27 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9faf005
allow spark to rerun on drop
samuelmtimbo Jan 26, 2024
929179f
workflow to run lint and type checker
samuelmtimbo Jan 26, 2024
b05817c
remove log
samuelmtimbo Jan 26, 2024
4d6b07e
animate center to view
samuelmtimbo Jan 26, 2024
2234af6
prettier to format json
samuelmtimbo Jan 26, 2024
a22eb62
prettier format all json
samuelmtimbo Jan 26, 2024
ce62048
z-index 1 on foreground svg/canvas
samuelmtimbo Jan 26, 2024
0d6b3f8
set move plug into ref
samuelmtimbo Jan 27, 2024
99d3c15
remove bad data visible break
samuelmtimbo Jan 27, 2024
28a7aac
remove old unused method
samuelmtimbo Jan 27, 2024
d60c9c3
predict collapse merge edge case
samuelmtimbo Jan 27, 2024
6fd0eda
add core `hovered` unit
samuelmtimbo Jan 27, 2024
8316349
no root dom append
samuelmtimbo Jan 27, 2024
5ced92e
prevent center graph reset animation
samuelmtimbo Jan 28, 2024
73125a7
fix method declaration position
samuelmtimbo Jan 28, 2024
e442efc
remove div default inline style
samuelmtimbo Jan 29, 2024
9dbed2f
prepublish lib before build
samuelmtimbo Jan 29, 2024
4ed26be
paste plug initial position
samuelmtimbo Jan 29, 2024
1f9386b
position observer to account for ancestor border
samuelmtimbo Jan 30, 2024
36b1bc2
editor to allow control lock without gui
samuelmtimbo Jan 30, 2024
b2dfbb2
ad hoc next tick position observe
samuelmtimbo Jan 30, 2024
a05d748
do not infer generic input types
samuelmtimbo Jan 30, 2024
6c39699
deep explode graph
samuelmtimbo Jan 31, 2024
d74d407
prop expression data tree
samuelmtimbo Feb 1, 2024
453f312
fix partial object parsing
samuelmtimbo Feb 1, 2024
70e9168
merge sort (js and ts) example
samuelmtimbo Feb 1, 2024
6ab4d4e
bump typescript-eslint
samuelmtimbo Feb 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ jobs:
run: npm i
- name: npm run setup
run: npm run setup
- name: npm run lint
run: npm run lint
- name: npm run type
run: npm run type
- name: npm run test
run: npm run test
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"build:ext": "ts-node -T src/script/build/ext.ts",
"ext:zip": "cd src/client/extension/src && zip -9 -r -u -q extension.zip . -x '/*.git/*' '/*.vscode/*' '/*.gitignore' '/*.gitmodules' '/*node_modules/*' '/*.md' '/*yarn.lock' 'package-lock.json' 'package.json' 'tsconfig.json' '/*.js.map' '/*README.md' '/*.npmignore' '/*.DS_Store' '/*.prettierrc' '/*.prettierignore' '/*.eslintrc' '/*.ts' '/*.zip' '*/_/*'",
"lint": "eslint src --ext .ts",
"format": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prepublishOnly": "run-s build lib",
"format": "prettier --config .prettierrc 'src/**/*.ts' 'src/**/*.json' --write",
"prepublishOnly": "run-s lib build",
"electron": "electron lib/client/platform/electron/index.js"
},
"dependencies": {
Expand All @@ -65,9 +65,9 @@
"@types/node": "20.9.0",
"@types/svg-path-bounding-box": "1.0.0",
"@types/ws": "8.5.2",
"@typescript-eslint/eslint-plugin": "6.12.0",
"@typescript-eslint/parser": "6.12.0",
"@typescript-eslint/typescript-estree": "6.12.0",
"@typescript-eslint/eslint-plugin": "6.20.0",
"@typescript-eslint/parser": "6.20.0",
"@typescript-eslint/typescript-estree": "6.20.0",
"electron": "28.1.1",
"esbuild": "0.17.5",
"eslint": "8.5.0",
Expand Down
1 change: 1 addition & 0 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export type API = {
}
ReadableStream: ReadableStream
open: (url: string, target: string, features: string) => Window
getComputedStyle: (element: Element) => CSSStyleDeclaration
}
document: {
createElement<K extends keyof HTMLElementTagNameMap>(
Expand Down
3 changes: 2 additions & 1 deletion src/Class/Graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ import {
GraphTakeUnitErrData,
GraphUnplugPinData,
} from './interface'
import { isRefMerge, moveSubgraph } from './moveSubgraph'
import { moveSubgraph } from './moveSubgraph'
import { isRefMerge } from './isRefMerge'
import { renameUnitInMerges } from '../../spec/reducers/spec'
import { weakMerge } from '../../weakMerge'
import { getSubComponentParentId } from '../../spec/util/component'
Expand Down
28 changes: 28 additions & 0 deletions src/Class/Graph/isRefMerge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getMergePinCount } from '../../spec/util/spec'
import { GraphMergeSpec } from '../../types/GraphMergeSpec'
import { IO } from '../../types/IO'
import { getObjSingleKey } from '../../util/object'
import { GraphLike } from './moveSubgraph'

export function isRefMerge(graph: GraphLike, mergeSpec: GraphMergeSpec) {
let isRef = false

if (getMergePinCount(mergeSpec) > 0) {
const sampleMergeUnitId = getObjSingleKey(mergeSpec)
const sampeMergeUnit = mergeSpec[sampleMergeUnitId]
const sampleMergeUnitType = getObjSingleKey(sampeMergeUnit) as IO
const sampleMergeUnitPinId = getObjSingleKey(
sampeMergeUnit[sampleMergeUnitType]
)

const unit = graph.getUnit(sampleMergeUnitId)

const ref = unit.isPinRef(sampleMergeUnitType, sampleMergeUnitPinId)

if (ref) {
isRef = true
}
}

return isRef
}
53 changes: 20 additions & 33 deletions src/Class/Graph/moveSubgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import {
forEachObjKV,
forEachObjVK,
getObjSingleKey,
mapObjKV,
} from '../../util/object'
import { GraphMoveSubGraphData } from './interface'
import { isRefMerge } from './isRefMerge'

export type GraphLike<T extends UCG = UCG> = Pick<
T,
Expand Down Expand Up @@ -72,29 +74,6 @@ export type GraphLike<T extends UCG = UCG> = Pick<
| 'setSubComponentSize'
>

export function isRefMerge(graph: GraphLike, mergeSpec: GraphMergeSpec) {
let isRef = false

if (getMergePinCount(mergeSpec) > 0) {
const sampleMergeUnitId = getObjSingleKey(mergeSpec)
const sampeMergeUnit = mergeSpec[sampleMergeUnitId]
const sampleMergeUnitType = getObjSingleKey(sampeMergeUnit) as IO
const sampleMergeUnitPinId = getObjSingleKey(
sampeMergeUnit[sampleMergeUnitType]
)

const unit = graph.getUnit(sampleMergeUnitId)

const ref = unit.isPinRef(sampleMergeUnitType, sampleMergeUnitPinId)

if (ref) {
isRef = true
}
}

return isRef
}

export function moveUnit(
source: GraphLike,
target: GraphLike,
Expand Down Expand Up @@ -598,6 +577,7 @@ export function moveMerge(
graphId: string,
mergeId: string,
mergeSpec: GraphMergeSpec,
mergeIsRef: boolean,
collapseMap: GraphMoveSubGraphData,
connectOpt: GraphUnitConnect,
ignoredUnit: Set<string> = new Set(),
Expand Down Expand Up @@ -695,7 +675,7 @@ export function moveMerge(
if (reverse) {
if (mergePinCount === 0 || pinIntoCount > 1) {
// AD HOC
const propagate = isRefMerge(target, nextMerge)
const propagate = mergeIsRef

target.addMerge(nextMerge, nextMergeId, false, propagate)
}
Expand All @@ -707,7 +687,7 @@ export function moveMerge(
pinIntoCount > 1
) {
// AD HOC
const propagate = isRefMerge(target, nextMerge)
const propagate = mergeIsRef

target.addMerge(nextMerge, nextMergeId, false, propagate)

Expand Down Expand Up @@ -1175,6 +1155,7 @@ export function movePlug(
plug: {
[nextSubPinId]: nextSubPinSpec_,
},
ref: !!pinSpec.ref,
},
data,
false,
Expand Down Expand Up @@ -1287,8 +1268,12 @@ export function moveSubgraph<T extends UCG<any, any, any>>(

const { merge = [], link = [], unit = [], plug = [] } = nodeIds

const mergeSpecs = clone(source.getMergesSpec())
const pinSpecs = clone(source.getExposedPinSpecs())
const sourceMergeSpecs = clone(source.getMergesSpec())
const sourcePinSpecs = clone(source.getExposedPinSpecs())

const sourceMergeRefMap = mapObjKV(sourceMergeSpecs, (mergeId, mergeSpec) => {
return isRefMerge(source, mergeSpec)
})

const ignoredUnitPin: Dict<{ input: Set<string>; output: Set<string> }> = {}
const ignoredUnit = new Set<string>(unit)
Expand All @@ -1312,7 +1297,7 @@ export function moveSubgraph<T extends UCG<any, any, any>>(
): GraphPlugOuterSpec => {
let plugSpec: GraphPlugOuterSpec

forIOObjKV(pinSpecs, (type, pinId: string, pinSpec: GraphPinSpec) => {
forIOObjKV(sourcePinSpecs, (type, pinId: string, pinSpec: GraphPinSpec) => {
const { plug } = pinSpec

for (const subPinId in plug) {
Expand Down Expand Up @@ -1401,32 +1386,34 @@ export function moveSubgraph<T extends UCG<any, any, any>>(
ignoredUnit,
ignoredUnitPin,
ignoredMerge,
pinSpecs,
sourcePinSpecs,
reverse
)
}

for (const mergeId of merge) {
const mergeSpec = mergeSpecs[mergeId]
const mergeSpec = sourceMergeSpecs[mergeId]
const mergeIsRef = sourceMergeRefMap[mergeId]

moveMerge(
source,
target,
graphId,
mergeId,
mergeSpec,
mergeIsRef,
collapseMap,
connectOpt,
ignoredUnit,
pinSpecs,
sourcePinSpecs,
reverse
)
}

for (const { type, pinId, subPinId } of plug) {
const pinSpec = deepGet(pinSpecs, [type, pinId])
const pinSpec = deepGet(sourcePinSpecs, [type, pinId])
const subPinSpec = deepGetOrDefault(
pinSpecs,
sourcePinSpecs,
[type, pinId, 'plug', subPinId],
undefined
)
Expand Down
3 changes: 2 additions & 1 deletion src/Registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export class Registry implements R {
// console.log('unregisterUnit', { id })

if (!this.specsCount[id]) {
throw new Error(`cannot unregister unit: no spec with id ${id}`)
return
// throw new Error(`cannot unregister unit: no spec with id ${id}`)
}

this.specsCount[id] -= 1
Expand Down
60 changes: 44 additions & 16 deletions src/client/PositionObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ export class PositionObserver implements IPositionObserver {
let ry: number = 0
let rz: number = 0

let px: number = 0
let py: number = 0
let bx: number = 0
let by: number = 0

let gbx: number = 0
let gby: number = 0

let width: number = 0
let height: number = 0
Expand All @@ -82,6 +85,12 @@ export class PositionObserver implements IPositionObserver {
let parent_x: number = 0
let parent_y: number = 0

let parent_bx: number = 0
let parent_by: number = 0

let parent_gbx: number = 0
let parent_gby: number = 0

let parent_scroll_top = 0
let parent_scroll_left = 0

Expand All @@ -93,7 +102,10 @@ export class PositionObserver implements IPositionObserver {
let parent_rz = 0

let _transform: string | undefined
let _border: string | undefined
let _borderWidth: string | undefined

let _border_x: number = 0
let _border_y: number = 0

function _update_local(): void {
__update_local()
Expand All @@ -108,7 +120,9 @@ export class PositionObserver implements IPositionObserver {
offset_x = offsetLeft
offset_y = offsetTop

const { transform, border } = style
const { transform } = style

const { borderWidth } = getComputedStyle(element)

if (
transform !== _transform ||
Expand Down Expand Up @@ -145,9 +159,9 @@ export class PositionObserver implements IPositionObserver {
_transform = transform
}

if (border !== _border) {
if (border) {
const [borderSizeStr] = border.split(' ')
if (borderWidth !== _borderWidth) {
if (borderWidth) {
const [borderSizeStr] = borderWidth.split(' ')

let borderSize = 0

Expand All @@ -157,13 +171,19 @@ export class PositionObserver implements IPositionObserver {
borderSize = applyLayoutValue(borderSizeStr, 0)
}

px = borderSize
py = borderSize
_border_x = borderSize
_border_y = borderSize
}

_border = border
_borderWidth = borderWidth
}

bx = _border_x
by = _border_y

gbx = parent_bx + parent_gbx
gby = parent_by + parent_gby

width = offsetWidth
height = offsetHeight
}
Expand Down Expand Up @@ -209,12 +229,14 @@ export class PositionObserver implements IPositionObserver {
parent_scaled_local_x * parent_rz_sin

const px =
parent_gbx / 2 +
parent_x -
parent_scroll_left +
parent_scaled_rotated_local_x * scale_x -
((width * parent_scale_x) / 2) * (scale_x - 1)

const py =
parent_gby / 2 +
parent_y -
parent_scroll_top +
parent_scaled_rotated_local_y * scale_y -
Expand Down Expand Up @@ -245,7 +267,7 @@ export class PositionObserver implements IPositionObserver {
const update = (): void => {
_update()

this._callback(x, y, sx, sy, rx, ry, rz, px, py)
this._callback(x, y, sx, sy, rx, ry, rz, bx, by, gbx, gby)
}

const mutationConfig = {
Expand Down Expand Up @@ -378,11 +400,17 @@ export class PositionObserver implements IPositionObserver {
rx: number,
ry: number,
rz: number,
px: number,
py: number
bx: number,
by: number,
gbx: number,
gby: number
) {
parent_x = x + px
parent_y = y + py
parent_x = x
parent_y = y
parent_bx = bx
parent_by = by
parent_gbx = gbx
parent_gby = gby
parent_scale_x = sx
parent_scale_y = sy
parent_rx = rx
Expand Down Expand Up @@ -447,7 +475,7 @@ export class PositionObserver implements IPositionObserver {
__update_local()
_update()

return { x, y, sx, sy, rx, ry, rz, px, py }
return { x, y, sx, sy, rx, ry, rz, bx, by, gbx, gby }
}

disconnect() {
Expand Down
Loading
Loading