@dxos/react-ui-mosaic 0.3.3-main.1817c8a → 0.3.3-main.22971a3
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 +87 -43
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +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/testing/generator.d.ts +4 -4
- package/dist/types/src/testing/generator.d.ts.map +1 -1
- package/dist/types/src/views/Grid/Grid.d.ts +1 -1
- package/dist/types/src/views/Grid/Grid.d.ts.map +1 -1
- package/dist/types/src/views/Grid/Grid.stories.d.ts +1 -1
- package/package.json +13 -13
- package/src/mosaic/hooks/index.ts +0 -1
- package/src/mosaic/hooks/useItemsWithPreview.ts +56 -20
- package/src/testing/generator.ts +9 -9
- package/src/views/Grid/Grid.tsx +2 -0
- package/src/views/Tree/Tree.tsx +16 -10
- 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
|
@@ -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
|
|
@@ -637,7 +657,7 @@ var defaultGridOptions = {
|
|
|
637
657
|
},
|
|
638
658
|
spacing: 6
|
|
639
659
|
};
|
|
640
|
-
var Grid = ({ id, items = [], layout = {}, options: opts, margin, square = true, debug, selected: controlledSelected, Component: Component2 = Mosaic.DefaultComponent, className, onDrop, onSelect, onCreate, onAction }) => {
|
|
660
|
+
var Grid = ({ id, items = [], layout = {}, options: opts, margin, square = true, debug, selected: controlledSelected, Component: Component2 = Mosaic.DefaultComponent, className, onDrop, onOver, onSelect, onCreate, onAction }) => {
|
|
641
661
|
const { ref: containerRef, width, height } = useResizeDetector({
|
|
642
662
|
refreshRate: 200
|
|
643
663
|
});
|
|
@@ -705,7 +725,8 @@ var Grid = ({ id, items = [], layout = {}, options: opts, margin, square = true,
|
|
|
705
725
|
grow: true
|
|
706
726
|
}),
|
|
707
727
|
getOverlayStyle: () => getDimension(cellBounds, options.spacing),
|
|
708
|
-
onDrop
|
|
728
|
+
onDrop,
|
|
729
|
+
onOver
|
|
709
730
|
}, /* @__PURE__ */ React8.createElement("div", {
|
|
710
731
|
className: mx2("flex grow overflow-auto", className)
|
|
711
732
|
}, /* @__PURE__ */ React8.createElement("div", {
|
|
@@ -931,7 +952,7 @@ var Stack = ({ id, Component: Component2 = Mosaic.DefaultComponent, onOver, onDr
|
|
|
931
952
|
};
|
|
932
953
|
|
|
933
954
|
// packages/ui/react-ui-mosaic/src/views/Tree/Tree.tsx
|
|
934
|
-
import React11, { forwardRef as forwardRef3 } from "react";
|
|
955
|
+
import React11, { forwardRef as forwardRef3, useMemo as useMemo3 } from "react";
|
|
935
956
|
import { Card as Card3, Tree as TreeComponent, TreeItem as TreeItemComponent } from "@dxos/react-ui";
|
|
936
957
|
import { dropRing, mx as mx5 } from "@dxos/react-ui-theme";
|
|
937
958
|
var Tree = ({ id, Component: Component2 = TreeItem, onOver, onDrop, items = [], debug, compare }) => {
|
|
@@ -947,15 +968,27 @@ var Tree = ({ id, Component: Component2 = TreeItem, onOver, onDrop, items = [],
|
|
|
947
968
|
}));
|
|
948
969
|
};
|
|
949
970
|
var TreeRoot = ({ items }) => {
|
|
950
|
-
const { id, Component: Component2 } = useContainer();
|
|
951
|
-
const sortedItems =
|
|
971
|
+
const { id, Component: Component2, compare } = useContainer();
|
|
972
|
+
const sortedItems = useMemo3(() => {
|
|
973
|
+
return compare ? [
|
|
974
|
+
...items
|
|
975
|
+
].sort(compare) : items;
|
|
976
|
+
}, [
|
|
977
|
+
items,
|
|
978
|
+
compare
|
|
979
|
+
]);
|
|
980
|
+
const itemsWithPreview = useItemsWithPreview({
|
|
981
|
+
items: sortedItems,
|
|
982
|
+
path: id,
|
|
983
|
+
strategy: "layout-stable"
|
|
984
|
+
});
|
|
952
985
|
return /* @__PURE__ */ React11.createElement(TreeComponent.Root, {
|
|
953
986
|
classNames: "flex flex-col"
|
|
954
987
|
}, /* @__PURE__ */ React11.createElement(Mosaic.SortableContext, {
|
|
955
988
|
id,
|
|
956
|
-
items:
|
|
989
|
+
items: itemsWithPreview,
|
|
957
990
|
direction: "vertical"
|
|
958
|
-
},
|
|
991
|
+
}, itemsWithPreview.map((item, index) => /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
|
|
959
992
|
key: item.id,
|
|
960
993
|
collapsible: true,
|
|
961
994
|
defaultOpen: true
|
|
@@ -981,15 +1014,27 @@ var TreeItem = /* @__PURE__ */ forwardRef3(({ path, draggableStyle, draggablePro
|
|
|
981
1014
|
});
|
|
982
1015
|
var TreeBranch = ({ path, items }) => {
|
|
983
1016
|
const { operation, overItem } = useMosaic();
|
|
984
|
-
const { Component: Component2 } = useContainer();
|
|
985
|
-
const sortedItems =
|
|
1017
|
+
const { Component: Component2, compare } = useContainer();
|
|
1018
|
+
const sortedItems = useMemo3(() => {
|
|
1019
|
+
return compare ? [
|
|
1020
|
+
...items
|
|
1021
|
+
].sort(compare) : items;
|
|
1022
|
+
}, [
|
|
1023
|
+
items,
|
|
1024
|
+
compare
|
|
1025
|
+
]);
|
|
1026
|
+
const itemsWithPreview = useItemsWithPreview({
|
|
1027
|
+
items: sortedItems,
|
|
1028
|
+
path,
|
|
1029
|
+
strategy: "layout-stable"
|
|
1030
|
+
});
|
|
986
1031
|
return /* @__PURE__ */ React11.createElement(TreeItemComponent.Body, {
|
|
987
1032
|
className: "pis-4"
|
|
988
1033
|
}, /* @__PURE__ */ React11.createElement(Mosaic.SortableContext, {
|
|
989
1034
|
id: path,
|
|
990
|
-
items:
|
|
1035
|
+
items: itemsWithPreview,
|
|
991
1036
|
direction: "vertical"
|
|
992
|
-
},
|
|
1037
|
+
}, itemsWithPreview.map((child, index) => /* @__PURE__ */ React11.createElement(TreeComponent.Branch, {
|
|
993
1038
|
key: child.id
|
|
994
1039
|
}, /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
|
|
995
1040
|
collapsible: true,
|
|
@@ -1018,7 +1063,6 @@ export {
|
|
|
1018
1063
|
swapItems,
|
|
1019
1064
|
useContainer,
|
|
1020
1065
|
useItemsWithPreview,
|
|
1021
|
-
useMosaic
|
|
1022
|
-
useSortedItems
|
|
1066
|
+
useMosaic
|
|
1023
1067
|
};
|
|
1024
1068
|
//# sourceMappingURL=index.mjs.map
|