@dxos/plugin-preview 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/dist/lib/neutral/PreviewPlugin.mjs +9 -0
- package/dist/lib/neutral/PreviewPlugin.mjs.map +7 -0
- package/dist/lib/neutral/PreviewPlugin.node.mjs +17 -0
- package/dist/lib/neutral/PreviewPlugin.node.mjs.map +7 -0
- package/dist/lib/neutral/PreviewPlugin.workerd.mjs +17 -0
- package/dist/lib/neutral/PreviewPlugin.workerd.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +9 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/neutral/chunk-3SWUVHXJ.mjs +28 -0
- package/dist/lib/neutral/chunk-3SWUVHXJ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QOM5APM7.mjs +23 -0
- package/dist/lib/neutral/chunk-QOM5APM7.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +7 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +7 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +11 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/preview-popover-FLMYMFCH.mjs +94 -0
- package/dist/lib/neutral/preview-popover-FLMYMFCH.mjs.map +7 -0
- package/dist/lib/neutral/react-surface-FE7E2JP7.mjs +418 -0
- package/dist/lib/neutral/react-surface-FE7E2JP7.mjs.map +7 -0
- package/dist/lib/neutral/testing.mjs +7 -0
- package/dist/lib/neutral/testing.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +21 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/types/src/PreviewPlugin.d.ts +3 -1
- package/dist/types/src/PreviewPlugin.d.ts.map +1 -1
- package/dist/types/src/PreviewPlugin.node.d.ts +4 -0
- package/dist/types/src/PreviewPlugin.node.d.ts.map +1 -0
- package/dist/types/src/PreviewPlugin.test.d.ts +2 -0
- package/dist/types/src/PreviewPlugin.test.d.ts.map +1 -0
- package/dist/types/src/PreviewPlugin.workerd.d.ts +4 -0
- package/dist/types/src/PreviewPlugin.workerd.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +3 -2
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/preview-popover.d.ts +3 -2
- package/dist/types/src/capabilities/preview-popover.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/cards/ExpandoCard.d.ts +4 -0
- package/dist/types/src/cards/ExpandoCard.d.ts.map +1 -0
- package/dist/types/src/cards/FormCard.d.ts +17 -0
- package/dist/types/src/cards/FormCard.d.ts.map +1 -0
- package/dist/types/src/cards/JsonCard.d.ts +5 -0
- package/dist/types/src/cards/JsonCard.d.ts.map +1 -0
- package/dist/types/src/cards/OrganizationCard.d.ts +5 -0
- package/dist/types/src/cards/OrganizationCard.d.ts.map +1 -0
- package/dist/types/src/cards/PersonCard.d.ts +5 -0
- package/dist/types/src/cards/PersonCard.d.ts.map +1 -0
- package/dist/types/src/cards/ProjectCard.d.ts +5 -0
- package/dist/types/src/cards/ProjectCard.d.ts.map +1 -0
- package/dist/types/src/cards/TaskCard.d.ts +5 -0
- package/dist/types/src/cards/TaskCard.d.ts.map +1 -0
- package/dist/types/src/cards/index.d.ts +8 -0
- package/dist/types/src/cards/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/plugin.d.ts +3 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/stories/Card.stories.d.ts +54 -46
- package/dist/types/src/stories/Card.stories.d.ts.map +1 -1
- package/dist/types/src/stories/testing.d.ts +53 -13
- package/dist/types/src/stories/testing.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts +2 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +8 -3
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +80 -36
- package/src/PreviewPlugin.node.ts +16 -0
- package/src/PreviewPlugin.test.ts +25 -0
- package/src/PreviewPlugin.tsx +19 -29
- package/src/PreviewPlugin.workerd.ts +16 -0
- package/src/capabilities/index.ts +3 -3
- package/src/capabilities/preview-popover.ts +96 -49
- package/src/capabilities/react-surface.tsx +139 -150
- package/src/cards/ExpandoCard.tsx +76 -0
- package/src/cards/FormCard.tsx +125 -0
- package/src/cards/JsonCard.tsx +19 -0
- package/src/cards/OrganizationCard.tsx +29 -0
- package/src/cards/PersonCard.tsx +65 -0
- package/src/cards/ProjectCard.tsx +22 -0
- package/src/cards/TaskCard.tsx +45 -0
- package/src/cards/index.ts +11 -0
- package/src/index.ts +0 -3
- package/src/meta.ts +12 -6
- package/src/plugin.ts +9 -0
- package/src/stories/Card.stories.tsx +152 -28
- package/src/stories/testing.tsx +119 -69
- package/src/testing.ts +7 -0
- package/src/translations.ts +8 -2
- package/dist/lib/browser/chunk-Z73ENKLE.mjs +0 -14
- package/dist/lib/browser/chunk-Z73ENKLE.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -60
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/preview-popover-MAIBTJKJ.mjs +0 -69
- package/dist/lib/browser/preview-popover-MAIBTJKJ.mjs.map +0 -7
- package/dist/lib/browser/react-surface-SC522FSX.mjs +0 -303
- package/dist/lib/browser/react-surface-SC522FSX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2ORSL4GJ.mjs +0 -16
- package/dist/lib/node-esm/chunk-2ORSL4GJ.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -61
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/preview-popover-LZGHYW23.mjs +0 -71
- package/dist/lib/node-esm/preview-popover-LZGHYW23.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-PDXF35OF.mjs +0 -304
- package/dist/lib/node-esm/react-surface-PDXF35OF.mjs.map +0 -7
- package/dist/types/src/components/ContactCard.d.ts +0 -7
- package/dist/types/src/components/ContactCard.d.ts.map +0 -1
- package/dist/types/src/components/OrganizationCard.d.ts +0 -5
- package/dist/types/src/components/OrganizationCard.d.ts.map +0 -1
- package/dist/types/src/components/ProjectCard.d.ts +0 -5
- package/dist/types/src/components/ProjectCard.d.ts.map +0 -1
- package/dist/types/src/components/index.d.ts +0 -4
- package/dist/types/src/components/index.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -7
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/components/ContactCard.tsx +0 -72
- package/src/components/OrganizationCard.tsx +0 -41
- package/src/components/ProjectCard.tsx +0 -20
- package/src/components/index.ts +0 -7
- package/src/types.ts +0 -11
|
@@ -2,162 +2,151 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import React
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
useIntentDispatcher,
|
|
16
|
-
} from '@dxos/app-framework';
|
|
17
|
-
import { fullyQualifiedId, getSchema, getSpace } from '@dxos/client/echo';
|
|
18
|
-
import { Filter, Obj } from '@dxos/echo';
|
|
19
|
-
import { type JsonPath, setValue } from '@dxos/echo-schema';
|
|
20
|
-
import { AttentionAction } from '@dxos/plugin-attention/types';
|
|
21
|
-
import { ATTENDABLE_PATH_SEPARATOR, DeckAction } from '@dxos/plugin-deck/types';
|
|
22
|
-
import { useQuery, useSpace } from '@dxos/react-client/echo';
|
|
23
|
-
import { useTranslation } from '@dxos/react-ui';
|
|
24
|
-
import { Form } from '@dxos/react-ui-form';
|
|
25
|
-
import { Card } from '@dxos/react-ui-stack';
|
|
26
|
-
import { TableView } from '@dxos/react-ui-table/types';
|
|
27
|
-
import { descriptionMessage, mx } from '@dxos/react-ui-theme';
|
|
28
|
-
import { DataType } from '@dxos/schema';
|
|
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';
|
|
29
15
|
|
|
30
|
-
import {
|
|
31
|
-
import { PREVIEW_PLUGIN } from '../meta';
|
|
16
|
+
import { ExpandoCard, FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
|
|
32
17
|
|
|
33
|
-
export default () =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
|
|
41
|
-
filter: (data): data is { subject: DataType.Person } => Obj.instanceOf(DataType.Person, data.subject),
|
|
42
|
-
component: ({ data, role }) => {
|
|
43
|
-
const { dispatch } = useIntentDispatcher();
|
|
44
|
-
const space = getSpace(data.subject);
|
|
45
|
-
const defaultSpace = useSpace();
|
|
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
|
+
//
|
|
46
25
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
26
|
+
Surface.create<{ subject: Person.Person }>({
|
|
27
|
+
id: 'schemaPopoverContact',
|
|
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: 'schemaPopoverOrganization',
|
|
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: 'schemaPopoverProject',
|
|
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: 'schemaPopoverTask',
|
|
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: 'schemaPopoverExpando',
|
|
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
|
+
}),
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}),
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}).pipe(Effect.runPromise),
|
|
98
|
-
[dispatch, currentSpaceOrgs, currentSpaceOrgTable, defaultSpaceOrgTable],
|
|
99
|
-
);
|
|
76
|
+
Surface.create({
|
|
77
|
+
id: 'schemaPopoverDynamicType',
|
|
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 (
|
|
92
|
+
!!db &&
|
|
93
|
+
!!typename &&
|
|
94
|
+
db.graph.registry
|
|
95
|
+
.list()
|
|
96
|
+
.filter(Type.isType)
|
|
97
|
+
.some((t) => Type.getTypename(t) === typename)
|
|
98
|
+
);
|
|
99
|
+
} catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
component: ({ data, role }) => {
|
|
104
|
+
// Dynamic/mutable schemas render an editable, full-layout form;
|
|
105
|
+
// FormCard handles both static and runtime schema resolution internally.
|
|
106
|
+
return <FormCard role={role} subject={data.subject} readonly={false} layout='full' />;
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
100
109
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
</ContactCard>
|
|
105
|
-
);
|
|
106
|
-
},
|
|
107
|
-
}),
|
|
108
|
-
createSurface({
|
|
109
|
-
id: `${PREVIEW_PLUGIN}/schema-popover--organization`,
|
|
110
|
-
role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
|
|
111
|
-
filter: (data): data is { subject: DataType.Organization } => Obj.instanceOf(DataType.Organization, data.subject),
|
|
112
|
-
component: ({ data, role }) => (
|
|
113
|
-
<OrganizationCard role={role} subject={data.subject}>
|
|
114
|
-
{role === 'card--popover' && <Surface role='related' data={data} />}
|
|
115
|
-
</OrganizationCard>
|
|
116
|
-
),
|
|
117
|
-
}),
|
|
118
|
-
createSurface({
|
|
119
|
-
id: `${PREVIEW_PLUGIN}/schema-popover--project`,
|
|
120
|
-
role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
|
|
121
|
-
filter: (data): data is { subject: DataType.Project } => Obj.instanceOf(DataType.Project, data.subject),
|
|
122
|
-
component: ({ data, role }) => <ProjectCard subject={data.subject} role={role} />,
|
|
123
|
-
}),
|
|
110
|
+
//
|
|
111
|
+
// Fallback for any object.
|
|
112
|
+
//
|
|
124
113
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const schema = getSchema(data.subject);
|
|
135
|
-
const { t } = useTranslation(PREVIEW_PLUGIN);
|
|
136
|
-
if (!schema) {
|
|
137
|
-
// TODO(burdon): Use Alert.
|
|
138
|
-
return <p className={mx(descriptionMessage)}>{t('unable to create preview message')}</p>;
|
|
139
|
-
}
|
|
114
|
+
Surface.create({
|
|
115
|
+
id: 'fallbackPopover',
|
|
116
|
+
role: 'card--content',
|
|
117
|
+
position: 'last',
|
|
118
|
+
filter: (data): data is { subject: Obj.Unknown; projection?: ProjectionModel } => Obj.isObject(data.subject),
|
|
119
|
+
component: ({ data, role }) => {
|
|
120
|
+
return <FormCard role={role} subject={data.subject} projection={data.projection} />;
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
140
123
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
124
|
+
Surface.create({
|
|
125
|
+
id: 'fallbackJson',
|
|
126
|
+
role: 'card--content',
|
|
127
|
+
position: 'last',
|
|
128
|
+
filter: (data): data is Record<string, unknown> => true,
|
|
129
|
+
component: ({ data }) => {
|
|
130
|
+
return <JsonCard data={data} />;
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
148
133
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
134
|
+
Surface.create({
|
|
135
|
+
id: 'section',
|
|
136
|
+
position: 'last',
|
|
137
|
+
filter: AppSurface.subject(AppSurface.Section, Obj.isObject),
|
|
138
|
+
component: ({ data }) => {
|
|
139
|
+
return (
|
|
140
|
+
<div className='flex w-full justify-center'>
|
|
141
|
+
<div className='py-2 dx-card-min-width dx-card-max-width'>
|
|
142
|
+
<Card.Root>
|
|
143
|
+
<Surface.Surface type={AppSurface.Card} data={data} limit={1} />
|
|
144
|
+
</Card.Root>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
);
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
150
|
+
]),
|
|
151
|
+
),
|
|
152
|
+
);
|
|
@@ -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 { SchemaEx } 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 = SchemaEx.splitJsonPath(path as SchemaEx.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,125 @@
|
|
|
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 { SchemaEx } from '@dxos/effect';
|
|
13
|
+
import { Card, Icon, useTranslation } from '@dxos/react-ui';
|
|
14
|
+
import { Form, type FormUpdateMeta, type Presentation, getFormProperties, omitId } from '@dxos/react-ui-form';
|
|
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
|
+
// Obj.getTypeURI throws for corrupted objects; only evaluate it on the fallback path.
|
|
43
|
+
const runtimeType = useType(db, staticType ? undefined : Obj.getTypeURI(subject));
|
|
44
|
+
const schema = useMemo((): Schema.Schema.AnyNoContext | undefined => {
|
|
45
|
+
const resolvedType = runtimeType ?? staticType;
|
|
46
|
+
return resolvedType ? omitId(Type.getSchema(resolvedType)) : undefined;
|
|
47
|
+
}, [runtimeType, staticType]);
|
|
48
|
+
|
|
49
|
+
// Predict whether the form would render anything visible. Without this guard,
|
|
50
|
+
// readonly + compact mode produces an empty scrollarea when every form-renderable
|
|
51
|
+
// field is unset (e.g., a Table object whose `view`/`sizes` are FormInput-hidden
|
|
52
|
+
// and whose `name` is undefined).
|
|
53
|
+
//
|
|
54
|
+
// - In editable mode (`!readonly`), the form renders empty fields, so we only
|
|
55
|
+
// bail when there are no form-renderable properties at all.
|
|
56
|
+
// - In readonly mode, the form hides fields with null/undefined values, so we
|
|
57
|
+
// bail when no form-renderable property has a non-null value.
|
|
58
|
+
const hasRenderableContent = useMemo(() => {
|
|
59
|
+
if (!schema) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const properties = getFormProperties(schema.ast);
|
|
63
|
+
if (properties.length === 0) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (!readonly) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return properties.some((prop) => (subject as any)?.[prop.name] != null);
|
|
70
|
+
}, [schema, subject, readonly]);
|
|
71
|
+
|
|
72
|
+
const handleSave = useCallback(
|
|
73
|
+
(values: AnyProperties, { changed }: FormUpdateMeta<AnyProperties>) => {
|
|
74
|
+
const paths = (Object.keys(changed) as SchemaEx.JsonPath[]).filter((path) => changed[path]);
|
|
75
|
+
Obj.update(subject, () => {
|
|
76
|
+
for (const path of paths) {
|
|
77
|
+
const parts = SchemaEx.splitJsonPath(path);
|
|
78
|
+
const value = Obj.getValue(values as any, parts);
|
|
79
|
+
Obj.setValue(subject, parts, value);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
[subject],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
if (!schema || !hasRenderableContent) {
|
|
87
|
+
return (
|
|
88
|
+
<Card.Body>
|
|
89
|
+
<Card.Row>
|
|
90
|
+
<Card.Text variant='description'>{t('unable-to-create-preview.message')}</Card.Text>
|
|
91
|
+
</Card.Row>
|
|
92
|
+
</Card.Body>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const { icon, hue } = Obj.getIcon(subject) ?? { icon: 'ph--circle-dashed--regular', hue: 'neutral' };
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Card.Body>
|
|
100
|
+
<Form.Root
|
|
101
|
+
schema={schema}
|
|
102
|
+
projection={projection}
|
|
103
|
+
values={subject}
|
|
104
|
+
readonly={readonly}
|
|
105
|
+
layout={resolvedLayout}
|
|
106
|
+
autoSave
|
|
107
|
+
onSave={handleSave}
|
|
108
|
+
>
|
|
109
|
+
<Form.Viewport>
|
|
110
|
+
<Form.Content>
|
|
111
|
+
<Form.FieldSet />
|
|
112
|
+
</Form.Content>
|
|
113
|
+
</Form.Viewport>
|
|
114
|
+
</Form.Root>
|
|
115
|
+
<Card.Row fullWidth>
|
|
116
|
+
<div className='pt-1'>
|
|
117
|
+
<div {...{ 'data-hue': hue }} className='inline-flex items-center gap-1 dx-tag'>
|
|
118
|
+
<Icon icon={icon} />
|
|
119
|
+
<span>{Obj.getTypename(subject)}</span>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
</Card.Row>
|
|
123
|
+
</Card.Body>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -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.Body>
|
|
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.Body>
|
|
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 { EffectEx } 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(EffectEx.runAndForwardErrors);
|
|
35
|
+
}, [invoke, organization]);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Card.Body>
|
|
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.Body>
|
|
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.Body>
|
|
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.Body>
|
|
21
|
+
);
|
|
22
|
+
};
|