@dxos/react-ui-mosaic 0.3.3-main.ff5734a → 0.3.3
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 +65 -88
- 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 +1 -6
- package/dist/types/src/mosaic/Container.d.ts.map +1 -1
- package/dist/types/src/mosaic/Mosaic.d.ts +1 -2
- package/dist/types/src/mosaic/Mosaic.d.ts.map +1 -1
- package/dist/types/src/mosaic/hooks/index.d.ts +1 -0
- package/dist/types/src/mosaic/hooks/index.d.ts.map +1 -1
- package/dist/types/src/mosaic/hooks/useItemsWithOrigin.d.ts +3 -0
- package/dist/types/src/mosaic/hooks/useItemsWithOrigin.d.ts.map +1 -0
- package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts +1 -2
- package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts.map +1 -1
- package/dist/types/src/testing/generator.d.ts +0 -7
- package/dist/types/src/testing/generator.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/views/Tree/Graph.stories.d.ts +1 -1
- package/dist/types/src/views/Tree/Tree.d.ts +2 -3
- package/dist/types/src/views/Tree/Tree.d.ts.map +1 -1
- package/dist/types/src/views/Tree/Tree.stories.d.ts +1 -1
- package/dist/types/src/views/Tree/testing.d.ts.map +1 -1
- package/package.json +13 -14
- package/src/mosaic/Container.tsx +0 -9
- package/src/mosaic/Mosaic.ts +0 -3
- package/src/mosaic/hooks/index.ts +1 -0
- package/src/mosaic/hooks/useItemsWithOrigin.ts +33 -0
- package/src/mosaic/hooks/useItemsWithPreview.ts +24 -55
- package/src/testing/generator.ts +2 -5
- package/src/testing/index.ts +0 -1
- package/src/views/Tree/Tree.tsx +11 -20
- package/src/views/Tree/testing.tsx +4 -24
- package/dist/types/src/testing/next-fractional-index.d.ts +0 -5
- package/dist/types/src/testing/next-fractional-index.d.ts.map +0 -1
- package/src/testing/next-fractional-index.ts +0 -36
|
@@ -6,7 +6,7 @@ import { raise } from "@dxos/debug";
|
|
|
6
6
|
import React, { createContext, useEffect } from "react";
|
|
7
7
|
var DEFAULT_TRANSITION = 200;
|
|
8
8
|
var MosaicContainerContext = /* @__PURE__ */ createContext(void 0);
|
|
9
|
-
var MosaicContainer = ({ children, id, debug, Component: Component2, transitionDuration = DEFAULT_TRANSITION, modifier, getOverlayProps, getOverlayStyle, onOver, onDrop
|
|
9
|
+
var MosaicContainer = ({ children, id, debug, Component: Component2, transitionDuration = DEFAULT_TRANSITION, modifier, getOverlayProps, getOverlayStyle, onOver, onDrop }) => {
|
|
10
10
|
const mosaic = useMosaic();
|
|
11
11
|
const container = {
|
|
12
12
|
id,
|
|
@@ -17,8 +17,7 @@ var MosaicContainer = ({ children, id, debug, Component: Component2, transitionD
|
|
|
17
17
|
getOverlayProps,
|
|
18
18
|
getOverlayStyle,
|
|
19
19
|
onOver,
|
|
20
|
-
onDrop
|
|
21
|
-
compare
|
|
20
|
+
onDrop
|
|
22
21
|
};
|
|
23
22
|
useEffect(() => {
|
|
24
23
|
mosaic.setContainer(container.id, container);
|
|
@@ -272,7 +271,7 @@ var MosaicDebug = ({ containers, operation, activeItem, overItem }) => {
|
|
|
272
271
|
var useMosaic = () => useContext2(MosaicContext) ?? raise2(new Error("Missing MosaicContext"));
|
|
273
272
|
|
|
274
273
|
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useItemsWithPreview.ts
|
|
275
|
-
var useItemsWithPreview = ({ path, items
|
|
274
|
+
var useItemsWithPreview = ({ path, items }) => {
|
|
276
275
|
const { operation, activeItem, overItem } = useMosaic();
|
|
277
276
|
const [itemsWithPreview, setItemsWithPreview] = useState2(items);
|
|
278
277
|
const overParent = (
|
|
@@ -293,53 +292,31 @@ var useItemsWithPreview = ({ path, items, strategy = "default" }) => {
|
|
|
293
292
|
const activeIsChild = Path.hasChild(path, activeItem.path);
|
|
294
293
|
const overIsChild = Path.hasChild(path, overItem.path);
|
|
295
294
|
const overSelf = overItem.path === path;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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;
|
|
295
|
+
if (operation === "reject" || operation === "rearrange") {
|
|
296
|
+
setLastOverParent(void 0);
|
|
297
|
+
setItemsWithPreview(items);
|
|
298
|
+
return;
|
|
299
|
+
} else {
|
|
300
|
+
setLastOverParent(overParent);
|
|
301
|
+
}
|
|
302
|
+
if (!activeIsChild && overIsChild) {
|
|
303
|
+
setItemsWithPreview((items2) => {
|
|
304
|
+
const position = overItem.position;
|
|
305
|
+
return [
|
|
306
|
+
...items2.slice(0, position),
|
|
307
|
+
activeItem.item,
|
|
308
|
+
...items2.slice(position)
|
|
309
|
+
];
|
|
310
|
+
});
|
|
311
|
+
} else if (!activeIsChild && overSelf) {
|
|
312
|
+
setItemsWithPreview((items2) => [
|
|
313
|
+
...items2,
|
|
314
|
+
activeItem.item
|
|
315
|
+
]);
|
|
316
|
+
} else if (activeIsChild && !overIsChild) {
|
|
317
|
+
setItemsWithPreview((items2) => items2.filter((item) => item.id !== activeItem.item.id));
|
|
318
|
+
} else {
|
|
319
|
+
setItemsWithPreview(items);
|
|
343
320
|
}
|
|
344
321
|
}, [
|
|
345
322
|
operation,
|
|
@@ -350,7 +327,31 @@ var useItemsWithPreview = ({ path, items, strategy = "default" }) => {
|
|
|
350
327
|
path,
|
|
351
328
|
items
|
|
352
329
|
]);
|
|
353
|
-
return
|
|
330
|
+
return items.length === itemsWithPreview.length ? items : itemsWithPreview;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// packages/ui/react-ui-mosaic/src/mosaic/hooks/useItemsWithOrigin.ts
|
|
334
|
+
var useItemsWithOrigin = (path, items) => {
|
|
335
|
+
const { operation, activeItem, overItem } = useMosaic();
|
|
336
|
+
if (!activeItem || !overItem) {
|
|
337
|
+
return items;
|
|
338
|
+
}
|
|
339
|
+
const activeIsChild = Path.hasChild(path, activeItem.path);
|
|
340
|
+
const overIsChild = Path.hasChild(path, overItem.path);
|
|
341
|
+
if (activeIsChild && !overIsChild && operation !== "rearrange") {
|
|
342
|
+
return items.map((item) => {
|
|
343
|
+
if (item.id === activeItem.item.id) {
|
|
344
|
+
return {
|
|
345
|
+
...item,
|
|
346
|
+
id: `${item.id}--origin`
|
|
347
|
+
};
|
|
348
|
+
} else {
|
|
349
|
+
return item;
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
} else {
|
|
353
|
+
return items;
|
|
354
|
+
}
|
|
354
355
|
};
|
|
355
356
|
|
|
356
357
|
// packages/ui/react-ui-mosaic/src/mosaic/DragOverlay.tsx
|
|
@@ -952,43 +953,30 @@ var Stack = ({ id, Component: Component2 = Mosaic.DefaultComponent, onOver, onDr
|
|
|
952
953
|
};
|
|
953
954
|
|
|
954
955
|
// packages/ui/react-ui-mosaic/src/views/Tree/Tree.tsx
|
|
955
|
-
import React11, { forwardRef as forwardRef3
|
|
956
|
+
import React11, { forwardRef as forwardRef3 } from "react";
|
|
956
957
|
import { Card as Card3, Tree as TreeComponent, TreeItem as TreeItemComponent } from "@dxos/react-ui";
|
|
957
958
|
import { dropRing, mx as mx5 } from "@dxos/react-ui-theme";
|
|
958
|
-
var Tree = ({ id, Component: Component2 = TreeItem, onOver, onDrop, items = [], debug
|
|
959
|
+
var Tree = ({ id, Component: Component2 = TreeItem, onOver, onDrop, items = [], debug }) => {
|
|
959
960
|
return /* @__PURE__ */ React11.createElement(Mosaic.Container, {
|
|
960
961
|
id,
|
|
961
962
|
debug,
|
|
962
963
|
Component: Component2,
|
|
963
964
|
onOver,
|
|
964
|
-
onDrop
|
|
965
|
-
compare
|
|
965
|
+
onDrop
|
|
966
966
|
}, /* @__PURE__ */ React11.createElement(TreeRoot, {
|
|
967
967
|
items
|
|
968
968
|
}));
|
|
969
969
|
};
|
|
970
970
|
var TreeRoot = ({ items }) => {
|
|
971
|
-
const { id, Component: Component2
|
|
972
|
-
const
|
|
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
|
-
});
|
|
971
|
+
const { id, Component: Component2 } = useContainer();
|
|
972
|
+
const itemsWithOrigin = useItemsWithOrigin(id, items);
|
|
985
973
|
return /* @__PURE__ */ React11.createElement(TreeComponent.Root, {
|
|
986
974
|
classNames: "flex flex-col"
|
|
987
975
|
}, /* @__PURE__ */ React11.createElement(Mosaic.SortableContext, {
|
|
988
976
|
id,
|
|
989
|
-
items:
|
|
977
|
+
items: itemsWithOrigin,
|
|
990
978
|
direction: "vertical"
|
|
991
|
-
},
|
|
979
|
+
}, itemsWithOrigin.map((item, index) => /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
|
|
992
980
|
key: item.id,
|
|
993
981
|
collapsible: true,
|
|
994
982
|
defaultOpen: true
|
|
@@ -1014,27 +1002,15 @@ var TreeItem = /* @__PURE__ */ forwardRef3(({ path, draggableStyle, draggablePro
|
|
|
1014
1002
|
});
|
|
1015
1003
|
var TreeBranch = ({ path, items }) => {
|
|
1016
1004
|
const { operation, overItem } = useMosaic();
|
|
1017
|
-
const { Component: Component2
|
|
1018
|
-
const
|
|
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
|
-
});
|
|
1005
|
+
const { Component: Component2 } = useContainer();
|
|
1006
|
+
const itemsWithOrigin = useItemsWithOrigin(path, items);
|
|
1031
1007
|
return /* @__PURE__ */ React11.createElement(TreeItemComponent.Body, {
|
|
1032
1008
|
className: "pis-4"
|
|
1033
1009
|
}, /* @__PURE__ */ React11.createElement(Mosaic.SortableContext, {
|
|
1034
1010
|
id: path,
|
|
1035
|
-
items:
|
|
1011
|
+
items: itemsWithOrigin,
|
|
1036
1012
|
direction: "vertical"
|
|
1037
|
-
},
|
|
1013
|
+
}, itemsWithOrigin.map((child, index) => /* @__PURE__ */ React11.createElement(TreeComponent.Branch, {
|
|
1038
1014
|
key: child.id
|
|
1039
1015
|
}, /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
|
|
1040
1016
|
collapsible: true,
|
|
@@ -1062,6 +1038,7 @@ export {
|
|
|
1062
1038
|
getTransformCSS,
|
|
1063
1039
|
swapItems,
|
|
1064
1040
|
useContainer,
|
|
1041
|
+
useItemsWithOrigin,
|
|
1065
1042
|
useItemsWithPreview,
|
|
1066
1043
|
useMosaic
|
|
1067
1044
|
};
|