@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,162 @@
|
|
|
1
|
+
import { draggedWorldPose, grabbedPoseAdapter } from "../delta.js";
|
|
2
|
+
import { rootTranslateOps, translateOps } from "../translate.js";
|
|
3
|
+
import { landAbove, landOps, landedCascadeOps, landedLocalPose, resolveDrop } from "./reparent.js";
|
|
4
|
+
import { followerMove, followerMoveOps, isFollower, keepOnPage, pasteboardOn, placedPage, rehomedFollowers } from "@weasel-js/core";
|
|
5
|
+
import { pageAt, pageIdOf, pageNodeOf, pageOfBounds, placedPagesOf, refusalOf, sceneViewPoseAdapter } from "@weasel-js/core/engine";
|
|
6
|
+
import * as coreOps from "@weasel-js/core/ops";
|
|
7
|
+
|
|
8
|
+
// src/actions/move/commit/pageDrop.ts
|
|
9
|
+
var STAY = { shift: {
|
|
10
|
+
dx: 0,
|
|
11
|
+
dy: 0
|
|
12
|
+
} };
|
|
13
|
+
/** The node a release over `under` drops into on that page when the binding reparents on drop: a group on
|
|
14
|
+
* it under the pointer (`resolveDrop`), on the layer that drop gives, else `under` itself; and, when the
|
|
15
|
+
* binding lands above the node hit, that node. `'refused'` when that drop is refused. */
|
|
16
|
+
function containerOn(session, under, at) {
|
|
17
|
+
const page = pageNodeOf(session.scene, under.id);
|
|
18
|
+
const mode = session.reparentOnDrop();
|
|
19
|
+
if (mode === "off") return {
|
|
20
|
+
into: page,
|
|
21
|
+
above: null
|
|
22
|
+
};
|
|
23
|
+
const drop = resolveDrop(session, at);
|
|
24
|
+
if (drop !== null && "refused" in drop) return "refused";
|
|
25
|
+
const inner = drop?.newParent ?? null;
|
|
26
|
+
const above = mode === "above" ? drop?.hitSibling ?? null : null;
|
|
27
|
+
return inner !== null && pageIdOf(session.scene, inner) === under.id ? {
|
|
28
|
+
into: inner,
|
|
29
|
+
above,
|
|
30
|
+
layer: drop.newLayer
|
|
31
|
+
} : {
|
|
32
|
+
into: page,
|
|
33
|
+
above: null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Where a release at `at` puts each dragged root that is a page's child or,
|
|
38
|
+
* with the pasteboard on, a root of the scene. Each root goes by where its own
|
|
39
|
+
* dragged box lands: on the page under the pointer when it overlaps that page
|
|
40
|
+
* (into a group there under the pointer, when the binding reparents on drop),
|
|
41
|
+
* else on the page it overlaps most. Off every page it goes to the top of the
|
|
42
|
+
* tree with the pasteboard on, and otherwise stays in its page. With the
|
|
43
|
+
* pasteboard off, each root ending on a page is shifted so part of it is on
|
|
44
|
+
* it. A page that refuses the roots silently is not landed on; a refusal with
|
|
45
|
+
* a reason refuses the move (`'refused'`). `null` when no root is either kind,
|
|
46
|
+
* or none changes parent or shifts.
|
|
47
|
+
*/
|
|
48
|
+
function pageDrops(session, at, delta) {
|
|
49
|
+
const { scene } = session;
|
|
50
|
+
const pasteboard = pasteboardOn(scene);
|
|
51
|
+
const isPage = (id) => id !== null && scene.get(id)?.page !== void 0;
|
|
52
|
+
const ours = session.ids.filter((id) => {
|
|
53
|
+
const node = scene.get(id);
|
|
54
|
+
if (!session.startPoses.has(id) || node === void 0) return false;
|
|
55
|
+
return !isFollower(node) && (isPage(node.parent) || pasteboard && node.parent === null);
|
|
56
|
+
});
|
|
57
|
+
if (ours.length === 0) return null;
|
|
58
|
+
const placed = placedPagesOf(scene);
|
|
59
|
+
let under = pageAt(placed, at);
|
|
60
|
+
if (under !== null) {
|
|
61
|
+
const verdict = session.verdict(pageNodeOf(scene, under.id));
|
|
62
|
+
if (refusalOf(verdict) !== null) return "refused";
|
|
63
|
+
if (verdict !== true) under = null;
|
|
64
|
+
}
|
|
65
|
+
const site = under === null ? null : containerOn(session, under, at);
|
|
66
|
+
if (site === "refused") return "refused";
|
|
67
|
+
const adapter = grabbedPoseAdapter(session, sceneViewPoseAdapter(scene));
|
|
68
|
+
const drops = /* @__PURE__ */ new Map();
|
|
69
|
+
for (const id of ours) {
|
|
70
|
+
const parent = scene.get(id).parent;
|
|
71
|
+
const from = parent === null ? null : pageIdOf(scene, parent);
|
|
72
|
+
const bounds = session.descriptorOf(id).getBounds(draggedWorldPose(session, adapter, id, delta));
|
|
73
|
+
const takers = placed.filter((p) => p.id === from || session.verdict(pageNodeOf(scene, p.id)) === true);
|
|
74
|
+
const page = under !== null && pageOfBounds([under], bounds) !== null ? under : pageOfBounds(takers, bounds);
|
|
75
|
+
let target = page === null ? null : page === under ? site.into : pageNodeOf(scene, page.id);
|
|
76
|
+
let landing = page;
|
|
77
|
+
if (page === null && !pasteboard) {
|
|
78
|
+
target = parent;
|
|
79
|
+
landing = placedPage(scene, from);
|
|
80
|
+
}
|
|
81
|
+
const shift = landing !== null && !pasteboard ? keepOnPage(landing, bounds) : STAY.shift;
|
|
82
|
+
const landsInSite = page !== null && page === under;
|
|
83
|
+
const above = landsInSite ? site.above : null;
|
|
84
|
+
const layer = landsInSite ? site.layer : void 0;
|
|
85
|
+
if (target !== parent) drops.set(id, {
|
|
86
|
+
into: target,
|
|
87
|
+
shift,
|
|
88
|
+
above,
|
|
89
|
+
...layer === void 0 ? {} : { layer }
|
|
90
|
+
});
|
|
91
|
+
else if (shift.dx !== 0 || shift.dy !== 0) drops.set(id, { shift });
|
|
92
|
+
}
|
|
93
|
+
const landed = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const [id, { into }] of drops) if (into !== void 0) landed.set(id, into === null ? null : pageIdOf(scene, into));
|
|
95
|
+
for (const [id, into] of rehomedFollowers(scene, landed)) drops.set(id, {
|
|
96
|
+
into,
|
|
97
|
+
shift: STAY.shift
|
|
98
|
+
});
|
|
99
|
+
return drops.size === 0 ? null : drops;
|
|
100
|
+
}
|
|
101
|
+
/** Each dragged node below one of `roots`, selected or not, keyed by that root. */
|
|
102
|
+
function belowRoots(session, roots) {
|
|
103
|
+
const out = /* @__PURE__ */ new Map();
|
|
104
|
+
for (const id of /* @__PURE__ */ new Set([...session.ids, ...session.cascadeIds])) {
|
|
105
|
+
let cur = session.scene.get(id)?.parent ?? null;
|
|
106
|
+
while (cur !== null && !roots.has(cur)) cur = session.scene.get(cur)?.parent ?? null;
|
|
107
|
+
if (cur !== null) out.set(cur, [...out.get(cur) ?? [], id]);
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
/** The commit for `drops`: each dragged root translated by the drag plus its shift, and moved into its new
|
|
112
|
+
* container at the world place that gives, its descendants with it. `null` when one would land in a
|
|
113
|
+
* singular frame, so the drop refuses whole. */
|
|
114
|
+
function pageDropOps(session, drops, delta) {
|
|
115
|
+
const { scene } = session;
|
|
116
|
+
const label = session.lifecycle.label;
|
|
117
|
+
const ops = [];
|
|
118
|
+
const dragged = new Set(session.ids);
|
|
119
|
+
const children = /* @__PURE__ */ new Map();
|
|
120
|
+
const childrenOf = (parent) => {
|
|
121
|
+
if (!children.has(parent)) children.set(parent, [...parent === null ? scene.roots : scene.childrenOf(parent)]);
|
|
122
|
+
return children.get(parent);
|
|
123
|
+
};
|
|
124
|
+
for (const [id, drop] of drops) {
|
|
125
|
+
if (dragged.has(id) || drop.into === void 0) continue;
|
|
126
|
+
const move = followerMove(scene, id, drop.into);
|
|
127
|
+
if (move === null) return null;
|
|
128
|
+
ops.push(...followerMoveOps([move], label));
|
|
129
|
+
}
|
|
130
|
+
const below = belowRoots(session, new Set([...drops.keys()].filter((id) => dragged.has(id))));
|
|
131
|
+
const ridden = new Set([...below.values()].flat());
|
|
132
|
+
for (const id of session.outer) {
|
|
133
|
+
if (ridden.has(id)) continue;
|
|
134
|
+
const drop = drops.get(id) ?? STAY;
|
|
135
|
+
const d = {
|
|
136
|
+
dx: delta.dx + drop.shift.dx,
|
|
137
|
+
dy: delta.dy + drop.shift.dy
|
|
138
|
+
};
|
|
139
|
+
if (drop.into === void 0) {
|
|
140
|
+
ops.push(...drops.has(id) ? translateOps(session, [id, ...below.get(id) ?? []], d) : rootTranslateOps(session, [id], d));
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const node = scene.get(id);
|
|
144
|
+
const layer = drop.layer ?? node.layer;
|
|
145
|
+
const toIndex = landAbove(childrenOf(drop.into), id, drop.above ?? null);
|
|
146
|
+
const to = landedLocalPose(session, id, drop.into, layer, d);
|
|
147
|
+
const cascade = landedCascadeOps(session, below.get(id) ?? [], drop.into, d, layer);
|
|
148
|
+
if (to === null || cascade === null) return null;
|
|
149
|
+
ops.push(...landOps(session, id, drop.into, toIndex, layer));
|
|
150
|
+
ops.push(coreOps.setPose({
|
|
151
|
+
id,
|
|
152
|
+
from: node.pose,
|
|
153
|
+
to,
|
|
154
|
+
label
|
|
155
|
+
}));
|
|
156
|
+
ops.push(...cascade);
|
|
157
|
+
}
|
|
158
|
+
return ops;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { belowRoots, pageDropOps, pageDrops };
|
|
162
|
+
//# sourceMappingURL=pageDrop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageDrop.js","names":[],"sources":["../../../../src/actions/move/commit/pageDrop.ts"],"sourcesContent":["import { pageAt, pageOfBounds, type PlacedPage, pageNodeOf, pageIdOf, placedPagesOf, refusalOf, sceneViewPoseAdapter } from '@weasel-js/core/engine';\nimport type { Op, NodeId } from '@weasel-js/core';\nimport { isFollower, keepOnPage, pasteboardOn, placedPage, rehomedFollowers, followerMove, followerMoveOps } from '@weasel-js/core';\nimport { draggedWorldPose, grabbedPoseAdapter } from '../delta';\nimport type { MoveSession } from '../session';\nimport { rootTranslateOps, translateOps } from '../translate';\nimport { landAbove, landedCascadeOps, landedLocalPose, landOps, resolveDrop } from './reparent';\nimport * as coreOps from '@weasel-js/core/ops';\n\n/** What a release does with one dragged root: add `shift` to the drag and, when `into` is given, move it into\n * that container (a page, a group on one, or `null` for the top of the tree), just above `above` and onto\n * `layer` when given. */\ninterface RootDrop {\n readonly into?: NodeId | null;\n readonly above?: NodeId | null;\n readonly layer?: string;\n readonly shift: { readonly dx: number; readonly dy: number };\n}\n\nconst STAY: RootDrop = { shift: { dx: 0, dy: 0 } };\n\n/** The node a release over `under` drops into on that page when the binding reparents on drop: a group on\n * it under the pointer (`resolveDrop`), on the layer that drop gives, else `under` itself; and, when the\n * binding lands above the node hit, that node. `'refused'` when that drop is refused. */\nfunction containerOn(\n session: MoveSession,\n under: PlacedPage,\n at: { x: number; y: number },\n): { into: NodeId; above: NodeId | null; layer?: string } | 'refused' {\n const page = pageNodeOf(session.scene, under.id)!;\n const mode = session.reparentOnDrop();\n if (mode === 'off') return { into: page, above: null };\n const drop = resolveDrop(session, at);\n if (drop !== null && 'refused' in drop) return 'refused';\n const inner = drop?.newParent ?? null;\n const above = mode === 'above' ? drop?.hitSibling ?? null : null;\n return inner !== null && pageIdOf(session.scene, inner) === under.id\n ? { into: inner, above, layer: drop!.newLayer }\n : { into: page, above: null };\n}\n\n/**\n * Where a release at `at` puts each dragged root that is a page's child or,\n * with the pasteboard on, a root of the scene. Each root goes by where its own\n * dragged box lands: on the page under the pointer when it overlaps that page\n * (into a group there under the pointer, when the binding reparents on drop),\n * else on the page it overlaps most. Off every page it goes to the top of the\n * tree with the pasteboard on, and otherwise stays in its page. With the\n * pasteboard off, each root ending on a page is shifted so part of it is on\n * it. A page that refuses the roots silently is not landed on; a refusal with\n * a reason refuses the move (`'refused'`). `null` when no root is either kind,\n * or none changes parent or shifts.\n */\nexport function pageDrops(\n session: MoveSession,\n at: { x: number; y: number },\n delta: { dx: number; dy: number },\n): Map<NodeId, RootDrop> | 'refused' | null {\n const { scene } = session;\n const pasteboard = pasteboardOn(scene);\n const isPage = (id: NodeId | null) => id !== null && scene.get(id)?.page !== undefined;\n const ours = session.ids.filter((id) => {\n const node = scene.get(id);\n if (!session.startPoses.has(id) || node === undefined) return false;\n return !isFollower(node) && (isPage(node.parent) || (pasteboard && node.parent === null));\n });\n if (ours.length === 0) return null;\n\n const placed = placedPagesOf(scene);\n let under = pageAt(placed, at);\n if (under !== null) {\n const verdict = session.verdict(pageNodeOf(scene, under.id)!);\n if (refusalOf(verdict) !== null) return 'refused';\n if (verdict !== true) under = null;\n }\n const site = under === null ? null : containerOn(session, under, at);\n if (site === 'refused') return 'refused';\n\n const adapter = grabbedPoseAdapter(session, sceneViewPoseAdapter(scene));\n const drops = new Map<NodeId, RootDrop>();\n for (const id of ours) {\n const parent = scene.get(id)!.parent;\n const from = parent === null ? null : pageIdOf(scene, parent);\n const bounds = session.descriptorOf(id).getBounds(draggedWorldPose(session, adapter, id, delta));\n const takers = placed.filter((p) => p.id === from || session.verdict(pageNodeOf(scene, p.id)!) === true);\n const page = under !== null && pageOfBounds([under], bounds) !== null ? under : pageOfBounds(takers, bounds);\n let target: NodeId | null = page === null ? null : page === under ? site!.into : pageNodeOf(scene, page.id);\n let landing = page;\n if (page === null && !pasteboard) {\n target = parent;\n landing = placedPage(scene, from!);\n }\n const shift = landing !== null && !pasteboard ? keepOnPage(landing, bounds) : STAY.shift;\n const landsInSite = page !== null && page === under;\n const above = landsInSite ? site!.above : null;\n const layer = landsInSite ? site!.layer : undefined;\n if (target !== parent) drops.set(id, { into: target, shift, above, ...(layer === undefined ? {} : { layer }) });\n else if (shift.dx !== 0 || shift.dy !== 0) drops.set(id, { shift });\n }\n const landed = new Map<string, string | null>();\n for (const [id, { into }] of drops) {\n if (into !== undefined) landed.set(id, into === null ? null : pageIdOf(scene, into));\n }\n for (const [id, into] of rehomedFollowers(scene, landed)) drops.set(id, { into, shift: STAY.shift });\n return drops.size === 0 ? null : drops;\n}\n\n/** Each dragged node below one of `roots`, selected or not, keyed by that root. */\nexport function belowRoots(session: MoveSession, roots: ReadonlySet<NodeId>): Map<NodeId, NodeId[]> {\n const out = new Map<NodeId, NodeId[]>();\n for (const id of new Set([...session.ids, ...session.cascadeIds])) {\n let cur = session.scene.get(id)?.parent ?? null;\n while (cur !== null && !roots.has(cur)) cur = session.scene.get(cur)?.parent ?? null;\n if (cur !== null) out.set(cur, [...(out.get(cur) ?? []), id]);\n }\n return out;\n}\n\n/** The commit for `drops`: each dragged root translated by the drag plus its shift, and moved into its new\n * container at the world place that gives, its descendants with it. `null` when one would land in a\n * singular frame, so the drop refuses whole. */\nexport function pageDropOps(\n session: MoveSession,\n drops: ReadonlyMap<NodeId, RootDrop>,\n delta: { dx: number; dy: number },\n): Op[] | null {\n const { scene } = session;\n const label = session.lifecycle.label;\n const ops: Op[] = [];\n const dragged = new Set(session.ids);\n const children = new Map<NodeId | null, NodeId[]>();\n const childrenOf = (parent: NodeId | null) => {\n if (!children.has(parent)) children.set(parent, [...(parent === null ? scene.roots : scene.childrenOf(parent))]);\n return children.get(parent)!;\n };\n for (const [id, drop] of drops) {\n if (dragged.has(id) || drop.into === undefined) continue;\n const move = followerMove(scene, id, drop.into);\n if (move === null) return null;\n ops.push(...followerMoveOps([move], label));\n }\n const below = belowRoots(session, new Set([...drops.keys()].filter((id) => dragged.has(id))));\n const ridden = new Set([...below.values()].flat());\n for (const id of session.outer) {\n if (ridden.has(id)) continue;\n const drop = drops.get(id) ?? STAY;\n const d = { dx: delta.dx + drop.shift.dx, dy: delta.dy + drop.shift.dy };\n if (drop.into === undefined) {\n ops.push(...(drops.has(id) ? translateOps(session, [id, ...below.get(id) ?? []], d) : rootTranslateOps(session, [id], d)));\n continue;\n }\n const node = scene.get(id)!;\n const layer = drop.layer ?? node.layer;\n const toIndex = landAbove(childrenOf(drop.into), id, drop.above ?? null);\n const to = landedLocalPose(session, id, drop.into, layer, d);\n const cascade = landedCascadeOps(session, below.get(id) ?? [], drop.into, d, layer);\n if (to === null || cascade === null) return null;\n ops.push(...landOps(session, id, drop.into, toIndex, layer));\n ops.push(coreOps.setPose<unknown>({ id: id as string, from: node.pose, to, label }));\n ops.push(...cascade);\n }\n return ops;\n}\n"],"mappings":";;;;;;;;AAmBA,IAAM,OAAiB,EAAE,OAAO;CAAE,IAAI;CAAG,IAAI;AAAE,EAAE;;;;AAKjD,SAAS,YACP,SACA,OACA,IACoE;CACpE,MAAM,OAAO,WAAW,QAAQ,OAAO,MAAM,EAAE;CAC/C,MAAM,OAAO,QAAQ,eAAe;CACpC,IAAI,SAAS,OAAO,OAAO;EAAE,MAAM;EAAM,OAAO;CAAK;CACrD,MAAM,OAAO,YAAY,SAAS,EAAE;CACpC,IAAI,SAAS,QAAQ,aAAa,MAAM,OAAO;CAC/C,MAAM,QAAQ,MAAM,aAAa;CACjC,MAAM,QAAQ,SAAS,UAAU,MAAM,cAAc,OAAO;CAC5D,OAAO,UAA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M,MAAM,QAAQ,OAAO;EAC9B,IAAI,OAAO,IAAI,EAAE,GAAG;EACpB,MAAM,OAAO,MAAM,IAAI,EAAE,KAAK;EAC9B,MAAM,IAAI;GAAE,IAAI,MAAM,KAAK,KAAK,MAAM;GAAI,IAAI,MAAM,KAAK,KAAK,MAAM;EAAG;EACvE,IAAI,KAAK,SAAS,QAAW;GAC3B,IAAI,KAAK,GAAI,MAAM,IAAI,EAAE,IAAI,aAAa,SAAS,CAAC,IAAI,GAAG,MAAM,IAAI,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,iBAAiB,SAAS,CAAC,EAAE,GAAG,CAAC,CAAE;GACzH;EACF;EACA,MAAM,OAAO,MAAM,IAAI,EAAE;EACzB,MAAM,QAAQ,KAAK,SAAS,KAAK;EACjC,MAAM,UAAU,UAAU,WAAW,KAAK,IAAI,GAAG,IAAI,KAAK,SAAS,IAAI;EACvE,MAAM,KAAK,gBAAgB,SAAS,IAAI,KAAK,MAAM,OAAO,CAAC;EAC3D,MAAM,UAAU,iBAAiB,SAAS,MAAM,IAAI,EAAE,KAAK,CAAC,GAAG,KAAK,MAAM,GAAG,KAAK;EAClF,IAAI,OAAO,QAAQ,YAAY,MAAM,OAAO;EAC5C,IAAI,KAAK,GAAG,QAAQ,SAAS,IAAI,KAAK,MAAM,SAAS,KAAK,CAAC;EAC3D,IAAI,KAAK,QAAQ,QAAiB;GAAM;GAAc,MAAM,KAAK;GAAM;GAAI;EAAM,CAAC,CAAC;EACnF,IAAI,KAAK,GAAG,OAAO;CACrB;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { rebaseLocalPose } from "@weasel-js/core/engine";
|
|
2
|
+
import * as ops from "@weasel-js/core/ops";
|
|
3
|
+
|
|
4
|
+
// src/actions/move/commit/rebase.ts
|
|
5
|
+
/** A world-posed transform op as one in its node's stored frame: `from` under
|
|
6
|
+
* `fromParent`, `to` under `toParent`. Any other op is returned as it is.
|
|
7
|
+
* `null` when either frame is singular and the op cannot keep its poses. */
|
|
8
|
+
function rebaseTransformOp(op, adapter, pc, fromParent, toParent) {
|
|
9
|
+
if (op.name !== "transform") return op;
|
|
10
|
+
const a = op.args;
|
|
11
|
+
const from = rebaseLocalPose(adapter, a.from, fromParent, pc.compose, pc.decompose);
|
|
12
|
+
const to = rebaseLocalPose(adapter, a.to, toParent, pc.compose, pc.decompose);
|
|
13
|
+
if (from === null || to === null) return null;
|
|
14
|
+
return ops.setPose({
|
|
15
|
+
id: a.id,
|
|
16
|
+
from,
|
|
17
|
+
to,
|
|
18
|
+
label: a.label,
|
|
19
|
+
coalesceKey: a.coalesceKey
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { rebaseTransformOp };
|
|
24
|
+
//# sourceMappingURL=rebase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rebase.js","names":[],"sources":["../../../../src/actions/move/commit/rebase.ts"],"sourcesContent":["import { rebaseLocalPose, type PoseAdapter, type PoseComposition } from '@weasel-js/core/engine';\nimport type { Op } from '@weasel-js/core';\nimport * as ops from '@weasel-js/core/ops';\n\n/** A world-posed transform op as one in its node's stored frame: `from` under\n * `fromParent`, `to` under `toParent`. Any other op is returned as it is.\n * `null` when either frame is singular and the op cannot keep its poses. */\nexport function rebaseTransformOp(\n op: Op,\n adapter: PoseAdapter<unknown>,\n pc: PoseComposition<unknown>,\n fromParent: string | null,\n toParent: string | null,\n): Op | null {\n if (op.name !== 'transform') return op;\n const a = op.args as { id: string; from: unknown; to: unknown; label?: string; coalesceKey?: string };\n const from = rebaseLocalPose(adapter, a.from, fromParent, pc.compose, pc.decompose);\n const to = rebaseLocalPose(adapter, a.to, toParent, pc.compose, pc.decompose);\n if (from === null || to === null) return null;\n return ops.setPose<unknown>({\n id: a.id,\n from,\n to,\n label: a.label,\n coalesceKey: a.coalesceKey,\n });\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,kBACd,IACA,SACA,IACA,YACA,UACW;CACX,IAAI,GAAG,SAAS,aAAa,OAAO;CACpC,MAAM,IAAI,GAAG;CACb,MAAM,OAAO,gBAAgB,SAAS,EAAE,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS;CAClF,MAAM,KAAK,gBAAgB,SAAS,EAAE,IAAI,UAAU,GAAG,SAAS,GAAG,SAAS;CAC5E,IAAI,SAAS,QAAQ,OAAO,MAAM,OAAO;CACzC,OAAO,IAAI,QAAiB;EAC1B,IAAI,EAAE;EACN;EACA;EACA,OAAO,EAAE;EACT,aAAa,EAAE;CACjB,CAAC;AACH"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { draggedWorldPose, grabbedPoseAdapter } from "../delta.js";
|
|
2
|
+
import { translateOps } from "../translate.js";
|
|
3
|
+
import { worldBoundsOf } from "../refusal.js";
|
|
4
|
+
import { carryPose, followerOpsFor, planeOf, translateNodeOps } from "@weasel-js/core";
|
|
5
|
+
import { isPageStructure, pageIdOf, planeToPlane, rebaseLocalPose as rebaseLocalPose$1, refusalOf, sceneViewPoseAdapter } from "@weasel-js/core/engine";
|
|
6
|
+
import * as coreOps from "@weasel-js/core/ops";
|
|
7
|
+
|
|
8
|
+
// src/actions/move/commit/reparent.ts
|
|
9
|
+
/** Walk the hit chain to find the appropriate drop target. Returns
|
|
10
|
+
* `null` when no reparent should happen (drop on empty canvas, the
|
|
11
|
+
* only hits are the moved subtree itself, or a page or the run refuses
|
|
12
|
+
* it, since the climb never passes page structure), and a refusal when the first
|
|
13
|
+
* node of the chain to answer refuses with a reason. */
|
|
14
|
+
function resolveDrop(session, at) {
|
|
15
|
+
const dep = session.nodeAtPoint;
|
|
16
|
+
if (!dep) return null;
|
|
17
|
+
const hit = dep(at, /* @__PURE__ */ new Set([...session.ids, ...session.cascadeIds]));
|
|
18
|
+
if (!hit) return null;
|
|
19
|
+
const hitNode = session.scene.get(hit);
|
|
20
|
+
if (!hitNode) return null;
|
|
21
|
+
let newParent = hit;
|
|
22
|
+
let hitSibling = null;
|
|
23
|
+
while (newParent !== null) {
|
|
24
|
+
const verdict = session.verdict(newParent);
|
|
25
|
+
if (verdict === true) break;
|
|
26
|
+
const reason = refusalOf(verdict);
|
|
27
|
+
if (reason !== null) return { refused: {
|
|
28
|
+
id: newParent,
|
|
29
|
+
bounds: worldBoundsOf(session, newParent),
|
|
30
|
+
reason
|
|
31
|
+
} };
|
|
32
|
+
if (isPageStructure(session.scene.get(newParent))) return null;
|
|
33
|
+
hitSibling = newParent;
|
|
34
|
+
newParent = session.scene.get(newParent)?.parent ?? null;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
newParent,
|
|
38
|
+
newLayer: hitNode.layer,
|
|
39
|
+
hitSibling
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Move `id` within `siblings`, a destination's children as the next op will find them, to just above
|
|
43
|
+
* `above` when it is among them, else to the end. Returns the index to reparent `id` to, or `undefined` to
|
|
44
|
+
* append. */
|
|
45
|
+
function landAbove(siblings, id, above) {
|
|
46
|
+
const was = siblings.indexOf(id);
|
|
47
|
+
if (was >= 0) siblings.splice(was, 1);
|
|
48
|
+
const hit = above === null ? -1 : siblings.indexOf(above);
|
|
49
|
+
const toIndex = hit >= 0 ? hit + 1 : void 0;
|
|
50
|
+
if (toIndex === void 0) siblings.push(id);
|
|
51
|
+
else siblings.splice(toIndex, 0, id);
|
|
52
|
+
return toIndex;
|
|
53
|
+
}
|
|
54
|
+
/** Root `id`'s pose stored under `newParent` on `newLayer`, keeping the world pose the drag `delta` shows.
|
|
55
|
+
* `null` when `newParent`'s frame is singular and no stored pose keeps it. */
|
|
56
|
+
function landedLocalPose(session, id, newParent, newLayer, delta) {
|
|
57
|
+
const { scene, pc, view } = session;
|
|
58
|
+
const adapter = sceneViewPoseAdapter(scene);
|
|
59
|
+
const layer = scene.get(id).layer;
|
|
60
|
+
const world = carryPose(session.descriptorOf(id), draggedWorldPose(session, grabbedPoseAdapter(session, adapter), id, delta), layer !== newLayer ? planeToPlane(planeOf(view, layer), planeOf(view, newLayer)) : null);
|
|
61
|
+
return rebaseLocalPose$1(adapter, world, newParent, pc.compose, pc.decompose);
|
|
62
|
+
}
|
|
63
|
+
/** The ops for `ids`, descendants of a root moved into `newParent`: each one stored in the frame it is
|
|
64
|
+
* moved into, on `newLayer` when given, at the world place the drag `delta` gives. One a moving frame
|
|
65
|
+
* carries keeps only what it caught mid-glide, as in a translate. `null` when one cannot keep its place. */
|
|
66
|
+
function landedCascadeOps(session, ids, newParent, delta, newLayer) {
|
|
67
|
+
const own = /* @__PURE__ */ new Map();
|
|
68
|
+
for (const id of ids) {
|
|
69
|
+
const start = session.startPoses.get(id);
|
|
70
|
+
if (start === void 0 || session.carried.has(id) || !session.scene.get(id)) continue;
|
|
71
|
+
const d = session.descriptorOf(id);
|
|
72
|
+
const landed = landedLocalPose(session, id, newParent, newLayer ?? session.scene.get(id).layer, delta);
|
|
73
|
+
if (landed === null) return null;
|
|
74
|
+
const from = d.getBounds(start);
|
|
75
|
+
const to = d.getBounds(landed);
|
|
76
|
+
const c = session.caught.get(id) ?? {
|
|
77
|
+
dx: 0,
|
|
78
|
+
dy: 0
|
|
79
|
+
};
|
|
80
|
+
own.set(id, {
|
|
81
|
+
dx: to.x - from.x + c.dx,
|
|
82
|
+
dy: to.y - from.y + c.dy
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return [...translateOps(session, ids.filter((id) => session.carried.has(id)), delta), ...translateNodeOps(session.scene, own.keys(), (id) => own.get(id) ?? null, session.descriptorOf, session.geometryProjection, session.lifecycle.label)];
|
|
86
|
+
}
|
|
87
|
+
/** The ops that move root `id` into `to` at `toIndex`, onto `layer` first when it is on another. */
|
|
88
|
+
function landOps(session, id, to, toIndex, layer) {
|
|
89
|
+
const node = session.scene.get(id);
|
|
90
|
+
const label = session.lifecycle.label;
|
|
91
|
+
const ops = [];
|
|
92
|
+
let from = node.parent;
|
|
93
|
+
if (node.layer !== layer) {
|
|
94
|
+
if (from !== null) {
|
|
95
|
+
ops.push(coreOps.reparent({
|
|
96
|
+
id,
|
|
97
|
+
fromParentId: from,
|
|
98
|
+
toParentId: null,
|
|
99
|
+
label,
|
|
100
|
+
coalesceKey: `reparent:${id}:orphan`
|
|
101
|
+
}));
|
|
102
|
+
from = null;
|
|
103
|
+
}
|
|
104
|
+
ops.push(coreOps.setLayer({
|
|
105
|
+
id,
|
|
106
|
+
from: node.layer,
|
|
107
|
+
to: layer,
|
|
108
|
+
label
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
ops.push(coreOps.reparent({
|
|
112
|
+
id,
|
|
113
|
+
fromParentId: from,
|
|
114
|
+
toParentId: to,
|
|
115
|
+
toIndex,
|
|
116
|
+
label
|
|
117
|
+
}));
|
|
118
|
+
return ops;
|
|
119
|
+
}
|
|
120
|
+
/** Reparent and reposition each moved root as ops, keeping the world pose the
|
|
121
|
+
* drag showed, then the ops that bring uncarried descendants along, and the
|
|
122
|
+
* followers whose page that changes (`followerMoves`). `null` when any of
|
|
123
|
+
* them would land in a singular frame, so the drop refuses whole. */
|
|
124
|
+
function reparentOps(session, target, mode, delta) {
|
|
125
|
+
const { scene } = session;
|
|
126
|
+
const label = session.lifecycle.label;
|
|
127
|
+
const ops = [];
|
|
128
|
+
const siblings = [...target.newParent === null ? scene.roots : scene.childrenOf(target.newParent)];
|
|
129
|
+
const roots = new Set(session.outer);
|
|
130
|
+
for (const id of roots) {
|
|
131
|
+
const node = scene.get(id);
|
|
132
|
+
if (!session.startPoses.has(id) || node === void 0) continue;
|
|
133
|
+
const to = landedLocalPose(session, id, target.newParent, target.newLayer, delta);
|
|
134
|
+
if (to === null) return null;
|
|
135
|
+
const toIndex = landAbove(siblings, id, mode === "above" ? target.hitSibling : null);
|
|
136
|
+
ops.push(...landOps(session, id, target.newParent, toIndex, target.newLayer));
|
|
137
|
+
ops.push(coreOps.setPose({
|
|
138
|
+
id,
|
|
139
|
+
from: node.pose,
|
|
140
|
+
to,
|
|
141
|
+
label
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
const riders = [.../* @__PURE__ */ new Set([...session.ids.filter((id) => !roots.has(id)), ...session.cascadeIds])];
|
|
145
|
+
const page = target.newParent === null ? null : pageIdOf(scene, target.newParent);
|
|
146
|
+
const landed = new Map([...roots].filter((id) => session.startPoses.has(id) && scene.get(id) !== void 0).map((id) => [id, page]));
|
|
147
|
+
const cascade = landedCascadeOps(session, riders, target.newParent, delta, target.newLayer);
|
|
148
|
+
const followers = followerOpsFor(scene, landed, label);
|
|
149
|
+
return cascade === null || followers === null ? null : [
|
|
150
|
+
...ops,
|
|
151
|
+
...cascade,
|
|
152
|
+
...followers
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { landAbove, landOps, landedCascadeOps, landedLocalPose, reparentOps, resolveDrop };
|
|
157
|
+
//# sourceMappingURL=reparent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reparent.js","names":["rebaseLocalPose"],"sources":["../../../../src/actions/move/commit/reparent.ts"],"sourcesContent":["import { followerOpsFor, carryPose, planeOf, translateNodeOps } from '@weasel-js/core';\nimport { isPageStructure, pageIdOf, planeToPlane, rebaseLocalPose, sceneViewPoseAdapter, refusalOf } from '@weasel-js/core/engine';\nimport type { Op, NodeId, ReparentOnDrop } from '@weasel-js/core';\nimport { draggedWorldPose, grabbedPoseAdapter } from '../delta';\nimport type { MoveSession } from '../session';\nimport { translateOps } from '../translate';\nimport { worldBoundsOf, type MoveRefusal } from '../refusal';\nimport * as coreOps from '@weasel-js/core/ops';\n\n/** Resolved drop target — the new parent + layer + (for `'above'` mode)\n * the hit sibling whose z-order position the moved node should land\n * immediately above. `newParent === null` means \"land at the layer\n * root\" (top-level node of `newLayer`). */\nexport interface DropTarget {\n newParent: NodeId | null;\n newLayer: string;\n hitSibling: NodeId | null;\n}\n\n/** Walk the hit chain to find the appropriate drop target. Returns\n * `null` when no reparent should happen (drop on empty canvas, the\n * only hits are the moved subtree itself, or a page or the run refuses\n * it, since the climb never passes page structure), and a refusal when the first\n * node of the chain to answer refuses with a reason. */\nexport function resolveDrop(\n session: MoveSession,\n at: { x: number; y: number },\n): DropTarget | { refused: MoveRefusal } | null {\n const dep = session.nodeAtPoint;\n if (!dep) return null;\n\n // Exclude moved roots + their descendants. Otherwise we'd happily\n // reparent a node into itself (or under one of its own children).\n const exclude = new Set<NodeId>([...session.ids, ...session.cascadeIds]);\n const hit = dep(at, exclude);\n if (!hit) return null;\n\n const hitNode = session.scene.get(hit);\n if (!hitNode) return null;\n\n // A node that admits the drop is a drop-INTO target; one that refuses it\n // silently is a sibling to land beside, inside the nearest ancestor that\n // admits it. When there is none, `newParent === null` and the moved subtree\n // lands at the layer root.\n let newParent: NodeId | null = hit;\n let hitSibling: NodeId | null = null;\n while (newParent !== null) {\n const verdict = session.verdict(newParent);\n if (verdict === true) break;\n const reason = refusalOf(verdict);\n if (reason !== null) return { refused: { id: newParent, bounds: worldBoundsOf(session, newParent), reason } };\n if (isPageStructure(session.scene.get(newParent))) return null;\n hitSibling = newParent;\n newParent = session.scene.get(newParent)?.parent ?? null;\n }\n return { newParent, newLayer: hitNode.layer, hitSibling };\n}\n\n/** Move `id` within `siblings`, a destination's children as the next op will find them, to just above\n * `above` when it is among them, else to the end. Returns the index to reparent `id` to, or `undefined` to\n * append. */\nexport function landAbove(siblings: NodeId[], id: NodeId, above: NodeId | null): number | undefined {\n const was = siblings.indexOf(id);\n if (was >= 0) siblings.splice(was, 1);\n const hit = above === null ? -1 : siblings.indexOf(above);\n const toIndex = hit >= 0 ? hit + 1 : undefined;\n if (toIndex === undefined) siblings.push(id);\n else siblings.splice(toIndex, 0, id);\n return toIndex;\n}\n\n/** Root `id`'s pose stored under `newParent` on `newLayer`, keeping the world pose the drag `delta` shows.\n * `null` when `newParent`'s frame is singular and no stored pose keeps it. */\nexport function landedLocalPose(\n session: MoveSession,\n id: NodeId,\n newParent: NodeId | null,\n newLayer: string,\n delta: { dx: number; dy: number },\n): object | null {\n const { scene, pc, view } = session;\n const adapter = sceneViewPoseAdapter(scene);\n const layer = scene.get(id)!.layer;\n const world = carryPose(\n session.descriptorOf(id),\n draggedWorldPose(session, grabbedPoseAdapter(session, adapter), id, delta),\n layer !== newLayer ? planeToPlane(planeOf(view, layer), planeOf(view, newLayer)) : null,\n );\n return rebaseLocalPose(adapter, world, newParent as string | null, pc.compose, pc.decompose) as object | null;\n}\n\n/** The ops for `ids`, descendants of a root moved into `newParent`: each one stored in the frame it is\n * moved into, on `newLayer` when given, at the world place the drag `delta` gives. One a moving frame\n * carries keeps only what it caught mid-glide, as in a translate. `null` when one cannot keep its place. */\nexport function landedCascadeOps(\n session: MoveSession,\n ids: readonly NodeId[],\n newParent: NodeId | null,\n delta: { dx: number; dy: number },\n newLayer?: string,\n): Op[] | null {\n const own = new Map<NodeId, { dx: number; dy: number }>();\n for (const id of ids) {\n const start = session.startPoses.get(id);\n if (start === undefined || session.carried.has(id) || !session.scene.get(id)) continue;\n const d = session.descriptorOf(id);\n const landed = landedLocalPose(session, id, newParent, newLayer ?? session.scene.get(id)!.layer, delta);\n if (landed === null) return null;\n const from = d.getBounds(start);\n const to = d.getBounds(landed);\n const c = session.caught.get(id) ?? { dx: 0, dy: 0 };\n own.set(id, { dx: to.x - from.x + c.dx, dy: to.y - from.y + c.dy });\n }\n return [\n ...translateOps(session, ids.filter((id) => session.carried.has(id)), delta),\n ...translateNodeOps(\n session.scene, own.keys(), (id) => own.get(id) ?? null, session.descriptorOf, session.geometryProjection,\n session.lifecycle.label,\n ),\n ];\n}\n\n/** The ops that move root `id` into `to` at `toIndex`, onto `layer` first when it is on another. */\nexport function landOps(\n session: MoveSession,\n id: NodeId,\n to: NodeId | null,\n toIndex: number | undefined,\n layer: string,\n): Op[] {\n const node = session.scene.get(id)!;\n const label = session.lifecycle.label;\n const ops: Op[] = [];\n let from = node.parent as string | null;\n if (node.layer !== layer) {\n // The scene refuses a layer change on a node whose parent is on another layer.\n if (from !== null) {\n ops.push(coreOps.reparent({\n id: id as string, fromParentId: from, toParentId: null, label, coalesceKey: `reparent:${id}:orphan`,\n }));\n from = null;\n }\n ops.push(coreOps.setLayer({ id: id as string, from: node.layer, to: layer, label }));\n }\n ops.push(coreOps.reparent({ id: id as string, fromParentId: from, toParentId: to as string | null, toIndex, label }));\n return ops;\n}\n\n/** Reparent and reposition each moved root as ops, keeping the world pose the\n * drag showed, then the ops that bring uncarried descendants along, and the\n * followers whose page that changes (`followerMoves`). `null` when any of\n * them would land in a singular frame, so the drop refuses whole. */\nexport function reparentOps(\n session: MoveSession,\n target: DropTarget,\n mode: ReparentOnDrop,\n delta: { dx: number; dy: number },\n): Op[] | null {\n const { scene } = session;\n const label = session.lifecycle.label;\n const ops: Op[] = [];\n // The destination's children as each op will find them: an earlier root's\n // landing shifts where a later one goes.\n const siblings = [...(target.newParent === null ? scene.roots : scene.childrenOf(target.newParent))];\n const roots = new Set(session.outer);\n for (const id of roots) {\n const node = scene.get(id);\n // A node removed mid-drag is skipped, as the translate commit skips it.\n if (!session.startPoses.has(id) || node === undefined) continue;\n const to = landedLocalPose(session, id, target.newParent, target.newLayer, delta);\n if (to === null) return null;\n const toIndex = landAbove(siblings, id, mode === 'above' ? target.hitSibling : null);\n ops.push(...landOps(session, id, target.newParent, toIndex, target.newLayer));\n ops.push(coreOps.setPose<unknown>({ id: id as string, from: node.pose, to, label }));\n }\n const riders = [...new Set([...session.ids.filter((id) => !roots.has(id)), ...session.cascadeIds])];\n const page = target.newParent === null ? null : pageIdOf(scene, target.newParent);\n const landed = new Map([...roots].filter((id) => session.startPoses.has(id) && scene.get(id) !== undefined)\n .map((id) => [id as string, page]));\n const cascade = landedCascadeOps(session, riders, target.newParent, delta, target.newLayer);\n const followers = followerOpsFor(scene, landed, label);\n return cascade === null || followers === null ? null : [...ops, ...cascade, ...followers];\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,YACd,SACA,IAC8C;CAC9C,MAA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BAAG,IAAI,IAAI,CAAC,GAAG,QAAQ,IAAI,QAAQ,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,GAAG,QAAQ,UAAU,CAAC,CAAC;CAClG,MAAM,OAAO,OAAO,cAAc,OAAO,OAAO,SAAS,OAAO,OAAO,SAAS;CAChF,MAAM,SAAS,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,OAAO,QAAQ,WAAW,IAAI,EAAE,KAAK,MAAM,IAAI,EAAE,MAAM,MAAS,CAAC,CACxG,KAAK,OAAO,CAAC,IAAc,IAAI,CAAC,CAAC;CACpC,MAAM,UAAU,iBAAiB,SAAS,QAAQ,OAAO,WAAW,OAAO,OAAO,QAAQ;CAC1F,MAAM,YAAY,eAAe,OAAO,QAAQ,KAAK;CACrD,OAAO,YAAY,QAAQ,cAAc,OAAO,OAAO;EAAC,GAAG;EAAK,GAAG;EAAS,GAAG;CAAS;AAC1F"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { snapLanding } from "./dragSnap.js";
|
|
2
|
+
import { leadUnder, planeOf, translatePoseViaDescriptor } from "@weasel-js/core";
|
|
3
|
+
import { composeWorldPose as composeWorldPose$1, toPlane } from "@weasel-js/core/engine";
|
|
4
|
+
|
|
5
|
+
// src/actions/move/delta.ts
|
|
6
|
+
/**
|
|
7
|
+
* The world drag `(dx, dy)` as a translation of `id`'s stored pose. A pose is
|
|
8
|
+
* stored in its frame, so under a turned frame the two point different ways.
|
|
9
|
+
* `null` in a singular frame: no stored move follows the drag there, so the
|
|
10
|
+
* node stays where it is.
|
|
11
|
+
*/
|
|
12
|
+
function localDelta(session, id, dx0, dy0) {
|
|
13
|
+
const { dx, dy } = planeDelta(session, id, dx0, dy0);
|
|
14
|
+
const f = session.frames.get(id);
|
|
15
|
+
if (f === void 0) return {
|
|
16
|
+
dx,
|
|
17
|
+
dy
|
|
18
|
+
};
|
|
19
|
+
const { pc } = session;
|
|
20
|
+
const d = session.descriptorOf(id);
|
|
21
|
+
const fromPose = pc.decompose(f.frameWorld, f.world);
|
|
22
|
+
const toPose = pc.decompose(f.frameWorld, translatePoseViaDescriptor(f.world, dx, dy, d, leadFor(session, id, dx0, dy0)));
|
|
23
|
+
if (fromPose === null || toPose === null) return null;
|
|
24
|
+
const from = d.getBounds(fromPose);
|
|
25
|
+
const to = d.getBounds(toPose);
|
|
26
|
+
return {
|
|
27
|
+
dx: to.x - from.x,
|
|
28
|
+
dy: to.y - from.y
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
var leads = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
/** The move's first root, at press and dragged by `(dx0, dy0)`, in world
|
|
33
|
+
* space. Kept for the last drag asked about, since every id asks per frame. */
|
|
34
|
+
function moveLead(session, dx0, dy0) {
|
|
35
|
+
const last = leads.get(session);
|
|
36
|
+
const snapped = snapLanding(session, dx0, dy0);
|
|
37
|
+
if (last && last.dx0 === dx0 && last.dy0 === dy0 && last.landing === snapped) return last;
|
|
38
|
+
const id = session.ids.find((r) => session.startPoses.has(r) && !session.carried.has(r) && !session.caught.has(r));
|
|
39
|
+
let next = {
|
|
40
|
+
dx0,
|
|
41
|
+
dy0,
|
|
42
|
+
dx: dx0,
|
|
43
|
+
dy: dy0,
|
|
44
|
+
lead: null,
|
|
45
|
+
landing: snapped
|
|
46
|
+
};
|
|
47
|
+
if (id !== void 0) {
|
|
48
|
+
const from = session.frames.get(id)?.world ?? session.startPoses.get(id);
|
|
49
|
+
const { dx, dy } = planeDelta(session, id, dx0, dy0);
|
|
50
|
+
const landing = dx === dx0 && dy === dy0 ? snapped : void 0;
|
|
51
|
+
next = {
|
|
52
|
+
dx0,
|
|
53
|
+
dy0,
|
|
54
|
+
dx,
|
|
55
|
+
dy,
|
|
56
|
+
lead: {
|
|
57
|
+
from,
|
|
58
|
+
to: translatePoseViaDescriptor(from, dx, dy, session.descriptorOf(id), void 0, landing)
|
|
59
|
+
},
|
|
60
|
+
landing: snapped
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
leads.set(session, next);
|
|
64
|
+
return next;
|
|
65
|
+
}
|
|
66
|
+
/** The lead to translate `id`'s world pose with under the drag `(dx0, dy0)`:
|
|
67
|
+
* the move's first root, when `id` measures the drag as the same delta. */
|
|
68
|
+
function leadFor(session, id, dx0, dy0) {
|
|
69
|
+
if (session.caught.has(id)) return void 0;
|
|
70
|
+
const m = moveLead(session, dx0, dy0);
|
|
71
|
+
if (!m.lead) return void 0;
|
|
72
|
+
const own = planeDelta(session, id, dx0, dy0);
|
|
73
|
+
return own.dx === m.dx && own.dy === m.dy ? m.lead : void 0;
|
|
74
|
+
}
|
|
75
|
+
/** The lead for translating `id`'s stored pose: the world lead, carried into
|
|
76
|
+
* the frame `id` is stored in. */
|
|
77
|
+
function storedLeadFor(session, id, dx0, dy0) {
|
|
78
|
+
const lead = leadFor(session, id, dx0, dy0);
|
|
79
|
+
return lead && leadUnder(session.pc, session.frames.get(id)?.frameWorld ?? null, lead);
|
|
80
|
+
}
|
|
81
|
+
/** The pose `id` stores once dragged by `(dx, dy)` from `start`, its stored
|
|
82
|
+
* pose at press. Unmoved when its frame is what moves. */
|
|
83
|
+
function draggedStoredPose(session, id, start, dx, dy) {
|
|
84
|
+
if (session.carried.has(id)) return start;
|
|
85
|
+
const l = localDelta(session, id, dx, dy);
|
|
86
|
+
if (l === null) return start;
|
|
87
|
+
return translatePoseViaDescriptor(start, l.dx, l.dy, session.descriptorOf(id), storedLeadFor(session, id, dx, dy));
|
|
88
|
+
}
|
|
89
|
+
/** The drag `(dx, dy)`, measured in the edited plane, as the drag of `id` in
|
|
90
|
+
* the world its own layer stores it in. */
|
|
91
|
+
function planeDelta(session, id, dx, dy) {
|
|
92
|
+
const layer = session.scene.get(id)?.layer;
|
|
93
|
+
const ref = layer === void 0 ? void 0 : session.planeRefs.get(layer);
|
|
94
|
+
if (!ref) return {
|
|
95
|
+
dx,
|
|
96
|
+
dy
|
|
97
|
+
};
|
|
98
|
+
const out = planeOf(session.view, layer);
|
|
99
|
+
const at = {
|
|
100
|
+
x: ref.edited.x + dx,
|
|
101
|
+
y: ref.edited.y + dy
|
|
102
|
+
};
|
|
103
|
+
const p = out ? toPlane(out, at) : at;
|
|
104
|
+
return {
|
|
105
|
+
dx: p.x - ref.own.x,
|
|
106
|
+
dy: p.y - ref.own.y
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** `adapter`, except that an id caught mid-glide answers with the pose it was
|
|
110
|
+
* grabbed at — where the drag measures it from. */
|
|
111
|
+
function grabbedPoseAdapter(session, adapter) {
|
|
112
|
+
if (session.caught.size === 0) return adapter;
|
|
113
|
+
return {
|
|
114
|
+
...adapter,
|
|
115
|
+
getPose: (id) => session.caught.has(id) ? session.startPoses.get(id) : adapter.getPose(id)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** The world pose `id` was dragged to: its pose at press composed up through
|
|
119
|
+
* `adapter`, moved by the drag as its own layer's plane measures it. */
|
|
120
|
+
function draggedWorldPose(session, adapter, id, delta) {
|
|
121
|
+
const start = composeWorldPose$1(adapter, id, session.pc.compose);
|
|
122
|
+
const own = planeDelta(session, id, delta.dx, delta.dy);
|
|
123
|
+
return translatePoseViaDescriptor(start, own.dx, own.dy, session.descriptorOf(id), leadFor(session, id, delta.dx, delta.dy));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export { draggedStoredPose, draggedWorldPose, grabbedPoseAdapter, localDelta, planeDelta, storedLeadFor };
|
|
127
|
+
//# sourceMappingURL=delta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delta.js","names":["composeWorldPose"],"sources":["../../../src/actions/move/delta.ts"],"sourcesContent":["import type { NodeId } from '@weasel-js/core';\nimport { leadUnder, translatePoseViaDescriptor, type TranslateLead, planeOf } from '@weasel-js/core';\nimport { toPlane, composeWorldPose, type PoseAdapter } from '@weasel-js/core/engine';\nimport type { MoveSession } from './session';\nimport { snapLanding } from './dragSnap';\n\n/**\n * The world drag `(dx, dy)` as a translation of `id`'s stored pose. A pose is\n * stored in its frame, so under a turned frame the two point different ways.\n * `null` in a singular frame: no stored move follows the drag there, so the\n * node stays where it is.\n */\nexport function localDelta(\n session: MoveSession,\n id: NodeId,\n dx0: number,\n dy0: number,\n): { dx: number; dy: number } | null {\n const { dx, dy } = planeDelta(session, id, dx0, dy0);\n const f = session.frames.get(id);\n if (f === undefined) return { dx, dy };\n const { pc } = session;\n const d = session.descriptorOf(id);\n const fromPose = pc.decompose(f.frameWorld, f.world);\n const toPose = pc.decompose(f.frameWorld, translatePoseViaDescriptor(f.world, dx, dy, d, leadFor(session, id, dx0, dy0)));\n if (fromPose === null || toPose === null) return null;\n const from = d.getBounds(fromPose);\n const to = d.getBounds(toPose);\n return { dx: to.x - from.x, dy: to.y - from.y };\n}\n\ninterface MoveLead {\n readonly dx0: number;\n readonly dy0: number;\n /** The lead's own delta, as its layer's plane measures the drag. */\n readonly dx: number;\n readonly dy: number;\n readonly lead: TranslateLead<unknown> | null;\n /** The snap's landing for `(dx0, dy0)` the lead was made with, which can change with the delta held still. */\n readonly landing: unknown;\n}\n\nconst leads = new WeakMap<MoveSession, MoveLead>();\n\n/** The move's first root, at press and dragged by `(dx0, dy0)`, in world\n * space. Kept for the last drag asked about, since every id asks per frame. */\nfunction moveLead(session: MoveSession, dx0: number, dy0: number): MoveLead {\n const last = leads.get(session);\n const snapped = snapLanding(session, dx0, dy0);\n if (last && last.dx0 === dx0 && last.dy0 === dy0 && last.landing === snapped) return last;\n const id = session.ids.find((r) =>\n session.startPoses.has(r) && !session.carried.has(r) && !session.caught.has(r));\n let next: MoveLead = { dx0, dy0, dx: dx0, dy: dy0, lead: null, landing: snapped };\n if (id !== undefined) {\n const from = session.frames.get(id)?.world ?? session.startPoses.get(id);\n const { dx, dy } = planeDelta(session, id, dx0, dy0);\n // A landing is the snap's answer for the drag as the edited plane measured it.\n const landing = dx === dx0 && dy === dy0 ? snapped : undefined;\n const to = translatePoseViaDescriptor(from, dx, dy, session.descriptorOf(id), undefined, landing);\n next = { dx0, dy0, dx, dy, lead: { from, to }, landing: snapped };\n }\n leads.set(session, next);\n return next;\n}\n\n/** The lead to translate `id`'s world pose with under the drag `(dx0, dy0)`:\n * the move's first root, when `id` measures the drag as the same delta. */\nfunction leadFor(session: MoveSession, id: NodeId, dx0: number, dy0: number): TranslateLead<unknown> | undefined {\n if (session.caught.has(id)) return undefined;\n const m = moveLead(session, dx0, dy0);\n if (!m.lead) return undefined;\n const own = planeDelta(session, id, dx0, dy0);\n return own.dx === m.dx && own.dy === m.dy ? m.lead : undefined;\n}\n\n/** The lead for translating `id`'s stored pose: the world lead, carried into\n * the frame `id` is stored in. */\nexport function storedLeadFor(session: MoveSession, id: NodeId, dx0: number, dy0: number): TranslateLead<unknown> | undefined {\n const lead = leadFor(session, id, dx0, dy0);\n return lead && leadUnder(session.pc, session.frames.get(id)?.frameWorld ?? null, lead);\n}\n\n/** The pose `id` stores once dragged by `(dx, dy)` from `start`, its stored\n * pose at press. Unmoved when its frame is what moves. */\nexport function draggedStoredPose(session: MoveSession, id: NodeId, start: unknown, dx: number, dy: number): unknown {\n if (session.carried.has(id)) return start;\n const l = localDelta(session, id, dx, dy);\n if (l === null) return start;\n return translatePoseViaDescriptor(start, l.dx, l.dy, session.descriptorOf(id), storedLeadFor(session, id, dx, dy));\n}\n\n/** The drag `(dx, dy)`, measured in the edited plane, as the drag of `id` in\n * the world its own layer stores it in. */\nexport function planeDelta(\n session: MoveSession,\n id: NodeId,\n dx: number,\n dy: number,\n): { dx: number; dy: number } {\n const layer = session.scene.get(id)?.layer;\n const ref = layer === undefined ? undefined : session.planeRefs.get(layer);\n if (!ref) return { dx, dy };\n const out = planeOf(session.view, layer!);\n const at = { x: ref.edited.x + dx, y: ref.edited.y + dy };\n const p = out ? toPlane(out, at) : at;\n return { dx: p.x - ref.own.x, dy: p.y - ref.own.y };\n}\n\n/** `adapter`, except that an id caught mid-glide answers with the pose it was\n * grabbed at — where the drag measures it from. */\nexport function grabbedPoseAdapter(\n session: MoveSession,\n adapter: PoseAdapter<unknown>,\n): PoseAdapter<unknown> {\n if (session.caught.size === 0) return adapter;\n return {\n ...adapter,\n getPose: (id) => (session.caught.has(id as NodeId)\n ? session.startPoses.get(id as NodeId)\n : adapter.getPose(id)),\n };\n}\n\n/** The world pose `id` was dragged to: its pose at press composed up through\n * `adapter`, moved by the drag as its own layer's plane measures it. */\nexport function draggedWorldPose(\n session: MoveSession,\n adapter: PoseAdapter<unknown>,\n id: NodeId,\n delta: { dx: number; dy: number },\n): unknown {\n const start = composeWorldPose(adapter, id as string, session.pc.compose);\n const own = planeDelta(session, id, delta.dx, delta.dy);\n return translatePoseViaDescriptor(\n start, own.dx, own.dy, session.descriptorOf(id), leadFor(session, id, delta.dx, delta.dy),\n );\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,WACd,SACA,IACA,KACA,KACmC;CACnC,MAAM,EAAE,IAAI,OAAO,WAAW,SAAS,IAAI,KAAK,GAAG;CACnD,MAAM,IAAI,QAAQ,OAAO,IAAI,EAAE;CAC/B,IAAI,MAAM,QAAW,OAAO;EAAE;EAAI;CAAG;CACrC,MAAM,EAAE,OAAO;CACf,MAAM,IAAI,QAAQ,aAAa,EAAE;CACjC,MAAM,WAAW,GAAG,UAAU,EAAE,YAAY,EAAE,KAAK;CACnD,MAAM,SAAS,GAAG,UAAU,EAAE,YAAY,2BAA2B,EAAE,OAAO,IAAI,IAAI,GAAG,QAAQ,SAAS,IAAI,KAAK,GAAG,CAAC,CAAC;CACxH,IAAI,aAAa,QAAQ,WAAW,MAAM,OAAO;CACjD,MAAM,OAAO,EAAE,UAAU,QAAQ;CACjC,MAAM,KAAK,EAAE,UAAU,MAAM;CAC7B,OAAO;EAAE,IAAI,GAAG,IAAI,KAAK;EAAG,IAAI,GAAG,IAAI,KAAK;CAAE;AAChD;AAaA,IAAM,wBAAQ,IAAI,QAA+B;;;AAIjD,SAAS,SAAS,SAAsB,K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WAAW,SAAS,IAAI,MAAM,IAAI,MAAM,EAAE;CACtD,OAAO,2BACL,OAAO,IAAI,IAAI,IAAI,IAAI,QAAQ,aAAa,EAAE,GAAG,QAAQ,SAAS,IAAI,MAAM,IAAI,MAAM,EAAE,CAC1F;AACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createLazySnapSession } from "@weasel-js/core";
|
|
2
|
+
import { snapMods } from "@weasel-js/core/engine";
|
|
3
|
+
|
|
4
|
+
// src/actions/move/dragSnap.ts
|
|
5
|
+
/** The snapping of a drag that translates `ids`, which offer no targets unless `exclude` names others. */
|
|
6
|
+
function beginDragSnap(ctx, ids, exclude) {
|
|
7
|
+
const press = ctx.drag?.start ?? ctx.world;
|
|
8
|
+
return {
|
|
9
|
+
snap: createLazySnapSession(ctx.deps.snap, {
|
|
10
|
+
gesture: "move",
|
|
11
|
+
ids,
|
|
12
|
+
press,
|
|
13
|
+
constrain: "axis",
|
|
14
|
+
...exclude ? { exclude } : {}
|
|
15
|
+
}),
|
|
16
|
+
press
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Each session's latest landing, with the delta it was reported for. */
|
|
20
|
+
var landings = /* @__PURE__ */ new WeakMap();
|
|
21
|
+
/** The pointer's delta, moved so the subject lands on what the snap session
|
|
22
|
+
* holds it to. */
|
|
23
|
+
function snappedDelta(drag, moveCtx) {
|
|
24
|
+
const d = moveCtx.drag.delta;
|
|
25
|
+
if (!drag.snap) return {
|
|
26
|
+
dx: d.x,
|
|
27
|
+
dy: d.y
|
|
28
|
+
};
|
|
29
|
+
const { press } = drag;
|
|
30
|
+
const out = drag.snap.at({
|
|
31
|
+
x: press.x + d.x,
|
|
32
|
+
y: press.y + d.y
|
|
33
|
+
}, snapMods(moveCtx));
|
|
34
|
+
const dx = out.point.x - press.x;
|
|
35
|
+
const dy = out.point.y - press.y;
|
|
36
|
+
if (out.landing === void 0) landings.delete(drag.snap);
|
|
37
|
+
else landings.set(drag.snap, {
|
|
38
|
+
dx,
|
|
39
|
+
dy,
|
|
40
|
+
landing: out.landing
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
dx,
|
|
44
|
+
dy
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** The host's landing (`SnapOutcome.landing`) for the drag `(dx, dy)`, when
|
|
48
|
+
* that is the delta the session last snapped to; otherwise undefined. */
|
|
49
|
+
function snapLanding(drag, dx, dy) {
|
|
50
|
+
const last = drag.snap ? landings.get(drag.snap) : void 0;
|
|
51
|
+
return last && last.dx === dx && last.dy === dy ? last.landing : void 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { beginDragSnap, snapLanding, snappedDelta };
|
|
55
|
+
//# sourceMappingURL=dragSnap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dragSnap.js","names":[],"sources":["../../../src/actions/move/dragSnap.ts"],"sourcesContent":["import type { InvocationCtx, WorldPoint } from '@weasel-js/routing';\nimport type { SnapSession } from '@weasel-js/core/engine';\nimport { createLazySnapSession } from '@weasel-js/core';\nimport { snapMods } from '@weasel-js/core/engine';\n\n/** A translate drag's snapping: a move's, or a clone's. */\nexport interface DragSnap {\n /** Begun once the drag passes its threshold; null with no `snap` dep. */\n readonly snap: SnapSession | null;\n /** The press, in the coordinates the drag's delta is measured in. */\n readonly press: WorldPoint;\n}\n\n/** The snapping of a drag that translates `ids`, which offer no targets unless `exclude` names others. */\nexport function beginDragSnap(ctx: InvocationCtx, ids: readonly string[], exclude?: readonly string[]): DragSnap {\n const press = ctx.drag?.start ?? ctx.world;\n return {\n snap: createLazySnapSession(ctx.deps.snap, { gesture: 'move', ids, press, constrain: 'axis', ...(exclude ? { exclude } : {}) }),\n press,\n };\n}\n\ninterface Landed {\n readonly dx: number;\n readonly dy: number;\n readonly landing: unknown;\n}\n\n/** Each session's latest landing, with the delta it was reported for. */\nconst landings = new WeakMap<SnapSession, Landed>();\n\n/** The pointer's delta, moved so the subject lands on what the snap session\n * holds it to. */\nexport function snappedDelta(drag: DragSnap, moveCtx: InvocationCtx): { dx: number; dy: number } {\n const d = moveCtx.drag!.delta;\n if (!drag.snap) return { dx: d.x, dy: d.y };\n const { press } = drag;\n const out = drag.snap.at({ x: press.x + d.x, y: press.y + d.y }, snapMods(moveCtx));\n const dx = out.point.x - press.x;\n const dy = out.point.y - press.y;\n if (out.landing === undefined) landings.delete(drag.snap);\n else landings.set(drag.snap, { dx, dy, landing: out.landing });\n return { dx, dy };\n}\n\n/** The host's landing (`SnapOutcome.landing`) for the drag `(dx, dy)`, when\n * that is the delta the session last snapped to; otherwise undefined. */\nexport function snapLanding(drag: DragSnap, dx: number, dy: number): unknown {\n const last = drag.snap ? landings.get(drag.snap) : undefined;\n return last && last.dx === dx && last.dy === dy ? last.landing : undefined;\n}\n"],"mappings":";;;;;AAcA,SAAgB,cAAc,KAAoB,KAAwB,SAAuC;CAC/G,MAAM,QAAQ,IAAI,MAAM,SAAS,IAAI;CACrC,OAAO;EACL,MAAM,sBAAsB,IAAI,KAAK,MAAM;GAAE,SAAS;GAAQ;GAAK;GAAO,WAAW;GAAQ,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;EAAG,CAAC;EAC9H;CACF;AACF;;AASA,IAAM,2BAAW,IAAI,QAA6B;;;AAIlD,SAAgB,aAAa,MAAgB,SAAoD;CAC/F,MAAM,IAAI,QAAQ,KAAM;CACxB,IAAI,CAAC,KAAK,MAAM,OAAO;EAAE,IAAI,EAAE;EAAG,IAAI,EAAE;CAAE;CAC1C,MAAM,EAAE,UAAU;CAClB,MAAM,MAAM,KAAK,KAAK,GAAG;EAAE,GAAG,MAAM,IAAI,EAAE;EAAG,GAAG,MAAM,IAAI,EAAE;CAAE,GAAG,SAAS,OAAO,CAAC;CAClF,MAAM,KAAK,IAAI,MAAM,IAAI,MAAM;CAC/B,MAAM,KAAK,IAAI,MAAM,IAAI,MAAM;CAC/B,IAAI,IAAI,YAAY,QAAW,SAAS,OAAO,KAAK,IAAI;MACnD,SAAS,IAAI,KAAK,MAAM;EAAE;EAAI;EAAI,SAAS,IAAI;CAAQ,CAAC;CAC7D,OAAO;EAAE;EAAI;CAAG;AAClB;;;AAIA,SAAgB,YAAY,MAAgB,IAAY,IAAqB;CAC3E,MAAM,OAAO,KAAK,OAAO,SAAS,IAAI,KAAK,IAAI,IAAI;CACnD,OAAO,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,KAAK,KAAK,UAAU;AACnE"}
|