@dxos/plugin-preview 0.8.4-main.e8ec1fe → 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 (125) 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-CEWM5LJG.mjs → neutral/chunk-XD3EYTHF.mjs} +7 -3
  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 +2 -2
  50. package/dist/types/src/cards/OrganizationCard.d.ts.map +1 -1
  51. package/dist/types/src/cards/PersonCard.d.ts +2 -2
  52. package/dist/types/src/cards/PersonCard.d.ts.map +1 -1
  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 +2 -2
  56. package/dist/types/src/cards/TaskCard.d.ts.map +1 -1
  57. package/dist/types/src/cards/index.d.ts +3 -0
  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 +43 -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 -40
  75. package/src/PreviewPlugin.node.ts +16 -0
  76. package/src/PreviewPlugin.test.ts +25 -0
  77. package/src/PreviewPlugin.tsx +16 -25
  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 +131 -143
  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 +11 -16
  86. package/src/cards/PersonCard.tsx +51 -49
  87. package/src/cards/ProjectCard.tsx +9 -11
  88. package/src/cards/TaskCard.tsx +26 -27
  89. package/src/cards/index.ts +3 -0
  90. package/src/index.ts +0 -3
  91. package/src/meta.ts +5 -3
  92. package/src/plugin.ts +9 -0
  93. package/src/stories/Card.stories.tsx +139 -24
  94. package/src/stories/testing.tsx +117 -78
  95. package/src/testing.ts +7 -0
  96. package/src/translations.ts +8 -8
  97. package/dist/lib/browser/chunk-CEWM5LJG.mjs.map +0 -7
  98. package/dist/lib/browser/index.mjs +0 -64
  99. package/dist/lib/browser/index.mjs.map +0 -7
  100. package/dist/lib/browser/meta.json +0 -1
  101. package/dist/lib/browser/preview-popover-IAPAEKZL.mjs +0 -65
  102. package/dist/lib/browser/preview-popover-IAPAEKZL.mjs.map +0 -7
  103. package/dist/lib/browser/react-surface-LRMZKOJS.mjs +0 -498
  104. package/dist/lib/browser/react-surface-LRMZKOJS.mjs.map +0 -7
  105. package/dist/lib/node-esm/chunk-Q5MUNELK.mjs +0 -19
  106. package/dist/lib/node-esm/chunk-Q5MUNELK.mjs.map +0 -7
  107. package/dist/lib/node-esm/index.mjs +0 -65
  108. package/dist/lib/node-esm/index.mjs.map +0 -7
  109. package/dist/lib/node-esm/meta.json +0 -1
  110. package/dist/lib/node-esm/preview-popover-CH2LDYWM.mjs +0 -67
  111. package/dist/lib/node-esm/preview-popover-CH2LDYWM.mjs.map +0 -7
  112. package/dist/lib/node-esm/react-surface-65UVGBIZ.mjs +0 -499
  113. package/dist/lib/node-esm/react-surface-65UVGBIZ.mjs.map +0 -7
  114. package/dist/types/src/components/CardComponents.d.ts +0 -16
  115. package/dist/types/src/components/CardComponents.d.ts.map +0 -1
  116. package/dist/types/src/components/CardSubjectMenu.d.ts +0 -8
  117. package/dist/types/src/components/CardSubjectMenu.d.ts.map +0 -1
  118. package/dist/types/src/components/index.d.ts +0 -3
  119. package/dist/types/src/components/index.d.ts.map +0 -1
  120. package/dist/types/src/types.d.ts +0 -12
  121. package/dist/types/src/types.d.ts.map +0 -1
  122. package/src/components/CardComponents.tsx +0 -67
  123. package/src/components/CardSubjectMenu.tsx +0 -103
  124. package/src/components/index.ts +0 -6
  125. package/src/types.ts +0 -29
@@ -2,156 +2,144 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React, { useCallback } from 'react';
5
+ import * as Effect from 'effect/Effect';
6
+ import React from 'react';
6
7
 
7
- import { Capabilities, LayoutAction, contributes, createIntent, createSurface } from '@dxos/app-framework';
8
- import { Surface, SurfaceCardRole, useIntentDispatcher } from '@dxos/app-framework/react';
9
- import { getSchema, getSpace } from '@dxos/client/echo';
10
- import { Obj } from '@dxos/echo';
11
- import { type JsonPath, setValue } from '@dxos/echo/internal';
12
- import { useActiveSpace } from '@dxos/plugin-space';
13
- import { useTranslation } from '@dxos/react-ui';
14
- import { Form } from '@dxos/react-ui-form';
15
- import { Card } from '@dxos/react-ui-stack';
16
- import { descriptionMessage, mx } from '@dxos/react-ui-theme';
17
- import { type ProjectionModel } from '@dxos/schema';
18
- import { Organization, Person, Project, Task } from '@dxos/types';
8
+ import { Capabilities, Capability } from '@dxos/app-framework';
9
+ import { Surface } from '@dxos/app-framework/ui';
10
+ import { AppSurface } from '@dxos/app-toolkit/ui';
11
+ import { Obj, Type } from '@dxos/echo';
12
+ import { Card } from '@dxos/react-ui';
13
+ import { Expando, type ProjectionModel } from '@dxos/schema';
14
+ import { Organization, Person, Pipeline, Task } from '@dxos/types';
19
15
 
20
- import { OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
21
- import { meta } from '../meta';
22
- import { type CardPreviewProps } from '../types';
16
+ import { ExpandoCard, FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
23
17
 
24
- export default () =>
25
- contributes(Capabilities.ReactSurface, [
26
- //
27
- // Specific schema types.
28
- // TODO(burdon): Create helpers and factor out.
29
- //
18
+ export default Capability.makeModule(() =>
19
+ Effect.succeed(
20
+ Capability.contributes(Capabilities.ReactSurface, [
21
+ //
22
+ // Specific schema types.
23
+ // TODO(burdon): Create helpers and factor out.
24
+ //
30
25
 
31
- // TODO(burdon): Infer Role type.
32
- createSurface<{ subject: Person.Person }>({
33
- id: `${meta.id}/schema-popover--contact`,
34
- role: SurfaceCardRole.literals as any,
35
- filter: (data): data is { subject: Person.Person } => Obj.instanceOf(Person.Person, data.subject),
36
- component: ({ data, role }) => {
37
- const { dispatchPromise: dispatch } = useIntentDispatcher();
38
- const space = getSpace(data.subject);
39
- const activeSpace = useActiveSpace(); // TODO(burdon): Disambiguate with space?
40
- const handleSelect = useCallback<NonNullable<CardPreviewProps['onSelect']>>(
41
- (object) =>
42
- dispatch(
43
- createIntent(LayoutAction.Open, {
44
- part: 'main',
45
- subject: [Obj.getDXN(object).toString()],
46
- options: {
47
- workspace: space?.id,
48
- },
49
- }),
50
- ),
51
- [dispatch],
52
- );
26
+ Surface.create<{ subject: Person.Person }>({
27
+ id: 'schema-popover--contact',
28
+ position: 'first',
29
+ filter: AppSurface.object(AppSurface.Card, Person.Person),
30
+ component: ({ data, role }) => {
31
+ return (
32
+ <>
33
+ <PersonCard role={role} subject={data.subject} />
34
+ <Surface.Surface type={AppSurface.Related} data={data} limit={1} />
35
+ </>
36
+ );
37
+ },
38
+ }),
39
+ Surface.create({
40
+ id: 'schema-popover--organization',
41
+ position: 'first',
42
+ filter: AppSurface.object(AppSurface.Card, Organization.Organization),
43
+ component: ({ data, role }) => {
44
+ return (
45
+ <>
46
+ <OrganizationCard role={role} subject={data.subject} />
47
+ <Surface.Surface type={AppSurface.Related} data={data} limit={1} />
48
+ </>
49
+ );
50
+ },
51
+ }),
52
+ Surface.create({
53
+ id: 'schema-popover--project',
54
+ position: 'first',
55
+ filter: AppSurface.object(AppSurface.Card, Pipeline.Pipeline),
56
+ component: ({ data, role }) => {
57
+ return <ProjectCard role={role} subject={data.subject} />;
58
+ },
59
+ }),
60
+ Surface.create({
61
+ id: 'schema-popover--task',
62
+ position: 'first',
63
+ filter: AppSurface.object(AppSurface.Card, Task.Task),
64
+ component: ({ data, role }) => {
65
+ return <TaskCard role={role} subject={data.subject} />;
66
+ },
67
+ }),
68
+ Surface.create<AppSurface.ObjectCardData<Expando.Expando>>({
69
+ id: 'schema-popover--expando',
70
+ filter: AppSurface.object(AppSurface.Card, Expando.Expando),
71
+ component: ({ data, role }) => {
72
+ return <ExpandoCard role={role} subject={data.subject} ignorePaths={data.ignorePaths} />;
73
+ },
74
+ }),
53
75
 
54
- return (
55
- <PersonCard
56
- role={role as SurfaceCardRole}
57
- subject={data.subject}
58
- activeSpace={activeSpace}
59
- onSelect={handleSelect}
60
- >
61
- {role === 'card--popover' && <Surface role='related' data={data} />}
62
- </PersonCard>
63
- );
64
- },
65
- }),
66
- createSurface({
67
- id: `${meta.id}/schema-popover--organization`,
68
- role: SurfaceCardRole.literals as any,
69
- filter: (data): data is { subject: Organization.Organization } =>
70
- Obj.instanceOf(Organization.Organization, data.subject),
71
- component: ({ data, role }) => {
72
- const activeSpace = useActiveSpace();
73
- return (
74
- <OrganizationCard role={role as SurfaceCardRole} subject={data.subject} activeSpace={activeSpace}>
75
- {role === 'card--popover' && <Surface role='related' data={data} />}
76
- </OrganizationCard>
77
- );
78
- },
79
- }),
80
- createSurface({
81
- id: `${meta.id}/schema-popover--project`,
82
- role: SurfaceCardRole.literals as any,
83
- filter: (data): data is { subject: Project.Project } => Obj.instanceOf(Project.Project, data.subject),
84
- component: ({ data, role }) => {
85
- const activeSpace = useActiveSpace();
86
- return <ProjectCard subject={data.subject} role={role as SurfaceCardRole} activeSpace={activeSpace} />;
87
- },
88
- }),
89
- createSurface({
90
- id: `${meta.id}/schema-popover--task`,
91
- role: SurfaceCardRole.literals as any,
92
- filter: (data): data is { subject: Task.Task } => Obj.instanceOf(Task.Task, data.subject),
93
- component: ({ data, role }) => {
94
- return <TaskCard subject={data.subject} role={role as SurfaceCardRole} />;
95
- },
96
- }),
97
-
98
- //
99
- // Fallback for any object.
100
- //
76
+ Surface.create({
77
+ id: 'schema-popover--dynamic-type',
78
+ role: 'card--content',
79
+ filter: (data): data is { subject: Obj.Unknown } => {
80
+ if (!Obj.isObject(data.subject)) {
81
+ return false;
82
+ }
83
+ const type = Obj.getType(data.subject);
84
+ if (type) {
85
+ return Type.getDatabase(type) != null;
86
+ }
87
+ // Obj.getType fails for database-registered schemas (DXN mismatch); fall back to typename query.
88
+ try {
89
+ const db = Obj.getDatabase(data.subject);
90
+ const typename = Obj.getTypename(data.subject);
91
+ return !!db && !!typename && db.schemaRegistry.query({ typename }).runSync().length > 0;
92
+ } catch {
93
+ return false;
94
+ }
95
+ },
96
+ component: ({ data, role }) => {
97
+ // Dynamic/mutable schemas render an editable, full-layout form;
98
+ // FormCard handles both static and runtime schema resolution internally.
99
+ return <FormCard role={role} subject={data.subject} readonly={false} layout='full' />;
100
+ },
101
+ }),
101
102
 
102
- createSurface({
103
- id: `${meta.id}/fallback-popover`,
104
- role: SurfaceCardRole.literals as any,
105
- position: 'fallback',
106
- filter: (data): data is { subject: Obj.Any; projection?: ProjectionModel } => Obj.isObject(data.subject),
107
- component: ({ data, role }) => {
108
- const schema = getSchema(data.subject);
109
- const { t } = useTranslation(meta.id);
110
- if (!schema) {
111
- // TODO(burdon): Use Alert.
112
- return <p className={mx(descriptionMessage)}>{t('unable to create preview message')}</p>;
113
- }
103
+ //
104
+ // Fallback for any object.
105
+ //
114
106
 
115
- const handleSave = useCallback((values: any, { changed }: { changed: Record<string, boolean> }) => {
116
- const changedPaths = Object.keys(changed).filter((path) => changed[path]);
117
- for (const path of changedPaths) {
118
- const value = values[path];
119
- setValue(data.subject, path as JsonPath, value);
120
- }
121
- }, []);
107
+ Surface.create({
108
+ id: 'fallback-popover',
109
+ role: 'card--content',
110
+ position: 'last',
111
+ filter: (data): data is { subject: Obj.Unknown; projection?: ProjectionModel } => Obj.isObject(data.subject),
112
+ component: ({ data, role }) => {
113
+ return <FormCard role={role} subject={data.subject} projection={data.projection} />;
114
+ },
115
+ }),
122
116
 
123
- return (
124
- <Card.SurfaceRoot role={role}>
125
- <Form
126
- id={data.subject.id}
127
- schema={schema}
128
- projection={data.projection}
129
- values={data.subject}
130
- readonly={role === 'card--popover' ? 'static' : false}
131
- onSave={handleSave}
132
- autoSave
133
- {...(role === 'card--intrinsic' && {
134
- outerSpacing: 'blockStart-0',
135
- })}
136
- />
137
- </Card.SurfaceRoot>
138
- );
139
- },
140
- }),
117
+ Surface.create({
118
+ id: 'fallback-json',
119
+ role: 'card--content',
120
+ position: 'last',
121
+ filter: (data): data is Record<string, unknown> => true,
122
+ component: ({ data }) => {
123
+ return <JsonCard data={data} />;
124
+ },
125
+ }),
141
126
 
142
- createSurface({
143
- id: `${meta.id}/section`,
144
- role: ['section'],
145
- position: 'fallback',
146
- filter: (data): data is { subject: Obj.Any } => Obj.isObject(data.subject),
147
- component: ({ data }) => {
148
- return (
149
- <div role='none' className='flex is-full justify-center'>
150
- <div role='none' className='pbs-2 pbe-2 card-min-width card-max-width'>
151
- <Surface role='card' data={data} limit={1} />
127
+ Surface.create({
128
+ id: 'section',
129
+ position: 'last',
130
+ filter: AppSurface.subject(AppSurface.Section, Obj.isObject),
131
+ component: ({ data }) => {
132
+ return (
133
+ <div className='flex w-full justify-center'>
134
+ <div className='py-2 dx-card-min-width dx-card-max-width'>
135
+ <Card.Root>
136
+ <Surface.Surface type={AppSurface.Card} data={data} limit={1} />
137
+ </Card.Root>
138
+ </div>
152
139
  </div>
153
- </div>
154
- );
155
- },
156
- }),
157
- ]);
140
+ );
141
+ },
142
+ }),
143
+ ]),
144
+ ),
145
+ );
@@ -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.Body>
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.Body>
75
+ );
76
+ };
@@ -0,0 +1,115 @@
1
+ //
2
+ // Copyright 2025 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, Type } from '@dxos/echo';
10
+ import { useType } from '@dxos/echo-react';
11
+ import { type AnyProperties } from '@dxos/echo/internal';
12
+ import { type JsonPath, splitJsonPath } from '@dxos/effect';
13
+ import { Card, useTranslation } from '@dxos/react-ui';
14
+ import { Form, type FormUpdateMeta, type Presentation, getFormProperties, omitId } from '@dxos/react-ui-form';
15
+ import { type ProjectionModel } from '@dxos/schema';
16
+
17
+ import { meta } from '#meta';
18
+
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) => {
32
+ const { t } = useTranslation(meta.id);
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
+ );
94
+ }
95
+
96
+ return (
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
+ >
107
+ <Form.Viewport>
108
+ <Form.Content>
109
+ <Form.FieldSet />
110
+ </Form.Content>
111
+ </Form.Viewport>
112
+ </Form.Root>
113
+ </Card.Body>
114
+ );
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,31 +4,26 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { Card } from '@dxos/react-ui-stack';
7
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
8
+ import { Card } from '@dxos/react-ui';
8
9
  import { type Organization } from '@dxos/types';
9
10
 
10
- import { CardHeader, CardLink } from '../components';
11
- import { type CardPreviewProps } from '../types';
12
-
13
- export const OrganizationCard = ({
14
- children,
15
- subject,
16
- role,
17
- activeSpace,
18
- }: CardPreviewProps<Organization.Organization>) => {
11
+ export const OrganizationCard = ({ subject }: AppSurface.ObjectCardProps<Organization.Organization>) => {
19
12
  const { name, image, description, website } = subject;
20
13
 
21
14
  return (
22
- <Card.SurfaceRoot id={subject.id} role={role}>
15
+ <Card.Body>
23
16
  <Card.Poster
24
17
  alt={name ?? ''}
25
18
  {...(image ? { image } : { icon: 'ph--building-office--regular' })}
26
19
  classNames={!image && 'opacity-50'}
27
20
  />
28
- <CardHeader label={name} subject={subject} activeSpace={activeSpace} />
29
- {description && <Card.Text classNames='line-clamp-2'>{description}</Card.Text>}
30
- {website && <CardLink label={website} href={website} />}
31
- {children}
32
- </Card.SurfaceRoot>
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.Body>
33
28
  );
34
29
  };
@@ -2,62 +2,64 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React, { Fragment } from 'react';
5
+ import * as Effect from 'effect/Effect';
6
+ import React, { useCallback } from 'react';
6
7
 
7
- import { Avatar, Icon } from '@dxos/react-ui';
8
- import { Card, cardHeading, cardText } from '@dxos/react-ui-stack';
9
- import { mx } from '@dxos/react-ui-theme';
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';
10
15
  import { type Person } from '@dxos/types';
11
16
 
12
- import { CardRow, CardSubjectMenu, gridRow } from '../components';
13
- import { type CardPreviewProps } from '../types';
17
+ export const PersonCard = ({ subject }: AppSurface.ObjectCardProps<Person.Person>) => {
18
+ const { invoke } = useOperationInvoker();
19
+ const { image, organization: { target: organization } = {}, emails = [] } = subject;
14
20
 
15
- export const PersonCard = ({ children, role, subject, activeSpace, onSelect }: CardPreviewProps<Person.Person>) => {
16
- const { fullName, image, organization: { target: organization } = {}, emails = [] } = subject;
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]);
17
36
 
18
37
  return (
19
- <Card.SurfaceRoot id={subject.id} role={role}>
38
+ <Card.Body>
20
39
  <Avatar.Root>
21
- <Card.Text role='group' classNames={mx('grid gap-2 grid-cols-[1fr_min-content]')}>
22
- <div role='none' className={mx(gridRow, 'grid-rows-2')}>
23
- {activeSpace ? <CardSubjectMenu subject={subject} activeSpace={activeSpace} /> : <div />}
24
- <Avatar.Label asChild>
25
- <h2 className={mx(cardHeading, 'grow truncate')}>{fullName}</h2>
26
- </Avatar.Label>
27
- </div>
28
- <Avatar.Content
29
- imgSrc={image}
30
- icon='ph--user--regular'
31
- size={16}
32
- classNames={['text-subdued', !image && 'opacity-50']}
33
- hue='neutral'
34
- variant='square'
35
- />
36
- </Card.Text>
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
+ ))}
37
62
  </Avatar.Root>
38
- {organization?.name && (
39
- <CardRow
40
- icon='ph--buildings--regular'
41
- label={organization.name}
42
- onClick={onSelect ? () => onSelect(organization) : undefined}
43
- />
44
- )}
45
- {emails.length > 0 && (
46
- <dl className={mx(cardText, gridRow, '[&_dt]:text-subdued [&_dt]:pbs-0.5 [&_dd]:min-is-0')}>
47
- {emails.map(({ label, value }) => (
48
- <Fragment key={value}>
49
- <dt>
50
- <span className='sr-only'>{label}</span>
51
- <Icon icon='ph--at--regular' size={5} />
52
- </dt>
53
- <dd key={value} className='col-span-2 break-words'>
54
- {value}
55
- </dd>
56
- </Fragment>
57
- ))}
58
- </dl>
59
- )}
60
- {children}
61
- </Card.SurfaceRoot>
63
+ </Card.Body>
62
64
  );
63
65
  };