@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.
@@ -1,252 +1,219 @@
1
- import {
2
- provideEditor,
3
- useEditorContext
4
- } from "./chunk-BD3KKHO6.js";
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
- // src/components/prosekit.ts
7
- import { ProsemirrorAdapterProvider } from "@prosemirror-adapter/vue";
8
- import {
9
- defineComponent as defineComponent3,
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
- const editorContext = useEditorContext();
38
- watchPostEffect((onCleanup) => {
39
- const editor = toValue(editorRef) || toValue(editorContext);
40
- const extension = toValue(extensionRef);
41
- if (!editor) {
42
- throw new EditorNotFoundError();
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
- // src/hooks/use-priority-extension.ts
51
- import {
52
- withPriority
53
- } from "@prosekit/core";
54
- import {
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
- return computed(() => {
60
- const ext = toValue2(extension);
61
- return ext && priority ? withPriority(ext, priority) : ext;
62
- });
26
+ return computed(() => {
27
+ const ext = toValue(extension);
28
+ return ext && priority ? withPriority(ext, priority) : ext;
29
+ });
63
30
  }
64
31
 
65
- // src/hooks/use-extension.ts
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
- useEditorExtension(
68
- options?.editor,
69
- usePriorityExtension(extension, options?.priority)
70
- );
40
+ useEditorExtension(options?.editor, usePriorityExtension(extension, options?.priority));
71
41
  }
72
42
 
73
- // src/extensions/vue-mark-view.ts
43
+ //#endregion
44
+ //#region src/extensions/vue-mark-view.ts
74
45
  function withMarkViewProps(component) {
75
- return defineComponent({
76
- name: "MarkViewPropsWrapper",
77
- setup: () => {
78
- const props = useMarkViewContext();
79
- return () => h(component, props);
80
- }
81
- });
46
+ return defineComponent({
47
+ name: "MarkViewPropsWrapper",
48
+ setup: () => {
49
+ const props = useMarkViewContext();
50
+ return () => h(component, props);
51
+ }
52
+ });
82
53
  }
83
- var VueMarkViewsConsumer = /* @__PURE__ */ defineComponent({
84
- name: "VueMarkViewsConsumer",
85
- setup: () => {
86
- const markViewFactory = useMarkViewFactory();
87
- const extension = computed2(() => {
88
- return defineVueMarkViewFactory(markViewFactory);
89
- });
90
- useExtension(extension);
91
- return () => null;
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
- const { name, component, ...userOptions } = options;
96
- const args = {
97
- ...userOptions,
98
- component: withMarkViewProps(component)
99
- };
100
- return defineMarkViewComponent({
101
- group: "vue",
102
- name,
103
- args
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
- return defineMarkViewFactory({
108
- group: "vue",
109
- factory
110
- });
86
+ return defineMarkViewFactory({
87
+ group: "vue",
88
+ factory
89
+ });
111
90
  }
112
91
 
113
- // src/extensions/vue-node-view.ts
114
- import {
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
- return defineComponent2({
129
- name: "NodeViewPropsWrapper",
130
- setup: () => {
131
- const props = useNodeViewContext();
132
- return () => h2(component, props);
133
- }
134
- });
95
+ return defineComponent({
96
+ name: "NodeViewPropsWrapper",
97
+ setup: () => {
98
+ const props = useNodeViewContext();
99
+ return () => h(component, props);
100
+ }
101
+ });
135
102
  }
136
- var VueNodeViewsConsumer = /* @__PURE__ */ defineComponent2({
137
- name: "VueNodeViewsConsumer",
138
- setup: () => {
139
- const nodeViewFactory = useNodeViewFactory();
140
- const extension = computed3(() => {
141
- return defineVueNodeViewFactory(nodeViewFactory);
142
- });
143
- useExtension(extension);
144
- return () => null;
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
- const { name, component, ...userOptions } = options;
149
- const args = {
150
- ...userOptions,
151
- component: withNodeViewProps(component)
152
- };
153
- return defineNodeViewComponent({
154
- group: "vue",
155
- name,
156
- args
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
- return defineNodeViewFactory({
161
- group: "vue",
162
- factory
163
- });
135
+ return defineNodeViewFactory({
136
+ group: "vue",
137
+ factory
138
+ });
164
139
  }
165
140
 
166
- // src/components/prosekit.ts
167
- var ProseKit = defineComponent3(
168
- (props, { slots }) => {
169
- provideEditor(props.editor);
170
- return () => {
171
- return h3(ProsemirrorAdapterProvider, null, () => [
172
- h3(VueNodeViewsConsumer),
173
- h3(VueMarkViewsConsumer),
174
- slots.default?.()
175
- ]);
176
- };
177
- },
178
- { props: { editor: { type: Object, required: true } } }
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
- // src/hooks/use-doc-change.ts
182
- import { defineDocChangeHandler } from "@prosekit/core";
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
- const extension = defineDocChangeHandler((view) => handler(view.state.doc));
185
- return useExtension(extension, options);
174
+ const extension = defineDocChangeHandler((view) => handler(view.state.doc));
175
+ useExtension(extension, options);
186
176
  }
187
177
 
188
- // src/hooks/use-editor.ts
189
- import {
190
- defineMountHandler,
191
- defineUpdateHandler,
192
- ProseKitError,
193
- union
194
- } from "@prosekit/core";
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
- const update = options?.update ?? false;
203
- const editor = useEditorContext();
204
- if (!editor) {
205
- throw new ProseKitError(
206
- "useEditor must be used within the ProseKit component"
207
- );
208
- }
209
- const editorRef = shallowRef(editor);
210
- if (update) {
211
- onMounted(() => {
212
- const forceUpdate = () => triggerRef(editorRef);
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
- // src/hooks/use-keymap.ts
225
- import {
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
- const extension = computed4(() => defineKeymap(toValue3(keymap)));
234
- return useExtension(extension, options);
202
+ const extension = computed(() => defineKeymap(toValue(keymap)));
203
+ useExtension(extension, options);
235
204
  }
236
205
 
237
- // src/hooks/use-state-update.ts
238
- import { defineUpdateHandler as defineUpdateHandler2 } from "@prosekit/core";
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
- const extension = defineUpdateHandler2((view) => handler(view.state));
241
- return useExtension(extension, options);
214
+ const extension = defineUpdateHandler((view) => handler(view.state));
215
+ useExtension(extension, options);
242
216
  }
243
- export {
244
- ProseKit,
245
- defineVueMarkView,
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.12",
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.0",
68
- "@prosekit/pm": "^0.1.9",
69
- "@prosekit/web": "^0.5.7"
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.3",
81
+ "@vitejs/plugin-vue": "^5.2.4",
81
82
  "@vue/test-utils": "^2.4.6",
82
- "tsup": "^8.4.0",
83
- "typescript": "~5.7.3",
84
- "vitest": "^3.0.9",
85
- "vue": "^3.5.13",
86
- "@prosekit/dev": "0.0.0"
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:tsup": "tsup"
107
+ "build:tsdown": "tsdown"
91
108
  },
92
109
  "types": "./dist/prosekit-vue.d.ts",
93
110
  "typesVersions": {