@dxos/plugin-markdown 0.8.1 → 0.8.2-main.f081794

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 (120) hide show
  1. package/dist/lib/browser/{MarkdownContainer-T3HU27RE.mjs → MarkdownContainer-MH6MMKA5.mjs} +12 -10
  2. package/dist/lib/browser/MarkdownContainer-MH6MMKA5.mjs.map +7 -0
  3. package/dist/lib/browser/{app-graph-serializer-NOXI4IQ5.mjs → app-graph-serializer-BF7WSE3D.mjs} +3 -3
  4. package/dist/lib/browser/{artifact-definition-CE6J6NY4.mjs → artifact-definition-XTVOUMMI.mjs} +2 -2
  5. package/dist/lib/browser/{chunk-QXDKFACU.mjs → chunk-2DKQKSBR.mjs} +2 -2
  6. package/dist/lib/browser/{chunk-YCJNW2RU.mjs → chunk-GVOEHF7E.mjs} +10 -1
  7. package/dist/lib/browser/chunk-GVOEHF7E.mjs.map +7 -0
  8. package/dist/lib/browser/{chunk-3ULJ4FIJ.mjs → chunk-V54HDI7B.mjs} +12 -12
  9. package/dist/lib/browser/chunk-V54HDI7B.mjs.map +7 -0
  10. package/dist/lib/browser/index.mjs +3 -3
  11. package/dist/lib/browser/index.mjs.map +1 -1
  12. package/dist/lib/browser/intent-resolver-H37L3DBD.mjs +86 -0
  13. package/dist/lib/browser/intent-resolver-H37L3DBD.mjs.map +7 -0
  14. package/dist/lib/browser/meta.json +1 -1
  15. package/dist/lib/browser/{react-surface-RQX3CPFV.mjs → react-surface-RONTBOZZ.mjs} +3 -3
  16. package/dist/lib/browser/{settings-GCSS3Y4Z.mjs → settings-EQSDBX6O.mjs} +4 -4
  17. package/dist/lib/browser/settings-EQSDBX6O.mjs.map +7 -0
  18. package/dist/lib/browser/{state-O7P5JDIH.mjs → state-AIN4J7N5.mjs} +1 -1
  19. package/dist/lib/browser/{state-O7P5JDIH.mjs.map → state-AIN4J7N5.mjs.map} +2 -2
  20. package/dist/lib/browser/{thread-3QGCFNVZ.mjs → thread-MFKBUVCB.mjs} +2 -2
  21. package/dist/lib/browser/types/index.mjs +3 -1
  22. package/dist/lib/node/{MarkdownContainer-6ZJIFAP6.cjs → MarkdownContainer-PCHMSPTC.cjs} +17 -15
  23. package/dist/lib/node/MarkdownContainer-PCHMSPTC.cjs.map +7 -0
  24. package/dist/lib/node/{app-graph-serializer-HKK3SEDN.cjs → app-graph-serializer-UVT5EAWW.cjs} +9 -9
  25. package/dist/lib/node/{artifact-definition-XGADFWCQ.cjs → artifact-definition-ADEN2KD6.cjs} +9 -9
  26. package/dist/lib/node/{chunk-7QVONRSI.cjs → chunk-5XQ27MNY.cjs} +14 -14
  27. package/dist/lib/node/chunk-5XQ27MNY.cjs.map +7 -0
  28. package/dist/lib/node/{chunk-H5MYVP6F.cjs → chunk-6ERKWMAU.cjs} +6 -6
  29. package/dist/lib/node/{chunk-UEXGNGSS.cjs → chunk-YHL4JSA6.cjs} +14 -4
  30. package/dist/lib/node/chunk-YHL4JSA6.cjs.map +7 -0
  31. package/dist/lib/node/index.cjs +20 -20
  32. package/dist/lib/node/index.cjs.map +1 -1
  33. package/dist/lib/node/{intent-resolver-NW27BF3W.cjs → intent-resolver-NX5QNRYF.cjs} +45 -9
  34. package/dist/lib/node/intent-resolver-NX5QNRYF.cjs.map +7 -0
  35. package/dist/lib/node/meta.json +1 -1
  36. package/dist/lib/node/{react-surface-5X3SMHGI.cjs → react-surface-26PWFBBV.cjs} +8 -8
  37. package/dist/lib/node/{settings-S2ISUVIH.cjs → settings-2JXASSLU.cjs} +7 -7
  38. package/dist/lib/node/settings-2JXASSLU.cjs.map +7 -0
  39. package/dist/lib/node/{state-L44SG3ZM.cjs → state-PC7IVXFP.cjs} +4 -4
  40. package/dist/lib/node/{state-L44SG3ZM.cjs.map → state-PC7IVXFP.cjs.map} +2 -2
  41. package/dist/lib/node/{thread-42R57L4K.cjs → thread-MXEGV6HS.cjs} +6 -6
  42. package/dist/lib/node/types/index.cjs +8 -6
  43. package/dist/lib/node/types/index.cjs.map +2 -2
  44. package/dist/lib/node-esm/{MarkdownContainer-URAPTO37.mjs → MarkdownContainer-ERQH4SXI.mjs} +12 -10
  45. package/dist/lib/node-esm/MarkdownContainer-ERQH4SXI.mjs.map +7 -0
  46. package/dist/lib/node-esm/{app-graph-serializer-QQ2CTHOQ.mjs → app-graph-serializer-LPRG2PFZ.mjs} +3 -3
  47. package/dist/lib/node-esm/{artifact-definition-WRG5ZRN5.mjs → artifact-definition-KTS5M2FW.mjs} +2 -2
  48. package/dist/lib/node-esm/{chunk-JAVD67QP.mjs → chunk-IZUCQ5P5.mjs} +2 -2
  49. package/dist/lib/node-esm/{chunk-4AM4VU3Y.mjs → chunk-NUZHKZSZ.mjs} +10 -1
  50. package/dist/lib/node-esm/chunk-NUZHKZSZ.mjs.map +7 -0
  51. package/dist/lib/node-esm/{chunk-F6UHVLH7.mjs → chunk-USLC246I.mjs} +12 -12
  52. package/dist/lib/node-esm/chunk-USLC246I.mjs.map +7 -0
  53. package/dist/lib/node-esm/index.mjs +3 -3
  54. package/dist/lib/node-esm/index.mjs.map +1 -1
  55. package/dist/lib/node-esm/intent-resolver-XES4ZCA6.mjs +87 -0
  56. package/dist/lib/node-esm/intent-resolver-XES4ZCA6.mjs.map +7 -0
  57. package/dist/lib/node-esm/meta.json +1 -1
  58. package/dist/lib/node-esm/{react-surface-6IKC3G46.mjs → react-surface-ZEJSYIRX.mjs} +3 -3
  59. package/dist/lib/node-esm/{settings-ZDIFTK4N.mjs → settings-67RVIH3N.mjs} +4 -4
  60. package/dist/lib/node-esm/settings-67RVIH3N.mjs.map +7 -0
  61. package/dist/lib/node-esm/{state-DWPOKLEY.mjs → state-PNOPM4TS.mjs} +1 -1
  62. package/dist/lib/node-esm/{state-DWPOKLEY.mjs.map → state-PNOPM4TS.mjs.map} +2 -2
  63. package/dist/lib/node-esm/{thread-R2KHZD6V.mjs → thread-5U4KSBED.mjs} +2 -2
  64. package/dist/lib/node-esm/types/index.mjs +3 -1
  65. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  66. package/dist/types/src/components/MarkdownContainer.d.ts.map +1 -1
  67. package/dist/types/src/components/MarkdownEditor.stories.d.ts +3 -3
  68. package/dist/types/src/components/MarkdownEditor.stories.d.ts.map +1 -1
  69. package/dist/types/src/components/Suggestions.stories.d.ts +12 -0
  70. package/dist/types/src/components/Suggestions.stories.d.ts.map +1 -0
  71. package/dist/types/src/components/Toolbar.stories.d.ts +2 -2
  72. package/dist/types/src/components/Toolbar.stories.d.ts.map +1 -1
  73. package/dist/types/src/extensions.d.ts.map +1 -1
  74. package/dist/types/src/types/schema.d.ts +83 -3
  75. package/dist/types/src/types/schema.d.ts.map +1 -1
  76. package/package.json +36 -32
  77. package/src/MarkdownPlugin.tsx +3 -3
  78. package/src/capabilities/intent-resolver.ts +38 -5
  79. package/src/capabilities/settings.ts +2 -2
  80. package/src/capabilities/state.ts +1 -1
  81. package/src/components/MarkdownContainer.tsx +1 -0
  82. package/src/components/MarkdownEditor.stories.tsx +21 -34
  83. package/src/components/MarkdownEditor.tsx +1 -1
  84. package/src/components/Suggestions.stories.tsx +182 -0
  85. package/src/components/Toolbar.stories.tsx +15 -15
  86. package/src/extensions.tsx +37 -32
  87. package/src/types/schema.ts +5 -0
  88. package/src/util.tsx +2 -2
  89. package/dist/lib/browser/MarkdownContainer-T3HU27RE.mjs.map +0 -7
  90. package/dist/lib/browser/chunk-3ULJ4FIJ.mjs.map +0 -7
  91. package/dist/lib/browser/chunk-YCJNW2RU.mjs.map +0 -7
  92. package/dist/lib/browser/intent-resolver-42GQ6HNZ.mjs +0 -50
  93. package/dist/lib/browser/intent-resolver-42GQ6HNZ.mjs.map +0 -7
  94. package/dist/lib/browser/settings-GCSS3Y4Z.mjs.map +0 -7
  95. package/dist/lib/node/MarkdownContainer-6ZJIFAP6.cjs.map +0 -7
  96. package/dist/lib/node/chunk-7QVONRSI.cjs.map +0 -7
  97. package/dist/lib/node/chunk-UEXGNGSS.cjs.map +0 -7
  98. package/dist/lib/node/intent-resolver-NW27BF3W.cjs.map +0 -7
  99. package/dist/lib/node/settings-S2ISUVIH.cjs.map +0 -7
  100. package/dist/lib/node-esm/MarkdownContainer-URAPTO37.mjs.map +0 -7
  101. package/dist/lib/node-esm/chunk-4AM4VU3Y.mjs.map +0 -7
  102. package/dist/lib/node-esm/chunk-F6UHVLH7.mjs.map +0 -7
  103. package/dist/lib/node-esm/intent-resolver-7HOMUVHR.mjs +0 -51
  104. package/dist/lib/node-esm/intent-resolver-7HOMUVHR.mjs.map +0 -7
  105. package/dist/lib/node-esm/settings-ZDIFTK4N.mjs.map +0 -7
  106. /package/dist/lib/browser/{app-graph-serializer-NOXI4IQ5.mjs.map → app-graph-serializer-BF7WSE3D.mjs.map} +0 -0
  107. /package/dist/lib/browser/{artifact-definition-CE6J6NY4.mjs.map → artifact-definition-XTVOUMMI.mjs.map} +0 -0
  108. /package/dist/lib/browser/{chunk-QXDKFACU.mjs.map → chunk-2DKQKSBR.mjs.map} +0 -0
  109. /package/dist/lib/browser/{react-surface-RQX3CPFV.mjs.map → react-surface-RONTBOZZ.mjs.map} +0 -0
  110. /package/dist/lib/browser/{thread-3QGCFNVZ.mjs.map → thread-MFKBUVCB.mjs.map} +0 -0
  111. /package/dist/lib/node/{app-graph-serializer-HKK3SEDN.cjs.map → app-graph-serializer-UVT5EAWW.cjs.map} +0 -0
  112. /package/dist/lib/node/{artifact-definition-XGADFWCQ.cjs.map → artifact-definition-ADEN2KD6.cjs.map} +0 -0
  113. /package/dist/lib/node/{chunk-H5MYVP6F.cjs.map → chunk-6ERKWMAU.cjs.map} +0 -0
  114. /package/dist/lib/node/{react-surface-5X3SMHGI.cjs.map → react-surface-26PWFBBV.cjs.map} +0 -0
  115. /package/dist/lib/node/{thread-42R57L4K.cjs.map → thread-MXEGV6HS.cjs.map} +0 -0
  116. /package/dist/lib/node-esm/{app-graph-serializer-QQ2CTHOQ.mjs.map → app-graph-serializer-LPRG2PFZ.mjs.map} +0 -0
  117. /package/dist/lib/node-esm/{artifact-definition-WRG5ZRN5.mjs.map → artifact-definition-KTS5M2FW.mjs.map} +0 -0
  118. /package/dist/lib/node-esm/{chunk-JAVD67QP.mjs.map → chunk-IZUCQ5P5.mjs.map} +0 -0
  119. /package/dist/lib/node-esm/{react-surface-6IKC3G46.mjs.map → react-surface-ZEJSYIRX.mjs.map} +0 -0
  120. /package/dist/lib/node-esm/{thread-R2KHZD6V.mjs.map → thread-5U4KSBED.mjs.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-markdown",
3
- "version": "0.8.1",
3
+ "version": "0.8.2-main.f081794",
4
4
  "description": "DXOS Surface plugin for interacting with Markdown",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -38,30 +38,32 @@
38
38
  "@preact/signals-core": "^1.6.0",
39
39
  "effect": "3.13.3",
40
40
  "react-dropzone": "^14.2.3",
41
- "@dxos/app-framework": "0.8.1",
42
- "@dxos/echo-schema": "0.8.1",
43
- "@dxos/artifact": "0.8.1",
44
- "@dxos/async": "0.8.1",
45
- "@dxos/invariant": "0.8.1",
46
- "@dxos/keys": "0.8.1",
47
- "@dxos/local-storage": "0.8.1",
48
- "@dxos/live-object": "0.8.1",
49
- "@dxos/log": "0.8.1",
50
- "@dxos/plugin-client": "0.8.1",
51
- "@dxos/plugin-deck": "0.8.1",
52
- "@dxos/plugin-graph": "0.8.1",
53
- "@dxos/plugin-space": "0.8.1",
54
- "@dxos/plugin-attention": "0.8.1",
55
- "@dxos/plugin-theme": "0.8.1",
56
- "@dxos/react-client": "0.8.1",
57
- "@dxos/react-hooks": "0.8.1",
58
- "@dxos/react-ui-attention": "0.8.1",
59
- "@dxos/react-ui-card": "0.8.1",
60
- "@dxos/react-ui-editor": "0.8.1",
61
- "@dxos/react-ui-form": "0.8.1",
62
- "@dxos/react-ui-stack": "0.8.1",
63
- "@dxos/util": "0.8.1",
64
- "@dxos/schema": "0.8.1"
41
+ "@dxos/app-framework": "0.8.2-main.f081794",
42
+ "@dxos/automerge": "0.8.2-main.f081794",
43
+ "@dxos/artifact": "0.8.2-main.f081794",
44
+ "@dxos/echo-schema": "0.8.2-main.f081794",
45
+ "@dxos/keys": "0.8.2-main.f081794",
46
+ "@dxos/lit-ui": "0.8.2-main.f081794",
47
+ "@dxos/async": "0.8.2-main.f081794",
48
+ "@dxos/invariant": "0.8.2-main.f081794",
49
+ "@dxos/live-object": "0.8.2-main.f081794",
50
+ "@dxos/log": "0.8.2-main.f081794",
51
+ "@dxos/plugin-attention": "0.8.2-main.f081794",
52
+ "@dxos/local-storage": "0.8.2-main.f081794",
53
+ "@dxos/plugin-client": "0.8.2-main.f081794",
54
+ "@dxos/plugin-deck": "0.8.2-main.f081794",
55
+ "@dxos/plugin-graph": "0.8.2-main.f081794",
56
+ "@dxos/plugin-theme": "0.8.2-main.f081794",
57
+ "@dxos/react-client": "0.8.2-main.f081794",
58
+ "@dxos/plugin-space": "0.8.2-main.f081794",
59
+ "@dxos/react-hooks": "0.8.2-main.f081794",
60
+ "@dxos/react-ui-card": "0.8.2-main.f081794",
61
+ "@dxos/react-ui-attention": "0.8.2-main.f081794",
62
+ "@dxos/react-ui-form": "0.8.2-main.f081794",
63
+ "@dxos/react-ui-stack": "0.8.2-main.f081794",
64
+ "@dxos/react-ui-editor": "0.8.2-main.f081794",
65
+ "@dxos/schema": "0.8.2-main.f081794",
66
+ "@dxos/util": "0.8.2-main.f081794"
65
67
  },
66
68
  "devDependencies": {
67
69
  "@phosphor-icons/react": "^2.1.5",
@@ -70,18 +72,20 @@
70
72
  "react": "~18.2.0",
71
73
  "react-dom": "~18.2.0",
72
74
  "vite": "5.4.7",
73
- "@dxos/react-ui": "0.8.1",
74
- "@dxos/random": "0.8.1",
75
- "@dxos/react-ui-theme": "0.8.1",
76
- "@dxos/debug": "0.8.1",
77
- "@dxos/storybook-utils": "0.8.1"
75
+ "@dxos/debug": "0.8.2-main.f081794",
76
+ "@dxos/plugin-storybook-layout": "0.8.2-main.f081794",
77
+ "@dxos/plugin-theme": "0.8.2-main.f081794",
78
+ "@dxos/random": "0.8.2-main.f081794",
79
+ "@dxos/react-ui": "0.8.2-main.f081794",
80
+ "@dxos/storybook-utils": "0.8.2-main.f081794",
81
+ "@dxos/react-ui-theme": "0.8.2-main.f081794"
78
82
  },
79
83
  "peerDependencies": {
80
84
  "@phosphor-icons/react": "^2.1.5",
81
85
  "react": "~18.2.0",
82
86
  "react-dom": "~18.2.0",
83
- "@dxos/react-ui": "0.8.1",
84
- "@dxos/react-ui-theme": "0.8.1"
87
+ "@dxos/react-ui": "0.8.2-main.f081794",
88
+ "@dxos/react-ui-theme": "0.8.2-main.f081794"
85
89
  },
86
90
  "publishConfig": {
87
91
  "access": "public"
@@ -12,13 +12,13 @@ import { translations as editorTranslations } from '@dxos/react-ui-editor';
12
12
  import { TextType } from '@dxos/schema';
13
13
 
14
14
  import {
15
+ AppGraphSerializer,
16
+ ArtifactDefinition,
17
+ IntentResolver,
15
18
  MarkdownState,
16
19
  MarkdownSettings,
17
20
  ReactSurface,
18
- IntentResolver,
19
- AppGraphSerializer,
20
21
  Thread,
21
- ArtifactDefinition,
22
22
  } from './capabilities';
23
23
  import { MarkdownEvents } from './events';
24
24
  import { meta } from './meta';
@@ -2,10 +2,21 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Capabilities, contributes, createResolver, type PluginsContext } from '@dxos/app-framework';
6
- import { ObjectId } from '@dxos/echo-schema';
5
+ import {
6
+ Capabilities,
7
+ CollaborationActions,
8
+ contributes,
9
+ createResolver,
10
+ type PluginsContext,
11
+ } from '@dxos/app-framework';
12
+ import { next as A } from '@dxos/automerge/automerge';
13
+ import { isInstanceOf, ObjectId } from '@dxos/echo-schema';
7
14
  import { DXN, QueueSubspaceTags } from '@dxos/keys';
8
- import { makeRef, create, refFromDXN } from '@dxos/live-object';
15
+ import { makeRef, live, refFromDXN } from '@dxos/live-object';
16
+ import { log } from '@dxos/log';
17
+ import { ClientCapabilities } from '@dxos/plugin-client';
18
+ import { resolveRef } from '@dxos/react-client';
19
+ import { createDocAccessor } from '@dxos/react-client/echo';
9
20
  import { TextType } from '@dxos/schema';
10
21
 
11
22
  import { MarkdownCapabilities } from './capabilities';
@@ -16,9 +27,9 @@ export default (context: PluginsContext) =>
16
27
  createResolver({
17
28
  intent: MarkdownAction.Create,
18
29
  resolve: ({ name, spaceId, content }) => {
19
- const doc = create(DocumentType, {
30
+ const doc = live(DocumentType, {
20
31
  name,
21
- content: makeRef(create(TextType, { content: content ?? '' })),
32
+ content: makeRef(live(TextType, { content: content ?? '' })),
22
33
  assistantChatQueue: refFromDXN(new DXN(DXN.kind.QUEUE, [QueueSubspaceTags.DATA, spaceId, ObjectId.random()])),
23
34
  threads: [],
24
35
  });
@@ -33,4 +44,26 @@ export default (context: PluginsContext) =>
33
44
  state.viewMode[id] = viewMode;
34
45
  },
35
46
  }),
47
+ // TODO(burdon): What is the error boundary for intents? Are errors reported back to caller?
48
+ createResolver({
49
+ intent: CollaborationActions.InsertContent,
50
+ resolve: async ({ spaceId, target: targetRef, object: objectRef, label }) => {
51
+ const client = context.requestCapability(ClientCapabilities.Client);
52
+ const space = client.spaces.get(spaceId);
53
+ const target = await resolveRef(client, targetRef.dxn, space);
54
+ if (target && isInstanceOf(DocumentType, target)) {
55
+ const accessor = createDocAccessor(target, ['content']);
56
+ // TODO(burdon): Should be a cursor that references a selected position.
57
+ const index = 0;
58
+ accessor.handle.change((doc) => {
59
+ // TODO(burdon): Throws error:
60
+ // intent-dispatcher.ts:270 Cannot read properties of undefined (reading 'annotations') (FiberFailure) TypeError: Cannot read properties of undefined (reading 'annotations')
61
+ const ref = `[${label ?? 'Generated content'}]](${objectRef.dxn.toString()})\n`;
62
+ A.splice(doc, accessor.path.slice(), index, 0, ref);
63
+ });
64
+ } else {
65
+ log.warn('target is not a document', { targetRef, objectRef });
66
+ }
67
+ },
68
+ }),
36
69
  ]);
@@ -3,13 +3,13 @@
3
3
  //
4
4
 
5
5
  import { Capabilities, contributes } from '@dxos/app-framework';
6
- import { create } from '@dxos/live-object';
6
+ import { live } from '@dxos/live-object';
7
7
 
8
8
  import { MARKDOWN_PLUGIN } from '../meta';
9
9
  import { type MarkdownSettingsProps, MarkdownSettingsSchema } from '../types';
10
10
 
11
11
  export default () => {
12
- const settings = create<MarkdownSettingsProps>({
12
+ const settings = live<MarkdownSettingsProps>({
13
13
  defaultViewMode: 'preview',
14
14
  toolbar: true,
15
15
  numberedHeadings: true,
@@ -12,7 +12,6 @@ import { type MarkdownPluginState, type MarkdownSettingsProps } from '../types';
12
12
 
13
13
  export default (context: PluginsContext) => {
14
14
  const state = new LocalStorageStore<MarkdownPluginState>(MARKDOWN_PLUGIN, { extensionProviders: [], viewMode: {} });
15
-
16
15
  state.prop({ key: 'viewMode', type: LocalStorageStore.json<{ [key: string]: EditorViewMode }>() });
17
16
 
18
17
  // TODO(wittjosiah): Fold into state.
@@ -27,5 +26,6 @@ export default (context: PluginsContext) => {
27
26
 
28
27
  const setViewMode = (id: string, viewMode: EditorViewMode) => (state.values.viewMode[id] = viewMode);
29
28
 
29
+ // Return object with methods.
30
30
  return contributes(MarkdownCapabilities.State, { state: state.values, editorState, getViewMode, setViewMode });
31
31
  };
@@ -68,6 +68,7 @@ const MarkdownContainer = ({
68
68
  />
69
69
  );
70
70
  } else {
71
+ // TODO(burdon): Normalize with above.
71
72
  return (
72
73
  <MarkdownEditor
73
74
  id={id}
@@ -10,19 +10,14 @@ import React, { useMemo } from 'react';
10
10
  import { IntentPlugin } from '@dxos/app-framework';
11
11
  import { withPluginManager } from '@dxos/app-framework/testing';
12
12
  import { createDocAccessor, createObject } from '@dxos/react-client/echo';
13
- import { Main } from '@dxos/react-ui';
14
- import { AttendableContainer } from '@dxos/react-ui-attention';
15
13
  import { withAttention } from '@dxos/react-ui-attention/testing';
16
- import { editorWithToolbarLayout, automerge, translations as editorTranslations } from '@dxos/react-ui-editor';
17
- import { topbarBlockPaddingStart } from '@dxos/react-ui-theme';
14
+ import { automerge, translations as editorTranslations } from '@dxos/react-ui-editor';
18
15
  import { withLayout, withTheme } from '@dxos/storybook-utils';
19
16
 
20
17
  import { MarkdownEditor, type MarkdownEditorProps } from './MarkdownEditor';
21
18
  import translations from '../translations';
22
19
 
23
- const content = Array.from({ length: 100 })
24
- .map((_, i) => `Line ${i + 1}`)
25
- .join('\n');
20
+ const content = Array.from({ length: 100 }, (_, i) => `Line ${i + 1}`).join('\n');
26
21
 
27
22
  type StoryProps = MarkdownEditorProps & {
28
23
  content?: string;
@@ -32,43 +27,35 @@ type StoryProps = MarkdownEditorProps & {
32
27
  const DefaultStory = ({ content = '# Test', toolbar }: StoryProps) => {
33
28
  const doc = useMemo(() => createObject({ content }), [content]);
34
29
  const extensions = useMemo(() => [automerge(createDocAccessor(doc, ['content']))], [doc]);
35
- return (
36
- <Main.Content
37
- bounce
38
- data-toolbar={toolbar ? 'enabled' : 'disabled'}
39
- classNames={[topbarBlockPaddingStart, editorWithToolbarLayout]}
40
- >
41
- <AttendableContainer id='test'>
42
- <MarkdownEditor id='test' initialValue={doc.content} extensions={extensions} toolbar={toolbar} />
43
- </AttendableContainer>
44
- </Main.Content>
45
- );
46
- };
47
-
48
- export const Default = {
49
- args: {
50
- content,
51
- },
52
- };
53
-
54
- export const WithToolbar = {
55
- args: {
56
- content,
57
- toolbar: true,
58
- },
30
+ return <MarkdownEditor id='test' initialValue={doc.content} extensions={extensions} toolbar={toolbar} />;
59
31
  };
60
32
 
61
33
  const meta: Meta<typeof MarkdownEditor> = {
62
- title: 'plugins/plugin-markdown/EditorMain',
34
+ title: 'plugins/plugin-markdown/MarkdownEditor',
63
35
  component: MarkdownEditor,
64
36
  render: DefaultStory,
65
37
  decorators: [
66
38
  withTheme,
67
- withLayout({ tooltips: true }),
39
+ withLayout({ tooltips: true, fullscreen: true }),
68
40
  withAttention,
69
41
  withPluginManager({ plugins: [IntentPlugin()] }),
70
42
  ],
71
- parameters: { layout: 'fullscreen', translations: [...translations, ...editorTranslations] },
43
+ parameters: {
44
+ translations: [...translations, ...editorTranslations],
45
+ },
72
46
  };
73
47
 
74
48
  export default meta;
49
+
50
+ export const Default = {
51
+ args: {
52
+ content,
53
+ },
54
+ };
55
+
56
+ export const WithToolbar = {
57
+ args: {
58
+ toolbar: true,
59
+ content,
60
+ },
61
+ };
@@ -211,7 +211,7 @@ export const MarkdownEditor = ({
211
211
  );
212
212
 
213
213
  return (
214
- <StackItem.Content toolbar={!!toolbar}>
214
+ <StackItem.Content toolbar={!!toolbar} classNames='is-full min-bs-0'>
215
215
  {toolbar && (
216
216
  <>
217
217
  <EditorToolbar
@@ -0,0 +1,182 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta } from '@storybook/react';
8
+ import React, { type FC, useEffect, useMemo, useState } from 'react';
9
+
10
+ import {
11
+ Capabilities,
12
+ CollaborationActions,
13
+ IntentPlugin,
14
+ SettingsPlugin,
15
+ contributes,
16
+ createIntent,
17
+ useCapability,
18
+ useIntentDispatcher,
19
+ } from '@dxos/app-framework';
20
+ import { withPluginManager } from '@dxos/app-framework/testing';
21
+ import { Message } from '@dxos/artifact';
22
+ import { S, AST, create, type Expando, EchoObject } from '@dxos/echo-schema';
23
+ import { invariant } from '@dxos/invariant';
24
+ import { DXN } from '@dxos/keys';
25
+ import { live, makeRef, refFromDXN } from '@dxos/live-object';
26
+ import { ClientPlugin } from '@dxos/plugin-client';
27
+ import { SpacePlugin } from '@dxos/plugin-space';
28
+ import { StorybookLayoutPlugin } from '@dxos/plugin-storybook-layout';
29
+ import { ThemePlugin } from '@dxos/plugin-theme';
30
+ import { faker } from '@dxos/random';
31
+ import { randomQueueDxn, useQueue, useSpace } from '@dxos/react-client/echo';
32
+ import { IconButton, Toolbar } from '@dxos/react-ui';
33
+ import { command, useTextEditor } from '@dxos/react-ui-editor';
34
+ import { StackItem } from '@dxos/react-ui-stack';
35
+ import { defaultTx } from '@dxos/react-ui-theme';
36
+ import { withLayout } from '@dxos/storybook-utils';
37
+
38
+ import MarkdownContainer from './MarkdownContainer';
39
+ import { MarkdownPlugin } from '../MarkdownPlugin';
40
+ import { MarkdownCapabilities } from '../capabilities';
41
+ import { MARKDOWN_PLUGIN } from '../meta';
42
+ import translations from '../translations';
43
+ import { createDocument, DocumentType, type MarkdownSettingsProps } from '../types';
44
+
45
+ faker.seed(1);
46
+
47
+ const TestItem = S.Struct({
48
+ title: S.String.annotations({
49
+ [AST.TitleAnnotationId]: 'Title',
50
+ [AST.DescriptionAnnotationId]: 'Product title',
51
+ }),
52
+ description: S.String.annotations({
53
+ [AST.TitleAnnotationId]: 'Description',
54
+ [AST.DescriptionAnnotationId]: 'Product description',
55
+ }),
56
+ }).pipe(EchoObject({ typename: 'dxos.org/type/Test', version: '0.1.0' }));
57
+
58
+ const TestChat: FC<{ doc: DocumentType; content: string }> = ({ doc, content }) => {
59
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
60
+ const { parentRef } = useTextEditor({ initialValue: content });
61
+
62
+ const space = useSpace();
63
+ const queueDxn = useMemo(() => space && randomQueueDxn(space.id), [space]);
64
+ const queue = useQueue<Message>(queueDxn);
65
+
66
+ const handleInsert = () => {
67
+ invariant(space);
68
+ invariant(queue);
69
+ queue.append([create(Message, { role: 'assistant', content: [{ type: 'text', text: 'Hello' }] })]);
70
+ const message = queue.items[queue.items.length - 1];
71
+
72
+ // {
73
+ // const ref = refFromDXN(new DXN(DXN.kind.QUEUE, [...queue.dxn.parts, message.id]));
74
+
75
+ // const message = deref(ref);
76
+ // }
77
+
78
+ void dispatch(
79
+ createIntent(CollaborationActions.InsertContent, {
80
+ spaceId: space.id,
81
+ target: makeRef(doc as any as Expando), // TODO(burdon): Comomon base type.
82
+ object: refFromDXN(new DXN(DXN.kind.QUEUE, [...queue.dxn.parts, message.id])),
83
+ label: 'Proposal',
84
+ }),
85
+ );
86
+ };
87
+
88
+ return (
89
+ <StackItem.Content toolbar classNames='w-full'>
90
+ <Toolbar.Root classNames='border-be border-separator'>
91
+ <IconButton icon='ph--plus--regular' disabled={!queue} label='Insert' onClick={handleInsert} />
92
+ </Toolbar.Root>
93
+ <div ref={parentRef} className='p-4' />
94
+ </StackItem.Content>
95
+ );
96
+ };
97
+
98
+ const DefaultStory = ({ document, chat }: { document: string; chat: string }) => {
99
+ const space = useSpace();
100
+ const [doc, setDoc] = useState<DocumentType>();
101
+ const settings = useCapability(Capabilities.SettingsStore).getStore<MarkdownSettingsProps>(MARKDOWN_PLUGIN)!.value;
102
+
103
+ useEffect(() => {
104
+ if (!space) {
105
+ return undefined;
106
+ }
107
+
108
+ const doc = space.db.add(
109
+ createDocument({
110
+ name: 'Test',
111
+
112
+ // Create links.
113
+ content: document.replaceAll(/\[(\w+)\]/g, (_, label) => {
114
+ const obj = space.db.add(live(TestItem, { title: label, description: faker.lorem.paragraph() }));
115
+ const dxn = makeRef(obj).dxn.toString();
116
+ return `[${label}][${dxn}]`;
117
+ }),
118
+ }),
119
+ );
120
+
121
+ setDoc(doc);
122
+ }, [space]);
123
+
124
+ if (!space || !doc) {
125
+ return <></>;
126
+ }
127
+
128
+ return (
129
+ <>
130
+ <MarkdownContainer id={doc.id} object={doc} settings={settings} />
131
+ <TestChat doc={doc} content={chat} />
132
+ </>
133
+ );
134
+ };
135
+
136
+ const meta: Meta<typeof DefaultStory> = {
137
+ title: 'plugins/plugin-markdown/Suggestions',
138
+ render: DefaultStory,
139
+ decorators: [
140
+ withPluginManager({
141
+ plugins: [
142
+ ThemePlugin({ tx: defaultTx }),
143
+ StorybookLayoutPlugin(),
144
+ ClientPlugin({
145
+ types: [DocumentType, TestItem],
146
+ onClientInitialized: async (_, client) => {
147
+ await client.halo.createIdentity();
148
+ },
149
+ }),
150
+ SpacePlugin(),
151
+ SettingsPlugin(),
152
+ IntentPlugin(),
153
+ MarkdownPlugin(),
154
+ ],
155
+ capabilities: [contributes(MarkdownCapabilities.Extensions, [() => command()])],
156
+ }),
157
+ withLayout({ tooltips: true, fullscreen: true, classNames: 'grid grid-cols-2' }),
158
+ ],
159
+ parameters: {
160
+ translations,
161
+ },
162
+ };
163
+
164
+ export default meta;
165
+
166
+ type Story = Meta<typeof DefaultStory>;
167
+
168
+ export const Default: Story = {
169
+ args: {
170
+ chat: 'Hello\n',
171
+ document: [
172
+ '# Test',
173
+ '',
174
+ faker.lorem.paragraph(1),
175
+ '',
176
+ 'This is a [DXOS] story that tests [ECHO] references inside the Markdown plugin.',
177
+ '',
178
+ faker.lorem.paragraph(3),
179
+ '',
180
+ ].join('\n'),
181
+ },
182
+ };
@@ -8,11 +8,12 @@ import { type Meta } from '@storybook/react';
8
8
  import React, { type FC, useState } from 'react';
9
9
 
10
10
  import { PublicKey } from '@dxos/keys';
11
- import { create } from '@dxos/live-object';
11
+ import { live } from '@dxos/live-object';
12
12
  import { faker } from '@dxos/random';
13
13
  import { createDocAccessor, createObject } from '@dxos/react-client/echo';
14
14
  import { useThemeContext } from '@dxos/react-ui';
15
15
  import {
16
+ EditorToolbar,
16
17
  type EditorAction,
17
18
  type Comment,
18
19
  comments,
@@ -23,7 +24,6 @@ import {
23
24
  decorateMarkdown,
24
25
  editorContent,
25
26
  formattingKeymap,
26
- EditorToolbar,
27
27
  translations,
28
28
  useActionHandler,
29
29
  useComments,
@@ -36,11 +36,9 @@ import { withLayout, withTheme } from '@dxos/storybook-utils';
36
36
 
37
37
  faker.seed(101);
38
38
 
39
- const _onUpload = async (file: File) => ({ url: file.name });
40
-
41
39
  const DefaultStory: FC<{ content?: string }> = ({ content = '' }) => {
42
40
  const { themeMode } = useThemeContext();
43
- const [text] = useState(createObject(create(TextType, { content })));
41
+ const [text] = useState(createObject(live(TextType, { content })));
44
42
  const toolbarState = useEditorToolbarState({ viewMode: 'preview' });
45
43
  const formattingObserver = useFormattingState(toolbarState);
46
44
  const { parentRef, view } = useTextEditor(() => {
@@ -79,9 +77,9 @@ const DefaultStory: FC<{ content?: string }> = ({ content = '' }) => {
79
77
  useComments(view, text.id, _comments);
80
78
 
81
79
  return (
82
- <div role='none' className='fixed inset-0 flex flex-col'>
80
+ <div role='none' className='flex flex-col'>
83
81
  <EditorToolbar onAction={handleAction} state={toolbarState ?? {}} />
84
- <div ref={parentRef} />
82
+ <div className='flex grow overflow-hidden' ref={parentRef} />
85
83
  </div>
86
84
  );
87
85
  };
@@ -96,18 +94,20 @@ const content = [
96
94
  '',
97
95
  ].join('\n');
98
96
 
99
- export const Default = {
100
- args: {
101
- content,
102
- },
103
- };
104
-
105
97
  const meta: Meta<typeof EditorToolbar> = {
106
98
  title: 'plugins/plugin-markdown/Toolbar',
107
99
  component: EditorToolbar,
108
100
  render: DefaultStory as any,
109
- decorators: [withTheme, withLayout({ tooltips: true })],
110
- parameters: { translations, layout: 'fullscreen' },
101
+ decorators: [withTheme, withLayout({ tooltips: true, fullscreen: true })],
102
+ parameters: {
103
+ translations,
104
+ },
111
105
  };
112
106
 
113
107
  export default meta;
108
+
109
+ export const Default = {
110
+ args: {
111
+ content,
112
+ },
113
+ };
@@ -29,8 +29,10 @@ import {
29
29
  formattingKeymap,
30
30
  linkTooltip,
31
31
  listener,
32
+ preview,
32
33
  selectionState,
33
34
  typewriter,
35
+ type RenderCallback,
34
36
  } from '@dxos/react-ui-editor';
35
37
  import { defaultTx } from '@dxos/react-ui-theme';
36
38
  import { type TextType } from '@dxos/schema';
@@ -175,7 +177,7 @@ const createBaseExtensions = ({
175
177
  // TODO(wittjosiah): For internal links, consider ignoring the link text and rendering the label of the object being linked to.
176
178
  renderLinkButton:
177
179
  dispatch && (document || id)
178
- ? onRenderLink((id: string) => {
180
+ ? createLinkRenderer((id: string) => {
179
181
  void dispatch(
180
182
  createIntent(LayoutAction.Open, {
181
183
  part: 'main',
@@ -189,6 +191,7 @@ const createBaseExtensions = ({
189
191
  : undefined,
190
192
  }),
191
193
  linkTooltip(renderLinkTooltip),
194
+ preview(),
192
195
  ],
193
196
  );
194
197
  }
@@ -233,40 +236,42 @@ const style = {
233
236
  icon: 'inline-block leading-none mis-1 cursor-pointer',
234
237
  };
235
238
 
236
- const onRenderLink = (onSelectObject: (id: string) => void) => (el: Element, url: string) => {
237
- // TODO(burdon): Formalize/document internal link format.
238
- const isInternal =
239
- url.startsWith('/') ||
240
- // TODO(wittjosiah): This should probably be parsed out on paste?
241
- url.startsWith(window.location.origin);
239
+ const createLinkRenderer =
240
+ (onSelectObject: (id: string) => void): RenderCallback<{ url: string }> =>
241
+ (el, { url }) => {
242
+ // TODO(burdon): Formalize/document internal link format.
243
+ const isInternal =
244
+ url.startsWith('/') ||
245
+ // TODO(wittjosiah): This should probably be parsed out on paste?
246
+ url.startsWith(window.location.origin);
242
247
 
243
- const options: AnchorHTMLAttributes<any> = isInternal
244
- ? {
245
- onClick: () => {
246
- const qualifiedId = url.split('/').at(-1);
247
- invariant(qualifiedId, 'Invalid link format.');
248
- onSelectObject(qualifiedId);
249
- },
250
- }
251
- : {
252
- href: url,
253
- rel: 'noreferrer',
254
- target: '_blank',
255
- };
248
+ const options: AnchorHTMLAttributes<any> = isInternal
249
+ ? {
250
+ onClick: () => {
251
+ const qualifiedId = url.split('/').at(-1);
252
+ invariant(qualifiedId, 'Invalid link format.');
253
+ onSelectObject(qualifiedId);
254
+ },
255
+ }
256
+ : {
257
+ href: url,
258
+ rel: 'noreferrer',
259
+ target: '_blank',
260
+ };
256
261
 
257
- renderRoot(
258
- el,
259
- <a {...options} className={style.hover}>
260
- <Icon
261
- icon={isInternal ? 'ph--arrow-square-down--bold' : 'ph--arrow-square-out--bold'}
262
- size={4}
263
- classNames={style.icon}
264
- />
265
- </a>,
266
- );
267
- };
262
+ renderRoot(
263
+ el,
264
+ <a {...options} className={style.hover}>
265
+ <Icon
266
+ icon={isInternal ? 'ph--arrow-square-down--bold' : 'ph--arrow-square-out--bold'}
267
+ size={4}
268
+ classNames={style.icon}
269
+ />
270
+ </a>,
271
+ );
272
+ };
268
273
 
269
- const renderLinkTooltip = (el: Element, url: string) => {
274
+ const renderLinkTooltip: RenderCallback<{ url: string }> = (el, { url }) => {
270
275
  const web = new URL(url);
271
276
  renderRoot(
272
277
  el,