@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/index43.js CHANGED
@@ -1,681 +1,240 @@
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 "./index50.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);
8
- }
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;
14
- }
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
- }
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;
38
- }
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;
45
- }
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;
1
+ import { Mark as y, mergeAttributes as p, Extension as l } from "@tiptap/core";
2
+ var d = 20, u = (t, e = 0) => {
3
+ const r = [];
4
+ return !t.children.length || e > d || Array.from(t.children).forEach((o) => {
5
+ o.tagName === "SPAN" ? r.push(o) : o.children.length && r.push(...u(o, e + 1));
6
+ }), r;
7
+ }, f = (t) => {
8
+ if (!t.children.length)
9
+ return;
10
+ const e = u(t);
11
+ e && e.forEach((r) => {
12
+ var o, n;
13
+ const s = r.getAttribute("style"), i = (n = (o = r.parentElement) == null ? void 0 : o.closest("span")) == null ? void 0 : n.getAttribute("style");
14
+ r.setAttribute("style", `${i};${s}`);
15
+ });
16
+ }, c = y.create({
17
+ name: "textStyle",
18
+ priority: 101,
19
+ addOptions() {
20
+ return {
21
+ HTMLAttributes: {},
22
+ mergeNestedSpanStyles: !0
122
23
  };
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: []
24
+ },
25
+ parseHTML() {
26
+ return [
27
+ {
28
+ tag: "span",
29
+ consuming: !1,
30
+ getAttrs: (t) => t.hasAttribute("style") ? (this.options.mergeNestedSpanStyles && f(t), {}) : !1
31
+ }
32
+ ];
33
+ },
34
+ renderHTML({ HTMLAttributes: t }) {
35
+ return ["span", p(this.options.HTMLAttributes, t), 0];
36
+ },
37
+ addCommands() {
38
+ return {
39
+ toggleTextStyle: (t) => ({ commands: e }) => e.toggleMark(this.name, t),
40
+ removeEmptyTextStyle: () => ({ tr: t }) => {
41
+ const { selection: e } = t;
42
+ return t.doc.nodesBetween(e.from, e.to, (r, o) => {
43
+ if (r.isTextblock)
44
+ return !0;
45
+ r.marks.filter((n) => n.type === this.type).some((n) => Object.values(n.attrs).some((s) => !!s)) || t.removeMark(o, o + r.nodeSize, this.type);
46
+ }), !0;
47
+ }
138
48
  };
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
49
  }
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);
50
+ }), m = l.create({
51
+ name: "backgroundColor",
52
+ addOptions() {
181
53
  return {
182
- type: "doc",
183
- content: this.parseTokens(n)
54
+ types: ["textStyle"]
184
55
  };
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
- `));
56
+ },
57
+ addGlobalAttributes() {
58
+ return [
59
+ {
60
+ types: this.options.types,
61
+ attributes: {
62
+ backgroundColor: {
63
+ default: null,
64
+ parseHTML: (t) => {
65
+ var e;
66
+ const r = t.getAttribute("style");
67
+ if (r) {
68
+ const o = r.split(";").map((n) => n.trim()).filter(Boolean);
69
+ for (let n = o.length - 1; n >= 0; n -= 1) {
70
+ const s = o[n].split(":");
71
+ if (s.length >= 2) {
72
+ const i = s[0].trim().toLowerCase(), a = s.slice(1).join(":").trim();
73
+ if (i === "background-color")
74
+ return a.replace(/['"]+/g, "");
75
+ }
76
+ }
77
+ }
78
+ return (e = t.style.backgroundColor) == null ? void 0 : e.replace(/['"]+/g, "");
79
+ },
80
+ renderHTML: (t) => t.backgroundColor ? {
81
+ style: `background-color: ${t.backgroundColor}`
82
+ } : {}
242
83
  }
243
84
  }
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
85
  }
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() {
86
+ ];
87
+ },
88
+ addCommands() {
289
89
  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
296
- }),
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
- })
90
+ setBackgroundColor: (t) => ({ chain: e }) => e().setMark("textStyle", { backgroundColor: t }).run(),
91
+ unsetBackgroundColor: () => ({ chain: t }) => t().setMark("textStyle", { backgroundColor: null }).removeEmptyTextStyle().run()
310
92
  };
311
93
  }
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;
94
+ }), g = l.create({
95
+ name: "color",
96
+ addOptions() {
97
+ return {
98
+ types: ["textStyle"]
99
+ };
100
+ },
101
+ addGlobalAttributes() {
102
+ return [
103
+ {
104
+ types: this.options.types,
105
+ attributes: {
106
+ color: {
107
+ default: null,
108
+ parseHTML: (t) => {
109
+ var e;
110
+ const r = t.getAttribute("style");
111
+ if (r) {
112
+ const o = r.split(";").map((n) => n.trim()).filter(Boolean);
113
+ for (let n = o.length - 1; n >= 0; n -= 1) {
114
+ const s = o[n].split(":");
115
+ if (s.length >= 2) {
116
+ const i = s[0].trim().toLowerCase(), a = s.slice(1).join(":").trim();
117
+ if (i === "color")
118
+ return a.replace(/['"]+/g, "");
119
+ }
120
+ }
121
+ }
122
+ return (e = t.style.color) == null ? void 0 : e.replace(/['"]+/g, "");
123
+ },
124
+ renderHTML: (t) => t.color ? {
125
+ style: `color: ${t.color}`
126
+ } : {}
358
127
  }
359
128
  }
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));
377
- }
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
- };
392
129
  }
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;
438
- }
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: {}
130
+ ];
131
+ },
132
+ addCommands() {
133
+ return {
134
+ setColor: (t) => ({ chain: e }) => e().setMark("textStyle", { color: t }).run(),
135
+ unsetColor: () => ({ chain: t }) => t().setMark("textStyle", { color: null }).removeEmptyTextStyle().run()
476
136
  };
477
- return ((r = i.renderMarkdown) == null ? void 0 : r.call(i, e, o, l)) || "";
478
137
  }
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));
138
+ }), h = l.create({
139
+ name: "fontFamily",
140
+ addOptions() {
141
+ return {
142
+ types: ["textStyle"]
143
+ };
144
+ },
145
+ addGlobalAttributes() {
146
+ return [
147
+ {
148
+ types: this.options.types,
149
+ attributes: {
150
+ fontFamily: {
151
+ default: null,
152
+ parseHTML: (t) => t.style.fontFamily,
153
+ renderHTML: (t) => t.fontFamily ? {
154
+ style: `font-family: ${t.fontFamily}`
155
+ } : {}
526
156
  }
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
157
  }
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 }]
158
+ }
159
+ ];
160
+ },
161
+ addCommands() {
162
+ return {
163
+ setFontFamily: (t) => ({ chain: e }) => e().setMark("textStyle", { fontFamily: t }).run(),
164
+ unsetFontFamily: () => ({ chain: t }) => t().setMark("textStyle", { fontFamily: null }).removeEmptyTextStyle().run()
575
165
  };
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
166
  }
597
- }, b = j, q = H.create({
598
- name: "markdown",
167
+ }), S = l.create({
168
+ name: "fontSize",
599
169
  addOptions() {
600
170
  return {
601
- indentation: { style: "space", size: 2 },
602
- marked: void 0,
603
- markedOptions: {}
171
+ types: ["textStyle"]
604
172
  };
605
173
  },
174
+ addGlobalAttributes() {
175
+ return [
176
+ {
177
+ types: this.options.types,
178
+ attributes: {
179
+ fontSize: {
180
+ default: null,
181
+ parseHTML: (t) => t.style.fontSize,
182
+ renderHTML: (t) => t.fontSize ? {
183
+ style: `font-size: ${t.fontSize}`
184
+ } : {}
185
+ }
186
+ }
187
+ }
188
+ ];
189
+ },
606
190
  addCommands() {
607
191
  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
- }
192
+ setFontSize: (t) => ({ chain: e }) => e().setMark("textStyle", { fontSize: t }).run(),
193
+ unsetFontSize: () => ({ chain: t }) => t().setMark("textStyle", { fontSize: null }).removeEmptyTextStyle().run()
632
194
  };
633
- },
634
- addStorage() {
195
+ }
196
+ }), b = l.create({
197
+ name: "lineHeight",
198
+ addOptions() {
635
199
  return {
636
- manager: new b({
637
- indentation: this.options.indentation,
638
- marked: this.options.marked,
639
- markedOptions: this.options.markedOptions,
640
- extensions: []
641
- })
200
+ types: ["textStyle"]
642
201
  };
643
202
  },
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;
203
+ addGlobalAttributes() {
204
+ return [
205
+ {
206
+ types: this.options.types,
207
+ attributes: {
208
+ lineHeight: {
209
+ default: null,
210
+ parseHTML: (t) => t.style.lineHeight,
211
+ renderHTML: (t) => t.lineHeight ? {
212
+ style: `line-height: ${t.lineHeight}`
213
+ } : {}
214
+ }
215
+ }
216
+ }
217
+ ];
218
+ },
219
+ addCommands() {
220
+ return {
221
+ setLineHeight: (t) => ({ chain: e }) => e().setMark("textStyle", { lineHeight: t }).run(),
222
+ unsetLineHeight: () => ({ chain: t }) => t().setMark("textStyle", { lineHeight: null }).removeEmptyTextStyle().run()
223
+ };
224
+ }
225
+ });
226
+ l.create({
227
+ name: "textStyleKit",
228
+ addExtensions() {
229
+ const t = [];
230
+ return this.options.backgroundColor !== !1 && t.push(m.configure(this.options.backgroundColor)), this.options.color !== !1 && t.push(g.configure(this.options.color)), this.options.fontFamily !== !1 && t.push(h.configure(this.options.fontFamily)), this.options.fontSize !== !1 && t.push(S.configure(this.options.fontSize)), this.options.lineHeight !== !1 && t.push(b.configure(this.options.lineHeight)), this.options.textStyle !== !1 && t.push(c.configure(this.options.textStyle)), t;
668
231
  }
669
232
  });
670
233
  export {
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
234
+ m as BackgroundColor,
235
+ g as Color,
236
+ h as FontFamily,
237
+ S as FontSize,
238
+ b as LineHeight,
239
+ c as TextStyle
681
240
  };