@weasel-js/editing 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +60 -2
- package/dist/actionGroups.js +27 -0
- package/dist/actionGroups.js.map +1 -0
- package/dist/actions/align/action.js +105 -0
- package/dist/actions/align/action.js.map +1 -0
- package/dist/actions/align/align.js +115 -0
- package/dist/actions/align/align.js.map +1 -0
- package/dist/actions/clipboard/action.js +133 -0
- package/dist/actions/clipboard/action.js.map +1 -0
- 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 +96 -0
- package/dist/actions/distribute/action.js.map +1 -0
- package/dist/actions/distribute/distribute.js +61 -0
- package/dist/actions/distribute/distribute.js.map +1 -0
- package/dist/actions/distribute/plan.js +55 -0
- package/dist/actions/distribute/plan.js.map +1 -0
- package/dist/actions/edit/createPaintAction.js +138 -0
- package/dist/actions/edit/createPaintAction.js.map +1 -0
- package/dist/actions/edit/deselect.js +34 -0
- package/dist/actions/edit/deselect.js.map +1 -0
- package/dist/actions/edit/duplicate.js +93 -0
- package/dist/actions/edit/duplicate.js.map +1 -0
- package/dist/actions/edit/group.js +281 -0
- package/dist/actions/edit/group.js.map +1 -0
- package/dist/actions/edit/ingest.js +114 -0
- package/dist/actions/edit/ingest.js.map +1 -0
- package/dist/actions/edit/nudge.js +97 -0
- package/dist/actions/edit/nudge.js.map +1 -0
- package/dist/actions/edit/selectAll.js +48 -0
- package/dist/actions/edit/selectAll.js.map +1 -0
- package/dist/actions/edit/setFill.js +52 -0
- package/dist/actions/edit/setFill.js.map +1 -0
- package/dist/actions/edit/setFillOpacity.js +26 -0
- package/dist/actions/edit/setFillOpacity.js.map +1 -0
- package/dist/actions/edit/setStroke.js +57 -0
- package/dist/actions/edit/setStroke.js.map +1 -0
- package/dist/actions/edit/setStrokeOpacity.js +28 -0
- package/dist/actions/edit/setStrokeOpacity.js.map +1 -0
- package/dist/actions/edit/setStrokeWidth.js +53 -0
- package/dist/actions/edit/setStrokeWidth.js.map +1 -0
- package/dist/actions/edit/setVertexColor.js +45 -0
- package/dist/actions/edit/setVertexColor.js.map +1 -0
- package/dist/actions/flip/action.js +209 -0
- package/dist/actions/flip/action.js.map +1 -0
- package/dist/actions/flip/helpers.js +80 -0
- package/dist/actions/flip/helpers.js.map +1 -0
- 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 +109 -0
- package/dist/actions/pathfinder/action.js.map +1 -0
- package/dist/actions/pathfinder/booleanGroupAction.js +117 -0
- package/dist/actions/pathfinder/booleanGroupAction.js.map +1 -0
- package/dist/actions/pathfinder/keymap.js +51 -0
- package/dist/actions/pathfinder/keymap.js.map +1 -0
- package/dist/actions/reorder/reorder.js +245 -0
- package/dist/actions/reorder/reorder.js.map +1 -0
- 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 +90 -0
- package/dist/actions/transformAgain/action.js.map +1 -0
- package/dist/actions/transformAgain/transformSelection.js +49 -0
- package/dist/actions/transformAgain/transformSelection.js.map +1 -0
- 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 +54 -0
- package/dist/engineStandardActions.js.map +1 -0
- 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 +1867 -0
- package/dist/index.js +86 -0
- 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 +83 -0
- package/dist/namedPresets.js.map +1 -0
- package/dist/presets/arrange.js +65 -0
- package/dist/presets/arrange.js.map +1 -0
- package/dist/presets/booleans.js +13 -0
- package/dist/presets/booleans.js.map +1 -0
- package/dist/presets/composites.js +46 -0
- package/dist/presets/composites.js.map +1 -0
- package/dist/presets/edit.js +125 -0
- package/dist/presets/edit.js.map +1 -0
- package/dist/presets/ingest.js +17 -0
- package/dist/presets/ingest.js.map +1 -0
- package/dist/presets/insert.js +28 -0
- package/dist/presets/insert.js.map +1 -0
- package/dist/presets/pathfinder.js +26 -0
- package/dist/presets/pathfinder.js.map +1 -0
- package/dist/presets/select.js +31 -0
- package/dist/presets/select.js.map +1 -0
- 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 +84 -0
- package/dist/presets/tools.js.map +1 -0
- package/dist/presets/transform.js +52 -0
- package/dist/presets/transform.js.map +1 -0
- 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/dist/useStandardActions.js +26 -0
- package/dist/useStandardActions.js.map +1 -0
- package/package.json +87 -4
|
@@ -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"}
|
|
@@ -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?: string | null }).parent === at && !keep(child.id)) return false;\n }\n return true;\n };\n return keep(id) ? ops : null;\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAI,QAAQ;AAEZ,SAAS,SAAgB,KAA4B,KAAiC;CACpF,IAAI,IAAI,WAAW,IAAI,SAAS,GAAG;CACnC,IAAI,CAAC,GAAG;EACN,IAAI;GAAE,iBAAiB;GAAM,eAAe;GAAM,eAAe;EAAK;EACtE,WAAW,IAAI,SAAS,KAAK,CAAuB;CACtD;CACA,OAAO;AACT;;AAGA,SAAS,QAAe,KAA+C;CACrE,OAAO,UAAU,IAAI,aAAa,OAAO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