@dxos/plugin-preview 0.8.4-main.9be5663bfe → 0.8.4-main.abd8ff62ef
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 +5 -41
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +21 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +5 -41
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +23 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/PreviewPlugin.d.ts +1 -0
- package/dist/types/src/PreviewPlugin.d.ts.map +1 -1
- package/dist/types/src/PreviewPlugin.node.d.ts +4 -0
- package/dist/types/src/PreviewPlugin.node.d.ts.map +1 -0
- package/dist/types/src/PreviewPlugin.test.d.ts +2 -0
- package/dist/types/src/PreviewPlugin.test.d.ts.map +1 -0
- package/dist/types/src/capabilities/preview-popover.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/cards/ExpandoCard.d.ts +4 -0
- package/dist/types/src/cards/ExpandoCard.d.ts.map +1 -0
- package/dist/types/src/cards/FormCard.d.ts.map +1 -1
- package/dist/types/src/cards/JsonCard.d.ts.map +1 -1
- package/dist/types/src/cards/OrganizationCard.d.ts.map +1 -1
- package/dist/types/src/cards/PersonCard.d.ts.map +1 -1
- package/dist/types/src/cards/ProjectCard.d.ts.map +1 -1
- package/dist/types/src/cards/TaskCard.d.ts.map +1 -1
- package/dist/types/src/cards/index.d.ts +1 -0
- package/dist/types/src/cards/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/stories/Card.stories.d.ts +10 -8
- package/dist/types/src/stories/Card.stories.d.ts.map +1 -1
- package/dist/types/src/stories/testing.d.ts +2 -0
- package/dist/types/src/stories/testing.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +8 -9
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +47 -38
- package/src/PreviewPlugin.node.ts +16 -0
- package/src/PreviewPlugin.test.ts +25 -0
- package/src/PreviewPlugin.tsx +4 -3
- package/src/capabilities/preview-popover.ts +5 -2
- package/src/capabilities/react-surface.tsx +18 -16
- package/src/cards/ExpandoCard.tsx +76 -0
- package/src/cards/FormCard.tsx +1 -1
- package/src/cards/JsonCard.tsx +5 -2
- package/src/cards/index.ts +1 -0
- package/src/index.ts +6 -2
- package/src/stories/Card.stories.tsx +18 -4
- package/src/stories/testing.tsx +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-preview",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.abd8ff62ef",
|
|
4
4
|
"description": "Preview plugin",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -14,63 +14,72 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"imports": {
|
|
16
16
|
"#capabilities": "./src/capabilities/index.ts",
|
|
17
|
-
"#meta": "./src/meta.ts"
|
|
17
|
+
"#meta": "./src/meta.ts",
|
|
18
|
+
"#plugin": {
|
|
19
|
+
"browser": "./src/PreviewPlugin.tsx",
|
|
20
|
+
"node": "./src/PreviewPlugin.node.ts",
|
|
21
|
+
"default": "./src/PreviewPlugin.tsx"
|
|
22
|
+
},
|
|
23
|
+
"#translations": "./src/translations.ts"
|
|
18
24
|
},
|
|
19
25
|
"exports": {
|
|
20
26
|
".": {
|
|
21
27
|
"source": "./src/index.ts",
|
|
22
28
|
"types": "./dist/types/src/index.d.ts",
|
|
23
29
|
"browser": "./dist/lib/browser/index.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./translations": {
|
|
32
|
+
"source": "./src/translations.ts",
|
|
33
|
+
"types": "./dist/types/src/translations.d.ts",
|
|
34
|
+
"browser": "./dist/lib/browser/translations.mjs",
|
|
35
|
+
"node": "./dist/lib/node-esm/translations.mjs"
|
|
24
36
|
}
|
|
25
37
|
},
|
|
26
38
|
"types": "dist/types/src/index.d.ts",
|
|
27
|
-
"typesVersions": {
|
|
28
|
-
"*": {}
|
|
29
|
-
},
|
|
30
39
|
"files": [
|
|
31
40
|
"dist",
|
|
32
41
|
"src"
|
|
33
42
|
],
|
|
34
43
|
"dependencies": {
|
|
35
44
|
"@effect-atom/atom-react": "^0.5.0",
|
|
36
|
-
"@dxos/app-framework": "0.8.4-main.
|
|
37
|
-
"@dxos/app-
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/effect": "0.8.4-main.
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/lit-ui": "0.8.4-main.
|
|
45
|
-
"@dxos/operation": "0.8.4-main.
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/plugin-attention": "0.8.4-main.
|
|
48
|
-
"@dxos/plugin-
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/react-
|
|
51
|
-
"@dxos/react-ui
|
|
52
|
-
"@dxos/react-ui-
|
|
53
|
-
"@dxos/react-ui-
|
|
54
|
-
"@dxos/react-ui-
|
|
55
|
-
"@dxos/react-ui-
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
45
|
+
"@dxos/app-framework": "0.8.4-main.abd8ff62ef",
|
|
46
|
+
"@dxos/app-graph": "0.8.4-main.abd8ff62ef",
|
|
47
|
+
"@dxos/app-toolkit": "0.8.4-main.abd8ff62ef",
|
|
48
|
+
"@dxos/async": "0.8.4-main.abd8ff62ef",
|
|
49
|
+
"@dxos/echo": "0.8.4-main.abd8ff62ef",
|
|
50
|
+
"@dxos/effect": "0.8.4-main.abd8ff62ef",
|
|
51
|
+
"@dxos/keys": "0.8.4-main.abd8ff62ef",
|
|
52
|
+
"@dxos/client": "0.8.4-main.abd8ff62ef",
|
|
53
|
+
"@dxos/lit-ui": "0.8.4-main.abd8ff62ef",
|
|
54
|
+
"@dxos/operation": "0.8.4-main.abd8ff62ef",
|
|
55
|
+
"@dxos/log": "0.8.4-main.abd8ff62ef",
|
|
56
|
+
"@dxos/plugin-attention": "0.8.4-main.abd8ff62ef",
|
|
57
|
+
"@dxos/plugin-client": "0.8.4-main.abd8ff62ef",
|
|
58
|
+
"@dxos/plugin-deck": "0.8.4-main.abd8ff62ef",
|
|
59
|
+
"@dxos/react-client": "0.8.4-main.abd8ff62ef",
|
|
60
|
+
"@dxos/react-ui": "0.8.4-main.abd8ff62ef",
|
|
61
|
+
"@dxos/react-ui-editor": "0.8.4-main.abd8ff62ef",
|
|
62
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.abd8ff62ef",
|
|
63
|
+
"@dxos/react-ui-menu": "0.8.4-main.abd8ff62ef",
|
|
64
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.abd8ff62ef",
|
|
65
|
+
"@dxos/schema": "0.8.4-main.abd8ff62ef",
|
|
66
|
+
"@dxos/react-ui-table": "0.8.4-main.abd8ff62ef",
|
|
67
|
+
"@dxos/types": "0.8.4-main.abd8ff62ef",
|
|
68
|
+
"@dxos/util": "0.8.4-main.abd8ff62ef",
|
|
69
|
+
"@dxos/ui-theme": "0.8.4-main.abd8ff62ef",
|
|
70
|
+
"@dxos/ui-editor": "0.8.4-main.abd8ff62ef",
|
|
71
|
+
"@dxos/react-ui-form": "0.8.4-main.abd8ff62ef"
|
|
63
72
|
},
|
|
64
73
|
"devDependencies": {
|
|
65
74
|
"effect": "3.20.0",
|
|
66
75
|
"react": "~19.2.3",
|
|
67
76
|
"react-dom": "~19.2.3",
|
|
68
|
-
"vite": "^
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
77
|
+
"vite": "^8.0.10",
|
|
78
|
+
"@dxos/plugin-testing": "0.8.4-main.abd8ff62ef",
|
|
79
|
+
"@dxos/echo-db": "0.8.4-main.abd8ff62ef",
|
|
80
|
+
"@dxos/random": "0.8.4-main.abd8ff62ef",
|
|
81
|
+
"@dxos/react-ui-components": "0.8.4-main.abd8ff62ef",
|
|
82
|
+
"@dxos/storybook-utils": "0.8.4-main.abd8ff62ef"
|
|
74
83
|
},
|
|
75
84
|
"peerDependencies": {
|
|
76
85
|
"effect": "3.20.0",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { AppPlugin } from '@dxos/app-toolkit';
|
|
7
|
+
import { Organization, Person } from '@dxos/types';
|
|
8
|
+
|
|
9
|
+
import { meta } from '#meta';
|
|
10
|
+
|
|
11
|
+
export const PreviewPlugin = Plugin.define(meta).pipe(
|
|
12
|
+
AppPlugin.addSchemaModule({ schema: [Person.Person, Organization.Organization] }),
|
|
13
|
+
Plugin.make,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export default PreviewPlugin;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { ClientPlugin } from '@dxos/plugin-client';
|
|
8
|
+
import { createComposerTestApp } from '@dxos/plugin-testing/harness';
|
|
9
|
+
|
|
10
|
+
import { PreviewPlugin } from '#plugin';
|
|
11
|
+
|
|
12
|
+
import { meta } from './meta';
|
|
13
|
+
|
|
14
|
+
const moduleId = (name: string) => `${meta.id}.module.${name}`;
|
|
15
|
+
|
|
16
|
+
describe('PreviewPlugin', () => {
|
|
17
|
+
test('modules activate on the expected events', async ({ expect }) => {
|
|
18
|
+
await using harness = await createComposerTestApp({
|
|
19
|
+
plugins: [ClientPlugin({}), PreviewPlugin()],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// After autoStart: schema auto-cascades from ClientPlugin.
|
|
23
|
+
expect(harness.manager.getActive()).toContain(moduleId('schema'));
|
|
24
|
+
});
|
|
25
|
+
});
|
package/src/PreviewPlugin.tsx
CHANGED
|
@@ -8,11 +8,10 @@ import { Organization, Person } from '@dxos/types';
|
|
|
8
8
|
|
|
9
9
|
import { PreviewPopover, ReactSurface } from '#capabilities';
|
|
10
10
|
import { meta } from '#meta';
|
|
11
|
-
|
|
12
|
-
import { translations } from './translations';
|
|
11
|
+
import { translations } from '#translations';
|
|
13
12
|
|
|
14
13
|
export const PreviewPlugin = Plugin.define(meta).pipe(
|
|
15
|
-
AppPlugin.addSchemaModule({ schema: [Person.Person, Organization.Organization]
|
|
14
|
+
AppPlugin.addSchemaModule({ schema: [Person.Person, Organization.Organization] }),
|
|
16
15
|
AppPlugin.addSurfaceModule({ activate: ReactSurface }),
|
|
17
16
|
AppPlugin.addTranslationsModule({ translations }),
|
|
18
17
|
Plugin.addModule({
|
|
@@ -22,3 +21,5 @@ export const PreviewPlugin = Plugin.define(meta).pipe(
|
|
|
22
21
|
}),
|
|
23
22
|
Plugin.make,
|
|
24
23
|
);
|
|
24
|
+
|
|
25
|
+
export default PreviewPlugin;
|
|
@@ -49,9 +49,12 @@ export default Capability.makeModule(
|
|
|
49
49
|
const { invokePromise } = capabilities.get(Capabilities.OperationInvoker);
|
|
50
50
|
const client = capabilities.get(ClientCapabilities.Client);
|
|
51
51
|
const registry = capabilities.get(Capabilities.AtomRegistry);
|
|
52
|
+
// Layout is optional: in standalone harnesses (Storybook, tests) no plugin contributes
|
|
53
|
+
// `AppCapabilities.Layout`, and `getAll` returns an empty array. Reading `registry.get(undefined)`
|
|
54
|
+
// would crash inside Atom's identity check (`'~atom/Serializable' in undefined`). When layout
|
|
55
|
+
// isn't available, fall through to the personal-space default.
|
|
52
56
|
const [layoutAtom] = capabilities.getAll(AppCapabilities.Layout);
|
|
53
|
-
const
|
|
54
|
-
const spaceId = getSpaceIdFromPath(layout.workspace);
|
|
57
|
+
const spaceId = layoutAtom && getSpaceIdFromPath(registry.get(layoutAtom).workspace);
|
|
55
58
|
const space = (spaceId && client.spaces.get(spaceId)) ?? getPersonalSpace(client);
|
|
56
59
|
if (!space) {
|
|
57
60
|
return;
|
|
@@ -10,10 +10,10 @@ import { Surface } from '@dxos/app-framework/ui';
|
|
|
10
10
|
import { AppSurface } from '@dxos/app-toolkit/ui';
|
|
11
11
|
import { Obj } from '@dxos/echo';
|
|
12
12
|
import { Card } from '@dxos/react-ui';
|
|
13
|
-
import { type ProjectionModel } from '@dxos/schema';
|
|
13
|
+
import { Expando, type ProjectionModel } from '@dxos/schema';
|
|
14
14
|
import { Organization, Person, Pipeline, Task } from '@dxos/types';
|
|
15
15
|
|
|
16
|
-
import { FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
|
|
16
|
+
import { ExpandoCard, FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
|
|
17
17
|
|
|
18
18
|
export default Capability.makeModule(() =>
|
|
19
19
|
Effect.succeed(
|
|
@@ -25,50 +25,53 @@ export default Capability.makeModule(() =>
|
|
|
25
25
|
|
|
26
26
|
Surface.create<{ subject: Person.Person }>({
|
|
27
27
|
id: 'schema-popover--contact',
|
|
28
|
-
role: 'card--content',
|
|
29
28
|
position: 'hoist',
|
|
30
|
-
filter: AppSurface.
|
|
29
|
+
filter: AppSurface.object(AppSurface.Card, Person.Person),
|
|
31
30
|
component: ({ data, role }) => {
|
|
32
31
|
return (
|
|
33
32
|
<>
|
|
34
33
|
<PersonCard role={role} subject={data.subject} />
|
|
35
|
-
<Surface.Surface
|
|
34
|
+
<Surface.Surface type={AppSurface.Related} data={data} limit={1} />
|
|
36
35
|
</>
|
|
37
36
|
);
|
|
38
37
|
},
|
|
39
38
|
}),
|
|
40
39
|
Surface.create({
|
|
41
40
|
id: 'schema-popover--organization',
|
|
42
|
-
role: 'card--content',
|
|
43
41
|
position: 'hoist',
|
|
44
|
-
filter: AppSurface.
|
|
42
|
+
filter: AppSurface.object(AppSurface.Card, Organization.Organization),
|
|
45
43
|
component: ({ data, role }) => {
|
|
46
44
|
return (
|
|
47
45
|
<>
|
|
48
46
|
<OrganizationCard role={role} subject={data.subject} />
|
|
49
|
-
<Surface.Surface
|
|
47
|
+
<Surface.Surface type={AppSurface.Related} data={data} limit={1} />
|
|
50
48
|
</>
|
|
51
49
|
);
|
|
52
50
|
},
|
|
53
51
|
}),
|
|
54
52
|
Surface.create({
|
|
55
53
|
id: 'schema-popover--project',
|
|
56
|
-
role: 'card--content',
|
|
57
54
|
position: 'hoist',
|
|
58
|
-
filter: AppSurface.
|
|
55
|
+
filter: AppSurface.object(AppSurface.Card, Pipeline.Pipeline),
|
|
59
56
|
component: ({ data, role }) => {
|
|
60
57
|
return <ProjectCard role={role} subject={data.subject} />;
|
|
61
58
|
},
|
|
62
59
|
}),
|
|
63
60
|
Surface.create({
|
|
64
61
|
id: 'schema-popover--task',
|
|
65
|
-
role: 'card--content',
|
|
66
62
|
position: 'hoist',
|
|
67
|
-
filter: AppSurface.
|
|
63
|
+
filter: AppSurface.object(AppSurface.Card, Task.Task),
|
|
68
64
|
component: ({ data, role }) => {
|
|
69
65
|
return <TaskCard role={role} subject={data.subject} />;
|
|
70
66
|
},
|
|
71
67
|
}),
|
|
68
|
+
Surface.create<AppSurface.ObjectCardData<Expando.Expando>>({
|
|
69
|
+
id: 'schema-popover--expando',
|
|
70
|
+
filter: AppSurface.object(AppSurface.Card, Expando.Expando),
|
|
71
|
+
component: ({ data, role }) => {
|
|
72
|
+
return <ExpandoCard role={role} subject={data.subject} ignorePaths={data.ignorePaths} />;
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
72
75
|
|
|
73
76
|
//
|
|
74
77
|
// Fallback for any object.
|
|
@@ -96,15 +99,14 @@ export default Capability.makeModule(() =>
|
|
|
96
99
|
|
|
97
100
|
Surface.create({
|
|
98
101
|
id: 'section',
|
|
99
|
-
role: ['section'],
|
|
100
102
|
position: 'fallback',
|
|
101
|
-
filter: AppSurface.
|
|
103
|
+
filter: AppSurface.subject(AppSurface.Section, Obj.isObject),
|
|
102
104
|
component: ({ data }) => {
|
|
103
105
|
return (
|
|
104
106
|
<div role='none' className='flex w-full justify-center'>
|
|
105
|
-
<div role='none' className='
|
|
107
|
+
<div role='none' className='py-2 dx-card-min-width dx-card-max-width'>
|
|
106
108
|
<Card.Root>
|
|
107
|
-
<Surface.Surface
|
|
109
|
+
<Surface.Surface type={AppSurface.Card} data={data} limit={1} />
|
|
108
110
|
</Card.Root>
|
|
109
111
|
</div>
|
|
110
112
|
</div>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import React, { useCallback, useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
|
+
import { type JsonPath, splitJsonPath } from '@dxos/effect';
|
|
11
|
+
import { Card } from '@dxos/react-ui';
|
|
12
|
+
import { Form } from '@dxos/react-ui-form';
|
|
13
|
+
|
|
14
|
+
const schemaForValue = (value: unknown): Schema.Schema.AnyNoContext | undefined => {
|
|
15
|
+
switch (typeof value) {
|
|
16
|
+
case 'string':
|
|
17
|
+
return Schema.String;
|
|
18
|
+
case 'number':
|
|
19
|
+
return Schema.Number;
|
|
20
|
+
case 'boolean':
|
|
21
|
+
return Schema.Boolean;
|
|
22
|
+
default:
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Reserved keys: `id`, plus any `~`-prefixed key (ECHO uses `~`-prefixed
|
|
29
|
+
* string keys to brand entity instances and schemas — KindId,
|
|
30
|
+
* SchemaKindId, SnapshotKindId, etc. — and the `~` namespace is reserved
|
|
31
|
+
* for that purpose). They show up in `Object.keys` but aren't user data.
|
|
32
|
+
*/
|
|
33
|
+
const isInternalKey = (key: string) => key === 'id' || key.startsWith('~');
|
|
34
|
+
|
|
35
|
+
export const ExpandoCard = ({ subject, ignorePaths }: AppSurface.ObjectCardProps) => {
|
|
36
|
+
const schema = useMemo(() => {
|
|
37
|
+
const ignored = new Set(ignorePaths ?? []);
|
|
38
|
+
const fields: Record<string, Schema.Schema.AnyNoContext> = {};
|
|
39
|
+
for (const key of Object.keys(subject)) {
|
|
40
|
+
if (isInternalKey(key) || ignored.has(key)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const fieldSchema = schemaForValue((subject as any)[key]);
|
|
44
|
+
if (fieldSchema) {
|
|
45
|
+
fields[key] = fieldSchema;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return Schema.Struct(fields);
|
|
49
|
+
}, [subject, ignorePaths]);
|
|
50
|
+
|
|
51
|
+
const handleSave = useCallback(
|
|
52
|
+
(values: any, { changed }: { changed: Record<string, boolean> }) => {
|
|
53
|
+
const paths = Object.keys(changed).filter((path) => changed[path]);
|
|
54
|
+
Obj.update(subject, () => {
|
|
55
|
+
for (const path of paths) {
|
|
56
|
+
const value = values[path];
|
|
57
|
+
const parts = splitJsonPath(path as JsonPath);
|
|
58
|
+
Obj.setValue(subject, parts, value);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
[subject],
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Card.Content>
|
|
67
|
+
<Form.Root schema={schema} values={subject} autoSave onSave={handleSave}>
|
|
68
|
+
<Form.Viewport>
|
|
69
|
+
<Form.Content>
|
|
70
|
+
<Form.FieldSet />
|
|
71
|
+
</Form.Content>
|
|
72
|
+
</Form.Viewport>
|
|
73
|
+
</Form.Root>
|
|
74
|
+
</Card.Content>
|
|
75
|
+
);
|
|
76
|
+
};
|
package/src/cards/FormCard.tsx
CHANGED
|
@@ -21,7 +21,7 @@ export const FormCard = ({ subject, projection }: AppSurface.ObjectCardProps & {
|
|
|
21
21
|
|
|
22
22
|
const handleSave = useCallback((values: any, { changed }: { changed: Record<string, boolean> }) => {
|
|
23
23
|
const paths = Object.keys(changed).filter((path) => changed[path]);
|
|
24
|
-
Obj.
|
|
24
|
+
Obj.update(subject, () => {
|
|
25
25
|
for (const path of paths) {
|
|
26
26
|
const value = values[path];
|
|
27
27
|
const parts = splitJsonPath(path as JsonPath);
|
package/src/cards/JsonCard.tsx
CHANGED
|
@@ -5,12 +5,15 @@
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
7
|
import { Card } from '@dxos/react-ui';
|
|
8
|
-
import {
|
|
8
|
+
import { JsonHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
9
9
|
|
|
10
10
|
export const JsonCard = ({ data }: { data: unknown }) => {
|
|
11
11
|
return (
|
|
12
12
|
<Card.Content>
|
|
13
|
-
<
|
|
13
|
+
<span />
|
|
14
|
+
{/* TODO(wittjosiah): Span whole row. */}
|
|
15
|
+
<JsonHighlighter data={data} />
|
|
16
|
+
<span />
|
|
14
17
|
</Card.Content>
|
|
15
18
|
);
|
|
16
19
|
};
|
package/src/cards/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { Plugin } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
import { meta } from './meta';
|
|
6
8
|
|
|
7
|
-
export
|
|
9
|
+
export const PreviewPlugin = Plugin.lazy(meta, () => import('#plugin'));
|
|
10
|
+
|
|
11
|
+
export * from './meta';
|
|
@@ -9,12 +9,14 @@ import { withPluginManager } from '@dxos/app-framework/testing';
|
|
|
9
9
|
import { corePlugins } from '@dxos/plugin-testing';
|
|
10
10
|
import { random } from '@dxos/random';
|
|
11
11
|
import { Card } from '@dxos/react-ui';
|
|
12
|
-
import { withLayout } from '@dxos/react-ui/testing';
|
|
12
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
13
|
+
import { type Expando } from '@dxos/schema';
|
|
13
14
|
import { type Organization, type Person, type Pipeline, type Task } from '@dxos/types';
|
|
14
15
|
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
import {
|
|
16
|
+
import { translations } from '#translations';
|
|
17
|
+
|
|
18
|
+
import { ExpandoCard, FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
|
|
19
|
+
import { DefaultStory, createExpando, createOrganization, createPerson, createProject, createTask } from './testing';
|
|
18
20
|
|
|
19
21
|
random.seed(999);
|
|
20
22
|
|
|
@@ -22,6 +24,11 @@ const meta = {
|
|
|
22
24
|
title: 'plugins/plugin-preview/cards/Card',
|
|
23
25
|
render: DefaultStory,
|
|
24
26
|
decorators: [
|
|
27
|
+
// `Card` and its descendants in `@dxos/react-ui` consume `ThemeContext`
|
|
28
|
+
// for tx-token resolution; without this the stories trip the surface's
|
|
29
|
+
// `ErrorBoundary` with "Missing ThemeContext" and the storybook test
|
|
30
|
+
// assert-no-error fails.
|
|
31
|
+
withTheme(),
|
|
25
32
|
withLayout({ layout: 'fullscreen' }),
|
|
26
33
|
// TODO(wittjosiah): Try to write story which does not depend on plugin manager.
|
|
27
34
|
withPluginManager({ plugins: corePlugins() }),
|
|
@@ -75,6 +82,13 @@ export const _Task: StoryObj<typeof DefaultStory<Task.Task>> = {
|
|
|
75
82
|
},
|
|
76
83
|
};
|
|
77
84
|
|
|
85
|
+
export const _Expando: StoryObj<typeof DefaultStory<Expando.Expando>> = {
|
|
86
|
+
args: {
|
|
87
|
+
Component: ExpandoCard,
|
|
88
|
+
createObject: createExpando,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
78
92
|
export const _Json = {
|
|
79
93
|
render: () => {
|
|
80
94
|
const data = {
|
package/src/stories/testing.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import { Obj, Ref } from '@dxos/echo';
|
|
|
9
9
|
import { random } from '@dxos/random';
|
|
10
10
|
import { Card } from '@dxos/react-ui';
|
|
11
11
|
import { CardContainer, type CardContainerProps } from '@dxos/react-ui-mosaic/testing';
|
|
12
|
+
import { Expando } from '@dxos/schema';
|
|
12
13
|
import { Organization, Person, Pipeline, Task } from '@dxos/types';
|
|
13
14
|
|
|
14
15
|
export type DefaultStoryProps<T extends Obj.Any> = {
|
|
@@ -89,3 +90,12 @@ export const createTask = (): Task.Task => {
|
|
|
89
90
|
status: random.helpers.arrayElement(['todo', 'in-progress', 'done'] as const),
|
|
90
91
|
});
|
|
91
92
|
};
|
|
93
|
+
|
|
94
|
+
export const createExpando = (): Expando.Expando => {
|
|
95
|
+
return Expando.make({
|
|
96
|
+
name: random.person.fullName(),
|
|
97
|
+
email: random.internet.email(),
|
|
98
|
+
age: random.number.int({ min: 18, max: 80 }),
|
|
99
|
+
active: random.datatype.boolean(),
|
|
100
|
+
});
|
|
101
|
+
};
|