@prosekit/vue 0.4.12 → 0.4.14
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-wOxhYs6n.js +46 -0
- package/dist/create-emits-QdHrV9Ip.d.ts +4 -0
- package/dist/editor-context-DKYvJpUt.js +19 -0
- package/dist/prosekit-vue-autocomplete.d.ts +50 -12
- package/dist/prosekit-vue-autocomplete.js +17 -54
- package/dist/prosekit-vue-block-handle.d.ts +39 -9
- package/dist/prosekit-vue-block-handle.js +14 -42
- package/dist/prosekit-vue-inline-popover.d.ts +17 -3
- package/dist/prosekit-vue-inline-popover.js +8 -18
- package/dist/prosekit-vue-popover.d.ts +39 -9
- package/dist/prosekit-vue-popover.js +14 -42
- package/dist/prosekit-vue-resizable.d.ts +28 -6
- package/dist/prosekit-vue-resizable.js +11 -30
- package/dist/prosekit-vue-table-handle.d.ts +83 -21
- package/dist/prosekit-vue-table-handle.js +26 -90
- package/dist/prosekit-vue-tooltip.d.ts +39 -9
- package/dist/prosekit-vue-tooltip.js +14 -42
- package/dist/prosekit-vue.d.ts +135 -16
- package/dist/prosekit-vue.js +181 -214
- package/package.json +28 -11
- package/dist/_tsup-dts-rollup.d.ts +0 -733
- package/dist/chunk-BD3KKHO6.js +0 -17
- package/dist/chunk-PTYQOFHO.js +0 -71
package/dist/prosekit-vue.js
CHANGED
@@ -1,252 +1,219 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
} from "
|
1
|
+
import { provideEditor, useEditorContext } from "./editor-context-DKYvJpUt.js";
|
2
|
+
import { ProsemirrorAdapterProvider, useMarkViewContext, useMarkViewFactory, useNodeViewContext, useNodeViewFactory } from "@prosemirror-adapter/vue";
|
3
|
+
import { computed, defineComponent, h, onMounted, onUnmounted, shallowRef, toValue, triggerRef, watchPostEffect } from "vue";
|
4
|
+
import { EditorNotFoundError, ProseKitError, defineDocChangeHandler, defineKeymap, defineMarkViewComponent, defineMarkViewFactory, defineMountHandler, defineNodeViewComponent, defineNodeViewFactory, defineUpdateHandler, union, withPriority } from "@prosekit/core";
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
h as h3
|
11
|
-
} from "vue";
|
12
|
-
|
13
|
-
// src/extensions/vue-mark-view.ts
|
14
|
-
import {
|
15
|
-
defineMarkViewComponent,
|
16
|
-
defineMarkViewFactory
|
17
|
-
} from "@prosekit/core";
|
18
|
-
import {
|
19
|
-
useMarkViewContext,
|
20
|
-
useMarkViewFactory
|
21
|
-
} from "@prosemirror-adapter/vue";
|
22
|
-
import {
|
23
|
-
computed as computed2,
|
24
|
-
defineComponent,
|
25
|
-
h
|
26
|
-
} from "vue";
|
27
|
-
|
28
|
-
// src/hooks/use-editor-extension.ts
|
29
|
-
import {
|
30
|
-
EditorNotFoundError
|
31
|
-
} from "@prosekit/core";
|
32
|
-
import {
|
33
|
-
toValue,
|
34
|
-
watchPostEffect
|
35
|
-
} from "vue";
|
6
|
+
//#region src/hooks/use-editor-extension.ts
|
7
|
+
/**
|
8
|
+
* @internal
|
9
|
+
*/
|
36
10
|
function useEditorExtension(editorRef, extensionRef) {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
if (extension) {
|
45
|
-
onCleanup(editor.use(extension));
|
46
|
-
}
|
47
|
-
});
|
11
|
+
const editorContext = useEditorContext();
|
12
|
+
watchPostEffect((onCleanup) => {
|
13
|
+
const editor = toValue(editorRef) || toValue(editorContext);
|
14
|
+
const extension = toValue(extensionRef);
|
15
|
+
if (!editor) throw new EditorNotFoundError();
|
16
|
+
if (extension) onCleanup(editor.use(extension));
|
17
|
+
});
|
48
18
|
}
|
49
19
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
computed,
|
56
|
-
toValue as toValue2
|
57
|
-
} from "vue";
|
20
|
+
//#endregion
|
21
|
+
//#region src/hooks/use-priority-extension.ts
|
22
|
+
/**
|
23
|
+
* @internal
|
24
|
+
*/
|
58
25
|
function usePriorityExtension(extension, priority) {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
26
|
+
return computed(() => {
|
27
|
+
const ext = toValue(extension);
|
28
|
+
return ext && priority ? withPriority(ext, priority) : ext;
|
29
|
+
});
|
63
30
|
}
|
64
31
|
|
65
|
-
|
32
|
+
//#endregion
|
33
|
+
//#region src/hooks/use-extension.ts
|
34
|
+
/**
|
35
|
+
* Add an extension to the editor.
|
36
|
+
*
|
37
|
+
* @public
|
38
|
+
*/
|
66
39
|
function useExtension(extension, options) {
|
67
|
-
|
68
|
-
options?.editor,
|
69
|
-
usePriorityExtension(extension, options?.priority)
|
70
|
-
);
|
40
|
+
useEditorExtension(options?.editor, usePriorityExtension(extension, options?.priority));
|
71
41
|
}
|
72
42
|
|
73
|
-
|
43
|
+
//#endregion
|
44
|
+
//#region src/extensions/vue-mark-view.ts
|
74
45
|
function withMarkViewProps(component) {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
46
|
+
return defineComponent({
|
47
|
+
name: "MarkViewPropsWrapper",
|
48
|
+
setup: () => {
|
49
|
+
const props = useMarkViewContext();
|
50
|
+
return () => h(component, props);
|
51
|
+
}
|
52
|
+
});
|
82
53
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
54
|
+
/**
|
55
|
+
* @internal
|
56
|
+
*/
|
57
|
+
const VueMarkViewsConsumer = /* @__PURE__ */ defineComponent({
|
58
|
+
name: "VueMarkViewsConsumer",
|
59
|
+
setup: () => {
|
60
|
+
const markViewFactory = useMarkViewFactory();
|
61
|
+
const extension = computed(() => {
|
62
|
+
return defineVueMarkViewFactory(markViewFactory);
|
63
|
+
});
|
64
|
+
useExtension(extension);
|
65
|
+
return () => null;
|
66
|
+
}
|
93
67
|
});
|
68
|
+
/**
|
69
|
+
* Defines a mark view using a Vue component.
|
70
|
+
*
|
71
|
+
* @public
|
72
|
+
*/
|
94
73
|
function defineVueMarkView(options) {
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
74
|
+
const { name, component,...userOptions } = options;
|
75
|
+
const args = {
|
76
|
+
...userOptions,
|
77
|
+
component: withMarkViewProps(component)
|
78
|
+
};
|
79
|
+
return defineMarkViewComponent({
|
80
|
+
group: "vue",
|
81
|
+
name,
|
82
|
+
args
|
83
|
+
});
|
105
84
|
}
|
106
85
|
function defineVueMarkViewFactory(factory) {
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
86
|
+
return defineMarkViewFactory({
|
87
|
+
group: "vue",
|
88
|
+
factory
|
89
|
+
});
|
111
90
|
}
|
112
91
|
|
113
|
-
|
114
|
-
|
115
|
-
defineNodeViewComponent,
|
116
|
-
defineNodeViewFactory
|
117
|
-
} from "@prosekit/core";
|
118
|
-
import {
|
119
|
-
useNodeViewContext,
|
120
|
-
useNodeViewFactory
|
121
|
-
} from "@prosemirror-adapter/vue";
|
122
|
-
import {
|
123
|
-
computed as computed3,
|
124
|
-
defineComponent as defineComponent2,
|
125
|
-
h as h2
|
126
|
-
} from "vue";
|
92
|
+
//#endregion
|
93
|
+
//#region src/extensions/vue-node-view.ts
|
127
94
|
function withNodeViewProps(component) {
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
95
|
+
return defineComponent({
|
96
|
+
name: "NodeViewPropsWrapper",
|
97
|
+
setup: () => {
|
98
|
+
const props = useNodeViewContext();
|
99
|
+
return () => h(component, props);
|
100
|
+
}
|
101
|
+
});
|
135
102
|
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
103
|
+
/**
|
104
|
+
* @internal
|
105
|
+
*/
|
106
|
+
const VueNodeViewsConsumer = /* @__PURE__ */ defineComponent({
|
107
|
+
name: "VueNodeViewsConsumer",
|
108
|
+
setup: () => {
|
109
|
+
const nodeViewFactory = useNodeViewFactory();
|
110
|
+
const extension = computed(() => {
|
111
|
+
return defineVueNodeViewFactory(nodeViewFactory);
|
112
|
+
});
|
113
|
+
useExtension(extension);
|
114
|
+
return () => null;
|
115
|
+
}
|
146
116
|
});
|
117
|
+
/**
|
118
|
+
* Defines a node view using a Vue component.
|
119
|
+
*
|
120
|
+
* @public
|
121
|
+
*/
|
147
122
|
function defineVueNodeView(options) {
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
123
|
+
const { name, component,...userOptions } = options;
|
124
|
+
const args = {
|
125
|
+
...userOptions,
|
126
|
+
component: withNodeViewProps(component)
|
127
|
+
};
|
128
|
+
return defineNodeViewComponent({
|
129
|
+
group: "vue",
|
130
|
+
name,
|
131
|
+
args
|
132
|
+
});
|
158
133
|
}
|
159
134
|
function defineVueNodeViewFactory(factory) {
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
135
|
+
return defineNodeViewFactory({
|
136
|
+
group: "vue",
|
137
|
+
factory
|
138
|
+
});
|
164
139
|
}
|
165
140
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
)
|
141
|
+
//#endregion
|
142
|
+
//#region src/components/prosekit.ts
|
143
|
+
/**
|
144
|
+
* The root component for a ProseKit editor.
|
145
|
+
*
|
146
|
+
* @public
|
147
|
+
*/
|
148
|
+
const ProseKit = defineComponent({
|
149
|
+
name: "ProseKit",
|
150
|
+
props: { editor: {
|
151
|
+
type: Object,
|
152
|
+
required: true
|
153
|
+
} },
|
154
|
+
setup: (props, { slots }) => {
|
155
|
+
provideEditor(props.editor);
|
156
|
+
return () => {
|
157
|
+
return h(ProsemirrorAdapterProvider, null, () => [
|
158
|
+
h(VueNodeViewsConsumer),
|
159
|
+
h(VueMarkViewsConsumer),
|
160
|
+
slots.default?.()
|
161
|
+
]);
|
162
|
+
};
|
163
|
+
}
|
164
|
+
});
|
180
165
|
|
181
|
-
|
182
|
-
|
166
|
+
//#endregion
|
167
|
+
//#region src/hooks/use-doc-change.ts
|
168
|
+
/**
|
169
|
+
* Calls the given handler whenever the editor document changes.
|
170
|
+
*
|
171
|
+
* @public
|
172
|
+
*/
|
183
173
|
function useDocChange(handler, options) {
|
184
|
-
|
185
|
-
|
174
|
+
const extension = defineDocChangeHandler((view) => handler(view.state.doc));
|
175
|
+
useExtension(extension, options);
|
186
176
|
}
|
187
177
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
import {
|
196
|
-
onMounted,
|
197
|
-
onUnmounted,
|
198
|
-
shallowRef,
|
199
|
-
triggerRef
|
200
|
-
} from "vue";
|
178
|
+
//#endregion
|
179
|
+
//#region src/hooks/use-editor.ts
|
180
|
+
/**
|
181
|
+
* Retrieves the editor instance from the nearest ProseKit component.
|
182
|
+
*
|
183
|
+
* @public
|
184
|
+
*/
|
201
185
|
function useEditor(options) {
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
const extension = union(
|
214
|
-
defineMountHandler(forceUpdate),
|
215
|
-
defineUpdateHandler(forceUpdate)
|
216
|
-
);
|
217
|
-
const dispose = editor.use(extension);
|
218
|
-
onUnmounted(dispose);
|
219
|
-
});
|
220
|
-
}
|
221
|
-
return editorRef;
|
186
|
+
const update = options?.update ?? false;
|
187
|
+
const editor = useEditorContext();
|
188
|
+
if (!editor) throw new ProseKitError("useEditor must be used within the ProseKit component");
|
189
|
+
const editorRef = shallowRef(editor);
|
190
|
+
if (update) onMounted(() => {
|
191
|
+
const forceUpdate = () => triggerRef(editorRef);
|
192
|
+
const extension = union(defineMountHandler(forceUpdate), defineUpdateHandler(forceUpdate));
|
193
|
+
const dispose = editor.use(extension);
|
194
|
+
onUnmounted(dispose);
|
195
|
+
});
|
196
|
+
return editorRef;
|
222
197
|
}
|
223
198
|
|
224
|
-
|
225
|
-
|
226
|
-
defineKeymap
|
227
|
-
} from "@prosekit/core";
|
228
|
-
import {
|
229
|
-
computed as computed4,
|
230
|
-
toValue as toValue3
|
231
|
-
} from "vue";
|
199
|
+
//#endregion
|
200
|
+
//#region src/hooks/use-keymap.ts
|
232
201
|
function useKeymap(keymap, options) {
|
233
|
-
|
234
|
-
|
202
|
+
const extension = computed(() => defineKeymap(toValue(keymap)));
|
203
|
+
useExtension(extension, options);
|
235
204
|
}
|
236
205
|
|
237
|
-
|
238
|
-
|
206
|
+
//#endregion
|
207
|
+
//#region src/hooks/use-state-update.ts
|
208
|
+
/**
|
209
|
+
* Calls the given handler whenever the editor state changes.
|
210
|
+
*
|
211
|
+
* @public
|
212
|
+
*/
|
239
213
|
function useStateUpdate(handler, options) {
|
240
|
-
|
241
|
-
|
214
|
+
const extension = defineUpdateHandler((view) => handler(view.state));
|
215
|
+
useExtension(extension, options);
|
242
216
|
}
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
defineVueNodeView,
|
247
|
-
useDocChange,
|
248
|
-
useEditor,
|
249
|
-
useExtension,
|
250
|
-
useKeymap,
|
251
|
-
useStateUpdate
|
252
|
-
};
|
217
|
+
|
218
|
+
//#endregion
|
219
|
+
export { ProseKit, defineVueMarkView, defineVueNodeView, useDocChange, useEditor, useExtension, useKeymap, useStateUpdate };
|
package/package.json
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/vue",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.4.
|
4
|
+
"version": "0.4.14",
|
5
5
|
"private": false,
|
6
|
+
"description": "Vue components and utilities for ProseKit",
|
6
7
|
"author": {
|
7
8
|
"name": "ocavue",
|
8
9
|
"email": "ocavue@gmail.com"
|
@@ -64,9 +65,9 @@
|
|
64
65
|
"dependencies": {
|
65
66
|
"@prosemirror-adapter/core": "^0.4.0",
|
66
67
|
"@prosemirror-adapter/vue": "^0.4.1",
|
67
|
-
"@prosekit/core": "^0.8.
|
68
|
-
"@prosekit/pm": "^0.1.
|
69
|
-
"@prosekit/web": "^0.5.
|
68
|
+
"@prosekit/core": "^0.8.1",
|
69
|
+
"@prosekit/pm": "^0.1.10",
|
70
|
+
"@prosekit/web": "^0.5.9"
|
70
71
|
},
|
71
72
|
"peerDependencies": {
|
72
73
|
"vue": ">= 3.0.0"
|
@@ -77,17 +78,33 @@
|
|
77
78
|
}
|
78
79
|
},
|
79
80
|
"devDependencies": {
|
80
|
-
"@vitejs/plugin-vue": "^5.2.
|
81
|
+
"@vitejs/plugin-vue": "^5.2.4",
|
81
82
|
"@vue/test-utils": "^2.4.6",
|
82
|
-
"
|
83
|
-
"typescript": "~5.
|
84
|
-
"vitest": "^3.
|
85
|
-
"vue": "^3.5.
|
86
|
-
"@prosekit/
|
83
|
+
"tsdown": "^0.12.4",
|
84
|
+
"typescript": "~5.8.3",
|
85
|
+
"vitest": "^3.1.4",
|
86
|
+
"vue": "^3.5.16",
|
87
|
+
"@prosekit/config-tsdown": "0.0.0",
|
88
|
+
"@prosekit/config-vitest": "0.0.0"
|
89
|
+
},
|
90
|
+
"publishConfig": {
|
91
|
+
"dev": {}
|
92
|
+
},
|
93
|
+
"dev": {
|
94
|
+
"entry": {
|
95
|
+
"prosekit-vue": "./src/index.ts",
|
96
|
+
"prosekit-vue-autocomplete": "./src/components/autocomplete/index.gen.ts",
|
97
|
+
"prosekit-vue-block-handle": "./src/components/block-handle/index.gen.ts",
|
98
|
+
"prosekit-vue-inline-popover": "./src/components/inline-popover/index.gen.ts",
|
99
|
+
"prosekit-vue-popover": "./src/components/popover/index.gen.ts",
|
100
|
+
"prosekit-vue-resizable": "./src/components/resizable/index.gen.ts",
|
101
|
+
"prosekit-vue-table-handle": "./src/components/table-handle/index.gen.ts",
|
102
|
+
"prosekit-vue-tooltip": "./src/components/tooltip/index.gen.ts"
|
103
|
+
}
|
87
104
|
},
|
88
105
|
"scripts": {
|
89
106
|
"build:tsc": "tsc -b tsconfig.json",
|
90
|
-
"build:
|
107
|
+
"build:tsdown": "tsdown"
|
91
108
|
},
|
92
109
|
"types": "./dist/prosekit-vue.d.ts",
|
93
110
|
"typesVersions": {
|