@dxos/react-ui-mosaic 0.3.8 → 0.3.9-main.325dd0a
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 +44 -450
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/mosaic/Container.d.ts +14 -4
- 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 +9 -7
- 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 +1 -0
- package/dist/types/src/mosaic/types.d.ts.map +1 -1
- package/dist/types/src/mosaic/util/index.d.ts +1 -0
- package/dist/types/src/mosaic/util/index.d.ts.map +1 -1
- package/dist/types/src/mosaic/util/props.d.ts +4 -0
- package/dist/types/src/mosaic/util/props.d.ts.map +1 -0
- package/package.json +12 -12
- package/src/index.ts +0 -3
- package/src/mosaic/Container.tsx +23 -3
- package/src/mosaic/DragOverlay.tsx +1 -0
- package/src/mosaic/Root.tsx +4 -2
- package/src/mosaic/Tile.tsx +18 -7
- package/src/mosaic/hooks/useContainer.ts +2 -5
- package/src/mosaic/types.ts +2 -0
- package/src/mosaic/util/index.ts +1 -0
- package/src/mosaic/util/props.ts +14 -0
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useContainer.ts
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import { raise } from "@dxos/debug";
|
|
4
3
|
|
|
5
4
|
// packages/ui/react-ui-mosaic/src/mosaic/Container.tsx
|
|
6
5
|
import React, { createContext, useEffect } from "react";
|
|
7
6
|
var DEFAULT_TRANSITION = 200;
|
|
8
|
-
var
|
|
9
|
-
var
|
|
7
|
+
var DEFAULT_TYPE = "unknown";
|
|
8
|
+
var MosaicOperations = [
|
|
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 }) => {
|
|
10
19
|
const mosaic = useMosaic();
|
|
11
20
|
const container = {
|
|
12
21
|
id,
|
|
13
22
|
debug,
|
|
23
|
+
type,
|
|
14
24
|
Component: Component2,
|
|
15
25
|
transitionDuration,
|
|
16
26
|
modifier,
|
|
@@ -30,14 +40,14 @@ var MosaicContainer = ({ children, id, debug, Component: Component2, transitionD
|
|
|
30
40
|
};
|
|
31
41
|
|
|
32
42
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useContainer.ts
|
|
33
|
-
var useContainer = () => useContext(MosaicContainerContext)
|
|
43
|
+
var useContainer = () => useContext(MosaicContainerContext);
|
|
34
44
|
|
|
35
45
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useItemsWithPreview.ts
|
|
36
46
|
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
37
47
|
|
|
38
48
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useMosaic.ts
|
|
39
49
|
import { useContext as useContext2 } from "react";
|
|
40
|
-
import { raise
|
|
50
|
+
import { raise } from "@dxos/debug";
|
|
41
51
|
|
|
42
52
|
// packages/ui/react-ui-mosaic/src/mosaic/Root.tsx
|
|
43
53
|
import { DndContext, KeyboardSensor, MouseSensor, pointerWithin, rectIntersection, TouchSensor, useSensor, useSensors } from "@dnd-kit/core";
|
|
@@ -81,6 +91,10 @@ var Path = {
|
|
|
81
91
|
onPath: (path, id) => Path.parts(path).includes(id)
|
|
82
92
|
};
|
|
83
93
|
|
|
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
|
+
|
|
84
98
|
// packages/ui/react-ui-mosaic/src/mosaic/util/styles.ts
|
|
85
99
|
import { CSS } from "@dnd-kit/utilities";
|
|
86
100
|
var getTransformCSS = (transform) => transform ? CSS.Transform.toString(Object.assign(transform, {
|
|
@@ -155,12 +169,12 @@ var MosaicRoot = ({ Component: Component2 = DefaultComponent, debug, children })
|
|
|
155
169
|
coordinateGetter: sortableKeyboardCoordinates
|
|
156
170
|
}));
|
|
157
171
|
const handleDragStart = (event) => {
|
|
158
|
-
setActiveItem(pick(event.active.data.current, "path", "item", "position"));
|
|
172
|
+
setActiveItem(pick(event.active.data.current, "path", "type", "item", "position"));
|
|
159
173
|
};
|
|
160
174
|
const handleDragMove = (event) => {
|
|
161
175
|
};
|
|
162
176
|
const handleDragOver = (event) => {
|
|
163
|
-
const overItem2 = pick(event.over?.data.current, "path", "item", "position");
|
|
177
|
+
const overItem2 = pick(event.over?.data.current, "path", "type", "item", "position");
|
|
164
178
|
if (overItem2?.item?.id === activeItem?.item.id) {
|
|
165
179
|
return;
|
|
166
180
|
}
|
|
@@ -256,11 +270,13 @@ var MosaicDebug = ({ containers, operation, activeItem, overItem }) => {
|
|
|
256
270
|
active: {
|
|
257
271
|
id: activeItem?.item?.id.slice(0, 16),
|
|
258
272
|
path: activeItem?.path && Path.create(...Path.parts(activeItem.path).map((part) => part.slice(0, 16))),
|
|
273
|
+
type: activeItem?.type,
|
|
259
274
|
position: activeItem?.position
|
|
260
275
|
},
|
|
261
276
|
over: {
|
|
262
277
|
id: overItem?.item?.id.slice(0, 16),
|
|
263
278
|
path: overItem?.path && Path.create(...Path.parts(overItem.path).map((part) => part.slice(0, 16))),
|
|
279
|
+
type: overItem?.type,
|
|
264
280
|
position: overItem?.position
|
|
265
281
|
}
|
|
266
282
|
}
|
|
@@ -268,7 +284,7 @@ var MosaicDebug = ({ containers, operation, activeItem, overItem }) => {
|
|
|
268
284
|
};
|
|
269
285
|
|
|
270
286
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useMosaic.ts
|
|
271
|
-
var useMosaic = () => useContext2(MosaicContext) ??
|
|
287
|
+
var useMosaic = () => useContext2(MosaicContext) ?? raise(new Error("Missing MosaicContext"));
|
|
272
288
|
|
|
273
289
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useItemsWithPreview.ts
|
|
274
290
|
var useItemsWithPreview = ({ path, items }) => {
|
|
@@ -364,19 +380,19 @@ var MosaicDragOverlay = ({ delay = 200, debug = false, ...overlayProps }) => {
|
|
|
364
380
|
useEffect3(() => {
|
|
365
381
|
if (activeItem) {
|
|
366
382
|
let container2;
|
|
367
|
-
let
|
|
383
|
+
let OverlayComponent2;
|
|
368
384
|
if (overItem?.path) {
|
|
369
385
|
container2 = containers[Path.first(overItem.path)];
|
|
370
|
-
|
|
386
|
+
OverlayComponent2 = container2?.Component;
|
|
371
387
|
}
|
|
372
|
-
if (!
|
|
388
|
+
if (!OverlayComponent2) {
|
|
373
389
|
container2 = containers[Path.first(activeItem.path)];
|
|
374
|
-
|
|
390
|
+
OverlayComponent2 = container2?.Component ?? DefaultComponent;
|
|
375
391
|
}
|
|
376
392
|
clearTimeout(timer.current);
|
|
377
393
|
timer.current = setTimeout(() => setState({
|
|
378
394
|
container: container2,
|
|
379
|
-
OverlayComponent:
|
|
395
|
+
OverlayComponent: OverlayComponent2
|
|
380
396
|
}), timer.current ? delay : 0);
|
|
381
397
|
} else {
|
|
382
398
|
setState({});
|
|
@@ -386,7 +402,7 @@ var MosaicDragOverlay = ({ delay = 200, debug = false, ...overlayProps }) => {
|
|
|
386
402
|
overItem
|
|
387
403
|
]);
|
|
388
404
|
const container = state.container ?? (activeItem && containers[Path.first(activeItem.path)]);
|
|
389
|
-
const
|
|
405
|
+
const OverlayComponent = state.OverlayComponent ?? container?.Component;
|
|
390
406
|
const FallbackComponent = (activeItem && containers[Path.first(activeItem.path)])?.Component ?? DefaultComponent;
|
|
391
407
|
return (
|
|
392
408
|
// TODO(burdon): Set custom animations (e.g., in/out/around).
|
|
@@ -396,7 +412,7 @@ var MosaicDragOverlay = ({ delay = 200, debug = false, ...overlayProps }) => {
|
|
|
396
412
|
style: {
|
|
397
413
|
...container?.getOverlayStyle?.()
|
|
398
414
|
}
|
|
399
|
-
}, activeItem?.path && container &&
|
|
415
|
+
}, activeItem?.path && container && OverlayComponent && /* @__PURE__ */ React5.createElement(OverlayErrorBoundary, {
|
|
400
416
|
fallback: /* @__PURE__ */ React5.createElement(FallbackComponent, {
|
|
401
417
|
...container.getOverlayProps?.(),
|
|
402
418
|
item: activeItem.item,
|
|
@@ -404,10 +420,11 @@ var MosaicDragOverlay = ({ delay = 200, debug = false, ...overlayProps }) => {
|
|
|
404
420
|
operation,
|
|
405
421
|
active: "overlay"
|
|
406
422
|
})
|
|
407
|
-
}, /* @__PURE__ */ React5.createElement(
|
|
423
|
+
}, /* @__PURE__ */ React5.createElement(OverlayComponent, {
|
|
408
424
|
...container.getOverlayProps?.(),
|
|
409
425
|
item: activeItem.item,
|
|
410
426
|
path: activeItem.path,
|
|
427
|
+
type: activeItem.type,
|
|
411
428
|
operation,
|
|
412
429
|
active: "overlay"
|
|
413
430
|
}), debug && /* @__PURE__ */ React5.createElement("div", {
|
|
@@ -480,7 +497,7 @@ var Row = ({ children, id, items }) => /* @__PURE__ */ React6.createElement(Sort
|
|
|
480
497
|
import { useDraggable, useDroppable } from "@dnd-kit/core";
|
|
481
498
|
import { defaultAnimateLayoutChanges, useSortable } from "@dnd-kit/sortable";
|
|
482
499
|
import React7 from "react";
|
|
483
|
-
var DraggableTile = ({ path: parentPath, item, Component: Component2 = DefaultComponent, position, draggableStyle, ...props }) => {
|
|
500
|
+
var DraggableTile = ({ path: parentPath, type = DEFAULT_TYPE, item, Component: Component2 = DefaultComponent, position, draggableStyle, ...props }) => {
|
|
484
501
|
const { operation } = useMosaic();
|
|
485
502
|
const path = Path.create(parentPath, item.id);
|
|
486
503
|
const {
|
|
@@ -493,6 +510,7 @@ var DraggableTile = ({ path: parentPath, item, Component: Component2 = DefaultCo
|
|
|
493
510
|
id: path,
|
|
494
511
|
data: {
|
|
495
512
|
path,
|
|
513
|
+
type,
|
|
496
514
|
item,
|
|
497
515
|
position
|
|
498
516
|
}
|
|
@@ -501,6 +519,7 @@ var DraggableTile = ({ path: parentPath, item, Component: Component2 = DefaultCo
|
|
|
501
519
|
ref: setNodeRef,
|
|
502
520
|
item,
|
|
503
521
|
path,
|
|
522
|
+
type,
|
|
504
523
|
position,
|
|
505
524
|
operation,
|
|
506
525
|
isDragging,
|
|
@@ -516,13 +535,14 @@ var DraggableTile = ({ path: parentPath, item, Component: Component2 = DefaultCo
|
|
|
516
535
|
...props
|
|
517
536
|
});
|
|
518
537
|
};
|
|
519
|
-
var DroppableTile = ({ path: parentPath, item, Component: Component2 = DefaultComponent, position, ...props }) => {
|
|
538
|
+
var DroppableTile = ({ path: parentPath, type = DEFAULT_TYPE, item, Component: Component2 = DefaultComponent, position, ...props }) => {
|
|
520
539
|
const { operation } = useMosaic();
|
|
521
540
|
const path = parentPath === item.id ? parentPath : Path.create(parentPath, item.id);
|
|
522
541
|
const { setNodeRef, isOver } = useDroppable({
|
|
523
542
|
id: path,
|
|
524
543
|
data: {
|
|
525
544
|
path,
|
|
545
|
+
type,
|
|
526
546
|
item,
|
|
527
547
|
position
|
|
528
548
|
}
|
|
@@ -531,13 +551,14 @@ var DroppableTile = ({ path: parentPath, item, Component: Component2 = DefaultCo
|
|
|
531
551
|
ref: setNodeRef,
|
|
532
552
|
item,
|
|
533
553
|
path,
|
|
554
|
+
type,
|
|
534
555
|
position,
|
|
535
556
|
operation,
|
|
536
557
|
isOver,
|
|
537
558
|
...props
|
|
538
559
|
});
|
|
539
560
|
};
|
|
540
|
-
var SortableTile = ({ path: parentPath, item, Component: OverrideComponent, position, draggableStyle, ...props }) => {
|
|
561
|
+
var SortableTile = ({ path: parentPath, type = DEFAULT_TYPE, item, Component: OverrideComponent, position, draggableStyle, ...props }) => {
|
|
541
562
|
const { operation, activeItem, overItem } = useMosaic();
|
|
542
563
|
const { transitionDuration, Component: ContainerComponent } = useContainer();
|
|
543
564
|
const path = Path.create(parentPath, item.id);
|
|
@@ -546,6 +567,7 @@ var SortableTile = ({ path: parentPath, item, Component: OverrideComponent, posi
|
|
|
546
567
|
id: isPreview ? activeItem.path : path,
|
|
547
568
|
data: {
|
|
548
569
|
path,
|
|
570
|
+
type,
|
|
549
571
|
item,
|
|
550
572
|
position
|
|
551
573
|
},
|
|
@@ -569,6 +591,7 @@ var SortableTile = ({ path: parentPath, item, Component: OverrideComponent, posi
|
|
|
569
591
|
ref: setNodeRef,
|
|
570
592
|
item,
|
|
571
593
|
path,
|
|
594
|
+
type,
|
|
572
595
|
position,
|
|
573
596
|
operation,
|
|
574
597
|
active,
|
|
@@ -601,441 +624,12 @@ var Mosaic = {
|
|
|
601
624
|
// TODO(burdon): Don't export; move to util.
|
|
602
625
|
Debug
|
|
603
626
|
};
|
|
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
|
-
};
|
|
1026
627
|
export {
|
|
1027
|
-
Grid,
|
|
1028
|
-
Kanban,
|
|
1029
628
|
Mosaic,
|
|
1030
629
|
Path,
|
|
1031
|
-
Stack,
|
|
1032
|
-
Tree,
|
|
1033
|
-
calculateCellWidth,
|
|
1034
|
-
createMatrix,
|
|
1035
|
-
getBounds,
|
|
1036
|
-
getDimension,
|
|
1037
|
-
getPanelBounds,
|
|
1038
630
|
getTransformCSS,
|
|
631
|
+
isTileComponentProps,
|
|
632
|
+
isTileProps,
|
|
1039
633
|
swapItems,
|
|
1040
634
|
useContainer,
|
|
1041
635
|
useItemsWithOrigin,
|