@dxos/plugin-preview 0.8.4-main.c1de068 → 0.8.4-main.dedc0f3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/lib/browser/index.mjs +6 -3
  2. package/dist/lib/browser/index.mjs.map +2 -2
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/{preview-popover-2UCEZUQW.mjs → preview-popover-HC6LHWXZ.mjs} +5 -10
  5. package/dist/lib/browser/preview-popover-HC6LHWXZ.mjs.map +7 -0
  6. package/dist/lib/browser/{react-surface-CZMUEWPV.mjs → react-surface-JGO43GLE.mjs} +146 -68
  7. package/dist/lib/browser/react-surface-JGO43GLE.mjs.map +7 -0
  8. package/dist/lib/node-esm/index.mjs +6 -3
  9. package/dist/lib/node-esm/index.mjs.map +2 -2
  10. package/dist/lib/node-esm/meta.json +1 -1
  11. package/dist/lib/node-esm/{preview-popover-OSHWR2YE.mjs → preview-popover-ROGTBCTT.mjs} +5 -10
  12. package/dist/lib/node-esm/preview-popover-ROGTBCTT.mjs.map +7 -0
  13. package/dist/lib/node-esm/{react-surface-IPZBISWS.mjs → react-surface-Q7F36L3Z.mjs} +146 -68
  14. package/dist/lib/node-esm/react-surface-Q7F36L3Z.mjs.map +7 -0
  15. package/dist/types/src/capabilities/index.d.ts +2 -2
  16. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  17. package/dist/types/src/capabilities/preview-popover.d.ts +1 -1
  18. package/dist/types/src/capabilities/preview-popover.d.ts.map +1 -1
  19. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  20. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  21. package/dist/types/src/components/CardSubjectMenu.d.ts +10 -0
  22. package/dist/types/src/components/CardSubjectMenu.d.ts.map +1 -0
  23. package/dist/types/src/components/ContactCard.d.ts +1 -1
  24. package/dist/types/src/components/ContactCard.d.ts.map +1 -1
  25. package/dist/types/src/components/OrganizationCard.d.ts +1 -1
  26. package/dist/types/src/components/OrganizationCard.d.ts.map +1 -1
  27. package/dist/types/src/components/ProjectCard.d.ts +1 -1
  28. package/dist/types/src/components/ProjectCard.d.ts.map +1 -1
  29. package/dist/types/src/components/TaskCard.d.ts +5 -0
  30. package/dist/types/src/components/TaskCard.d.ts.map +1 -0
  31. package/dist/types/src/stories/Card.stories.d.ts +27 -0
  32. package/dist/types/src/stories/Card.stories.d.ts.map +1 -0
  33. package/dist/types/src/stories/testing.d.ts +17 -0
  34. package/dist/types/src/stories/testing.d.ts.map +1 -0
  35. package/dist/types/src/translations.d.ts +3 -0
  36. package/dist/types/src/translations.d.ts.map +1 -1
  37. package/dist/types/src/types.d.ts +2 -1
  38. package/dist/types/src/types.d.ts.map +1 -1
  39. package/dist/types/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +29 -25
  41. package/src/capabilities/preview-popover.ts +8 -13
  42. package/src/capabilities/react-surface.tsx +9 -8
  43. package/src/components/CardSubjectMenu.tsx +56 -0
  44. package/src/components/ContactCard.tsx +28 -22
  45. package/src/components/OrganizationCard.tsx +10 -7
  46. package/src/components/ProjectCard.tsx +12 -4
  47. package/src/components/TaskCard.tsx +46 -0
  48. package/src/stories/Card.stories.tsx +59 -0
  49. package/src/stories/testing.tsx +114 -0
  50. package/src/translations.ts +3 -0
  51. package/src/types.ts +2 -2
  52. package/dist/lib/browser/preview-popover-2UCEZUQW.mjs.map +0 -7
  53. package/dist/lib/browser/react-surface-CZMUEWPV.mjs.map +0 -7
  54. package/dist/lib/node-esm/preview-popover-OSHWR2YE.mjs.map +0 -7
  55. package/dist/lib/node-esm/react-surface-IPZBISWS.mjs.map +0 -7
  56. package/dist/types/src/testing/ExtrinsicPreviews.stories.d.ts +0 -35
  57. package/dist/types/src/testing/ExtrinsicPreviews.stories.d.ts.map +0 -1
  58. package/dist/types/src/testing/IntrinsicPreviews.stories.d.ts +0 -35
  59. package/dist/types/src/testing/IntrinsicPreviews.stories.d.ts.map +0 -1
  60. package/dist/types/src/testing/PopoverPreviews.stories.d.ts +0 -35
  61. package/dist/types/src/testing/PopoverPreviews.stories.d.ts.map +0 -1
  62. package/dist/types/src/testing/util.d.ts +0 -80
  63. package/dist/types/src/testing/util.d.ts.map +0 -1
  64. package/src/testing/ExtrinsicPreviews.stories.tsx +0 -55
  65. package/src/testing/IntrinsicPreviews.stories.tsx +0 -55
  66. package/src/testing/PopoverPreviews.stories.tsx +0 -55
  67. package/src/testing/util.tsx +0 -79
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-preview",
3
- "version": "0.8.4-main.c1de068",
3
+ "version": "0.8.4-main.dedc0f3",
4
4
  "description": "Preview plugin",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -10,6 +10,7 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
13
+ "source": "./src/index.ts",
13
14
  "types": "./dist/types/src/index.d.ts",
14
15
  "browser": "./dist/lib/browser/index.mjs"
15
16
  }
@@ -23,35 +24,38 @@
23
24
  "src"
24
25
  ],
25
26
  "dependencies": {
27
+ "@effect-rx/rx-react": "0.38.0",
26
28
  "@preact-signals/safe-react": "^0.9.0",
27
- "@dxos/app-framework": "0.8.4-main.c1de068",
28
- "@dxos/async": "0.8.4-main.c1de068",
29
- "@dxos/client": "0.8.4-main.c1de068",
30
- "@dxos/echo": "0.8.4-main.c1de068",
31
- "@dxos/keys": "0.8.4-main.c1de068",
32
- "@dxos/lit-ui": "0.8.4-main.c1de068",
33
- "@dxos/log": "0.8.4-main.c1de068",
34
- "@dxos/echo-schema": "0.8.4-main.c1de068",
35
- "@dxos/plugin-attention": "0.8.4-main.c1de068",
36
- "@dxos/plugin-client": "0.8.4-main.c1de068",
37
- "@dxos/plugin-deck": "0.8.4-main.c1de068",
38
- "@dxos/react-client": "0.8.4-main.c1de068",
39
- "@dxos/react-ui": "0.8.4-main.c1de068",
40
- "@dxos/react-ui-editor": "0.8.4-main.c1de068",
41
- "@dxos/react-ui-form": "0.8.4-main.c1de068",
42
- "@dxos/react-ui-stack": "0.8.4-main.c1de068",
43
- "@dxos/react-ui-table": "0.8.4-main.c1de068",
44
- "@dxos/react-ui-theme": "0.8.4-main.c1de068",
45
- "@dxos/schema": "0.8.4-main.c1de068",
46
- "@dxos/util": "0.8.4-main.c1de068"
29
+ "@dxos/app-framework": "0.8.4-main.dedc0f3",
30
+ "@dxos/app-graph": "0.8.4-main.dedc0f3",
31
+ "@dxos/async": "0.8.4-main.dedc0f3",
32
+ "@dxos/client": "0.8.4-main.dedc0f3",
33
+ "@dxos/echo": "0.8.4-main.dedc0f3",
34
+ "@dxos/echo-schema": "0.8.4-main.dedc0f3",
35
+ "@dxos/keys": "0.8.4-main.dedc0f3",
36
+ "@dxos/log": "0.8.4-main.dedc0f3",
37
+ "@dxos/plugin-client": "0.8.4-main.dedc0f3",
38
+ "@dxos/plugin-attention": "0.8.4-main.dedc0f3",
39
+ "@dxos/plugin-deck": "0.8.4-main.dedc0f3",
40
+ "@dxos/react-client": "0.8.4-main.dedc0f3",
41
+ "@dxos/react-ui": "0.8.4-main.dedc0f3",
42
+ "@dxos/lit-ui": "0.8.4-main.dedc0f3",
43
+ "@dxos/react-ui-editor": "0.8.4-main.dedc0f3",
44
+ "@dxos/react-ui-form": "0.8.4-main.dedc0f3",
45
+ "@dxos/react-ui-menu": "0.8.4-main.dedc0f3",
46
+ "@dxos/react-ui-stack": "0.8.4-main.dedc0f3",
47
+ "@dxos/react-ui-table": "0.8.4-main.dedc0f3",
48
+ "@dxos/react-ui-theme": "0.8.4-main.dedc0f3",
49
+ "@dxos/schema": "0.8.4-main.dedc0f3",
50
+ "@dxos/util": "0.8.4-main.dedc0f3"
47
51
  },
48
52
  "devDependencies": {
49
- "effect": "3.17.0",
53
+ "effect": "3.17.7",
50
54
  "react": "~18.2.0",
51
55
  "react-dom": "~18.2.0",
52
- "vite": "5.4.7",
53
- "@dxos/random": "0.8.4-main.c1de068",
54
- "@dxos/storybook-utils": "0.8.4-main.c1de068"
56
+ "vite": "7.1.1",
57
+ "@dxos/random": "0.8.4-main.dedc0f3",
58
+ "@dxos/storybook-utils": "0.8.4-main.dedc0f3"
55
59
  },
56
60
  "peerDependencies": {
57
61
  "effect": "^3.13.3",
@@ -2,12 +2,12 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Capabilities, LayoutAction, contributes, createIntent, type PluginContext } from '@dxos/app-framework';
5
+ import { Capabilities, LayoutAction, type PluginContext, contributes, createIntent } from '@dxos/app-framework';
6
6
  import { addEventListener } from '@dxos/async';
7
- import { type Client, resolveRef } from '@dxos/client';
8
- import { parseId, type Space } from '@dxos/client/echo';
7
+ import { type Client } from '@dxos/client';
8
+ import { type Space, parseId } from '@dxos/client/echo';
9
9
  import { DXN } from '@dxos/keys';
10
- import { type DxRefTagActivate } from '@dxos/lit-ui';
10
+ import { type DxAnchorActivate } from '@dxos/lit-ui';
11
11
  import { log } from '@dxos/log';
12
12
  import { ClientCapabilities } from '@dxos/plugin-client';
13
13
  import { type PreviewLinkRef, type PreviewLinkTarget } from '@dxos/react-ui-editor';
@@ -20,12 +20,7 @@ const handlePreviewLookup = async (
20
20
  { ref, label }: PreviewLinkRef,
21
21
  ): Promise<PreviewLinkTarget | null> => {
22
22
  try {
23
- const dxn = DXN.parse(ref);
24
- if (!dxn) {
25
- return null;
26
- }
27
-
28
- const object = await resolveRef(client, dxn, defaultSpace);
23
+ const object = await defaultSpace.db.ref(DXN.parse(ref)).load();
29
24
  return { label, object };
30
25
  } catch (err) {
31
26
  return null;
@@ -34,7 +29,7 @@ const handlePreviewLookup = async (
34
29
 
35
30
  export default (context: PluginContext) => {
36
31
  // TODO(wittjosiah): Factor out lookup handlers to other plugins to make not ECHO-specific.
37
- const handleDxRefTagActivate = async ({ refId, label, trigger }: DxRefTagActivate) => {
32
+ const handleDxAnchorActivate = async ({ refId, label, trigger }: DxAnchorActivate) => {
38
33
  const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);
39
34
  const client = context.getCapability(ClientCapabilities.Client);
40
35
  const [layout] = context.getCapabilities(Capabilities.Layout);
@@ -62,8 +57,8 @@ export default (context: PluginContext) => {
62
57
  if (document.defaultView) {
63
58
  cleanup = addEventListener(
64
59
  document.defaultView,
65
- 'dx-ref-tag-activate' as any,
66
- handleDxRefTagActivate,
60
+ 'dx-anchor-activate' as any,
61
+ handleDxAnchorActivate,
67
62
  customEventOptions,
68
63
  );
69
64
  } else {
@@ -23,9 +23,9 @@ import { useQuery, useSpace } from '@dxos/react-client/echo';
23
23
  import { useTranslation } from '@dxos/react-ui';
24
24
  import { Form } from '@dxos/react-ui-form';
25
25
  import { Card } from '@dxos/react-ui-stack';
26
- import { TableView } from '@dxos/react-ui-table/types';
26
+ import { Table } from '@dxos/react-ui-table/types';
27
27
  import { descriptionMessage, mx } from '@dxos/react-ui-theme';
28
- import { DataType } from '@dxos/schema';
28
+ import { DataType, type ProjectionModel, typenameFromQuery } from '@dxos/schema';
29
29
 
30
30
  import { ContactCard, OrganizationCard, ProjectCard } from '../components';
31
31
  import { PREVIEW_PLUGIN } from '../meta';
@@ -49,13 +49,13 @@ export default () =>
49
49
  const defaultSpaceViews = useQuery(defaultSpace, Filter.type(DataType.View));
50
50
  const currentSpaceOrgTable = currentSpaceViews.find(
51
51
  (view) =>
52
- view.query.typename === DataType.Organization.typename &&
53
- Obj.instanceOf(TableView, view.presentation.target),
52
+ typenameFromQuery(view.query) === DataType.Organization.typename &&
53
+ Obj.instanceOf(Table.Table, view.presentation.target),
54
54
  );
55
55
  const defaultSpaceOrgTable = defaultSpaceViews.find(
56
56
  (view) =>
57
- view.query.typename === DataType.Organization.typename &&
58
- Obj.instanceOf(TableView, view.presentation.target),
57
+ typenameFromQuery(view.query) === DataType.Organization.typename &&
58
+ Obj.instanceOf(Table.Table, view.presentation.target),
59
59
  );
60
60
 
61
61
  // TODO(wittjosiah): Generalized way of handling related objects navigation.
@@ -129,7 +129,7 @@ export default () =>
129
129
  id: `${PREVIEW_PLUGIN}/fallback-popover`,
130
130
  role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
131
131
  position: 'fallback',
132
- filter: (data): data is { subject: Obj.Any } => Obj.isObject(data.subject),
132
+ filter: (data): data is { subject: Obj.Any; projection?: ProjectionModel } => Obj.isObject(data.subject),
133
133
  component: ({ data, role }) => {
134
134
  const schema = getSchema(data.subject);
135
135
  const { t } = useTranslation(PREVIEW_PLUGIN);
@@ -150,8 +150,9 @@ export default () =>
150
150
  <Card.SurfaceRoot role={role}>
151
151
  <Form
152
152
  schema={schema}
153
+ projection={data.projection}
153
154
  values={data.subject}
154
- readonly={role === 'card--popover'}
155
+ readonly={role === 'card--popover' ? 'static' : false}
155
156
  onSave={handleSave}
156
157
  autoSave
157
158
  {...(role === 'card--intrinsic' && { outerSpacing: 'blockStart-0' })}
@@ -0,0 +1,56 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Rx } from '@effect-rx/rx-react';
6
+ import React from 'react';
7
+
8
+ // import { useIntentDispatcher } from '@dxos/app-framework';
9
+ import { ACTION_TYPE } from '@dxos/app-graph';
10
+ import { type AnyEchoObject } from '@dxos/echo-schema';
11
+ import { IconButton, type IconButtonProps, useTranslation } from '@dxos/react-ui';
12
+ import { type ActionGraphProps, DropdownMenu, MenuProvider, useMenuActions } from '@dxos/react-ui-menu';
13
+
14
+ const useSubjectMenuGroupItems = (subject: AnyEchoObject) => {
15
+ // const { dispatchPromise: dispatch } = useIntentDispatcher();
16
+ const result: ActionGraphProps = { edges: [], nodes: [] };
17
+ result.nodes.push({
18
+ type: ACTION_TYPE,
19
+ id: `${subject.id}/add-to-space`,
20
+ data: () => console.log('[TO DO]', 'add object to space', subject),
21
+ properties: {
22
+ label: ['add object to space label', { ns: 'os' }],
23
+ icon: 'ph--file-plus--regular',
24
+ },
25
+ });
26
+ result.nodes.forEach(({ id: target }) => {
27
+ result.edges.push({ source: 'root', target });
28
+ });
29
+ return useMenuActions(Rx.make(result));
30
+ };
31
+
32
+ /**
33
+ * This is a generic menu for objects that tries to infer common actions.
34
+ */
35
+ export const CardSubjectMenu = ({
36
+ subject,
37
+ ...props
38
+ }: Omit<IconButtonProps, 'icon' | 'label'> & { subject: AnyEchoObject }) => {
39
+ const { t } = useTranslation('os');
40
+ const menuProps = useSubjectMenuGroupItems(subject);
41
+ return (
42
+ <MenuProvider {...menuProps}>
43
+ <DropdownMenu.Root>
44
+ <DropdownMenu.Trigger asChild>
45
+ <IconButton
46
+ iconOnly
47
+ variant='ghost'
48
+ icon='ph--dots-three-vertical--bold'
49
+ label={t('more options label')}
50
+ {...props}
51
+ />
52
+ </DropdownMenu.Trigger>
53
+ </DropdownMenu.Root>
54
+ </MenuProvider>
55
+ );
56
+ };
@@ -4,29 +4,33 @@
4
4
 
5
5
  import React, { Fragment } from 'react';
6
6
 
7
- import { Icon, Avatar, Button } from '@dxos/react-ui';
7
+ import { Avatar, Button, Icon } from '@dxos/react-ui';
8
8
  import { Card, cardHeading, cardText } from '@dxos/react-ui-stack';
9
9
  import { mx } from '@dxos/react-ui-theme';
10
10
  import { type DataType } from '@dxos/schema';
11
11
 
12
12
  import { type PreviewProps } from '../types';
13
13
 
14
+ import { CardSubjectMenu } from './CardSubjectMenu';
15
+
14
16
  export const ContactCard = ({
15
17
  children,
16
- subject: { fullName, image, organization, emails },
18
+ subject,
17
19
  onOrgClick,
18
20
  role,
19
21
  }: PreviewProps<DataType.Person> & { onOrgClick?: (org: DataType.Organization) => void }) => {
22
+ const { fullName, image, organization, emails } = subject;
20
23
  const organizationName = organization && typeof organization === 'object' ? organization.target?.name : organization;
21
24
  return (
22
25
  <Card.SurfaceRoot role={role}>
23
26
  <Avatar.Root>
24
27
  <Card.Text role='group' classNames='grid gap-3 grid-cols-[min-content_1fr]'>
25
28
  <Avatar.Content imgSrc={image} icon='ph--user--regular' size={16} hue='neutral' />
26
- <div role='none' className='bs-min self-center'>
29
+ <div role='none' className='bs-min self-center flex items-center'>
27
30
  <Avatar.Label asChild>
28
- <h2 className={cardHeading}>{fullName}</h2>
31
+ <h2 className={mx(cardHeading, 'grow')}>{fullName}</h2>
29
32
  </Avatar.Label>
33
+ <CardSubjectMenu subject={subject} />
30
34
  </div>
31
35
  </Card.Text>
32
36
  </Avatar.Root>
@@ -46,24 +50,26 @@ export const ContactCard = ({
46
50
  )}
47
51
  </Card.Chrome>
48
52
  )}
49
- <dl
50
- className={mx(
51
- cardText,
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>
53
+ {emails?.length && (
54
+ <dl
55
+ className={mx(
56
+ cardText,
57
+ 'grid gap-2 grid-cols-[min-content_1fr] [&_dt]:text-subdued [&_dt]:pbs-0.5 [&_dd]:min-is-0',
58
+ )}
59
+ >
60
+ {emails?.length &&
61
+ emails.map(({ label, value }) => (
62
+ <Fragment key={value}>
63
+ <dt>
64
+ <Icon icon='ph--at--regular' size={5} />
65
+ </dt>
66
+ <dd key={value} className='break-words'>
67
+ {value}
68
+ </dd>
69
+ </Fragment>
70
+ ))}
71
+ </dl>
72
+ )}
67
73
  {children}
68
74
  </Card.SurfaceRoot>
69
75
  );
@@ -5,20 +5,23 @@
5
5
  import React from 'react';
6
6
 
7
7
  import { Icon } from '@dxos/react-ui';
8
- import { Card } from '@dxos/react-ui-stack';
8
+ import { Card, cardNoSpacing, cardSpacing } from '@dxos/react-ui-stack';
9
+ import { mx } from '@dxos/react-ui-theme';
9
10
  import { type DataType } from '@dxos/schema';
10
11
 
11
12
  import { type PreviewProps } from '../types';
12
13
 
13
- export const OrganizationCard = ({
14
- children,
15
- subject: { name, image, description, website },
16
- role,
17
- }: PreviewProps<DataType.Organization>) => {
14
+ import { CardSubjectMenu } from './CardSubjectMenu';
15
+
16
+ export const OrganizationCard = ({ children, subject, role }: PreviewProps<DataType.Organization>) => {
17
+ const { name, image, description, website } = subject;
18
18
  return (
19
19
  <Card.SurfaceRoot role={role}>
20
20
  <Card.Poster alt={name!} {...(image ? { image } : { icon: 'ph--building-office--regular' })} />
21
- <Card.Heading>{name}</Card.Heading>
21
+ <div role='none' className={mx('flex items-center gap-2', cardSpacing)}>
22
+ <Card.Heading classNames={cardNoSpacing}>{name}</Card.Heading>
23
+ <CardSubjectMenu subject={subject} />
24
+ </div>
22
25
  {description && <Card.Text classNames='line-clamp-2'>{description}</Card.Text>}
23
26
  {website && (
24
27
  <Card.Chrome>
@@ -4,16 +4,24 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { Card } from '@dxos/react-ui-stack';
7
+ import { Obj } from '@dxos/echo';
8
+ import { Card, cardNoSpacing, cardSpacing } from '@dxos/react-ui-stack';
9
+ import { mx } from '@dxos/react-ui-theme';
8
10
  import { type DataType } from '@dxos/schema';
9
11
 
10
12
  import { type PreviewProps } from '../types';
11
13
 
12
- export const ProjectCard = ({ subject: { name, image, description }, role }: PreviewProps<DataType.Project>) => {
14
+ import { CardSubjectMenu } from './CardSubjectMenu';
15
+
16
+ export const ProjectCard = ({ subject, role }: PreviewProps<DataType.Project>) => {
17
+ const { name, image, description } = subject;
13
18
  return (
14
19
  <Card.SurfaceRoot role={role}>
15
- {image && <Card.Poster image={image} alt={name} aspect='auto' />}
16
- <Card.Heading>{name}</Card.Heading>
20
+ {image && <Card.Poster image={image} alt={Obj.getLabel(subject) ?? ''} aspect='auto' />}
21
+ <div role='none' className={mx('flex items-center gap-2', cardSpacing)}>
22
+ <Card.Heading classNames={cardNoSpacing}>{name}</Card.Heading>
23
+ <CardSubjectMenu subject={subject} />
24
+ </div>
17
25
  {description && <Card.Text classNames='line-clamp-2'>{description}</Card.Text>}
18
26
  </Card.SurfaceRoot>
19
27
  );
@@ -0,0 +1,46 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { SchemaAST } from 'effect';
6
+ import React from 'react';
7
+
8
+ import { type PropertyMetaAnnotation, PropertyMetaAnnotationId } from '@dxos/echo-schema';
9
+ import { Card, cardNoSpacing, cardSpacing } from '@dxos/react-ui-stack';
10
+ import { mx } from '@dxos/react-ui-theme';
11
+ import { DataType } from '@dxos/schema';
12
+
13
+ import { type PreviewProps } from '../types';
14
+
15
+ import { CardSubjectMenu } from './CardSubjectMenu';
16
+
17
+ // TODO(thure): Should this move upstream as a helper? Is there an easier way to get options?
18
+ const getActiveStatusOption = (status?: string) => {
19
+ const properties = SchemaAST.getPropertySignatures(DataType.Task.ast);
20
+ const statusProperty = properties.find((p) => p.name === 'status');
21
+ const statusMeta = SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(
22
+ // TODO(thure): Typescript asserts `.type` doesn’t have `.types`, but in runtime it does.
23
+ (statusProperty!.type as any).types[0],
24
+ );
25
+ const options = // TODO(thure): Typescript asserts `statusMeta` doesn’t have `.value`, but in runtime it does.
26
+ (statusMeta as any).value.singleSelect.options as { id: string; title: string; color: string }[];
27
+ return options.find(({ id }) => id === status);
28
+ };
29
+
30
+ export const TaskCard = ({ subject, role }: PreviewProps<DataType.Task>) => {
31
+ const { title, status } = subject;
32
+ const statusOption = getActiveStatusOption(status);
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} />
43
+ </div>
44
+ </Card.SurfaceRoot>
45
+ );
46
+ };
@@ -0,0 +1,59 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
+
9
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
10
+
11
+ import { translations } from '../translations';
12
+
13
+ import { Defaultstory, createCards } from './testing';
14
+
15
+ const meta = {
16
+ title: 'plugins/plugin-preview/Card',
17
+ render: Defaultstory,
18
+ decorators: [
19
+ withTheme,
20
+ withLayout({
21
+ fullscreen: true,
22
+ classNames: 'flex flex-col justify-center',
23
+ }),
24
+ ],
25
+ parameters: { translations },
26
+ tags: ['cards'],
27
+ } satisfies Meta<typeof Defaultstory>;
28
+
29
+ export default meta;
30
+
31
+ type Story = StoryObj<typeof meta>;
32
+
33
+ export const Popover: Story = {
34
+ args: {
35
+ role: 'card--popover',
36
+ cards: createCards(),
37
+ },
38
+ };
39
+
40
+ export const Intrinsic: Story = {
41
+ args: {
42
+ role: 'card--intrinsic',
43
+ cards: createCards(),
44
+ },
45
+ };
46
+
47
+ export const Extrinsic: Story = {
48
+ args: {
49
+ role: 'card--extrinsic',
50
+ cards: createCards(),
51
+ },
52
+ };
53
+
54
+ export const ExtrinsicNoImage: Story = {
55
+ args: {
56
+ role: 'card--extrinsic',
57
+ cards: createCards(false),
58
+ },
59
+ };
@@ -0,0 +1,114 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React, { type FC } from 'react';
6
+
7
+ import { Obj, Ref } from '@dxos/echo';
8
+ import { faker } from '@dxos/random';
9
+ import { CardContainer } from '@dxos/react-ui-stack/testing';
10
+ import { DataType } from '@dxos/schema';
11
+
12
+ import { ContactCard, OrganizationCard, ProjectCard } from '../components';
13
+ import { TaskCard } from '../components/TaskCard';
14
+ import { type PreviewProps } from '../types';
15
+
16
+ faker.seed(1234);
17
+
18
+ type CardProps<T extends object> = {
19
+ Component: FC<PreviewProps<T>>;
20
+ subject: T;
21
+ icon?: string;
22
+ image?: boolean;
23
+ };
24
+
25
+ export type DefaultstoryProps = {
26
+ role: 'card--popover' | 'card--intrinsic' | 'card--extrinsic' | 'card--transclusion';
27
+ cards: CardProps<any>[];
28
+ };
29
+
30
+ export const Defaultstory = ({ role, cards }: DefaultstoryProps) => {
31
+ return (
32
+ <div className='grid grid-cols-4'>
33
+ {cards.map(({ Component, icon, image, subject }, i) => (
34
+ <div key={i} className='flex justify-center'>
35
+ <CardContainer icon={icon} role={role}>
36
+ <Component role={role} subject={image ? subject : omitImage(subject)} />
37
+ </CardContainer>
38
+ </div>
39
+ ))}
40
+ </div>
41
+ );
42
+ };
43
+
44
+ export const omitImage = ({ image: _, ...rest }: any) => rest;
45
+
46
+ // TODO(burdon): Test data should exercise the standard data generators.
47
+ export const createCards = (image = true): CardProps<any>[] => {
48
+ const organization = Obj.make(DataType.Organization, {
49
+ name: faker.company.name(),
50
+ image:
51
+ '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',
52
+ website: faker.internet.url(),
53
+ description: faker.lorem.paragraph(),
54
+ });
55
+
56
+ const contact = Obj.make(DataType.Person, {
57
+ fullName: faker.person.fullName(),
58
+ image:
59
+ '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',
60
+ organization: Ref.make(organization),
61
+ emails: [
62
+ {
63
+ label: 'Work',
64
+ value: faker.internet.email(),
65
+ },
66
+ {
67
+ label: 'Work',
68
+ value: faker.internet.email(),
69
+ },
70
+ {
71
+ label: 'Work',
72
+ value: faker.internet.email(),
73
+ },
74
+ ],
75
+ });
76
+
77
+ const project = DataType.makeProject({
78
+ name: faker.person.fullName(),
79
+ image: 'https://dxos.network/dxos-logotype-blue.png',
80
+ description: faker.lorem.paragraph(),
81
+ });
82
+
83
+ const task = Obj.make(DataType.Task, {
84
+ title: faker.lorem.sentence(),
85
+ status: faker.helpers.arrayElement(['todo', 'in-progress', 'done']),
86
+ });
87
+
88
+ return [
89
+ {
90
+ Component: OrganizationCard,
91
+ subject: organization,
92
+ icon: 'ph--building-office--regular',
93
+ image,
94
+ },
95
+ {
96
+ Component: ContactCard,
97
+ subject: contact,
98
+ icon: 'ph--user--regular',
99
+ image,
100
+ },
101
+ {
102
+ Component: ProjectCard,
103
+ subject: project,
104
+ icon: 'ph--building--regular',
105
+ image,
106
+ },
107
+ {
108
+ Component: TaskCard,
109
+ subject: task,
110
+ icon: 'ph--list-checks--regular',
111
+ image,
112
+ },
113
+ ];
114
+ };
@@ -11,6 +11,9 @@ export const translations = [
11
11
  'en-US': {
12
12
  [meta.id]: {
13
13
  'unable to create preview message': 'No preview',
14
+ 'todo label': 'To do',
15
+ 'in-progress label': 'In progress',
16
+ 'done label': 'Done',
14
17
  },
15
18
  },
16
19
  },
package/src/types.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import { type Schema } from 'effect';
5
6
  import { type PropsWithChildren } from 'react';
6
7
 
7
- // TODO(burdon): Better place for these defs?
8
- export type PreviewProps<T extends object> = PropsWithChildren<{
8
+ export type PreviewProps<T extends Schema.Schema.Type<any>> = PropsWithChildren<{
9
9
  subject: T;
10
10
  role?: string;
11
11
  }>;
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/capabilities/preview-popover.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capabilities, LayoutAction, contributes, createIntent, type PluginContext } from '@dxos/app-framework';\nimport { addEventListener } from '@dxos/async';\nimport { type Client, resolveRef } from '@dxos/client';\nimport { parseId, type Space } from '@dxos/client/echo';\nimport { DXN } from '@dxos/keys';\nimport { type DxRefTagActivate } from '@dxos/lit-ui';\nimport { log } from '@dxos/log';\nimport { ClientCapabilities } from '@dxos/plugin-client';\nimport { type PreviewLinkRef, type PreviewLinkTarget } from '@dxos/react-ui-editor';\n\nconst customEventOptions = { capture: true, passive: false };\n\nconst handlePreviewLookup = async (\n client: Client,\n defaultSpace: Space,\n { ref, label }: PreviewLinkRef,\n): Promise<PreviewLinkTarget | null> => {\n try {\n const dxn = DXN.parse(ref);\n if (!dxn) {\n return null;\n }\n\n const object = await resolveRef(client, dxn, defaultSpace);\n return { label, object };\n } catch (err) {\n return null;\n }\n};\n\nexport default (context: PluginContext) => {\n // TODO(wittjosiah): Factor out lookup handlers to other plugins to make not ECHO-specific.\n const handleDxRefTagActivate = async ({ refId, label, trigger }: DxRefTagActivate) => {\n const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);\n const client = context.getCapability(ClientCapabilities.Client);\n const [layout] = context.getCapabilities(Capabilities.Layout);\n const { spaceId } = parseId(layout.workspace);\n const space = (spaceId && client.spaces.get(spaceId)) ?? client.spaces.default;\n const result = await handlePreviewLookup(client, space, { ref: refId, label });\n if (!result) {\n return;\n }\n\n await dispatch(\n createIntent(LayoutAction.UpdatePopover, {\n part: 'popover',\n subject: result.object,\n options: {\n state: true,\n variant: 'virtual',\n anchor: trigger,\n },\n }),\n );\n };\n\n let cleanup: () => void;\n if (document.defaultView) {\n cleanup = addEventListener(\n document.defaultView,\n 'dx-ref-tag-activate' as any,\n handleDxRefTagActivate,\n customEventOptions,\n );\n } else {\n log.warn('No default view found');\n }\n\n return contributes(Capabilities.Null, null, () => cleanup());\n};\n"],
5
- "mappings": ";AAIA,SAASA,cAAcC,cAAcC,aAAaC,oBAAwC;AAC1F,SAASC,wBAAwB;AACjC,SAAsBC,kBAAkB;AACxC,SAASC,eAA2B;AACpC,SAASC,WAAW;AAEpB,SAASC,WAAW;AACpB,SAASC,0BAA0B;;AAGnC,IAAMC,qBAAqB;EAAEC,SAAS;EAAMC,SAAS;AAAM;AAE3D,IAAMC,sBAAsB,OAC1BC,QACAC,cACA,EAAEC,KAAKC,MAAK,MAAkB;AAE9B,MAAI;AACF,UAAMC,MAAMX,IAAIY,MAAMH,GAAAA;AACtB,QAAI,CAACE,KAAK;AACR,aAAO;IACT;AAEA,UAAME,SAAS,MAAMf,WAAWS,QAAQI,KAAKH,YAAAA;AAC7C,WAAO;MAAEE;MAAOG;IAAO;EACzB,SAASC,KAAK;AACZ,WAAO;EACT;AACF;AAEA,IAAA,0BAAe,CAACC,YAAAA;AAEd,QAAMC,yBAAyB,OAAO,EAAEC,OAAOP,OAAOQ,QAAO,MAAoB;AAC/E,UAAM,EAAEC,iBAAiBC,SAAQ,IAAKL,QAAQM,cAAc5B,aAAa6B,gBAAgB;AACzF,UAAMf,SAASQ,QAAQM,cAAcnB,mBAAmBqB,MAAM;AAC9D,UAAM,CAACC,MAAAA,IAAUT,QAAQU,gBAAgBhC,aAAaiC,MAAM;AAC5D,UAAM,EAAEC,QAAO,IAAK5B,QAAQyB,OAAOI,SAAS;AAC5C,UAAMC,SAASF,WAAWpB,OAAOuB,OAAOC,IAAIJ,OAAAA,MAAapB,OAAOuB,OAAOE;AACvE,UAAMC,SAAS,MAAM3B,oBAAoBC,QAAQsB,OAAO;MAAEpB,KAAKQ;MAAOP;IAAM,CAAA;AAC5E,QAAI,CAACuB,QAAQ;AACX;IACF;AAEA,UAAMb,SACJxB,aAAaF,aAAawC,eAAe;MACvCC,MAAM;MACNC,SAASH,OAAOpB;MAChBwB,SAAS;QACPC,OAAO;QACPC,SAAS;QACTC,QAAQtB;MACV;IACF,CAAA,CAAA;EAEJ;AAEA,MAAIuB;AACJ,MAAIC,SAASC,aAAa;AACxBF,cAAU5C,iBACR6C,SAASC,aACT,uBACA3B,wBACAb,kBAAAA;EAEJ,OAAO;AACLF,QAAI2C,KAAK,yBAAA,QAAA;;;;;;EACX;AAEA,SAAOjD,YAAYF,aAAaoD,MAAM,MAAM,MAAMJ,QAAAA,CAAAA;AACpD;",
6
- "names": ["Capabilities", "LayoutAction", "contributes", "createIntent", "addEventListener", "resolveRef", "parseId", "DXN", "log", "ClientCapabilities", "customEventOptions", "capture", "passive", "handlePreviewLookup", "client", "defaultSpace", "ref", "label", "dxn", "parse", "object", "err", "context", "handleDxRefTagActivate", "refId", "trigger", "dispatchPromise", "dispatch", "getCapability", "IntentDispatcher", "Client", "layout", "getCapabilities", "Layout", "spaceId", "workspace", "space", "spaces", "get", "default", "result", "UpdatePopover", "part", "subject", "options", "state", "variant", "anchor", "cleanup", "document", "defaultView", "warn", "Null"]
7
- }