@dxos/react-ui-mosaic 0.4.10-main.fa5a270 → 0.4.10-main.fd8ea31
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 +9 -7
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/mosaic/Container.d.ts +1 -1
- package/dist/types/src/mosaic/Container.d.ts.map +1 -1
- package/dist/types/src/mosaic/Tile.d.ts +22 -1
- package/dist/types/src/mosaic/Tile.d.ts.map +1 -1
- package/dist/types/src/testing/generator.d.ts +4 -5
- package/dist/types/src/testing/generator.d.ts.map +1 -1
- package/dist/types/src/views/Demo/Echo.stories.d.ts.map +1 -1
- package/dist/types/src/views/Kanban/testing.d.ts +0 -8
- package/dist/types/src/views/Kanban/testing.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/mosaic/Container.tsx +1 -1
- package/src/mosaic/Tile.tsx +30 -32
- package/src/testing/generator.ts +35 -28
- package/src/views/Demo/Echo.stories.tsx +5 -4
- package/src/views/Kanban/Echo.stories.tsx +23 -23
- package/src/views/Kanban/testing.tsx +149 -153
|
@@ -2,18 +2,13 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import React, { type FC, useRef, useState } from 'react';
|
|
5
|
+
import React, { type FC, useState } from 'react';
|
|
7
6
|
|
|
8
7
|
import { invariant } from '@dxos/invariant';
|
|
9
|
-
import { type PublicKey } from '@dxos/react-client';
|
|
10
|
-
import { Schema, type TypedObject, useQuery, useSpace } from '@dxos/react-client/echo';
|
|
11
|
-
import { Button, Select, Toolbar } from '@dxos/react-ui';
|
|
12
|
-
import { arrayMove } from '@dxos/util';
|
|
13
8
|
|
|
14
9
|
import { Kanban, type KanbanColumn, type KanbanProps } from './Kanban';
|
|
15
10
|
import { Mosaic, type MosaicDropEvent, Path, swapItems } from '../../mosaic';
|
|
16
|
-
import { TestObjectGenerator,
|
|
11
|
+
import { TestObjectGenerator, Priority, Status, type TestItem } from '../../testing';
|
|
17
12
|
|
|
18
13
|
const createKanban = ({ types, columns = 3 }: { types?: string[]; columns?: number }) => {
|
|
19
14
|
const generator = new TestObjectGenerator({ types });
|
|
@@ -83,149 +78,150 @@ export const columnValues: { [property: string]: any[] } = {
|
|
|
83
78
|
priority: ['unknown', ...Priority],
|
|
84
79
|
};
|
|
85
80
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
81
|
+
// TODO(wittjosiah): Update to use effect schema.
|
|
82
|
+
// export const EchoKanban = ({
|
|
83
|
+
// id,
|
|
84
|
+
// spaceKey,
|
|
85
|
+
// generator,
|
|
86
|
+
// debug,
|
|
87
|
+
// }: {
|
|
88
|
+
// id: string;
|
|
89
|
+
// spaceKey: PublicKey;
|
|
90
|
+
// generator: TestObjectGenerator;
|
|
91
|
+
// debug?: boolean;
|
|
92
|
+
// }) => {
|
|
93
|
+
// const space = useSpace(spaceKey);
|
|
94
|
+
// // TODO(burdon): Decorator is not re-run schema is empty when returning to story after first run. Different kanban id.
|
|
95
|
+
// const [kanban] = useQuery(space, { type: 'kanban' });
|
|
96
|
+
|
|
97
|
+
// const getProperty = (property: string) => {
|
|
98
|
+
// const schemaProperty = kanban.schema.props.find((prop: any) => prop.id === kanban.columnProp);
|
|
99
|
+
// if (schemaProperty.type === Schema.PropType.NUMBER) {
|
|
100
|
+
// return parseInt(property);
|
|
101
|
+
// } else {
|
|
102
|
+
// return property;
|
|
103
|
+
// }
|
|
104
|
+
// };
|
|
105
|
+
|
|
106
|
+
// const objects = useQuery<TypedObject>(space, (object) => object.__schema === kanban.schema, {}, [kanban.schema]);
|
|
107
|
+
// const columns: KanbanColumn<TypedObject>[] = kanban.columnValues.map((value: string) => {
|
|
108
|
+
// const objectPosition = kanban.objectPosition[value] ?? [];
|
|
109
|
+
// const items =
|
|
110
|
+
// objectPosition.length > 0
|
|
111
|
+
// ? objectPosition.map((id: string) => objects.find((object) => object.id === id))
|
|
112
|
+
// : objects;
|
|
113
|
+
|
|
114
|
+
// // TODO(burdon): Special case for 'unknown' values?
|
|
115
|
+
// return {
|
|
116
|
+
// id: getProperty(value),
|
|
117
|
+
// title: value,
|
|
118
|
+
// items: items.filter((object: TypedObject) => object[kanban.columnProp] === value),
|
|
119
|
+
// };
|
|
120
|
+
// });
|
|
121
|
+
|
|
122
|
+
// // TODO(burdon): Why ref?
|
|
123
|
+
// const columnsRef = useRef<KanbanColumn<TypedObject>[]>([]);
|
|
124
|
+
// columnsRef.current = columns;
|
|
125
|
+
|
|
126
|
+
// // TODO(burdon): Called for each object generated (should batch?)
|
|
127
|
+
// // console.log(JSON.stringify(objects[0]));
|
|
128
|
+
|
|
129
|
+
// // TODO(burdon): Should views maintain an positional index map per property (to enable switching?)
|
|
130
|
+
// // TODO(burdon): Is the current index map making use of ECHO object CRDT? Need multi-peer test in this suite.
|
|
131
|
+
// const handleSetProperty = (property: string) => {
|
|
132
|
+
// kanban.columnProp = property;
|
|
133
|
+
// kanban.columnValues = columnValues[kanban.columnProp];
|
|
134
|
+
// };
|
|
135
|
+
|
|
136
|
+
// // TODO(burdon): Factor out util.
|
|
137
|
+
// const getOrder = (kanban: TypedObject, property: string) => {
|
|
138
|
+
// // TODO(wittjosiah): Columns is stale here.
|
|
139
|
+
// return (
|
|
140
|
+
// kanban.objectPosition[property] ??
|
|
141
|
+
// columnsRef.current.find((column) => column.id === getProperty(property))?.items.map((item) => item.id) ??
|
|
142
|
+
// []
|
|
143
|
+
// );
|
|
144
|
+
// };
|
|
145
|
+
|
|
146
|
+
// // TODO(burdon): Currently broken: factor out with demo story.
|
|
147
|
+
// const handleDrop = ({ active, over }: MosaicDropEvent<number>) => {
|
|
148
|
+
// // Reorder columns.
|
|
149
|
+
// // TODO(burdon): Factor out util.
|
|
150
|
+
// if (active.path === Path.create(id, active.item.id)) {
|
|
151
|
+
// // Reorder columns.
|
|
152
|
+
// const fromIndex = kanban.columnValues.findIndex((value: string) => value === active.item.id);
|
|
153
|
+
// const toIndex = kanban.columnValues.findIndex((value: string) => value === over.item.id);
|
|
154
|
+
// fromIndex !== -1 && toIndex !== -1 && arrayMove(kanban.columnValues, fromIndex, toIndex);
|
|
155
|
+
// return;
|
|
156
|
+
// }
|
|
157
|
+
|
|
158
|
+
// if (Path.hasDescendent(id, active.path)) {
|
|
159
|
+
// const activeProperty = Path.last(Path.parent(active.path));
|
|
160
|
+
// const overProperty = Path.length(over.path) > 2 ? Path.last(Path.parent(over.path)) : Path.last(over.path);
|
|
161
|
+
// invariant(activeProperty);
|
|
162
|
+
// invariant(overProperty);
|
|
163
|
+
|
|
164
|
+
// // Update property.
|
|
165
|
+
// (active.item as TypedObject)[kanban.columnProp] = getProperty(overProperty);
|
|
166
|
+
|
|
167
|
+
// // Update active column order.
|
|
168
|
+
// const activeOrder = getOrder(kanban, activeProperty);
|
|
169
|
+
// activeOrder.length > 0 && activeOrder.splice(active.position, 1);
|
|
170
|
+
// kanban.objectPosition[activeProperty] = activeOrder;
|
|
171
|
+
|
|
172
|
+
// // Update over column order.
|
|
173
|
+
// const overOrder = getOrder(kanban, overProperty);
|
|
174
|
+
// overOrder.length > 0 && Path.length(over.path) === Path.length(active.path)
|
|
175
|
+
// ? overOrder.splice(over.position, 0, active.item.id)
|
|
176
|
+
// : overOrder.push(active.item.id);
|
|
177
|
+
// kanban.objectPosition[overProperty] = overOrder;
|
|
178
|
+
// }
|
|
179
|
+
// };
|
|
180
|
+
|
|
181
|
+
// const handleAddData = () => {
|
|
182
|
+
// const object = generator.createObject({ types: ['project'] });
|
|
183
|
+
// space?.db.add(object);
|
|
184
|
+
// };
|
|
185
|
+
|
|
186
|
+
// return (
|
|
187
|
+
// <div className='flex flex-col grow'>
|
|
188
|
+
// <Toolbar.Root classNames='p-2'>
|
|
189
|
+
// <PropertySelector
|
|
190
|
+
// property={kanban.columnProp}
|
|
191
|
+
// properties={Object.keys(columnValues)}
|
|
192
|
+
// onSetProperty={handleSetProperty}
|
|
193
|
+
// />
|
|
194
|
+
// <Button title='Add Data' onClick={handleAddData}>
|
|
195
|
+
// <Plus />
|
|
196
|
+
// </Button>
|
|
197
|
+
// </Toolbar.Root>
|
|
198
|
+
// <Kanban id={id} columns={columns} Component={SimpleCard} onDrop={handleDrop} debug={debug} />
|
|
199
|
+
// </div>
|
|
200
|
+
// );
|
|
201
|
+
// };
|
|
202
|
+
|
|
203
|
+
// const PropertySelector: FC<{ property: string; properties: string[]; onSetProperty: (property: string) => void }> = ({
|
|
204
|
+
// property,
|
|
205
|
+
// properties,
|
|
206
|
+
// onSetProperty,
|
|
207
|
+
// }) => {
|
|
208
|
+
// return (
|
|
209
|
+
// <Select.Root value={property} onValueChange={onSetProperty}>
|
|
210
|
+
// <Select.TriggerButton placeholder='Select value' />
|
|
211
|
+
// <Select.Portal>
|
|
212
|
+
// <Select.Content>
|
|
213
|
+
// <Select.ScrollUpButton />
|
|
214
|
+
// <Select.Viewport>
|
|
215
|
+
// {properties.map((property) => (
|
|
216
|
+
// <Select.Option key={property} value={property}>
|
|
217
|
+
// {property}
|
|
218
|
+
// </Select.Option>
|
|
219
|
+
// ))}
|
|
220
|
+
// </Select.Viewport>
|
|
221
|
+
// <Select.ScrollDownButton />
|
|
222
|
+
// <Select.Arrow />
|
|
223
|
+
// </Select.Content>
|
|
224
|
+
// </Select.Portal>
|
|
225
|
+
// </Select.Root>
|
|
226
|
+
// );
|
|
227
|
+
// };
|