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

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 (81) hide show
  1. package/dist/lib/browser/{chunk-Z73ENKLE.mjs → chunk-XKCIQK3C.mjs} +2 -4
  2. package/dist/lib/browser/chunk-XKCIQK3C.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +8 -7
  4. package/dist/lib/browser/index.mjs.map +2 -2
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/{preview-popover-2UCEZUQW.mjs → preview-popover-EIATF2VR.mjs} +8 -12
  7. package/dist/lib/browser/preview-popover-EIATF2VR.mjs.map +7 -0
  8. package/dist/lib/browser/react-surface-X5EXLQX7.mjs +471 -0
  9. package/dist/lib/browser/react-surface-X5EXLQX7.mjs.map +7 -0
  10. package/dist/lib/node-esm/{chunk-2ORSL4GJ.mjs → chunk-L3IZVX56.mjs} +2 -4
  11. package/dist/lib/node-esm/chunk-L3IZVX56.mjs.map +7 -0
  12. package/dist/lib/node-esm/index.mjs +8 -7
  13. package/dist/lib/node-esm/index.mjs.map +2 -2
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/{preview-popover-OSHWR2YE.mjs → preview-popover-623SB5KV.mjs} +8 -12
  16. package/dist/lib/node-esm/preview-popover-623SB5KV.mjs.map +7 -0
  17. package/dist/lib/node-esm/react-surface-EO4RGRB5.mjs +472 -0
  18. package/dist/lib/node-esm/react-surface-EO4RGRB5.mjs.map +7 -0
  19. package/dist/types/src/PreviewPlugin.d.ts +1 -1
  20. package/dist/types/src/PreviewPlugin.d.ts.map +1 -1
  21. package/dist/types/src/capabilities/index.d.ts +2 -2
  22. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  23. package/dist/types/src/capabilities/preview-popover.d.ts +1 -1
  24. package/dist/types/src/capabilities/preview-popover.d.ts.map +1 -1
  25. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  26. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  27. package/dist/types/src/components/CardSubjectMenu.d.ts +12 -0
  28. package/dist/types/src/components/CardSubjectMenu.d.ts.map +1 -0
  29. package/dist/types/src/components/ContactCard.d.ts +1 -1
  30. package/dist/types/src/components/ContactCard.d.ts.map +1 -1
  31. package/dist/types/src/components/OrganizationCard.d.ts +1 -1
  32. package/dist/types/src/components/OrganizationCard.d.ts.map +1 -1
  33. package/dist/types/src/components/ProjectCard.d.ts +1 -1
  34. package/dist/types/src/components/ProjectCard.d.ts.map +1 -1
  35. package/dist/types/src/components/TaskCard.d.ts +5 -0
  36. package/dist/types/src/components/TaskCard.d.ts.map +1 -0
  37. package/dist/types/src/meta.d.ts +0 -1
  38. package/dist/types/src/meta.d.ts.map +1 -1
  39. package/dist/types/src/stories/Card.stories.d.ts +27 -0
  40. package/dist/types/src/stories/Card.stories.d.ts.map +1 -0
  41. package/dist/types/src/stories/testing.d.ts +17 -0
  42. package/dist/types/src/stories/testing.d.ts.map +1 -0
  43. package/dist/types/src/translations.d.ts +3 -0
  44. package/dist/types/src/translations.d.ts.map +1 -1
  45. package/dist/types/src/types.d.ts +4 -1
  46. package/dist/types/src/types.d.ts.map +1 -1
  47. package/dist/types/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +33 -29
  49. package/src/PreviewPlugin.tsx +22 -23
  50. package/src/capabilities/preview-popover.ts +8 -13
  51. package/src/capabilities/react-surface.tsx +41 -23
  52. package/src/components/CardSubjectMenu.tsx +68 -0
  53. package/src/components/ContactCard.tsx +30 -22
  54. package/src/components/OrganizationCard.tsx +11 -8
  55. package/src/components/ProjectCard.tsx +12 -4
  56. package/src/components/TaskCard.tsx +46 -0
  57. package/src/meta.ts +1 -3
  58. package/src/stories/Card.stories.tsx +59 -0
  59. package/src/stories/testing.tsx +114 -0
  60. package/src/translations.ts +3 -0
  61. package/src/types.ts +5 -2
  62. package/dist/lib/browser/chunk-Z73ENKLE.mjs.map +0 -7
  63. package/dist/lib/browser/preview-popover-2UCEZUQW.mjs.map +0 -7
  64. package/dist/lib/browser/react-surface-CZMUEWPV.mjs +0 -303
  65. package/dist/lib/browser/react-surface-CZMUEWPV.mjs.map +0 -7
  66. package/dist/lib/node-esm/chunk-2ORSL4GJ.mjs.map +0 -7
  67. package/dist/lib/node-esm/preview-popover-OSHWR2YE.mjs.map +0 -7
  68. package/dist/lib/node-esm/react-surface-IPZBISWS.mjs +0 -304
  69. package/dist/lib/node-esm/react-surface-IPZBISWS.mjs.map +0 -7
  70. package/dist/types/src/testing/ExtrinsicPreviews.stories.d.ts +0 -35
  71. package/dist/types/src/testing/ExtrinsicPreviews.stories.d.ts.map +0 -1
  72. package/dist/types/src/testing/IntrinsicPreviews.stories.d.ts +0 -35
  73. package/dist/types/src/testing/IntrinsicPreviews.stories.d.ts.map +0 -1
  74. package/dist/types/src/testing/PopoverPreviews.stories.d.ts +0 -35
  75. package/dist/types/src/testing/PopoverPreviews.stories.d.ts.map +0 -1
  76. package/dist/types/src/testing/util.d.ts +0 -80
  77. package/dist/types/src/testing/util.d.ts.map +0 -1
  78. package/src/testing/ExtrinsicPreviews.stories.tsx +0 -55
  79. package/src/testing/IntrinsicPreviews.stories.tsx +0 -55
  80. package/src/testing/PopoverPreviews.stories.tsx +0 -55
  81. 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.c4373fc",
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,40 +24,43 @@
23
24
  "src"
24
25
  ],
25
26
  "dependencies": {
27
+ "@effect-rx/rx-react": "0.42.4",
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.c4373fc",
30
+ "@dxos/async": "0.8.4-main.c4373fc",
31
+ "@dxos/app-graph": "0.8.4-main.c4373fc",
32
+ "@dxos/client": "0.8.4-main.c4373fc",
33
+ "@dxos/echo": "0.8.4-main.c4373fc",
34
+ "@dxos/lit-ui": "0.8.4-main.c4373fc",
35
+ "@dxos/log": "0.8.4-main.c4373fc",
36
+ "@dxos/plugin-client": "0.8.4-main.c4373fc",
37
+ "@dxos/plugin-attention": "0.8.4-main.c4373fc",
38
+ "@dxos/plugin-deck": "0.8.4-main.c4373fc",
39
+ "@dxos/keys": "0.8.4-main.c4373fc",
40
+ "@dxos/react-client": "0.8.4-main.c4373fc",
41
+ "@dxos/plugin-space": "0.8.4-main.c4373fc",
42
+ "@dxos/react-ui": "0.8.4-main.c4373fc",
43
+ "@dxos/react-ui-editor": "0.8.4-main.c4373fc",
44
+ "@dxos/react-ui-form": "0.8.4-main.c4373fc",
45
+ "@dxos/react-ui-menu": "0.8.4-main.c4373fc",
46
+ "@dxos/react-ui-stack": "0.8.4-main.c4373fc",
47
+ "@dxos/react-ui-table": "0.8.4-main.c4373fc",
48
+ "@dxos/react-ui-theme": "0.8.4-main.c4373fc",
49
+ "@dxos/schema": "0.8.4-main.c4373fc",
50
+ "@dxos/util": "0.8.4-main.c4373fc"
47
51
  },
48
52
  "devDependencies": {
49
- "effect": "3.17.0",
50
- "react": "~18.2.0",
51
- "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"
53
+ "effect": "3.18.3",
54
+ "react": "~19.2.0",
55
+ "react-dom": "~19.2.0",
56
+ "vite": "7.1.9",
57
+ "@dxos/storybook-utils": "0.8.4-main.c4373fc",
58
+ "@dxos/random": "0.8.4-main.c4373fc"
55
59
  },
56
60
  "peerDependencies": {
57
61
  "effect": "^3.13.3",
58
- "react": "~18.2.0",
59
- "react-dom": "~18.2.0"
62
+ "react": "^19.0.0",
63
+ "react-dom": "^19.0.0"
60
64
  },
61
65
  "publishConfig": {
62
66
  "access": "public"
@@ -10,26 +10,25 @@ import { PreviewPopover, ReactSurface } from './capabilities';
10
10
  import { meta } from './meta';
11
11
  import { translations } from './translations';
12
12
 
13
- export const PreviewPlugin = () =>
14
- definePlugin(meta, [
15
- defineModule({
16
- id: `${meta.id}/module/translations`,
17
- activatesOn: Events.SetupTranslations,
18
- activate: () => contributes(Capabilities.Translations, translations),
19
- }),
20
- defineModule({
21
- id: `${meta.id}/module/schema`,
22
- activatesOn: ClientEvents.SetupSchema,
23
- activate: () => [contributes(ClientCapabilities.Schema, [DataType.Person, DataType.Organization])],
24
- }),
25
- defineModule({
26
- id: `${meta.id}/module/preview-popover`,
27
- activatesOn: Events.Startup,
28
- activate: PreviewPopover,
29
- }),
30
- defineModule({
31
- id: `${meta.id}/module/react-surface`,
32
- activatesOn: Events.SetupReactSurface,
33
- activate: ReactSurface,
34
- }),
35
- ]);
13
+ export const PreviewPlugin = definePlugin(meta, () => [
14
+ defineModule({
15
+ id: `${meta.id}/module/translations`,
16
+ activatesOn: Events.SetupTranslations,
17
+ activate: () => contributes(Capabilities.Translations, translations),
18
+ }),
19
+ defineModule({
20
+ id: `${meta.id}/module/schema`,
21
+ activatesOn: ClientEvents.SetupSchema,
22
+ activate: () => [contributes(ClientCapabilities.Schema, [DataType.Person, DataType.Organization])],
23
+ }),
24
+ defineModule({
25
+ id: `${meta.id}/module/preview-popover`,
26
+ activatesOn: Events.Startup,
27
+ activate: PreviewPopover,
28
+ }),
29
+ defineModule({
30
+ id: `${meta.id}/module/react-surface`,
31
+ activatesOn: Events.SetupReactSurface,
32
+ activate: ReactSurface,
33
+ }),
34
+ ]);
@@ -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,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Effect } from 'effect';
5
+ import * as Effect from 'effect/Effect';
6
6
  import React, { useCallback } from 'react';
7
7
 
8
8
  import {
@@ -16,19 +16,21 @@ import {
16
16
  } from '@dxos/app-framework';
17
17
  import { fullyQualifiedId, getSchema, getSpace } from '@dxos/client/echo';
18
18
  import { Filter, Obj } from '@dxos/echo';
19
- import { type JsonPath, setValue } from '@dxos/echo-schema';
19
+ import { type JsonPath, setValue } from '@dxos/echo/internal';
20
20
  import { AttentionAction } from '@dxos/plugin-attention/types';
21
21
  import { ATTENDABLE_PATH_SEPARATOR, DeckAction } from '@dxos/plugin-deck/types';
22
+ import { useActiveSpace } from '@dxos/plugin-space';
22
23
  import { useQuery, useSpace } from '@dxos/react-client/echo';
23
24
  import { useTranslation } from '@dxos/react-ui';
24
25
  import { Form } from '@dxos/react-ui-form';
25
26
  import { Card } from '@dxos/react-ui-stack';
26
- import { TableView } from '@dxos/react-ui-table/types';
27
+ import { Table } from '@dxos/react-ui-table/types';
27
28
  import { descriptionMessage, mx } from '@dxos/react-ui-theme';
28
- import { DataType } from '@dxos/schema';
29
+ import { DataType, type ProjectionModel, getTypenameFromQuery } from '@dxos/schema';
29
30
 
30
31
  import { ContactCard, OrganizationCard, ProjectCard } from '../components';
31
- import { PREVIEW_PLUGIN } from '../meta';
32
+ import { TaskCard } from '../components/TaskCard';
33
+ import { meta } from '../meta';
32
34
 
33
35
  export default () =>
34
36
  contributes(Capabilities.ReactSurface, [
@@ -36,26 +38,27 @@ export default () =>
36
38
  // Specific schema types.
37
39
  //
38
40
  createSurface({
39
- id: `${PREVIEW_PLUGIN}/schema-popover--contact`,
41
+ id: `${meta.id}/schema-popover--contact`,
40
42
  role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
41
43
  filter: (data): data is { subject: DataType.Person } => Obj.instanceOf(DataType.Person, data.subject),
42
44
  component: ({ data, role }) => {
43
45
  const { dispatch } = useIntentDispatcher();
44
46
  const space = getSpace(data.subject);
45
47
  const defaultSpace = useSpace();
48
+ const activeSpace = useActiveSpace();
46
49
 
47
50
  const currentSpaceOrgs = useQuery(space, Filter.type(DataType.Organization));
48
51
  const currentSpaceViews = useQuery(space, Filter.type(DataType.View));
49
52
  const defaultSpaceViews = useQuery(defaultSpace, Filter.type(DataType.View));
50
53
  const currentSpaceOrgTable = currentSpaceViews.find(
51
54
  (view) =>
52
- view.query.typename === DataType.Organization.typename &&
53
- Obj.instanceOf(TableView, view.presentation.target),
55
+ getTypenameFromQuery(view.query.ast) === DataType.Organization.typename &&
56
+ Obj.instanceOf(Table.Table, view.presentation.target),
54
57
  );
55
58
  const defaultSpaceOrgTable = defaultSpaceViews.find(
56
59
  (view) =>
57
- view.query.typename === DataType.Organization.typename &&
58
- Obj.instanceOf(TableView, view.presentation.target),
60
+ getTypenameFromQuery(view.query.ast) === DataType.Organization.typename &&
61
+ Obj.instanceOf(Table.Table, view.presentation.target),
59
62
  );
60
63
 
61
64
  // TODO(wittjosiah): Generalized way of handling related objects navigation.
@@ -99,40 +102,54 @@ export default () =>
99
102
  );
100
103
 
101
104
  return (
102
- <ContactCard role={role} subject={data.subject} onOrgClick={handleOrgClick}>
105
+ <ContactCard role={role} subject={data.subject} activeSpace={activeSpace} onOrgClick={handleOrgClick}>
103
106
  {role === 'card--popover' && <Surface role='related' data={data} />}
104
107
  </ContactCard>
105
108
  );
106
109
  },
107
110
  }),
108
111
  createSurface({
109
- id: `${PREVIEW_PLUGIN}/schema-popover--organization`,
112
+ id: `${meta.id}/schema-popover--organization`,
110
113
  role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
111
114
  filter: (data): data is { subject: DataType.Organization } => Obj.instanceOf(DataType.Organization, data.subject),
112
- component: ({ data, role }) => (
113
- <OrganizationCard role={role} subject={data.subject}>
114
- {role === 'card--popover' && <Surface role='related' data={data} />}
115
- </OrganizationCard>
116
- ),
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
+ },
117
124
  }),
118
125
  createSurface({
119
- id: `${PREVIEW_PLUGIN}/schema-popover--project`,
126
+ id: `${meta.id}/schema-popover--project`,
120
127
  role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
121
128
  filter: (data): data is { subject: DataType.Project } => Obj.instanceOf(DataType.Project, data.subject),
122
- 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: `${meta.id}/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} />,
123
140
  }),
124
141
 
125
142
  //
126
143
  // Fallback for any object.
127
144
  //
128
145
  createSurface({
129
- id: `${PREVIEW_PLUGIN}/fallback-popover`,
146
+ id: `${meta.id}/fallback-popover`,
130
147
  role: ['card--popover', 'card--intrinsic', 'card--transclusion', 'card--extrinsic', 'card'],
131
148
  position: 'fallback',
132
- 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),
133
150
  component: ({ data, role }) => {
134
151
  const schema = getSchema(data.subject);
135
- const { t } = useTranslation(PREVIEW_PLUGIN);
152
+ const { t } = useTranslation(meta.id);
136
153
  if (!schema) {
137
154
  // TODO(burdon): Use Alert.
138
155
  return <p className={mx(descriptionMessage)}>{t('unable to create preview message')}</p>;
@@ -150,8 +167,9 @@ export default () =>
150
167
  <Card.SurfaceRoot role={role}>
151
168
  <Form
152
169
  schema={schema}
170
+ projection={data.projection}
153
171
  values={data.subject}
154
- readonly={role === 'card--popover'}
172
+ readonly={role === 'card--popover' ? 'static' : false}
155
173
  onSave={handleSave}
156
174
  autoSave
157
175
  {...(role === 'card--intrinsic' && { outerSpacing: 'blockStart-0' })}
@@ -0,0 +1,68 @@
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
+
35
+ return useMenuActions(Rx.make(result));
36
+ };
37
+
38
+ /**
39
+ * This is a generic menu for objects that tries to infer common actions.
40
+ */
41
+ export const CardSubjectMenu = ({
42
+ subject,
43
+ activeSpace,
44
+ ...props
45
+ }: Omit<IconButtonProps, 'icon' | 'label'> & { subject: Obj.Any; activeSpace?: Space }) => {
46
+ const { t } = useTranslation('os');
47
+ const menuProps = useSubjectMenuGroupItems(subject, activeSpace);
48
+
49
+ if (!activeSpace) {
50
+ return null;
51
+ }
52
+
53
+ return (
54
+ <MenuProvider {...menuProps}>
55
+ <DropdownMenu.Root>
56
+ <DropdownMenu.Trigger asChild>
57
+ <IconButton
58
+ iconOnly
59
+ variant='ghost'
60
+ icon='ph--dots-three-vertical--bold'
61
+ label={t('more options label')}
62
+ {...props}
63
+ />
64
+ </DropdownMenu.Trigger>
65
+ </DropdownMenu.Root>
66
+ </MenuProvider>
67
+ );
68
+ };
@@ -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
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,24 +51,27 @@ 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
76
  </Card.SurfaceRoot>
69
77
  );
@@ -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
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,7 +33,7 @@ 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>
@@ -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, activeSpace }: 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} activeSpace={activeSpace} />
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 * as SchemaAST from 'effect/SchemaAST';
6
+ import React from 'react';
7
+
8
+ import { type PropertyMetaAnnotation, PropertyMetaAnnotationId } from '@dxos/echo/internal';
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/meta.ts CHANGED
@@ -4,10 +4,8 @@
4
4
 
5
5
  import { type PluginMeta } from '@dxos/app-framework';
6
6
 
7
- export const PREVIEW_PLUGIN = 'dxos.org/plugin/preview';
8
-
9
7
  export const meta: PluginMeta = {
10
- id: PREVIEW_PLUGIN,
8
+ id: 'dxos.org/plugin/preview',
11
9
  name: 'Preview',
12
10
  icon: 'ph--eye--regular',
13
11
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-preview',