@prosekit/vue 0.6.7 → 0.7.0-beta.0
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.
- package/dist/{create-component-BREKWlWW.js → create-component.js} +3 -4
- package/dist/create-component.js.map +1 -0
- package/dist/{create-emits-B8725q2G.d.ts → create-emits.d.ts} +1 -1
- package/dist/create-emits.d.ts.map +1 -0
- package/dist/{editor-context-BfHHplRP.js → editor-context.js} +2 -3
- package/dist/editor-context.js.map +1 -0
- package/dist/prosekit-vue-autocomplete.d.ts +1 -1
- package/dist/prosekit-vue-autocomplete.js +2 -6
- package/dist/prosekit-vue-autocomplete.js.map +1 -1
- package/dist/prosekit-vue-block-handle.d.ts +1 -1
- package/dist/prosekit-vue-block-handle.js +2 -5
- package/dist/prosekit-vue-block-handle.js.map +1 -1
- package/dist/prosekit-vue-drop-indicator.d.ts +1 -1
- package/dist/prosekit-vue-drop-indicator.js +2 -3
- package/dist/prosekit-vue-drop-indicator.js.map +1 -1
- package/dist/prosekit-vue-inline-popover.d.ts +1 -1
- package/dist/prosekit-vue-inline-popover.js +2 -3
- package/dist/prosekit-vue-inline-popover.js.map +1 -1
- package/dist/prosekit-vue-popover.d.ts +1 -1
- package/dist/prosekit-vue-popover.js +2 -5
- package/dist/prosekit-vue-popover.js.map +1 -1
- package/dist/prosekit-vue-resizable.d.ts +1 -1
- package/dist/prosekit-vue-resizable.js +2 -4
- package/dist/prosekit-vue-resizable.js.map +1 -1
- package/dist/prosekit-vue-table-handle.d.ts +1 -1
- package/dist/prosekit-vue-table-handle.js +2 -11
- package/dist/prosekit-vue-table-handle.js.map +1 -1
- package/dist/prosekit-vue-tooltip.d.ts +1 -1
- package/dist/prosekit-vue-tooltip.js +2 -5
- package/dist/prosekit-vue-tooltip.js.map +1 -1
- package/dist/prosekit-vue.d.ts +1 -1
- package/dist/prosekit-vue.d.ts.map +1 -1
- package/dist/prosekit-vue.js +112 -122
- package/dist/prosekit-vue.js.map +1 -1
- package/package.json +11 -11
- package/src/components/prosekit.ts +8 -10
- package/src/components/view-renderer.ts +34 -0
- package/src/extensions/vue-mark-view.ts +33 -48
- package/src/extensions/vue-node-view.ts +33 -48
- package/dist/create-component-BREKWlWW.js.map +0 -1
- package/dist/create-emits-B8725q2G.d.ts.map +0 -1
- package/dist/editor-context-BfHHplRP.js.map +0 -1
- package/src/extensions/helpers.ts +0 -3
package/dist/prosekit-vue.js
CHANGED
|
@@ -1,145 +1,125 @@
|
|
|
1
|
-
import { n as useEditorContext, t as provideEditor } from "./editor-context
|
|
2
|
-
import {
|
|
3
|
-
import { computed, defineComponent, h, onMounted, onUnmounted, shallowRef, toValue, triggerRef, watchPostEffect } from "vue";
|
|
1
|
+
import { n as useEditorContext, t as provideEditor } from "./editor-context.js";
|
|
2
|
+
import { Teleport, computed, defineComponent, h, markRaw, onMounted, onUnmounted, shallowRef, toValue, triggerRef, watchPostEffect } from "vue";
|
|
4
3
|
import { EditorNotFoundError, ProseKitError, defineDocChangeHandler, defineKeymap, defineMarkViewComponent, defineMarkViewFactory, defineMountHandler, defineNodeViewComponent, defineNodeViewFactory, defineUpdateHandler, union, withPriority } from "@prosekit/core";
|
|
5
|
-
|
|
6
|
-
//#region src/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
import { AbstractVueMarkView, AbstractVueNodeView, buildVueMarkViewCreator, buildVueNodeViewCreator, useVueRenderer } from "@prosemirror-adapter/vue";
|
|
5
|
+
//#region src/extensions/vue-mark-view.ts
|
|
6
|
+
var ProseKitVueMarkView = class extends AbstractVueMarkView {
|
|
7
|
+
constructor(..._args) {
|
|
8
|
+
super(..._args);
|
|
9
|
+
this.render = () => {
|
|
10
|
+
const UserComponent = this.component;
|
|
11
|
+
const render = () => {
|
|
12
|
+
const props = this.context;
|
|
13
|
+
return h(Teleport, {
|
|
14
|
+
key: this.key,
|
|
15
|
+
to: this.dom
|
|
16
|
+
}, [h(UserComponent, props)]);
|
|
17
|
+
};
|
|
18
|
+
return markRaw(defineComponent({
|
|
19
|
+
name: "ProsemirrorMarkView",
|
|
20
|
+
setup: () => {
|
|
21
|
+
return render;
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
22
27
|
/**
|
|
23
28
|
* @internal
|
|
24
29
|
*/
|
|
25
|
-
function
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
//#region src/hooks/use-extension.ts
|
|
34
|
-
/**
|
|
35
|
-
* Add an extension to the editor.
|
|
36
|
-
*
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
function useExtension(extension, options) {
|
|
40
|
-
useEditorExtension(options?.editor, usePriorityExtension(extension, options?.priority));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/extensions/helpers.ts
|
|
45
|
-
function renderNothing() {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/extensions/vue-mark-view.ts
|
|
51
|
-
function withMarkViewProps(component) {
|
|
52
|
-
return defineComponent({
|
|
53
|
-
name: "MarkViewPropsWrapper",
|
|
54
|
-
setup: () => {
|
|
55
|
-
const props = useMarkViewContext();
|
|
56
|
-
return () => h(component, props);
|
|
57
|
-
}
|
|
30
|
+
function defineVueMarkViewFactory(renderVueRenderer, removeVueRenderer) {
|
|
31
|
+
return defineMarkViewFactory({
|
|
32
|
+
group: "vue",
|
|
33
|
+
factory: buildVueMarkViewCreator(renderVueRenderer, removeVueRenderer, ProseKitVueMarkView)
|
|
58
34
|
});
|
|
59
35
|
}
|
|
60
36
|
/**
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
const VueMarkViewsConsumer = /* @__PURE__ */ defineComponent({
|
|
64
|
-
name: "VueMarkViewsConsumer",
|
|
65
|
-
setup: () => {
|
|
66
|
-
const markViewFactory = useMarkViewFactory();
|
|
67
|
-
useExtension(computed(() => {
|
|
68
|
-
return defineVueMarkViewFactory(markViewFactory);
|
|
69
|
-
}));
|
|
70
|
-
return renderNothing;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
/**
|
|
74
37
|
* Defines a mark view using a Vue component.
|
|
75
38
|
*
|
|
76
39
|
* @public
|
|
77
40
|
*/
|
|
78
41
|
function defineVueMarkView(options) {
|
|
79
|
-
const { name, component, ...userOptions } = options;
|
|
80
42
|
return defineMarkViewComponent({
|
|
81
43
|
group: "vue",
|
|
82
|
-
name,
|
|
83
|
-
args:
|
|
84
|
-
...userOptions,
|
|
85
|
-
component: withMarkViewProps(component)
|
|
86
|
-
}
|
|
44
|
+
name: options.name,
|
|
45
|
+
args: options
|
|
87
46
|
});
|
|
88
47
|
}
|
|
89
|
-
function defineVueMarkViewFactory(factory) {
|
|
90
|
-
return defineMarkViewFactory({
|
|
91
|
-
group: "vue",
|
|
92
|
-
factory
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
48
|
//#endregion
|
|
97
49
|
//#region src/extensions/vue-node-view.ts
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
50
|
+
var ProseKitVueNodeView = class extends AbstractVueNodeView {
|
|
51
|
+
constructor(..._args) {
|
|
52
|
+
super(..._args);
|
|
53
|
+
this.render = () => {
|
|
54
|
+
const UserComponent = this.component;
|
|
55
|
+
const render = () => {
|
|
56
|
+
const props = this.context;
|
|
57
|
+
return h(Teleport, {
|
|
58
|
+
key: this.key,
|
|
59
|
+
to: this.dom
|
|
60
|
+
}, [h(UserComponent, props)]);
|
|
61
|
+
};
|
|
62
|
+
return markRaw(defineComponent({
|
|
63
|
+
name: "ProsemirrorNodeView",
|
|
64
|
+
setup: () => {
|
|
65
|
+
return render;
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
107
71
|
/**
|
|
108
72
|
* @internal
|
|
109
73
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}));
|
|
117
|
-
return renderNothing;
|
|
118
|
-
}
|
|
119
|
-
});
|
|
74
|
+
function defineVueNodeViewFactory(renderVueRenderer, removeVueRenderer) {
|
|
75
|
+
return defineNodeViewFactory({
|
|
76
|
+
group: "vue",
|
|
77
|
+
factory: buildVueNodeViewCreator(renderVueRenderer, removeVueRenderer, ProseKitVueNodeView)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
120
80
|
/**
|
|
121
81
|
* Defines a node view using a Vue component.
|
|
122
82
|
*
|
|
123
83
|
* @public
|
|
124
84
|
*/
|
|
125
85
|
function defineVueNodeView(options) {
|
|
126
|
-
const { name, component, ...userOptions } = options;
|
|
127
86
|
return defineNodeViewComponent({
|
|
128
87
|
group: "vue",
|
|
129
|
-
name,
|
|
130
|
-
args:
|
|
131
|
-
...userOptions,
|
|
132
|
-
component: withNodeViewProps(component)
|
|
133
|
-
}
|
|
88
|
+
name: options.name,
|
|
89
|
+
args: options
|
|
134
90
|
});
|
|
135
91
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/hooks/use-editor-extension.ts
|
|
94
|
+
/**
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
function useEditorExtension(editorRef, extensionRef) {
|
|
98
|
+
const editorContext = useEditorContext();
|
|
99
|
+
watchPostEffect((onCleanup) => {
|
|
100
|
+
const editor = toValue(editorRef) || toValue(editorContext);
|
|
101
|
+
const extension = toValue(extensionRef);
|
|
102
|
+
if (!editor) throw new EditorNotFoundError();
|
|
103
|
+
if (extension) onCleanup(editor.use(extension));
|
|
140
104
|
});
|
|
141
105
|
}
|
|
142
|
-
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/components/view-renderer.ts
|
|
108
|
+
/**
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
const ViewRenderer = defineComponent({
|
|
112
|
+
name: "ViewRenderer",
|
|
113
|
+
props: { editor: {
|
|
114
|
+
type: Object,
|
|
115
|
+
required: true
|
|
116
|
+
} },
|
|
117
|
+
setup: (props, { slots }) => {
|
|
118
|
+
const { renderVueRenderer, removeVueRenderer, render } = useVueRenderer();
|
|
119
|
+
useEditorExtension(() => props.editor, union([defineVueMarkViewFactory(renderVueRenderer, removeVueRenderer), defineVueNodeViewFactory(renderVueRenderer, removeVueRenderer)]));
|
|
120
|
+
return () => [slots.default?.(), render()];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
143
123
|
//#endregion
|
|
144
124
|
//#region src/components/prosekit.ts
|
|
145
125
|
/**
|
|
@@ -155,16 +135,30 @@ const ProseKit = defineComponent({
|
|
|
155
135
|
} },
|
|
156
136
|
setup: (props, { slots }) => {
|
|
157
137
|
provideEditor(props.editor);
|
|
158
|
-
return () => {
|
|
159
|
-
return h(ProsemirrorAdapterProvider, null, () => [
|
|
160
|
-
h(VueNodeViewsConsumer),
|
|
161
|
-
h(VueMarkViewsConsumer),
|
|
162
|
-
slots.default?.()
|
|
163
|
-
]);
|
|
164
|
-
};
|
|
138
|
+
return () => h(ViewRenderer, { editor: props.editor }, () => slots.default?.());
|
|
165
139
|
}
|
|
166
140
|
});
|
|
167
|
-
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/hooks/use-priority-extension.ts
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
function usePriorityExtension(extension, priority) {
|
|
147
|
+
return computed(() => {
|
|
148
|
+
const ext = toValue(extension);
|
|
149
|
+
return ext && priority ? withPriority(ext, priority) : ext;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/hooks/use-extension.ts
|
|
154
|
+
/**
|
|
155
|
+
* Add an extension to the editor.
|
|
156
|
+
*
|
|
157
|
+
* @public
|
|
158
|
+
*/
|
|
159
|
+
function useExtension(extension, options) {
|
|
160
|
+
useEditorExtension(options?.editor, usePriorityExtension(extension, options?.priority));
|
|
161
|
+
}
|
|
168
162
|
//#endregion
|
|
169
163
|
//#region src/hooks/use-doc-change.ts
|
|
170
164
|
/**
|
|
@@ -175,7 +169,6 @@ const ProseKit = defineComponent({
|
|
|
175
169
|
function useDocChange(handler, options) {
|
|
176
170
|
useExtension(defineDocChangeHandler((view) => handler(view.state.doc)), options);
|
|
177
171
|
}
|
|
178
|
-
|
|
179
172
|
//#endregion
|
|
180
173
|
//#region src/hooks/use-editor.ts
|
|
181
174
|
/**
|
|
@@ -197,7 +190,6 @@ function useEditor(options) {
|
|
|
197
190
|
}
|
|
198
191
|
return editorRef;
|
|
199
192
|
}
|
|
200
|
-
|
|
201
193
|
//#endregion
|
|
202
194
|
//#region src/hooks/use-editor-derived-value.ts
|
|
203
195
|
/**
|
|
@@ -217,13 +209,11 @@ function useEditorDerivedValue(derive, options) {
|
|
|
217
209
|
const editorAccessor = initialEditor ? computed(() => toValue(initialEditor)) : useEditor({ update: true });
|
|
218
210
|
return computed(() => derive(toValue(editorAccessor)));
|
|
219
211
|
}
|
|
220
|
-
|
|
221
212
|
//#endregion
|
|
222
213
|
//#region src/hooks/use-keymap.ts
|
|
223
214
|
function useKeymap(keymap, options) {
|
|
224
215
|
useExtension(computed(() => defineKeymap(toValue(keymap))), options);
|
|
225
216
|
}
|
|
226
|
-
|
|
227
217
|
//#endregion
|
|
228
218
|
//#region src/hooks/use-state-update.ts
|
|
229
219
|
/**
|
|
@@ -234,7 +224,7 @@ function useKeymap(keymap, options) {
|
|
|
234
224
|
function useStateUpdate(handler, options) {
|
|
235
225
|
useExtension(defineUpdateHandler((view) => handler(view.state)), options);
|
|
236
226
|
}
|
|
237
|
-
|
|
238
227
|
//#endregion
|
|
239
228
|
export { ProseKit, defineVueMarkView, defineVueNodeView, useDocChange, useEditor, useEditorDerivedValue, useExtension, useKeymap, useStateUpdate };
|
|
229
|
+
|
|
240
230
|
//# sourceMappingURL=prosekit-vue.js.map
|
package/dist/prosekit-vue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-vue.js","names":[],"sources":["../src/hooks/use-editor-extension.ts","../src/hooks/use-priority-extension.ts","../src/hooks/use-extension.ts","../src/extensions/helpers.ts","../src/extensions/vue-mark-view.ts","../src/extensions/vue-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":["import { EditorNotFoundError, type Editor, type Extension } from '@prosekit/core'\nimport { toValue, watchPostEffect, type MaybeRefOrGetter } from 'vue'\n\nimport { useEditorContext } from '../injection/editor-context.ts'\n\n/**\n * @internal\n */\nexport function useEditorExtension(\n editorRef: MaybeRefOrGetter<Editor> | null | undefined,\n extensionRef: MaybeRefOrGetter<Extension | null> | null,\n): void {\n const editorContext = useEditorContext()\n\n watchPostEffect((onCleanup) => {\n const editor = toValue(editorRef) || toValue(editorContext)\n const extension = toValue(extensionRef)\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'\nimport { computed, toValue, type ComputedRef, type MaybeRefOrGetter } from 'vue'\n\n/**\n * @internal\n */\nexport function usePriorityExtension<T extends Extension = Extension>(\n extension: MaybeRefOrGetter<T | null>,\n priority: Priority | null | undefined,\n): ComputedRef<T | null> {\n return computed(() => {\n const ext = toValue(extension)\n return ext && priority ? withPriority(ext, priority) : ext\n })\n}\n","import type { Editor, Extension, Priority } from '@prosekit/core'\nimport type { MaybeRefOrGetter } from 'vue'\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?: MaybeRefOrGetter<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 *\n * @public\n */\nexport function useExtension(\n /**\n * The ref 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: MaybeRefOrGetter<Extension | null>,\n options?: UseExtensionOptions,\n): void {\n useEditorExtension(\n options?.editor,\n usePriorityExtension(extension, options?.priority),\n )\n}\n","export function renderNothing(): null {\n return null\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 MarkViewContext,\n type MarkViewFactory,\n type VueMarkViewUserOptions,\n} from '@prosemirror-adapter/vue'\nimport { computed, defineComponent, h, type DefineComponent } from 'vue'\n\nimport { useExtension } from '../hooks/use-extension.ts'\n\nimport { renderNothing } from './helpers.ts'\n\n/**\n * @public\n */\nexport interface VueMarkViewProps extends MarkViewContext {}\n\n/**\n * @public\n */\nexport type VueMarkViewComponent = DefineComponent<VueMarkViewProps, any, any>\n\n/**\n * Options for {@link defineVueMarkView}.\n *\n * @public\n */\nexport interface VueMarkViewOptions extends CoreMarkViewUserOptions<VueMarkViewComponent> {\n /**\n * The name of the mark type.\n */\n name: string\n}\n\nfunction withMarkViewProps(component: VueMarkViewComponent) {\n return defineComponent({\n name: 'MarkViewPropsWrapper',\n setup: () => {\n const props: Readonly<VueMarkViewProps> = useMarkViewContext()\n return () => h(component, props)\n },\n })\n}\n\n/**\n * @internal\n */\nexport const VueMarkViewsConsumer: DefineComponent = /* @__PURE__ */ defineComponent({\n name: 'VueMarkViewsConsumer',\n setup: () => {\n const markViewFactory: MarkViewFactory = useMarkViewFactory()\n const extension = computed(() => {\n return defineVueMarkViewFactory(markViewFactory)\n })\n useExtension(extension)\n return renderNothing\n },\n})\n\n/**\n * Defines a mark view using a Vue component.\n *\n * @public\n */\nexport function defineVueMarkView(options: VueMarkViewOptions): Extension {\n const { name, component, ...userOptions } = options\n\n const args: VueMarkViewUserOptions = {\n ...userOptions,\n component: withMarkViewProps(component),\n }\n\n return defineMarkViewComponent<VueMarkViewUserOptions>({\n group: 'vue',\n name,\n args,\n })\n}\n\nfunction defineVueMarkViewFactory(\n factory: (options: VueMarkViewUserOptions) => MarkViewConstructor,\n) {\n return defineMarkViewFactory<VueMarkViewUserOptions>({\n group: 'vue',\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 NodeViewContext,\n type NodeViewFactory,\n type VueNodeViewUserOptions,\n} from '@prosemirror-adapter/vue'\nimport { computed, defineComponent, h, type DefineComponent } from 'vue'\n\nimport { useExtension } from '../hooks/use-extension.ts'\n\nimport { renderNothing } from './helpers.ts'\n\n/**\n * @public\n */\nexport interface VueNodeViewProps extends NodeViewContext {}\n\n/**\n * @public\n */\nexport type VueNodeViewComponent = DefineComponent<VueNodeViewProps, any, any>\n\n/**\n * Options for {@link defineVueNodeView}.\n *\n * @public\n */\nexport interface VueNodeViewOptions extends CoreNodeViewUserOptions<VueNodeViewComponent> {\n /**\n * The name of the node type.\n */\n name: string\n}\n\nfunction withNodeViewProps(component: VueNodeViewComponent) {\n return defineComponent({\n name: 'NodeViewPropsWrapper',\n setup: () => {\n const props: Readonly<VueNodeViewProps> = useNodeViewContext()\n return () => h(component, props)\n },\n })\n}\n\n/**\n * @internal\n */\nexport const VueNodeViewsConsumer: DefineComponent = /* @__PURE__ */ defineComponent({\n name: 'VueNodeViewsConsumer',\n setup: () => {\n const nodeViewFactory: NodeViewFactory = useNodeViewFactory()\n const extension = computed(() => {\n return defineVueNodeViewFactory(nodeViewFactory)\n })\n useExtension(extension)\n return renderNothing\n },\n})\n\n/**\n * Defines a node view using a Vue component.\n *\n * @public\n */\nexport function defineVueNodeView(options: VueNodeViewOptions): Extension {\n const { name, component, ...userOptions } = options\n\n const args: VueNodeViewUserOptions = {\n ...userOptions,\n component: withNodeViewProps(component),\n }\n\n return defineNodeViewComponent<VueNodeViewUserOptions>({\n group: 'vue',\n name,\n args,\n })\n}\n\nfunction defineVueNodeViewFactory(\n factory: (options: VueNodeViewUserOptions) => NodeViewConstructor,\n) {\n return defineNodeViewFactory<VueNodeViewUserOptions>({\n group: 'vue',\n factory,\n })\n}\n","import type { Editor } from '@prosekit/core'\nimport { ProsemirrorAdapterProvider } from '@prosemirror-adapter/vue'\nimport { defineComponent, h, type DefineSetupFnComponent, type PropType } from 'vue'\n\nimport { VueMarkViewsConsumer } from '../extensions/vue-mark-view.ts'\nimport { VueNodeViewsConsumer } from '../extensions/vue-node-view.ts'\nimport { provideEditor } from '../injection/editor-context.ts'\n\nexport interface ProseKitProps {\n editor: Editor\n}\n\n/**\n * The root component for a ProseKit editor.\n *\n * @public\n */\nexport const ProseKit: DefineSetupFnComponent<ProseKitProps> = defineComponent<ProseKitProps>({\n name: 'ProseKit',\n props: { editor: { type: Object as PropType<Editor>, required: true } },\n setup: (props, { slots }) => {\n provideEditor(props.editor)\n return () => {\n return h(ProsemirrorAdapterProvider, null, () => [\n h(VueNodeViewsConsumer),\n h(VueMarkViewsConsumer),\n slots.default?.(),\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 { onMounted, onUnmounted, shallowRef, triggerRef, type ShallowRef } from 'vue'\n\nimport { useEditorContext } from '../injection/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}): ShallowRef<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 editorRef = shallowRef<Editor<E>>(editor)\n\n if (update) {\n const forceUpdate = () => triggerRef(editorRef)\n onMounted(() => {\n const extension = union(\n defineMountHandler(forceUpdate),\n defineUpdateHandler(forceUpdate),\n )\n const dispose = editor.use(extension)\n onUnmounted(dispose)\n })\n }\n\n return editorRef\n}\n","import type { Editor, Extension } from '@prosekit/core'\nimport { computed, toValue, type MaybeRefOrGetter, type Ref, type ShallowRef } from 'vue'\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?: MaybeRefOrGetter<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 a shallow ref 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): ShallowRef<Derived> {\n const initialEditor = options?.editor\n const editorAccessor: Ref<Editor<E>> = initialEditor\n ? computed(() => toValue(initialEditor))\n : useEditor<E>({ update: true })\n\n return computed(() => derive(toValue(editorAccessor)))\n}\n","import { defineKeymap, type Keymap } from '@prosekit/core'\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\nexport function useKeymap(\n keymap: MaybeRefOrGetter<Keymap>,\n options?: UseExtensionOptions,\n): void {\n const extension = computed(() => defineKeymap(toValue(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":";;;;;;;;;AAQA,SAAgB,mBACd,WACA,cACM;CACN,MAAM,gBAAgB,kBAAkB;AAExC,kBAAiB,cAAc;EAC7B,MAAM,SAAS,QAAQ,UAAU,IAAI,QAAQ,cAAc;EAC3D,MAAM,YAAY,QAAQ,aAAa;AAEvC,MAAI,CAAC,OACH,OAAM,IAAI,qBAAqB;AAEjC,MAAI,UACF,WAAU,OAAO,IAAI,UAAU,CAAC;GAElC;;;;;;;;AClBJ,SAAgB,qBACd,WACA,UACuB;AACvB,QAAO,eAAe;EACpB,MAAM,MAAM,QAAQ,UAAU;AAC9B,SAAO,OAAO,WAAW,aAAa,KAAK,SAAS,GAAG;GACvD;;;;;;;;;;ACWJ,S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AC5C,QAAQ"}
|
|
1
|
+
{"version":3,"file":"prosekit-vue.js","names":[],"sources":["../src/extensions/vue-mark-view.ts","../src/extensions/vue-node-view.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":["import { defineMarkViewComponent, defineMarkViewFactory, type Extension } from '@prosekit/core'\nimport type { CoreMarkViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n AbstractVueMarkView,\n buildVueMarkViewCreator,\n type MarkViewContext,\n type VueRendererComponent,\n type VueRendererResult,\n} from '@prosemirror-adapter/vue'\nimport { defineComponent, h, markRaw, Teleport, type DefineComponent } from 'vue'\n\n/**\n * @public\n */\nexport interface VueMarkViewProps extends MarkViewContext {}\n\n/**\n * @public\n */\nexport type VueMarkViewComponent = DefineComponent<VueMarkViewProps, any, any>\n\n/**\n * Options for {@link defineVueMarkView}.\n *\n * @public\n */\nexport interface VueMarkViewOptions extends CoreMarkViewUserOptions<VueMarkViewComponent> {\n /**\n * The name of the mark type.\n */\n name: string\n}\n\nclass ProseKitVueMarkView extends AbstractVueMarkView<VueMarkViewComponent> {\n render = (): VueRendererComponent => {\n const UserComponent = this.component\n const render = () => {\n const props = this.context\n return h(Teleport, { key: this.key, to: this.dom }, [h(UserComponent, props)])\n }\n const RendererComponent: VueRendererComponent = defineComponent({\n name: 'ProsemirrorMarkView',\n setup: () => {\n return render\n },\n })\n return markRaw(RendererComponent)\n }\n}\n\n/**\n * @internal\n */\nexport function defineVueMarkViewFactory(\n renderVueRenderer: VueRendererResult['renderVueRenderer'],\n removeVueRenderer: VueRendererResult['removeVueRenderer'],\n): Extension {\n const factory = buildVueMarkViewCreator(renderVueRenderer, removeVueRenderer, ProseKitVueMarkView)\n return defineMarkViewFactory<VueMarkViewOptions>({\n group: 'vue',\n factory,\n })\n}\n\n/**\n * Defines a mark view using a Vue component.\n *\n * @public\n */\nexport function defineVueMarkView(options: VueMarkViewOptions): Extension {\n return defineMarkViewComponent<VueMarkViewOptions>({\n group: 'vue',\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 AbstractVueNodeView,\n buildVueNodeViewCreator,\n type NodeViewContext,\n type VueRendererComponent,\n type VueRendererResult,\n} from '@prosemirror-adapter/vue'\nimport { defineComponent, h, markRaw, Teleport, type DefineComponent } from 'vue'\n\n/**\n * @public\n */\nexport interface VueNodeViewProps extends NodeViewContext {}\n\n/**\n * @public\n */\nexport type VueNodeViewComponent = DefineComponent<VueNodeViewProps, any, any>\n\n/**\n * Options for {@link defineVueNodeView}.\n *\n * @public\n */\nexport interface VueNodeViewOptions extends CoreNodeViewUserOptions<VueNodeViewComponent> {\n /**\n * The name of the node type.\n */\n name: string\n}\n\nclass ProseKitVueNodeView extends AbstractVueNodeView<VueNodeViewComponent> {\n render = (): VueRendererComponent => {\n const UserComponent = this.component\n const render = () => {\n const props = this.context\n return h(Teleport, { key: this.key, to: this.dom }, [h(UserComponent, props)])\n }\n const RendererComponent: VueRendererComponent = defineComponent({\n name: 'ProsemirrorNodeView',\n setup: () => {\n return render\n },\n })\n return markRaw(RendererComponent)\n }\n}\n\n/**\n * @internal\n */\nexport function defineVueNodeViewFactory(\n renderVueRenderer: VueRendererResult['renderVueRenderer'],\n removeVueRenderer: VueRendererResult['removeVueRenderer'],\n): Extension {\n const factory = buildVueNodeViewCreator(renderVueRenderer, removeVueRenderer, ProseKitVueNodeView)\n return defineNodeViewFactory<VueNodeViewOptions>({\n group: 'vue',\n factory,\n })\n}\n\n/**\n * Defines a node view using a Vue component.\n *\n * @public\n */\nexport function defineVueNodeView(options: VueNodeViewOptions): Extension {\n return defineNodeViewComponent<VueNodeViewOptions>({\n group: 'vue',\n name: options.name,\n args: options,\n })\n}\n","import { EditorNotFoundError, type Editor, type Extension } from '@prosekit/core'\nimport { toValue, watchPostEffect, type MaybeRefOrGetter } from 'vue'\n\nimport { useEditorContext } from '../injection/editor-context.ts'\n\n/**\n * @internal\n */\nexport function useEditorExtension(\n editorRef: MaybeRefOrGetter<Editor> | null | undefined,\n extensionRef: MaybeRefOrGetter<Extension | null> | null,\n): void {\n const editorContext = useEditorContext()\n\n watchPostEffect((onCleanup) => {\n const editor = toValue(editorRef) || toValue(editorContext)\n const extension = toValue(extensionRef)\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 { useVueRenderer } from '@prosemirror-adapter/vue'\nimport { defineComponent, type DefineSetupFnComponent, type PropType } from 'vue'\n\nimport { defineVueMarkViewFactory } from '../extensions/vue-mark-view.ts'\nimport { defineVueNodeViewFactory } from '../extensions/vue-node-view.ts'\nimport { useEditorExtension } from '../hooks/use-editor-extension.ts'\n\n/**\n * @internal\n */\ninterface ViewRendererProps {\n editor: Editor\n}\n\n/**\n * @internal\n */\nexport const ViewRenderer: DefineSetupFnComponent<ViewRendererProps> = defineComponent<ViewRendererProps>({\n name: 'ViewRenderer',\n props: { editor: { type: Object as PropType<Editor>, required: true } },\n setup: (props, { slots }) => {\n const { renderVueRenderer, removeVueRenderer, render } = useVueRenderer()\n\n const extension = union([\n defineVueMarkViewFactory(renderVueRenderer, removeVueRenderer),\n defineVueNodeViewFactory(renderVueRenderer, removeVueRenderer),\n ])\n\n useEditorExtension(() => props.editor, extension)\n\n return () => [slots.default?.(), render()]\n },\n})\n","import type { Editor } from '@prosekit/core'\nimport { defineComponent, h, type DefineSetupFnComponent, type PropType } from 'vue'\n\nimport { provideEditor } from '../injection/editor-context.ts'\n\nimport { ViewRenderer } from './view-renderer.ts'\n\nexport interface ProseKitProps {\n editor: Editor\n}\n\n/**\n * The root component for a ProseKit editor.\n *\n * @public\n */\nexport const ProseKit: DefineSetupFnComponent<ProseKitProps> = defineComponent<ProseKitProps>({\n name: 'ProseKit',\n props: { editor: { type: Object as PropType<Editor>, required: true } },\n setup: (props, { slots }) => {\n provideEditor(props.editor)\n return () =>\n h(\n ViewRenderer,\n { editor: props.editor },\n () => slots.default?.(),\n )\n },\n})\n","import { withPriority, type Extension, type Priority } from '@prosekit/core'\nimport { computed, toValue, type ComputedRef, type MaybeRefOrGetter } from 'vue'\n\n/**\n * @internal\n */\nexport function usePriorityExtension<T extends Extension = Extension>(\n extension: MaybeRefOrGetter<T | null>,\n priority: Priority | null | undefined,\n): ComputedRef<T | null> {\n return computed(() => {\n const ext = toValue(extension)\n return ext && priority ? withPriority(ext, priority) : ext\n })\n}\n","import type { Editor, Extension, Priority } from '@prosekit/core'\nimport type { MaybeRefOrGetter } from 'vue'\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?: MaybeRefOrGetter<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 *\n * @public\n */\nexport function useExtension(\n /**\n * The ref 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: MaybeRefOrGetter<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 { onMounted, onUnmounted, shallowRef, triggerRef, type ShallowRef } from 'vue'\n\nimport { useEditorContext } from '../injection/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}): ShallowRef<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 editorRef = shallowRef<Editor<E>>(editor)\n\n if (update) {\n const forceUpdate = () => triggerRef(editorRef)\n onMounted(() => {\n const extension = union(\n defineMountHandler(forceUpdate),\n defineUpdateHandler(forceUpdate),\n )\n const dispose = editor.use(extension)\n onUnmounted(dispose)\n })\n }\n\n return editorRef\n}\n","import type { Editor, Extension } from '@prosekit/core'\nimport { computed, toValue, type MaybeRefOrGetter, type Ref, type ShallowRef } from 'vue'\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?: MaybeRefOrGetter<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 a shallow ref 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): ShallowRef<Derived> {\n const initialEditor = options?.editor\n const editorAccessor: Ref<Editor<E>> = initialEditor\n ? computed(() => toValue(initialEditor))\n : useEditor<E>({ update: true })\n\n return computed(() => derive(toValue(editorAccessor)))\n}\n","import { defineKeymap, type Keymap } from '@prosekit/core'\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\nexport function useKeymap(\n keymap: MaybeRefOrGetter<Keymap>,\n options?: UseExtensionOptions,\n): void {\n const extension = computed(() => defineKeymap(toValue(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":";;;;;AAiCA,IAAM,sBAAN,cAAkC,oBAA0C;;;sBACrC;GACnC,MAAM,gBAAgB,KAAK;GAC3B,MAAM,eAAe;IACnB,MAAM,QAAQ,KAAK;AACnB,WAAO,EAAE,UAAU;KAAE,KAAK,KAAK;KAAK,IAAI,KAAK;KAAK,EAAE,CAAC,EAAE,eAAe,MAAM,CAAC,CAAC;;AAQhF,UAAO,QANyC,gBAAgB;IAC9D,MAAM;IACN,aAAa;AACX,YAAO;;IAEV,CAAC,CAC+B;;;;;;;AAOrC,SAAgB,yBACd,mBACA,mBACW;AAEX,QAAO,sBAA0C;EAC/C,OAAO;EACP,SAHc,wBAAwB,mBAAmB,mBAAmB,oBAAoB;EAIjG,CAAC;;;;;;;AAQJ,SAAgB,kBAAkB,SAAwC;AACxE,QAAO,wBAA4C;EACjD,OAAO;EACP,MAAM,QAAQ;EACd,MAAM;EACP,CAAC;;;;ACzCJ,IAAM,sBAAN,cAAkC,oBAA0C;;;sBACrC;GACnC,MAAM,gBAAgB,KAAK;GAC3B,MAAM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M,CAAC,EAC5C,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosekit/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0-beta.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Vue 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.
|
|
72
|
-
"@prosemirror-adapter/vue": "^0.
|
|
73
|
-
"@prosekit/core": "^0.
|
|
71
|
+
"@prosemirror-adapter/core": "^0.5.2",
|
|
72
|
+
"@prosemirror-adapter/vue": "^0.5.2",
|
|
73
|
+
"@prosekit/core": "^0.12.0-beta.0",
|
|
74
74
|
"@prosekit/pm": "^0.1.15",
|
|
75
|
-
"@prosekit/web": "^0.
|
|
75
|
+
"@prosekit/web": "^0.8.0-beta.0"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"vue": ">= 3.0.0"
|
|
@@ -83,15 +83,15 @@
|
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
86
|
+
"@vitejs/plugin-vue": "^6.0.5",
|
|
87
87
|
"@vue/test-utils": "^2.4.6",
|
|
88
|
-
"tsdown": "^0.
|
|
88
|
+
"tsdown": "^0.21.4",
|
|
89
89
|
"typescript": "~5.9.3",
|
|
90
|
-
"vitest": "^4.1.
|
|
91
|
-
"vue": "^3.5.
|
|
92
|
-
"@prosekit/config-tsdown": "0.0.0",
|
|
90
|
+
"vitest": "^4.1.1",
|
|
91
|
+
"vue": "^3.5.30",
|
|
93
92
|
"@prosekit/config-ts": "0.0.0",
|
|
94
|
-
"@prosekit/config-vitest": "0.0.0"
|
|
93
|
+
"@prosekit/config-vitest": "0.0.0",
|
|
94
|
+
"@prosekit/config-tsdown": "0.0.0"
|
|
95
95
|
},
|
|
96
96
|
"publishConfig": {
|
|
97
97
|
"dev": {}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Editor } from '@prosekit/core'
|
|
2
|
-
import { ProsemirrorAdapterProvider } from '@prosemirror-adapter/vue'
|
|
3
2
|
import { defineComponent, h, type DefineSetupFnComponent, type PropType } from 'vue'
|
|
4
3
|
|
|
5
|
-
import { VueMarkViewsConsumer } from '../extensions/vue-mark-view.ts'
|
|
6
|
-
import { VueNodeViewsConsumer } from '../extensions/vue-node-view.ts'
|
|
7
4
|
import { provideEditor } from '../injection/editor-context.ts'
|
|
8
5
|
|
|
6
|
+
import { ViewRenderer } from './view-renderer.ts'
|
|
7
|
+
|
|
9
8
|
export interface ProseKitProps {
|
|
10
9
|
editor: Editor
|
|
11
10
|
}
|
|
@@ -20,12 +19,11 @@ export const ProseKit: DefineSetupFnComponent<ProseKitProps> = defineComponent<P
|
|
|
20
19
|
props: { editor: { type: Object as PropType<Editor>, required: true } },
|
|
21
20
|
setup: (props, { slots }) => {
|
|
22
21
|
provideEditor(props.editor)
|
|
23
|
-
return () =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
slots.default?.(),
|
|
28
|
-
|
|
29
|
-
}
|
|
22
|
+
return () =>
|
|
23
|
+
h(
|
|
24
|
+
ViewRenderer,
|
|
25
|
+
{ editor: props.editor },
|
|
26
|
+
() => slots.default?.(),
|
|
27
|
+
)
|
|
30
28
|
},
|
|
31
29
|
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { union, type Editor } from '@prosekit/core'
|
|
2
|
+
import { useVueRenderer } from '@prosemirror-adapter/vue'
|
|
3
|
+
import { defineComponent, type DefineSetupFnComponent, type PropType } from 'vue'
|
|
4
|
+
|
|
5
|
+
import { defineVueMarkViewFactory } from '../extensions/vue-mark-view.ts'
|
|
6
|
+
import { defineVueNodeViewFactory } from '../extensions/vue-node-view.ts'
|
|
7
|
+
import { useEditorExtension } from '../hooks/use-editor-extension.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
interface ViewRendererProps {
|
|
13
|
+
editor: Editor
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export const ViewRenderer: DefineSetupFnComponent<ViewRendererProps> = defineComponent<ViewRendererProps>({
|
|
20
|
+
name: 'ViewRenderer',
|
|
21
|
+
props: { editor: { type: Object as PropType<Editor>, required: true } },
|
|
22
|
+
setup: (props, { slots }) => {
|
|
23
|
+
const { renderVueRenderer, removeVueRenderer, render } = useVueRenderer()
|
|
24
|
+
|
|
25
|
+
const extension = union([
|
|
26
|
+
defineVueMarkViewFactory(renderVueRenderer, removeVueRenderer),
|
|
27
|
+
defineVueNodeViewFactory(renderVueRenderer, removeVueRenderer),
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
useEditorExtension(() => props.editor, extension)
|
|
31
|
+
|
|
32
|
+
return () => [slots.default?.(), render()]
|
|
33
|
+
},
|
|
34
|
+
})
|
|
@@ -1,18 +1,13 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
4
|
+
AbstractVueMarkView,
|
|
5
|
+
buildVueMarkViewCreator,
|
|
7
6
|
type MarkViewContext,
|
|
8
|
-
type
|
|
9
|
-
type
|
|
7
|
+
type VueRendererComponent,
|
|
8
|
+
type VueRendererResult,
|
|
10
9
|
} from '@prosemirror-adapter/vue'
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
import { useExtension } from '../hooks/use-extension.ts'
|
|
14
|
-
|
|
15
|
-
import { renderNothing } from './helpers.ts'
|
|
10
|
+
import { defineComponent, h, markRaw, Teleport, type DefineComponent } from 'vue'
|
|
16
11
|
|
|
17
12
|
/**
|
|
18
13
|
* @public
|
|
@@ -36,30 +31,36 @@ export interface VueMarkViewOptions extends CoreMarkViewUserOptions<VueMarkViewC
|
|
|
36
31
|
name: string
|
|
37
32
|
}
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const props
|
|
44
|
-
return (
|
|
45
|
-
}
|
|
46
|
-
|
|
34
|
+
class ProseKitVueMarkView extends AbstractVueMarkView<VueMarkViewComponent> {
|
|
35
|
+
render = (): VueRendererComponent => {
|
|
36
|
+
const UserComponent = this.component
|
|
37
|
+
const render = () => {
|
|
38
|
+
const props = this.context
|
|
39
|
+
return h(Teleport, { key: this.key, to: this.dom }, [h(UserComponent, props)])
|
|
40
|
+
}
|
|
41
|
+
const RendererComponent: VueRendererComponent = defineComponent({
|
|
42
|
+
name: 'ProsemirrorMarkView',
|
|
43
|
+
setup: () => {
|
|
44
|
+
return render
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
return markRaw(RendererComponent)
|
|
48
|
+
}
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/**
|
|
50
52
|
* @internal
|
|
51
53
|
*/
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})
|
|
54
|
+
export function defineVueMarkViewFactory(
|
|
55
|
+
renderVueRenderer: VueRendererResult['renderVueRenderer'],
|
|
56
|
+
removeVueRenderer: VueRendererResult['removeVueRenderer'],
|
|
57
|
+
): Extension {
|
|
58
|
+
const factory = buildVueMarkViewCreator(renderVueRenderer, removeVueRenderer, ProseKitVueMarkView)
|
|
59
|
+
return defineMarkViewFactory<VueMarkViewOptions>({
|
|
60
|
+
group: 'vue',
|
|
61
|
+
factory,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
63
64
|
|
|
64
65
|
/**
|
|
65
66
|
* Defines a mark view using a Vue component.
|
|
@@ -67,25 +68,9 @@ export const VueMarkViewsConsumer: DefineComponent = /* @__PURE__ */ defineCompo
|
|
|
67
68
|
* @public
|
|
68
69
|
*/
|
|
69
70
|
export function defineVueMarkView(options: VueMarkViewOptions): Extension {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const args: VueMarkViewUserOptions = {
|
|
73
|
-
...userOptions,
|
|
74
|
-
component: withMarkViewProps(component),
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return defineMarkViewComponent<VueMarkViewUserOptions>({
|
|
71
|
+
return defineMarkViewComponent<VueMarkViewOptions>({
|
|
78
72
|
group: 'vue',
|
|
79
|
-
name,
|
|
80
|
-
args,
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function defineVueMarkViewFactory(
|
|
85
|
-
factory: (options: VueMarkViewUserOptions) => MarkViewConstructor,
|
|
86
|
-
) {
|
|
87
|
-
return defineMarkViewFactory<VueMarkViewUserOptions>({
|
|
88
|
-
group: 'vue',
|
|
89
|
-
factory,
|
|
73
|
+
name: options.name,
|
|
74
|
+
args: options,
|
|
90
75
|
})
|
|
91
76
|
}
|