@dxos/plugin-debug 0.8.3 → 0.8.4-main.1c7ec43d41
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 +19 -123
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +81 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/types/src/DebugPlugin.d.ts +4 -1
- package/dist/types/src/DebugPlugin.d.ts.map +1 -1
- package/dist/types/src/DebugPlugin.node.d.ts +5 -0
- package/dist/types/src/DebugPlugin.node.d.ts.map +1 -0
- package/dist/types/src/DebugPlugin.test.d.ts +2 -0
- package/dist/types/src/DebugPlugin.test.d.ts.map +1 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts +4 -2
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +8 -5
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-context.d.ts +4 -2
- package/dist/types/src/capabilities/react-context.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +7 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/settings.d.ts +5 -2
- package/dist/types/src/capabilities/settings.d.ts.map +1 -1
- package/dist/types/src/components/DebugSettings/DebugSettings.d.ts +11 -0
- package/dist/types/src/components/DebugSettings/DebugSettings.d.ts.map +1 -0
- package/dist/types/src/components/DebugSettings/DebugSettings.stories.d.ts +99 -0
- package/dist/types/src/components/DebugSettings/DebugSettings.stories.d.ts.map +1 -0
- package/dist/types/src/components/DebugSettings/index.d.ts +2 -0
- package/dist/types/src/components/DebugSettings/index.d.ts.map +1 -0
- package/dist/types/src/components/SchemaTable/SchemaTable.d.ts.map +1 -0
- package/dist/types/src/components/SchemaTable/index.d.ts +2 -0
- package/dist/types/src/components/SchemaTable/index.d.ts.map +1 -0
- package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts +6 -4
- package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/draw-util.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/index.d.ts +2 -2
- package/dist/types/src/components/SpaceGenerator/index.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/presets.d.ts +5 -8
- package/dist/types/src/components/SpaceGenerator/presets.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +4 -9
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/DebugGraph/DebugGraph.d.ts +8 -0
- package/dist/types/src/containers/DebugGraph/DebugGraph.d.ts.map +1 -0
- package/dist/types/src/containers/DebugGraph/index.d.ts +2 -0
- package/dist/types/src/containers/DebugGraph/index.d.ts.map +1 -0
- package/dist/types/src/containers/DebugObjectPanel/DebugObjectPanel.d.ts +6 -0
- package/dist/types/src/containers/DebugObjectPanel/DebugObjectPanel.d.ts.map +1 -0
- package/dist/types/src/containers/DebugObjectPanel/index.d.ts +2 -0
- package/dist/types/src/containers/DebugObjectPanel/index.d.ts.map +1 -0
- package/dist/types/src/containers/DebugSpaceObjectsPanel/DebugSpaceObjectsPanel.d.ts +5 -0
- package/dist/types/src/containers/DebugSpaceObjectsPanel/DebugSpaceObjectsPanel.d.ts.map +1 -0
- package/dist/types/src/containers/DebugSpaceObjectsPanel/index.d.ts +2 -0
- package/dist/types/src/containers/DebugSpaceObjectsPanel/index.d.ts.map +1 -0
- package/dist/types/src/containers/DebugStatus/DebugStatus.d.ts.map +1 -0
- package/dist/types/src/containers/DebugStatus/index.d.ts +2 -0
- package/dist/types/src/containers/DebugStatus/index.d.ts.map +1 -0
- package/dist/types/src/{components → containers/DevtoolsOverviewContainer}/DevtoolsOverviewContainer.d.ts +0 -1
- package/dist/types/src/containers/DevtoolsOverviewContainer/DevtoolsOverviewContainer.d.ts.map +1 -0
- package/dist/types/src/containers/DevtoolsOverviewContainer/index.d.ts +2 -0
- package/dist/types/src/containers/DevtoolsOverviewContainer/index.d.ts.map +1 -0
- package/dist/types/src/containers/SpaceGenerator/SpaceGenerator.d.ts +11 -0
- package/dist/types/src/containers/SpaceGenerator/SpaceGenerator.d.ts.map +1 -0
- package/dist/types/src/containers/SpaceGenerator/index.d.ts +2 -0
- package/dist/types/src/containers/SpaceGenerator/index.d.ts.map +1 -0
- package/dist/types/src/{components → containers/Wireframe}/Wireframe.d.ts +2 -2
- package/dist/types/src/containers/Wireframe/Wireframe.d.ts.map +1 -0
- package/dist/types/src/containers/Wireframe/index.d.ts +2 -0
- package/dist/types/src/containers/Wireframe/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +9 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +83 -60
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Settings.d.ts +8 -0
- package/dist/types/src/types/Settings.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +69 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +99 -73
- package/src/DebugPlugin.node.ts +18 -0
- package/src/DebugPlugin.test.ts +29 -0
- package/src/DebugPlugin.tsx +30 -37
- package/src/capabilities/app-graph-builder.ts +361 -413
- package/src/capabilities/index.ts +5 -5
- package/src/capabilities/react-context.tsx +16 -7
- package/src/capabilities/react-surface.tsx +381 -339
- package/src/capabilities/settings.ts +24 -12
- package/src/components/DebugSettings/DebugSettings.stories.tsx +36 -0
- package/src/components/DebugSettings/DebugSettings.tsx +262 -0
- package/src/components/DebugSettings/index.ts +5 -0
- package/src/components/SchemaTable/index.ts +5 -0
- package/src/components/SpaceGenerator/ObjectGenerator.tsx +44 -46
- package/src/components/SpaceGenerator/draw-util.ts +13 -13
- package/src/components/SpaceGenerator/index.ts +2 -3
- package/src/components/SpaceGenerator/presets.ts +527 -263
- package/src/components/index.ts +4 -8
- package/src/containers/DebugGraph/DebugGraph.tsx +14 -0
- package/src/containers/DebugGraph/index.ts +5 -0
- package/src/containers/DebugObjectPanel/DebugObjectPanel.tsx +76 -0
- package/src/containers/DebugObjectPanel/index.ts +5 -0
- package/src/containers/DebugSpaceObjectsPanel/DebugSpaceObjectsPanel.tsx +47 -0
- package/src/containers/DebugSpaceObjectsPanel/index.ts +5 -0
- package/src/{components → containers/DebugStatus}/DebugStatus.tsx +43 -21
- package/src/containers/DebugStatus/index.ts +5 -0
- package/src/containers/DevtoolsOverviewContainer/DevtoolsOverviewContainer.tsx +25 -0
- package/src/containers/DevtoolsOverviewContainer/index.ts +5 -0
- package/src/containers/SpaceGenerator/SpaceGenerator.tsx +126 -0
- package/src/containers/SpaceGenerator/index.ts +5 -0
- package/src/{components → containers/Wireframe}/Wireframe.tsx +8 -12
- package/src/containers/Wireframe/index.ts +5 -0
- package/src/containers/index.ts +13 -0
- package/src/index.ts +7 -1
- package/src/meta.ts +8 -7
- package/src/translations.ts +80 -59
- package/src/types/Settings.ts +16 -0
- package/src/{types.ts → types/index.ts} +20 -11
- package/dist/lib/browser/DebugApp-WSEJPCKY.mjs +0 -225
- package/dist/lib/browser/DebugApp-WSEJPCKY.mjs.map +0 -7
- package/dist/lib/browser/DevtoolsOverviewContainer-IIIWO77Q.mjs +0 -25
- package/dist/lib/browser/DevtoolsOverviewContainer-IIIWO77Q.mjs.map +0 -7
- package/dist/lib/browser/SpaceGenerator-VB6IB2LL.mjs +0 -1238
- package/dist/lib/browser/SpaceGenerator-VB6IB2LL.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-6HHJMKVU.mjs +0 -597
- package/dist/lib/browser/app-graph-builder-6HHJMKVU.mjs.map +0 -7
- package/dist/lib/browser/chunk-47JOZTT2.mjs +0 -18
- package/dist/lib/browser/chunk-47JOZTT2.mjs.map +0 -7
- package/dist/lib/browser/chunk-KS3YBEL7.mjs +0 -68
- package/dist/lib/browser/chunk-KS3YBEL7.mjs.map +0 -7
- package/dist/lib/browser/react-context-ZQRD2WG2.mjs +0 -16
- package/dist/lib/browser/react-context-ZQRD2WG2.mjs.map +0 -7
- package/dist/lib/browser/react-surface-UI6OK73H.mjs +0 -768
- package/dist/lib/browser/react-surface-UI6OK73H.mjs.map +0 -7
- package/dist/lib/browser/settings-SXQWSIM4.mjs +0 -22
- package/dist/lib/browser/settings-SXQWSIM4.mjs.map +0 -7
- package/dist/types/src/components/Container.d.ts +0 -5
- package/dist/types/src/components/Container.d.ts.map +0 -1
- package/dist/types/src/components/DebugApp/DebugApp.d.ts +0 -6
- package/dist/types/src/components/DebugApp/DebugApp.d.ts.map +0 -1
- package/dist/types/src/components/DebugApp/Tree.d.ts +0 -18
- package/dist/types/src/components/DebugApp/Tree.d.ts.map +0 -1
- package/dist/types/src/components/DebugApp/index.d.ts +0 -3
- package/dist/types/src/components/DebugApp/index.d.ts.map +0 -1
- package/dist/types/src/components/DebugObjectPanel.d.ts +0 -7
- package/dist/types/src/components/DebugObjectPanel.d.ts.map +0 -1
- package/dist/types/src/components/DebugSettings.d.ts +0 -6
- package/dist/types/src/components/DebugSettings.d.ts.map +0 -1
- package/dist/types/src/components/DebugStatus.d.ts.map +0 -1
- package/dist/types/src/components/DevtoolsOverviewContainer.d.ts.map +0 -1
- package/dist/types/src/components/SpaceGenerator/SchemaTable.d.ts.map +0 -1
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts +0 -9
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts.map +0 -1
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts +0 -6
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts.map +0 -1
- package/dist/types/src/components/Wireframe.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -63
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/components/Container.tsx +0 -15
- package/src/components/DebugApp/DebugApp.tsx +0 -77
- package/src/components/DebugApp/Tree.tsx +0 -103
- package/src/components/DebugApp/index.ts +0 -7
- package/src/components/DebugObjectPanel.tsx +0 -35
- package/src/components/DebugSettings.tsx +0 -151
- package/src/components/DevtoolsOverviewContainer.tsx +0 -20
- package/src/components/SpaceGenerator/SpaceGenerator.stories.tsx +0 -52
- package/src/components/SpaceGenerator/SpaceGenerator.tsx +0 -179
- /package/dist/types/src/components/{SpaceGenerator → SchemaTable}/SchemaTable.d.ts +0 -0
- /package/dist/types/src/{components → containers/DebugStatus}/DebugStatus.d.ts +0 -0
- /package/src/components/{SpaceGenerator → SchemaTable}/SchemaTable.tsx +0 -0
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useEffect, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { Capabilities, useCapabilities } from '@dxos/app-framework';
|
|
8
|
-
import { type ConfigProto, defs, SaveConfig, Storage } from '@dxos/config';
|
|
9
|
-
import { log } from '@dxos/log';
|
|
10
|
-
import { useClient } from '@dxos/react-client';
|
|
11
|
-
import { useTranslation, Button, Toast, Input, useFileDownload, Select, Icon } from '@dxos/react-ui';
|
|
12
|
-
import { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';
|
|
13
|
-
import { setDeep } from '@dxos/util';
|
|
14
|
-
|
|
15
|
-
import { DEBUG_PLUGIN } from '../meta';
|
|
16
|
-
import { type DebugSettingsProps } from '../types';
|
|
17
|
-
|
|
18
|
-
type Toast = {
|
|
19
|
-
title: string;
|
|
20
|
-
description?: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const StorageAdapters = {
|
|
24
|
-
opfs: defs.Runtime.Client.Storage.StorageDriver.WEBFS,
|
|
25
|
-
idb: defs.Runtime.Client.Storage.StorageDriver.IDB,
|
|
26
|
-
} as const;
|
|
27
|
-
|
|
28
|
-
export const DebugSettings = ({ settings }: { settings: DebugSettingsProps }) => {
|
|
29
|
-
const { t } = useTranslation(DEBUG_PLUGIN);
|
|
30
|
-
const [toast, setToast] = useState<Toast>();
|
|
31
|
-
const client = useClient();
|
|
32
|
-
const download = useFileDownload();
|
|
33
|
-
// TODO(mykola): Get updates from other places that change Config.
|
|
34
|
-
const [storageConfig, setStorageConfig] = useState<ConfigProto>({});
|
|
35
|
-
const [upload] = useCapabilities(Capabilities.FileUploader);
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
void Storage().then((config) => setStorageConfig(config));
|
|
39
|
-
}, []);
|
|
40
|
-
|
|
41
|
-
const handleToast = (toast: Toast) => {
|
|
42
|
-
setToast(toast);
|
|
43
|
-
const t = setTimeout(() => setToast(undefined), 5_000);
|
|
44
|
-
return () => clearTimeout(t);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const handleDownload = async () => {
|
|
48
|
-
const data = await client.diagnostics();
|
|
49
|
-
const file = new Blob([JSON.stringify(data, undefined, 2)], { type: 'text/plain' });
|
|
50
|
-
const fileName = `composer-${new Date().toISOString().replace(/\W/g, '-')}.json`;
|
|
51
|
-
download(file, fileName);
|
|
52
|
-
|
|
53
|
-
if (upload) {
|
|
54
|
-
const info = await upload(new File([file], fileName), client.spaces.default);
|
|
55
|
-
if (!info) {
|
|
56
|
-
log.error('diagnostics failed to upload to IPFS');
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
handleToast({ title: t('settings uploaded'), description: t('settings uploaded to clipboard') });
|
|
60
|
-
|
|
61
|
-
// TODO(nf): move to IpfsPlugin?
|
|
62
|
-
const url = client.config.values.runtime!.services!.ipfs!.gateway + '/' + info.cid;
|
|
63
|
-
void navigator.clipboard.writeText(url);
|
|
64
|
-
handleToast({ title: t('settings uploaded'), description: t('settings uploaded to clipboard') });
|
|
65
|
-
log.info('diagnostics', { url });
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const handleRepair = async () => {
|
|
70
|
-
try {
|
|
71
|
-
const info = await client.repair();
|
|
72
|
-
setStorageConfig(await Storage());
|
|
73
|
-
handleToast({ title: t('settings repair success'), description: JSON.stringify(info, undefined, 2) });
|
|
74
|
-
} catch (err: any) {
|
|
75
|
-
handleToast({ title: t('settings repair failed'), description: err.message });
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<DeprecatedFormContainer>
|
|
81
|
-
<DeprecatedFormInput label={t('settings wireframe')}>
|
|
82
|
-
<Input.Switch checked={settings.wireframe} onCheckedChange={(checked) => (settings.wireframe = !!checked)} />
|
|
83
|
-
</DeprecatedFormInput>
|
|
84
|
-
<DeprecatedFormInput label={t('settings download diagnostics')}>
|
|
85
|
-
<Button onClick={handleDownload}>
|
|
86
|
-
<Icon icon='ph--download-simple--regular' size={5} />
|
|
87
|
-
</Button>
|
|
88
|
-
</DeprecatedFormInput>
|
|
89
|
-
<DeprecatedFormInput label={t('settings repair')}>
|
|
90
|
-
<Button onClick={handleRepair}>
|
|
91
|
-
<Icon icon='ph--first-aid-kit--regular' size={5} />
|
|
92
|
-
</Button>
|
|
93
|
-
</DeprecatedFormInput>
|
|
94
|
-
|
|
95
|
-
{/* TODO(burdon): Move to layout? */}
|
|
96
|
-
{toast && (
|
|
97
|
-
<Toast.Root>
|
|
98
|
-
<Toast.Body>
|
|
99
|
-
<Toast.Title>
|
|
100
|
-
<Icon icon='ph--gift--duotone' size={5} classNames='inline mr-1' />
|
|
101
|
-
<span>{toast.title}</span>
|
|
102
|
-
</Toast.Title>
|
|
103
|
-
{toast.description && <Toast.Description>{toast.description}</Toast.Description>}
|
|
104
|
-
</Toast.Body>
|
|
105
|
-
</Toast.Root>
|
|
106
|
-
)}
|
|
107
|
-
|
|
108
|
-
<DeprecatedFormInput label={t('settings choose storage adaptor')}>
|
|
109
|
-
<Select.Root
|
|
110
|
-
value={
|
|
111
|
-
Object.entries(StorageAdapters).find(
|
|
112
|
-
([name, value]) => value === storageConfig?.runtime?.client?.storage?.dataStore,
|
|
113
|
-
)?.[0]
|
|
114
|
-
}
|
|
115
|
-
onValueChange={(value) => {
|
|
116
|
-
if (confirm(t('settings storage adapter changed alert'))) {
|
|
117
|
-
updateConfig(
|
|
118
|
-
storageConfig,
|
|
119
|
-
setStorageConfig,
|
|
120
|
-
['runtime', 'client', 'storage', 'dataStore'],
|
|
121
|
-
StorageAdapters[value as keyof typeof StorageAdapters],
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
}}
|
|
125
|
-
>
|
|
126
|
-
<Select.TriggerButton placeholder={t('settings data store label')} />
|
|
127
|
-
<Select.Portal>
|
|
128
|
-
<Select.Content>
|
|
129
|
-
<Select.Viewport>
|
|
130
|
-
{Object.keys(StorageAdapters).map((key) => (
|
|
131
|
-
<Select.Option key={key} value={key}>
|
|
132
|
-
{t(`settings storage adaptor ${key} label`)}
|
|
133
|
-
</Select.Option>
|
|
134
|
-
))}
|
|
135
|
-
</Select.Viewport>
|
|
136
|
-
</Select.Content>
|
|
137
|
-
</Select.Portal>
|
|
138
|
-
</Select.Root>
|
|
139
|
-
</DeprecatedFormInput>
|
|
140
|
-
</DeprecatedFormContainer>
|
|
141
|
-
);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const updateConfig = (config: ConfigProto, setConfig: (newConfig: ConfigProto) => void, path: string[], value: any) => {
|
|
145
|
-
const storageConfigCopy = JSON.parse(JSON.stringify(config ?? {}));
|
|
146
|
-
setDeep(storageConfigCopy, path, value);
|
|
147
|
-
setConfig(storageConfigCopy);
|
|
148
|
-
queueMicrotask(async () => {
|
|
149
|
-
await SaveConfig(storageConfigCopy);
|
|
150
|
-
});
|
|
151
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React from 'react';
|
|
6
|
-
|
|
7
|
-
import { Surface } from '@dxos/app-framework';
|
|
8
|
-
import { StatsPanel, useStats } from '@dxos/devtools';
|
|
9
|
-
|
|
10
|
-
export const DevtoolsOverviewContainer = () => {
|
|
11
|
-
const [stats, refreshStats] = useStats();
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
<StatsPanel stats={stats} onRefresh={refreshStats}>
|
|
15
|
-
<Surface role='devtools-overview' />
|
|
16
|
-
</StatsPanel>
|
|
17
|
-
);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default DevtoolsOverviewContainer;
|
|
@@ -1,52 +0,0 @@
|
|
|
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 { IntentPlugin } from '@dxos/app-framework';
|
|
11
|
-
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
12
|
-
import { ClientPlugin } from '@dxos/plugin-client';
|
|
13
|
-
import { useSpaces } from '@dxos/react-client/echo';
|
|
14
|
-
import { render, withLayout, withTheme } from '@dxos/storybook-utils';
|
|
15
|
-
|
|
16
|
-
import { SpaceGenerator } from './SpaceGenerator';
|
|
17
|
-
|
|
18
|
-
const DefaultStory = () => {
|
|
19
|
-
const [space] = useSpaces();
|
|
20
|
-
if (!space) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return <SpaceGenerator space={space} />;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const meta: Meta = {
|
|
28
|
-
title: 'plugins/plugin-debug/SpaceGenerator',
|
|
29
|
-
component: SpaceGenerator,
|
|
30
|
-
render: render(DefaultStory),
|
|
31
|
-
decorators: [
|
|
32
|
-
withPluginManager({
|
|
33
|
-
plugins: [
|
|
34
|
-
ClientPlugin({
|
|
35
|
-
onClientInitialized: async (_, client) => {
|
|
36
|
-
await client.halo.createIdentity();
|
|
37
|
-
},
|
|
38
|
-
}),
|
|
39
|
-
IntentPlugin(),
|
|
40
|
-
],
|
|
41
|
-
}),
|
|
42
|
-
withLayout(),
|
|
43
|
-
withTheme,
|
|
44
|
-
],
|
|
45
|
-
parameters: {
|
|
46
|
-
layout: 'fullscreen',
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export default meta;
|
|
51
|
-
|
|
52
|
-
export const Default = {};
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useCallback, useMemo, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
|
|
8
|
-
import { ComputeGraph } from '@dxos/conductor';
|
|
9
|
-
import { Filter, Obj, Type } from '@dxos/echo';
|
|
10
|
-
import { log } from '@dxos/log';
|
|
11
|
-
import { DocumentType } from '@dxos/plugin-markdown/types';
|
|
12
|
-
import { SheetType } from '@dxos/plugin-sheet/types';
|
|
13
|
-
import { DiagramType } from '@dxos/plugin-sketch/types';
|
|
14
|
-
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
15
|
-
import { useClient } from '@dxos/react-client';
|
|
16
|
-
import { getTypename, type Space } from '@dxos/react-client/echo';
|
|
17
|
-
import { IconButton, Input, Toolbar, useAsyncEffect } from '@dxos/react-ui';
|
|
18
|
-
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
19
|
-
import { initializeTable, TableType } from '@dxos/react-ui-table';
|
|
20
|
-
import { DataType } from '@dxos/schema';
|
|
21
|
-
import { jsonKeyReplacer, sortKeys } from '@dxos/util';
|
|
22
|
-
|
|
23
|
-
import { createGenerator, staticGenerators, type ObjectGenerator } from './ObjectGenerator';
|
|
24
|
-
import { SchemaTable } from './SchemaTable';
|
|
25
|
-
import { generator } from './presets';
|
|
26
|
-
|
|
27
|
-
export type SpaceGeneratorProps = {
|
|
28
|
-
space: Space;
|
|
29
|
-
onCreateObjects?: (objects: Obj.Any[]) => void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps) => {
|
|
33
|
-
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
34
|
-
const client = useClient();
|
|
35
|
-
const staticTypes = [DocumentType, DiagramType, SheetType, ComputeGraph]; // TODO(burdon): Make extensible.
|
|
36
|
-
const mutableTypes = [DataType.Organization, DataType.Project, DataType.Person, DataType.Message];
|
|
37
|
-
const [count, setCount] = useState(1);
|
|
38
|
-
const [info, setInfo] = useState<any>({});
|
|
39
|
-
const presets = useMemo(() => generator(), []);
|
|
40
|
-
|
|
41
|
-
// Create type generators.
|
|
42
|
-
const typeMap = useMemo(() => {
|
|
43
|
-
client.addTypes([...staticTypes, ...presets.schemas]);
|
|
44
|
-
const mutableGenerators = new Map<string, ObjectGenerator<any>>(
|
|
45
|
-
mutableTypes.map((type) => [type.typename, createGenerator(type as any)]),
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
return new Map([...staticGenerators, ...presets.items, ...mutableGenerators]);
|
|
49
|
-
}, [client, mutableTypes]);
|
|
50
|
-
|
|
51
|
-
// Query space to get info.
|
|
52
|
-
const updateInfo = async () => {
|
|
53
|
-
// Create schema map.
|
|
54
|
-
const echoSchema = await space.db.schemaRegistry.query().run();
|
|
55
|
-
const staticSchema = space.db.graph.schemaRegistry.schemas;
|
|
56
|
-
|
|
57
|
-
// Create object map.
|
|
58
|
-
const { objects } = await space.db.query(Filter.everything()).run();
|
|
59
|
-
const objectMap = sortKeys(
|
|
60
|
-
objects.reduce<Record<string, number>>((map, obj) => {
|
|
61
|
-
const type = getTypename(obj);
|
|
62
|
-
if (type) {
|
|
63
|
-
const count = map[type] ?? 0;
|
|
64
|
-
map[type] = count + 1;
|
|
65
|
-
}
|
|
66
|
-
return map;
|
|
67
|
-
}, {}),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
setInfo({
|
|
71
|
-
schema: {
|
|
72
|
-
static: staticSchema.length,
|
|
73
|
-
mutable: echoSchema.length,
|
|
74
|
-
},
|
|
75
|
-
objects: objectMap,
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
useAsyncEffect(updateInfo, [space]);
|
|
80
|
-
|
|
81
|
-
const handleCreateData = useCallback(
|
|
82
|
-
async (typename: string) => {
|
|
83
|
-
const constructor = typeMap.get(typename);
|
|
84
|
-
if (constructor) {
|
|
85
|
-
// TODO(burdon): Input to specify number of objects.
|
|
86
|
-
await constructor(space, count, onCreateObjects);
|
|
87
|
-
await updateInfo();
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
[typeMap, count],
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
// TODO(wittjosiah): Remove. Replace with proper echo import.
|
|
94
|
-
const handleLoadTables = useCallback(async () => {
|
|
95
|
-
const input = document.createElement('input');
|
|
96
|
-
input.type = 'file';
|
|
97
|
-
input.accept = '.json';
|
|
98
|
-
|
|
99
|
-
input.onchange = async (e) => {
|
|
100
|
-
const file = (e.target as HTMLInputElement).files?.[0];
|
|
101
|
-
if (!file) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
const content = await file.text();
|
|
107
|
-
const data = JSON.parse(content);
|
|
108
|
-
const schemas = await space.db.schemaRegistry.register(data.schemas.map(Type.toEffectSchema));
|
|
109
|
-
// TODO(wittjosiah): If the schema is already registered this should skip.
|
|
110
|
-
await Promise.all(
|
|
111
|
-
schemas.map(async (schema) => {
|
|
112
|
-
const parts = schema.typename.split('/');
|
|
113
|
-
const name = parts[parts.length - 1];
|
|
114
|
-
const table = Obj.make(TableType, { name, threads: [] });
|
|
115
|
-
await initializeTable({ client, space, table, typename: schema.typename });
|
|
116
|
-
await dispatch(createIntent(SpaceAction.AddObject, { target: space, object: table }));
|
|
117
|
-
return table;
|
|
118
|
-
}),
|
|
119
|
-
);
|
|
120
|
-
// TODO(wittjosiah): This should query the space for schemas.
|
|
121
|
-
await Promise.all(
|
|
122
|
-
data.objects.map(async ({ id, '@type': typename, ...fields }: any) => {
|
|
123
|
-
const schema = schemas.find((s) => `dxn:type:${s.typename}:${s.version}` === typename);
|
|
124
|
-
if (!schema) {
|
|
125
|
-
log.warn('Missing schema for object', { id, typename });
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const object = Obj.make(schema, fields);
|
|
129
|
-
space.db.add(object);
|
|
130
|
-
return object;
|
|
131
|
-
}),
|
|
132
|
-
);
|
|
133
|
-
} catch (err) {
|
|
134
|
-
log.catch(err);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
input.click();
|
|
139
|
-
}, []);
|
|
140
|
-
|
|
141
|
-
return (
|
|
142
|
-
<div role='none' className='flex flex-col grow overflow-hidden'>
|
|
143
|
-
<Toolbar.Root classNames='border-be border-subduedSeparator'>
|
|
144
|
-
<IconButton icon='ph--arrow-clockwise--regular' iconOnly label='Refresh' onClick={updateInfo} />
|
|
145
|
-
<IconButton
|
|
146
|
-
icon='ph--file-arrow-up--regular'
|
|
147
|
-
iconOnly
|
|
148
|
-
label='Load tables from JSON'
|
|
149
|
-
onClick={handleLoadTables}
|
|
150
|
-
/>
|
|
151
|
-
<Toolbar.Separator variant='gap' />
|
|
152
|
-
<Input.Root>
|
|
153
|
-
<Input.TextInput
|
|
154
|
-
type='number'
|
|
155
|
-
min={1}
|
|
156
|
-
max={100}
|
|
157
|
-
placeholder={'Count'}
|
|
158
|
-
classNames='!w-[4rem] !text-right'
|
|
159
|
-
size={8}
|
|
160
|
-
value={count}
|
|
161
|
-
onChange={(ev) => setCount(parseInt(ev.target.value))}
|
|
162
|
-
/>
|
|
163
|
-
</Input.Root>
|
|
164
|
-
</Toolbar.Root>
|
|
165
|
-
|
|
166
|
-
<div className='flex flex-col overflow-y-auto divide-y divide-separator'>
|
|
167
|
-
<SchemaTable types={staticTypes} objects={info.objects} label='Static Types' onClick={handleCreateData} />
|
|
168
|
-
<SchemaTable types={mutableTypes} objects={info.objects} label='Mutable Types' onClick={handleCreateData} />
|
|
169
|
-
<SchemaTable types={presets.types} objects={info.objects} label='Presets' onClick={handleCreateData} />
|
|
170
|
-
|
|
171
|
-
<div>
|
|
172
|
-
<SyntaxHighlighter classNames='flex text-xs' language='json'>
|
|
173
|
-
{JSON.stringify({ space, ...info }, jsonKeyReplacer({ truncate: true }), 2)}
|
|
174
|
-
</SyntaxHighlighter>
|
|
175
|
-
</div>
|
|
176
|
-
</div>
|
|
177
|
-
</div>
|
|
178
|
-
);
|
|
179
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|