@pixerate/editor 0.14.3 → 0.15.0

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 (71) hide show
  1. package/dist/agent/index.cjs +28 -220
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.d.cts +1 -1
  4. package/dist/agent/index.d.ts +1 -1
  5. package/dist/agent/index.js +5 -154
  6. package/dist/agent/index.js.map +1 -1
  7. package/dist/canvas/index.cjs +113 -377
  8. package/dist/canvas/index.cjs.map +1 -1
  9. package/dist/canvas/index.d.cts +2 -2
  10. package/dist/canvas/index.d.ts +2 -2
  11. package/dist/canvas/index.js +18 -208
  12. package/dist/canvas/index.js.map +1 -1
  13. package/dist/chunk-33UVEDOS.cjs +233 -0
  14. package/dist/chunk-33UVEDOS.cjs.map +1 -0
  15. package/dist/chunk-7FWEWE6T.js +1888 -0
  16. package/dist/chunk-7FWEWE6T.js.map +1 -0
  17. package/dist/chunk-BYCOFZAA.js +514 -0
  18. package/dist/chunk-BYCOFZAA.js.map +1 -0
  19. package/dist/chunk-CYKQLDYH.cjs +1290 -0
  20. package/dist/chunk-CYKQLDYH.cjs.map +1 -0
  21. package/dist/chunk-GLSIZKOX.js +17 -0
  22. package/dist/chunk-GLSIZKOX.js.map +1 -0
  23. package/dist/chunk-GWHJVZPI.js +233 -0
  24. package/dist/chunk-GWHJVZPI.js.map +1 -0
  25. package/dist/chunk-LDES3EOS.cjs +1888 -0
  26. package/dist/chunk-LDES3EOS.cjs.map +1 -0
  27. package/dist/chunk-MPPXH7U5.cjs +336 -0
  28. package/dist/chunk-MPPXH7U5.cjs.map +1 -0
  29. package/dist/chunk-NNJRJJSC.js +1290 -0
  30. package/dist/chunk-NNJRJJSC.js.map +1 -0
  31. package/dist/chunk-O7LOPQMH.js +336 -0
  32. package/dist/chunk-O7LOPQMH.js.map +1 -0
  33. package/dist/chunk-SEDR75VH.cjs +17 -0
  34. package/dist/chunk-SEDR75VH.cjs.map +1 -0
  35. package/dist/chunk-SHWP2A43.cjs +514 -0
  36. package/dist/chunk-SHWP2A43.cjs.map +1 -0
  37. package/dist/chunk-VHZCXHS4.js +222 -0
  38. package/dist/chunk-VHZCXHS4.js.map +1 -0
  39. package/dist/chunk-WADCJ7A7.cjs +222 -0
  40. package/dist/chunk-WADCJ7A7.cjs.map +1 -0
  41. package/dist/extensions/index.cjs +25 -1920
  42. package/dist/extensions/index.cjs.map +1 -1
  43. package/dist/extensions/index.js +22 -1868
  44. package/dist/extensions/index.js.map +1 -1
  45. package/dist/grammar/index.cjs +44 -387
  46. package/dist/grammar/index.cjs.map +1 -1
  47. package/dist/grammar/index.js +23 -321
  48. package/dist/grammar/index.js.map +1 -1
  49. package/dist/history/index.cjs +6 -257
  50. package/dist/history/index.cjs.map +1 -1
  51. package/dist/history/index.js +4 -227
  52. package/dist/history/index.js.map +1 -1
  53. package/dist/image-editor/index.cjs +63 -106
  54. package/dist/image-editor/index.cjs.map +1 -1
  55. package/dist/index.cjs +324 -7232
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.cts +0 -4
  58. package/dist/index.d.ts +0 -4
  59. package/dist/index.js +258 -7007
  60. package/dist/index.js.map +1 -1
  61. package/dist/serializers/index.cjs +28 -558
  62. package/dist/serializers/index.cjs.map +1 -1
  63. package/dist/serializers/index.js +16 -496
  64. package/dist/serializers/index.js.map +1 -1
  65. package/dist/spreadsheet/index.cjs +21 -1319
  66. package/dist/spreadsheet/index.cjs.map +1 -1
  67. package/dist/spreadsheet/index.js +14 -1274
  68. package/dist/spreadsheet/index.js.map +1 -1
  69. package/dist/{types-lGtRobRV.d.cts → types-DC8b2TsA.d.cts} +1 -1
  70. package/dist/{types-lGtRobRV.d.ts → types-DC8b2TsA.d.ts} +1 -1
  71. package/package.json +1 -1
@@ -0,0 +1,1888 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+ var _chunkSEDR75VHcjs = require('./chunk-SEDR75VH.cjs');
6
+
7
+ // src/extensions/gradient-text.ts
8
+ var _core = require('@tiptap/core');
9
+ var _state = require('@tiptap/pm/state');
10
+ var _view = require('@tiptap/pm/view');
11
+ var createGradientDecorations = (doc, options) => {
12
+ const decorations = [];
13
+ const speed = _nullishCoalesce(options.speed, () => ( 1));
14
+ const jsonVarSet = options.jsonVariables ? options.jsonVariables instanceof Set ? options.jsonVariables : new Set(options.jsonVariables) : null;
15
+ doc.descendants((node, pos) => {
16
+ if (node.isText) {
17
+ const text = node.text || "";
18
+ let match;
19
+ const tmplRegex = new RegExp(_chunkSEDR75VHcjs.TEMPLATE_REGEX.source, _chunkSEDR75VHcjs.TEMPLATE_REGEX.flags);
20
+ while ((match = tmplRegex.exec(text)) !== null) {
21
+ const templateName = match[1].trim();
22
+ const colors = _optionalChain([options, 'access', _2 => _2.templateColorMap, 'optionalAccess', _3 => _3.get, 'call', _4 => _4(templateName)]);
23
+ if (colors) {
24
+ const start = pos + match.index;
25
+ const end = start + match[0].length;
26
+ const { from: colorFrom, to: colorTo } = colors;
27
+ const style = `--bg-size: ${speed * 300}%; --color-from: ${colorFrom}; --color-to: ${colorTo}; caret-color: #111 !important; background-image: linear-gradient(to right, ${colorFrom}, ${colorTo}, ${colorFrom}); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;`;
28
+ decorations.push(
29
+ _view.Decoration.inline(start, end, {
30
+ class: "inline animate-gradient bg-gradient-to-r from-[var(--color-from)] via-[var(--color-to)] to-[var(--color-from)] bg-[length:var(--bg-size)_100%] bg-clip-text text-transparent border border-(--color-to)/20 px-1 py-0.5 rounded-sm cursor-pointer",
31
+ style,
32
+ "data-template": templateName
33
+ })
34
+ );
35
+ }
36
+ }
37
+ const instRegex = new RegExp(
38
+ _chunkSEDR75VHcjs.INSTRUCTION_REGEX.source,
39
+ _chunkSEDR75VHcjs.INSTRUCTION_REGEX.flags
40
+ );
41
+ while ((match = instRegex.exec(text)) !== null) {
42
+ const content = match[1].trim();
43
+ const colors = _optionalChain([options, 'access', _5 => _5.templateColorMap, 'optionalAccess', _6 => _6.get, 'call', _7 => _7(content)]) || {
44
+ from: "#ffaa40",
45
+ to: "#9c40ff"
46
+ };
47
+ const start = pos + match.index;
48
+ const end = start + match[0].length;
49
+ const { from: colorFrom, to: colorTo } = colors;
50
+ const style = `--bg-size: ${speed * 300}%; --color-from: ${colorFrom}; --color-to: ${colorTo}; caret-color: #111 !important; background-image: linear-gradient(to right, #fb7185, #8b5cf6, #fb7185); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;`;
51
+ decorations.push(
52
+ _view.Decoration.inline(start, end, {
53
+ class: "italic animate-gradient bg-gradient-to-r from-rose-400 from-50% to-violet-500 to-50% bg-size-[200%_100%] bg-clip-text text-transparent inline-flex items-baseline gap-0.5",
54
+ style
55
+ })
56
+ );
57
+ }
58
+ const varRegex = new RegExp(
59
+ _chunkSEDR75VHcjs.VARIABLE_REGEX.source,
60
+ _chunkSEDR75VHcjs.VARIABLE_REGEX.flags
61
+ );
62
+ while ((match = varRegex.exec(text)) !== null) {
63
+ const variableName = match[1].trim();
64
+ const start = pos + match.index;
65
+ const end = start + match[0].length;
66
+ const isJsonVar = _optionalChain([jsonVarSet, 'optionalAccess', _8 => _8.has, 'call', _9 => _9(variableName)]);
67
+ decorations.push(
68
+ _view.Decoration.inline(start, end, {
69
+ class: isJsonVar ? "bg-violet-400/40 border-b-4 border-rose-300 dark:border-rose-800 inline-flex items-baseline px-1 py-0 text-foreground/80 gap-0.5 rounded-xs" : "bg-rose-400/40 border-b-4 border-violet-300 dark:border-violet-800 inline-flex items-baseline px-1 py-0 text-foreground/80 gap-0.5 rounded-xs",
70
+ "data-variable": variableName
71
+ })
72
+ );
73
+ }
74
+ }
75
+ });
76
+ return decorations;
77
+ };
78
+ var GradientText = _core.Mark.create({
79
+ name: "gradientText",
80
+ addOptions() {
81
+ return {
82
+ templateColorMap: /* @__PURE__ */ new Map(),
83
+ speed: 1,
84
+ jsonVariables: void 0,
85
+ onTemplateClick: void 0
86
+ };
87
+ },
88
+ renderHTML({ HTMLAttributes }) {
89
+ const defaultColors = {
90
+ from: "#ffaa40",
91
+ to: "#9c40ff"
92
+ };
93
+ const speed = _nullishCoalesce(this.options.speed, () => ( 1));
94
+ const style = `--bg-size: ${speed * 300}%; --color-from: ${defaultColors.from}; --color-to: ${defaultColors.to}; caret-color: #111 !important;`;
95
+ return [
96
+ "span",
97
+ {
98
+ class: "inline animate-gradient bg-gradient-to-r from-[var(--color-from)] via-[var(--color-to)] to-[var(--color-from)] bg-[length:var(--bg-size)_100%] bg-clip-text text-transparent",
99
+ style,
100
+ ...HTMLAttributes
101
+ },
102
+ 0
103
+ ];
104
+ },
105
+ parseHTML() {
106
+ return [
107
+ {
108
+ tag: "span",
109
+ getAttrs: (node) => node.classList.contains("animate-gradient") && node.classList.contains("bg-clip-text") && null
110
+ }
111
+ ];
112
+ },
113
+ addProseMirrorPlugins() {
114
+ const markOptions = this.options;
115
+ return [
116
+ new (0, _state.Plugin)({
117
+ state: {
118
+ init(_, { doc }) {
119
+ return _view.DecorationSet.create(
120
+ doc,
121
+ createGradientDecorations(doc, markOptions)
122
+ );
123
+ },
124
+ apply(tr, value) {
125
+ const newDoc = tr.doc;
126
+ if (tr.docChanged) {
127
+ return _view.DecorationSet.create(
128
+ newDoc,
129
+ createGradientDecorations(newDoc, markOptions)
130
+ );
131
+ }
132
+ return value.map(tr.mapping, newDoc);
133
+ }
134
+ },
135
+ props: {
136
+ decorations(state) {
137
+ return this.getState(state);
138
+ },
139
+ handleClickOn(view, pos, _node, _nodePos, event) {
140
+ const decorationSet = this.getState(
141
+ view.state
142
+ );
143
+ const decorations = decorationSet.find(pos, pos + 1);
144
+ for (const decoration of decorations) {
145
+ const decorationWithAttrs = decoration;
146
+ const templateName = _optionalChain([decorationWithAttrs, 'access', _10 => _10.type, 'optionalAccess', _11 => _11.attrs, 'optionalAccess', _12 => _12["data-template"]]);
147
+ if (templateName) {
148
+ if (markOptions.onTemplateClick) {
149
+ markOptions.onTemplateClick(templateName, event);
150
+ }
151
+ if (typeof window !== "undefined") {
152
+ window.dispatchEvent(
153
+ new CustomEvent("show-gradient-popover", {
154
+ detail: {
155
+ templateName,
156
+ target: event.target
157
+ }
158
+ })
159
+ );
160
+ }
161
+ return true;
162
+ }
163
+ }
164
+ return false;
165
+ }
166
+ }
167
+ })
168
+ ];
169
+ }
170
+ });
171
+
172
+ // src/extensions/slash-commands.ts
173
+
174
+
175
+ var SlashCommands = _core.Extension.create({
176
+ name: "slashCommands",
177
+ addOptions() {
178
+ return {
179
+ trigger: "/",
180
+ onMatch: void 0,
181
+ onClear: void 0,
182
+ containerId: void 0
183
+ };
184
+ },
185
+ addProseMirrorPlugins() {
186
+ const opts = this.options;
187
+ return [
188
+ new (0, _state.Plugin)({
189
+ view() {
190
+ return {
191
+ update(view) {
192
+ const { state } = view;
193
+ const { selection } = state;
194
+ const { $from } = selection;
195
+ if (!$from.parent.isTextblock) {
196
+ _optionalChain([opts, 'access', _13 => _13.onClear, 'optionalCall', _14 => _14()]);
197
+ return;
198
+ }
199
+ const textBeforeCursor = $from.parent.textBetween(
200
+ 0,
201
+ $from.parentOffset
202
+ );
203
+ const slashMatch = textBeforeCursor.match(
204
+ /(?:^|\s)\/([a-zA-Z0-9_-]*)$/
205
+ );
206
+ if (slashMatch) {
207
+ const matchIndex = _nullishCoalesce(slashMatch.index, () => ( 0));
208
+ const offsetInParent = matchIndex + (slashMatch[0].startsWith(" ") ? 1 : 0);
209
+ const matchFrom = $from.start() + offsetInParent;
210
+ const matchTo = $from.pos;
211
+ const coords = view.coordsAtPos($from.pos);
212
+ let relativeCoords = {
213
+ top: coords.top,
214
+ left: coords.left,
215
+ bottom: coords.bottom,
216
+ right: coords.right
217
+ };
218
+ if (opts.containerId && typeof document !== "undefined") {
219
+ const container = document.getElementById(opts.containerId);
220
+ if (container) {
221
+ const rect = container.getBoundingClientRect();
222
+ relativeCoords = {
223
+ top: coords.bottom - rect.top + 5,
224
+ left: coords.left - rect.left,
225
+ bottom: coords.bottom - rect.top,
226
+ right: coords.right - rect.left
227
+ };
228
+ }
229
+ }
230
+ _optionalChain([opts, 'access', _15 => _15.onMatch, 'optionalCall', _16 => _16({
231
+ match: slashMatch,
232
+ query: slashMatch[1] || "",
233
+ from: matchFrom,
234
+ to: matchTo,
235
+ coords: relativeCoords
236
+ })]);
237
+ } else {
238
+ _optionalChain([opts, 'access', _17 => _17.onClear, 'optionalCall', _18 => _18()]);
239
+ }
240
+ }
241
+ };
242
+ }
243
+ })
244
+ ];
245
+ }
246
+ });
247
+
248
+ // src/extensions/template-suggestions.ts
249
+
250
+ var _suggestion = require('@tiptap/suggestion'); var _suggestion2 = _interopRequireDefault(_suggestion);
251
+ var TemplateSuggestions = _core.Extension.create({
252
+ name: "templateSuggestions",
253
+ addOptions() {
254
+ return {
255
+ templates: [],
256
+ char: "{{",
257
+ onSuggestion: void 0
258
+ };
259
+ },
260
+ addProseMirrorPlugins() {
261
+ const opts = this.options;
262
+ const suggestionConfig = {
263
+ char: opts.char || "{{",
264
+ items: ({ query }) => {
265
+ const lower = query.toLowerCase();
266
+ return (opts.templates || []).filter(
267
+ (t) => t.name.toLowerCase().includes(lower)
268
+ );
269
+ },
270
+ command: ({ editor, range, props }) => {
271
+ editor.chain().focus().deleteRange(range).insertContent(`{{${props.name}}}`).run();
272
+ },
273
+ render: () => {
274
+ return {
275
+ onStart: (props) => {
276
+ _optionalChain([opts, 'access', _19 => _19.onSuggestion, 'optionalCall', _20 => _20(props)]);
277
+ },
278
+ onUpdate: (props) => {
279
+ _optionalChain([opts, 'access', _21 => _21.onSuggestion, 'optionalCall', _22 => _22(props)]);
280
+ },
281
+ onExit: () => {
282
+ _optionalChain([opts, 'access', _23 => _23.onSuggestion, 'optionalCall', _24 => _24({
283
+ query: "",
284
+ range: { from: 0, to: 0 },
285
+ items: [],
286
+ command: () => {
287
+ }
288
+ })]);
289
+ }
290
+ };
291
+ }
292
+ };
293
+ const SuggestionFn = typeof _suggestion2.default === "function" ? _suggestion2.default : _optionalChain([_suggestion2.default, 'optionalAccess', _25 => _25.default]) || _optionalChain([_suggestion2.default, 'optionalAccess', _26 => _26.Suggestion]);
294
+ return [
295
+ SuggestionFn({
296
+ editor: this.editor,
297
+ ...suggestionConfig
298
+ })
299
+ ];
300
+ }
301
+ });
302
+
303
+ // src/extensions/loading-node.ts
304
+
305
+ var LoadingNode = _core.Node.create({
306
+ name: "loadingNode",
307
+ group: "inline",
308
+ inline: true,
309
+ selectable: true,
310
+ atom: true,
311
+ addAttributes() {
312
+ return {
313
+ id: {
314
+ default: null,
315
+ parseHTML: (element) => element.getAttribute("data-id"),
316
+ renderHTML: (attributes) => {
317
+ if (!attributes.id) return {};
318
+ return { "data-id": attributes.id };
319
+ }
320
+ }
321
+ };
322
+ },
323
+ parseHTML() {
324
+ return [
325
+ {
326
+ tag: 'span[data-type="loading"]'
327
+ }
328
+ ];
329
+ },
330
+ renderHTML({ HTMLAttributes }) {
331
+ return [
332
+ "span",
333
+ _core.mergeAttributes.call(void 0, HTMLAttributes, {
334
+ "data-type": "loading",
335
+ class: "inline-flex items-center px-1.5 py-0.5 text-xs text-muted-foreground animate-pulse"
336
+ }),
337
+ "\u23F3"
338
+ ];
339
+ }
340
+ });
341
+
342
+ // src/extensions/SmilieReplacer.ts
343
+
344
+ var SmilieReplacer = _core.Extension.create({
345
+ name: "smilieReplacer",
346
+ addInputRules() {
347
+ return [
348
+ _core.textInputRule.call(void 0, { find: /-___- $/, replace: "\u{1F611} " }),
349
+ _core.textInputRule.call(void 0, { find: /:'-\) $/, replace: "\u{1F602} " }),
350
+ _core.textInputRule.call(void 0, { find: /':-\) $/, replace: "\u{1F605} " }),
351
+ _core.textInputRule.call(void 0, { find: /':-D $/, replace: "\u{1F605} " }),
352
+ _core.textInputRule.call(void 0, { find: />:-\) $/, replace: "\u{1F606} " }),
353
+ _core.textInputRule.call(void 0, { find: /-__- $/, replace: "\u{1F611} " }),
354
+ _core.textInputRule.call(void 0, { find: /':-\( $/, replace: "\u{1F613} " }),
355
+ _core.textInputRule.call(void 0, { find: /:'-\( $/, replace: "\u{1F622} " }),
356
+ _core.textInputRule.call(void 0, { find: />:-\( $/, replace: "\u{1F620} " }),
357
+ _core.textInputRule.call(void 0, { find: /O:-\) $/, replace: "\u{1F607} " }),
358
+ _core.textInputRule.call(void 0, { find: /:'\) $/, replace: "\u{1F602} " }),
359
+ _core.textInputRule.call(void 0, { find: /:-D $/, replace: "\u{1F603} " }),
360
+ _core.textInputRule.call(void 0, { find: /':\) $/, replace: "\u{1F605} " }),
361
+ _core.textInputRule.call(void 0, { find: /;-\) $/, replace: "\u{1F609} " }),
362
+ _core.textInputRule.call(void 0, { find: /B-\) $/, replace: "\u{1F60E} " }),
363
+ _core.textInputRule.call(void 0, { find: /:-\* $/, replace: "\u{1F618} " }),
364
+ _core.textInputRule.call(void 0, { find: /:-\) $/, replace: "\u{1F642} " }),
365
+ _core.textInputRule.call(void 0, { find: /-_- $/, replace: "\u{1F611} " }),
366
+ _core.textInputRule.call(void 0, { find: /:-O $/, replace: "\u{1F62E} " }),
367
+ _core.textInputRule.call(void 0, { find: /:-P $/, replace: "\u{1F61B} " }),
368
+ _core.textInputRule.call(void 0, { find: /:-p $/, replace: "\u{1F61B} " }),
369
+ _core.textInputRule.call(void 0, { find: /:-\/ $/, replace: "\u{1F615} " }),
370
+ _core.textInputRule.call(void 0, { find: /:-\( $/, replace: "\u{1F61E} " }),
371
+ _core.textInputRule.call(void 0, { find: /:'\( $/, replace: "\u{1F622} " }),
372
+ _core.textInputRule.call(void 0, { find: /:D $/, replace: "\u{1F603} " }),
373
+ _core.textInputRule.call(void 0, { find: /=D $/, replace: "\u{1F603} " }),
374
+ _core.textInputRule.call(void 0, { find: /;\) $/, replace: "\u{1F609} " }),
375
+ _core.textInputRule.call(void 0, { find: /B\) $/, replace: "\u{1F60E} " }),
376
+ _core.textInputRule.call(void 0, { find: /:\) $/, replace: "\u{1F642} " }),
377
+ _core.textInputRule.call(void 0, { find: /=\) $/, replace: "\u{1F642} " }),
378
+ _core.textInputRule.call(void 0, { find: /:O $/, replace: "\u{1F62E} " }),
379
+ _core.textInputRule.call(void 0, { find: /:P $/, replace: "\u{1F61B} " }),
380
+ _core.textInputRule.call(void 0, { find: /:p $/, replace: "\u{1F61B} " }),
381
+ _core.textInputRule.call(void 0, { find: /:\/ $/, replace: "\u{1F615} " }),
382
+ _core.textInputRule.call(void 0, { find: /:\( $/, replace: "\u{1F61E} " }),
383
+ _core.textInputRule.call(void 0, { find: /<3 $/, replace: "\u2764\uFE0F " }),
384
+ _core.textInputRule.call(void 0, { find: /<\/3 $/, replace: "\u{1F494} " }),
385
+ _core.textInputRule.call(void 0, { find: /\/shrug $/, replace: "\xAF\\_(\u30C4)_/\xAF " })
386
+ ];
387
+ }
388
+ });
389
+
390
+ // src/extensions/ColorHighlighter.ts
391
+
392
+
393
+
394
+ function findHexColors(doc) {
395
+ const hexColorRegex = /(#[0-9a-fA-F]{3,8})\b/g;
396
+ const decorations = [];
397
+ doc.descendants((node, position) => {
398
+ if (!node.text) return;
399
+ let match;
400
+ while ((match = hexColorRegex.exec(node.text)) !== null) {
401
+ const color = match[0];
402
+ const from = position + match.index;
403
+ const to = from + color.length;
404
+ decorations.push(
405
+ _view.Decoration.inline(from, to, {
406
+ class: "color-highlight px-1 py-0.5 rounded text-xs font-mono border",
407
+ style: `--color: ${color}; background-color: ${color}20; border-color: ${color}; color: ${color};`
408
+ })
409
+ );
410
+ }
411
+ });
412
+ return _view.DecorationSet.create(doc, decorations);
413
+ }
414
+ var ColorHighlighter = _core.Extension.create({
415
+ name: "colorHighlighter",
416
+ addProseMirrorPlugins() {
417
+ return [
418
+ new (0, _state.Plugin)({
419
+ state: {
420
+ init(_, { doc }) {
421
+ return findHexColors(doc);
422
+ },
423
+ apply(transaction, oldState) {
424
+ return transaction.docChanged ? findHexColors(transaction.doc) : oldState;
425
+ }
426
+ },
427
+ props: {
428
+ decorations(state) {
429
+ return this.getState(state);
430
+ }
431
+ }
432
+ })
433
+ ];
434
+ }
435
+ });
436
+
437
+ // src/extensions/FontSize.ts
438
+
439
+ var _extensiontextstyle = require('@tiptap/extension-text-style'); var _TextStyle = _interopRequireWildcard(_extensiontextstyle);
440
+ var FontSize = _core.Extension.create({
441
+ name: "fontSize",
442
+ addOptions() {
443
+ return {
444
+ types: ["textStyle"]
445
+ };
446
+ },
447
+ addGlobalAttributes() {
448
+ return [
449
+ {
450
+ types: this.options.types,
451
+ attributes: {
452
+ fontSize: {
453
+ default: null,
454
+ parseHTML: (element) => element.style.fontSize.replace(/['"]+/g, ""),
455
+ renderHTML: (attributes) => {
456
+ if (!attributes.fontSize) {
457
+ return {};
458
+ }
459
+ return {
460
+ style: `font-size: ${attributes.fontSize}`
461
+ };
462
+ }
463
+ }
464
+ }
465
+ }
466
+ ];
467
+ },
468
+ addCommands() {
469
+ return {
470
+ setFontSize: (fontSize) => ({ chain }) => chain().setMark("textStyle", { fontSize }).run(),
471
+ unsetFontSize: () => ({ chain }) => chain().setMark("textStyle", { fontSize: null }).removeEmptyTextStyle().run()
472
+ };
473
+ }
474
+ });
475
+
476
+ // src/extensions/rich-text-preset.ts
477
+
478
+
479
+
480
+
481
+ var _starterkit = require('@tiptap/starter-kit'); var _StarterKit = _interopRequireWildcard(_starterkit);
482
+ var _extensioncolor = require('@tiptap/extension-color'); var _Color = _interopRequireWildcard(_extensioncolor);
483
+ var _extensionhighlight = require('@tiptap/extension-highlight'); var _Highlight = _interopRequireWildcard(_extensionhighlight);
484
+ var _extensionlink = require('@tiptap/extension-link'); var _Link = _interopRequireWildcard(_extensionlink);
485
+ var _extensiontasklist = require('@tiptap/extension-task-list'); var _TaskList = _interopRequireWildcard(_extensiontasklist);
486
+ var _extensiontaskitem = require('@tiptap/extension-task-item'); var _TaskItem = _interopRequireWildcard(_extensiontaskitem);
487
+ var _extensiontextalign = require('@tiptap/extension-text-align'); var _TextAlign = _interopRequireWildcard(_extensiontextalign);
488
+
489
+ var _extensiontypography = require('@tiptap/extension-typography'); var _Typography = _interopRequireWildcard(_extensiontypography);
490
+ var _extensionunderline = require('@tiptap/extension-underline'); var _Underline = _interopRequireWildcard(_extensionunderline);
491
+ var _extensionplaceholder = require('@tiptap/extension-placeholder'); var _Placeholder = _interopRequireWildcard(_extensionplaceholder);
492
+ var _extensioncharactercount = require('@tiptap/extension-character-count'); var _CharacterCount = _interopRequireWildcard(_extensioncharactercount);
493
+
494
+ // src/extensions/mention.ts
495
+
496
+
497
+ var _extensionmention = require('@tiptap/extension-mention');
498
+ var BaseMention = _extensionmention.Mention || _optionalChain([_extensionmention.Mention, 'optionalAccess', _27 => _27.default, 'optionalAccess', _28 => _28.default]) || _optionalChain([_extensionmention.Mention, 'optionalAccess', _29 => _29.default]) || _extensionmention.Mention;
499
+ var Mention = BaseMention.extend({
500
+ addAttributes() {
501
+ return {
502
+ ..._optionalChain([this, 'access', _30 => _30.parent, 'optionalCall', _31 => _31()]),
503
+ type: {
504
+ default: null,
505
+ parseHTML: (element) => element.getAttribute("data-type-name") || element.getAttribute("data-entity-type"),
506
+ renderHTML: (attributes) => {
507
+ if (!attributes.type) return {};
508
+ return { "data-type-name": attributes.type };
509
+ }
510
+ },
511
+ avatarUrl: {
512
+ default: null,
513
+ parseHTML: (element) => element.getAttribute("data-avatar-url"),
514
+ renderHTML: (attributes) => {
515
+ if (!attributes.avatarUrl) return {};
516
+ return { "data-avatar-url": attributes.avatarUrl };
517
+ }
518
+ },
519
+ color: {
520
+ default: null,
521
+ parseHTML: (element) => element.getAttribute("data-color"),
522
+ renderHTML: (attributes) => {
523
+ if (!attributes.color) return {};
524
+ return { "data-color": attributes.color };
525
+ }
526
+ }
527
+ };
528
+ }
529
+ });
530
+ function createMentionExtension(options = {}) {
531
+ const { HTMLAttributes = {}, ...rest } = options;
532
+ return Mention.configure({
533
+ HTMLAttributes: {
534
+ class: "pixerate-mention-node",
535
+ ...HTMLAttributes
536
+ },
537
+ ...rest
538
+ });
539
+ }
540
+
541
+ // ../../node_modules/.pnpm/tiptap-markdown@0.8.10_@tiptap+core@2.27.3_@tiptap+pm@2.27.3_/node_modules/tiptap-markdown/dist/tiptap-markdown.es.js
542
+
543
+ var _prosemirrormarkdown = require('prosemirror-markdown');
544
+ var _markdownit = require('markdown-it'); var _markdownit2 = _interopRequireDefault(_markdownit);
545
+ var _model = require('@tiptap/pm/model');
546
+ var _markdownittasklists = require('markdown-it-task-lists'); var _markdownittasklists2 = _interopRequireDefault(_markdownittasklists);
547
+
548
+ var __defProp = Object.defineProperty;
549
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
550
+ var __publicField = (obj, key, value) => {
551
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
552
+ return value;
553
+ };
554
+ var MarkdownTightLists = _core.Extension.create({
555
+ name: "markdownTightLists",
556
+ addOptions: () => ({
557
+ tight: true,
558
+ tightClass: "tight",
559
+ listTypes: ["bulletList", "orderedList"]
560
+ }),
561
+ addGlobalAttributes() {
562
+ return [{
563
+ types: this.options.listTypes,
564
+ attributes: {
565
+ tight: {
566
+ default: this.options.tight,
567
+ parseHTML: (element) => element.getAttribute("data-tight") === "true" || !element.querySelector("p"),
568
+ renderHTML: (attributes) => ({
569
+ class: attributes.tight ? this.options.tightClass : null,
570
+ "data-tight": attributes.tight ? "true" : null
571
+ })
572
+ }
573
+ }
574
+ }];
575
+ },
576
+ addCommands() {
577
+ var _this = this;
578
+ return {
579
+ toggleTight: function() {
580
+ let tight = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
581
+ return (_ref) => {
582
+ let {
583
+ editor,
584
+ commands
585
+ } = _ref;
586
+ function toggleTight(name) {
587
+ if (!editor.isActive(name)) {
588
+ return false;
589
+ }
590
+ const attrs = editor.getAttributes(name);
591
+ return commands.updateAttributes(name, {
592
+ tight: tight !== null && tight !== void 0 ? tight : !(attrs !== null && attrs !== void 0 && attrs.tight)
593
+ });
594
+ }
595
+ return _this.options.listTypes.some((name) => toggleTight(name));
596
+ };
597
+ }
598
+ };
599
+ }
600
+ });
601
+ var md = _markdownit2.default.call(void 0, );
602
+ function scanDelims(text, pos) {
603
+ md.inline.State.prototype.scanDelims.call({
604
+ src: text,
605
+ posMax: text.length
606
+ });
607
+ const state = new md.inline.State(text, null, null, []);
608
+ return state.scanDelims(pos, true);
609
+ }
610
+ function shiftDelim(text, delim, start, offset) {
611
+ let res = text.substring(0, start) + text.substring(start + delim.length);
612
+ res = res.substring(0, start + offset) + delim + res.substring(start + offset);
613
+ return res;
614
+ }
615
+ function trimStart(text, delim, from, to) {
616
+ let pos = from, res = text;
617
+ while (pos < to) {
618
+ if (scanDelims(res, pos).can_open) {
619
+ break;
620
+ }
621
+ res = shiftDelim(res, delim, pos, 1);
622
+ pos++;
623
+ }
624
+ return {
625
+ text: res,
626
+ from: pos,
627
+ to
628
+ };
629
+ }
630
+ function trimEnd(text, delim, from, to) {
631
+ let pos = to, res = text;
632
+ while (pos > from) {
633
+ if (scanDelims(res, pos).can_close) {
634
+ break;
635
+ }
636
+ res = shiftDelim(res, delim, pos, -1);
637
+ pos--;
638
+ }
639
+ return {
640
+ text: res,
641
+ from,
642
+ to: pos
643
+ };
644
+ }
645
+ function trimInline(text, delim, from, to) {
646
+ let state = {
647
+ text,
648
+ from,
649
+ to
650
+ };
651
+ state = trimStart(state.text, delim, state.from, state.to);
652
+ state = trimEnd(state.text, delim, state.from, state.to);
653
+ if (state.to - state.from < delim.length + 1) {
654
+ state.text = state.text.substring(0, state.from) + state.text.substring(state.to + delim.length);
655
+ }
656
+ return state.text;
657
+ }
658
+ var MarkdownSerializerState = class extends _prosemirrormarkdown.MarkdownSerializerState {
659
+ constructor(nodes, marks, options) {
660
+ super(nodes, marks, options !== null && options !== void 0 ? options : {});
661
+ __publicField(this, "inTable", false);
662
+ this.inlines = [];
663
+ }
664
+ render(node, parent, index) {
665
+ super.render(node, parent, index);
666
+ const top = this.inlines[this.inlines.length - 1];
667
+ if (top !== null && top !== void 0 && top.start && top !== null && top !== void 0 && top.end) {
668
+ const {
669
+ delimiter,
670
+ start,
671
+ end
672
+ } = this.normalizeInline(top);
673
+ this.out = trimInline(this.out, delimiter, start, end);
674
+ this.inlines.pop();
675
+ }
676
+ }
677
+ markString(mark, open, parent, index) {
678
+ const info = this.marks[mark.type.name];
679
+ if (info.expelEnclosingWhitespace) {
680
+ if (open) {
681
+ this.inlines.push({
682
+ start: this.out.length,
683
+ delimiter: info.open
684
+ });
685
+ } else {
686
+ const top = this.inlines.pop();
687
+ this.inlines.push({
688
+ ...top,
689
+ end: this.out.length
690
+ });
691
+ }
692
+ }
693
+ return super.markString(mark, open, parent, index);
694
+ }
695
+ normalizeInline(inline) {
696
+ let {
697
+ start,
698
+ end
699
+ } = inline;
700
+ while (this.out.charAt(start).match(/\s/)) {
701
+ start++;
702
+ }
703
+ return {
704
+ ...inline,
705
+ start
706
+ };
707
+ }
708
+ };
709
+ var HTMLMark = _core.Mark.create({
710
+ name: "markdownHTMLMark",
711
+ /**
712
+ * @return {{markdown: MarkdownMarkSpec}}
713
+ */
714
+ addStorage() {
715
+ return {
716
+ markdown: {
717
+ serialize: {
718
+ open(state, mark) {
719
+ var _getMarkTags$, _getMarkTags;
720
+ if (!this.editor.storage.markdown.options.html) {
721
+ console.warn(`Tiptap Markdown: "${mark.type.name}" mark is only available in html mode`);
722
+ return "";
723
+ }
724
+ return (_getMarkTags$ = (_getMarkTags = getMarkTags(mark)) === null || _getMarkTags === void 0 ? void 0 : _getMarkTags[0]) !== null && _getMarkTags$ !== void 0 ? _getMarkTags$ : "";
725
+ },
726
+ close(state, mark) {
727
+ var _getMarkTags$2, _getMarkTags2;
728
+ if (!this.editor.storage.markdown.options.html) {
729
+ return "";
730
+ }
731
+ return (_getMarkTags$2 = (_getMarkTags2 = getMarkTags(mark)) === null || _getMarkTags2 === void 0 ? void 0 : _getMarkTags2[1]) !== null && _getMarkTags$2 !== void 0 ? _getMarkTags$2 : "";
732
+ }
733
+ },
734
+ parse: {
735
+ // handled by markdown-it
736
+ }
737
+ }
738
+ };
739
+ }
740
+ });
741
+ function getMarkTags(mark) {
742
+ const schema = mark.type.schema;
743
+ const node = schema.text(" ", [mark]);
744
+ const html = _core.getHTMLFromFragment.call(void 0, _model.Fragment.from(node), schema);
745
+ const match = html.match(/^(<.*?>) (<\/.*?>)$/);
746
+ return match ? [match[1], match[2]] : null;
747
+ }
748
+ function elementFromString(value) {
749
+ const wrappedValue = `<body>${value}</body>`;
750
+ return new window.DOMParser().parseFromString(wrappedValue, "text/html").body;
751
+ }
752
+ function escapeHTML(value) {
753
+ return value === null || value === void 0 ? void 0 : value.replace(/</g, "&lt;").replace(/>/g, "&gt;");
754
+ }
755
+ function extractElement(node) {
756
+ const parent = node.parentElement;
757
+ const prepend = parent.cloneNode();
758
+ while (parent.firstChild && parent.firstChild !== node) {
759
+ prepend.appendChild(parent.firstChild);
760
+ }
761
+ if (prepend.childNodes.length > 0) {
762
+ parent.parentElement.insertBefore(prepend, parent);
763
+ }
764
+ parent.parentElement.insertBefore(node, parent);
765
+ if (parent.childNodes.length === 0) {
766
+ parent.remove();
767
+ }
768
+ }
769
+ function unwrapElement(node) {
770
+ const parent = node.parentNode;
771
+ while (node.firstChild)
772
+ parent.insertBefore(node.firstChild, node);
773
+ parent.removeChild(node);
774
+ }
775
+ var HTMLNode = _core.Node.create({
776
+ name: "markdownHTMLNode",
777
+ addStorage() {
778
+ return {
779
+ markdown: {
780
+ serialize(state, node, parent) {
781
+ if (this.editor.storage.markdown.options.html) {
782
+ state.write(serializeHTML(node, parent));
783
+ } else {
784
+ console.warn(`Tiptap Markdown: "${node.type.name}" node is only available in html mode`);
785
+ state.write(`[${node.type.name}]`);
786
+ }
787
+ if (node.isBlock) {
788
+ state.closeBlock(node);
789
+ }
790
+ },
791
+ parse: {
792
+ // handled by markdown-it
793
+ }
794
+ }
795
+ };
796
+ }
797
+ });
798
+ function serializeHTML(node, parent) {
799
+ const schema = node.type.schema;
800
+ const html = _core.getHTMLFromFragment.call(void 0, _model.Fragment.from(node), schema);
801
+ if (node.isBlock && (parent instanceof _model.Fragment || parent.type.name === schema.topNodeType.name)) {
802
+ return formatBlock(html);
803
+ }
804
+ return html;
805
+ }
806
+ function formatBlock(html) {
807
+ const dom = elementFromString(html);
808
+ const element = dom.firstElementChild;
809
+ element.innerHTML = element.innerHTML.trim() ? `
810
+ ${element.innerHTML}
811
+ ` : `
812
+ `;
813
+ return element.outerHTML;
814
+ }
815
+ var Blockquote = _core.Node.create({
816
+ name: "blockquote"
817
+ });
818
+ var Blockquote$1 = Blockquote.extend({
819
+ /**
820
+ * @return {{markdown: MarkdownNodeSpec}}
821
+ */
822
+ addStorage() {
823
+ return {
824
+ markdown: {
825
+ serialize: _prosemirrormarkdown.defaultMarkdownSerializer.nodes.blockquote,
826
+ parse: {
827
+ // handled by markdown-it
828
+ }
829
+ }
830
+ };
831
+ }
832
+ });
833
+ var BulletList = _core.Node.create({
834
+ name: "bulletList"
835
+ });
836
+ var BulletList$1 = BulletList.extend({
837
+ /**
838
+ * @return {{markdown: MarkdownNodeSpec}}
839
+ */
840
+ addStorage() {
841
+ return {
842
+ markdown: {
843
+ serialize(state, node) {
844
+ return state.renderList(node, " ", () => (this.editor.storage.markdown.options.bulletListMarker || "-") + " ");
845
+ },
846
+ parse: {
847
+ // handled by markdown-it
848
+ }
849
+ }
850
+ };
851
+ }
852
+ });
853
+ var CodeBlock = _core.Node.create({
854
+ name: "codeBlock"
855
+ });
856
+ var CodeBlock$1 = CodeBlock.extend({
857
+ /**
858
+ * @return {{markdown: MarkdownNodeSpec}}
859
+ */
860
+ addStorage() {
861
+ return {
862
+ markdown: {
863
+ serialize(state, node) {
864
+ state.write("```" + (node.attrs.language || "") + "\n");
865
+ state.text(node.textContent, false);
866
+ state.ensureNewLine();
867
+ state.write("```");
868
+ state.closeBlock(node);
869
+ },
870
+ parse: {
871
+ setup(markdownit2) {
872
+ var _this$options$languag;
873
+ markdownit2.set({
874
+ langPrefix: (_this$options$languag = this.options.languageClassPrefix) !== null && _this$options$languag !== void 0 ? _this$options$languag : "language-"
875
+ });
876
+ },
877
+ updateDOM(element) {
878
+ element.innerHTML = element.innerHTML.replace(/\n<\/code><\/pre>/g, "</code></pre>");
879
+ }
880
+ }
881
+ }
882
+ };
883
+ }
884
+ });
885
+ var HardBreak = _core.Node.create({
886
+ name: "hardBreak"
887
+ });
888
+ var HardBreak$1 = HardBreak.extend({
889
+ /**
890
+ * @return {{markdown: MarkdownNodeSpec}}
891
+ */
892
+ addStorage() {
893
+ return {
894
+ markdown: {
895
+ serialize(state, node, parent, index) {
896
+ for (let i = index + 1; i < parent.childCount; i++)
897
+ if (parent.child(i).type != node.type) {
898
+ state.write(state.inTable ? HTMLNode.storage.markdown.serialize.call(this, state, node, parent) : "\\\n");
899
+ return;
900
+ }
901
+ },
902
+ parse: {
903
+ // handled by markdown-it
904
+ }
905
+ }
906
+ };
907
+ }
908
+ });
909
+ var Heading = _core.Node.create({
910
+ name: "heading"
911
+ });
912
+ var Heading$1 = Heading.extend({
913
+ /**
914
+ * @return {{markdown: MarkdownNodeSpec}}
915
+ */
916
+ addStorage() {
917
+ return {
918
+ markdown: {
919
+ serialize: _prosemirrormarkdown.defaultMarkdownSerializer.nodes.heading,
920
+ parse: {
921
+ // handled by markdown-it
922
+ }
923
+ }
924
+ };
925
+ }
926
+ });
927
+ var HorizontalRule = _core.Node.create({
928
+ name: "horizontalRule"
929
+ });
930
+ var HorizontalRule$1 = HorizontalRule.extend({
931
+ /**
932
+ * @return {{markdown: MarkdownNodeSpec}}
933
+ */
934
+ addStorage() {
935
+ return {
936
+ markdown: {
937
+ serialize: _prosemirrormarkdown.defaultMarkdownSerializer.nodes.horizontal_rule,
938
+ parse: {
939
+ // handled by markdown-it
940
+ }
941
+ }
942
+ };
943
+ }
944
+ });
945
+ var Image = _core.Node.create({
946
+ name: "image"
947
+ });
948
+ var Image$1 = Image.extend({
949
+ /**
950
+ * @return {{markdown: MarkdownNodeSpec}}
951
+ */
952
+ addStorage() {
953
+ return {
954
+ markdown: {
955
+ serialize: _prosemirrormarkdown.defaultMarkdownSerializer.nodes.image,
956
+ parse: {
957
+ // handled by markdown-it
958
+ }
959
+ }
960
+ };
961
+ }
962
+ });
963
+ var ListItem = _core.Node.create({
964
+ name: "listItem"
965
+ });
966
+ var ListItem$1 = ListItem.extend({
967
+ /**
968
+ * @return {{markdown: MarkdownNodeSpec}}
969
+ */
970
+ addStorage() {
971
+ return {
972
+ markdown: {
973
+ serialize: _prosemirrormarkdown.defaultMarkdownSerializer.nodes.list_item,
974
+ parse: {
975
+ // handled by markdown-it
976
+ }
977
+ }
978
+ };
979
+ }
980
+ });
981
+ var OrderedList = _core.Node.create({
982
+ name: "orderedList"
983
+ });
984
+ function findIndexOfAdjacentNode(node, parent, index) {
985
+ let i = 0;
986
+ for (; index - i > 0; i++) {
987
+ if (parent.child(index - i - 1).type.name !== node.type.name) {
988
+ break;
989
+ }
990
+ }
991
+ return i;
992
+ }
993
+ var OrderedList$1 = OrderedList.extend({
994
+ /**
995
+ * @return {{markdown: MarkdownNodeSpec}}
996
+ */
997
+ addStorage() {
998
+ return {
999
+ markdown: {
1000
+ serialize(state, node, parent, index) {
1001
+ const start = node.attrs.start || 1;
1002
+ const maxW = String(start + node.childCount - 1).length;
1003
+ const space = state.repeat(" ", maxW + 2);
1004
+ const adjacentIndex = findIndexOfAdjacentNode(node, parent, index);
1005
+ const separator = adjacentIndex % 2 ? ") " : ". ";
1006
+ state.renderList(node, space, (i) => {
1007
+ const nStr = String(start + i);
1008
+ return state.repeat(" ", maxW - nStr.length) + nStr + separator;
1009
+ });
1010
+ },
1011
+ parse: {
1012
+ // handled by markdown-it
1013
+ }
1014
+ }
1015
+ };
1016
+ }
1017
+ });
1018
+ var Paragraph = _core.Node.create({
1019
+ name: "paragraph"
1020
+ });
1021
+ var Paragraph$1 = Paragraph.extend({
1022
+ /**
1023
+ * @return {{markdown: MarkdownNodeSpec}}
1024
+ */
1025
+ addStorage() {
1026
+ return {
1027
+ markdown: {
1028
+ serialize: _prosemirrormarkdown.defaultMarkdownSerializer.nodes.paragraph,
1029
+ parse: {
1030
+ // handled by markdown-it
1031
+ }
1032
+ }
1033
+ };
1034
+ }
1035
+ });
1036
+ function childNodes(node) {
1037
+ var _node$content$content, _node$content;
1038
+ return (_node$content$content = node === null || node === void 0 || (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.content) !== null && _node$content$content !== void 0 ? _node$content$content : [];
1039
+ }
1040
+ var Table = _core.Node.create({
1041
+ name: "table"
1042
+ });
1043
+ var Table$1 = Table.extend({
1044
+ /**
1045
+ * @return {{markdown: MarkdownNodeSpec}}
1046
+ */
1047
+ addStorage() {
1048
+ return {
1049
+ markdown: {
1050
+ serialize(state, node, parent) {
1051
+ if (!isMarkdownSerializable(node)) {
1052
+ HTMLNode.storage.markdown.serialize.call(this, state, node, parent);
1053
+ return;
1054
+ }
1055
+ state.inTable = true;
1056
+ node.forEach((row, p, i) => {
1057
+ state.write("| ");
1058
+ row.forEach((col, p2, j) => {
1059
+ if (j) {
1060
+ state.write(" | ");
1061
+ }
1062
+ const cellContent = col.firstChild;
1063
+ if (cellContent.textContent.trim()) {
1064
+ state.renderInline(cellContent);
1065
+ }
1066
+ });
1067
+ state.write(" |");
1068
+ state.ensureNewLine();
1069
+ if (!i) {
1070
+ const delimiterRow = Array.from({
1071
+ length: row.childCount
1072
+ }).map(() => "---").join(" | ");
1073
+ state.write(`| ${delimiterRow} |`);
1074
+ state.ensureNewLine();
1075
+ }
1076
+ });
1077
+ state.closeBlock(node);
1078
+ state.inTable = false;
1079
+ },
1080
+ parse: {
1081
+ // handled by markdown-it
1082
+ }
1083
+ }
1084
+ };
1085
+ }
1086
+ });
1087
+ function hasSpan(node) {
1088
+ return node.attrs.colspan > 1 || node.attrs.rowspan > 1;
1089
+ }
1090
+ function isMarkdownSerializable(node) {
1091
+ const rows = childNodes(node);
1092
+ const firstRow = rows[0];
1093
+ const bodyRows = rows.slice(1);
1094
+ if (childNodes(firstRow).some((cell) => cell.type.name !== "tableHeader" || hasSpan(cell) || cell.childCount > 1)) {
1095
+ return false;
1096
+ }
1097
+ if (bodyRows.some((row) => childNodes(row).some((cell) => cell.type.name === "tableHeader" || hasSpan(cell) || cell.childCount > 1))) {
1098
+ return false;
1099
+ }
1100
+ return true;
1101
+ }
1102
+ var TaskItem = _core.Node.create({
1103
+ name: "taskItem"
1104
+ });
1105
+ var TaskItem$1 = TaskItem.extend({
1106
+ /**
1107
+ * @return {{markdown: MarkdownNodeSpec}}
1108
+ */
1109
+ addStorage() {
1110
+ return {
1111
+ markdown: {
1112
+ serialize(state, node) {
1113
+ const check = node.attrs.checked ? "[x]" : "[ ]";
1114
+ state.write(`${check} `);
1115
+ state.renderContent(node);
1116
+ },
1117
+ parse: {
1118
+ updateDOM(element) {
1119
+ [...element.querySelectorAll(".task-list-item")].forEach((item) => {
1120
+ const input = item.querySelector("input");
1121
+ item.setAttribute("data-type", "taskItem");
1122
+ if (input) {
1123
+ item.setAttribute("data-checked", input.checked);
1124
+ input.remove();
1125
+ }
1126
+ });
1127
+ }
1128
+ }
1129
+ }
1130
+ };
1131
+ }
1132
+ });
1133
+ var TaskList = _core.Node.create({
1134
+ name: "taskList"
1135
+ });
1136
+ var TaskList$1 = TaskList.extend({
1137
+ /**
1138
+ * @return {{markdown: MarkdownNodeSpec}}
1139
+ */
1140
+ addStorage() {
1141
+ return {
1142
+ markdown: {
1143
+ serialize: BulletList$1.storage.markdown.serialize,
1144
+ parse: {
1145
+ setup(markdownit2) {
1146
+ markdownit2.use(_markdownittasklists2.default);
1147
+ },
1148
+ updateDOM(element) {
1149
+ [...element.querySelectorAll(".contains-task-list")].forEach((list) => {
1150
+ list.setAttribute("data-type", "taskList");
1151
+ });
1152
+ }
1153
+ }
1154
+ }
1155
+ };
1156
+ }
1157
+ });
1158
+ var Text = _core.Node.create({
1159
+ name: "text"
1160
+ });
1161
+ var Text$1 = Text.extend({
1162
+ /**
1163
+ * @return {{markdown: MarkdownNodeSpec}}
1164
+ */
1165
+ addStorage() {
1166
+ return {
1167
+ markdown: {
1168
+ serialize(state, node) {
1169
+ state.text(escapeHTML(node.text));
1170
+ },
1171
+ parse: {
1172
+ // handled by markdown-it
1173
+ }
1174
+ }
1175
+ };
1176
+ }
1177
+ });
1178
+ var Bold = _core.Mark.create({
1179
+ name: "bold"
1180
+ });
1181
+ var Bold$1 = Bold.extend({
1182
+ /**
1183
+ * @return {{markdown: MarkdownMarkSpec}}
1184
+ */
1185
+ addStorage() {
1186
+ return {
1187
+ markdown: {
1188
+ serialize: _prosemirrormarkdown.defaultMarkdownSerializer.marks.strong,
1189
+ parse: {
1190
+ // handled by markdown-it
1191
+ }
1192
+ }
1193
+ };
1194
+ }
1195
+ });
1196
+ var Code = _core.Mark.create({
1197
+ name: "code"
1198
+ });
1199
+ var Code$1 = Code.extend({
1200
+ /**
1201
+ * @return {{markdown: MarkdownMarkSpec}}
1202
+ */
1203
+ addStorage() {
1204
+ return {
1205
+ markdown: {
1206
+ serialize: _prosemirrormarkdown.defaultMarkdownSerializer.marks.code,
1207
+ parse: {
1208
+ // handled by markdown-it
1209
+ }
1210
+ }
1211
+ };
1212
+ }
1213
+ });
1214
+ var Italic = _core.Mark.create({
1215
+ name: "italic"
1216
+ });
1217
+ var Italic$1 = Italic.extend({
1218
+ /**
1219
+ * @return {{markdown: MarkdownMarkSpec}}
1220
+ */
1221
+ addStorage() {
1222
+ return {
1223
+ markdown: {
1224
+ serialize: _prosemirrormarkdown.defaultMarkdownSerializer.marks.em,
1225
+ parse: {
1226
+ // handled by markdown-it
1227
+ }
1228
+ }
1229
+ };
1230
+ }
1231
+ });
1232
+ var Link = _core.Mark.create({
1233
+ name: "link"
1234
+ });
1235
+ var Link$1 = Link.extend({
1236
+ /**
1237
+ * @return {{markdown: MarkdownMarkSpec}}
1238
+ */
1239
+ addStorage() {
1240
+ return {
1241
+ markdown: {
1242
+ serialize: _prosemirrormarkdown.defaultMarkdownSerializer.marks.link,
1243
+ parse: {
1244
+ // handled by markdown-it
1245
+ }
1246
+ }
1247
+ };
1248
+ }
1249
+ });
1250
+ var Strike = _core.Mark.create({
1251
+ name: "strike"
1252
+ });
1253
+ var Strike$1 = Strike.extend({
1254
+ /**
1255
+ * @return {{markdown: MarkdownMarkSpec}}
1256
+ */
1257
+ addStorage() {
1258
+ return {
1259
+ markdown: {
1260
+ serialize: {
1261
+ open: "~~",
1262
+ close: "~~",
1263
+ expelEnclosingWhitespace: true
1264
+ },
1265
+ parse: {
1266
+ // handled by markdown-it
1267
+ }
1268
+ }
1269
+ };
1270
+ }
1271
+ });
1272
+ var markdownExtensions = [Blockquote$1, BulletList$1, CodeBlock$1, HardBreak$1, Heading$1, HorizontalRule$1, HTMLNode, Image$1, ListItem$1, OrderedList$1, Paragraph$1, Table$1, TaskItem$1, TaskList$1, Text$1, Bold$1, Code$1, HTMLMark, Italic$1, Link$1, Strike$1];
1273
+ function getMarkdownSpec(extension) {
1274
+ var _extension$storage, _markdownExtensions$f;
1275
+ const markdownSpec = (_extension$storage = extension.storage) === null || _extension$storage === void 0 ? void 0 : _extension$storage.markdown;
1276
+ const defaultMarkdownSpec = (_markdownExtensions$f = markdownExtensions.find((e) => e.name === extension.name)) === null || _markdownExtensions$f === void 0 ? void 0 : _markdownExtensions$f.storage.markdown;
1277
+ if (markdownSpec || defaultMarkdownSpec) {
1278
+ return {
1279
+ ...defaultMarkdownSpec,
1280
+ ...markdownSpec
1281
+ };
1282
+ }
1283
+ return null;
1284
+ }
1285
+ var MarkdownSerializer = class {
1286
+ constructor(editor) {
1287
+ __publicField(this, "editor", null);
1288
+ this.editor = editor;
1289
+ }
1290
+ serialize(content) {
1291
+ const state = new MarkdownSerializerState(this.nodes, this.marks, {
1292
+ hardBreakNodeName: HardBreak$1.name
1293
+ });
1294
+ state.renderContent(content);
1295
+ return state.out;
1296
+ }
1297
+ get nodes() {
1298
+ var _this$editor$extensio;
1299
+ return {
1300
+ ...Object.fromEntries(Object.keys(this.editor.schema.nodes).map((name) => [name, this.serializeNode(HTMLNode)])),
1301
+ ...Object.fromEntries((_this$editor$extensio = this.editor.extensionManager.extensions.filter((extension) => extension.type === "node" && this.serializeNode(extension)).map((extension) => [extension.name, this.serializeNode(extension)])) !== null && _this$editor$extensio !== void 0 ? _this$editor$extensio : [])
1302
+ };
1303
+ }
1304
+ get marks() {
1305
+ var _this$editor$extensio2;
1306
+ return {
1307
+ ...Object.fromEntries(Object.keys(this.editor.schema.marks).map((name) => [name, this.serializeMark(HTMLMark)])),
1308
+ ...Object.fromEntries((_this$editor$extensio2 = this.editor.extensionManager.extensions.filter((extension) => extension.type === "mark" && this.serializeMark(extension)).map((extension) => [extension.name, this.serializeMark(extension)])) !== null && _this$editor$extensio2 !== void 0 ? _this$editor$extensio2 : [])
1309
+ };
1310
+ }
1311
+ serializeNode(node) {
1312
+ var _getMarkdownSpec;
1313
+ return (_getMarkdownSpec = getMarkdownSpec(node)) === null || _getMarkdownSpec === void 0 || (_getMarkdownSpec = _getMarkdownSpec.serialize) === null || _getMarkdownSpec === void 0 ? void 0 : _getMarkdownSpec.bind({
1314
+ editor: this.editor,
1315
+ options: node.options
1316
+ });
1317
+ }
1318
+ serializeMark(mark) {
1319
+ var _getMarkdownSpec2;
1320
+ const serialize = (_getMarkdownSpec2 = getMarkdownSpec(mark)) === null || _getMarkdownSpec2 === void 0 ? void 0 : _getMarkdownSpec2.serialize;
1321
+ return serialize ? {
1322
+ ...serialize,
1323
+ open: typeof serialize.open === "function" ? serialize.open.bind({
1324
+ editor: this.editor,
1325
+ options: mark.options
1326
+ }) : serialize.open,
1327
+ close: typeof serialize.close === "function" ? serialize.close.bind({
1328
+ editor: this.editor,
1329
+ options: mark.options
1330
+ }) : serialize.close
1331
+ } : null;
1332
+ }
1333
+ };
1334
+ var MarkdownParser = class {
1335
+ constructor(editor, _ref) {
1336
+ __publicField(this, "editor", null);
1337
+ __publicField(this, "md", null);
1338
+ let {
1339
+ html,
1340
+ linkify,
1341
+ breaks
1342
+ } = _ref;
1343
+ this.editor = editor;
1344
+ this.md = this.withPatchedRenderer(_markdownit2.default.call(void 0, {
1345
+ html,
1346
+ linkify,
1347
+ breaks
1348
+ }));
1349
+ }
1350
+ parse(content) {
1351
+ let {
1352
+ inline
1353
+ } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1354
+ if (typeof content === "string") {
1355
+ this.editor.extensionManager.extensions.forEach((extension) => {
1356
+ var _getMarkdownSpec;
1357
+ return (_getMarkdownSpec = getMarkdownSpec(extension)) === null || _getMarkdownSpec === void 0 || (_getMarkdownSpec = _getMarkdownSpec.parse) === null || _getMarkdownSpec === void 0 || (_getMarkdownSpec = _getMarkdownSpec.setup) === null || _getMarkdownSpec === void 0 ? void 0 : _getMarkdownSpec.call({
1358
+ editor: this.editor,
1359
+ options: extension.options
1360
+ }, this.md);
1361
+ });
1362
+ const renderedHTML = this.md.render(content);
1363
+ const element = elementFromString(renderedHTML);
1364
+ this.editor.extensionManager.extensions.forEach((extension) => {
1365
+ var _getMarkdownSpec2;
1366
+ return (_getMarkdownSpec2 = getMarkdownSpec(extension)) === null || _getMarkdownSpec2 === void 0 || (_getMarkdownSpec2 = _getMarkdownSpec2.parse) === null || _getMarkdownSpec2 === void 0 || (_getMarkdownSpec2 = _getMarkdownSpec2.updateDOM) === null || _getMarkdownSpec2 === void 0 ? void 0 : _getMarkdownSpec2.call({
1367
+ editor: this.editor,
1368
+ options: extension.options
1369
+ }, element);
1370
+ });
1371
+ this.normalizeDOM(element, {
1372
+ inline,
1373
+ content
1374
+ });
1375
+ return element.innerHTML;
1376
+ }
1377
+ return content;
1378
+ }
1379
+ normalizeDOM(node, _ref2) {
1380
+ let {
1381
+ inline,
1382
+ content
1383
+ } = _ref2;
1384
+ this.normalizeBlocks(node);
1385
+ node.querySelectorAll("*").forEach((el) => {
1386
+ var _el$nextSibling;
1387
+ if (((_el$nextSibling = el.nextSibling) === null || _el$nextSibling === void 0 ? void 0 : _el$nextSibling.nodeType) === Node.TEXT_NODE && !el.closest("pre")) {
1388
+ el.nextSibling.textContent = el.nextSibling.textContent.replace(/^\n/, "");
1389
+ }
1390
+ });
1391
+ if (inline) {
1392
+ this.normalizeInline(node, content);
1393
+ }
1394
+ return node;
1395
+ }
1396
+ normalizeBlocks(node) {
1397
+ const blocks = Object.values(this.editor.schema.nodes).filter((node2) => node2.isBlock);
1398
+ const selector = blocks.map((block) => {
1399
+ var _block$spec$parseDOM;
1400
+ return (_block$spec$parseDOM = block.spec.parseDOM) === null || _block$spec$parseDOM === void 0 ? void 0 : _block$spec$parseDOM.map((spec) => spec.tag);
1401
+ }).flat().filter(Boolean).join(",");
1402
+ if (!selector) {
1403
+ return;
1404
+ }
1405
+ [...node.querySelectorAll(selector)].forEach((el) => {
1406
+ if (el.parentElement.matches("p")) {
1407
+ extractElement(el);
1408
+ }
1409
+ });
1410
+ }
1411
+ normalizeInline(node, content) {
1412
+ var _node$firstElementChi;
1413
+ if ((_node$firstElementChi = node.firstElementChild) !== null && _node$firstElementChi !== void 0 && _node$firstElementChi.matches("p")) {
1414
+ var _content$match$, _content$match, _content$match$2, _content$match2;
1415
+ const firstParagraph = node.firstElementChild;
1416
+ const {
1417
+ nextElementSibling
1418
+ } = firstParagraph;
1419
+ const startSpaces = (_content$match$ = (_content$match = content.match(/^\s+/)) === null || _content$match === void 0 ? void 0 : _content$match[0]) !== null && _content$match$ !== void 0 ? _content$match$ : "";
1420
+ const endSpaces = !nextElementSibling ? (_content$match$2 = (_content$match2 = content.match(/\s+$/)) === null || _content$match2 === void 0 ? void 0 : _content$match2[0]) !== null && _content$match$2 !== void 0 ? _content$match$2 : "" : "";
1421
+ if (content.match(/^\n\n/)) {
1422
+ firstParagraph.innerHTML = `${firstParagraph.innerHTML}${endSpaces}`;
1423
+ return;
1424
+ }
1425
+ unwrapElement(firstParagraph);
1426
+ node.innerHTML = `${startSpaces}${node.innerHTML}${endSpaces}`;
1427
+ }
1428
+ }
1429
+ /**
1430
+ * @param {markdownit} md
1431
+ */
1432
+ withPatchedRenderer(md2) {
1433
+ const withoutNewLine = (renderer) => function() {
1434
+ const rendered = renderer(...arguments);
1435
+ if (rendered === "\n") {
1436
+ return rendered;
1437
+ }
1438
+ if (rendered[rendered.length - 1] === "\n") {
1439
+ return rendered.slice(0, -1);
1440
+ }
1441
+ return rendered;
1442
+ };
1443
+ md2.renderer.rules.hardbreak = withoutNewLine(md2.renderer.rules.hardbreak);
1444
+ md2.renderer.rules.softbreak = withoutNewLine(md2.renderer.rules.softbreak);
1445
+ md2.renderer.rules.fence = withoutNewLine(md2.renderer.rules.fence);
1446
+ md2.renderer.rules.code_block = withoutNewLine(md2.renderer.rules.code_block);
1447
+ md2.renderer.renderToken = withoutNewLine(md2.renderer.renderToken.bind(md2.renderer));
1448
+ return md2;
1449
+ }
1450
+ };
1451
+ var MarkdownClipboard = _core.Extension.create({
1452
+ name: "markdownClipboard",
1453
+ addOptions() {
1454
+ return {
1455
+ transformPastedText: false,
1456
+ transformCopiedText: false
1457
+ };
1458
+ },
1459
+ addProseMirrorPlugins() {
1460
+ return [new (0, _state.Plugin)({
1461
+ key: new (0, _state.PluginKey)("markdownClipboard"),
1462
+ props: {
1463
+ clipboardTextParser: (text, context, plainText) => {
1464
+ if (plainText || !this.options.transformPastedText) {
1465
+ return null;
1466
+ }
1467
+ const parsed = this.editor.storage.markdown.parser.parse(text, {
1468
+ inline: true
1469
+ });
1470
+ return _model.DOMParser.fromSchema(this.editor.schema).parseSlice(elementFromString(parsed), {
1471
+ preserveWhitespace: true,
1472
+ context
1473
+ });
1474
+ },
1475
+ /**
1476
+ * @param {import('prosemirror-model').Slice} slice
1477
+ */
1478
+ clipboardTextSerializer: (slice) => {
1479
+ if (!this.options.transformCopiedText) {
1480
+ return null;
1481
+ }
1482
+ return this.editor.storage.markdown.serializer.serialize(slice.content);
1483
+ }
1484
+ }
1485
+ })];
1486
+ }
1487
+ });
1488
+ var Markdown = _core.Extension.create({
1489
+ name: "markdown",
1490
+ priority: 50,
1491
+ addOptions() {
1492
+ return {
1493
+ html: true,
1494
+ tightLists: true,
1495
+ tightListClass: "tight",
1496
+ bulletListMarker: "-",
1497
+ linkify: false,
1498
+ breaks: false,
1499
+ transformPastedText: false,
1500
+ transformCopiedText: false
1501
+ };
1502
+ },
1503
+ addCommands() {
1504
+ const commands = _core.extensions.Commands.config.addCommands();
1505
+ return {
1506
+ setContent: (content, emitUpdate, parseOptions) => (props) => {
1507
+ return commands.setContent(props.editor.storage.markdown.parser.parse(content), emitUpdate, parseOptions)(props);
1508
+ },
1509
+ insertContentAt: (range, content, options) => (props) => {
1510
+ return commands.insertContentAt(range, props.editor.storage.markdown.parser.parse(content, {
1511
+ inline: true
1512
+ }), options)(props);
1513
+ }
1514
+ };
1515
+ },
1516
+ onBeforeCreate() {
1517
+ this.editor.storage.markdown = {
1518
+ options: {
1519
+ ...this.options
1520
+ },
1521
+ parser: new MarkdownParser(this.editor, this.options),
1522
+ serializer: new MarkdownSerializer(this.editor),
1523
+ getMarkdown: () => {
1524
+ return this.editor.storage.markdown.serializer.serialize(this.editor.state.doc);
1525
+ }
1526
+ };
1527
+ this.editor.options.initialContent = this.editor.options.content;
1528
+ this.editor.options.content = this.editor.storage.markdown.parser.parse(this.editor.options.content);
1529
+ },
1530
+ onCreate() {
1531
+ this.editor.options.content = this.editor.options.initialContent;
1532
+ delete this.editor.options.initialContent;
1533
+ },
1534
+ addStorage() {
1535
+ return {
1536
+ /// storage will be defined in onBeforeCreate() to prevent initial object overriding
1537
+ };
1538
+ },
1539
+ addExtensions() {
1540
+ return [MarkdownTightLists.configure({
1541
+ tight: this.options.tightLists,
1542
+ tightClass: this.options.tightListClass
1543
+ }), MarkdownClipboard.configure({
1544
+ transformPastedText: this.options.transformPastedText,
1545
+ transformCopiedText: this.options.transformCopiedText
1546
+ })];
1547
+ }
1548
+ });
1549
+
1550
+ // src/extensions/markdown.ts
1551
+ var resolveExt = (mod, name) => _optionalChain([mod, 'optionalAccess', _32 => _32[name]]) || _optionalChain([mod, 'optionalAccess', _33 => _33.default, 'optionalAccess', _34 => _34[name]]) || _optionalChain([mod, 'optionalAccess', _35 => _35.default, 'optionalAccess', _36 => _36.default]) || _optionalChain([mod, 'optionalAccess', _37 => _37.default]) || mod;
1552
+ var Markdown2 = resolveExt(Markdown, "Markdown");
1553
+
1554
+ // src/extensions/image.ts
1555
+ var _extensionimage = require('@tiptap/extension-image'); var _Image = _interopRequireWildcard(_extensionimage);
1556
+
1557
+ var resolveExt2 = (mod, name) => _optionalChain([mod, 'optionalAccess', _38 => _38[name]]) || _optionalChain([mod, 'optionalAccess', _39 => _39.default, 'optionalAccess', _40 => _40[name]]) || _optionalChain([mod, 'optionalAccess', _41 => _41.default, 'optionalAccess', _42 => _42.default]) || _optionalChain([mod, 'optionalAccess', _43 => _43.default]) || mod;
1558
+ var BaseImage = resolveExt2(_Image, "Image");
1559
+ var imagePastePluginKey = new (0, _state.PluginKey)("imagePasteHandler");
1560
+ function insertImageNode(view, src, alt) {
1561
+ const { schema } = view.state;
1562
+ const imageType = schema.nodes.image;
1563
+ if (!imageType) return;
1564
+ const node = imageType.create({ src, alt: alt || "" });
1565
+ const tr = view.state.tr.replaceSelectionWith(node);
1566
+ view.dispatch(tr);
1567
+ }
1568
+ function updateImageSrc(view, oldSrc, newSrc) {
1569
+ const { doc } = view.state;
1570
+ let foundPos = null;
1571
+ let foundAttrs = null;
1572
+ doc.descendants((node, pos) => {
1573
+ if (node.type.name === "image" && node.attrs.src === oldSrc) {
1574
+ foundPos = pos;
1575
+ foundAttrs = node.attrs;
1576
+ return false;
1577
+ }
1578
+ });
1579
+ if (foundPos !== null && foundAttrs) {
1580
+ const tr = view.state.tr.setNodeMarkup(foundPos, void 0, {
1581
+ ...foundAttrs,
1582
+ src: newSrc
1583
+ });
1584
+ view.dispatch(tr);
1585
+ }
1586
+ }
1587
+ function removeImageNode(view, src) {
1588
+ const { doc } = view.state;
1589
+ let foundPos = null;
1590
+ let nodeSize = 0;
1591
+ doc.descendants((node, pos) => {
1592
+ if (node.type.name === "image" && node.attrs.src === src) {
1593
+ foundPos = pos;
1594
+ nodeSize = node.nodeSize;
1595
+ return false;
1596
+ }
1597
+ });
1598
+ if (foundPos !== null) {
1599
+ const tr = view.state.tr.delete(foundPos, foundPos + nodeSize);
1600
+ view.dispatch(tr);
1601
+ }
1602
+ }
1603
+ function handleImageInsertion(view, file, options) {
1604
+ if (typeof options.upload === "function") {
1605
+ const hasObjectUrl = typeof URL !== "undefined" && typeof URL.createObjectURL === "function";
1606
+ const tempUrl = hasObjectUrl ? URL.createObjectURL(file) : null;
1607
+ if (tempUrl) {
1608
+ insertImageNode(view, tempUrl, file.name);
1609
+ }
1610
+ Promise.resolve(options.upload(file)).then((uploadedUrl) => {
1611
+ if (!uploadedUrl) {
1612
+ throw new Error("Upload handler returned empty URL");
1613
+ }
1614
+ if (tempUrl) {
1615
+ updateImageSrc(view, tempUrl, uploadedUrl);
1616
+ if (typeof URL.revokeObjectURL === "function") {
1617
+ URL.revokeObjectURL(tempUrl);
1618
+ }
1619
+ } else {
1620
+ insertImageNode(view, uploadedUrl, file.name);
1621
+ }
1622
+ }).catch((err) => {
1623
+ const error = err instanceof Error ? err : new Error(String(err));
1624
+ console.error("Failed to upload pasted image:", error);
1625
+ if (tempUrl) {
1626
+ removeImageNode(view, tempUrl);
1627
+ if (typeof URL.revokeObjectURL === "function") {
1628
+ URL.revokeObjectURL(tempUrl);
1629
+ }
1630
+ }
1631
+ if (typeof options.onUploadError === "function") {
1632
+ options.onUploadError(error, file);
1633
+ }
1634
+ });
1635
+ } else if (options.allowBase64 !== false) {
1636
+ const maxBase64Size = _nullishCoalesce(options.maxBase64Size, () => ( 65536));
1637
+ if (file.size > maxBase64Size) {
1638
+ const err = new Error(
1639
+ `Image size (${Math.round(file.size / 1024)}KB) exceeds maxBase64Size (${Math.round(
1640
+ maxBase64Size / 1024
1641
+ )}KB). Provide an upload handler to support large images.`
1642
+ );
1643
+ console.warn(`[Editor] ${err.message}`);
1644
+ if (typeof options.onUploadError === "function") {
1645
+ options.onUploadError(err, file);
1646
+ }
1647
+ return;
1648
+ }
1649
+ if (typeof FileReader !== "undefined") {
1650
+ const reader = new FileReader();
1651
+ reader.onload = () => {
1652
+ const src = reader.result;
1653
+ if (src) {
1654
+ insertImageNode(view, src, file.name);
1655
+ }
1656
+ };
1657
+ reader.readAsDataURL(file);
1658
+ }
1659
+ }
1660
+ }
1661
+ var Image2 = BaseImage.extend({
1662
+ addOptions() {
1663
+ return {
1664
+ ..._optionalChain([this, 'access', _44 => _44.parent, 'optionalCall', _45 => _45()]),
1665
+ allowBase64: true,
1666
+ maxBase64Size: 65536,
1667
+ enablePaste: true,
1668
+ enableDrop: true,
1669
+ upload: void 0,
1670
+ onUploadError: void 0,
1671
+ HTMLAttributes: {
1672
+ class: "rounded-md max-w-full h-auto my-2"
1673
+ }
1674
+ };
1675
+ },
1676
+ addProseMirrorPlugins() {
1677
+ const parentPlugins = _optionalChain([this, 'access', _46 => _46.parent, 'optionalCall', _47 => _47()]) || [];
1678
+ const options = this.options;
1679
+ if (!options.enablePaste && !options.enableDrop) {
1680
+ return parentPlugins;
1681
+ }
1682
+ const pastePlugin = new (0, _state.Plugin)({
1683
+ key: imagePastePluginKey,
1684
+ props: {
1685
+ handlePaste(view, event) {
1686
+ if (!options.enablePaste) return false;
1687
+ const items = Array.from(_optionalChain([event, 'access', _48 => _48.clipboardData, 'optionalAccess', _49 => _49.items]) || []);
1688
+ const imageItems = items.filter(
1689
+ (item) => item.kind === "file" && item.type.startsWith("image/")
1690
+ );
1691
+ if (imageItems.length === 0) return false;
1692
+ event.preventDefault();
1693
+ for (const item of imageItems) {
1694
+ const file = item.getAsFile();
1695
+ if (!file) continue;
1696
+ handleImageInsertion(view, file, options);
1697
+ }
1698
+ return true;
1699
+ },
1700
+ handleDrop(view, event) {
1701
+ if (!options.enableDrop) return false;
1702
+ const files = Array.from(_optionalChain([event, 'access', _50 => _50.dataTransfer, 'optionalAccess', _51 => _51.files]) || []);
1703
+ const imageFiles = files.filter((f) => f.type.startsWith("image/"));
1704
+ if (imageFiles.length === 0) return false;
1705
+ event.preventDefault();
1706
+ for (const file of imageFiles) {
1707
+ handleImageInsertion(view, file, options);
1708
+ }
1709
+ return true;
1710
+ }
1711
+ }
1712
+ });
1713
+ return [...parentPlugins, pastePlugin];
1714
+ }
1715
+ });
1716
+
1717
+ // src/extensions/rich-text-preset.ts
1718
+ var resolveExt3 = (mod, name) => _optionalChain([mod, 'optionalAccess', _52 => _52[name]]) || _optionalChain([mod, 'optionalAccess', _53 => _53.default, 'optionalAccess', _54 => _54[name]]) || _optionalChain([mod, 'optionalAccess', _55 => _55.default, 'optionalAccess', _56 => _56.default]) || _optionalChain([mod, 'optionalAccess', _57 => _57.default]) || mod;
1719
+ var StarterKit = resolveExt3(_StarterKit, "StarterKit");
1720
+ var Color = resolveExt3(_Color, "Color");
1721
+ var Highlight = resolveExt3(_Highlight, "Highlight");
1722
+ var Link2 = resolveExt3(_Link, "Link");
1723
+ var TaskList2 = resolveExt3(_TaskList, "TaskList");
1724
+ var TaskItem2 = resolveExt3(_TaskItem, "TaskItem");
1725
+ var TextAlign = resolveExt3(_TextAlign, "TextAlign");
1726
+ var TextStyle = resolveExt3(_TextStyle, "TextStyle");
1727
+ var Typography = resolveExt3(_Typography, "Typography");
1728
+ var Underline = resolveExt3(_Underline, "Underline");
1729
+ var Placeholder = resolveExt3(_Placeholder, "Placeholder");
1730
+ var CharacterCount = resolveExt3(_CharacterCount, "CharacterCount");
1731
+ function createRichTextPreset(options = {}) {
1732
+ const {
1733
+ placeholder = "Start typing...",
1734
+ characterLimit,
1735
+ openLinksOnClick = false,
1736
+ enableSmilies = true,
1737
+ enableColorHighlighter = true,
1738
+ headingLevels = [1, 2, 3, 4]
1739
+ } = options;
1740
+ const extensions2 = [
1741
+ StarterKit.configure({
1742
+ orderedList: {
1743
+ HTMLAttributes: {
1744
+ class: "list-decimal pl-4"
1745
+ }
1746
+ },
1747
+ bulletList: {
1748
+ HTMLAttributes: {
1749
+ class: "list-disc pl-4"
1750
+ }
1751
+ },
1752
+ heading: {
1753
+ levels: headingLevels,
1754
+ HTMLAttributes: {
1755
+ class: "font-bold tracking-tight"
1756
+ }
1757
+ }
1758
+ }),
1759
+ TextStyle,
1760
+ Color,
1761
+ Highlight.configure({ multicolor: true }),
1762
+ Underline,
1763
+ Typography,
1764
+ TextAlign.configure({
1765
+ types: ["heading", "paragraph"]
1766
+ }),
1767
+ Link2.extend({
1768
+ addInputRules() {
1769
+ return [
1770
+ _core.markInputRule.call(void 0, {
1771
+ find: /(?:^|\s)\[([^\]]+)\]\(([^)]+)\)$/,
1772
+ type: this.type,
1773
+ getAttributes: (match) => ({
1774
+ href: match[2]
1775
+ })
1776
+ })
1777
+ ];
1778
+ }
1779
+ }).configure({
1780
+ openOnClick: openLinksOnClick,
1781
+ autolink: true,
1782
+ defaultProtocol: "https",
1783
+ protocols: ["file", "vscode", "cursor"],
1784
+ HTMLAttributes: {
1785
+ target: "_blank",
1786
+ rel: "noopener noreferrer",
1787
+ class: "text-blue-500 underline underline-offset-2"
1788
+ }
1789
+ }),
1790
+ TaskList2,
1791
+ TaskItem2.extend({
1792
+ addInputRules() {
1793
+ return [
1794
+ _core.wrappingInputRule.call(void 0, {
1795
+ find: /^\s*(\[([ |x])?\])\s$/i,
1796
+ type: this.type,
1797
+ getAttributes: (match) => ({
1798
+ checked: _optionalChain([match, 'access', _58 => _58[2], 'optionalAccess', _59 => _59.toLowerCase, 'call', _60 => _60()]) === "x"
1799
+ })
1800
+ })
1801
+ ];
1802
+ }
1803
+ }).configure({
1804
+ nested: true
1805
+ }),
1806
+ FontSize,
1807
+ Placeholder.configure({
1808
+ emptyEditorClass: "is-empty",
1809
+ placeholder: typeof placeholder === "function" ? placeholder : () => placeholder
1810
+ })
1811
+ ];
1812
+ if (characterLimit) {
1813
+ extensions2.push(
1814
+ CharacterCount.configure({
1815
+ limit: characterLimit
1816
+ })
1817
+ );
1818
+ }
1819
+ if (enableSmilies) {
1820
+ extensions2.push(SmilieReplacer);
1821
+ }
1822
+ if (enableColorHighlighter) {
1823
+ extensions2.push(ColorHighlighter);
1824
+ }
1825
+ if (options.mention) {
1826
+ const mentionConfig = typeof options.mention === "object" ? options.mention : {};
1827
+ extensions2.push(
1828
+ Mention.configure({
1829
+ HTMLAttributes: {
1830
+ class: "pixerate-mention-node",
1831
+ ...mentionConfig.HTMLAttributes || {}
1832
+ },
1833
+ ...mentionConfig
1834
+ })
1835
+ );
1836
+ }
1837
+ if (options.markdown) {
1838
+ const markdownConfig = typeof options.markdown === "object" ? options.markdown : {};
1839
+ extensions2.push(
1840
+ Markdown2.configure({
1841
+ html: true,
1842
+ tightLists: true,
1843
+ tightListClass: "tight",
1844
+ bulletListMarker: "-",
1845
+ linkify: true,
1846
+ breaks: true,
1847
+ transformPastedText: true,
1848
+ transformCopiedText: true,
1849
+ ...markdownConfig
1850
+ })
1851
+ );
1852
+ }
1853
+ if (options.image !== false) {
1854
+ const imageConfig = typeof options.image === "object" ? options.image : {};
1855
+ extensions2.push(
1856
+ Image2.configure({
1857
+ HTMLAttributes: {
1858
+ class: "rounded-md max-w-full h-auto my-2",
1859
+ ...imageConfig.HTMLAttributes || {}
1860
+ },
1861
+ ...imageConfig
1862
+ })
1863
+ );
1864
+ }
1865
+ return extensions2;
1866
+ }
1867
+
1868
+
1869
+
1870
+
1871
+
1872
+
1873
+
1874
+
1875
+
1876
+
1877
+
1878
+
1879
+
1880
+
1881
+
1882
+
1883
+
1884
+
1885
+
1886
+
1887
+ exports.GradientText = GradientText; exports.SlashCommands = SlashCommands; exports.TemplateSuggestions = TemplateSuggestions; exports.LoadingNode = LoadingNode; exports.SmilieReplacer = SmilieReplacer; exports.findHexColors = findHexColors; exports.ColorHighlighter = ColorHighlighter; exports.FontSize = FontSize; exports.Mention = Mention; exports.createMentionExtension = createMentionExtension; exports.Markdown = Markdown2; exports.imagePastePluginKey = imagePastePluginKey; exports.insertImageNode = insertImageNode; exports.updateImageSrc = updateImageSrc; exports.removeImageNode = removeImageNode; exports.handleImageInsertion = handleImageInsertion; exports.Image = Image2; exports.createRichTextPreset = createRichTextPreset;
1888
+ //# sourceMappingURL=chunk-LDES3EOS.cjs.map