@dxos/plugin-preview 0.8.4-main.3c1ae3b → 0.8.4-main.3fbcb4aa9b
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/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/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/{browser/chunk-CEWM5LJG.mjs → neutral/chunk-52UEVZSF.mjs} +2 -2
- package/dist/lib/neutral/chunk-52UEVZSF.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-MPPEMUIA.mjs +78 -0
- package/dist/lib/neutral/preview-popover-MPPEMUIA.mjs.map +7 -0
- package/dist/lib/neutral/react-surface-YFFJXXPQ.mjs +348 -0
- package/dist/lib/neutral/react-surface-YFFJXXPQ.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/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 +2 -3
- package/dist/types/src/cards/FormCard.d.ts.map +1 -1
- 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 +2 -2
- package/dist/types/src/cards/OrganizationCard.d.ts.map +1 -1
- package/dist/types/src/cards/PersonCard.d.ts +2 -2
- package/dist/types/src/cards/PersonCard.d.ts.map +1 -1
- package/dist/types/src/cards/ProjectCard.d.ts +3 -3
- package/dist/types/src/cards/ProjectCard.d.ts.map +1 -1
- package/dist/types/src/cards/TaskCard.d.ts +2 -2
- package/dist/types/src/cards/TaskCard.d.ts.map +1 -1
- package/dist/types/src/cards/index.d.ts +2 -0
- package/dist/types/src/cards/index.d.ts.map +1 -1
- 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 -2
- 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 +23 -14
- package/dist/types/src/stories/Card.stories.d.ts.map +1 -1
- package/dist/types/src/stories/testing.d.ts +15 -12
- 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 -9
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +87 -39
- package/src/PreviewPlugin.node.ts +16 -0
- package/src/PreviewPlugin.test.ts +25 -0
- package/src/PreviewPlugin.tsx +16 -25
- package/src/capabilities/index.ts +3 -3
- package/src/capabilities/preview-popover.ts +68 -41
- package/src/capabilities/react-surface.tsx +104 -108
- package/src/cards/ExpandoCard.tsx +76 -0
- package/src/cards/FormCard.tsx +23 -32
- package/src/cards/JsonCard.tsx +19 -0
- package/src/cards/OrganizationCard.tsx +11 -16
- package/src/cards/PersonCard.tsx +51 -49
- package/src/cards/ProjectCard.tsx +9 -11
- package/src/cards/TaskCard.tsx +24 -26
- package/src/cards/index.ts +2 -0
- package/src/index.ts +0 -3
- package/src/meta.ts +3 -3
- package/src/plugin.ts +9 -0
- package/src/stories/Card.stories.tsx +83 -24
- package/src/stories/testing.tsx +64 -83
- package/src/testing.ts +7 -0
- package/src/translations.ts +8 -8
- package/dist/lib/browser/chunk-CEWM5LJG.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -64
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/preview-popover-4QZ2WDE6.mjs +0 -65
- package/dist/lib/browser/preview-popover-4QZ2WDE6.mjs.map +0 -7
- package/dist/lib/browser/react-surface-4AKVMPIJ.mjs +0 -513
- package/dist/lib/browser/react-surface-4AKVMPIJ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-Q5MUNELK.mjs +0 -19
- package/dist/lib/node-esm/chunk-Q5MUNELK.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -65
- 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-FJ2ARIGS.mjs +0 -67
- package/dist/lib/node-esm/preview-popover-FJ2ARIGS.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-ZJ4C32OR.mjs +0 -514
- package/dist/lib/node-esm/react-surface-ZJ4C32OR.mjs.map +0 -7
- package/dist/types/src/components/CardComponents.d.ts +0 -16
- package/dist/types/src/components/CardComponents.d.ts.map +0 -1
- package/dist/types/src/components/CardSubjectMenu.d.ts +0 -8
- package/dist/types/src/components/CardSubjectMenu.d.ts.map +0 -1
- package/dist/types/src/components/index.d.ts +0 -3
- package/dist/types/src/components/index.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -12
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/components/CardComponents.tsx +0 -67
- package/src/components/CardSubjectMenu.tsx +0 -103
- package/src/components/index.ts +0 -6
- package/src/types.ts +0 -25
|
@@ -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
|
+
};
|
package/src/cards/FormCard.tsx
CHANGED
|
@@ -2,56 +2,47 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { useCallback } from 'react';
|
|
5
|
+
import React, { useCallback, useMemo } from 'react';
|
|
7
6
|
|
|
7
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
|
-
import { type JsonPath,
|
|
10
|
-
import { useTranslation } from '@dxos/react-ui';
|
|
9
|
+
import { type JsonPath, splitJsonPath } from '@dxos/effect';
|
|
10
|
+
import { Card, useTranslation } from '@dxos/react-ui';
|
|
11
11
|
import { Form, omitId } from '@dxos/react-ui-form';
|
|
12
|
-
import { Card } from '@dxos/react-ui-stack';
|
|
13
|
-
import { descriptionMessage, mx } from '@dxos/react-ui-theme';
|
|
14
12
|
import { type ProjectionModel } from '@dxos/schema';
|
|
13
|
+
import { descriptionMessage, mx } from '@dxos/ui-theme';
|
|
15
14
|
|
|
16
|
-
import { meta } from '
|
|
17
|
-
import { type CardPreviewProps } from '../types';
|
|
15
|
+
import { meta } from '#meta';
|
|
18
16
|
|
|
19
|
-
export const FormCard = ({
|
|
20
|
-
subject,
|
|
21
|
-
projection,
|
|
22
|
-
role,
|
|
23
|
-
}: CardPreviewProps<Obj.Any> & { projection?: ProjectionModel }) => {
|
|
24
|
-
const schema = Obj.getSchema(subject);
|
|
17
|
+
export const FormCard = ({ subject, projection }: AppSurface.ObjectCardProps & { projection?: ProjectionModel }) => {
|
|
25
18
|
const { t } = useTranslation(meta.id);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return <p className={mx(descriptionMessage)}>{t('unable to create preview message')}</p>;
|
|
29
|
-
}
|
|
19
|
+
const echoSchema = Obj.getSchema(subject);
|
|
20
|
+
const schema = useMemo(() => echoSchema && omitId(echoSchema), [echoSchema]);
|
|
30
21
|
|
|
31
22
|
const handleSave = useCallback((values: any, { changed }: { changed: Record<string, boolean> }) => {
|
|
32
23
|
const paths = Object.keys(changed).filter((path) => changed[path]);
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
});
|
|
37
31
|
}, []);
|
|
38
32
|
|
|
33
|
+
if (!schema) {
|
|
34
|
+
return <p className={mx(descriptionMessage)}>{t('unable-to-create-preview.message')}</p>;
|
|
35
|
+
}
|
|
36
|
+
|
|
39
37
|
return (
|
|
40
|
-
<Card.
|
|
41
|
-
<Form.Root
|
|
42
|
-
schema={omitId(schema)}
|
|
43
|
-
projection={projection}
|
|
44
|
-
values={subject}
|
|
45
|
-
layout={role === 'card--popover' ? 'static' : undefined}
|
|
46
|
-
autoSave
|
|
47
|
-
onSave={handleSave}
|
|
48
|
-
>
|
|
38
|
+
<Card.Content>
|
|
39
|
+
<Form.Root schema={schema} projection={projection} values={subject} autoSave onSave={handleSave}>
|
|
49
40
|
<Form.Viewport>
|
|
50
41
|
<Form.Content>
|
|
51
42
|
<Form.FieldSet />
|
|
52
43
|
</Form.Content>
|
|
53
44
|
</Form.Viewport>
|
|
54
45
|
</Form.Root>
|
|
55
|
-
</Card.
|
|
46
|
+
</Card.Content>
|
|
56
47
|
);
|
|
57
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
|
+
};
|
|
@@ -4,31 +4,26 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
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
|
-
|
|
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.
|
|
15
|
+
<Card.Content>
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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>
|
|
33
28
|
);
|
|
34
29
|
};
|
package/src/cards/PersonCard.tsx
CHANGED
|
@@ -2,62 +2,64 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import React, { useCallback } from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
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
|
-
|
|
13
|
-
|
|
17
|
+
export const PersonCard = ({ subject }: AppSurface.ObjectCardProps<Person.Person>) => {
|
|
18
|
+
const { invoke } = useOperationInvoker();
|
|
19
|
+
const { image, organization: { target: organization } = {}, emails = [] } = subject;
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
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.
|
|
38
|
+
<Card.Content>
|
|
20
39
|
<Avatar.Root>
|
|
21
|
-
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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.Content>
|
|
62
64
|
);
|
|
63
65
|
};
|
|
@@ -4,21 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
7
8
|
import { Obj } from '@dxos/echo';
|
|
8
|
-
import { Card } from '@dxos/react-ui
|
|
9
|
-
import { type
|
|
9
|
+
import { Card } from '@dxos/react-ui';
|
|
10
|
+
import { type Pipeline } from '@dxos/types';
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const ProjectCard = ({ subject, role, activeSpace }: CardPreviewProps<Project.Project>) => {
|
|
15
|
-
const { name, image, description } = subject;
|
|
12
|
+
export const ProjectCard = ({ subject }: AppSurface.ObjectCardProps<Pipeline.Pipeline>) => {
|
|
13
|
+
const { image, description } = subject;
|
|
16
14
|
|
|
17
15
|
return (
|
|
18
|
-
<Card.
|
|
16
|
+
<Card.Content>
|
|
19
17
|
{image && <Card.Poster image={image} alt={Obj.getLabel(subject) ?? ''} aspect='auto' />}
|
|
20
|
-
<CardHeader label={name} subject={subject}
|
|
21
|
-
{description && <Card.Text
|
|
22
|
-
</Card.
|
|
18
|
+
{/* <CardHeader label={name} subject={subject} db={db} /> */}
|
|
19
|
+
{description && <Card.Text variant='description'>{description}</Card.Text>}
|
|
20
|
+
</Card.Content>
|
|
23
21
|
);
|
|
24
22
|
};
|
package/src/cards/TaskCard.tsx
CHANGED
|
@@ -5,42 +5,40 @@
|
|
|
5
5
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
8
9
|
import { type PropertyMetaAnnotation, PropertyMetaAnnotationId } from '@dxos/echo/internal';
|
|
9
|
-
import { Card
|
|
10
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
10
|
+
import { Card } from '@dxos/react-ui';
|
|
11
11
|
import { Task } from '@dxos/types';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
};
|
|
15
31
|
|
|
16
32
|
// TODO(thure): Should this move upstream as a helper? Is there an easier way to get options?
|
|
17
33
|
const getActiveStatusOption = (status?: string) => {
|
|
18
34
|
const properties = SchemaAST.getPropertySignatures(Task.Task.ast);
|
|
19
35
|
const statusProperty = properties.find((p) => p.name === 'status');
|
|
36
|
+
// TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
|
|
20
37
|
const statusMeta = SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(
|
|
21
|
-
// TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
|
|
22
38
|
(statusProperty!.type as any).types[0],
|
|
23
39
|
);
|
|
24
|
-
const options = // TODO(thure): Typescript asserts `statusMeta` doesn’t have `.value`, but in runtime it does.
|
|
25
|
-
(statusMeta as any).value.singleSelect.options as { id: string; title: string; color: string }[];
|
|
26
|
-
return options.find(({ id }) => id === status);
|
|
27
|
-
};
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
const { title
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<Card.SurfaceRoot id={subject.id} role={role}>
|
|
35
|
-
<div role='none' className={mx('flex items-center gap-2', cardSpacing)}>
|
|
36
|
-
<Card.Heading classNames={[cardNoSpacing, 'min-is-0 flex-1 truncate']}>{title}</Card.Heading>
|
|
37
|
-
{statusOption && (
|
|
38
|
-
<span className='dx-tag' data-hue={statusOption.color}>
|
|
39
|
-
{statusOption.title}
|
|
40
|
-
</span>
|
|
41
|
-
)}
|
|
42
|
-
<CardSubjectMenu subject={subject} activeSpace={activeSpace} />
|
|
43
|
-
</div>
|
|
44
|
-
</Card.SurfaceRoot>
|
|
45
|
-
);
|
|
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);
|
|
46
44
|
};
|
package/src/cards/index.ts
CHANGED
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
6
|
import { trim } from '@dxos/util';
|
|
7
7
|
|
|
8
|
-
export const meta:
|
|
9
|
-
id: 'dxos.
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
|
+
id: 'org.dxos.plugin.preview',
|
|
10
10
|
name: 'Preview',
|
|
11
11
|
description: trim`
|
|
12
12
|
Rich preview panel for viewing object content without opening full editors.
|
package/src/plugin.ts
ADDED
|
@@ -3,60 +3,119 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React from 'react';
|
|
6
7
|
|
|
7
|
-
import { IntentPlugin } from '@dxos/app-framework';
|
|
8
8
|
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { corePlugins } from '@dxos/plugin-testing';
|
|
10
|
+
import { random } from '@dxos/random';
|
|
11
|
+
import { Card } from '@dxos/react-ui';
|
|
12
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
13
|
+
import { type Expando } from '@dxos/schema';
|
|
14
|
+
import { type Organization, type Person, type Pipeline, type Task } from '@dxos/types';
|
|
11
15
|
|
|
12
|
-
import { translations } from '
|
|
16
|
+
import { translations } from '#translations';
|
|
13
17
|
|
|
14
|
-
import {
|
|
18
|
+
import { ExpandoCard, FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
|
|
19
|
+
import { DefaultStory, createExpando, createOrganization, createPerson, createProject, createTask } from './testing';
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
random.seed(999);
|
|
17
22
|
|
|
18
23
|
const meta = {
|
|
19
|
-
title: 'plugins/plugin-preview/Card',
|
|
20
|
-
render:
|
|
24
|
+
title: 'plugins/plugin-preview/cards/Card',
|
|
25
|
+
render: DefaultStory,
|
|
21
26
|
decorators: [
|
|
22
|
-
|
|
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' }),
|
|
23
33
|
// TODO(wittjosiah): Try to write story which does not depend on plugin manager.
|
|
24
|
-
withPluginManager({ plugins:
|
|
34
|
+
withPluginManager({ plugins: corePlugins() }),
|
|
25
35
|
],
|
|
26
36
|
parameters: {
|
|
37
|
+
layout: 'fullscreen',
|
|
27
38
|
translations,
|
|
28
39
|
},
|
|
29
40
|
tags: ['cards'],
|
|
30
|
-
} satisfies Meta<typeof
|
|
41
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
31
42
|
|
|
32
43
|
export default meta;
|
|
33
44
|
|
|
34
|
-
|
|
45
|
+
export const _Form: StoryObj<typeof DefaultStory<Person.Person>> = {
|
|
46
|
+
args: {
|
|
47
|
+
Component: FormCard,
|
|
48
|
+
createObject: createPerson,
|
|
49
|
+
image: true,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
35
52
|
|
|
36
|
-
export const
|
|
53
|
+
export const _Person: StoryObj<typeof DefaultStory<Person.Person>> = {
|
|
37
54
|
args: {
|
|
38
|
-
|
|
39
|
-
|
|
55
|
+
Component: PersonCard,
|
|
56
|
+
createObject: createPerson,
|
|
57
|
+
image: true,
|
|
40
58
|
},
|
|
41
59
|
};
|
|
42
60
|
|
|
43
|
-
export const
|
|
61
|
+
export const _Organization: StoryObj<typeof DefaultStory<Organization.Organization>> = {
|
|
44
62
|
args: {
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
Component: OrganizationCard,
|
|
64
|
+
createObject: createOrganization,
|
|
65
|
+
image: true,
|
|
47
66
|
},
|
|
48
67
|
};
|
|
49
68
|
|
|
50
|
-
export const
|
|
69
|
+
export const _Project: StoryObj<typeof DefaultStory<Pipeline.Pipeline>> = {
|
|
51
70
|
args: {
|
|
52
|
-
|
|
53
|
-
|
|
71
|
+
Component: ProjectCard,
|
|
72
|
+
createObject: createProject,
|
|
73
|
+
image: true,
|
|
54
74
|
},
|
|
55
75
|
};
|
|
56
76
|
|
|
57
|
-
export const
|
|
77
|
+
export const _Task: StoryObj<typeof DefaultStory<Task.Task>> = {
|
|
58
78
|
args: {
|
|
59
|
-
|
|
60
|
-
|
|
79
|
+
Component: TaskCard,
|
|
80
|
+
createObject: createTask,
|
|
81
|
+
image: true,
|
|
82
|
+
},
|
|
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
|
+
);
|
|
61
120
|
},
|
|
62
121
|
};
|