@prosekit/vue 0.2.0 → 0.2.1

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.
@@ -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';
@@ -24,6 +25,7 @@ import { ExtractPropTypes } from 'vue';
24
25
  import type { InjectionKey } from 'vue';
25
26
  import { InlinePopoverProps as InlinePopoverProps_2 } from '@prosekit/lit/inline-popover';
26
27
  import { Keymap } from '@prosekit/core';
28
+ import { MaybeRefOrGetter } from 'vue';
27
29
  import type { Node as Node_2 } from '@prosekit/pm/model';
28
30
  import type { NodeViewConstructor } from '@prosekit/pm/view';
29
31
  import { Options } from 'tsup';
@@ -32,7 +34,7 @@ import { PositioningOptions } from '@prosekit/lit/autocomplete-popover';
32
34
  import { PositioningOptions as PositioningOptions_alias_1 } from '@prosekit/lit/inline-popover';
33
35
  import { Priority } from '@prosekit/core';
34
36
  import { PublicProps } from 'vue';
35
- import { Ref } from 'vue';
37
+ import type { Ref } from 'vue';
36
38
  import { RendererElement } from 'vue';
37
39
  import { RendererNode } from 'vue';
38
40
  import { ResizableHandleProps as ResizableHandleProps_2 } from '@prosekit/lit/resizable-handle';
@@ -129,8 +131,6 @@ export { defineVueNodeView as defineVueNodeView_alias_1 }
129
131
  */
130
132
  export declare function defineVueNodeViewFactory(nodeViewFactory: NodeViewFactory): Extension<ExtensionTyping<string, string, CommandArgs>>;
131
133
 
132
- export declare function injectEditor(): Editor;
133
-
134
134
  declare const InlinePopover: (props: {
135
135
  editor: Editor<any>;
136
136
  } & PopoverProps_2 & {
@@ -164,6 +164,11 @@ export declare type PropsWithClass<P = unknown> = P & {
164
164
  class?: string | undefined;
165
165
  };
166
166
 
167
+ /**
168
+ * The root component for a ProseKit editor.
169
+ *
170
+ * @public
171
+ */
167
172
  declare const ProseKit: (props: ProseKitProps & {}) => any;
168
173
  export { ProseKit }
169
174
  export { ProseKit as ProseKit_alias_1 }
@@ -174,6 +179,9 @@ declare interface ProseKitProps {
174
179
  export { ProseKitProps }
175
180
  export { ProseKitProps as ProseKitProps_alias_1 }
176
181
 
182
+ /**
183
+ * @internal
184
+ */
177
185
  export declare function provideEditor(editor: Editor): void;
178
186
 
179
187
  export declare const Resizable: (props: ResizableProps_2 & {
@@ -205,26 +213,54 @@ declare function useEditor<E extends Extension = any>(options?: {
205
213
  export { useEditor }
206
214
  export { useEditor as useEditor_alias_1 }
207
215
 
216
+ /**
217
+ * @internal
218
+ */
219
+ export declare function useEditorContext<E extends Extension>(): Editor<E> | undefined;
220
+
221
+ /**
222
+ * @internal
223
+ */
224
+ export declare function useEditorExtension(editorRef: MaybeRefOrGetter<Editor> | null | undefined, extensionRef: MaybeRefOrGetter<Extension | null> | null): void;
225
+
208
226
  /**
209
227
  * Add an extension to the editor.
210
228
  *
211
- * It accepts a ref to an optional extension. If the extension is changed, the
212
- * previous extension will be removed and the new one (if not null) will be
213
- * added.
229
+ * @public
214
230
  */
215
- declare function useExtension<T extends Extension = Extension>(extension: Ref<T | null>): void;
231
+ declare function useExtension(
232
+ /**
233
+ * The ref to an extension to add to the editor. If it changes, the previous
234
+ * extension will be removed and the new one (if not null) will be added.
235
+ */
236
+ extension: MaybeRefOrGetter<Extension | null>, options?: UseExtensionOptions): void;
216
237
  export { useExtension }
217
238
  export { useExtension as useExtension_alias_1 }
218
239
 
219
- declare function useKeymap(keymap: Ref<Keymap>, options?: {
240
+ declare interface UseExtensionOptions {
241
+ /**
242
+ * The editor to add the extension to. If not provided, it will use the
243
+ * editor from the nearest `ProseKit` component.
244
+ */
245
+ editor?: MaybeRefOrGetter<Editor>;
246
+ /**
247
+ * Optional priority to add the extension with.
248
+ */
220
249
  priority?: Priority;
221
- }): void;
250
+ }
251
+ export { UseExtensionOptions }
252
+ export { UseExtensionOptions as UseExtensionOptions_alias_1 }
253
+
254
+ declare function useKeymap(keymap: MaybeRefOrGetter<Keymap>, options?: UseExtensionOptions): void;
222
255
  export { useKeymap }
223
256
  export { useKeymap as useKeymap_alias_1 }
224
257
 
225
258
  export declare function useNodeViewFactory(): NodeViewFactory;
226
259
 
227
- export declare function usePriorityExtension<T extends Extension = Extension>(extension: Ref<T | null>, priority?: Priority | null): void;
260
+ /**
261
+ * @internal
262
+ */
263
+ export declare function usePriorityExtension<T extends Extension = Extension>(extension: MaybeRefOrGetter<T | null>, priority: Priority | null | undefined): ComputedRef<T | null>;
228
264
 
229
265
  export declare function useVueNodeViewCreator(renderVueRenderer: VueRendererResult['renderVueRenderer'], removeVueRenderer: VueRendererResult['removeVueRenderer']): NodeViewFactory;
230
266
 
@@ -4,6 +4,7 @@ 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';
8
9
  export { VueNodeViewComponent } from './_tsup-dts-rollup';
9
10
  export { VueNodeViewProps } from './_tsup-dts-rollup';
@@ -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-injection.ts
6
- import { ProseKitError } from "@prosekit/core";
7
- import { inject, provide } from "vue";
8
- var symbol = Symbol("ProseKitContext");
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 injectEditor() {
13
- const editor = inject(symbol);
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 as ProseKitError2 } from "@prosekit/core";
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 ProseKitError2("Cannot find node view factory context.");
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 { unref, watchPostEffect } from "vue";
210
-
211
- // src/hooks/use-editor.ts
212
- import {
213
- defineMountHandler,
214
- defineUpdateHandler,
215
- union
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
- }
205
+ import "vue";
241
206
 
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 ext = unref(extension);
247
- if (ext) {
248
- onCleanup(editor.value.use(ext));
213
+ const editor = toValue(editorRef) || toValue(editorContext);
214
+ const extension = toValue(extensionRef);
215
+ if (!editor) {
216
+ throw new EditorNotFoundError();
249
217
  }
218
+ if (extension) {
219
+ onCleanup(editor.use(extension));
220
+ }
221
+ });
222
+ }
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;
250
231
  });
251
232
  }
252
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 = computed(() => {
247
+ const extension = computed2(() => {
259
248
  return defineVueNodeViewFactory(nodeViewFactory);
260
249
  });
261
250
  useExtension(extension);
@@ -280,25 +269,49 @@ var ProseKit = defineComponent4(
280
269
  { props: ["editor"] }
281
270
  );
282
271
 
283
- // src/hooks/use-keymap.ts
284
- import { defineKeymap } from "@prosekit/core";
285
- import { computed as computed3, unref as unref3 } from "vue";
286
-
287
- // src/hooks/use-priority-extension.ts
288
- import { withPriority } from "@prosekit/core";
289
- import { computed as computed2, unref as unref2 } from "vue";
290
- function usePriorityExtension(extension, priority) {
291
- const extensionWithPriority = computed2(() => {
292
- const ext = unref2(extension);
293
- return ext && priority ? withPriority(ext, priority) : ext;
294
- });
295
- return useExtension(extensionWithPriority);
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(unref3(keymap)));
301
- usePriorityExtension(extension, options == null ? void 0 : options.priority);
313
+ const extension = computed3(() => defineKeymap(toValue3(keymap)));
314
+ return useExtension(extension, options);
302
315
  }
303
316
  export {
304
317
  ProseKit,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/vue",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
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.5",
99
- "@prosekit/lit": "^0.2.0",
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.0",
116
- "vue": "^3.4.13"
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'