@vizel/core 0.0.1-alpha.2 → 0.0.1-alpha.3

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 (47) hide show
  1. package/dist/index10.js +1 -1
  2. package/dist/index11.js +2 -2
  3. package/dist/index14.js +1 -1
  4. package/dist/index20.js +2 -2
  5. package/dist/index21.js +2 -2
  6. package/dist/index22.js +3 -3
  7. package/dist/index26.js +1 -1
  8. package/dist/index3.js +1 -1
  9. package/dist/index31.js +2 -2
  10. package/dist/index34.js +63 -16
  11. package/dist/index35.js +4 -58
  12. package/dist/index36.js +123 -15
  13. package/dist/index37.js +316 -37
  14. package/dist/index38.js +481 -58
  15. package/dist/index39.js +48 -4
  16. package/dist/index4.js +1 -1
  17. package/dist/index40.js +664 -108
  18. package/dist/index41.js +4 -327
  19. package/dist/index42.js +4 -487
  20. package/dist/index43.js +206 -647
  21. package/dist/index44.js +82 -4
  22. package/dist/index45.js +17 -4
  23. package/dist/index46.js +57 -237
  24. package/dist/index47.js +15 -82
  25. package/dist/index48.js +190 -274
  26. package/dist/index49.js +274 -190
  27. package/dist/index5.js +1 -1
  28. package/dist/index50.js +1408 -1467
  29. package/dist/index51.js +5 -1502
  30. package/dist/index52.js +1533 -695
  31. package/dist/index53.js +723 -5
  32. package/dist/index54.js +84 -21
  33. package/dist/index55.js +246 -10
  34. package/dist/index56.js +3 -7
  35. package/dist/index57.js +1231 -7
  36. package/dist/index58.js +731 -11
  37. package/dist/index59.js +21 -19
  38. package/dist/index6.js +1 -1
  39. package/dist/index60.js +10 -25
  40. package/dist/index61.js +6 -83
  41. package/dist/index62.js +7 -245
  42. package/dist/index63.js +11 -1229
  43. package/dist/index64.js +17 -732
  44. package/dist/index65.js +25 -3
  45. package/dist/index8.js +1 -1
  46. package/dist/index9.js +1 -1
  47. package/package.json +1 -1
package/dist/index40.js CHANGED
@@ -1,125 +1,681 @@
1
- import x from "@tiptap/extension-code-block";
2
- import { findChildren as p } from "@tiptap/core";
3
- import { Plugin as y, PluginKey as w } from "./index42.js";
4
- import { Decoration as N, DecorationSet as L } from "./index51.js";
5
- import C from "./index53.js";
6
- function v(e, i = []) {
7
- return e.flatMap((t) => {
8
- const a = [...i, ...t.properties ? t.properties.className : []];
9
- return t.children ? v(t.children, a) : {
10
- text: t.value,
11
- classes: a
12
- };
13
- });
1
+ import { Extension as H, commands as y, flattenExtensions as z, getExtensionField as C, generateJSON as L } from "@tiptap/core";
2
+ import { marked as P } from "./index52.js";
3
+ function _(e, n) {
4
+ const s = n.split(`
5
+ `).flatMap((r) => [r, ""]).map((r) => `${e}${r}`).join(`
6
+ `);
7
+ return s.slice(0, s.length - 1);
14
8
  }
15
- function f(e) {
16
- return e.value || e.children || [];
9
+ function O(e, n) {
10
+ const t = [];
11
+ return Array.from(e.keys()).forEach((s) => {
12
+ (!n || !n.marks || !n.marks.map((r) => r.type).includes(s)) && t.push(s);
13
+ }), t;
17
14
  }
18
- function P(e) {
19
- return !!C.getLanguage(e);
15
+ function F(e, n) {
16
+ const t = [];
17
+ return Array.from(n.entries()).forEach(([s, r]) => {
18
+ e.has(s) || t.push({ type: s, mark: r });
19
+ }), t;
20
20
  }
21
- function m({
22
- doc: e,
23
- name: i,
24
- lowlight: t,
25
- defaultLanguage: a
26
- }) {
27
- const n = [];
28
- return p(e, (r) => r.type.name === i).forEach((r) => {
29
- var u;
30
- let l = r.pos + 1;
31
- const s = r.node.attrs.language || a, h = t.listLanguages(), d = s && (h.includes(s) || P(s) || (u = t.registered) != null && u.call(t, s)) ? f(t.highlight(s, r.node.textContent)) : f(t.highlightAuto(r.node.textContent));
32
- v(d).forEach((g) => {
33
- const o = l + g.text.length;
34
- if (g.classes.length) {
35
- const c = N.inline(l, o, {
36
- class: g.classes.join(" ")
37
- });
38
- n.push(c);
39
- }
40
- l = o;
41
- });
42
- }), L.create(e, n);
21
+ function N(e, n, t, s) {
22
+ const r = !t, i = t && t.type === "text" && (!t.marks || t.marks.length === 0), o = t && t.type === "text" && t.marks && !s(n, new Map(t.marks.map((d) => [d.type, d]))), l = [];
23
+ if (r || i || o)
24
+ if (t && t.type === "text" && t.marks) {
25
+ const d = new Map(t.marks.map((a) => [a.type, a]));
26
+ Array.from(e.keys()).forEach((a) => {
27
+ d.has(a) || l.push(a);
28
+ });
29
+ } else (r || i) && l.push(...Array.from(e.keys()));
30
+ return l;
31
+ }
32
+ function $(e, n) {
33
+ let t = "";
34
+ return Array.from(e.keys()).reverse().forEach((s) => {
35
+ const r = e.get(s), i = n(s, r);
36
+ i && (t = i + t);
37
+ }), e.clear(), t;
43
38
  }
44
- function _(e) {
45
- return typeof e == "function";
39
+ function S(e, n, t) {
40
+ let s = "";
41
+ return Array.from(e.entries()).forEach(([r, i]) => {
42
+ const o = t(r, i);
43
+ o && (s += o), n.set(r, i);
44
+ }), s;
46
45
  }
47
- function A({
48
- name: e,
49
- lowlight: i,
50
- defaultLanguage: t
51
- }) {
52
- if (!["highlight", "highlightAuto", "listLanguages"].every((n) => _(i[n])))
53
- throw Error("You should provide an instance of lowlight to use the code-block-lowlight extension");
54
- const a = new y({
55
- key: new w("lowlight"),
56
- state: {
57
- init: (n, { doc: r }) => m({
58
- doc: r,
59
- name: e,
60
- lowlight: i,
61
- defaultLanguage: t
46
+ function R(e) {
47
+ const t = (e.raw || e.text || "").match(/^(\s*)[-+*]\s+\[([ xX])\]\s+/);
48
+ return t ? { isTask: !0, checked: t[2].toLowerCase() === "x", indentLevel: t[1].length } : { isTask: !1, indentLevel: 0 };
49
+ }
50
+ function E(e, n) {
51
+ return typeof e != "string" ? "json" : n;
52
+ }
53
+ var j = class {
54
+ /**
55
+ * Create a MarkdownManager.
56
+ * @param options.marked Optional marked instance to use (injected).
57
+ * @param options.markedOptions Optional options to pass to marked.setOptions
58
+ * @param options.indentation Indentation settings (style and size).
59
+ * @param options.extensions An array of Tiptap extensions to register for markdown parsing and rendering.
60
+ */
61
+ constructor(e) {
62
+ this.baseExtensions = [], this.extensions = [], this.lastParseResult = null;
63
+ var n, t, s, r, i;
64
+ this.markedInstance = (n = e?.marked) != null ? n : P, this.lexer = new this.markedInstance.Lexer(), this.indentStyle = (s = (t = e?.indentation) == null ? void 0 : t.style) != null ? s : "space", this.indentSize = (i = (r = e?.indentation) == null ? void 0 : r.size) != null ? i : 2, this.baseExtensions = e?.extensions || [], e?.markedOptions && typeof this.markedInstance.setOptions == "function" && this.markedInstance.setOptions(e.markedOptions), this.registry = /* @__PURE__ */ new Map(), this.nodeTypeRegistry = /* @__PURE__ */ new Map(), e?.extensions && (this.baseExtensions = e.extensions, z(e.extensions).forEach((l) => this.registerExtension(l, !1))), this.lexer = new this.markedInstance.Lexer();
65
+ }
66
+ /** Returns the underlying marked instance. */
67
+ get instance() {
68
+ return this.markedInstance;
69
+ }
70
+ /** Returns the correct indentCharacter (space or tab) */
71
+ get indentCharacter() {
72
+ return this.indentStyle === "space" ? " " : " ";
73
+ }
74
+ /** Returns the correct indentString repeated X times */
75
+ get indentString() {
76
+ return this.indentCharacter.repeat(this.indentSize);
77
+ }
78
+ /** Helper to quickly check whether a marked instance is available. */
79
+ hasMarked() {
80
+ return !!this.markedInstance;
81
+ }
82
+ /**
83
+ * Register a Tiptap extension (Node/Mark/Extension). This will read
84
+ * `markdownName`, `parseMarkdown`, `renderMarkdown` and `priority` from the
85
+ * extension config (using the same resolution used across the codebase).
86
+ */
87
+ registerExtension(e, n = !0) {
88
+ var t, s;
89
+ this.extensions.push(e);
90
+ const r = e.name, i = C(e, "markdownTokenName") || r, o = C(e, "parseMarkdown"), l = C(e, "renderMarkdown"), d = C(e, "markdownTokenizer"), a = (t = C(e, "markdownOptions")) != null ? t : null, c = (s = a?.indentsContent) != null ? s : !1, p = {
91
+ tokenName: i,
92
+ nodeName: r,
93
+ parseMarkdown: o,
94
+ renderMarkdown: l,
95
+ isIndenting: c,
96
+ tokenizer: d
97
+ };
98
+ if (i && o) {
99
+ const u = this.registry.get(i) || [];
100
+ u.push(p), this.registry.set(i, u);
101
+ }
102
+ if (l) {
103
+ const u = this.nodeTypeRegistry.get(r) || [];
104
+ u.push(p), this.nodeTypeRegistry.set(r, u);
105
+ }
106
+ d && this.hasMarked() && (this.registerTokenizer(d), n && (this.lexer = new this.markedInstance.Lexer()));
107
+ }
108
+ /**
109
+ * Register a custom tokenizer with marked.js for parsing non-standard markdown syntax.
110
+ */
111
+ registerTokenizer(e) {
112
+ if (!this.hasMarked())
113
+ return;
114
+ const { name: n, start: t, level: s = "inline", tokenize: r } = e, l = {
115
+ inlineTokens: (c) => this.lexer.inlineTokens(c),
116
+ blockTokens: (c) => this.lexer.blockTokens(c)
117
+ };
118
+ let d;
119
+ t ? d = typeof t == "function" ? t : (c) => c.indexOf(t) : d = (c) => {
120
+ const p = r(c, [], l);
121
+ return p && p.raw ? c.indexOf(p.raw) : -1;
122
+ };
123
+ const a = {
124
+ name: n,
125
+ level: s,
126
+ start: d,
127
+ tokenizer: (c, p) => {
128
+ const u = r(c, p, l);
129
+ if (u && u.type)
130
+ return {
131
+ ...u,
132
+ type: u.type || n,
133
+ raw: u.raw || "",
134
+ tokens: u.tokens || []
135
+ };
136
+ },
137
+ childTokens: []
138
+ };
139
+ this.markedInstance.use({
140
+ extensions: [a]
141
+ });
142
+ }
143
+ /** Get registered handlers for a token type and try each until one succeeds. */
144
+ getHandlersForToken(e) {
145
+ try {
146
+ return this.registry.get(e) || [];
147
+ } catch {
148
+ return [];
149
+ }
150
+ }
151
+ /** Get the first handler for a token type (for backwards compatibility). */
152
+ getHandlerForToken(e) {
153
+ const n = this.getHandlersForToken(e);
154
+ if (n.length > 0)
155
+ return n[0];
156
+ const t = this.getHandlersForNodeType(e);
157
+ return t.length > 0 ? t[0] : void 0;
158
+ }
159
+ /** Get registered handlers for a node type (for rendering). */
160
+ getHandlersForNodeType(e) {
161
+ try {
162
+ return this.nodeTypeRegistry.get(e) || [];
163
+ } catch {
164
+ return [];
165
+ }
166
+ }
167
+ /**
168
+ * Serialize a ProseMirror-like JSON document (or node array) to a Markdown string
169
+ * using registered renderers and fallback renderers.
170
+ */
171
+ serialize(e) {
172
+ return e ? Array.isArray(e) ? this.renderNodes(e, e) : this.renderNodes(e, e) : "";
173
+ }
174
+ /**
175
+ * Parse markdown string into Tiptap JSON document using registered extension handlers.
176
+ */
177
+ parse(e) {
178
+ if (!this.hasMarked())
179
+ throw new Error("No marked instance available for parsing");
180
+ const n = this.markedInstance.lexer(e);
181
+ return {
182
+ type: "doc",
183
+ content: this.parseTokens(n)
184
+ };
185
+ }
186
+ /**
187
+ * Convert an array of marked tokens into Tiptap JSON nodes using registered extension handlers.
188
+ */
189
+ parseTokens(e) {
190
+ return e.map((n) => this.parseToken(n)).filter((n) => n !== null).flatMap((n) => Array.isArray(n) ? n : [n]);
191
+ }
192
+ /**
193
+ * Parse a single token into Tiptap JSON using the appropriate registered handler.
194
+ */
195
+ parseToken(e) {
196
+ if (!e.type)
197
+ return null;
198
+ if (e.type === "list")
199
+ return this.parseListToken(e);
200
+ const n = this.getHandlersForToken(e.type), t = this.createParseHelpers();
201
+ if (n.find((r) => {
202
+ if (!r.parseMarkdown)
203
+ return !1;
204
+ const i = r.parseMarkdown(e, t), o = this.normalizeParseResult(i);
205
+ return o && (!Array.isArray(o) || o.length > 0) ? (this.lastParseResult = o, !0) : !1;
206
+ }) && this.lastParseResult) {
207
+ const r = this.lastParseResult;
208
+ return this.lastParseResult = null, r;
209
+ }
210
+ return this.parseFallbackToken(e);
211
+ }
212
+ /**
213
+ * Parse a list token, handling mixed bullet and task list items by splitting them into separate lists.
214
+ * This ensures that consecutive task items and bullet items are grouped and parsed as separate list nodes.
215
+ *
216
+ * @param token The list token to parse
217
+ * @returns Array of parsed list nodes, or null if parsing fails
218
+ */
219
+ parseListToken(e) {
220
+ if (!e.items || e.items.length === 0)
221
+ return this.parseTokenWithHandlers(e);
222
+ const n = e.items.some((l) => R(l).isTask), t = e.items.some((l) => !R(l).isTask);
223
+ if (!n || !t || this.getHandlersForToken("taskList").length === 0)
224
+ return this.parseTokenWithHandlers(e);
225
+ const s = [];
226
+ let r = [], i = null;
227
+ for (let l = 0; l < e.items.length; l += 1) {
228
+ const d = e.items[l], { isTask: a, checked: c, indentLevel: p } = R(d);
229
+ let u = d;
230
+ if (a) {
231
+ const m = (d.raw || d.text || "").split(`
232
+ `), g = m[0].match(/^\s*[-+*]\s+\[([ xX])\]\s+(.*)$/), h = g ? g[2] : "";
233
+ let k = [];
234
+ if (m.length > 1 && m.slice(1).join(`
235
+ `).trim()) {
236
+ const T = m.slice(1), v = T.filter((A) => A.trim());
237
+ if (v.length > 0) {
238
+ const A = Math.min(...v.map((x) => x.length - x.trimStart().length)), I = T.map((x) => x.trim() ? x.slice(A) : "").join(`
239
+ `).trim();
240
+ I && (k = this.markedInstance.lexer(`${I}
241
+ `));
242
+ }
243
+ }
244
+ u = {
245
+ type: "taskItem",
246
+ raw: "",
247
+ mainContent: h,
248
+ indentLevel: p,
249
+ checked: c ?? !1,
250
+ text: h,
251
+ tokens: this.lexer.inlineTokens(h),
252
+ nestedTokens: k
253
+ };
254
+ }
255
+ const w = a ? "taskList" : "list";
256
+ i !== w ? (r.length > 0 && s.push({ type: i, items: r }), r = [u], i = w) : r.push(u);
257
+ }
258
+ r.length > 0 && s.push({ type: i, items: r });
259
+ const o = [];
260
+ for (let l = 0; l < s.length; l += 1) {
261
+ const d = s[l], a = { ...e, type: d.type, items: d.items }, c = this.parseToken(a);
262
+ c && (Array.isArray(c) ? o.push(...c) : o.push(c));
263
+ }
264
+ return o.length > 0 ? o : null;
265
+ }
266
+ /**
267
+ * Parse a token using registered handlers (extracted for reuse).
268
+ */
269
+ parseTokenWithHandlers(e) {
270
+ if (!e.type)
271
+ return null;
272
+ const n = this.getHandlersForToken(e.type), t = this.createParseHelpers();
273
+ if (n.find((r) => {
274
+ if (!r.parseMarkdown)
275
+ return !1;
276
+ const i = r.parseMarkdown(e, t), o = this.normalizeParseResult(i);
277
+ return o && (!Array.isArray(o) || o.length > 0) ? (this.lastParseResult = o, !0) : !1;
278
+ }) && this.lastParseResult) {
279
+ const r = this.lastParseResult;
280
+ return this.lastParseResult = null, r;
281
+ }
282
+ return this.parseFallbackToken(e);
283
+ }
284
+ /**
285
+ * Creates helper functions for parsing markdown tokens.
286
+ * @returns An object containing helper functions for parsing.
287
+ */
288
+ createParseHelpers() {
289
+ return {
290
+ parseInline: (e) => this.parseInlineTokens(e),
291
+ parseChildren: (e) => this.parseTokens(e),
292
+ createTextNode: (e, n) => ({
293
+ type: "text",
294
+ text: e,
295
+ marks: n || void 0
62
296
  }),
63
- apply: (n, r, u, l) => {
64
- const s = u.selection.$head.parent.type.name, h = l.selection.$head.parent.type.name, d = p(u.doc, (o) => o.type.name === e), g = p(l.doc, (o) => o.type.name === e);
65
- return n.docChanged && // Apply decorations if:
66
- // selection includes named node,
67
- ([s, h].includes(e) || // OR transaction adds/removes named node,
68
- g.length !== d.length || // OR transaction has changes that completely encapsulte a node
69
- // (for example, a transaction that affects the entire document).
70
- // Such transactions can happen during collab syncing via y-prosemirror, for example.
71
- n.steps.some((o) => (
72
- // @ts-ignore
73
- o.from !== void 0 && // @ts-ignore
74
- o.to !== void 0 && d.some((c) => (
75
- // @ts-ignore
76
- c.pos >= o.from && // @ts-ignore
77
- c.pos + c.node.nodeSize <= o.to
78
- ))
79
- ))) ? m({
80
- doc: n.doc,
81
- name: e,
82
- lowlight: i,
83
- defaultLanguage: t
84
- }) : r.map(n.mapping, n.doc);
297
+ createNode: (e, n, t) => {
298
+ const s = {
299
+ type: e,
300
+ attrs: n || void 0,
301
+ content: t || void 0
302
+ };
303
+ return (!n || Object.keys(n).length === 0) && delete s.attrs, s;
304
+ },
305
+ applyMark: (e, n, t) => ({
306
+ mark: e,
307
+ content: n,
308
+ attrs: t && Object.keys(t).length > 0 ? t : void 0
309
+ })
310
+ };
311
+ }
312
+ /**
313
+ * Escape special regex characters in a string.
314
+ */
315
+ escapeRegex(e) {
316
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
317
+ }
318
+ /**
319
+ * Parse inline tokens (bold, italic, links, etc.) into text nodes with marks.
320
+ * This is the complex part that handles mark nesting and boundaries.
321
+ */
322
+ parseInlineTokens(e) {
323
+ var n, t, s, r;
324
+ const i = [];
325
+ for (let o = 0; o < e.length; o += 1) {
326
+ const l = e[o];
327
+ if (l.type === "text")
328
+ i.push({
329
+ type: "text",
330
+ text: l.text || ""
331
+ });
332
+ else if (l.type === "html") {
333
+ const d = ((t = (n = l.raw) != null ? n : l.text) != null ? t : "").toString(), a = /^<\/[\s]*[\w-]+/i.test(d), c = d.match(/^<[\s]*([\w-]+)(\s|>|\/|$)/i);
334
+ if (!a && c && !/\/>$/.test(d)) {
335
+ const u = c[1], w = this.escapeRegex(u), M = new RegExp(`^<\\/\\s*${w}\\b`, "i");
336
+ let m = -1;
337
+ const g = [d];
338
+ for (let h = o + 1; h < e.length; h += 1) {
339
+ const k = e[h], f = ((r = (s = k.raw) != null ? s : k.text) != null ? r : "").toString();
340
+ if (g.push(f), k.type === "html" && M.test(f)) {
341
+ m = h;
342
+ break;
343
+ }
344
+ }
345
+ if (m !== -1) {
346
+ const h = g.join(""), k = {
347
+ type: "html",
348
+ raw: h,
349
+ text: h,
350
+ block: !1
351
+ }, f = this.parseHTMLToken(k);
352
+ if (f) {
353
+ const T = this.normalizeParseResult(f);
354
+ Array.isArray(T) ? i.push(...T) : T && i.push(T);
355
+ }
356
+ o = m;
357
+ continue;
358
+ }
359
+ }
360
+ const p = this.parseHTMLToken(l);
361
+ if (p) {
362
+ const u = this.normalizeParseResult(p);
363
+ Array.isArray(u) ? i.push(...u) : u && i.push(u);
364
+ }
365
+ } else if (l.type) {
366
+ const d = this.getHandlerForToken(l.type);
367
+ if (d && d.parseMarkdown) {
368
+ const a = this.createParseHelpers(), c = d.parseMarkdown(l, a);
369
+ if (this.isMarkResult(c)) {
370
+ const p = this.applyMarkToContent(c.mark, c.content, c.attrs);
371
+ i.push(...p);
372
+ } else {
373
+ const p = this.normalizeParseResult(c);
374
+ Array.isArray(p) ? i.push(...p) : p && i.push(p);
375
+ }
376
+ } else l.tokens && i.push(...this.parseInlineTokens(l.tokens));
85
377
  }
86
- },
87
- props: {
88
- decorations(n) {
89
- return a.getState(n);
378
+ }
379
+ return i;
380
+ }
381
+ /**
382
+ * Apply a mark to content nodes.
383
+ */
384
+ applyMarkToContent(e, n, t) {
385
+ return n.map((s) => {
386
+ if (s.type === "text") {
387
+ const r = s.marks || [], i = t ? { type: e, attrs: t } : { type: e };
388
+ return {
389
+ ...s,
390
+ marks: [...r, i]
391
+ };
90
392
  }
393
+ return {
394
+ ...s,
395
+ content: s.content ? this.applyMarkToContent(e, s.content, t) : void 0
396
+ };
397
+ });
398
+ }
399
+ /**
400
+ * Check if a parse result represents a mark to be applied.
401
+ */
402
+ isMarkResult(e) {
403
+ return e && typeof e == "object" && "mark" in e;
404
+ }
405
+ /**
406
+ * Normalize parse results to ensure they're valid JSONContent.
407
+ */
408
+ normalizeParseResult(e) {
409
+ return e ? this.isMarkResult(e) ? e.content : e : null;
410
+ }
411
+ /**
412
+ * Fallback parsing for common tokens when no specific handler is registered.
413
+ */
414
+ parseFallbackToken(e) {
415
+ switch (e.type) {
416
+ case "paragraph":
417
+ return {
418
+ type: "paragraph",
419
+ content: e.tokens ? this.parseInlineTokens(e.tokens) : []
420
+ };
421
+ case "heading":
422
+ return {
423
+ type: "heading",
424
+ attrs: { level: e.depth || 1 },
425
+ content: e.tokens ? this.parseInlineTokens(e.tokens) : []
426
+ };
427
+ case "text":
428
+ return {
429
+ type: "text",
430
+ text: e.text || ""
431
+ };
432
+ case "html":
433
+ return this.parseHTMLToken(e);
434
+ case "space":
435
+ return null;
436
+ default:
437
+ return e.tokens ? this.parseTokens(e.tokens) : null;
91
438
  }
92
- });
93
- return a;
94
- }
95
- var D = x.extend({
439
+ }
440
+ /**
441
+ * Parse HTML tokens using extensions' parseHTML methods.
442
+ * This allows HTML within markdown to be parsed according to extension rules.
443
+ */
444
+ parseHTMLToken(e) {
445
+ const n = e.text || e.raw || "";
446
+ if (!n.trim())
447
+ return null;
448
+ try {
449
+ const t = L(n, this.baseExtensions);
450
+ return t.type === "doc" && t.content ? e.block ? t.content : t.content.length === 1 && t.content[0].type === "paragraph" && t.content[0].content ? t.content[0].content : t.content : t;
451
+ } catch (t) {
452
+ throw new Error(`Failed to parse HTML in markdown: ${t}`);
453
+ }
454
+ }
455
+ renderNodeToMarkdown(e, n, t = 0, s = 0) {
456
+ var r;
457
+ if (e.type === "text")
458
+ return e.text || "";
459
+ if (!e.type)
460
+ return "";
461
+ const i = this.getHandlerForToken(e.type);
462
+ if (!i)
463
+ return "";
464
+ const o = {
465
+ renderChildren: (a, c) => {
466
+ const p = i.isIndenting ? s + 1 : s;
467
+ return !Array.isArray(a) && a.content ? this.renderNodes(a.content, e, c || "", t, p) : this.renderNodes(a, e, c || "", t, p);
468
+ },
469
+ indent: (a) => this.indentString + a,
470
+ wrapInBlock: _
471
+ }, l = {
472
+ index: t,
473
+ level: s,
474
+ parentType: n?.type,
475
+ meta: {}
476
+ };
477
+ return ((r = i.renderMarkdown) == null ? void 0 : r.call(i, e, o, l)) || "";
478
+ }
479
+ /**
480
+ * Render a node or an array of nodes. Parent type controls how children
481
+ * are joined (which determines newline insertion between children).
482
+ */
483
+ renderNodes(e, n, t = "", s = 0, r = 0) {
484
+ return Array.isArray(e) ? this.renderNodesWithMarkBoundaries(e, n, t, r) : e.type ? this.renderNodeToMarkdown(e, n, s, r) : "";
485
+ }
486
+ /**
487
+ * Render an array of nodes while properly tracking mark boundaries.
488
+ * This handles cases where marks span across multiple text nodes.
489
+ */
490
+ renderNodesWithMarkBoundaries(e, n, t = "", s = 0) {
491
+ const r = [], i = /* @__PURE__ */ new Map();
492
+ return e.forEach((o, l) => {
493
+ const d = l < e.length - 1 ? e[l + 1] : null;
494
+ if (o.type)
495
+ if (o.type === "text") {
496
+ let a = o.text || "";
497
+ const c = new Map((o.marks || []).map((h) => [h.type, h])), p = F(i, c), u = O(c, d);
498
+ let w = "";
499
+ if (u.length > 0) {
500
+ const h = a.match(/(\s+)$/);
501
+ h && (w = h[1], a = a.slice(0, -w.length));
502
+ }
503
+ u.forEach((h) => {
504
+ const k = c.get(h), f = this.getMarkClosing(h, k);
505
+ f && (a += f), i.has(h) && i.delete(h);
506
+ });
507
+ let M = "";
508
+ if (p.length > 0) {
509
+ const h = a.match(/^(\s+)/);
510
+ h && (M = h[1], a = a.slice(M.length));
511
+ }
512
+ p.forEach(({ type: h, mark: k }) => {
513
+ const f = this.getMarkOpening(h, k);
514
+ f && (a = f + a), u.includes(h) || i.set(h, k);
515
+ }), a = M + a;
516
+ const m = N(
517
+ i,
518
+ c,
519
+ d,
520
+ this.markSetsEqual.bind(this)
521
+ );
522
+ let g = "";
523
+ if (m.length > 0) {
524
+ const h = a.match(/(\s+)$/);
525
+ h && (g = h[1], a = a.slice(0, -g.length));
526
+ }
527
+ m.forEach((h) => {
528
+ const k = i.get(h), f = this.getMarkClosing(h, k);
529
+ f && (a += f), i.delete(h);
530
+ }), a += g, a += w, r.push(a);
531
+ } else {
532
+ const a = new Map(i), c = $(i, this.getMarkClosing.bind(this)), p = this.renderNodeToMarkdown(o, n, l, s), u = o.type === "hardBreak" ? "" : S(a, i, this.getMarkOpening.bind(this));
533
+ r.push(c + p + u);
534
+ }
535
+ }), r.join(t);
536
+ }
537
+ /**
538
+ * Get the opening markdown syntax for a mark type.
539
+ */
540
+ getMarkOpening(e, n) {
541
+ const t = this.getHandlersForNodeType(e), s = t.length > 0 ? t[0] : void 0;
542
+ if (!s || !s.renderMarkdown)
543
+ return "";
544
+ const r = "__TIPTAP_MARKDOWN_PLACEHOLDER__", i = {
545
+ type: e,
546
+ attrs: n.attrs || {},
547
+ content: [{ type: "text", text: r }]
548
+ };
549
+ try {
550
+ const o = s.renderMarkdown(
551
+ i,
552
+ {
553
+ renderChildren: () => r,
554
+ indent: (d) => d,
555
+ wrapInBlock: (d, a) => d + a
556
+ },
557
+ { index: 0, level: 0, parentType: "text", meta: {} }
558
+ ), l = o.indexOf(r);
559
+ return l >= 0 ? o.substring(0, l) : "";
560
+ } catch (o) {
561
+ throw new Error(`Failed to get mark opening for ${e}: ${o}`);
562
+ }
563
+ }
564
+ /**
565
+ * Get the closing markdown syntax for a mark type.
566
+ */
567
+ getMarkClosing(e, n) {
568
+ const t = this.getHandlersForNodeType(e), s = t.length > 0 ? t[0] : void 0;
569
+ if (!s || !s.renderMarkdown)
570
+ return "";
571
+ const r = "__TIPTAP_MARKDOWN_PLACEHOLDER__", i = {
572
+ type: e,
573
+ attrs: n.attrs || {},
574
+ content: [{ type: "text", text: r }]
575
+ };
576
+ try {
577
+ const o = s.renderMarkdown(
578
+ i,
579
+ {
580
+ renderChildren: () => r,
581
+ indent: (a) => a,
582
+ wrapInBlock: (a, c) => a + c
583
+ },
584
+ { index: 0, level: 0, parentType: "text", meta: {} }
585
+ ), l = o.indexOf(r), d = l + r.length;
586
+ return l >= 0 ? o.substring(d) : "";
587
+ } catch (o) {
588
+ throw new Error(`Failed to get mark closing for ${e}: ${o}`);
589
+ }
590
+ }
591
+ /**
592
+ * Check if two mark sets are equal.
593
+ */
594
+ markSetsEqual(e, n) {
595
+ return e.size !== n.size ? !1 : Array.from(e.keys()).every((t) => n.has(t));
596
+ }
597
+ }, b = j, q = H.create({
598
+ name: "markdown",
96
599
  addOptions() {
97
- var e;
98
600
  return {
99
- ...(e = this.parent) == null ? void 0 : e.call(this),
100
- lowlight: {},
101
- languageClassPrefix: "language-",
102
- exitOnTripleEnter: !0,
103
- exitOnArrowDown: !0,
104
- defaultLanguage: null,
105
- enableTabIndentation: !1,
106
- tabSize: 4,
107
- HTMLAttributes: {}
601
+ indentation: { style: "space", size: 2 },
602
+ marked: void 0,
603
+ markedOptions: {}
604
+ };
605
+ },
606
+ addCommands() {
607
+ return {
608
+ setContent: (e, n) => {
609
+ if (!n?.contentType)
610
+ return y.setContent(e, n);
611
+ if (E(e, n?.contentType) !== "markdown" || !this.editor.markdown)
612
+ return y.setContent(e, n);
613
+ const s = this.editor.markdown.parse(e);
614
+ return y.setContent(s, n);
615
+ },
616
+ insertContent: (e, n) => {
617
+ if (!n?.contentType)
618
+ return y.insertContent(e, n);
619
+ if (E(e, n?.contentType) !== "markdown" || !this.editor.markdown)
620
+ return y.insertContent(e, n);
621
+ const s = this.editor.markdown.parse(e);
622
+ return y.insertContent(s, n);
623
+ },
624
+ insertContentAt: (e, n, t) => {
625
+ if (!t?.contentType)
626
+ return y.insertContentAt(e, n, t);
627
+ if (E(n, t?.contentType) !== "markdown" || !this.editor.markdown)
628
+ return y.insertContentAt(e, n, t);
629
+ const r = this.editor.markdown.parse(n);
630
+ return y.insertContentAt(e, r, t);
631
+ }
108
632
  };
109
633
  },
110
- addProseMirrorPlugins() {
111
- var e;
112
- return [
113
- ...((e = this.parent) == null ? void 0 : e.call(this)) || [],
114
- A({
115
- name: this.name,
116
- lowlight: this.options.lowlight,
117
- defaultLanguage: this.options.defaultLanguage
634
+ addStorage() {
635
+ return {
636
+ manager: new b({
637
+ indentation: this.options.indentation,
638
+ marked: this.options.marked,
639
+ markedOptions: this.options.markedOptions,
640
+ extensions: []
118
641
  })
119
- ];
642
+ };
643
+ },
644
+ onBeforeCreate() {
645
+ if (this.editor.markdown) {
646
+ console.error(
647
+ "[tiptap][markdown]: There is already a `markdown` property on the editor instance. This might lead to unexpected behavior."
648
+ );
649
+ return;
650
+ }
651
+ if (this.storage.manager = new b({
652
+ indentation: this.options.indentation,
653
+ marked: this.options.marked,
654
+ markedOptions: this.options.markedOptions,
655
+ extensions: this.editor.extensionManager.baseExtensions
656
+ }), this.editor.markdown = this.storage.manager, this.editor.getMarkdown = () => this.storage.manager.serialize(this.editor.getJSON()), !this.editor.options.contentType || E(this.editor.options.content, this.editor.options.contentType) !== "markdown")
657
+ return;
658
+ if (!this.editor.markdown)
659
+ throw new Error(
660
+ '[tiptap][markdown]: The `contentType` option is set to "markdown", but the Markdown extension is not added to the editor. Please add the Markdown extension to use this feature.'
661
+ );
662
+ if (this.editor.options.content === void 0 || typeof this.editor.options.content != "string")
663
+ throw new Error(
664
+ '[tiptap][markdown]: The `contentType` option is set to "markdown", but the initial content is not a string. Please provide the initial content as a markdown string.'
665
+ );
666
+ const n = this.editor.markdown.parse(this.editor.options.content);
667
+ this.editor.options.content = n;
120
668
  }
121
- }), S = D;
669
+ });
122
670
  export {
123
- D as CodeBlockLowlight,
124
- S as default
671
+ q as Markdown,
672
+ j as MarkdownManager,
673
+ E as assumeContentType,
674
+ $ as closeMarksBeforeNode,
675
+ O as findMarksToClose,
676
+ N as findMarksToCloseAtEnd,
677
+ F as findMarksToOpen,
678
+ R as isTaskItem,
679
+ S as reopenMarksAfterNode,
680
+ _ as wrapInMarkdownBlock
125
681
  };