@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 @@
|
|
|
1
|
+
{"version":3,"file":"lockedWrites.js","names":[],"sources":["../../src/actions/lockedWrites.ts"],"sourcesContent":["import type { NodeId, Op, Scene } from '@weasel-js/core';\nimport { writtenBy } from '@weasel-js/core';\nimport { ActionDisabledReason } from '@weasel-js/routing';\n\n/** Whether committing `ops` would write the pose or data of a locked node, which the scene's lock guard refuses:\n * an envelope moves, turns, or mirrors by rewriting its sources, and one of them may be locked. */\nexport function writesLocked(scene: Scene<unknown, string, unknown>, ops: readonly Op[]): boolean {\n if (ops.length === 0 || typeof scene.isLocked !== 'function') return false;\n const written = writtenBy(scene, ops);\n return written !== null && [...written.keys()].some((id) => scene.isLocked(id as NodeId));\n}\n\n/** `enabled`'s answer for a command that would commit `ops` (ruled 2026-11-09 and 2026-11-10): not applicable when\n * they change nothing, locked when they would rewrite a locked node. */\nexport function opsAnswer(scene: Scene<unknown, string, unknown>, ops: readonly Op[]): true | ActionDisabledReason {\n if (ops.length === 0) return ActionDisabledReason.NotApplicable;\n return writesLocked(scene, ops) ? ActionDisabledReason.Locked : true;\n}\n"],"mappings":";;;;;;AAMA,SAAgB,aAAa,OAAwC,KAA6B;CAChG,IAAI,IAAI,WAAW,KAAK,OAAO,MAAM,aAAa,YAAY,OAAO;CACrE,MAAM,UAAU,UAAU,OAAO,GAAG;CACpC,OAAO,YAAY,QAAQ,CAAC,GAAG,QAAQ,KAAK,CAAC,CAAC,CAAC,MAAM,OAAO,MAAM,SAAS,EAAY,CAAC;AAC1F;;;AAIA,SAAgB,UAAU,OAAwC,KAAiD;CACjH,IAAI,IAAI,WAAW,GAAG,OAAO,qBAAqB;CAClD,OAAO,aAAa,OAAO,GAAG,IAAI,qBAAqB,SAAS;AAClE"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { beginMove } from "./session.js";
|
|
2
|
+
import { nextFrame } from "./frame.js";
|
|
3
|
+
import { commitMove } from "./commit/index.js";
|
|
4
|
+
import { closeRun, createTransformPreview, finiteFrame, inPlane, recordTransform, runBehaviorCancel, selectionLayer } from "@weasel-js/core";
|
|
5
|
+
import { defineAction } from "@weasel-js/routing";
|
|
6
|
+
import { SNAP_ROLES } from "@weasel-js/core/engine";
|
|
7
|
+
import { createEmitter } from "@weasel-js/registry";
|
|
8
|
+
|
|
9
|
+
// src/actions/move/action.ts
|
|
10
|
+
/**
|
|
11
|
+
* Drag-translates the selection.
|
|
12
|
+
*
|
|
13
|
+
* Each frame's poses go to the scene's ephemeral override table, not the
|
|
14
|
+
* document: `Scene.setPose` records an undo entry per call, and the overrides
|
|
15
|
+
* are what let a node deriving its geometry from a dragged one follow the
|
|
16
|
+
* drag. Release commits one batch — at most one undo entry, none when the
|
|
17
|
+
* binding's params make it transient — and cancel drops the overrides.
|
|
18
|
+
*
|
|
19
|
+
* Behaviors from the binding's `opts.behaviors` fold into each frame; on
|
|
20
|
+
* release the first non-`undefined` answer wins (`Op[]` commits, `null`
|
|
21
|
+
* aborts). `beginMove` appends the action's own: a layout drop, a page drop
|
|
22
|
+
* in a paged scene, and reparent-on-drop.
|
|
23
|
+
*/
|
|
24
|
+
var moveAction = inPlane(defineAction({
|
|
25
|
+
id: "move",
|
|
26
|
+
label: "Move",
|
|
27
|
+
activeCursor: "move",
|
|
28
|
+
defaultBinding: [{
|
|
29
|
+
spec: {
|
|
30
|
+
kind: "drag",
|
|
31
|
+
target: "selected-body"
|
|
32
|
+
},
|
|
33
|
+
opts: { id: "move.drag" }
|
|
34
|
+
}],
|
|
35
|
+
eligible: { capability: "transforms-selection" },
|
|
36
|
+
modifierRoles: SNAP_ROLES,
|
|
37
|
+
requires: [
|
|
38
|
+
"operands",
|
|
39
|
+
"scene",
|
|
40
|
+
"poseDescriptor",
|
|
41
|
+
"layout",
|
|
42
|
+
"applyOps",
|
|
43
|
+
"geometryProjection",
|
|
44
|
+
"nodeAtPoint",
|
|
45
|
+
"canDropInto",
|
|
46
|
+
"canSwap",
|
|
47
|
+
"view",
|
|
48
|
+
"boundsIncludeStroke",
|
|
49
|
+
"drawnBoxes",
|
|
50
|
+
"kitSettings",
|
|
51
|
+
"snap",
|
|
52
|
+
"transformFollowers"
|
|
53
|
+
],
|
|
54
|
+
invoker: {
|
|
55
|
+
timing: "ongoing",
|
|
56
|
+
start(ctx, opts) {
|
|
57
|
+
let frame = {
|
|
58
|
+
delta: {
|
|
59
|
+
dx: 0,
|
|
60
|
+
dy: 0
|
|
61
|
+
},
|
|
62
|
+
previews: /* @__PURE__ */ new Map(),
|
|
63
|
+
opaque: /* @__PURE__ */ new Set(),
|
|
64
|
+
overlays: []
|
|
65
|
+
};
|
|
66
|
+
const begun = beginMove(ctx, opts, () => frame);
|
|
67
|
+
if (!begun) return {};
|
|
68
|
+
const { session, readers } = begun;
|
|
69
|
+
const subject = [...ctx.deps.operands?.get() ?? []];
|
|
70
|
+
const hold = session.scene.overrides.hold();
|
|
71
|
+
const preview = createTransformPreview(ctx.deps, session.scene, () => frame.previews);
|
|
72
|
+
let engaged = null;
|
|
73
|
+
let lastMove = null;
|
|
74
|
+
const shown = createEmitter();
|
|
75
|
+
const show = (moveCtx) => {
|
|
76
|
+
frame = finiteFrame(frame, moveCtx, () => nextFrame(session, readers, moveCtx), (f) => f.previews);
|
|
77
|
+
hold.set(preview.poses());
|
|
78
|
+
};
|
|
79
|
+
session.gestureCtx.refresh = () => {
|
|
80
|
+
if (!lastMove) return;
|
|
81
|
+
show(lastMove);
|
|
82
|
+
shown.emit();
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
kind: "move",
|
|
86
|
+
autoPan: true,
|
|
87
|
+
onMove(moveCtx) {
|
|
88
|
+
if (!moveCtx.drag) return;
|
|
89
|
+
if (!engaged) session.lifecycle.start(session.ids);
|
|
90
|
+
engaged = moveCtx.world;
|
|
91
|
+
lastMove = moveCtx;
|
|
92
|
+
show(moveCtx);
|
|
93
|
+
},
|
|
94
|
+
subscribe: (changed) => shown.subscribe(changed),
|
|
95
|
+
cursor: () => frame.cursor,
|
|
96
|
+
onEnd(endCtx, reason) {
|
|
97
|
+
let committed = false;
|
|
98
|
+
try {
|
|
99
|
+
if (reason === "commit" && engaged) {
|
|
100
|
+
committed = commitMove({
|
|
101
|
+
session,
|
|
102
|
+
delta: frame.delta,
|
|
103
|
+
at: endCtx.drag ? endCtx.world : engaged
|
|
104
|
+
});
|
|
105
|
+
if (committed) recordTransform(session.scene, {
|
|
106
|
+
kind: "translate",
|
|
107
|
+
...frame.delta
|
|
108
|
+
}, subject);
|
|
109
|
+
} else runBehaviorCancel(session.behaviors, session.gestureCtx);
|
|
110
|
+
} finally {
|
|
111
|
+
session.snap?.end();
|
|
112
|
+
closeRun({
|
|
113
|
+
hold,
|
|
114
|
+
previews: frame.previews,
|
|
115
|
+
behaviors: session.behaviors,
|
|
116
|
+
ctx: session.gestureCtx,
|
|
117
|
+
lifecycle: session.lifecycle
|
|
118
|
+
}, committed);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
previewIds: preview.previewIds,
|
|
122
|
+
previewData: preview.previewData,
|
|
123
|
+
previewOpaqueIds: () => frame.opaque.size === 0 ? null : frame.opaque,
|
|
124
|
+
overlay: () => frame.overlays.length === 0 ? null : frame.overlays
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Always enabled: the dispatcher treats anything `!== true` as "fall
|
|
130
|
+
* through to the next-best match", so a disabled reason here loses every
|
|
131
|
+
* drag-on-selected-body to a lower-specificity binding (a shape tool's
|
|
132
|
+
* insert drag).
|
|
133
|
+
*/
|
|
134
|
+
enabled: () => true
|
|
135
|
+
}), selectionLayer);
|
|
136
|
+
|
|
137
|
+
export { moveAction };
|
|
138
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.js","names":[],"sources":["../../../src/actions/move/action.ts"],"sourcesContent":["import { defineAction, type Action } from '@weasel-js/routing';\nimport { createEmitter } from '@weasel-js/registry';\nimport type { InvocationCtx } from '@weasel-js/routing';\nimport { createTransformPreview, finiteFrame, closeRun, runBehaviorCancel, inPlane, selectionLayer, recordTransform } from '@weasel-js/core';\nimport { beginMove, type MoveFrame } from './session';\nimport type { ReparentOnDrop } from '@weasel-js/core';\nimport { nextFrame } from './frame';\nimport { commitMove } from './commit';\nimport { SNAP_ROLES } from '@weasel-js/core/engine';\nimport type {} from '@weasel-js/core';\nexport type { ReparentOnDrop };\n\n/**\n * Drag-translates the selection.\n *\n * Each frame's poses go to the scene's ephemeral override table, not the\n * document: `Scene.setPose` records an undo entry per call, and the overrides\n * are what let a node deriving its geometry from a dragged one follow the\n * drag. Release commits one batch — at most one undo entry, none when the\n * binding's params make it transient — and cancel drops the overrides.\n *\n * Behaviors from the binding's `opts.behaviors` fold into each frame; on\n * release the first non-`undefined` answer wins (`Op[]` commits, `null`\n * aborts). `beginMove` appends the action's own: a layout drop, a page drop\n * in a paged scene, and reparent-on-drop.\n */\nexport const moveAction: Action = inPlane(defineAction({\n id: 'move',\n label: 'Move',\n // No hover `cursor`: pointing at a node shouldn't preemptively promise a move.\n activeCursor: 'move',\n // Ambient default targets `selected-body`, not a bare `{ kind: 'drag' }`,\n // which catches every drag in ambient scope and bleeds the move into\n // drawing-tool gestures wherever the higher-priority active match falls\n // through.\n defaultBinding: [{ spec: { kind: 'drag', target: 'selected-body' }, opts: { id: 'move.drag' } }],\n eligible: { capability: 'transforms-selection' },\n modifierRoles: SNAP_ROLES,\n requires: ['operands', 'scene', 'poseDescriptor', 'layout', 'applyOps', 'geometryProjection', 'nodeAtPoint', 'canDropInto', 'canSwap', 'view', 'boundsIncludeStroke', 'drawnBoxes', 'kitSettings', 'snap', 'transformFollowers'],\n invoker: {\n timing: 'ongoing',\n start(ctx, opts) {\n let frame: MoveFrame = { delta: { dx: 0, dy: 0 }, previews: new Map(), opaque: new Set(), overlays: [] };\n const begun = beginMove(ctx, opts, () => frame);\n if (!begun) return {};\n const { session, readers } = begun;\n const subject = [...(ctx.deps.operands?.get() ?? [])] as string[];\n const hold = session.scene.overrides.hold();\n const preview = createTransformPreview(ctx.deps, session.scene, () => frame.previews);\n // Where the last move put the pointer; null until the first.\n let engaged: { x: number; y: number } | null = null;\n let lastMove: InvocationCtx | null = null;\n const shown = createEmitter();\n const show = (moveCtx: InvocationCtx): void => {\n frame = finiteFrame(frame, moveCtx, () => nextFrame(session, readers, moveCtx), (f) => f.previews);\n hold.set(preview.poses());\n };\n session.gestureCtx.refresh = () => {\n if (!lastMove) return;\n show(lastMove);\n shown.emit();\n };\n return {\n kind: 'move',\n autoPan: true,\n onMove(moveCtx: InvocationCtx): void {\n if (!moveCtx.drag) return;\n if (!engaged) session.lifecycle.start(session.ids as unknown as string[]);\n engaged = moveCtx.world;\n lastMove = moveCtx;\n show(moveCtx);\n },\n subscribe: (changed) => shown.subscribe(changed),\n cursor: () => frame.cursor,\n onEnd(endCtx: InvocationCtx, reason: 'commit' | 'cancel'): void {\n let committed = false;\n try {\n // A press that never moved was never a move: its behaviors\n // started, so they are canceled, not asked to commit.\n if (reason === 'commit' && engaged) {\n committed = commitMove({\n session,\n delta: frame.delta,\n at: endCtx.drag ? endCtx.world : engaged,\n });\n if (committed) recordTransform(session.scene, { kind: 'translate', ...frame.delta }, subject);\n } else runBehaviorCancel(session.behaviors, session.gestureCtx);\n } finally {\n session.snap?.end();\n // After the commit, so no frame can paint the pre-drag pose between\n // the override going away and the document catching up.\n closeRun({ hold, previews: frame.previews, behaviors: session.behaviors, ctx: session.gestureCtx, lifecycle: session.lifecycle }, committed);\n }\n },\n previewIds: preview.previewIds,\n previewData: preview.previewData,\n previewOpaqueIds: () => (frame.opaque.size === 0 ? null : frame.opaque),\n overlay: () => (frame.overlays.length === 0 ? null : frame.overlays),\n };\n },\n },\n /**\n * Always enabled: the dispatcher treats anything `!== true` as \"fall\n * through to the next-best match\", so a disabled reason here loses every\n * drag-on-selected-body to a lower-specificity binding (a shape tool's\n * insert drag).\n */\n enabled: () => true,\n}), selectionLayer);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,aAAqB,QAAQ,aAAa;CACrD,IAAI;CACJ,OAAO;CAEP,cAAc;CAKd,gBAAgB,CAAC;EAAE,MAAM;GAAE,MAAM;GAAQ,QAAQ;EAAgB;EAAG,MAAM,EAAE,IAAI,YAAY;CAAE,CAAC;CAC/F,UAAU,EAAE,YAAY,uBAAuB;CAC/C,eAAe;CACf,UAAU;EAAC;EAAY;EAAS;EAAkB;EAAU;EAAY;EAAsB;EAAe;EAAe;EAAW;EAAQ;EAAuB;EAAc;EAAe;EAAQ;CAAoB;CAC/N,SAAS;EACP,QAAQ;EACR,MAAM,KAAK,MAAM;GACf,IAAI,QAAmB;IAAE,OAAO;KAAE,IAAI;KAAG,IAAI;IAAE;IAAG,0BAAU,IAAI,IAAI;IAAG,wBAAQ,IAAI,IAAI;IAAG,UAAU,CAAC;GAAE;GACvG,MAAM,QAAQ,UAAU,KAAK,YAAY,KAAK;GAC9C,IAAI,CAAC,OAAO,OAAO,CAAC;GACpB,MAAM,EAAE,SAAS,YAAY;GAC7B,MAAM,UAAU,CAAC,GAAI,IAAI,KAAK,UAAU,IAAI,KAAK,CAAC,CAAE;GACpD,MAAM,OAAO,QAAQ,MAAM,UAAU,KAAK;GAC1C,MAAM,UAAU,uBAAuB,IAAI,MAAM,QAAQ,aAAa,MAAM,QAAQ;GAEpF,IAAI,UAA2C;GAC/C,IAAI,WAAiC;GACrC,MAAM,QAAQ,cAAc;GAC5B,MAAM,QAAQ,YAAiC;IAC7C,QAAQ,YAAY,OAAO,eAAe,UAAU,SAAS,SAAS,OAAO,IAAI,MAAM,EAAE,QAAQ;IACjG,KAAK,IAAI,QAAQ,MAAM,CAAC;GAC1B;GACA,QAAQ,WAAW,gBAAgB;IACjC,IAAI,CAAC,UAAU;IACf,KAAK,QAAQ;IACb,MAAM,KAAK;GACb;GACA,OAAO;IACL,MAAM;IACN,SAAS;IACT,OAAO,SAA8B;KACnC,IAAI,CAAC,QAAQ,MAAM;KACnB,IAAI,CAAC,SAAS,QAAQ,UAAU,MAAM,QAAQ,GAA0B;KACxE,UAAU,QAAQ;KAClB,WAAW;KACX,KAAK,OAAO;IACd;IACA,YAAY,YAAY,MAAM,UAAU,OAAO;IAC/C,cAAc,MAAM;IACpB,MAAM,QAAuB,QAAmC;KAC9D,IAAI,YAAY;KAChB,IAAI;MAGF,IAAI,WAAW,YAAY,SAAS;OAClC,YAAY,WAAW;QACrB;QACA,OAAO,MAAM;QACb,IAAI,OAAO,OAAO,OAAO,QAAQ;OACnC,CAAC;OACD,IAAI,WAAW,gBAAgB,QAAQ,OAAO;QAAE,MAAM;QAAa,GAAG,MAAM;OAAM,GAAG,OAAO;MAC9F,OAAO,kBAAkB,QAAQ,WAAW,QAAQ,UAAU;KAChE,UAAU;MACR,QAAQ,MAAM,IAAI;MAGlB,SAAS;OAAE;OAAM,UAAU,MAAM;OAAU,WAAW,QAAQ;OAAW,KAAK,QAAQ;OAAY,WAAW,QAAQ;MAAU,GAAG,SAAS;KAC7I;IACF;IACA,YAAY,QAAQ;IACpB,aAAa,QAAQ;IACrB,wBAAyB,MAAM,OAAO,SAAS,IAAI,OAAO,MAAM;IAChE,eAAgB,MAAM,SAAS,WAAW,IAAI,OAAO,MAAM;GAC7D;EACF;CACF;;;;;;;CAOA,eAAe;AACjB,CAAC,GAAG,cAAc"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AUTO_POSE_DESCRIPTOR } from "@weasel-js/core/engine";
|
|
2
|
+
import { unionRects } from "@weasel-js/geom";
|
|
3
|
+
|
|
4
|
+
// src/actions/move/behaviors/clampMove.ts
|
|
5
|
+
/** The shift along one axis that keeps `[lo, hi]` moved by `d` inside `[min, max]`; a span wider
|
|
6
|
+
* than the range is held to its start. */
|
|
7
|
+
function clampAxis(d, lo, hi, min, max) {
|
|
8
|
+
if (hi + d > max) d = max - hi;
|
|
9
|
+
if (lo + d < min) d = min - lo;
|
|
10
|
+
return d;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Move behavior that keeps the dragged nodes inside `bounds`: the drag's translation is
|
|
14
|
+
* clamped so the box around every dragged node's start pose in world, moved by it, stays in the rect.
|
|
15
|
+
* The clamp applies to the preview and the commit alike, so a node let go past an edge lands
|
|
16
|
+
* on it. Put it after behaviors that reshape the translation, so it has the last word.
|
|
17
|
+
*/
|
|
18
|
+
function clampMove(opts) {
|
|
19
|
+
const d = opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR;
|
|
20
|
+
return { onMove(ctx, proposed) {
|
|
21
|
+
const b = typeof opts.bounds === "function" ? opts.bounds() : opts.bounds;
|
|
22
|
+
const starts = [];
|
|
23
|
+
for (const id of ctx.draggedIds) {
|
|
24
|
+
const pose = ctx.origin.get(id);
|
|
25
|
+
if (pose !== void 0) starts.push(d.getBounds(ctx.frames ? ctx.frames.toWorld(id, pose) : pose));
|
|
26
|
+
}
|
|
27
|
+
const u = unionRects(starts);
|
|
28
|
+
if (!u) return void 0;
|
|
29
|
+
const x0 = u.x, y0 = u.y, x1 = u.x + u.width, y1 = u.y + u.height;
|
|
30
|
+
const dx = clampAxis(proposed.dx, x0, x1, b.x, b.x + b.width);
|
|
31
|
+
const dy = clampAxis(proposed.dy, y0, y1, b.y, b.y + b.height);
|
|
32
|
+
if (dx === proposed.dx && dy === proposed.dy) return void 0;
|
|
33
|
+
return { transform: {
|
|
34
|
+
kind: "translate",
|
|
35
|
+
dx,
|
|
36
|
+
dy
|
|
37
|
+
} };
|
|
38
|
+
} };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { clampMove };
|
|
42
|
+
//# sourceMappingURL=clampMove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clampMove.js","names":[],"sources":["../../../../src/actions/move/behaviors/clampMove.ts"],"sourcesContent":["import { unionRects, type FramedRect, type Rect } from '@weasel-js/geom';\nimport type { PoseDescriptor, MoveBehavior } from '@weasel-js/core/engine';\nimport { AUTO_POSE_DESCRIPTOR } from '@weasel-js/core/engine';\n\n/** What {@link clampMove} takes. */\nexport interface ClampMoveOptions<TPose> {\n /** The world rect the dragged nodes stay inside, or a function read each frame for one that changes. */\n bounds: FramedRect | (() => FramedRect);\n /** Reads each pose's box. Default `AUTO_POSE_DESCRIPTOR`. */\n poseDescriptor?: PoseDescriptor<TPose>;\n}\n\n/** The shift along one axis that keeps `[lo, hi]` moved by `d` inside `[min, max]`; a span wider\n * than the range is held to its start. */\nfunction clampAxis(d: number, lo: number, hi: number, min: number, max: number): number {\n if (hi + d > max) d = max - hi;\n if (lo + d < min) d = min - lo;\n return d;\n}\n\n/**\n * Move behavior that keeps the dragged nodes inside `bounds`: the drag's translation is\n * clamped so the box around every dragged node's start pose in world, moved by it, stays in the rect.\n * The clamp applies to the preview and the commit alike, so a node let go past an edge lands\n * on it. Put it after behaviors that reshape the translation, so it has the last word.\n */\nexport function clampMove<TPose>(opts: ClampMoveOptions<TPose>): MoveBehavior<TPose> {\n const d = (opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n return {\n onMove(ctx, proposed) {\n const b = typeof opts.bounds === 'function' ? opts.bounds() : opts.bounds;\n const starts: Rect[] = [];\n for (const id of ctx.draggedIds) {\n const pose = ctx.origin.get(id);\n if (pose !== undefined) starts.push(d.getBounds(ctx.frames ? ctx.frames.toWorld(id, pose) : pose));\n }\n const u = unionRects(starts);\n if (!u) return undefined;\n const x0 = u.x, y0 = u.y, x1 = u.x + u.width, y1 = u.y + u.height;\n const dx = clampAxis(proposed.dx, x0, x1, b.x, b.x + b.width);\n const dy = clampAxis(proposed.dy, y0, y1, b.y, b.y + b.height);\n if (dx === proposed.dx && dy === proposed.dy) return undefined;\n return { transform: { kind: 'translate', dx, dy } };\n },\n };\n}\n"],"mappings":";;;;;;AAcA,SAAS,UAAU,GAAW,IAAY,IAAY,KAAa,KAAqB;CACtF,IAAI,KAAK,IAAI,KAAK,IAAI,MAAM;CAC5B,IAAI,KAAK,IAAI,KAAK,IAAI,MAAM;CAC5B,OAAO;AACT;;;;;;;AAQA,SAAgB,UAAiB,MAAoD;CACnF,MAAM,IAAK,KAAK,kBAAkB;CAClC,OAAO,EACL,OAAO,KAAK,UAAU;EACpB,MAAM,IAAI,OAAO,KAAK,WAAW,aAAa,KAAK,OAAO,IAAI,KAAK;EACnE,MAAM,SAAiB,CAAC;EACxB,KAAK,MAAM,MAAM,IAAI,YAAY;GAC/B,MAAM,OAAO,IAAI,OAAO,IAAI,EAAE;GAC9B,IAAI,SAAS,QAAW,OAAO,KAAK,EAAE,UAAU,IAAI,SAAS,IAAI,OAAO,QAAQ,IAAI,IAAI,IAAI,IAAI,CAAC;EACnG;EACA,MAAM,IAAI,WAAW,MAAM;EAC3B,IAAI,CAAC,GAAG,OAAO;EACf,MAAM,KAAK,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,OAAO,KAAK,EAAE,IAAI,EAAE;EAC3D,MAAM,KAAK,UAAU,SAAS,IAAI,IAAI,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK;EAC5D,MAAM,KAAK,UAAU,SAAS,IAAI,IAAI,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM;EAC7D,IAAI,OAAO,SAAS,MAAM,OAAO,SAAS,IAAI,OAAO;EACrD,OAAO,EAAE,WAAW;GAAE,MAAM;GAAa;GAAI;EAAG,EAAE;CACpD,EACF;AACF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { layoutDropOps } from "../commit/layoutDrop.js";
|
|
2
|
+
import { layoutReleaseOps } from "../commit/layoutRelease.js";
|
|
3
|
+
import { runDropPass } from "../layout/dropPass.js";
|
|
4
|
+
import { landReleased, releasedPoses, stepGlide } from "../layout/glide.js";
|
|
5
|
+
import { swapArmed } from "../sessionOf.js";
|
|
6
|
+
import { refusalOverlays } from "../refusal.js";
|
|
7
|
+
|
|
8
|
+
// src/actions/move/behaviors/layoutDrop.ts
|
|
9
|
+
/**
|
|
10
|
+
* The move behavior that drops the selection into the layout container under
|
|
11
|
+
* it. Each move it resolves the drop and shows the siblings making room; on
|
|
12
|
+
* release it answers with the container's `commitDrop`, or, outside every
|
|
13
|
+
* container, with what the source layouts' `releaseDrop` and the exits decide.
|
|
14
|
+
*
|
|
15
|
+
* Built by the move action for one drag, after the binding's own behaviors, and
|
|
16
|
+
* only when the `layout` dep is present.
|
|
17
|
+
*/
|
|
18
|
+
function layoutDrop(move) {
|
|
19
|
+
let drop = null;
|
|
20
|
+
const gliding = /* @__PURE__ */ new Set();
|
|
21
|
+
let released = null;
|
|
22
|
+
const noteReleased = () => {
|
|
23
|
+
const session = move.session();
|
|
24
|
+
if (session.layout?.reflow) released = releasedPoses(session, move.frame().previews);
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
onMove(ctx, proposed) {
|
|
28
|
+
drop = null;
|
|
29
|
+
const session = move.session();
|
|
30
|
+
const reflow = session.layout?.reflow;
|
|
31
|
+
if (swapArmed(ctx)) {
|
|
32
|
+
if (reflow) stepGlide(reflow, gliding, /* @__PURE__ */ new Map());
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
drop = runDropPass(session, {
|
|
36
|
+
dx: proposed.dx,
|
|
37
|
+
dy: proposed.dy
|
|
38
|
+
}, {
|
|
39
|
+
x: ctx.pointer.worldX,
|
|
40
|
+
y: ctx.pointer.worldY
|
|
41
|
+
});
|
|
42
|
+
const opaque = drop?.pass?.reflowIds;
|
|
43
|
+
const overlays = drop?.refused ? refusalOverlays(drop.refused, {
|
|
44
|
+
x: ctx.pointer.worldX,
|
|
45
|
+
y: ctx.pointer.worldY
|
|
46
|
+
}) : void 0;
|
|
47
|
+
if (!reflow) return {
|
|
48
|
+
poses: drop?.reflow,
|
|
49
|
+
opaque,
|
|
50
|
+
overlays
|
|
51
|
+
};
|
|
52
|
+
stepGlide(reflow, gliding, drop?.reflow ?? /* @__PURE__ */ new Map());
|
|
53
|
+
return {
|
|
54
|
+
opaque,
|
|
55
|
+
overlays
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
onEnd(_ctx, end) {
|
|
59
|
+
noteReleased();
|
|
60
|
+
if (end.answered) return;
|
|
61
|
+
if (drop?.refused) return null;
|
|
62
|
+
const session = move.session();
|
|
63
|
+
const { delta } = move.frame();
|
|
64
|
+
if (delta.dx === 0 && delta.dy === 0) return;
|
|
65
|
+
const orAbort = (ops) => ops !== null && ops.length > 0 ? ops : null;
|
|
66
|
+
if (drop?.pass) return orAbort(layoutDropOps(session, drop.pass));
|
|
67
|
+
const release = layoutReleaseOps(session, delta, drop?.dropCenter ?? null);
|
|
68
|
+
return release === void 0 ? void 0 : orAbort(release);
|
|
69
|
+
},
|
|
70
|
+
onCancel: noteReleased,
|
|
71
|
+
onSettled() {
|
|
72
|
+
const session = move.session();
|
|
73
|
+
const reflow = session.layout?.reflow;
|
|
74
|
+
if (reflow) {
|
|
75
|
+
for (const id of gliding) reflow.settle(id);
|
|
76
|
+
landReleased(session, reflow, released ?? /* @__PURE__ */ new Map());
|
|
77
|
+
}
|
|
78
|
+
gliding.clear();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { layoutDrop };
|
|
84
|
+
//# sourceMappingURL=layoutDrop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layoutDrop.js","names":[],"sources":["../../../../src/actions/move/behaviors/layoutDrop.ts"],"sourcesContent":["import type { Op, NodeId } from '@weasel-js/core';\nimport type { BehaviorResult, MoveBehavior } from '@weasel-js/core/engine';\nimport { layoutDropOps } from '../commit/layoutDrop';\nimport { layoutReleaseOps } from '../commit/layoutRelease';\nimport { runDropPass } from '../layout/dropPass';\nimport { landReleased, releasedPoses, stepGlide, type Released } from '../layout/glide';\nimport type { DropPass } from '../layout/types';\nimport type { MoveGesture } from '../session';\nimport { swapArmed } from '../sessionOf';\nimport { refusalOverlays } from '../refusal';\n\n/**\n * The move behavior that drops the selection into the layout container under\n * it. Each move it resolves the drop and shows the siblings making room; on\n * release it answers with the container's `commitDrop`, or, outside every\n * container, with what the source layouts' `releaseDrop` and the exits decide.\n *\n * Built by the move action for one drag, after the binding's own behaviors, and\n * only when the `layout` dep is present.\n */\nexport function layoutDrop(move: MoveGesture): MoveBehavior<unknown> {\n // This frame's pass; reset by every move, a throwing one included.\n let drop: DropPass | null = null;\n const gliding = new Set<NodeId>();\n let released: Map<NodeId, Released> | null = null;\n // Before the commit: where each dragged id is shown as the gesture closes.\n const noteReleased = (): void => {\n const session = move.session();\n if (session.layout?.reflow) released = releasedPoses(session, move.frame().previews);\n };\n\n return {\n onMove(ctx, proposed): BehaviorResult<unknown> | void {\n drop = null;\n const session = move.session();\n const reflow = session.layout?.reflow;\n if (swapArmed(ctx)) {\n if (reflow) stepGlide(reflow, gliding, new Map());\n return undefined;\n }\n drop = runDropPass(\n session,\n { dx: proposed.dx, dy: proposed.dy },\n { x: ctx.pointer.worldX, y: ctx.pointer.worldY },\n );\n const opaque = drop?.pass?.reflowIds;\n const overlays = drop?.refused ? refusalOverlays(drop.refused, { x: ctx.pointer.worldX, y: ctx.pointer.worldY }) : undefined;\n if (!reflow) return { poses: drop?.reflow, opaque, overlays };\n stepGlide(reflow, gliding, drop?.reflow ?? new Map());\n return { opaque, overlays };\n },\n\n onEnd(_ctx, end): Op[] | null | void {\n noteReleased();\n if (end.answered) return;\n // Released over a container that refuses the drop: the drag goes home.\n if (drop?.refused) return null;\n const session = move.session();\n const { delta } = move.frame();\n // No-op if no movement (sub-threshold drag or zero delta).\n if (delta.dx === 0 && delta.dy === 0) return;\n // A drop or a release that claims the selection and writes nothing\n // commits nothing: the translate must not run in its place.\n const orAbort = (ops: Op[] | null): Op[] | null => (ops !== null && ops.length > 0 ? ops : null);\n // Layout drop commit — takes precedence over reparent-on-drop when a\n // layout container accepted the drag this gesture. One placement per\n // dragged child, replayed in the order the preview resolved them.\n // TODO: geometryProjection for drop-reflow — left pose-only because the\n // reflow distributes per-child poses with no single global delta; not\n // exercised by the geometry contract gate.\n if (drop?.pass) return orAbort(layoutDropOps(session, drop.pass));\n const release = layoutReleaseOps(session, delta, drop?.dropCenter ?? null);\n return release === undefined ? undefined : orAbort(release);\n },\n\n onCancel: noteReleased,\n\n onSettled(): void {\n const session = move.session();\n const reflow = session.layout?.reflow;\n // After the commit: each glide settles onto the pose the document now\n // holds, or back home on a cancel — the dragged ids from where they\n // were let go.\n if (reflow) {\n for (const id of gliding) reflow.settle(id as string);\n landReleased(session, reflow, released ?? new Map());\n }\n gliding.clear();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,SAAgB,WAAW,MAA0C;CAEnE,IAAI,OAAwB;CAC5B,MAAM,0BAAU,IAAI,IAAY;CAChC,IAAI,WAAyC;CAE7C,MAAM,qBAA2B;EAC/B,MAAM,UAAU,KAAK,QAAQ;EAC7B,IAAI,QAAQ,QAAQ,QAAQ,WAAW,cAAc,SAAS,KAAK,MAAM,CAAC,CAAC,QAAQ;CACrF;CAEA,OAAO;EACL,OAAO,KAAK,UAA0C;GACpD,OAAO;GACP,MAAM,UAAU,KAAK,QAAQ;GAC7B,MAAM,SAAS,QAAQ,QAAQ;GAC/B,IAAI,UAAU,GAAG,GAAG;IAClB,IAAI,QAAQ,UAAU,QAAQ,yBAAS,IAAI,IAAI,CAAC;IAChD;GACF;GACA,OAAO,YACL,SACA;IAAE,IAAI,SAAS;IAAI,IAAI,SAAS;GAAG,GACnC;IAAE,GAAG,IAAI,QAAQ;IAAQ,GAAG,IAAI,QAAQ;GAAO,CACjD;GACA,MAAM,SAAS,MAAM,MAAM;GAC3B,MAAM,WAAW,MAAM,UAAU,gBAAgB,KAAK,SAAS;IAAE,GAAG,IAAI,QAAQ;IAAQ,GAAG,IAAI,QAAQ;GAAO,CAAC,IAAI;GACnH,IAAI,CAAC,QAAQ,OAAO;IAAE,OAAO,MAAM;IAAQ;IAAQ;GAAS;GAC5D,UAAU,QAAQ,SAAS,MAAM,0BAAU,IAAI,IAAI,CAAC;GACpD,OAAO;IAAE;IAAQ;GAAS;EAC5B;EAEA,MAAM,MAAM,KAAyB;GACnC,aAAa;GACb,IAAI,IAAI,UAAU;GAElB,IAAI,MAAM,SAAS,OAAO;GAC1B,MAAM,UAAU,KAAK,QAAQ;GAC7B,MAAM,EAAE,UAAU,KAAK,MAAM;GAE7B,IAAI,MAAM,OAAO,KAAK,MAAM,OAAO,GAAG;GAGtC,MAAM,WAAW,QAAmC,QAAQ,QAAQ,IAAI,SAAS,IAAI,MAAM;GAO3F,IAAI,MAAM,MAAM,OAAO,QAAQ,cAAc,SAAS,KAAK,IAAI,CAAC;GAChE,MAAM,UAAU,iBAAiB,SAAS,OAAO,MAAM,cAAc,IAAI;GACzE,OAAO,YAAY,SAAY,SAAY,QAAQ,OAAO;EAC5D;EAEA,UAAU;EAEV,YAAkB;GAChB,MAAM,UAAU,KAAK,QAAQ;GAC7B,MAAM,SAAS,QAAQ,QAAQ;GAI/B,IAAI,QAAQ;IACV,KAAK,MAAM,MAAM,SAAS,OAAO,OAAO,EAAY;IACpD,aAAa,SAAS,QAAQ,4BAAY,IAAI,IAAI,CAAC;GACrD;GACA,QAAQ,MAAM;EAChB;CACF;AACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { pageDropOps, pageDrops } from "../commit/pageDrop.js";
|
|
2
|
+
|
|
3
|
+
// src/actions/move/behaviors/pageDrop.ts
|
|
4
|
+
/**
|
|
5
|
+
* The move behavior that keeps a paged scene's content on its pages: a page's
|
|
6
|
+
* child released on another page moves into it, and one released off every
|
|
7
|
+
* page goes to the top of the tree with the pasteboard on, or stays in its
|
|
8
|
+
* page with part of it still on it with the pasteboard off. With the
|
|
9
|
+
* pasteboard on, a root released on a page moves into it. A move within one
|
|
10
|
+
* page, and one of a node deeper than a page's child, is left to the
|
|
11
|
+
* behaviors after it.
|
|
12
|
+
*
|
|
13
|
+
* Built by the move action for one drag in a paged scene, before
|
|
14
|
+
* reparent-on-drop, whose `reparentOnDrop` param it does not read.
|
|
15
|
+
*/
|
|
16
|
+
function pageDrop(move) {
|
|
17
|
+
return { onEnd(_ctx, end) {
|
|
18
|
+
if (end.answered) return;
|
|
19
|
+
const session = move.session();
|
|
20
|
+
const { delta } = move.frame();
|
|
21
|
+
if (delta.dx === 0 && delta.dy === 0) return;
|
|
22
|
+
const drops = pageDrops(session, end.pointer, delta);
|
|
23
|
+
if (drops === null) return;
|
|
24
|
+
if (drops === "refused") return null;
|
|
25
|
+
return pageDropOps(session, drops, delta);
|
|
26
|
+
} };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { pageDrop };
|
|
30
|
+
//# sourceMappingURL=pageDrop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageDrop.js","names":[],"sources":["../../../../src/actions/move/behaviors/pageDrop.ts"],"sourcesContent":["import type { MoveBehavior } from '@weasel-js/core/engine';\nimport { pageDropOps, pageDrops } from '../commit/pageDrop';\nimport type { MoveGesture } from '../session';\n\n/**\n * The move behavior that keeps a paged scene's content on its pages: a page's\n * child released on another page moves into it, and one released off every\n * page goes to the top of the tree with the pasteboard on, or stays in its\n * page with part of it still on it with the pasteboard off. With the\n * pasteboard on, a root released on a page moves into it. A move within one\n * page, and one of a node deeper than a page's child, is left to the\n * behaviors after it.\n *\n * Built by the move action for one drag in a paged scene, before\n * reparent-on-drop, whose `reparentOnDrop` param it does not read.\n */\nexport function pageDrop(move: MoveGesture): MoveBehavior<unknown> {\n return {\n onEnd(_ctx, end) {\n if (end.answered) return;\n const session = move.session();\n const { delta } = move.frame();\n if (delta.dx === 0 && delta.dy === 0) return;\n const drops = pageDrops(session, end.pointer, delta);\n if (drops === null) return;\n if (drops === 'refused') return null;\n return pageDropOps(session, drops, delta);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,SAAS,MAA0C;CACjE,OAAO,EACL,MAAM,MAAM,KAAK;EACf,IAAI,IAAI,UAAU;EAClB,MAAM,UAAU,KAAK,QAAQ;EAC7B,MAAM,EAAE,UAAU,KAAK,MAAM;EAC7B,IAAI,MAAM,OAAO,KAAK,MAAM,OAAO,GAAG;EACtC,MAAM,QAAQ,UAAU,SAAS,IAAI,SAAS,KAAK;EACnD,IAAI,UAAU,MAAM;EACpB,IAAI,UAAU,WAAW,OAAO;EAChC,OAAO,YAAY,SAAS,OAAO,KAAK;CAC1C,EACF;AACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { reparentOps, resolveDrop } from "../commit/reparent.js";
|
|
2
|
+
import { refusalOverlays } from "../refusal.js";
|
|
3
|
+
import { swapArmed } from "../sessionOf.js";
|
|
4
|
+
|
|
5
|
+
// src/actions/move/behaviors/reparentOnDrop.ts
|
|
6
|
+
/**
|
|
7
|
+
* The move behavior that reparents the selection under the node the pointer is
|
|
8
|
+
* released over, when the binding's `reparentOnDrop` param asks for it. While
|
|
9
|
+
* the pointer is over a container that refuses the drop with a reason, it draws
|
|
10
|
+
* the refusal, and a release there moves nothing.
|
|
11
|
+
*
|
|
12
|
+
* Built by the move action for one drag and run last, so a binding's behavior
|
|
13
|
+
* or a layout drop that claims the commit preempts it.
|
|
14
|
+
*/
|
|
15
|
+
function reparentOnDrop(move) {
|
|
16
|
+
const dropAt = (at) => {
|
|
17
|
+
const session = move.session();
|
|
18
|
+
return session.reparentOnDrop() === "off" ? null : resolveDrop(session, at);
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
onMove(ctx) {
|
|
22
|
+
if (!move.session().mayRefuse || swapArmed(ctx)) return void 0;
|
|
23
|
+
const at = {
|
|
24
|
+
x: ctx.pointer.worldX,
|
|
25
|
+
y: ctx.pointer.worldY
|
|
26
|
+
};
|
|
27
|
+
const drop = dropAt(at);
|
|
28
|
+
return drop !== null && "refused" in drop ? { overlays: refusalOverlays(drop.refused, at) } : void 0;
|
|
29
|
+
},
|
|
30
|
+
onEnd(_ctx, end) {
|
|
31
|
+
if (end.answered) return;
|
|
32
|
+
const session = move.session();
|
|
33
|
+
const { delta } = move.frame();
|
|
34
|
+
if (delta.dx === 0 && delta.dy === 0) return;
|
|
35
|
+
const drop = dropAt(end.pointer);
|
|
36
|
+
if (drop === null) return void 0;
|
|
37
|
+
if ("refused" in drop) return null;
|
|
38
|
+
return reparentOps(session, drop, session.reparentOnDrop(), delta);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { reparentOnDrop };
|
|
44
|
+
//# sourceMappingURL=reparentOnDrop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reparentOnDrop.js","names":[],"sources":["../../../../src/actions/move/behaviors/reparentOnDrop.ts"],"sourcesContent":["import type { MoveBehavior } from '@weasel-js/core/engine';\nimport { reparentOps, resolveDrop } from '../commit/reparent';\nimport { refusalOverlays } from '../refusal';\nimport type { MoveGesture } from '../session';\nimport { swapArmed } from '../sessionOf';\n\n/**\n * The move behavior that reparents the selection under the node the pointer is\n * released over, when the binding's `reparentOnDrop` param asks for it. While\n * the pointer is over a container that refuses the drop with a reason, it draws\n * the refusal, and a release there moves nothing.\n *\n * Built by the move action for one drag and run last, so a binding's behavior\n * or a layout drop that claims the commit preempts it.\n */\nexport function reparentOnDrop(move: MoveGesture): MoveBehavior<unknown> {\n const dropAt = (at: { x: number; y: number }) => {\n const session = move.session();\n return session.reparentOnDrop() === 'off' ? null : resolveDrop(session, at);\n };\n return {\n onMove(ctx) {\n // Only a `canDropInto` dep refuses with a reason; without one, the hit-test waits for the release.\n if (!move.session().mayRefuse || swapArmed(ctx)) return undefined;\n const at = { x: ctx.pointer.worldX, y: ctx.pointer.worldY };\n const drop = dropAt(at);\n return drop !== null && 'refused' in drop ? { overlays: refusalOverlays(drop.refused, at) } : undefined;\n },\n onEnd(_ctx, end) {\n if (end.answered) return;\n const session = move.session();\n const { delta } = move.frame();\n // No-op if no movement (sub-threshold drag or zero delta).\n if (delta.dx === 0 && delta.dy === 0) return;\n // Resolves the drop target via the `nodeAtPoint` dep (sourced by\n // `<SceneCanvas>`) and reparents each moved root under it, then\n // writes the translated pose in the new parent's frame so the\n // visual position is preserved across the parent swap.\n // An end with no drag carries no pointer: the dispatcher's `cancelAll`\n // reports the world origin.\n const drop = dropAt(end.pointer);\n if (drop === null) return undefined;\n if ('refused' in drop) return null;\n return reparentOps(session, drop, session.reparentOnDrop(), delta);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,eAAe,MAA0C;CACvE,MAAM,UAAU,OAAiC;EAC/C,MAAM,UAAU,KAAK,QAAQ;EAC7B,OAAO,QAAQ,eAAe,MAAM,QAAQ,OAAO,YAAY,SAAS,EAAE;CAC5E;CACA,OAAO;EACL,OAAO,KAAK;GAEV,IAAI,CAAC,KAAK,QAAQ,CAAC,CAAC,aAAa,UAAU,GAAG,GAAG,OAAO;GACxD,MAAM,KAAK;IAAE,GAAG,IAAI,QAAQ;IAAQ,GAAG,IAAI,QAAQ;GAAO;GAC1D,MAAM,OAAO,OAAO,EAAE;GACtB,OAAO,SAAS,QAAQ,aAAa,OAAO,EAAE,UAAU,gBAAgB,KAAK,SAAS,EAAE,EAAE,IAAI;EAChG;EACA,MAAM,MAAM,KAAK;GACf,IAAI,IAAI,UAAU;GAClB,MAAM,UAAU,KAAK,QAAQ;GAC7B,MAAM,EAAE,UAAU,KAAK,MAAM;GAE7B,IAAI,MAAM,OAAO,KAAK,MAAM,OAAO,GAAG;GAOtC,MAAM,OAAO,OAAO,IAAI,OAAO;GAC/B,IAAI,SAAS,MAAM,OAAO;GAC1B,IAAI,aAAa,MAAM,OAAO;GAC9B,OAAO,YAAY,SAAS,MAAM,QAAQ,eAAe,GAAG,KAAK;EACnE;CACF;AACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getScratch, scratchKey, setScratch } from "@weasel-js/routing";
|
|
2
|
+
import { AUTO_ORIGIN_PROJECTION } from "@weasel-js/core/engine";
|
|
3
|
+
import * as ops from "@weasel-js/core/ops";
|
|
4
|
+
|
|
5
|
+
// src/actions/move/behaviors/snapBackOrDelete.ts
|
|
6
|
+
var SNAPSHOTS = scratchKey("snapBackOrDelete.snapshots");
|
|
7
|
+
var INDEXES = scratchKey("snapBackOrDelete.indexes");
|
|
8
|
+
/** Snap back to the origin pose, or delete, depending on where the drag is
|
|
9
|
+
* released. */
|
|
10
|
+
function snapBackOrDelete(args) {
|
|
11
|
+
const { radius, onFreeRelease, deleteLabel = "Delete" } = args;
|
|
12
|
+
const proj = args.origin ?? AUTO_ORIGIN_PROJECTION;
|
|
13
|
+
const r2 = radius * radius;
|
|
14
|
+
return {
|
|
15
|
+
clone: { onEnd: (ctx) => ctx.snap ? void 0 : null },
|
|
16
|
+
onStart(ctx) {
|
|
17
|
+
const snapshots = /* @__PURE__ */ new Map();
|
|
18
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
19
|
+
const nodes = ctx.adapter.getNodes();
|
|
20
|
+
for (const id of ctx.draggedIds) {
|
|
21
|
+
const obj = ctx.adapter.getNode(id) ?? { id };
|
|
22
|
+
snapshots.set(id, obj);
|
|
23
|
+
indexes.set(id, nodes.findIndex((n) => n.id === id));
|
|
24
|
+
}
|
|
25
|
+
setScratch(ctx.scratch, SNAPSHOTS, snapshots);
|
|
26
|
+
setScratch(ctx.scratch, INDEXES, indexes);
|
|
27
|
+
},
|
|
28
|
+
onEnd(ctx) {
|
|
29
|
+
if (ctx.snap) return;
|
|
30
|
+
const id = ctx.draggedIds[0];
|
|
31
|
+
const o0 = proj.getOrigin(ctx.origin.get(id));
|
|
32
|
+
const o1 = proj.getOrigin(ctx.current.get(id));
|
|
33
|
+
const dx = o1.x - o0.x;
|
|
34
|
+
const dy = o1.y - o0.y;
|
|
35
|
+
if (dx * dx + dy * dy <= r2) return null;
|
|
36
|
+
if (onFreeRelease === "delete") {
|
|
37
|
+
const snapshots = getScratch(ctx.scratch, SNAPSHOTS);
|
|
38
|
+
const indexes = getScratch(ctx.scratch, INDEXES);
|
|
39
|
+
const indexOf = (dragged) => indexes?.get(dragged) ?? -1;
|
|
40
|
+
return [...ctx.draggedIds].sort((p, q) => indexOf(q) - indexOf(p)).map((dragged) => ops.delete({
|
|
41
|
+
node: snapshots?.get(dragged) ?? { id: dragged },
|
|
42
|
+
label: deleteLabel,
|
|
43
|
+
index: indexOf(dragged)
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { snapBackOrDelete };
|
|
52
|
+
//# sourceMappingURL=snapBackOrDelete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapBackOrDelete.js","names":[],"sources":["../../../../src/actions/move/behaviors/snapBackOrDelete.ts"],"sourcesContent":["import type { Op } from '@weasel-js/core';\nimport type { MoveBehavior } from '@weasel-js/core/engine';\nimport {\n AUTO_ORIGIN_PROJECTION,\n type OriginProjection,\n} from '@weasel-js/core/engine';\nimport { scratchKey, getScratch, setScratch } from '@weasel-js/routing';\nimport * as ops from '@weasel-js/core/ops';\n\nconst SNAPSHOTS = scratchKey<Map<string, { id: string }>>('snapBackOrDelete.snapshots');\nconst INDEXES = scratchKey<Map<string, number>>('snapBackOrDelete.indexes');\n\n/**\n * Move behavior for a drag that is only meaningful near where it started:\n * release inside `radius` and every dragged node returns to its original\n * pose; release outside it and they all either spring back anyway or are\n * deleted, per `onFreeRelease`. The distance is the first dragged node's. A\n * deletion is recorded as undoable ops with paint order preserved. An Alt-drag\n * clone released anywhere but a snap target makes no copy.\n */\nexport function snapBackOrDelete<TPose extends { x: number; y: number }>(args: {\n radius: number;\n onFreeRelease: 'snap-back' | 'delete';\n deleteLabel?: string;\n}): MoveBehavior<TPose>;\n/** As above, for a `TPose` that is not a rect: `origin` tells the behavior how\n * to read and write the pose's origin. */\nexport function snapBackOrDelete<TPose>(args: {\n radius: number;\n onFreeRelease: 'snap-back' | 'delete';\n deleteLabel?: string;\n origin: OriginProjection<TPose>;\n}): MoveBehavior<TPose>;\n/** Snap back to the origin pose, or delete, depending on where the drag is\n * released. */\nexport function snapBackOrDelete<TPose>(args: {\n radius: number;\n onFreeRelease: 'snap-back' | 'delete';\n deleteLabel?: string;\n origin?: OriginProjection<TPose>;\n}): MoveBehavior<TPose> {\n const { radius, onFreeRelease, deleteLabel = 'Delete' } = args;\n const proj: OriginProjection<TPose> =\n args.origin ?? (AUTO_ORIGIN_PROJECTION as unknown as OriginProjection<TPose>);\n const r2 = radius * radius;\n\n return {\n clone: { onEnd: (ctx) => (ctx.snap ? undefined : null) },\n onStart(ctx) {\n // Snapshot the dragged objects + their z-indexes at gesture start so\n // delete can undo with paint order intact.\n const snapshots = new Map<string, { id: string }>();\n const indexes = new Map<string, number>();\n const nodes = ctx.adapter.getNodes();\n for (const id of ctx.draggedIds) {\n const obj = ctx.adapter.getNode(id) ?? { id };\n snapshots.set(id, obj);\n indexes.set(id, nodes.findIndex((n) => n.id === id));\n }\n setScratch(ctx.scratch, SNAPSHOTS, snapshots);\n setScratch(ctx.scratch, INDEXES, indexes);\n },\n\n onEnd(ctx) {\n if (ctx.snap) return;\n const id = ctx.draggedIds[0];\n const o0 = proj.getOrigin(ctx.origin.get(id)!);\n const o1 = proj.getOrigin(ctx.current.get(id)!);\n const dx = o1.x - o0.x;\n const dy = o1.y - o0.y;\n const within = dx * dx + dy * dy <= r2;\n if (within) {\n return null;\n }\n if (onFreeRelease === 'delete') {\n const snapshots = getScratch(ctx.scratch, SNAPSHOTS);\n const indexes = getScratch(ctx.scratch, INDEXES);\n const indexOf = (dragged: string): number => indexes?.get(dragged) ?? -1;\n // Topmost first, so an undo, which replays in reverse, restores each index in turn.\n return [...ctx.draggedIds]\n .sort((p, q) => indexOf(q) - indexOf(p))\n .map((dragged): Op => ops.delete({\n node: snapshots?.get(dragged) ?? { id: dragged },\n label: deleteLabel,\n index: indexOf(dragged),\n }));\n }\n // `'snap-back'` — abort, same as a release inside the radius. Returning\n // `undefined` would defer to the default translate and leave the node\n // where it was dropped, which is the one thing this policy rules out.\n return null;\n },\n };\n}\n"],"mappings":";;;;;AASA,IAAM,YAAY,WAAwC,4BAA4B;AACtF,IAAM,UAAU,WAAgC,0BAA0B;;;AAyB1E,SAAgB,iBAAwB,MAKhB;CACtB,MAAM,EAAE,QAAQ,eAAe,cAAc,aAAa;CAC1D,MAAM,OACJ,KAAK,UAAW;CAClB,MAAM,KAAK,SAAS;CAEpB,OAAO;EACL,OAAO,EAAE,QAAQ,QAAS,IAAI,OAAO,SAAY,KAAM;EACvD,QAAQ,KAAK;GAGX,MAAM,4BAAY,IAAI,IAA4B;GAClD,MAAM,0BAAU,IAAI,IAAoB;GACxC,MAAM,QAAQ,IAAI,QAAQ,SAAS;GACnC,KAAK,MAAM,MAAM,IAAI,YAAY;IAC/B,MAAM,MAAM,IAAI,QAAQ,QAAQ,EAAE,KAAK,EAAE,GAAG;IAC5C,UAAU,IAAI,IAAI,GAAG;IACrB,QAAQ,IAAI,IAAI,MAAM,WAAW,MAAM,EAAE,OAAO,EAAE,CAAC;GACrD;GACA,WAAW,IAAI,SAAS,WAAW,SAAS;GAC5C,WAAW,IAAI,SAAS,SAAS,OAAO;EAC1C;EAEA,MAAM,KAAK;GACT,IAAI,IAAI,MAAM;GACd,MAAM,KAAK,IAAI,WAAW;GAC1B,MAAM,KAAK,KAAK,UAAU,IAAI,OAAO,IAAI,EAAE,CAAE;GAC7C,MAAM,KAAK,KAAK,UAAU,IAAI,QAAQ,IAAI,EAAE,CAAE;GAC9C,MAAM,KAAK,GAAG,IAAI,GAAG;GACrB,MAAM,KAAK,GAAG,IAAI,GAAG;GAErB,IADe,KAAK,KAAK,KAAK,MAAM,IAElC,OAAO;GAET,IAAI,kBAAkB,UAAU;IAC9B,MAAM,YAAY,WAAW,IAAI,SAAS,SAAS;IACnD,MAAM,UAAU,WAAW,IAAI,SAAS,OAAO;IAC/C,MAAM,WAAW,YAA4B,SAAS,IAAI,OAAO,KAAK;IAEtE,OAAO,CAAC,GAAG,IAAI,UAAU,CAAC,CACvB,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CACvC,KAAK,YAAgB,IAAI,OAAO;KAC/B,MAAM,WAAW,IAAI,OAAO,KAAK,EAAE,IAAI,QAAQ;KAC/C,OAAO;KACP,OAAO,QAAQ,OAAO;IACxB,CAAC,CAAC;GACN;GAIA,OAAO;EACT;CACF;AACF"}
|