@witchcraft/layout 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +474 -0
- package/dist/module.d.mts +14 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +26 -0
- package/dist/runtime/components/LayoutDecos.d.vue.ts +0 -0
- package/dist/runtime/components/LayoutDecos.vue +54 -0
- package/dist/runtime/components/LayoutDecos.vue.d.ts +0 -0
- package/dist/runtime/components/LayoutEdges.d.vue.ts +0 -0
- package/dist/runtime/components/LayoutEdges.vue +145 -0
- package/dist/runtime/components/LayoutEdges.vue.d.ts +0 -0
- package/dist/runtime/components/LayoutFrame.d.vue.ts +0 -0
- package/dist/runtime/components/LayoutFrame.vue +41 -0
- package/dist/runtime/components/LayoutFrame.vue.d.ts +0 -0
- package/dist/runtime/components/LayoutShapeSquare.d.vue.ts +0 -0
- package/dist/runtime/components/LayoutShapeSquare.vue +36 -0
- package/dist/runtime/components/LayoutShapeSquare.vue.d.ts +0 -0
- package/dist/runtime/components/LayoutWindow.d.vue.ts +0 -0
- package/dist/runtime/components/LayoutWindow.vue +183 -0
- package/dist/runtime/components/LayoutWindow.vue.d.ts +0 -0
- package/dist/runtime/composables/useFrames.d.ts +0 -0
- package/dist/runtime/composables/useFrames.js +184 -0
- package/dist/runtime/demo/App.d.vue.ts +0 -0
- package/dist/runtime/demo/App.vue +123 -0
- package/dist/runtime/demo/App.vue.d.ts +0 -0
- package/dist/runtime/demo/DemoControls.d.vue.ts +0 -0
- package/dist/runtime/demo/DemoControls.vue +14 -0
- package/dist/runtime/demo/DemoControls.vue.d.ts +0 -0
- package/dist/runtime/demo/README.md +1 -0
- package/dist/runtime/demo/main.d.ts +0 -0
- package/dist/runtime/demo/main.js +4 -0
- package/dist/runtime/demo/sharedLayoutInstance.d.ts +0 -0
- package/dist/runtime/demo/sharedLayoutInstance.js +5 -0
- package/dist/runtime/demo/tailwind.css +1 -0
- package/dist/runtime/drag/CloseAction.d.ts +0 -0
- package/dist/runtime/drag/CloseAction.js +121 -0
- package/dist/runtime/drag/DragActionHandler.d.ts +0 -0
- package/dist/runtime/drag/DragActionHandler.js +83 -0
- package/dist/runtime/drag/DragDirectionStore.d.ts +0 -0
- package/dist/runtime/drag/DragDirectionStore.js +45 -0
- package/dist/runtime/drag/SplitAction.d.ts +0 -0
- package/dist/runtime/drag/SplitAction.js +110 -0
- package/dist/runtime/drag/types.d.ts +0 -0
- package/dist/runtime/drag/types.js +0 -0
- package/dist/runtime/helpers/addPointsToIntersection.d.ts +0 -0
- package/dist/runtime/helpers/addPointsToIntersection.js +7 -0
- package/dist/runtime/helpers/assertEdgeSorted.d.ts +0 -0
- package/dist/runtime/helpers/assertEdgeSorted.js +7 -0
- package/dist/runtime/helpers/assertItemIn.d.ts +0 -0
- package/dist/runtime/helpers/assertItemIn.js +8 -0
- package/dist/runtime/helpers/assertItemNotIn.d.ts +0 -0
- package/dist/runtime/helpers/assertItemNotIn.js +7 -0
- package/dist/runtime/helpers/assertLayoutHasActiveWindow.d.ts +0 -0
- package/dist/runtime/helpers/assertLayoutHasActiveWindow.js +7 -0
- package/dist/runtime/helpers/assertValidWinAndFrame.d.ts +0 -0
- package/dist/runtime/helpers/assertValidWinAndFrame.js +5 -0
- package/dist/runtime/helpers/assertValidWinAndFrameIds.d.ts +0 -0
- package/dist/runtime/helpers/assertValidWinAndFrameIds.js +6 -0
- package/dist/runtime/helpers/assertWindowHasActiveFrame.d.ts +0 -0
- package/dist/runtime/helpers/assertWindowHasActiveFrame.js +7 -0
- package/dist/runtime/helpers/clampNumber.d.ts +0 -0
- package/dist/runtime/helpers/clampNumber.js +3 -0
- package/dist/runtime/helpers/cloneFrame.d.ts +0 -0
- package/dist/runtime/helpers/cloneFrame.js +3 -0
- package/dist/runtime/helpers/cloneFrames.d.ts +0 -0
- package/dist/runtime/helpers/cloneFrames.js +16 -0
- package/dist/runtime/helpers/containsEdge.d.ts +0 -0
- package/dist/runtime/helpers/containsEdge.js +13 -0
- package/dist/runtime/helpers/convertLayoutWindowToWorkspace.d.ts +0 -0
- package/dist/runtime/helpers/convertLayoutWindowToWorkspace.js +10 -0
- package/dist/runtime/helpers/copySize.d.ts +0 -0
- package/dist/runtime/helpers/copySize.js +5 -0
- package/dist/runtime/helpers/createEdge.d.ts +0 -0
- package/dist/runtime/helpers/createEdge.js +13 -0
- package/dist/runtime/helpers/dirToOrientation.d.ts +0 -0
- package/dist/runtime/helpers/dirToOrientation.js +10 -0
- package/dist/runtime/helpers/dirToSide.d.ts +0 -0
- package/dist/runtime/helpers/dirToSide.js +5 -0
- package/dist/runtime/helpers/doEdgesOverlap.d.ts +0 -0
- package/dist/runtime/helpers/doEdgesOverlap.js +22 -0
- package/dist/runtime/helpers/doesEdgeContinueEdge.d.ts +0 -0
- package/dist/runtime/helpers/doesEdgeContinueEdge.js +17 -0
- package/dist/runtime/helpers/edgeToPoints.d.ts +0 -0
- package/dist/runtime/helpers/edgeToPoints.js +3 -0
- package/dist/runtime/helpers/findDraggableEdge.d.ts +0 -0
- package/dist/runtime/helpers/findDraggableEdge.js +13 -0
- package/dist/runtime/helpers/findFrameDraggableEdges.d.ts +0 -0
- package/dist/runtime/helpers/findFrameDraggableEdges.js +18 -0
- package/dist/runtime/helpers/frameToEdges.d.ts +0 -0
- package/dist/runtime/helpers/frameToEdges.js +21 -0
- package/dist/runtime/helpers/frameToPoints.d.ts +0 -0
- package/dist/runtime/helpers/frameToPoints.js +7 -0
- package/dist/runtime/helpers/getEdgeOrientation.d.ts +0 -0
- package/dist/runtime/helpers/getEdgeOrientation.js +4 -0
- package/dist/runtime/helpers/getEdgeSharedDirection.d.ts +0 -0
- package/dist/runtime/helpers/getEdgeSharedDirection.js +7 -0
- package/dist/runtime/helpers/getEdgeSide.d.ts +0 -0
- package/dist/runtime/helpers/getEdgeSide.js +16 -0
- package/dist/runtime/helpers/getFrameById.d.ts +0 -0
- package/dist/runtime/helpers/getFrameById.js +5 -0
- package/dist/runtime/helpers/getFrameConstant.d.ts +0 -0
- package/dist/runtime/helpers/getFrameConstant.js +15 -0
- package/dist/runtime/helpers/getIntersections.d.ts +0 -0
- package/dist/runtime/helpers/getIntersections.js +63 -0
- package/dist/runtime/helpers/getIntersectionsCss.d.ts +0 -0
- package/dist/runtime/helpers/getIntersectionsCss.js +56 -0
- package/dist/runtime/helpers/getMoveEdgeInfo.d.ts +0 -0
- package/dist/runtime/helpers/getMoveEdgeInfo.js +42 -0
- package/dist/runtime/helpers/getResizeLimit.d.ts +0 -0
- package/dist/runtime/helpers/getResizeLimit.js +39 -0
- package/dist/runtime/helpers/getShapeSquareCss.d.ts +0 -0
- package/dist/runtime/helpers/getShapeSquareCss.js +17 -0
- package/dist/runtime/helpers/getSideTouching.d.ts +0 -0
- package/dist/runtime/helpers/getSideTouching.js +7 -0
- package/dist/runtime/helpers/getVisualEdgeCss.d.ts +0 -0
- package/dist/runtime/helpers/getVisualEdgeCss.js +40 -0
- package/dist/runtime/helpers/getVisualEdges.d.ts +0 -0
- package/dist/runtime/helpers/getVisualEdges.js +89 -0
- package/dist/runtime/helpers/getVisualEdgesCss.d.ts +0 -0
- package/dist/runtime/helpers/getVisualEdgesCss.js +4 -0
- package/dist/runtime/helpers/getWinAndFrameById.d.ts +0 -0
- package/dist/runtime/helpers/getWinAndFrameById.js +14 -0
- package/dist/runtime/helpers/getWinByFrameUuid.d.ts +0 -0
- package/dist/runtime/helpers/getWinByFrameUuid.js +13 -0
- package/dist/runtime/helpers/getWinById.d.ts +0 -0
- package/dist/runtime/helpers/getWinById.js +5 -0
- package/dist/runtime/helpers/getWindowConstant.d.ts +0 -0
- package/dist/runtime/helpers/getWindowConstant.js +14 -0
- package/dist/runtime/helpers/inRange.d.ts +0 -0
- package/dist/runtime/helpers/inRange.js +3 -0
- package/dist/runtime/helpers/index.d.ts +0 -0
- package/dist/runtime/helpers/index.js +62 -0
- package/dist/runtime/helpers/isEdgeEqual.d.ts +0 -0
- package/dist/runtime/helpers/isEdgeEqual.js +11 -0
- package/dist/runtime/helpers/isEdgeParallel.d.ts +0 -0
- package/dist/runtime/helpers/isEdgeParallel.js +7 -0
- package/dist/runtime/helpers/isPointEqual.d.ts +0 -0
- package/dist/runtime/helpers/isPointEqual.js +3 -0
- package/dist/runtime/helpers/isSizeAboveMin.d.ts +0 -0
- package/dist/runtime/helpers/isSizeAboveMin.js +3 -0
- package/dist/runtime/helpers/isSizeEqual.d.ts +0 -0
- package/dist/runtime/helpers/isSizeEqual.js +3 -0
- package/dist/runtime/helpers/isWindowEdge.d.ts +0 -0
- package/dist/runtime/helpers/isWindowEdge.js +7 -0
- package/dist/runtime/helpers/isWindowEdgePoint.d.ts +0 -0
- package/dist/runtime/helpers/isWindowEdgePoint.js +5 -0
- package/dist/runtime/helpers/moveEdge.d.ts +0 -0
- package/dist/runtime/helpers/moveEdge.js +8 -0
- package/dist/runtime/helpers/numberToScaledPercent.d.ts +0 -0
- package/dist/runtime/helpers/numberToScaledPercent.js +5 -0
- package/dist/runtime/helpers/numberToScaledSize.d.ts +0 -0
- package/dist/runtime/helpers/numberToScaledSize.js +19 -0
- package/dist/runtime/helpers/oppositeSide.d.ts +0 -0
- package/dist/runtime/helpers/oppositeSide.js +30 -0
- package/dist/runtime/helpers/resizeByEdge.d.ts +0 -0
- package/dist/runtime/helpers/resizeByEdge.js +29 -0
- package/dist/runtime/helpers/sideToDirection.d.ts +0 -0
- package/dist/runtime/helpers/sideToDirection.js +11 -0
- package/dist/runtime/helpers/sideToOrientation.d.ts +0 -0
- package/dist/runtime/helpers/sideToOrientation.js +10 -0
- package/dist/runtime/helpers/splitEdge.d.ts +0 -0
- package/dist/runtime/helpers/splitEdge.js +20 -0
- package/dist/runtime/helpers/toCoord.d.ts +0 -0
- package/dist/runtime/helpers/toCoord.js +10 -0
- package/dist/runtime/helpers/toId.d.ts +0 -0
- package/dist/runtime/helpers/toId.js +4 -0
- package/dist/runtime/helpers/toWindowCoord.d.ts +0 -0
- package/dist/runtime/helpers/toWindowCoord.js +14 -0
- package/dist/runtime/helpers/unionEdges.d.ts +0 -0
- package/dist/runtime/helpers/unionEdges.js +8 -0
- package/dist/runtime/helpers/updateWindowSizeWithEvent.d.ts +0 -0
- package/dist/runtime/helpers/updateWindowSizeWithEvent.js +8 -0
- package/dist/runtime/index.d.ts +0 -0
- package/dist/runtime/index.js +5 -0
- package/dist/runtime/layout/closeFrame.d.ts +0 -0
- package/dist/runtime/layout/closeFrame.js +13 -0
- package/dist/runtime/layout/closeFrames.d.ts +0 -0
- package/dist/runtime/layout/closeFrames.js +8 -0
- package/dist/runtime/layout/createSplitDecoEdge.d.ts +0 -0
- package/dist/runtime/layout/createSplitDecoEdge.js +24 -0
- package/dist/runtime/layout/createSplitDecoFromDrag.d.ts +0 -0
- package/dist/runtime/layout/createSplitDecoFromDrag.js +14 -0
- package/dist/runtime/layout/debugFrame.d.ts +0 -0
- package/dist/runtime/layout/debugFrame.js +4 -0
- package/dist/runtime/layout/findFramesTouchingEdge.d.ts +0 -0
- package/dist/runtime/layout/findFramesTouchingEdge.js +33 -0
- package/dist/runtime/layout/findSafeSplitEdge.d.ts +0 -0
- package/dist/runtime/layout/findSafeSplitEdge.js +20 -0
- package/dist/runtime/layout/findVisualEdge.d.ts +0 -0
- package/dist/runtime/layout/findVisualEdge.js +9 -0
- package/dist/runtime/layout/frameCreate.d.ts +0 -0
- package/dist/runtime/layout/frameCreate.js +13 -0
- package/dist/runtime/layout/frameSplit.d.ts +0 -0
- package/dist/runtime/layout/frameSplit.js +9 -0
- package/dist/runtime/layout/getCloseFrameInfo.d.ts +0 -0
- package/dist/runtime/layout/getCloseFrameInfo.js +103 -0
- package/dist/runtime/layout/getFrameSplitInfo.d.ts +0 -0
- package/dist/runtime/layout/getFrameSplitInfo.js +40 -0
- package/dist/runtime/layout/getFrameTo.d.ts +0 -0
- package/dist/runtime/layout/getFrameTo.js +47 -0
- package/dist/runtime/layout/index.d.ts +0 -0
- package/dist/runtime/layout/index.js +22 -0
- package/dist/runtime/layout/isPointInFrame.d.ts +0 -0
- package/dist/runtime/layout/isPointInFrame.js +4 -0
- package/dist/runtime/layout/layoutAddWindow.d.ts +0 -0
- package/dist/runtime/layout/layoutAddWindow.js +4 -0
- package/dist/runtime/layout/layoutCreate.d.ts +0 -0
- package/dist/runtime/layout/layoutCreate.js +7 -0
- package/dist/runtime/layout/layoutRemoveWindow.d.ts +0 -0
- package/dist/runtime/layout/layoutRemoveWindow.js +5 -0
- package/dist/runtime/layout/resizeFrame.d.ts +0 -0
- package/dist/runtime/layout/resizeFrame.js +69 -0
- package/dist/runtime/layout/windowAddFrame.d.ts +0 -0
- package/dist/runtime/layout/windowAddFrame.js +4 -0
- package/dist/runtime/layout/windowCreate.d.ts +0 -0
- package/dist/runtime/layout/windowCreate.js +13 -0
- package/dist/runtime/layout/windowRemoveFrame.d.ts +0 -0
- package/dist/runtime/layout/windowRemoveFrame.js +5 -0
- package/dist/runtime/layout/windowSetActiveFrame.d.ts +0 -0
- package/dist/runtime/layout/windowSetActiveFrame.js +5 -0
- package/dist/runtime/settings.d.ts +0 -0
- package/dist/runtime/settings.js +54 -0
- package/dist/runtime/types/index.d.ts +0 -0
- package/dist/runtime/types/index.js +120 -0
- package/dist/runtime/utils/KnownError.d.ts +0 -0
- package/dist/runtime/utils/KnownError.js +9 -0
- package/dist/types.d.mts +5 -0
- package/package.json +153 -0
- package/src/module.ts +43 -0
- package/src/runtime/components/LayoutDecos.vue +62 -0
- package/src/runtime/components/LayoutEdges.vue +172 -0
- package/src/runtime/components/LayoutFrame.vue +47 -0
- package/src/runtime/components/LayoutShapeSquare.vue +38 -0
- package/src/runtime/components/LayoutWindow.vue +223 -0
- package/src/runtime/composables/useFrames.ts +251 -0
- package/src/runtime/demo/App.vue +140 -0
- package/src/runtime/demo/DemoControls.vue +17 -0
- package/src/runtime/demo/README.md +1 -0
- package/src/runtime/demo/main.ts +9 -0
- package/src/runtime/demo/sharedLayoutInstance.ts +7 -0
- package/src/runtime/demo/tailwind.css +4 -0
- package/src/runtime/drag/CloseAction.ts +158 -0
- package/src/runtime/drag/DragActionHandler.ts +146 -0
- package/src/runtime/drag/DragDirectionStore.ts +63 -0
- package/src/runtime/drag/SplitAction.ts +147 -0
- package/src/runtime/drag/types.ts +107 -0
- package/src/runtime/helpers/addPointsToIntersection.ts +9 -0
- package/src/runtime/helpers/assertEdgeSorted.ts +11 -0
- package/src/runtime/helpers/assertItemIn.ts +13 -0
- package/src/runtime/helpers/assertItemNotIn.ts +10 -0
- package/src/runtime/helpers/assertLayoutHasActiveWindow.ts +9 -0
- package/src/runtime/helpers/assertValidWinAndFrame.ts +16 -0
- package/src/runtime/helpers/assertValidWinAndFrameIds.ts +9 -0
- package/src/runtime/helpers/assertWindowHasActiveFrame.ts +9 -0
- package/src/runtime/helpers/clampNumber.ts +9 -0
- package/src/runtime/helpers/cloneFrame.ts +5 -0
- package/src/runtime/helpers/cloneFrames.ts +20 -0
- package/src/runtime/helpers/containsEdge.ts +16 -0
- package/src/runtime/helpers/convertLayoutWindowToWorkspace.ts +18 -0
- package/src/runtime/helpers/copySize.ts +7 -0
- package/src/runtime/helpers/createEdge.ts +19 -0
- package/src/runtime/helpers/dirToOrientation.ts +12 -0
- package/src/runtime/helpers/dirToSide.ts +7 -0
- package/src/runtime/helpers/doEdgesOverlap.ts +25 -0
- package/src/runtime/helpers/doesEdgeContinueEdge.ts +20 -0
- package/src/runtime/helpers/edgeToPoints.ts +5 -0
- package/src/runtime/helpers/findDraggableEdge.ts +24 -0
- package/src/runtime/helpers/findFrameDraggableEdges.ts +32 -0
- package/src/runtime/helpers/frameToEdges.ts +32 -0
- package/src/runtime/helpers/frameToPoints.ts +14 -0
- package/src/runtime/helpers/getEdgeOrientation.ts +6 -0
- package/src/runtime/helpers/getEdgeSharedDirection.ts +10 -0
- package/src/runtime/helpers/getEdgeSide.ts +27 -0
- package/src/runtime/helpers/getFrameById.ts +15 -0
- package/src/runtime/helpers/getFrameConstant.ts +22 -0
- package/src/runtime/helpers/getIntersections.ts +87 -0
- package/src/runtime/helpers/getIntersectionsCss.ts +65 -0
- package/src/runtime/helpers/getMoveEdgeInfo.ts +69 -0
- package/src/runtime/helpers/getResizeLimit.ts +60 -0
- package/src/runtime/helpers/getShapeSquareCss.ts +28 -0
- package/src/runtime/helpers/getSideTouching.ts +9 -0
- package/src/runtime/helpers/getVisualEdgeCss.ts +53 -0
- package/src/runtime/helpers/getVisualEdges.ts +155 -0
- package/src/runtime/helpers/getVisualEdgesCss.ts +13 -0
- package/src/runtime/helpers/getWinAndFrameById.ts +28 -0
- package/src/runtime/helpers/getWinByFrameUuid.ts +19 -0
- package/src/runtime/helpers/getWinById.ts +12 -0
- package/src/runtime/helpers/getWindowConstant.ts +21 -0
- package/src/runtime/helpers/inRange.ts +5 -0
- package/src/runtime/helpers/index.ts +64 -0
- package/src/runtime/helpers/isEdgeEqual.ts +14 -0
- package/src/runtime/helpers/isEdgeParallel.ts +10 -0
- package/src/runtime/helpers/isPointEqual.ts +5 -0
- package/src/runtime/helpers/isSizeAboveMin.ts +8 -0
- package/src/runtime/helpers/isSizeEqual.ts +5 -0
- package/src/runtime/helpers/isWindowEdge.ts +11 -0
- package/src/runtime/helpers/isWindowEdgePoint.ts +8 -0
- package/src/runtime/helpers/moveEdge.ts +21 -0
- package/src/runtime/helpers/numberToScaledPercent.ts +19 -0
- package/src/runtime/helpers/numberToScaledSize.ts +28 -0
- package/src/runtime/helpers/oppositeSide.ts +45 -0
- package/src/runtime/helpers/resizeByEdge.ts +45 -0
- package/src/runtime/helpers/sideToDirection.ts +15 -0
- package/src/runtime/helpers/sideToOrientation.ts +12 -0
- package/src/runtime/helpers/splitEdge.ts +23 -0
- package/src/runtime/helpers/toCoord.ts +13 -0
- package/src/runtime/helpers/toId.ts +9 -0
- package/src/runtime/helpers/toWindowCoord.ts +23 -0
- package/src/runtime/helpers/unionEdges.ts +11 -0
- package/src/runtime/helpers/updateWindowSizeWithEvent.ts +10 -0
- package/src/runtime/index.ts +5 -0
- package/src/runtime/layout/closeFrame.ts +33 -0
- package/src/runtime/layout/closeFrames.ts +14 -0
- package/src/runtime/layout/createSplitDecoEdge.ts +34 -0
- package/src/runtime/layout/createSplitDecoFromDrag.ts +24 -0
- package/src/runtime/layout/debugFrame.ts +6 -0
- package/src/runtime/layout/findFramesTouchingEdge.ts +92 -0
- package/src/runtime/layout/findSafeSplitEdge.ts +39 -0
- package/src/runtime/layout/findVisualEdge.ts +11 -0
- package/src/runtime/layout/frameCreate.ts +23 -0
- package/src/runtime/layout/frameSplit.ts +31 -0
- package/src/runtime/layout/getCloseFrameInfo.ts +193 -0
- package/src/runtime/layout/getFrameSplitInfo.ts +65 -0
- package/src/runtime/layout/getFrameTo.ts +65 -0
- package/src/runtime/layout/index.ts +24 -0
- package/src/runtime/layout/isPointInFrame.ts +7 -0
- package/src/runtime/layout/layoutAddWindow.ts +6 -0
- package/src/runtime/layout/layoutCreate.ts +12 -0
- package/src/runtime/layout/layoutRemoveWindow.ts +7 -0
- package/src/runtime/layout/resizeFrame.ts +106 -0
- package/src/runtime/layout/windowAddFrame.ts +10 -0
- package/src/runtime/layout/windowCreate.ts +18 -0
- package/src/runtime/layout/windowRemoveFrame.ts +7 -0
- package/src/runtime/layout/windowSetActiveFrame.ts +7 -0
- package/src/runtime/settings.ts +63 -0
- package/src/runtime/types/index.ts +293 -0
- package/src/runtime/utils/KnownError.ts +24 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<LayoutShapeSquare
|
|
3
|
+
v-if="activeFrame"
|
|
4
|
+
:css="getShapeSquareCss(activeFrame, `var(--layoutEdgeWidth,2px)`)"
|
|
5
|
+
:class="twMerge(
|
|
6
|
+
`
|
|
7
|
+
active-frame-edge
|
|
8
|
+
pointer-events-none
|
|
9
|
+
z-0
|
|
10
|
+
border-blue-500
|
|
11
|
+
border
|
|
12
|
+
`
|
|
13
|
+
)"
|
|
14
|
+
/>
|
|
15
|
+
|
|
16
|
+
<template
|
|
17
|
+
v-for="css, i of cssDragEdges"
|
|
18
|
+
:key="i"
|
|
19
|
+
>
|
|
20
|
+
<LayoutShapeSquare
|
|
21
|
+
:css="css.thick"
|
|
22
|
+
:class="twMerge(`
|
|
23
|
+
drag-edge
|
|
24
|
+
z-20
|
|
25
|
+
hover:cursor-pointer
|
|
26
|
+
[&:hover+.edge]:bg-blue-500/50
|
|
27
|
+
`)"
|
|
28
|
+
@pointerdown="emit('dragStart', $event, { edge: edges[i] })"
|
|
29
|
+
/>
|
|
30
|
+
<LayoutShapeSquare
|
|
31
|
+
:css="css.thin"
|
|
32
|
+
:class="twMerge(`
|
|
33
|
+
pointer-events-none
|
|
34
|
+
edge
|
|
35
|
+
`)"
|
|
36
|
+
/>
|
|
37
|
+
</template>
|
|
38
|
+
<LayoutShapeSquare
|
|
39
|
+
:css="css"
|
|
40
|
+
:class="twMerge(`
|
|
41
|
+
grabbed-edge
|
|
42
|
+
z-20
|
|
43
|
+
bg-blue-500/50
|
|
44
|
+
cursor-pointer
|
|
45
|
+
`)"
|
|
46
|
+
v-for="css, i of cssDragEdge"
|
|
47
|
+
:key="i"
|
|
48
|
+
/>
|
|
49
|
+
<template v-for="css, i of cssDragIntersections" :key="i">
|
|
50
|
+
<LayoutShapeSquare
|
|
51
|
+
:css="css.thick"
|
|
52
|
+
:class="twMerge(
|
|
53
|
+
`
|
|
54
|
+
drag-intersection
|
|
55
|
+
z-30
|
|
56
|
+
rounded-full
|
|
57
|
+
hover:cursor-pointer
|
|
58
|
+
[&:hover+.intersection]:bg-blue-500/50
|
|
59
|
+
`
|
|
60
|
+
)"
|
|
61
|
+
@pointerdown="emit('dragStart', $event, { intersection: wantedIntersections[i] })"
|
|
62
|
+
/>
|
|
63
|
+
<LayoutShapeSquare
|
|
64
|
+
:css="css.thin"
|
|
65
|
+
:class="twMerge(
|
|
66
|
+
`
|
|
67
|
+
intersection
|
|
68
|
+
z-30
|
|
69
|
+
rounded-full
|
|
70
|
+
pointer-events-none
|
|
71
|
+
`,
|
|
72
|
+
css.thin._shifted && `w-[7px] h-[7px]`
|
|
73
|
+
)"
|
|
74
|
+
/>
|
|
75
|
+
</template>
|
|
76
|
+
</template>
|
|
77
|
+
|
|
78
|
+
<script setup>
|
|
79
|
+
import { twMerge } from "@witchcraft/ui/utils/twMerge";
|
|
80
|
+
import { computed, ref, useAttrs } from "vue";
|
|
81
|
+
import LayoutShapeSquare from "./LayoutShapeSquare.vue";
|
|
82
|
+
import { frameToEdges } from "../helpers/frameToEdges.js";
|
|
83
|
+
import { getIntersectionsCss } from "../helpers/getIntersectionsCss.js";
|
|
84
|
+
import { getShapeSquareCss } from "../helpers/getShapeSquareCss.js";
|
|
85
|
+
import { getVisualEdgesCss } from "../helpers/getVisualEdgesCss.js";
|
|
86
|
+
import { isEdgeEqual } from "../helpers/isEdgeEqual.js";
|
|
87
|
+
import { toWindowCoord } from "../helpers/toWindowCoord.js";
|
|
88
|
+
import {
|
|
89
|
+
} from "../types/index.js";
|
|
90
|
+
const $attrs = useAttrs();
|
|
91
|
+
const emit = defineEmits(["dragStart"]);
|
|
92
|
+
const props = defineProps({
|
|
93
|
+
edges: { type: Array, required: true },
|
|
94
|
+
intersections: { type: Array, required: true },
|
|
95
|
+
win: { type: Object, required: true },
|
|
96
|
+
activeFrame: { type: Object, required: false, default: void 0 },
|
|
97
|
+
draggingEdge: { type: null, required: false, default: void 0 },
|
|
98
|
+
draggingIntersection: { type: Object, required: false, default: void 0 }
|
|
99
|
+
});
|
|
100
|
+
const activeFrameCssEdges = computed(() => {
|
|
101
|
+
if (!props.activeFrame) return [];
|
|
102
|
+
return getVisualEdgesCss(Object.values(frameToEdges(props.activeFrame)), {
|
|
103
|
+
edgeWidth: `var(--layoutEdgeWidth, 2px)`
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
const cssDragEdges = computed(() => {
|
|
107
|
+
const thickEdges = getVisualEdgesCss(
|
|
108
|
+
props.draggingEdge ? props.edges.filter((_) => !isEdgeEqual(props.draggingEdge, _)) : props.edges,
|
|
109
|
+
{
|
|
110
|
+
edgeWidth: `var(--layoutHandleWidth, 8px)`,
|
|
111
|
+
padLongAxis: `var(--layoutEdgeWidth, 2px)`
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
const thinEdges = getVisualEdgesCss(props.edges, {
|
|
115
|
+
edgeWidth: `var(--layoutEdgeWidth, 2px)`,
|
|
116
|
+
padLongAxis: `(var(--layoutEdgeWidth, 2px) + var(--layoutExtraDragEdgePadding, 0px))`
|
|
117
|
+
});
|
|
118
|
+
const edges = [];
|
|
119
|
+
for (let i = 0; i < thickEdges.length; i++) {
|
|
120
|
+
edges.push({ thin: thinEdges[i], thick: thickEdges[i] });
|
|
121
|
+
}
|
|
122
|
+
return edges;
|
|
123
|
+
});
|
|
124
|
+
const cssDragEdge = computed(() => {
|
|
125
|
+
if (!props.draggingEdge) return [];
|
|
126
|
+
return getVisualEdgesCss([props.draggingEdge], {
|
|
127
|
+
edgeWidth: `var(--layoutEdgeWidth, 2px)`,
|
|
128
|
+
padLongAxis: `(var(--layoutEdgeWidth, 2px) + var(--layoutExtraDragEdgePadding, 0px))`
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
const wantedIntersections = computed(
|
|
132
|
+
() => props.intersections.filter((_) => !_.isWindowEdge && (_.count === 4 || _.count === 1 && _.sharesEdge))
|
|
133
|
+
);
|
|
134
|
+
const cssDragIntersections = computed(() => {
|
|
135
|
+
const intersections = [];
|
|
136
|
+
const thick = getIntersectionsCss(wantedIntersections.value, {
|
|
137
|
+
intersectionWidth: `var(--layoutIntersectionWidth, 15px)`
|
|
138
|
+
});
|
|
139
|
+
const thin = getIntersectionsCss(wantedIntersections.value, {});
|
|
140
|
+
for (let i = 0; i < thick.length; i++) {
|
|
141
|
+
intersections.push({ thick: thick[i], thin: thin[i] });
|
|
142
|
+
}
|
|
143
|
+
return intersections;
|
|
144
|
+
});
|
|
145
|
+
</script>
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- @vue-expect-error just let it inherit extra attrs -->
|
|
3
|
+
<!-- overflow-hidden is just in case, if the frame's css is not properly set to h-full, overflow-auto, or the border/padding are too large, we can still get overflows -->
|
|
4
|
+
<LayoutShapeSquare
|
|
5
|
+
tabindex="0"
|
|
6
|
+
:css="getShapeSquareCss(frame)"
|
|
7
|
+
:class="twMerge(
|
|
8
|
+
`
|
|
9
|
+
frame
|
|
10
|
+
p-[var(--layoutEdgeWidth,_2px)]
|
|
11
|
+
overflow-hidden
|
|
12
|
+
`,
|
|
13
|
+
$attrs.class
|
|
14
|
+
)"
|
|
15
|
+
v-bind="{ ...$attrs, class: void 0 }"
|
|
16
|
+
@focus="emit('focus')"
|
|
17
|
+
>
|
|
18
|
+
<slot>
|
|
19
|
+
<div class="p-2 text-xs bg-neutral-500">
|
|
20
|
+
{{ debugFrame(frame) }}
|
|
21
|
+
</div>
|
|
22
|
+
<div>No slot found for `frame-{{ frame.id }}`. </div>
|
|
23
|
+
</slot>
|
|
24
|
+
</LayoutShapeSquare>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<script setup>
|
|
28
|
+
import { twMerge } from "@witchcraft/ui/utils/twMerge";
|
|
29
|
+
import {} from "vue";
|
|
30
|
+
import { useAttrs } from "vue";
|
|
31
|
+
const $attrs = useAttrs();
|
|
32
|
+
import LayoutShapeSquare from "./LayoutShapeSquare.vue";
|
|
33
|
+
import { getShapeSquareCss } from "../helpers/getShapeSquareCss";
|
|
34
|
+
import { debugFrame } from "../layout/debugFrame.js";
|
|
35
|
+
import {} from "../types/index.js";
|
|
36
|
+
const emit = defineEmits(["focus"]);
|
|
37
|
+
defineProps({
|
|
38
|
+
frame: { type: Object, required: true },
|
|
39
|
+
isActiveFrame: { type: Boolean, required: true }
|
|
40
|
+
});
|
|
41
|
+
</script>
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:style="`
|
|
4
|
+
--posX:${css.x};
|
|
5
|
+
--posY:${css.y};
|
|
6
|
+
--width:${css.width};
|
|
7
|
+
--height:${css.height};
|
|
8
|
+
${css.translate ? `--translate:${css.translate}` : ``}
|
|
9
|
+
` + style"
|
|
10
|
+
:class="twMerge(
|
|
11
|
+
`
|
|
12
|
+
absolute
|
|
13
|
+
w-[var(--width)]
|
|
14
|
+
h-[var(--height)]
|
|
15
|
+
top-[var(--posY)]
|
|
16
|
+
left-[var(--posX)]
|
|
17
|
+
`,
|
|
18
|
+
css.translate && `[transform:var(--translate)]`,
|
|
19
|
+
$attrs.class
|
|
20
|
+
)"
|
|
21
|
+
v-bind="{ ...$attrs, class: void 0 }"
|
|
22
|
+
>
|
|
23
|
+
<slot/>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<script setup>
|
|
28
|
+
import { twMerge } from "@witchcraft/ui/utils/twMerge";
|
|
29
|
+
import {} from "vue";
|
|
30
|
+
import { useAttrs } from "vue";
|
|
31
|
+
const $attrs = useAttrs();
|
|
32
|
+
const props = defineProps({
|
|
33
|
+
style: { type: String, required: false, default: "" },
|
|
34
|
+
css: { type: Object, required: true }
|
|
35
|
+
});
|
|
36
|
+
</script>
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- overflow hidden is because the borders inside will make it overflow -->
|
|
3
|
+
<div :class="twMerge(
|
|
4
|
+
`window
|
|
5
|
+
relative
|
|
6
|
+
overflow-hidden
|
|
7
|
+
`,
|
|
8
|
+
isDragging && `dragging cursor-pointer`,
|
|
9
|
+
requestType && `request-${requestType}`,
|
|
10
|
+
$attrs.attrs.class
|
|
11
|
+
)"
|
|
12
|
+
ref="windowEl"
|
|
13
|
+
v-bind="{ ...$attrs.attrs, class: void 0 }"
|
|
14
|
+
>
|
|
15
|
+
<template v-if="windowEl && win">
|
|
16
|
+
<LayoutFrameComponent :frame="frame"
|
|
17
|
+
:is-active-frame="frame.id === win.activeFrame"
|
|
18
|
+
v-for="frame of frames"
|
|
19
|
+
:key="frame.id"
|
|
20
|
+
v-bind="$attrs.frameAttrs"
|
|
21
|
+
@focus="windowSetActiveFrame(win, frame.id)"
|
|
22
|
+
>
|
|
23
|
+
<slot :name="`frame-${frame.id}`" v-bind="{ frame }"/>
|
|
24
|
+
</LayoutFrameComponent>
|
|
25
|
+
<LayoutEdgesComponent
|
|
26
|
+
:win="win"
|
|
27
|
+
:active-frame="win.activeFrame ? frames[win.activeFrame] : void 0"
|
|
28
|
+
:edges="visualEdges"
|
|
29
|
+
:intersections="intersections"
|
|
30
|
+
:dragging-edge="draggingEdges.length === 1 ? draggingEdges[0] : void 0"
|
|
31
|
+
:dragging-intersection="draggingIntersection"
|
|
32
|
+
v-bind="$attrs.edgesAttrs"
|
|
33
|
+
@drag-start="dragStart"
|
|
34
|
+
/>
|
|
35
|
+
<LayoutDecosComponent
|
|
36
|
+
:frames="frames"
|
|
37
|
+
:split-decos="splitDecos"
|
|
38
|
+
:close-decos="closeDecos"
|
|
39
|
+
v-bind="$attrs.decosAttrs"
|
|
40
|
+
/>
|
|
41
|
+
<slot name="extra-decos"/>
|
|
42
|
+
</template>
|
|
43
|
+
<Teleport v-if="instructionsTeleportTo && filteredUsageInstructions.length > 0" defer :to="instructionsTeleportTo">
|
|
44
|
+
<span aria-live="polite">
|
|
45
|
+
<span
|
|
46
|
+
class="
|
|
47
|
+
after:content-['┃']
|
|
48
|
+
after:text-accent-500
|
|
49
|
+
last:after:content-none
|
|
50
|
+
after:mx-1
|
|
51
|
+
after:text-gray-500
|
|
52
|
+
"
|
|
53
|
+
v-for="instruction of filteredUsageInstructions"
|
|
54
|
+
:key="instruction"
|
|
55
|
+
>
|
|
56
|
+
{{ instruction }}
|
|
57
|
+
</span>
|
|
58
|
+
</span>
|
|
59
|
+
</Teleport>
|
|
60
|
+
</div>
|
|
61
|
+
</template>
|
|
62
|
+
|
|
63
|
+
<script setup>
|
|
64
|
+
import { useDivideAttrs } from "@witchcraft/ui/composables/useDivideAttrs";
|
|
65
|
+
import { useGlobalResizeObserver } from "@witchcraft/ui/composables/useGlobalResizeObserver";
|
|
66
|
+
import { twMerge } from "@witchcraft/ui/utils/twMerge";
|
|
67
|
+
import { computed, ref, watch } from "vue";
|
|
68
|
+
import LayoutDecosComponent from "./LayoutDecos.vue";
|
|
69
|
+
import LayoutEdgesComponent from "./LayoutEdges.vue";
|
|
70
|
+
import LayoutFrameComponent from "./LayoutFrame.vue";
|
|
71
|
+
import { useFrames } from "../composables/useFrames.js";
|
|
72
|
+
import { CloseAction } from "../drag/CloseAction";
|
|
73
|
+
import { DragActionHandler } from "../drag/DragActionHandler";
|
|
74
|
+
import { SplitAction } from "../drag/SplitAction.js";
|
|
75
|
+
import {} from "../drag/types.js";
|
|
76
|
+
import { updateWindowWithEvent } from "../helpers/updateWindowSizeWithEvent.js";
|
|
77
|
+
import { windowSetActiveFrame } from "../layout/windowSetActiveFrame.js";
|
|
78
|
+
import {} from "../types/index.js";
|
|
79
|
+
const $attrs = useDivideAttrs(["frame", "edges", "decos"]);
|
|
80
|
+
const win = defineModel("win", { type: Object, ...{ required: true } });
|
|
81
|
+
const props = defineProps({
|
|
82
|
+
additionalDragActions: { type: Array, required: false, default: () => [] },
|
|
83
|
+
splitKeyHandler: { type: Function, required: false, default: void 0 },
|
|
84
|
+
closeKeyHandler: { type: Function, required: false, default: void 0 },
|
|
85
|
+
usageInstructions: { type: Object, required: false, default: () => ({}) },
|
|
86
|
+
instructionsTeleportTo: { type: null, required: true },
|
|
87
|
+
allowWindowSizeUpdate: { type: Boolean, required: false, default: true }
|
|
88
|
+
});
|
|
89
|
+
const emit = defineEmits(["isShowingDrag", "dragState"]);
|
|
90
|
+
const filteredUsageInstructions = computed(() => Object.values(props.usageInstructions).filter((_) => _ !== void 0).map((_) => _));
|
|
91
|
+
const splitKeyHandler = props.splitKeyHandler ?? ((e, state2) => e.altKey || state2.isDraggingFromWindowEdge);
|
|
92
|
+
const closeKeyHandler = props.closeKeyHandler ?? ((e) => {
|
|
93
|
+
if (e.ctrlKey && e.shiftKey) {
|
|
94
|
+
return "force";
|
|
95
|
+
}
|
|
96
|
+
if (e.shiftKey) return true;
|
|
97
|
+
return false;
|
|
98
|
+
});
|
|
99
|
+
const windowEl = ref(null);
|
|
100
|
+
const showDragging = ref(true);
|
|
101
|
+
const closeDecos = ref([]);
|
|
102
|
+
const splitDecos = ref([]);
|
|
103
|
+
const requestType = ref();
|
|
104
|
+
const dragActionHandler = new DragActionHandler(
|
|
105
|
+
(type, _e, state2) => type === "move" ? !state2.isDraggingFromWindowEdge : void 0,
|
|
106
|
+
[
|
|
107
|
+
new SplitAction(
|
|
108
|
+
splitKeyHandler,
|
|
109
|
+
((decos) => splitDecos.value = decos),
|
|
110
|
+
{
|
|
111
|
+
onStart: () => showDragging.value = false,
|
|
112
|
+
onCancel: () => showDragging.value = true
|
|
113
|
+
}
|
|
114
|
+
),
|
|
115
|
+
new CloseAction(
|
|
116
|
+
closeKeyHandler,
|
|
117
|
+
((decos) => closeDecos.value = decos)
|
|
118
|
+
),
|
|
119
|
+
...props.additionalDragActions
|
|
120
|
+
],
|
|
121
|
+
{
|
|
122
|
+
onEvent: (e, cancel) => {
|
|
123
|
+
showDragging.value = true;
|
|
124
|
+
if (e instanceof KeyboardEvent && e.key === "Escape") {
|
|
125
|
+
cancel();
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
onRequestChange: (type) => {
|
|
129
|
+
requestType.value = type;
|
|
130
|
+
},
|
|
131
|
+
onEnd: () => {
|
|
132
|
+
requestType.value = void 0;
|
|
133
|
+
showDragging.value = true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
const {
|
|
138
|
+
dragStart,
|
|
139
|
+
visualEdges,
|
|
140
|
+
isDragging,
|
|
141
|
+
draggingEdges,
|
|
142
|
+
draggingIntersection,
|
|
143
|
+
frames,
|
|
144
|
+
intersections,
|
|
145
|
+
state
|
|
146
|
+
} = useFrames(
|
|
147
|
+
win,
|
|
148
|
+
showDragging,
|
|
149
|
+
dragActionHandler
|
|
150
|
+
);
|
|
151
|
+
function getWindowOffset() {
|
|
152
|
+
const windowElRect = windowEl.value.getBoundingClientRect();
|
|
153
|
+
return {
|
|
154
|
+
pxX: Math.floor(windowElRect.x),
|
|
155
|
+
pxY: Math.floor(windowElRect.y)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function getWindowSize() {
|
|
159
|
+
const windowElRect = windowEl.value.getBoundingClientRect();
|
|
160
|
+
return {
|
|
161
|
+
pxWidth: Math.floor(windowElRect.width),
|
|
162
|
+
pxHeight: Math.floor(windowElRect.height)
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function updateWindowSize() {
|
|
166
|
+
if (!props.allowWindowSizeUpdate) return;
|
|
167
|
+
const newSize = { ...getWindowSize(), ...getWindowOffset() };
|
|
168
|
+
updateWindowWithEvent(win.value, newSize);
|
|
169
|
+
}
|
|
170
|
+
useGlobalResizeObserver(windowEl, updateWindowSize);
|
|
171
|
+
watch(() => props.allowWindowSizeUpdate, (newval, oldval) => {
|
|
172
|
+
if (oldval === false && newval === true) {
|
|
173
|
+
updateWindowSize();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
watch(state, () => emit("dragState", state.value));
|
|
177
|
+
watch(showDragging, () => emit("isShowingDrag", showDragging.value));
|
|
178
|
+
defineExpose({
|
|
179
|
+
state,
|
|
180
|
+
win,
|
|
181
|
+
updateWindowSize
|
|
182
|
+
});
|
|
183
|
+
</script>
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { debounce } from "@alanscodelog/utils/debounce";
|
|
2
|
+
import { keys } from "@alanscodelog/utils/keys";
|
|
3
|
+
import { computed, onBeforeUnmount, onMounted, ref, watchEffect } from "vue";
|
|
4
|
+
import { DragDirectionStore } from "../drag/DragDirectionStore.js";
|
|
5
|
+
import { cloneFrame } from "../helpers/cloneFrame.js";
|
|
6
|
+
import { getIntersections } from "../helpers/getIntersections.js";
|
|
7
|
+
import { getVisualEdges } from "../helpers/getVisualEdges.js";
|
|
8
|
+
import { isWindowEdge } from "../helpers/isWindowEdge.js";
|
|
9
|
+
import { moveEdge } from "../helpers/moveEdge.js";
|
|
10
|
+
import { toWindowCoord } from "../helpers/toWindowCoord.js";
|
|
11
|
+
import { findFramesTouchingEdge } from "../layout/findFramesTouchingEdge.js";
|
|
12
|
+
import { isPointInFrame } from "../layout/isPointInFrame.js";
|
|
13
|
+
export function useFrames(win, showDragging, handler) {
|
|
14
|
+
const draggingEdges = ref([]);
|
|
15
|
+
const touchingFrames = ref([]);
|
|
16
|
+
const allTouchingFrames = computed(() => {
|
|
17
|
+
const result = {};
|
|
18
|
+
for (const entry of touchingFrames.value) {
|
|
19
|
+
for (const frame of Object.values(entry)) {
|
|
20
|
+
result[frame.id] = frame;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
});
|
|
25
|
+
const touchingFramesArrays = computed(() => touchingFrames.value.map((entry) => Object.values(entry)));
|
|
26
|
+
const isDragging = ref(false);
|
|
27
|
+
const dragPoint = ref();
|
|
28
|
+
const dragDirections = ref({});
|
|
29
|
+
const draggingIntersection = ref(void 0);
|
|
30
|
+
const isDraggingFromWindowEdge = ref(false);
|
|
31
|
+
const frames = computed(
|
|
32
|
+
() => isDragging.value && showDragging.value ? { ...win.value.frames, ...allTouchingFrames.value } : win.value.frames
|
|
33
|
+
);
|
|
34
|
+
const dragHoveredFrame = computed(() => {
|
|
35
|
+
if (isDragging.value) {
|
|
36
|
+
for (const id of keys(frames.value)) {
|
|
37
|
+
if (isPointInFrame(frames.value[id], dragPoint.value)) {
|
|
38
|
+
return frames.value[id];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return void 0;
|
|
43
|
+
});
|
|
44
|
+
const visualEdges = ref([]);
|
|
45
|
+
const intersections = computed(() => getIntersections(visualEdges.value));
|
|
46
|
+
const debounceGetDraggableEdges = debounce((f) => {
|
|
47
|
+
visualEdges.value = getVisualEdges(f, { includeWindowEdges: true });
|
|
48
|
+
}, 50, {});
|
|
49
|
+
watchEffect(() => {
|
|
50
|
+
if (isDragging.value) return;
|
|
51
|
+
debounceGetDraggableEdges(Object.values(frames.value));
|
|
52
|
+
});
|
|
53
|
+
function forceRecalculateEdges() {
|
|
54
|
+
visualEdges.value = getVisualEdges(Object.values(frames.value), { includeWindowEdges: true });
|
|
55
|
+
}
|
|
56
|
+
const dragDirStore = new DragDirectionStore({
|
|
57
|
+
onUpdate: (dir) => dragDirections.value = dir
|
|
58
|
+
});
|
|
59
|
+
const state = computed(() => ({
|
|
60
|
+
dragDirections: dragDirections.value,
|
|
61
|
+
dragPoint: dragPoint.value,
|
|
62
|
+
isDragging: isDragging.value,
|
|
63
|
+
draggingEdges: draggingEdges.value,
|
|
64
|
+
draggingIntersection: draggingIntersection.value,
|
|
65
|
+
visualEdges: visualEdges.value,
|
|
66
|
+
touchingFrames: touchingFrames.value,
|
|
67
|
+
touchingFramesArrays: touchingFramesArrays.value,
|
|
68
|
+
frames: frames.value,
|
|
69
|
+
dragHoveredFrame: dragHoveredFrame.value,
|
|
70
|
+
intersections: intersections.value,
|
|
71
|
+
isDraggingFromWindowEdge: isDraggingFromWindowEdge.value,
|
|
72
|
+
win: win.value
|
|
73
|
+
}));
|
|
74
|
+
let controller;
|
|
75
|
+
function resetState() {
|
|
76
|
+
draggingEdges.value = [];
|
|
77
|
+
draggingIntersection.value = void 0;
|
|
78
|
+
isDragging.value = false;
|
|
79
|
+
dragPoint.value = void 0;
|
|
80
|
+
touchingFrames.value = [];
|
|
81
|
+
dragDirStore.reset();
|
|
82
|
+
forceRecalculateEdges();
|
|
83
|
+
}
|
|
84
|
+
function dragStart(e, { edge, intersection }) {
|
|
85
|
+
controller = new AbortController();
|
|
86
|
+
controller.signal.addEventListener("abort", () => resetState());
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
window.addEventListener("pointermove", dragMove, { signal: controller.signal });
|
|
89
|
+
window.addEventListener("pointerup", dragEnd, { signal: controller.signal });
|
|
90
|
+
const point = toWindowCoord(win.value, e);
|
|
91
|
+
dragPoint.value = point;
|
|
92
|
+
isDragging.value = true;
|
|
93
|
+
draggingIntersection.value = intersection;
|
|
94
|
+
draggingEdges.value = edge ? [edge] : [
|
|
95
|
+
...draggingIntersection.value?.sharedEdges.horizontal ?? [],
|
|
96
|
+
...draggingIntersection.value?.sharedEdges.vertical ?? []
|
|
97
|
+
];
|
|
98
|
+
dragDirStore.update(point);
|
|
99
|
+
isDraggingFromWindowEdge.value = draggingEdges.value.some((_) => isWindowEdge(_));
|
|
100
|
+
const framesArray = Object.values(win.value.frames);
|
|
101
|
+
touchingFrames.value = [];
|
|
102
|
+
const clones = /* @__PURE__ */ new Map();
|
|
103
|
+
for (let i = 0; i < draggingEdges.value.length; i++) {
|
|
104
|
+
const draggingEdge = draggingEdges.value[i];
|
|
105
|
+
touchingFrames.value[i] = {};
|
|
106
|
+
for (const { frame } of findFramesTouchingEdge(draggingEdge, framesArray)) {
|
|
107
|
+
if (!clones.has(frame.id)) {
|
|
108
|
+
const clone = cloneFrame(frame);
|
|
109
|
+
touchingFrames.value[i][frame.id] = clone;
|
|
110
|
+
clones.set(frame.id, clone);
|
|
111
|
+
} else {
|
|
112
|
+
touchingFrames.value[i][frame.id] = clones.get(frame.id);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
handler.onDragChange("start", e, state.value, forceRecalculateEdges, cancel);
|
|
117
|
+
}
|
|
118
|
+
function dragMove(e) {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
const point = toWindowCoord(win.value, e);
|
|
121
|
+
const didChange = dragDirStore.update(point);
|
|
122
|
+
dragPoint.value = point;
|
|
123
|
+
if (!didChange) return;
|
|
124
|
+
const allowed = handler.onDragChange("move", e, state.value, forceRecalculateEdges, cancel);
|
|
125
|
+
if (!allowed) return;
|
|
126
|
+
requestAnimationFrame(() => {
|
|
127
|
+
for (let i = 0; i < draggingEdges.value.length; i++) {
|
|
128
|
+
const draggingEdge = draggingEdges.value[i];
|
|
129
|
+
if (draggingEdge) {
|
|
130
|
+
moveEdge(touchingFramesArrays.value[i], draggingEdge, point);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
forceRecalculateEdges();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function dragEnd(e, { apply = true } = {}) {
|
|
137
|
+
if (e) {
|
|
138
|
+
const point = toWindowCoord(win.value, e);
|
|
139
|
+
dragPoint.value = point;
|
|
140
|
+
}
|
|
141
|
+
const doApply = apply && handler.onDragApply(state.value, forceRecalculateEdges);
|
|
142
|
+
if (doApply) {
|
|
143
|
+
for (const frame of touchingFramesArrays.value.flat()) {
|
|
144
|
+
win.value.frames[frame.id] = frame;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
handler.onDragChange("end", e, state.value, forceRecalculateEdges, cancel);
|
|
148
|
+
controller?.abort();
|
|
149
|
+
}
|
|
150
|
+
function cancel() {
|
|
151
|
+
dragEnd(void 0, { apply: false });
|
|
152
|
+
}
|
|
153
|
+
const keydownController = new AbortController();
|
|
154
|
+
const wrappedKeydownHandler = (e) => {
|
|
155
|
+
handler.eventHandler(e, state.value, forceRecalculateEdges);
|
|
156
|
+
};
|
|
157
|
+
onMounted(() => {
|
|
158
|
+
window.addEventListener("keydown", wrappedKeydownHandler, { signal: keydownController.signal });
|
|
159
|
+
window.addEventListener("keyup", wrappedKeydownHandler, { signal: keydownController.signal });
|
|
160
|
+
});
|
|
161
|
+
onBeforeUnmount(() => {
|
|
162
|
+
controller?.abort();
|
|
163
|
+
keydownController?.abort();
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
dragStart,
|
|
167
|
+
dragEnd,
|
|
168
|
+
cancel,
|
|
169
|
+
dragDirections,
|
|
170
|
+
dragPoint,
|
|
171
|
+
isDragging,
|
|
172
|
+
draggingEdges,
|
|
173
|
+
draggingIntersection,
|
|
174
|
+
visualEdges,
|
|
175
|
+
touchingFrames,
|
|
176
|
+
touchingFramesArrays,
|
|
177
|
+
frames,
|
|
178
|
+
dragHoveredFrame,
|
|
179
|
+
intersections,
|
|
180
|
+
isDraggingFromWindowEdge,
|
|
181
|
+
forceRecalculateEdges,
|
|
182
|
+
state
|
|
183
|
+
};
|
|
184
|
+
}
|
|
File without changes
|