@witchcraft/layout 0.3.0 → 0.4.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.
Files changed (167) hide show
  1. package/README.md +79 -74
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +6 -1
  4. package/dist/runtime/components/FrameDragHandle.vue +1 -1
  5. package/dist/runtime/components/LayoutDecosEdges.d.vue.ts +15 -0
  6. package/dist/runtime/components/LayoutDecosEdges.vue +34 -0
  7. package/dist/runtime/components/LayoutDecosEdges.vue.d.ts +15 -0
  8. package/dist/runtime/components/LayoutDecosRects.d.vue.ts +15 -0
  9. package/dist/runtime/components/LayoutDecosRects.vue +37 -0
  10. package/dist/runtime/components/LayoutDecosRects.vue.d.ts +15 -0
  11. package/dist/runtime/components/LayoutDragEdgeGrabbed.d.vue.ts +2 -0
  12. package/dist/runtime/components/LayoutDragEdgeGrabbed.vue +43 -0
  13. package/dist/runtime/components/LayoutDragEdgeGrabbed.vue.d.ts +2 -0
  14. package/dist/runtime/components/LayoutDragEdgeHandle.d.vue.ts +9 -0
  15. package/dist/runtime/components/LayoutDragEdgeHandle.vue +44 -0
  16. package/dist/runtime/components/LayoutDragEdgeHandle.vue.d.ts +9 -0
  17. package/dist/runtime/components/{LayoutDecos.d.vue.ts → LayoutDragEdgeVisible.d.vue.ts} +3 -2
  18. package/dist/runtime/components/LayoutDragEdgeVisible.vue +38 -0
  19. package/dist/runtime/components/{LayoutDecos.vue.d.ts → LayoutDragEdgeVisible.vue.d.ts} +3 -2
  20. package/dist/runtime/components/LayoutDragEdges.d.vue.ts +21 -0
  21. package/dist/runtime/components/LayoutDragEdges.vue +67 -0
  22. package/dist/runtime/components/LayoutDragEdges.vue.d.ts +21 -0
  23. package/dist/runtime/components/LayoutEdgesActiveFrame.d.vue.ts +2 -0
  24. package/dist/runtime/components/LayoutEdgesActiveFrame.vue +35 -0
  25. package/dist/runtime/components/LayoutEdgesActiveFrame.vue.d.ts +2 -0
  26. package/dist/runtime/components/LayoutFrame.d.vue.ts +7 -6
  27. package/dist/runtime/components/LayoutFrame.vue +18 -14
  28. package/dist/runtime/components/LayoutFrame.vue.d.ts +7 -6
  29. package/dist/runtime/components/LayoutIntersectionHandle.d.vue.ts +10 -0
  30. package/dist/runtime/components/LayoutIntersectionHandle.vue +36 -0
  31. package/dist/runtime/components/LayoutIntersectionHandle.vue.d.ts +10 -0
  32. package/dist/runtime/components/LayoutIntersectionVisible.d.vue.ts +6 -0
  33. package/dist/runtime/components/LayoutIntersectionVisible.vue +34 -0
  34. package/dist/runtime/components/LayoutIntersectionVisible.vue.d.ts +6 -0
  35. package/dist/runtime/components/LayoutIntersections.d.vue.ts +21 -0
  36. package/dist/runtime/components/LayoutIntersections.vue +52 -0
  37. package/dist/runtime/components/LayoutIntersections.vue.d.ts +21 -0
  38. package/dist/runtime/components/{LayoutShapeSquare.d.vue.ts → LayoutShapeRect.d.vue.ts} +2 -2
  39. package/dist/runtime/components/{LayoutShapeSquare.vue.d.ts → LayoutShapeRect.vue.d.ts} +2 -2
  40. package/dist/runtime/components/LayoutWindow.d.vue.ts +252 -14
  41. package/dist/runtime/components/LayoutWindow.vue +27 -48
  42. package/dist/runtime/components/LayoutWindow.vue.d.ts +252 -14
  43. package/dist/runtime/composables/useFrames.d.ts +859 -2
  44. package/dist/runtime/composables/useFrames.js +2 -0
  45. package/dist/runtime/demo/App.vue +122 -74
  46. package/dist/runtime/demo/DemoControls.vue +7 -5
  47. package/dist/runtime/demo/index.html +12 -0
  48. package/dist/runtime/demo/tailwind.css +1 -1
  49. package/dist/runtime/drag/CloseAction.d.ts +1 -2
  50. package/dist/runtime/drag/CloseAction.js +1 -1
  51. package/dist/runtime/drag/DragActionHandler.d.ts +5 -3
  52. package/dist/runtime/drag/DragActionHandler.js +40 -6
  53. package/dist/runtime/drag/FrameDragAction.js +6 -7
  54. package/dist/runtime/drag/SplitAction.d.ts +1 -2
  55. package/dist/runtime/drag/SplitAction.js +1 -1
  56. package/dist/runtime/drag/createDefaultHandlers.d.ts +1 -1
  57. package/dist/runtime/drag/defaultDragActions.d.ts +1 -1
  58. package/dist/runtime/helpers/consoleDebugWindow.d.ts +43 -0
  59. package/dist/runtime/helpers/consoleDebugWindow.js +222 -0
  60. package/dist/runtime/helpers/convertLayoutWindowToWorkspace.js +2 -2
  61. package/dist/runtime/helpers/framesRedistributeFix.d.ts +87 -0
  62. package/dist/runtime/helpers/framesRedistributeFix.js +54 -0
  63. package/dist/runtime/helpers/getMoveEdgeInfo.d.ts +6 -2
  64. package/dist/runtime/helpers/getMoveEdgeInfo.js +11 -2
  65. package/dist/runtime/helpers/getPinnedEdgesForCollapsedFrames.d.ts +5 -0
  66. package/dist/runtime/helpers/getPinnedEdgesForCollapsedFrames.js +18 -0
  67. package/dist/runtime/helpers/getShapeRectCss.d.ts +7 -0
  68. package/dist/runtime/helpers/{getShapeSquareCss.js → getShapeRectCss.js} +1 -1
  69. package/dist/runtime/helpers/index.d.ts +3 -3
  70. package/dist/runtime/helpers/index.js +3 -3
  71. package/dist/runtime/helpers/moveEdge.js +3 -1
  72. package/dist/runtime/helpers/pxSizeToScaledSize.d.ts +2 -0
  73. package/dist/runtime/helpers/{numberToScaledSize.js → pxSizeToScaledSize.js} +1 -1
  74. package/dist/runtime/helpers/updateWindowSizeWithEvent.d.ts +3 -0
  75. package/dist/runtime/helpers/validateLayoutShape.d.ts +5 -0
  76. package/dist/runtime/helpers/validateLayoutShape.js +28 -0
  77. package/dist/runtime/layout/applyFrameChanges.js +6 -0
  78. package/dist/runtime/layout/createSplitDecoShapes.js +1 -1
  79. package/dist/runtime/layout/getFrameCollapseInfo.d.ts +5 -2
  80. package/dist/runtime/layout/getFrameCollapseInfo.js +16 -46
  81. package/dist/runtime/layout/getFrameDockInfo.d.ts +1 -1
  82. package/dist/runtime/layout/getFrameDockInfo.js +5 -1
  83. package/dist/runtime/layout/getFrameUncollapseInfo.d.ts +5 -2
  84. package/dist/runtime/layout/getFrameUncollapseInfo.js +16 -50
  85. package/dist/runtime/layout/getFramesRedistributeInfo.d.ts +20 -4
  86. package/dist/runtime/layout/getFramesRedistributeInfo.js +31 -2
  87. package/dist/runtime/layout/getRelaxFramesInfo.d.ts +7 -0
  88. package/dist/runtime/layout/getRelaxFramesInfo.js +91 -0
  89. package/dist/runtime/layout/getUpdateWindowSizeInfo.d.ts +13 -0
  90. package/dist/runtime/layout/getUpdateWindowSizeInfo.js +65 -0
  91. package/dist/runtime/layout/index.d.ts +1 -0
  92. package/dist/runtime/layout/index.js +1 -0
  93. package/dist/runtime/layout/resizeFrame.js +1 -3
  94. package/dist/runtime/settings.d.ts +26 -19
  95. package/dist/runtime/settings.js +57 -22
  96. package/dist/runtime/types/index.d.ts +1243 -30
  97. package/dist/runtime/types/index.js +22 -8
  98. package/dist/runtime/types/vue.d.ts +41 -0
  99. package/dist/runtime/{drag/types.js → types/vue.js} +1 -0
  100. package/dist/runtime/utils/cssToKey.d.ts +5 -0
  101. package/dist/runtime/utils/cssToKey.js +3 -0
  102. package/package.json +11 -12
  103. package/src/module.ts +6 -1
  104. package/src/runtime/components/FrameDragHandle.vue +1 -1
  105. package/src/runtime/components/LayoutDecosEdges.vue +38 -0
  106. package/src/runtime/components/LayoutDecosRects.vue +42 -0
  107. package/src/runtime/components/LayoutDragEdgeGrabbed.vue +50 -0
  108. package/src/runtime/components/LayoutDragEdgeHandle.vue +52 -0
  109. package/src/runtime/components/LayoutDragEdgeVisible.vue +45 -0
  110. package/src/runtime/components/LayoutDragEdges.vue +78 -0
  111. package/src/runtime/components/LayoutEdgesActiveFrame.vue +43 -0
  112. package/src/runtime/components/LayoutFrame.vue +22 -15
  113. package/src/runtime/components/LayoutIntersectionHandle.vue +45 -0
  114. package/src/runtime/components/LayoutIntersectionVisible.vue +41 -0
  115. package/src/runtime/components/LayoutIntersections.vue +64 -0
  116. package/src/runtime/components/{LayoutShapeSquare.vue → LayoutShapeRect.vue} +2 -2
  117. package/src/runtime/components/LayoutWindow.vue +29 -49
  118. package/src/runtime/composables/useFrames.ts +7 -2
  119. package/src/runtime/demo/App.vue +128 -78
  120. package/src/runtime/demo/DemoControls.vue +7 -5
  121. package/src/runtime/demo/index.html +12 -0
  122. package/src/runtime/demo/tailwind.css +3 -0
  123. package/src/runtime/drag/CloseAction.ts +2 -3
  124. package/src/runtime/drag/DragActionHandler.ts +48 -10
  125. package/src/runtime/drag/FrameDragAction.ts +4 -5
  126. package/src/runtime/drag/SplitAction.ts +4 -3
  127. package/src/runtime/drag/createDefaultHandlers.ts +2 -1
  128. package/src/runtime/drag/defaultDragActions.ts +2 -1
  129. package/src/runtime/helpers/consoleDebugWindow.ts +331 -0
  130. package/src/runtime/helpers/convertLayoutWindowToWorkspace.ts +2 -2
  131. package/src/runtime/helpers/framesRedistributeFix.ts +162 -0
  132. package/src/runtime/helpers/getMoveEdgeInfo.ts +22 -5
  133. package/src/runtime/helpers/getPinnedEdgesForCollapsedFrames.ts +29 -0
  134. package/src/runtime/helpers/{getShapeSquareCss.ts → getShapeRectCss.ts} +3 -3
  135. package/src/runtime/helpers/index.ts +4 -3
  136. package/src/runtime/helpers/moveEdge.ts +3 -1
  137. package/src/runtime/helpers/{numberToScaledSize.ts → pxSizeToScaledSize.ts} +2 -2
  138. package/src/runtime/helpers/updateWindowSizeWithEvent.ts +3 -0
  139. package/src/runtime/helpers/validateLayoutShape.ts +46 -0
  140. package/src/runtime/layout/applyFrameChanges.ts +5 -0
  141. package/src/runtime/layout/createSplitDecoShapes.ts +1 -1
  142. package/src/runtime/layout/getFrameCollapseInfo.ts +26 -85
  143. package/src/runtime/layout/getFrameDockInfo.ts +8 -1
  144. package/src/runtime/layout/getFrameUncollapseInfo.ts +29 -96
  145. package/src/runtime/layout/getFramesRedistributeInfo.ts +60 -5
  146. package/src/runtime/layout/getRelaxFramesInfo.ts +139 -0
  147. package/src/runtime/layout/getUpdateWindowSizeInfo.ts +105 -0
  148. package/src/runtime/layout/index.ts +1 -0
  149. package/src/runtime/layout/resizeFrame.ts +4 -3
  150. package/src/runtime/settings.ts +78 -25
  151. package/src/runtime/types/index.ts +205 -33
  152. package/src/runtime/types/vue.ts +41 -0
  153. package/src/runtime/utils/cssToKey.ts +8 -0
  154. package/dist/runtime/components/LayoutDecos.vue +0 -26
  155. package/dist/runtime/components/LayoutEdges.d.vue.ts +0 -17
  156. package/dist/runtime/components/LayoutEdges.vue +0 -144
  157. package/dist/runtime/components/LayoutEdges.vue.d.ts +0 -17
  158. package/dist/runtime/drag/types.d.ts +0 -161
  159. package/dist/runtime/helpers/clampNumber.d.ts +0 -1
  160. package/dist/runtime/helpers/clampNumber.js +0 -3
  161. package/dist/runtime/helpers/getShapeSquareCss.d.ts +0 -7
  162. package/dist/runtime/helpers/numberToScaledSize.d.ts +0 -2
  163. package/src/runtime/components/LayoutDecos.vue +0 -28
  164. package/src/runtime/components/LayoutEdges.vue +0 -170
  165. package/src/runtime/drag/types.ts +0 -177
  166. package/src/runtime/helpers/clampNumber.ts +0 -9
  167. /package/dist/runtime/components/{LayoutShapeSquare.vue → LayoutShapeRect.vue} +0 -0
@@ -1,144 +0,0 @@
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
- $attrs.class
14
- )"
15
- v-bind="{ ...$attrs, class: void 0 }"
16
- />
17
-
18
- <template
19
- v-for="css, i of cssDragEdges"
20
- :key="i"
21
- >
22
- <LayoutShapeSquare
23
- :css="css.thick"
24
- :class="twMerge(`
25
- drag-edge
26
- z-20
27
- hover:cursor-pointer
28
- [&:hover+.edge]:bg-blue-500/50
29
- `)"
30
- @pointerdown="emit('dragStart', $event, 'edge', { edge: edges[i] })"
31
- />
32
- <LayoutShapeSquare
33
- :css="css.thin"
34
- :class="twMerge(`
35
- pointer-events-none
36
- edge
37
- `)"
38
- />
39
- </template>
40
- <LayoutShapeSquare
41
- :css="css"
42
- :class="twMerge(`
43
- grabbed-edge
44
- z-20
45
- bg-blue-500/50
46
- cursor-pointer
47
- `)"
48
- v-for="css, i of cssDragEdge"
49
- :key="i"
50
- />
51
- <template
52
- v-for="css, i of cssDragIntersections"
53
- :key="i"
54
- >
55
- <LayoutShapeSquare
56
- :css="css.thick"
57
- :class="twMerge(
58
- `
59
- drag-intersection
60
- z-30
61
- rounded-full
62
- hover:cursor-pointer
63
- [&:hover+.intersection]:bg-blue-500/50
64
- `
65
- )"
66
- @pointerdown="emit('dragStart', $event, 'edge', { intersection: wantedIntersections[i] })"
67
- />
68
- <LayoutShapeSquare
69
- :css="css.thin"
70
- :class="twMerge(
71
- `
72
- intersection
73
- z-30
74
- rounded-full
75
- pointer-events-none
76
- `,
77
- css.thin._shifted && `w-[7px] h-[7px]`
78
- )"
79
- />
80
- </template>
81
- </template>
82
-
83
- <script setup>
84
- import { twMerge } from "@witchcraft/ui/utils/twMerge";
85
- import { computed, useAttrs } from "vue";
86
- import LayoutShapeSquare from "./LayoutShapeSquare.vue";
87
- import { getIntersectionsCss } from "../helpers/getIntersectionsCss.js";
88
- import { getShapeSquareCss } from "../helpers/getShapeSquareCss.js";
89
- import { getVisualEdgesCss } from "../helpers/getVisualEdgesCss.js";
90
- import { isEdgeEqual } from "../helpers/isEdgeEqual.js";
91
- const $attrs = useAttrs();
92
- defineOptions({
93
- inheritAttrs: false
94
- });
95
- const emit = defineEmits(["dragStart"]);
96
- const props = defineProps({
97
- edges: { type: Array, required: true },
98
- intersections: { type: Array, required: true },
99
- win: { type: Object, required: true },
100
- activeFrame: { type: Object, required: false, default: void 0 },
101
- draggingEdge: { type: null, required: false, default: void 0 },
102
- draggingIntersection: { type: Object, required: false, default: void 0 },
103
- css: { type: Object, required: false }
104
- });
105
- const cssDragEdges = computed(() => {
106
- const thickEdges = getVisualEdgesCss(
107
- props.draggingEdge ? props.edges.filter((_) => !isEdgeEqual(props.draggingEdge, _)) : props.edges,
108
- {
109
- edgeWidth: `var(--layoutHandleWidth, 8px)`,
110
- padLongAxis: `var(--layoutEdgeWidth, 2px)`
111
- }
112
- );
113
- const thinEdges = getVisualEdgesCss(props.edges, {
114
- edgeWidth: `var(--layoutEdgeWidth, 2px)`,
115
- padLongAxis: `(var(--layoutEdgeWidth, 2px) + var(--layoutExtraDragEdgePadding, 0px))`
116
- });
117
- const edges = [];
118
- for (let i = 0; i < thickEdges.length; i++) {
119
- edges.push({ thin: thinEdges[i], thick: thickEdges[i] });
120
- }
121
- return edges;
122
- });
123
- const cssDragEdge = computed(() => {
124
- if (!props.draggingEdge) return [];
125
- return getVisualEdgesCss([props.draggingEdge], {
126
- edgeWidth: `var(--layoutEdgeWidth, 2px)`,
127
- padLongAxis: `(var(--layoutEdgeWidth, 2px) + var(--layoutExtraDragEdgePadding, 0px))`
128
- });
129
- });
130
- const wantedIntersections = computed(
131
- () => props.intersections.filter((_) => !_.isWindowEdge && (_.count === 4 || _.count === 1 && _.sharesEdge))
132
- );
133
- const cssDragIntersections = computed(() => {
134
- const intersections = [];
135
- const thick = getIntersectionsCss(wantedIntersections.value, {
136
- intersectionWidth: `var(--layoutIntersectionWidth, 15px)`
137
- });
138
- const thin = getIntersectionsCss(wantedIntersections.value, {});
139
- for (let i = 0; i < thick.length; i++) {
140
- intersections.push({ thick: thick[i], thin: thin[i] });
141
- }
142
- return intersections;
143
- });
144
- </script>
@@ -1,17 +0,0 @@
1
- import type { Edge, IntersectionEntry, LayoutEdgesProps } from "../types/index.js";
2
- declare const _default: import("vue").DefineComponent<LayoutEdgesProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
3
- dragStart: (e: PointerEvent, type: "edge", opts: {
4
- edge?: Edge;
5
- intersection?: IntersectionEntry;
6
- }) => any;
7
- }, string, import("vue").PublicProps, Readonly<LayoutEdgesProps> & Readonly<{
8
- onDragStart?: ((e: PointerEvent, type: "edge", opts: {
9
- edge?: Edge;
10
- intersection?: IntersectionEntry;
11
- }) => any) | undefined;
12
- }>, {
13
- activeFrame: import("../types/index.js").LayoutFrame;
14
- draggingEdge: Edge;
15
- draggingIntersection: IntersectionEntry;
16
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
17
- export default _default;
@@ -1,161 +0,0 @@
1
- import type { ComputedRef, InjectionKey, Ref } from "vue";
2
- import type { Direction, Edge, FrameId, IntersectionEntry, LayoutFrame, LayoutShape, LayoutWindow, Orientation, Point } from "../types/index.js";
3
- export type DragState = {
4
- /** The current directions in the corresponding orientations that the user is dragging in. */
5
- dragDirections: Record<Orientation, Direction | undefined>;
6
- /** The curren point (in scaled window coordinates) the user is dragging at. */
7
- dragPoint?: Point;
8
- /** Whether the user is currently dragging and what type of drag. Is truthy string during all drag events. */
9
- isDragging: boolean | "frame" | "edge";
10
- /** Whether to show the moved frames while dragging. */
11
- showDragging: boolean;
12
- /** The frame being dragged during a frame drag. Only set when isDragging is "frame". */
13
- draggingFrameId?: FrameId;
14
- /**
15
- * The edges that are currently being dragged. There are multiple edges if they drag an intersection since what's actually happening is we're just dragging the closest horizontal and vertical edges.
16
- */
17
- draggingEdges: Edge[];
18
- /**
19
- * The intersection that is currently being dragged.
20
- */
21
- draggingIntersection?: IntersectionEntry;
22
- /** The "visual" edges that can be displayed for dragging. See {@link getVisualEdges} */
23
- visualEdges: Edge[];
24
- /**
25
- * The frames touching the currently dragged edges. Each entry corresponds to the frames touching the corresponding dragging edge.
26
- *
27
- * So you can use the index in draggingEdges to get the corresponding frames.
28
- */
29
- touchingFrames: Record<string, LayoutFrame>[];
30
- /**
31
- * Same as touchingFrames, but with the frames in an array.
32
- */
33
- touchingFramesArrays: LayoutFrame[][];
34
- /**
35
- * All the frames, with/without the currently dragged frames depending on if `showDragging` is true.
36
- */
37
- frames: Record<string, LayoutFrame>;
38
- /**
39
- * The frame that is currently being hovered over (according to whether `dragPoint` in in the frame or not).
40
- */
41
- dragHoveredFrame: LayoutFrame | undefined;
42
- /**
43
- * A list of corner intersections. Frames can also be dragged by these.
44
- */
45
- intersections: IntersectionEntry[];
46
- /**
47
- * Whether the drag was initiated from a point along the window edge.
48
- */
49
- isDraggingFromWindowEdge: boolean;
50
- win: LayoutWindow;
51
- };
52
- export interface ActionDragChangeResult {
53
- /** Whether the drag should update the edges. Defaults to false. */
54
- updateEdges?: boolean;
55
- /** Deco shapes produced by this action during this drag step. */
56
- shapes: LayoutShape[];
57
- /** Whether to show the moved edges while dragging. Defaults to true. */
58
- showDragging?: boolean;
59
- }
60
- export type DragChangeResult = Omit<ActionDragChangeResult, "shapes">;
61
- /**
62
- * Called when the drag coordinates change (during any event).
63
- *
64
- * Should return `{ allowed: true/false, shapes: LayoutShape[] }` to control whether the action is allowed and edges update and what deco shapes to render.
65
- *
66
- * Note that the allowed return type only affect the `move` event but is also typed as `boolean` for other events for ease of use.
67
- */
68
- export type DragChangeHandler = <T extends "start" | "move" | "end">(type: T, e: T extends "end" ? PointerEvent | undefined : PointerEvent, state: DragState, forceRecalculateEdges: () => void, cancel: (e: PointerEvent | KeyboardEvent | undefined, state: DragState) => void) => ActionDragChangeResult;
69
- /**
70
- * A drag action describes when and how to handle a drag event.
71
- *
72
- * For example, there are the default split/close actions that can be triggered in certain situations. This could be when holding down a modifier or key, or some other condition (e.g. the user is dragging a specific edge).
73
- *
74
- * Each action should handle it's configuration and saving/caching any state it needs. See {@link SplitAction} and {@link CloseAction} for examples.
75
- */
76
- export interface IDragAction {
77
- /** A unique name for your action. */
78
- name: string;
79
- onDragChange: DragChangeHandler;
80
- /**
81
- *
82
- * Is called after `onDragChange("end")` with the same event. Might not be called if the request was cancelled.
83
- *
84
- * You should apply your action if possible and return whether it was applied.
85
- *
86
- * This is also a good place to reset your state.
87
- */
88
- onDragApply: (state: DragState, forceRecalculateEdges: () => void) => boolean;
89
- /**
90
- * Should return true if it should handle the "request"/event (e.g. some modifier is being pressed => user is requesting x action).
91
- *
92
- * The user is not necessarily dragging at this point, though they might also change actions mid drag. So it does not necessarily mean the event is allowed.
93
- *
94
- * Here is where you should initiate your state. Don't allow the action by default unless it can always be allowed.
95
- */
96
- canHandleRequest(e: KeyboardEvent | PointerEvent, state: DragState, forceRecalculateEdges: () => void): boolean;
97
- /**
98
- * Called when a user cancels the drag action.
99
- *
100
- * You should reset your state here.
101
- */
102
- cancel(e: PointerEvent | KeyboardEvent | undefined, state: DragState): void;
103
- /**
104
- * Plugins should implement some basic debug logs by calling {@link DragActionHandler.debugState } at least before and after applying actions in onDragApply. Debug can be a string because it can be an object key to filter on (see the debugState function).
105
- *
106
- *
107
- * Calls look like this usually, where this.state is the plugin state:
108
- * ```ts
109
- * DragActionHandler.debugState(this.name, "before", state, this.state, this.debug)
110
- * ```
111
- */
112
- debug: boolean | string;
113
- /**
114
- * The action handler will call this regardless of whether the action is active or not.
115
- *
116
- * Can be used by actions to return display hints.
117
- *
118
- * Actions should keep the state of the hints locally and update them in canHandlerRequest/onDrag*, etc. and only use this to return the state of the actions, not update them as that could become expensive.
119
- */
120
- getTextHints(type: "start" | "move" | "end"): {
121
- /** Hint texts to display regarding the action state/usage. Undefined means no hint. */
122
- actions?: string[];
123
- /** Error texts/hints to display when the action produces an error. */
124
- errors?: string[];
125
- };
126
- }
127
- export type EdgeDragStartData = {
128
- edge?: Edge;
129
- intersection?: IntersectionEntry;
130
- };
131
- export type FrameDragStartData = {
132
- frameId: FrameId;
133
- };
134
- export type DragStartFn = {
135
- (e: PointerEvent, type: "edge", data: EdgeDragStartData): void;
136
- (e: PointerEvent, type: "frame", data: FrameDragStartData): void;
137
- };
138
- export interface UseFramesContext {
139
- dragStart: DragStartFn;
140
- dragMove: (e: PointerEvent) => void;
141
- dragEnd: (e?: PointerEvent, options?: {
142
- apply?: boolean;
143
- }) => void;
144
- cancel: () => void;
145
- dragDirections: Ref<Record<Orientation, Direction | undefined>>;
146
- dragPoint: Ref<Point | undefined>;
147
- isDragging: Ref<false | "frame" | "edge">;
148
- draggingEdges: Ref<Edge[]>;
149
- draggingIntersection: Ref<IntersectionEntry | undefined>;
150
- visualEdges: Ref<Edge[]>;
151
- touchingFrames: Ref<Record<string, LayoutFrame>[]>;
152
- touchingFramesArrays: Ref<LayoutFrame[][]>;
153
- frames: ComputedRef<Record<string, LayoutFrame>>;
154
- dragHoveredFrame: ComputedRef<LayoutFrame | undefined>;
155
- intersections: ComputedRef<IntersectionEntry[]>;
156
- isDraggingFromWindowEdge: Ref<boolean>;
157
- forceRecalculateEdges: () => void;
158
- state: ComputedRef<DragState>;
159
- frameDragFrameId: Ref<FrameId | undefined>;
160
- }
161
- export declare const dragContextInjectionKey: InjectionKey<UseFramesContext>;
@@ -1 +0,0 @@
1
- export declare function clampNumber(num: number, lowerLimit: number, upperLimit: number): number;
@@ -1,3 +0,0 @@
1
- export function clampNumber(num, lowerLimit, upperLimit) {
2
- return num <= lowerLimit ? lowerLimit : num >= upperLimit ? upperLimit : num;
3
- }
@@ -1,7 +0,0 @@
1
- import type { BaseSquare } from "../types/index.js";
2
- export declare function getShapeSquareCss(obj: BaseSquare, pad?: string): {
3
- x: string;
4
- y: string;
5
- width: string;
6
- height: string;
7
- };
@@ -1,2 +0,0 @@
1
- import type { LayoutWindow, PxSize, Size } from "../types/index.js";
2
- export declare function numberToScaledSize(win: LayoutWindow, size: PxSize | number, scale?: number): Size;
@@ -1,28 +0,0 @@
1
- <template>
2
- <template
3
- v-for="(shape, i) of shapes"
4
- :key="`${shape.type}-${i}`"
5
- >
6
- <LayoutShapeSquare
7
- v-if="shape.type === 'square'"
8
- :css="getShapeSquareCss(shape.data, `var(--layoutEdgeWidth,2px)`)"
9
- v-bind="shape.attrs ?? {}"
10
- />
11
- <LayoutShapeSquare
12
- v-else-if="shape.type === 'edge'"
13
- :css="getVisualEdgeCss(shape.data, { padLongAxis: 'var(--layoutEdgeWidth,2px)' })"
14
- v-bind="shape.attrs ?? {}"
15
- />
16
- </template>
17
- </template>
18
- <script lang="ts" setup>
19
- import LayoutShapeSquare from "./LayoutShapeSquare.vue"
20
-
21
- import { getShapeSquareCss } from "../helpers/getShapeSquareCss"
22
- import { getVisualEdgeCss } from "../helpers/getVisualEdgeCss"
23
- import type { LayoutShape } from "../types/index.js"
24
-
25
- defineProps<{
26
- shapes: LayoutShape[]
27
- }>()
28
- </script>
@@ -1,170 +0,0 @@
1
- <template>
2
- <LayoutShapeSquare
3
- v-if="activeFrame"
4
- :css="getShapeSquareCss(activeFrame, `var(--layoutEdgeWidth,2px)`)"
5
- :class="twMerge(`
6
- active-frame-edge
7
- pointer-events-none
8
- z-0
9
- border-blue-500
10
- border
11
- `,
12
- ($attrs as any).class
13
- )"
14
- v-bind="{ ...$attrs, class: undefined }"
15
- />
16
-
17
- <template
18
- v-for="css, i of cssDragEdges"
19
- :key="i"
20
- >
21
- <LayoutShapeSquare
22
- :css="css.thick"
23
- :class="twMerge(`
24
- drag-edge
25
- z-20
26
- hover:cursor-pointer
27
- [&:hover+.edge]:bg-blue-500/50
28
- `)"
29
- @pointerdown="emit('dragStart', $event, 'edge', { edge: edges[i] })"
30
- />
31
- <LayoutShapeSquare
32
- :css="css.thin"
33
- :class="twMerge(`
34
- pointer-events-none
35
- edge
36
- `)"
37
- />
38
- </template>
39
- <LayoutShapeSquare
40
- :css="css"
41
- :class="twMerge(`
42
- grabbed-edge
43
- z-20
44
- bg-blue-500/50
45
- cursor-pointer
46
- `)"
47
- v-for="css, i of cssDragEdge"
48
- :key="i"
49
- />
50
- <template
51
- v-for="css, i of cssDragIntersections"
52
- :key="i"
53
- >
54
- <LayoutShapeSquare
55
- :css="css.thick"
56
- :class="twMerge(`
57
- drag-intersection
58
- z-30
59
- rounded-full
60
- hover:cursor-pointer
61
- [&:hover+.intersection]:bg-blue-500/50
62
- `
63
- )"
64
- @pointerdown="emit('dragStart', $event, 'edge', { intersection: wantedIntersections[i] })"
65
- />
66
- <LayoutShapeSquare
67
- :css="css.thin"
68
- :class="twMerge(`
69
- intersection
70
- z-30
71
- rounded-full
72
- pointer-events-none
73
- `,
74
- css.thin._shifted && `w-[7px] h-[7px]`
75
- )"
76
- />
77
- </template>
78
- </template>
79
-
80
- <script lang="ts" setup>
81
- import { twMerge } from "@witchcraft/ui/utils/twMerge"
82
- import { computed, useAttrs } from "vue"
83
-
84
- import LayoutShapeSquare from "./LayoutShapeSquare.vue"
85
-
86
- import { getIntersectionsCss } from "../helpers/getIntersectionsCss.js"
87
- import { getShapeSquareCss } from "../helpers/getShapeSquareCss.js"
88
- import { getVisualEdgesCss } from "../helpers/getVisualEdgesCss.js"
89
- import { isEdgeEqual } from "../helpers/isEdgeEqual.js"
90
- import type {
91
- Edge,
92
- EdgeCss,
93
- IntersectionEntry,
94
- LayoutEdgesProps
95
- } from "../types/index.js"
96
-
97
- const $attrs = useAttrs()
98
-
99
- defineOptions({
100
- inheritAttrs: false
101
- })
102
-
103
- const emit = defineEmits<{
104
- dragStart: [e: PointerEvent, type:"edge", opts:{ edge?: Edge, intersection?: IntersectionEntry }]
105
- }>()
106
-
107
- const props = withDefaults(defineProps<LayoutEdgesProps>(), {
108
- activeFrame: undefined,
109
- draggingEdge: undefined,
110
- draggingIntersection: undefined
111
- })
112
-
113
-
114
- // const activeFrameCssEdges = computed(() => {
115
- // if (!props.activeFrame) return []
116
- // return getVisualEdgesCss(Object.values(frameToEdges(props.activeFrame)), {
117
- // edgeWidth: `var(--layoutEdgeWidth, 2px)`,
118
- // })
119
- // })
120
-
121
- const cssDragEdges = computed(() => {
122
- const thickEdges = getVisualEdgesCss(
123
- props.draggingEdge
124
- ? props.edges.filter(_ => !isEdgeEqual(props.draggingEdge!, _))
125
- : props.edges,
126
- {
127
- edgeWidth: `var(--layoutHandleWidth, 8px)`,
128
- padLongAxis: `var(--layoutEdgeWidth, 2px)`
129
- }
130
- )
131
- const thinEdges = getVisualEdgesCss(props.edges, {
132
- edgeWidth: `var(--layoutEdgeWidth, 2px)`,
133
- padLongAxis: `(var(--layoutEdgeWidth, 2px) + var(--layoutExtraDragEdgePadding, 0px))`
134
- })
135
- const edges: { thin: EdgeCss, thick: EdgeCss }[] = []
136
- for (let i = 0; i < thickEdges.length; i++) {
137
- edges.push({ thin: thinEdges[i], thick: thickEdges[i] })
138
- }
139
- return edges
140
- })
141
-
142
- const cssDragEdge = computed(() => {
143
- if (!props.draggingEdge) return []
144
- return getVisualEdgesCss([props.draggingEdge], {
145
- edgeWidth: `var(--layoutEdgeWidth, 2px)`,
146
- padLongAxis: `(var(--layoutEdgeWidth, 2px) + var(--layoutExtraDragEdgePadding, 0px))`
147
- })
148
- })
149
-
150
-
151
- const wantedIntersections = computed(() => props.intersections
152
- .filter(_ => !_.isWindowEdge && (_.count === 4 || (_.count === 1 && _.sharesEdge)))
153
- )
154
- const cssDragIntersections = computed(() => {
155
- const intersections: {
156
- thick: ReturnType<typeof getIntersectionsCss>[number]
157
- thin: ReturnType<typeof getIntersectionsCss>[number]
158
- }[] = []
159
- const thick = getIntersectionsCss(wantedIntersections.value, {
160
- intersectionWidth: `var(--layoutIntersectionWidth, 15px)`
161
- })
162
- const thin = getIntersectionsCss(wantedIntersections.value, {
163
- })
164
- for (let i = 0; i < thick.length; i++) {
165
- intersections.push({ thick: thick[i], thin: thin[i] })
166
- }
167
- return intersections
168
- })
169
- </script>
170
-