@dxos/react-ui-mosaic 0.3.9-main.57b66d1 → 0.3.9-main.cea1d3b
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/dist/lib/browser/index.mjs +450 -44
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/mosaic/Container.d.ts +4 -14
- package/dist/types/src/mosaic/Container.d.ts.map +1 -1
- package/dist/types/src/mosaic/DragOverlay.d.ts.map +1 -1
- package/dist/types/src/mosaic/Tile.d.ts +7 -9
- package/dist/types/src/mosaic/Tile.d.ts.map +1 -1
- package/dist/types/src/mosaic/hooks/useContainer.d.ts +2 -2
- package/dist/types/src/mosaic/hooks/useContainer.d.ts.map +1 -1
- package/dist/types/src/mosaic/types.d.ts +0 -1
- package/dist/types/src/mosaic/types.d.ts.map +1 -1
- package/dist/types/src/mosaic/util/index.d.ts +0 -1
- package/dist/types/src/mosaic/util/index.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/index.ts +3 -0
- package/src/mosaic/Container.tsx +3 -23
- package/src/mosaic/DragOverlay.tsx +0 -1
- package/src/mosaic/Root.tsx +2 -4
- package/src/mosaic/Tile.tsx +7 -18
- package/src/mosaic/hooks/useContainer.ts +5 -2
- package/src/mosaic/types.ts +0 -2
- package/src/mosaic/util/index.ts +0 -1
- package/dist/types/src/mosaic/util/props.d.ts +0 -4
- package/dist/types/src/mosaic/util/props.d.ts.map +0 -1
- package/src/mosaic/util/props.ts +0 -14
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useContainer.ts
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
+
import { raise } from "@dxos/debug";
|
|
3
4
|
|
|
4
5
|
// packages/ui/react-ui-mosaic/src/mosaic/Container.tsx
|
|
5
6
|
import React, { createContext, useEffect } from "react";
|
|
6
7
|
var DEFAULT_TRANSITION = 200;
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
"transfer",
|
|
10
|
-
"copy",
|
|
11
|
-
"rearrange",
|
|
12
|
-
"reject"
|
|
13
|
-
];
|
|
14
|
-
var MosaicContainerContext = /* @__PURE__ */ createContext({
|
|
15
|
-
id: "never",
|
|
16
|
-
type: DEFAULT_TYPE
|
|
17
|
-
});
|
|
18
|
-
var MosaicContainer = ({ children, id, debug, type = DEFAULT_TYPE, Component: Component2, transitionDuration = DEFAULT_TRANSITION, modifier, getOverlayProps, getOverlayStyle, onOver, onDrop }) => {
|
|
8
|
+
var MosaicContainerContext = /* @__PURE__ */ createContext(void 0);
|
|
9
|
+
var MosaicContainer = ({ children, id, debug, Component: Component2, transitionDuration = DEFAULT_TRANSITION, modifier, getOverlayProps, getOverlayStyle, onOver, onDrop }) => {
|
|
19
10
|
const mosaic = useMosaic();
|
|
20
11
|
const container = {
|
|
21
12
|
id,
|
|
22
13
|
debug,
|
|
23
|
-
type,
|
|
24
14
|
Component: Component2,
|
|
25
15
|
transitionDuration,
|
|
26
16
|
modifier,
|
|
@@ -40,14 +30,14 @@ var MosaicContainer = ({ children, id, debug, type = DEFAULT_TYPE, Component: Co
|
|
|
40
30
|
};
|
|
41
31
|
|
|
42
32
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useContainer.ts
|
|
43
|
-
var useContainer = () => useContext(MosaicContainerContext);
|
|
33
|
+
var useContainer = () => useContext(MosaicContainerContext) ?? raise(new Error("Missing MosaicContainerContext"));
|
|
44
34
|
|
|
45
35
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useItemsWithPreview.ts
|
|
46
36
|
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
47
37
|
|
|
48
38
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useMosaic.ts
|
|
49
39
|
import { useContext as useContext2 } from "react";
|
|
50
|
-
import { raise } from "@dxos/debug";
|
|
40
|
+
import { raise as raise2 } from "@dxos/debug";
|
|
51
41
|
|
|
52
42
|
// packages/ui/react-ui-mosaic/src/mosaic/Root.tsx
|
|
53
43
|
import { DndContext, KeyboardSensor, MouseSensor, pointerWithin, rectIntersection, TouchSensor, useSensor, useSensors } from "@dnd-kit/core";
|
|
@@ -91,10 +81,6 @@ var Path = {
|
|
|
91
81
|
onPath: (path, id) => Path.parts(path).includes(id)
|
|
92
82
|
};
|
|
93
83
|
|
|
94
|
-
// packages/ui/react-ui-mosaic/src/mosaic/util/props.ts
|
|
95
|
-
var isTileProps = (props) => typeof props.path === "string" && typeof props.item === "object" && props.item ? "id" in props.item && typeof props.item.id === "string" : false;
|
|
96
|
-
var isTileComponentProps = (props) => isTileProps(props) && typeof props.operation === "string" && MosaicOperations.includes(props.operation);
|
|
97
|
-
|
|
98
84
|
// packages/ui/react-ui-mosaic/src/mosaic/util/styles.ts
|
|
99
85
|
import { CSS } from "@dnd-kit/utilities";
|
|
100
86
|
var getTransformCSS = (transform) => transform ? CSS.Transform.toString(Object.assign(transform, {
|
|
@@ -169,12 +155,12 @@ var MosaicRoot = ({ Component: Component2 = DefaultComponent, debug, children })
|
|
|
169
155
|
coordinateGetter: sortableKeyboardCoordinates
|
|
170
156
|
}));
|
|
171
157
|
const handleDragStart = (event) => {
|
|
172
|
-
setActiveItem(pick(event.active.data.current, "path", "
|
|
158
|
+
setActiveItem(pick(event.active.data.current, "path", "item", "position"));
|
|
173
159
|
};
|
|
174
160
|
const handleDragMove = (event) => {
|
|
175
161
|
};
|
|
176
162
|
const handleDragOver = (event) => {
|
|
177
|
-
const overItem2 = pick(event.over?.data.current, "path", "
|
|
163
|
+
const overItem2 = pick(event.over?.data.current, "path", "item", "position");
|
|
178
164
|
if (overItem2?.item?.id === activeItem?.item.id) {
|
|
179
165
|
return;
|
|
180
166
|
}
|
|
@@ -270,13 +256,11 @@ var MosaicDebug = ({ containers, operation, activeItem, overItem }) => {
|
|
|
270
256
|
active: {
|
|
271
257
|
id: activeItem?.item?.id.slice(0, 16),
|
|
272
258
|
path: activeItem?.path && Path.create(...Path.parts(activeItem.path).map((part) => part.slice(0, 16))),
|
|
273
|
-
type: activeItem?.type,
|
|
274
259
|
position: activeItem?.position
|
|
275
260
|
},
|
|
276
261
|
over: {
|
|
277
262
|
id: overItem?.item?.id.slice(0, 16),
|
|
278
263
|
path: overItem?.path && Path.create(...Path.parts(overItem.path).map((part) => part.slice(0, 16))),
|
|
279
|
-
type: overItem?.type,
|
|
280
264
|
position: overItem?.position
|
|
281
265
|
}
|
|
282
266
|
}
|
|
@@ -284,7 +268,7 @@ var MosaicDebug = ({ containers, operation, activeItem, overItem }) => {
|
|
|
284
268
|
};
|
|
285
269
|
|
|
286
270
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useMosaic.ts
|
|
287
|
-
var useMosaic = () => useContext2(MosaicContext) ??
|
|
271
|
+
var useMosaic = () => useContext2(MosaicContext) ?? raise2(new Error("Missing MosaicContext"));
|
|
288
272
|
|
|
289
273
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useItemsWithPreview.ts
|
|
290
274
|
var useItemsWithPreview = ({ path, items }) => {
|
|
@@ -380,19 +364,19 @@ var MosaicDragOverlay = ({ delay = 200, debug = false, ...overlayProps }) => {
|
|
|
380
364
|
useEffect3(() => {
|
|
381
365
|
if (activeItem) {
|
|
382
366
|
let container2;
|
|
383
|
-
let
|
|
367
|
+
let OverlayComponent3;
|
|
384
368
|
if (overItem?.path) {
|
|
385
369
|
container2 = containers[Path.first(overItem.path)];
|
|
386
|
-
|
|
370
|
+
OverlayComponent3 = container2?.Component;
|
|
387
371
|
}
|
|
388
|
-
if (!
|
|
372
|
+
if (!OverlayComponent3) {
|
|
389
373
|
container2 = containers[Path.first(activeItem.path)];
|
|
390
|
-
|
|
374
|
+
OverlayComponent3 = container2?.Component ?? DefaultComponent;
|
|
391
375
|
}
|
|
392
376
|
clearTimeout(timer.current);
|
|
393
377
|
timer.current = setTimeout(() => setState({
|
|
394
378
|
container: container2,
|
|
395
|
-
OverlayComponent:
|
|
379
|
+
OverlayComponent: OverlayComponent3
|
|
396
380
|
}), timer.current ? delay : 0);
|
|
397
381
|
} else {
|
|
398
382
|
setState({});
|
|
@@ -402,7 +386,7 @@ var MosaicDragOverlay = ({ delay = 200, debug = false, ...overlayProps }) => {
|
|
|
402
386
|
overItem
|
|
403
387
|
]);
|
|
404
388
|
const container = state.container ?? (activeItem && containers[Path.first(activeItem.path)]);
|
|
405
|
-
const
|
|
389
|
+
const OverlayComponent2 = state.OverlayComponent ?? container?.Component;
|
|
406
390
|
const FallbackComponent = (activeItem && containers[Path.first(activeItem.path)])?.Component ?? DefaultComponent;
|
|
407
391
|
return (
|
|
408
392
|
// TODO(burdon): Set custom animations (e.g., in/out/around).
|
|
@@ -412,7 +396,7 @@ var MosaicDragOverlay = ({ delay = 200, debug = false, ...overlayProps }) => {
|
|
|
412
396
|
style: {
|
|
413
397
|
...container?.getOverlayStyle?.()
|
|
414
398
|
}
|
|
415
|
-
}, activeItem?.path && container &&
|
|
399
|
+
}, activeItem?.path && container && OverlayComponent2 && /* @__PURE__ */ React5.createElement(OverlayErrorBoundary, {
|
|
416
400
|
fallback: /* @__PURE__ */ React5.createElement(FallbackComponent, {
|
|
417
401
|
...container.getOverlayProps?.(),
|
|
418
402
|
item: activeItem.item,
|
|
@@ -420,11 +404,10 @@ var MosaicDragOverlay = ({ delay = 200, debug = false, ...overlayProps }) => {
|
|
|
420
404
|
operation,
|
|
421
405
|
active: "overlay"
|
|
422
406
|
})
|
|
423
|
-
}, /* @__PURE__ */ React5.createElement(
|
|
407
|
+
}, /* @__PURE__ */ React5.createElement(OverlayComponent2, {
|
|
424
408
|
...container.getOverlayProps?.(),
|
|
425
409
|
item: activeItem.item,
|
|
426
410
|
path: activeItem.path,
|
|
427
|
-
type: activeItem.type,
|
|
428
411
|
operation,
|
|
429
412
|
active: "overlay"
|
|
430
413
|
}), debug && /* @__PURE__ */ React5.createElement("div", {
|
|
@@ -497,7 +480,7 @@ var Row = ({ children, id, items }) => /* @__PURE__ */ React6.createElement(Sort
|
|
|
497
480
|
import { useDraggable, useDroppable } from "@dnd-kit/core";
|
|
498
481
|
import { defaultAnimateLayoutChanges, useSortable } from "@dnd-kit/sortable";
|
|
499
482
|
import React7 from "react";
|
|
500
|
-
var DraggableTile = ({ path: parentPath,
|
|
483
|
+
var DraggableTile = ({ path: parentPath, item, Component: Component2 = DefaultComponent, position, draggableStyle, ...props }) => {
|
|
501
484
|
const { operation } = useMosaic();
|
|
502
485
|
const path = Path.create(parentPath, item.id);
|
|
503
486
|
const {
|
|
@@ -510,7 +493,6 @@ var DraggableTile = ({ path: parentPath, type = DEFAULT_TYPE, item, Component: C
|
|
|
510
493
|
id: path,
|
|
511
494
|
data: {
|
|
512
495
|
path,
|
|
513
|
-
type,
|
|
514
496
|
item,
|
|
515
497
|
position
|
|
516
498
|
}
|
|
@@ -519,7 +501,6 @@ var DraggableTile = ({ path: parentPath, type = DEFAULT_TYPE, item, Component: C
|
|
|
519
501
|
ref: setNodeRef,
|
|
520
502
|
item,
|
|
521
503
|
path,
|
|
522
|
-
type,
|
|
523
504
|
position,
|
|
524
505
|
operation,
|
|
525
506
|
isDragging,
|
|
@@ -535,14 +516,13 @@ var DraggableTile = ({ path: parentPath, type = DEFAULT_TYPE, item, Component: C
|
|
|
535
516
|
...props
|
|
536
517
|
});
|
|
537
518
|
};
|
|
538
|
-
var DroppableTile = ({ path: parentPath,
|
|
519
|
+
var DroppableTile = ({ path: parentPath, item, Component: Component2 = DefaultComponent, position, ...props }) => {
|
|
539
520
|
const { operation } = useMosaic();
|
|
540
521
|
const path = parentPath === item.id ? parentPath : Path.create(parentPath, item.id);
|
|
541
522
|
const { setNodeRef, isOver } = useDroppable({
|
|
542
523
|
id: path,
|
|
543
524
|
data: {
|
|
544
525
|
path,
|
|
545
|
-
type,
|
|
546
526
|
item,
|
|
547
527
|
position
|
|
548
528
|
}
|
|
@@ -551,14 +531,13 @@ var DroppableTile = ({ path: parentPath, type = DEFAULT_TYPE, item, Component: C
|
|
|
551
531
|
ref: setNodeRef,
|
|
552
532
|
item,
|
|
553
533
|
path,
|
|
554
|
-
type,
|
|
555
534
|
position,
|
|
556
535
|
operation,
|
|
557
536
|
isOver,
|
|
558
537
|
...props
|
|
559
538
|
});
|
|
560
539
|
};
|
|
561
|
-
var SortableTile = ({ path: parentPath,
|
|
540
|
+
var SortableTile = ({ path: parentPath, item, Component: OverrideComponent, position, draggableStyle, ...props }) => {
|
|
562
541
|
const { operation, activeItem, overItem } = useMosaic();
|
|
563
542
|
const { transitionDuration, Component: ContainerComponent } = useContainer();
|
|
564
543
|
const path = Path.create(parentPath, item.id);
|
|
@@ -567,7 +546,6 @@ var SortableTile = ({ path: parentPath, type = DEFAULT_TYPE, item, Component: Ov
|
|
|
567
546
|
id: isPreview ? activeItem.path : path,
|
|
568
547
|
data: {
|
|
569
548
|
path,
|
|
570
|
-
type,
|
|
571
549
|
item,
|
|
572
550
|
position
|
|
573
551
|
},
|
|
@@ -591,7 +569,6 @@ var SortableTile = ({ path: parentPath, type = DEFAULT_TYPE, item, Component: Ov
|
|
|
591
569
|
ref: setNodeRef,
|
|
592
570
|
item,
|
|
593
571
|
path,
|
|
594
|
-
type,
|
|
595
572
|
position,
|
|
596
573
|
operation,
|
|
597
574
|
active,
|
|
@@ -624,12 +601,441 @@ var Mosaic = {
|
|
|
624
601
|
// TODO(burdon): Don't export; move to util.
|
|
625
602
|
Debug
|
|
626
603
|
};
|
|
604
|
+
|
|
605
|
+
// packages/ui/react-ui-mosaic/src/views/Grid/layout.ts
|
|
606
|
+
var createMatrix = (size, value) => {
|
|
607
|
+
const matrix = [];
|
|
608
|
+
for (let x = 0; x < size.x; x++) {
|
|
609
|
+
matrix.push(Array.from({
|
|
610
|
+
length: size.y
|
|
611
|
+
}, (_, y) => value({
|
|
612
|
+
x,
|
|
613
|
+
y
|
|
614
|
+
})));
|
|
615
|
+
}
|
|
616
|
+
return matrix;
|
|
617
|
+
};
|
|
618
|
+
var getDimension = ({ width, height }, spacing = 0) => ({
|
|
619
|
+
width: width - spacing * 2,
|
|
620
|
+
height: height - spacing * 2
|
|
621
|
+
});
|
|
622
|
+
var getBounds = ({ x, y }, { width, height }, spacing = 0) => ({
|
|
623
|
+
left: x * width + spacing * 2,
|
|
624
|
+
top: y * height + spacing * 2,
|
|
625
|
+
width: width - spacing * 2,
|
|
626
|
+
height: height - spacing * 2
|
|
627
|
+
});
|
|
628
|
+
var getPanelBounds = ({ x, y }, { width, height }, spacing = 0) => ({
|
|
629
|
+
width: x * width + spacing * 2,
|
|
630
|
+
height: y * height + spacing * 2
|
|
631
|
+
});
|
|
632
|
+
var calculateCellWidth = (defaultWidth, screenWidth, options = {
|
|
633
|
+
min: 260,
|
|
634
|
+
max: 400
|
|
635
|
+
}) => {
|
|
636
|
+
return screenWidth > options.min && screenWidth < options.max ? screenWidth : defaultWidth;
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
// packages/ui/react-ui-mosaic/src/views/Grid/Grid.tsx
|
|
640
|
+
import { useDroppable as useDroppable2 } from "@dnd-kit/core";
|
|
641
|
+
import { PlusCircle } from "@phosphor-icons/react";
|
|
642
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
643
|
+
import React8, { useState as useState4, useMemo, useEffect as useEffect4 } from "react";
|
|
644
|
+
import { useResizeDetector } from "react-resize-detector";
|
|
645
|
+
import { Button, useMediaQuery } from "@dxos/react-ui";
|
|
646
|
+
import { getSize, mx as mx2 } from "@dxos/react-ui-theme";
|
|
647
|
+
var defaultGridOptions = {
|
|
648
|
+
size: {
|
|
649
|
+
x: 8,
|
|
650
|
+
y: 8
|
|
651
|
+
},
|
|
652
|
+
cellBounds: {
|
|
653
|
+
width: 272,
|
|
654
|
+
height: 272
|
|
655
|
+
},
|
|
656
|
+
spacing: 6
|
|
657
|
+
};
|
|
658
|
+
var Grid = ({ id, items = [], layout = {}, options: opts, margin, square = true, debug, selected: controlledSelected, Component: Component2 = Mosaic.DefaultComponent, className, onDrop, onOver, onSelect, onCreate, onAction }) => {
|
|
659
|
+
const { ref: containerRef, width, height } = useResizeDetector({
|
|
660
|
+
refreshRate: 200
|
|
661
|
+
});
|
|
662
|
+
const options = defaultsDeep({}, opts, defaultGridOptions);
|
|
663
|
+
const { matrix, bounds, cellBounds } = useMemo(() => {
|
|
664
|
+
const cellWidth = calculateCellWidth(options.cellBounds.width, width ?? 0);
|
|
665
|
+
const cellBounds2 = {
|
|
666
|
+
width: cellWidth,
|
|
667
|
+
height: square ? cellWidth : options.cellBounds.height
|
|
668
|
+
};
|
|
669
|
+
return {
|
|
670
|
+
matrix: createMatrix(options.size, ({ x, y }) => ({
|
|
671
|
+
x,
|
|
672
|
+
y
|
|
673
|
+
})),
|
|
674
|
+
bounds: getPanelBounds(options.size, cellBounds2, options.spacing),
|
|
675
|
+
cellBounds: cellBounds2
|
|
676
|
+
};
|
|
677
|
+
}, [
|
|
678
|
+
options,
|
|
679
|
+
width
|
|
680
|
+
]);
|
|
681
|
+
const [isNotMobile] = useMediaQuery("md");
|
|
682
|
+
const marginSize = margin && !isNotMobile ? Math.max(cellBounds.width, cellBounds.height) : 0;
|
|
683
|
+
const [selected, setSelected] = useState4(controlledSelected);
|
|
684
|
+
useEffect4(() => {
|
|
685
|
+
setSelected(controlledSelected);
|
|
686
|
+
if (controlledSelected) {
|
|
687
|
+
scrollToCenter(controlledSelected);
|
|
688
|
+
}
|
|
689
|
+
}, [
|
|
690
|
+
controlledSelected
|
|
691
|
+
]);
|
|
692
|
+
const scrollToCenter = (id2) => {
|
|
693
|
+
const item = items.find((item2) => item2.id === id2);
|
|
694
|
+
if (item && width && height) {
|
|
695
|
+
const pos = getBounds(layout[item.id], cellBounds);
|
|
696
|
+
const top = pos.top + marginSize - (height - cellBounds.height) / 2;
|
|
697
|
+
const left = pos.left + marginSize - (width - cellBounds.width) / 2;
|
|
698
|
+
containerRef.current.scrollTo({
|
|
699
|
+
top,
|
|
700
|
+
left,
|
|
701
|
+
behavior: "smooth"
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
const handleSelect = (id2) => {
|
|
706
|
+
setSelected(id2);
|
|
707
|
+
scrollToCenter(id2);
|
|
708
|
+
onSelect?.(id2);
|
|
709
|
+
};
|
|
710
|
+
useEffect4(() => {
|
|
711
|
+
if (selected) {
|
|
712
|
+
scrollToCenter(selected);
|
|
713
|
+
}
|
|
714
|
+
}, [
|
|
715
|
+
selected,
|
|
716
|
+
width,
|
|
717
|
+
height
|
|
718
|
+
]);
|
|
719
|
+
return /* @__PURE__ */ React8.createElement(Mosaic.Container, {
|
|
720
|
+
id,
|
|
721
|
+
Component: Component2,
|
|
722
|
+
getOverlayProps: () => ({
|
|
723
|
+
grow: true
|
|
724
|
+
}),
|
|
725
|
+
getOverlayStyle: () => ({
|
|
726
|
+
display: "flex",
|
|
727
|
+
...getDimension(cellBounds, options.spacing)
|
|
728
|
+
}),
|
|
729
|
+
onDrop,
|
|
730
|
+
onOver
|
|
731
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
732
|
+
className: mx2("flex grow overflow-auto", className)
|
|
733
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
734
|
+
ref: containerRef,
|
|
735
|
+
className: mx2("grow overflow-auto snap-x md:snap-none snap-mandatory")
|
|
736
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
737
|
+
className: "group block relative",
|
|
738
|
+
style: {
|
|
739
|
+
...bounds,
|
|
740
|
+
margin: marginSize
|
|
741
|
+
}
|
|
742
|
+
}, matrix && /* @__PURE__ */ React8.createElement("div", {
|
|
743
|
+
style: {
|
|
744
|
+
padding: options.spacing
|
|
745
|
+
}
|
|
746
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
747
|
+
className: "relative"
|
|
748
|
+
}, matrix.map((row) => row.map(({ x, y }) => /* @__PURE__ */ React8.createElement(GridCell, {
|
|
749
|
+
key: `${x}-${y}`,
|
|
750
|
+
path: id,
|
|
751
|
+
position: {
|
|
752
|
+
x,
|
|
753
|
+
y
|
|
754
|
+
},
|
|
755
|
+
bounds: getBounds({
|
|
756
|
+
x,
|
|
757
|
+
y
|
|
758
|
+
}, cellBounds),
|
|
759
|
+
padding: options.spacing,
|
|
760
|
+
onCreate
|
|
761
|
+
}))))), /* @__PURE__ */ React8.createElement("div", null, items.map((item) => {
|
|
762
|
+
const position = layout[item.id] ?? {
|
|
763
|
+
x: 0,
|
|
764
|
+
y: 0
|
|
765
|
+
};
|
|
766
|
+
return /* @__PURE__ */ React8.createElement(Mosaic.DraggableTile, {
|
|
767
|
+
key: item.id,
|
|
768
|
+
item,
|
|
769
|
+
path: id,
|
|
770
|
+
position,
|
|
771
|
+
Component: Component2,
|
|
772
|
+
draggableStyle: {
|
|
773
|
+
position: "absolute",
|
|
774
|
+
...getBounds(position, cellBounds, options.spacing)
|
|
775
|
+
},
|
|
776
|
+
onSelect: () => handleSelect(item.id),
|
|
777
|
+
onAction
|
|
778
|
+
});
|
|
779
|
+
}))), debug && /* @__PURE__ */ React8.createElement(Mosaic.Debug, {
|
|
780
|
+
data: {
|
|
781
|
+
items: items?.length
|
|
782
|
+
},
|
|
783
|
+
position: "bottom-right"
|
|
784
|
+
}))));
|
|
785
|
+
};
|
|
786
|
+
var GridCell = ({ path, position, bounds, padding, onCreate }) => {
|
|
787
|
+
const { overItem } = useMosaic();
|
|
788
|
+
const isOverContainer = path === overItem?.path;
|
|
789
|
+
const { setNodeRef, isOver } = useDroppable2({
|
|
790
|
+
id: Path.create(path, "cell", `${position.x}-${position.y}`),
|
|
791
|
+
data: {
|
|
792
|
+
path,
|
|
793
|
+
position
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
return /* @__PURE__ */ React8.createElement("div", {
|
|
797
|
+
ref: setNodeRef,
|
|
798
|
+
style: {
|
|
799
|
+
...bounds,
|
|
800
|
+
padding
|
|
801
|
+
},
|
|
802
|
+
className: "absolute flex justify-center items-center grow select-none cursor-pointer"
|
|
803
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
804
|
+
className: mx2("group/cell flex group-hover:flex w-full h-full items-center justify-center", "box-border border-dashed border-4 border-neutral-75 dark:border-neutral-850 rounded-lg", "transition ease-in-out duration-300", isOver && "flex bg-neutral-75 dark:bg-neutral-850 border-neutral-200 dark:border-neutral-800")
|
|
805
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
806
|
+
className: mx2("opacity-10 transition ease-in-out duration-300 group-hover/cell:opacity-100", isOverContainer && "hidden")
|
|
807
|
+
}, onCreate && // TODO(burdon): Style button.
|
|
808
|
+
/* @__PURE__ */ React8.createElement(Button, {
|
|
809
|
+
variant: "ghost",
|
|
810
|
+
onClick: () => onCreate(position)
|
|
811
|
+
}, /* @__PURE__ */ React8.createElement(PlusCircle, {
|
|
812
|
+
className: getSize(8)
|
|
813
|
+
})))));
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
// packages/ui/react-ui-mosaic/src/views/Kanban/Kanban.tsx
|
|
817
|
+
import React9, { forwardRef as forwardRef2, useMemo as useMemo2 } from "react";
|
|
818
|
+
import { Card as Card2 } from "@dxos/react-ui";
|
|
819
|
+
import { groupSurface, mx as mx3 } from "@dxos/react-ui-theme";
|
|
820
|
+
var Kanban = ({ id, columns, Component: TileComponent = Mosaic.DefaultComponent, debug, onDrop }) => {
|
|
821
|
+
const Component2 = useMemo2(() => OverlayComponent(id, TileComponent), [
|
|
822
|
+
id,
|
|
823
|
+
TileComponent
|
|
824
|
+
]);
|
|
825
|
+
return /* @__PURE__ */ React9.createElement(Mosaic.Container, {
|
|
826
|
+
id,
|
|
827
|
+
debug,
|
|
828
|
+
Component: Component2,
|
|
829
|
+
// Restrict columns to x-axis.
|
|
830
|
+
modifier: ({ path, item }, { transform }) => path === Path.create(id, item.id) ? {
|
|
831
|
+
...transform,
|
|
832
|
+
y: 0
|
|
833
|
+
} : transform,
|
|
834
|
+
// Restrict to objects from other columns.
|
|
835
|
+
// TODO(burdon): Consider objects from other containers.
|
|
836
|
+
// TODO(wittjosiah): Allow override.
|
|
837
|
+
onOver: ({ active, over }) => Path.length(active.path) >= Path.length(over.path) ? "transfer" : "reject",
|
|
838
|
+
onDrop
|
|
839
|
+
}, /* @__PURE__ */ React9.createElement("div", {
|
|
840
|
+
className: "grow flex overflow-y-hidden overflow-x-auto"
|
|
841
|
+
}, /* @__PURE__ */ React9.createElement("div", {
|
|
842
|
+
className: "flex"
|
|
843
|
+
}, /* @__PURE__ */ React9.createElement(Mosaic.SortableContext, {
|
|
844
|
+
items: columns,
|
|
845
|
+
direction: "horizontal"
|
|
846
|
+
}, columns.map((column, index) => /* @__PURE__ */ React9.createElement(Mosaic.SortableTile, {
|
|
847
|
+
key: column.id,
|
|
848
|
+
item: column,
|
|
849
|
+
path: id,
|
|
850
|
+
position: index,
|
|
851
|
+
Component: Component2,
|
|
852
|
+
debug
|
|
853
|
+
}))))));
|
|
854
|
+
};
|
|
855
|
+
var OverlayComponent = (id, Component2) => /* @__PURE__ */ forwardRef2((props, ref) => {
|
|
856
|
+
const isColumn = Path.hasRoot(props.path, id) && Path.length(props.path) === 2;
|
|
857
|
+
if (isColumn && props.active === "overlay") {
|
|
858
|
+
return (
|
|
859
|
+
// Needs to not override the main kanban path.
|
|
860
|
+
/* @__PURE__ */ React9.createElement(Mosaic.Container, {
|
|
861
|
+
id: `${id}-active`,
|
|
862
|
+
Component: Component2
|
|
863
|
+
}, /* @__PURE__ */ React9.createElement(KanbanColumnComponent, {
|
|
864
|
+
...props,
|
|
865
|
+
ref
|
|
866
|
+
}))
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
return isColumn ? /* @__PURE__ */ React9.createElement(KanbanColumnComponent, {
|
|
870
|
+
...props,
|
|
871
|
+
ref
|
|
872
|
+
}) : /* @__PURE__ */ React9.createElement(Component2, {
|
|
873
|
+
...props,
|
|
874
|
+
ref
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
var KanbanColumnComponent = /* @__PURE__ */ forwardRef2(({ path, item, active, draggableStyle, draggableProps, debug }, forwardRef1) => {
|
|
878
|
+
const { id, title, items } = item;
|
|
879
|
+
const { Component: Component2 } = useContainer();
|
|
880
|
+
const itemsWithPreview = useItemsWithPreview({
|
|
881
|
+
path,
|
|
882
|
+
items
|
|
883
|
+
});
|
|
884
|
+
return /* @__PURE__ */ React9.createElement("div", {
|
|
885
|
+
role: "none",
|
|
886
|
+
className: "grow flex flex-col",
|
|
887
|
+
ref: forwardRef1
|
|
888
|
+
}, /* @__PURE__ */ React9.createElement("div", {
|
|
889
|
+
className: mx3(groupSurface, "grow flex flex-col w-[300px] snap-center overflow-hidden m-1", active === "rearrange" && "opacity-0"),
|
|
890
|
+
style: draggableStyle
|
|
891
|
+
}, /* @__PURE__ */ React9.createElement(Card2.Root, {
|
|
892
|
+
classNames: "shrink-0 bg-cyan-200"
|
|
893
|
+
}, /* @__PURE__ */ React9.createElement(Card2.Header, null, /* @__PURE__ */ React9.createElement(Card2.DragHandle, draggableProps), /* @__PURE__ */ React9.createElement(Card2.Title, {
|
|
894
|
+
title
|
|
895
|
+
}), /* @__PURE__ */ React9.createElement(Card2.Menu, null))), /* @__PURE__ */ React9.createElement("div", {
|
|
896
|
+
className: mx3("flex flex-col grow overflow-y-scroll")
|
|
897
|
+
}, /* @__PURE__ */ React9.createElement("div", {
|
|
898
|
+
className: "flex flex-col my-1"
|
|
899
|
+
}, /* @__PURE__ */ React9.createElement(Mosaic.SortableContext, {
|
|
900
|
+
id: path,
|
|
901
|
+
items: itemsWithPreview,
|
|
902
|
+
direction: "vertical"
|
|
903
|
+
}, itemsWithPreview.map((item2, index) => /* @__PURE__ */ React9.createElement(Mosaic.SortableTile, {
|
|
904
|
+
key: item2.id,
|
|
905
|
+
item: item2,
|
|
906
|
+
path,
|
|
907
|
+
position: index,
|
|
908
|
+
Component: Component2,
|
|
909
|
+
className: "m-1"
|
|
910
|
+
}))))), debug && /* @__PURE__ */ React9.createElement(Mosaic.Debug, {
|
|
911
|
+
data: {
|
|
912
|
+
path,
|
|
913
|
+
id,
|
|
914
|
+
items: itemsWithPreview.length
|
|
915
|
+
}
|
|
916
|
+
})));
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
// packages/ui/react-ui-mosaic/src/views/Stack/Stack.tsx
|
|
920
|
+
import React10 from "react";
|
|
921
|
+
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
922
|
+
var Stack = ({ id, Component: Component2 = Mosaic.DefaultComponent, onOver, onDrop, items = [], direction = "vertical", debug }) => {
|
|
923
|
+
const itemsWithPreview = useItemsWithPreview({
|
|
924
|
+
path: id,
|
|
925
|
+
items
|
|
926
|
+
});
|
|
927
|
+
return /* @__PURE__ */ React10.createElement("div", {
|
|
928
|
+
className: mx4("flex overflow-hidden", direction === "vertical" && "w-[300px]")
|
|
929
|
+
}, /* @__PURE__ */ React10.createElement("div", {
|
|
930
|
+
className: mx4("flex flex-col w-full my-1", direction === "vertical" ? "overflow-y-auto" : "overflow-x-auto")
|
|
931
|
+
}, /* @__PURE__ */ React10.createElement(Mosaic.Container, {
|
|
932
|
+
id,
|
|
933
|
+
Component: Component2,
|
|
934
|
+
onOver,
|
|
935
|
+
onDrop
|
|
936
|
+
}, /* @__PURE__ */ React10.createElement(Mosaic.SortableContext, {
|
|
937
|
+
items: itemsWithPreview,
|
|
938
|
+
direction
|
|
939
|
+
}, itemsWithPreview.map((item, index) => /* @__PURE__ */ React10.createElement(Mosaic.SortableTile, {
|
|
940
|
+
key: item.id,
|
|
941
|
+
item,
|
|
942
|
+
path: id,
|
|
943
|
+
position: index,
|
|
944
|
+
className: "m-1"
|
|
945
|
+
})))), debug && /* @__PURE__ */ React10.createElement("div", {
|
|
946
|
+
className: "grow"
|
|
947
|
+
}, /* @__PURE__ */ React10.createElement(Mosaic.Debug, {
|
|
948
|
+
data: {
|
|
949
|
+
id,
|
|
950
|
+
items: itemsWithPreview.length
|
|
951
|
+
}
|
|
952
|
+
}))));
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
// packages/ui/react-ui-mosaic/src/views/Tree/Tree.tsx
|
|
956
|
+
import React11, { forwardRef as forwardRef3 } from "react";
|
|
957
|
+
import { Card as Card3, Tree as TreeComponent, TreeItem as TreeItemComponent } from "@dxos/react-ui";
|
|
958
|
+
import { dropRing, mx as mx5 } from "@dxos/react-ui-theme";
|
|
959
|
+
var Tree = ({ id, Component: Component2 = TreeItem, onOver, onDrop, items = [], debug }) => {
|
|
960
|
+
return /* @__PURE__ */ React11.createElement(Mosaic.Container, {
|
|
961
|
+
id,
|
|
962
|
+
debug,
|
|
963
|
+
Component: Component2,
|
|
964
|
+
onOver,
|
|
965
|
+
onDrop
|
|
966
|
+
}, /* @__PURE__ */ React11.createElement(TreeRoot, {
|
|
967
|
+
items
|
|
968
|
+
}));
|
|
969
|
+
};
|
|
970
|
+
var TreeRoot = ({ items }) => {
|
|
971
|
+
const { id, Component: Component2 } = useContainer();
|
|
972
|
+
const itemsWithOrigin = useItemsWithOrigin(id, items);
|
|
973
|
+
return /* @__PURE__ */ React11.createElement(TreeComponent.Root, {
|
|
974
|
+
classNames: "flex flex-col"
|
|
975
|
+
}, /* @__PURE__ */ React11.createElement(Mosaic.SortableContext, {
|
|
976
|
+
id,
|
|
977
|
+
items: itemsWithOrigin,
|
|
978
|
+
direction: "vertical"
|
|
979
|
+
}, itemsWithOrigin.map((item, index) => /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
|
|
980
|
+
key: item.id,
|
|
981
|
+
collapsible: true,
|
|
982
|
+
defaultOpen: true
|
|
983
|
+
}, /* @__PURE__ */ React11.createElement(Mosaic.SortableTile, {
|
|
984
|
+
item,
|
|
985
|
+
path: id,
|
|
986
|
+
position: index,
|
|
987
|
+
Component: Component2
|
|
988
|
+
})))));
|
|
989
|
+
};
|
|
990
|
+
var TreeItem = /* @__PURE__ */ forwardRef3(({ path, draggableStyle, draggableProps, item, operation, active, isOver, isDragging, className }, forwardedRef) => {
|
|
991
|
+
return /* @__PURE__ */ React11.createElement("div", {
|
|
992
|
+
ref: forwardedRef,
|
|
993
|
+
style: draggableStyle,
|
|
994
|
+
className: mx5("flex flex-col rounded", className, (active === "rearrange" || active === "origin") && "opacity-0", active === "destination" && "opacity-20", isOver && dropRing)
|
|
995
|
+
}, /* @__PURE__ */ React11.createElement(Card3.Header, null, /* @__PURE__ */ React11.createElement(Card3.DragHandle, draggableProps), /* @__PURE__ */ React11.createElement(Card3.Title, {
|
|
996
|
+
title: item.label ?? path,
|
|
997
|
+
classNames: "truncate"
|
|
998
|
+
})), !active && item.children && /* @__PURE__ */ React11.createElement(TreeBranch, {
|
|
999
|
+
path,
|
|
1000
|
+
items: item.children
|
|
1001
|
+
}));
|
|
1002
|
+
});
|
|
1003
|
+
var TreeBranch = ({ path, items }) => {
|
|
1004
|
+
const { operation, overItem } = useMosaic();
|
|
1005
|
+
const { Component: Component2 } = useContainer();
|
|
1006
|
+
const itemsWithOrigin = useItemsWithOrigin(path, items);
|
|
1007
|
+
return /* @__PURE__ */ React11.createElement(TreeItemComponent.Body, {
|
|
1008
|
+
className: "pis-4"
|
|
1009
|
+
}, /* @__PURE__ */ React11.createElement(Mosaic.SortableContext, {
|
|
1010
|
+
id: path,
|
|
1011
|
+
items: itemsWithOrigin,
|
|
1012
|
+
direction: "vertical"
|
|
1013
|
+
}, itemsWithOrigin.map((child, index) => /* @__PURE__ */ React11.createElement(TreeComponent.Branch, {
|
|
1014
|
+
key: child.id
|
|
1015
|
+
}, /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
|
|
1016
|
+
collapsible: true,
|
|
1017
|
+
defaultOpen: true
|
|
1018
|
+
}, /* @__PURE__ */ React11.createElement(Mosaic.SortableTile, {
|
|
1019
|
+
item: child,
|
|
1020
|
+
path,
|
|
1021
|
+
position: index,
|
|
1022
|
+
Component: Component2,
|
|
1023
|
+
isOver: overItem?.path === Path.create(path, child.id) && (operation === "transfer" || operation === "copy")
|
|
1024
|
+
}))))));
|
|
1025
|
+
};
|
|
627
1026
|
export {
|
|
1027
|
+
Grid,
|
|
1028
|
+
Kanban,
|
|
628
1029
|
Mosaic,
|
|
629
1030
|
Path,
|
|
1031
|
+
Stack,
|
|
1032
|
+
Tree,
|
|
1033
|
+
calculateCellWidth,
|
|
1034
|
+
createMatrix,
|
|
1035
|
+
getBounds,
|
|
1036
|
+
getDimension,
|
|
1037
|
+
getPanelBounds,
|
|
630
1038
|
getTransformCSS,
|
|
631
|
-
isTileComponentProps,
|
|
632
|
-
isTileProps,
|
|
633
1039
|
swapItems,
|
|
634
1040
|
useContainer,
|
|
635
1041
|
useItemsWithOrigin,
|