@prosekit/solid 0.6.7 → 0.6.8

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 (46) hide show
  1. package/dist/{create-component-B7NzEJxP.js → create-component.js} +3 -4
  2. package/dist/create-component.js.map +1 -0
  3. package/dist/{create-props-CFK4CtjG.d.ts → create-props.d.ts} +1 -1
  4. package/dist/create-props.d.ts.map +1 -0
  5. package/dist/{editor-context-CAdqwRwB.js → editor-context.js} +2 -3
  6. package/dist/editor-context.js.map +1 -0
  7. package/dist/prosekit-solid-autocomplete.d.ts +2 -2
  8. package/dist/prosekit-solid-autocomplete.js +2 -6
  9. package/dist/prosekit-solid-autocomplete.js.map +1 -1
  10. package/dist/prosekit-solid-block-handle.d.ts +2 -2
  11. package/dist/prosekit-solid-block-handle.js +2 -5
  12. package/dist/prosekit-solid-block-handle.js.map +1 -1
  13. package/dist/prosekit-solid-drop-indicator.d.ts +2 -2
  14. package/dist/prosekit-solid-drop-indicator.js +2 -3
  15. package/dist/prosekit-solid-drop-indicator.js.map +1 -1
  16. package/dist/prosekit-solid-inline-popover.d.ts +2 -2
  17. package/dist/prosekit-solid-inline-popover.js +2 -3
  18. package/dist/prosekit-solid-inline-popover.js.map +1 -1
  19. package/dist/prosekit-solid-popover.d.ts +2 -2
  20. package/dist/prosekit-solid-popover.js +2 -5
  21. package/dist/prosekit-solid-popover.js.map +1 -1
  22. package/dist/prosekit-solid-resizable.d.ts +2 -2
  23. package/dist/prosekit-solid-resizable.js +2 -4
  24. package/dist/prosekit-solid-resizable.js.map +1 -1
  25. package/dist/prosekit-solid-table-handle.d.ts +2 -2
  26. package/dist/prosekit-solid-table-handle.js +2 -11
  27. package/dist/prosekit-solid-table-handle.js.map +1 -1
  28. package/dist/prosekit-solid-tooltip.d.ts +2 -2
  29. package/dist/prosekit-solid-tooltip.js +2 -5
  30. package/dist/prosekit-solid-tooltip.js.map +1 -1
  31. package/dist/prosekit-solid.d.ts +2 -2
  32. package/dist/prosekit-solid.d.ts.map +1 -1
  33. package/dist/prosekit-solid.js +115 -140
  34. package/dist/prosekit-solid.js.map +1 -1
  35. package/dist/{types-Bx9mKDTJ.d.ts → types.d.ts} +1 -1
  36. package/dist/types.d.ts.map +1 -0
  37. package/package.json +8 -8
  38. package/src/components/prosekit.ts +6 -6
  39. package/src/components/view-renderer.ts +24 -0
  40. package/src/extensions/helpers.ts +4 -0
  41. package/src/extensions/solid-mark-view.ts +29 -49
  42. package/src/extensions/solid-node-view.ts +29 -64
  43. package/dist/create-component-B7NzEJxP.js.map +0 -1
  44. package/dist/create-props-CFK4CtjG.d.ts.map +0 -1
  45. package/dist/editor-context-CAdqwRwB.js.map +0 -1
  46. package/dist/types-Bx9mKDTJ.d.ts.map +0 -1
@@ -1,82 +1,39 @@
1
- import { n as useEditorContext, t as EditorContextProvider } from "./editor-context-CAdqwRwB.js";
2
- import { ProsemirrorAdapterProvider, useMarkViewContext, useMarkViewFactory, useNodeViewContext, useNodeViewFactory } from "@prosemirror-adapter/solid";
1
+ import { n as useEditorContext, t as EditorContextProvider } from "./editor-context.js";
3
2
  import { createComponent, createEffect, createMemo, createSignal, onCleanup } from "solid-js";
4
3
  import { EditorNotFoundError, ProseKitError, defineDocChangeHandler, defineKeymap, defineMarkViewComponent, defineMarkViewFactory, defineMountHandler, defineNodeViewComponent, defineNodeViewFactory, defineUpdateHandler, union, withPriority } from "@prosekit/core";
5
-
6
- //#region src/utils/to-value.ts
7
- /**
8
- * Accesses the value of a MaybeAccessor
9
- *
10
- * @example
11
- * ```ts
12
- * access("foo") // => "foo"
13
- * access(() => "foo") // => "foo"
14
- * ```
15
- */
16
- function toValue(v) {
17
- return typeof v === "function" ? v() : v;
18
- }
19
-
20
- //#endregion
21
- //#region src/hooks/use-editor-extension.ts
22
- /**
23
- * @internal
24
- */
25
- function useEditorExtension(editorAccessor, extensionAccessor) {
26
- const editorContext = useEditorContext();
27
- createEffect(() => {
28
- const editor = toValue(editorAccessor) || toValue(editorContext);
29
- const extension = extensionAccessor();
30
- if (!editor) throw new EditorNotFoundError();
31
- if (extension) onCleanup(editor.use(extension));
32
- });
4
+ import { AbstractSolidMarkView, AbstractSolidNodeView, buildSolidMarkViewCreator, buildSolidNodeViewCreator, useSolidRenderer } from "@prosemirror-adapter/solid";
5
+ import { Portal } from "solid-js/web";
6
+ //#region src/extensions/helpers.ts
7
+ function hidePortalDiv(el) {
8
+ el.style.display = "contents";
9
+ el.dataset.solidPortal = "true";
33
10
  }
34
-
35
- //#endregion
36
- //#region src/hooks/use-priority-extension.ts
37
- /**
38
- * @internal
39
- */
40
- function usePriorityExtension(extension, priority) {
41
- return () => {
42
- const ext = extension();
43
- return ext && priority ? withPriority(ext, priority) : ext;
44
- };
45
- }
46
-
47
- //#endregion
48
- //#region src/hooks/use-extension.ts
49
- /**
50
- * Add an extension to the editor.
51
- */
52
- function useExtension(extension, options) {
53
- useEditorExtension(options?.editor, usePriorityExtension(extension, options?.priority));
54
- }
55
-
56
11
  //#endregion
57
12
  //#region src/extensions/solid-mark-view.ts
58
- function withMarkViewProps(component) {
59
- return function MarkViewPropsWrapper() {
60
- const context = useMarkViewContext();
61
- return createComponent(component, {
62
- get contentRef() {
63
- return context().contentRef;
64
- },
65
- get view() {
66
- return context().view;
67
- },
68
- get mark() {
69
- return context().mark;
70
- }
71
- });
72
- };
73
- }
13
+ var ProseKitSolidMarkView = class extends AbstractSolidMarkView {
14
+ constructor(..._args) {
15
+ super(..._args);
16
+ this.render = () => {
17
+ const UserComponent = this.component;
18
+ const getProps = this.context;
19
+ return createComponent(Portal, {
20
+ mount: this.dom,
21
+ get children() {
22
+ return createComponent(UserComponent, getProps());
23
+ },
24
+ ref: hidePortalDiv
25
+ });
26
+ };
27
+ }
28
+ };
74
29
  /**
75
30
  * @internal
76
31
  */
77
- function consumeSolidMarkViews() {
78
- const markViewFactory = useMarkViewFactory();
79
- useExtension(createMemo(() => defineSolidMarkViewFactory(markViewFactory), [markViewFactory]));
32
+ function defineSolidMarkViewFactory(renderSolidRenderer, removeSolidRenderer) {
33
+ return defineMarkViewFactory({
34
+ group: "solid",
35
+ factory: buildSolidMarkViewCreator(renderSolidRenderer, removeSolidRenderer, ProseKitSolidMarkView)
36
+ });
80
37
  }
81
38
  /**
82
39
  * Defines a mark view using a Solid component.
@@ -84,62 +41,38 @@ function consumeSolidMarkViews() {
84
41
  * @public
85
42
  */
86
43
  function defineSolidMarkView(options) {
87
- const { name, component, ...userOptions } = options;
88
44
  return defineMarkViewComponent({
89
45
  group: "solid",
90
- name,
91
- args: {
92
- ...userOptions,
93
- component: withMarkViewProps(component)
94
- }
46
+ name: options.name,
47
+ args: options
95
48
  });
96
49
  }
97
- function defineSolidMarkViewFactory(factory) {
98
- return defineMarkViewFactory({
99
- group: "solid",
100
- factory
101
- });
102
- }
103
-
104
50
  //#endregion
105
51
  //#region src/extensions/solid-node-view.ts
106
- function withNodeViewProps(component) {
107
- return function NodeViewPropsWrapper() {
108
- const context = useNodeViewContext();
109
- return createComponent(component, {
110
- get contentRef() {
111
- return context().contentRef;
112
- },
113
- get view() {
114
- return context().view;
115
- },
116
- get getPos() {
117
- return context().getPos;
118
- },
119
- get setAttrs() {
120
- return context().setAttrs;
121
- },
122
- get node() {
123
- return context().node;
124
- },
125
- get selected() {
126
- return context().selected;
127
- },
128
- get decorations() {
129
- return context().decorations;
130
- },
131
- get innerDecorations() {
132
- return context().innerDecorations;
133
- }
134
- });
135
- };
136
- }
52
+ var ProseKitSolidNodeView = class extends AbstractSolidNodeView {
53
+ constructor(..._args) {
54
+ super(..._args);
55
+ this.render = () => {
56
+ const UserComponent = this.component;
57
+ const getProps = this.context;
58
+ return createComponent(Portal, {
59
+ mount: this.dom,
60
+ get children() {
61
+ return createComponent(UserComponent, getProps());
62
+ },
63
+ ref: hidePortalDiv
64
+ });
65
+ };
66
+ }
67
+ };
137
68
  /**
138
69
  * @internal
139
70
  */
140
- function consumeSolidNodeViews() {
141
- const nodeViewFactory = useNodeViewFactory();
142
- useExtension(createMemo(() => defineSolidNodeViewFactory(nodeViewFactory), [nodeViewFactory]));
71
+ function defineSolidNodeViewFactory(renderSolidRenderer, removeSolidRenderer) {
72
+ return defineNodeViewFactory({
73
+ group: "solid",
74
+ factory: buildSolidNodeViewCreator(renderSolidRenderer, removeSolidRenderer, ProseKitSolidNodeView)
75
+ });
143
76
  }
144
77
  /**
145
78
  * Defines a node view using a Solid component.
@@ -147,23 +80,48 @@ function consumeSolidNodeViews() {
147
80
  * @public
148
81
  */
149
82
  function defineSolidNodeView(options) {
150
- const { name, component, ...userOptions } = options;
151
83
  return defineNodeViewComponent({
152
84
  group: "solid",
153
- name,
154
- args: {
155
- ...userOptions,
156
- component: withNodeViewProps(component)
157
- }
85
+ name: options.name,
86
+ args: options
158
87
  });
159
88
  }
160
- function defineSolidNodeViewFactory(factory) {
161
- return defineNodeViewFactory({
162
- group: "solid",
163
- factory
89
+ //#endregion
90
+ //#region src/utils/to-value.ts
91
+ /**
92
+ * Accesses the value of a MaybeAccessor
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * access("foo") // => "foo"
97
+ * access(() => "foo") // => "foo"
98
+ * ```
99
+ */
100
+ function toValue(v) {
101
+ return typeof v === "function" ? v() : v;
102
+ }
103
+ //#endregion
104
+ //#region src/hooks/use-editor-extension.ts
105
+ /**
106
+ * @internal
107
+ */
108
+ function useEditorExtension(editorAccessor, extensionAccessor) {
109
+ const editorContext = useEditorContext();
110
+ createEffect(() => {
111
+ const editor = toValue(editorAccessor) || toValue(editorContext);
112
+ const extension = extensionAccessor();
113
+ if (!editor) throw new EditorNotFoundError();
114
+ if (extension) onCleanup(editor.use(extension));
164
115
  });
165
116
  }
166
-
117
+ //#endregion
118
+ //#region src/components/view-renderer.ts
119
+ const ViewRenderer = (props) => {
120
+ const { renderSolidRenderer, removeSolidRenderer, render } = useSolidRenderer();
121
+ const extension = union([defineSolidMarkViewFactory(renderSolidRenderer, removeSolidRenderer), defineSolidNodeViewFactory(renderSolidRenderer, removeSolidRenderer)]);
122
+ useEditorExtension(() => props.editor, () => extension);
123
+ return [props.children, render];
124
+ };
167
125
  //#endregion
168
126
  //#region src/components/prosekit.ts
169
127
  /**
@@ -177,15 +135,36 @@ const ProseKit = (props) => {
177
135
  return props.editor;
178
136
  },
179
137
  get children() {
180
- return createComponent(ProsemirrorAdapterProvider, { get children() {
181
- consumeSolidNodeViews();
182
- consumeSolidMarkViews();
183
- return props.children;
184
- } });
138
+ return createComponent(ViewRenderer, {
139
+ get editor() {
140
+ return props.editor;
141
+ },
142
+ get children() {
143
+ return props.children;
144
+ }
145
+ });
185
146
  }
186
147
  });
187
148
  };
188
-
149
+ //#endregion
150
+ //#region src/hooks/use-priority-extension.ts
151
+ /**
152
+ * @internal
153
+ */
154
+ function usePriorityExtension(extension, priority) {
155
+ return () => {
156
+ const ext = extension();
157
+ return ext && priority ? withPriority(ext, priority) : ext;
158
+ };
159
+ }
160
+ //#endregion
161
+ //#region src/hooks/use-extension.ts
162
+ /**
163
+ * Add an extension to the editor.
164
+ */
165
+ function useExtension(extension, options) {
166
+ useEditorExtension(options?.editor, usePriorityExtension(extension, options?.priority));
167
+ }
189
168
  //#endregion
190
169
  //#region src/hooks/use-doc-change.ts
191
170
  /**
@@ -197,7 +176,6 @@ function useDocChange(handler, options) {
197
176
  const extension = defineDocChangeHandler((view) => handler(view.state.doc));
198
177
  useExtension(() => extension, options);
199
178
  }
200
-
201
179
  //#endregion
202
180
  //#region src/hooks/use-editor.ts
203
181
  /**
@@ -228,7 +206,6 @@ function useEditor(options) {
228
206
  function useForceUpdate() {
229
207
  return createSignal(void 0, { equals: false });
230
208
  }
231
-
232
209
  //#endregion
233
210
  //#region src/hooks/use-editor-derived-value.ts
234
211
  /**
@@ -248,14 +225,12 @@ function useEditorDerivedValue(derive, options) {
248
225
  const editorAccessor = initialEditor ? () => toValue(initialEditor) : useEditor({ update: true });
249
226
  return createMemo(() => derive(editorAccessor()));
250
227
  }
251
-
252
228
  //#endregion
253
229
  //#region src/hooks/use-keymap.ts
254
230
  function useKeymap(keymap, options) {
255
231
  const extension = () => defineKeymap(keymap());
256
232
  useExtension(extension, options);
257
233
  }
258
-
259
234
  //#endregion
260
235
  //#region src/hooks/use-state-update.ts
261
236
  /**
@@ -267,7 +242,7 @@ function useStateUpdate(handler, options) {
267
242
  const extension = defineUpdateHandler((view) => handler(view.state));
268
243
  useExtension(() => extension, options);
269
244
  }
270
-
271
245
  //#endregion
272
246
  export { ProseKit, defineSolidMarkView, defineSolidNodeView, useDocChange, useEditor, useEditorDerivedValue, useExtension, useKeymap, useStateUpdate };
247
+
273
248
  //# sourceMappingURL=prosekit-solid.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-solid.js","names":[],"sources":["../src/utils/to-value.ts","../src/hooks/use-editor-extension.ts","../src/hooks/use-priority-extension.ts","../src/hooks/use-extension.ts","../src/extensions/solid-mark-view.ts","../src/extensions/solid-node-view.ts","../src/components/prosekit.ts","../src/hooks/use-doc-change.ts","../src/hooks/use-editor.ts","../src/hooks/use-editor-derived-value.ts","../src/hooks/use-keymap.ts","../src/hooks/use-state-update.ts"],"sourcesContent":["/**\n * Accesses the value of a MaybeAccessor\n *\n * @example\n * ```ts\n * access(\"foo\") // => \"foo\"\n * access(() => \"foo\") // => \"foo\"\n * ```\n */\nexport function toValue<T>(\n v: (() => T) | T,\n): T {\n return (typeof v === 'function') ? (v as () => T)() : v\n}\n","import { EditorNotFoundError, type Editor, type Extension } from '@prosekit/core'\nimport { createEffect, onCleanup, type Accessor } from 'solid-js'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\nimport type { MaybeAccessor } from '../types.ts'\nimport { toValue } from '../utils/to-value.ts'\n\n/**\n * @internal\n */\nexport function useEditorExtension(\n editorAccessor: MaybeAccessor<Editor> | undefined | null,\n extensionAccessor: Accessor<Extension | null>,\n): void {\n const editorContext = useEditorContext()\n\n createEffect(() => {\n const editor = toValue(editorAccessor) || toValue(editorContext)\n const extension = extensionAccessor()\n\n if (!editor) {\n throw new EditorNotFoundError()\n }\n if (extension) {\n onCleanup(editor.use(extension))\n }\n })\n}\n","import { withPriority, type Extension, type Priority } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function usePriorityExtension<T extends Extension = Extension>(\n extension: () => T | null,\n priority?: Priority | null,\n): () => T | null {\n return () => {\n const ext = extension()\n return ext && priority ? withPriority(ext, priority) : ext\n }\n}\n","import type { Editor, Extension, Priority } from '@prosekit/core'\nimport type { Accessor } from 'solid-js'\n\nimport type { MaybeAccessor } from '../types.ts'\n\nimport { useEditorExtension } from './use-editor-extension.ts'\nimport { usePriorityExtension } from './use-priority-extension.ts'\n\nexport interface UseExtensionOptions {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: MaybeAccessor<Editor>\n\n /**\n * Optional priority to add the extension with.\n */\n priority?: Priority\n}\n\n/**\n * Add an extension to the editor.\n */\nexport function useExtension(\n /**\n * The accessor to an extension to add to the editor. If it changes, the previous\n * extension will be removed and the new one (if not null) will be added.\n */\n extension: Accessor<Extension | null>,\n options?: UseExtensionOptions,\n): void {\n useEditorExtension(\n options?.editor,\n usePriorityExtension(extension, options?.priority),\n )\n}\n","import { defineMarkViewComponent, defineMarkViewFactory, type Extension } from '@prosekit/core'\nimport type { MarkViewConstructor } from '@prosekit/pm/view'\nimport type { CoreMarkViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n useMarkViewContext,\n useMarkViewFactory,\n type MarkViewContextProps,\n type SolidMarkViewUserOptions,\n} from '@prosemirror-adapter/solid'\nimport { createComponent, createMemo, type Accessor, type Component } from 'solid-js'\n\nimport { useExtension } from '../hooks/use-extension.ts'\n\n/**\n * @public\n */\nexport interface SolidMarkViewProps extends MarkViewContextProps {}\n\n/**\n * @public\n */\nexport type SolidMarkViewComponent = Component<SolidMarkViewProps>\n\n/**\n * Options for {@link defineSolidMarkView}.\n *\n * @public\n */\nexport interface SolidMarkViewOptions extends CoreMarkViewUserOptions<SolidMarkViewComponent> {\n /**\n * The name of the mark type.\n */\n name: string\n}\n\nfunction withMarkViewProps(\n component: SolidMarkViewComponent,\n): Component<SolidMarkViewProps> {\n return function MarkViewPropsWrapper() {\n const context: Accessor<SolidMarkViewProps> = useMarkViewContext()\n const props: SolidMarkViewProps = {\n get contentRef() {\n return context().contentRef\n },\n get view() {\n return context().view\n },\n get mark() {\n return context().mark\n },\n }\n return createComponent(component, props)\n }\n}\n\n/**\n * @internal\n */\nexport function consumeSolidMarkViews(): void {\n const markViewFactory = useMarkViewFactory()\n const extension = createMemo(\n () => defineSolidMarkViewFactory(markViewFactory),\n [markViewFactory],\n )\n\n useExtension(extension)\n}\n\n/**\n * Defines a mark view using a Solid component.\n *\n * @public\n */\nexport function defineSolidMarkView(options: SolidMarkViewOptions): Extension {\n const { name, component, ...userOptions } = options\n\n const args: SolidMarkViewUserOptions = {\n ...userOptions,\n component: withMarkViewProps(component),\n }\n\n return defineMarkViewComponent<SolidMarkViewUserOptions>({\n group: 'solid',\n name,\n args,\n })\n}\n\nfunction defineSolidMarkViewFactory(\n factory: (options: SolidMarkViewOptions) => MarkViewConstructor,\n) {\n return defineMarkViewFactory<SolidMarkViewOptions>({\n group: 'solid',\n factory,\n })\n}\n","import { defineNodeViewComponent, defineNodeViewFactory, type Extension } from '@prosekit/core'\nimport type { NodeViewConstructor } from '@prosekit/pm/view'\nimport type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n useNodeViewContext,\n useNodeViewFactory,\n type NodeViewContextProps,\n type SolidNodeViewUserOptions,\n} from '@prosemirror-adapter/solid'\nimport { createComponent, createMemo, type Accessor, type Component } from 'solid-js'\n\nimport { useExtension } from '../hooks/use-extension.ts'\n\n/**\n * @public\n */\nexport interface SolidNodeViewProps extends NodeViewContextProps {}\n\n/**\n * @public\n */\nexport type SolidNodeViewComponent = Component<SolidNodeViewProps>\n\n/**\n * Options for {@link defineSolidNodeView}.\n *\n * @public\n */\nexport interface SolidNodeViewOptions extends CoreNodeViewUserOptions<SolidNodeViewComponent> {\n /**\n * The name of the node type.\n */\n name: string\n}\n\nfunction withNodeViewProps(\n component: SolidNodeViewComponent,\n): Component<SolidNodeViewProps> {\n return function NodeViewPropsWrapper() {\n const context: Accessor<SolidNodeViewProps> = useNodeViewContext()\n const props: SolidNodeViewProps = {\n get contentRef() {\n return context().contentRef\n },\n get view() {\n return context().view\n },\n get getPos() {\n return context().getPos\n },\n get setAttrs() {\n return context().setAttrs\n },\n get node() {\n return context().node\n },\n get selected() {\n return context().selected\n },\n get decorations() {\n return context().decorations\n },\n get innerDecorations() {\n return context().innerDecorations\n },\n }\n return createComponent(component, props)\n }\n}\n\n/**\n * @internal\n */\nexport function consumeSolidNodeViews(): void {\n const nodeViewFactory = useNodeViewFactory()\n const extension = createMemo(\n () => defineSolidNodeViewFactory(nodeViewFactory),\n [nodeViewFactory],\n )\n\n useExtension(extension)\n}\n\n/**\n * Defines a node view using a Solid component.\n *\n * @public\n */\nexport function defineSolidNodeView(options: SolidNodeViewOptions): Extension {\n const { name, component, ...userOptions } = options\n\n const args: SolidNodeViewUserOptions = {\n ...userOptions,\n component: withNodeViewProps(component),\n }\n\n return defineNodeViewComponent<SolidNodeViewUserOptions>({\n group: 'solid',\n name,\n args,\n })\n}\n\nfunction defineSolidNodeViewFactory(\n factory: (options: SolidNodeViewOptions) => NodeViewConstructor,\n) {\n return defineNodeViewFactory<SolidNodeViewOptions>({\n group: 'solid',\n factory,\n })\n}\n","import type { Editor } from '@prosekit/core'\nimport { ProsemirrorAdapterProvider } from '@prosemirror-adapter/solid'\nimport { createComponent, type Component, type ParentProps } from 'solid-js'\n\nimport { EditorContextProvider } from '../contexts/editor-context.ts'\nimport { consumeSolidMarkViews } from '../extensions/solid-mark-view.ts'\nimport { consumeSolidNodeViews } from '../extensions/solid-node-view.ts'\n\nexport type ProseKitProps = ParentProps<{\n editor: Editor\n}>\n\n/**\n * The root component for a ProseKit editor.\n *\n * @public\n */\nexport const ProseKit: Component<ProseKitProps> = (props) => {\n return createComponent(EditorContextProvider, {\n get value() {\n return props.editor\n },\n get children() {\n return createComponent(ProsemirrorAdapterProvider, {\n get children() {\n consumeSolidNodeViews()\n consumeSolidMarkViews()\n return props.children\n },\n })\n },\n })\n}\n","import { defineDocChangeHandler } from '@prosekit/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\n/**\n * Calls the given handler whenever the editor document changes.\n *\n * @public\n */\nexport function useDocChange(\n handler: (doc: ProseMirrorNode) => void,\n options?: UseExtensionOptions,\n): void {\n const extension = defineDocChangeHandler((view) => handler(view.state.doc))\n useExtension(() => extension, options)\n}\n","import { defineMountHandler, defineUpdateHandler, ProseKitError, union, type Editor, type Extension } from '@prosekit/core'\nimport { createEffect, createSignal } from 'solid-js'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\n\n/**\n * Retrieves the editor instance from the nearest ProseKit component.\n *\n * @public\n */\nexport function useEditor<E extends Extension = any>(options?: {\n /**\n * Whether to update the component when the editor is mounted or editor state\n * is updated.\n *\n * @default false\n */\n update?: boolean\n}): () => Editor<E> {\n const update = options?.update ?? false\n\n const editor = useEditorContext<E>()\n if (!editor) {\n throw new ProseKitError(\n 'useEditor must be used within the ProseKit component',\n )\n }\n\n const [depend, forceUpdate] = useForceUpdate()\n\n createEffect(() => {\n if (update) {\n const extension = union(\n defineMountHandler(forceUpdate),\n defineUpdateHandler(forceUpdate),\n )\n return editor.use(extension)\n }\n }, [editor, update, forceUpdate])\n\n return () => {\n depend()\n return editor\n }\n}\n\nfunction useForceUpdate() {\n return createSignal(undefined, { equals: false })\n}\n","import type { Editor, Extension } from '@prosekit/core'\nimport { createMemo, type Accessor } from 'solid-js'\n\nimport type { MaybeAccessor } from '../types.ts'\nimport { toValue } from '../utils/to-value.ts'\n\nimport { useEditor } from './use-editor.ts'\n\nexport interface UseEditorDerivedOptions<E extends Extension = any> {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: MaybeAccessor<Editor<E>>\n}\n\n/**\n * Runs a function to derive a value from the editor instance after editor state\n * changes.\n *\n * This is useful when you need to render something based on the editor state,\n * for example, whether the selected text is wrapped in an italic mark.\n *\n * It returns an accessor of the derived value that updates whenever the editor\n * state changes.\n *\n * @public\n */\nexport function useEditorDerivedValue<E extends Extension, Derived>(\n /**\n * A function that receives the editor instance and returns a derived value.\n *\n * It will be called whenever the editor's document state changes, or when it\n * mounts.\n */\n derive: (editor: Editor<E>) => Derived,\n options?: UseEditorDerivedOptions<E>,\n): Accessor<Derived> {\n const initialEditor = options?.editor\n const editorAccessor: Accessor<Editor<E>> = initialEditor\n ? () => toValue(initialEditor)\n : useEditor<E>({ update: true })\n\n return createMemo(() => derive(editorAccessor()))\n}\n","import { defineKeymap, type Keymap } from '@prosekit/core'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\nexport function useKeymap(keymap: () => Keymap, options?: UseExtensionOptions): void {\n const extension = () => defineKeymap(keymap())\n useExtension(extension, options)\n}\n","import { defineUpdateHandler } from '@prosekit/core'\nimport type { EditorState } from '@prosekit/pm/state'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\n/**\n * Calls the given handler whenever the editor state changes.\n *\n * @public\n */\nexport function useStateUpdate(\n handler: (state: EditorState) => void,\n options?: UseExtensionOptions,\n): void {\n const extension = defineUpdateHandler((view) => handler(view.state))\n useExtension(() => extension, options)\n}\n"],"mappings":";;;;;;;;;;;;;;;AASA,SAAgB,QACd,GACG;AACH,QAAQ,OAAO,MAAM,aAAe,GAAe,GAAG;;;;;;;;ACFxD,SAAgB,mBACd,gBACA,mBACM;CACN,MAAM,gBAAgB,kBAAkB;AAExC,oBAAmB;EACjB,MAAM,SAAS,QAAQ,eAAe,IAAI,QAAQ,cAAc;EAChE,MAAM,YAAY,mBAAmB;AAErC,MAAI,CAAC,OACH,OAAM,IAAI,qBAAqB;AAEj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U;;IAE7B;EAAC;EAAQ;EAAQ;EAAY,CAAC;AAEjC,cAAa;AACX,UAAQ;AACR,SAAO;;;AAIX,SAAS,iBAAiB;AACxB,QAAO,aAAa,QAAW,EAAE,QAAQ,OAAO,CAAC;;;;;;;;;;;;;;;;;ACnBnD,SAAgB,sBAOd,QACA,SACmB;CACnB,MAAM,gBAAgB,SAAS;CAC/B,MAAM,iBAAsC,sBAClC,QAAQ,cAAc,GAC5B,UAAa,EAAE,QAAQ,MAAM,CAAC;AAElC,QAAO,iBAAiB,OAAO,gBAAgB,CAAC,CAAC;;;;;ACvCnD,SAAgB,UAAU,QAAsB,SAAqC;CACnF,MAAM,kBAAkB,aAAa,QAAQ,CAAC;AAC9C,cAAa,WAAW,QAAQ;;;;;;;;;;ACIlC,SAAgB,eACd,SACA,SACM;CACN,MAAM,YAAY,qBAAqB,SAAS,QAAQ,KAAK,MAAM,CAAC;AACpE,oBAAmB,WAAW,QAAQ"}
1
+ {"version":3,"file":"prosekit-solid.js","names":[],"sources":["../src/extensions/helpers.ts","../src/extensions/solid-mark-view.ts","../src/extensions/solid-node-view.ts","../src/utils/to-value.ts","../src/hooks/use-editor-extension.ts","../src/components/view-renderer.ts","../src/components/prosekit.ts","../src/hooks/use-priority-extension.ts","../src/hooks/use-extension.ts","../src/hooks/use-doc-change.ts","../src/hooks/use-editor.ts","../src/hooks/use-editor-derived-value.ts","../src/hooks/use-keymap.ts","../src/hooks/use-state-update.ts"],"sourcesContent":["export function hidePortalDiv(el: HTMLElement): void {\n el.style.display = 'contents'\n el.dataset.solidPortal = 'true'\n}\n","import { defineMarkViewComponent, defineMarkViewFactory, type Extension } from '@prosekit/core'\nimport type { CoreMarkViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n AbstractSolidMarkView,\n buildSolidMarkViewCreator,\n type MarkViewContextProps,\n type SolidRendererResult,\n} from '@prosemirror-adapter/solid'\nimport { createComponent, type Component, type JSX } from 'solid-js'\nimport { Portal } from 'solid-js/web'\n\nimport { hidePortalDiv } from './helpers.ts'\n\n/**\n * @public\n */\nexport interface SolidMarkViewProps extends MarkViewContextProps {}\n\n/**\n * @public\n */\nexport type SolidMarkViewComponent = Component<SolidMarkViewProps>\n\n/**\n * Options for {@link defineSolidMarkView}.\n *\n * @public\n */\nexport interface SolidMarkViewOptions extends CoreMarkViewUserOptions<SolidMarkViewComponent> {\n /**\n * The name of the mark type.\n */\n name: string\n}\n\nclass ProseKitSolidMarkView extends AbstractSolidMarkView<SolidMarkViewComponent> {\n render = (): JSX.Element => {\n const UserComponent = this.component\n const getProps = this.context\n return createComponent(Portal, {\n mount: this.dom,\n get children() {\n const props: MarkViewContextProps = getProps()\n return createComponent(UserComponent, props)\n },\n ref: hidePortalDiv,\n })\n }\n}\n\n/**\n * @internal\n */\nexport function defineSolidMarkViewFactory(\n renderSolidRenderer: SolidRendererResult['renderSolidRenderer'],\n removeSolidRenderer: SolidRendererResult['removeSolidRenderer'],\n): Extension {\n const factory = buildSolidMarkViewCreator(renderSolidRenderer, removeSolidRenderer, ProseKitSolidMarkView)\n return defineMarkViewFactory<SolidMarkViewOptions>({\n group: 'solid',\n factory,\n })\n}\n\n/**\n * Defines a mark view using a Solid component.\n *\n * @public\n */\nexport function defineSolidMarkView(options: SolidMarkViewOptions): Extension {\n return defineMarkViewComponent<SolidMarkViewOptions>({\n group: 'solid',\n name: options.name,\n args: options,\n })\n}\n","import { defineNodeViewComponent, defineNodeViewFactory, type Extension } from '@prosekit/core'\nimport type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n AbstractSolidNodeView,\n buildSolidNodeViewCreator,\n type NodeViewContextProps,\n type SolidRendererResult,\n} from '@prosemirror-adapter/solid'\nimport { createComponent, type Component, type JSX } from 'solid-js'\nimport { Portal } from 'solid-js/web'\n\nimport { hidePortalDiv } from './helpers.ts'\n\n/**\n * @public\n */\nexport interface SolidNodeViewProps extends NodeViewContextProps {}\n\n/**\n * @public\n */\nexport type SolidNodeViewComponent = Component<SolidNodeViewProps>\n\n/**\n * Options for {@link defineSolidNodeView}.\n *\n * @public\n */\nexport interface SolidNodeViewOptions extends CoreNodeViewUserOptions<SolidNodeViewComponent> {\n /**\n * The name of the node type.\n */\n name: string\n}\n\nclass ProseKitSolidNodeView extends AbstractSolidNodeView<SolidNodeViewComponent> {\n render = (): JSX.Element => {\n const UserComponent = this.component\n const getProps = this.context\n return createComponent(Portal, {\n mount: this.dom,\n get children() {\n const props: SolidNodeViewProps = getProps()\n return createComponent(UserComponent, props)\n },\n ref: hidePortalDiv,\n })\n }\n}\n\n/**\n * @internal\n */\nexport function defineSolidNodeViewFactory(\n renderSolidRenderer: SolidRendererResult['renderSolidRenderer'],\n removeSolidRenderer: SolidRendererResult['removeSolidRenderer'],\n): Extension {\n const factory = buildSolidNodeViewCreator(renderSolidRenderer, removeSolidRenderer, ProseKitSolidNodeView)\n return defineNodeViewFactory<SolidNodeViewOptions>({\n group: 'solid',\n factory,\n })\n}\n\n/**\n * Defines a node view using a Solid component.\n *\n * @public\n */\nexport function defineSolidNodeView(options: SolidNodeViewOptions): Extension {\n return defineNodeViewComponent<SolidNodeViewOptions>({\n group: 'solid',\n name: options.name,\n args: options,\n })\n}\n","/**\n * Accesses the value of a MaybeAccessor\n *\n * @example\n * ```ts\n * access(\"foo\") // => \"foo\"\n * access(() => \"foo\") // => \"foo\"\n * ```\n */\nexport function toValue<T>(\n v: (() => T) | T,\n): T {\n return (typeof v === 'function') ? (v as () => T)() : v\n}\n","import { EditorNotFoundError, type Editor, type Extension } from '@prosekit/core'\nimport { createEffect, onCleanup, type Accessor } from 'solid-js'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\nimport type { MaybeAccessor } from '../types.ts'\nimport { toValue } from '../utils/to-value.ts'\n\n/**\n * @internal\n */\nexport function useEditorExtension(\n editorAccessor: MaybeAccessor<Editor> | undefined | null,\n extensionAccessor: Accessor<Extension | null>,\n): void {\n const editorContext = useEditorContext()\n\n createEffect(() => {\n const editor = toValue(editorAccessor) || toValue(editorContext)\n const extension = extensionAccessor()\n\n if (!editor) {\n throw new EditorNotFoundError()\n }\n if (extension) {\n onCleanup(editor.use(extension))\n }\n })\n}\n","import { union, type Editor } from '@prosekit/core'\nimport { useSolidRenderer } from '@prosemirror-adapter/solid'\nimport type { Component, JSX, ParentProps } from 'solid-js'\n\nimport { defineSolidMarkViewFactory } from '../extensions/solid-mark-view.ts'\nimport { defineSolidNodeViewFactory } from '../extensions/solid-node-view.ts'\nimport { useEditorExtension } from '../hooks/use-editor-extension.ts'\n\ntype ViewRendererProps = ParentProps<{\n editor: Editor\n}>\n\nexport const ViewRenderer: Component<ViewRendererProps> = (props): JSX.Element => {\n const { renderSolidRenderer, removeSolidRenderer, render } = useSolidRenderer()\n\n const extension = union([\n defineSolidMarkViewFactory(renderSolidRenderer, removeSolidRenderer),\n defineSolidNodeViewFactory(renderSolidRenderer, removeSolidRenderer),\n ])\n\n useEditorExtension(() => props.editor, () => extension)\n\n return [props.children, render] as unknown as JSX.Element\n}\n","import type { Editor } from '@prosekit/core'\nimport { createComponent, type Component, type ParentProps } from 'solid-js'\n\nimport { EditorContextProvider } from '../contexts/editor-context.ts'\n\nimport { ViewRenderer } from './view-renderer.ts'\n\nexport type ProseKitProps = ParentProps<{\n editor: Editor\n}>\n\n/**\n * The root component for a ProseKit editor.\n *\n * @public\n */\nexport const ProseKit: Component<ProseKitProps> = (props) => {\n return createComponent(EditorContextProvider, {\n get value() {\n return props.editor\n },\n get children() {\n return createComponent(ViewRenderer, {\n get editor() {\n return props.editor\n },\n get children() {\n return props.children\n },\n })\n },\n })\n}\n","import { withPriority, type Extension, type Priority } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function usePriorityExtension<T extends Extension = Extension>(\n extension: () => T | null,\n priority?: Priority | null,\n): () => T | null {\n return () => {\n const ext = extension()\n return ext && priority ? withPriority(ext, priority) : ext\n }\n}\n","import type { Editor, Extension, Priority } from '@prosekit/core'\nimport type { Accessor } from 'solid-js'\n\nimport type { MaybeAccessor } from '../types.ts'\n\nimport { useEditorExtension } from './use-editor-extension.ts'\nimport { usePriorityExtension } from './use-priority-extension.ts'\n\nexport interface UseExtensionOptions {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: MaybeAccessor<Editor>\n\n /**\n * Optional priority to add the extension with.\n */\n priority?: Priority\n}\n\n/**\n * Add an extension to the editor.\n */\nexport function useExtension(\n /**\n * The accessor to an extension to add to the editor. If it changes, the previous\n * extension will be removed and the new one (if not null) will be added.\n */\n extension: Accessor<Extension | null>,\n options?: UseExtensionOptions,\n): void {\n useEditorExtension(\n options?.editor,\n usePriorityExtension(extension, options?.priority),\n )\n}\n","import { defineDocChangeHandler } from '@prosekit/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\n/**\n * Calls the given handler whenever the editor document changes.\n *\n * @public\n */\nexport function useDocChange(\n handler: (doc: ProseMirrorNode) => void,\n options?: UseExtensionOptions,\n): void {\n const extension = defineDocChangeHandler((view) => handler(view.state.doc))\n useExtension(() => extension, options)\n}\n","import { defineMountHandler, defineUpdateHandler, ProseKitError, union, type Editor, type Extension } from '@prosekit/core'\nimport { createEffect, createSignal } from 'solid-js'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\n\n/**\n * Retrieves the editor instance from the nearest ProseKit component.\n *\n * @public\n */\nexport function useEditor<E extends Extension = any>(options?: {\n /**\n * Whether to update the component when the editor is mounted or editor state\n * is updated.\n *\n * @default false\n */\n update?: boolean\n}): () => Editor<E> {\n const update = options?.update ?? false\n\n const editor = useEditorContext<E>()\n if (!editor) {\n throw new ProseKitError(\n 'useEditor must be used within the ProseKit component',\n )\n }\n\n const [depend, forceUpdate] = useForceUpdate()\n\n createEffect(() => {\n if (update) {\n const extension = union(\n defineMountHandler(forceUpdate),\n defineUpdateHandler(forceUpdate),\n )\n return editor.use(extension)\n }\n }, [editor, update, forceUpdate])\n\n return () => {\n depend()\n return editor\n }\n}\n\nfunction useForceUpdate() {\n return createSignal(undefined, { equals: false })\n}\n","import type { Editor, Extension } from '@prosekit/core'\nimport { createMemo, type Accessor } from 'solid-js'\n\nimport type { MaybeAccessor } from '../types.ts'\nimport { toValue } from '../utils/to-value.ts'\n\nimport { useEditor } from './use-editor.ts'\n\nexport interface UseEditorDerivedOptions<E extends Extension = any> {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: MaybeAccessor<Editor<E>>\n}\n\n/**\n * Runs a function to derive a value from the editor instance after editor state\n * changes.\n *\n * This is useful when you need to render something based on the editor state,\n * for example, whether the selected text is wrapped in an italic mark.\n *\n * It returns an accessor of the derived value that updates whenever the editor\n * state changes.\n *\n * @public\n */\nexport function useEditorDerivedValue<E extends Extension, Derived>(\n /**\n * A function that receives the editor instance and returns a derived value.\n *\n * It will be called whenever the editor's document state changes, or when it\n * mounts.\n */\n derive: (editor: Editor<E>) => Derived,\n options?: UseEditorDerivedOptions<E>,\n): Accessor<Derived> {\n const initialEditor = options?.editor\n const editorAccessor: Accessor<Editor<E>> = initialEditor\n ? () => toValue(initialEditor)\n : useEditor<E>({ update: true })\n\n return createMemo(() => derive(editorAccessor()))\n}\n","import { defineKeymap, type Keymap } from '@prosekit/core'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\nexport function useKeymap(keymap: () => Keymap, options?: UseExtensionOptions): void {\n const extension = () => defineKeymap(keymap())\n useExtension(extension, options)\n}\n","import { defineUpdateHandler } from '@prosekit/core'\nimport type { EditorState } from '@prosekit/pm/state'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\n/**\n * Calls the given handler whenever the editor state changes.\n *\n * @public\n */\nexport function useStateUpdate(\n handler: (state: EditorState) => void,\n options?: UseExtensionOptions,\n): void {\n const extension = defineUpdateHandler((view) => handler(view.state))\n useExtension(() => extension, options)\n}\n"],"mappings":";;;;;;AAAA,SAAgB,cAA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AO,OAAO,IAAI,UAAU;;IAE7B;EAAC;EAAQ;EAAQ;EAAY,CAAC;AAEjC,cAAa;AACX,UAAQ;AACR,SAAO;;;AAIX,SAAS,iBAAiB;AACxB,QAAO,aAAa,KAAA,GAAW,EAAE,QAAQ,OAAO,CAAC;;;;;;;;;;;;;;;;ACnBnD,SAAgB,sBAOd,QACA,SACmB;CACnB,MAAM,gBAAgB,SAAS;CAC/B,MAAM,iBAAsC,sBAClC,QAAQ,cAAc,GAC5B,UAAa,EAAE,QAAQ,MAAM,CAAC;AAElC,QAAO,iBAAiB,OAAO,gBAAgB,CAAC,CAAC;;;;ACvCnD,SAAgB,UAAU,QAAsB,SAAqC;CACnF,MAAM,kBAAkB,aAAa,QAAQ,CAAC;AAC9C,cAAa,WAAW,QAAQ;;;;;;;;;ACIlC,SAAgB,eACd,SACA,SACM;CACN,MAAM,YAAY,qBAAqB,SAAS,QAAQ,KAAK,MAAM,CAAC;AACpE,oBAAmB,WAAW,QAAQ"}
@@ -23,4 +23,4 @@ type PropsWithElement<Props extends object, CustomElement extends HTMLElement> =
23
23
  type MaybeAccessor<T> = T | Accessor<T>;
24
24
  //#endregion
25
25
  export { PropsWithElement as i, PropsWithChildren as n, PropsWithClass as r, MaybeAccessor as t };
26
- //# sourceMappingURL=types-Bx9mKDTJ.d.ts.map
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;AAKA;KAAY,cAAA,gBAA8B,CAAA;EACxC,KAAA;AAAA;;;;KAMU,iBAAA,gBAAiC,CAAA;EAC3C,QAAA,GAAW,UAAA;AAAA;;;;KAMD,gBAAA,6CAA6D,WAAA,IAAe,KAAA,GAAQ,GAAA,CAAI,cAAA,CAAe,aAAA;;;;KAKvG,aAAA,MAAmB,CAAA,GAAI,QAAA,CAAS,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/solid",
3
3
  "type": "module",
4
- "version": "0.6.7",
4
+ "version": "0.6.8",
5
5
  "private": false,
6
6
  "description": "Solid components and utilities for ProseKit",
7
7
  "author": {
@@ -68,11 +68,11 @@
68
68
  "src"
69
69
  ],
70
70
  "dependencies": {
71
- "@prosemirror-adapter/core": "^0.4.6",
72
- "@prosemirror-adapter/solid": "^0.4.6",
73
- "@prosekit/core": "^0.10.0",
74
- "@prosekit/web": "^0.7.12",
75
- "@prosekit/pm": "^0.1.15"
71
+ "@prosemirror-adapter/core": "^0.5.2",
72
+ "@prosemirror-adapter/solid": "^0.5.2",
73
+ "@prosekit/core": "^0.11.0",
74
+ "@prosekit/pm": "^0.1.15",
75
+ "@prosekit/web": "^0.7.13"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "solid-js": ">= 1.7.0"
@@ -84,10 +84,10 @@
84
84
  },
85
85
  "devDependencies": {
86
86
  "solid-js": "^1.9.11",
87
- "tsdown": "^0.20.3",
87
+ "tsdown": "^0.21.4",
88
88
  "typescript": "~5.9.3",
89
- "@prosekit/config-vitest": "0.0.0",
90
89
  "@prosekit/config-ts": "0.0.0",
90
+ "@prosekit/config-vitest": "0.0.0",
91
91
  "@prosekit/config-tsdown": "0.0.0"
92
92
  },
93
93
  "publishConfig": {
@@ -1,10 +1,9 @@
1
1
  import type { Editor } from '@prosekit/core'
2
- import { ProsemirrorAdapterProvider } from '@prosemirror-adapter/solid'
3
2
  import { createComponent, type Component, type ParentProps } from 'solid-js'
4
3
 
5
4
  import { EditorContextProvider } from '../contexts/editor-context.ts'
6
- import { consumeSolidMarkViews } from '../extensions/solid-mark-view.ts'
7
- import { consumeSolidNodeViews } from '../extensions/solid-node-view.ts'
5
+
6
+ import { ViewRenderer } from './view-renderer.ts'
8
7
 
9
8
  export type ProseKitProps = ParentProps<{
10
9
  editor: Editor
@@ -21,10 +20,11 @@ export const ProseKit: Component<ProseKitProps> = (props) => {
21
20
  return props.editor
22
21
  },
23
22
  get children() {
24
- return createComponent(ProsemirrorAdapterProvider, {
23
+ return createComponent(ViewRenderer, {
24
+ get editor() {
25
+ return props.editor
26
+ },
25
27
  get children() {
26
- consumeSolidNodeViews()
27
- consumeSolidMarkViews()
28
28
  return props.children
29
29
  },
30
30
  })
@@ -0,0 +1,24 @@
1
+ import { union, type Editor } from '@prosekit/core'
2
+ import { useSolidRenderer } from '@prosemirror-adapter/solid'
3
+ import type { Component, JSX, ParentProps } from 'solid-js'
4
+
5
+ import { defineSolidMarkViewFactory } from '../extensions/solid-mark-view.ts'
6
+ import { defineSolidNodeViewFactory } from '../extensions/solid-node-view.ts'
7
+ import { useEditorExtension } from '../hooks/use-editor-extension.ts'
8
+
9
+ type ViewRendererProps = ParentProps<{
10
+ editor: Editor
11
+ }>
12
+
13
+ export const ViewRenderer: Component<ViewRendererProps> = (props): JSX.Element => {
14
+ const { renderSolidRenderer, removeSolidRenderer, render } = useSolidRenderer()
15
+
16
+ const extension = union([
17
+ defineSolidMarkViewFactory(renderSolidRenderer, removeSolidRenderer),
18
+ defineSolidNodeViewFactory(renderSolidRenderer, removeSolidRenderer),
19
+ ])
20
+
21
+ useEditorExtension(() => props.editor, () => extension)
22
+
23
+ return [props.children, render] as unknown as JSX.Element
24
+ }
@@ -0,0 +1,4 @@
1
+ export function hidePortalDiv(el: HTMLElement): void {
2
+ el.style.display = 'contents'
3
+ el.dataset.solidPortal = 'true'
4
+ }
@@ -1,15 +1,15 @@
1
1
  import { defineMarkViewComponent, defineMarkViewFactory, type Extension } from '@prosekit/core'
2
- import type { MarkViewConstructor } from '@prosekit/pm/view'
3
2
  import type { CoreMarkViewUserOptions } from '@prosemirror-adapter/core'
4
3
  import {
5
- useMarkViewContext,
6
- useMarkViewFactory,
4
+ AbstractSolidMarkView,
5
+ buildSolidMarkViewCreator,
7
6
  type MarkViewContextProps,
8
- type SolidMarkViewUserOptions,
7
+ type SolidRendererResult,
9
8
  } from '@prosemirror-adapter/solid'
10
- import { createComponent, createMemo, type Accessor, type Component } from 'solid-js'
9
+ import { createComponent, type Component, type JSX } from 'solid-js'
10
+ import { Portal } from 'solid-js/web'
11
11
 
12
- import { useExtension } from '../hooks/use-extension.ts'
12
+ import { hidePortalDiv } from './helpers.ts'
13
13
 
14
14
  /**
15
15
  * @public
@@ -33,37 +33,33 @@ export interface SolidMarkViewOptions extends CoreMarkViewUserOptions<SolidMarkV
33
33
  name: string
34
34
  }
35
35
 
36
- function withMarkViewProps(
37
- component: SolidMarkViewComponent,
38
- ): Component<SolidMarkViewProps> {
39
- return function MarkViewPropsWrapper() {
40
- const context: Accessor<SolidMarkViewProps> = useMarkViewContext()
41
- const props: SolidMarkViewProps = {
42
- get contentRef() {
43
- return context().contentRef
36
+ class ProseKitSolidMarkView extends AbstractSolidMarkView<SolidMarkViewComponent> {
37
+ render = (): JSX.Element => {
38
+ const UserComponent = this.component
39
+ const getProps = this.context
40
+ return createComponent(Portal, {
41
+ mount: this.dom,
42
+ get children() {
43
+ const props: MarkViewContextProps = getProps()
44
+ return createComponent(UserComponent, props)
44
45
  },
45
- get view() {
46
- return context().view
47
- },
48
- get mark() {
49
- return context().mark
50
- },
51
- }
52
- return createComponent(component, props)
46
+ ref: hidePortalDiv,
47
+ })
53
48
  }
54
49
  }
55
50
 
56
51
  /**
57
52
  * @internal
58
53
  */
59
- export function consumeSolidMarkViews(): void {
60
- const markViewFactory = useMarkViewFactory()
61
- const extension = createMemo(
62
- () => defineSolidMarkViewFactory(markViewFactory),
63
- [markViewFactory],
64
- )
65
-
66
- useExtension(extension)
54
+ export function defineSolidMarkViewFactory(
55
+ renderSolidRenderer: SolidRendererResult['renderSolidRenderer'],
56
+ removeSolidRenderer: SolidRendererResult['removeSolidRenderer'],
57
+ ): Extension {
58
+ const factory = buildSolidMarkViewCreator(renderSolidRenderer, removeSolidRenderer, ProseKitSolidMarkView)
59
+ return defineMarkViewFactory<SolidMarkViewOptions>({
60
+ group: 'solid',
61
+ factory,
62
+ })
67
63
  }
68
64
 
69
65
  /**
@@ -72,25 +68,9 @@ export function consumeSolidMarkViews(): void {
72
68
  * @public
73
69
  */
74
70
  export function defineSolidMarkView(options: SolidMarkViewOptions): Extension {
75
- const { name, component, ...userOptions } = options
76
-
77
- const args: SolidMarkViewUserOptions = {
78
- ...userOptions,
79
- component: withMarkViewProps(component),
80
- }
81
-
82
- return defineMarkViewComponent<SolidMarkViewUserOptions>({
83
- group: 'solid',
84
- name,
85
- args,
86
- })
87
- }
88
-
89
- function defineSolidMarkViewFactory(
90
- factory: (options: SolidMarkViewOptions) => MarkViewConstructor,
91
- ) {
92
- return defineMarkViewFactory<SolidMarkViewOptions>({
71
+ return defineMarkViewComponent<SolidMarkViewOptions>({
93
72
  group: 'solid',
94
- factory,
73
+ name: options.name,
74
+ args: options,
95
75
  })
96
76
  }