@dxos/plugin-preview 0.8.4-main.ead640a → 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.
- 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-XD3EYTHF.mjs +21 -0
- package/dist/lib/neutral/chunk-XD3EYTHF.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-F33UBSBM.mjs +80 -0
- package/dist/lib/neutral/preview-popover-F33UBSBM.mjs.map +7 -0
- package/dist/lib/neutral/react-surface-3UPRCM4X.mjs +408 -0
- package/dist/lib/neutral/react-surface-3UPRCM4X.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 +3 -3
- package/dist/types/src/cards/OrganizationCard.d.ts.map +1 -1
- 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 +3 -3
- package/dist/types/src/cards/ProjectCard.d.ts.map +1 -1
- package/dist/types/src/cards/TaskCard.d.ts +3 -3
- package/dist/types/src/cards/TaskCard.d.ts.map +1 -1
- package/dist/types/src/cards/index.d.ts +4 -1
- 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 +42 -14
- package/dist/types/src/stories/Card.stories.d.ts.map +1 -1
- package/dist/types/src/stories/testing.d.ts +52 -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 +92 -39
- package/src/PreviewPlugin.node.ts +16 -0
- package/src/PreviewPlugin.test.ts +25 -0
- package/src/PreviewPlugin.tsx +17 -26
- package/src/PreviewPlugin.workerd.ts +16 -0
- package/src/capabilities/index.ts +3 -3
- package/src/capabilities/preview-popover.ts +69 -42
- package/src/capabilities/react-surface.tsx +132 -120
- package/src/cards/ExpandoCard.tsx +76 -0
- package/src/cards/FormCard.tsx +115 -0
- package/src/cards/JsonCard.tsx +19 -0
- package/src/cards/OrganizationCard.tsx +17 -13
- package/src/cards/PersonCard.tsx +65 -0
- package/src/cards/ProjectCard.tsx +9 -11
- package/src/cards/TaskCard.tsx +27 -28
- package/src/cards/index.ts +4 -1
- package/src/index.ts +0 -3
- package/src/meta.ts +10 -3
- package/src/plugin.ts +9 -0
- package/src/stories/Card.stories.tsx +139 -24
- package/src/stories/testing.tsx +117 -77
- package/src/testing.ts +7 -0
- package/src/translations.ts +8 -8
- package/dist/lib/browser/chunk-XKCIQK3C.mjs +0 -12
- package/dist/lib/browser/chunk-XKCIQK3C.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-RKHENTFP.mjs +0 -65
- package/dist/lib/browser/preview-popover-RKHENTFP.mjs.map +0 -7
- package/dist/lib/browser/react-surface-CPGRW3OV.mjs +0 -493
- package/dist/lib/browser/react-surface-CPGRW3OV.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-L3IZVX56.mjs +0 -14
- package/dist/lib/node-esm/chunk-L3IZVX56.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-TZKX67EY.mjs +0 -67
- package/dist/lib/node-esm/preview-popover-TZKX67EY.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-XJKNWCPR.mjs +0 -494
- package/dist/lib/node-esm/react-surface-XJKNWCPR.mjs.map +0 -7
- package/dist/types/src/cards/ContactCard.d.ts +0 -5
- package/dist/types/src/cards/ContactCard.d.ts.map +0 -1
- 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 -10
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/cards/ContactCard.tsx +0 -58
- package/src/components/CardComponents.tsx +0 -67
- package/src/components/CardSubjectMenu.tsx +0 -91
- package/src/components/index.ts +0 -6
- package/src/types.ts +0 -15
package/src/cards/TaskCard.tsx
CHANGED
|
@@ -5,42 +5,41 @@
|
|
|
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';
|
|
9
|
+
import { Type } from '@dxos/echo';
|
|
8
10
|
import { type PropertyMetaAnnotation, PropertyMetaAnnotationId } from '@dxos/echo/internal';
|
|
9
|
-
import { Card
|
|
10
|
-
import {
|
|
11
|
-
import { DataType } from '@dxos/schema';
|
|
11
|
+
import { Card } from '@dxos/react-ui';
|
|
12
|
+
import { Task } from '@dxos/types';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
export const TaskCard = ({ subject }: AppSurface.ObjectCardProps<Task.Task>) => {
|
|
15
|
+
const { title, status } = subject;
|
|
16
|
+
const statusOption = getActiveStatusOption(status);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Card.Body>
|
|
20
|
+
<Card.Row>
|
|
21
|
+
{statusOption && (
|
|
22
|
+
<div>
|
|
23
|
+
<span className='dx-tag' data-hue={statusOption.color}>
|
|
24
|
+
{statusOption.title}
|
|
25
|
+
</span>
|
|
26
|
+
</div>
|
|
27
|
+
)}
|
|
28
|
+
</Card.Row>
|
|
29
|
+
</Card.Body>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
15
32
|
|
|
16
33
|
// TODO(thure): Should this move upstream as a helper? Is there an easier way to get options?
|
|
17
34
|
const getActiveStatusOption = (status?: string) => {
|
|
18
|
-
const properties = SchemaAST.getPropertySignatures(
|
|
35
|
+
const properties = SchemaAST.getPropertySignatures(Type.getSchema(Task.Task).ast);
|
|
19
36
|
const statusProperty = properties.find((p) => p.name === 'status');
|
|
37
|
+
// TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
|
|
20
38
|
const statusMeta = SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(
|
|
21
|
-
// TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
|
|
22
39
|
(statusProperty!.type as any).types[0],
|
|
23
40
|
);
|
|
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
41
|
|
|
29
|
-
|
|
30
|
-
const { title
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<Card.SurfaceRoot 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
|
-
);
|
|
42
|
+
// TODO(thure): Typescript asserts `statusMeta` doesn’t have `.value`, but in runtime it does.
|
|
43
|
+
const options = (statusMeta as any).value.singleSelect.options as { id: string; title: string; color: string }[];
|
|
44
|
+
return options.find(({ id }) => id === status);
|
|
46
45
|
};
|
package/src/cards/index.ts
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './ExpandoCard';
|
|
6
|
+
export * from './FormCard';
|
|
7
|
+
export * from './JsonCard';
|
|
6
8
|
export * from './OrganizationCard';
|
|
9
|
+
export * from './PersonCard';
|
|
7
10
|
export * from './ProjectCard';
|
|
8
11
|
export * from './TaskCard';
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,11 +2,18 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
6
7
|
|
|
7
|
-
export const meta:
|
|
8
|
-
id: 'dxos.
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
|
+
id: 'org.dxos.plugin.preview',
|
|
9
10
|
name: 'Preview',
|
|
11
|
+
author: 'DXOS',
|
|
12
|
+
description: trim`
|
|
13
|
+
Rich preview panel for viewing object content without opening full editors.
|
|
14
|
+
Quick peek at documents, images, and data with inline rendering.
|
|
15
|
+
`,
|
|
10
16
|
icon: 'ph--eye--regular',
|
|
11
17
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview',
|
|
18
|
+
tags: ['system'],
|
|
12
19
|
};
|
package/src/plugin.ts
ADDED
|
@@ -3,60 +3,175 @@
|
|
|
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 {
|
|
20
|
+
DefaultStory,
|
|
21
|
+
createExpando,
|
|
22
|
+
createOrganization,
|
|
23
|
+
createPerson,
|
|
24
|
+
createPersonEmpty,
|
|
25
|
+
createProject,
|
|
26
|
+
createTableEmpty,
|
|
27
|
+
createTask,
|
|
28
|
+
createUnknown,
|
|
29
|
+
} from './testing';
|
|
15
30
|
|
|
16
|
-
|
|
31
|
+
random.seed(999);
|
|
17
32
|
|
|
18
33
|
const meta = {
|
|
19
|
-
title: 'plugins/plugin-preview/Card',
|
|
20
|
-
render:
|
|
34
|
+
title: 'plugins/plugin-preview/cards/Card',
|
|
35
|
+
render: DefaultStory,
|
|
21
36
|
decorators: [
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
// `Card` and its descendants in `@dxos/react-ui` consume `ThemeContext`
|
|
38
|
+
// for tx-token resolution; without this the stories trip the surface's
|
|
39
|
+
// `ErrorBoundary` with "Missing ThemeContext" and the storybook test
|
|
40
|
+
// assert-no-error fails.
|
|
41
|
+
withTheme(),
|
|
42
|
+
withLayout({ layout: 'fullscreen' }),
|
|
43
|
+
// TODO(wittjosiah): Try to write story which does not depend on plugin manager.
|
|
44
|
+
withPluginManager({ plugins: corePlugins() }),
|
|
24
45
|
],
|
|
25
46
|
parameters: {
|
|
26
47
|
layout: 'fullscreen',
|
|
27
48
|
translations,
|
|
28
49
|
},
|
|
29
50
|
tags: ['cards'],
|
|
30
|
-
} satisfies Meta<typeof
|
|
51
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
31
52
|
|
|
32
53
|
export default meta;
|
|
33
54
|
|
|
34
|
-
|
|
55
|
+
export const _Form: StoryObj<typeof DefaultStory<Person.Person>> = {
|
|
56
|
+
args: {
|
|
57
|
+
Component: FormCard,
|
|
58
|
+
createObject: createPerson,
|
|
59
|
+
image: true,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const _FormEditable: StoryObj<typeof DefaultStory<Person.Person>> = {
|
|
64
|
+
args: {
|
|
65
|
+
Component: FormCard,
|
|
66
|
+
createObject: createPerson,
|
|
67
|
+
image: true,
|
|
68
|
+
componentProps: { readonly: false, layout: 'full' },
|
|
69
|
+
},
|
|
70
|
+
};
|
|
35
71
|
|
|
36
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Empty-state variant: the subject has no resolvable schema so `FormCard` renders
|
|
74
|
+
* `<Card.Body><Card.Row><Card.Text variant='description'>No preview</Card.Text></Card.Row></Card.Body>`.
|
|
75
|
+
* Use this story to verify the empty message lands in the card's center column.
|
|
76
|
+
*/
|
|
77
|
+
export const _FormEmpty: StoryObj<typeof DefaultStory> = {
|
|
37
78
|
args: {
|
|
38
|
-
|
|
39
|
-
|
|
79
|
+
Component: FormCard,
|
|
80
|
+
createObject: createUnknown,
|
|
40
81
|
},
|
|
41
82
|
};
|
|
42
83
|
|
|
43
|
-
|
|
84
|
+
/**
|
|
85
|
+
* No-values variant: the subject has a valid schema (Person) but no populated
|
|
86
|
+
* fields, so `FormCard` falls through to the same empty state instead of
|
|
87
|
+
* rendering an empty scrollarea.
|
|
88
|
+
*/
|
|
89
|
+
export const _FormNoValues: StoryObj<typeof DefaultStory<Person.Person>> = {
|
|
44
90
|
args: {
|
|
45
|
-
|
|
46
|
-
|
|
91
|
+
Component: FormCard,
|
|
92
|
+
createObject: createPersonEmpty,
|
|
47
93
|
},
|
|
48
94
|
};
|
|
49
95
|
|
|
50
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Table-like variant: the subject has values only in form-hidden fields
|
|
98
|
+
* (`view`, `sizes` annotated `FormInputAnnotation.set(false)`). `FormCard`
|
|
99
|
+
* must consult the schema's form-input annotations — not just `Object.keys` —
|
|
100
|
+
* to recognize this case and fall through to the empty state.
|
|
101
|
+
*/
|
|
102
|
+
export const _FormTableEmpty: StoryObj<typeof DefaultStory<any>> = {
|
|
51
103
|
args: {
|
|
52
|
-
|
|
53
|
-
|
|
104
|
+
Component: FormCard,
|
|
105
|
+
createObject: createTableEmpty,
|
|
54
106
|
},
|
|
55
107
|
};
|
|
56
108
|
|
|
57
|
-
export const
|
|
109
|
+
export const _Person: StoryObj<typeof DefaultStory<Person.Person>> = {
|
|
58
110
|
args: {
|
|
59
|
-
|
|
60
|
-
|
|
111
|
+
Component: PersonCard,
|
|
112
|
+
createObject: createPerson,
|
|
113
|
+
image: true,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const _Organization: StoryObj<typeof DefaultStory<Organization.Organization>> = {
|
|
118
|
+
args: {
|
|
119
|
+
Component: OrganizationCard,
|
|
120
|
+
createObject: createOrganization,
|
|
121
|
+
image: true,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export const _Project: StoryObj<typeof DefaultStory<Pipeline.Pipeline>> = {
|
|
126
|
+
args: {
|
|
127
|
+
Component: ProjectCard,
|
|
128
|
+
createObject: createProject,
|
|
129
|
+
image: true,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const _Task: StoryObj<typeof DefaultStory<Task.Task>> = {
|
|
134
|
+
args: {
|
|
135
|
+
Component: TaskCard,
|
|
136
|
+
createObject: createTask,
|
|
137
|
+
image: true,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const _Expando: StoryObj<typeof DefaultStory<Expando.Expando>> = {
|
|
142
|
+
args: {
|
|
143
|
+
Component: ExpandoCard,
|
|
144
|
+
createObject: createExpando,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const _Json = {
|
|
149
|
+
render: () => {
|
|
150
|
+
const data = {
|
|
151
|
+
subject: {
|
|
152
|
+
id: random.string.uuid(),
|
|
153
|
+
name: random.person.fullName(),
|
|
154
|
+
email: random.internet.email(),
|
|
155
|
+
tags: [random.lorem.word(), random.lorem.word(), random.lorem.word()],
|
|
156
|
+
nested: {
|
|
157
|
+
count: random.number.int({ max: 100 }),
|
|
158
|
+
active: random.datatype.boolean(),
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
<div className='flex justify-center p-16'>
|
|
165
|
+
<div className='dx-card-min-width dx-card-max-width'>
|
|
166
|
+
<Card.Root>
|
|
167
|
+
<Card.Header>
|
|
168
|
+
<Card.IconBlock />
|
|
169
|
+
<Card.Title>JSON</Card.Title>
|
|
170
|
+
</Card.Header>
|
|
171
|
+
<JsonCard data={data} />
|
|
172
|
+
</Card.Root>
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
61
176
|
},
|
|
62
177
|
};
|
package/src/stories/testing.tsx
CHANGED
|
@@ -2,112 +2,152 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import React, { type FC, useMemo } from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
9
|
+
import { DXN, Obj, Ref, Type } from '@dxos/echo';
|
|
10
|
+
import { Annotation } from '@dxos/echo';
|
|
11
|
+
import { random } from '@dxos/random';
|
|
12
|
+
import { Card } from '@dxos/react-ui';
|
|
13
|
+
import { CardContainer, type CardContainerProps } from '@dxos/react-ui-mosaic/testing';
|
|
14
|
+
import { Expando } from '@dxos/schema';
|
|
15
|
+
import { Organization, Person, Pipeline, Task } from '@dxos/types';
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type CardProps<T extends Obj.Any> = {
|
|
16
|
-
Component: FC<PreviewProps<T>>;
|
|
17
|
-
subject: T;
|
|
18
|
-
icon?: string;
|
|
17
|
+
export type DefaultStoryProps<T extends Obj.Any, P extends {} = {}> = {
|
|
18
|
+
Component: FC<AppSurface.ObjectCardProps<T> & P>;
|
|
19
|
+
createObject: () => T;
|
|
19
20
|
image?: boolean;
|
|
21
|
+
componentProps?: P;
|
|
20
22
|
};
|
|
21
23
|
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
export const DefaultStory = <T extends Obj.Any, P extends {} = {}>({
|
|
25
|
+
Component,
|
|
26
|
+
createObject,
|
|
27
|
+
image,
|
|
28
|
+
componentProps,
|
|
29
|
+
}: DefaultStoryProps<T, P>) => {
|
|
30
|
+
const object = useMemo(() => createObject(), [createObject]);
|
|
31
|
+
const roles: CardContainerProps['role'][] = ['intrinsic', 'popover'];
|
|
26
32
|
|
|
27
|
-
export const Defaultstory = ({ role, cards }: DefaultstoryProps) => {
|
|
28
33
|
return (
|
|
29
|
-
<div className='
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
<div
|
|
33
|
-
<
|
|
34
|
-
|
|
34
|
+
<div className='h-full w-full grid grid-cols-2 py-16 gap-8'>
|
|
35
|
+
{roles.map((role, i) => (
|
|
36
|
+
<div key={i} className='flex h-full justify-center overflow-hidden'>
|
|
37
|
+
<div className='flex flex-col gap-4 w-full items-center'>
|
|
38
|
+
<span className='text-sm text-description'>{role}</span>
|
|
39
|
+
<CardContainer role={role}>
|
|
40
|
+
<Card.Root border={false}>
|
|
41
|
+
<Card.Header>
|
|
42
|
+
<Card.DragHandle />
|
|
43
|
+
<Card.Title>{Obj.getLabel(object)}</Card.Title>
|
|
44
|
+
<Card.Menu />
|
|
45
|
+
</Card.Header>
|
|
46
|
+
<Component
|
|
47
|
+
role={role ?? 'card--content'}
|
|
48
|
+
subject={image ? object : omitImage(object)}
|
|
49
|
+
{...(componentProps ?? ({} as P))}
|
|
50
|
+
/>
|
|
51
|
+
</Card.Root>
|
|
35
52
|
</CardContainer>
|
|
36
53
|
</div>
|
|
37
|
-
|
|
38
|
-
|
|
54
|
+
</div>
|
|
55
|
+
))}
|
|
39
56
|
</div>
|
|
40
57
|
);
|
|
41
58
|
};
|
|
42
59
|
|
|
43
60
|
export const omitImage = ({ image: _, ...rest }: any) => rest;
|
|
44
61
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Factory functions for creating test objects at render time.
|
|
64
|
+
*/
|
|
65
|
+
export const createOrganization = (): Organization.Organization => {
|
|
66
|
+
return Obj.make(Organization.Organization, {
|
|
67
|
+
name: random.company.name(),
|
|
49
68
|
image:
|
|
50
69
|
'https://plus.unsplash.com/premium_photo-1672116452571-896980a801c8?q=80&w=2671&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
|
|
51
|
-
website:
|
|
52
|
-
description:
|
|
70
|
+
website: random.internet.url(),
|
|
71
|
+
description: random.lorem.paragraph(),
|
|
53
72
|
});
|
|
73
|
+
};
|
|
54
74
|
|
|
55
|
-
|
|
56
|
-
|
|
75
|
+
export const createPerson = (): Person.Person => {
|
|
76
|
+
const organization = createOrganization();
|
|
77
|
+
return Obj.make(Person.Person, {
|
|
78
|
+
fullName: random.person.fullName(),
|
|
57
79
|
image:
|
|
58
80
|
'https://plus.unsplash.com/premium_photo-1664536392779-049ba8fde933?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
|
|
59
81
|
organization: Ref.make(organization),
|
|
60
82
|
emails: [
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
label: 'Work',
|
|
67
|
-
value: faker.internet.email(),
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
label: 'Work',
|
|
71
|
-
value: faker.internet.email(),
|
|
72
|
-
},
|
|
83
|
+
{ label: 'Work', value: random.internet.email() },
|
|
84
|
+
{ label: 'Work', value: random.internet.email() },
|
|
85
|
+
{ label: 'Work', value: random.internet.email() },
|
|
73
86
|
],
|
|
74
87
|
});
|
|
88
|
+
};
|
|
75
89
|
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
export const createProject = (): Pipeline.Pipeline => {
|
|
91
|
+
return Obj.make(Pipeline.Pipeline, {
|
|
92
|
+
name: random.person.fullName(),
|
|
78
93
|
image: 'https://dxos.network/dxos-logotype-blue.png',
|
|
79
|
-
description:
|
|
94
|
+
description: random.lorem.paragraph(),
|
|
95
|
+
columns: [],
|
|
80
96
|
});
|
|
97
|
+
};
|
|
81
98
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
99
|
+
export const createTask = (): Task.Task => {
|
|
100
|
+
return Obj.make(Task.Task, {
|
|
101
|
+
title: random.lorem.sentence(),
|
|
102
|
+
status: random.helpers.arrayElement(['todo', 'in-progress', 'done'] as const),
|
|
85
103
|
});
|
|
104
|
+
};
|
|
86
105
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Plain object cast as `Obj.Any` — has no schema, typename, or database, so cards
|
|
108
|
+
* like `FormCard` fall through to their empty/unsupported state. Use to story-pin
|
|
109
|
+
* fallback rendering.
|
|
110
|
+
*/
|
|
111
|
+
export const createUnknown = (): Obj.Any => ({}) as unknown as Obj.Any;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Typed object with no user-facing values (only `id`). All Person fields are
|
|
115
|
+
* optional, so `Obj.make(Person, {})` is valid and triggers the FormCard
|
|
116
|
+
* "no values" branch in readonly mode.
|
|
117
|
+
*/
|
|
118
|
+
export const createPersonEmpty = (): Person.Person => Obj.make(Person.Person, {});
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Mock of the `Table` schema (org.dxos.type.table): an optional `name` plus
|
|
122
|
+
* `view` and `sizes` fields annotated with `FormInputAnnotation.set(false)`.
|
|
123
|
+
* When constructed without a `name`, no form-renderable field has a value so
|
|
124
|
+
* FormCard should fall through to its empty state — even though
|
|
125
|
+
* `Object.keys(subject)` includes `view`/`sizes`.
|
|
126
|
+
*/
|
|
127
|
+
const TableLike = Schema.Struct({
|
|
128
|
+
name: Schema.String.pipe(Schema.optional),
|
|
129
|
+
view: Schema.String.pipe(Annotation.FormInputAnnotation.set(false)),
|
|
130
|
+
sizes: Schema.Record({ key: Schema.String, value: Schema.Number }).pipe(
|
|
131
|
+
Schema.mutable,
|
|
132
|
+
Annotation.FormInputAnnotation.set(false),
|
|
133
|
+
),
|
|
134
|
+
}).pipe(Type.makeObject(DXN.make('org.dxos.test.table-like', '0.1.0')));
|
|
135
|
+
type TableLike = Type.InstanceType<typeof TableLike>;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Table-like object with values only in form-hidden fields (`view`, `sizes`).
|
|
139
|
+
* `Object.keys` includes them, but a naive `hasValues` check would
|
|
140
|
+
* misclassify this as having data. FormCard must consult the schema's
|
|
141
|
+
* form-input annotations to correctly fall through to the empty state.
|
|
142
|
+
*/
|
|
143
|
+
export const createTableEmpty = (): TableLike =>
|
|
144
|
+
Obj.make(TableLike, { view: 'view-dxn:placeholder', sizes: {} } as Obj.MakeProps<typeof TableLike>);
|
|
145
|
+
|
|
146
|
+
export const createExpando = (): Expando.Expando => {
|
|
147
|
+
return Expando.make({
|
|
148
|
+
name: random.person.fullName(),
|
|
149
|
+
email: random.internet.email(),
|
|
150
|
+
age: random.number.int({ min: 18, max: 80 }),
|
|
151
|
+
active: random.datatype.boolean(),
|
|
152
|
+
});
|
|
113
153
|
};
|
package/src/testing.ts
ADDED
package/src/translations.ts
CHANGED
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
import { meta } from '
|
|
7
|
+
import { meta } from '#meta';
|
|
8
8
|
|
|
9
9
|
export const translations = [
|
|
10
10
|
{
|
|
11
11
|
'en-US': {
|
|
12
12
|
[meta.id]: {
|
|
13
|
-
'unable
|
|
14
|
-
'todo
|
|
15
|
-
'in-progress
|
|
16
|
-
'done
|
|
17
|
-
'open
|
|
18
|
-
'add
|
|
19
|
-
'more
|
|
13
|
+
'unable-to-create-preview.message': 'No preview',
|
|
14
|
+
'todo.label': 'To do',
|
|
15
|
+
'in-progress.label': 'In progress',
|
|
16
|
+
'done.label': 'Done',
|
|
17
|
+
'open-object.label': 'Open',
|
|
18
|
+
'add-object-to-space.label': 'Add to space',
|
|
19
|
+
'more-options.label': 'More options',
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
22
|
},
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/meta.ts
|
|
2
|
-
var meta = {
|
|
3
|
-
id: "dxos.org/plugin/preview",
|
|
4
|
-
name: "Preview",
|
|
5
|
-
icon: "ph--eye--regular",
|
|
6
|
-
source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview"
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
meta
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=chunk-XKCIQK3C.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/meta.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const meta: PluginMeta = {\n id: 'dxos.org/plugin/preview',\n name: 'Preview',\n icon: 'ph--eye--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview',\n};\n"],
|
|
5
|
-
"mappings": ";AAMO,IAAMA,OAAmB;EAC9BC,IAAI;EACJC,MAAM;EACNC,MAAM;EACNC,QAAQ;AACV;",
|
|
6
|
-
"names": ["meta", "id", "name", "icon", "source"]
|
|
7
|
-
}
|