@prosekit/vue 0.2.0 → 0.2.2
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/_tsup-dts-rollup.d.ts +56 -10
- package/dist/prosekit-vue.d.ts +2 -0
- package/dist/prosekit-vue.js +90 -69
- package/package.json +5 -5
- package/src/index.ts +0 -10
@@ -10,6 +10,7 @@ import { ComboBoxListProps as ComboBoxListProps_2 } from '@prosekit/lit/combo-bo
|
|
10
10
|
import { ComboBoxProps as ComboBoxProps_2 } from '@prosekit/lit/combo-box';
|
11
11
|
import { CommandArgs } from '@prosekit/core';
|
12
12
|
import { ComponentOptionsMixin } from 'vue';
|
13
|
+
import { ComputedRef } from 'vue';
|
13
14
|
import { CoreNodeView } from '@prosemirror-adapter/core';
|
14
15
|
import type { CoreNodeViewSpec } from '@prosemirror-adapter/core';
|
15
16
|
import type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core';
|
@@ -17,6 +18,7 @@ import type { Decoration } from '@prosekit/pm/view';
|
|
17
18
|
import type { DecorationSource } from '@prosekit/pm/view';
|
18
19
|
import { DefineComponent } from 'vue';
|
19
20
|
import { Editor } from '@prosekit/core';
|
21
|
+
import type { EditorState } from '@prosekit/pm/state';
|
20
22
|
import type { EditorView } from '@prosekit/pm/view';
|
21
23
|
import { Extension } from '@prosekit/core';
|
22
24
|
import { ExtensionTyping } from '@prosekit/core';
|
@@ -24,6 +26,7 @@ import { ExtractPropTypes } from 'vue';
|
|
24
26
|
import type { InjectionKey } from 'vue';
|
25
27
|
import { InlinePopoverProps as InlinePopoverProps_2 } from '@prosekit/lit/inline-popover';
|
26
28
|
import { Keymap } from '@prosekit/core';
|
29
|
+
import { MaybeRefOrGetter } from 'vue';
|
27
30
|
import type { Node as Node_2 } from '@prosekit/pm/model';
|
28
31
|
import type { NodeViewConstructor } from '@prosekit/pm/view';
|
29
32
|
import { Options } from 'tsup';
|
@@ -32,7 +35,7 @@ import { PositioningOptions } from '@prosekit/lit/autocomplete-popover';
|
|
32
35
|
import { PositioningOptions as PositioningOptions_alias_1 } from '@prosekit/lit/inline-popover';
|
33
36
|
import { Priority } from '@prosekit/core';
|
34
37
|
import { PublicProps } from 'vue';
|
35
|
-
import { Ref } from 'vue';
|
38
|
+
import type { Ref } from 'vue';
|
36
39
|
import { RendererElement } from 'vue';
|
37
40
|
import { RendererNode } from 'vue';
|
38
41
|
import { ResizableHandleProps as ResizableHandleProps_2 } from '@prosekit/lit/resizable-handle';
|
@@ -129,8 +132,6 @@ export { defineVueNodeView as defineVueNodeView_alias_1 }
|
|
129
132
|
*/
|
130
133
|
export declare function defineVueNodeViewFactory(nodeViewFactory: NodeViewFactory): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
131
134
|
|
132
|
-
export declare function injectEditor(): Editor;
|
133
|
-
|
134
135
|
declare const InlinePopover: (props: {
|
135
136
|
editor: Editor<any>;
|
136
137
|
} & PopoverProps_2 & {
|
@@ -164,6 +165,11 @@ export declare type PropsWithClass<P = unknown> = P & {
|
|
164
165
|
class?: string | undefined;
|
165
166
|
};
|
166
167
|
|
168
|
+
/**
|
169
|
+
* The root component for a ProseKit editor.
|
170
|
+
*
|
171
|
+
* @public
|
172
|
+
*/
|
167
173
|
declare const ProseKit: (props: ProseKitProps & {}) => any;
|
168
174
|
export { ProseKit }
|
169
175
|
export { ProseKit as ProseKit_alias_1 }
|
@@ -174,6 +180,9 @@ declare interface ProseKitProps {
|
|
174
180
|
export { ProseKitProps }
|
175
181
|
export { ProseKitProps as ProseKitProps_alias_1 }
|
176
182
|
|
183
|
+
/**
|
184
|
+
* @internal
|
185
|
+
*/
|
177
186
|
export declare function provideEditor(editor: Editor): void;
|
178
187
|
|
179
188
|
export declare const Resizable: (props: ResizableProps_2 & {
|
@@ -205,26 +214,63 @@ declare function useEditor<E extends Extension = any>(options?: {
|
|
205
214
|
export { useEditor }
|
206
215
|
export { useEditor as useEditor_alias_1 }
|
207
216
|
|
217
|
+
/**
|
218
|
+
* @internal
|
219
|
+
*/
|
220
|
+
export declare function useEditorContext<E extends Extension>(): Editor<E> | undefined;
|
221
|
+
|
222
|
+
/**
|
223
|
+
* @internal
|
224
|
+
*/
|
225
|
+
export declare function useEditorExtension(editorRef: MaybeRefOrGetter<Editor> | null | undefined, extensionRef: MaybeRefOrGetter<Extension | null> | null): void;
|
226
|
+
|
208
227
|
/**
|
209
228
|
* Add an extension to the editor.
|
210
229
|
*
|
211
|
-
*
|
212
|
-
* previous extension will be removed and the new one (if not null) will be
|
213
|
-
* added.
|
230
|
+
* @public
|
214
231
|
*/
|
215
|
-
declare function useExtension
|
232
|
+
declare function useExtension(
|
233
|
+
/**
|
234
|
+
* The ref to an extension to add to the editor. If it changes, the previous
|
235
|
+
* extension will be removed and the new one (if not null) will be added.
|
236
|
+
*/
|
237
|
+
extension: MaybeRefOrGetter<Extension | null>, options?: UseExtensionOptions): void;
|
216
238
|
export { useExtension }
|
217
239
|
export { useExtension as useExtension_alias_1 }
|
218
240
|
|
219
|
-
declare
|
241
|
+
declare interface UseExtensionOptions {
|
242
|
+
/**
|
243
|
+
* The editor to add the extension to. If not provided, it will use the
|
244
|
+
* editor from the nearest `ProseKit` component.
|
245
|
+
*/
|
246
|
+
editor?: MaybeRefOrGetter<Editor>;
|
247
|
+
/**
|
248
|
+
* Optional priority to add the extension with.
|
249
|
+
*/
|
220
250
|
priority?: Priority;
|
221
|
-
}
|
251
|
+
}
|
252
|
+
export { UseExtensionOptions }
|
253
|
+
export { UseExtensionOptions as UseExtensionOptions_alias_1 }
|
254
|
+
|
255
|
+
declare function useKeymap(keymap: MaybeRefOrGetter<Keymap>, options?: UseExtensionOptions): void;
|
222
256
|
export { useKeymap }
|
223
257
|
export { useKeymap as useKeymap_alias_1 }
|
224
258
|
|
225
259
|
export declare function useNodeViewFactory(): NodeViewFactory;
|
226
260
|
|
227
|
-
|
261
|
+
/**
|
262
|
+
* @internal
|
263
|
+
*/
|
264
|
+
export declare function usePriorityExtension<T extends Extension = Extension>(extension: MaybeRefOrGetter<T | null>, priority: Priority | null | undefined): ComputedRef<T | null>;
|
265
|
+
|
266
|
+
/**
|
267
|
+
* Calls the given handler whenever the editor state changes.
|
268
|
+
*
|
269
|
+
* @public
|
270
|
+
*/
|
271
|
+
declare function useStateUpdate(handler: (state: EditorState) => void, options?: UseExtensionOptions): void;
|
272
|
+
export { useStateUpdate }
|
273
|
+
export { useStateUpdate as useStateUpdate_alias_1 }
|
228
274
|
|
229
275
|
export declare function useVueNodeViewCreator(renderVueRenderer: VueRendererResult['renderVueRenderer'], removeVueRenderer: VueRendererResult['removeVueRenderer']): NodeViewFactory;
|
230
276
|
|
package/dist/prosekit-vue.d.ts
CHANGED
@@ -4,6 +4,8 @@ export { defineVueNodeView } from './_tsup-dts-rollup';
|
|
4
4
|
export { VueNodeViewOptions } from './_tsup-dts-rollup';
|
5
5
|
export { useEditor } from './_tsup-dts-rollup';
|
6
6
|
export { useExtension } from './_tsup-dts-rollup';
|
7
|
+
export { UseExtensionOptions } from './_tsup-dts-rollup';
|
7
8
|
export { useKeymap } from './_tsup-dts-rollup';
|
9
|
+
export { useStateUpdate } from './_tsup-dts-rollup';
|
8
10
|
export { VueNodeViewComponent } from './_tsup-dts-rollup';
|
9
11
|
export { VueNodeViewProps } from './_tsup-dts-rollup';
|
package/dist/prosekit-vue.js
CHANGED
@@ -2,26 +2,22 @@
|
|
2
2
|
import "@prosekit/core";
|
3
3
|
import { defineComponent as defineComponent4, h as h3 } from "vue";
|
4
4
|
|
5
|
-
// src/injection/editor-
|
6
|
-
import
|
7
|
-
import { inject, provide } from "vue";
|
8
|
-
var symbol = Symbol("
|
5
|
+
// src/injection/editor-context.ts
|
6
|
+
import "@prosekit/core";
|
7
|
+
import { inject, provide, toRef } from "vue";
|
8
|
+
var symbol = Symbol("prosekit-vue-editor-context");
|
9
9
|
function provideEditor(editor) {
|
10
|
-
provide(symbol, editor);
|
10
|
+
provide(symbol, toRef(editor));
|
11
11
|
}
|
12
|
-
function
|
13
|
-
|
14
|
-
if (!editor) {
|
15
|
-
throw new ProseKitError("Can't inject editor");
|
16
|
-
}
|
17
|
-
return editor;
|
12
|
+
function useEditorContext() {
|
13
|
+
return inject(symbol);
|
18
14
|
}
|
19
15
|
|
20
16
|
// src/views/vue-views-provider.ts
|
21
17
|
import { Fragment, defineComponent as defineComponent2, h as h2, provide as provide2 } from "vue";
|
22
18
|
|
23
19
|
// src/views/node-view/node-view-context.ts
|
24
|
-
import { ProseKitError
|
20
|
+
import { ProseKitError } from "@prosekit/core";
|
25
21
|
import { inject as inject2 } from "vue";
|
26
22
|
var nodeViewFactoryKey = Symbol(
|
27
23
|
"[ProseKit]useNodeViewFactory"
|
@@ -29,7 +25,7 @@ var nodeViewFactoryKey = Symbol(
|
|
29
25
|
function useNodeViewFactory() {
|
30
26
|
const nodeViewFactory = inject2(nodeViewFactoryKey);
|
31
27
|
if (!nodeViewFactory) {
|
32
|
-
throw new
|
28
|
+
throw new ProseKitError("Cannot find node view factory context.");
|
33
29
|
}
|
34
30
|
return nodeViewFactory;
|
35
31
|
}
|
@@ -183,7 +179,7 @@ var VueViewsProvider = defineComponent2({
|
|
183
179
|
});
|
184
180
|
|
185
181
|
// src/views/vue-views-comsumer.ts
|
186
|
-
import { computed, defineComponent as defineComponent3 } from "vue";
|
182
|
+
import { computed as computed2, defineComponent as defineComponent3 } from "vue";
|
187
183
|
|
188
184
|
// src/extensions/vue-node-view.ts
|
189
185
|
import {
|
@@ -206,56 +202,49 @@ function defineVueNodeViewFactory(nodeViewFactory) {
|
|
206
202
|
|
207
203
|
// src/hooks/use-extension.ts
|
208
204
|
import "@prosekit/core";
|
209
|
-
import
|
205
|
+
import "vue";
|
210
206
|
|
211
|
-
// src/hooks/use-editor.ts
|
212
|
-
import {
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
} from "@prosekit/core";
|
217
|
-
import {
|
218
|
-
onMounted,
|
219
|
-
onUnmounted as onUnmounted2,
|
220
|
-
shallowRef as shallowRef2,
|
221
|
-
triggerRef
|
222
|
-
} from "vue";
|
223
|
-
function useEditor(options) {
|
224
|
-
var _a;
|
225
|
-
const update = (_a = options == null ? void 0 : options.update) != null ? _a : false;
|
226
|
-
const editor = injectEditor();
|
227
|
-
const editorRef = shallowRef2(editor);
|
228
|
-
if (update) {
|
229
|
-
onMounted(() => {
|
230
|
-
const forceUpdate = () => triggerRef(editorRef);
|
231
|
-
const extension = union([
|
232
|
-
defineMountHandler(forceUpdate),
|
233
|
-
defineUpdateHandler(forceUpdate)
|
234
|
-
]);
|
235
|
-
const dispose = editor.use(extension);
|
236
|
-
onUnmounted2(dispose);
|
237
|
-
});
|
238
|
-
}
|
239
|
-
return editorRef;
|
240
|
-
}
|
241
|
-
|
242
|
-
// src/hooks/use-extension.ts
|
243
|
-
function useExtension(extension) {
|
244
|
-
const editor = useEditor();
|
207
|
+
// src/hooks/use-editor-extension.ts
|
208
|
+
import { EditorNotFoundError } from "@prosekit/core";
|
209
|
+
import { toValue, watchPostEffect } from "vue";
|
210
|
+
function useEditorExtension(editorRef, extensionRef) {
|
211
|
+
const editorContext = useEditorContext();
|
245
212
|
watchPostEffect((onCleanup) => {
|
246
|
-
const
|
247
|
-
|
248
|
-
|
213
|
+
const editor = toValue(editorRef) || toValue(editorContext);
|
214
|
+
const extension = toValue(extensionRef);
|
215
|
+
if (!editor) {
|
216
|
+
throw new EditorNotFoundError();
|
217
|
+
}
|
218
|
+
if (extension) {
|
219
|
+
onCleanup(editor.use(extension));
|
249
220
|
}
|
250
221
|
});
|
251
222
|
}
|
252
223
|
|
224
|
+
// src/hooks/use-priority-extension.ts
|
225
|
+
import { withPriority } from "@prosekit/core";
|
226
|
+
import { computed, toValue as toValue2 } from "vue";
|
227
|
+
function usePriorityExtension(extension, priority) {
|
228
|
+
return computed(() => {
|
229
|
+
const ext = toValue2(extension);
|
230
|
+
return ext && priority ? withPriority(ext, priority) : ext;
|
231
|
+
});
|
232
|
+
}
|
233
|
+
|
234
|
+
// src/hooks/use-extension.ts
|
235
|
+
function useExtension(extension, options) {
|
236
|
+
useEditorExtension(
|
237
|
+
options == null ? void 0 : options.editor,
|
238
|
+
usePriorityExtension(extension, options == null ? void 0 : options.priority)
|
239
|
+
);
|
240
|
+
}
|
241
|
+
|
253
242
|
// src/views/vue-views-comsumer.ts
|
254
243
|
var VueViewsConsumer = defineComponent3({
|
255
244
|
name: "VueViewsConsumer",
|
256
245
|
setup: () => {
|
257
246
|
const nodeViewFactory = useNodeViewFactory();
|
258
|
-
const extension =
|
247
|
+
const extension = computed2(() => {
|
259
248
|
return defineVueNodeViewFactory(nodeViewFactory);
|
260
249
|
});
|
261
250
|
useExtension(extension);
|
@@ -280,30 +269,62 @@ var ProseKit = defineComponent4(
|
|
280
269
|
{ props: ["editor"] }
|
281
270
|
);
|
282
271
|
|
283
|
-
// src/hooks/use-
|
284
|
-
import {
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
272
|
+
// src/hooks/use-editor.ts
|
273
|
+
import {
|
274
|
+
ProseKitError as ProseKitError2,
|
275
|
+
defineMountHandler,
|
276
|
+
defineUpdateHandler,
|
277
|
+
union
|
278
|
+
} from "@prosekit/core";
|
279
|
+
import {
|
280
|
+
onMounted,
|
281
|
+
onUnmounted as onUnmounted2,
|
282
|
+
shallowRef as shallowRef2,
|
283
|
+
triggerRef
|
284
|
+
} from "vue";
|
285
|
+
function useEditor(options) {
|
286
|
+
var _a;
|
287
|
+
const update = (_a = options == null ? void 0 : options.update) != null ? _a : false;
|
288
|
+
const editor = useEditorContext();
|
289
|
+
if (!editor) {
|
290
|
+
throw new ProseKitError2(
|
291
|
+
"useEditor must be used within the ProseKit component"
|
292
|
+
);
|
293
|
+
}
|
294
|
+
const editorRef = shallowRef2(editor);
|
295
|
+
if (update) {
|
296
|
+
onMounted(() => {
|
297
|
+
const forceUpdate = () => triggerRef(editorRef);
|
298
|
+
const extension = union([
|
299
|
+
defineMountHandler(forceUpdate),
|
300
|
+
defineUpdateHandler(forceUpdate)
|
301
|
+
]);
|
302
|
+
const dispose = editor.use(extension);
|
303
|
+
onUnmounted2(dispose);
|
304
|
+
});
|
305
|
+
}
|
306
|
+
return editorRef;
|
296
307
|
}
|
297
308
|
|
298
309
|
// src/hooks/use-keymap.ts
|
310
|
+
import { defineKeymap } from "@prosekit/core";
|
311
|
+
import { computed as computed3, toValue as toValue3 } from "vue";
|
299
312
|
function useKeymap(keymap, options) {
|
300
|
-
const extension = computed3(() => defineKeymap(
|
301
|
-
|
313
|
+
const extension = computed3(() => defineKeymap(toValue3(keymap)));
|
314
|
+
return useExtension(extension, options);
|
315
|
+
}
|
316
|
+
|
317
|
+
// src/hooks/use-state-update.ts
|
318
|
+
import { defineUpdateHandler as defineUpdateHandler2 } from "@prosekit/core";
|
319
|
+
function useStateUpdate(handler, options) {
|
320
|
+
const extension = defineUpdateHandler2((view) => handler(view.state));
|
321
|
+
return useExtension(extension, options);
|
302
322
|
}
|
303
323
|
export {
|
304
324
|
ProseKit,
|
305
325
|
defineVueNodeView,
|
306
326
|
useEditor,
|
307
327
|
useExtension,
|
308
|
-
useKeymap
|
328
|
+
useKeymap,
|
329
|
+
useStateUpdate
|
309
330
|
};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/vue",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.2.
|
4
|
+
"version": "0.2.2",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -95,8 +95,8 @@
|
|
95
95
|
"dist"
|
96
96
|
],
|
97
97
|
"dependencies": {
|
98
|
-
"@prosekit/core": "^0.2.
|
99
|
-
"@prosekit/lit": "^0.2.
|
98
|
+
"@prosekit/core": "^0.2.7",
|
99
|
+
"@prosekit/lit": "^0.2.1",
|
100
100
|
"@prosekit/pm": "^0.1.1",
|
101
101
|
"@prosemirror-adapter/core": "^0.2.6"
|
102
102
|
},
|
@@ -112,8 +112,8 @@
|
|
112
112
|
"@prosekit/dev": "*",
|
113
113
|
"tsup": "^8.0.1",
|
114
114
|
"typescript": "^5.3.3",
|
115
|
-
"vitest": "^1.2.
|
116
|
-
"vue": "^3.4.
|
115
|
+
"vitest": "^1.2.1",
|
116
|
+
"vue": "^3.4.15"
|
117
117
|
},
|
118
118
|
"scripts": {
|
119
119
|
"build:tsup": "tsup",
|
package/src/index.ts
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
export { ProseKit, type ProseKitProps } from './components/prosekit'
|
2
|
-
export {
|
3
|
-
defineVueNodeView,
|
4
|
-
type VueNodeViewOptions,
|
5
|
-
} from './extensions/vue-node-view'
|
6
|
-
export { useEditor } from './hooks/use-editor'
|
7
|
-
export { useExtension } from './hooks/use-extension'
|
8
|
-
export { useKeymap } from './hooks/use-keymap'
|
9
|
-
export type { VueNodeViewComponent } from './views/node-view/vue-node-view-options'
|
10
|
-
export type { VueNodeViewProps } from './views/node-view/vue-node-view-props'
|