@dxos/plugin-preview 0.8.4-main.d05673bc65 → 0.8.4-main.d9fc60f731

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 (121) 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/{browser/chunk-KLQDOIFV.mjs → neutral/chunk-QOM5APM7.mjs} +11 -5
  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/{browser/preview-popover-X2ZJM5MK.mjs → neutral/preview-popover-FLMYMFCH.mjs} +30 -17
  22. package/dist/lib/neutral/preview-popover-FLMYMFCH.mjs.map +7 -0
  23. package/dist/lib/neutral/react-surface-HDOPNIQM.mjs +406 -0
  24. package/dist/lib/neutral/react-surface-HDOPNIQM.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/index.d.ts +3 -2
  38. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  39. package/dist/types/src/capabilities/preview-popover.d.ts.map +1 -0
  40. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  41. package/dist/types/src/cards/ExpandoCard.d.ts +4 -0
  42. package/dist/types/src/cards/ExpandoCard.d.ts.map +1 -0
  43. package/dist/types/src/cards/FormCard.d.ts +13 -3
  44. package/dist/types/src/cards/FormCard.d.ts.map +1 -1
  45. package/dist/types/src/cards/JsonCard.d.ts +5 -0
  46. package/dist/types/src/cards/JsonCard.d.ts.map +1 -0
  47. package/dist/types/src/cards/OrganizationCard.d.ts +2 -2
  48. package/dist/types/src/cards/OrganizationCard.d.ts.map +1 -1
  49. package/dist/types/src/cards/PersonCard.d.ts +2 -2
  50. package/dist/types/src/cards/PersonCard.d.ts.map +1 -1
  51. package/dist/types/src/cards/ProjectCard.d.ts +2 -2
  52. package/dist/types/src/cards/ProjectCard.d.ts.map +1 -1
  53. package/dist/types/src/cards/TaskCard.d.ts +2 -2
  54. package/dist/types/src/cards/TaskCard.d.ts.map +1 -1
  55. package/dist/types/src/cards/index.d.ts +2 -0
  56. package/dist/types/src/cards/index.d.ts.map +1 -1
  57. package/dist/types/src/index.d.ts +0 -1
  58. package/dist/types/src/index.d.ts.map +1 -1
  59. package/dist/types/src/meta.d.ts +1 -1
  60. package/dist/types/src/meta.d.ts.map +1 -1
  61. package/dist/types/src/plugin.d.ts +3 -0
  62. package/dist/types/src/plugin.d.ts.map +1 -0
  63. package/dist/types/src/stories/Card.stories.d.ts +35 -9
  64. package/dist/types/src/stories/Card.stories.d.ts.map +1 -1
  65. package/dist/types/src/stories/testing.d.ts +44 -5
  66. package/dist/types/src/stories/testing.d.ts.map +1 -1
  67. package/dist/types/src/testing.d.ts +2 -0
  68. package/dist/types/src/testing.d.ts.map +1 -0
  69. package/dist/types/src/translations.d.ts +8 -9
  70. package/dist/types/src/translations.d.ts.map +1 -1
  71. package/dist/types/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +72 -42
  73. package/src/PreviewPlugin.node.ts +16 -0
  74. package/src/PreviewPlugin.test.ts +25 -0
  75. package/src/PreviewPlugin.tsx +6 -4
  76. package/src/PreviewPlugin.workerd.ts +16 -0
  77. package/src/capabilities/index.ts +4 -2
  78. package/src/capabilities/{preview-popover/preview-popover.ts → preview-popover.ts} +38 -7
  79. package/src/capabilities/react-surface.tsx +152 -0
  80. package/src/cards/ExpandoCard.tsx +76 -0
  81. package/src/cards/FormCard.tsx +92 -25
  82. package/src/cards/JsonCard.tsx +19 -0
  83. package/src/cards/OrganizationCard.tsx +5 -5
  84. package/src/cards/PersonCard.tsx +29 -11
  85. package/src/cards/ProjectCard.tsx +4 -4
  86. package/src/cards/TaskCard.tsx +19 -14
  87. package/src/cards/index.ts +2 -0
  88. package/src/index.ts +0 -2
  89. package/src/meta.ts +7 -4
  90. package/src/plugin.ts +9 -0
  91. package/src/stories/Card.stories.tsx +106 -5
  92. package/src/stories/testing.tsx +83 -21
  93. package/src/testing.ts +7 -0
  94. package/src/translations.ts +8 -8
  95. package/dist/lib/browser/chunk-KLQDOIFV.mjs.map +0 -7
  96. package/dist/lib/browser/index.mjs +0 -55
  97. package/dist/lib/browser/index.mjs.map +0 -7
  98. package/dist/lib/browser/meta.json +0 -1
  99. package/dist/lib/browser/preview-popover-X2ZJM5MK.mjs.map +0 -7
  100. package/dist/lib/browser/react-surface-XGUZ4J2A.mjs +0 -236
  101. package/dist/lib/browser/react-surface-XGUZ4J2A.mjs.map +0 -7
  102. package/dist/lib/node-esm/chunk-GFWHEHC5.mjs +0 -19
  103. package/dist/lib/node-esm/chunk-GFWHEHC5.mjs.map +0 -7
  104. package/dist/lib/node-esm/index.mjs +0 -56
  105. package/dist/lib/node-esm/index.mjs.map +0 -7
  106. package/dist/lib/node-esm/meta.json +0 -1
  107. package/dist/lib/node-esm/preview-popover-6FLDJHHB.mjs +0 -83
  108. package/dist/lib/node-esm/preview-popover-6FLDJHHB.mjs.map +0 -7
  109. package/dist/lib/node-esm/react-surface-DGHIAODG.mjs +0 -237
  110. package/dist/lib/node-esm/react-surface-DGHIAODG.mjs.map +0 -7
  111. package/dist/types/src/capabilities/preview-popover/index.d.ts +0 -3
  112. package/dist/types/src/capabilities/preview-popover/index.d.ts.map +0 -1
  113. package/dist/types/src/capabilities/preview-popover/preview-popover.d.ts.map +0 -1
  114. package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
  115. package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
  116. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
  117. package/src/capabilities/preview-popover/index.ts +0 -7
  118. package/src/capabilities/react-surface/index.ts +0 -7
  119. package/src/capabilities/react-surface/react-surface.tsx +0 -97
  120. /package/dist/types/src/capabilities/{preview-popover/preview-popover.d.ts → preview-popover.d.ts} +0 -0
  121. /package/dist/types/src/capabilities/{react-surface/react-surface.d.ts → react-surface.d.ts} +0 -0
@@ -2,47 +2,114 @@
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
- import { type SurfaceComponentProps } from '@dxos/app-toolkit/ui';
8
- import { Obj } from '@dxos/echo';
8
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
9
+ import { Obj, Type } from '@dxos/echo';
10
+ import { useType } from '@dxos/echo-react';
11
+ import { type AnyProperties } from '@dxos/echo/internal';
9
12
  import { type JsonPath, splitJsonPath } from '@dxos/effect';
10
13
  import { Card, useTranslation } from '@dxos/react-ui';
11
- import { Form, omitId } from '@dxos/react-ui-form';
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
- import { meta } from '../meta';
17
+ import { meta } from '#meta';
16
18
 
17
- export const FormCard = ({ subject, projection }: SurfaceComponentProps & { 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
+ const typename = Obj.getTypename(subject);
43
+ const runtimeType = useType(db, staticType ? undefined : typename);
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 JsonPath[]).filter((path) => changed[path]);
75
+ Obj.update(subject, () => {
76
+ for (const path of paths) {
77
+ const parts = 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
 
37
96
  return (
38
- <Card.Content>
39
- <Form.Root schema={schema} projection={projection} values={subject} autoSave onSave={handleSave}>
97
+ <Card.Body>
98
+ <Form.Root
99
+ schema={schema}
100
+ projection={projection}
101
+ values={subject}
102
+ readonly={readonly}
103
+ layout={resolvedLayout}
104
+ autoSave
105
+ onSave={handleSave}
106
+ >
40
107
  <Form.Viewport>
41
108
  <Form.Content>
42
109
  <Form.FieldSet />
43
110
  </Form.Content>
44
111
  </Form.Viewport>
45
112
  </Form.Root>
46
- </Card.Content>
113
+ </Card.Body>
47
114
  );
48
115
  };
@@ -0,0 +1,19 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { Card } from '@dxos/react-ui';
8
+ import { JsonHighlighter } from '@dxos/react-ui-syntax-highlighter';
9
+
10
+ export const JsonCard = ({ data }: { data: unknown }) => {
11
+ return (
12
+ <Card.Body>
13
+ <span />
14
+ {/* TODO(wittjosiah): Span whole row. */}
15
+ <JsonHighlighter data={data} />
16
+ <span />
17
+ </Card.Body>
18
+ );
19
+ };
@@ -4,15 +4,15 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { type SurfaceComponentProps } from '@dxos/app-toolkit/ui';
7
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
8
8
  import { Card } from '@dxos/react-ui';
9
9
  import { type Organization } from '@dxos/types';
10
10
 
11
- export const OrganizationCard = ({ subject }: SurfaceComponentProps<Organization.Organization>) => {
12
- const { image, description, website } = subject;
11
+ export const OrganizationCard = ({ subject }: AppSurface.ObjectCardProps<Organization.Organization>) => {
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 }: SurfaceComponentProps<Organization
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
  };
@@ -2,25 +2,47 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React from 'react';
5
+ import * as Effect from 'effect/Effect';
6
+ import React, { useCallback } from 'react';
6
7
 
7
- import { type SurfaceComponentProps } from '@dxos/app-toolkit/ui';
8
+ import { useOperationInvoker } from '@dxos/app-framework/ui';
9
+ import { LayoutOperation, getObjectPathFromObject, getSpacePath } from '@dxos/app-toolkit';
10
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
11
+ import { Obj } from '@dxos/echo';
12
+ import { runAndForwardErrors } from '@dxos/effect';
8
13
  import { Avatar } from '@dxos/react-ui';
9
14
  import { Card } from '@dxos/react-ui';
10
15
  import { type Person } from '@dxos/types';
11
16
 
12
- export const PersonCard = ({ subject }: SurfaceComponentProps<Person.Person>) => {
17
+ export const PersonCard = ({ subject }: AppSurface.ObjectCardProps<Person.Person>) => {
18
+ const { invoke } = useOperationInvoker();
13
19
  const { image, organization: { target: organization } = {}, emails = [] } = subject;
14
20
 
21
+ const handleOrganizationClick = useCallback(() => {
22
+ if (!organization) {
23
+ return;
24
+ }
25
+
26
+ return Effect.gen(function* () {
27
+ const organizationPath = getObjectPathFromObject(organization);
28
+ const db = Obj.getDatabase(organization);
29
+ yield* invoke(LayoutOperation.UpdatePopover, { state: false, anchorId: '' });
30
+ yield* invoke(LayoutOperation.Open, {
31
+ subject: [organizationPath],
32
+ workspace: db ? getSpacePath(db.spaceId) : undefined,
33
+ });
34
+ }).pipe(runAndForwardErrors);
35
+ }, [invoke, organization]);
36
+
15
37
  return (
16
- <Card.Content>
38
+ <Card.Body>
17
39
  <Avatar.Root>
18
40
  {image && (
19
41
  <Card.Row className='py-1'>
20
42
  <Avatar.Content
21
43
  imgSrc={image}
22
44
  icon='ph--user--regular'
23
- size={16}
45
+ size={20}
24
46
  classNames={!image && 'opacity-50'}
25
47
  hue='neutral'
26
48
  variant='square'
@@ -28,11 +50,7 @@ export const PersonCard = ({ subject }: SurfaceComponentProps<Person.Person>) =>
28
50
  </Card.Row>
29
51
  )}
30
52
  {organization?.name && (
31
- <Card.Action
32
- icon='ph--buildings--regular'
33
- label={organization.name}
34
- // onClick={onSelect ? () => onSelect(organization) : undefined}
35
- />
53
+ <Card.Action icon='ph--buildings--regular' label={organization.name} onClick={handleOrganizationClick} />
36
54
  )}
37
55
  {emails.map(({ value }) => (
38
56
  <Card.Row key={value} icon='ph--at--regular'>
@@ -42,6 +60,6 @@ export const PersonCard = ({ subject }: SurfaceComponentProps<Person.Person>) =>
42
60
  </Card.Row>
43
61
  ))}
44
62
  </Avatar.Root>
45
- </Card.Content>
63
+ </Card.Body>
46
64
  );
47
65
  };
@@ -4,19 +4,19 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { type SurfaceComponentProps } from '@dxos/app-toolkit/ui';
7
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
8
8
  import { Obj } from '@dxos/echo';
9
9
  import { Card } from '@dxos/react-ui';
10
10
  import { type Pipeline } from '@dxos/types';
11
11
 
12
- export const ProjectCard = ({ subject }: SurfaceComponentProps<Pipeline.Pipeline>) => {
12
+ export const ProjectCard = ({ subject }: AppSurface.ObjectCardProps<Pipeline.Pipeline>) => {
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
  };
@@ -5,36 +5,41 @@
5
5
  import * as SchemaAST from 'effect/SchemaAST';
6
6
  import React from 'react';
7
7
 
8
- import { type SurfaceComponentProps } from '@dxos/app-toolkit/ui';
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';
12
13
 
13
- export const TaskCard = ({ subject }: SurfaceComponentProps<Task.Task>) => {
14
+ export const TaskCard = ({ subject }: AppSurface.ObjectCardProps<Task.Task>) => {
14
15
  const { title, status } = subject;
15
16
  const statusOption = getActiveStatusOption(status);
16
17
 
17
18
  return (
18
- <Card.Content>
19
- <Card.Heading classNames='min-w-0 flex-1 truncate'>{title}</Card.Heading>
20
- {statusOption && (
21
- <span className='dx-tag' data-hue={statusOption.color}>
22
- {statusOption.title}
23
- </span>
24
- )}
25
- </Card.Content>
19
+ <Card.Body>
20
+ <Card.Row>
21
+ {statusOption && (
22
+ <div>
23
+ <span className='dx-tag' data-hue={statusOption.color}>
24
+ {statusOption.title}
25
+ </span>
26
+ </div>
27
+ )}
28
+ </Card.Row>
29
+ </Card.Body>
26
30
  );
27
31
  };
28
32
 
29
33
  // TODO(thure): Should this move upstream as a helper? Is there an easier way to get options?
30
34
  const getActiveStatusOption = (status?: string) => {
31
- const properties = SchemaAST.getPropertySignatures(Task.Task.ast);
35
+ const properties = SchemaAST.getPropertySignatures(Type.getSchema(Task.Task).ast);
32
36
  const statusProperty = properties.find((p) => p.name === 'status');
37
+ // TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
33
38
  const statusMeta = SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(
34
- // TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
35
39
  (statusProperty!.type as any).types[0],
36
40
  );
37
- const options = // TODO(thure): Typescript asserts `statusMeta` doesn’t have `.value`, but in runtime it does.
38
- (statusMeta as any).value.singleSelect.options as { id: string; title: string; color: string }[];
41
+
42
+ // TODO(thure): Typescript asserts `statusMeta` doesn’t have `.value`, but in runtime it does.
43
+ const options = (statusMeta as any).value.singleSelect.options as { id: string; title: string; color: string }[];
39
44
  return options.find(({ id }) => id === status);
40
45
  };
@@ -2,7 +2,9 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ export * from './ExpandoCard';
5
6
  export * from './FormCard';
7
+ export * from './JsonCard';
6
8
  export * from './OrganizationCard';
7
9
  export * from './PersonCard';
8
10
  export * from './ProjectCard';
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'));
@@ -3,24 +3,41 @@
3
3
  //
4
4
 
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import React from 'react';
6
7
 
7
8
  import { withPluginManager } from '@dxos/app-framework/testing';
8
9
  import { corePlugins } from '@dxos/plugin-testing';
9
- import { faker } from '@dxos/random';
10
+ import { random } from '@dxos/random';
11
+ import { Card } from '@dxos/react-ui';
10
12
  import { withLayout, withTheme } from '@dxos/react-ui/testing';
13
+ import { type Expando } from '@dxos/schema';
11
14
  import { type Organization, type Person, type Pipeline, type Task } from '@dxos/types';
12
15
 
13
- import { FormCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
14
- import { translations } from '../translations';
16
+ import { translations } from '#translations';
15
17
 
16
- import { DefaultStory, createOrganization, createPerson, createProject, createTask } from './testing';
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';
17
30
 
18
- faker.seed(999);
31
+ random.seed(999);
19
32
 
20
33
  const meta = {
21
34
  title: 'plugins/plugin-preview/cards/Card',
22
35
  render: DefaultStory,
23
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.
24
41
  withTheme(),
25
42
  withLayout({ layout: 'fullscreen' }),
26
43
  // TODO(wittjosiah): Try to write story which does not depend on plugin manager.
@@ -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,
@@ -74,3 +137,41 @@ export const _Task: StoryObj<typeof DefaultStory<Task.Task>> = {
74
137
  image: true,
75
138
  },
76
139
  };
140
+
141
+ export const _Expando: StoryObj<typeof DefaultStory<Expando.Expando>> = {
142
+ args: {
143
+ Component: ExpandoCard,
144
+ createObject: createExpando,
145
+ },
146
+ };
147
+
148
+ export const _Json = {
149
+ render: () => {
150
+ const data = {
151
+ subject: {
152
+ id: random.string.uuid(),
153
+ name: random.person.fullName(),
154
+ email: random.internet.email(),
155
+ tags: [random.lorem.word(), random.lorem.word(), random.lorem.word()],
156
+ nested: {
157
+ count: random.number.int({ max: 100 }),
158
+ active: random.datatype.boolean(),
159
+ },
160
+ },
161
+ };
162
+
163
+ return (
164
+ <div className='flex justify-center p-16'>
165
+ <div className='dx-card-min-width dx-card-max-width'>
166
+ <Card.Root>
167
+ <Card.Header>
168
+ <Card.IconBlock />
169
+ <Card.Title>JSON</Card.Title>
170
+ </Card.Header>
171
+ <JsonCard data={data} />
172
+ </Card.Root>
173
+ </div>
174
+ </div>
175
+ );
176
+ },
177
+ };