@dxos/plugin-preview 0.8.4-main.422d1c7879 → 0.8.4-main.43cb759274

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 (91) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/neutral/PreviewPlugin.mjs +9 -0
  3. package/dist/lib/neutral/PreviewPlugin.mjs.map +7 -0
  4. package/dist/lib/neutral/PreviewPlugin.node.mjs +17 -0
  5. package/dist/lib/neutral/PreviewPlugin.node.mjs.map +7 -0
  6. package/dist/lib/neutral/PreviewPlugin.workerd.mjs +17 -0
  7. package/dist/lib/neutral/PreviewPlugin.workerd.mjs.map +7 -0
  8. package/dist/lib/neutral/capabilities/index.mjs +9 -0
  9. package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
  10. package/dist/lib/neutral/chunk-3SWUVHXJ.mjs +28 -0
  11. package/dist/lib/neutral/chunk-3SWUVHXJ.mjs.map +7 -0
  12. package/dist/lib/neutral/chunk-QOM5APM7.mjs +23 -0
  13. package/dist/lib/neutral/chunk-QOM5APM7.mjs.map +7 -0
  14. package/dist/lib/neutral/index.mjs +7 -0
  15. package/dist/lib/neutral/index.mjs.map +7 -0
  16. package/dist/lib/neutral/meta.json +1 -0
  17. package/dist/lib/neutral/meta.mjs +7 -0
  18. package/dist/lib/neutral/meta.mjs.map +7 -0
  19. package/dist/lib/neutral/plugin.mjs +11 -0
  20. package/dist/lib/neutral/plugin.mjs.map +7 -0
  21. package/dist/lib/neutral/preview-popover-FLMYMFCH.mjs +94 -0
  22. package/dist/lib/neutral/preview-popover-FLMYMFCH.mjs.map +7 -0
  23. package/dist/lib/neutral/react-surface-HDOPNIQM.mjs +406 -0
  24. package/dist/lib/neutral/react-surface-HDOPNIQM.mjs.map +7 -0
  25. package/dist/lib/neutral/testing.mjs +7 -0
  26. package/dist/lib/neutral/testing.mjs.map +7 -0
  27. package/dist/lib/neutral/translations.mjs +21 -0
  28. package/dist/lib/neutral/translations.mjs.map +7 -0
  29. package/dist/types/src/PreviewPlugin.d.ts +1 -0
  30. package/dist/types/src/PreviewPlugin.d.ts.map +1 -1
  31. package/dist/types/src/PreviewPlugin.node.d.ts +4 -0
  32. package/dist/types/src/PreviewPlugin.node.d.ts.map +1 -0
  33. package/dist/types/src/PreviewPlugin.test.d.ts +2 -0
  34. package/dist/types/src/PreviewPlugin.test.d.ts.map +1 -0
  35. package/dist/types/src/PreviewPlugin.workerd.d.ts +4 -0
  36. package/dist/types/src/PreviewPlugin.workerd.d.ts.map +1 -0
  37. package/dist/types/src/capabilities/preview-popover.d.ts.map +1 -1
  38. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  39. package/dist/types/src/cards/ExpandoCard.d.ts +4 -0
  40. package/dist/types/src/cards/ExpandoCard.d.ts.map +1 -0
  41. package/dist/types/src/cards/FormCard.d.ts +12 -2
  42. package/dist/types/src/cards/FormCard.d.ts.map +1 -1
  43. package/dist/types/src/cards/JsonCard.d.ts.map +1 -1
  44. package/dist/types/src/cards/OrganizationCard.d.ts.map +1 -1
  45. package/dist/types/src/cards/PersonCard.d.ts.map +1 -1
  46. package/dist/types/src/cards/ProjectCard.d.ts.map +1 -1
  47. package/dist/types/src/cards/TaskCard.d.ts.map +1 -1
  48. package/dist/types/src/cards/index.d.ts +1 -0
  49. package/dist/types/src/cards/index.d.ts.map +1 -1
  50. package/dist/types/src/index.d.ts +0 -1
  51. package/dist/types/src/index.d.ts.map +1 -1
  52. package/dist/types/src/meta.d.ts +1 -1
  53. package/dist/types/src/meta.d.ts.map +1 -1
  54. package/dist/types/src/plugin.d.ts +3 -0
  55. package/dist/types/src/plugin.d.ts.map +1 -0
  56. package/dist/types/src/stories/Card.stories.d.ts +31 -9
  57. package/dist/types/src/stories/Card.stories.d.ts.map +1 -1
  58. package/dist/types/src/stories/testing.d.ts +43 -4
  59. package/dist/types/src/stories/testing.d.ts.map +1 -1
  60. package/dist/types/src/testing.d.ts +2 -0
  61. package/dist/types/src/testing.d.ts.map +1 -0
  62. package/dist/types/src/translations.d.ts +8 -9
  63. package/dist/types/src/translations.d.ts.map +1 -1
  64. package/dist/types/tsconfig.tsbuildinfo +1 -1
  65. package/package.json +70 -41
  66. package/src/PreviewPlugin.node.ts +16 -0
  67. package/src/PreviewPlugin.test.ts +25 -0
  68. package/src/PreviewPlugin.tsx +4 -3
  69. package/src/PreviewPlugin.workerd.ts +16 -0
  70. package/src/capabilities/preview-popover.ts +29 -4
  71. package/src/capabilities/react-surface.tsx +59 -18
  72. package/src/cards/ExpandoCard.tsx +76 -0
  73. package/src/cards/FormCard.tsx +90 -23
  74. package/src/cards/JsonCard.tsx +5 -2
  75. package/src/cards/OrganizationCard.tsx +2 -2
  76. package/src/cards/PersonCard.tsx +2 -2
  77. package/src/cards/ProjectCard.tsx +2 -2
  78. package/src/cards/TaskCard.tsx +4 -3
  79. package/src/cards/index.ts +1 -0
  80. package/src/index.ts +0 -2
  81. package/src/meta.ts +7 -4
  82. package/src/plugin.ts +9 -0
  83. package/src/stories/Card.stories.tsx +76 -6
  84. package/src/stories/testing.tsx +69 -7
  85. package/src/testing.ts +7 -0
  86. package/dist/lib/browser/index.mjs +0 -59
  87. package/dist/lib/browser/index.mjs.map +0 -7
  88. package/dist/lib/browser/meta.json +0 -1
  89. package/dist/lib/node-esm/index.mjs +0 -61
  90. package/dist/lib/node-esm/index.mjs.map +0 -7
  91. package/dist/lib/node-esm/meta.json +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-preview",
3
- "version": "0.8.4-main.422d1c7879",
3
+ "version": "0.8.4-main.43cb759274",
4
4
  "description": "Preview plugin",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -8,19 +8,58 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/dxos/dxos"
10
10
  },
11
- "license": "MIT",
11
+ "license": "FSL-1.1-Apache-2.0",
12
12
  "author": "DXOS.org",
13
13
  "sideEffects": true,
14
14
  "type": "module",
15
15
  "imports": {
16
- "#capabilities": "./src/capabilities/index.ts",
17
- "#meta": "./src/meta.ts"
16
+ "#capabilities": {
17
+ "source": "./src/capabilities/index.ts",
18
+ "types": "./dist/types/src/capabilities/index.d.ts",
19
+ "default": "./dist/lib/neutral/capabilities/index.mjs"
20
+ },
21
+ "#meta": {
22
+ "source": "./src/meta.ts",
23
+ "types": "./dist/types/src/meta.d.ts",
24
+ "default": "./dist/lib/neutral/meta.mjs"
25
+ },
26
+ "#plugin": {
27
+ "source": {
28
+ "workerd": "./src/PreviewPlugin.workerd.ts",
29
+ "node": "./src/PreviewPlugin.node.ts",
30
+ "default": "./src/PreviewPlugin.tsx"
31
+ },
32
+ "types": "./dist/types/src/PreviewPlugin.d.ts",
33
+ "workerd": "./dist/lib/neutral/PreviewPlugin.workerd.mjs",
34
+ "node": "./dist/lib/neutral/PreviewPlugin.node.mjs",
35
+ "default": "./dist/lib/neutral/PreviewPlugin.mjs"
36
+ },
37
+ "#translations": {
38
+ "source": "./src/translations.ts",
39
+ "types": "./dist/types/src/translations.d.ts",
40
+ "default": "./dist/lib/neutral/translations.mjs"
41
+ }
18
42
  },
19
43
  "exports": {
20
44
  ".": {
21
45
  "source": "./src/index.ts",
22
46
  "types": "./dist/types/src/index.d.ts",
23
- "browser": "./dist/lib/browser/index.mjs"
47
+ "default": "./dist/lib/neutral/index.mjs"
48
+ },
49
+ "./plugin": {
50
+ "source": "./src/plugin.ts",
51
+ "types": "./dist/types/src/plugin.d.ts",
52
+ "default": "./dist/lib/neutral/plugin.mjs"
53
+ },
54
+ "./testing": {
55
+ "source": "./src/testing.ts",
56
+ "types": "./dist/types/src/testing.d.ts",
57
+ "default": "./dist/lib/neutral/testing.mjs"
58
+ },
59
+ "./translations": {
60
+ "source": "./src/translations.ts",
61
+ "types": "./dist/types/src/translations.d.ts",
62
+ "default": "./dist/lib/neutral/translations.mjs"
24
63
  }
25
64
  },
26
65
  "types": "dist/types/src/index.d.ts",
@@ -29,48 +68,38 @@
29
68
  "src"
30
69
  ],
31
70
  "dependencies": {
32
- "@effect-atom/atom-react": "^0.5.0",
33
- "@dxos/app-framework": "0.8.4-main.422d1c7879",
34
- "@dxos/async": "0.8.4-main.422d1c7879",
35
- "@dxos/app-toolkit": "0.8.4-main.422d1c7879",
36
- "@dxos/client": "0.8.4-main.422d1c7879",
37
- "@dxos/echo": "0.8.4-main.422d1c7879",
38
- "@dxos/lit-ui": "0.8.4-main.422d1c7879",
39
- "@dxos/log": "0.8.4-main.422d1c7879",
40
- "@dxos/effect": "0.8.4-main.422d1c7879",
41
- "@dxos/keys": "0.8.4-main.422d1c7879",
42
- "@dxos/operation": "0.8.4-main.422d1c7879",
43
- "@dxos/plugin-attention": "0.8.4-main.422d1c7879",
44
- "@dxos/plugin-client": "0.8.4-main.422d1c7879",
45
- "@dxos/react-client": "0.8.4-main.422d1c7879",
46
- "@dxos/react-ui": "0.8.4-main.422d1c7879",
47
- "@dxos/react-ui-editor": "0.8.4-main.422d1c7879",
48
- "@dxos/react-ui-form": "0.8.4-main.422d1c7879",
49
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.422d1c7879",
50
- "@dxos/react-ui-table": "0.8.4-main.422d1c7879",
51
- "@dxos/react-ui-mosaic": "0.8.4-main.422d1c7879",
52
- "@dxos/schema": "0.8.4-main.422d1c7879",
53
- "@dxos/types": "0.8.4-main.422d1c7879",
54
- "@dxos/react-ui-menu": "0.8.4-main.422d1c7879",
55
- "@dxos/ui-editor": "0.8.4-main.422d1c7879",
56
- "@dxos/ui-theme": "0.8.4-main.422d1c7879",
57
- "@dxos/util": "0.8.4-main.422d1c7879",
58
- "@dxos/plugin-deck": "0.8.4-main.422d1c7879",
59
- "@dxos/app-graph": "0.8.4-main.422d1c7879"
71
+ "@dxos/app-toolkit": "0.8.4-main.43cb759274",
72
+ "@dxos/app-framework": "0.8.4-main.43cb759274",
73
+ "@dxos/async": "0.8.4-main.43cb759274",
74
+ "@dxos/echo": "0.8.4-main.43cb759274",
75
+ "@dxos/client": "0.8.4-main.43cb759274",
76
+ "@dxos/echo-react": "0.8.4-main.43cb759274",
77
+ "@dxos/log": "0.8.4-main.43cb759274",
78
+ "@dxos/effect": "0.8.4-main.43cb759274",
79
+ "@dxos/plugin-client": "0.8.4-main.43cb759274",
80
+ "@dxos/keys": "0.8.4-main.43cb759274",
81
+ "@dxos/react-ui": "0.8.4-main.43cb759274",
82
+ "@dxos/react-ui-form": "0.8.4-main.43cb759274",
83
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.43cb759274",
84
+ "@dxos/types": "0.8.4-main.43cb759274",
85
+ "@dxos/react-ui-mosaic": "0.8.4-main.43cb759274",
86
+ "@dxos/schema": "0.8.4-main.43cb759274",
87
+ "@dxos/ui-editor": "0.8.4-main.43cb759274",
88
+ "@dxos/util": "0.8.4-main.43cb759274"
60
89
  },
61
90
  "devDependencies": {
62
- "effect": "3.20.0",
91
+ "effect": "3.21.2",
63
92
  "react": "~19.2.3",
64
93
  "react-dom": "~19.2.3",
65
- "vite": "^7.1.11",
66
- "@dxos/echo-db": "0.8.4-main.422d1c7879",
67
- "@dxos/plugin-testing": "0.8.4-main.422d1c7879",
68
- "@dxos/random": "0.8.4-main.422d1c7879",
69
- "@dxos/react-ui-components": "0.8.4-main.422d1c7879",
70
- "@dxos/storybook-utils": "0.8.4-main.422d1c7879"
94
+ "vite": "^8.0.14",
95
+ "@dxos/plugin-testing": "0.8.4-main.43cb759274",
96
+ "@dxos/random": "0.8.4-main.43cb759274",
97
+ "@dxos/echo-react": "0.8.4-main.43cb759274",
98
+ "@dxos/react-ui-components": "0.8.4-main.43cb759274",
99
+ "@dxos/storybook-utils": "0.8.4-main.43cb759274"
71
100
  },
72
101
  "peerDependencies": {
73
- "effect": "3.20.0",
102
+ "effect": "3.21.2",
74
103
  "react": "~19.2.3",
75
104
  "react-dom": "~19.2.3"
76
105
  },
@@ -0,0 +1,16 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { Plugin } from '@dxos/app-framework';
6
+ import { AppPlugin } from '@dxos/app-toolkit';
7
+ import { Organization, Person } from '@dxos/types';
8
+
9
+ import { meta } from '#meta';
10
+
11
+ export const PreviewPlugin = Plugin.define(meta).pipe(
12
+ AppPlugin.addSchemaModule({ schema: [Person.Person, Organization.Organization] }),
13
+ Plugin.make,
14
+ );
15
+
16
+ export default PreviewPlugin;
@@ -0,0 +1,25 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { describe, test } from 'vitest';
6
+
7
+ import { ClientPlugin } from '@dxos/plugin-client/plugin';
8
+ import { createComposerTestApp } from '@dxos/plugin-testing/harness';
9
+
10
+ import { PreviewPlugin } from '#plugin';
11
+
12
+ import { meta } from './meta';
13
+
14
+ const moduleId = (name: string) => `${meta.id}.module.${name}`;
15
+
16
+ describe('PreviewPlugin', () => {
17
+ test('modules activate on the expected events', { timeout: 10_000 }, async ({ expect }) => {
18
+ await using harness = await createComposerTestApp({
19
+ plugins: [ClientPlugin({}), PreviewPlugin()],
20
+ });
21
+
22
+ // After autoStart: schema auto-cascades from ClientPlugin.
23
+ expect(harness.manager.getActive()).toContain(moduleId('schema'));
24
+ });
25
+ });
@@ -8,11 +8,10 @@ import { Organization, Person } from '@dxos/types';
8
8
 
9
9
  import { PreviewPopover, ReactSurface } from '#capabilities';
10
10
  import { meta } from '#meta';
11
-
12
- import { translations } from './translations';
11
+ import { translations } from '#translations';
13
12
 
14
13
  export const PreviewPlugin = Plugin.define(meta).pipe(
15
- AppPlugin.addSchemaModule({ schema: [Person.Person, Organization.Organization], id: 'schema' }),
14
+ AppPlugin.addSchemaModule({ schema: [Person.Person, Organization.Organization] }),
16
15
  AppPlugin.addSurfaceModule({ activate: ReactSurface }),
17
16
  AppPlugin.addTranslationsModule({ translations }),
18
17
  Plugin.addModule({
@@ -22,3 +21,5 @@ export const PreviewPlugin = Plugin.define(meta).pipe(
22
21
  }),
23
22
  Plugin.make,
24
23
  );
24
+
25
+ export default PreviewPlugin;
@@ -0,0 +1,16 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { Plugin } from '@dxos/app-framework';
6
+ import { AppPlugin } from '@dxos/app-toolkit';
7
+ import { Organization, Person } from '@dxos/types';
8
+
9
+ import { meta } from '#meta';
10
+
11
+ export const PreviewPlugin = Plugin.define(meta).pipe(
12
+ AppPlugin.addSchemaModule({ schema: [Person.Person, Organization.Organization] }),
13
+ Plugin.make,
14
+ );
15
+
16
+ export default PreviewPlugin;
@@ -10,9 +10,9 @@ import { addEventListener } from '@dxos/async';
10
10
  import { type Client } from '@dxos/client';
11
11
  import { type Space } from '@dxos/client/echo';
12
12
  import { Obj } from '@dxos/echo';
13
- import { DXN } from '@dxos/keys';
13
+ import { EID } from '@dxos/keys';
14
14
  import { log } from '@dxos/log';
15
- import { ClientCapabilities } from '@dxos/plugin-client/types';
15
+ import { ClientCapabilities } from '@dxos/plugin-client';
16
16
  import { DX_ANCHOR_ACTIVATE, type DxAnchorActivate } from '@dxos/react-ui';
17
17
  import { type PreviewLinkRef, type PreviewLinkTarget } from '@dxos/ui-editor';
18
18
 
@@ -24,7 +24,7 @@ const handlePreviewLookup = async (
24
24
  { dxn, label }: PreviewLinkRef,
25
25
  ): Promise<PreviewLinkTarget | null> => {
26
26
  try {
27
- const object = await defaultSpace.db.makeRef(DXN.parse(dxn)).load();
27
+ const object = await defaultSpace.db.makeRef(EID.parse(dxn)).load();
28
28
  return { label, object };
29
29
  } catch {
30
30
  return null;
@@ -37,6 +37,10 @@ export default Capability.makeModule(
37
37
  const capabilities = yield* Capability.Service;
38
38
 
39
39
  // TODO(wittjosiah): Factor out lookup handlers to other plugins to make not ECHO-specific.
40
+ // Monotonic activation token: each invocation captures its own sequence; only the
41
+ // most recent activation is allowed to commit popover state. Prevents a slow
42
+ // open (async lookup) from clobbering a later close that fires while it's in flight.
43
+ let activationSequence = 0;
40
44
  const handleAnchorActivate = async ({
41
45
  dxn,
42
46
  label,
@@ -45,8 +49,24 @@ export default Capability.makeModule(
45
49
  title: titleProp,
46
50
  side,
47
51
  props,
52
+ state,
48
53
  }: DxAnchorActivate) => {
54
+ const sequence = ++activationSequence;
49
55
  const { invokePromise } = capabilities.get(Capabilities.OperationInvoker);
56
+
57
+ // Explicit close: callers pass `state: false` on pointer-leave to dismiss
58
+ // the popover. Operation schema requires anchor + kind, so use placeholders;
59
+ // they're overwritten in ephemeral state but only `state` is read by the UI.
60
+ if (state === false) {
61
+ await invokePromise(LayoutOperation.UpdatePopover, {
62
+ variant: 'virtual',
63
+ anchor: trigger,
64
+ kind: 'base',
65
+ state: false,
66
+ });
67
+ return;
68
+ }
69
+
50
70
  const client = capabilities.get(ClientCapabilities.Client);
51
71
  const registry = capabilities.get(Capabilities.AtomRegistry);
52
72
  // Layout is optional: in standalone harnesses (Storybook, tests) no plugin contributes
@@ -63,8 +83,13 @@ export default Capability.makeModule(
63
83
  if (!result) {
64
84
  return;
65
85
  }
86
+ // A newer activation (open or close) arrived while the lookup was in flight; bail
87
+ // out so we don't clobber the latest state.
88
+ if (sequence !== activationSequence) {
89
+ return;
90
+ }
66
91
 
67
- const title = titleProp ?? Obj.getLabel(result.object);
92
+ const title = titleProp ?? Obj.getLabel(result.object, { fallback: 'typename' });
68
93
 
69
94
  await invokePromise(LayoutOperation.UpdatePopover, {
70
95
  subjectRef: dxn,
@@ -8,12 +8,12 @@ import React from 'react';
8
8
  import { Capabilities, Capability } from '@dxos/app-framework';
9
9
  import { Surface } from '@dxos/app-framework/ui';
10
10
  import { AppSurface } from '@dxos/app-toolkit/ui';
11
- import { Obj } from '@dxos/echo';
11
+ import { Obj, Type } from '@dxos/echo';
12
12
  import { Card } from '@dxos/react-ui';
13
- import { type ProjectionModel } from '@dxos/schema';
13
+ import { Expando, type ProjectionModel } from '@dxos/schema';
14
14
  import { Organization, Person, Pipeline, Task } from '@dxos/types';
15
15
 
16
- import { FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
16
+ import { ExpandoCard, FormCard, JsonCard, OrganizationCard, PersonCard, ProjectCard, TaskCard } from '../cards';
17
17
 
18
18
  export default Capability.makeModule(() =>
19
19
  Effect.succeed(
@@ -24,8 +24,8 @@ export default Capability.makeModule(() =>
24
24
  //
25
25
 
26
26
  Surface.create<{ subject: Person.Person }>({
27
- id: 'schema-popover--contact',
28
- position: 'hoist',
27
+ id: 'schemaPopoverContact',
28
+ position: 'first',
29
29
  filter: AppSurface.object(AppSurface.Card, Person.Person),
30
30
  component: ({ data, role }) => {
31
31
  return (
@@ -37,8 +37,8 @@ export default Capability.makeModule(() =>
37
37
  },
38
38
  }),
39
39
  Surface.create({
40
- id: 'schema-popover--organization',
41
- position: 'hoist',
40
+ id: 'schemaPopoverOrganization',
41
+ position: 'first',
42
42
  filter: AppSurface.object(AppSurface.Card, Organization.Organization),
43
43
  component: ({ data, role }) => {
44
44
  return (
@@ -50,30 +50,71 @@ export default Capability.makeModule(() =>
50
50
  },
51
51
  }),
52
52
  Surface.create({
53
- id: 'schema-popover--project',
54
- position: 'hoist',
53
+ id: 'schemaPopoverProject',
54
+ position: 'first',
55
55
  filter: AppSurface.object(AppSurface.Card, Pipeline.Pipeline),
56
56
  component: ({ data, role }) => {
57
57
  return <ProjectCard role={role} subject={data.subject} />;
58
58
  },
59
59
  }),
60
60
  Surface.create({
61
- id: 'schema-popover--task',
62
- position: 'hoist',
61
+ id: 'schemaPopoverTask',
62
+ position: 'first',
63
63
  filter: AppSurface.object(AppSurface.Card, Task.Task),
64
64
  component: ({ data, role }) => {
65
65
  return <TaskCard role={role} subject={data.subject} />;
66
66
  },
67
67
  }),
68
+ Surface.create<AppSurface.ObjectCardData<Expando.Expando>>({
69
+ id: 'schemaPopoverExpando',
70
+ filter: AppSurface.object(AppSurface.Card, Expando.Expando),
71
+ component: ({ data, role }) => {
72
+ return <ExpandoCard role={role} subject={data.subject} ignorePaths={data.ignorePaths} />;
73
+ },
74
+ }),
75
+
76
+ Surface.create({
77
+ id: 'schemaPopoverDynamicType',
78
+ role: 'card--content',
79
+ filter: (data): data is { subject: Obj.Unknown } => {
80
+ if (!Obj.isObject(data.subject)) {
81
+ return false;
82
+ }
83
+ const type = Obj.getType(data.subject);
84
+ if (type) {
85
+ return Type.getDatabase(type) != null;
86
+ }
87
+ // Obj.getType fails for database-registered schemas (DXN mismatch); fall back to typename query.
88
+ try {
89
+ const db = Obj.getDatabase(data.subject);
90
+ const typename = Obj.getTypename(data.subject);
91
+ return (
92
+ !!db &&
93
+ !!typename &&
94
+ db.graph.registry
95
+ .list()
96
+ .filter(Type.isType)
97
+ .some((t) => Type.getTypename(t) === typename)
98
+ );
99
+ } catch {
100
+ return false;
101
+ }
102
+ },
103
+ component: ({ data, role }) => {
104
+ // Dynamic/mutable schemas render an editable, full-layout form;
105
+ // FormCard handles both static and runtime schema resolution internally.
106
+ return <FormCard role={role} subject={data.subject} readonly={false} layout='full' />;
107
+ },
108
+ }),
68
109
 
69
110
  //
70
111
  // Fallback for any object.
71
112
  //
72
113
 
73
114
  Surface.create({
74
- id: 'fallback-popover',
115
+ id: 'fallbackPopover',
75
116
  role: 'card--content',
76
- position: 'fallback',
117
+ position: 'last',
77
118
  filter: (data): data is { subject: Obj.Unknown; projection?: ProjectionModel } => Obj.isObject(data.subject),
78
119
  component: ({ data, role }) => {
79
120
  return <FormCard role={role} subject={data.subject} projection={data.projection} />;
@@ -81,9 +122,9 @@ export default Capability.makeModule(() =>
81
122
  }),
82
123
 
83
124
  Surface.create({
84
- id: 'fallback-json',
125
+ id: 'fallbackJson',
85
126
  role: 'card--content',
86
- position: 'fallback',
127
+ position: 'last',
87
128
  filter: (data): data is Record<string, unknown> => true,
88
129
  component: ({ data }) => {
89
130
  return <JsonCard data={data} />;
@@ -92,12 +133,12 @@ export default Capability.makeModule(() =>
92
133
 
93
134
  Surface.create({
94
135
  id: 'section',
95
- position: 'fallback',
136
+ position: 'last',
96
137
  filter: AppSurface.subject(AppSurface.Section, Obj.isObject),
97
138
  component: ({ data }) => {
98
139
  return (
99
- <div role='none' className='flex w-full justify-center'>
100
- <div role='none' className='pt-2 pb-2 dx-card-min-width dx-card-max-width'>
140
+ <div className='flex w-full justify-center'>
141
+ <div className='py-2 dx-card-min-width dx-card-max-width'>
101
142
  <Card.Root>
102
143
  <Surface.Surface type={AppSurface.Card} data={data} limit={1} />
103
144
  </Card.Root>
@@ -0,0 +1,76 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+ import React, { useCallback, useMemo } from 'react';
7
+
8
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
9
+ import { Obj } from '@dxos/echo';
10
+ import { type JsonPath, splitJsonPath } from '@dxos/effect';
11
+ import { Card } from '@dxos/react-ui';
12
+ import { Form } from '@dxos/react-ui-form';
13
+
14
+ const schemaForValue = (value: unknown): Schema.Schema.AnyNoContext | undefined => {
15
+ switch (typeof value) {
16
+ case 'string':
17
+ return Schema.String;
18
+ case 'number':
19
+ return Schema.Number;
20
+ case 'boolean':
21
+ return Schema.Boolean;
22
+ default:
23
+ return undefined;
24
+ }
25
+ };
26
+
27
+ /**
28
+ * Reserved keys: `id`, plus any `~`-prefixed key (ECHO uses `~`-prefixed
29
+ * string keys to brand entity instances and schemas — KindId,
30
+ * SchemaKindId, SnapshotKindId, etc. — and the `~` namespace is reserved
31
+ * for that purpose). They show up in `Object.keys` but aren't user data.
32
+ */
33
+ const isInternalKey = (key: string) => key === 'id' || key.startsWith('~');
34
+
35
+ export const ExpandoCard = ({ subject, ignorePaths }: AppSurface.ObjectCardProps) => {
36
+ const schema = useMemo(() => {
37
+ const ignored = new Set(ignorePaths ?? []);
38
+ const fields: Record<string, Schema.Schema.AnyNoContext> = {};
39
+ for (const key of Object.keys(subject)) {
40
+ if (isInternalKey(key) || ignored.has(key)) {
41
+ continue;
42
+ }
43
+ const fieldSchema = schemaForValue((subject as any)[key]);
44
+ if (fieldSchema) {
45
+ fields[key] = fieldSchema;
46
+ }
47
+ }
48
+ return Schema.Struct(fields);
49
+ }, [subject, ignorePaths]);
50
+
51
+ const handleSave = useCallback(
52
+ (values: any, { changed }: { changed: Record<string, boolean> }) => {
53
+ const paths = Object.keys(changed).filter((path) => changed[path]);
54
+ Obj.update(subject, () => {
55
+ for (const path of paths) {
56
+ const value = values[path];
57
+ const parts = splitJsonPath(path as JsonPath);
58
+ Obj.setValue(subject, parts, value);
59
+ }
60
+ });
61
+ },
62
+ [subject],
63
+ );
64
+
65
+ return (
66
+ <Card.Body>
67
+ <Form.Root schema={schema} values={subject} autoSave onSave={handleSave}>
68
+ <Form.Viewport>
69
+ <Form.Content>
70
+ <Form.FieldSet />
71
+ </Form.Content>
72
+ </Form.Viewport>
73
+ </Form.Root>
74
+ </Card.Body>
75
+ );
76
+ };
@@ -2,47 +2,114 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import * as Schema from 'effect/Schema';
5
6
  import React, { useCallback, useMemo } from 'react';
6
7
 
7
8
  import { type AppSurface } from '@dxos/app-toolkit/ui';
8
- import { Obj } from '@dxos/echo';
9
+ import { Obj, Type } from '@dxos/echo';
10
+ import { useType } from '@dxos/echo-react';
11
+ import { type AnyProperties } from '@dxos/echo/internal';
9
12
  import { type JsonPath, splitJsonPath } from '@dxos/effect';
10
13
  import { Card, useTranslation } from '@dxos/react-ui';
11
- import { Form, omitId } from '@dxos/react-ui-form';
14
+ import { Form, type FormUpdateMeta, type Presentation, getFormProperties, omitId } from '@dxos/react-ui-form';
12
15
  import { type ProjectionModel } from '@dxos/schema';
13
- import { descriptionMessage, mx } from '@dxos/ui-theme';
14
16
 
15
17
  import { meta } from '#meta';
16
18
 
17
- export const FormCard = ({ subject, projection }: AppSurface.ObjectCardProps & { projection?: ProjectionModel }) => {
19
+ export type FormCardProps = AppSurface.ObjectCardProps & {
20
+ projection?: ProjectionModel;
21
+ readonly?: boolean;
22
+ layout?: Presentation;
23
+ };
24
+
25
+ /**
26
+ * Default/fallback card for any ECHO object.
27
+ * Renders a `Form` against the object's schema — either the static schema
28
+ * from `Obj.getSchema` or, for runtime/mutable schemas, the reactive
29
+ * schema looked up via `useType`.
30
+ */
31
+ export const FormCard = ({ subject, projection, readonly = true, layout }: FormCardProps) => {
18
32
  const { t } = useTranslation(meta.id);
19
- const echoSchema = Obj.getSchema(subject);
20
- const schema = useMemo(() => echoSchema && omitId(echoSchema), [echoSchema]);
21
-
22
- const handleSave = useCallback((values: any, { changed }: { changed: Record<string, boolean> }) => {
23
- const paths = Object.keys(changed).filter((path) => changed[path]);
24
- Obj.change(subject, () => {
25
- for (const path of paths) {
26
- const value = values[path];
27
- const parts = splitJsonPath(path as JsonPath);
28
- Obj.setValue(subject, parts, value);
29
- }
30
- });
31
- }, []);
32
-
33
- if (!schema) {
34
- return <p className={mx(descriptionMessage)}>{t('unable-to-create-preview.message')}</p>;
33
+ // Readonly cards default to the `static` presentation — plain DOM, undefined values
34
+ // omitted — which reads as a preview rather than a form. Editable cards keep the
35
+ // `compact` form layout. Callers can override either via the explicit `layout` prop.
36
+ const resolvedLayout: Presentation = layout ?? (readonly ? 'static' : 'compact');
37
+
38
+ // Try the static schema first; fall back to the runtime/database schema for
39
+ // dynamic types whose schema isn't reachable via `Obj.getSchema` (DXN mismatch).
40
+ const staticType = Obj.getType(subject);
41
+ const db = Obj.getDatabase(subject);
42
+ const typename = Obj.getTypename(subject);
43
+ const runtimeType = useType(db, staticType ? undefined : typename);
44
+ const schema = useMemo((): Schema.Schema.AnyNoContext | undefined => {
45
+ const resolvedType = runtimeType ?? staticType;
46
+ return resolvedType ? omitId(Type.getSchema(resolvedType)) : undefined;
47
+ }, [runtimeType, staticType]);
48
+
49
+ // Predict whether the form would render anything visible. Without this guard,
50
+ // readonly + compact mode produces an empty scrollarea when every form-renderable
51
+ // field is unset (e.g., a Table object whose `view`/`sizes` are FormInput-hidden
52
+ // and whose `name` is undefined).
53
+ //
54
+ // - In editable mode (`!readonly`), the form renders empty fields, so we only
55
+ // bail when there are no form-renderable properties at all.
56
+ // - In readonly mode, the form hides fields with null/undefined values, so we
57
+ // bail when no form-renderable property has a non-null value.
58
+ const hasRenderableContent = useMemo(() => {
59
+ if (!schema) {
60
+ return false;
61
+ }
62
+ const properties = getFormProperties(schema.ast);
63
+ if (properties.length === 0) {
64
+ return false;
65
+ }
66
+ if (!readonly) {
67
+ return true;
68
+ }
69
+ return properties.some((prop) => (subject as any)?.[prop.name] != null);
70
+ }, [schema, subject, readonly]);
71
+
72
+ const handleSave = useCallback(
73
+ (values: AnyProperties, { changed }: FormUpdateMeta<AnyProperties>) => {
74
+ const paths = (Object.keys(changed) as JsonPath[]).filter((path) => changed[path]);
75
+ Obj.update(subject, () => {
76
+ for (const path of paths) {
77
+ const parts = splitJsonPath(path);
78
+ const value = Obj.getValue(values as any, parts);
79
+ Obj.setValue(subject, parts, value);
80
+ }
81
+ });
82
+ },
83
+ [subject],
84
+ );
85
+
86
+ if (!schema || !hasRenderableContent) {
87
+ return (
88
+ <Card.Body>
89
+ <Card.Row>
90
+ <Card.Text variant='description'>{t('unable-to-create-preview.message')}</Card.Text>
91
+ </Card.Row>
92
+ </Card.Body>
93
+ );
35
94
  }
36
95
 
37
96
  return (
38
- <Card.Content>
39
- <Form.Root schema={schema} projection={projection} values={subject} autoSave onSave={handleSave}>
97
+ <Card.Body>
98
+ <Form.Root
99
+ schema={schema}
100
+ projection={projection}
101
+ values={subject}
102
+ readonly={readonly}
103
+ layout={resolvedLayout}
104
+ autoSave
105
+ onSave={handleSave}
106
+ >
40
107
  <Form.Viewport>
41
108
  <Form.Content>
42
109
  <Form.FieldSet />
43
110
  </Form.Content>
44
111
  </Form.Viewport>
45
112
  </Form.Root>
46
- </Card.Content>
113
+ </Card.Body>
47
114
  );
48
115
  };