@dxos/plugin-preview 0.8.4-main.ead640a → 0.8.4-main.effb148878

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 (129) 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-XD3EYTHF.mjs +21 -0
  13. package/dist/lib/neutral/chunk-XD3EYTHF.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-F33UBSBM.mjs +80 -0
  22. package/dist/lib/neutral/preview-popover-F33UBSBM.mjs.map +7 -0
  23. package/dist/lib/neutral/react-surface-3UPRCM4X.mjs +408 -0
  24. package/dist/lib/neutral/react-surface-3UPRCM4X.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 +3 -1
  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 +3 -2
  40. package/dist/types/src/capabilities/preview-popover.d.ts.map +1 -1
  41. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  42. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  43. package/dist/types/src/cards/ExpandoCard.d.ts +4 -0
  44. package/dist/types/src/cards/ExpandoCard.d.ts.map +1 -0
  45. package/dist/types/src/cards/FormCard.d.ts +17 -0
  46. package/dist/types/src/cards/FormCard.d.ts.map +1 -0
  47. package/dist/types/src/cards/JsonCard.d.ts +5 -0
  48. package/dist/types/src/cards/JsonCard.d.ts.map +1 -0
  49. package/dist/types/src/cards/OrganizationCard.d.ts +3 -3
  50. package/dist/types/src/cards/OrganizationCard.d.ts.map +1 -1
  51. package/dist/types/src/cards/PersonCard.d.ts +5 -0
  52. package/dist/types/src/cards/PersonCard.d.ts.map +1 -0
  53. package/dist/types/src/cards/ProjectCard.d.ts +3 -3
  54. package/dist/types/src/cards/ProjectCard.d.ts.map +1 -1
  55. package/dist/types/src/cards/TaskCard.d.ts +3 -3
  56. package/dist/types/src/cards/TaskCard.d.ts.map +1 -1
  57. package/dist/types/src/cards/index.d.ts +4 -1
  58. package/dist/types/src/cards/index.d.ts.map +1 -1
  59. package/dist/types/src/index.d.ts +0 -2
  60. package/dist/types/src/index.d.ts.map +1 -1
  61. package/dist/types/src/meta.d.ts +2 -2
  62. package/dist/types/src/meta.d.ts.map +1 -1
  63. package/dist/types/src/plugin.d.ts +3 -0
  64. package/dist/types/src/plugin.d.ts.map +1 -0
  65. package/dist/types/src/stories/Card.stories.d.ts +42 -14
  66. package/dist/types/src/stories/Card.stories.d.ts.map +1 -1
  67. package/dist/types/src/stories/testing.d.ts +52 -12
  68. package/dist/types/src/stories/testing.d.ts.map +1 -1
  69. package/dist/types/src/testing.d.ts +2 -0
  70. package/dist/types/src/testing.d.ts.map +1 -0
  71. package/dist/types/src/translations.d.ts +8 -9
  72. package/dist/types/src/translations.d.ts.map +1 -1
  73. package/dist/types/tsconfig.tsbuildinfo +1 -1
  74. package/package.json +92 -39
  75. package/src/PreviewPlugin.node.ts +16 -0
  76. package/src/PreviewPlugin.test.ts +25 -0
  77. package/src/PreviewPlugin.tsx +17 -26
  78. package/src/PreviewPlugin.workerd.ts +16 -0
  79. package/src/capabilities/index.ts +3 -3
  80. package/src/capabilities/preview-popover.ts +69 -42
  81. package/src/capabilities/react-surface.tsx +132 -120
  82. package/src/cards/ExpandoCard.tsx +76 -0
  83. package/src/cards/FormCard.tsx +115 -0
  84. package/src/cards/JsonCard.tsx +19 -0
  85. package/src/cards/OrganizationCard.tsx +17 -13
  86. package/src/cards/PersonCard.tsx +65 -0
  87. package/src/cards/ProjectCard.tsx +9 -11
  88. package/src/cards/TaskCard.tsx +27 -28
  89. package/src/cards/index.ts +4 -1
  90. package/src/index.ts +0 -3
  91. package/src/meta.ts +10 -3
  92. package/src/plugin.ts +9 -0
  93. package/src/stories/Card.stories.tsx +139 -24
  94. package/src/stories/testing.tsx +117 -77
  95. package/src/testing.ts +7 -0
  96. package/src/translations.ts +8 -8
  97. package/dist/lib/browser/chunk-XKCIQK3C.mjs +0 -12
  98. package/dist/lib/browser/chunk-XKCIQK3C.mjs.map +0 -7
  99. package/dist/lib/browser/index.mjs +0 -64
  100. package/dist/lib/browser/index.mjs.map +0 -7
  101. package/dist/lib/browser/meta.json +0 -1
  102. package/dist/lib/browser/preview-popover-RKHENTFP.mjs +0 -65
  103. package/dist/lib/browser/preview-popover-RKHENTFP.mjs.map +0 -7
  104. package/dist/lib/browser/react-surface-CPGRW3OV.mjs +0 -493
  105. package/dist/lib/browser/react-surface-CPGRW3OV.mjs.map +0 -7
  106. package/dist/lib/node-esm/chunk-L3IZVX56.mjs +0 -14
  107. package/dist/lib/node-esm/chunk-L3IZVX56.mjs.map +0 -7
  108. package/dist/lib/node-esm/index.mjs +0 -65
  109. package/dist/lib/node-esm/index.mjs.map +0 -7
  110. package/dist/lib/node-esm/meta.json +0 -1
  111. package/dist/lib/node-esm/preview-popover-TZKX67EY.mjs +0 -67
  112. package/dist/lib/node-esm/preview-popover-TZKX67EY.mjs.map +0 -7
  113. package/dist/lib/node-esm/react-surface-XJKNWCPR.mjs +0 -494
  114. package/dist/lib/node-esm/react-surface-XJKNWCPR.mjs.map +0 -7
  115. package/dist/types/src/cards/ContactCard.d.ts +0 -5
  116. package/dist/types/src/cards/ContactCard.d.ts.map +0 -1
  117. package/dist/types/src/components/CardComponents.d.ts +0 -16
  118. package/dist/types/src/components/CardComponents.d.ts.map +0 -1
  119. package/dist/types/src/components/CardSubjectMenu.d.ts +0 -8
  120. package/dist/types/src/components/CardSubjectMenu.d.ts.map +0 -1
  121. package/dist/types/src/components/index.d.ts +0 -3
  122. package/dist/types/src/components/index.d.ts.map +0 -1
  123. package/dist/types/src/types.d.ts +0 -10
  124. package/dist/types/src/types.d.ts.map +0 -1
  125. package/src/cards/ContactCard.tsx +0 -58
  126. package/src/components/CardComponents.tsx +0 -67
  127. package/src/components/CardSubjectMenu.tsx +0 -91
  128. package/src/components/index.ts +0 -6
  129. package/src/types.ts +0 -15
@@ -5,42 +5,41 @@
5
5
  import * as SchemaAST from 'effect/SchemaAST';
6
6
  import React from 'react';
7
7
 
8
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
9
+ import { Type } from '@dxos/echo';
8
10
  import { type PropertyMetaAnnotation, PropertyMetaAnnotationId } from '@dxos/echo/internal';
9
- import { Card, cardNoSpacing, cardSpacing } from '@dxos/react-ui-stack';
10
- import { mx } from '@dxos/react-ui-theme';
11
- import { DataType } from '@dxos/schema';
11
+ import { Card } from '@dxos/react-ui';
12
+ import { Task } from '@dxos/types';
12
13
 
13
- import { CardSubjectMenu } from '../components';
14
- import { type PreviewProps } from '../types';
14
+ export const TaskCard = ({ subject }: AppSurface.ObjectCardProps<Task.Task>) => {
15
+ const { title, status } = subject;
16
+ const statusOption = getActiveStatusOption(status);
17
+
18
+ return (
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>
30
+ );
31
+ };
15
32
 
16
33
  // TODO(thure): Should this move upstream as a helper? Is there an easier way to get options?
17
34
  const getActiveStatusOption = (status?: string) => {
18
- const properties = SchemaAST.getPropertySignatures(DataType.Task.ast);
35
+ const properties = SchemaAST.getPropertySignatures(Type.getSchema(Task.Task).ast);
19
36
  const statusProperty = properties.find((p) => p.name === 'status');
37
+ // TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
20
38
  const statusMeta = SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(
21
- // TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
22
39
  (statusProperty!.type as any).types[0],
23
40
  );
24
- const options = // TODO(thure): Typescript asserts `statusMeta` doesn’t have `.value`, but in runtime it does.
25
- (statusMeta as any).value.singleSelect.options as { id: string; title: string; color: string }[];
26
- return options.find(({ id }) => id === status);
27
- };
28
41
 
29
- export const TaskCard = ({ subject, role, activeSpace }: PreviewProps<DataType.Task>) => {
30
- const { title, status } = subject;
31
- const statusOption = getActiveStatusOption(status);
32
-
33
- return (
34
- <Card.SurfaceRoot role={role}>
35
- <div role='none' className={mx('flex items-center gap-2', cardSpacing)}>
36
- <Card.Heading classNames={[cardNoSpacing, 'min-is-0 flex-1 truncate']}>{title}</Card.Heading>
37
- {statusOption && (
38
- <span className='dx-tag' data-hue={statusOption.color}>
39
- {statusOption.title}
40
- </span>
41
- )}
42
- <CardSubjectMenu subject={subject} activeSpace={activeSpace} />
43
- </div>
44
- </Card.SurfaceRoot>
45
- );
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 }[];
44
+ return options.find(({ id }) => id === status);
46
45
  };
@@ -2,7 +2,10 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './ContactCard';
5
+ export * from './ExpandoCard';
6
+ export * from './FormCard';
7
+ export * from './JsonCard';
6
8
  export * from './OrganizationCard';
9
+ export * from './PersonCard';
7
10
  export * from './ProjectCard';
8
11
  export * from './TaskCard';
package/src/index.ts CHANGED
@@ -3,6 +3,3 @@
3
3
  //
4
4
 
5
5
  export * from './meta';
6
- export type * from './types';
7
-
8
- export * from './PreviewPlugin';
package/src/meta.ts CHANGED
@@ -2,11 +2,18 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type PluginMeta } from '@dxos/app-framework';
5
+ import { type Plugin } from '@dxos/app-framework';
6
+ import { trim } from '@dxos/util';
6
7
 
7
- export const meta: PluginMeta = {
8
- id: 'dxos.org/plugin/preview',
8
+ export const meta: Plugin.Meta = {
9
+ id: 'org.dxos.plugin.preview',
9
10
  name: 'Preview',
11
+ author: 'DXOS',
12
+ description: trim`
13
+ Rich preview panel for viewing object content without opening full editors.
14
+ Quick peek at documents, images, and data with inline rendering.
15
+ `,
10
16
  icon: 'ph--eye--regular',
11
17
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview',
18
+ tags: ['system'],
12
19
  };
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,60 +3,175 @@
3
3
  //
4
4
 
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import React from 'react';
6
7
 
7
- import { IntentPlugin } from '@dxos/app-framework';
8
8
  import { withPluginManager } from '@dxos/app-framework/testing';
9
- import { faker } from '@dxos/random';
10
- import { withTheme } from '@dxos/react-ui/testing';
9
+ import { corePlugins } from '@dxos/plugin-testing';
10
+ import { random } from '@dxos/random';
11
+ import { Card } from '@dxos/react-ui';
12
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
13
+ import { type Expando } from '@dxos/schema';
14
+ import { type Organization, type Person, type Pipeline, type Task } from '@dxos/types';
11
15
 
12
- import { translations } from '../translations';
16
+ import { translations } from '#translations';
13
17
 
14
- import { Defaultstory, createCards } 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';
15
30
 
16
- faker.seed(999);
31
+ random.seed(999);
17
32
 
18
33
  const meta = {
19
- title: 'plugins/plugin-preview/Card',
20
- render: Defaultstory,
34
+ title: 'plugins/plugin-preview/cards/Card',
35
+ render: DefaultStory,
21
36
  decorators: [
22
- withTheme, // TODO(wittjosiah): Try to write story which does not depend on plugin manager.
23
- withPluginManager({ plugins: [IntentPlugin()] }),
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(),
42
+ withLayout({ layout: 'fullscreen' }),
43
+ // TODO(wittjosiah): Try to write story which does not depend on plugin manager.
44
+ withPluginManager({ plugins: corePlugins() }),
24
45
  ],
25
46
  parameters: {
26
47
  layout: 'fullscreen',
27
48
  translations,
28
49
  },
29
50
  tags: ['cards'],
30
- } satisfies Meta<typeof Defaultstory>;
51
+ } satisfies Meta<typeof DefaultStory>;
31
52
 
32
53
  export default meta;
33
54
 
34
- type Story = StoryObj<typeof meta>;
55
+ export const _Form: StoryObj<typeof DefaultStory<Person.Person>> = {
56
+ args: {
57
+ Component: FormCard,
58
+ createObject: createPerson,
59
+ image: true,
60
+ },
61
+ };
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
+ };
35
71
 
36
- export const Popover: Story = {
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> = {
37
78
  args: {
38
- role: 'card--popover',
39
- cards: createCards(),
79
+ Component: FormCard,
80
+ createObject: createUnknown,
40
81
  },
41
82
  };
42
83
 
43
- export const Intrinsic: Story = {
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>> = {
44
90
  args: {
45
- role: 'card--intrinsic',
46
- cards: createCards(),
91
+ Component: FormCard,
92
+ createObject: createPersonEmpty,
47
93
  },
48
94
  };
49
95
 
50
- export const Extrinsic: Story = {
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>> = {
51
103
  args: {
52
- role: 'card--extrinsic',
53
- cards: createCards(),
104
+ Component: FormCard,
105
+ createObject: createTableEmpty,
54
106
  },
55
107
  };
56
108
 
57
- export const ExtrinsicNoImage: Story = {
109
+ export const _Person: StoryObj<typeof DefaultStory<Person.Person>> = {
58
110
  args: {
59
- role: 'card--extrinsic',
60
- cards: createCards(false),
111
+ Component: PersonCard,
112
+ createObject: createPerson,
113
+ image: true,
114
+ },
115
+ };
116
+
117
+ export const _Organization: StoryObj<typeof DefaultStory<Organization.Organization>> = {
118
+ args: {
119
+ Component: OrganizationCard,
120
+ createObject: createOrganization,
121
+ image: true,
122
+ },
123
+ };
124
+
125
+ export const _Project: StoryObj<typeof DefaultStory<Pipeline.Pipeline>> = {
126
+ args: {
127
+ Component: ProjectCard,
128
+ createObject: createProject,
129
+ image: true,
130
+ },
131
+ };
132
+
133
+ export const _Task: StoryObj<typeof DefaultStory<Task.Task>> = {
134
+ args: {
135
+ Component: TaskCard,
136
+ createObject: createTask,
137
+ image: true,
138
+ },
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
+ );
61
176
  },
62
177
  };
@@ -2,112 +2,152 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React, { type FC } from 'react';
5
+ import * as Schema from 'effect/Schema';
6
+ import React, { type FC, useMemo } from 'react';
6
7
 
7
- import { Obj, Ref } from '@dxos/echo';
8
- import { faker } from '@dxos/random';
9
- import { CardContainer } from '@dxos/react-ui-stack/testing';
10
- import { DataType } from '@dxos/schema';
8
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
9
+ import { DXN, Obj, Ref, Type } from '@dxos/echo';
10
+ import { Annotation } from '@dxos/echo';
11
+ import { random } from '@dxos/random';
12
+ import { Card } from '@dxos/react-ui';
13
+ import { CardContainer, type CardContainerProps } from '@dxos/react-ui-mosaic/testing';
14
+ import { Expando } from '@dxos/schema';
15
+ import { Organization, Person, Pipeline, Task } from '@dxos/types';
11
16
 
12
- import { ContactCard, OrganizationCard, ProjectCard, TaskCard } from '../cards';
13
- import { type PreviewProps } from '../types';
14
-
15
- type CardProps<T extends Obj.Any> = {
16
- Component: FC<PreviewProps<T>>;
17
- subject: T;
18
- icon?: string;
17
+ export type DefaultStoryProps<T extends Obj.Any, P extends {} = {}> = {
18
+ Component: FC<AppSurface.ObjectCardProps<T> & P>;
19
+ createObject: () => T;
19
20
  image?: boolean;
21
+ componentProps?: P;
20
22
  };
21
23
 
22
- export type DefaultstoryProps = {
23
- role: 'card--popover' | 'card--intrinsic' | 'card--extrinsic' | 'card--transclusion';
24
- cards: CardProps<any>[];
25
- };
24
+ export const DefaultStory = <T extends Obj.Any, P extends {} = {}>({
25
+ Component,
26
+ createObject,
27
+ image,
28
+ componentProps,
29
+ }: DefaultStoryProps<T, P>) => {
30
+ const object = useMemo(() => createObject(), [createObject]);
31
+ const roles: CardContainerProps['role'][] = ['intrinsic', 'popover'];
26
32
 
27
- export const Defaultstory = ({ role, cards }: DefaultstoryProps) => {
28
33
  return (
29
- <div className='flex bs-full'>
30
- <div className='flex shrink-0 gap-8 overflow-x-auto pbe-4'>
31
- {cards.map(({ Component, icon, image, subject }, i) => (
32
- <div key={i} className='flex is-[24rem] justify-center'>
33
- <CardContainer icon={icon} role={role}>
34
- <Component role={role} subject={image ? subject : omitImage(subject)} />
34
+ <div className='h-full w-full grid grid-cols-2 py-16 gap-8'>
35
+ {roles.map((role, i) => (
36
+ <div key={i} className='flex h-full justify-center overflow-hidden'>
37
+ <div className='flex flex-col gap-4 w-full items-center'>
38
+ <span className='text-sm text-description'>{role}</span>
39
+ <CardContainer role={role}>
40
+ <Card.Root border={false}>
41
+ <Card.Header>
42
+ <Card.DragHandle />
43
+ <Card.Title>{Obj.getLabel(object)}</Card.Title>
44
+ <Card.Menu />
45
+ </Card.Header>
46
+ <Component
47
+ role={role ?? 'card--content'}
48
+ subject={image ? object : omitImage(object)}
49
+ {...(componentProps ?? ({} as P))}
50
+ />
51
+ </Card.Root>
35
52
  </CardContainer>
36
53
  </div>
37
- ))}
38
- </div>
54
+ </div>
55
+ ))}
39
56
  </div>
40
57
  );
41
58
  };
42
59
 
43
60
  export const omitImage = ({ image: _, ...rest }: any) => rest;
44
61
 
45
- // TODO(burdon): Test data should exercise the standard data generators.
46
- export const createCards = (image = true): CardProps<any>[] => {
47
- const organization = Obj.make(DataType.Organization, {
48
- name: faker.company.name(),
62
+ /**
63
+ * Factory functions for creating test objects at render time.
64
+ */
65
+ export const createOrganization = (): Organization.Organization => {
66
+ return Obj.make(Organization.Organization, {
67
+ name: random.company.name(),
49
68
  image:
50
69
  'https://plus.unsplash.com/premium_photo-1672116452571-896980a801c8?q=80&w=2671&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
51
- website: faker.internet.url(),
52
- description: faker.lorem.paragraph(),
70
+ website: random.internet.url(),
71
+ description: random.lorem.paragraph(),
53
72
  });
73
+ };
54
74
 
55
- const contact = Obj.make(DataType.Person, {
56
- fullName: faker.person.fullName(),
75
+ export const createPerson = (): Person.Person => {
76
+ const organization = createOrganization();
77
+ return Obj.make(Person.Person, {
78
+ fullName: random.person.fullName(),
57
79
  image:
58
80
  'https://plus.unsplash.com/premium_photo-1664536392779-049ba8fde933?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
59
81
  organization: Ref.make(organization),
60
82
  emails: [
61
- {
62
- label: 'Work',
63
- value: faker.internet.email(),
64
- },
65
- {
66
- label: 'Work',
67
- value: faker.internet.email(),
68
- },
69
- {
70
- label: 'Work',
71
- value: faker.internet.email(),
72
- },
83
+ { label: 'Work', value: random.internet.email() },
84
+ { label: 'Work', value: random.internet.email() },
85
+ { label: 'Work', value: random.internet.email() },
73
86
  ],
74
87
  });
88
+ };
75
89
 
76
- const project = DataType.makeProject({
77
- name: faker.person.fullName(),
90
+ export const createProject = (): Pipeline.Pipeline => {
91
+ return Obj.make(Pipeline.Pipeline, {
92
+ name: random.person.fullName(),
78
93
  image: 'https://dxos.network/dxos-logotype-blue.png',
79
- description: faker.lorem.paragraph(),
94
+ description: random.lorem.paragraph(),
95
+ columns: [],
80
96
  });
97
+ };
81
98
 
82
- const task = Obj.make(DataType.Task, {
83
- title: faker.lorem.sentence(),
84
- status: faker.helpers.arrayElement(['todo', 'in-progress', 'done']),
99
+ export const createTask = (): Task.Task => {
100
+ return Obj.make(Task.Task, {
101
+ title: random.lorem.sentence(),
102
+ status: random.helpers.arrayElement(['todo', 'in-progress', 'done'] as const),
85
103
  });
104
+ };
86
105
 
87
- return [
88
- {
89
- Component: OrganizationCard,
90
- subject: organization,
91
- icon: 'ph--building-office--regular',
92
- image,
93
- },
94
- {
95
- Component: ContactCard,
96
- subject: contact,
97
- icon: 'ph--user--regular',
98
- image,
99
- },
100
- {
101
- Component: ProjectCard,
102
- subject: project,
103
- icon: 'ph--building--regular',
104
- image,
105
- },
106
- {
107
- Component: TaskCard,
108
- subject: task,
109
- icon: 'ph--list-checks--regular',
110
- image,
111
- },
112
- ];
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.table-like', '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
+ });
113
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';
@@ -4,19 +4,19 @@
4
4
 
5
5
  import { type Resource } from '@dxos/react-ui';
6
6
 
7
- import { meta } from './meta';
7
+ import { meta } from '#meta';
8
8
 
9
9
  export const translations = [
10
10
  {
11
11
  'en-US': {
12
12
  [meta.id]: {
13
- 'unable to create preview message': 'No preview',
14
- 'todo label': 'To do',
15
- 'in-progress label': 'In progress',
16
- 'done label': 'Done',
17
- 'open object label': 'Open',
18
- 'add object to space label': 'Add to space',
19
- 'more options label': 'More options',
13
+ 'unable-to-create-preview.message': 'No preview',
14
+ 'todo.label': 'To do',
15
+ 'in-progress.label': 'In progress',
16
+ 'done.label': 'Done',
17
+ 'open-object.label': 'Open',
18
+ 'add-object-to-space.label': 'Add to space',
19
+ 'more-options.label': 'More options',
20
20
  },
21
21
  },
22
22
  },
@@ -1,12 +0,0 @@
1
- // src/meta.ts
2
- var meta = {
3
- id: "dxos.org/plugin/preview",
4
- name: "Preview",
5
- icon: "ph--eye--regular",
6
- source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview"
7
- };
8
-
9
- export {
10
- meta
11
- };
12
- //# sourceMappingURL=chunk-XKCIQK3C.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const meta: PluginMeta = {\n id: 'dxos.org/plugin/preview',\n name: 'Preview',\n icon: 'ph--eye--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview',\n};\n"],
5
- "mappings": ";AAMO,IAAMA,OAAmB;EAC9BC,IAAI;EACJC,MAAM;EACNC,MAAM;EACNC,QAAQ;AACV;",
6
- "names": ["meta", "id", "name", "icon", "source"]
7
- }