@dxos/react-ui-mosaic 0.3.3-main.88f4df1 → 0.3.3-main.97c2b9e

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 (34) hide show
  1. package/dist/lib/browser/index.mjs +90 -46
  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 +9 -1
  5. package/dist/types/src/mosaic/Container.d.ts.map +1 -1
  6. package/dist/types/src/mosaic/Root.d.ts.map +1 -1
  7. package/dist/types/src/mosaic/hooks/index.d.ts +0 -1
  8. package/dist/types/src/mosaic/hooks/index.d.ts.map +1 -1
  9. package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts +2 -1
  10. package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts.map +1 -1
  11. package/dist/types/src/testing/next-fractional-index.d.ts +1 -1
  12. package/dist/types/src/testing/next-fractional-index.d.ts.map +1 -1
  13. package/dist/types/src/views/Grid/Grid.d.ts +1 -1
  14. package/dist/types/src/views/Grid/Grid.d.ts.map +1 -1
  15. package/dist/types/src/views/Grid/Grid.stories.d.ts +1 -1
  16. package/dist/types/src/views/Stack/Columns.stories.d.ts +1 -1
  17. package/dist/types/src/views/Stack/Columns.stories.d.ts.map +1 -1
  18. package/dist/types/src/views/Tree/testing.d.ts +1 -1
  19. package/dist/types/src/views/Tree/testing.d.ts.map +1 -1
  20. package/package.json +13 -13
  21. package/src/mosaic/Container.tsx +10 -2
  22. package/src/mosaic/Root.tsx +1 -2
  23. package/src/mosaic/hooks/index.ts +0 -1
  24. package/src/mosaic/hooks/useItemsWithPreview.ts +56 -20
  25. package/src/testing/next-fractional-index.ts +1 -1
  26. package/src/views/Grid/Grid.tsx +2 -0
  27. package/src/views/Kanban/Kanban.tsx +1 -1
  28. package/src/views/Stack/Columns.stories.tsx +1 -1
  29. package/src/views/Stack/testing.tsx +1 -1
  30. package/src/views/Tree/Tree.tsx +17 -11
  31. package/src/views/Tree/testing.tsx +11 -9
  32. package/dist/types/src/mosaic/hooks/useSortedItems.d.ts +0 -6
  33. package/dist/types/src/mosaic/hooks/useSortedItems.d.ts.map +0 -1
  34. package/src/mosaic/hooks/useSortedItems.ts +0 -14
@@ -5,12 +5,12 @@
5
5
  import { faker } from '@faker-js/faker';
6
6
  import React, { useCallback, useState } from 'react';
7
7
 
8
- import { type Graph, GraphBuilder, type Node } from '@braneframe/plugin-graph';
9
- import { buildGraph } from '@braneframe/plugin-graph/testing';
8
+ import { type Graph, GraphBuilder, type Node } from '@dxos/app-graph';
9
+ import { buildGraph } from '@dxos/app-graph/testing';
10
10
  import { arrayMove } from '@dxos/util';
11
11
 
12
12
  import { Tree, type TreeData, type TreeProps } from './Tree';
13
- import { type MosaicDropEvent, type MosaicMoveEvent, Path } from '../../mosaic';
13
+ import { type MosaicDropEvent, type MosaicMoveEvent, Path, type MosaicOperation } from '../../mosaic';
14
14
  import { TestObjectGenerator, nextRearrangeIndex } from '../../testing';
15
15
 
16
16
  const fake = faker.helpers.fake;
@@ -47,8 +47,8 @@ export const DemoTree = ({ id = 'tree', initialItems, types, debug }: DemoTreePr
47
47
  }),
48
48
  );
49
49
 
50
- const handleOver = useCallback(({ active, over }: MosaicMoveEvent<number>) => {
51
- return !(active.path === id && over.path !== id) ? 'adopt' : 'reject';
50
+ const handleOver = useCallback(({ over }: MosaicMoveEvent<number>) => {
51
+ return over && Path.hasChild(id, over.path) ? 'transfer' : 'reject';
52
52
  }, []);
53
53
 
54
54
  // NOTE: Does not handle deep operations.
@@ -67,8 +67,8 @@ export const DemoTree = ({ id = 'tree', initialItems, types, debug }: DemoTreePr
67
67
  if (Path.last(Path.parent(active.path)) === item.id) {
68
68
  children.splice(active.position!, 1);
69
69
  }
70
- if (Path.last(Path.parent(over.path)) === item.id) {
71
- children.splice(over.position!, 0, active.item as TreeData);
70
+ if (Path.last(over.path) === item.id) {
71
+ children.push(active.item as TreeData);
72
72
  }
73
73
  return { ...item, children };
74
74
  }),
@@ -117,7 +117,6 @@ const graphNodeCompare = (a: Node, b: Node) => {
117
117
  };
118
118
 
119
119
  export const GraphTree = ({ id, graph = createGraph(), debug }: { id: string; graph?: Graph; debug: boolean }) => {
120
- // TODO(wittjosiah): This graph does not handle order currently.
121
120
  const handleDrop = ({ operation, active, over }: MosaicDropEvent<number>) => {
122
121
  // Moving within the tree.
123
122
  if (Path.hasDescendent(id, active.path) && Path.hasDescendent(id, over.path)) {
@@ -137,18 +136,21 @@ export const GraphTree = ({ id, graph = createGraph(), debug }: { id: string; gr
137
136
  // This is a rearrange operation
138
137
  const nextIndex = nextRearrangeIndex(activeParent.children.sort(graphNodeCompare), activeNode.id, overNode.id);
139
138
  activeNode.properties.index = nextIndex ?? 'a0';
140
- } else if (activeNode && activeParent && overParent && operation === 'adopt') {
139
+ } else if (activeNode && activeParent && overParent && operation === 'transfer') {
141
140
  activeParent.removeNode(active.item.id);
142
141
  overNode.addNode('tree', { ...activeNode });
143
142
  }
144
143
  }
145
144
  };
146
145
 
146
+ const handleOver = (): MosaicOperation => 'transfer';
147
+
147
148
  return (
148
149
  <Tree
149
150
  id={id}
150
151
  items={graph.root.children as TreeData[]}
151
152
  onDrop={handleDrop}
153
+ onOver={handleOver}
152
154
  debug={debug}
153
155
  compare={graphNodeCompare}
154
156
  />
@@ -1,6 +0,0 @@
1
- import { type MosaicDataItem } from '../types';
2
- /**
3
- * Returns a sorted collection of items if a compare function is provided.
4
- */
5
- export declare const useSortedItems: <T extends MosaicDataItem>(items: T[]) => T[];
6
- //# sourceMappingURL=useSortedItems.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useSortedItems.d.ts","sourceRoot":"","sources":["../../../../../src/mosaic/hooks/useSortedItems.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,cAAc,+CAG1B,CAAC"}
@@ -1,14 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { useContainer } from './useContainer';
6
- import { type MosaicDataItem } from '../types';
7
-
8
- /**
9
- * Returns a sorted collection of items if a compare function is provided.
10
- */
11
- export const useSortedItems = <T extends MosaicDataItem>(items: T[]): T[] => {
12
- const { compare } = useContainer();
13
- return compare ? [...items].sort(compare) : items;
14
- };