@dxos/plugin-debug 0.7.2 → 0.7.3-staging.0905f03

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 (39) hide show
  1. package/dist/lib/browser/{DebugSpace-ZLGGNDAR.mjs → DebugSpace-DHKEAMIC.mjs} +3 -3
  2. package/dist/lib/browser/{DebugSpace-ZLGGNDAR.mjs.map → DebugSpace-DHKEAMIC.mjs.map} +2 -2
  3. package/dist/lib/browser/SpaceGenerator-BQ3645OS.mjs +273 -0
  4. package/dist/lib/browser/SpaceGenerator-BQ3645OS.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +43 -34
  6. package/dist/lib/browser/index.mjs.map +3 -3
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/types/src/DebugPlugin.d.ts.map +1 -1
  9. package/dist/types/src/components/DebugObjectPanel.d.ts.map +1 -1
  10. package/dist/types/src/components/DebugSpace/DebugSpace.d.ts +1 -1
  11. package/dist/types/src/components/{SurfaceDebug.d.ts → DebugSurface.d.ts} +2 -2
  12. package/dist/types/src/components/{SurfaceDebug.d.ts.map → DebugSurface.d.ts.map} +1 -1
  13. package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts +7 -0
  14. package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts.map +1 -0
  15. package/dist/types/src/components/SpaceGenerator/SchemaTable.d.ts +9 -0
  16. package/dist/types/src/components/SpaceGenerator/SchemaTable.d.ts.map +1 -0
  17. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts +9 -0
  18. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts.map +1 -0
  19. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts +6 -0
  20. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts.map +1 -0
  21. package/dist/types/src/components/SpaceGenerator/draw-util.d.ts +8 -0
  22. package/dist/types/src/components/SpaceGenerator/draw-util.d.ts.map +1 -0
  23. package/dist/types/src/components/SpaceGenerator/index.d.ts +3 -0
  24. package/dist/types/src/components/SpaceGenerator/index.d.ts.map +1 -0
  25. package/dist/types/src/components/index.d.ts +2 -1
  26. package/dist/types/src/components/index.d.ts.map +1 -1
  27. package/package.json +45 -38
  28. package/src/DebugPlugin.tsx +74 -39
  29. package/src/components/DebugObjectPanel.tsx +2 -1
  30. package/src/components/DebugSpace/DebugSpace.tsx +2 -2
  31. package/src/components/DebugSpace/ObjectCreator.tsx +1 -1
  32. package/src/components/{SurfaceDebug.tsx → DebugSurface.tsx} +1 -1
  33. package/src/components/SpaceGenerator/ObjectGenerator.tsx +141 -0
  34. package/src/components/SpaceGenerator/SchemaTable.tsx +38 -0
  35. package/src/components/SpaceGenerator/SpaceGenerator.stories.tsx +37 -0
  36. package/src/components/SpaceGenerator/SpaceGenerator.tsx +113 -0
  37. package/src/components/SpaceGenerator/draw-util.ts +190 -0
  38. package/src/components/SpaceGenerator/index.ts +7 -0
  39. package/src/components/index.ts +1 -0
@@ -3,8 +3,9 @@ export declare const DebugApp: import("react").LazyExoticComponent<import("react
3
3
  }>>;
4
4
  export declare const DebugSpace: import("react").LazyExoticComponent<import("react").FC<{
5
5
  space: import("packages/sdk/client-protocol/dist/types/src").Space;
6
- onAddObjects?: (objects: import("packages/core/echo/echo-schema/dist/types/src").ReactiveObject<any>[]) => void;
6
+ onAddObjects?: (objects: import("packages/core/echo/live-object/dist/types/src").ReactiveObject<any>[]) => void;
7
7
  }>>;
8
+ export declare const SpaceGenerator: import("react").LazyExoticComponent<({ space, onCreateObjects }: import("./SpaceGenerator/SpaceGenerator").SpaceGeneratorProps) => import("react").JSX.Element>;
8
9
  export * from './DebugObjectPanel';
9
10
  export * from './DebugSettings';
10
11
  export * from './DebugStatus';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ;;GAAmC,CAAC;AACzD,eAAO,MAAM,UAAU;;;GAAqC,CAAC;AAE7D,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ;;GAAmC,CAAC;AACzD,eAAO,MAAM,UAAU;;;GAAqC,CAAC;AAC7D,eAAO,MAAM,cAAc,iKAAyC,CAAC;AAErE,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-debug",
3
- "version": "0.7.2",
3
+ "version": "0.7.3-staging.0905f03",
4
4
  "description": "DXOS Surface plugin for testing.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -30,43 +30,50 @@
30
30
  "src"
31
31
  ],
32
32
  "dependencies": {
33
+ "@antv/graphlib": "^2.0.4",
34
+ "@antv/layout": "^1.2.13",
33
35
  "@preact/signals-core": "^1.6.0",
34
36
  "@tldraw/tldraw": "^3.0.0",
35
37
  "date-fns": "^3.3.1",
38
+ "effect": "^3.9.2",
36
39
  "lodash.get": "^4.4.2",
37
40
  "react-json-tree": "^0.18.0",
38
41
  "react-resize-detector": "^11.0.1",
39
- "@dxos/app-framework": "0.7.2",
40
- "@dxos/async": "0.7.2",
41
- "@dxos/automerge": "0.7.2",
42
- "@dxos/client-services": "0.7.2",
43
- "@dxos/config": "0.7.2",
44
- "@dxos/echo-generator": "0.7.2",
45
- "@dxos/echo-pipeline": "0.7.2",
46
- "@dxos/invariant": "0.7.2",
47
- "@dxos/devtools": "0.7.2",
48
- "@dxos/keys": "0.7.2",
49
- "@dxos/echo-schema": "0.7.2",
50
- "@dxos/local-storage": "0.7.2",
51
- "@dxos/log": "0.7.2",
52
- "@dxos/plugin-client": "0.7.2",
53
- "@dxos/plugin-deck": "0.7.2",
54
- "@dxos/plugin-graph": "0.7.2",
55
- "@dxos/plugin-sketch": "0.7.2",
56
- "@dxos/plugin-markdown": "0.7.2",
57
- "@dxos/plugin-space": "0.7.2",
58
- "@dxos/plugin-status-bar": "0.7.2",
59
- "@dxos/protocols": "0.7.2",
60
- "@dxos/plugin-theme": "0.7.2",
61
- "@dxos/react-client": "0.7.2",
62
- "@dxos/plugin-table": "0.7.2",
63
- "@dxos/react-hooks": "0.7.2",
64
- "@dxos/random": "0.7.2",
65
- "@dxos/react-ui-attention": "0.7.2",
66
- "@dxos/react-ui-form": "0.7.2",
67
- "@dxos/react-ui-syntax-highlighter": "0.7.2",
68
- "@dxos/react-ui-table": "0.7.2",
69
- "@dxos/util": "0.7.2"
42
+ "workerize-loader": "^2.0.2",
43
+ "@dxos/app-framework": "0.7.3-staging.0905f03",
44
+ "@dxos/automerge": "0.7.3-staging.0905f03",
45
+ "@dxos/client-services": "0.7.3-staging.0905f03",
46
+ "@dxos/async": "0.7.3-staging.0905f03",
47
+ "@dxos/echo-generator": "0.7.3-staging.0905f03",
48
+ "@dxos/devtools": "0.7.3-staging.0905f03",
49
+ "@dxos/config": "0.7.3-staging.0905f03",
50
+ "@dxos/echo-pipeline": "0.7.3-staging.0905f03",
51
+ "@dxos/echo-schema": "0.7.3-staging.0905f03",
52
+ "@dxos/keys": "0.7.3-staging.0905f03",
53
+ "@dxos/live-object": "0.7.3-staging.0905f03",
54
+ "@dxos/local-storage": "0.7.3-staging.0905f03",
55
+ "@dxos/log": "0.7.3-staging.0905f03",
56
+ "@dxos/invariant": "0.7.3-staging.0905f03",
57
+ "@dxos/plugin-client": "0.7.3-staging.0905f03",
58
+ "@dxos/plugin-deck": "0.7.3-staging.0905f03",
59
+ "@dxos/plugin-markdown": "0.7.3-staging.0905f03",
60
+ "@dxos/plugin-graph": "0.7.3-staging.0905f03",
61
+ "@dxos/plugin-sheet": "0.7.3-staging.0905f03",
62
+ "@dxos/plugin-space": "0.7.3-staging.0905f03",
63
+ "@dxos/plugin-sketch": "0.7.3-staging.0905f03",
64
+ "@dxos/plugin-status-bar": "0.7.3-staging.0905f03",
65
+ "@dxos/plugin-table": "0.7.3-staging.0905f03",
66
+ "@dxos/random": "0.7.3-staging.0905f03",
67
+ "@dxos/plugin-theme": "0.7.3-staging.0905f03",
68
+ "@dxos/react-client": "0.7.3-staging.0905f03",
69
+ "@dxos/protocols": "0.7.3-staging.0905f03",
70
+ "@dxos/react-ui-attention": "0.7.3-staging.0905f03",
71
+ "@dxos/react-hooks": "0.7.3-staging.0905f03",
72
+ "@dxos/react-ui-form": "0.7.3-staging.0905f03",
73
+ "@dxos/react-ui-syntax-highlighter": "0.7.3-staging.0905f03",
74
+ "@dxos/react-ui-table": "0.7.3-staging.0905f03",
75
+ "@dxos/schema": "0.7.3-staging.0905f03",
76
+ "@dxos/util": "0.7.3-staging.0905f03"
70
77
  },
71
78
  "devDependencies": {
72
79
  "@phosphor-icons/react": "^2.1.5",
@@ -76,17 +83,17 @@
76
83
  "react": "~18.2.0",
77
84
  "react-dom": "~18.2.0",
78
85
  "vite": "5.4.7",
79
- "@dxos/storybook-utils": "0.7.2",
80
- "@dxos/react-ui": "0.7.2",
81
- "@dxos/react-ui-theme": "0.7.2"
86
+ "@dxos/react-ui-theme": "0.7.3-staging.0905f03",
87
+ "@dxos/react-ui": "0.7.3-staging.0905f03",
88
+ "@dxos/storybook-utils": "0.7.3-staging.0905f03"
82
89
  },
83
90
  "peerDependencies": {
84
91
  "@phosphor-icons/react": "^2.1.5",
85
92
  "react": "~18.2.0",
86
93
  "react-dom": "~18.2.0",
87
- "@dxos/random": "0.7.2",
88
- "@dxos/react-ui": "0.7.2",
89
- "@dxos/react-ui-theme": "0.7.2"
94
+ "@dxos/random": "0.7.3-staging.0905f03",
95
+ "@dxos/react-ui": "0.7.3-staging.0905f03",
96
+ "@dxos/react-ui-theme": "0.7.3-staging.0905f03"
90
97
  },
91
98
  "publishConfig": {
92
99
  "access": "public"
@@ -17,10 +17,19 @@ import { Devtools } from '@dxos/devtools';
17
17
  import { invariant } from '@dxos/invariant';
18
18
  import { type ClientPluginProvides, parseClientPlugin } from '@dxos/plugin-client';
19
19
  import { createExtension, Graph, type Node, toSignal } from '@dxos/plugin-graph';
20
- import { SpaceAction } from '@dxos/plugin-space';
20
+ import { memoizeQuery, SpaceAction } from '@dxos/plugin-space';
21
21
  import { CollectionType } from '@dxos/plugin-space/types';
22
22
  import { type Client } from '@dxos/react-client';
23
- import { create, getTypename, isEchoObject, isSpace, parseId, type Space, SpaceState } from '@dxos/react-client/echo';
23
+ import {
24
+ create,
25
+ getTypename,
26
+ isEchoObject,
27
+ isSpace,
28
+ parseId,
29
+ type ReactiveObject,
30
+ type Space,
31
+ SpaceState,
32
+ } from '@dxos/react-client/echo';
24
33
  import { Main } from '@dxos/react-ui';
25
34
  import {
26
35
  baseSurface,
@@ -29,7 +38,15 @@ import {
29
38
  topbarBlockPaddingStart,
30
39
  } from '@dxos/react-ui-theme';
31
40
 
32
- import { DebugApp, DebugObjectPanel, DebugSettings, DebugSpace, DebugStatus, Wireframe } from './components';
41
+ import {
42
+ DebugApp,
43
+ DebugObjectPanel,
44
+ DebugSettings,
45
+ DebugSpace,
46
+ DebugStatus,
47
+ SpaceGenerator,
48
+ Wireframe,
49
+ } from './components';
33
50
  import meta, { DEBUG_PLUGIN } from './meta';
34
51
  import translations from './translations';
35
52
  import {
@@ -153,11 +170,27 @@ export const DebugPlugin = definePlugin<DebugPluginProvides>((context) => {
153
170
  filter: (node): node is Node<Space> => !!settings.debug && isSpace(node.data),
154
171
  connector: ({ node }) => {
155
172
  const space = node.data;
173
+ const state = toSignal(
174
+ (onChange) => space.state.subscribe(() => onChange()).unsubscribe,
175
+ () => space.state.get(),
176
+ );
177
+ if (state !== SpaceState.SPACE_READY) {
178
+ return;
179
+ }
180
+
181
+ // Not adding the debug node until the root collection is available aligns the behaviour of this
182
+ // extension with that of the space plugin adding objects. This ensures that the debug node is added at
183
+ // the same time as objects and prevents order from changing as the nodes are added.
184
+ const collection = space.properties[CollectionType.typename] as CollectionType | undefined;
185
+ if (!collection) {
186
+ return;
187
+ }
188
+
156
189
  return [
157
190
  {
158
191
  id: `${space.id}-debug`, // TODO(burdon): Change to slashes consistently.
159
192
  type: 'dxos.org/plugin/debug/space',
160
- data: { space },
193
+ data: { space, type: 'dxos.org/plugin/debug/space' },
161
194
  properties: {
162
195
  label: ['debug label', { ns: DEBUG_PLUGIN }],
163
196
  icon: 'ph--bug--regular',
@@ -181,7 +214,13 @@ export const DebugPlugin = definePlugin<DebugPluginProvides>((context) => {
181
214
 
182
215
  const [subjectId] = id.split('~');
183
216
  const { spaceId, objectId } = parseId(subjectId);
184
- const space = client.spaces.get().find((space) => space.id === spaceId);
217
+ const spaces = toSignal(
218
+ (onChange) => client.spaces.subscribe(() => onChange()).unsubscribe,
219
+ () => client.spaces.get(),
220
+ );
221
+ const space = spaces?.find(
222
+ (space) => space.state.get() === SpaceState.SPACE_READY && space.id === spaceId,
223
+ );
185
224
  if (!objectId) {
186
225
  // TODO(burdon): Ref SPACE_PLUGIN ns.
187
226
  const label = space
@@ -204,18 +243,7 @@ export const DebugPlugin = definePlugin<DebugPluginProvides>((context) => {
204
243
  };
205
244
  }
206
245
 
207
- const object = toSignal(
208
- (onChange) => {
209
- const timeout = setTimeout(async () => {
210
- await space?.db.query({ id: objectId }).first();
211
- onChange();
212
- });
213
-
214
- return () => clearTimeout(timeout);
215
- },
216
- () => space?.db.getObjectById(objectId),
217
- subjectId,
218
- );
246
+ const [object] = memoizeQuery(space, { id: objectId });
219
247
  if (!object || !subjectId) {
220
248
  return;
221
249
  }
@@ -283,30 +311,37 @@ export const DebugPlugin = definePlugin<DebugPluginProvides>((context) => {
283
311
  component = <Devtools />;
284
312
  } else if (!primary || typeof primary !== 'object' || !settings.debug) {
285
313
  component = null;
286
- } else if ('space' in primary && isSpace(primary.space)) {
287
- component = (
288
- <DebugSpace
289
- space={primary.space}
290
- onAddObjects={(objects) => {
291
- if (!isSpace(primary.space)) {
292
- return;
293
- }
314
+ } else if (
315
+ 'type' in primary &&
316
+ primary.type === 'dxos.org/plugin/debug/space' &&
317
+ 'space' in primary &&
318
+ isSpace(primary.space)
319
+ ) {
320
+ const handleCreateObject = (objects: ReactiveObject<any>[]) => {
321
+ if (!isSpace(primary.space)) {
322
+ return;
323
+ }
294
324
 
295
- const collection =
296
- primary.space.state.get() === SpaceState.SPACE_READY &&
297
- primary.space.properties[CollectionType.typename];
298
- if (!(collection instanceof CollectionType)) {
299
- return;
300
- }
325
+ const collection =
326
+ primary.space.state.get() === SpaceState.SPACE_READY &&
327
+ primary.space.properties[CollectionType.typename];
328
+ if (!(collection instanceof CollectionType)) {
329
+ return;
330
+ }
331
+
332
+ void context.resolvePlugin(parseIntentPlugin).provides.intent.dispatch(
333
+ objects.map((object) => ({
334
+ action: SpaceAction.ADD_OBJECT,
335
+ data: { target: collection, object },
336
+ })),
337
+ );
338
+ };
301
339
 
302
- void context.resolvePlugin(parseIntentPlugin).provides.intent.dispatch(
303
- objects.map((object) => ({
304
- action: SpaceAction.ADD_OBJECT,
305
- data: { target: collection, object },
306
- })),
307
- );
308
- }}
309
- />
340
+ const deprecated = false;
341
+ component = deprecated ? (
342
+ <DebugSpace space={primary.space} onAddObjects={handleCreateObject} />
343
+ ) : (
344
+ <SpaceGenerator space={primary.space} onCreateObjects={handleCreateObject} />
310
345
  );
311
346
  } else if ('graph' in primary && primary.graph instanceof Graph) {
312
347
  component = <DebugApp graph={primary.graph} />;
@@ -11,9 +11,10 @@ export type DebugObjectPanelProps = {
11
11
  object: ReactiveEchoObject<any>;
12
12
  };
13
13
 
14
+ // TODO(burdon): Get schema and traverse references.
14
15
  export const DebugObjectPanel = ({ object }: DebugObjectPanelProps) => {
15
16
  return (
16
- <div role='form' className='flex flex-col'>
17
+ <div className='flex flex-col'>
17
18
  <SyntaxHighlighter classNames='flex text-xs' language='json'>
18
19
  {JSON.stringify(object, null, 2)}
19
20
  </SyntaxHighlighter>
@@ -5,7 +5,7 @@
5
5
  import React, { type FC, useContext, useMemo, useState } from 'react';
6
6
 
7
7
  import { createSpaceObjectGenerator } from '@dxos/echo-generator';
8
- import { type ReactiveObject } from '@dxos/echo-schema';
8
+ import { type ReactiveObject } from '@dxos/live-object';
9
9
  import { DocumentType } from '@dxos/plugin-markdown/types';
10
10
  import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
11
11
  import { faker } from '@dxos/random';
@@ -149,7 +149,7 @@ export const DebugSpace: FC<{
149
149
  />
150
150
 
151
151
  <IconButton
152
- icon={running ? 'ph--hand-palm--regular' : 'ph--play--regular'}
152
+ icon={running ? 'ph--pause-circle--regular' : 'ph--play-circle--regular'}
153
153
  iconOnly
154
154
  label='Start/stop'
155
155
  size={5}
@@ -92,7 +92,7 @@ export const ObjectCreator = ({ space, onAddObjects }: ObjectCreatorProps) => {
92
92
  <Table.Main<CreateObjectsParams> columns={columns} data={objects} />
93
93
  </Table.Viewport>
94
94
  </Table.Root>
95
- <Toolbar.Root classNames='p-2'>
95
+ <Toolbar.Root classNames='p-1'>
96
96
  <IconButton icon='ph--plus--regular' label='Create' onClick={handleCreate} />
97
97
  </Toolbar.Root>
98
98
  </>
@@ -16,7 +16,7 @@ export type SurfaceDebugProps = ThemedClassName<{}>;
16
16
  * Show surface info.
17
17
  * NOTE: Remove from @dxos/app-framework if removing this.
18
18
  */
19
- export const SurfaceDebug = ({ classNames }: SurfaceDebugProps) => {
19
+ export const DebugSurface = ({ classNames }: SurfaceDebugProps) => {
20
20
  const context = useSurfaceRoot();
21
21
  const [surfaces, setSurfaces] = useState<DebugInfo[]>([]);
22
22
  const renderMap = useMemo(() => new Map<string, { last: number; delta: number }>(), []);
@@ -0,0 +1,141 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type AbstractSchema, type BaseObject } from '@dxos/echo-schema';
6
+ import { create, type ReactiveObject } from '@dxos/live-object';
7
+ import { DocumentType, TextType } from '@dxos/plugin-markdown/types';
8
+ import { addressToA1Notation, createSheet } from '@dxos/plugin-sheet';
9
+ import { type CellValue } from '@dxos/plugin-sheet/types';
10
+ import { SheetType } from '@dxos/plugin-sheet/types';
11
+ import { CanvasType, DiagramType } from '@dxos/plugin-sketch/types';
12
+ import { faker } from '@dxos/random';
13
+ import { Filter, type Space } from '@dxos/react-client/echo';
14
+ import { TableType } from '@dxos/react-ui-table';
15
+ import { createView } from '@dxos/schema';
16
+ import { createAsyncGenerator, type ValueGenerator } from '@dxos/schema/testing';
17
+ import { range } from '@dxos/util';
18
+
19
+ const generator: ValueGenerator = faker as any;
20
+
21
+ // TODO(burdon): Add objects to collections.
22
+ // TODO(burdon): Create docs.
23
+ // TODO(burdon): Create sketches.
24
+ // TODO(burdon): Create sheets.
25
+ // TODO(burdon): Create comments.
26
+ // TODO(burdon): Reuse in testbench-app.
27
+ // TODO(burdon): Mutator running in background (factor out): from echo-generator.
28
+
29
+ export type ObjectGenerator<T extends BaseObject> = (
30
+ space: Space,
31
+ n: number,
32
+ cb?: (objects: ReactiveObject<any>[]) => void,
33
+ ) => Promise<ReactiveObject<T>[]>;
34
+
35
+ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
36
+ [
37
+ DocumentType.typename,
38
+ async (space, n, cb) => {
39
+ const objects = range(n).map(() => {
40
+ const obj = space.db.add(
41
+ create(DocumentType, {
42
+ name: faker.commerce.productName(),
43
+ content: create(TextType, { content: faker.lorem.sentences(5) }),
44
+ threads: [],
45
+ }),
46
+ );
47
+
48
+ return obj;
49
+ });
50
+
51
+ cb?.(objects);
52
+ return objects;
53
+ },
54
+ ],
55
+ [
56
+ DiagramType.typename,
57
+ async (space, n, cb) => {
58
+ const objects = range(n).map(() => {
59
+ // TODO(burdon): Generate diagram.
60
+ const obj = space.db.add(
61
+ create(DiagramType, {
62
+ name: faker.commerce.productName(),
63
+ canvas: create(CanvasType, { content: {} }),
64
+ }),
65
+ );
66
+
67
+ return obj;
68
+ });
69
+
70
+ cb?.(objects);
71
+ return objects;
72
+ },
73
+ ],
74
+ // TODO(burdon): Create unit tests.
75
+ [
76
+ SheetType.typename,
77
+ async (space, n, cb) => {
78
+ const objects = range(n).map(() => {
79
+ const cells: Record<string, CellValue> = {};
80
+ const year = new Date().getFullYear();
81
+ const cols = 4;
82
+ const rows = 16;
83
+ for (let col = 1; col <= cols; col++) {
84
+ for (let row = 1; row <= rows; row++) {
85
+ const cell = addressToA1Notation({ col, row });
86
+ if (row === 1) {
87
+ cells[cell] = { value: `${year} Q${col}` };
88
+ } else if (row === rows) {
89
+ const from = addressToA1Notation({ col, row: 2 });
90
+ const to = addressToA1Notation({ col, row: rows - 1 });
91
+ cells[cell] = { value: `=SUM(${from}:${to})` };
92
+ } else if (row > 2 && row < rows - 1) {
93
+ cells[cell] = { value: Math.floor(Math.random() * 10_000) };
94
+ }
95
+ }
96
+ }
97
+
98
+ // TODO(burdon): Set width.
99
+ // TODO(burdon): Set formatting for columns.
100
+ return space.db.add(
101
+ createSheet({
102
+ name: faker.commerce.productName(),
103
+ cells,
104
+ }),
105
+ );
106
+ });
107
+
108
+ cb?.(objects);
109
+ return objects;
110
+ },
111
+ ],
112
+ ]);
113
+
114
+ export const createGenerator = <T extends BaseObject>(type: AbstractSchema<T>): ObjectGenerator<T> => {
115
+ return async (
116
+ space: Space,
117
+ n: number,
118
+ cb?: (objects: ReactiveObject<any>[]) => void,
119
+ ): Promise<ReactiveObject<T>[]> => {
120
+ // Find or create mutable schema.
121
+ const mutableSchema = await space.db.schemaRegistry.query();
122
+ const schema =
123
+ mutableSchema.find((schema) => schema.typename === type.typename) ?? space.db.schemaRegistry.addSchema(type);
124
+
125
+ // Create objects.
126
+ const generate = createAsyncGenerator(generator, schema.schema, { db: space.db });
127
+ const objects = await generate.createObjects(n);
128
+
129
+ // Find or create table and view.
130
+ const { objects: tables } = await space.db.query(Filter.schema(TableType)).run();
131
+ const table = tables.find((table) => table.view?.query?.type === type.typename);
132
+ if (!table) {
133
+ const name = type.typename.split('/').pop() ?? type.typename;
134
+ const view = createView({ name, typename: type.typename, jsonSchema: schema.jsonSchema });
135
+ const table = space.db.add(create(TableType, { name, view }));
136
+ cb?.([table]);
137
+ }
138
+
139
+ return objects;
140
+ };
141
+ };
@@ -0,0 +1,38 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { IconButton } from '@dxos/react-ui';
8
+
9
+ export type SchemaTableProps = {
10
+ types: any[];
11
+ objects?: Record<string, number | undefined>;
12
+ label: string;
13
+ onClick: (typename: string) => void;
14
+ };
15
+
16
+ export const SchemaTable = ({ types, objects = {}, label, onClick }: SchemaTableProps) => {
17
+ return (
18
+ <div className='grid grid-cols-[1fr_80px_40px] gap-1 overflow-hidden'>
19
+ <div className='grid grid-cols-subgrid col-span-3'>
20
+ <div className='px-2 text-sm text-primary-500'>{label}</div>
21
+ <div className='px-2 text-xs text-subdued text-right'>count</div>
22
+ </div>
23
+ {types.map((type) => (
24
+ <div key={type.typename} className='grid grid-cols-subgrid col-span-3 items-center'>
25
+ <div className='px-2 text-sm font-mono text-green-500'>{type.typename}</div>
26
+ <div className='px-2 text-right font-mono'>{objects[type.typename] ?? 0}</div>
27
+ <IconButton
28
+ variant='ghost'
29
+ icon='ph--plus--regular'
30
+ iconOnly
31
+ label='Create data'
32
+ onClick={() => onClick(type.typename)}
33
+ />
34
+ </div>
35
+ ))}
36
+ </div>
37
+ );
38
+ };
@@ -0,0 +1,37 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta } from '@storybook/react';
8
+ import React from 'react';
9
+
10
+ import { useSpaces } from '@dxos/react-client/echo';
11
+ import { withClientProvider } from '@dxos/react-client/testing';
12
+ import { render, withLayout, withTheme } from '@dxos/storybook-utils';
13
+
14
+ import { SpaceGenerator } from './SpaceGenerator';
15
+
16
+ const DefaultStory = () => {
17
+ const [space] = useSpaces();
18
+ if (!space) {
19
+ return null;
20
+ }
21
+
22
+ return <SpaceGenerator space={space} />;
23
+ };
24
+
25
+ const meta: Meta = {
26
+ title: 'plugins/plugin-debug/SpaceGenerator',
27
+ component: SpaceGenerator,
28
+ render: render(DefaultStory),
29
+ decorators: [withClientProvider({ createSpace: true }), withLayout({ tooltips: true }), withTheme],
30
+ parameters: {
31
+ layout: 'fullscreen',
32
+ },
33
+ };
34
+
35
+ export default meta;
36
+
37
+ export const Default = {};