@dxos/react-ui-mosaic 0.3.8-next.f4e0086 → 0.3.9-main.14901ff

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.
@@ -1 +1 @@
1
- {"version":3,"file":"DragOverlay.d.ts","sourceRoot":"","sources":["../../../../src/mosaic/DragOverlay.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAyE,MAAM,OAAO,CAAC;AAQ9F,MAAM,MAAM,sBAAsB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAC7E,KAAK,CAAC,cAAc,CAAC,OAAO,WAAW,CAAC,EACxC,UAAU,CACX,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,sCAAqD,sBAAsB,gBA+ExG,CAAC"}
1
+ {"version":3,"file":"DragOverlay.d.ts","sourceRoot":"","sources":["../../../../src/mosaic/DragOverlay.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAyE,MAAM,OAAO,CAAC;AAQ9F,MAAM,MAAM,sBAAsB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAC7E,KAAK,CAAC,cAAc,CAAC,OAAO,WAAW,CAAC,EACxC,UAAU,CACX,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,sCAAqD,sBAAsB,gBAgFxG,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { type DraggableAttributes } from '@dnd-kit/core';
2
2
  import type { CSSProperties, ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from 'react';
3
- import type { MosaicOperation, MosaicTileOverlayProps } from './Container';
3
+ import { type MosaicOperation, type MosaicTileOverlayProps } from './Container';
4
4
  import type { MosaicDataItem } from './types';
5
5
  export type MosaicActiveType = 'overlay' | 'rearrange' | 'origin' | 'destination';
6
6
  export type MosaicTileAction = {
@@ -16,6 +16,7 @@ export type MosaicTileProps<TData extends MosaicDataItem = MosaicDataItem, TPosi
16
16
  item: TData;
17
17
  Component?: MosaicTileComponent<TData, any>;
18
18
  position?: TPosition;
19
+ type?: string;
19
20
  operation?: MosaicOperation;
20
21
  active?: MosaicActiveType;
21
22
  isDragging?: boolean;
@@ -24,24 +25,26 @@ export type MosaicTileProps<TData extends MosaicDataItem = MosaicDataItem, TPosi
24
25
  draggableProps?: DraggableAttributes & HTMLAttributes<HTMLElement>;
25
26
  onSelect?: () => void;
26
27
  onRemove?: () => void;
28
+ onNavigate?: () => void;
27
29
  onAction?: (action: MosaicTileAction) => void;
28
30
  };
31
+ export type MosaicTileComponentProps<TData extends MosaicDataItem = MosaicDataItem> = Omit<MosaicTileProps<TData>, 'Component' | 'operation'> & {
32
+ operation: MosaicOperation;
33
+ };
29
34
  /**
30
35
  * Mosaic Tile component.
31
36
  */
32
- export type MosaicTileComponent<TData extends MosaicDataItem = MosaicDataItem, TElement extends HTMLElement = HTMLDivElement> = ForwardRefExoticComponent<RefAttributes<TElement> & Omit<MosaicTileProps<TData>, 'Component' | 'operation'> & {
33
- operation: MosaicOperation;
34
- }>;
37
+ export type MosaicTileComponent<TData extends MosaicDataItem = MosaicDataItem, TElement extends HTMLElement = HTMLDivElement> = ForwardRefExoticComponent<RefAttributes<TElement> & MosaicTileComponentProps<TData>>;
35
38
  /**
36
39
  * Basic draggable mosaic tile.
37
40
  */
38
- export declare const DraggableTile: ({ path: parentPath, item, Component, position, draggableStyle, ...props }: MosaicTileProps<any>) => JSX.Element;
41
+ export declare const DraggableTile: ({ path: parentPath, type, item, Component, position, draggableStyle, ...props }: MosaicTileProps<any>) => JSX.Element;
39
42
  /**
40
43
  * Basic droppable mosaic tile.
41
44
  */
42
- export declare const DroppableTile: ({ path: parentPath, item, Component, position, ...props }: MosaicTileProps<any>) => JSX.Element;
45
+ export declare const DroppableTile: ({ path: parentPath, type, item, Component, position, ...props }: MosaicTileProps<any>) => JSX.Element;
43
46
  /**
44
47
  * Mosaic tile that can be sorted.
45
48
  */
46
- export declare const SortableTile: ({ path: parentPath, item, Component: OverrideComponent, position, draggableStyle, ...props }: MosaicTileProps<any, number>) => JSX.Element;
49
+ export declare const SortableTile: ({ path: parentPath, type, item, Component: OverrideComponent, position, draggableStyle, ...props }: MosaicTileProps<any, number>) => JSX.Element;
47
50
  //# sourceMappingURL=Tile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tile.d.ts","sourceRoot":"","sources":["../../../../src/mosaic/Tile.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,mBAAmB,EAA8B,MAAM,eAAe,CAAC;AAGrF,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAErG,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG3E,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,SAAS,CAAC;AAGjE,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,aAAa,CAAC;AAElF,MAAM,MAAM,gBAAgB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,KAAK,SAAS,cAAc,GAAG,cAAc,EAAE,SAAS,GAAG,OAAO,IAAI,IAAI,CACpG,cAAc,CAAC,cAAc,CAAC,EAC9B,WAAW,CACZ,GACC,sBAAsB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,CAAC;IACZ,SAAS,CAAC,EAAE,mBAAmB,CAAC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;CAC/C,CAAC;AAEJ,MAAM,MAAM,wBAAwB,CAAC,KAAK,SAAS,cAAc,GAAG,cAAc,IAAI,IAAI,CACxF,eAAe,CAAC,KAAK,CAAC,EACtB,WAAW,GAAG,WAAW,CAC1B,GAAG;IAAE,SAAS,EAAE,eAAe,CAAA;CAAE,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAC7B,KAAK,SAAS,cAAc,GAAG,cAAc,EAC7C,QAAQ,SAAS,WAAW,GAAG,cAAc,IAC3C,yBAAyB,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC;AAEzF;;GAEG;AACH,eAAO,MAAM,aAAa,oFAQvB,gBAAgB,GAAG,CAAC,gBA0BtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,oEAOvB,gBAAgB,GAAG,CAAC,gBAuBtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,uGAQtB,gBAAgB,GAAG,EAAE,MAAM,CAAC,gBAuD9B,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type MosaicContainerProps } from '../Container';
1
+ import { type MosaicContainerContextType } from '../Container';
2
2
  import { type MosaicDataItem } from '../types';
3
- export declare const useContainer: <TData extends MosaicDataItem = MosaicDataItem, TPosition = unknown>() => MosaicContainerProps<TData, TPosition>;
3
+ export declare const useContainer: <TData extends MosaicDataItem = MosaicDataItem, TPosition = unknown>() => MosaicContainerContextType<TData, TPosition>;
4
4
  //# sourceMappingURL=useContainer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useContainer.d.ts","sourceRoot":"","sources":["../../../../../src/mosaic/hooks/useContainer.ts"],"names":[],"mappings":"AAQA,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,eAAO,MAAM,YAAY,kHAIiE,CAAC"}
1
+ {"version":3,"file":"useContainer.d.ts","sourceRoot":"","sources":["../../../../../src/mosaic/hooks/useContainer.ts"],"names":[],"mappings":"AAMA,OAAO,EAA0B,KAAK,0BAA0B,EAAE,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,eAAO,MAAM,YAAY,wHAG8D,CAAC"}
@@ -3,6 +3,7 @@ export type MosaicDataItem = {
3
3
  };
4
4
  export type MosaicDraggedItem<TPosition = unknown> = {
5
5
  path: string;
6
+ type: string;
6
7
  item: MosaicDataItem;
7
8
  position?: TPosition;
8
9
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/mosaic/types.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C,MAAM,MAAM,iBAAiB,CAAC,SAAS,GAAG,OAAO,IAAI;IACnD,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,cAAc,CAAC;IAErB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/mosaic/types.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C,MAAM,MAAM,iBAAiB,CAAC,SAAS,GAAG,OAAO,IAAI;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,cAAc,CAAC;IAErB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from './data';
2
2
  export * from './path';
3
+ export * from './props';
3
4
  export * from './styles';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/mosaic/util/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/mosaic/util/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type MosaicTileComponentProps, type MosaicTileProps } from '../Tile';
2
+ export declare const isTileProps: (props: Record<string, unknown>) => props is MosaicTileProps;
3
+ export declare const isTileComponentProps: (props: Record<string, unknown>) => props is MosaicTileComponentProps;
4
+ //# sourceMappingURL=props.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../../../../src/mosaic/util/props.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,wBAAwB,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAE9E,eAAO,MAAM,WAAW,UAAW,OAAO,MAAM,EAAE,OAAO,CAAC,6BAG/C,CAAC;AAEZ,eAAO,MAAM,oBAAoB,UAAW,OAAO,MAAM,EAAE,OAAO,CAAC,sCACsC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-mosaic",
3
- "version": "0.3.8-next.f4e0086",
3
+ "version": "0.3.9-main.14901ff",
4
4
  "description": "An intermediate interface for drag-and-drop interactions.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -25,13 +25,13 @@
25
25
  "lodash.defaultsdeep": "^4.6.1",
26
26
  "lodash.pick": "^4.4.0",
27
27
  "react-resize-detector": "^7.1.2",
28
- "@dxos/debug": "0.3.8-next.f4e0086",
29
- "@dxos/invariant": "0.3.8-next.f4e0086",
30
- "@dxos/keys": "0.3.8-next.f4e0086",
31
- "@dxos/react-ui": "0.3.8-next.f4e0086",
32
- "@dxos/util": "0.3.8-next.f4e0086",
33
- "@dxos/react-ui-types": "0.3.8-next.f4e0086",
34
- "@dxos/react-ui-theme": "0.3.8-next.f4e0086"
28
+ "@dxos/invariant": "0.3.9-main.14901ff",
29
+ "@dxos/debug": "0.3.9-main.14901ff",
30
+ "@dxos/keys": "0.3.9-main.14901ff",
31
+ "@dxos/react-ui": "0.3.9-main.14901ff",
32
+ "@dxos/react-ui-theme": "0.3.9-main.14901ff",
33
+ "@dxos/react-ui-types": "0.3.9-main.14901ff",
34
+ "@dxos/util": "0.3.9-main.14901ff"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@faker-js/faker": "^8.0.2",
@@ -47,10 +47,10 @@
47
47
  "react-dom": "^18.2.0",
48
48
  "vite": "^4.3.9",
49
49
  "vite-plugin-turbosnap": "^1.0.2",
50
- "@dxos/app-graph": "0.3.8-next.f4e0086",
51
- "@dxos/echo-schema": "0.3.8-next.f4e0086",
52
- "@dxos/gem-core": "0.3.8-next.f4e0086",
53
- "@dxos/react-client": "0.3.8-next.f4e0086"
50
+ "@dxos/app-graph": "0.3.9-main.14901ff",
51
+ "@dxos/echo-schema": "0.3.9-main.14901ff",
52
+ "@dxos/gem-core": "0.3.9-main.14901ff",
53
+ "@dxos/react-client": "0.3.9-main.14901ff"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@phosphor-icons/react": "^2.0.5",
package/src/index.ts CHANGED
@@ -3,6 +3,3 @@
3
3
  //
4
4
 
5
5
  export * from './mosaic';
6
-
7
- // TODO(burdon): Remove (factor out components).
8
- export * from './views';
@@ -15,7 +15,13 @@ import { type MosaicTileComponent } from './Tile';
15
15
  import { useMosaic } from './hooks';
16
16
  import { type MosaicDataItem, type MosaicDraggedItem } from './types';
17
17
 
18
+ // TODO(wittjosiah): Factor out.
19
+ type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
20
+ [Property in Key]-?: Type[Property];
21
+ };
22
+
18
23
  export const DEFAULT_TRANSITION = 200;
24
+ export const DEFAULT_TYPE = 'unknown';
19
25
 
20
26
  export type MosaicTileOverlayProps = {
21
27
  grow?: boolean;
@@ -31,7 +37,8 @@ export type MosaicTileOverlayProps = {
31
37
  * * `reject` - The tile is not allowed where it was dropped.
32
38
  */
33
39
  // TODO(wittjosiah): Add 'delete'. Consider adding 'swap'.
34
- export type MosaicOperation = 'transfer' | 'copy' | 'rearrange' | 'reject';
40
+ export const MosaicOperations = ['transfer', 'copy', 'rearrange', 'reject'] as const;
41
+ export type MosaicOperation = (typeof MosaicOperations)[number];
35
42
 
36
43
  export type MosaicMoveEvent<TPosition = unknown> = {
37
44
  active: MosaicDraggedItem<TPosition>;
@@ -57,6 +64,11 @@ export type MosaicContainerProps<TData extends MosaicDataItem = MosaicDataItem,
57
64
  */
58
65
  Component?: MosaicTileComponent<TData, any>;
59
66
 
67
+ /**
68
+ * Default type of tiles.
69
+ */
70
+ type?: string;
71
+
60
72
  /**
61
73
  * Length of transition when moving tiles in milliseconds.
62
74
  *
@@ -92,9 +104,15 @@ export type MosaicContainerProps<TData extends MosaicDataItem = MosaicDataItem,
92
104
  onDrop?: (event: MosaicDropEvent<TPosition>) => void;
93
105
  }>;
94
106
 
95
- export type MosaicContainerContextType = Omit<MosaicContainerProps<any>, 'children'>;
107
+ export type MosaicContainerContextType<
108
+ TData extends MosaicDataItem = MosaicDataItem,
109
+ TPosition = unknown,
110
+ > = WithRequiredProperty<Omit<MosaicContainerProps<TData, TPosition>, 'children'>, 'type'>;
96
111
 
97
- export const MosaicContainerContext = createContext<MosaicContainerContextType | undefined>(undefined);
112
+ export const MosaicContainerContext = createContext<MosaicContainerContextType<any>>({
113
+ id: 'never',
114
+ type: DEFAULT_TYPE,
115
+ });
98
116
 
99
117
  /**
100
118
  * Root Container that manages the layout of tiles.
@@ -103,6 +121,7 @@ export const MosaicContainer = ({
103
121
  children,
104
122
  id,
105
123
  debug,
124
+ type = DEFAULT_TYPE,
106
125
  Component,
107
126
  transitionDuration = DEFAULT_TRANSITION,
108
127
  modifier,
@@ -115,6 +134,7 @@ export const MosaicContainer = ({
115
134
  const container = {
116
135
  id,
117
136
  debug,
137
+ type,
118
138
  Component,
119
139
  transitionDuration,
120
140
  modifier,
@@ -79,6 +79,7 @@ export const MosaicDragOverlay = ({ delay = 200, debug = false, ...overlayProps
79
79
  {...container.getOverlayProps?.()}
80
80
  item={activeItem.item}
81
81
  path={activeItem.path}
82
+ type={activeItem.type}
82
83
  operation={operation}
83
84
  active='overlay'
84
85
  />
@@ -133,13 +133,13 @@ export const MosaicRoot: FC<MosaicRootProps> = ({ Component = DefaultComponent,
133
133
  //
134
134
 
135
135
  const handleDragStart = (event: DragStartEvent) => {
136
- setActiveItem(pick(event.active.data.current as MosaicDraggedItem, 'path', 'item', 'position'));
136
+ setActiveItem(pick(event.active.data.current as MosaicDraggedItem, 'path', 'type', 'item', 'position'));
137
137
  };
138
138
 
139
139
  const handleDragMove = (event: DragMoveEvent) => {};
140
140
 
141
141
  const handleDragOver = (event: DragOverEvent) => {
142
- const overItem = pick(event.over?.data.current as MosaicDraggedItem, 'path', 'item', 'position');
142
+ const overItem = pick(event.over?.data.current as MosaicDraggedItem, 'path', 'type', 'item', 'position');
143
143
 
144
144
  // If the over item is the same as the active item, do nothing.
145
145
  // This happens when moving between containers where a placeholder of itself is rendered where it will be dropped.
@@ -241,11 +241,13 @@ const MosaicDebug: FC<{
241
241
  active: {
242
242
  id: activeItem?.item?.id.slice(0, 16),
243
243
  path: activeItem?.path && Path.create(...Path.parts(activeItem.path).map((part) => part.slice(0, 16))),
244
+ type: activeItem?.type,
244
245
  position: activeItem?.position,
245
246
  },
246
247
  over: {
247
248
  id: overItem?.item?.id.slice(0, 16),
248
249
  path: overItem?.path && Path.create(...Path.parts(overItem.path).map((part) => part.slice(0, 16))),
250
+ type: overItem?.type,
249
251
  position: overItem?.position,
250
252
  },
251
253
  }}
@@ -7,7 +7,7 @@ import { defaultAnimateLayoutChanges, useSortable } from '@dnd-kit/sortable';
7
7
  import React from 'react';
8
8
  import type { CSSProperties, ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from 'react';
9
9
 
10
- import type { MosaicOperation, MosaicTileOverlayProps } from './Container';
10
+ import { DEFAULT_TYPE, type MosaicOperation, type MosaicTileOverlayProps } from './Container';
11
11
  import { DefaultComponent } from './DefaultComponent';
12
12
  import { useContainer, useMosaic } from './hooks';
13
13
  import type { MosaicDataItem, MosaicDraggedItem } from './types';
@@ -15,6 +15,7 @@ import { getTransformCSS, Path } from './util';
15
15
 
16
16
  export type MosaicActiveType = 'overlay' | 'rearrange' | 'origin' | 'destination';
17
17
 
18
+ // TODO(wittjosiah): `id` should be `path` and `data` should be a `MosaicDataItem`.
18
19
  export type MosaicTileAction = { id: string; action: string; data?: any };
19
20
 
20
21
  /**
@@ -29,6 +30,7 @@ export type MosaicTileProps<TData extends MosaicDataItem = MosaicDataItem, TPosi
29
30
  item: TData;
30
31
  Component?: MosaicTileComponent<TData, any>;
31
32
  position?: TPosition;
33
+ type?: string;
32
34
  operation?: MosaicOperation;
33
35
  active?: MosaicActiveType; // TODO(burdon): Rename state?
34
36
 
@@ -43,24 +45,29 @@ export type MosaicTileProps<TData extends MosaicDataItem = MosaicDataItem, TPosi
43
45
  // TODO(burdon): Generalize events via onAction?
44
46
  onSelect?: () => void;
45
47
  onRemove?: () => void;
48
+ onNavigate?: () => void;
46
49
  onAction?: (action: MosaicTileAction) => void;
47
50
  };
48
51
 
52
+ export type MosaicTileComponentProps<TData extends MosaicDataItem = MosaicDataItem> = Omit<
53
+ MosaicTileProps<TData>,
54
+ 'Component' | 'operation'
55
+ > & { operation: MosaicOperation };
56
+
49
57
  /**
50
58
  * Mosaic Tile component.
51
59
  */
52
60
  export type MosaicTileComponent<
53
61
  TData extends MosaicDataItem = MosaicDataItem,
54
62
  TElement extends HTMLElement = HTMLDivElement,
55
- > = ForwardRefExoticComponent<
56
- RefAttributes<TElement> & Omit<MosaicTileProps<TData>, 'Component' | 'operation'> & { operation: MosaicOperation }
57
- >;
63
+ > = ForwardRefExoticComponent<RefAttributes<TElement> & MosaicTileComponentProps<TData>>;
58
64
 
59
65
  /**
60
66
  * Basic draggable mosaic tile.
61
67
  */
62
68
  export const DraggableTile = ({
63
69
  path: parentPath,
70
+ type = DEFAULT_TYPE,
64
71
  item,
65
72
  Component = DefaultComponent,
66
73
  position,
@@ -71,7 +78,7 @@ export const DraggableTile = ({
71
78
  const path = Path.create(parentPath, item.id);
72
79
  const { setNodeRef, attributes, listeners, /* transform, */ isDragging } = useDraggable({
73
80
  id: path,
74
- data: { path, item, position } satisfies MosaicDraggedItem,
81
+ data: { path, type, item, position } satisfies MosaicDraggedItem,
75
82
  });
76
83
 
77
84
  return (
@@ -79,6 +86,7 @@ export const DraggableTile = ({
79
86
  ref={setNodeRef}
80
87
  item={item}
81
88
  path={path}
89
+ type={type}
82
90
  position={position}
83
91
  operation={operation}
84
92
  isDragging={isDragging}
@@ -98,6 +106,7 @@ export const DraggableTile = ({
98
106
  */
99
107
  export const DroppableTile = ({
100
108
  path: parentPath,
109
+ type = DEFAULT_TYPE,
101
110
  item,
102
111
  Component = DefaultComponent,
103
112
  position,
@@ -110,7 +119,7 @@ export const DroppableTile = ({
110
119
  : Path.create(parentPath, item.id);
111
120
  const { setNodeRef, isOver } = useDroppable({
112
121
  id: path,
113
- data: { path, item, position } satisfies MosaicDraggedItem,
122
+ data: { path, type, item, position } satisfies MosaicDraggedItem,
114
123
  });
115
124
 
116
125
  return (
@@ -118,6 +127,7 @@ export const DroppableTile = ({
118
127
  ref={setNodeRef}
119
128
  item={item}
120
129
  path={path}
130
+ type={type}
121
131
  position={position}
122
132
  operation={operation}
123
133
  isOver={isOver}
@@ -131,6 +141,7 @@ export const DroppableTile = ({
131
141
  */
132
142
  export const SortableTile = ({
133
143
  path: parentPath,
144
+ type = DEFAULT_TYPE,
134
145
  item,
135
146
  Component: OverrideComponent,
136
147
  position,
@@ -153,7 +164,7 @@ export const SortableTile = ({
153
164
 
154
165
  const { setNodeRef, attributes, listeners, transform, isDragging, isOver } = useSortable({
155
166
  id: isPreview ? activeItem.path : path,
156
- data: { path, item, position } satisfies MosaicDraggedItem,
167
+ data: { path, type, item, position } satisfies MosaicDraggedItem,
157
168
  animateLayoutChanges: (args) =>
158
169
  defaultAnimateLayoutChanges({ ...args, wasDragging: item.id !== activeItem?.item.id }),
159
170
  });
@@ -176,6 +187,7 @@ export const SortableTile = ({
176
187
  ref={setNodeRef}
177
188
  item={item}
178
189
  path={path}
190
+ type={type}
179
191
  position={position}
180
192
  operation={operation}
181
193
  active={active}
@@ -4,13 +4,10 @@
4
4
 
5
5
  import { useContext } from 'react';
6
6
 
7
- import { raise } from '@dxos/debug';
8
-
9
- import { MosaicContainerContext, type MosaicContainerProps } from '../Container';
7
+ import { MosaicContainerContext, type MosaicContainerContextType } from '../Container';
10
8
  import { type MosaicDataItem } from '../types';
11
9
 
12
10
  export const useContainer = <
13
11
  TData extends MosaicDataItem = MosaicDataItem,
14
12
  TPosition = unknown,
15
- >(): MosaicContainerProps<TData, TPosition> =>
16
- useContext(MosaicContainerContext) ?? raise(new Error('Missing MosaicContainerContext'));
13
+ >(): MosaicContainerContextType<TData, TPosition> => useContext(MosaicContainerContext);
@@ -2,10 +2,12 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ // TODO(wittjosiah): Rename MosiacDataItem to MosaicItemData?
5
6
  export type MosaicDataItem = { id: string };
6
7
 
7
8
  export type MosaicDraggedItem<TPosition = unknown> = {
8
9
  path: string;
10
+ type: string;
9
11
  // TODO(wittjosiah): Rename data? Otherwise item within item.
10
12
  item: MosaicDataItem;
11
13
  // Index or layout-specific positional information (stored separately from the item).
@@ -4,4 +4,5 @@
4
4
 
5
5
  export * from './data';
6
6
  export * from './path';
7
+ export * from './props';
7
8
  export * from './styles';
@@ -0,0 +1,14 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { MosaicOperations } from '../Container';
6
+ import { type MosaicTileComponentProps, type MosaicTileProps } from '../Tile';
7
+
8
+ export const isTileProps = (props: Record<string, unknown>): props is MosaicTileProps =>
9
+ typeof props.path === 'string' && typeof props.item === 'object' && props.item
10
+ ? 'id' in props.item && typeof props.item.id === 'string'
11
+ : false;
12
+
13
+ export const isTileComponentProps = (props: Record<string, unknown>): props is MosaicTileComponentProps =>
14
+ isTileProps(props) && typeof props.operation === 'string' && MosaicOperations.includes(props.operation);