@vuu-ui/grid-layout 4.0.0-alpha.1

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 (142) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +141 -0
  3. package/package.json +40 -0
  4. package/src/GridCommand.js +395 -0
  5. package/src/GridComponentSettings.js +163 -0
  6. package/src/GridController.js +359 -0
  7. package/src/GridDragCoordinator.js +293 -0
  8. package/src/GridGeometry.js +1298 -0
  9. package/src/GridLayout.css.js +119 -0
  10. package/src/GridLayout.js +120 -0
  11. package/src/GridLayoutContext.js +58 -0
  12. package/src/GridLayoutDocument.js +307 -0
  13. package/src/GridLayoutDocumentIds.js +110 -0
  14. package/src/GridLayoutItem.css.js +46 -0
  15. package/src/GridLayoutItem.js +147 -0
  16. package/src/GridLayoutLegacyCompatibility.js +66 -0
  17. package/src/GridLayoutModel.js +138 -0
  18. package/src/GridLayoutProvider.js +263 -0
  19. package/src/GridLayoutStackedItem.css.js +26 -0
  20. package/src/GridLayoutStackedtem.js +140 -0
  21. package/src/GridModel.js +1289 -0
  22. package/src/GridPlaceholder.css.js +9 -0
  23. package/src/GridPlaceholder.js +24 -0
  24. package/src/GridSnapshot.js +11 -0
  25. package/src/GridSplitter.css.js +62 -0
  26. package/src/GridSplitter.js +26 -0
  27. package/src/GridStack.js +277 -0
  28. package/src/Icon.css.js +8 -0
  29. package/src/Icon.js +26 -0
  30. package/src/IconButton.css.js +9 -0
  31. package/src/IconButton.js +28 -0
  32. package/src/TabDialog.css.js +10 -0
  33. package/src/TabDialog.js +77 -0
  34. package/src/TabMenu.css.js +8 -0
  35. package/src/TabMenu.js +78 -0
  36. package/src/componentToJson.js +41 -0
  37. package/src/drag-drop-next/DragContextNext.js +173 -0
  38. package/src/drag-drop-next/DragDropProviderNext.css.js +72 -0
  39. package/src/drag-drop-next/DragDropProviderNext.js +91 -0
  40. package/src/drag-drop-next/SpaceMan.js +256 -0
  41. package/src/drag-drop-next/TemplateDragSession.js +36 -0
  42. package/src/drag-drop-next/tabstrip-drag-drop.js +251 -0
  43. package/src/grid-dom-utils.js +57 -0
  44. package/src/grid-layout-utils.js +39 -0
  45. package/src/grid-snapshot-adapters.js +435 -0
  46. package/src/index.js +24 -0
  47. package/src/json-value.js +56 -0
  48. package/src/layoutFromJson.js +15 -0
  49. package/src/layoutToJson.js +5 -0
  50. package/src/propUtils.js +15 -0
  51. package/src/react-element-utils.js +15 -0
  52. package/src/typeOf.js +15 -0
  53. package/src/useAsDropTarget.js +229 -0
  54. package/src/useDraggable.js +46 -0
  55. package/src/useEditTabName.js +70 -0
  56. package/src/useGridChildProps.js +47 -0
  57. package/src/useGridControllerSnapshot.js +21 -0
  58. package/src/useGridLayout.js +727 -0
  59. package/src/useGridSplitterResizing.js +262 -0
  60. package/src/useNotDropTarget.js +2 -0
  61. package/types/AddTabDialog.d.ts +5 -0
  62. package/types/GridCommand.d.ts +146 -0
  63. package/types/GridComponentSettings.d.ts +71 -0
  64. package/types/GridController.d.ts +50 -0
  65. package/types/GridDragCoordinator.d.ts +80 -0
  66. package/types/GridGeometry.d.ts +331 -0
  67. package/types/GridLayout.d.ts +20 -0
  68. package/types/GridLayoutContext.d.ts +141 -0
  69. package/types/GridLayoutDocument.d.ts +61 -0
  70. package/types/GridLayoutDocumentIds.d.ts +15 -0
  71. package/types/GridLayoutItem.d.ts +28 -0
  72. package/types/GridLayoutLegacyCompatibility.d.ts +57 -0
  73. package/types/GridLayoutModel.d.ts +72 -0
  74. package/types/GridLayoutProvider.d.ts +59 -0
  75. package/types/GridLayoutStackedtem.d.ts +10 -0
  76. package/types/GridModel.d.ts +504 -0
  77. package/types/GridPlaceholder.d.ts +5 -0
  78. package/types/GridSnapshot.d.ts +49 -0
  79. package/types/GridSplitter.d.ts +10 -0
  80. package/types/GridStack.d.ts +160 -0
  81. package/types/Icon.d.ts +6 -0
  82. package/types/IconButton.d.ts +6 -0
  83. package/types/TabDialog.d.ts +9 -0
  84. package/types/TabMenu.d.ts +7 -0
  85. package/types/componentToJson.d.ts +38 -0
  86. package/types/drag-drop-next/DragContextNext.d.ts +92 -0
  87. package/types/drag-drop-next/DragDropProviderNext.d.ts +23 -0
  88. package/types/drag-drop-next/SpaceMan.d.ts +35 -0
  89. package/types/drag-drop-next/TemplateDragSession.d.ts +21 -0
  90. package/types/drag-drop-next/tabstrip-drag-drop.d.ts +3 -0
  91. package/types/grid-dom-utils.d.ts +17 -0
  92. package/types/grid-layout-utils.d.ts +18 -0
  93. package/types/grid-matrix.d.ts +5 -0
  94. package/types/grid-snapshot-adapters.d.ts +22 -0
  95. package/types/index.d.ts +24 -0
  96. package/types/json-value.d.ts +23 -0
  97. package/types/layoutFromJson.d.ts +4 -0
  98. package/types/layoutToJson.d.ts +3 -0
  99. package/types/propUtils.d.ts +5 -0
  100. package/types/react-element-utils.d.ts +3 -0
  101. package/types/src/AddTabDialog.d.ts +5 -0
  102. package/types/src/GridLayout.d.ts +14 -0
  103. package/types/src/GridLayoutContext.d.ts +88 -0
  104. package/types/src/GridLayoutItem.d.ts +28 -0
  105. package/types/src/GridLayoutModel.d.ts +59 -0
  106. package/types/src/GridLayoutProvider.d.ts +37 -0
  107. package/types/src/GridLayoutStackedtem.d.ts +10 -0
  108. package/types/src/GridModel.d.ts +350 -0
  109. package/types/src/GridPlaceholder.d.ts +5 -0
  110. package/types/src/GridSplitter.d.ts +9 -0
  111. package/types/src/Icon.d.ts +6 -0
  112. package/types/src/IconButton.d.ts +6 -0
  113. package/types/src/TabMenu.d.ts +6 -0
  114. package/types/src/componentToJson.d.ts +32 -0
  115. package/types/src/drag-drop-next/DragContextNext.d.ts +73 -0
  116. package/types/src/drag-drop-next/DragDropProviderNext.d.ts +20 -0
  117. package/types/src/drag-drop-next/SpaceMan.d.ts +35 -0
  118. package/types/src/drag-drop-next/tabstrip-drag-drop.d.ts +3 -0
  119. package/types/src/grid-dom-utils.d.ts +17 -0
  120. package/types/src/grid-layout-utils.d.ts +80 -0
  121. package/types/src/grid-matrix.d.ts +5 -0
  122. package/types/src/index.d.ts +10 -0
  123. package/types/src/layoutFromJson.d.ts +3 -0
  124. package/types/src/layoutToJson.d.ts +2 -0
  125. package/types/src/propUtils.d.ts +5 -0
  126. package/types/src/react-element-utils.d.ts +3 -0
  127. package/types/src/typeOf.d.ts +6 -0
  128. package/types/src/useAsDropTarget.d.ts +7 -0
  129. package/types/src/useDraggable.d.ts +23 -0
  130. package/types/src/useGridChildProps.d.ts +13 -0
  131. package/types/src/useGridLayout.d.ts +43 -0
  132. package/types/src/useGridSplitterResizing.d.ts +12 -0
  133. package/types/src/useNotDropTarget.d.ts +1 -0
  134. package/types/typeOf.d.ts +6 -0
  135. package/types/useAsDropTarget.d.ts +7 -0
  136. package/types/useDraggable.d.ts +24 -0
  137. package/types/useEditTabName.d.ts +11 -0
  138. package/types/useGridChildProps.d.ts +13 -0
  139. package/types/useGridControllerSnapshot.d.ts +7 -0
  140. package/types/useGridLayout.d.ts +53 -0
  141. package/types/useGridSplitterResizing.d.ts +14 -0
  142. package/types/useNotDropTarget.d.ts +1 -0
@@ -0,0 +1,251 @@
1
+ import { queryClosest } from "@vuu-ui/vuu-utils";
2
+ import { SpaceMan } from "./SpaceMan.js";
3
+ import { sourceIsTabbedComponent } from "../GridLayoutContext.js";
4
+ import { getClosestGridLayout } from "../grid-dom-utils.js";
5
+ const isDraggable = (target)=>{
6
+ const el = target;
7
+ return null !== el && null !== queryClosest(el, '[draggable="true"]');
8
+ };
9
+ const getDraggableEl = (target)=>{
10
+ const el = target;
11
+ if (!isDraggable(target)) return null;
12
+ if (el?.classList.contains("vuuDraggableItem")) return el;
13
+ return queryClosest(el, ".vuuDraggableItem");
14
+ };
15
+ const isRemoteContainer = (sourceElement, targetElement)=>sourceElement.parentElement !== targetElement?.parentElement;
16
+ const getDataIndex = (el)=>el ? parseInt(el.dataset.index ?? "-1") : -1;
17
+ const getDataLabel = (el)=>el?.dataset.label ?? "";
18
+ const TAB_CLICK_MOVEMENT_TOLERANCE = 12;
19
+ const getDropPosition = (target, clientX, clientY, orientation)=>{
20
+ const itemId = target?.dataset.gridLayoutItemId;
21
+ if (!target || !itemId) return;
22
+ const rect = target.getBoundingClientRect();
23
+ const after = "horizontal" === orientation ? clientX >= rect.left + rect.width / 2 : clientY >= rect.top + rect.height / 2;
24
+ return {
25
+ position: after ? "after" : "before",
26
+ target: itemId
27
+ };
28
+ };
29
+ const eventTargetsGrid = (event, gridId)=>{
30
+ const target = event.target;
31
+ return target instanceof Element && target.closest(".vuuGridLayout")?.id === gridId;
32
+ };
33
+ const getDropPositionAtEnd = (target, containerEl)=>{
34
+ if (target.closest(".vuuDragContainer") !== containerEl) return;
35
+ const tabs = containerEl.querySelectorAll(".vuuDraggableItem[data-label]");
36
+ const lastTab = tabs.item(tabs.length - 1);
37
+ return lastTab ? {
38
+ position: "after",
39
+ target: lastTab.dataset.gridLayoutItemId ?? getDataLabel(lastTab)
40
+ } : void 0;
41
+ };
42
+ const getDropPositionAtPoint = (containerEl, clientX, clientY, orientation)=>{
43
+ const tabs = [
44
+ ...containerEl.querySelectorAll(".vuuDraggableItem[data-grid-layout-item-id]")
45
+ ];
46
+ const target = tabs.reduce((closest, tab)=>{
47
+ if (!closest) return tab;
48
+ const coordinate = "horizontal" === orientation ? clientX : clientY;
49
+ const rect = tab.getBoundingClientRect();
50
+ const closestRect = closest.getBoundingClientRect();
51
+ const midpoint = "horizontal" === orientation ? rect.left + rect.width / 2 : rect.top + rect.height / 2;
52
+ const closestMidpoint = "horizontal" === orientation ? closestRect.left + closestRect.width / 2 : closestRect.top + closestRect.height / 2;
53
+ return Math.abs(coordinate - midpoint) < Math.abs(coordinate - closestMidpoint) ? tab : closest;
54
+ }, void 0);
55
+ return getDropPosition(target ?? null, clientX, clientY, orientation);
56
+ };
57
+ function initializeDragContainer(containerEl, dragContext, orientation = "horizontal", tabsId = containerEl.id) {
58
+ const gridId = getClosestGridLayout(containerEl);
59
+ const spaceMan = new SpaceMan(dragContext, containerEl.id, orientation);
60
+ spaceMan.setDragContainer(containerEl);
61
+ let mouseDown;
62
+ let tabDropTarget;
63
+ const clearTabDropTarget = ()=>{
64
+ tabDropTarget?.classList.remove("vuuTabDropTarget-after", "vuuTabDropTarget-before");
65
+ tabDropTarget = void 0;
66
+ };
67
+ const clearTabDropTargetAfterFrame = ()=>{
68
+ const target = tabDropTarget;
69
+ tabDropTarget = void 0;
70
+ requestAnimationFrame(()=>{
71
+ target?.classList.remove("vuuTabDropTarget-after", "vuuTabDropTarget-before");
72
+ });
73
+ };
74
+ const unregisterDragStateCleanup = dragContext.registerDragStateCleanup(()=>{
75
+ clearTabDropTargetAfterFrame();
76
+ spaceMan.cleanup();
77
+ });
78
+ const focusDroppedTab = (tabsId, itemId, tabLabel)=>{
79
+ requestAnimationFrame(()=>{
80
+ const selector = itemId ? `[data-grid-layout-item-id="${CSS.escape(itemId)}"] .saltTabNextTrigger` : `[data-label="${CSS.escape(tabLabel)}"] .saltTabNextTrigger`;
81
+ const droppedTab = document.getElementById(tabsId)?.querySelector(selector);
82
+ droppedTab?.focus();
83
+ });
84
+ };
85
+ const onDragStart = (e)=>{
86
+ const element = getDraggableEl(e.target);
87
+ if (element) {
88
+ const tabsContainer = queryClosest(e.target, ".vuuDragContainer", true);
89
+ const gridLayout = queryClosest(tabsContainer, ".vuuGridLayout", true);
90
+ const gridLayoutItem = queryClosest(tabsContainer, ".vuuGridLayoutItem", true);
91
+ const tabIndex = getDataIndex(element);
92
+ const label = getDataLabel(element);
93
+ const isSelectedTab = null !== element.querySelector('[aria-selected="true"]');
94
+ const { gridLayoutItemId } = element.dataset;
95
+ e.stopPropagation();
96
+ dragContext.beginDrag(e, {
97
+ element,
98
+ label,
99
+ isSelectedTab,
100
+ layoutId: gridLayout.id,
101
+ tab: {
102
+ id: gridLayoutItemId ?? "",
103
+ label
104
+ },
105
+ tabIndex,
106
+ tabsId: gridLayoutItem.id,
107
+ type: "tabbed-component"
108
+ });
109
+ dragContext.detachTab(gridId, gridLayoutItem.id, gridLayoutItemId ?? "", label);
110
+ spaceMan.dragStart(tabIndex);
111
+ }
112
+ };
113
+ const onDragEnter = (e)=>{
114
+ const dropTarget = getDraggableEl(e.target);
115
+ e.preventDefault();
116
+ const { dragSource, x, y } = dragContext;
117
+ if (dropTarget) {
118
+ const indexOfDropTarget = getDataIndex(dropTarget);
119
+ if (sourceIsTabbedComponent(dragSource)) {
120
+ if (-1 !== indexOfDropTarget && (indexOfDropTarget !== dragSource?.tabIndex || isRemoteContainer(dragSource.element, dropTarget))) {
121
+ const position = getDropPosition(dropTarget, e.clientX, e.clientY, orientation);
122
+ clearTabDropTarget();
123
+ if (position) {
124
+ tabDropTarget = dropTarget;
125
+ dropTarget.classList.add(`vuuTabDropTarget-${position.position}`);
126
+ }
127
+ const direction = position?.position === "after" ? "fwd" : "bwd";
128
+ spaceMan.dragEnter(indexOfDropTarget, direction);
129
+ }
130
+ } else {
131
+ const direction = "horizontal" === orientation ? e.clientX > x ? "fwd" : "bwd" : e.clientY > y ? "fwd" : "bwd";
132
+ spaceMan.dragEnter(indexOfDropTarget, direction);
133
+ }
134
+ } else if (dragSource && !sourceIsTabbedComponent(dragSource) && e.target.closest(".vuuDragContainer")) {
135
+ const tabs = containerEl.querySelectorAll(".vuuDraggableItem[data-index]");
136
+ const lastTab = tabs.item(tabs.length - 1);
137
+ const lastIndex = getDataIndex(lastTab);
138
+ if (-1 !== lastIndex) spaceMan.dragEnter(lastIndex, "fwd");
139
+ }
140
+ dragContext.x = e.clientX;
141
+ dragContext.y = e.clientY;
142
+ };
143
+ const onDragOver = (e)=>{
144
+ const dropTarget = getDraggableEl(e.target);
145
+ if (dropTarget && sourceIsTabbedComponent(dragContext.dragSource)) {
146
+ const position = getDropPosition(dropTarget, e.clientX, e.clientY, orientation);
147
+ clearTabDropTarget();
148
+ if (position) {
149
+ tabDropTarget = dropTarget;
150
+ dropTarget.classList.add(`vuuTabDropTarget-${position.position}`);
151
+ }
152
+ } else if (sourceIsTabbedComponent(dragContext.dragSource)) {
153
+ const position = getDropPositionAtPoint(containerEl, e.clientX, e.clientY, orientation);
154
+ const target = position ? containerEl.querySelector(`[data-grid-layout-item-id="${CSS.escape(position.target)}"]`) : void 0;
155
+ clearTabDropTarget();
156
+ if (position && target) {
157
+ tabDropTarget = target;
158
+ target.classList.add(`vuuTabDropTarget-${position.position}`);
159
+ }
160
+ }
161
+ e.preventDefault();
162
+ };
163
+ const onDragLeave = (e)=>{
164
+ const container = queryClosest(e.relatedTarget, `#${spaceMan.id}`);
165
+ if (null === container) {
166
+ clearTabDropTarget();
167
+ spaceMan.leaveDragContainer();
168
+ }
169
+ };
170
+ const onDrop = async (e)=>{
171
+ if (!eventTargetsGrid(e, gridId)) return;
172
+ if (dragContext.dropped) return void spaceMan.cleanup();
173
+ const { clientX, clientY } = e;
174
+ const dropPosition = getDropPosition(getDraggableEl(e.target), clientX, clientY, orientation) ?? getDropPositionAtPoint(containerEl, clientX, clientY, orientation) ?? spaceMan.dropPosition ?? getDropPositionAtEnd(e.target, containerEl);
175
+ if (dropPosition) {
176
+ e.preventDefault();
177
+ e.stopPropagation();
178
+ const source = dragContext.dragSource;
179
+ const droppedLabel = source?.label;
180
+ const droppedItemId = sourceIsTabbedComponent(source) ? source.tab.id : void 0;
181
+ if (sourceIsTabbedComponent(source)) {
182
+ dragContext.beginDrop();
183
+ await spaceMan.drop(clientX, clientY);
184
+ dragContext.drop({
185
+ tabsId,
186
+ dropPosition
187
+ });
188
+ } else {
189
+ spaceMan.cleanup();
190
+ dragContext.drop({
191
+ tabsId,
192
+ dropPosition
193
+ });
194
+ }
195
+ if (droppedLabel) focusDroppedTab(tabsId, droppedItemId, droppedLabel);
196
+ dragContext.endDrag();
197
+ } else spaceMan.cleanup();
198
+ };
199
+ const onDragEnd = ({ clientX, clientY })=>{
200
+ if (mouseDown && Math.hypot(clientX - mouseDown.x, clientY - mouseDown.y) <= TAB_CLICK_MOVEMENT_TOLERANCE && "true" !== mouseDown.tab.ariaSelected) mouseDown.tab.click();
201
+ mouseDown = void 0;
202
+ if (!dragContext.ownsDrag) return;
203
+ if (dragContext.dropped || dragContext.dropPending) {
204
+ if (dragContext.dropped) dragContext.endDrag();
205
+ } else dragContext.cancelDrag();
206
+ };
207
+ const onMouseDown = (event)=>{
208
+ const { clientX, clientY, target } = event;
209
+ const draggable = getDraggableEl(target);
210
+ if (draggable) {
211
+ const tab = draggable.querySelector('[role="tab"]');
212
+ if (tab) mouseDown = {
213
+ tab,
214
+ x: clientX,
215
+ y: clientY
216
+ };
217
+ const { left, top } = draggable.getBoundingClientRect();
218
+ spaceMan.mouseOffset = {
219
+ x: clientX - left,
220
+ y: clientY - top
221
+ };
222
+ }
223
+ };
224
+ const onMouseUp = ({ clientX, clientY })=>{
225
+ if (mouseDown && Math.hypot(clientX - mouseDown.x, clientY - mouseDown.y) <= TAB_CLICK_MOVEMENT_TOLERANCE && "true" !== mouseDown.tab.ariaSelected) mouseDown.tab.click();
226
+ mouseDown = void 0;
227
+ };
228
+ containerEl?.addEventListener("mousedown", onMouseDown, true);
229
+ document.body.addEventListener("mouseup", onMouseUp);
230
+ containerEl?.addEventListener("dragstart", onDragStart, true);
231
+ containerEl?.addEventListener("dragenter", onDragEnter, true);
232
+ containerEl?.addEventListener("dragleave", onDragLeave, true);
233
+ containerEl?.addEventListener("dragover", onDragOver, true);
234
+ containerEl?.addEventListener("drop", onDrop, true);
235
+ document.body.addEventListener("dragend", onDragEnd);
236
+ function cleanUp() {
237
+ unregisterDragStateCleanup();
238
+ clearTabDropTarget();
239
+ spaceMan.cleanup();
240
+ containerEl?.removeEventListener("mousedown", onMouseDown, true);
241
+ document.body.removeEventListener("mouseup", onMouseUp);
242
+ containerEl?.removeEventListener("dragstart", onDragStart, true);
243
+ containerEl?.removeEventListener("dragenter", onDragEnter, true);
244
+ containerEl?.removeEventListener("dragleave", onDragLeave, true);
245
+ containerEl?.removeEventListener("dragover", onDragOver, true);
246
+ containerEl?.removeEventListener("drop", onDrop, true);
247
+ document.body.removeEventListener("dragend", onDragEnd);
248
+ }
249
+ return cleanUp;
250
+ }
251
+ export { initializeDragContainer };
@@ -0,0 +1,57 @@
1
+ import { queryClosest } from "@vuu-ui/vuu-utils";
2
+ const classNameLayoutItem = "vuuGridLayoutItem";
3
+ const classNameGridSplitter = "vuuGridSplitter";
4
+ const getGridSplitter = (el)=>{
5
+ if (el.classList.contains(classNameGridSplitter)) return el;
6
+ return el.closest(`.${classNameGridSplitter}`);
7
+ };
8
+ const getGridLayoutItem = (el)=>{
9
+ if (el.classList.contains(classNameLayoutItem)) return el;
10
+ return el.closest(`.${classNameLayoutItem}`);
11
+ };
12
+ const NO_POSITION = [
13
+ -1,
14
+ -1
15
+ ];
16
+ const getColumn = (el)=>{
17
+ const value = getComputedStyle(el).getPropertyValue("grid-column").split("/").map((value)=>parseInt(value, 10));
18
+ if (2 === value.length) return value;
19
+ if (1 === value.length) return [
20
+ value[0],
21
+ value[0]
22
+ ];
23
+ return NO_POSITION;
24
+ };
25
+ const getRow = (el)=>{
26
+ if (void 0 === el) throw Error("getRow invoked with null element");
27
+ const value = getComputedStyle(el).getPropertyValue("grid-row").split("/").map((value)=>parseInt(value, 10));
28
+ if (2 === value.length) return value;
29
+ if (1 === value.length) return [
30
+ value[0],
31
+ value[0]
32
+ ];
33
+ return NO_POSITION;
34
+ };
35
+ const getRowIndex = (el)=>{
36
+ const [from] = getRow(el);
37
+ return from - 1;
38
+ };
39
+ const setGridColumn = (target, { start, end })=>{
40
+ const el = "string" == typeof target ? document.getElementById(target) : target;
41
+ el?.style.setProperty("grid-column", `${start}/${end}`);
42
+ };
43
+ const setGridRow = (target, { start, end })=>{
44
+ const el = "string" == typeof target ? document.getElementById(target) : target;
45
+ el?.style.setProperty("grid-row", `${start}/${end}`);
46
+ };
47
+ const spansMultipleTracks = (gridItem, direction)=>{
48
+ const track = "horizontal" === direction ? "column" : "row";
49
+ const { start, end } = gridItem[track];
50
+ return end - start > 1;
51
+ };
52
+ function getClosestGridLayout(source) {
53
+ const el = "string" == typeof source ? document.getElementById(source) : source;
54
+ const gridLayout = queryClosest(el, ".vuuGridLayout", true);
55
+ return gridLayout.id;
56
+ }
57
+ export { classNameGridSplitter, classNameLayoutItem, getClosestGridLayout, getColumn, getGridLayoutItem, getGridSplitter, getRow, getRowIndex, setGridColumn, setGridRow, spansMultipleTracks };
@@ -0,0 +1,39 @@
1
+ const adjustDistance = (moveBy, adjustmentAmount)=>{
2
+ if (moveBy < 0) return moveBy + adjustmentAmount;
3
+ return moveBy - adjustmentAmount;
4
+ };
5
+ const getGridArea = ({ column, row })=>`${row.start}/${column.start}/${row.end}/${column.end}`;
6
+ const getActiveIndex = (childItems)=>{
7
+ const index = childItems.findIndex((item)=>item.contentVisible);
8
+ if (0 === childItems.length) return -1;
9
+ if (-1 === index) return 0;
10
+ return index;
11
+ };
12
+ const getSharedGridPosition = (childItems)=>{
13
+ const [{ column, row }, ...rest] = childItems;
14
+ if (rest.length > 0) {
15
+ if (rest.some(({ column: c, row: r })=>c.start !== column.start || c.end !== column.end || r.start !== row.start || r.end !== row.end)) throw Error("grid-layout-utils] getSharedGridPosition not all child grid items hae same GridLayoutModelCoordinates");
16
+ }
17
+ return {
18
+ column,
19
+ row
20
+ };
21
+ };
22
+ const getGridPosition = (gridArea)=>{
23
+ if ("string" == typeof gridArea) {
24
+ const [rowStart, colStart, rowEnd, colEnd] = gridArea.split("/").map((val)=>parseInt(val, 10));
25
+ return {
26
+ column: {
27
+ start: colStart,
28
+ end: colEnd
29
+ },
30
+ row: {
31
+ start: rowStart,
32
+ end: rowEnd
33
+ }
34
+ };
35
+ }
36
+ throw Error("[grid-layout-utils] getGridPosition gridArea must be valid");
37
+ };
38
+ const getTrackType = (splitter)=>"vertical" === splitter.orientation ? "row" : "column";
39
+ export { adjustDistance, getActiveIndex, getGridArea, getGridPosition, getSharedGridPosition, getTrackType };