@dxos/plugin-preview 0.8.3 → 0.8.4-main.1f223c7

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 (77) hide show
  1. package/dist/lib/browser/{chunk-LFAK2TMG.mjs → chunk-Z73ENKLE.mjs} +2 -2
  2. package/dist/lib/browser/index.mjs +14 -11
  3. package/dist/lib/browser/index.mjs.map +3 -3
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/{preview-popover-NRFVC4QQ.mjs → preview-popover-55HRKRXY.mjs} +8 -12
  6. package/dist/lib/browser/preview-popover-55HRKRXY.mjs.map +7 -0
  7. package/dist/lib/browser/react-surface-JGO43GLE.mjs +381 -0
  8. package/dist/lib/browser/react-surface-JGO43GLE.mjs.map +7 -0
  9. package/dist/lib/node-esm/{chunk-7BPXNL44.mjs → chunk-2ORSL4GJ.mjs} +2 -2
  10. package/dist/lib/node-esm/index.mjs +14 -11
  11. package/dist/lib/node-esm/index.mjs.map +3 -3
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/{preview-popover-HBGSL64N.mjs → preview-popover-6GFVXZGN.mjs} +8 -12
  14. package/dist/lib/node-esm/preview-popover-6GFVXZGN.mjs.map +7 -0
  15. package/dist/lib/node-esm/react-surface-Q7F36L3Z.mjs +382 -0
  16. package/dist/lib/node-esm/react-surface-Q7F36L3Z.mjs.map +7 -0
  17. package/dist/types/src/capabilities/index.d.ts +2 -2
  18. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  19. package/dist/types/src/capabilities/preview-popover.d.ts +1 -1
  20. package/dist/types/src/capabilities/preview-popover.d.ts.map +1 -1
  21. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  22. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  23. package/dist/types/src/components/CardSubjectMenu.d.ts +10 -0
  24. package/dist/types/src/components/CardSubjectMenu.d.ts.map +1 -0
  25. package/dist/types/src/components/ContactCard.d.ts +1 -1
  26. package/dist/types/src/components/ContactCard.d.ts.map +1 -1
  27. package/dist/types/src/components/OrganizationCard.d.ts +1 -1
  28. package/dist/types/src/components/OrganizationCard.d.ts.map +1 -1
  29. package/dist/types/src/components/ProjectCard.d.ts +1 -1
  30. package/dist/types/src/components/ProjectCard.d.ts.map +1 -1
  31. package/dist/types/src/components/TaskCard.d.ts +5 -0
  32. package/dist/types/src/components/TaskCard.d.ts.map +1 -0
  33. package/dist/types/src/index.d.ts +1 -1
  34. package/dist/types/src/index.d.ts.map +1 -1
  35. package/dist/types/src/stories/Card.stories.d.ts +27 -0
  36. package/dist/types/src/stories/Card.stories.d.ts.map +1 -0
  37. package/dist/types/src/stories/testing.d.ts +17 -0
  38. package/dist/types/src/stories/testing.d.ts.map +1 -0
  39. package/dist/types/src/translations.d.ts +9 -6
  40. package/dist/types/src/translations.d.ts.map +1 -1
  41. package/dist/types/src/types.d.ts +2 -1
  42. package/dist/types/src/types.d.ts.map +1 -1
  43. package/dist/types/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +29 -24
  45. package/src/PreviewPlugin.tsx +1 -1
  46. package/src/capabilities/preview-popover.ts +8 -13
  47. package/src/capabilities/react-surface.tsx +73 -39
  48. package/src/components/CardSubjectMenu.tsx +56 -0
  49. package/src/components/ContactCard.tsx +30 -24
  50. package/src/components/OrganizationCard.tsx +12 -9
  51. package/src/components/ProjectCard.tsx +14 -6
  52. package/src/components/TaskCard.tsx +46 -0
  53. package/src/index.ts +1 -1
  54. package/src/stories/Card.stories.tsx +59 -0
  55. package/src/stories/testing.tsx +114 -0
  56. package/src/translations.ts +9 -4
  57. package/src/types.ts +2 -2
  58. package/dist/lib/browser/preview-popover-NRFVC4QQ.mjs.map +0 -7
  59. package/dist/lib/browser/react-surface-J2R6Q33B.mjs +0 -272
  60. package/dist/lib/browser/react-surface-J2R6Q33B.mjs.map +0 -7
  61. package/dist/lib/node/chunk-XGHMBEIV.cjs +0 -37
  62. package/dist/lib/node/chunk-XGHMBEIV.cjs.map +0 -7
  63. package/dist/lib/node/index.cjs +0 -85
  64. package/dist/lib/node/index.cjs.map +0 -7
  65. package/dist/lib/node/meta.json +0 -1
  66. package/dist/lib/node/preview-popover-HIXRYF6L.cjs +0 -88
  67. package/dist/lib/node/preview-popover-HIXRYF6L.cjs.map +0 -7
  68. package/dist/lib/node/react-surface-ZSNNAKBG.cjs +0 -290
  69. package/dist/lib/node/react-surface-ZSNNAKBG.cjs.map +0 -7
  70. package/dist/lib/node-esm/preview-popover-HBGSL64N.mjs.map +0 -7
  71. package/dist/lib/node-esm/react-surface-UKEVHG5K.mjs +0 -273
  72. package/dist/lib/node-esm/react-surface-UKEVHG5K.mjs.map +0 -7
  73. package/dist/types/src/Preview.stories.d.ts +0 -127
  74. package/dist/types/src/Preview.stories.d.ts.map +0 -1
  75. package/src/Preview.stories.tsx +0 -147
  76. /package/dist/lib/browser/{chunk-LFAK2TMG.mjs.map → chunk-Z73ENKLE.mjs.map} +0 -0
  77. /package/dist/lib/node-esm/{chunk-7BPXNL44.mjs.map → chunk-2ORSL4GJ.mjs.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-preview",
3
- "version": "0.8.3",
3
+ "version": "0.8.4-main.1f223c7",
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,34 +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
- "effect": "3.14.21",
28
- "@dxos/app-framework": "0.8.3",
29
- "@dxos/async": "0.8.3",
30
- "@dxos/echo": "0.8.3",
31
- "@dxos/echo-schema": "0.8.3",
32
- "@dxos/lit-ui": "0.8.3",
33
- "@dxos/plugin-client": "0.8.3",
34
- "@dxos/client": "0.8.3",
35
- "@dxos/log": "0.8.3",
36
- "@dxos/keys": "0.8.3",
37
- "@dxos/react-client": "0.8.3",
38
- "@dxos/react-ui": "0.8.3",
39
- "@dxos/react-ui-editor": "0.8.3",
40
- "@dxos/react-ui-stack": "0.8.3",
41
- "@dxos/react-ui-form": "0.8.3",
42
- "@dxos/react-ui-table": "0.8.3",
43
- "@dxos/react-ui-theme": "0.8.3",
44
- "@dxos/util": "0.8.3",
45
- "@dxos/schema": "0.8.3"
29
+ "@dxos/app-framework": "0.8.4-main.1f223c7",
30
+ "@dxos/app-graph": "0.8.4-main.1f223c7",
31
+ "@dxos/async": "0.8.4-main.1f223c7",
32
+ "@dxos/echo": "0.8.4-main.1f223c7",
33
+ "@dxos/client": "0.8.4-main.1f223c7",
34
+ "@dxos/echo-schema": "0.8.4-main.1f223c7",
35
+ "@dxos/keys": "0.8.4-main.1f223c7",
36
+ "@dxos/lit-ui": "0.8.4-main.1f223c7",
37
+ "@dxos/log": "0.8.4-main.1f223c7",
38
+ "@dxos/plugin-attention": "0.8.4-main.1f223c7",
39
+ "@dxos/plugin-client": "0.8.4-main.1f223c7",
40
+ "@dxos/react-client": "0.8.4-main.1f223c7",
41
+ "@dxos/react-ui": "0.8.4-main.1f223c7",
42
+ "@dxos/plugin-deck": "0.8.4-main.1f223c7",
43
+ "@dxos/react-ui-form": "0.8.4-main.1f223c7",
44
+ "@dxos/react-ui-editor": "0.8.4-main.1f223c7",
45
+ "@dxos/react-ui-stack": "0.8.4-main.1f223c7",
46
+ "@dxos/react-ui-menu": "0.8.4-main.1f223c7",
47
+ "@dxos/react-ui-table": "0.8.4-main.1f223c7",
48
+ "@dxos/react-ui-theme": "0.8.4-main.1f223c7",
49
+ "@dxos/schema": "0.8.4-main.1f223c7",
50
+ "@dxos/util": "0.8.4-main.1f223c7"
46
51
  },
47
52
  "devDependencies": {
48
- "effect": "3.14.21",
53
+ "effect": "3.17.7",
49
54
  "react": "~18.2.0",
50
55
  "react-dom": "~18.2.0",
51
- "vite": "5.4.7",
52
- "@dxos/random": "0.8.3",
53
- "@dxos/storybook-utils": "0.8.3"
56
+ "vite": "7.1.1",
57
+ "@dxos/storybook-utils": "0.8.4-main.1f223c7",
58
+ "@dxos/random": "0.8.4-main.1f223c7"
54
59
  },
55
60
  "peerDependencies": {
56
61
  "effect": "^3.13.3",
@@ -8,7 +8,7 @@ import { DataType } from '@dxos/schema';
8
8
 
9
9
  import { PreviewPopover, ReactSurface } from './capabilities';
10
10
  import { meta } from './meta';
11
- import translations from './translations';
11
+ import { translations } from './translations';
12
12
 
13
13
  export const PreviewPlugin = () =>
14
14
  definePlugin(meta, [
@@ -2,14 +2,14 @@
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';
11
10
  import { log } from '@dxos/log';
12
11
  import { ClientCapabilities } from '@dxos/plugin-client';
12
+ import { DX_ANCHOR_ACTIVATE, type DxAnchorActivate } from '@dxos/react-ui';
13
13
  import { type PreviewLinkRef, type PreviewLinkTarget } from '@dxos/react-ui-editor';
14
14
 
15
15
  const customEventOptions = { capture: true, passive: false };
@@ -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 {
@@ -2,6 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import { Effect } from 'effect';
5
6
  import React, { useCallback } from 'react';
6
7
 
7
8
  import {
@@ -14,14 +15,17 @@ import {
14
15
  useIntentDispatcher,
15
16
  } from '@dxos/app-framework';
16
17
  import { fullyQualifiedId, getSchema, getSpace } from '@dxos/client/echo';
17
- import { Obj, Filter } from '@dxos/echo';
18
+ import { Filter, Obj } from '@dxos/echo';
18
19
  import { type JsonPath, setValue } from '@dxos/echo-schema';
20
+ import { AttentionAction } from '@dxos/plugin-attention/types';
21
+ import { ATTENDABLE_PATH_SEPARATOR, DeckAction } from '@dxos/plugin-deck/types';
22
+ import { useQuery, useSpace } from '@dxos/react-client/echo';
19
23
  import { useTranslation } from '@dxos/react-ui';
20
24
  import { Form } from '@dxos/react-ui-form';
21
25
  import { Card } from '@dxos/react-ui-stack';
22
- import { TableType } from '@dxos/react-ui-table';
26
+ import { Table } from '@dxos/react-ui-table/types';
23
27
  import { descriptionMessage, mx } from '@dxos/react-ui-theme';
24
- import { DataType } from '@dxos/schema';
28
+ import { DataType, type ProjectionModel, typenameFromQuery } from '@dxos/schema';
25
29
 
26
30
  import { ContactCard, OrganizationCard, ProjectCard } from '../components';
27
31
  import { PREVIEW_PLUGIN } from '../meta';
@@ -33,58 +37,87 @@ export default () =>
33
37
  //
34
38
  createSurface({
35
39
  id: `${PREVIEW_PLUGIN}/schema-popover--contact`,
36
- role: ['popover', 'card--kanban', 'card--document', 'card'],
40
+ role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
37
41
  filter: (data): data is { subject: DataType.Person } => Obj.instanceOf(DataType.Person, data.subject),
38
42
  component: ({ data, role }) => {
39
- const { dispatchPromise: dispatch } = useIntentDispatcher();
43
+ const { dispatch } = useIntentDispatcher();
44
+ const space = getSpace(data.subject);
45
+ const defaultSpace = useSpace();
46
+
47
+ const currentSpaceOrgs = useQuery(space, Filter.type(DataType.Organization));
48
+ const currentSpaceViews = useQuery(space, Filter.type(DataType.View));
49
+ const defaultSpaceViews = useQuery(defaultSpace, Filter.type(DataType.View));
50
+ const currentSpaceOrgTable = currentSpaceViews.find(
51
+ (view) =>
52
+ typenameFromQuery(view.query) === DataType.Organization.typename &&
53
+ Obj.instanceOf(Table.Table, view.presentation.target),
54
+ );
55
+ const defaultSpaceOrgTable = defaultSpaceViews.find(
56
+ (view) =>
57
+ typenameFromQuery(view.query) === DataType.Organization.typename &&
58
+ Obj.instanceOf(Table.Table, view.presentation.target),
59
+ );
60
+
61
+ // TODO(wittjosiah): Generalized way of handling related objects navigation.
40
62
  const handleOrgClick = useCallback(
41
- async (org: DataType.Organization) => {
42
- const space = getSpace(org);
43
- const tablesQuery = await space?.db.query(Filter.type(TableType)).run();
44
- const currentSpaceOrgTable = tablesQuery?.objects.find((table) => {
45
- return table.view?.target?.query?.typename === DataType.Organization.typename;
46
- });
47
- await dispatch(
48
- createIntent(LayoutAction.UpdatePopover, {
49
- part: 'popover',
50
- options: {
51
- state: false,
52
- anchorId: '',
53
- },
54
- }),
55
- );
56
- if (currentSpaceOrgTable) {
57
- return dispatch(
58
- createIntent(LayoutAction.Open, {
59
- part: 'main',
60
- subject: [fullyQualifiedId(currentSpaceOrgTable)],
61
- options: { workspace: space?.id },
63
+ (org: DataType.Organization) =>
64
+ Effect.gen(function* () {
65
+ const view = currentSpaceOrgs.includes(org) ? currentSpaceOrgTable : defaultSpaceOrgTable;
66
+ yield* dispatch(
67
+ createIntent(LayoutAction.UpdatePopover, {
68
+ part: 'popover',
69
+ options: {
70
+ state: false,
71
+ anchorId: '',
72
+ },
62
73
  }),
63
74
  );
64
- }
65
- },
66
- [dispatch],
75
+ if (view) {
76
+ const id = fullyQualifiedId(view);
77
+ yield* dispatch(
78
+ createIntent(LayoutAction.Open, {
79
+ part: 'main',
80
+ subject: [id],
81
+ options: { workspace: space?.id },
82
+ }),
83
+ );
84
+ yield* dispatch(
85
+ createIntent(DeckAction.ChangeCompanion, {
86
+ primary: id,
87
+ companion: [id, 'selected-objects'].join(ATTENDABLE_PATH_SEPARATOR),
88
+ }),
89
+ );
90
+ yield* dispatch(
91
+ createIntent(AttentionAction.Select, {
92
+ contextId: id,
93
+ selection: { mode: 'multi', ids: [org.id] },
94
+ }),
95
+ );
96
+ }
97
+ }).pipe(Effect.runPromise),
98
+ [dispatch, currentSpaceOrgs, currentSpaceOrgTable, defaultSpaceOrgTable],
67
99
  );
100
+
68
101
  return (
69
102
  <ContactCard role={role} subject={data.subject} onOrgClick={handleOrgClick}>
70
- {role === 'popover' && <Surface role='related' data={data} />}
103
+ {role === 'card--popover' && <Surface role='related' data={data} />}
71
104
  </ContactCard>
72
105
  );
73
106
  },
74
107
  }),
75
108
  createSurface({
76
109
  id: `${PREVIEW_PLUGIN}/schema-popover--organization`,
77
- role: ['popover', 'card--kanban', 'card--document', 'card'],
110
+ role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
78
111
  filter: (data): data is { subject: DataType.Organization } => Obj.instanceOf(DataType.Organization, data.subject),
79
112
  component: ({ data, role }) => (
80
113
  <OrganizationCard role={role} subject={data.subject}>
81
- {role === 'popover' && <Surface role='related' data={data} />}
114
+ {role === 'card--popover' && <Surface role='related' data={data} />}
82
115
  </OrganizationCard>
83
116
  ),
84
117
  }),
85
118
  createSurface({
86
119
  id: `${PREVIEW_PLUGIN}/schema-popover--project`,
87
- role: ['popover', 'card--kanban', 'card--document', 'card'],
120
+ role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
88
121
  filter: (data): data is { subject: DataType.Project } => Obj.instanceOf(DataType.Project, data.subject),
89
122
  component: ({ data, role }) => <ProjectCard subject={data.subject} role={role} />,
90
123
  }),
@@ -94,9 +127,9 @@ export default () =>
94
127
  //
95
128
  createSurface({
96
129
  id: `${PREVIEW_PLUGIN}/fallback-popover`,
97
- role: ['popover', 'card--kanban', 'card--document', 'card'],
130
+ role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
98
131
  position: 'fallback',
99
- 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),
100
133
  component: ({ data, role }) => {
101
134
  const schema = getSchema(data.subject);
102
135
  const { t } = useTranslation(PREVIEW_PLUGIN);
@@ -114,16 +147,17 @@ export default () =>
114
147
  }, []);
115
148
 
116
149
  return (
117
- <Card.Container role={role}>
150
+ <Card.SurfaceRoot role={role}>
118
151
  <Form
119
152
  schema={schema}
153
+ projection={data.projection}
120
154
  values={data.subject}
121
- readonly={role === 'popover'}
155
+ readonly={role === 'card--popover' ? 'static' : false}
122
156
  onSave={handleSave}
123
157
  autoSave
124
- {...(role === 'card--kanban' && { outerSpacing: 'blockStart-0' })}
158
+ {...(role === 'card--intrinsic' && { outerSpacing: 'blockStart-0' })}
125
159
  />
126
- </Card.Container>
160
+ </Card.SurfaceRoot>
127
161
  );
128
162
  },
129
163
  }),
@@ -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
- <Card.Container role={role}>
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,25 +50,27 @@ 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
- </Card.Container>
74
+ </Card.SurfaceRoot>
69
75
  );
70
76
  };
@@ -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
- <Card.Container role={role}>
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>
@@ -36,6 +39,6 @@ export const OrganizationCard = ({
36
39
  </Card.Chrome>
37
40
  )}
38
41
  {children}
39
- </Card.Container>
42
+ </Card.SurfaceRoot>
40
43
  );
41
44
  };
@@ -4,17 +4,25 @@
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
- <Card.Container role={role}>
15
- {image && <Card.Poster image={image} alt={name} aspect='auto' />}
16
- <Card.Heading>{name}</Card.Heading>
19
+ <Card.SurfaceRoot role={role}>
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
- </Card.Container>
26
+ </Card.SurfaceRoot>
19
27
  );
20
28
  };
@@ -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
+ };
package/src/index.ts CHANGED
@@ -3,6 +3,6 @@
3
3
  //
4
4
 
5
5
  export * from './meta';
6
- export * from './types';
6
+ export type * from './types';
7
7
 
8
8
  export * from './PreviewPlugin';
@@ -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
+ };