@dxos/plugin-preview 0.8.4-main.f5c0578 → 0.8.4-main.fcc0d83b33

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 (93) hide show
  1. package/dist/lib/browser/index.mjs +33 -53
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/translations.mjs +21 -0
  5. package/dist/lib/browser/translations.mjs.map +7 -0
  6. package/dist/lib/node-esm/index.mjs +33 -52
  7. package/dist/lib/node-esm/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/meta.json +1 -1
  9. package/dist/lib/node-esm/translations.mjs +23 -0
  10. package/dist/lib/node-esm/translations.mjs.map +7 -0
  11. package/dist/types/src/PreviewPlugin.d.ts +2 -1
  12. package/dist/types/src/PreviewPlugin.d.ts.map +1 -1
  13. package/dist/types/src/capabilities/index.d.ts +3 -2
  14. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  15. package/dist/types/src/capabilities/preview-popover.d.ts +3 -2
  16. package/dist/types/src/capabilities/preview-popover.d.ts.map +1 -1
  17. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  18. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  19. package/dist/types/src/cards/ExpandoCard.d.ts +4 -0
  20. package/dist/types/src/cards/ExpandoCard.d.ts.map +1 -0
  21. package/dist/types/src/cards/FormCard.d.ts +7 -0
  22. package/dist/types/src/cards/FormCard.d.ts.map +1 -0
  23. package/dist/types/src/cards/JsonCard.d.ts +5 -0
  24. package/dist/types/src/cards/JsonCard.d.ts.map +1 -0
  25. package/dist/types/src/cards/OrganizationCard.d.ts +5 -0
  26. package/dist/types/src/cards/OrganizationCard.d.ts.map +1 -0
  27. package/dist/types/src/cards/PersonCard.d.ts +5 -0
  28. package/dist/types/src/cards/PersonCard.d.ts.map +1 -0
  29. package/dist/types/src/cards/ProjectCard.d.ts +5 -0
  30. package/dist/types/src/cards/ProjectCard.d.ts.map +1 -0
  31. package/dist/types/src/cards/TaskCard.d.ts +5 -0
  32. package/dist/types/src/cards/TaskCard.d.ts.map +1 -0
  33. package/dist/types/src/cards/index.d.ts +8 -0
  34. package/dist/types/src/cards/index.d.ts.map +1 -0
  35. package/dist/types/src/index.d.ts +0 -1
  36. package/dist/types/src/index.d.ts.map +1 -1
  37. package/dist/types/src/meta.d.ts +2 -3
  38. package/dist/types/src/meta.d.ts.map +1 -1
  39. package/dist/types/src/stories/Card.stories.d.ts +34 -46
  40. package/dist/types/src/stories/Card.stories.d.ts.map +1 -1
  41. package/dist/types/src/stories/testing.d.ts +17 -14
  42. package/dist/types/src/stories/testing.d.ts.map +1 -1
  43. package/dist/types/src/translations.d.ts +8 -3
  44. package/dist/types/src/translations.d.ts.map +1 -1
  45. package/dist/types/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +56 -37
  47. package/src/PreviewPlugin.tsx +17 -29
  48. package/src/capabilities/index.ts +3 -3
  49. package/src/capabilities/preview-popover.ts +72 -50
  50. package/src/capabilities/react-surface.tsx +106 -151
  51. package/src/cards/ExpandoCard.tsx +76 -0
  52. package/src/cards/FormCard.tsx +48 -0
  53. package/src/cards/JsonCard.tsx +19 -0
  54. package/src/cards/OrganizationCard.tsx +29 -0
  55. package/src/cards/PersonCard.tsx +65 -0
  56. package/src/cards/ProjectCard.tsx +22 -0
  57. package/src/cards/TaskCard.tsx +44 -0
  58. package/src/cards/index.ts +11 -0
  59. package/src/index.ts +0 -1
  60. package/src/meta.ts +8 -5
  61. package/src/stories/Card.stories.tsx +96 -28
  62. package/src/stories/testing.tsx +66 -68
  63. package/src/translations.ts +8 -2
  64. package/dist/lib/browser/chunk-Z73ENKLE.mjs +0 -14
  65. package/dist/lib/browser/chunk-Z73ENKLE.mjs.map +0 -7
  66. package/dist/lib/browser/preview-popover-MAIBTJKJ.mjs +0 -69
  67. package/dist/lib/browser/preview-popover-MAIBTJKJ.mjs.map +0 -7
  68. package/dist/lib/browser/react-surface-H4RYYXVQ.mjs +0 -379
  69. package/dist/lib/browser/react-surface-H4RYYXVQ.mjs.map +0 -7
  70. package/dist/lib/node-esm/chunk-2ORSL4GJ.mjs +0 -16
  71. package/dist/lib/node-esm/chunk-2ORSL4GJ.mjs.map +0 -7
  72. package/dist/lib/node-esm/preview-popover-LZGHYW23.mjs +0 -71
  73. package/dist/lib/node-esm/preview-popover-LZGHYW23.mjs.map +0 -7
  74. package/dist/lib/node-esm/react-surface-4C44XCLH.mjs +0 -380
  75. package/dist/lib/node-esm/react-surface-4C44XCLH.mjs.map +0 -7
  76. package/dist/types/src/components/CardSubjectMenu.d.ts +0 -10
  77. package/dist/types/src/components/CardSubjectMenu.d.ts.map +0 -1
  78. package/dist/types/src/components/ContactCard.d.ts +0 -7
  79. package/dist/types/src/components/ContactCard.d.ts.map +0 -1
  80. package/dist/types/src/components/OrganizationCard.d.ts +0 -5
  81. package/dist/types/src/components/OrganizationCard.d.ts.map +0 -1
  82. package/dist/types/src/components/ProjectCard.d.ts +0 -5
  83. package/dist/types/src/components/ProjectCard.d.ts.map +0 -1
  84. package/dist/types/src/components/index.d.ts +0 -4
  85. package/dist/types/src/components/index.d.ts.map +0 -1
  86. package/dist/types/src/types.d.ts +0 -7
  87. package/dist/types/src/types.d.ts.map +0 -1
  88. package/src/components/CardSubjectMenu.tsx +0 -56
  89. package/src/components/ContactCard.tsx +0 -76
  90. package/src/components/OrganizationCard.tsx +0 -44
  91. package/src/components/ProjectCard.tsx +0 -27
  92. package/src/components/index.ts +0 -7
  93. package/src/types.ts +0 -11
@@ -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
+ };
@@ -0,0 +1,48 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React, { useCallback, useMemo } from 'react';
6
+
7
+ 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';
12
+ import { type ProjectionModel } from '@dxos/schema';
13
+ import { descriptionMessage, mx } from '@dxos/ui-theme';
14
+
15
+ import { meta } from '#meta';
16
+
17
+ export const FormCard = ({ subject, projection }: AppSurface.ObjectCardProps & { projection?: ProjectionModel }) => {
18
+ 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.update(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>;
35
+ }
36
+
37
+ return (
38
+ <Card.Content>
39
+ <Form.Root schema={schema} projection={projection} values={subject} autoSave onSave={handleSave}>
40
+ <Form.Viewport>
41
+ <Form.Content>
42
+ <Form.FieldSet />
43
+ </Form.Content>
44
+ </Form.Viewport>
45
+ </Form.Root>
46
+ </Card.Content>
47
+ );
48
+ };
@@ -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.Content>
13
+ <span />
14
+ {/* TODO(wittjosiah): Span whole row. */}
15
+ <JsonHighlighter data={data} />
16
+ <span />
17
+ </Card.Content>
18
+ );
19
+ };
@@ -0,0 +1,29 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
8
+ import { Card } from '@dxos/react-ui';
9
+ import { type Organization } from '@dxos/types';
10
+
11
+ export const OrganizationCard = ({ subject }: AppSurface.ObjectCardProps<Organization.Organization>) => {
12
+ const { name, image, description, website } = subject;
13
+
14
+ return (
15
+ <Card.Content>
16
+ <Card.Poster
17
+ alt={name ?? ''}
18
+ {...(image ? { image } : { icon: 'ph--building-office--regular' })}
19
+ classNames={!image && 'opacity-50'}
20
+ />
21
+ {description && (
22
+ <Card.Row>
23
+ <Card.Text variant='description'>{description}</Card.Text>
24
+ </Card.Row>
25
+ )}
26
+ {website && <Card.Link label={website} href={website} />}
27
+ </Card.Content>
28
+ );
29
+ };
@@ -0,0 +1,65 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+ import React, { useCallback } from 'react';
7
+
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';
13
+ import { Avatar } from '@dxos/react-ui';
14
+ import { Card } from '@dxos/react-ui';
15
+ import { type Person } from '@dxos/types';
16
+
17
+ export const PersonCard = ({ subject }: AppSurface.ObjectCardProps<Person.Person>) => {
18
+ const { invoke } = useOperationInvoker();
19
+ const { image, organization: { target: organization } = {}, emails = [] } = subject;
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
+
37
+ return (
38
+ <Card.Content>
39
+ <Avatar.Root>
40
+ {image && (
41
+ <Card.Row className='py-1'>
42
+ <Avatar.Content
43
+ imgSrc={image}
44
+ icon='ph--user--regular'
45
+ size={20}
46
+ classNames={!image && 'opacity-50'}
47
+ hue='neutral'
48
+ variant='square'
49
+ />
50
+ </Card.Row>
51
+ )}
52
+ {organization?.name && (
53
+ <Card.Action icon='ph--buildings--regular' label={organization.name} onClick={handleOrganizationClick} />
54
+ )}
55
+ {emails.map(({ value }) => (
56
+ <Card.Row key={value} icon='ph--at--regular'>
57
+ <Card.Text truncate className='text-primary-text'>
58
+ {value}
59
+ </Card.Text>
60
+ </Card.Row>
61
+ ))}
62
+ </Avatar.Root>
63
+ </Card.Content>
64
+ );
65
+ };
@@ -0,0 +1,22 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
8
+ import { Obj } from '@dxos/echo';
9
+ import { Card } from '@dxos/react-ui';
10
+ import { type Pipeline } from '@dxos/types';
11
+
12
+ export const ProjectCard = ({ subject }: AppSurface.ObjectCardProps<Pipeline.Pipeline>) => {
13
+ const { image, description } = subject;
14
+
15
+ return (
16
+ <Card.Content>
17
+ {image && <Card.Poster image={image} alt={Obj.getLabel(subject) ?? ''} aspect='auto' />}
18
+ {/* <CardHeader label={name} subject={subject} db={db} /> */}
19
+ {description && <Card.Text variant='description'>{description}</Card.Text>}
20
+ </Card.Content>
21
+ );
22
+ };
@@ -0,0 +1,44 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as SchemaAST from 'effect/SchemaAST';
6
+ import React from 'react';
7
+
8
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
9
+ import { type PropertyMetaAnnotation, PropertyMetaAnnotationId } from '@dxos/echo/internal';
10
+ import { Card } from '@dxos/react-ui';
11
+ import { Task } from '@dxos/types';
12
+
13
+ export const TaskCard = ({ subject }: AppSurface.ObjectCardProps<Task.Task>) => {
14
+ const { title, status } = subject;
15
+ const statusOption = getActiveStatusOption(status);
16
+
17
+ return (
18
+ <Card.Content>
19
+ <Card.Row>
20
+ {statusOption && (
21
+ <div>
22
+ <span className='dx-tag' data-hue={statusOption.color}>
23
+ {statusOption.title}
24
+ </span>
25
+ </div>
26
+ )}
27
+ </Card.Row>
28
+ </Card.Content>
29
+ );
30
+ };
31
+
32
+ // TODO(thure): Should this move upstream as a helper? Is there an easier way to get options?
33
+ const getActiveStatusOption = (status?: string) => {
34
+ const properties = SchemaAST.getPropertySignatures(Task.Task.ast);
35
+ const statusProperty = properties.find((p) => p.name === 'status');
36
+ // TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
37
+ const statusMeta = SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(
38
+ (statusProperty!.type as any).types[0],
39
+ );
40
+
41
+ // TODO(thure): Typescript asserts `statusMeta` doesn’t have `.value`, but in runtime it does.
42
+ const options = (statusMeta as any).value.singleSelect.options as { id: string; title: string; color: string }[];
43
+ return options.find(({ id }) => id === status);
44
+ };
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './ExpandoCard';
6
+ export * from './FormCard';
7
+ export * from './JsonCard';
8
+ export * from './OrganizationCard';
9
+ export * from './PersonCard';
10
+ export * from './ProjectCard';
11
+ export * from './TaskCard';
package/src/index.ts CHANGED
@@ -3,6 +3,5 @@
3
3
  //
4
4
 
5
5
  export * from './meta';
6
- export type * from './types';
7
6
 
8
7
  export * from './PreviewPlugin';
package/src/meta.ts CHANGED
@@ -2,13 +2,16 @@
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 PREVIEW_PLUGIN = 'dxos.org/plugin/preview';
8
-
9
- export const meta: PluginMeta = {
10
- id: PREVIEW_PLUGIN,
8
+ export const meta: Plugin.Meta = {
9
+ id: 'org.dxos.plugin.preview',
11
10
  name: 'Preview',
11
+ description: trim`
12
+ Rich preview panel for viewing object content without opening full editors.
13
+ Quick peek at documents, images, and data with inline rendering.
14
+ `,
12
15
  icon: 'ph--eye--regular',
13
16
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview',
14
17
  };
@@ -2,52 +2,120 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import React from 'react';
7
+
8
+ import { withPluginManager } from '@dxos/app-framework/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';
8
15
 
9
- import { withLayout, withTheme } from '@dxos/storybook-utils';
16
+ import { translations } from '#translations';
10
17
 
11
- import { translations } from '../translations';
18
+ import { ExpandoCard, FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
19
+ import { DefaultStory, createExpando, createOrganization, createPerson, createProject, createTask } from './testing';
12
20
 
13
- import { Defaultstory, type DefaultstoryProps, createCards } from './testing';
21
+ random.seed(999);
14
22
 
15
- const meta: Meta<DefaultstoryProps> = {
16
- title: 'plugins/plugin-preview/Card',
17
- render: Defaultstory,
18
- decorators: [withTheme, withLayout({ fullscreen: true, classNames: 'flex flex-col justify-center' })],
19
- parameters: { translations },
23
+ const meta = {
24
+ title: 'plugins/plugin-preview/cards/Card',
25
+ render: DefaultStory,
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(),
32
+ withLayout({ layout: 'fullscreen' }),
33
+ // TODO(wittjosiah): Try to write story which does not depend on plugin manager.
34
+ withPluginManager({ plugins: corePlugins() }),
35
+ ],
36
+ parameters: {
37
+ layout: 'fullscreen',
38
+ translations,
39
+ },
20
40
  tags: ['cards'],
21
- };
41
+ } satisfies Meta<typeof DefaultStory>;
22
42
 
23
43
  export default meta;
24
44
 
25
- type Story = StoryObj<DefaultstoryProps>;
45
+ export const _Form: StoryObj<typeof DefaultStory<Person.Person>> = {
46
+ args: {
47
+ Component: FormCard,
48
+ createObject: createPerson,
49
+ image: true,
50
+ },
51
+ };
26
52
 
27
- export const Popover = {
53
+ export const _Person: StoryObj<typeof DefaultStory<Person.Person>> = {
28
54
  args: {
29
- role: 'card--popover',
30
- cards: createCards(),
55
+ Component: PersonCard,
56
+ createObject: createPerson,
57
+ image: true,
31
58
  },
32
- } satisfies Story;
59
+ };
33
60
 
34
- export const Intrinsic = {
61
+ export const _Organization: StoryObj<typeof DefaultStory<Organization.Organization>> = {
35
62
  args: {
36
- role: 'card--intrinsic',
37
- cards: createCards(),
63
+ Component: OrganizationCard,
64
+ createObject: createOrganization,
65
+ image: true,
38
66
  },
39
- } satisfies Story;
67
+ };
40
68
 
41
- export const Extrinsic = {
69
+ export const _Project: StoryObj<typeof DefaultStory<Pipeline.Pipeline>> = {
42
70
  args: {
43
- role: 'card--extrinsic',
44
- cards: createCards(),
71
+ Component: ProjectCard,
72
+ createObject: createProject,
73
+ image: true,
45
74
  },
46
- } satisfies Story;
75
+ };
47
76
 
48
- export const ExtrinsicNoImage = {
77
+ export const _Task: StoryObj<typeof DefaultStory<Task.Task>> = {
49
78
  args: {
50
- role: 'card--extrinsic',
51
- cards: createCards(false),
79
+ Component: TaskCard,
80
+ createObject: createTask,
81
+ image: true,
52
82
  },
53
- } satisfies Story;
83
+ };
84
+
85
+ export const _Expando: StoryObj<typeof DefaultStory<Expando.Expando>> = {
86
+ args: {
87
+ Component: ExpandoCard,
88
+ createObject: createExpando,
89
+ },
90
+ };
91
+
92
+ export const _Json = {
93
+ render: () => {
94
+ const data = {
95
+ subject: {
96
+ id: random.string.uuid(),
97
+ name: random.person.fullName(),
98
+ email: random.internet.email(),
99
+ tags: [random.lorem.word(), random.lorem.word(), random.lorem.word()],
100
+ nested: {
101
+ count: random.number.int({ max: 100 }),
102
+ active: random.datatype.boolean(),
103
+ },
104
+ },
105
+ };
106
+
107
+ return (
108
+ <div className='flex justify-center p-16'>
109
+ <div className='dx-card-min-width dx-card-max-width'>
110
+ <Card.Root>
111
+ <Card.Toolbar>
112
+ <Card.IconBlock />
113
+ <Card.Title>JSON</Card.Title>
114
+ </Card.Toolbar>
115
+ <JsonCard data={data} />
116
+ </Card.Root>
117
+ </div>
118
+ </div>
119
+ );
120
+ },
121
+ };
@@ -2,39 +2,43 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import type { Meta } from '@storybook/react-vite';
6
- import React, { type FC } from 'react';
5
+ import React, { type FC, useMemo } from 'react';
7
6
 
7
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
8
8
  import { Obj, Ref } from '@dxos/echo';
9
- import { faker } from '@dxos/random';
10
- import { CardContainer } from '@dxos/react-ui-stack/testing';
11
- import { DataType } from '@dxos/schema';
9
+ import { random } from '@dxos/random';
10
+ import { Card } from '@dxos/react-ui';
11
+ import { CardContainer, type CardContainerProps } from '@dxos/react-ui-mosaic/testing';
12
+ import { Expando } from '@dxos/schema';
13
+ import { Organization, Person, Pipeline, Task } from '@dxos/types';
12
14
 
13
- import { ContactCard, OrganizationCard, ProjectCard } from '../components';
14
- import { type PreviewProps } from '../types';
15
-
16
- faker.seed(1234);
17
-
18
- type CardProps<T extends object> = {
19
- Component: FC<PreviewProps<T>>;
20
- subject: T;
21
- icon?: string;
15
+ export type DefaultStoryProps<T extends Obj.Any> = {
16
+ Component: FC<AppSurface.ObjectCardProps<T>>;
17
+ createObject: () => T;
22
18
  image?: boolean;
23
19
  };
24
20
 
25
- export type DefaultstoryProps = {
26
- role: 'card--popover' | 'card--intrinsic' | 'card--extrinsic' | 'card--transclusion';
27
- cards: CardProps<any>[];
28
- };
21
+ export const DefaultStory = <T extends Obj.Any>({ Component, createObject, image }: DefaultStoryProps<T>) => {
22
+ const object = useMemo(() => createObject(), [createObject]);
23
+ const roles: CardContainerProps['role'][] = ['intrinsic', 'popover'];
29
24
 
30
- export const Defaultstory: Meta<DefaultstoryProps>['render'] = ({ role, cards }) => {
31
25
  return (
32
- <div className='grid grid-cols-3'>
33
- {cards.map(({ Component, icon, image, subject }, i) => (
34
- <div key={i} className='flex justify-center'>
35
- <CardContainer icon={icon} role={role}>
36
- <Component role={role} subject={image ? subject : omitImage(subject)} />
37
- </CardContainer>
26
+ <div className='h-full w-full grid grid-cols-2 py-16 gap-8'>
27
+ {roles.map((role, i) => (
28
+ <div key={i} className='flex h-full justify-center overflow-hidden'>
29
+ <div className='flex flex-col gap-4 w-full items-center'>
30
+ <span className='text-sm text-description'>{role}</span>
31
+ <CardContainer role={role}>
32
+ <Card.Root border={false}>
33
+ <Card.Toolbar>
34
+ <Card.DragHandle />
35
+ <Card.Title>{Obj.getLabel(object)}</Card.Title>
36
+ <Card.Menu />
37
+ </Card.Toolbar>
38
+ <Component role={role ?? 'card--content'} subject={image ? object : omitImage(object)} />
39
+ </Card.Root>
40
+ </CardContainer>
41
+ </div>
38
42
  </div>
39
43
  ))}
40
44
  </div>
@@ -43,61 +47,55 @@ export const Defaultstory: Meta<DefaultstoryProps>['render'] = ({ role, cards })
43
47
 
44
48
  export const omitImage = ({ image: _, ...rest }: any) => rest;
45
49
 
46
- // TODO(burdon): Test data should exercise the standard data generators.
47
- export const createCards = (image = true): CardProps<any>[] => {
48
- const organization = Obj.make(DataType.Organization, {
49
- name: faker.company.name(),
50
+ /**
51
+ * Factory functions for creating test objects at render time.
52
+ */
53
+ export const createOrganization = (): Organization.Organization => {
54
+ return Obj.make(Organization.Organization, {
55
+ name: random.company.name(),
50
56
  image:
51
57
  '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',
52
- website: faker.internet.url(),
53
- description: faker.lorem.paragraph(),
58
+ website: random.internet.url(),
59
+ description: random.lorem.paragraph(),
54
60
  });
61
+ };
55
62
 
56
- const contact = Obj.make(DataType.Person, {
57
- fullName: faker.person.fullName(),
63
+ export const createPerson = (): Person.Person => {
64
+ const organization = createOrganization();
65
+ return Obj.make(Person.Person, {
66
+ fullName: random.person.fullName(),
58
67
  image:
59
68
  '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',
60
69
  organization: Ref.make(organization),
61
70
  emails: [
62
- {
63
- label: 'Work',
64
- value: faker.internet.email(),
65
- },
66
- {
67
- label: 'Work',
68
- value: faker.internet.email(),
69
- },
70
- {
71
- label: 'Work',
72
- value: faker.internet.email(),
73
- },
71
+ { label: 'Work', value: random.internet.email() },
72
+ { label: 'Work', value: random.internet.email() },
73
+ { label: 'Work', value: random.internet.email() },
74
74
  ],
75
75
  });
76
+ };
76
77
 
77
- const project = Obj.make(DataType.Project, {
78
- name: faker.person.fullName(),
78
+ export const createProject = (): Pipeline.Pipeline => {
79
+ return Obj.make(Pipeline.Pipeline, {
80
+ name: random.person.fullName(),
79
81
  image: 'https://dxos.network/dxos-logotype-blue.png',
80
- description: faker.lorem.paragraph(),
82
+ description: random.lorem.paragraph(),
83
+ columns: [],
81
84
  });
85
+ };
82
86
 
83
- return [
84
- {
85
- Component: OrganizationCard,
86
- subject: organization,
87
- icon: 'ph--building-office--regular',
88
- image,
89
- },
90
- {
91
- Component: ContactCard,
92
- subject: contact,
93
- icon: 'ph--user--regular',
94
- image,
95
- },
96
- {
97
- Component: ProjectCard,
98
- subject: project,
99
- icon: 'ph--building--regular',
100
- image,
101
- },
102
- ];
87
+ export const createTask = (): Task.Task => {
88
+ return Obj.make(Task.Task, {
89
+ title: random.lorem.sentence(),
90
+ status: random.helpers.arrayElement(['todo', 'in-progress', 'done'] as const),
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
+ });
103
101
  };