@dxos/react-ui-mosaic 0.3.3-main.1b7ca63 → 0.3.3-main.3806cc2
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 +90 -47
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/mosaic/Container.d.ts +9 -1
- package/dist/types/src/mosaic/Container.d.ts.map +1 -1
- package/dist/types/src/mosaic/Root.d.ts.map +1 -1
- package/dist/types/src/mosaic/hooks/index.d.ts +0 -1
- package/dist/types/src/mosaic/hooks/index.d.ts.map +1 -1
- package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts +2 -1
- package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts.map +1 -1
- package/dist/types/src/stories/Home.stories.d.ts +11 -0
- package/dist/types/src/stories/Home.stories.d.ts.map +1 -0
- package/dist/types/src/testing/decorators.d.ts.map +1 -1
- package/dist/types/src/testing/next-fractional-index.d.ts +1 -1
- package/dist/types/src/testing/next-fractional-index.d.ts.map +1 -1
- package/dist/types/src/views/Stack/Columns.stories.d.ts +1 -1
- package/dist/types/src/views/Stack/Columns.stories.d.ts.map +1 -1
- package/dist/types/src/views/Tree/testing.d.ts +1 -1
- package/dist/types/src/views/Tree/testing.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/mosaic/Container.tsx +10 -2
- package/src/mosaic/Root.tsx +1 -2
- package/src/mosaic/hooks/index.ts +0 -1
- package/src/mosaic/hooks/useItemsWithPreview.ts +56 -20
- package/src/stories/Home.stories.tsx +87 -0
- package/src/testing/decorators.tsx +1 -0
- package/src/testing/next-fractional-index.ts +1 -1
- package/src/views/Grid/Grid.tsx +2 -2
- package/src/views/Kanban/Kanban.tsx +1 -1
- package/src/views/Stack/Columns.stories.tsx +1 -1
- package/src/views/Stack/testing.tsx +1 -1
- package/src/views/Tree/Tree.tsx +17 -11
- package/src/views/Tree/testing.tsx +11 -9
- package/dist/types/src/mosaic/hooks/useSortedItems.d.ts +0 -6
- package/dist/types/src/mosaic/hooks/useSortedItems.d.ts.map +0 -1
- package/src/mosaic/hooks/useSortedItems.ts +0 -14
|
@@ -181,7 +181,7 @@ var MosaicRoot = ({ Component: Component2 = DefaultComponent, debug, children })
|
|
|
181
181
|
over
|
|
182
182
|
});
|
|
183
183
|
} else {
|
|
184
|
-
return "
|
|
184
|
+
return "reject";
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
187
|
setOperation(onOver({
|
|
@@ -272,7 +272,7 @@ var MosaicDebug = ({ containers, operation, activeItem, overItem }) => {
|
|
|
272
272
|
var useMosaic = () => useContext2(MosaicContext) ?? raise2(new Error("Missing MosaicContext"));
|
|
273
273
|
|
|
274
274
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useItemsWithPreview.ts
|
|
275
|
-
var useItemsWithPreview = ({ path, items }) => {
|
|
275
|
+
var useItemsWithPreview = ({ path, items, strategy = "default" }) => {
|
|
276
276
|
const { operation, activeItem, overItem } = useMosaic();
|
|
277
277
|
const [itemsWithPreview, setItemsWithPreview] = useState2(items);
|
|
278
278
|
const overParent = (
|
|
@@ -282,7 +282,7 @@ var useItemsWithPreview = ({ path, items }) => {
|
|
|
282
282
|
);
|
|
283
283
|
const [lastOverParent, setLastOverParent] = useState2(overParent);
|
|
284
284
|
useEffect2(() => {
|
|
285
|
-
if (
|
|
285
|
+
if (!activeItem || !overItem) {
|
|
286
286
|
setLastOverParent(void 0);
|
|
287
287
|
setItemsWithPreview(items);
|
|
288
288
|
return;
|
|
@@ -290,28 +290,56 @@ var useItemsWithPreview = ({ path, items }) => {
|
|
|
290
290
|
if (lastOverParent === overParent) {
|
|
291
291
|
return;
|
|
292
292
|
}
|
|
293
|
-
setLastOverParent(overParent);
|
|
294
293
|
const activeIsChild = Path.hasChild(path, activeItem.path);
|
|
295
294
|
const overIsChild = Path.hasChild(path, overItem.path);
|
|
296
295
|
const overSelf = overItem.path === path;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
296
|
+
switch (strategy) {
|
|
297
|
+
case "layout-stable":
|
|
298
|
+
setLastOverParent(overParent);
|
|
299
|
+
if (activeIsChild && !overIsChild && operation !== "rearrange") {
|
|
300
|
+
setItemsWithPreview((sortedItems) => sortedItems.map((item) => {
|
|
301
|
+
if (item.id === activeItem.item.id) {
|
|
302
|
+
return {
|
|
303
|
+
...item,
|
|
304
|
+
id: `${item.id}--origin`
|
|
305
|
+
};
|
|
306
|
+
} else {
|
|
307
|
+
return item;
|
|
308
|
+
}
|
|
309
|
+
}));
|
|
310
|
+
} else {
|
|
311
|
+
setItemsWithPreview(items);
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
case "default":
|
|
315
|
+
default:
|
|
316
|
+
if (operation === "reject" || operation === "rearrange") {
|
|
317
|
+
setLastOverParent(void 0);
|
|
318
|
+
setItemsWithPreview(items);
|
|
319
|
+
return;
|
|
320
|
+
} else {
|
|
321
|
+
setLastOverParent(overParent);
|
|
322
|
+
}
|
|
323
|
+
if (!activeIsChild && overIsChild) {
|
|
324
|
+
setItemsWithPreview((items2) => {
|
|
325
|
+
const position = overItem.position;
|
|
326
|
+
return [
|
|
327
|
+
...items2.slice(0, position),
|
|
328
|
+
activeItem.item,
|
|
329
|
+
...items2.slice(position)
|
|
330
|
+
];
|
|
331
|
+
});
|
|
332
|
+
} else if (!activeIsChild && overSelf) {
|
|
333
|
+
setItemsWithPreview((items2) => [
|
|
334
|
+
...items2,
|
|
335
|
+
activeItem.item
|
|
336
|
+
]);
|
|
337
|
+
} else if (activeIsChild && !overIsChild) {
|
|
338
|
+
setItemsWithPreview((items2) => items2.filter((item) => item.id !== activeItem.item.id));
|
|
339
|
+
} else {
|
|
340
|
+
setItemsWithPreview(items);
|
|
341
|
+
}
|
|
342
|
+
break;
|
|
315
343
|
}
|
|
316
344
|
}, [
|
|
317
345
|
operation,
|
|
@@ -322,15 +350,7 @@ var useItemsWithPreview = ({ path, items }) => {
|
|
|
322
350
|
path,
|
|
323
351
|
items
|
|
324
352
|
]);
|
|
325
|
-
return items.length === itemsWithPreview.length ? items : itemsWithPreview;
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useSortedItems.ts
|
|
329
|
-
var useSortedItems = (items) => {
|
|
330
|
-
const { compare } = useContainer();
|
|
331
|
-
return compare ? [
|
|
332
|
-
...items
|
|
333
|
-
].sort(compare) : items;
|
|
353
|
+
return strategy !== "layout-stable" && items.length === itemsWithPreview.length ? items : itemsWithPreview;
|
|
334
354
|
};
|
|
335
355
|
|
|
336
356
|
// packages/ui/react-ui-mosaic/src/mosaic/DragOverlay.tsx
|
|
@@ -632,10 +652,10 @@ var defaultGridOptions = {
|
|
|
632
652
|
y: 8
|
|
633
653
|
},
|
|
634
654
|
cellBounds: {
|
|
635
|
-
width:
|
|
636
|
-
height:
|
|
655
|
+
width: 272,
|
|
656
|
+
height: 272
|
|
637
657
|
},
|
|
638
|
-
spacing:
|
|
658
|
+
spacing: 6
|
|
639
659
|
};
|
|
640
660
|
var Grid = ({ id, items = [], layout = {}, options: opts, margin, square = true, debug, selected: controlledSelected, Component: Component2 = Mosaic.DefaultComponent, className, onDrop, onSelect, onCreate, onAction }) => {
|
|
641
661
|
const { ref: containerRef, width, height } = useResizeDetector({
|
|
@@ -812,7 +832,7 @@ var Kanban = ({ id, columns, Component: TileComponent = Mosaic.DefaultComponent,
|
|
|
812
832
|
// Restrict to objects from other columns.
|
|
813
833
|
// TODO(burdon): Consider objects from other containers.
|
|
814
834
|
// TODO(wittjosiah): Allow override.
|
|
815
|
-
onOver: ({ active, over }) => Path.length(active.path) >= Path.length(over.path) ? "
|
|
835
|
+
onOver: ({ active, over }) => Path.length(active.path) >= Path.length(over.path) ? "transfer" : "reject",
|
|
816
836
|
onDrop
|
|
817
837
|
}, /* @__PURE__ */ React9.createElement("div", {
|
|
818
838
|
className: "grow flex overflow-y-hidden overflow-x-auto"
|
|
@@ -931,7 +951,7 @@ var Stack = ({ id, Component: Component2 = Mosaic.DefaultComponent, onOver, onDr
|
|
|
931
951
|
};
|
|
932
952
|
|
|
933
953
|
// packages/ui/react-ui-mosaic/src/views/Tree/Tree.tsx
|
|
934
|
-
import React11, { forwardRef as forwardRef3 } from "react";
|
|
954
|
+
import React11, { forwardRef as forwardRef3, useMemo as useMemo3 } from "react";
|
|
935
955
|
import { Card as Card3, Tree as TreeComponent, TreeItem as TreeItemComponent } from "@dxos/react-ui";
|
|
936
956
|
import { dropRing, mx as mx5 } from "@dxos/react-ui-theme";
|
|
937
957
|
var Tree = ({ id, Component: Component2 = TreeItem, onOver, onDrop, items = [], debug, compare }) => {
|
|
@@ -947,15 +967,27 @@ var Tree = ({ id, Component: Component2 = TreeItem, onOver, onDrop, items = [],
|
|
|
947
967
|
}));
|
|
948
968
|
};
|
|
949
969
|
var TreeRoot = ({ items }) => {
|
|
950
|
-
const { id, Component: Component2 } = useContainer();
|
|
951
|
-
const sortedItems =
|
|
970
|
+
const { id, Component: Component2, compare } = useContainer();
|
|
971
|
+
const sortedItems = useMemo3(() => {
|
|
972
|
+
return compare ? [
|
|
973
|
+
...items
|
|
974
|
+
].sort(compare) : items;
|
|
975
|
+
}, [
|
|
976
|
+
items,
|
|
977
|
+
compare
|
|
978
|
+
]);
|
|
979
|
+
const itemsWithPreview = useItemsWithPreview({
|
|
980
|
+
items: sortedItems,
|
|
981
|
+
path: id,
|
|
982
|
+
strategy: "layout-stable"
|
|
983
|
+
});
|
|
952
984
|
return /* @__PURE__ */ React11.createElement(TreeComponent.Root, {
|
|
953
985
|
classNames: "flex flex-col"
|
|
954
986
|
}, /* @__PURE__ */ React11.createElement(Mosaic.SortableContext, {
|
|
955
987
|
id,
|
|
956
|
-
items:
|
|
988
|
+
items: itemsWithPreview,
|
|
957
989
|
direction: "vertical"
|
|
958
|
-
},
|
|
990
|
+
}, itemsWithPreview.map((item, index) => /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
|
|
959
991
|
key: item.id,
|
|
960
992
|
collapsible: true,
|
|
961
993
|
defaultOpen: true
|
|
@@ -981,15 +1013,27 @@ var TreeItem = /* @__PURE__ */ forwardRef3(({ path, draggableStyle, draggablePro
|
|
|
981
1013
|
});
|
|
982
1014
|
var TreeBranch = ({ path, items }) => {
|
|
983
1015
|
const { operation, overItem } = useMosaic();
|
|
984
|
-
const { Component: Component2 } = useContainer();
|
|
985
|
-
const sortedItems =
|
|
1016
|
+
const { Component: Component2, compare } = useContainer();
|
|
1017
|
+
const sortedItems = useMemo3(() => {
|
|
1018
|
+
return compare ? [
|
|
1019
|
+
...items
|
|
1020
|
+
].sort(compare) : items;
|
|
1021
|
+
}, [
|
|
1022
|
+
items,
|
|
1023
|
+
compare
|
|
1024
|
+
]);
|
|
1025
|
+
const itemsWithPreview = useItemsWithPreview({
|
|
1026
|
+
items: sortedItems,
|
|
1027
|
+
path,
|
|
1028
|
+
strategy: "layout-stable"
|
|
1029
|
+
});
|
|
986
1030
|
return /* @__PURE__ */ React11.createElement(TreeItemComponent.Body, {
|
|
987
1031
|
className: "pis-4"
|
|
988
1032
|
}, /* @__PURE__ */ React11.createElement(Mosaic.SortableContext, {
|
|
989
1033
|
id: path,
|
|
990
|
-
items:
|
|
1034
|
+
items: itemsWithPreview,
|
|
991
1035
|
direction: "vertical"
|
|
992
|
-
},
|
|
1036
|
+
}, itemsWithPreview.map((child, index) => /* @__PURE__ */ React11.createElement(TreeComponent.Branch, {
|
|
993
1037
|
key: child.id
|
|
994
1038
|
}, /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
|
|
995
1039
|
collapsible: true,
|
|
@@ -999,7 +1043,7 @@ var TreeBranch = ({ path, items }) => {
|
|
|
999
1043
|
path,
|
|
1000
1044
|
position: index,
|
|
1001
1045
|
Component: Component2,
|
|
1002
|
-
isOver: overItem?.path === Path.create(path, child.id) && (operation === "
|
|
1046
|
+
isOver: overItem?.path === Path.create(path, child.id) && (operation === "transfer" || operation === "copy")
|
|
1003
1047
|
}))))));
|
|
1004
1048
|
};
|
|
1005
1049
|
export {
|
|
@@ -1018,7 +1062,6 @@ export {
|
|
|
1018
1062
|
swapItems,
|
|
1019
1063
|
useContainer,
|
|
1020
1064
|
useItemsWithPreview,
|
|
1021
|
-
useMosaic
|
|
1022
|
-
useSortedItems
|
|
1065
|
+
useMosaic
|
|
1023
1066
|
};
|
|
1024
1067
|
//# sourceMappingURL=index.mjs.map
|