@zoneflow/editor-dom 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/zOrderEditor.d.ts +14 -0
- package/dist/zOrderEditor.js +126 -0
- package/dist/zoneMoveEditor.d.ts +1 -0
- package/dist/zoneMoveEditor.js +13 -5
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./zoneMoveEditor";
|
|
2
2
|
export * from "./pathCreateEditor";
|
|
3
|
+
export * from "./zOrderEditor";
|
|
3
4
|
export { alignPathsByMode, alignZonesByMode, commitZoneGroupReparentAtCurrentPosition, commitZoneReparentAtCurrentPosition, distributePathsByMode, distributeZonesByMode, resolveGroupPathDragOrigin, resolveGroupZoneDragOrigin, resolveZonePlacementAtWorldRect, resolvePathResizeOrigin, resizePathNodeByScreenDelta, } from "./zoneMoveEditor";
|
|
4
5
|
export type { PathResizeOrigin } from "./zoneMoveEditor";
|
|
5
6
|
export { resolvePathOutputAnchorScreenRect, retargetPathFromOutputAnchorDrag, } from "./pathCreateEditor";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./zoneMoveEditor";
|
|
2
2
|
export * from "./pathCreateEditor";
|
|
3
|
+
export * from "./zOrderEditor";
|
|
3
4
|
export { alignPathsByMode, alignZonesByMode, commitZoneGroupReparentAtCurrentPosition, commitZoneReparentAtCurrentPosition, distributePathsByMode, distributeZonesByMode, resolveGroupPathDragOrigin, resolveGroupZoneDragOrigin, resolveZonePlacementAtWorldRect, resolvePathResizeOrigin, resizePathNodeByScreenDelta, } from "./zoneMoveEditor";
|
|
4
5
|
export { resolvePathOutputAnchorScreenRect, retargetPathFromOutputAnchorDrag, } from "./pathCreateEditor";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type PathId, type UniverseLayoutModel, type UniverseModel, type ZoneId } from "@zoneflow/core";
|
|
2
|
+
export type ZOrderMode = "send-to-back" | "send-backward" | "bring-forward" | "bring-to-front";
|
|
3
|
+
export declare function reorderZonesByZOrderMode(params: {
|
|
4
|
+
model: UniverseModel;
|
|
5
|
+
layoutModel: UniverseLayoutModel;
|
|
6
|
+
zoneIds: ZoneId[];
|
|
7
|
+
mode: ZOrderMode;
|
|
8
|
+
}): UniverseLayoutModel;
|
|
9
|
+
export declare function reorderPathsByZOrderMode(params: {
|
|
10
|
+
model: UniverseModel;
|
|
11
|
+
layoutModel: UniverseLayoutModel;
|
|
12
|
+
pathIds: PathId[];
|
|
13
|
+
mode: ZOrderMode;
|
|
14
|
+
}): UniverseLayoutModel;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { updatePathLayout, updateZoneLayout, } from "@zoneflow/core";
|
|
2
|
+
function reorderIds(params) {
|
|
3
|
+
const { orderedIds, selectedIds, mode } = params;
|
|
4
|
+
if (orderedIds.length < 2 || selectedIds.size === 0)
|
|
5
|
+
return orderedIds;
|
|
6
|
+
if (mode === "send-to-back") {
|
|
7
|
+
return [
|
|
8
|
+
...orderedIds.filter((id) => selectedIds.has(id)),
|
|
9
|
+
...orderedIds.filter((id) => !selectedIds.has(id)),
|
|
10
|
+
];
|
|
11
|
+
}
|
|
12
|
+
if (mode === "bring-to-front") {
|
|
13
|
+
return [
|
|
14
|
+
...orderedIds.filter((id) => !selectedIds.has(id)),
|
|
15
|
+
...orderedIds.filter((id) => selectedIds.has(id)),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
const nextIds = [...orderedIds];
|
|
19
|
+
if (mode === "send-backward") {
|
|
20
|
+
for (let index = 1; index < nextIds.length; index += 1) {
|
|
21
|
+
const currentId = nextIds[index];
|
|
22
|
+
const previousId = nextIds[index - 1];
|
|
23
|
+
if (!currentId || !previousId)
|
|
24
|
+
continue;
|
|
25
|
+
if (!selectedIds.has(currentId) || selectedIds.has(previousId))
|
|
26
|
+
continue;
|
|
27
|
+
nextIds[index - 1] = currentId;
|
|
28
|
+
nextIds[index] = previousId;
|
|
29
|
+
}
|
|
30
|
+
return nextIds;
|
|
31
|
+
}
|
|
32
|
+
for (let index = nextIds.length - 2; index >= 0; index -= 1) {
|
|
33
|
+
const currentId = nextIds[index];
|
|
34
|
+
const nextId = nextIds[index + 1];
|
|
35
|
+
if (!currentId || !nextId)
|
|
36
|
+
continue;
|
|
37
|
+
if (!selectedIds.has(currentId) || selectedIds.has(nextId))
|
|
38
|
+
continue;
|
|
39
|
+
nextIds[index] = nextId;
|
|
40
|
+
nextIds[index + 1] = currentId;
|
|
41
|
+
}
|
|
42
|
+
return nextIds;
|
|
43
|
+
}
|
|
44
|
+
function sortByCurrentZOrder(params) {
|
|
45
|
+
const { ids, getZOrder } = params;
|
|
46
|
+
return [...ids]
|
|
47
|
+
.map((id, index) => ({
|
|
48
|
+
id,
|
|
49
|
+
index,
|
|
50
|
+
zOrder: getZOrder(id) ?? index,
|
|
51
|
+
}))
|
|
52
|
+
.sort((a, b) => a.zOrder - b.zOrder || a.index - b.index)
|
|
53
|
+
.map((entry) => entry.id);
|
|
54
|
+
}
|
|
55
|
+
export function reorderZonesByZOrderMode(params) {
|
|
56
|
+
const { model, layoutModel, zoneIds, mode } = params;
|
|
57
|
+
const selectedIds = new Set(zoneIds);
|
|
58
|
+
if (selectedIds.size === 0)
|
|
59
|
+
return layoutModel;
|
|
60
|
+
const selectedIdsByParent = new Map();
|
|
61
|
+
for (const zoneId of selectedIds) {
|
|
62
|
+
const zone = model.zonesById[zoneId];
|
|
63
|
+
if (!zone)
|
|
64
|
+
continue;
|
|
65
|
+
const parentZoneId = zone.parentZoneId;
|
|
66
|
+
const current = selectedIdsByParent.get(parentZoneId) ?? new Set();
|
|
67
|
+
current.add(zoneId);
|
|
68
|
+
selectedIdsByParent.set(parentZoneId, current);
|
|
69
|
+
}
|
|
70
|
+
let nextLayoutModel = layoutModel;
|
|
71
|
+
for (const [parentZoneId, selectedSiblingIds] of selectedIdsByParent) {
|
|
72
|
+
const siblingIds = parentZoneId === null
|
|
73
|
+
? model.rootZoneIds
|
|
74
|
+
: model.zonesById[parentZoneId]?.childZoneIds ?? [];
|
|
75
|
+
const orderedSiblingIds = sortByCurrentZOrder({
|
|
76
|
+
ids: siblingIds.filter((zoneId) => Boolean(model.zonesById[zoneId])),
|
|
77
|
+
getZOrder: (zoneId) => layoutModel.zoneLayoutsById[zoneId]?.zOrder,
|
|
78
|
+
});
|
|
79
|
+
const reorderedSiblingIds = reorderIds({
|
|
80
|
+
orderedIds: orderedSiblingIds,
|
|
81
|
+
selectedIds: selectedSiblingIds,
|
|
82
|
+
mode,
|
|
83
|
+
});
|
|
84
|
+
reorderedSiblingIds.forEach((zoneId, zOrder) => {
|
|
85
|
+
if (!nextLayoutModel.zoneLayoutsById[zoneId])
|
|
86
|
+
return;
|
|
87
|
+
nextLayoutModel = updateZoneLayout(nextLayoutModel, zoneId, {
|
|
88
|
+
zOrder,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return nextLayoutModel;
|
|
93
|
+
}
|
|
94
|
+
function getAllPathIds(model) {
|
|
95
|
+
const pathIds = [];
|
|
96
|
+
const zoneIds = Object.keys(model.zonesById);
|
|
97
|
+
for (const zoneId of zoneIds) {
|
|
98
|
+
const zone = model.zonesById[zoneId];
|
|
99
|
+
if (!zone)
|
|
100
|
+
continue;
|
|
101
|
+
pathIds.push(...zone.pathIds.filter((pathId) => Boolean(zone.pathsById[pathId])));
|
|
102
|
+
}
|
|
103
|
+
return pathIds;
|
|
104
|
+
}
|
|
105
|
+
export function reorderPathsByZOrderMode(params) {
|
|
106
|
+
const { model, layoutModel, pathIds, mode } = params;
|
|
107
|
+
const selectedIds = new Set(pathIds);
|
|
108
|
+
if (selectedIds.size === 0)
|
|
109
|
+
return layoutModel;
|
|
110
|
+
const orderedPathIds = sortByCurrentZOrder({
|
|
111
|
+
ids: getAllPathIds(model),
|
|
112
|
+
getZOrder: (pathId) => layoutModel.pathLayoutsById[pathId]?.zOrder,
|
|
113
|
+
});
|
|
114
|
+
const reorderedPathIds = reorderIds({
|
|
115
|
+
orderedIds: orderedPathIds,
|
|
116
|
+
selectedIds,
|
|
117
|
+
mode,
|
|
118
|
+
});
|
|
119
|
+
let nextLayoutModel = layoutModel;
|
|
120
|
+
reorderedPathIds.forEach((pathId, zOrder) => {
|
|
121
|
+
nextLayoutModel = updatePathLayout(nextLayoutModel, pathId, {
|
|
122
|
+
zOrder,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return nextLayoutModel;
|
|
126
|
+
}
|
package/dist/zoneMoveEditor.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { alignPathsByMode, distributePathsByMode, resolveGroupPathDragOrigin, re
|
|
|
6
6
|
export { commitZoneGroupReparentAtCurrentPosition, commitZoneReparentAtCurrentPosition, reparentZoneAtCurrentPosition, resolveZonePlacementAtWorldRect, resolveZoneReparentCandidate, } from "./zoneReparent";
|
|
7
7
|
export declare function getMoveEditorTargets(params: {
|
|
8
8
|
model: UniverseModel;
|
|
9
|
+
layoutModel?: UniverseLayoutModel;
|
|
9
10
|
frame: RendererFrame;
|
|
10
11
|
camera: CameraState;
|
|
11
12
|
options?: MoveEditorTargetOptions;
|
package/dist/zoneMoveEditor.js
CHANGED
|
@@ -76,7 +76,7 @@ function resolveResizedAnchor(params) {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
export function getMoveEditorTargets(params) {
|
|
79
|
-
const { model, frame, camera, options, } = params;
|
|
79
|
+
const { model, layoutModel, frame, camera, options, } = params;
|
|
80
80
|
const includeRoot = options?.includeRoot ?? true;
|
|
81
81
|
const minVisibleSize = options?.minVisibleSize ?? DEFAULT_MIN_VISIBLE_SIZE;
|
|
82
82
|
const zoneTargets = [];
|
|
@@ -99,9 +99,10 @@ export function getMoveEditorTargets(params) {
|
|
|
99
99
|
label: zone.name,
|
|
100
100
|
rect,
|
|
101
101
|
depth: getZoneDepth(model, zoneVisual.zoneId),
|
|
102
|
+
zOrder: layoutModel?.zoneLayoutsById[zoneVisual.zoneId]?.zOrder,
|
|
102
103
|
});
|
|
103
104
|
}
|
|
104
|
-
for (const pathVisual of typedValues(frame.pipeline.graphLayout.pathsById)) {
|
|
105
|
+
for (const [index, pathVisual] of typedValues(frame.pipeline.graphLayout.pathsById).entries()) {
|
|
105
106
|
const visibility = frame.pipeline.visibility.pathVisibilityById[pathVisual.pathId];
|
|
106
107
|
if (!visibility?.shouldRenderNode || !pathVisual.rect)
|
|
107
108
|
continue;
|
|
@@ -115,13 +116,20 @@ export function getMoveEditorTargets(params) {
|
|
|
115
116
|
pathId: pathVisual.pathId,
|
|
116
117
|
label: pathVisual.path.name,
|
|
117
118
|
rect,
|
|
119
|
+
zOrder: layoutModel?.pathLayoutsById[pathVisual.pathId]?.zOrder ?? index,
|
|
118
120
|
});
|
|
119
121
|
}
|
|
120
122
|
return [
|
|
121
123
|
...zoneTargets
|
|
122
|
-
.sort((a, b) =>
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
.sort((a, b) => {
|
|
125
|
+
const aOrder = a.zOrder ?? 0;
|
|
126
|
+
const bOrder = b.zOrder ?? 0;
|
|
127
|
+
return a.depth - b.depth || aOrder - bOrder;
|
|
128
|
+
})
|
|
129
|
+
.map(({ depth: _depth, zOrder: _zOrder, ...target }) => target),
|
|
130
|
+
...pathTargets
|
|
131
|
+
.sort((a, b) => (a.zOrder ?? 0) - (b.zOrder ?? 0))
|
|
132
|
+
.map(({ zOrder: _zOrder, ...target }) => target),
|
|
125
133
|
];
|
|
126
134
|
}
|
|
127
135
|
export function resolveMoveEditorDragOrigin(params) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zoneflow/editor-dom",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Low-level editor geometry and interaction helpers for Zoneflow.",
|
|
6
6
|
"type": "module",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@zoneflow/core": "0.0.
|
|
23
|
-
"@zoneflow/renderer-dom": "0.0.
|
|
22
|
+
"@zoneflow/core": "0.0.7",
|
|
23
|
+
"@zoneflow/renderer-dom": "0.0.7"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsc -p tsconfig.json",
|