@dxos/plugin-preview 0.8.2-main.12df754 → 0.8.2-main.30e4dbb
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/dist/lib/browser/index.mjs +289 -6
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +291 -4
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +289 -6
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/Preview.stories.d.ts +203 -0
- package/dist/types/src/Preview.stories.d.ts.map +1 -0
- package/dist/types/src/PreviewPlugin.d.ts.map +1 -1
- package/dist/types/src/components/ContactCard.d.ts +7 -0
- package/dist/types/src/components/ContactCard.d.ts.map +1 -0
- package/dist/types/src/components/OrganizationCard.d.ts +5 -0
- package/dist/types/src/components/OrganizationCard.d.ts.map +1 -0
- package/dist/types/src/components/ProjectCard.d.ts +5 -0
- package/dist/types/src/components/ProjectCard.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +4 -0
- package/dist/types/src/components/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +9 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +25 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -10
- package/src/Preview.stories.tsx +145 -0
- package/src/PreviewPlugin.tsx +136 -9
- package/src/components/ContactCard.tsx +70 -0
- package/src/components/OrganizationCard.tsx +42 -0
- package/src/components/ProjectCard.tsx +24 -0
- package/src/components/index.ts +7 -0
- package/src/index.ts +2 -0
- package/src/translations.ts +15 -0
- package/src/types.ts +40 -0
package/src/PreviewPlugin.tsx
CHANGED
|
@@ -2,26 +2,48 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import React, { useCallback } from 'react';
|
|
6
|
+
|
|
5
7
|
import {
|
|
6
|
-
createIntent,
|
|
7
8
|
Capabilities,
|
|
8
|
-
contributes,
|
|
9
9
|
Events,
|
|
10
|
+
LayoutAction,
|
|
11
|
+
Surface,
|
|
12
|
+
contributes,
|
|
13
|
+
createIntent,
|
|
14
|
+
createSurface,
|
|
10
15
|
defineModule,
|
|
11
16
|
definePlugin,
|
|
12
|
-
|
|
17
|
+
useIntentDispatcher,
|
|
13
18
|
} from '@dxos/app-framework';
|
|
14
19
|
import { addEventListener } from '@dxos/async';
|
|
15
|
-
import { type Client } from '@dxos/client';
|
|
16
|
-
import {
|
|
17
|
-
|
|
20
|
+
import { type Client, resolveRef } from '@dxos/client';
|
|
21
|
+
import {
|
|
22
|
+
Filter,
|
|
23
|
+
fullyQualifiedId,
|
|
24
|
+
getSchema,
|
|
25
|
+
getSpace,
|
|
26
|
+
isEchoObject,
|
|
27
|
+
parseId,
|
|
28
|
+
type AnyLiveObject,
|
|
29
|
+
type Space,
|
|
30
|
+
} from '@dxos/client/echo';
|
|
31
|
+
import { isInstanceOf } from '@dxos/echo-schema';
|
|
18
32
|
import { DXN } from '@dxos/keys';
|
|
19
33
|
import { type DxRefTagActivate } from '@dxos/lit-ui';
|
|
20
34
|
import { log } from '@dxos/log';
|
|
21
|
-
import { ClientCapabilities } from '@dxos/plugin-client';
|
|
35
|
+
import { ClientCapabilities, ClientEvents } from '@dxos/plugin-client';
|
|
36
|
+
import { useTranslation } from '@dxos/react-ui';
|
|
22
37
|
import { type PreviewLinkRef, type PreviewLinkTarget } from '@dxos/react-ui-editor';
|
|
38
|
+
import { Form } from '@dxos/react-ui-form';
|
|
39
|
+
import { TableType } from '@dxos/react-ui-table';
|
|
40
|
+
import { descriptionMessage } from '@dxos/react-ui-theme';
|
|
41
|
+
import { DataType } from '@dxos/schema';
|
|
23
42
|
|
|
24
|
-
import {
|
|
43
|
+
import { ContactCard, OrganizationCard, ProjectCard } from './components';
|
|
44
|
+
import { meta, PREVIEW_PLUGIN } from './meta';
|
|
45
|
+
import translations from './translations';
|
|
46
|
+
import { kanbanCardWithoutPoster } from './types';
|
|
25
47
|
|
|
26
48
|
const customEventOptions = { capture: true, passive: false };
|
|
27
49
|
|
|
@@ -42,7 +64,17 @@ const handlePreviewLookup = async (
|
|
|
42
64
|
export const PreviewPlugin = () =>
|
|
43
65
|
definePlugin(meta, [
|
|
44
66
|
defineModule({
|
|
45
|
-
id: `${meta.id}/module/
|
|
67
|
+
id: `${meta.id}/module/translations`,
|
|
68
|
+
activatesOn: Events.SetupTranslations,
|
|
69
|
+
activate: () => contributes(Capabilities.Translations, translations),
|
|
70
|
+
}),
|
|
71
|
+
defineModule({
|
|
72
|
+
id: `${meta.id}/module/schema`,
|
|
73
|
+
activatesOn: ClientEvents.SetupSchema,
|
|
74
|
+
activate: () => [contributes(ClientCapabilities.Schema, [DataType.Person, DataType.Organization])],
|
|
75
|
+
}),
|
|
76
|
+
defineModule({
|
|
77
|
+
id: `${meta.id}/module/preview-popover`,
|
|
46
78
|
activatesOn: Events.Startup,
|
|
47
79
|
activate: (context) => {
|
|
48
80
|
// TODO(wittjosiah): Factor out lookup handlers to other plugins to make not ECHO-specific.
|
|
@@ -84,4 +116,99 @@ export const PreviewPlugin = () =>
|
|
|
84
116
|
return contributes(Capabilities.Null, null, () => cleanup());
|
|
85
117
|
},
|
|
86
118
|
}),
|
|
119
|
+
defineModule({
|
|
120
|
+
id: `${meta.id}/module/react-surface`,
|
|
121
|
+
activatesOn: Events.SetupReactSurface,
|
|
122
|
+
activate: () =>
|
|
123
|
+
// TODO(wittjosiah): Factor out to lazy capabilities like other plugins.
|
|
124
|
+
contributes(Capabilities.ReactSurface, [
|
|
125
|
+
//
|
|
126
|
+
// Specific schema types.
|
|
127
|
+
//
|
|
128
|
+
createSurface({
|
|
129
|
+
id: `${PREVIEW_PLUGIN}/schema-popover`,
|
|
130
|
+
role: ['popover', 'card--kanban'],
|
|
131
|
+
filter: (data): data is { subject: DataType.Person } => isInstanceOf(DataType.Person, data.subject),
|
|
132
|
+
component: ({ data, role }) => {
|
|
133
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
134
|
+
const handleOrgClick = useCallback(
|
|
135
|
+
async (org: DataType.Organization) => {
|
|
136
|
+
const space = getSpace(org);
|
|
137
|
+
const tablesQuery = await space?.db.query(Filter.schema(TableType)).run();
|
|
138
|
+
const currentSpaceOrgTable = tablesQuery?.objects.find((table) => {
|
|
139
|
+
return table.view?.target?.query?.typename === DataType.Organization.typename;
|
|
140
|
+
});
|
|
141
|
+
await dispatch(
|
|
142
|
+
createIntent(LayoutAction.UpdatePopover, {
|
|
143
|
+
part: 'popover',
|
|
144
|
+
options: {
|
|
145
|
+
state: false,
|
|
146
|
+
anchorId: '',
|
|
147
|
+
},
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
if (currentSpaceOrgTable) {
|
|
151
|
+
return dispatch(
|
|
152
|
+
createIntent(LayoutAction.Open, {
|
|
153
|
+
part: 'main',
|
|
154
|
+
subject: [fullyQualifiedId(currentSpaceOrgTable)],
|
|
155
|
+
options: { workspace: space?.id },
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
[dispatch],
|
|
161
|
+
);
|
|
162
|
+
return (
|
|
163
|
+
<ContactCard subject={data.subject} onOrgClick={handleOrgClick} role={role}>
|
|
164
|
+
{role === 'popover' && <Surface role='related' data={data} />}
|
|
165
|
+
</ContactCard>
|
|
166
|
+
);
|
|
167
|
+
},
|
|
168
|
+
}),
|
|
169
|
+
createSurface({
|
|
170
|
+
id: `${PREVIEW_PLUGIN}/schema-popover`,
|
|
171
|
+
role: ['popover', 'card--kanban'],
|
|
172
|
+
filter: (data): data is { subject: DataType.Organization } =>
|
|
173
|
+
isInstanceOf(DataType.Organization, data.subject),
|
|
174
|
+
component: ({ data, role }) => (
|
|
175
|
+
<OrganizationCard subject={data.subject} role={role}>
|
|
176
|
+
{role === 'popover' && <Surface role='related' data={data} />}
|
|
177
|
+
</OrganizationCard>
|
|
178
|
+
),
|
|
179
|
+
}),
|
|
180
|
+
createSurface({
|
|
181
|
+
id: `${PREVIEW_PLUGIN}/schema-popover`,
|
|
182
|
+
role: ['popover', 'card--kanban'],
|
|
183
|
+
filter: (data): data is { subject: DataType.Project } => isInstanceOf(DataType.Project, data.subject),
|
|
184
|
+
component: ({ data, role }) => <ProjectCard subject={data.subject} role={role} />,
|
|
185
|
+
}),
|
|
186
|
+
|
|
187
|
+
//
|
|
188
|
+
// Fallback for any object.
|
|
189
|
+
//
|
|
190
|
+
createSurface({
|
|
191
|
+
id: `${PREVIEW_PLUGIN}/fallback-popover`,
|
|
192
|
+
role: ['popover', 'card--kanban'],
|
|
193
|
+
position: 'fallback',
|
|
194
|
+
filter: (data): data is { subject: AnyLiveObject<any> } => isEchoObject(data.subject),
|
|
195
|
+
component: ({ data, role }) => {
|
|
196
|
+
const schema = getSchema(data.subject);
|
|
197
|
+
const { t } = useTranslation(PREVIEW_PLUGIN);
|
|
198
|
+
if (!schema) {
|
|
199
|
+
return <p className={descriptionMessage}>{t('unable to create preview message')}</p>;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<Form
|
|
204
|
+
schema={schema}
|
|
205
|
+
values={data.subject}
|
|
206
|
+
readonly
|
|
207
|
+
{...(role === 'card--kanban' && { classNames: kanbanCardWithoutPoster })}
|
|
208
|
+
/>
|
|
209
|
+
);
|
|
210
|
+
},
|
|
211
|
+
}),
|
|
212
|
+
]),
|
|
213
|
+
}),
|
|
87
214
|
]);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { Fragment } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Icon, Avatar, Button } from '@dxos/react-ui';
|
|
8
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
9
|
+
import { type DataType } from '@dxos/schema';
|
|
10
|
+
|
|
11
|
+
import { type PreviewProps, popoverCard, previewTitle, previewProse, previewChrome, defaultCard } from '../types';
|
|
12
|
+
|
|
13
|
+
export const ContactCard = ({
|
|
14
|
+
children,
|
|
15
|
+
classNames,
|
|
16
|
+
role,
|
|
17
|
+
subject: { fullName, image, organization, emails },
|
|
18
|
+
onOrgClick,
|
|
19
|
+
}: PreviewProps<DataType.Person> & { onOrgClick?: (org: DataType.Organization) => void }) => {
|
|
20
|
+
const organizationName = organization && typeof organization === 'object' ? organization.target?.name : organization;
|
|
21
|
+
return (
|
|
22
|
+
<div role='none' className={mx(role === 'popover' ? popoverCard : defaultCard, classNames)}>
|
|
23
|
+
<Avatar.Root>
|
|
24
|
+
<div role='group' className={mx(previewProse, 'grid gap-3 grid-cols-[min-content_1fr]')}>
|
|
25
|
+
<Avatar.Content imgSrc={image} icon='ph--user--regular' size={16} hue='neutral' />
|
|
26
|
+
<div role='none' className='bs-min self-center'>
|
|
27
|
+
<Avatar.Label asChild>
|
|
28
|
+
<h2 className={previewTitle}>{fullName}</h2>
|
|
29
|
+
</Avatar.Label>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
</Avatar.Root>
|
|
33
|
+
{organizationName && (
|
|
34
|
+
<div role='none' className={previewChrome}>
|
|
35
|
+
{typeof organization === 'object' && onOrgClick ? (
|
|
36
|
+
<Button variant='ghost' classNames='gap-2 text-start' onClick={() => onOrgClick(organization.target!)}>
|
|
37
|
+
<Icon icon='ph--buildings--regular' size={5} classNames='text-subdued' />
|
|
38
|
+
<span className='min-is-0 flex-1 truncate'>{organizationName}</span>
|
|
39
|
+
<Icon icon='ph--arrow-right--regular' />
|
|
40
|
+
</Button>
|
|
41
|
+
) : (
|
|
42
|
+
<p className='dx-button gap-2' data-variant='ghost'>
|
|
43
|
+
<Icon icon='ph--buildings--regular' size={5} classNames='text-subdued' />
|
|
44
|
+
<span className='min-is-0 flex-1 truncate'>{organizationName}</span>
|
|
45
|
+
</p>
|
|
46
|
+
)}
|
|
47
|
+
</div>
|
|
48
|
+
)}
|
|
49
|
+
<dl
|
|
50
|
+
className={mx(
|
|
51
|
+
previewProse,
|
|
52
|
+
'grid gap-2 grid-cols-[min-content_1fr] [&_dt]:text-subdued [&_dt]:pbs-0.5 [&_dd]:min-is-0',
|
|
53
|
+
)}
|
|
54
|
+
>
|
|
55
|
+
{emails?.length &&
|
|
56
|
+
emails.map(({ label, value }) => (
|
|
57
|
+
<Fragment key={value}>
|
|
58
|
+
<dt>
|
|
59
|
+
<Icon icon='ph--at--regular' size={5} />
|
|
60
|
+
</dt>
|
|
61
|
+
<dd key={value} className='break-words'>
|
|
62
|
+
{value}
|
|
63
|
+
</dd>
|
|
64
|
+
</Fragment>
|
|
65
|
+
))}
|
|
66
|
+
</dl>
|
|
67
|
+
{children}
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { Icon } from '@dxos/react-ui';
|
|
8
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
9
|
+
import { type DataType } from '@dxos/schema';
|
|
10
|
+
|
|
11
|
+
import { type PreviewProps, popoverCard, previewTitle, previewProse, previewChrome, defaultCard } from '../types';
|
|
12
|
+
|
|
13
|
+
export const OrganizationCard = ({
|
|
14
|
+
children,
|
|
15
|
+
classNames,
|
|
16
|
+
subject: { name, image, description, website },
|
|
17
|
+
role,
|
|
18
|
+
}: PreviewProps<DataType.Organization>) => {
|
|
19
|
+
return (
|
|
20
|
+
<div role='none' className={mx(role === 'popover' ? popoverCard : defaultCard, classNames)}>
|
|
21
|
+
{image ? (
|
|
22
|
+
<img className='aspect-video object-cover is-full bs-auto' src={image} alt={name} />
|
|
23
|
+
) : (
|
|
24
|
+
<div role='image' className='grid aspect-video place-items-center bg-input text-subdued'>
|
|
25
|
+
<Icon icon='ph--building-office--regular' size={10} />
|
|
26
|
+
</div>
|
|
27
|
+
)}
|
|
28
|
+
<h2 className={mx(previewTitle, previewProse)}>{name}</h2>
|
|
29
|
+
{description && <p className={mx(previewProse, 'line-clamp-2')}>{description}</p>}
|
|
30
|
+
{website && (
|
|
31
|
+
<div role='none' className={previewChrome}>
|
|
32
|
+
<a className='dx-button dx-focus-ring gap-2' href={website} target='_blank' rel='noreferrer'>
|
|
33
|
+
<Icon icon='ph--link--regular' size={5} classNames='text-subdued' />
|
|
34
|
+
<span className='grow'>{website}</span>
|
|
35
|
+
<Icon icon='ph--arrow-square-out--regular' />
|
|
36
|
+
</a>
|
|
37
|
+
</div>
|
|
38
|
+
)}
|
|
39
|
+
{children}
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
8
|
+
import { type DataType } from '@dxos/schema';
|
|
9
|
+
|
|
10
|
+
import { type PreviewProps, popoverCard, previewTitle, defaultCard } from '../types';
|
|
11
|
+
|
|
12
|
+
export const ProjectCard = ({
|
|
13
|
+
classNames,
|
|
14
|
+
role,
|
|
15
|
+
subject: { name, image, description },
|
|
16
|
+
}: PreviewProps<DataType.Project>) => {
|
|
17
|
+
return (
|
|
18
|
+
<div role='none' className={mx(role === 'popover' ? popoverCard : defaultCard, classNames)}>
|
|
19
|
+
{image && <img className='is-full bs-auto' src={image} alt={name} />}
|
|
20
|
+
<h2 className={mx(previewTitle, 'pli-3 mlb-3')}>{name}</h2>
|
|
21
|
+
{description && <p className='pli-3 line-clamp-2 mlb-3'>{description}</p>}
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
};
|
package/src/index.ts
CHANGED
package/src/types.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type PropsWithChildren } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
8
|
+
|
|
9
|
+
// TODO(burdon): Better place for these defs?
|
|
10
|
+
export type PreviewProps<T extends object> = PropsWithChildren<
|
|
11
|
+
ThemedClassName<{
|
|
12
|
+
subject: T;
|
|
13
|
+
role: string;
|
|
14
|
+
}>
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
// TODO(burdon): Update react-ui-card (to use grid) and re-use here.
|
|
18
|
+
// - See https://dxos-storybook.pages.dev/?path=/story/ui-react-ui-card-card--draggable
|
|
19
|
+
// - Standardize Header, actions, image, body, etc.
|
|
20
|
+
// - Support different grid layouts (e.g., image to the side, on top, etc.)
|
|
21
|
+
// - Should co-exist naturally with react-ui-form (e.g., as main content).
|
|
22
|
+
// - Considerations for drag-and-drop.
|
|
23
|
+
/**
|
|
24
|
+
* <Card.Root>
|
|
25
|
+
* <Card.Header>
|
|
26
|
+
* <Card.Title>
|
|
27
|
+
* <Card.Action>
|
|
28
|
+
* </Card.Header>
|
|
29
|
+
* <Card.Body>
|
|
30
|
+
* <Card.Image>
|
|
31
|
+
* <Form />
|
|
32
|
+
* </Card.Body>
|
|
33
|
+
* </Card.Root>
|
|
34
|
+
*/
|
|
35
|
+
export const popoverCard = 'popover-consistent-width rounded-lg overflow-hidden';
|
|
36
|
+
export const defaultCard = '';
|
|
37
|
+
export const kanbanCardWithoutPoster = 'pbs-[--rail-action]';
|
|
38
|
+
export const previewTitle = 'text-lg font-medium line-clamp-2';
|
|
39
|
+
export const previewProse = 'pli-3 mlb-3';
|
|
40
|
+
export const previewChrome = 'pli-1.5 mlb-1.5 [&_.dx-button]:pli-1.5 [&_.dx-button]:text-start [&_.dx-button]:is-full';
|