@weasel-js/editing 1.19.1 → 2.0.0
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/README.md +23 -11
- package/dist/actionGroups.js +27 -0
- package/dist/actionGroups.js.map +1 -0
- package/dist/actions/align/action.js +12 -9
- package/dist/actions/align/action.js.map +1 -1
- package/dist/actions/align/align.js +5 -4
- package/dist/actions/align/align.js.map +1 -1
- package/dist/actions/clipboard/action.js +10 -7
- package/dist/actions/clipboard/action.js.map +1 -1
- package/dist/actions/clone/action.js +217 -0
- package/dist/actions/clone/action.js.map +1 -0
- package/dist/actions/clone/behaviors.js +65 -0
- package/dist/actions/clone/behaviors.js.map +1 -0
- package/dist/actions/delete/delete.js +123 -0
- package/dist/actions/delete/delete.js.map +1 -0
- package/dist/actions/derivedBox.js +16 -0
- package/dist/actions/derivedBox.js.map +1 -0
- package/dist/actions/distribute/action.js +6 -3
- package/dist/actions/distribute/action.js.map +1 -1
- package/dist/actions/distribute/distribute.js +3 -2
- package/dist/actions/distribute/distribute.js.map +1 -1
- package/dist/actions/distribute/plan.js.map +1 -1
- package/dist/actions/edit/createPaintAction.js +42 -13
- package/dist/actions/edit/createPaintAction.js.map +1 -1
- package/dist/actions/edit/{escape.js → deselect.js} +8 -8
- package/dist/actions/edit/deselect.js.map +1 -0
- package/dist/actions/edit/duplicate.js +9 -7
- package/dist/actions/edit/duplicate.js.map +1 -1
- package/dist/actions/edit/group.js +24 -20
- package/dist/actions/edit/group.js.map +1 -1
- package/dist/actions/edit/ingest.js +4 -2
- package/dist/actions/edit/ingest.js.map +1 -1
- package/dist/actions/edit/nudge.js +14 -10
- package/dist/actions/edit/nudge.js.map +1 -1
- package/dist/actions/edit/selectAll.js +1 -1
- package/dist/actions/edit/setFill.js +1 -1
- package/dist/actions/edit/setFill.js.map +1 -1
- package/dist/actions/edit/setFillOpacity.js +5 -5
- package/dist/actions/edit/setFillOpacity.js.map +1 -1
- package/dist/actions/edit/setStroke.js +1 -1
- package/dist/actions/edit/setStroke.js.map +1 -1
- package/dist/actions/edit/setStrokeOpacity.js +6 -6
- package/dist/actions/edit/setStrokeOpacity.js.map +1 -1
- package/dist/actions/edit/setStrokeWidth.js +13 -8
- package/dist/actions/edit/setStrokeWidth.js.map +1 -1
- package/dist/actions/edit/setVertexColor.js +13 -6
- package/dist/actions/edit/setVertexColor.js.map +1 -1
- package/dist/actions/flip/action.js +19 -14
- package/dist/actions/flip/action.js.map +1 -1
- package/dist/actions/flip/helpers.js.map +1 -1
- package/dist/actions/group/enterGroup.js +81 -0
- package/dist/actions/group/enterGroup.js.map +1 -0
- package/dist/actions/insert/action.js +152 -0
- package/dist/actions/insert/action.js.map +1 -0
- package/dist/actions/insert/commit.js +52 -0
- package/dist/actions/insert/commit.js.map +1 -0
- package/dist/actions/insert/extras.js +88 -0
- package/dist/actions/insert/extras.js.map +1 -0
- package/dist/actions/insert/frame.js +96 -0
- package/dist/actions/insert/frame.js.map +1 -0
- package/dist/actions/insert/geometry.js +35 -0
- package/dist/actions/insert/geometry.js.map +1 -0
- package/dist/actions/insert/lands.js +41 -0
- package/dist/actions/insert/lands.js.map +1 -0
- package/dist/actions/insert/params.js +42 -0
- package/dist/actions/insert/params.js.map +1 -0
- package/dist/actions/insert/placeAction.js +137 -0
- package/dist/actions/insert/placeAction.js.map +1 -0
- package/dist/actions/insert/repositionAction.js +47 -0
- package/dist/actions/insert/repositionAction.js.map +1 -0
- package/dist/actions/insert/rotateAction.js +34 -0
- package/dist/actions/insert/rotateAction.js.map +1 -0
- package/dist/actions/insert/session.js +99 -0
- package/dist/actions/insert/session.js.map +1 -0
- package/dist/actions/insert/shape.js +117 -0
- package/dist/actions/insert/shape.js.map +1 -0
- package/dist/actions/insert/style.js +23 -0
- package/dist/actions/insert/style.js.map +1 -0
- package/dist/actions/lassoSelect/action.js +201 -0
- package/dist/actions/lassoSelect/action.js.map +1 -0
- package/dist/actions/lassoSelect/behaviors/selectFromLasso.js +61 -0
- package/dist/actions/lassoSelect/behaviors/selectFromLasso.js.map +1 -0
- package/dist/actions/lockedWrites.js +20 -0
- package/dist/actions/lockedWrites.js.map +1 -0
- package/dist/actions/move/action.js +138 -0
- package/dist/actions/move/action.js.map +1 -0
- package/dist/actions/move/behaviors/clampMove.js +42 -0
- package/dist/actions/move/behaviors/clampMove.js.map +1 -0
- package/dist/actions/move/behaviors/layoutDrop.js +84 -0
- package/dist/actions/move/behaviors/layoutDrop.js.map +1 -0
- package/dist/actions/move/behaviors/pageDrop.js +30 -0
- package/dist/actions/move/behaviors/pageDrop.js.map +1 -0
- package/dist/actions/move/behaviors/reparentOnDrop.js +44 -0
- package/dist/actions/move/behaviors/reparentOnDrop.js.map +1 -0
- package/dist/actions/move/behaviors/snapBackOrDelete.js +52 -0
- package/dist/actions/move/behaviors/snapBackOrDelete.js.map +1 -0
- package/dist/actions/move/behaviors/snapToContainer.js +214 -0
- package/dist/actions/move/behaviors/snapToContainer.js.map +1 -0
- package/dist/actions/move/behaviors/swapOnDrop.js +180 -0
- package/dist/actions/move/behaviors/swapOnDrop.js.map +1 -0
- package/dist/actions/move/capture.js +116 -0
- package/dist/actions/move/capture.js.map +1 -0
- package/dist/actions/move/commit/index.js +47 -0
- package/dist/actions/move/commit/index.js.map +1 -0
- package/dist/actions/move/commit/layoutDrop.js +68 -0
- package/dist/actions/move/commit/layoutDrop.js.map +1 -0
- package/dist/actions/move/commit/layoutRelease.js +146 -0
- package/dist/actions/move/commit/layoutRelease.js.map +1 -0
- package/dist/actions/move/commit/pageDrop.js +162 -0
- package/dist/actions/move/commit/pageDrop.js.map +1 -0
- package/dist/actions/move/commit/rebase.js +24 -0
- package/dist/actions/move/commit/rebase.js.map +1 -0
- package/dist/actions/move/commit/reparent.js +157 -0
- package/dist/actions/move/commit/reparent.js.map +1 -0
- package/dist/actions/move/delta.js +127 -0
- package/dist/actions/move/delta.js.map +1 -0
- package/dist/actions/move/dragSnap.js +55 -0
- package/dist/actions/move/dragSnap.js.map +1 -0
- package/dist/actions/move/frame.js +67 -0
- package/dist/actions/move/frame.js.map +1 -0
- package/dist/actions/move/gestureAdapter.js +36 -0
- package/dist/actions/move/gestureAdapter.js.map +1 -0
- package/dist/actions/move/landedDescendants.js +50 -0
- package/dist/actions/move/landedDescendants.js.map +1 -0
- package/dist/actions/move/layout/container.js +119 -0
- package/dist/actions/move/layout/container.js.map +1 -0
- package/dist/actions/move/layout/dragged.js +75 -0
- package/dist/actions/move/layout/dragged.js.map +1 -0
- package/dist/actions/move/layout/dropPass.js +205 -0
- package/dist/actions/move/layout/dropPass.js.map +1 -0
- package/dist/actions/move/layout/exits.js +62 -0
- package/dist/actions/move/layout/exits.js.map +1 -0
- package/dist/actions/move/layout/glide.js +70 -0
- package/dist/actions/move/layout/glide.js.map +1 -0
- package/dist/actions/move/layout/view.js +60 -0
- package/dist/actions/move/layout/view.js.map +1 -0
- package/dist/actions/move/refusal.js +49 -0
- package/dist/actions/move/refusal.js.map +1 -0
- package/dist/actions/move/session.js +105 -0
- package/dist/actions/move/session.js.map +1 -0
- package/dist/actions/move/sessionOf.js +27 -0
- package/dist/actions/move/sessionOf.js.map +1 -0
- package/dist/actions/move/translate.js +49 -0
- package/dist/actions/move/translate.js.map +1 -0
- package/dist/actions/pathfinder/action.js +8 -6
- package/dist/actions/pathfinder/action.js.map +1 -1
- package/dist/actions/pathfinder/booleanGroupAction.js +16 -10
- package/dist/actions/pathfinder/booleanGroupAction.js.map +1 -1
- package/dist/actions/pathfinder/keymap.js +2 -2
- package/dist/actions/pathfinder/keymap.js.map +1 -1
- package/dist/actions/reorder/reorder.js +13 -11
- package/dist/actions/reorder/reorder.js.map +1 -1
- package/dist/actions/resize/action.js +105 -0
- package/dist/actions/resize/action.js.map +1 -0
- package/dist/actions/resize/aspect.js +42 -0
- package/dist/actions/resize/aspect.js.map +1 -0
- package/dist/actions/resize/behaviors/clampMinSize.js +100 -0
- package/dist/actions/resize/behaviors/clampMinSize.js.map +1 -0
- package/dist/actions/resize/boxFrame.js +19 -0
- package/dist/actions/resize/boxFrame.js.map +1 -0
- package/dist/actions/resize/capture.js +121 -0
- package/dist/actions/resize/capture.js.map +1 -0
- package/dist/actions/resize/commit.js +104 -0
- package/dist/actions/resize/commit.js.map +1 -0
- package/dist/actions/resize/frame.js +171 -0
- package/dist/actions/resize/frame.js.map +1 -0
- package/dist/actions/resize/held.js +44 -0
- package/dist/actions/resize/held.js.map +1 -0
- package/dist/actions/resize/minimum.js +34 -0
- package/dist/actions/resize/minimum.js.map +1 -0
- package/dist/actions/resize/replay.js +58 -0
- package/dist/actions/resize/replay.js.map +1 -0
- package/dist/actions/resize/ruleBounds.js +11 -0
- package/dist/actions/resize/ruleBounds.js.map +1 -0
- package/dist/actions/resize/session.js +118 -0
- package/dist/actions/resize/session.js.map +1 -0
- package/dist/actions/rotate/action.js +99 -0
- package/dist/actions/rotate/action.js.map +1 -0
- package/dist/actions/rotate/commit.js +48 -0
- package/dist/actions/rotate/commit.js.map +1 -0
- package/dist/actions/rotate/frame.js +96 -0
- package/dist/actions/rotate/frame.js.map +1 -0
- package/dist/actions/rotate/replay.js +25 -0
- package/dist/actions/rotate/replay.js.map +1 -0
- package/dist/actions/rotate/session.js +135 -0
- package/dist/actions/rotate/session.js.map +1 -0
- package/dist/actions/select/areaSelect.js +83 -0
- package/dist/actions/select/areaSelect.js.map +1 -0
- package/dist/actions/select/clearSelection.js +33 -0
- package/dist/actions/select/clearSelection.js.map +1 -0
- package/dist/actions/swap/action.js +63 -0
- package/dist/actions/swap/action.js.map +1 -0
- package/dist/actions/swap/swapOps.js +160 -0
- package/dist/actions/swap/swapOps.js.map +1 -0
- package/dist/actions/transformAgain/action.js +16 -14
- package/dist/actions/transformAgain/action.js.map +1 -1
- package/dist/actions/transformAgain/transformSelection.js +19 -5
- package/dist/actions/transformAgain/transformSelection.js.map +1 -1
- package/dist/booleans/booleans.js +130 -0
- package/dist/booleans/booleans.js.map +1 -0
- package/dist/booleans/commit.js +45 -0
- package/dist/booleans/commit.js.map +1 -0
- package/dist/booleans/custom.js +48 -0
- package/dist/booleans/custom.js.map +1 -0
- package/dist/booleans/operands.js +50 -0
- package/dist/booleans/operands.js.map +1 -0
- package/dist/booleans/pieces.js +43 -0
- package/dist/booleans/pieces.js.map +1 -0
- package/dist/booleans/placement.js +37 -0
- package/dist/booleans/placement.js.map +1 -0
- package/dist/booleans/useBooleans.js +34 -0
- package/dist/booleans/useBooleans.js.map +1 -0
- package/dist/booleans/useBooleansAdapter.js +11 -0
- package/dist/booleans/useBooleansAdapter.js.map +1 -0
- package/dist/chrome/affordances/cornerResize.js +123 -0
- package/dist/chrome/affordances/cornerResize.js.map +1 -0
- package/dist/chrome/affordances/rotateCursor.js +17 -0
- package/dist/chrome/affordances/rotateCursor.js.map +1 -0
- package/dist/chrome/affordances/rotationHandle.js +117 -0
- package/dist/chrome/affordances/rotationHandle.js.map +1 -0
- package/dist/chrome/handleCommands.js +110 -0
- package/dist/chrome/handleCommands.js.map +1 -0
- package/dist/chrome/overlay.js +271 -0
- package/dist/chrome/overlay.js.map +1 -0
- package/dist/chrome/rotationBadge.js +132 -0
- package/dist/chrome/rotationBadge.js.map +1 -0
- package/dist/chrome/rotationHandleGeometry.js +49 -0
- package/dist/chrome/rotationHandleGeometry.js.map +1 -0
- package/dist/chrome/selectionChrome.js +25 -0
- package/dist/chrome/selectionChrome.js.map +1 -0
- package/dist/chrome/selectionPose.js +112 -0
- package/dist/chrome/selectionPose.js.map +1 -0
- package/dist/chrome/shapeOutline.js +137 -0
- package/dist/chrome/shapeOutline.js.map +1 -0
- package/dist/clipboard/clipboardOps.js +48 -0
- package/dist/clipboard/clipboardOps.js.map +1 -0
- package/dist/clipboard/materializePaste.js +34 -0
- package/dist/clipboard/materializePaste.js.map +1 -0
- package/dist/clipboard/osClipboard.js +67 -0
- package/dist/clipboard/osClipboard.js.map +1 -0
- package/dist/clipboard/useClipboard.js +64 -0
- package/dist/clipboard/useClipboard.js.map +1 -0
- package/dist/clipboard/wireFormat.js +108 -0
- package/dist/clipboard/wireFormat.js.map +1 -0
- package/dist/deps/areaSelect.js +42 -0
- package/dist/deps/areaSelect.js.map +1 -0
- package/dist/deps/booleans.js +99 -0
- package/dist/deps/booleans.js.map +1 -0
- package/dist/deps/insert.js +260 -0
- package/dist/deps/insert.js.map +1 -0
- package/dist/deps/lassoSelect.js +37 -0
- package/dist/deps/lassoSelect.js.map +1 -0
- package/dist/deps/presetDeps.js +40 -0
- package/dist/deps/presetDeps.js.map +1 -0
- package/dist/deps/resizePolicy.js +41 -0
- package/dist/deps/resizePolicy.js.map +1 -0
- package/dist/engine-BV9RDHOL.d.ts +339 -0
- package/dist/engine.d.ts +6 -0
- package/dist/engine.js +10 -0
- package/dist/engineStandardActions.js +16 -7
- package/dist/engineStandardActions.js.map +1 -1
- package/dist/groups.d.ts +27 -0
- package/dist/groups.js +4 -0
- package/dist/icons.gen.js +8 -0
- package/dist/icons.gen.js.map +1 -0
- package/dist/icons.table.d.ts +6 -0
- package/dist/icons.table.js +8 -0
- package/dist/icons.table.js.map +1 -0
- package/dist/icons.table.json +156 -0
- package/dist/icons2.table.js +163 -0
- package/dist/icons2.table.js.map +1 -0
- package/dist/index.d.ts +1293 -105
- package/dist/index.js +61 -12
- package/dist/ingest/ghost.js +58 -0
- package/dist/ingest/ghost.js.map +1 -0
- package/dist/ingest/imageHandler.js +80 -0
- package/dist/ingest/imageHandler.js.map +1 -0
- package/dist/ingest/kitHandlers.js +15 -0
- package/dist/ingest/kitHandlers.js.map +1 -0
- package/dist/ingest/svgHandler.js +97 -0
- package/dist/ingest/svgHandler.js.map +1 -0
- package/dist/ingest/weaselJsonHandler.js +68 -0
- package/dist/ingest/weaselJsonHandler.js.map +1 -0
- package/dist/namedPresets.js +23 -11
- package/dist/namedPresets.js.map +1 -1
- package/dist/presets/arrange.js +21 -7
- package/dist/presets/arrange.js.map +1 -1
- package/dist/presets/booleans.js +13 -0
- package/dist/presets/booleans.js.map +1 -0
- package/dist/presets/composites.js +8 -5
- package/dist/presets/composites.js.map +1 -1
- package/dist/presets/edit.js +25 -13
- package/dist/presets/edit.js.map +1 -1
- package/dist/presets/ingest.js +7 -3
- package/dist/presets/ingest.js.map +1 -1
- package/dist/presets/insert.js +28 -0
- package/dist/presets/insert.js.map +1 -0
- package/dist/presets/pathfinder.js +5 -2
- package/dist/presets/pathfinder.js.map +1 -1
- package/dist/presets/select.js +16 -3
- package/dist/presets/select.js.map +1 -1
- package/dist/presets/selection.js +13 -0
- package/dist/presets/selection.js.map +1 -0
- package/dist/presets/selectionChrome.js +15 -0
- package/dist/presets/selectionChrome.js.map +1 -0
- package/dist/presets/tools.js +78 -9
- package/dist/presets/tools.js.map +1 -1
- package/dist/presets/transform.js +20 -7
- package/dist/presets/transform.js.map +1 -1
- package/dist/presets.d.ts +104 -0
- package/dist/presets.js +15 -0
- package/dist/selection/useSelection.js +127 -0
- package/dist/selection/useSelection.js.map +1 -0
- package/dist/test-seams.d.ts +50 -0
- package/dist/test-seams.js +4 -0
- package/dist/tools/ellipse/useEllipseTool.js +72 -0
- package/dist/tools/ellipse/useEllipseTool.js.map +1 -0
- package/dist/tools/eyedropper/useEyedropperTool.js +100 -0
- package/dist/tools/eyedropper/useEyedropperTool.js.map +1 -0
- package/dist/tools/image/useImageTool.js +57 -0
- package/dist/tools/image/useImageTool.js.map +1 -0
- package/dist/tools/lasso/useLassoTool.js +96 -0
- package/dist/tools/lasso/useLassoTool.js.map +1 -0
- package/dist/tools/line/useLineTool.js +67 -0
- package/dist/tools/line/useLineTool.js.map +1 -0
- package/dist/tools/polygon/usePolygonTool.js +149 -0
- package/dist/tools/polygon/usePolygonTool.js.map +1 -0
- package/dist/tools/rect/useRectTool.js +74 -0
- package/dist/tools/rect/useRectTool.js.map +1 -0
- package/dist/tools/select/adapterPointQuery.js +56 -0
- package/dist/tools/select/adapterPointQuery.js.map +1 -0
- package/dist/tools/select/collapseDeferred.js +35 -0
- package/dist/tools/select/collapseDeferred.js.map +1 -0
- package/dist/tools/select/extendPressLocked.js +17 -0
- package/dist/tools/select/extendPressLocked.js.map +1 -0
- package/dist/tools/select/groupEntry.js +73 -0
- package/dist/tools/select/groupEntry.js.map +1 -0
- package/dist/tools/select/pressDecision.js +39 -0
- package/dist/tools/select/pressDecision.js.map +1 -0
- package/dist/tools/select/selectDeep.js +39 -0
- package/dist/tools/select/selectDeep.js.map +1 -0
- package/dist/tools/select/selectPick.js +60 -0
- package/dist/tools/select/selectPick.js.map +1 -0
- package/dist/tools/select/selectionContributions.js +191 -0
- package/dist/tools/select/selectionContributions.js.map +1 -0
- package/dist/tools/select/usePickerSelectTool.js +145 -0
- package/dist/tools/select/usePickerSelectTool.js.map +1 -0
- package/dist/tools/select/useSelectTool.js +54 -0
- package/dist/tools/select/useSelectTool.js.map +1 -0
- package/dist/tools/shared/countOption.js +24 -0
- package/dist/tools/shared/countOption.js.map +1 -0
- package/dist/tools/shared/insertToolOptions.js +8 -0
- package/dist/tools/shared/insertToolOptions.js.map +1 -0
- package/dist/tools/shared/pointerFollower.js +23 -0
- package/dist/tools/shared/pointerFollower.js.map +1 -0
- package/dist/tools/shared/styleOptions.js +76 -0
- package/dist/tools/shared/styleOptions.js.map +1 -0
- package/dist/tools/star/useStarTool.js +149 -0
- package/dist/tools/star/useStarTool.js.map +1 -0
- package/dist/tools/toolSets.js +26 -0
- package/dist/tools/toolSets.js.map +1 -0
- package/package.json +39 -11
- package/dist/actions/edit/escape.js.map +0 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { getScratch, scratchKey, setScratch } from "@weasel-js/routing";
|
|
2
|
+
import { definesFrame } from "@weasel-js/core/engine";
|
|
3
|
+
import * as coreOps from "@weasel-js/core/ops";
|
|
4
|
+
import { after } from "@weasel-js/registry";
|
|
5
|
+
import { holderOf, outermost } from "@weasel-js/select";
|
|
6
|
+
|
|
7
|
+
// src/actions/move/behaviors/snapToContainer.ts
|
|
8
|
+
/** How many snap behaviors have been built: each keeps its state under a key of its own, so two on one
|
|
9
|
+
* binding never share a dwell timer. */
|
|
10
|
+
var built = 0;
|
|
11
|
+
function getState(ctx, key) {
|
|
12
|
+
let s = getScratch(ctx.scratch, key);
|
|
13
|
+
if (!s) {
|
|
14
|
+
s = {
|
|
15
|
+
pendingTargetId: null,
|
|
16
|
+
cancelPending: null,
|
|
17
|
+
committedSnap: null
|
|
18
|
+
};
|
|
19
|
+
setScratch(ctx.scratch, key, s);
|
|
20
|
+
}
|
|
21
|
+
return s;
|
|
22
|
+
}
|
|
23
|
+
/** The dragged nodes no other dragged one holds: each is planted, and the rest ride inside it. */
|
|
24
|
+
function rootsOf(ctx) {
|
|
25
|
+
return outermost(ctx.draggedIds, (id) => ctx.adapter.getParent(id));
|
|
26
|
+
}
|
|
27
|
+
/** Whether `snap` would put a dragged node inside itself: its container is one of them or under one. */
|
|
28
|
+
function intoDragged(ctx, snap) {
|
|
29
|
+
return holderOf(new Set(ctx.draggedIds), snap.parentId, (id) => ctx.adapter.getParent(id)) !== null;
|
|
30
|
+
}
|
|
31
|
+
function clearTimer(s) {
|
|
32
|
+
s.cancelPending?.();
|
|
33
|
+
s.cancelPending = null;
|
|
34
|
+
s.pendingTargetId = null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Move behavior that drops the dragged nodes into a container the pointer
|
|
38
|
+
* hovers over for `dwellMs`, reparenting each and giving it the slot
|
|
39
|
+
* `findTarget` answers for its id. A node `findTarget` has no slot for in
|
|
40
|
+
* that container rides along with the first, at its offset from it.
|
|
41
|
+
*
|
|
42
|
+
* The dwell is what keeps a drag that merely passes over a container from
|
|
43
|
+
* being captured by it. On an Alt-drag clone the copies drop in the same way
|
|
44
|
+
* and the originals stay put.
|
|
45
|
+
*/
|
|
46
|
+
function snapToContainer(args) {
|
|
47
|
+
const { dwellMs, findTarget, isInstant, moveLabel = "Move", reparentLabel = "Move and reparent" } = args;
|
|
48
|
+
const key = scratchKey(`snapToContainer.${++built}`);
|
|
49
|
+
/** Each dragged node's slot in the snapped container: the snapped slot for
|
|
50
|
+
* the first, and for each other node the one `findTarget` answers for it. */
|
|
51
|
+
const slotsFor = (ctx, snap) => {
|
|
52
|
+
const [primary, ...rest] = rootsOf(ctx);
|
|
53
|
+
const slots = /* @__PURE__ */ new Map([[primary, snap.slotPose]]);
|
|
54
|
+
for (const id of rest) {
|
|
55
|
+
const own = findTarget(id, ctx.pointer.worldX, ctx.pointer.worldY);
|
|
56
|
+
if (own?.parentId === snap.parentId) slots.set(id, own.slotPose);
|
|
57
|
+
}
|
|
58
|
+
return slots;
|
|
59
|
+
};
|
|
60
|
+
const snapped = (ctx, snap, originInWorld) => {
|
|
61
|
+
const id = rootsOf(ctx)[0];
|
|
62
|
+
const start = ctx.origin.get(id);
|
|
63
|
+
const startWorld = start === void 0 || originInWorld ? start : ctx.frames?.toWorld(id, start) ?? start;
|
|
64
|
+
const toSlot = startWorld !== void 0 ? ctx.offset?.(startWorld, snap.slotPose) : void 0;
|
|
65
|
+
const poses = /* @__PURE__ */ new Map();
|
|
66
|
+
for (const [at, slot] of slotsFor(ctx, snap)) {
|
|
67
|
+
const shown = ctx.frames ? ctx.frames.toLocal(at, slot) : slot;
|
|
68
|
+
if (shown !== null) poses.set(at, shown);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
...toSlot ? { transform: {
|
|
72
|
+
kind: "translate",
|
|
73
|
+
...toSlot
|
|
74
|
+
} } : {},
|
|
75
|
+
poses,
|
|
76
|
+
snap
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const track = (ctx, originInWorld) => {
|
|
80
|
+
const s = getState(ctx, key);
|
|
81
|
+
const found = findTarget(rootsOf(ctx)[0], ctx.pointer.worldX, ctx.pointer.worldY);
|
|
82
|
+
const target = found && !intoDragged(ctx, found) ? found : null;
|
|
83
|
+
let left;
|
|
84
|
+
if (s.committedSnap) {
|
|
85
|
+
if (target && target.parentId === s.committedSnap.parentId) return snapped(ctx, s.committedSnap, originInWorld);
|
|
86
|
+
s.committedSnap = null;
|
|
87
|
+
left = { snap: null };
|
|
88
|
+
}
|
|
89
|
+
if (!target) {
|
|
90
|
+
clearTimer(s);
|
|
91
|
+
return left;
|
|
92
|
+
}
|
|
93
|
+
if (isInstant?.(target)) {
|
|
94
|
+
clearTimer(s);
|
|
95
|
+
s.committedSnap = target;
|
|
96
|
+
return snapped(ctx, target, originInWorld);
|
|
97
|
+
}
|
|
98
|
+
if (s.pendingTargetId === target.parentId) return left;
|
|
99
|
+
clearTimer(s);
|
|
100
|
+
s.pendingTargetId = target.parentId;
|
|
101
|
+
s.cancelPending = after(dwellMs, () => {
|
|
102
|
+
s.committedSnap = target;
|
|
103
|
+
s.cancelPending = null;
|
|
104
|
+
ctx.refresh?.();
|
|
105
|
+
});
|
|
106
|
+
return left;
|
|
107
|
+
};
|
|
108
|
+
const cancel = (ctx) => {
|
|
109
|
+
clearTimer(getState(ctx, key));
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
clone: {
|
|
113
|
+
onMove: (ctx) => track(ctx, true),
|
|
114
|
+
onCancel: cancel,
|
|
115
|
+
onEnd(ctx, end) {
|
|
116
|
+
const snap = released(ctx, key);
|
|
117
|
+
return snap ? end.copyOps({
|
|
118
|
+
parentId: snap.parentId,
|
|
119
|
+
poses: slotsFor(ctx, snap)
|
|
120
|
+
}) : void 0;
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
onMove: (ctx) => track(ctx, false),
|
|
124
|
+
onCancel: cancel,
|
|
125
|
+
onEnd(ctx, end) {
|
|
126
|
+
const snap = released(ctx, key);
|
|
127
|
+
return snap ? plantOps(ctx, end, snap, slotsFor(ctx, snap), moveLabel, reparentLabel) : void 0;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** The container a drag is let go into, if any; its dwell timer stops either way. */
|
|
132
|
+
function released(ctx, key) {
|
|
133
|
+
const s = getState(ctx, key);
|
|
134
|
+
clearTimer(s);
|
|
135
|
+
const snap = s.committedSnap ?? ctx.snap;
|
|
136
|
+
return snap && !intoDragged(ctx, snap) ? snap : null;
|
|
137
|
+
}
|
|
138
|
+
/** A move's commit into `snap`: each node with a slot goes there, the rest
|
|
139
|
+
* land where the drag left them, and every one is reparented under it.
|
|
140
|
+
* `null`, refusing the commit, when `snap`'s frame is singular. */
|
|
141
|
+
function plantOps(ctx, end, snap, slots, moveLabel, reparentLabel) {
|
|
142
|
+
const ops = [];
|
|
143
|
+
const landed = /* @__PURE__ */ new Map();
|
|
144
|
+
const reparent = (id) => {
|
|
145
|
+
const oldParent = ctx.adapter.getParent(id);
|
|
146
|
+
if (oldParent !== snap.parentId) {
|
|
147
|
+
landed.set(id, snap.parentId);
|
|
148
|
+
ops.push(coreOps.reparent({
|
|
149
|
+
id,
|
|
150
|
+
fromParentId: oldParent,
|
|
151
|
+
toParentId: snap.parentId,
|
|
152
|
+
label: reparentLabel
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
for (const [id, slot] of slots) {
|
|
157
|
+
const to = ctx.frames ? ctx.frames.toLocalUnder(snap.parentId, slot) : slot;
|
|
158
|
+
if (to === null) return null;
|
|
159
|
+
ops.push(coreOps.setPose({
|
|
160
|
+
id,
|
|
161
|
+
from: ctx.origin.get(id),
|
|
162
|
+
to,
|
|
163
|
+
label: moveLabel
|
|
164
|
+
}));
|
|
165
|
+
reparent(id);
|
|
166
|
+
}
|
|
167
|
+
const rest = rootsOf(ctx).filter((id) => !slots.has(id));
|
|
168
|
+
const moved = end.translateOps(rest);
|
|
169
|
+
ops.push(...moved);
|
|
170
|
+
for (const id of rest) {
|
|
171
|
+
const was = ctx.adapter.getParent(id);
|
|
172
|
+
reparent(id);
|
|
173
|
+
if (was === snap.parentId) continue;
|
|
174
|
+
const kept = keptInPlace(ctx, snap.parentId, id, moved, reparentLabel);
|
|
175
|
+
if (kept === null) return null;
|
|
176
|
+
ops.push(...kept);
|
|
177
|
+
}
|
|
178
|
+
if (landed.size > 0 && ctx.followerOps) {
|
|
179
|
+
const followers = ctx.followerOps(landed, reparentLabel);
|
|
180
|
+
if (followers === null) return null;
|
|
181
|
+
ops.push(...followers);
|
|
182
|
+
}
|
|
183
|
+
return ops;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The ops that keep `id`, reparented into `parentId`, where `moved` left it:
|
|
187
|
+
* its pose made local to the new frame, and through an envelope, the poses of
|
|
188
|
+
* what shares its frame. `null` when `parentId`'s frame is singular.
|
|
189
|
+
*/
|
|
190
|
+
function keptInPlace(ctx, parentId, id, moved, label) {
|
|
191
|
+
const frames = ctx.frames;
|
|
192
|
+
if (frames === void 0) return [];
|
|
193
|
+
const translated = new Map(moved.filter((op) => op.name === "transform").map((op) => [op.args.id, op.args.to]));
|
|
194
|
+
const ops = [];
|
|
195
|
+
const keep = (at) => {
|
|
196
|
+
const from = translated.get(at) ?? ctx.adapter.getPose(at);
|
|
197
|
+
const to = frames.toLocalUnder(parentId, frames.toWorld(at, from));
|
|
198
|
+
if (to === null) return false;
|
|
199
|
+
ops.push(coreOps.setPose({
|
|
200
|
+
id: at,
|
|
201
|
+
from,
|
|
202
|
+
to,
|
|
203
|
+
label
|
|
204
|
+
}));
|
|
205
|
+
const node = ctx.adapter.getNode(at);
|
|
206
|
+
if (node === void 0 || definesFrame(node)) return true;
|
|
207
|
+
for (const child of ctx.adapter.getNodes()) if (child.parent === at && !keep(child.id)) return false;
|
|
208
|
+
return true;
|
|
209
|
+
};
|
|
210
|
+
return keep(id) ? ops : null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { snapToContainer };
|
|
214
|
+
//# sourceMappingURL=snapToContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapToContainer.js","names":[],"sources":["../../../../src/actions/move/behaviors/snapToContainer.ts"],"sourcesContent":["import { definesFrame } from '@weasel-js/core/engine';\nimport type { Op } from '@weasel-js/core';\nimport type { SnapTarget, BehaviorResult, CloneBehavior, MoveBehavior, MoveEnd, GestureContext } from '@weasel-js/core/engine';\nimport { scratchKey, getScratch, setScratch, type ScratchKey } from '@weasel-js/routing';\nimport { holderOf, outermost } from '@weasel-js/select';\nimport { after } from '@weasel-js/registry';\nimport * as coreOps from '@weasel-js/core/ops';\n\ninterface SnapState<TPose> {\n pendingTargetId: string | null;\n cancelPending: (() => void) | null;\n committedSnap: SnapTarget<TPose> | null;\n}\n\ntype StateKey = ScratchKey<SnapState<unknown>>;\n\n/** How many snap behaviors have been built: each keeps its state under a key of its own, so two on one\n * binding never share a dwell timer. */\nlet built = 0;\n\nfunction getState<TPose>(ctx: GestureContext<TPose>, key: StateKey): SnapState<TPose> {\n let s = getScratch(ctx.scratch, key) as SnapState<TPose> | undefined;\n if (!s) {\n s = { pendingTargetId: null, cancelPending: null, committedSnap: null };\n setScratch(ctx.scratch, key, s as SnapState<unknown>);\n }\n return s;\n}\n\n/** The dragged nodes no other dragged one holds: each is planted, and the rest ride inside it. */\nfunction rootsOf<TPose>(ctx: GestureContext<TPose>): readonly string[] {\n return outermost(ctx.draggedIds, (id) => ctx.adapter.getParent(id));\n}\n\n/** Whether `snap` would put a dragged node inside itself: its container is one of them or under one. */\nfunction intoDragged<TPose>(ctx: GestureContext<TPose>, snap: SnapTarget<TPose>): boolean {\n return holderOf(new Set(ctx.draggedIds), snap.parentId, (id) => ctx.adapter.getParent(id)) !== null;\n}\n\nfunction clearTimer<TPose>(s: SnapState<TPose>) {\n s.cancelPending?.();\n s.cancelPending = null;\n s.pendingTargetId = null;\n}\n\n/**\n * Move behavior that drops the dragged nodes into a container the pointer\n * hovers over for `dwellMs`, reparenting each and giving it the slot\n * `findTarget` answers for its id. A node `findTarget` has no slot for in\n * that container rides along with the first, at its offset from it.\n *\n * The dwell is what keeps a drag that merely passes over a container from\n * being captured by it. On an Alt-drag clone the copies drop in the same way\n * and the originals stay put.\n */\nexport function snapToContainer<TPose>(args: {\n dwellMs: number;\n findTarget: (\n draggedId: string,\n worldX: number,\n worldY: number,\n ) => SnapTarget<TPose> | null;\n isInstant?: (target: SnapTarget<TPose>) => boolean;\n moveLabel?: string;\n reparentLabel?: string;\n}): MoveBehavior<TPose> {\n const { dwellMs, findTarget, isInstant, moveLabel = 'Move', reparentLabel = 'Move and reparent' } = args;\n const key: StateKey = scratchKey<SnapState<unknown>>(`snapToContainer.${++built}`);\n\n /** Each dragged node's slot in the snapped container: the snapped slot for\n * the first, and for each other node the one `findTarget` answers for it. */\n const slotsFor = (ctx: GestureContext<TPose>, snap: SnapTarget<TPose>): Map<string, TPose> => {\n const [primary, ...rest] = rootsOf(ctx);\n const slots = new Map<string, TPose>([[primary, snap.slotPose]]);\n for (const id of rest) {\n const own = findTarget(id, ctx.pointer.worldX, ctx.pointer.worldY);\n if (own?.parentId === snap.parentId) slots.set(id, own.slotPose);\n }\n return slots;\n };\n // A slot is a world pose; a preview shows it in the frame the node is stored in now.\n // A move's origin is as stored and a clone's is in world.\n const snapped = (ctx: GestureContext<TPose>, snap: SnapTarget<TPose>, originInWorld: boolean): BehaviorResult<TPose> => {\n const id = rootsOf(ctx)[0];\n const start = ctx.origin.get(id);\n const startWorld = start === undefined || originInWorld ? start : ctx.frames?.toWorld(id, start) ?? start;\n const toSlot = startWorld !== undefined ? ctx.offset?.(startWorld, snap.slotPose) : undefined;\n const poses = new Map<string, TPose>();\n for (const [at, slot] of slotsFor(ctx, snap)) {\n const shown = ctx.frames ? ctx.frames.toLocal(at, slot) : slot;\n if (shown !== null) poses.set(at, shown);\n }\n return {\n ...(toSlot ? { transform: { kind: 'translate' as const, ...toSlot } } : {}),\n poses,\n snap,\n };\n };\n\n const track = (ctx: GestureContext<TPose>, originInWorld: boolean): BehaviorResult<TPose> | undefined => {\n const s = getState<TPose>(ctx, key);\n const found = findTarget(rootsOf(ctx)[0], ctx.pointer.worldX, ctx.pointer.worldY);\n const target = found && !intoDragged(ctx, found) ? found : null;\n\n // Leaving a container withdraws the target it announced, which the commit reads.\n let left: BehaviorResult<TPose> | undefined;\n if (s.committedSnap) {\n if (target && target.parentId === s.committedSnap.parentId) {\n return snapped(ctx, s.committedSnap, originInWorld);\n }\n s.committedSnap = null;\n left = { snap: null };\n }\n\n if (!target) {\n clearTimer(s);\n return left;\n }\n\n if (isInstant?.(target)) {\n clearTimer(s);\n s.committedSnap = target;\n return snapped(ctx, target, originInWorld);\n }\n\n if (s.pendingTargetId === target.parentId) {\n return left;\n }\n clearTimer(s);\n s.pendingTargetId = target.parentId;\n s.cancelPending = after(dwellMs, () => {\n s.committedSnap = target;\n s.cancelPending = null;\n ctx.refresh?.();\n });\n return left;\n };\n const cancel = (ctx: GestureContext<TPose>): void => { clearTimer(getState<TPose>(ctx, key)); };\n\n const clone: CloneBehavior<TPose> = {\n onMove: (ctx) => track(ctx, true),\n onCancel: cancel,\n onEnd(ctx, end) {\n const snap = released(ctx, key);\n return snap ? end.copyOps({ parentId: snap.parentId, poses: slotsFor(ctx, snap) }) : undefined;\n },\n };\n\n return {\n clone,\n onMove: (ctx) => track(ctx, false),\n onCancel: cancel,\n onEnd(ctx, end) {\n const snap = released(ctx, key);\n return snap ? plantOps(ctx, end, snap, slotsFor(ctx, snap), moveLabel, reparentLabel) : undefined;\n },\n };\n}\n\n/** The container a drag is let go into, if any; its dwell timer stops either way. */\nfunction released<TPose>(ctx: GestureContext<TPose>, key: StateKey): SnapTarget<TPose> | null {\n const s = getState<TPose>(ctx, key);\n clearTimer(s);\n const snap = s.committedSnap ?? ctx.snap;\n return snap && !intoDragged(ctx, snap) ? snap : null;\n}\n\n/** A move's commit into `snap`: each node with a slot goes there, the rest\n * land where the drag left them, and every one is reparented under it.\n * `null`, refusing the commit, when `snap`'s frame is singular. */\nfunction plantOps<TPose>(\n ctx: GestureContext<TPose>,\n end: MoveEnd,\n snap: SnapTarget<TPose>,\n slots: ReadonlyMap<string, TPose>,\n moveLabel: string,\n reparentLabel: string,\n): Op[] | null {\n const ops: Op[] = [];\n const landed = new Map<string, string | null>();\n const reparent = (id: string): void => {\n const oldParent = ctx.adapter.getParent(id);\n if (oldParent !== snap.parentId) {\n landed.set(id, snap.parentId);\n ops.push(coreOps.reparent({\n id,\n fromParentId: oldParent,\n toParentId: snap.parentId,\n label: reparentLabel,\n }));\n }\n };\n for (const [id, slot] of slots) {\n const to = ctx.frames ? ctx.frames.toLocalUnder(snap.parentId, slot) : slot;\n if (to === null) return null;\n ops.push(coreOps.setPose<TPose>({ id, from: ctx.origin.get(id)!, to, label: moveLabel }));\n reparent(id);\n }\n // A node with no slot of its own lands where the preview drew it.\n const rest = rootsOf(ctx).filter((id) => !slots.has(id));\n const moved = end.translateOps(rest);\n ops.push(...moved);\n for (const id of rest) {\n const was = ctx.adapter.getParent(id);\n reparent(id);\n if (was === snap.parentId) continue;\n const kept = keptInPlace(ctx, snap.parentId, id, moved, reparentLabel);\n if (kept === null) return null;\n ops.push(...kept);\n }\n if (landed.size > 0 && ctx.followerOps) {\n const followers = ctx.followerOps(landed, reparentLabel);\n if (followers === null) return null;\n ops.push(...followers);\n }\n return ops;\n}\n\n/**\n * The ops that keep `id`, reparented into `parentId`, where `moved` left it:\n * its pose made local to the new frame, and through an envelope, the poses of\n * what shares its frame. `null` when `parentId`'s frame is singular.\n */\nfunction keptInPlace<TPose>(\n ctx: GestureContext<TPose>,\n parentId: string,\n id: string,\n moved: readonly Op[],\n label: string,\n): Op[] | null {\n const frames = ctx.frames;\n if (frames === undefined) return [];\n const translated = new Map(moved.filter((op) => op.name === 'transform')\n .map((op) => [(op.args as { id: string }).id, (op.args as { to: TPose }).to]));\n const ops: Op[] = [];\n const keep = (at: string): boolean => {\n const from = translated.get(at) ?? ctx.adapter.getPose(at);\n const to = frames.toLocalUnder(parentId, frames.toWorld(at, from));\n if (to === null) return false;\n ops.push(coreOps.setPose<TPose>({ id: at, from, to, label }));\n const node = ctx.adapter.getNode(at) as { dependsOn?: unknown; derivePose?: unknown } | undefined;\n if (node === undefined || definesFrame(node)) return true;\n for (const child of ctx.adapter.getNodes()) {\n if ((child as { parent?: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AM,OAAO;EACxB,IAAI,KAAK,QAAQ,QAAe;GAAE,IAAI;GAAI;GAAM;GAAI;EAAM,CAAC,CAAC;EAC5D,MAAM,OAAO,IAAI,QAAQ,QAAQ,EAAE;EACnC,IAAI,SAAS,UAAa,aAAa,IAAI,GAAG,OAAO;EACrD,KAAK,MAAM,SAAS,IAAI,QAAQ,SAAS,GACvC,IAAK,MAAqC,WAAW,MAAM,CAAC,KAAK,MAAM,EAAE,GAAG,OAAO;EAErF,OAAO;CACT;CACA,OAAO,KAAK,EAAE,IAAI,MAAM;AAC1B"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { holdSwap, moveSessionOf } from "../sessionOf.js";
|
|
2
|
+
import { swapOps } from "../../swap/swapOps.js";
|
|
3
|
+
import { writesLocked } from "../../lockedWrites.js";
|
|
4
|
+
import { documentOf, moveEachOps, nodeDescriptors, scenePoseFrame } from "@weasel-js/core";
|
|
5
|
+
import { getScratch, scratchKey, setScratch } from "@weasel-js/routing";
|
|
6
|
+
import { after } from "@weasel-js/registry";
|
|
7
|
+
|
|
8
|
+
// src/actions/move/behaviors/swapOnDrop.ts
|
|
9
|
+
var SWAP_CURSOR = {
|
|
10
|
+
glyph: "swap",
|
|
11
|
+
fallback: "move"
|
|
12
|
+
};
|
|
13
|
+
/** How many swap behaviors have been built: each keeps its state under a key of its own, so the move's own
|
|
14
|
+
* and a binding's never share a timer. */
|
|
15
|
+
var built = 0;
|
|
16
|
+
function stateIn(ctx, key) {
|
|
17
|
+
let s = getScratch(ctx.scratch, key);
|
|
18
|
+
if (!s) {
|
|
19
|
+
s = {
|
|
20
|
+
over: null,
|
|
21
|
+
armed: null,
|
|
22
|
+
cancel: null
|
|
23
|
+
};
|
|
24
|
+
setScratch(ctx.scratch, key, s);
|
|
25
|
+
}
|
|
26
|
+
return s;
|
|
27
|
+
}
|
|
28
|
+
function disarm(s) {
|
|
29
|
+
s.cancel?.();
|
|
30
|
+
s.cancel = null;
|
|
31
|
+
s.over = null;
|
|
32
|
+
s.armed = null;
|
|
33
|
+
}
|
|
34
|
+
/** The node the dragged one is over and may trade places with, by the `nodeAtPoint` dep. */
|
|
35
|
+
function hitTarget(session, point, draggedId) {
|
|
36
|
+
const dep = session.nodeAtPoint;
|
|
37
|
+
if (!dep) return null;
|
|
38
|
+
const exclude = /* @__PURE__ */ new Set([
|
|
39
|
+
...session.ids,
|
|
40
|
+
...session.cascadeIds,
|
|
41
|
+
draggedId
|
|
42
|
+
]);
|
|
43
|
+
const seen = /* @__PURE__ */ new Set();
|
|
44
|
+
for (let at = dep(point, exclude); at !== null && !seen.has(at); at = session.scene.get(at)?.parent ?? null) {
|
|
45
|
+
if (session.swaps(draggedId, at)) return at;
|
|
46
|
+
seen.add(at);
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/** `target` armed against the dragged `id`: its bounds, and where the preview slides it. */
|
|
51
|
+
function arm(session, id, target) {
|
|
52
|
+
const doc = documentOf(session.scene);
|
|
53
|
+
const frame = scenePoseFrame(doc);
|
|
54
|
+
const descriptorOf = nodeDescriptors(doc, session.projection);
|
|
55
|
+
const home = descriptorOf(id).getBounds(frame.world(id));
|
|
56
|
+
const bounds = descriptorOf(target).getBounds(frame.world(target));
|
|
57
|
+
const ops = moveEachOps(doc, [{
|
|
58
|
+
ids: [target],
|
|
59
|
+
dx: home.x - bounds.x,
|
|
60
|
+
dy: home.y - bounds.y
|
|
61
|
+
}], { poseDescriptor: session.projection });
|
|
62
|
+
return {
|
|
63
|
+
id: target,
|
|
64
|
+
bounds,
|
|
65
|
+
poses: new Map(ops.filter((op) => op.name === "transform").map((op) => [op.args.id, op.args.to]))
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
var inside = (r, p) => p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;
|
|
69
|
+
function outline({ x, y, width, height }) {
|
|
70
|
+
return {
|
|
71
|
+
kind: "polyline",
|
|
72
|
+
points: [
|
|
73
|
+
{
|
|
74
|
+
x,
|
|
75
|
+
y
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
x: x + width,
|
|
79
|
+
y
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
x: x + width,
|
|
83
|
+
y: y + height
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
x,
|
|
87
|
+
y: y + height
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
x,
|
|
91
|
+
y
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
role: "target"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A swap drop, run while `on` says so. Built by the move action for its `swapOnDrop` param, and by
|
|
99
|
+
* {@link swapOnDrop} for a binding's `behaviors`.
|
|
100
|
+
*/
|
|
101
|
+
function swapBehavior(options, on) {
|
|
102
|
+
const dwellMs = options.dwellMs ?? 1e3;
|
|
103
|
+
const key = scratchKey(`swapOnDrop.${++built}`);
|
|
104
|
+
const stateOf = (ctx) => stateIn(ctx, key);
|
|
105
|
+
/** The one node the drag moves, which is the one it can swap, or null: a drag of several never swaps. */
|
|
106
|
+
const draggedOf = (session) => on(session) && session.ids.length === 1 ? session.ids[0] : null;
|
|
107
|
+
const targetAt = (session, point, id) => {
|
|
108
|
+
const found = options.targetAt ? options.targetAt(point, id) : hitTarget(session, point, id);
|
|
109
|
+
return found !== null && found !== id && session.swaps(id, found) ? found : null;
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
onMove(ctx) {
|
|
113
|
+
const s = stateOf(ctx);
|
|
114
|
+
const session = moveSessionOf(ctx);
|
|
115
|
+
const id = session ? draggedOf(session) : null;
|
|
116
|
+
if (!session || id === null) {
|
|
117
|
+
disarm(s);
|
|
118
|
+
holdSwap(ctx, s, false);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const point = {
|
|
122
|
+
x: ctx.pointer.worldX,
|
|
123
|
+
y: ctx.pointer.worldY
|
|
124
|
+
};
|
|
125
|
+
const target = s.armed && inside(s.armed.bounds, point) ? s.armed.id : targetAt(session, point, id);
|
|
126
|
+
if (target !== s.over) {
|
|
127
|
+
disarm(s);
|
|
128
|
+
s.over = target;
|
|
129
|
+
if (target !== null) s.cancel = after(dwellMs, () => {
|
|
130
|
+
s.cancel = null;
|
|
131
|
+
s.armed = arm(session, id, target);
|
|
132
|
+
ctx.refresh?.();
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const armed = s.armed;
|
|
136
|
+
holdSwap(ctx, s, armed !== null);
|
|
137
|
+
if (armed === null) return void 0;
|
|
138
|
+
return {
|
|
139
|
+
poses: armed.poses,
|
|
140
|
+
overlays: [outline(armed.bounds)],
|
|
141
|
+
cursor: SWAP_CURSOR
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
onCancel(ctx) {
|
|
145
|
+
const s = stateOf(ctx);
|
|
146
|
+
disarm(s);
|
|
147
|
+
holdSwap(ctx, s, false);
|
|
148
|
+
},
|
|
149
|
+
onEnd(ctx, end) {
|
|
150
|
+
const s = stateOf(ctx);
|
|
151
|
+
const armed = s.armed;
|
|
152
|
+
disarm(s);
|
|
153
|
+
holdSwap(ctx, s, false);
|
|
154
|
+
const session = moveSessionOf(ctx);
|
|
155
|
+
if (end.answered || armed === null || !session) return void 0;
|
|
156
|
+
const id = draggedOf(session);
|
|
157
|
+
if (id === null || !session.swaps(id, armed.id)) return void 0;
|
|
158
|
+
const ops = swapOps(session.scene, id, armed.id, {
|
|
159
|
+
poseDescriptor: session.projection,
|
|
160
|
+
...session.geometryProjection ? { geometryProjection: session.geometryProjection } : {}
|
|
161
|
+
});
|
|
162
|
+
return ops !== null && writesLocked(session.scene, ops) ? null : ops;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Move behavior that swaps the one dragged node with the node it is held over: resting there for `dwellMs`
|
|
168
|
+
* arms the swap, which slides that node into the dragged one's start place, outlines it, and shows the swap
|
|
169
|
+
* cursor, and a release while armed trades the two (`swapOps`), as one undo step. Moving off disarms it, and
|
|
170
|
+
* coming back starts the wait again. A drag of several nodes never swaps, nor does an Alt-drag clone.
|
|
171
|
+
*
|
|
172
|
+
* The move action's `swapOnDrop: 'dwell'` param runs this with the defaults; a binding that needs another
|
|
173
|
+
* `targetAt` or wait passes its own in `behaviors`.
|
|
174
|
+
*/
|
|
175
|
+
function swapOnDrop(options = {}) {
|
|
176
|
+
return swapBehavior(options, () => true);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { swapBehavior, swapOnDrop };
|
|
180
|
+
//# sourceMappingURL=swapOnDrop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swapOnDrop.js","names":[],"sources":["../../../../src/actions/move/behaviors/swapOnDrop.ts"],"sourcesContent":["import type { BehaviorResult, GestureContext, MoveBehavior } from '@weasel-js/core/engine';\nimport { documentOf, moveEachOps, nodeDescriptors, scenePoseFrame, type NodeId } from '@weasel-js/core';\nimport type { OngoingOverlay } from '@weasel-js/routing';\nimport { scratchKey, getScratch, setScratch, type ScratchKey } from '@weasel-js/routing';\nimport type { CursorSpec } from '@weasel-js/cursor';\nimport { after } from '@weasel-js/registry';\nimport type { Rect } from '@weasel-js/geom';\nimport type { MoveSession } from '../session';\nimport { holdSwap, moveSessionOf } from '../sessionOf';\nimport { swapOps } from '../../swap/swapOps';\nimport { writesLocked } from '../../lockedWrites';\n\n/** Options for {@link swapOnDrop}. */\nexport interface SwapOnDropOptions {\n /** How long the pointer rests over a node before a release there swaps. Default 1000. */\n dwellMs?: number;\n /**\n * The node the dragged node `draggedId` would trade places with, for the pointer at `point` in world, or\n * `null`. Default: the node the `nodeAtPoint` dep hits, outside the dragged node, or the first of its\n * ancestors `swappable` lets trade places with it.\n */\n targetAt?(point: { x: number; y: number }, draggedId: string): string | null;\n}\n\nconst SWAP_CURSOR: CursorSpec = { glyph: 'swap', fallback: 'move' };\n\n/** The node a swap would trade with and how the preview shows it, armed. */\ninterface Armed {\n id: string;\n /** Its world bounds in the document: the pointer holding inside them keeps it armed. */\n bounds: Rect;\n /** It and what moves with it, slid into the dragged node's start place, each in its stored frame. */\n poses: ReadonlyMap<string, unknown>;\n}\n\ninterface SwapState {\n /** The node the pointer is resting over, its dwell timer running or done. */\n over: string | null;\n armed: Armed | null;\n cancel: (() => void) | null;\n}\n\n/** How many swap behaviors have been built: each keeps its state under a key of its own, so the move's own\n * and a binding's never share a timer. */\nlet built = 0;\n\nfunction stateIn(ctx: GestureContext<unknown>, key: ScratchKey<SwapState>): SwapState {\n let s = getScratch(ctx.scratch, key);\n if (!s) {\n s = { over: null, armed: null, cancel: null };\n setScratch(ctx.scratch, key, s);\n }\n return s;\n}\n\nfunction disarm(s: SwapState): void {\n s.cancel?.();\n s.cancel = null;\n s.over = null;\n s.armed = null;\n}\n\n/** The node the dragged one is over and may trade places with, by the `nodeAtPoint` dep. */\nfunction hitTarget(session: MoveSession, point: { x: number; y: number }, draggedId: string): string | null {\n const dep = session.nodeAtPoint;\n if (!dep) return null;\n const exclude = new Set<NodeId>([...session.ids, ...session.cascadeIds, draggedId as NodeId]);\n const seen = new Set<string>();\n for (let at: string | null = dep(point, exclude); at !== null && !seen.has(at); at = session.scene.get(at as NodeId)?.parent ?? null) {\n if (session.swaps(draggedId, at)) return at;\n seen.add(at);\n }\n return null;\n}\n\n/** `target` armed against the dragged `id`: its bounds, and where the preview slides it. */\nfunction arm(session: MoveSession, id: string, target: string): Armed {\n const doc = documentOf(session.scene);\n const frame = scenePoseFrame(doc);\n const descriptorOf = nodeDescriptors(doc, session.projection);\n const home = descriptorOf(id as NodeId).getBounds(frame.world(id as NodeId));\n const bounds = descriptorOf(target as NodeId).getBounds(frame.world(target as NodeId));\n const ops = moveEachOps(doc, [{ ids: [target], dx: home.x - bounds.x, dy: home.y - bounds.y }], { poseDescriptor: session.projection });\n const poses = new Map(ops.filter((op) => op.name === 'transform')\n .map((op) => [(op.args as { id: string }).id, (op.args as { to: unknown }).to]));\n return { id: target, bounds, poses };\n}\n\nconst inside = (r: Rect, p: { x: number; y: number }): boolean =>\n p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;\n\nfunction outline({ x, y, width, height }: Rect): OngoingOverlay {\n const points = [{ x, y }, { x: x + width, y }, { x: x + width, y: y + height }, { x, y: y + height }, { x, y }];\n return { kind: 'polyline', points, role: 'target' };\n}\n\n/**\n * A swap drop, run while `on` says so. Built by the move action for its `swapOnDrop` param, and by\n * {@link swapOnDrop} for a binding's `behaviors`.\n */\nexport function swapBehavior(options: SwapOnDropOptions, on: (session: MoveSession) => boolean): MoveBehavior<unknown> {\n const dwellMs = options.dwellMs ?? 1000;\n const key = scratchKey<SwapState>(`swapOnDrop.${++built}`);\n const stateOf = (ctx: GestureContext<unknown>): SwapState => stateIn(ctx, key);\n /** The one node the drag moves, which is the one it can swap, or null: a drag of several never swaps. */\n const draggedOf = (session: MoveSession): string | null =>\n (on(session) && session.ids.length === 1 ? session.ids[0]! : null);\n\n const targetAt = (session: MoveSession, point: { x: number; y: number }, id: string): string | null => {\n const found = options.targetAt ? options.targetAt(point, id) : hitTarget(session, point, id);\n return found !== null && found !== id && session.swaps(id, found) ? found : null;\n };\n\n return {\n onMove(ctx): BehaviorResult<unknown> | undefined {\n const s = stateOf(ctx);\n const session = moveSessionOf(ctx);\n const id = session ? draggedOf(session) : null;\n if (!session || id === null) {\n disarm(s);\n holdSwap(ctx, s, false);\n return undefined;\n }\n const point = { x: ctx.pointer.worldX, y: ctx.pointer.worldY };\n // Armed, the target is previewed elsewhere, so a hit-test there would miss it: its own place holds it.\n const target = s.armed && inside(s.armed.bounds, point) ? s.armed.id : targetAt(session, point, id);\n if (target !== s.over) {\n disarm(s);\n s.over = target;\n if (target !== null) {\n s.cancel = after(dwellMs, () => {\n s.cancel = null;\n s.armed = arm(session, id, target);\n ctx.refresh?.();\n });\n }\n }\n const armed = s.armed;\n holdSwap(ctx, s, armed !== null);\n if (armed === null) return undefined;\n return { poses: armed.poses, overlays: [outline(armed.bounds)], cursor: SWAP_CURSOR };\n },\n onCancel(ctx) {\n const s = stateOf(ctx);\n disarm(s);\n holdSwap(ctx, s, false);\n },\n onEnd(ctx, end) {\n const s = stateOf(ctx);\n const armed = s.armed;\n disarm(s);\n holdSwap(ctx, s, false);\n const session = moveSessionOf(ctx);\n if (end.answered || armed === null || !session) return undefined;\n const id = draggedOf(session);\n if (id === null || !session.swaps(id, armed.id)) return undefined;\n const ops = swapOps(session.scene, id, armed.id, {\n poseDescriptor: session.projection,\n ...(session.geometryProjection ? { geometryProjection: session.geometryProjection } : {}),\n });\n return ops !== null && writesLocked(session.scene, ops) ? null : ops;\n },\n };\n}\n\n/**\n * Move behavior that swaps the one dragged node with the node it is held over: resting there for `dwellMs`\n * arms the swap, which slides that node into the dragged one's start place, outlines it, and shows the swap\n * cursor, and a release while armed trades the two (`swapOps`), as one undo step. Moving off disarms it, and\n * coming back starts the wait again. A drag of several nodes never swaps, nor does an Alt-drag clone.\n *\n * The move action's `swapOnDrop: 'dwell'` param runs this with the defaults; a binding that needs another\n * `targetAt` or wait passes its own in `behaviors`.\n */\nexport function swapOnDrop(options: SwapOnDropOptions = {}): MoveBehavior<unknown> {\n return swapBehavior(options, () => true);\n}\n"],"mappings":";;;;;;;;AAwBA,IAAM,cAA0B;CAAE,OAAO;CAAQ,UAAU;AAAO;;;AAoBlE,IAAI,QAAQ;AAEZ,SAAS,QAAQ,KAA8B,KAAuC;CACpF,IAAI,IAAI,WAAW,IAAI,SAAS,GAAG;CACnC,IAAI,CAAC,GAAG;EACN,IAAI;GAAE,MAAM;GAAM,OAAO;GAAM,QAAQ;EAAK;EAC5C,WAAW,IAAI,SAAS,KAAK,CAAC;CAChC;CACA,OAAO;AACT;AAEA,SAAS,OAAO,GAAoB;CAClC,EAAE,SAAS;CACX,EAAE,SAAS;CACX,EAAE,OAAO;CACT,EAAE,QAAQ;AACZ;;AAGA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IACR,EAAE,OAAO;IACT,IAAI,WAAW,MACb,EAAE,SAAS,MAAM,eAAe;KAC9B,EAAE,SAAS;KACX,EAAE,QAAQ,IAAI,SAAS,IAAI,MAAM;KACjC,IAAI,UAAU;IAChB,CAAC;GAEL;GACA,MAAM,QAAQ,EAAE;GAChB,SAAS,KAAK,GAAG,UAAU,IAAI;GAC/B,IAAI,UAAU,MAAM,OAAO;GAC3B,OAAO;IAAE,OAAO,MAAM;IAAO,UAAU,CAAC,QAAQ,MAAM,MAAM,CAAC;IAAG,QAAQ;GAAY;EACtF;EACA,SAAS,KAAK;GACZ,MAAM,IAAI,QAAQ,GAAG;GACrB,OAAO,CAAC;GACR,SAAS,KAAK,GAAG,KAAK;EACxB;EACA,MAAM,KAAK,KAAK;GACd,MAAM,IAAI,QAAQ,GAAG;GACrB,MAAM,QAAQ,EAAE;GAChB,OAAO,CAAC;GACR,SAAS,KAAK,GAAG,KAAK;GACtB,MAAM,UAAU,cAAc,GAAG;GACjC,IAAI,IAAI,YAAY,UAAU,QAAQ,CAAC,SAAS,OAAO;GACvD,MAAM,KAAK,UAAU,OAAO;GAC5B,IAAI,OAAO,QAAQ,CAAC,QAAQ,MAAM,IAAI,MAAM,EAAE,GAAG,OAAO;GACxD,MAAM,MAAM,QAAQ,QAAQ,OAAO,IAAI,MAAM,IAAI;IAC/C,gBAAgB,QAAQ;IACxB,GAAI,QAAQ,qBAAqB,EAAE,oBAAoB,QAAQ,mBAAmB,IAAI,CAAC;GACzF,CAAC;GACD,OAAO,QAAQ,QAAQ,aAAa,QAAQ,OAAO,GAAG,IAAI,OAAO;EACnE;CACF;AACF;;;;;;;;;;AAWA,SAAgB,WAAW,UAA6B,CAAC,GAA0B;CACjF,OAAO,aAAa,eAAe,IAAI;AACzC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { catchGliding } from "./layout/glide.js";
|
|
2
|
+
import { boundsOffset, composeChildFrame, composeWorldPose, followerOpsFor, frameAtOrAbove, invertPlane, planeOf, pointerStateOf, poseDescriptorOf, sceneGestureFrames, translateTargets } from "@weasel-js/core";
|
|
3
|
+
import { effectivePose, poseDescriptorForNode, scenePoseFrame as scenePoseFrame$1, sceneViewPoseAdapter, toPlane } from "@weasel-js/core/engine";
|
|
4
|
+
|
|
5
|
+
// src/actions/move/capture.ts
|
|
6
|
+
/** Start pose of each root and descendant, the descendants in walk order, and
|
|
7
|
+
* the offsets of any caught mid-glide. */
|
|
8
|
+
function captureStartPoses(scene, ids, reflow, projection) {
|
|
9
|
+
const startPoses = /* @__PURE__ */ new Map();
|
|
10
|
+
const cascadeIds = [];
|
|
11
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12
|
+
const queue = [];
|
|
13
|
+
const caught = /* @__PURE__ */ new Map();
|
|
14
|
+
const hold = (id) => {
|
|
15
|
+
const held = catchGliding(scene, reflow, projection, id);
|
|
16
|
+
if (held) caught.set(id, held);
|
|
17
|
+
};
|
|
18
|
+
for (const id of ids) {
|
|
19
|
+
const node = scene.get(id);
|
|
20
|
+
if (!node) continue;
|
|
21
|
+
hold(id);
|
|
22
|
+
startPoses.set(id, effectivePose(scene, node));
|
|
23
|
+
seen.add(id);
|
|
24
|
+
queue.push(id);
|
|
25
|
+
}
|
|
26
|
+
while (queue.length > 0) {
|
|
27
|
+
const parent = queue.shift();
|
|
28
|
+
for (const childId of scene.childrenOf(parent)) {
|
|
29
|
+
if (seen.has(childId)) continue;
|
|
30
|
+
seen.add(childId);
|
|
31
|
+
const childNode = scene.get(childId);
|
|
32
|
+
if (!childNode) continue;
|
|
33
|
+
hold(childId);
|
|
34
|
+
startPoses.set(childId, effectivePose(scene, childNode));
|
|
35
|
+
cascadeIds.push(childId);
|
|
36
|
+
queue.push(childId);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
startPoses,
|
|
41
|
+
cascadeIds,
|
|
42
|
+
caught
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Which ids ride a moving frame, and the world poses of the rest that sit under one. */
|
|
46
|
+
function captureFrames(scene, ids, startPoses) {
|
|
47
|
+
const carried = /* @__PURE__ */ new Set();
|
|
48
|
+
const frames = /* @__PURE__ */ new Map();
|
|
49
|
+
const pc = scene.composition;
|
|
50
|
+
const written = new Set(translateTargets(scene, scenePoseFrame$1(scene), ids));
|
|
51
|
+
const poseAdapter = sceneViewPoseAdapter(scene);
|
|
52
|
+
for (const id of startPoses.keys()) {
|
|
53
|
+
if (!written.has(id)) {
|
|
54
|
+
carried.add(id);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const frame = frameAtOrAbove(poseAdapter, scene.get(id)?.parent ?? null);
|
|
58
|
+
if (frame === null) continue;
|
|
59
|
+
frames.set(id, {
|
|
60
|
+
world: composeWorldPose(poseAdapter, id, pc.compose),
|
|
61
|
+
frameWorld: composeChildFrame(poseAdapter, frame, pc.compose)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
carried,
|
|
66
|
+
frames
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** For each layer on another plane: a point of its first root, in its own world and the edited one. */
|
|
70
|
+
function capturePlaneRefs(scene, ids, view, frames, startPoses, projection) {
|
|
71
|
+
const planeRefs = /* @__PURE__ */ new Map();
|
|
72
|
+
for (const id of ids) {
|
|
73
|
+
const node = scene.get(id);
|
|
74
|
+
const layer = node?.layer;
|
|
75
|
+
if (node === void 0 || layer === void 0 || planeRefs.has(layer)) continue;
|
|
76
|
+
const m = planeOf(view, layer);
|
|
77
|
+
const back = invertPlane(m);
|
|
78
|
+
if (m === null || back === null) continue;
|
|
79
|
+
const world = frames.get(id)?.world ?? startPoses.get(id);
|
|
80
|
+
if (world === void 0) continue;
|
|
81
|
+
const b = poseDescriptorForNode(projection, node).getBounds(world);
|
|
82
|
+
const own = {
|
|
83
|
+
x: b.x,
|
|
84
|
+
y: b.y
|
|
85
|
+
};
|
|
86
|
+
planeRefs.set(layer, {
|
|
87
|
+
own,
|
|
88
|
+
edited: toPlane(back, own)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return planeRefs;
|
|
92
|
+
}
|
|
93
|
+
function buildGestureContext(ctx, scene, ids, startPoses, adapter, readers) {
|
|
94
|
+
const origin = /* @__PURE__ */ new Map();
|
|
95
|
+
for (const [id, pose] of startPoses) origin.set(id, pose);
|
|
96
|
+
const projection = poseDescriptorOf(ctx.deps.poseDescriptor);
|
|
97
|
+
return {
|
|
98
|
+
draggedIds: ids,
|
|
99
|
+
origin,
|
|
100
|
+
current: new Map(origin),
|
|
101
|
+
snap: null,
|
|
102
|
+
modifiers: { ...ctx.modifiers },
|
|
103
|
+
pointer: pointerStateOf(ctx.world, ctx),
|
|
104
|
+
view: readers.view(),
|
|
105
|
+
plane: readers.plane(),
|
|
106
|
+
kitSettings: readers.kitSettings,
|
|
107
|
+
frames: sceneGestureFrames(scene, ctx.deps),
|
|
108
|
+
offset: boundsOffset(projection),
|
|
109
|
+
followerOps: (landed, label) => followerOpsFor(scene, landed, label),
|
|
110
|
+
adapter,
|
|
111
|
+
scratch: {}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { buildGestureContext, captureFrames, capturePlaneRefs, captureStartPoses };
|
|
116
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","names":["scenePoseFrame"],"sources":["../../../src/actions/move/capture.ts"],"sourcesContent":["import type { InvocationCtx } from '@weasel-js/routing';\nimport { pointerStateOf, composeChildFrame, composeWorldPose, frameAtOrAbove, invertPlane, planeOf, sceneGestureFrames, boundsOffset, poseDescriptorOf, translateTargets, followerOpsFor } from '@weasel-js/core';\nimport type { PoseDescriptor, ReflowTransition, GestureContext } from '@weasel-js/core/engine';\nimport { effectivePose, toPlane, sceneViewPoseAdapter, scenePoseFrame, poseDescriptorForNode } from '@weasel-js/core/engine';\nimport type { NodeId, Scene, GestureReaders } from '@weasel-js/core';\nimport type { MoveGestureAdapter } from './gestureAdapter';\nimport { catchGliding } from './layout/glide';\n\n/** Start pose of each root and descendant, the descendants in walk order, and\n * the offsets of any caught mid-glide. */\nexport function captureStartPoses(\n scene: Scene<unknown, string, unknown>,\n ids: readonly NodeId[],\n reflow: ReflowTransition | null,\n projection: PoseDescriptor<unknown>,\n): { startPoses: Map<NodeId, unknown>; cascadeIds: NodeId[]; caught: Map<NodeId, { dx: number; dy: number }> } {\n // Capture origin poses once at drag start. Walk descendants so\n // container drags can preview every displaced child — required by\n // `usePreviewGhostLayer.buildSubtree` which only recurses into ids\n // present in `previewIds()`.\n const startPoses = new Map<NodeId, unknown>();\n const cascadeIds: NodeId[] = [];\n const seen = new Set<NodeId>();\n const queue: NodeId[] = [];\n // A node still gliding from an earlier reflow is held where it is\n // shown, and the drag starts from there.\n const caught = new Map<NodeId, { dx: number; dy: number }>();\n const hold = (id: NodeId): void => {\n const held = catchGliding(scene, reflow, projection, id);\n if (held) caught.set(id, held);\n };\n for (const id of ids) {\n const node = scene.get(id);\n if (!node) continue;\n hold(id);\n startPoses.set(id, effectivePose(scene, node));\n seen.add(id);\n queue.push(id);\n }\n while (queue.length > 0) {\n const parent = queue.shift()!;\n for (const childId of scene.childrenOf(parent)) {\n if (seen.has(childId)) continue;\n seen.add(childId);\n const childNode = scene.get(childId);\n if (!childNode) continue;\n hold(childId);\n startPoses.set(childId, effectivePose(scene, childNode));\n cascadeIds.push(childId);\n queue.push(childId);\n }\n }\n return { startPoses, cascadeIds, caught };\n}\n\n/** Which ids ride a moving frame, and the world poses of the rest that sit under one. */\nexport function captureFrames(\n scene: Scene<unknown, string, unknown>,\n ids: readonly NodeId[],\n startPoses: ReadonlyMap<NodeId, unknown>,\n): { carried: Set<NodeId>; frames: Map<NodeId, { world: unknown; frameWorld: unknown }> } {\n const carried = new Set<NodeId>();\n const frames = new Map<NodeId, { world: unknown; frameWorld: unknown }>();\n const pc = scene.composition;\n const written = new Set(translateTargets(scene, scenePoseFrame(scene), ids));\n const poseAdapter = sceneViewPoseAdapter(scene);\n for (const id of startPoses.keys()) {\n if (!written.has(id)) {\n carried.add(id);\n continue;\n }\n const frame = frameAtOrAbove(poseAdapter, scene.get(id)?.parent ?? null);\n if (frame === null) continue;\n frames.set(id, {\n world: composeWorldPose(poseAdapter, id as string, pc.compose),\n frameWorld: composeChildFrame(poseAdapter, frame, pc.compose),\n });\n }\n return { carried, frames };\n}\n\n/** For each layer on another plane: a point of its first root, in its own world and the edited one. */\nexport function capturePlaneRefs(\n scene: Scene<unknown, string, unknown>,\n ids: readonly NodeId[],\n view: unknown,\n frames: ReadonlyMap<NodeId, { world: unknown }>,\n startPoses: ReadonlyMap<NodeId, unknown>,\n projection: PoseDescriptor<unknown>,\n): Map<string, { own: { x: number; y: number }; edited: { x: number; y: number } }> {\n const planeRefs = new Map<string, { own: { x: number; y: number }; edited: { x: number; y: number } }>();\n for (const id of ids) {\n const node = scene.get(id);\n const layer = node?.layer;\n if (node === undefined || layer === undefined || planeRefs.has(layer)) continue;\n const m = planeOf(view, layer);\n // An identity map has no inverse to answer: its plane is the edited one, which needs no reference.\n const back = invertPlane(m);\n if (m === null || back === null) continue;\n const world = frames.get(id)?.world ?? startPoses.get(id);\n if (world === undefined) continue;\n const b = poseDescriptorForNode(projection, node).getBounds(world);\n const own = { x: b.x, y: b.y };\n planeRefs.set(layer, { own, edited: toPlane(back, own) });\n }\n return planeRefs;\n}\n\nexport function buildGestureContext(\n ctx: InvocationCtx,\n scene: Scene<unknown, string, unknown>,\n ids: readonly NodeId[],\n startPoses: ReadonlyMap<NodeId, unknown>,\n adapter: MoveGestureAdapter<unknown>,\n readers: GestureReaders,\n): GestureContext<unknown> {\n const origin = new Map<string, unknown>();\n for (const [id, pose] of startPoses) origin.set(id as string, pose);\n const projection = poseDescriptorOf(ctx.deps.poseDescriptor);\n const gestureCtx: GestureContext<unknown> = {\n draggedIds: ids as unknown as string[],\n origin,\n current: new Map(origin),\n snap: null,\n modifiers: { ...ctx.modifiers },\n pointer: pointerStateOf(ctx.world, ctx),\n view: readers.view(),\n plane: readers.plane(),\n kitSettings: readers.kitSettings,\n frames: sceneGestureFrames(scene, ctx.deps),\n offset: boundsOffset(projection),\n followerOps: (landed, label) => followerOpsFor(scene, landed, label),\n adapter: adapter as unknown as GestureContext<unknown>['adapter'],\n scratch: {},\n };\n return gestureCtx;\n}\n"],"mappings":";;;;;;;AAUA,SAAgB,kBACd,OACA,KACA,QACA,YAC6G;CAK7G,MAAM,6BAAa,IAAI,IAAqB;CAC5C,MAAM,aAAuB,CAAC;CAC9B,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,QAAkB,CAAC;CAGzB,MAAM,yBAAS,IAAI,IAAwC;CAC3D,MAAM,QAAQ,OAAqB;EACjC,MAAM,OAAO,aAAa,OAAO,QAAQ,YAAY,EAAE;EACvD,IAAI,MAAM,OAAO,IAAI,IAAI,IAAI;CAC/B;CACA,KAAK,MAAM,MAAM,KAAK;EACpB,MAAM,OAAO,MAAM,IAAI,EAAE;EACzB,IAAI,CAAC,MAAM;EACX,KAAK,EAAE;EACP,WAAW,IAAI,IAAI,cAAc,OAAO,IAAI,CAAC;EAC7C,KAAK,IAAI,EAAE;EACX,MAAM,KAAK,EAAE;CACf;CACA,OAAO,MAAM,SAAS,GAAG;EACvB,MAAM,SAAS,MAAM,MAAM;EAC3B,KAAK,MAAM,WAAW,MAAM,WAAW,MAAM,GAAG;GAC9C,IAAI,KAAK,IAAI,OAAO,GAAG;GACvB,KAAK,IAAI,OAAO;GAChB,MAAM,YAAY,MAAM,IAAI,OAAO;GACnC,IAAI,CAAC,WAAW;GAChB,KAAK,OAAO;GACZ,WAAW,IAAI,SAAS,cAAc,OAAO,SAAS,CAAC;GACvD,WAAW,KAAK,OAAO;GACvB,MAAM,KAAK,OAAO;EACpB;CACF;CACA,OAAO;EAAE;EAAY;EAAY;CAAO;AAC1C;;AAGA,SAAgB,cACd,OACA,KACA,YACwF;CACxF,MAAM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;AAEA,SAAgB,oBACd,KACA,OACA,KACA,YACA,SACA,SACyB;CACzB,MAAM,yBAAS,IAAI,IAAqB;CACxC,KAAK,MAAM,CAAC,IAAI,SAAS,YAAY,OAAO,IAAI,IAAc,IAAI;CAClE,MAAM,aAAa,iBAAiB,IAAI,KAAK,cAAc;CAiB3D,OAAO;EAfL,YAAY;EACZ;EACA,SAAS,IAAI,IAAI,MAAM;EACvB,MAAM;EACN,WAAW,EAAE,GAAG,IAAI,UAAU;EAC9B,SAAS,eAAe,IAAI,OAAO,GAAG;EACtC,MAAM,QAAQ,KAAK;EACnB,OAAO,QAAQ,MAAM;EACrB,aAAa,QAAQ;EACrB,QAAQ,mBAAmB,OAAO,IAAI,IAAI;EAC1C,QAAQ,aAAa,UAAU;EAC/B,cAAc,QAAQ,UAAU,eAAe,OAAO,QAAQ,KAAK;EAC1D;EACT,SAAS,CAAC;CAEL;AACT"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { draggedStoredPose } from "../delta.js";
|
|
2
|
+
import { landedDescendantOps } from "../landedDescendants.js";
|
|
3
|
+
import { rootTranslateOps, translateOps } from "../translate.js";
|
|
4
|
+
import { commitRunOps, reduceBehaviorEnd } from "@weasel-js/core";
|
|
5
|
+
|
|
6
|
+
// src/actions/move/commit/index.ts
|
|
7
|
+
/** What the behaviors answer for the commit: ops, `null` to abort, or
|
|
8
|
+
* `undefined` when every one of them leaves it to the default translate. */
|
|
9
|
+
function endBehaviors(session, delta, at) {
|
|
10
|
+
const { dx, dy } = delta;
|
|
11
|
+
const gctx = session.gestureCtx;
|
|
12
|
+
for (const [id, ori] of session.startPoses) gctx.current.set(id, draggedStoredPose(session, id, ori, dx, dy));
|
|
13
|
+
return reduceBehaviorEnd(session.behaviors, gctx, {
|
|
14
|
+
translateOps: (ids) => rootTranslateOps(session, ids, delta),
|
|
15
|
+
pointer: at
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Commit the drag. Returns whether anything reached the document: false
|
|
19
|
+
* when there was nothing to write, or a container refused what it was sent. */
|
|
20
|
+
function commitMove(input) {
|
|
21
|
+
const { session, at } = input;
|
|
22
|
+
const { dx, dy } = input.delta;
|
|
23
|
+
const commitOps = (ops) => {
|
|
24
|
+
const followers = landedDescendantOps({
|
|
25
|
+
scene: session.scene,
|
|
26
|
+
descriptorOf: session.descriptorOf,
|
|
27
|
+
startPoses: session.startPoses,
|
|
28
|
+
label: session.lifecycle.label
|
|
29
|
+
}, ops);
|
|
30
|
+
return commitRunOps(session, session.lifecycle, [...ops, ...followers]);
|
|
31
|
+
};
|
|
32
|
+
const answer = endBehaviors(session, {
|
|
33
|
+
dx,
|
|
34
|
+
dy
|
|
35
|
+
}, at);
|
|
36
|
+
if (answer === null) return false;
|
|
37
|
+
if (answer !== void 0) return commitOps(answer);
|
|
38
|
+
if (dx === 0 && dy === 0) return false;
|
|
39
|
+
const ops = translateOps(session, [...session.ids, ...session.cascadeIds], {
|
|
40
|
+
dx,
|
|
41
|
+
dy
|
|
42
|
+
});
|
|
43
|
+
return ops.length > 0 && commitOps(ops);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { commitMove };
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/actions/move/commit/index.ts"],"sourcesContent":["import type { Op } from '@weasel-js/core';\nimport { commitRunOps, reduceBehaviorEnd } from '@weasel-js/core';\nimport { draggedStoredPose } from '../delta';\nimport { landedDescendantOps } from '../landedDescendants';\nimport type { MoveSession } from '../session';\nimport { rootTranslateOps, translateOps } from '../translate';\n\nexport interface CommitInput {\n session: MoveSession;\n delta: { dx: number; dy: number };\n /** Where the pointer was let go, or the last move's point when the end carried none. */\n at: { x: number; y: number };\n}\n\n/** What the behaviors answer for the commit: ops, `null` to abort, or\n * `undefined` when every one of them leaves it to the default translate. */\nfunction endBehaviors(\n session: MoveSession,\n delta: { dx: number; dy: number },\n at: { x: number; y: number },\n): Op[] | null | undefined {\n const { dx, dy } = delta;\n const gctx = session.gestureCtx;\n for (const [id, ori] of session.startPoses) {\n gctx.current.set(id as string, draggedStoredPose(session, id, ori, dx, dy));\n }\n return reduceBehaviorEnd(session.behaviors, gctx, {\n translateOps: (ids) => rootTranslateOps(session, ids, delta),\n pointer: at,\n });\n}\n\n/** Commit the drag. Returns whether anything reached the document: false\n * when there was nothing to write, or a container refused what it was sent. */\nexport function commitMove(input: CommitInput): boolean {\n const { session, at } = input;\n // Apply the final delta as a single batch → one undo entry.\n const { dx, dy } = input.delta;\n const commitOps = (ops: Op[]): boolean => {\n const followers = landedDescendantOps(\n {\n scene: session.scene,\n descriptorOf: session.descriptorOf,\n startPoses: session.startPoses,\n label: session.lifecycle.label,\n },\n ops,\n );\n return commitRunOps(session, session.lifecycle, [...ops, ...followers]);\n };\n\n // Behavior pipeline owns the commit if any behavior returns non-undefined.\n const answer = endBehaviors(session, { dx, dy }, at);\n if (answer === null) return false; // abort (e.g. snap-back)\n if (answer !== undefined) return commitOps(answer);\n\n // No-op if no movement (sub-threshold drag or zero delta).\n if (dx === 0 && dy === 0) return false;\n\n // No behavior claimed it — translate-only commit, emitted as transform ops\n // so it routes through the consumer `applyOps` hook when present. A\n // descendant a moving frame carries is left out; one under an envelope is\n // translated with it.\n const ops = translateOps(session, [...session.ids, ...session.cascadeIds], { dx, dy });\n return ops.length > 0 && commitOps(ops);\n}\n"],"mappings":";;;;;;;;AAgBA,SAAS,aACP,SACA,OACA,IACyB;CACzB,MAAM,EAAE,IAAI,OAAO;CACnB,MAAM,OAAO,QAAQ;CACrB,KAAK,MAAM,CAAC,IAAI,QAAQ,QAAQ,YAC9B,KAAK,QAAQ,IAAI,IAAc,kBAAkB,SAAS,IAAI,KAAK,IAAI,EAAE,CAAC;CAE5E,OAAO,kBAAkB,QAAQ,WAAW,MAAM;EAChD,eAAe,QAAQ,iBAAiB,SAAS,KAAK,KAAK;EAC3D,SAAS;CACX,CAAC;AACH;;;AAIA,SAAgB,WAAW,OAA6B;CACtD,MAAM,EAAE,SAAS,OAAO;CAExB,MAAM,EAAE,IAAI,OAAO,MAAM;CACzB,MAAM,aAAa,QAAuB;EACxC,MAAM,YAAY,oBAChB;GACE,OAAO,QAAQ;GACf,cAAc,QAAQ;GACtB,YAAY,QAAQ;GACpB,OAAO,QAAQ,UAAU;EAC3B,GACA,GACF;EACA,OAAO,aAAa,SAAS,QAAQ,WAAW,CAAC,GAAG,KAAK,GAAG,SAAS,CAAC;CACxE;CAGA,MAAM,SAAS,aAAa,SAAS;EAAE;EAAI;CAAG,GAAG,EAAE;CACnD,IAAI,WAAW,MAAM,OAAO;CAC5B,IAAI,WAAW,QAAW,OAAO,UAAU,MAAM;CAGjD,IAAI,OAAO,KAAK,OAAO,GAAG,OAAO;CAMjC,MAAM,MAAM,aAAa,SAAS,CAAC,GAAG,QAAQ,KAAK,GAAG,QAAQ,UAAU,GAAG;EAAE;EAAI;CAAG,CAAC;CACrF,OAAO,IAAI,SAAS,KAAK,UAAU,GAAG;AACxC"}
|