@vuu-ui/vuu-layout 0.5.14 → 0.5.15

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 (114) hide show
  1. package/package.json +10 -13
  2. package/src/Component.css +0 -0
  3. package/src/Component.tsx +20 -0
  4. package/src/DraggableLayout.css +18 -0
  5. package/src/DraggableLayout.tsx +26 -0
  6. package/src/__tests__/flexbox-utils.spec.js +90 -0
  7. package/src/chest-of-drawers/Chest.css +36 -0
  8. package/src/chest-of-drawers/Chest.tsx +42 -0
  9. package/src/chest-of-drawers/Drawer.css +159 -0
  10. package/src/chest-of-drawers/Drawer.tsx +118 -0
  11. package/src/chest-of-drawers/index.ts +2 -0
  12. package/src/common-types.ts +9 -0
  13. package/src/debug.ts +16 -0
  14. package/src/drag-drop/BoxModel.ts +551 -0
  15. package/src/drag-drop/DragState.ts +219 -0
  16. package/src/drag-drop/Draggable.ts +282 -0
  17. package/src/drag-drop/DropMenu.css +71 -0
  18. package/src/drag-drop/DropMenu.tsx +61 -0
  19. package/src/drag-drop/DropTarget.ts +393 -0
  20. package/src/drag-drop/DropTargetRenderer.css +40 -0
  21. package/src/drag-drop/DropTargetRenderer.tsx +277 -0
  22. package/src/drag-drop/dragDropTypes.ts +47 -0
  23. package/src/drag-drop/index.ts +5 -0
  24. package/src/editable-label/EditableLabel.css +28 -0
  25. package/src/editable-label/EditableLabel.tsx +99 -0
  26. package/src/editable-label/index.ts +1 -0
  27. package/src/flexbox/Flexbox.css +45 -0
  28. package/src/flexbox/Flexbox.tsx +70 -0
  29. package/src/flexbox/FlexboxLayout.tsx +28 -0
  30. package/src/flexbox/FluidGrid.css +134 -0
  31. package/src/flexbox/FluidGrid.tsx +82 -0
  32. package/src/flexbox/FluidGridLayout.tsx +9 -0
  33. package/src/flexbox/Splitter.css +140 -0
  34. package/src/flexbox/Splitter.tsx +127 -0
  35. package/src/flexbox/flexbox-utils.ts +128 -0
  36. package/src/flexbox/flexboxTypes.ts +68 -0
  37. package/src/flexbox/index.ts +5 -0
  38. package/src/flexbox/useResponsiveSizing.ts +82 -0
  39. package/src/flexbox/useSplitterResizing.ts +270 -0
  40. package/src/index.ts +19 -0
  41. package/src/layout-action.ts +21 -0
  42. package/src/layout-header/ActionButton.tsx +23 -0
  43. package/src/layout-header/Header.css +8 -0
  44. package/src/layout-header/Header.tsx +216 -0
  45. package/src/layout-header/index.ts +1 -0
  46. package/src/layout-provider/LayoutProvider.tsx +161 -0
  47. package/src/layout-provider/LayoutProviderContext.ts +17 -0
  48. package/src/layout-provider/index.ts +3 -0
  49. package/src/layout-provider/useLayoutDragDrop.ts +210 -0
  50. package/src/layout-reducer/flexUtils.ts +276 -0
  51. package/src/layout-reducer/index.ts +5 -0
  52. package/src/layout-reducer/insert-layout-element.ts +365 -0
  53. package/src/layout-reducer/layout-reducer.ts +237 -0
  54. package/src/layout-reducer/layoutTypes.ts +159 -0
  55. package/src/layout-reducer/layoutUtils.ts +288 -0
  56. package/src/layout-reducer/remove-layout-element.ts +226 -0
  57. package/src/layout-reducer/replace-layout-element.ts +113 -0
  58. package/src/layout-reducer/resize-flex-children.ts +55 -0
  59. package/src/layout-reducer/wrap-layout-element.ts +307 -0
  60. package/src/layout-view/View.css +61 -0
  61. package/src/layout-view/View.tsx +143 -0
  62. package/src/layout-view/ViewContext.ts +30 -0
  63. package/src/layout-view/index.ts +5 -0
  64. package/src/layout-view/useView.tsx +104 -0
  65. package/src/layout-view/useViewActionDispatcher.ts +123 -0
  66. package/src/layout-view/useViewResize.ts +53 -0
  67. package/src/layout-view/viewTypes.ts +35 -0
  68. package/src/palette/Palette.css +33 -0
  69. package/src/palette/Palette.tsx +140 -0
  70. package/src/palette/PaletteSalt.css +9 -0
  71. package/src/palette/PaletteSalt.tsx +79 -0
  72. package/src/palette/index.ts +3 -0
  73. package/src/placeholder/Placeholder.css +10 -0
  74. package/src/placeholder/Placeholder.tsx +38 -0
  75. package/src/placeholder/index.ts +1 -0
  76. package/src/registry/ComponentRegistry.ts +44 -0
  77. package/src/registry/index.ts +1 -0
  78. package/src/responsive/breakpoints.ts +62 -0
  79. package/src/responsive/index.ts +3 -0
  80. package/src/responsive/measureMinimumNodeSize.ts +23 -0
  81. package/src/responsive/overflowUtils.js +14 -0
  82. package/src/responsive/use-breakpoints.ts +101 -0
  83. package/src/responsive/useResizeObserver.ts +154 -0
  84. package/src/responsive/utils.ts +37 -0
  85. package/src/stack/Stack.css +39 -0
  86. package/src/stack/Stack.tsx +173 -0
  87. package/src/stack/StackLayout.tsx +119 -0
  88. package/src/stack/index.ts +4 -0
  89. package/src/stack/stackTypes.ts +22 -0
  90. package/src/tabs/TabPanel.css +12 -0
  91. package/src/tabs/TabPanel.tsx +17 -0
  92. package/src/tabs/index.ts +1 -0
  93. package/src/tools/config-wrapper/ConfigWrapper.tsx +55 -0
  94. package/src/tools/config-wrapper/index.ts +1 -0
  95. package/src/tools/devtools-box/layout-configurator.css +112 -0
  96. package/src/tools/devtools-box/layout-configurator.jsx +369 -0
  97. package/src/tools/devtools-tree/layout-tree-viewer.css +15 -0
  98. package/src/tools/devtools-tree/layout-tree-viewer.jsx +36 -0
  99. package/src/tools/index.ts +4 -0
  100. package/src/use-persistent-state.ts +112 -0
  101. package/src/utils/index.ts +5 -0
  102. package/src/utils/pathUtils.ts +283 -0
  103. package/src/utils/propUtils.ts +26 -0
  104. package/src/utils/refUtils.ts +16 -0
  105. package/src/utils/styleUtils.ts +13 -0
  106. package/src/utils/typeOf.ts +25 -0
  107. package/tsconfig-emit-types.json +11 -0
  108. package/LICENSE +0 -201
  109. package/cjs/index.js +0 -20
  110. package/cjs/index.js.map +0 -7
  111. package/esm/index.js +0 -20
  112. package/esm/index.js.map +0 -7
  113. package/index.css +0 -2
  114. package/index.css.map +0 -7
@@ -0,0 +1,551 @@
1
+ import { ReactElement } from "react";
2
+ import { rect } from "../common-types";
3
+ import { LayoutModel } from "../layout-reducer";
4
+ import { isContainer } from "../registry/ComponentRegistry";
5
+ import { getProps, typeOf } from "../utils";
6
+ import { DragDropRect, DropPos, RelativePosition } from "./dragDropTypes";
7
+
8
+ export const positionValues = {
9
+ north: 1,
10
+ east: 2,
11
+ south: 4,
12
+ west: 8,
13
+ header: 16,
14
+ centre: 32,
15
+ absolute: 64,
16
+ };
17
+
18
+ export const RelativeDropPosition = {
19
+ AFTER: "after" as RelativePosition,
20
+ BEFORE: "before" as RelativePosition,
21
+ };
22
+
23
+ export const Position = Object.freeze({
24
+ North: _position("north"),
25
+ East: _position("east"),
26
+ South: _position("south"),
27
+ West: _position("west"),
28
+ Header: _position("header"),
29
+ Centre: _position("centre"),
30
+ Absolute: _position("absolute"),
31
+ });
32
+
33
+ function _position(str: keyof typeof positionValues) {
34
+ return Object.freeze({
35
+ offset:
36
+ str === "north" || str === "west"
37
+ ? 0
38
+ : str === "south" || str === "east"
39
+ ? 1
40
+ : NaN,
41
+ valueOf: function () {
42
+ return positionValues[str];
43
+ },
44
+ toString: function () {
45
+ return str;
46
+ },
47
+ North: str === "north",
48
+ South: str === "south",
49
+ East: str === "east",
50
+ West: str === "west",
51
+ Header: str === "header",
52
+ Centre: str === "centre",
53
+ NorthOrSouth: str === "north" || str === "south",
54
+ EastOrWest: str === "east" || str === "west",
55
+ NorthOrWest: str === "north" || str === "west",
56
+ SouthOrEast: str === "east" || str === "south",
57
+ Absolute: str === "absolute",
58
+ });
59
+ }
60
+
61
+ const NORTH = Position.North,
62
+ SOUTH = Position.South,
63
+ EAST = Position.East,
64
+ WEST = Position.West,
65
+ HEADER = Position.Header,
66
+ CENTRE = Position.Centre;
67
+
68
+ export interface Measurements {
69
+ [key: string]: DragDropRect;
70
+ }
71
+
72
+ export class BoxModel {
73
+ //TODO we should accept initial let,top offsets here
74
+ // if dropTargets are supplied, we will only allow drop operations directly on these targets
75
+ // TODO we will need to make this more flexible e.g allowing drop anywhere within these target
76
+ static measure(
77
+ model: ReactElement,
78
+ dropTargetPaths: string[] = []
79
+ ): Measurements {
80
+ const measurements: Measurements = {};
81
+ measureRootComponent(model, measurements, dropTargetPaths);
82
+ return measurements;
83
+ }
84
+
85
+ static allBoxesContainingPoint(
86
+ layout: LayoutModel,
87
+ measurements: Measurements,
88
+ x: number,
89
+ y: number,
90
+ validDropTargets?: string[]
91
+ ) {
92
+ return allBoxesContainingPoint(
93
+ layout,
94
+ measurements,
95
+ x,
96
+ y,
97
+ validDropTargets
98
+ ).reverse();
99
+ }
100
+ }
101
+
102
+ export function pointPositionWithinRect(
103
+ x: number,
104
+ y: number,
105
+ rect: DragDropRect,
106
+ borderZone = 30
107
+ ) {
108
+ const width = rect.right - rect.left;
109
+ const height = rect.bottom - rect.top;
110
+ const posX = x - rect.left;
111
+ const posY = y - rect.top;
112
+ let closeToTheEdge = 0;
113
+
114
+ if (posX < borderZone) closeToTheEdge += 8;
115
+ if (posX > width - borderZone) closeToTheEdge += 2;
116
+ if (posY < borderZone) closeToTheEdge += 1;
117
+ if (posY > height - borderZone) closeToTheEdge += 4;
118
+
119
+ return { pctX: posX / width, pctY: posY / height, closeToTheEdge };
120
+ }
121
+
122
+ export function getPosition(
123
+ x: number,
124
+ y: number,
125
+ rect: DragDropRect,
126
+ targetOrientation?: "row" | "column"
127
+ ): DropPos {
128
+ const { BEFORE, AFTER } = RelativeDropPosition;
129
+ const { pctX, pctY, closeToTheEdge } = pointPositionWithinRect(x, y, rect);
130
+ let position;
131
+ let tab;
132
+
133
+ if (targetOrientation === "row") {
134
+ position = pctX < 0.5 ? WEST : EAST;
135
+ } else if (rect.header && containsPoint(rect.header, x, y)) {
136
+ position = HEADER;
137
+
138
+ if (rect.Stack) {
139
+ const tabCount = rect.Stack.length;
140
+ if (tabCount === 0) {
141
+ tab = {
142
+ index: -1,
143
+ left: rect.left,
144
+ positionRelativeToTab: AFTER,
145
+ width: 0,
146
+ };
147
+ } else {
148
+ //TODO account for gaps between tabs
149
+ const targetTab = rect.Stack.find(
150
+ ({ left, right }) => x >= left && x <= right
151
+ );
152
+ if (targetTab) {
153
+ const tabWidth = targetTab.right - targetTab.left;
154
+ tab = {
155
+ index: rect.Stack.indexOf(targetTab),
156
+ left: targetTab.left,
157
+ positionRelativeToTab:
158
+ (x - targetTab.left) / tabWidth < 0.5 ? BEFORE : AFTER,
159
+ width: tabWidth,
160
+ };
161
+ } else {
162
+ const lastTab = rect.Stack[tabCount - 1];
163
+ tab = {
164
+ left: lastTab.right,
165
+ width: 0,
166
+ index: tabCount,
167
+ positionRelativeToTab: AFTER,
168
+ };
169
+ }
170
+ }
171
+ } else if (rect.header.titleWidth) {
172
+ const tabWidth = rect.header.titleWidth;
173
+ tab = {
174
+ index: -1,
175
+ left: rect.left,
176
+ positionRelativeToTab:
177
+ (x - rect.left) / tabWidth < 0.5 ? BEFORE : AFTER,
178
+ width: tabWidth,
179
+ };
180
+ } else {
181
+ tab = {
182
+ left: rect.left,
183
+ width: 0,
184
+ positionRelativeToTab: BEFORE,
185
+ index: -1,
186
+ };
187
+ }
188
+ } else {
189
+ position = getPositionWithinBox(x, y, rect, pctX, pctY);
190
+ }
191
+ return { position: position!, x, y, closeToTheEdge, tab };
192
+ }
193
+
194
+ function getPositionWithinBox(
195
+ x: number,
196
+ y: number,
197
+ rect: DragDropRect,
198
+ pctX: number,
199
+ pctY: number
200
+ ) {
201
+ const centerBox = getCenteredBox(rect, 0.2);
202
+ if (containsPoint(centerBox, x, y)) {
203
+ return CENTRE;
204
+ } else {
205
+ const quadrant = `${pctY < 0.5 ? "north" : "south"}${
206
+ pctX < 0.5 ? "west" : "east"
207
+ }`;
208
+
209
+ switch (quadrant) {
210
+ case "northwest":
211
+ return pctX > pctY ? NORTH : WEST;
212
+ case "northeast":
213
+ return 1 - pctX > pctY ? NORTH : EAST;
214
+ case "southeast":
215
+ return pctX > pctY ? EAST : SOUTH;
216
+ case "southwest":
217
+ return 1 - pctX > pctY ? WEST : SOUTH;
218
+ default:
219
+ }
220
+ }
221
+ }
222
+
223
+ function getCenteredBox(
224
+ { right, left, top, bottom }: DragDropRect,
225
+ pctSize: number
226
+ ) {
227
+ const pctOffset = (1 - pctSize) / 2;
228
+ const w = (right - left) * pctOffset;
229
+ const h = (bottom - top) * pctOffset;
230
+ return { left: left + w, top: top + h, right: right - w, bottom: bottom - h };
231
+ }
232
+
233
+ function measureRootComponent(
234
+ rootComponent: ReactElement,
235
+ measurements: Measurements,
236
+ dropTargets: string[]
237
+ ) {
238
+ const {
239
+ id,
240
+ "data-path": dataPath,
241
+ path = dataPath,
242
+ } = getProps(rootComponent);
243
+ const type = typeOf(rootComponent) as string;
244
+
245
+ if (id && path) {
246
+ const [rect, el] = measureComponentDomElement(rootComponent);
247
+ measureComponent(rootComponent, rect, el, measurements);
248
+ if (isContainer(type)) {
249
+ collectChildMeasurements(rootComponent, measurements, dropTargets);
250
+ }
251
+ }
252
+ }
253
+
254
+ function measureComponent(
255
+ component: LayoutModel,
256
+ rect: DragDropRect,
257
+ el: HTMLElement,
258
+ measurements: Measurements
259
+ ) {
260
+ const {
261
+ "data-path": dataPath,
262
+ path = dataPath,
263
+ header,
264
+ } = getProps(component);
265
+
266
+ measurements[path] = rect;
267
+
268
+ const type = typeOf(component);
269
+ if (header || type === "Stack") {
270
+ const headerEl = el.querySelector(".vuuHeader");
271
+ if (headerEl) {
272
+ const { top, left, right, bottom } = headerEl.getBoundingClientRect();
273
+ measurements[path].header = {
274
+ top: Math.round(top),
275
+ left: Math.round(left),
276
+ right: Math.round(right),
277
+ bottom: Math.round(bottom),
278
+ };
279
+ if (type === "Stack") {
280
+ measurements[path].Stack = Array.from(
281
+ headerEl.querySelectorAll(".saltTab")
282
+ )
283
+ .map((tab) => tab.getBoundingClientRect())
284
+ .map(({ left, right }) => ({ left, right }));
285
+ } else {
286
+ const titleEl = headerEl.querySelector('[class^="vuuHeader-title"]');
287
+ const { header } = measurements[path];
288
+ if (titleEl && header) {
289
+ header.titleWidth = titleEl.clientWidth;
290
+ }
291
+ }
292
+ }
293
+ }
294
+
295
+ return measurements[path];
296
+ }
297
+
298
+ function collectChildMeasurements(
299
+ component: LayoutModel,
300
+ measurements: Measurements,
301
+ dropTargets: string[],
302
+ preX = 0,
303
+ posX = 0,
304
+ preY = 0,
305
+ posY = 0
306
+ ) {
307
+ const {
308
+ children,
309
+ "data-path": dataPath,
310
+ path = dataPath,
311
+ style,
312
+ active = 0,
313
+ } = getProps(component);
314
+
315
+ const type = typeOf(component);
316
+ const isFlexbox = type === "Flexbox";
317
+ const isStack = type === "Stack";
318
+ const isTower = isFlexbox && style.flexDirection === "column";
319
+ const isTerrace = isFlexbox && style.flexDirection === "row";
320
+
321
+ const childrenToMeasure = isStack
322
+ ? children.filter((_child: ReactElement, idx: number) => idx === active)
323
+ : children.filter(omitDragging);
324
+
325
+ type measuredTuple = [DragDropRect, HTMLElement, ReactElement];
326
+ // Collect all the measurements in first pass ...
327
+ const childMeasurements: measuredTuple[] = childrenToMeasure.map(
328
+ (child: ReactElement) => {
329
+ const [rect, el] = measureComponentDomElement(child);
330
+
331
+ return [
332
+ {
333
+ ...rect,
334
+ top: rect.top - preY,
335
+ right: rect.right + posX,
336
+ bottom: rect.bottom + posY,
337
+ left: rect.left - preX,
338
+ },
339
+ el,
340
+ child,
341
+ ];
342
+ }
343
+ );
344
+
345
+ // ...so that, in the second pass, we can identify gaps ...
346
+ const expandedMeasurements = childMeasurements.map(
347
+ ([rect, el, child], i, all) => {
348
+ // generate a 'local' splitter adjustment for children adjacent to splitters
349
+ let localPreX;
350
+ let localPosX;
351
+ let localPreY;
352
+ let localPosY;
353
+ let gapPre;
354
+ let gapPos;
355
+ const n = all.length - 1;
356
+ if (isTerrace) {
357
+ gapPre = i === 0 ? 0 : rect.left - all[i - 1][0].right;
358
+ gapPos = i === n ? 0 : all[i + 1][0].left - rect.right;
359
+ // we don't need to divide the leading gap, as half the gap will
360
+ // already have been assigned to the preceeding child in the
361
+ // previous loop iteration.
362
+ localPreX = i === 0 ? 0 : gapPre === 0 ? 0 : gapPre;
363
+ localPosX = i === n ? 0 : gapPos === 0 ? 0 : gapPos - gapPos / 2;
364
+ rect.left -= localPreX;
365
+ rect.right += localPosX;
366
+ localPreY = preY;
367
+ localPosY = posY;
368
+ } else if (isTower) {
369
+ gapPre = i === 0 ? 0 : rect.top - all[i - 1][0].bottom;
370
+ gapPos = i === n ? 0 : all[i + 1][0].top - rect.bottom;
371
+ // we don't need to divide the leading gap, as half the gap will
372
+ // already have been assigned to the preceeding child in the
373
+ // previous loop iteration.
374
+ localPreY = i === 0 ? 0 : gapPre === 0 ? 0 : gapPre;
375
+ localPosY = i === n ? 0 : gapPos === 0 ? 0 : gapPos - gapPos / 2;
376
+ rect.top -= localPreY;
377
+ rect.bottom += localPosY;
378
+ localPreX = preX;
379
+ localPosX = posX;
380
+ }
381
+
382
+ const componentMeasurements = measureComponent(
383
+ child,
384
+ rect,
385
+ el,
386
+ measurements
387
+ );
388
+
389
+ const childType = typeOf(child) as string;
390
+ if (isContainer(childType)) {
391
+ collectChildMeasurements(
392
+ child,
393
+ measurements,
394
+ dropTargets,
395
+ localPreX,
396
+ localPosX,
397
+ localPreY,
398
+ localPosY
399
+ );
400
+ }
401
+ return componentMeasurements;
402
+ }
403
+ );
404
+ if (childMeasurements.length) {
405
+ measurements[path].children = expandedMeasurements;
406
+ }
407
+ }
408
+
409
+ function omitDragging(component: ReactElement) {
410
+ const { id } = getProps(component);
411
+ const el = document.getElementById(id);
412
+ if (el) {
413
+ return el.dataset.dragging !== "true";
414
+ } else {
415
+ console.warn(`BoxModel: no element found with id #${id}`);
416
+ return false;
417
+ }
418
+ }
419
+
420
+ function measureComponentDomElement(
421
+ component: LayoutModel
422
+ ): [DragDropRect, HTMLElement, LayoutModel] {
423
+ const { id } = getProps(component) as { id: string };
424
+ if (id === undefined) {
425
+ throw Error("`BoxModel.measureComponentElement, component has no id");
426
+ }
427
+ const el = document.getElementById(id);
428
+ if (!el) {
429
+ throw Error(
430
+ "BoxModel.measureComponentElement, no DOM element found for component"
431
+ );
432
+ }
433
+ // Note: height and width are not required for dropTarget identification, but
434
+ // are used in sizing calculations on drop
435
+ const { top, left, right, bottom, height, width } =
436
+ el.getBoundingClientRect();
437
+ let scrolling = undefined;
438
+ const type = typeOf(component) as string;
439
+ if (isContainer(type)) {
440
+ const scrollHeight = el.scrollHeight;
441
+ if (scrollHeight > height) {
442
+ scrolling = { id, scrollHeight, scrollTop: el.scrollTop };
443
+ }
444
+ }
445
+ return [
446
+ {
447
+ top: Math.round(top),
448
+ left: Math.round(left),
449
+ right: Math.round(right),
450
+ bottom: Math.round(bottom),
451
+ height: Math.round(height),
452
+ width: Math.round(width),
453
+ scrolling,
454
+ },
455
+ el,
456
+ component,
457
+ ];
458
+ }
459
+
460
+ function allBoxesContainingPoint(
461
+ component: LayoutModel,
462
+ measurements: Measurements,
463
+ x: number,
464
+ y: number,
465
+ dropTargets?: string[],
466
+ boxes: LayoutModel[] = []
467
+ ): LayoutModel[] {
468
+ const {
469
+ children,
470
+ "data-path": dataPath,
471
+ path = dataPath,
472
+ } = getProps(component);
473
+
474
+ const type = typeOf(component) as string;
475
+ const rect = measurements[path];
476
+ if (!containsPoint(rect, x, y)) return boxes;
477
+
478
+ if (dropTargets && dropTargets.length) {
479
+ if (dropTargets.includes(path)) {
480
+ boxes.push(component);
481
+ } else if (
482
+ dropTargets.some((dropTargetPath) => dropTargetPath.startsWith(path))
483
+ ) {
484
+ // keep going
485
+ } else {
486
+ return boxes;
487
+ }
488
+ } else {
489
+ boxes.push(component);
490
+ }
491
+
492
+ if (!isContainer(type)) {
493
+ return boxes;
494
+ }
495
+
496
+ if (rect.header && containsPoint(rect.header, x, y)) {
497
+ return boxes;
498
+ }
499
+
500
+ if (rect.scrolling) {
501
+ scrollIntoViewIfNeccesary(rect, x, y);
502
+ }
503
+
504
+ for (let i = 0; i < children.length; i++) {
505
+ if (type === "Stack" && component.props.active !== i) {
506
+ continue;
507
+ }
508
+ const nestedBoxes = allBoxesContainingPoint(
509
+ children[i],
510
+ measurements,
511
+ x,
512
+ y,
513
+ dropTargets
514
+ );
515
+ if (nestedBoxes.length) {
516
+ return boxes.concat(nestedBoxes);
517
+ }
518
+ }
519
+ return boxes;
520
+ }
521
+
522
+ function containsPoint(rect: rect, x: number, y: number) {
523
+ if (rect) {
524
+ return x >= rect.left && x < rect.right && y >= rect.top && y < rect.bottom;
525
+ }
526
+ }
527
+
528
+ function scrollIntoViewIfNeccesary(
529
+ { top, bottom, scrolling }: DragDropRect,
530
+ x: number,
531
+ y: number
532
+ ) {
533
+ if (scrolling) {
534
+ const { id, scrollTop, scrollHeight } = scrolling;
535
+ const height = bottom - top;
536
+ if (scrollTop === 0 && bottom - y < 50) {
537
+ const scrollMax = scrollHeight - height;
538
+ const el = document.getElementById(id) as HTMLElement;
539
+ el.scrollTo({ left: 0, top: scrollMax, behavior: "smooth" });
540
+ scrolling.scrollTop = scrollMax;
541
+ } else if (scrollTop > 0 && y - top < 50) {
542
+ const el = document.getElementById(id) as HTMLElement;
543
+ el.scrollTo({ left: 0, top: 0, behavior: "smooth" });
544
+ scrolling.scrollTop = 0;
545
+ } else {
546
+ return false;
547
+ }
548
+ } else {
549
+ return false;
550
+ }
551
+ }