@dxos/react-ui-mosaic 0.3.8 → 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.
- package/dist/lib/browser/index.mjs +44 -450
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/mosaic/Container.d.ts +14 -4
- package/dist/types/src/mosaic/Container.d.ts.map +1 -1
- package/dist/types/src/mosaic/DragOverlay.d.ts.map +1 -1
- package/dist/types/src/mosaic/Tile.d.ts +9 -7
- package/dist/types/src/mosaic/Tile.d.ts.map +1 -1
- package/dist/types/src/mosaic/hooks/useContainer.d.ts +2 -2
- package/dist/types/src/mosaic/hooks/useContainer.d.ts.map +1 -1
- package/dist/types/src/mosaic/types.d.ts +1 -0
- package/dist/types/src/mosaic/types.d.ts.map +1 -1
- package/dist/types/src/mosaic/util/index.d.ts +1 -0
- package/dist/types/src/mosaic/util/index.d.ts.map +1 -1
- package/dist/types/src/mosaic/util/props.d.ts +4 -0
- package/dist/types/src/mosaic/util/props.d.ts.map +1 -0
- package/package.json +12 -12
- package/src/index.ts +0 -3
- package/src/mosaic/Container.tsx +23 -3
- package/src/mosaic/DragOverlay.tsx +1 -0
- package/src/mosaic/Root.tsx +4 -2
- package/src/mosaic/Tile.tsx +18 -7
- package/src/mosaic/hooks/useContainer.ts +2 -5
- package/src/mosaic/types.ts +2 -0
- package/src/mosaic/util/index.ts +1 -0
- package/src/mosaic/util/props.ts +14 -0
|
@@ -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,
|
|
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
|
|
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;
|
|
@@ -27,22 +28,23 @@ export type MosaicTileProps<TData extends MosaicDataItem = MosaicDataItem, TPosi
|
|
|
27
28
|
onNavigate?: () => void;
|
|
28
29
|
onAction?: (action: MosaicTileAction) => void;
|
|
29
30
|
};
|
|
31
|
+
export type MosaicTileComponentProps<TData extends MosaicDataItem = MosaicDataItem> = Omit<MosaicTileProps<TData>, 'Component' | 'operation'> & {
|
|
32
|
+
operation: MosaicOperation;
|
|
33
|
+
};
|
|
30
34
|
/**
|
|
31
35
|
* Mosaic Tile component.
|
|
32
36
|
*/
|
|
33
|
-
export type MosaicTileComponent<TData extends MosaicDataItem = MosaicDataItem, TElement extends HTMLElement = HTMLDivElement> = ForwardRefExoticComponent<RefAttributes<TElement> &
|
|
34
|
-
operation: MosaicOperation;
|
|
35
|
-
}>;
|
|
37
|
+
export type MosaicTileComponent<TData extends MosaicDataItem = MosaicDataItem, TElement extends HTMLElement = HTMLDivElement> = ForwardRefExoticComponent<RefAttributes<TElement> & MosaicTileComponentProps<TData>>;
|
|
36
38
|
/**
|
|
37
39
|
* Basic draggable mosaic tile.
|
|
38
40
|
*/
|
|
39
|
-
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;
|
|
40
42
|
/**
|
|
41
43
|
* Basic droppable mosaic tile.
|
|
42
44
|
*/
|
|
43
|
-
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;
|
|
44
46
|
/**
|
|
45
47
|
* Mosaic tile that can be sorted.
|
|
46
48
|
*/
|
|
47
|
-
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;
|
|
48
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,
|
|
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,EAAgB,KAAK,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG9F,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,SAAS,CAAC;AAGjE,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,aAAa,CAAC;AAGlF,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,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAG1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B,cAAc,CAAC,EAAE,mBAAmB,GAElC,cAAc,CAAC,WAAW,CAAC,CAAC;IAG9B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;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
|
|
1
|
+
import { type MosaicContainerContextType } from '../Container';
|
|
2
2
|
import { type MosaicDataItem } from '../types';
|
|
3
|
-
export declare const useContainer: <TData extends MosaicDataItem = MosaicDataItem, TPosition = unknown>() =>
|
|
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":"
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/mosaic/types.ts"],"names":[],"mappings":"
|
|
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 +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.
|
|
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/
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/react-ui
|
|
32
|
-
"@dxos/react-ui-
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
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.
|
|
51
|
-
"@dxos/echo-schema": "0.3.
|
|
52
|
-
"@dxos/gem-core": "0.3.
|
|
53
|
-
"@dxos/react-client": "0.3.
|
|
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
package/src/mosaic/Container.tsx
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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,
|
package/src/mosaic/Root.tsx
CHANGED
|
@@ -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
|
}}
|
package/src/mosaic/Tile.tsx
CHANGED
|
@@ -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
|
|
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
|
|
|
@@ -47,21 +49,25 @@ export type MosaicTileProps<TData extends MosaicDataItem = MosaicDataItem, TPosi
|
|
|
47
49
|
onAction?: (action: MosaicTileAction) => void;
|
|
48
50
|
};
|
|
49
51
|
|
|
52
|
+
export type MosaicTileComponentProps<TData extends MosaicDataItem = MosaicDataItem> = Omit<
|
|
53
|
+
MosaicTileProps<TData>,
|
|
54
|
+
'Component' | 'operation'
|
|
55
|
+
> & { operation: MosaicOperation };
|
|
56
|
+
|
|
50
57
|
/**
|
|
51
58
|
* Mosaic Tile component.
|
|
52
59
|
*/
|
|
53
60
|
export type MosaicTileComponent<
|
|
54
61
|
TData extends MosaicDataItem = MosaicDataItem,
|
|
55
62
|
TElement extends HTMLElement = HTMLDivElement,
|
|
56
|
-
> = ForwardRefExoticComponent<
|
|
57
|
-
RefAttributes<TElement> & Omit<MosaicTileProps<TData>, 'Component' | 'operation'> & { operation: MosaicOperation }
|
|
58
|
-
>;
|
|
63
|
+
> = ForwardRefExoticComponent<RefAttributes<TElement> & MosaicTileComponentProps<TData>>;
|
|
59
64
|
|
|
60
65
|
/**
|
|
61
66
|
* Basic draggable mosaic tile.
|
|
62
67
|
*/
|
|
63
68
|
export const DraggableTile = ({
|
|
64
69
|
path: parentPath,
|
|
70
|
+
type = DEFAULT_TYPE,
|
|
65
71
|
item,
|
|
66
72
|
Component = DefaultComponent,
|
|
67
73
|
position,
|
|
@@ -72,7 +78,7 @@ export const DraggableTile = ({
|
|
|
72
78
|
const path = Path.create(parentPath, item.id);
|
|
73
79
|
const { setNodeRef, attributes, listeners, /* transform, */ isDragging } = useDraggable({
|
|
74
80
|
id: path,
|
|
75
|
-
data: { path, item, position } satisfies MosaicDraggedItem,
|
|
81
|
+
data: { path, type, item, position } satisfies MosaicDraggedItem,
|
|
76
82
|
});
|
|
77
83
|
|
|
78
84
|
return (
|
|
@@ -80,6 +86,7 @@ export const DraggableTile = ({
|
|
|
80
86
|
ref={setNodeRef}
|
|
81
87
|
item={item}
|
|
82
88
|
path={path}
|
|
89
|
+
type={type}
|
|
83
90
|
position={position}
|
|
84
91
|
operation={operation}
|
|
85
92
|
isDragging={isDragging}
|
|
@@ -99,6 +106,7 @@ export const DraggableTile = ({
|
|
|
99
106
|
*/
|
|
100
107
|
export const DroppableTile = ({
|
|
101
108
|
path: parentPath,
|
|
109
|
+
type = DEFAULT_TYPE,
|
|
102
110
|
item,
|
|
103
111
|
Component = DefaultComponent,
|
|
104
112
|
position,
|
|
@@ -111,7 +119,7 @@ export const DroppableTile = ({
|
|
|
111
119
|
: Path.create(parentPath, item.id);
|
|
112
120
|
const { setNodeRef, isOver } = useDroppable({
|
|
113
121
|
id: path,
|
|
114
|
-
data: { path, item, position } satisfies MosaicDraggedItem,
|
|
122
|
+
data: { path, type, item, position } satisfies MosaicDraggedItem,
|
|
115
123
|
});
|
|
116
124
|
|
|
117
125
|
return (
|
|
@@ -119,6 +127,7 @@ export const DroppableTile = ({
|
|
|
119
127
|
ref={setNodeRef}
|
|
120
128
|
item={item}
|
|
121
129
|
path={path}
|
|
130
|
+
type={type}
|
|
122
131
|
position={position}
|
|
123
132
|
operation={operation}
|
|
124
133
|
isOver={isOver}
|
|
@@ -132,6 +141,7 @@ export const DroppableTile = ({
|
|
|
132
141
|
*/
|
|
133
142
|
export const SortableTile = ({
|
|
134
143
|
path: parentPath,
|
|
144
|
+
type = DEFAULT_TYPE,
|
|
135
145
|
item,
|
|
136
146
|
Component: OverrideComponent,
|
|
137
147
|
position,
|
|
@@ -154,7 +164,7 @@ export const SortableTile = ({
|
|
|
154
164
|
|
|
155
165
|
const { setNodeRef, attributes, listeners, transform, isDragging, isOver } = useSortable({
|
|
156
166
|
id: isPreview ? activeItem.path : path,
|
|
157
|
-
data: { path, item, position } satisfies MosaicDraggedItem,
|
|
167
|
+
data: { path, type, item, position } satisfies MosaicDraggedItem,
|
|
158
168
|
animateLayoutChanges: (args) =>
|
|
159
169
|
defaultAnimateLayoutChanges({ ...args, wasDragging: item.id !== activeItem?.item.id }),
|
|
160
170
|
});
|
|
@@ -177,6 +187,7 @@ export const SortableTile = ({
|
|
|
177
187
|
ref={setNodeRef}
|
|
178
188
|
item={item}
|
|
179
189
|
path={path}
|
|
190
|
+
type={type}
|
|
180
191
|
position={position}
|
|
181
192
|
operation={operation}
|
|
182
193
|
active={active}
|
|
@@ -4,13 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { useContext } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
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
|
-
>():
|
|
16
|
-
useContext(MosaicContainerContext) ?? raise(new Error('Missing MosaicContainerContext'));
|
|
13
|
+
>(): MosaicContainerContextType<TData, TPosition> => useContext(MosaicContainerContext);
|
package/src/mosaic/types.ts
CHANGED
|
@@ -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).
|
package/src/mosaic/util/index.ts
CHANGED
|
@@ -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);
|