@dxos/plugin-preview 0.8.3-staging.0fa589b → 0.8.4-main.1da679c

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-EIATF2VR.mjs} +10 -14
  6. package/dist/lib/browser/preview-popover-EIATF2VR.mjs.map +7 -0
  7. package/dist/lib/browser/react-surface-B5AX4QFQ.mjs +471 -0
  8. package/dist/lib/browser/react-surface-B5AX4QFQ.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-623SB5KV.mjs} +10 -14
  14. package/dist/lib/node-esm/preview-popover-623SB5KV.mjs.map +7 -0
  15. package/dist/lib/node-esm/react-surface-F5E3ITVY.mjs +472 -0
  16. package/dist/lib/node-esm/react-surface-F5E3ITVY.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 +12 -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 +4 -1
  42. package/dist/types/src/types.d.ts.map +1 -1
  43. package/dist/types/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +30 -24
  45. package/src/PreviewPlugin.tsx +1 -1
  46. package/src/capabilities/preview-popover.ts +8 -13
  47. package/src/capabilities/react-surface.tsx +96 -45
  48. package/src/components/CardSubjectMenu.tsx +67 -0
  49. package/src/components/ContactCard.tsx +32 -24
  50. package/src/components/OrganizationCard.tsx +13 -10
  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 +5 -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-staging.0fa589b",
3
+ "version": "0.8.4-main.1da679c",
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,39 @@
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-staging.0fa589b",
29
- "@dxos/client": "0.8.3-staging.0fa589b",
30
- "@dxos/async": "0.8.3-staging.0fa589b",
31
- "@dxos/echo": "0.8.3-staging.0fa589b",
32
- "@dxos/echo-schema": "0.8.3-staging.0fa589b",
33
- "@dxos/keys": "0.8.3-staging.0fa589b",
34
- "@dxos/lit-ui": "0.8.3-staging.0fa589b",
35
- "@dxos/log": "0.8.3-staging.0fa589b",
36
- "@dxos/plugin-client": "0.8.3-staging.0fa589b",
37
- "@dxos/react-ui": "0.8.3-staging.0fa589b",
38
- "@dxos/react-client": "0.8.3-staging.0fa589b",
39
- "@dxos/react-ui-editor": "0.8.3-staging.0fa589b",
40
- "@dxos/react-ui-form": "0.8.3-staging.0fa589b",
41
- "@dxos/react-ui-stack": "0.8.3-staging.0fa589b",
42
- "@dxos/react-ui-theme": "0.8.3-staging.0fa589b",
43
- "@dxos/schema": "0.8.3-staging.0fa589b",
44
- "@dxos/react-ui-table": "0.8.3-staging.0fa589b",
45
- "@dxos/util": "0.8.3-staging.0fa589b"
29
+ "@dxos/app-framework": "0.8.4-main.1da679c",
30
+ "@dxos/async": "0.8.4-main.1da679c",
31
+ "@dxos/app-graph": "0.8.4-main.1da679c",
32
+ "@dxos/echo": "0.8.4-main.1da679c",
33
+ "@dxos/client": "0.8.4-main.1da679c",
34
+ "@dxos/echo-schema": "0.8.4-main.1da679c",
35
+ "@dxos/keys": "0.8.4-main.1da679c",
36
+ "@dxos/log": "0.8.4-main.1da679c",
37
+ "@dxos/plugin-attention": "0.8.4-main.1da679c",
38
+ "@dxos/plugin-client": "0.8.4-main.1da679c",
39
+ "@dxos/plugin-deck": "0.8.4-main.1da679c",
40
+ "@dxos/lit-ui": "0.8.4-main.1da679c",
41
+ "@dxos/plugin-space": "0.8.4-main.1da679c",
42
+ "@dxos/react-client": "0.8.4-main.1da679c",
43
+ "@dxos/react-ui-editor": "0.8.4-main.1da679c",
44
+ "@dxos/react-ui": "0.8.4-main.1da679c",
45
+ "@dxos/react-ui-form": "0.8.4-main.1da679c",
46
+ "@dxos/react-ui-table": "0.8.4-main.1da679c",
47
+ "@dxos/react-ui-stack": "0.8.4-main.1da679c",
48
+ "@dxos/react-ui-menu": "0.8.4-main.1da679c",
49
+ "@dxos/react-ui-theme": "0.8.4-main.1da679c",
50
+ "@dxos/schema": "0.8.4-main.1da679c",
51
+ "@dxos/util": "0.8.4-main.1da679c"
46
52
  },
47
53
  "devDependencies": {
48
- "effect": "3.14.21",
54
+ "effect": "3.17.7",
49
55
  "react": "~18.2.0",
50
56
  "react-dom": "~18.2.0",
51
- "vite": "5.4.7",
52
- "@dxos/random": "0.8.3-staging.0fa589b",
53
- "@dxos/storybook-utils": "0.8.3-staging.0fa589b"
57
+ "vite": "7.1.1",
58
+ "@dxos/random": "0.8.4-main.1da679c",
59
+ "@dxos/storybook-utils": "0.8.4-main.1da679c"
54
60
  },
55
61
  "peerDependencies": {
56
62
  "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,16 +15,21 @@ 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 { useActiveSpace } from '@dxos/plugin-space';
23
+ import { useQuery, useSpace } from '@dxos/react-client/echo';
19
24
  import { useTranslation } from '@dxos/react-ui';
20
25
  import { Form } from '@dxos/react-ui-form';
21
26
  import { Card } from '@dxos/react-ui-stack';
22
- import { TableType } from '@dxos/react-ui-table';
27
+ import { Table } from '@dxos/react-ui-table/types';
23
28
  import { descriptionMessage, mx } from '@dxos/react-ui-theme';
24
- import { DataType } from '@dxos/schema';
29
+ import { DataType, type ProjectionModel, typenameFromQuery } from '@dxos/schema';
25
30
 
26
31
  import { ContactCard, OrganizationCard, ProjectCard } from '../components';
32
+ import { TaskCard } from '../components/TaskCard';
27
33
  import { PREVIEW_PLUGIN } from '../meta';
28
34
 
29
35
  export default () =>
@@ -33,60 +39,104 @@ export default () =>
33
39
  //
34
40
  createSurface({
35
41
  id: `${PREVIEW_PLUGIN}/schema-popover--contact`,
36
- role: ['popover', 'card--kanban', 'card--document', 'card'],
42
+ role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
37
43
  filter: (data): data is { subject: DataType.Person } => Obj.instanceOf(DataType.Person, data.subject),
38
44
  component: ({ data, role }) => {
39
- const { dispatchPromise: dispatch } = useIntentDispatcher();
45
+ const { dispatch } = useIntentDispatcher();
46
+ const space = getSpace(data.subject);
47
+ const defaultSpace = useSpace();
48
+ const activeSpace = useActiveSpace();
49
+
50
+ const currentSpaceOrgs = useQuery(space, Filter.type(DataType.Organization));
51
+ const currentSpaceViews = useQuery(space, Filter.type(DataType.View));
52
+ const defaultSpaceViews = useQuery(defaultSpace, Filter.type(DataType.View));
53
+ const currentSpaceOrgTable = currentSpaceViews.find(
54
+ (view) =>
55
+ typenameFromQuery(view.query) === DataType.Organization.typename &&
56
+ Obj.instanceOf(Table.Table, view.presentation.target),
57
+ );
58
+ const defaultSpaceOrgTable = defaultSpaceViews.find(
59
+ (view) =>
60
+ typenameFromQuery(view.query) === DataType.Organization.typename &&
61
+ Obj.instanceOf(Table.Table, view.presentation.target),
62
+ );
63
+
64
+ // TODO(wittjosiah): Generalized way of handling related objects navigation.
40
65
  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 },
66
+ (org: DataType.Organization) =>
67
+ Effect.gen(function* () {
68
+ const view = currentSpaceOrgs.includes(org) ? currentSpaceOrgTable : defaultSpaceOrgTable;
69
+ yield* dispatch(
70
+ createIntent(LayoutAction.UpdatePopover, {
71
+ part: 'popover',
72
+ options: {
73
+ state: false,
74
+ anchorId: '',
75
+ },
62
76
  }),
63
77
  );
64
- }
65
- },
66
- [dispatch],
78
+ if (view) {
79
+ const id = fullyQualifiedId(view);
80
+ yield* dispatch(
81
+ createIntent(LayoutAction.Open, {
82
+ part: 'main',
83
+ subject: [id],
84
+ options: { workspace: space?.id },
85
+ }),
86
+ );
87
+ yield* dispatch(
88
+ createIntent(DeckAction.ChangeCompanion, {
89
+ primary: id,
90
+ companion: [id, 'selected-objects'].join(ATTENDABLE_PATH_SEPARATOR),
91
+ }),
92
+ );
93
+ yield* dispatch(
94
+ createIntent(AttentionAction.Select, {
95
+ contextId: id,
96
+ selection: { mode: 'multi', ids: [org.id] },
97
+ }),
98
+ );
99
+ }
100
+ }).pipe(Effect.runPromise),
101
+ [dispatch, currentSpaceOrgs, currentSpaceOrgTable, defaultSpaceOrgTable],
67
102
  );
103
+
68
104
  return (
69
- <ContactCard role={role} subject={data.subject} onOrgClick={handleOrgClick}>
70
- {role === 'popover' && <Surface role='related' data={data} />}
105
+ <ContactCard role={role} subject={data.subject} activeSpace={activeSpace} onOrgClick={handleOrgClick}>
106
+ {role === 'card--popover' && <Surface role='related' data={data} />}
71
107
  </ContactCard>
72
108
  );
73
109
  },
74
110
  }),
75
111
  createSurface({
76
112
  id: `${PREVIEW_PLUGIN}/schema-popover--organization`,
77
- role: ['popover', 'card--kanban', 'card--document', 'card'],
113
+ role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
78
114
  filter: (data): data is { subject: DataType.Organization } => Obj.instanceOf(DataType.Organization, data.subject),
79
- component: ({ data, role }) => (
80
- <OrganizationCard role={role} subject={data.subject}>
81
- {role === 'popover' && <Surface role='related' data={data} />}
82
- </OrganizationCard>
83
- ),
115
+ component: ({ data, role }) => {
116
+ const activeSpace = useActiveSpace();
117
+
118
+ return (
119
+ <OrganizationCard role={role} subject={data.subject} activeSpace={activeSpace}>
120
+ {role === 'card--popover' && <Surface role='related' data={data} />}
121
+ </OrganizationCard>
122
+ );
123
+ },
84
124
  }),
85
125
  createSurface({
86
126
  id: `${PREVIEW_PLUGIN}/schema-popover--project`,
87
- role: ['popover', 'card--kanban', 'card--document', 'card'],
127
+ role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
88
128
  filter: (data): data is { subject: DataType.Project } => Obj.instanceOf(DataType.Project, data.subject),
89
- component: ({ data, role }) => <ProjectCard subject={data.subject} role={role} />,
129
+ component: ({ data, role }) => {
130
+ const activeSpace = useActiveSpace();
131
+
132
+ return <ProjectCard subject={data.subject} role={role} activeSpace={activeSpace} />;
133
+ },
134
+ }),
135
+ createSurface({
136
+ id: `${PREVIEW_PLUGIN}/schema-popover--task`,
137
+ role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
138
+ filter: (data): data is { subject: DataType.Task } => Obj.instanceOf(DataType.Task, data.subject),
139
+ component: ({ data, role }) => <TaskCard subject={data.subject} role={role} />,
90
140
  }),
91
141
 
92
142
  //
@@ -94,9 +144,9 @@ export default () =>
94
144
  //
95
145
  createSurface({
96
146
  id: `${PREVIEW_PLUGIN}/fallback-popover`,
97
- role: ['popover', 'card--kanban', 'card--document', 'card'],
147
+ role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
98
148
  position: 'fallback',
99
- filter: (data): data is { subject: Obj.Any } => Obj.isObject(data.subject),
149
+ filter: (data): data is { subject: Obj.Any; projection?: ProjectionModel } => Obj.isObject(data.subject),
100
150
  component: ({ data, role }) => {
101
151
  const schema = getSchema(data.subject);
102
152
  const { t } = useTranslation(PREVIEW_PLUGIN);
@@ -114,16 +164,17 @@ export default () =>
114
164
  }, []);
115
165
 
116
166
  return (
117
- <Card.Container role={role}>
167
+ <Card.SurfaceRoot role={role}>
118
168
  <Form
119
169
  schema={schema}
170
+ projection={data.projection}
120
171
  values={data.subject}
121
- readonly={role === 'popover'}
172
+ readonly={role === 'card--popover' ? 'static' : false}
122
173
  onSave={handleSave}
123
174
  autoSave
124
- {...(role === 'card--kanban' && { outerSpacing: 'blockStart-0' })}
175
+ {...(role === 'card--intrinsic' && { outerSpacing: 'blockStart-0' })}
125
176
  />
126
- </Card.Container>
177
+ </Card.SurfaceRoot>
127
178
  );
128
179
  },
129
180
  }),
@@ -0,0 +1,67 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Rx } from '@effect-rx/rx-react';
6
+ import React from 'react';
7
+
8
+ import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
9
+ import { ACTION_TYPE } from '@dxos/app-graph';
10
+ import { Obj } from '@dxos/echo';
11
+ import { SpaceAction } from '@dxos/plugin-space/types';
12
+ import { type Space } from '@dxos/react-client/echo';
13
+ import { IconButton, type IconButtonProps, useTranslation } from '@dxos/react-ui';
14
+ import { type ActionGraphProps, DropdownMenu, MenuProvider, useMenuActions } from '@dxos/react-ui-menu';
15
+
16
+ const useSubjectMenuGroupItems = (subject: Obj.Any, activeSpace?: Space) => {
17
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
18
+ const result: ActionGraphProps = { edges: [], nodes: [] };
19
+ if (activeSpace && Obj.getDXN(subject).asQueueDXN()) {
20
+ result.nodes.push({
21
+ type: ACTION_TYPE,
22
+ id: `${subject.id}/add-to-space`,
23
+ // TODO(wittjosiah): Update reference to point to db object when adding?
24
+ data: () => dispatch(createIntent(SpaceAction.AddObject, { object: subject, target: activeSpace, hidden: true })),
25
+ properties: {
26
+ label: ['add object to space label', { ns: 'os' }],
27
+ icon: 'ph--file-plus--regular',
28
+ },
29
+ });
30
+ }
31
+ result.nodes.forEach(({ id: target }) => {
32
+ result.edges.push({ source: 'root', target });
33
+ });
34
+ return useMenuActions(Rx.make(result));
35
+ };
36
+
37
+ /**
38
+ * This is a generic menu for objects that tries to infer common actions.
39
+ */
40
+ export const CardSubjectMenu = ({
41
+ subject,
42
+ activeSpace,
43
+ ...props
44
+ }: Omit<IconButtonProps, 'icon' | 'label'> & { subject: Obj.Any; activeSpace?: Space }) => {
45
+ const { t } = useTranslation('os');
46
+ const menuProps = useSubjectMenuGroupItems(subject, activeSpace);
47
+
48
+ if (!activeSpace) {
49
+ return null;
50
+ }
51
+
52
+ return (
53
+ <MenuProvider {...menuProps}>
54
+ <DropdownMenu.Root>
55
+ <DropdownMenu.Trigger asChild>
56
+ <IconButton
57
+ iconOnly
58
+ variant='ghost'
59
+ icon='ph--dots-three-vertical--bold'
60
+ label={t('more options label')}
61
+ {...props}
62
+ />
63
+ </DropdownMenu.Trigger>
64
+ </DropdownMenu.Root>
65
+ </MenuProvider>
66
+ );
67
+ };
@@ -4,29 +4,34 @@
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,
19
+ activeSpace,
17
20
  onOrgClick,
18
21
  role,
19
22
  }: PreviewProps<DataType.Person> & { onOrgClick?: (org: DataType.Organization) => void }) => {
23
+ const { fullName, image, organization, emails } = subject;
20
24
  const organizationName = organization && typeof organization === 'object' ? organization.target?.name : organization;
21
25
  return (
22
- <Card.Container role={role}>
26
+ <Card.SurfaceRoot role={role}>
23
27
  <Avatar.Root>
24
28
  <Card.Text role='group' classNames='grid gap-3 grid-cols-[min-content_1fr]'>
25
29
  <Avatar.Content imgSrc={image} icon='ph--user--regular' size={16} hue='neutral' />
26
- <div role='none' className='bs-min self-center'>
30
+ <div role='none' className='bs-min self-center flex items-center'>
27
31
  <Avatar.Label asChild>
28
- <h2 className={cardHeading}>{fullName}</h2>
32
+ <h2 className={mx(cardHeading, 'grow')}>{fullName}</h2>
29
33
  </Avatar.Label>
34
+ <CardSubjectMenu subject={subject} activeSpace={activeSpace} />
30
35
  </div>
31
36
  </Card.Text>
32
37
  </Avatar.Root>
@@ -46,25 +51,28 @@ export const ContactCard = ({
46
51
  )}
47
52
  </Card.Chrome>
48
53
  )}
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>
54
+ {emails?.length && (
55
+ <dl
56
+ className={mx(
57
+ cardText,
58
+ 'grid gap-2 grid-cols-[min-content_1fr] [&_dt]:text-subdued [&_dt]:pbs-0.5 [&_dd]:min-is-0',
59
+ )}
60
+ >
61
+ {emails?.length &&
62
+ emails.map(({ label, value }) => (
63
+ <Fragment key={value}>
64
+ <dt>
65
+ <span className='sr-only'>{label}</span>
66
+ <Icon icon='ph--at--regular' size={5} />
67
+ </dt>
68
+ <dd key={value} className='break-words'>
69
+ {value}
70
+ </dd>
71
+ </Fragment>
72
+ ))}
73
+ </dl>
74
+ )}
67
75
  {children}
68
- </Card.Container>
76
+ </Card.SurfaceRoot>
69
77
  );
70
78
  };
@@ -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, activeSpace }: 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} activeSpace={activeSpace} />
24
+ </div>
22
25
  {description && <Card.Text classNames='line-clamp-2'>{description}</Card.Text>}
23
26
  {website && (
24
27
  <Card.Chrome>
@@ -30,12 +33,12 @@ export const OrganizationCard = ({
30
33
  rel='noreferrer'
31
34
  >
32
35
  <Icon icon='ph--link--regular' size={5} classNames='text-subdued' />
33
- <span className='grow'>{website}</span>
36
+ <span className='min-is-0 flex-1 truncate'>{website}</span>
34
37
  <Icon icon='ph--arrow-square-out--regular' />
35
38
  </a>
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, activeSpace }: 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} activeSpace={activeSpace} />
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, activeSpace }: 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} activeSpace={activeSpace} />
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';