@dxos/plugin-preview 0.8.4-main.fcfe5033a5 → 0.8.4-staging.60fe92afc8

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 (91) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/neutral/PreviewPlugin.mjs +9 -0
  3. package/dist/lib/neutral/PreviewPlugin.mjs.map +7 -0
  4. package/dist/lib/neutral/PreviewPlugin.node.mjs +17 -0
  5. package/dist/lib/neutral/PreviewPlugin.node.mjs.map +7 -0
  6. package/dist/lib/neutral/PreviewPlugin.workerd.mjs +17 -0
  7. package/dist/lib/neutral/PreviewPlugin.workerd.mjs.map +7 -0
  8. package/dist/lib/neutral/capabilities/index.mjs +9 -0
  9. package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
  10. package/dist/lib/neutral/chunk-3SWUVHXJ.mjs +28 -0
  11. package/dist/lib/neutral/chunk-3SWUVHXJ.mjs.map +7 -0
  12. package/dist/lib/neutral/chunk-QOM5APM7.mjs +23 -0
  13. package/dist/lib/neutral/chunk-QOM5APM7.mjs.map +7 -0
  14. package/dist/lib/neutral/index.mjs +7 -0
  15. package/dist/lib/neutral/index.mjs.map +7 -0
  16. package/dist/lib/neutral/meta.json +1 -0
  17. package/dist/lib/neutral/meta.mjs +7 -0
  18. package/dist/lib/neutral/meta.mjs.map +7 -0
  19. package/dist/lib/neutral/plugin.mjs +11 -0
  20. package/dist/lib/neutral/plugin.mjs.map +7 -0
  21. package/dist/lib/neutral/preview-popover-FLMYMFCH.mjs +94 -0
  22. package/dist/lib/neutral/preview-popover-FLMYMFCH.mjs.map +7 -0
  23. package/dist/lib/neutral/react-surface-FE7E2JP7.mjs +418 -0
  24. package/dist/lib/neutral/react-surface-FE7E2JP7.mjs.map +7 -0
  25. package/dist/lib/neutral/testing.mjs +7 -0
  26. package/dist/lib/neutral/testing.mjs.map +7 -0
  27. package/dist/lib/neutral/translations.mjs +21 -0
  28. package/dist/lib/neutral/translations.mjs.map +7 -0
  29. package/dist/types/src/PreviewPlugin.d.ts +1 -0
  30. package/dist/types/src/PreviewPlugin.d.ts.map +1 -1
  31. package/dist/types/src/PreviewPlugin.node.d.ts +4 -0
  32. package/dist/types/src/PreviewPlugin.node.d.ts.map +1 -0
  33. package/dist/types/src/PreviewPlugin.test.d.ts +2 -0
  34. package/dist/types/src/PreviewPlugin.test.d.ts.map +1 -0
  35. package/dist/types/src/PreviewPlugin.workerd.d.ts +4 -0
  36. package/dist/types/src/PreviewPlugin.workerd.d.ts.map +1 -0
  37. package/dist/types/src/capabilities/preview-popover.d.ts.map +1 -1
  38. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  39. package/dist/types/src/cards/ExpandoCard.d.ts +4 -0
  40. package/dist/types/src/cards/ExpandoCard.d.ts.map +1 -0
  41. package/dist/types/src/cards/FormCard.d.ts +12 -2
  42. package/dist/types/src/cards/FormCard.d.ts.map +1 -1
  43. package/dist/types/src/cards/JsonCard.d.ts.map +1 -1
  44. package/dist/types/src/cards/OrganizationCard.d.ts.map +1 -1
  45. package/dist/types/src/cards/PersonCard.d.ts.map +1 -1
  46. package/dist/types/src/cards/ProjectCard.d.ts.map +1 -1
  47. package/dist/types/src/cards/TaskCard.d.ts.map +1 -1
  48. package/dist/types/src/cards/index.d.ts +1 -0
  49. package/dist/types/src/cards/index.d.ts.map +1 -1
  50. package/dist/types/src/index.d.ts +0 -1
  51. package/dist/types/src/index.d.ts.map +1 -1
  52. package/dist/types/src/meta.d.ts +1 -1
  53. package/dist/types/src/meta.d.ts.map +1 -1
  54. package/dist/types/src/plugin.d.ts +3 -0
  55. package/dist/types/src/plugin.d.ts.map +1 -0
  56. package/dist/types/src/stories/Card.stories.d.ts +31 -9
  57. package/dist/types/src/stories/Card.stories.d.ts.map +1 -1
  58. package/dist/types/src/stories/testing.d.ts +43 -4
  59. package/dist/types/src/stories/testing.d.ts.map +1 -1
  60. package/dist/types/src/testing.d.ts +2 -0
  61. package/dist/types/src/testing.d.ts.map +1 -0
  62. package/dist/types/src/translations.d.ts +8 -9
  63. package/dist/types/src/translations.d.ts.map +1 -1
  64. package/dist/types/tsconfig.tsbuildinfo +1 -1
  65. package/package.json +70 -44
  66. package/src/PreviewPlugin.node.ts +16 -0
  67. package/src/PreviewPlugin.test.ts +25 -0
  68. package/src/PreviewPlugin.tsx +4 -3
  69. package/src/PreviewPlugin.workerd.ts +16 -0
  70. package/src/capabilities/preview-popover.ts +34 -6
  71. package/src/capabilities/react-surface.tsx +59 -18
  72. package/src/cards/ExpandoCard.tsx +76 -0
  73. package/src/cards/FormCard.tsx +102 -25
  74. package/src/cards/JsonCard.tsx +7 -4
  75. package/src/cards/OrganizationCard.tsx +2 -2
  76. package/src/cards/PersonCard.tsx +4 -4
  77. package/src/cards/ProjectCard.tsx +2 -2
  78. package/src/cards/TaskCard.tsx +4 -3
  79. package/src/cards/index.ts +1 -0
  80. package/src/index.ts +0 -2
  81. package/src/meta.ts +7 -4
  82. package/src/plugin.ts +9 -0
  83. package/src/stories/Card.stories.tsx +76 -6
  84. package/src/stories/testing.tsx +69 -7
  85. package/src/testing.ts +7 -0
  86. package/dist/lib/browser/index.mjs +0 -59
  87. package/dist/lib/browser/index.mjs.map +0 -7
  88. package/dist/lib/browser/meta.json +0 -1
  89. package/dist/lib/node-esm/index.mjs +0 -61
  90. package/dist/lib/node-esm/index.mjs.map +0 -7
  91. package/dist/lib/node-esm/meta.json +0 -1
@@ -2,47 +2,124 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import * as Schema from 'effect/Schema';
5
6
  import React, { useCallback, useMemo } from 'react';
6
7
 
7
8
  import { type AppSurface } from '@dxos/app-toolkit/ui';
8
- import { Obj } from '@dxos/echo';
9
- import { type JsonPath, splitJsonPath } from '@dxos/effect';
10
- import { Card, useTranslation } from '@dxos/react-ui';
11
- import { Form, omitId } from '@dxos/react-ui-form';
9
+ import { Obj, Type } from '@dxos/echo';
10
+ import { useType } from '@dxos/echo-react';
11
+ import { type AnyProperties } from '@dxos/echo/internal';
12
+ import { SchemaEx } from '@dxos/effect';
13
+ import { Card, Icon, useTranslation } from '@dxos/react-ui';
14
+ import { Form, type FormUpdateMeta, type Presentation, getFormProperties, omitId } from '@dxos/react-ui-form';
12
15
  import { type ProjectionModel } from '@dxos/schema';
13
- import { descriptionMessage, mx } from '@dxos/ui-theme';
14
16
 
15
17
  import { meta } from '#meta';
16
18
 
17
- export const FormCard = ({ subject, projection }: AppSurface.ObjectCardProps & { projection?: ProjectionModel }) => {
19
+ export type FormCardProps = AppSurface.ObjectCardProps & {
20
+ projection?: ProjectionModel;
21
+ readonly?: boolean;
22
+ layout?: Presentation;
23
+ };
24
+
25
+ /**
26
+ * Default/fallback card for any ECHO object.
27
+ * Renders a `Form` against the object's schema — either the static schema
28
+ * from `Obj.getSchema` or, for runtime/mutable schemas, the reactive
29
+ * schema looked up via `useType`.
30
+ */
31
+ export const FormCard = ({ subject, projection, readonly = true, layout }: FormCardProps) => {
18
32
  const { t } = useTranslation(meta.id);
19
- const echoSchema = Obj.getSchema(subject);
20
- const schema = useMemo(() => echoSchema && omitId(echoSchema), [echoSchema]);
21
-
22
- const handleSave = useCallback((values: any, { changed }: { changed: Record<string, boolean> }) => {
23
- const paths = Object.keys(changed).filter((path) => changed[path]);
24
- Obj.change(subject, () => {
25
- for (const path of paths) {
26
- const value = values[path];
27
- const parts = splitJsonPath(path as JsonPath);
28
- Obj.setValue(subject, parts, value);
29
- }
30
- });
31
- }, []);
32
-
33
- if (!schema) {
34
- return <p className={mx(descriptionMessage)}>{t('unable-to-create-preview.message')}</p>;
33
+ // Readonly cards default to the `static` presentation — plain DOM, undefined values
34
+ // omitted — which reads as a preview rather than a form. Editable cards keep the
35
+ // `compact` form layout. Callers can override either via the explicit `layout` prop.
36
+ const resolvedLayout: Presentation = layout ?? (readonly ? 'static' : 'compact');
37
+
38
+ // Try the static schema first; fall back to the runtime/database schema for
39
+ // dynamic types whose schema isn't reachable via `Obj.getSchema` (DXN mismatch).
40
+ const staticType = Obj.getType(subject);
41
+ const db = Obj.getDatabase(subject);
42
+ // Obj.getTypeURI throws for corrupted objects; only evaluate it on the fallback path.
43
+ const runtimeType = useType(db, staticType ? undefined : Obj.getTypeURI(subject));
44
+ const schema = useMemo((): Schema.Schema.AnyNoContext | undefined => {
45
+ const resolvedType = runtimeType ?? staticType;
46
+ return resolvedType ? omitId(Type.getSchema(resolvedType)) : undefined;
47
+ }, [runtimeType, staticType]);
48
+
49
+ // Predict whether the form would render anything visible. Without this guard,
50
+ // readonly + compact mode produces an empty scrollarea when every form-renderable
51
+ // field is unset (e.g., a Table object whose `view`/`sizes` are FormInput-hidden
52
+ // and whose `name` is undefined).
53
+ //
54
+ // - In editable mode (`!readonly`), the form renders empty fields, so we only
55
+ // bail when there are no form-renderable properties at all.
56
+ // - In readonly mode, the form hides fields with null/undefined values, so we
57
+ // bail when no form-renderable property has a non-null value.
58
+ const hasRenderableContent = useMemo(() => {
59
+ if (!schema) {
60
+ return false;
61
+ }
62
+ const properties = getFormProperties(schema.ast);
63
+ if (properties.length === 0) {
64
+ return false;
65
+ }
66
+ if (!readonly) {
67
+ return true;
68
+ }
69
+ return properties.some((prop) => (subject as any)?.[prop.name] != null);
70
+ }, [schema, subject, readonly]);
71
+
72
+ const handleSave = useCallback(
73
+ (values: AnyProperties, { changed }: FormUpdateMeta<AnyProperties>) => {
74
+ const paths = (Object.keys(changed) as SchemaEx.JsonPath[]).filter((path) => changed[path]);
75
+ Obj.update(subject, () => {
76
+ for (const path of paths) {
77
+ const parts = SchemaEx.splitJsonPath(path);
78
+ const value = Obj.getValue(values as any, parts);
79
+ Obj.setValue(subject, parts, value);
80
+ }
81
+ });
82
+ },
83
+ [subject],
84
+ );
85
+
86
+ if (!schema || !hasRenderableContent) {
87
+ return (
88
+ <Card.Body>
89
+ <Card.Row>
90
+ <Card.Text variant='description'>{t('unable-to-create-preview.message')}</Card.Text>
91
+ </Card.Row>
92
+ </Card.Body>
93
+ );
35
94
  }
36
95
 
96
+ const { icon, hue } = Obj.getIcon(subject) ?? { icon: 'ph--circle-dashed--regular', hue: 'neutral' };
97
+
37
98
  return (
38
- <Card.Content>
39
- <Form.Root schema={schema} projection={projection} values={subject} autoSave onSave={handleSave}>
99
+ <Card.Body>
100
+ <Form.Root
101
+ schema={schema}
102
+ projection={projection}
103
+ values={subject}
104
+ readonly={readonly}
105
+ layout={resolvedLayout}
106
+ autoSave
107
+ onSave={handleSave}
108
+ >
40
109
  <Form.Viewport>
41
110
  <Form.Content>
42
111
  <Form.FieldSet />
43
112
  </Form.Content>
44
113
  </Form.Viewport>
45
114
  </Form.Root>
46
- </Card.Content>
115
+ <Card.Row fullWidth>
116
+ <div className='pt-1'>
117
+ <div {...{ 'data-hue': hue }} className='inline-flex items-center gap-1 dx-tag'>
118
+ <Icon icon={icon} />
119
+ <span>{Obj.getTypename(subject)}</span>
120
+ </div>
121
+ </div>
122
+ </Card.Row>
123
+ </Card.Body>
47
124
  );
48
125
  };
@@ -5,12 +5,15 @@
5
5
  import React from 'react';
6
6
 
7
7
  import { Card } from '@dxos/react-ui';
8
- import { Json } from '@dxos/react-ui-syntax-highlighter';
8
+ import { JsonHighlighter } from '@dxos/react-ui-syntax-highlighter';
9
9
 
10
10
  export const JsonCard = ({ data }: { data: unknown }) => {
11
11
  return (
12
- <Card.Content>
13
- <Json.Data data={data} />
14
- </Card.Content>
12
+ <Card.Body>
13
+ <span />
14
+ {/* TODO(wittjosiah): Span whole row. */}
15
+ <JsonHighlighter data={data} />
16
+ <span />
17
+ </Card.Body>
15
18
  );
16
19
  };
@@ -12,7 +12,7 @@ export const OrganizationCard = ({ subject }: AppSurface.ObjectCardProps<Organiz
12
12
  const { name, image, description, website } = subject;
13
13
 
14
14
  return (
15
- <Card.Content>
15
+ <Card.Body>
16
16
  <Card.Poster
17
17
  alt={name ?? ''}
18
18
  {...(image ? { image } : { icon: 'ph--building-office--regular' })}
@@ -24,6 +24,6 @@ export const OrganizationCard = ({ subject }: AppSurface.ObjectCardProps<Organiz
24
24
  </Card.Row>
25
25
  )}
26
26
  {website && <Card.Link label={website} href={website} />}
27
- </Card.Content>
27
+ </Card.Body>
28
28
  );
29
29
  };
@@ -9,7 +9,7 @@ import { useOperationInvoker } from '@dxos/app-framework/ui';
9
9
  import { LayoutOperation, getObjectPathFromObject, getSpacePath } from '@dxos/app-toolkit';
10
10
  import { type AppSurface } from '@dxos/app-toolkit/ui';
11
11
  import { Obj } from '@dxos/echo';
12
- import { runAndForwardErrors } from '@dxos/effect';
12
+ import { EffectEx } from '@dxos/effect';
13
13
  import { Avatar } from '@dxos/react-ui';
14
14
  import { Card } from '@dxos/react-ui';
15
15
  import { type Person } from '@dxos/types';
@@ -31,11 +31,11 @@ export const PersonCard = ({ subject }: AppSurface.ObjectCardProps<Person.Person
31
31
  subject: [organizationPath],
32
32
  workspace: db ? getSpacePath(db.spaceId) : undefined,
33
33
  });
34
- }).pipe(runAndForwardErrors);
34
+ }).pipe(EffectEx.runAndForwardErrors);
35
35
  }, [invoke, organization]);
36
36
 
37
37
  return (
38
- <Card.Content>
38
+ <Card.Body>
39
39
  <Avatar.Root>
40
40
  {image && (
41
41
  <Card.Row className='py-1'>
@@ -60,6 +60,6 @@ export const PersonCard = ({ subject }: AppSurface.ObjectCardProps<Person.Person
60
60
  </Card.Row>
61
61
  ))}
62
62
  </Avatar.Root>
63
- </Card.Content>
63
+ </Card.Body>
64
64
  );
65
65
  };
@@ -13,10 +13,10 @@ export const ProjectCard = ({ subject }: AppSurface.ObjectCardProps<Pipeline.Pip
13
13
  const { image, description } = subject;
14
14
 
15
15
  return (
16
- <Card.Content>
16
+ <Card.Body>
17
17
  {image && <Card.Poster image={image} alt={Obj.getLabel(subject) ?? ''} aspect='auto' />}
18
18
  {/* <CardHeader label={name} subject={subject} db={db} /> */}
19
19
  {description && <Card.Text variant='description'>{description}</Card.Text>}
20
- </Card.Content>
20
+ </Card.Body>
21
21
  );
22
22
  };
@@ -6,6 +6,7 @@ import * as SchemaAST from 'effect/SchemaAST';
6
6
  import React from 'react';
7
7
 
8
8
  import { type AppSurface } from '@dxos/app-toolkit/ui';
9
+ import { Type } from '@dxos/echo';
9
10
  import { type PropertyMetaAnnotation, PropertyMetaAnnotationId } from '@dxos/echo/internal';
10
11
  import { Card } from '@dxos/react-ui';
11
12
  import { Task } from '@dxos/types';
@@ -15,7 +16,7 @@ export const TaskCard = ({ subject }: AppSurface.ObjectCardProps<Task.Task>) =>
15
16
  const statusOption = getActiveStatusOption(status);
16
17
 
17
18
  return (
18
- <Card.Content>
19
+ <Card.Body>
19
20
  <Card.Row>
20
21
  {statusOption && (
21
22
  <div>
@@ -25,13 +26,13 @@ export const TaskCard = ({ subject }: AppSurface.ObjectCardProps<Task.Task>) =>
25
26
  </div>
26
27
  )}
27
28
  </Card.Row>
28
- </Card.Content>
29
+ </Card.Body>
29
30
  );
30
31
  };
31
32
 
32
33
  // TODO(thure): Should this move upstream as a helper? Is there an easier way to get options?
33
34
  const getActiveStatusOption = (status?: string) => {
34
- const properties = SchemaAST.getPropertySignatures(Task.Task.ast);
35
+ const properties = SchemaAST.getPropertySignatures(Type.getSchema(Task.Task).ast);
35
36
  const statusProperty = properties.find((p) => p.name === 'status');
36
37
  // TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
37
38
  const statusMeta = SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(
@@ -2,6 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ export * from './ExpandoCard';
5
6
  export * from './FormCard';
6
7
  export * from './JsonCard';
7
8
  export * from './OrganizationCard';
package/src/index.ts CHANGED
@@ -3,5 +3,3 @@
3
3
  //
4
4
 
5
5
  export * from './meta';
6
-
7
- export * from './PreviewPlugin';
package/src/meta.ts CHANGED
@@ -2,16 +2,19 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type Plugin } from '@dxos/app-framework';
5
+ import { Plugin } from '@dxos/app-framework';
6
+ import { DXN } from '@dxos/keys';
6
7
  import { trim } from '@dxos/util';
7
8
 
8
- export const meta: Plugin.Meta = {
9
- id: 'org.dxos.plugin.preview',
9
+ export const meta = Plugin.makeMeta({
10
+ key: DXN.make('org.dxos.plugin.preview'),
10
11
  name: 'Preview',
12
+ author: 'DXOS',
11
13
  description: trim`
12
14
  Rich preview panel for viewing object content without opening full editors.
13
15
  Quick peek at documents, images, and data with inline rendering.
14
16
  `,
15
17
  icon: 'ph--eye--regular',
16
18
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview',
17
- };
19
+ tags: ['system'],
20
+ });
package/src/plugin.ts ADDED
@@ -0,0 +1,9 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { Plugin } from '@dxos/app-framework';
6
+
7
+ import { meta } from './meta';
8
+
9
+ export const PreviewPlugin = Plugin.lazy(meta, () => import('#plugin'));
@@ -9,12 +9,24 @@ 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 { FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
16
- import { translations } from '../translations';
17
- import { DefaultStory, createOrganization, createPerson, createProject, createTask } from './testing';
16
+ import { translations } from '#translations';
17
+
18
+ import { ExpandoCard, FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
19
+ import {
20
+ DefaultStory,
21
+ createExpando,
22
+ createOrganization,
23
+ createPerson,
24
+ createPersonEmpty,
25
+ createProject,
26
+ createTableEmpty,
27
+ createTask,
28
+ createUnknown,
29
+ } from './testing';
18
30
 
19
31
  random.seed(999);
20
32
 
@@ -22,6 +34,11 @@ const meta = {
22
34
  title: 'plugins/plugin-preview/cards/Card',
23
35
  render: DefaultStory,
24
36
  decorators: [
37
+ // `Card` and its descendants in `@dxos/react-ui` consume `ThemeContext`
38
+ // for tx-token resolution; without this the stories trip the surface's
39
+ // `ErrorBoundary` with "Missing ThemeContext" and the storybook test
40
+ // assert-no-error fails.
41
+ withTheme(),
25
42
  withLayout({ layout: 'fullscreen' }),
26
43
  // TODO(wittjosiah): Try to write story which does not depend on plugin manager.
27
44
  withPluginManager({ plugins: corePlugins() }),
@@ -43,6 +60,52 @@ export const _Form: StoryObj<typeof DefaultStory<Person.Person>> = {
43
60
  },
44
61
  };
45
62
 
63
+ export const _FormEditable: StoryObj<typeof DefaultStory<Person.Person>> = {
64
+ args: {
65
+ Component: FormCard,
66
+ createObject: createPerson,
67
+ image: true,
68
+ componentProps: { readonly: false, layout: 'full' },
69
+ },
70
+ };
71
+
72
+ /**
73
+ * Empty-state variant: the subject has no resolvable schema so `FormCard` renders
74
+ * `<Card.Body><Card.Row><Card.Text variant='description'>No preview</Card.Text></Card.Row></Card.Body>`.
75
+ * Use this story to verify the empty message lands in the card's center column.
76
+ */
77
+ export const _FormEmpty: StoryObj<typeof DefaultStory> = {
78
+ args: {
79
+ Component: FormCard,
80
+ createObject: createUnknown,
81
+ },
82
+ };
83
+
84
+ /**
85
+ * No-values variant: the subject has a valid schema (Person) but no populated
86
+ * fields, so `FormCard` falls through to the same empty state instead of
87
+ * rendering an empty scrollarea.
88
+ */
89
+ export const _FormNoValues: StoryObj<typeof DefaultStory<Person.Person>> = {
90
+ args: {
91
+ Component: FormCard,
92
+ createObject: createPersonEmpty,
93
+ },
94
+ };
95
+
96
+ /**
97
+ * Table-like variant: the subject has values only in form-hidden fields
98
+ * (`view`, `sizes` annotated `FormInputAnnotation.set(false)`). `FormCard`
99
+ * must consult the schema's form-input annotations — not just `Object.keys` —
100
+ * to recognize this case and fall through to the empty state.
101
+ */
102
+ export const _FormTableEmpty: StoryObj<typeof DefaultStory<any>> = {
103
+ args: {
104
+ Component: FormCard,
105
+ createObject: createTableEmpty,
106
+ },
107
+ };
108
+
46
109
  export const _Person: StoryObj<typeof DefaultStory<Person.Person>> = {
47
110
  args: {
48
111
  Component: PersonCard,
@@ -75,6 +138,13 @@ export const _Task: StoryObj<typeof DefaultStory<Task.Task>> = {
75
138
  },
76
139
  };
77
140
 
141
+ export const _Expando: StoryObj<typeof DefaultStory<Expando.Expando>> = {
142
+ args: {
143
+ Component: ExpandoCard,
144
+ createObject: createExpando,
145
+ },
146
+ };
147
+
78
148
  export const _Json = {
79
149
  render: () => {
80
150
  const data = {
@@ -94,10 +164,10 @@ export const _Json = {
94
164
  <div className='flex justify-center p-16'>
95
165
  <div className='dx-card-min-width dx-card-max-width'>
96
166
  <Card.Root>
97
- <Card.Toolbar>
167
+ <Card.Header>
98
168
  <Card.IconBlock />
99
169
  <Card.Title>JSON</Card.Title>
100
- </Card.Toolbar>
170
+ </Card.Header>
101
171
  <JsonCard data={data} />
102
172
  </Card.Root>
103
173
  </div>
@@ -2,22 +2,31 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import * as Schema from 'effect/Schema';
5
6
  import React, { type FC, useMemo } from 'react';
6
7
 
7
8
  import { type AppSurface } from '@dxos/app-toolkit/ui';
8
- import { Obj, Ref } from '@dxos/echo';
9
+ import { DXN, Obj, Ref, Type } from '@dxos/echo';
10
+ import { Annotation } from '@dxos/echo';
9
11
  import { random } from '@dxos/random';
10
12
  import { Card } from '@dxos/react-ui';
11
13
  import { CardContainer, type CardContainerProps } from '@dxos/react-ui-mosaic/testing';
14
+ import { Expando } from '@dxos/schema';
12
15
  import { Organization, Person, Pipeline, Task } from '@dxos/types';
13
16
 
14
- export type DefaultStoryProps<T extends Obj.Any> = {
15
- Component: FC<AppSurface.ObjectCardProps<T>>;
17
+ export type DefaultStoryProps<T extends Obj.Any, P extends {} = {}> = {
18
+ Component: FC<AppSurface.ObjectCardProps<T> & P>;
16
19
  createObject: () => T;
17
20
  image?: boolean;
21
+ componentProps?: P;
18
22
  };
19
23
 
20
- export const DefaultStory = <T extends Obj.Any>({ Component, createObject, image }: DefaultStoryProps<T>) => {
24
+ export const DefaultStory = <T extends Obj.Any, P extends {} = {}>({
25
+ Component,
26
+ createObject,
27
+ image,
28
+ componentProps,
29
+ }: DefaultStoryProps<T, P>) => {
21
30
  const object = useMemo(() => createObject(), [createObject]);
22
31
  const roles: CardContainerProps['role'][] = ['intrinsic', 'popover'];
23
32
 
@@ -29,12 +38,16 @@ export const DefaultStory = <T extends Obj.Any>({ Component, createObject, image
29
38
  <span className='text-sm text-description'>{role}</span>
30
39
  <CardContainer role={role}>
31
40
  <Card.Root border={false}>
32
- <Card.Toolbar>
41
+ <Card.Header>
33
42
  <Card.DragHandle />
34
43
  <Card.Title>{Obj.getLabel(object)}</Card.Title>
35
44
  <Card.Menu />
36
- </Card.Toolbar>
37
- <Component role={role ?? 'card--content'} subject={image ? object : omitImage(object)} />
45
+ </Card.Header>
46
+ <Component
47
+ role={role ?? 'card--content'}
48
+ subject={image ? object : omitImage(object)}
49
+ {...(componentProps ?? ({} as P))}
50
+ />
38
51
  </Card.Root>
39
52
  </CardContainer>
40
53
  </div>
@@ -89,3 +102,52 @@ export const createTask = (): Task.Task => {
89
102
  status: random.helpers.arrayElement(['todo', 'in-progress', 'done'] as const),
90
103
  });
91
104
  };
105
+
106
+ /**
107
+ * Plain object cast as `Obj.Any` — has no schema, typename, or database, so cards
108
+ * like `FormCard` fall through to their empty/unsupported state. Use to story-pin
109
+ * fallback rendering.
110
+ */
111
+ export const createUnknown = (): Obj.Any => ({}) as unknown as Obj.Any;
112
+
113
+ /**
114
+ * Typed object with no user-facing values (only `id`). All Person fields are
115
+ * optional, so `Obj.make(Person, {})` is valid and triggers the FormCard
116
+ * "no values" branch in readonly mode.
117
+ */
118
+ export const createPersonEmpty = (): Person.Person => Obj.make(Person.Person, {});
119
+
120
+ /**
121
+ * Mock of the `Table` schema (org.dxos.type.table): an optional `name` plus
122
+ * `view` and `sizes` fields annotated with `FormInputAnnotation.set(false)`.
123
+ * When constructed without a `name`, no form-renderable field has a value so
124
+ * FormCard should fall through to its empty state — even though
125
+ * `Object.keys(subject)` includes `view`/`sizes`.
126
+ */
127
+ const TableLike = Schema.Struct({
128
+ name: Schema.String.pipe(Schema.optional),
129
+ view: Schema.String.pipe(Annotation.FormInputAnnotation.set(false)),
130
+ sizes: Schema.Record({ key: Schema.String, value: Schema.Number }).pipe(
131
+ Schema.mutable,
132
+ Annotation.FormInputAnnotation.set(false),
133
+ ),
134
+ }).pipe(Type.makeObject(DXN.make('org.dxos.test.tableLike', '0.1.0')));
135
+ type TableLike = Type.InstanceType<typeof TableLike>;
136
+
137
+ /**
138
+ * Table-like object with values only in form-hidden fields (`view`, `sizes`).
139
+ * `Object.keys` includes them, but a naive `hasValues` check would
140
+ * misclassify this as having data. FormCard must consult the schema's
141
+ * form-input annotations to correctly fall through to the empty state.
142
+ */
143
+ export const createTableEmpty = (): TableLike =>
144
+ Obj.make(TableLike, { view: 'view-dxn:placeholder', sizes: {} } as Obj.MakeProps<typeof TableLike>);
145
+
146
+ export const createExpando = (): Expando.Expando => {
147
+ return Expando.make({
148
+ name: random.person.fullName(),
149
+ email: random.internet.email(),
150
+ age: random.number.int({ min: 18, max: 80 }),
151
+ active: random.datatype.boolean(),
152
+ });
153
+ };
package/src/testing.ts ADDED
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // Eager re-export of `PreviewPlugin`. See `@dxos/plugin-testing/src/core.ts`
6
+ // for the rationale.
7
+ export * from './PreviewPlugin';
@@ -1,59 +0,0 @@
1
- // src/meta.ts
2
- import { trim } from "@dxos/util";
3
- var meta = {
4
- id: "org.dxos.plugin.preview",
5
- name: "Preview",
6
- description: trim`
7
- Rich preview panel for viewing object content without opening full editors.
8
- Quick peek at documents, images, and data with inline rendering.
9
- `,
10
- icon: "ph--eye--regular",
11
- source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview"
12
- };
13
-
14
- // src/PreviewPlugin.tsx
15
- import { ActivationEvents, Plugin } from "@dxos/app-framework";
16
- import { AppPlugin } from "@dxos/app-toolkit";
17
- import { Organization, Person } from "@dxos/types";
18
- import { PreviewPopover, ReactSurface } from "#capabilities";
19
- import { meta as meta3 } from "#meta";
20
-
21
- // src/translations.ts
22
- import { meta as meta2 } from "#meta";
23
- var translations = [
24
- {
25
- "en-US": {
26
- [meta2.id]: {
27
- "unable-to-create-preview.message": "No preview",
28
- "todo.label": "To do",
29
- "in-progress.label": "In progress",
30
- "done.label": "Done",
31
- "open-object.label": "Open",
32
- "add-object-to-space.label": "Add to space",
33
- "more-options.label": "More options"
34
- }
35
- }
36
- }
37
- ];
38
-
39
- // src/PreviewPlugin.tsx
40
- var PreviewPlugin = Plugin.define(meta3).pipe(AppPlugin.addSchemaModule({
41
- schema: [
42
- Person.Person,
43
- Organization.Organization
44
- ],
45
- id: "schema"
46
- }), AppPlugin.addSurfaceModule({
47
- activate: ReactSurface
48
- }), AppPlugin.addTranslationsModule({
49
- translations
50
- }), Plugin.addModule({
51
- id: "preview-popover",
52
- activatesOn: ActivationEvents.Startup,
53
- activate: PreviewPopover
54
- }), Plugin.make);
55
- export {
56
- PreviewPlugin,
57
- meta
58
- };
59
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.ts", "../../../src/PreviewPlugin.tsx", "../../../src/translations.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Plugin } from '@dxos/app-framework';\nimport { trim } from '@dxos/util';\n\nexport const meta: Plugin.Meta = {\n id: 'org.dxos.plugin.preview',\n name: 'Preview',\n description: trim`\n Rich preview panel for viewing object content without opening full editors.\n Quick peek at documents, images, and data with inline rendering.\n `,\n icon: 'ph--eye--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview',\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { ActivationEvents, Plugin } from '@dxos/app-framework';\nimport { AppPlugin } from '@dxos/app-toolkit';\nimport { Organization, Person } from '@dxos/types';\n\nimport { PreviewPopover, ReactSurface } from '#capabilities';\nimport { meta } from '#meta';\n\nimport { translations } from './translations';\n\nexport const PreviewPlugin = Plugin.define(meta).pipe(\n AppPlugin.addSchemaModule({ schema: [Person.Person, Organization.Organization], id: 'schema' }),\n AppPlugin.addSurfaceModule({ activate: ReactSurface }),\n AppPlugin.addTranslationsModule({ translations }),\n Plugin.addModule({\n id: 'preview-popover',\n activatesOn: ActivationEvents.Startup,\n activate: PreviewPopover,\n }),\n Plugin.make,\n);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Resource } from '@dxos/react-ui';\n\nimport { meta } from '#meta';\n\nexport const translations = [\n {\n 'en-US': {\n [meta.id]: {\n 'unable-to-create-preview.message': 'No preview',\n 'todo.label': 'To do',\n 'in-progress.label': 'In progress',\n 'done.label': 'Done',\n 'open-object.label': 'Open',\n 'add-object-to-space.label': 'Add to space',\n 'more-options.label': 'More options',\n },\n },\n },\n] as const satisfies Resource[];\n"],
5
- "mappings": ";AAKA,SAASA,YAAY;AAEd,IAAMC,OAAoB;EAC/BC,IAAI;EACJC,MAAM;EACNC,aAAaC;;;;EAIbC,MAAM;EACNC,QAAQ;AACV;;;ACZA,SAASC,kBAAkBC,cAAc;AACzC,SAASC,iBAAiB;AAC1B,SAASC,cAAcC,cAAc;AAErC,SAASC,gBAAgBC,oBAAoB;AAC7C,SAASC,QAAAA,aAAY;;;ACHrB,SAASC,QAAAA,aAAY;AAEd,IAAMC,eAAe;EAC1B;IACE,SAAS;MACP,CAACC,MAAKC,EAAE,GAAG;QACT,oCAAoC;QACpC,cAAc;QACd,qBAAqB;QACrB,cAAc;QACd,qBAAqB;QACrB,6BAA6B;QAC7B,sBAAsB;MACxB;IACF;EACF;;;;ADRK,IAAMC,gBAAgBC,OAAOC,OAAOC,KAAAA,EAAMC,KAC/CC,UAAUC,gBAAgB;EAAEC,QAAQ;IAACC,OAAOA;IAAQC,aAAaA;;EAAeC,IAAI;AAAS,CAAA,GAC7FL,UAAUM,iBAAiB;EAAEC,UAAUC;AAAa,CAAA,GACpDR,UAAUS,sBAAsB;EAAEC;AAAa,CAAA,GAC/Cd,OAAOe,UAAU;EACfN,IAAI;EACJO,aAAaC,iBAAiBC;EAC9BP,UAAUQ;AACZ,CAAA,GACAnB,OAAOoB,IAAI;",
6
- "names": ["trim", "meta", "id", "name", "description", "trim", "icon", "source", "ActivationEvents", "Plugin", "AppPlugin", "Organization", "Person", "PreviewPopover", "ReactSurface", "meta", "meta", "translations", "meta", "id", "PreviewPlugin", "Plugin", "define", "meta", "pipe", "AppPlugin", "addSchemaModule", "schema", "Person", "Organization", "id", "addSurfaceModule", "activate", "ReactSurface", "addTranslationsModule", "translations", "addModule", "activatesOn", "ActivationEvents", "Startup", "PreviewPopover", "make"]
7
- }
@@ -1 +0,0 @@
1
- {"inputs":{"src/meta.ts":{"bytes":1673,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/translations.ts":{"bytes":1898,"imports":[{"path":"#meta","kind":"import-statement","external":true}],"format":"esm"},"src/PreviewPlugin.tsx":{"bytes":3181,"imports":[{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/app-toolkit","kind":"import-statement","external":true},{"path":"@dxos/types","kind":"import-statement","external":true},{"path":"#capabilities","kind":"import-statement","external":true},{"path":"#meta","kind":"import-statement","external":true},{"path":"src/translations.ts","kind":"import-statement","original":"./translations"}],"format":"esm"},"src/index.ts":{"bytes":555,"imports":[{"path":"src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"src/PreviewPlugin.tsx","kind":"import-statement","original":"./PreviewPlugin"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3249},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/app-toolkit","kind":"import-statement","external":true},{"path":"@dxos/types","kind":"import-statement","external":true},{"path":"#capabilities","kind":"import-statement","external":true},{"path":"#meta","kind":"import-statement","external":true},{"path":"#meta","kind":"import-statement","external":true}],"exports":["PreviewPlugin","meta"],"entryPoint":"src/index.ts","inputs":{"src/meta.ts":{"bytesInOutput":389},"src/index.ts":{"bytesInOutput":0},"src/PreviewPlugin.tsx":{"bytesInOutput":664},"src/translations.ts":{"bytesInOutput":418}},"bytes":1633}}}