@voicenter-team/voicenter-ui-plus 4.0.0-beta.0 → 4.0.0-beta.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.
Files changed (55) hide show
  1. package/README.md +48 -61
  2. package/library/assets/components/VcChatComposer/VcChatComposer.css +1 -1
  3. package/library/assets/components/VcMdEditor/ParameterNode.css +1 -1
  4. package/library/assets/components/VcMdEditor/VcMdEditorContent.css +1 -1
  5. package/library/components/VcChatComposer/VcChatComposer.vue.mjs +173 -139
  6. package/library/components/VcChatComposer/tiptap.mjs +45 -0
  7. package/library/components/VcCodeBlock/VcCodeBlock.vue.mjs +18 -5
  8. package/library/components/VcCodeBlock/highlight.mjs +8 -0
  9. package/library/components/VcEmojiPicker/VcEmojiPicker.vue.mjs +3 -4
  10. package/library/components/VcEmojiPicker/emojiData.mjs +16 -21
  11. package/library/components/VcHtmlEditor/VcHtmlEditor.vue.mjs +19 -12
  12. package/library/components/VcHtmlEditor/codemirror.mjs +14 -0
  13. package/library/components/VcImageUploader/VcImageUploader.vue.mjs +14 -8
  14. package/library/components/VcImageUploader/cropper.mjs +5 -0
  15. package/library/components/VcJsonSchema/Components/JsonCodeMirror.vue.mjs +16 -7
  16. package/library/components/VcJsonSchema/Components/codemirror.mjs +15 -0
  17. package/library/components/VcMdEditor/ParameterNode.vue.mjs +1 -1
  18. package/library/components/VcMdEditor/ParameterNode.vue2.mjs +2 -2
  19. package/library/components/VcMdEditor/VcMdEditor.vue.mjs +114 -108
  20. package/library/components/VcMdEditor/VcMdEditorContent.vue.mjs +18 -21
  21. package/library/components/VcMdEditor/ltrNumbersPlugin.mjs +42 -39
  22. package/library/components/VcMdEditor/mdEditor.config.mjs +107 -99
  23. package/library/components/VcMdEditor/milkdown.mjs +67 -0
  24. package/library/components/VcMdEditor/rtlCursorPlugin.mjs +3 -3
  25. package/library/components/VcPdfViewer/VcPdfDocument.vue.mjs +4 -8
  26. package/library/components/VcPdfViewer/pdfjslib.mjs +13 -16
  27. package/library/components/VcSoundplayer/VcSoundPlayerProgress.vue.mjs +1 -1
  28. package/library/components/VcSoundplayer/VcSoundPlayerWrapper.vue.mjs +17 -6
  29. package/library/components/VcSoundplayer/wavesurfer.mjs +14 -0
  30. package/library/style.css +3 -3
  31. package/library/style.css.br +0 -0
  32. package/library/style.css.gz +0 -0
  33. package/library/types/components/VcChatComposer/VcChatComposer.vue.d.ts +2 -1
  34. package/library/types/components/VcChatComposer/tiptap.d.ts +61 -0
  35. package/library/types/components/VcCodeBlock/highlight.d.ts +3 -0
  36. package/library/types/components/VcEmojiPicker/VcEmojiPicker.vue.d.ts +1 -1
  37. package/library/types/components/VcEmojiPicker/emojiData.d.ts +3 -3
  38. package/library/types/components/VcHtmlEditor/codemirror.d.ts +8 -0
  39. package/library/types/components/VcImageUploader/VcImageUploader.vue.d.ts +1 -1
  40. package/library/types/components/VcImageUploader/cropper.d.ts +34 -0
  41. package/library/types/components/VcJsonSchema/Components/codemirror.d.ts +9 -0
  42. package/library/types/components/VcMdEditor/ltrNumbersPlugin.d.ts +7 -13
  43. package/library/types/components/VcMdEditor/mdEditor.config.d.ts +12 -16
  44. package/library/types/components/VcMdEditor/milkdown.d.ts +25 -0
  45. package/library/types/components/VcMdEditor/rtlCursorPlugin.d.ts +3 -2
  46. package/library/types/components/VcPdfViewer/VcPdfDocument.vue.d.ts +1 -1
  47. package/library/types/components/VcPdfViewer/VcPdfDocumentPage.vue.d.ts +1 -1
  48. package/library/types/components/VcPdfViewer/pdfjslib.d.ts +1 -1
  49. package/library/types/components/VcSoundplayer/VcSoundPlayerWrapper.vue.d.ts +1 -1
  50. package/library/types/components/VcSoundplayer/wavesurfer.d.ts +8 -0
  51. package/library/types/types/VcSoundPlayer.types.d.ts +1 -1
  52. package/library/types/utils/optionalPeer.d.ts +33 -0
  53. package/library/utils/excelParser/helper.mjs +2 -7
  54. package/library/utils/optionalPeer.mjs +32 -0
  55. package/package.json +95 -1
@@ -1,8 +1,4 @@
1
- import { $prose } from "@milkdown/utils";
2
- import { Plugin, PluginKey } from "@milkdown/kit/prose/state";
3
- import { DecorationSet, Decoration } from "@milkdown/kit/prose/view";
4
1
  import { findNumberRuns } from "../../utils/numberRuns.mjs";
5
- const ltrNumbersKey = new PluginKey("VC_LTR_NUMBERS");
6
2
  const PLACEHOLDER = "";
7
3
  function textOfBlock(block) {
8
4
  let text = "";
@@ -12,44 +8,51 @@ function textOfBlock(block) {
12
8
  });
13
9
  return text;
14
10
  }
15
- function ltrNumberDecorations(doc) {
16
- const decorations = [];
17
- doc.descendants((node, position) => {
18
- if (!node.isTextblock) {
19
- return true;
20
- }
21
- if (!node.type.spec.code) {
22
- const start = position + 1;
23
- for (const [from, to] of findNumberRuns(textOfBlock(node))) {
24
- decorations.push(Decoration.inline(start + from, start + to, { dir: "ltr" }));
11
+ function createLtrNumbers(milkdown) {
12
+ const { Plugin, PluginKey } = milkdown.kit.proseState;
13
+ const { Decoration, DecorationSet } = milkdown.kit.proseView;
14
+ const ltrNumbersKey = new PluginKey("VC_LTR_NUMBERS");
15
+ function ltrNumberDecorations(doc) {
16
+ const decorations = [];
17
+ doc.descendants((node, position) => {
18
+ if (!node.isTextblock) {
19
+ return true;
25
20
  }
26
- }
27
- return false;
28
- });
29
- return DecorationSet.create(doc, decorations);
30
- }
31
- function ltrNumbersPlugin(enabled) {
32
- return $prose(() => new Plugin({
33
- key: ltrNumbersKey,
34
- state: {
35
- init: (_, state) => enabled() ? ltrNumberDecorations(state.doc) : DecorationSet.empty,
36
- apply: (transaction, decorations, _, state) => {
37
- if (!transaction.docChanged && !transaction.getMeta(ltrNumbersKey)) {
38
- return decorations;
21
+ if (!node.type.spec.code) {
22
+ const start = position + 1;
23
+ for (const [from, to] of findNumberRuns(textOfBlock(node))) {
24
+ decorations.push(Decoration.inline(start + from, start + to, { dir: "ltr" }));
39
25
  }
40
- return enabled() ? ltrNumberDecorations(state.doc) : DecorationSet.empty;
41
26
  }
42
- },
43
- props: {
44
- decorations: (state) => ltrNumbersKey.getState(state)
45
- }
46
- }));
47
- }
48
- function refreshLtrNumbers(view) {
49
- view.dispatch(view.state.tr.setMeta(ltrNumbersKey, true));
27
+ return false;
28
+ });
29
+ return DecorationSet.create(doc, decorations);
30
+ }
31
+ function ltrNumbersPlugin(enabled) {
32
+ return milkdown.utils.$prose(() => new Plugin({
33
+ key: ltrNumbersKey,
34
+ state: {
35
+ init: (_, state) => enabled() ? ltrNumberDecorations(state.doc) : DecorationSet.empty,
36
+ apply: (transaction, decorations, _, state) => {
37
+ if (!transaction.docChanged && !transaction.getMeta(ltrNumbersKey)) {
38
+ return decorations;
39
+ }
40
+ return enabled() ? ltrNumberDecorations(state.doc) : DecorationSet.empty;
41
+ }
42
+ },
43
+ props: {
44
+ decorations: (state) => ltrNumbersKey.getState(state)
45
+ }
46
+ }));
47
+ }
48
+ function refreshLtrNumbers(view) {
49
+ view.dispatch(view.state.tr.setMeta(ltrNumbersKey, true));
50
+ }
51
+ return {
52
+ ltrNumbersPlugin,
53
+ refreshLtrNumbers
54
+ };
50
55
  }
51
56
  export {
52
- ltrNumberDecorations,
53
- ltrNumbersPlugin,
54
- refreshLtrNumbers
57
+ createLtrNumbers
55
58
  };
@@ -1,13 +1,5 @@
1
1
  import { computed } from "vue";
2
2
  import { tVU } from "../../localization/index.mjs";
3
- import { Plugin, PluginKey, TextSelection } from "@milkdown/kit/prose/state";
4
- import { findWrapping } from "@milkdown/kit/prose/transform";
5
- import { editorViewCtx } from "@milkdown/kit/core";
6
- import { codeBlockSchema, listItemSchema, orderedListSchema, bulletListSchema, hrSchema, blockquoteSchema, paragraphSchema, headingSchema } from "@milkdown/kit/preset/commonmark";
7
- import { imageBlockSchema } from "@milkdown/kit/component/image-block";
8
- import { createTable } from "@milkdown/kit/preset/gfm";
9
- import { $prose } from "@milkdown/utils";
10
- import { DecorationSet, Decoration } from "@milkdown/kit/prose/view";
11
3
  import ParameterNode from "./ParameterNode.vue.mjs";
12
4
  import { Heading1, Heading2, Heading3, Heading4, Heading5, Heading6, ReceiptText, Quote, Minus, List, ListOrdered, ListChecks, Image, Code, Table, SquareFunction, ListStart, ListEnd, Braces, Brackets } from "@lucide/vue";
13
5
  const NodeParameterHiddenClass = "hidden-parameter-text";
@@ -34,30 +26,6 @@ const LIST_ITEM_SCHEMA = "listItemSchema";
34
26
  const IMAGE_SCHEMA = "imageBlockSchema";
35
27
  const CODE_BLOCK_SCHEMA = "codeBlockSchema";
36
28
  const TABLE_SCHEMA = "tableSchema";
37
- const SCHEMA_TYPES = {
38
- [HEADING_SCHEMA]: headingSchema,
39
- [PARAGRAPH_SCHEMA]: paragraphSchema,
40
- [QUOTES_SCHEMA]: blockquoteSchema,
41
- [DIVIDER_SCHEMA]: hrSchema,
42
- [LIST_BULLET_SCHEMA]: bulletListSchema,
43
- [LIST_ORDERED_SCHEMA]: orderedListSchema,
44
- [LIST_ITEM_SCHEMA]: listItemSchema,
45
- [IMAGE_SCHEMA]: imageBlockSchema,
46
- [CODE_BLOCK_SCHEMA]: codeBlockSchema,
47
- [TABLE_SCHEMA]: null
48
- };
49
- const SCHEMA_TYPE_ACTION = {
50
- [HEADING_SCHEMA]: setContentBlockType,
51
- [PARAGRAPH_SCHEMA]: setContentBlockType,
52
- [QUOTES_SCHEMA]: setContentAndWrapInBlockType,
53
- [DIVIDER_SCHEMA]: contentAddBlockType,
54
- [LIST_BULLET_SCHEMA]: setContentAndWrapInBlockType,
55
- [LIST_ORDERED_SCHEMA]: setContentAndWrapInBlockType,
56
- [LIST_ITEM_SCHEMA]: setContentAndWrapInBlockType,
57
- [IMAGE_SCHEMA]: contentAddBlockType,
58
- [CODE_BLOCK_SCHEMA]: contentAddBlockType,
59
- [TABLE_SCHEMA]: null
60
- };
61
29
  const headingMenuItems = computed(() => {
62
30
  return [
63
31
  {
@@ -170,53 +138,112 @@ const advancedMenuItems = computed(() => {
170
138
  }
171
139
  ];
172
140
  });
173
- function dispatchEditorAction(crepeInstance, actionType) {
174
- if (!crepeInstance) {
175
- return;
141
+ function createEditorActions(milkdown) {
142
+ const { editorViewCtx } = milkdown.kit.core;
143
+ const { TextSelection } = milkdown.kit.proseState;
144
+ const { findWrapping } = milkdown.kit.proseTransform;
145
+ const { createTable } = milkdown.kit.presetGfm;
146
+ const {
147
+ blockquoteSchema,
148
+ bulletListSchema,
149
+ codeBlockSchema,
150
+ headingSchema,
151
+ hrSchema,
152
+ listItemSchema,
153
+ orderedListSchema,
154
+ paragraphSchema
155
+ } = milkdown.kit.presetCommonmark;
156
+ const SCHEMA_TYPES = {
157
+ [HEADING_SCHEMA]: headingSchema,
158
+ [PARAGRAPH_SCHEMA]: paragraphSchema,
159
+ [QUOTES_SCHEMA]: blockquoteSchema,
160
+ [DIVIDER_SCHEMA]: hrSchema,
161
+ [LIST_BULLET_SCHEMA]: bulletListSchema,
162
+ [LIST_ORDERED_SCHEMA]: orderedListSchema,
163
+ [LIST_ITEM_SCHEMA]: listItemSchema,
164
+ [IMAGE_SCHEMA]: milkdown.kit.imageBlock.imageBlockSchema,
165
+ [CODE_BLOCK_SCHEMA]: codeBlockSchema,
166
+ [TABLE_SCHEMA]: null
167
+ };
168
+ const SCHEMA_TYPE_ACTION = {
169
+ [HEADING_SCHEMA]: setContentBlockType,
170
+ [PARAGRAPH_SCHEMA]: setContentBlockType,
171
+ [QUOTES_SCHEMA]: setContentAndWrapInBlockType,
172
+ [DIVIDER_SCHEMA]: contentAddBlockType,
173
+ [LIST_BULLET_SCHEMA]: setContentAndWrapInBlockType,
174
+ [LIST_ORDERED_SCHEMA]: setContentAndWrapInBlockType,
175
+ [LIST_ITEM_SCHEMA]: setContentAndWrapInBlockType,
176
+ [IMAGE_SCHEMA]: contentAddBlockType,
177
+ [CODE_BLOCK_SCHEMA]: contentAddBlockType,
178
+ [TABLE_SCHEMA]: null
179
+ };
180
+ function wrapInBlockType(tr, nodeType, attrs = null) {
181
+ const { $from, $to } = tr.selection;
182
+ const range = $from.blockRange($to);
183
+ const wrapping = range && findWrapping(range, nodeType, attrs);
184
+ if (!wrapping) return null;
185
+ return tr.wrap(range, wrapping);
176
186
  }
177
- crepeInstance.editor.action((ctx) => {
178
- const view = ctx.get(editorViewCtx);
179
- const { dispatch, state } = view;
180
- const schemaType = SCHEMA_TYPES[actionType.schemaType];
181
- const commandType = SCHEMA_TYPE_ACTION[actionType.schemaType];
182
- if (!schemaType || !commandType) return false;
183
- const command = commandType(schemaType.type(ctx), actionType.attrs);
184
- command(state, dispatch);
185
- });
186
- }
187
- function dispatchAdvancedEditorAction(crepeInstance, actionType) {
188
- if (!crepeInstance) {
189
- return;
187
+ function setContentAndWrapInBlockType(nodeType, attrs = null) {
188
+ return (state, dispatch) => {
189
+ const tr = wrapInBlockType(state.tr, nodeType, attrs);
190
+ if (!tr) return false;
191
+ if (dispatch) dispatch(tr.scrollIntoView());
192
+ return true;
193
+ };
190
194
  }
191
- if (actionType.schemaType === "tableSchema") {
192
- dispatchEditorTableAction(crepeInstance);
193
- } else {
194
- dispatchEditorAction(crepeInstance, actionType);
195
+ function dispatchEditorAction(crepeInstance, actionType) {
196
+ if (!crepeInstance) {
197
+ return;
198
+ }
199
+ crepeInstance.editor.action((ctx) => {
200
+ const view = ctx.get(editorViewCtx);
201
+ const { dispatch, state } = view;
202
+ const schemaType = SCHEMA_TYPES[actionType.schemaType];
203
+ const commandType = SCHEMA_TYPE_ACTION[actionType.schemaType];
204
+ if (!schemaType || !commandType) return false;
205
+ const command = commandType(schemaType.type(ctx), actionType.attrs);
206
+ command(state, dispatch);
207
+ });
195
208
  }
196
- }
197
- function dispatchEditorTableAction(crepeInstance) {
198
- if (!crepeInstance) {
199
- return;
209
+ function dispatchAdvancedEditorAction(crepeInstance, actionType) {
210
+ if (!crepeInstance) {
211
+ return;
212
+ }
213
+ if (actionType.schemaType === "tableSchema") {
214
+ dispatchEditorTableAction(crepeInstance);
215
+ } else {
216
+ dispatchEditorAction(crepeInstance, actionType);
217
+ }
200
218
  }
201
- crepeInstance.editor.action((ctx) => {
202
- const view = ctx.get(editorViewCtx);
203
- const { dispatch, state } = view;
204
- let { tr } = state;
205
- const from = tr.selection.from;
206
- const table = createTable(ctx, 3, 3);
207
- tr = tr.replaceSelectionWith(table);
208
- dispatch(tr);
209
- requestAnimationFrame(() => {
210
- const docSize = view.state.doc.content.size;
211
- const $pos = view.state.doc.resolve(
212
- from > docSize ? docSize : from < 0 ? 0 : from
213
- );
214
- const selection = TextSelection.near($pos);
215
- const tr2 = view.state.tr;
216
- tr2.setSelection(selection);
217
- dispatch(tr2.scrollIntoView());
219
+ function dispatchEditorTableAction(crepeInstance) {
220
+ if (!crepeInstance) {
221
+ return;
222
+ }
223
+ crepeInstance.editor.action((ctx) => {
224
+ const view = ctx.get(editorViewCtx);
225
+ const { dispatch, state } = view;
226
+ let { tr } = state;
227
+ const from = tr.selection.from;
228
+ const table = createTable(ctx, 3, 3);
229
+ tr = tr.replaceSelectionWith(table);
230
+ dispatch(tr);
231
+ requestAnimationFrame(() => {
232
+ const docSize = view.state.doc.content.size;
233
+ const $pos = view.state.doc.resolve(
234
+ from > docSize ? docSize : from < 0 ? 0 : from
235
+ );
236
+ const selection = TextSelection.near($pos);
237
+ const tr2 = view.state.tr;
238
+ tr2.setSelection(selection);
239
+ dispatch(tr2.scrollIntoView());
240
+ });
218
241
  });
219
- });
242
+ }
243
+ return {
244
+ dispatchEditorAction,
245
+ dispatchAdvancedEditorAction
246
+ };
220
247
  }
221
248
  function setBlockType(tr, nodeType, attrs = null) {
222
249
  const { from, to } = tr.selection;
@@ -244,29 +271,16 @@ function contentAddBlockType(nodeType, attrs = null) {
244
271
  return true;
245
272
  };
246
273
  }
247
- function wrapInBlockType(tr, nodeType, attrs = null) {
248
- const { $from, $to } = tr.selection;
249
- const range = $from.blockRange($to);
250
- const wrapping = range && findWrapping(range, nodeType, attrs);
251
- if (!wrapping) return null;
252
- return tr.wrap(range, wrapping);
253
- }
254
- function setContentAndWrapInBlockType(nodeType, attrs = null) {
255
- return (state, dispatch) => {
256
- const tr = wrapInBlockType(state.tr, nodeType, attrs);
257
- if (!tr) return false;
258
- if (dispatch) dispatch(tr.scrollIntoView());
259
- return true;
260
- };
261
- }
262
274
  const MUSTACHE_PATTERNS = {
263
275
  ARRAY_BLOCK: /{{#(\w+)}}[^{]*{{\.}}[^{]*{{\/\1}}/g,
264
276
  BLOCK_WITH_FIELDS: /{{#(\w+)}}(?:(?!{{[/#]).)*?:\s*{{.*?}}.*?{{\/\1}}/g,
265
277
  SINGLE_LINE_BLOCK: /^[ \t]*{{[/#](\w+)}}[ \t]*$/gm,
266
278
  SIMPLE_PARAMETER: /{{(\w+)}}/g
267
279
  };
268
- const useMustachePlugin = (replaceTest, widgetViewFactory) => {
269
- return $prose(() => {
280
+ const useMustachePlugin = (milkdown, replaceTest, widgetViewFactory) => {
281
+ const { Plugin, PluginKey } = milkdown.kit.proseState;
282
+ const { Decoration, DecorationSet } = milkdown.kit.proseView;
283
+ return milkdown.utils.$prose(() => {
270
284
  const getParameterWidget = widgetViewFactory({
271
285
  as: "span",
272
286
  component: ParameterNode
@@ -359,20 +373,14 @@ export {
359
373
  NodeParameterIcons,
360
374
  PARAGRAPH_SCHEMA,
361
375
  QUOTES_SCHEMA,
362
- SCHEMA_TYPES,
363
- SCHEMA_TYPE_ACTION,
364
376
  TABLE_SCHEMA,
365
377
  addEditorBlockType,
366
378
  advancedMenuItems,
367
379
  contentAddBlockType,
368
- dispatchAdvancedEditorAction,
369
- dispatchEditorAction,
370
- dispatchEditorTableAction,
380
+ createEditorActions,
371
381
  headingMenuItems,
372
382
  listMenuItems,
373
383
  setBlockType,
374
- setContentAndWrapInBlockType,
375
384
  setContentBlockType,
376
- useMustachePlugin,
377
- wrapInBlockType
385
+ useMustachePlugin
378
386
  };
@@ -0,0 +1,67 @@
1
+ import { inject } from "vue";
2
+ import { cachedLoad, loadOptionalPeer } from "../../utils/optionalPeer.mjs";
3
+ const loadMilkdown = cachedLoad(async () => {
4
+ const [
5
+ vue,
6
+ core,
7
+ proseState,
8
+ proseView,
9
+ proseModel,
10
+ proseTransform,
11
+ presetCommonmark,
12
+ presetGfm,
13
+ imageBlock,
14
+ utils,
15
+ crepe,
16
+ adapter,
17
+ langMarkdown,
18
+ codemirror
19
+ ] = await Promise.all([
20
+ loadOptionalPeer("@milkdown/vue", import("@milkdown/vue")),
21
+ loadOptionalPeer("@milkdown/kit", import("@milkdown/kit/core")),
22
+ loadOptionalPeer("@milkdown/kit", import("@milkdown/kit/prose/state")),
23
+ loadOptionalPeer("@milkdown/kit", import("@milkdown/kit/prose/view")),
24
+ loadOptionalPeer("@milkdown/kit", import("@milkdown/kit/prose/model")),
25
+ loadOptionalPeer("@milkdown/kit", import("@milkdown/kit/prose/transform")),
26
+ loadOptionalPeer("@milkdown/kit", import("@milkdown/kit/preset/commonmark")),
27
+ loadOptionalPeer("@milkdown/kit", import("@milkdown/kit/preset/gfm")),
28
+ loadOptionalPeer("@milkdown/kit", import("@milkdown/kit/component/image-block")),
29
+ loadOptionalPeer("@milkdown/utils", import("@milkdown/utils")),
30
+ loadOptionalPeer("@milkdown/crepe", import("@milkdown/crepe")),
31
+ loadOptionalPeer("@prosemirror-adapter/vue", import("@prosemirror-adapter/vue")),
32
+ loadOptionalPeer("@codemirror/lang-markdown", import("@codemirror/lang-markdown")),
33
+ loadOptionalPeer("vue-codemirror6", import("vue-codemirror6"))
34
+ ]);
35
+ return {
36
+ vue,
37
+ kit: {
38
+ core,
39
+ proseState,
40
+ proseView,
41
+ proseModel,
42
+ proseTransform,
43
+ presetCommonmark,
44
+ presetGfm,
45
+ imageBlock
46
+ },
47
+ utils,
48
+ crepe,
49
+ adapter,
50
+ langMarkdown,
51
+ codemirror
52
+ };
53
+ });
54
+ const milkdownKey = Symbol("VcMdEditorMilkdown");
55
+ function injectMilkdown() {
56
+ var _a;
57
+ const milkdown = (_a = inject(milkdownKey)) == null ? void 0 : _a.value;
58
+ if (!milkdown) {
59
+ throw new Error("[VcMdEditor] milkdown is used before it is loaded");
60
+ }
61
+ return milkdown;
62
+ }
63
+ export {
64
+ injectMilkdown,
65
+ loadMilkdown,
66
+ milkdownKey
67
+ };
@@ -1,6 +1,6 @@
1
- import { editorViewCtx } from "@milkdown/kit/core";
2
- import { TextSelection } from "@milkdown/kit/prose/state";
3
- const rtlCursorPlugin = (ctx) => {
1
+ const rtlCursorPlugin = (milkdown) => (ctx) => {
2
+ const { editorViewCtx } = milkdown.kit.core;
3
+ const { TextSelection } = milkdown.kit.proseState;
4
4
  return async () => {
5
5
  let eventHandler = null;
6
6
  const setupRTLCursorFix = () => {
@@ -157,10 +157,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
157
157
  };
158
158
  pdfDocument.value = await documentLoadingTask.promise;
159
159
  pageCount.value = ((_a = pdfDocument.value) == null ? void 0 : _a.numPages) || 0;
160
- } catch (e) {
160
+ } catch (error) {
161
161
  pdfDocument.value = void 0;
162
162
  pageCount.value = 0;
163
- console.error(e);
163
+ throw error;
164
164
  }
165
165
  }
166
166
  function onPrintDocument(dpi, pageNumberOnly) {
@@ -174,13 +174,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
174
174
  }
175
175
  watch(
176
176
  () => props.document,
177
- () => {
178
- loadDocument();
179
- }
177
+ () => loadDocument()
180
178
  );
181
- onMounted(() => {
182
- loadDocument();
183
- });
179
+ onMounted(() => loadDocument());
184
180
  onBeforeUnmount(() => {
185
181
  destroy();
186
182
  });
@@ -1,19 +1,16 @@
1
- let pdfPromise = null;
2
- function loadPdf() {
3
- if (!pdfPromise) {
4
- pdfPromise = (async () => {
5
- const pdfImport = import("pdfjs-dist/build/pdf.js");
6
- const viewerImport = import("pdfjs-dist/web/pdf_viewer");
7
- const [pdf, viewer] = await Promise.all([pdfImport, viewerImport]);
8
- pdf.GlobalWorkerOptions.workerSrc = new URL("./pdf.worker.min.js", import.meta.url).toString();
9
- return {
10
- pdf,
11
- PDFLinkService: viewer.PDFLinkService
12
- };
13
- })();
14
- }
15
- return pdfPromise;
16
- }
1
+ import { cachedLoad, loadOptionalPeer } from "../../utils/optionalPeer.mjs";
2
+ const loadPdf = cachedLoad(async () => {
3
+ const [pdf, { PDFLinkService }] = await Promise.all([
4
+ // @ts-expect-error -- no .d.ts ships beside build/pdf.js; the module is typed via the package root types.
5
+ loadOptionalPeer("pdfjs-dist", import("pdfjs-dist/build/pdf.js")),
6
+ loadOptionalPeer("pdfjs-dist", import("pdfjs-dist/web/pdf_viewer"))
7
+ ]);
8
+ pdf.GlobalWorkerOptions.workerSrc = new URL("./pdf.worker.min.js", import.meta.url).toString();
9
+ return {
10
+ pdf,
11
+ PDFLinkService
12
+ };
13
+ });
17
14
  export {
18
15
  loadPdf
19
16
  };
@@ -35,7 +35,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
35
35
  throw Error("You have to use only one VcSoundPlayerProgress Component");
36
36
  }
37
37
  if (componentId && initWavesurfer) {
38
- initWavesurfer(componentId, waveformProgress.value);
38
+ return initWavesurfer(componentId, waveformProgress.value);
39
39
  }
40
40
  });
41
41
  return (_ctx, _cache) => {
@@ -1,10 +1,9 @@
1
1
  import '../../assets/components/VcSoundplayer/VcSoundPlayerWrapper.css';
2
2
  import { defineComponent, ref, shallowRef, computed, watch, onBeforeUnmount, openBlock, createElementBlock, renderSlot, nextTick } from "vue";
3
- import WaveSurfer from "wavesurfer.js";
4
- import Hover from "wavesurfer.js/dist/plugins/hover";
5
3
  import { useRafFn } from "@vueuse/core";
6
4
  import { DEFAULT_OPTIONS, themedWaveColors, DEFAULT_HOVER_OPTIONS } from "./player.options.mjs";
7
5
  import { useSoundPlayerProvide } from "./useSoundPlayerProvideInject.mjs";
6
+ import { loadWaveSurfer } from "./wavesurfer.mjs";
8
7
  import UniqueComponentId from "../../utils/UniqueComponentId.mjs";
9
8
  const _hoisted_1 = { class: "vc-sound-player__wrapper" };
10
9
  const _sfc_main = /* @__PURE__ */ defineComponent({
@@ -38,6 +37,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
38
37
  const initialStartTime = ref(0);
39
38
  const currentTime = ref(0);
40
39
  const duration = ref(0);
40
+ let isUnmounted = false;
41
41
  const usedOptions = shallowRef({ ...DEFAULT_OPTIONS });
42
42
  const { pause: animatePause, resume: animationResume } = useRafFn(() => {
43
43
  var _a;
@@ -46,7 +46,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
46
46
  const isPlayingInProgress = computed(() => {
47
47
  return isPlaying.value || showReset.value;
48
48
  });
49
- function getAdditionalPlugins() {
49
+ function getAdditionalPlugins(Hover) {
50
50
  const plugins = [];
51
51
  if (props.showHover) {
52
52
  const option = Object.assign({}, DEFAULT_HOVER_OPTIONS, props.hoverOptions);
@@ -54,11 +54,17 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
54
54
  }
55
55
  return plugins;
56
56
  }
57
- function initWavesurfer(soundId, el) {
57
+ async function initWavesurfer(soundId, el) {
58
58
  if (isInitialized.value) return;
59
59
  isInitialized.value = true;
60
- nextTick(() => {
61
- const plugins = getAdditionalPlugins();
60
+ loading.value = true;
61
+ return loadWaveSurfer().finally(() => {
62
+ loading.value = false;
63
+ }).then(({ WaveSurfer, Hover }) => nextTick(() => {
64
+ if (isUnmounted) {
65
+ return;
66
+ }
67
+ const plugins = getAdditionalPlugins(Hover);
62
68
  const _height = props.options.height ? props.options.height : props.size === "sm" ? 16 : 32;
63
69
  const _options = {
64
70
  // the theme's colours, read where the player renders; options override them
@@ -77,6 +83,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
77
83
  volume.value = Math.min(props.defaultVolume, 100);
78
84
  }
79
85
  emit("ready", soundId);
86
+ }), (error) => {
87
+ isInitialized.value = false;
88
+ emit("on-error", error instanceof Error ? error : new Error(String(error)));
89
+ throw error;
80
90
  });
81
91
  }
82
92
  function loadingSound(startTime = 0) {
@@ -249,6 +259,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
249
259
  }
250
260
  );
251
261
  onBeforeUnmount(() => {
262
+ isUnmounted = true;
252
263
  if (wavesurfer.value) {
253
264
  wavesurfer.value.destroy();
254
265
  }
@@ -0,0 +1,14 @@
1
+ import { cachedLoad, loadOptionalPeer } from "../../utils/optionalPeer.mjs";
2
+ const loadWaveSurfer = cachedLoad(async () => {
3
+ const [{ default: WaveSurfer }, { default: Hover }] = await Promise.all([
4
+ loadOptionalPeer("wavesurfer.js", import("wavesurfer.js")),
5
+ loadOptionalPeer("wavesurfer.js", import("wavesurfer.js/dist/plugins/hover"))
6
+ ]);
7
+ return {
8
+ WaveSurfer,
9
+ Hover
10
+ };
11
+ });
12
+ export {
13
+ loadWaveSurfer
14
+ };