@dxos/plugin-debug 0.7.5-main.ff8607b → 0.7.5-staging.2ff1350

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 (71) hide show
  1. package/dist/lib/browser/{DebugSpace-4JHYA7FG.mjs → DebugSpace-BTMTVZ6C.mjs} +2 -2
  2. package/dist/lib/browser/SpaceGenerator-BPZGOSH4.mjs +1238 -0
  3. package/dist/lib/browser/SpaceGenerator-BPZGOSH4.mjs.map +7 -0
  4. package/dist/lib/browser/app-graph-builder-BZFZ6UG6.mjs +533 -0
  5. package/dist/lib/browser/app-graph-builder-BZFZ6UG6.mjs.map +7 -0
  6. package/dist/lib/browser/chunk-UASI2CRI.mjs +72 -0
  7. package/dist/lib/browser/chunk-UASI2CRI.mjs.map +7 -0
  8. package/dist/lib/browser/index.mjs +44 -8
  9. package/dist/lib/browser/index.mjs.map +3 -3
  10. package/dist/lib/browser/meta.json +1 -1
  11. package/dist/lib/browser/react-context-TCD3MNIT.mjs +16 -0
  12. package/dist/lib/browser/react-context-TCD3MNIT.mjs.map +7 -0
  13. package/dist/lib/browser/{react-surface-VEEFOGIM.mjs → react-surface-W6QLG4YJ.mjs} +210 -40
  14. package/dist/lib/browser/react-surface-W6QLG4YJ.mjs.map +7 -0
  15. package/dist/lib/browser/{settings-OIMSBZUC.mjs → settings-INPXR64L.mjs} +5 -6
  16. package/dist/lib/browser/{settings-OIMSBZUC.mjs.map → settings-INPXR64L.mjs.map} +3 -3
  17. package/dist/types/src/DebugPlugin.d.ts.map +1 -1
  18. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  19. package/dist/types/src/capabilities/index.d.ts +5 -0
  20. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  21. package/dist/types/src/capabilities/react-context.d.ts +8 -0
  22. package/dist/types/src/capabilities/react-context.d.ts.map +1 -0
  23. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  24. package/dist/types/src/capabilities/settings.d.ts.map +1 -1
  25. package/dist/types/src/components/Container.d.ts +2 -2
  26. package/dist/types/src/components/Container.d.ts.map +1 -1
  27. package/dist/types/src/components/DebugObjectPanel.d.ts +1 -2
  28. package/dist/types/src/components/DebugObjectPanel.d.ts.map +1 -1
  29. package/dist/types/src/components/DebugSettings.d.ts +1 -2
  30. package/dist/types/src/components/DebugSettings.d.ts.map +1 -1
  31. package/dist/types/src/components/DebugSpace/ObjectCreator.d.ts +1 -2
  32. package/dist/types/src/components/DebugSpace/ObjectCreator.d.ts.map +1 -1
  33. package/dist/types/src/components/DebugStatus.d.ts +1 -2
  34. package/dist/types/src/components/DebugStatus.d.ts.map +1 -1
  35. package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts.map +1 -1
  36. package/dist/types/src/components/SpaceGenerator/SchemaTable.d.ts +1 -2
  37. package/dist/types/src/components/SpaceGenerator/SchemaTable.d.ts.map +1 -1
  38. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts +1 -2
  39. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts.map +1 -1
  40. package/dist/types/src/components/SpaceGenerator/presets.d.ts +22 -0
  41. package/dist/types/src/components/SpaceGenerator/presets.d.ts.map +1 -0
  42. package/dist/types/src/components/Wireframe.d.ts +1 -2
  43. package/dist/types/src/components/Wireframe.d.ts.map +1 -1
  44. package/dist/types/src/components/index.d.ts +1 -1
  45. package/dist/types/src/components/index.d.ts.map +1 -1
  46. package/dist/types/src/translations.d.ts +28 -0
  47. package/dist/types/src/translations.d.ts.map +1 -1
  48. package/dist/types/src/types.d.ts +44 -1
  49. package/dist/types/src/types.d.ts.map +1 -1
  50. package/package.json +50 -44
  51. package/src/DebugPlugin.tsx +12 -4
  52. package/src/capabilities/app-graph-builder.ts +292 -89
  53. package/src/capabilities/index.ts +1 -0
  54. package/src/capabilities/react-context.tsx +16 -0
  55. package/src/capabilities/react-surface.tsx +204 -27
  56. package/src/capabilities/settings.ts +0 -1
  57. package/src/components/DebugObjectPanel.tsx +17 -5
  58. package/src/components/DebugSettings.tsx +0 -3
  59. package/src/components/SpaceGenerator/ObjectGenerator.tsx +31 -4
  60. package/src/components/SpaceGenerator/SpaceGenerator.tsx +75 -6
  61. package/src/components/SpaceGenerator/presets.ts +563 -0
  62. package/src/translations.ts +28 -0
  63. package/src/types.ts +52 -1
  64. package/dist/lib/browser/SpaceGenerator-NJCG57CU.mjs +0 -279
  65. package/dist/lib/browser/SpaceGenerator-NJCG57CU.mjs.map +0 -7
  66. package/dist/lib/browser/app-graph-builder-66ZVNTDI.mjs +0 -182
  67. package/dist/lib/browser/app-graph-builder-66ZVNTDI.mjs.map +0 -7
  68. package/dist/lib/browser/chunk-P7GHHMDB.mjs +0 -21
  69. package/dist/lib/browser/chunk-P7GHHMDB.mjs.map +0 -7
  70. package/dist/lib/browser/react-surface-VEEFOGIM.mjs.map +0 -7
  71. /package/dist/lib/browser/{DebugSpace-4JHYA7FG.mjs.map → DebugSpace-BTMTVZ6C.mjs.map} +0 -0
@@ -4,8 +4,39 @@
4
4
 
5
5
  import React, { useCallback } from 'react';
6
6
 
7
- import { Capabilities, contributes, createIntent, createSurface, type PluginsContext } from '@dxos/app-framework';
8
- import { Devtools } from '@dxos/devtools';
7
+ import {
8
+ Capabilities,
9
+ contributes,
10
+ createIntent,
11
+ createSurface,
12
+ LayoutAction,
13
+ type PluginsContext,
14
+ } from '@dxos/app-framework';
15
+ import {
16
+ ConfigPanel,
17
+ CredentialsPanel,
18
+ DeviceListPanel,
19
+ DiagnosticsPanel,
20
+ FeedsPanel,
21
+ IdentityPanel,
22
+ KeyringPanel,
23
+ LoggingPanel,
24
+ MembersPanel,
25
+ MetadataPanel,
26
+ NetworkPanel,
27
+ ObjectsPanel,
28
+ SignalPanel,
29
+ SpaceInfoPanel,
30
+ SpaceListPanel,
31
+ StoragePanel,
32
+ SwarmPanel,
33
+ TracingPanel,
34
+ DashboardPanel,
35
+ EdgeDashboardPanel,
36
+ SearchPanel,
37
+ AutomergePanel,
38
+ WorkflowPanel,
39
+ } from '@dxos/devtools';
9
40
  import { SettingsStore } from '@dxos/local-storage';
10
41
  import { Graph } from '@dxos/plugin-graph';
11
42
  import { SpaceAction, CollectionType } from '@dxos/plugin-space/types';
@@ -28,7 +59,7 @@ import {
28
59
  Wireframe,
29
60
  } from '../components';
30
61
  import { DEBUG_PLUGIN } from '../meta';
31
- import { type DebugSettingsProps } from '../types';
62
+ import { type DebugSettingsProps, Devtools } from '../types';
32
63
 
33
64
  type SpaceDebug = {
34
65
  type: string;
@@ -39,8 +70,8 @@ type GraphDebug = {
39
70
  graph: Graph;
40
71
  };
41
72
 
42
- const isSpaceDebug = (data: any): data is SpaceDebug => data.type === `${DEBUG_PLUGIN}/space` && isSpace(data.space);
43
- const isGraphDebug = (data: any): data is GraphDebug => data.graph instanceof Graph;
73
+ const isSpaceDebug = (data: any): data is SpaceDebug => data?.type === `${DEBUG_PLUGIN}/space` && isSpace(data.space);
74
+ const isGraphDebug = (data: any): data is GraphDebug => data?.graph instanceof Graph;
44
75
 
45
76
  export default (context: PluginsContext) =>
46
77
  contributes(Capabilities.ReactSurface, [
@@ -51,28 +82,6 @@ export default (context: PluginsContext) =>
51
82
  data.subject instanceof SettingsStore && data.subject.prefix === DEBUG_PLUGIN,
52
83
  component: ({ data: { subject } }) => <DebugSettings settings={subject.value} />,
53
84
  }),
54
- createSurface({
55
- id: `${DEBUG_PLUGIN}/status`,
56
- role: 'status',
57
- component: () => <DebugStatus />,
58
- }),
59
- createSurface({
60
- id: `${DEBUG_PLUGIN}/complementary`,
61
- role: 'complementary--debug',
62
- filter: (data): data is { subject: ReactiveEchoObject<any> } => isEchoObject(data.subject),
63
- component: ({ data }) => <DebugObjectPanel object={data.subject} />,
64
- }),
65
- createSurface({
66
- id: `${DEBUG_PLUGIN}/devtools`,
67
- role: 'article',
68
- filter: (data): data is any => {
69
- const settings = context
70
- .requestCapability(Capabilities.SettingsStore)
71
- .getStore<DebugSettingsProps>(DEBUG_PLUGIN)!.value;
72
- return data.subject === 'devtools' && !!settings.devtools;
73
- },
74
- component: () => <Devtools />,
75
- }),
76
85
  createSurface({
77
86
  id: `${DEBUG_PLUGIN}/space`,
78
87
  role: 'article',
@@ -127,4 +136,172 @@ export default (context: PluginsContext) =>
127
136
  <Wireframe label={`${role}:${name}`} object={data.subject} classNames='row-span-2 overflow-hidden' />
128
137
  ),
129
138
  }),
139
+ createSurface({
140
+ id: `${DEBUG_PLUGIN}/complementary`,
141
+ role: 'complementary--debug',
142
+ filter: (data): data is { subject: ReactiveEchoObject<any> } => isEchoObject(data.subject),
143
+ component: ({ data }) => <DebugObjectPanel object={data.subject} />,
144
+ }),
145
+ createSurface({
146
+ id: `${DEBUG_PLUGIN}/status`,
147
+ role: 'status',
148
+ component: () => <DebugStatus />,
149
+ }),
150
+
151
+ //
152
+ // Devtools
153
+ //
154
+
155
+ createSurface({
156
+ id: `${DEBUG_PLUGIN}/client/config`,
157
+ role: 'article',
158
+ filter: (data): data is any => data.subject === Devtools.Client.Config,
159
+ component: () => <ConfigPanel />,
160
+ }),
161
+ createSurface({
162
+ id: `${DEBUG_PLUGIN}/client/storage`,
163
+ role: 'article',
164
+ filter: (data): data is any => data.subject === Devtools.Client.Storage,
165
+ component: () => <StoragePanel />,
166
+ }),
167
+ createSurface({
168
+ id: `${DEBUG_PLUGIN}/client/logs`,
169
+ role: 'article',
170
+ filter: (data): data is any => data.subject === Devtools.Client.Logs,
171
+ component: () => <LoggingPanel />,
172
+ }),
173
+ createSurface({
174
+ id: `${DEBUG_PLUGIN}/client/diagnostics`,
175
+ role: 'article',
176
+ filter: (data): data is any => data.subject === Devtools.Client.Diagnostics,
177
+ component: () => <DiagnosticsPanel />,
178
+ }),
179
+ createSurface({
180
+ id: `${DEBUG_PLUGIN}/client/tracing`,
181
+ role: 'article',
182
+ filter: (data): data is any => data.subject === Devtools.Client.Tracing,
183
+ component: () => <TracingPanel />,
184
+ }),
185
+ createSurface({
186
+ id: `${DEBUG_PLUGIN}/halo/identity`,
187
+ role: 'article',
188
+ filter: (data): data is any => data.subject === Devtools.Halo.Identity,
189
+ component: () => <IdentityPanel />,
190
+ }),
191
+ createSurface({
192
+ id: `${DEBUG_PLUGIN}/halo/devices`,
193
+ role: 'article',
194
+ filter: (data): data is any => data.subject === Devtools.Halo.Devices,
195
+ component: () => <DeviceListPanel />,
196
+ }),
197
+ createSurface({
198
+ id: `${DEBUG_PLUGIN}/halo/keyring`,
199
+ role: 'article',
200
+ filter: (data): data is any => data.subject === Devtools.Halo.Keyring,
201
+ component: () => <KeyringPanel />,
202
+ }),
203
+ createSurface({
204
+ id: `${DEBUG_PLUGIN}/halo/credentials`,
205
+ role: 'article',
206
+ filter: (data): data is any => data.subject === Devtools.Halo.Credentials,
207
+ component: () => <CredentialsPanel />,
208
+ }),
209
+ createSurface({
210
+ id: `${DEBUG_PLUGIN}/echo/spaces`,
211
+ role: 'article',
212
+ filter: (data): data is any => data.subject === Devtools.Echo.Spaces,
213
+ component: () => {
214
+ const { dispatchPromise: dispatch } = context.requestCapability(Capabilities.IntentDispatcher);
215
+ const handleSelect = useCallback(
216
+ () => dispatch(createIntent(LayoutAction.Open, { part: 'main', subject: [Devtools.Echo.Space] })),
217
+ [dispatch],
218
+ );
219
+ return <SpaceListPanel onSelect={handleSelect} />;
220
+ },
221
+ }),
222
+ createSurface({
223
+ id: `${DEBUG_PLUGIN}/echo/space`,
224
+ role: 'article',
225
+ filter: (data): data is any => data.subject === Devtools.Echo.Space,
226
+ component: () => {
227
+ const { dispatchPromise: dispatch } = context.requestCapability(Capabilities.IntentDispatcher);
228
+ const handleSelect = useCallback(
229
+ () => dispatch(createIntent(LayoutAction.Open, { part: 'main', subject: [Devtools.Echo.Feeds] })),
230
+ [dispatch],
231
+ );
232
+ return <SpaceInfoPanel onSelectFeed={handleSelect} onSelectPipeline={handleSelect} />;
233
+ },
234
+ }),
235
+ createSurface({
236
+ id: `${DEBUG_PLUGIN}/echo/feeds`,
237
+ role: 'article',
238
+ filter: (data): data is any => data.subject === Devtools.Echo.Feeds,
239
+ component: () => <FeedsPanel />,
240
+ }),
241
+ createSurface({
242
+ id: `${DEBUG_PLUGIN}/echo/objects`,
243
+ role: 'article',
244
+ filter: (data): data is any => data.subject === Devtools.Echo.Objects,
245
+ component: () => <ObjectsPanel />,
246
+ }),
247
+ createSurface({
248
+ id: `${DEBUG_PLUGIN}/echo/automerge`,
249
+ role: 'article',
250
+ filter: (data): data is any => data.subject === Devtools.Echo.Automerge,
251
+ component: () => <AutomergePanel />,
252
+ }),
253
+ createSurface({
254
+ id: `${DEBUG_PLUGIN}/echo/members`,
255
+ role: 'article',
256
+ filter: (data): data is any => data.subject === Devtools.Echo.Members,
257
+ component: () => <MembersPanel />,
258
+ }),
259
+ createSurface({
260
+ id: `${DEBUG_PLUGIN}/echo/metadata`,
261
+ role: 'article',
262
+ filter: (data): data is any => data.subject === Devtools.Echo.Metadata,
263
+ component: () => <MetadataPanel />,
264
+ }),
265
+ createSurface({
266
+ id: `${DEBUG_PLUGIN}/mesh/signal`,
267
+ role: 'article',
268
+ filter: (data): data is any => data.subject === Devtools.Mesh.Signal,
269
+ component: () => <SignalPanel />,
270
+ }),
271
+ createSurface({
272
+ id: `${DEBUG_PLUGIN}/mesh/swarm`,
273
+ role: 'article',
274
+ filter: (data): data is any => data.subject === Devtools.Mesh.Swarm,
275
+ component: () => <SwarmPanel />,
276
+ }),
277
+ createSurface({
278
+ id: `${DEBUG_PLUGIN}/mesh/network`,
279
+ role: 'article',
280
+ filter: (data): data is any => data.subject === Devtools.Mesh.Network,
281
+ component: () => <NetworkPanel />,
282
+ }),
283
+ createSurface({
284
+ id: `${DEBUG_PLUGIN}/agent/dashboard`,
285
+ role: 'article',
286
+ filter: (data): data is any => data.subject === Devtools.Agent.Dashboard,
287
+ component: () => <DashboardPanel />,
288
+ }),
289
+ createSurface({
290
+ id: `${DEBUG_PLUGIN}/agent/search`,
291
+ role: 'article',
292
+ filter: (data): data is any => data.subject === Devtools.Agent.Search,
293
+ component: () => <SearchPanel />,
294
+ }),
295
+ createSurface({
296
+ id: `${DEBUG_PLUGIN}/edge/dashboard`,
297
+ role: 'article',
298
+ filter: (data): data is any => data.subject === Devtools.Edge.Dashboard,
299
+ component: () => <EdgeDashboardPanel />,
300
+ }),
301
+ createSurface({
302
+ id: `${DEBUG_PLUGIN}/edge/workflows`,
303
+ role: 'article',
304
+ filter: (data): data is any => data.subject === Devtools.Edge.Workflows,
305
+ component: () => <WorkflowPanel />,
306
+ }),
130
307
  ]);
@@ -11,7 +11,6 @@ import { type DebugSettingsProps, DebugSettingsSchema } from '../types';
11
11
  export default () => {
12
12
  const settings = create<DebugSettingsProps>({
13
13
  debug: true,
14
- devtools: true,
15
14
  });
16
15
 
17
16
  return contributes(Capabilities.Settings, { schema: DebugSettingsSchema, prefix: DEBUG_PLUGIN, value: settings });
@@ -5,6 +5,7 @@
5
5
  import React from 'react';
6
6
 
7
7
  import { type ReactiveEchoObject } from '@dxos/client/echo';
8
+ import { Clipboard, Input } from '@dxos/react-ui';
8
9
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
9
10
 
10
11
  export type DebugObjectPanelProps = {
@@ -13,11 +14,22 @@ export type DebugObjectPanelProps = {
13
14
 
14
15
  // TODO(burdon): Get schema and traverse references.
15
16
  export const DebugObjectPanel = ({ object }: DebugObjectPanelProps) => {
17
+ const dxn = `dxn:echo:@:${object.id}`;
16
18
  return (
17
- <div className='flex flex-col'>
18
- <SyntaxHighlighter classNames='flex text-xs' language='json'>
19
- {JSON.stringify(object, null, 2)}
20
- </SyntaxHighlighter>
21
- </div>
19
+ <Clipboard.Provider>
20
+ <div className='flex flex-col'>
21
+ <Input.Root>
22
+ <div role='none' className='flex flex-col gap-1'>
23
+ <div role='none' className='flex gap-1'>
24
+ <Input.TextInput disabled value={dxn} />
25
+ <Clipboard.IconButton value={dxn} />
26
+ </div>
27
+ </div>
28
+ </Input.Root>
29
+ <SyntaxHighlighter classNames='flex text-xs' language='json'>
30
+ {JSON.stringify(object, null, 2)}
31
+ </SyntaxHighlighter>
32
+ </div>
33
+ </Clipboard.Provider>
22
34
  );
23
35
  };
@@ -81,9 +81,6 @@ export const DebugSettings = ({ settings }: { settings: DebugSettingsProps }) =>
81
81
  <DeprecatedFormInput label={t('settings show debug panel')}>
82
82
  <Input.Switch checked={settings.debug} onCheckedChange={(checked) => (settings.debug = !!checked)} />
83
83
  </DeprecatedFormInput>
84
- <DeprecatedFormInput label={t('settings show devtools panel')}>
85
- <Input.Switch checked={settings.devtools} onCheckedChange={(checked) => (settings.devtools = !!checked)} />
86
- </DeprecatedFormInput>
87
84
  <DeprecatedFormInput label={t('settings wireframe')}>
88
85
  <Input.Switch checked={settings.wireframe} onCheckedChange={(checked) => (settings.wireframe = !!checked)} />
89
86
  </DeprecatedFormInput>
@@ -3,7 +3,9 @@
3
3
  //
4
4
 
5
5
  import { addressToA1Notation } from '@dxos/compute';
6
- import { type BaseObject, type TypedObject } from '@dxos/echo-schema';
6
+ import { ComputeGraph, ComputeGraphModel, DEFAULT_OUTPUT, NODE_INPUT, NODE_OUTPUT } from '@dxos/conductor';
7
+ import { ObjectId, type BaseObject, type TypedObject } from '@dxos/echo-schema';
8
+ import { DXN } from '@dxos/keys';
7
9
  import { create, makeRef, type ReactiveObject } from '@dxos/live-object';
8
10
  import { DocumentType } from '@dxos/plugin-markdown/types';
9
11
  import { createSheet } from '@dxos/plugin-sheet/types';
@@ -37,15 +39,13 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
37
39
  DocumentType.typename,
38
40
  async (space, n, cb) => {
39
41
  const objects = range(n).map(() => {
40
- const obj = space.db.add(
42
+ return space.db.add(
41
43
  create(DocumentType, {
42
44
  name: faker.commerce.productName(),
43
45
  content: makeRef(create(TextType, { content: faker.lorem.sentences(5) })),
44
46
  threads: [],
45
47
  }),
46
48
  );
47
-
48
- return obj;
49
49
  });
50
50
 
51
51
  cb?.(objects);
@@ -109,6 +109,33 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
109
109
  return objects;
110
110
  },
111
111
  ],
112
+ [
113
+ ComputeGraph.typename,
114
+ async (space, n, cb) => {
115
+ const objects = range(n, () => {
116
+ const model = ComputeGraphModel.create();
117
+ model.builder
118
+ .createNode({ id: 'gpt-INPUT', type: NODE_INPUT })
119
+ .createNode({ id: 'gpt-GPT', type: 'gpt' })
120
+ .createNode({
121
+ id: 'gpt-QUEUE_ID',
122
+ type: 'constant',
123
+ value: new DXN(DXN.kind.QUEUE, ['data', space.id, ObjectId.random()]).toString(),
124
+ })
125
+ .createNode({ id: 'gpt-APPEND', type: 'append' })
126
+ .createNode({ id: 'gpt-OUTPUT', type: NODE_OUTPUT })
127
+ .createEdge({ node: 'gpt-INPUT', property: 'prompt' }, { node: 'gpt-GPT', property: 'prompt' })
128
+ .createEdge({ node: 'gpt-GPT', property: 'text' }, { node: 'gpt-OUTPUT', property: 'text' })
129
+ .createEdge({ node: 'gpt-QUEUE_ID', property: DEFAULT_OUTPUT }, { node: 'gpt-APPEND', property: 'id' })
130
+ .createEdge({ node: 'gpt-GPT', property: 'messages' }, { node: 'gpt-APPEND', property: 'items' })
131
+ .createEdge({ node: 'gpt-QUEUE_ID', property: DEFAULT_OUTPUT }, { node: 'gpt-OUTPUT', property: 'queue' });
132
+
133
+ return space.db.add(model.root);
134
+ });
135
+ cb?.(objects);
136
+ return objects;
137
+ },
138
+ ],
112
139
  ]);
113
140
 
114
141
  export const createGenerator = <T extends BaseObject>(type: TypedObject<T>): ObjectGenerator<T> => {
@@ -4,19 +4,26 @@
4
4
 
5
5
  import React, { useCallback, useMemo, useState } from 'react';
6
6
 
7
- import { type ReactiveObject } from '@dxos/live-object';
7
+ import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
8
+ import { ComputeGraph } from '@dxos/conductor';
9
+ import { toEffectSchema } from '@dxos/echo-schema';
10
+ import { create, type ReactiveObject } from '@dxos/live-object';
11
+ import { log } from '@dxos/log';
8
12
  import { DocumentType } from '@dxos/plugin-markdown/types';
9
13
  import { SheetType } from '@dxos/plugin-sheet/types';
10
14
  import { DiagramType } from '@dxos/plugin-sketch/types';
15
+ import { SpaceAction } from '@dxos/plugin-space/types';
11
16
  import { useClient } from '@dxos/react-client';
12
17
  import { getTypename, type Space } from '@dxos/react-client/echo';
13
18
  import { IconButton, Input, Toolbar, useAsyncEffect } from '@dxos/react-ui';
14
19
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
20
+ import { initializeTable, TableType } from '@dxos/react-ui-table';
15
21
  import { Testing } from '@dxos/schema/testing';
16
22
  import { jsonKeyReplacer, sortKeys } from '@dxos/util';
17
23
 
18
24
  import { type ObjectGenerator, createGenerator, staticGenerators } from './ObjectGenerator';
19
25
  import { SchemaTable } from './SchemaTable';
26
+ import { presets } from './presets';
20
27
 
21
28
  export type SpaceGeneratorProps = {
22
29
  space: Space;
@@ -24,20 +31,27 @@ export type SpaceGeneratorProps = {
24
31
  };
25
32
 
26
33
  export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps) => {
34
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
27
35
  const client = useClient();
28
- const staticTypes = [DocumentType, DiagramType, SheetType]; // TODO(burdon): Make extensible.
29
- const mutableTypes = [Testing.OrgType, Testing.ProjectType, Testing.ContactType];
36
+ const staticTypes = [DocumentType, DiagramType, SheetType, ComputeGraph]; // TODO(burdon): Make extensible.
37
+ const mutableTypes = [
38
+ Testing.OrgType,
39
+ Testing.ProjectType,
40
+ Testing.ContactType,
41
+ Testing.EmailType,
42
+ Testing.MessageType,
43
+ ];
30
44
  const [count, setCount] = useState(1);
31
45
  const [info, setInfo] = useState<any>({});
32
46
 
33
47
  // Create type generators.
34
48
  const typeMap = useMemo(() => {
35
- client.addTypes(staticTypes);
49
+ client.addTypes([...staticTypes, ...presets.schemas]);
36
50
  const mutableGenerators = new Map<string, ObjectGenerator<any>>(
37
- mutableTypes.map((type) => [type.typename, createGenerator(type)]),
51
+ mutableTypes.map((type) => [type.typename, createGenerator(type as any)]),
38
52
  );
39
53
 
40
- return new Map([...staticGenerators, ...mutableGenerators]);
54
+ return new Map([...staticGenerators, ...presets.items, ...mutableGenerators]);
41
55
  }, [client, mutableTypes]);
42
56
 
43
57
  // Query space to get info.
@@ -82,10 +96,64 @@ export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps)
82
96
  [typeMap, count],
83
97
  );
84
98
 
99
+ // TODO(wittjosiah): Remove. Replace with proper echo import.
100
+ const handleLoadTables = useCallback(async () => {
101
+ const input = document.createElement('input');
102
+ input.type = 'file';
103
+ input.accept = '.json';
104
+
105
+ input.onchange = async (e) => {
106
+ const file = (e.target as HTMLInputElement).files?.[0];
107
+ if (!file) {
108
+ return;
109
+ }
110
+
111
+ try {
112
+ const content = await file.text();
113
+ const data = JSON.parse(content);
114
+ const schemas = await space.db.schemaRegistry.register(data.schemas.map(toEffectSchema));
115
+ // TODO(wittjosiah): If the schema is already registered this should skip.
116
+ await Promise.all(
117
+ schemas.map(async (schema) => {
118
+ const parts = schema.typename.split('/');
119
+ const name = parts[parts.length - 1];
120
+ const table = create(TableType, { name, threads: [] });
121
+ await initializeTable({ space, table, initialSchema: schema.typename });
122
+ await dispatch(createIntent(SpaceAction.AddObject, { target: space, object: table }));
123
+ return table;
124
+ }),
125
+ );
126
+ // TODO(wittjosiah): This should query the space for schemas.
127
+ await Promise.all(
128
+ data.objects.map(async ({ id, '@type': typename, ...fields }: any) => {
129
+ const schema = schemas.find((s) => `dxn:type:${s.typename}:${s.version}` === typename);
130
+ if (!schema) {
131
+ log.warn('Missing schema for object', { id, typename });
132
+ return;
133
+ }
134
+ const object = create(schema, fields);
135
+ space.db.add(object);
136
+ return object;
137
+ }),
138
+ );
139
+ } catch (err) {
140
+ log.catch(err);
141
+ }
142
+ };
143
+
144
+ input.click();
145
+ }, []);
146
+
85
147
  return (
86
148
  <div role='none' className='flex flex-col divide-y divide-separator'>
87
149
  <Toolbar.Root classNames='p-1'>
88
150
  <IconButton icon='ph--arrow-clockwise--regular' iconOnly label='Refresh' onClick={updateInfo} />
151
+ <IconButton
152
+ icon='ph--file-arrow-up--regular'
153
+ iconOnly
154
+ label='Load tables from JSON'
155
+ onClick={handleLoadTables}
156
+ />
89
157
  <Toolbar.Separator variant='gap' />
90
158
  <div className='flex'>
91
159
  <Input.Root>
@@ -104,6 +172,7 @@ export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps)
104
172
 
105
173
  <SchemaTable types={staticTypes} objects={info.objects} label='Static Types' onClick={handleCreateData} />
106
174
  <SchemaTable types={mutableTypes} objects={info.objects} label='Mutable Types' onClick={handleCreateData} />
175
+ <SchemaTable types={presets.types} objects={info.objects} label='Presets' onClick={handleCreateData} />
107
176
 
108
177
  <SyntaxHighlighter classNames='flex text-xs' language='json'>
109
178
  {JSON.stringify({ space, ...info }, jsonKeyReplacer({ truncate: true }), 2)}