@dxos/react-ui-mosaic 0.3.3-main.f990aad → 0.3.3-next.6bede4d

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.
Files changed (54) hide show
  1. package/dist/lib/browser/index.mjs +51 -30
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/types/src/mosaic/Container.d.ts +10 -7
  5. package/dist/types/src/mosaic/Container.d.ts.map +1 -1
  6. package/dist/types/src/mosaic/Mosaic.d.ts +1 -2
  7. package/dist/types/src/mosaic/Mosaic.d.ts.map +1 -1
  8. package/dist/types/src/mosaic/Root.d.ts.map +1 -1
  9. package/dist/types/src/mosaic/hooks/index.d.ts +1 -1
  10. package/dist/types/src/mosaic/hooks/index.d.ts.map +1 -1
  11. package/dist/types/src/mosaic/hooks/useItemsWithOrigin.d.ts +3 -0
  12. package/dist/types/src/mosaic/hooks/useItemsWithOrigin.d.ts.map +1 -0
  13. package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts.map +1 -1
  14. package/dist/types/src/stories/Home.stories.d.ts +11 -0
  15. package/dist/types/src/stories/Home.stories.d.ts.map +1 -0
  16. package/dist/types/src/testing/decorators.d.ts.map +1 -1
  17. package/dist/types/src/testing/generator.d.ts +3 -10
  18. package/dist/types/src/testing/generator.d.ts.map +1 -1
  19. package/dist/types/src/testing/index.d.ts +0 -1
  20. package/dist/types/src/testing/index.d.ts.map +1 -1
  21. package/dist/types/src/views/Grid/Grid.d.ts +1 -1
  22. package/dist/types/src/views/Grid/Grid.d.ts.map +1 -1
  23. package/dist/types/src/views/Grid/Grid.stories.d.ts +1 -1
  24. package/dist/types/src/views/Stack/Columns.stories.d.ts +1 -1
  25. package/dist/types/src/views/Stack/Columns.stories.d.ts.map +1 -1
  26. package/dist/types/src/views/Tree/Graph.stories.d.ts +1 -1
  27. package/dist/types/src/views/Tree/Tree.d.ts +2 -3
  28. package/dist/types/src/views/Tree/Tree.d.ts.map +1 -1
  29. package/dist/types/src/views/Tree/Tree.stories.d.ts +1 -1
  30. package/dist/types/src/views/Tree/testing.d.ts +1 -1
  31. package/dist/types/src/views/Tree/testing.d.ts.map +1 -1
  32. package/package.json +14 -15
  33. package/src/mosaic/Container.tsx +10 -11
  34. package/src/mosaic/Mosaic.ts +0 -3
  35. package/src/mosaic/Root.tsx +1 -2
  36. package/src/mosaic/hooks/index.ts +1 -1
  37. package/src/mosaic/hooks/useItemsWithOrigin.ts +33 -0
  38. package/src/mosaic/hooks/useItemsWithPreview.ts +8 -3
  39. package/src/stories/Home.stories.tsx +87 -0
  40. package/src/testing/decorators.tsx +1 -0
  41. package/src/testing/generator.ts +11 -14
  42. package/src/testing/index.ts +0 -1
  43. package/src/views/Grid/Grid.tsx +4 -2
  44. package/src/views/Kanban/Kanban.tsx +1 -1
  45. package/src/views/Stack/Columns.stories.tsx +1 -1
  46. package/src/views/Stack/testing.tsx +1 -1
  47. package/src/views/Tree/Tree.tsx +9 -12
  48. package/src/views/Tree/testing.tsx +13 -31
  49. package/dist/types/src/mosaic/hooks/useSortedItems.d.ts +0 -6
  50. package/dist/types/src/mosaic/hooks/useSortedItems.d.ts.map +0 -1
  51. package/dist/types/src/testing/next-fractional-index.d.ts +0 -5
  52. package/dist/types/src/testing/next-fractional-index.d.ts.map +0 -1
  53. package/src/mosaic/hooks/useSortedItems.ts +0 -14
  54. 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, compare }) => {
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);
@@ -181,7 +180,7 @@ var MosaicRoot = ({ Component: Component2 = DefaultComponent, debug, children })
181
180
  over
182
181
  });
183
182
  } else {
184
- return "adopt";
183
+ return "reject";
185
184
  }
186
185
  };
187
186
  setOperation(onOver({
@@ -282,7 +281,7 @@ var useItemsWithPreview = ({ path, items }) => {
282
281
  );
283
282
  const [lastOverParent, setLastOverParent] = useState2(overParent);
284
283
  useEffect2(() => {
285
- if (operation === "reject" || operation === "rearrange" || !activeItem || !overItem) {
284
+ if (!activeItem || !overItem) {
286
285
  setLastOverParent(void 0);
287
286
  setItemsWithPreview(items);
288
287
  return;
@@ -290,10 +289,16 @@ var useItemsWithPreview = ({ path, items }) => {
290
289
  if (lastOverParent === overParent) {
291
290
  return;
292
291
  }
293
- setLastOverParent(overParent);
294
292
  const activeIsChild = Path.hasChild(path, activeItem.path);
295
293
  const overIsChild = Path.hasChild(path, overItem.path);
296
294
  const overSelf = overItem.path === path;
295
+ if (operation === "reject" || operation === "rearrange") {
296
+ setLastOverParent(void 0);
297
+ setItemsWithPreview(items);
298
+ return;
299
+ } else {
300
+ setLastOverParent(overParent);
301
+ }
297
302
  if (!activeIsChild && overIsChild) {
298
303
  setItemsWithPreview((items2) => {
299
304
  const position = overItem.position;
@@ -325,12 +330,28 @@ var useItemsWithPreview = ({ path, items }) => {
325
330
  return items.length === itemsWithPreview.length ? items : itemsWithPreview;
326
331
  };
327
332
 
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;
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
+ }
334
355
  };
335
356
 
336
357
  // packages/ui/react-ui-mosaic/src/mosaic/DragOverlay.tsx
@@ -632,12 +653,12 @@ var defaultGridOptions = {
632
653
  y: 8
633
654
  },
634
655
  cellBounds: {
635
- width: 280,
636
- height: 280
656
+ width: 272,
657
+ height: 272
637
658
  },
638
- spacing: 8
659
+ spacing: 6
639
660
  };
640
- var Grid = ({ id, items = [], layout = {}, options: opts, margin, square = true, debug, selected: controlledSelected, Component: Component2 = Mosaic.DefaultComponent, className, onDrop, onSelect, onCreate, onAction }) => {
661
+ var Grid = ({ id, items = [], layout = {}, options: opts, margin, square = true, debug, selected: controlledSelected, Component: Component2 = Mosaic.DefaultComponent, className, onDrop, onOver, onSelect, onCreate, onAction }) => {
641
662
  const { ref: containerRef, width, height } = useResizeDetector({
642
663
  refreshRate: 200
643
664
  });
@@ -705,7 +726,8 @@ var Grid = ({ id, items = [], layout = {}, options: opts, margin, square = true,
705
726
  grow: true
706
727
  }),
707
728
  getOverlayStyle: () => getDimension(cellBounds, options.spacing),
708
- onDrop
729
+ onDrop,
730
+ onOver
709
731
  }, /* @__PURE__ */ React8.createElement("div", {
710
732
  className: mx2("flex grow overflow-auto", className)
711
733
  }, /* @__PURE__ */ React8.createElement("div", {
@@ -812,7 +834,7 @@ var Kanban = ({ id, columns, Component: TileComponent = Mosaic.DefaultComponent,
812
834
  // Restrict to objects from other columns.
813
835
  // TODO(burdon): Consider objects from other containers.
814
836
  // TODO(wittjosiah): Allow override.
815
- onOver: ({ active, over }) => Path.length(active.path) >= Path.length(over.path) ? "adopt" : "reject",
837
+ onOver: ({ active, over }) => Path.length(active.path) >= Path.length(over.path) ? "transfer" : "reject",
816
838
  onDrop
817
839
  }, /* @__PURE__ */ React9.createElement("div", {
818
840
  className: "grow flex overflow-y-hidden overflow-x-auto"
@@ -934,28 +956,27 @@ var Stack = ({ id, Component: Component2 = Mosaic.DefaultComponent, onOver, onDr
934
956
  import React11, { forwardRef as forwardRef3 } from "react";
935
957
  import { Card as Card3, Tree as TreeComponent, TreeItem as TreeItemComponent } from "@dxos/react-ui";
936
958
  import { dropRing, mx as mx5 } from "@dxos/react-ui-theme";
937
- var Tree = ({ id, Component: Component2 = TreeItem, onOver, onDrop, items = [], debug, compare }) => {
959
+ var Tree = ({ id, Component: Component2 = TreeItem, onOver, onDrop, items = [], debug }) => {
938
960
  return /* @__PURE__ */ React11.createElement(Mosaic.Container, {
939
961
  id,
940
962
  debug,
941
963
  Component: Component2,
942
964
  onOver,
943
- onDrop,
944
- compare
965
+ onDrop
945
966
  }, /* @__PURE__ */ React11.createElement(TreeRoot, {
946
967
  items
947
968
  }));
948
969
  };
949
970
  var TreeRoot = ({ items }) => {
950
971
  const { id, Component: Component2 } = useContainer();
951
- const sortedItems = useSortedItems(items);
972
+ const itemsWithOrigin = useItemsWithOrigin(id, items);
952
973
  return /* @__PURE__ */ React11.createElement(TreeComponent.Root, {
953
974
  classNames: "flex flex-col"
954
975
  }, /* @__PURE__ */ React11.createElement(Mosaic.SortableContext, {
955
976
  id,
956
- items: sortedItems,
977
+ items: itemsWithOrigin,
957
978
  direction: "vertical"
958
- }, sortedItems.map((item, index) => /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
979
+ }, itemsWithOrigin.map((item, index) => /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
959
980
  key: item.id,
960
981
  collapsible: true,
961
982
  defaultOpen: true
@@ -982,14 +1003,14 @@ var TreeItem = /* @__PURE__ */ forwardRef3(({ path, draggableStyle, draggablePro
982
1003
  var TreeBranch = ({ path, items }) => {
983
1004
  const { operation, overItem } = useMosaic();
984
1005
  const { Component: Component2 } = useContainer();
985
- const sortedItems = useSortedItems(items);
1006
+ const itemsWithOrigin = useItemsWithOrigin(path, items);
986
1007
  return /* @__PURE__ */ React11.createElement(TreeItemComponent.Body, {
987
1008
  className: "pis-4"
988
1009
  }, /* @__PURE__ */ React11.createElement(Mosaic.SortableContext, {
989
1010
  id: path,
990
- items: sortedItems,
1011
+ items: itemsWithOrigin,
991
1012
  direction: "vertical"
992
- }, sortedItems.map((child, index) => /* @__PURE__ */ React11.createElement(TreeComponent.Branch, {
1013
+ }, itemsWithOrigin.map((child, index) => /* @__PURE__ */ React11.createElement(TreeComponent.Branch, {
993
1014
  key: child.id
994
1015
  }, /* @__PURE__ */ React11.createElement(TreeItemComponent.Root, {
995
1016
  collapsible: true,
@@ -999,7 +1020,7 @@ var TreeBranch = ({ path, items }) => {
999
1020
  path,
1000
1021
  position: index,
1001
1022
  Component: Component2,
1002
- isOver: overItem?.path === Path.create(path, child.id) && (operation === "adopt" || operation === "copy")
1023
+ isOver: overItem?.path === Path.create(path, child.id) && (operation === "transfer" || operation === "copy")
1003
1024
  }))))));
1004
1025
  };
1005
1026
  export {
@@ -1017,8 +1038,8 @@ export {
1017
1038
  getTransformCSS,
1018
1039
  swapItems,
1019
1040
  useContainer,
1041
+ useItemsWithOrigin,
1020
1042
  useItemsWithPreview,
1021
- useMosaic,
1022
- useSortedItems
1043
+ useMosaic
1023
1044
  };
1024
1045
  //# sourceMappingURL=index.mjs.map