@threadlabs/looma 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/editor/{chunk-NOOV344H.js → chunk-PQAV4KXC.js} +28 -0
- package/editor/chunk-YGJLGDQC.js +4010 -0
- package/editor/extensions/index.d.ts +4 -8
- package/editor/extensions/index.js +1 -1
- package/editor/index.d.ts +0 -3
- package/editor/index.js +2 -2
- package/editor/ui.js +1 -1
- package/package.json +1 -125
- package/editor/chunk-JKRA4D4W.js +0 -435
|
@@ -0,0 +1,4010 @@
|
|
|
1
|
+
// ../../node_modules/.pnpm/@tiptap+extension-document@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-document/dist/index.js
|
|
2
|
+
import { Node } from "@tiptap/core";
|
|
3
|
+
var Document = Node.create({
|
|
4
|
+
name: "doc",
|
|
5
|
+
topNode: true,
|
|
6
|
+
content: "block+"
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// ../../node_modules/.pnpm/@tiptap+extension-paragraph@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-paragraph/dist/index.js
|
|
10
|
+
import { Node as Node2, mergeAttributes } from "@tiptap/core";
|
|
11
|
+
var Paragraph = Node2.create({
|
|
12
|
+
name: "paragraph",
|
|
13
|
+
priority: 1e3,
|
|
14
|
+
addOptions() {
|
|
15
|
+
return {
|
|
16
|
+
HTMLAttributes: {}
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
group: "block",
|
|
20
|
+
content: "inline*",
|
|
21
|
+
parseHTML() {
|
|
22
|
+
return [
|
|
23
|
+
{ tag: "p" }
|
|
24
|
+
];
|
|
25
|
+
},
|
|
26
|
+
renderHTML({ HTMLAttributes }) {
|
|
27
|
+
return ["p", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
28
|
+
},
|
|
29
|
+
addCommands() {
|
|
30
|
+
return {
|
|
31
|
+
setParagraph: () => ({ commands }) => {
|
|
32
|
+
return commands.setNode(this.name);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
addKeyboardShortcuts() {
|
|
37
|
+
return {
|
|
38
|
+
"Mod-Alt-0": () => this.editor.commands.setParagraph()
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// ../../node_modules/.pnpm/@tiptap+extension-text@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-text/dist/index.js
|
|
44
|
+
import { Node as Node3 } from "@tiptap/core";
|
|
45
|
+
var Text = Node3.create({
|
|
46
|
+
name: "text",
|
|
47
|
+
group: "inline"
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// ../../node_modules/.pnpm/@tiptap+extension-bold@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-bold/dist/index.js
|
|
51
|
+
import { Mark, mergeAttributes as mergeAttributes2, markInputRule, markPasteRule } from "@tiptap/core";
|
|
52
|
+
var starInputRegex = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/;
|
|
53
|
+
var starPasteRegex = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g;
|
|
54
|
+
var underscoreInputRegex = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/;
|
|
55
|
+
var underscorePasteRegex = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g;
|
|
56
|
+
var Bold = Mark.create({
|
|
57
|
+
name: "bold",
|
|
58
|
+
addOptions() {
|
|
59
|
+
return {
|
|
60
|
+
HTMLAttributes: {}
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
parseHTML() {
|
|
64
|
+
return [
|
|
65
|
+
{
|
|
66
|
+
tag: "strong"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
tag: "b",
|
|
70
|
+
getAttrs: (node) => node.style.fontWeight !== "normal" && null
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
style: "font-weight=400",
|
|
74
|
+
clearMark: (mark) => mark.type.name === this.name
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
style: "font-weight",
|
|
78
|
+
getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
},
|
|
82
|
+
renderHTML({ HTMLAttributes }) {
|
|
83
|
+
return ["strong", mergeAttributes2(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
84
|
+
},
|
|
85
|
+
addCommands() {
|
|
86
|
+
return {
|
|
87
|
+
setBold: () => ({ commands }) => {
|
|
88
|
+
return commands.setMark(this.name);
|
|
89
|
+
},
|
|
90
|
+
toggleBold: () => ({ commands }) => {
|
|
91
|
+
return commands.toggleMark(this.name);
|
|
92
|
+
},
|
|
93
|
+
unsetBold: () => ({ commands }) => {
|
|
94
|
+
return commands.unsetMark(this.name);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
addKeyboardShortcuts() {
|
|
99
|
+
return {
|
|
100
|
+
"Mod-b": () => this.editor.commands.toggleBold(),
|
|
101
|
+
"Mod-B": () => this.editor.commands.toggleBold()
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
addInputRules() {
|
|
105
|
+
return [
|
|
106
|
+
markInputRule({
|
|
107
|
+
find: starInputRegex,
|
|
108
|
+
type: this.type
|
|
109
|
+
}),
|
|
110
|
+
markInputRule({
|
|
111
|
+
find: underscoreInputRegex,
|
|
112
|
+
type: this.type
|
|
113
|
+
})
|
|
114
|
+
];
|
|
115
|
+
},
|
|
116
|
+
addPasteRules() {
|
|
117
|
+
return [
|
|
118
|
+
markPasteRule({
|
|
119
|
+
find: starPasteRegex,
|
|
120
|
+
type: this.type
|
|
121
|
+
}),
|
|
122
|
+
markPasteRule({
|
|
123
|
+
find: underscorePasteRegex,
|
|
124
|
+
type: this.type
|
|
125
|
+
})
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// ../../node_modules/.pnpm/@tiptap+extension-italic@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-italic/dist/index.js
|
|
131
|
+
import { Mark as Mark2, mergeAttributes as mergeAttributes3, markInputRule as markInputRule2, markPasteRule as markPasteRule2 } from "@tiptap/core";
|
|
132
|
+
var starInputRegex2 = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/;
|
|
133
|
+
var starPasteRegex2 = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g;
|
|
134
|
+
var underscoreInputRegex2 = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/;
|
|
135
|
+
var underscorePasteRegex2 = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g;
|
|
136
|
+
var Italic = Mark2.create({
|
|
137
|
+
name: "italic",
|
|
138
|
+
addOptions() {
|
|
139
|
+
return {
|
|
140
|
+
HTMLAttributes: {}
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
parseHTML() {
|
|
144
|
+
return [
|
|
145
|
+
{
|
|
146
|
+
tag: "em"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
tag: "i",
|
|
150
|
+
getAttrs: (node) => node.style.fontStyle !== "normal" && null
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
style: "font-style=normal",
|
|
154
|
+
clearMark: (mark) => mark.type.name === this.name
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
style: "font-style=italic"
|
|
158
|
+
}
|
|
159
|
+
];
|
|
160
|
+
},
|
|
161
|
+
renderHTML({ HTMLAttributes }) {
|
|
162
|
+
return ["em", mergeAttributes3(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
163
|
+
},
|
|
164
|
+
addCommands() {
|
|
165
|
+
return {
|
|
166
|
+
setItalic: () => ({ commands }) => {
|
|
167
|
+
return commands.setMark(this.name);
|
|
168
|
+
},
|
|
169
|
+
toggleItalic: () => ({ commands }) => {
|
|
170
|
+
return commands.toggleMark(this.name);
|
|
171
|
+
},
|
|
172
|
+
unsetItalic: () => ({ commands }) => {
|
|
173
|
+
return commands.unsetMark(this.name);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
addKeyboardShortcuts() {
|
|
178
|
+
return {
|
|
179
|
+
"Mod-i": () => this.editor.commands.toggleItalic(),
|
|
180
|
+
"Mod-I": () => this.editor.commands.toggleItalic()
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
addInputRules() {
|
|
184
|
+
return [
|
|
185
|
+
markInputRule2({
|
|
186
|
+
find: starInputRegex2,
|
|
187
|
+
type: this.type
|
|
188
|
+
}),
|
|
189
|
+
markInputRule2({
|
|
190
|
+
find: underscoreInputRegex2,
|
|
191
|
+
type: this.type
|
|
192
|
+
})
|
|
193
|
+
];
|
|
194
|
+
},
|
|
195
|
+
addPasteRules() {
|
|
196
|
+
return [
|
|
197
|
+
markPasteRule2({
|
|
198
|
+
find: starPasteRegex2,
|
|
199
|
+
type: this.type
|
|
200
|
+
}),
|
|
201
|
+
markPasteRule2({
|
|
202
|
+
find: underscorePasteRegex2,
|
|
203
|
+
type: this.type
|
|
204
|
+
})
|
|
205
|
+
];
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// ../../node_modules/.pnpm/@tiptap+extension-strike@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-strike/dist/index.js
|
|
210
|
+
import { Mark as Mark3, mergeAttributes as mergeAttributes4, markInputRule as markInputRule3, markPasteRule as markPasteRule3 } from "@tiptap/core";
|
|
211
|
+
var inputRegex = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/;
|
|
212
|
+
var pasteRegex = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g;
|
|
213
|
+
var Strike = Mark3.create({
|
|
214
|
+
name: "strike",
|
|
215
|
+
addOptions() {
|
|
216
|
+
return {
|
|
217
|
+
HTMLAttributes: {}
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
parseHTML() {
|
|
221
|
+
return [
|
|
222
|
+
{
|
|
223
|
+
tag: "s"
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
tag: "del"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
tag: "strike"
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
style: "text-decoration",
|
|
233
|
+
consuming: false,
|
|
234
|
+
getAttrs: (style) => style.includes("line-through") ? {} : false
|
|
235
|
+
}
|
|
236
|
+
];
|
|
237
|
+
},
|
|
238
|
+
renderHTML({ HTMLAttributes }) {
|
|
239
|
+
return ["s", mergeAttributes4(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
240
|
+
},
|
|
241
|
+
addCommands() {
|
|
242
|
+
return {
|
|
243
|
+
setStrike: () => ({ commands }) => {
|
|
244
|
+
return commands.setMark(this.name);
|
|
245
|
+
},
|
|
246
|
+
toggleStrike: () => ({ commands }) => {
|
|
247
|
+
return commands.toggleMark(this.name);
|
|
248
|
+
},
|
|
249
|
+
unsetStrike: () => ({ commands }) => {
|
|
250
|
+
return commands.unsetMark(this.name);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
},
|
|
254
|
+
addKeyboardShortcuts() {
|
|
255
|
+
return {
|
|
256
|
+
"Mod-Shift-s": () => this.editor.commands.toggleStrike()
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
addInputRules() {
|
|
260
|
+
return [
|
|
261
|
+
markInputRule3({
|
|
262
|
+
find: inputRegex,
|
|
263
|
+
type: this.type
|
|
264
|
+
})
|
|
265
|
+
];
|
|
266
|
+
},
|
|
267
|
+
addPasteRules() {
|
|
268
|
+
return [
|
|
269
|
+
markPasteRule3({
|
|
270
|
+
find: pasteRegex,
|
|
271
|
+
type: this.type
|
|
272
|
+
})
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// ../../node_modules/.pnpm/@tiptap+extension-underline@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-underline/dist/index.js
|
|
278
|
+
import { Mark as Mark4, mergeAttributes as mergeAttributes5 } from "@tiptap/core";
|
|
279
|
+
var Underline = Mark4.create({
|
|
280
|
+
name: "underline",
|
|
281
|
+
addOptions() {
|
|
282
|
+
return {
|
|
283
|
+
HTMLAttributes: {}
|
|
284
|
+
};
|
|
285
|
+
},
|
|
286
|
+
parseHTML() {
|
|
287
|
+
return [
|
|
288
|
+
{
|
|
289
|
+
tag: "u"
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
style: "text-decoration",
|
|
293
|
+
consuming: false,
|
|
294
|
+
getAttrs: (style) => style.includes("underline") ? {} : false
|
|
295
|
+
}
|
|
296
|
+
];
|
|
297
|
+
},
|
|
298
|
+
renderHTML({ HTMLAttributes }) {
|
|
299
|
+
return ["u", mergeAttributes5(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
300
|
+
},
|
|
301
|
+
addCommands() {
|
|
302
|
+
return {
|
|
303
|
+
setUnderline: () => ({ commands }) => {
|
|
304
|
+
return commands.setMark(this.name);
|
|
305
|
+
},
|
|
306
|
+
toggleUnderline: () => ({ commands }) => {
|
|
307
|
+
return commands.toggleMark(this.name);
|
|
308
|
+
},
|
|
309
|
+
unsetUnderline: () => ({ commands }) => {
|
|
310
|
+
return commands.unsetMark(this.name);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
},
|
|
314
|
+
addKeyboardShortcuts() {
|
|
315
|
+
return {
|
|
316
|
+
"Mod-u": () => this.editor.commands.toggleUnderline(),
|
|
317
|
+
"Mod-U": () => this.editor.commands.toggleUnderline()
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// ../../node_modules/.pnpm/@tiptap+extension-heading@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-heading/dist/index.js
|
|
323
|
+
import { Node as Node4, mergeAttributes as mergeAttributes6, textblockTypeInputRule } from "@tiptap/core";
|
|
324
|
+
var Heading = Node4.create({
|
|
325
|
+
name: "heading",
|
|
326
|
+
addOptions() {
|
|
327
|
+
return {
|
|
328
|
+
levels: [1, 2, 3, 4, 5, 6],
|
|
329
|
+
HTMLAttributes: {}
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
content: "inline*",
|
|
333
|
+
group: "block",
|
|
334
|
+
defining: true,
|
|
335
|
+
addAttributes() {
|
|
336
|
+
return {
|
|
337
|
+
level: {
|
|
338
|
+
default: 1,
|
|
339
|
+
rendered: false
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
},
|
|
343
|
+
parseHTML() {
|
|
344
|
+
return this.options.levels.map((level) => ({
|
|
345
|
+
tag: `h${level}`,
|
|
346
|
+
attrs: { level }
|
|
347
|
+
}));
|
|
348
|
+
},
|
|
349
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
350
|
+
const hasLevel = this.options.levels.includes(node.attrs.level);
|
|
351
|
+
const level = hasLevel ? node.attrs.level : this.options.levels[0];
|
|
352
|
+
return [`h${level}`, mergeAttributes6(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
353
|
+
},
|
|
354
|
+
addCommands() {
|
|
355
|
+
return {
|
|
356
|
+
setHeading: (attributes) => ({ commands }) => {
|
|
357
|
+
if (!this.options.levels.includes(attributes.level)) {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
return commands.setNode(this.name, attributes);
|
|
361
|
+
},
|
|
362
|
+
toggleHeading: (attributes) => ({ commands }) => {
|
|
363
|
+
if (!this.options.levels.includes(attributes.level)) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
return commands.toggleNode(this.name, "paragraph", attributes);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
},
|
|
370
|
+
addKeyboardShortcuts() {
|
|
371
|
+
return this.options.levels.reduce((items, level) => ({
|
|
372
|
+
...items,
|
|
373
|
+
...{
|
|
374
|
+
[`Mod-Alt-${level}`]: () => this.editor.commands.toggleHeading({ level })
|
|
375
|
+
}
|
|
376
|
+
}), {});
|
|
377
|
+
},
|
|
378
|
+
addInputRules() {
|
|
379
|
+
return this.options.levels.map((level) => {
|
|
380
|
+
return textblockTypeInputRule({
|
|
381
|
+
find: new RegExp(`^(#{${Math.min(...this.options.levels)},${level}})\\s$`),
|
|
382
|
+
type: this.type,
|
|
383
|
+
getAttributes: {
|
|
384
|
+
level
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// ../../node_modules/.pnpm/@tiptap+extension-bullet-list@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-bullet-list/dist/index.js
|
|
392
|
+
import { Node as Node5, mergeAttributes as mergeAttributes7, wrappingInputRule } from "@tiptap/core";
|
|
393
|
+
var ListItemName = "listItem";
|
|
394
|
+
var TextStyleName = "textStyle";
|
|
395
|
+
var inputRegex2 = /^\s*([-+*])\s$/;
|
|
396
|
+
var BulletList = Node5.create({
|
|
397
|
+
name: "bulletList",
|
|
398
|
+
addOptions() {
|
|
399
|
+
return {
|
|
400
|
+
itemTypeName: "listItem",
|
|
401
|
+
HTMLAttributes: {},
|
|
402
|
+
keepMarks: false,
|
|
403
|
+
keepAttributes: false
|
|
404
|
+
};
|
|
405
|
+
},
|
|
406
|
+
group: "block list",
|
|
407
|
+
content() {
|
|
408
|
+
return `${this.options.itemTypeName}+`;
|
|
409
|
+
},
|
|
410
|
+
parseHTML() {
|
|
411
|
+
return [
|
|
412
|
+
{ tag: "ul" }
|
|
413
|
+
];
|
|
414
|
+
},
|
|
415
|
+
renderHTML({ HTMLAttributes }) {
|
|
416
|
+
return ["ul", mergeAttributes7(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
417
|
+
},
|
|
418
|
+
addCommands() {
|
|
419
|
+
return {
|
|
420
|
+
toggleBulletList: () => ({ commands, chain }) => {
|
|
421
|
+
if (this.options.keepAttributes) {
|
|
422
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
|
|
423
|
+
}
|
|
424
|
+
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
},
|
|
428
|
+
addKeyboardShortcuts() {
|
|
429
|
+
return {
|
|
430
|
+
"Mod-Shift-8": () => this.editor.commands.toggleBulletList()
|
|
431
|
+
};
|
|
432
|
+
},
|
|
433
|
+
addInputRules() {
|
|
434
|
+
let inputRule = wrappingInputRule({
|
|
435
|
+
find: inputRegex2,
|
|
436
|
+
type: this.type
|
|
437
|
+
});
|
|
438
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
439
|
+
inputRule = wrappingInputRule({
|
|
440
|
+
find: inputRegex2,
|
|
441
|
+
type: this.type,
|
|
442
|
+
keepMarks: this.options.keepMarks,
|
|
443
|
+
keepAttributes: this.options.keepAttributes,
|
|
444
|
+
getAttributes: () => {
|
|
445
|
+
return this.editor.getAttributes(TextStyleName);
|
|
446
|
+
},
|
|
447
|
+
editor: this.editor
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
return [
|
|
451
|
+
inputRule
|
|
452
|
+
];
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
// ../../node_modules/.pnpm/@tiptap+extension-ordered-list@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-ordered-list/dist/index.js
|
|
457
|
+
import { Node as Node6, mergeAttributes as mergeAttributes8, wrappingInputRule as wrappingInputRule2 } from "@tiptap/core";
|
|
458
|
+
var ListItemName2 = "listItem";
|
|
459
|
+
var TextStyleName2 = "textStyle";
|
|
460
|
+
var inputRegex3 = /^(\d+)\.\s$/;
|
|
461
|
+
var OrderedList = Node6.create({
|
|
462
|
+
name: "orderedList",
|
|
463
|
+
addOptions() {
|
|
464
|
+
return {
|
|
465
|
+
itemTypeName: "listItem",
|
|
466
|
+
HTMLAttributes: {},
|
|
467
|
+
keepMarks: false,
|
|
468
|
+
keepAttributes: false
|
|
469
|
+
};
|
|
470
|
+
},
|
|
471
|
+
group: "block list",
|
|
472
|
+
content() {
|
|
473
|
+
return `${this.options.itemTypeName}+`;
|
|
474
|
+
},
|
|
475
|
+
addAttributes() {
|
|
476
|
+
return {
|
|
477
|
+
start: {
|
|
478
|
+
default: 1,
|
|
479
|
+
parseHTML: (element) => {
|
|
480
|
+
return element.hasAttribute("start") ? parseInt(element.getAttribute("start") || "", 10) : 1;
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
type: {
|
|
484
|
+
default: null,
|
|
485
|
+
parseHTML: (element) => element.getAttribute("type")
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
},
|
|
489
|
+
parseHTML() {
|
|
490
|
+
return [
|
|
491
|
+
{
|
|
492
|
+
tag: "ol"
|
|
493
|
+
}
|
|
494
|
+
];
|
|
495
|
+
},
|
|
496
|
+
renderHTML({ HTMLAttributes }) {
|
|
497
|
+
const { start, ...attributesWithoutStart } = HTMLAttributes;
|
|
498
|
+
return start === 1 ? ["ol", mergeAttributes8(this.options.HTMLAttributes, attributesWithoutStart), 0] : ["ol", mergeAttributes8(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
499
|
+
},
|
|
500
|
+
addCommands() {
|
|
501
|
+
return {
|
|
502
|
+
toggleOrderedList: () => ({ commands, chain }) => {
|
|
503
|
+
if (this.options.keepAttributes) {
|
|
504
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName2, this.editor.getAttributes(TextStyleName2)).run();
|
|
505
|
+
}
|
|
506
|
+
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
},
|
|
510
|
+
addKeyboardShortcuts() {
|
|
511
|
+
return {
|
|
512
|
+
"Mod-Shift-7": () => this.editor.commands.toggleOrderedList()
|
|
513
|
+
};
|
|
514
|
+
},
|
|
515
|
+
addInputRules() {
|
|
516
|
+
let inputRule = wrappingInputRule2({
|
|
517
|
+
find: inputRegex3,
|
|
518
|
+
type: this.type,
|
|
519
|
+
getAttributes: (match) => ({ start: +match[1] }),
|
|
520
|
+
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1]
|
|
521
|
+
});
|
|
522
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
523
|
+
inputRule = wrappingInputRule2({
|
|
524
|
+
find: inputRegex3,
|
|
525
|
+
type: this.type,
|
|
526
|
+
keepMarks: this.options.keepMarks,
|
|
527
|
+
keepAttributes: this.options.keepAttributes,
|
|
528
|
+
getAttributes: (match) => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName2) }),
|
|
529
|
+
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
|
|
530
|
+
editor: this.editor
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
return [
|
|
534
|
+
inputRule
|
|
535
|
+
];
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// ../../node_modules/.pnpm/@tiptap+extension-list-item@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-list-item/dist/index.js
|
|
540
|
+
import { Node as Node7, mergeAttributes as mergeAttributes9 } from "@tiptap/core";
|
|
541
|
+
var ListItem = Node7.create({
|
|
542
|
+
name: "listItem",
|
|
543
|
+
addOptions() {
|
|
544
|
+
return {
|
|
545
|
+
HTMLAttributes: {},
|
|
546
|
+
bulletListTypeName: "bulletList",
|
|
547
|
+
orderedListTypeName: "orderedList"
|
|
548
|
+
};
|
|
549
|
+
},
|
|
550
|
+
content: "paragraph block*",
|
|
551
|
+
defining: true,
|
|
552
|
+
parseHTML() {
|
|
553
|
+
return [
|
|
554
|
+
{
|
|
555
|
+
tag: "li"
|
|
556
|
+
}
|
|
557
|
+
];
|
|
558
|
+
},
|
|
559
|
+
renderHTML({ HTMLAttributes }) {
|
|
560
|
+
return ["li", mergeAttributes9(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
561
|
+
},
|
|
562
|
+
addKeyboardShortcuts() {
|
|
563
|
+
return {
|
|
564
|
+
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
565
|
+
Tab: () => this.editor.commands.sinkListItem(this.name),
|
|
566
|
+
"Shift-Tab": () => this.editor.commands.liftListItem(this.name)
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
// ../../node_modules/.pnpm/@tiptap+extension-task-list@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-task-list/dist/index.js
|
|
572
|
+
import { Node as Node8, mergeAttributes as mergeAttributes10 } from "@tiptap/core";
|
|
573
|
+
var TaskList = Node8.create({
|
|
574
|
+
name: "taskList",
|
|
575
|
+
addOptions() {
|
|
576
|
+
return {
|
|
577
|
+
itemTypeName: "taskItem",
|
|
578
|
+
HTMLAttributes: {}
|
|
579
|
+
};
|
|
580
|
+
},
|
|
581
|
+
group: "block list",
|
|
582
|
+
content() {
|
|
583
|
+
return `${this.options.itemTypeName}+`;
|
|
584
|
+
},
|
|
585
|
+
parseHTML() {
|
|
586
|
+
return [
|
|
587
|
+
{
|
|
588
|
+
tag: `ul[data-type="${this.name}"]`,
|
|
589
|
+
priority: 51
|
|
590
|
+
}
|
|
591
|
+
];
|
|
592
|
+
},
|
|
593
|
+
renderHTML({ HTMLAttributes }) {
|
|
594
|
+
return ["ul", mergeAttributes10(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }), 0];
|
|
595
|
+
},
|
|
596
|
+
addCommands() {
|
|
597
|
+
return {
|
|
598
|
+
toggleTaskList: () => ({ commands }) => {
|
|
599
|
+
return commands.toggleList(this.name, this.options.itemTypeName);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
},
|
|
603
|
+
addKeyboardShortcuts() {
|
|
604
|
+
return {
|
|
605
|
+
"Mod-Shift-9": () => this.editor.commands.toggleTaskList()
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
// ../../node_modules/.pnpm/@tiptap+extension-task-item@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/extension-task-item/dist/index.js
|
|
611
|
+
import { Node as Node9, mergeAttributes as mergeAttributes11, wrappingInputRule as wrappingInputRule3 } from "@tiptap/core";
|
|
612
|
+
var inputRegex4 = /^\s*(\[([( |x])?\])\s$/;
|
|
613
|
+
var TaskItem = Node9.create({
|
|
614
|
+
name: "taskItem",
|
|
615
|
+
addOptions() {
|
|
616
|
+
return {
|
|
617
|
+
nested: false,
|
|
618
|
+
HTMLAttributes: {},
|
|
619
|
+
taskListTypeName: "taskList",
|
|
620
|
+
a11y: void 0
|
|
621
|
+
};
|
|
622
|
+
},
|
|
623
|
+
content() {
|
|
624
|
+
return this.options.nested ? "paragraph block*" : "paragraph+";
|
|
625
|
+
},
|
|
626
|
+
defining: true,
|
|
627
|
+
addAttributes() {
|
|
628
|
+
return {
|
|
629
|
+
checked: {
|
|
630
|
+
default: false,
|
|
631
|
+
keepOnSplit: false,
|
|
632
|
+
parseHTML: (element) => {
|
|
633
|
+
const dataChecked = element.getAttribute("data-checked");
|
|
634
|
+
return dataChecked === "" || dataChecked === "true";
|
|
635
|
+
},
|
|
636
|
+
renderHTML: (attributes) => ({
|
|
637
|
+
"data-checked": attributes.checked
|
|
638
|
+
})
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
},
|
|
642
|
+
parseHTML() {
|
|
643
|
+
return [
|
|
644
|
+
{
|
|
645
|
+
tag: `li[data-type="${this.name}"]`,
|
|
646
|
+
priority: 51
|
|
647
|
+
}
|
|
648
|
+
];
|
|
649
|
+
},
|
|
650
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
651
|
+
return [
|
|
652
|
+
"li",
|
|
653
|
+
mergeAttributes11(this.options.HTMLAttributes, HTMLAttributes, {
|
|
654
|
+
"data-type": this.name
|
|
655
|
+
}),
|
|
656
|
+
[
|
|
657
|
+
"label",
|
|
658
|
+
[
|
|
659
|
+
"input",
|
|
660
|
+
{
|
|
661
|
+
type: "checkbox",
|
|
662
|
+
checked: node.attrs.checked ? "checked" : null
|
|
663
|
+
}
|
|
664
|
+
],
|
|
665
|
+
["span"]
|
|
666
|
+
],
|
|
667
|
+
["div", 0]
|
|
668
|
+
];
|
|
669
|
+
},
|
|
670
|
+
addKeyboardShortcuts() {
|
|
671
|
+
const shortcuts = {
|
|
672
|
+
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
673
|
+
"Shift-Tab": () => this.editor.commands.liftListItem(this.name)
|
|
674
|
+
};
|
|
675
|
+
if (!this.options.nested) {
|
|
676
|
+
return shortcuts;
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
...shortcuts,
|
|
680
|
+
Tab: () => this.editor.commands.sinkListItem(this.name)
|
|
681
|
+
};
|
|
682
|
+
},
|
|
683
|
+
addNodeView() {
|
|
684
|
+
return ({ node, HTMLAttributes, getPos, editor }) => {
|
|
685
|
+
const listItem = document.createElement("li");
|
|
686
|
+
const checkboxWrapper = document.createElement("label");
|
|
687
|
+
const checkboxStyler = document.createElement("span");
|
|
688
|
+
const checkbox = document.createElement("input");
|
|
689
|
+
const content = document.createElement("div");
|
|
690
|
+
const updateA11Y = () => {
|
|
691
|
+
var _a, _b;
|
|
692
|
+
checkbox.ariaLabel = ((_b = (_a = this.options.a11y) === null || _a === void 0 ? void 0 : _a.checkboxLabel) === null || _b === void 0 ? void 0 : _b.call(_a, node, checkbox.checked)) || `Task item checkbox for ${node.textContent || "empty task item"}`;
|
|
693
|
+
};
|
|
694
|
+
updateA11Y();
|
|
695
|
+
checkboxWrapper.contentEditable = "false";
|
|
696
|
+
checkbox.type = "checkbox";
|
|
697
|
+
checkbox.addEventListener("mousedown", (event) => event.preventDefault());
|
|
698
|
+
checkbox.addEventListener("change", (event) => {
|
|
699
|
+
if (!editor.isEditable && !this.options.onReadOnlyChecked) {
|
|
700
|
+
checkbox.checked = !checkbox.checked;
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
const { checked } = event.target;
|
|
704
|
+
if (editor.isEditable && typeof getPos === "function") {
|
|
705
|
+
editor.chain().focus(void 0, { scrollIntoView: false }).command(({ tr: tr2 }) => {
|
|
706
|
+
const position = getPos();
|
|
707
|
+
if (typeof position !== "number") {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
const currentNode = tr2.doc.nodeAt(position);
|
|
711
|
+
tr2.setNodeMarkup(position, void 0, {
|
|
712
|
+
...currentNode === null || currentNode === void 0 ? void 0 : currentNode.attrs,
|
|
713
|
+
checked
|
|
714
|
+
});
|
|
715
|
+
return true;
|
|
716
|
+
}).run();
|
|
717
|
+
}
|
|
718
|
+
if (!editor.isEditable && this.options.onReadOnlyChecked) {
|
|
719
|
+
if (!this.options.onReadOnlyChecked(node, checked)) {
|
|
720
|
+
checkbox.checked = !checkbox.checked;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
|
|
725
|
+
listItem.setAttribute(key, value);
|
|
726
|
+
});
|
|
727
|
+
listItem.dataset.checked = node.attrs.checked;
|
|
728
|
+
checkbox.checked = node.attrs.checked;
|
|
729
|
+
checkboxWrapper.append(checkbox, checkboxStyler);
|
|
730
|
+
listItem.append(checkboxWrapper, content);
|
|
731
|
+
Object.entries(HTMLAttributes).forEach(([key, value]) => {
|
|
732
|
+
listItem.setAttribute(key, value);
|
|
733
|
+
});
|
|
734
|
+
return {
|
|
735
|
+
dom: listItem,
|
|
736
|
+
contentDOM: content,
|
|
737
|
+
update: (updatedNode) => {
|
|
738
|
+
if (updatedNode.type !== this.type) {
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
listItem.dataset.checked = updatedNode.attrs.checked;
|
|
742
|
+
checkbox.checked = updatedNode.attrs.checked;
|
|
743
|
+
updateA11Y();
|
|
744
|
+
return true;
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
};
|
|
748
|
+
},
|
|
749
|
+
addInputRules() {
|
|
750
|
+
return [
|
|
751
|
+
wrappingInputRule3({
|
|
752
|
+
find: inputRegex4,
|
|
753
|
+
type: this.type,
|
|
754
|
+
getAttributes: (match) => ({
|
|
755
|
+
checked: match[match.length - 1] === "x"
|
|
756
|
+
})
|
|
757
|
+
})
|
|
758
|
+
];
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
// ../../node_modules/.pnpm/@tiptap+extension-blockquote@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-blockquote/dist/index.js
|
|
763
|
+
import { Node as Node10, mergeAttributes as mergeAttributes12, wrappingInputRule as wrappingInputRule4 } from "@tiptap/core";
|
|
764
|
+
var inputRegex5 = /^\s*>\s$/;
|
|
765
|
+
var Blockquote = Node10.create({
|
|
766
|
+
name: "blockquote",
|
|
767
|
+
addOptions() {
|
|
768
|
+
return {
|
|
769
|
+
HTMLAttributes: {}
|
|
770
|
+
};
|
|
771
|
+
},
|
|
772
|
+
content: "block+",
|
|
773
|
+
group: "block",
|
|
774
|
+
defining: true,
|
|
775
|
+
parseHTML() {
|
|
776
|
+
return [
|
|
777
|
+
{ tag: "blockquote" }
|
|
778
|
+
];
|
|
779
|
+
},
|
|
780
|
+
renderHTML({ HTMLAttributes }) {
|
|
781
|
+
return ["blockquote", mergeAttributes12(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
782
|
+
},
|
|
783
|
+
addCommands() {
|
|
784
|
+
return {
|
|
785
|
+
setBlockquote: () => ({ commands }) => {
|
|
786
|
+
return commands.wrapIn(this.name);
|
|
787
|
+
},
|
|
788
|
+
toggleBlockquote: () => ({ commands }) => {
|
|
789
|
+
return commands.toggleWrap(this.name);
|
|
790
|
+
},
|
|
791
|
+
unsetBlockquote: () => ({ commands }) => {
|
|
792
|
+
return commands.lift(this.name);
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
},
|
|
796
|
+
addKeyboardShortcuts() {
|
|
797
|
+
return {
|
|
798
|
+
"Mod-Shift-b": () => this.editor.commands.toggleBlockquote()
|
|
799
|
+
};
|
|
800
|
+
},
|
|
801
|
+
addInputRules() {
|
|
802
|
+
return [
|
|
803
|
+
wrappingInputRule4({
|
|
804
|
+
find: inputRegex5,
|
|
805
|
+
type: this.type
|
|
806
|
+
})
|
|
807
|
+
];
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
// ../../node_modules/.pnpm/@tiptap+extension-horizontal-rule@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/extension-horizontal-rule/dist/index.js
|
|
812
|
+
import { Node as Node11, mergeAttributes as mergeAttributes13, canInsertNode, isNodeSelection, nodeInputRule } from "@tiptap/core";
|
|
813
|
+
import { TextSelection, NodeSelection } from "@tiptap/pm/state";
|
|
814
|
+
var HorizontalRule = Node11.create({
|
|
815
|
+
name: "horizontalRule",
|
|
816
|
+
addOptions() {
|
|
817
|
+
return {
|
|
818
|
+
HTMLAttributes: {}
|
|
819
|
+
};
|
|
820
|
+
},
|
|
821
|
+
group: "block",
|
|
822
|
+
parseHTML() {
|
|
823
|
+
return [{ tag: "hr" }];
|
|
824
|
+
},
|
|
825
|
+
renderHTML({ HTMLAttributes }) {
|
|
826
|
+
return ["hr", mergeAttributes13(this.options.HTMLAttributes, HTMLAttributes)];
|
|
827
|
+
},
|
|
828
|
+
addCommands() {
|
|
829
|
+
return {
|
|
830
|
+
setHorizontalRule: () => ({ chain, state }) => {
|
|
831
|
+
if (!canInsertNode(state, state.schema.nodes[this.name])) {
|
|
832
|
+
return false;
|
|
833
|
+
}
|
|
834
|
+
const { selection } = state;
|
|
835
|
+
const { $from: $originFrom, $to: $originTo } = selection;
|
|
836
|
+
const currentChain = chain();
|
|
837
|
+
if ($originFrom.parentOffset === 0) {
|
|
838
|
+
currentChain.insertContentAt({
|
|
839
|
+
from: Math.max($originFrom.pos - 1, 0),
|
|
840
|
+
to: $originTo.pos
|
|
841
|
+
}, {
|
|
842
|
+
type: this.name
|
|
843
|
+
});
|
|
844
|
+
} else if (isNodeSelection(selection)) {
|
|
845
|
+
currentChain.insertContentAt($originTo.pos, {
|
|
846
|
+
type: this.name
|
|
847
|
+
});
|
|
848
|
+
} else {
|
|
849
|
+
currentChain.insertContent({ type: this.name });
|
|
850
|
+
}
|
|
851
|
+
return currentChain.command(({ tr: tr2, dispatch }) => {
|
|
852
|
+
var _a;
|
|
853
|
+
if (dispatch) {
|
|
854
|
+
const { $to } = tr2.selection;
|
|
855
|
+
const posAfter = $to.end();
|
|
856
|
+
if ($to.nodeAfter) {
|
|
857
|
+
if ($to.nodeAfter.isTextblock) {
|
|
858
|
+
tr2.setSelection(TextSelection.create(tr2.doc, $to.pos + 1));
|
|
859
|
+
} else if ($to.nodeAfter.isBlock) {
|
|
860
|
+
tr2.setSelection(NodeSelection.create(tr2.doc, $to.pos));
|
|
861
|
+
} else {
|
|
862
|
+
tr2.setSelection(TextSelection.create(tr2.doc, $to.pos));
|
|
863
|
+
}
|
|
864
|
+
} else {
|
|
865
|
+
const node = (_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create();
|
|
866
|
+
if (node) {
|
|
867
|
+
tr2.insert(posAfter, node);
|
|
868
|
+
tr2.setSelection(TextSelection.create(tr2.doc, posAfter + 1));
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
tr2.scrollIntoView();
|
|
872
|
+
}
|
|
873
|
+
return true;
|
|
874
|
+
}).run();
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
},
|
|
878
|
+
addInputRules() {
|
|
879
|
+
return [
|
|
880
|
+
nodeInputRule({
|
|
881
|
+
find: /^(?:---|—-|___\s|\*\*\*\s)$/,
|
|
882
|
+
type: this.type
|
|
883
|
+
})
|
|
884
|
+
];
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
// ../../node_modules/.pnpm/@tiptap+extension-hard-break@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-hard-break/dist/index.js
|
|
889
|
+
import { Node as Node12, mergeAttributes as mergeAttributes14 } from "@tiptap/core";
|
|
890
|
+
var HardBreak = Node12.create({
|
|
891
|
+
name: "hardBreak",
|
|
892
|
+
addOptions() {
|
|
893
|
+
return {
|
|
894
|
+
keepMarks: true,
|
|
895
|
+
HTMLAttributes: {}
|
|
896
|
+
};
|
|
897
|
+
},
|
|
898
|
+
inline: true,
|
|
899
|
+
group: "inline",
|
|
900
|
+
selectable: false,
|
|
901
|
+
linebreakReplacement: true,
|
|
902
|
+
parseHTML() {
|
|
903
|
+
return [
|
|
904
|
+
{ tag: "br" }
|
|
905
|
+
];
|
|
906
|
+
},
|
|
907
|
+
renderHTML({ HTMLAttributes }) {
|
|
908
|
+
return ["br", mergeAttributes14(this.options.HTMLAttributes, HTMLAttributes)];
|
|
909
|
+
},
|
|
910
|
+
renderText() {
|
|
911
|
+
return "\n";
|
|
912
|
+
},
|
|
913
|
+
addCommands() {
|
|
914
|
+
return {
|
|
915
|
+
setHardBreak: () => ({ commands, chain, state, editor }) => {
|
|
916
|
+
return commands.first([
|
|
917
|
+
() => commands.exitCode(),
|
|
918
|
+
() => commands.command(() => {
|
|
919
|
+
const { selection, storedMarks } = state;
|
|
920
|
+
if (selection.$from.parent.type.spec.isolating) {
|
|
921
|
+
return false;
|
|
922
|
+
}
|
|
923
|
+
const { keepMarks } = this.options;
|
|
924
|
+
const { splittableMarks } = editor.extensionManager;
|
|
925
|
+
const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
|
|
926
|
+
return chain().insertContent({ type: this.name }).command(({ tr: tr2, dispatch }) => {
|
|
927
|
+
if (dispatch && marks && keepMarks) {
|
|
928
|
+
const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name));
|
|
929
|
+
tr2.ensureMarks(filteredMarks);
|
|
930
|
+
}
|
|
931
|
+
return true;
|
|
932
|
+
}).run();
|
|
933
|
+
})
|
|
934
|
+
]);
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
},
|
|
938
|
+
addKeyboardShortcuts() {
|
|
939
|
+
return {
|
|
940
|
+
"Mod-Enter": () => this.editor.commands.setHardBreak(),
|
|
941
|
+
"Shift-Enter": () => this.editor.commands.setHardBreak()
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
// ../../node_modules/.pnpm/@tiptap+extension-history@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/extension-history/dist/index.js
|
|
947
|
+
import { Extension } from "@tiptap/core";
|
|
948
|
+
import { undo, redo, history } from "@tiptap/pm/history";
|
|
949
|
+
var History = Extension.create({
|
|
950
|
+
name: "history",
|
|
951
|
+
addOptions() {
|
|
952
|
+
return {
|
|
953
|
+
depth: 100,
|
|
954
|
+
newGroupDelay: 500
|
|
955
|
+
};
|
|
956
|
+
},
|
|
957
|
+
addCommands() {
|
|
958
|
+
return {
|
|
959
|
+
undo: () => ({ state, dispatch }) => {
|
|
960
|
+
return undo(state, dispatch);
|
|
961
|
+
},
|
|
962
|
+
redo: () => ({ state, dispatch }) => {
|
|
963
|
+
return redo(state, dispatch);
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
},
|
|
967
|
+
addProseMirrorPlugins() {
|
|
968
|
+
return [
|
|
969
|
+
history(this.options)
|
|
970
|
+
];
|
|
971
|
+
},
|
|
972
|
+
addKeyboardShortcuts() {
|
|
973
|
+
return {
|
|
974
|
+
"Mod-z": () => this.editor.commands.undo(),
|
|
975
|
+
"Shift-Mod-z": () => this.editor.commands.redo(),
|
|
976
|
+
"Mod-y": () => this.editor.commands.redo(),
|
|
977
|
+
// Russian keyboard layouts
|
|
978
|
+
"Mod-\u044F": () => this.editor.commands.undo(),
|
|
979
|
+
"Shift-Mod-\u044F": () => this.editor.commands.redo()
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
|
|
984
|
+
// ../../node_modules/.pnpm/@tiptap+extension-dropcursor@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/extension-dropcursor/dist/index.js
|
|
985
|
+
import { Extension as Extension2 } from "@tiptap/core";
|
|
986
|
+
import { dropCursor } from "@tiptap/pm/dropcursor";
|
|
987
|
+
var Dropcursor = Extension2.create({
|
|
988
|
+
name: "dropCursor",
|
|
989
|
+
addOptions() {
|
|
990
|
+
return {
|
|
991
|
+
color: "currentColor",
|
|
992
|
+
width: 1,
|
|
993
|
+
class: void 0
|
|
994
|
+
};
|
|
995
|
+
},
|
|
996
|
+
addProseMirrorPlugins() {
|
|
997
|
+
return [
|
|
998
|
+
dropCursor(this.options)
|
|
999
|
+
];
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
// ../../node_modules/.pnpm/@tiptap+extension-gapcursor@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/extension-gapcursor/dist/index.js
|
|
1004
|
+
import { Extension as Extension3, callOrReturn, getExtensionField } from "@tiptap/core";
|
|
1005
|
+
import { gapCursor } from "@tiptap/pm/gapcursor";
|
|
1006
|
+
var Gapcursor = Extension3.create({
|
|
1007
|
+
name: "gapCursor",
|
|
1008
|
+
addProseMirrorPlugins() {
|
|
1009
|
+
return [
|
|
1010
|
+
gapCursor()
|
|
1011
|
+
];
|
|
1012
|
+
},
|
|
1013
|
+
extendNodeSchema(extension) {
|
|
1014
|
+
var _a;
|
|
1015
|
+
const context = {
|
|
1016
|
+
name: extension.name,
|
|
1017
|
+
options: extension.options,
|
|
1018
|
+
storage: extension.storage
|
|
1019
|
+
};
|
|
1020
|
+
return {
|
|
1021
|
+
allowGapCursor: (_a = callOrReturn(getExtensionField(extension, "allowGapCursor", context))) !== null && _a !== void 0 ? _a : null
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
// ../../node_modules/.pnpm/@tiptap+extension-link@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/extension-link/dist/index.js
|
|
1027
|
+
import { combineTransactionSteps, getChangedRanges, findChildrenInRange, getMarksBetween, getAttributes, Mark as Mark5, mergeAttributes as mergeAttributes15, markPasteRule as markPasteRule4 } from "@tiptap/core";
|
|
1028
|
+
|
|
1029
|
+
// ../../node_modules/.pnpm/linkifyjs@4.3.2/node_modules/linkifyjs/dist/linkify.mjs
|
|
1030
|
+
var encodedTlds = "aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5m\xF6gensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2";
|
|
1031
|
+
var encodedUtlds = "\u03B5\u03BB1\u03C52\u0431\u04331\u0435\u043B3\u0434\u0435\u0442\u04384\u0435\u044E2\u043A\u0430\u0442\u043E\u043B\u0438\u043A6\u043E\u043C3\u043C\u043A\u04342\u043E\u043D1\u0441\u043A\u0432\u04306\u043E\u043D\u043B\u0430\u0439\u043D5\u0440\u04333\u0440\u0443\u04412\u04442\u0441\u0430\u0439\u04423\u0440\u04313\u0443\u043A\u04403\u049B\u0430\u04373\u0570\u0561\u05753\u05D9\u05E9\u05E8\u05D0\u05DC5\u05E7\u05D5\u05DD3\u0627\u0628\u0648\u0638\u0628\u064A5\u0631\u0627\u0645\u0643\u06485\u0644\u0627\u0631\u062F\u06464\u0628\u062D\u0631\u064A\u06465\u062C\u0632\u0627\u0626\u06315\u0633\u0639\u0648\u062F\u064A\u06296\u0639\u0644\u064A\u0627\u06465\u0645\u063A\u0631\u06285\u0645\u0627\u0631\u0627\u062A5\u06CC\u0631\u0627\u06465\u0628\u0627\u0631\u062A2\u0632\u0627\u06314\u064A\u062A\u06433\u06BE\u0627\u0631\u062A5\u062A\u0648\u0646\u06334\u0633\u0648\u062F\u0627\u06463\u0631\u064A\u06295\u0634\u0628\u0643\u06294\u0639\u0631\u0627\u06422\u06282\u0645\u0627\u06464\u0641\u0644\u0633\u0637\u064A\u06466\u0642\u0637\u06313\u0643\u0627\u062B\u0648\u0644\u064A\u06436\u0648\u06453\u0645\u0635\u06312\u0644\u064A\u0633\u064A\u06275\u0648\u0631\u064A\u062A\u0627\u0646\u064A\u06277\u0642\u06394\u0647\u0645\u0631\u0627\u06475\u067E\u0627\u06A9\u0633\u062A\u0627\u06467\u0680\u0627\u0631\u062A4\u0915\u0949\u092E3\u0928\u0947\u091F3\u092D\u093E\u0930\u09240\u092E\u094D3\u094B\u09245\u0938\u0902\u0917\u0920\u09285\u09AC\u09BE\u0982\u09B2\u09BE5\u09AD\u09BE\u09B0\u09A42\u09F0\u09A44\u0A2D\u0A3E\u0A30\u0A244\u0AAD\u0ABE\u0AB0\u0AA44\u0B2D\u0B3E\u0B30\u0B244\u0B87\u0BA8\u0BCD\u0BA4\u0BBF\u0BAF\u0BBE6\u0BB2\u0B99\u0BCD\u0B95\u0BC86\u0B9A\u0BBF\u0B99\u0BCD\u0B95\u0BAA\u0BCD\u0BAA\u0BC2\u0BB0\u0BCD11\u0C2D\u0C3E\u0C30\u0C24\u0C4D5\u0CAD\u0CBE\u0CB0\u0CA44\u0D2D\u0D3E\u0D30\u0D24\u0D025\u0DBD\u0D82\u0D9A\u0DCF4\u0E04\u0E2D\u0E213\u0E44\u0E17\u0E223\u0EA5\u0EB2\u0EA73\u10D2\u10D42\u307F\u3093\u306A3\u30A2\u30DE\u30BE\u30F34\u30AF\u30E9\u30A6\u30C94\u30B0\u30FC\u30B0\u30EB4\u30B3\u30E02\u30B9\u30C8\u30A23\u30BB\u30FC\u30EB3\u30D5\u30A1\u30C3\u30B7\u30E7\u30F36\u30DD\u30A4\u30F3\u30C84\u4E16\u754C2\u4E2D\u4FE11\u56FD1\u570B1\u6587\u7F513\u4E9A\u9A6C\u900A3\u4F01\u4E1A2\u4F5B\u5C712\u4FE1\u606F2\u5065\u5EB72\u516B\u53662\u516C\u53F81\u76CA2\u53F0\u6E7E1\u70632\u5546\u57CE1\u5E971\u68072\u5609\u91CC0\u5927\u9152\u5E975\u5728\u7EBF2\u5927\u62FF2\u5929\u4E3B\u65593\u5A31\u4E502\u5BB6\u96FB2\u5E7F\u4E1C2\u5FAE\u535A2\u6148\u55842\u6211\u7231\u4F603\u624B\u673A2\u62DB\u80582\u653F\u52A11\u5E9C2\u65B0\u52A0\u57612\u95FB2\u65F6\u5C1A2\u66F8\u7C4D2\u673A\u67842\u6DE1\u9A6C\u95213\u6E38\u620F2\u6FB3\u95802\u70B9\u770B2\u79FB\u52A82\u7EC4\u7EC7\u673A\u67844\u7F51\u57401\u5E971\u7AD91\u7EDC2\u8054\u901A2\u8C37\u6B4C2\u8D2D\u72692\u901A\u8CA92\u96C6\u56E22\u96FB\u8A0A\u76C8\u79D14\u98DE\u5229\u6D663\u98DF\u54C12\u9910\u53852\u9999\u683C\u91CC\u62C93\u6E2F2\uB2F7\uB1371\uCEF42\uC0BC\uC1312\uD55C\uAD6D2";
|
|
1032
|
+
var numeric = "numeric";
|
|
1033
|
+
var ascii = "ascii";
|
|
1034
|
+
var alpha = "alpha";
|
|
1035
|
+
var asciinumeric = "asciinumeric";
|
|
1036
|
+
var alphanumeric = "alphanumeric";
|
|
1037
|
+
var domain = "domain";
|
|
1038
|
+
var emoji = "emoji";
|
|
1039
|
+
var scheme = "scheme";
|
|
1040
|
+
var slashscheme = "slashscheme";
|
|
1041
|
+
var whitespace = "whitespace";
|
|
1042
|
+
function registerGroup(name, groups) {
|
|
1043
|
+
if (!(name in groups)) {
|
|
1044
|
+
groups[name] = [];
|
|
1045
|
+
}
|
|
1046
|
+
return groups[name];
|
|
1047
|
+
}
|
|
1048
|
+
function addToGroups(t, flags, groups) {
|
|
1049
|
+
if (flags[numeric]) {
|
|
1050
|
+
flags[asciinumeric] = true;
|
|
1051
|
+
flags[alphanumeric] = true;
|
|
1052
|
+
}
|
|
1053
|
+
if (flags[ascii]) {
|
|
1054
|
+
flags[asciinumeric] = true;
|
|
1055
|
+
flags[alpha] = true;
|
|
1056
|
+
}
|
|
1057
|
+
if (flags[asciinumeric]) {
|
|
1058
|
+
flags[alphanumeric] = true;
|
|
1059
|
+
}
|
|
1060
|
+
if (flags[alpha]) {
|
|
1061
|
+
flags[alphanumeric] = true;
|
|
1062
|
+
}
|
|
1063
|
+
if (flags[alphanumeric]) {
|
|
1064
|
+
flags[domain] = true;
|
|
1065
|
+
}
|
|
1066
|
+
if (flags[emoji]) {
|
|
1067
|
+
flags[domain] = true;
|
|
1068
|
+
}
|
|
1069
|
+
for (const k in flags) {
|
|
1070
|
+
const group = registerGroup(k, groups);
|
|
1071
|
+
if (group.indexOf(t) < 0) {
|
|
1072
|
+
group.push(t);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
function flagsForToken(t, groups) {
|
|
1077
|
+
const result = {};
|
|
1078
|
+
for (const c in groups) {
|
|
1079
|
+
if (groups[c].indexOf(t) >= 0) {
|
|
1080
|
+
result[c] = true;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
return result;
|
|
1084
|
+
}
|
|
1085
|
+
function State(token = null) {
|
|
1086
|
+
this.j = {};
|
|
1087
|
+
this.jr = [];
|
|
1088
|
+
this.jd = null;
|
|
1089
|
+
this.t = token;
|
|
1090
|
+
}
|
|
1091
|
+
State.groups = {};
|
|
1092
|
+
State.prototype = {
|
|
1093
|
+
accepts() {
|
|
1094
|
+
return !!this.t;
|
|
1095
|
+
},
|
|
1096
|
+
/**
|
|
1097
|
+
* Follow an existing transition from the given input to the next state.
|
|
1098
|
+
* Does not mutate.
|
|
1099
|
+
* @param {string} input character or token type to transition on
|
|
1100
|
+
* @returns {?State<T>} the next state, if any
|
|
1101
|
+
*/
|
|
1102
|
+
go(input) {
|
|
1103
|
+
const state = this;
|
|
1104
|
+
const nextState = state.j[input];
|
|
1105
|
+
if (nextState) {
|
|
1106
|
+
return nextState;
|
|
1107
|
+
}
|
|
1108
|
+
for (let i = 0; i < state.jr.length; i++) {
|
|
1109
|
+
const regex = state.jr[i][0];
|
|
1110
|
+
const nextState2 = state.jr[i][1];
|
|
1111
|
+
if (nextState2 && regex.test(input)) {
|
|
1112
|
+
return nextState2;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
return state.jd;
|
|
1116
|
+
},
|
|
1117
|
+
/**
|
|
1118
|
+
* Whether the state has a transition for the given input. Set the second
|
|
1119
|
+
* argument to true to only look for an exact match (and not a default or
|
|
1120
|
+
* regular-expression-based transition)
|
|
1121
|
+
* @param {string} input
|
|
1122
|
+
* @param {boolean} exactOnly
|
|
1123
|
+
*/
|
|
1124
|
+
has(input, exactOnly = false) {
|
|
1125
|
+
return exactOnly ? input in this.j : !!this.go(input);
|
|
1126
|
+
},
|
|
1127
|
+
/**
|
|
1128
|
+
* Short for "transition all"; create a transition from the array of items
|
|
1129
|
+
* in the given list to the same final resulting state.
|
|
1130
|
+
* @param {string | string[]} inputs Group of inputs to transition on
|
|
1131
|
+
* @param {Transition<T> | State<T>} [next] Transition options
|
|
1132
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
1133
|
+
* @param {Collections<T>} [groups] Master list of token groups
|
|
1134
|
+
*/
|
|
1135
|
+
ta(inputs, next, flags, groups) {
|
|
1136
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
1137
|
+
this.tt(inputs[i], next, flags, groups);
|
|
1138
|
+
}
|
|
1139
|
+
},
|
|
1140
|
+
/**
|
|
1141
|
+
* Short for "take regexp transition"; defines a transition for this state
|
|
1142
|
+
* when it encounters a token which matches the given regular expression
|
|
1143
|
+
* @param {RegExp} regexp Regular expression transition (populate first)
|
|
1144
|
+
* @param {T | State<T>} [next] Transition options
|
|
1145
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
1146
|
+
* @param {Collections<T>} [groups] Master list of token groups
|
|
1147
|
+
* @returns {State<T>} taken after the given input
|
|
1148
|
+
*/
|
|
1149
|
+
tr(regexp, next, flags, groups) {
|
|
1150
|
+
groups = groups || State.groups;
|
|
1151
|
+
let nextState;
|
|
1152
|
+
if (next && next.j) {
|
|
1153
|
+
nextState = next;
|
|
1154
|
+
} else {
|
|
1155
|
+
nextState = new State(next);
|
|
1156
|
+
if (flags && groups) {
|
|
1157
|
+
addToGroups(next, flags, groups);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
this.jr.push([regexp, nextState]);
|
|
1161
|
+
return nextState;
|
|
1162
|
+
},
|
|
1163
|
+
/**
|
|
1164
|
+
* Short for "take transitions", will take as many sequential transitions as
|
|
1165
|
+
* the length of the given input and returns the
|
|
1166
|
+
* resulting final state.
|
|
1167
|
+
* @param {string | string[]} input
|
|
1168
|
+
* @param {T | State<T>} [next] Transition options
|
|
1169
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
1170
|
+
* @param {Collections<T>} [groups] Master list of token groups
|
|
1171
|
+
* @returns {State<T>} taken after the given input
|
|
1172
|
+
*/
|
|
1173
|
+
ts(input, next, flags, groups) {
|
|
1174
|
+
let state = this;
|
|
1175
|
+
const len = input.length;
|
|
1176
|
+
if (!len) {
|
|
1177
|
+
return state;
|
|
1178
|
+
}
|
|
1179
|
+
for (let i = 0; i < len - 1; i++) {
|
|
1180
|
+
state = state.tt(input[i]);
|
|
1181
|
+
}
|
|
1182
|
+
return state.tt(input[len - 1], next, flags, groups);
|
|
1183
|
+
},
|
|
1184
|
+
/**
|
|
1185
|
+
* Short for "take transition", this is a method for building/working with
|
|
1186
|
+
* state machines.
|
|
1187
|
+
*
|
|
1188
|
+
* If a state already exists for the given input, returns it.
|
|
1189
|
+
*
|
|
1190
|
+
* If a token is specified, that state will emit that token when reached by
|
|
1191
|
+
* the linkify engine.
|
|
1192
|
+
*
|
|
1193
|
+
* If no state exists, it will be initialized with some default transitions
|
|
1194
|
+
* that resemble existing default transitions.
|
|
1195
|
+
*
|
|
1196
|
+
* If a state is given for the second argument, that state will be
|
|
1197
|
+
* transitioned to on the given input regardless of what that input
|
|
1198
|
+
* previously did.
|
|
1199
|
+
*
|
|
1200
|
+
* Specify a token group flags to define groups that this token belongs to.
|
|
1201
|
+
* The token will be added to corresponding entires in the given groups
|
|
1202
|
+
* object.
|
|
1203
|
+
*
|
|
1204
|
+
* @param {string} input character, token type to transition on
|
|
1205
|
+
* @param {T | State<T>} [next] Transition options
|
|
1206
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
1207
|
+
* @param {Collections<T>} [groups] Master list of groups
|
|
1208
|
+
* @returns {State<T>} taken after the given input
|
|
1209
|
+
*/
|
|
1210
|
+
tt(input, next, flags, groups) {
|
|
1211
|
+
groups = groups || State.groups;
|
|
1212
|
+
const state = this;
|
|
1213
|
+
if (next && next.j) {
|
|
1214
|
+
state.j[input] = next;
|
|
1215
|
+
return next;
|
|
1216
|
+
}
|
|
1217
|
+
const t = next;
|
|
1218
|
+
let nextState, templateState = state.go(input);
|
|
1219
|
+
if (templateState) {
|
|
1220
|
+
nextState = new State();
|
|
1221
|
+
Object.assign(nextState.j, templateState.j);
|
|
1222
|
+
nextState.jr.push.apply(nextState.jr, templateState.jr);
|
|
1223
|
+
nextState.jd = templateState.jd;
|
|
1224
|
+
nextState.t = templateState.t;
|
|
1225
|
+
} else {
|
|
1226
|
+
nextState = new State();
|
|
1227
|
+
}
|
|
1228
|
+
if (t) {
|
|
1229
|
+
if (groups) {
|
|
1230
|
+
if (nextState.t && typeof nextState.t === "string") {
|
|
1231
|
+
const allFlags = Object.assign(flagsForToken(nextState.t, groups), flags);
|
|
1232
|
+
addToGroups(t, allFlags, groups);
|
|
1233
|
+
} else if (flags) {
|
|
1234
|
+
addToGroups(t, flags, groups);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
nextState.t = t;
|
|
1238
|
+
}
|
|
1239
|
+
state.j[input] = nextState;
|
|
1240
|
+
return nextState;
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
var ta = (state, input, next, flags, groups) => state.ta(input, next, flags, groups);
|
|
1244
|
+
var tr = (state, regexp, next, flags, groups) => state.tr(regexp, next, flags, groups);
|
|
1245
|
+
var ts = (state, input, next, flags, groups) => state.ts(input, next, flags, groups);
|
|
1246
|
+
var tt = (state, input, next, flags, groups) => state.tt(input, next, flags, groups);
|
|
1247
|
+
var WORD = "WORD";
|
|
1248
|
+
var UWORD = "UWORD";
|
|
1249
|
+
var ASCIINUMERICAL = "ASCIINUMERICAL";
|
|
1250
|
+
var ALPHANUMERICAL = "ALPHANUMERICAL";
|
|
1251
|
+
var LOCALHOST = "LOCALHOST";
|
|
1252
|
+
var TLD = "TLD";
|
|
1253
|
+
var UTLD = "UTLD";
|
|
1254
|
+
var SCHEME = "SCHEME";
|
|
1255
|
+
var SLASH_SCHEME = "SLASH_SCHEME";
|
|
1256
|
+
var NUM = "NUM";
|
|
1257
|
+
var WS = "WS";
|
|
1258
|
+
var NL = "NL";
|
|
1259
|
+
var OPENBRACE = "OPENBRACE";
|
|
1260
|
+
var CLOSEBRACE = "CLOSEBRACE";
|
|
1261
|
+
var OPENBRACKET = "OPENBRACKET";
|
|
1262
|
+
var CLOSEBRACKET = "CLOSEBRACKET";
|
|
1263
|
+
var OPENPAREN = "OPENPAREN";
|
|
1264
|
+
var CLOSEPAREN = "CLOSEPAREN";
|
|
1265
|
+
var OPENANGLEBRACKET = "OPENANGLEBRACKET";
|
|
1266
|
+
var CLOSEANGLEBRACKET = "CLOSEANGLEBRACKET";
|
|
1267
|
+
var FULLWIDTHLEFTPAREN = "FULLWIDTHLEFTPAREN";
|
|
1268
|
+
var FULLWIDTHRIGHTPAREN = "FULLWIDTHRIGHTPAREN";
|
|
1269
|
+
var LEFTCORNERBRACKET = "LEFTCORNERBRACKET";
|
|
1270
|
+
var RIGHTCORNERBRACKET = "RIGHTCORNERBRACKET";
|
|
1271
|
+
var LEFTWHITECORNERBRACKET = "LEFTWHITECORNERBRACKET";
|
|
1272
|
+
var RIGHTWHITECORNERBRACKET = "RIGHTWHITECORNERBRACKET";
|
|
1273
|
+
var FULLWIDTHLESSTHAN = "FULLWIDTHLESSTHAN";
|
|
1274
|
+
var FULLWIDTHGREATERTHAN = "FULLWIDTHGREATERTHAN";
|
|
1275
|
+
var AMPERSAND = "AMPERSAND";
|
|
1276
|
+
var APOSTROPHE = "APOSTROPHE";
|
|
1277
|
+
var ASTERISK = "ASTERISK";
|
|
1278
|
+
var AT = "AT";
|
|
1279
|
+
var BACKSLASH = "BACKSLASH";
|
|
1280
|
+
var BACKTICK = "BACKTICK";
|
|
1281
|
+
var CARET = "CARET";
|
|
1282
|
+
var COLON = "COLON";
|
|
1283
|
+
var COMMA = "COMMA";
|
|
1284
|
+
var DOLLAR = "DOLLAR";
|
|
1285
|
+
var DOT = "DOT";
|
|
1286
|
+
var EQUALS = "EQUALS";
|
|
1287
|
+
var EXCLAMATION = "EXCLAMATION";
|
|
1288
|
+
var HYPHEN = "HYPHEN";
|
|
1289
|
+
var PERCENT = "PERCENT";
|
|
1290
|
+
var PIPE = "PIPE";
|
|
1291
|
+
var PLUS = "PLUS";
|
|
1292
|
+
var POUND = "POUND";
|
|
1293
|
+
var QUERY = "QUERY";
|
|
1294
|
+
var QUOTE = "QUOTE";
|
|
1295
|
+
var FULLWIDTHMIDDLEDOT = "FULLWIDTHMIDDLEDOT";
|
|
1296
|
+
var SEMI = "SEMI";
|
|
1297
|
+
var SLASH = "SLASH";
|
|
1298
|
+
var TILDE = "TILDE";
|
|
1299
|
+
var UNDERSCORE = "UNDERSCORE";
|
|
1300
|
+
var EMOJI$1 = "EMOJI";
|
|
1301
|
+
var SYM = "SYM";
|
|
1302
|
+
var tk = /* @__PURE__ */ Object.freeze({
|
|
1303
|
+
__proto__: null,
|
|
1304
|
+
ALPHANUMERICAL,
|
|
1305
|
+
AMPERSAND,
|
|
1306
|
+
APOSTROPHE,
|
|
1307
|
+
ASCIINUMERICAL,
|
|
1308
|
+
ASTERISK,
|
|
1309
|
+
AT,
|
|
1310
|
+
BACKSLASH,
|
|
1311
|
+
BACKTICK,
|
|
1312
|
+
CARET,
|
|
1313
|
+
CLOSEANGLEBRACKET,
|
|
1314
|
+
CLOSEBRACE,
|
|
1315
|
+
CLOSEBRACKET,
|
|
1316
|
+
CLOSEPAREN,
|
|
1317
|
+
COLON,
|
|
1318
|
+
COMMA,
|
|
1319
|
+
DOLLAR,
|
|
1320
|
+
DOT,
|
|
1321
|
+
EMOJI: EMOJI$1,
|
|
1322
|
+
EQUALS,
|
|
1323
|
+
EXCLAMATION,
|
|
1324
|
+
FULLWIDTHGREATERTHAN,
|
|
1325
|
+
FULLWIDTHLEFTPAREN,
|
|
1326
|
+
FULLWIDTHLESSTHAN,
|
|
1327
|
+
FULLWIDTHMIDDLEDOT,
|
|
1328
|
+
FULLWIDTHRIGHTPAREN,
|
|
1329
|
+
HYPHEN,
|
|
1330
|
+
LEFTCORNERBRACKET,
|
|
1331
|
+
LEFTWHITECORNERBRACKET,
|
|
1332
|
+
LOCALHOST,
|
|
1333
|
+
NL,
|
|
1334
|
+
NUM,
|
|
1335
|
+
OPENANGLEBRACKET,
|
|
1336
|
+
OPENBRACE,
|
|
1337
|
+
OPENBRACKET,
|
|
1338
|
+
OPENPAREN,
|
|
1339
|
+
PERCENT,
|
|
1340
|
+
PIPE,
|
|
1341
|
+
PLUS,
|
|
1342
|
+
POUND,
|
|
1343
|
+
QUERY,
|
|
1344
|
+
QUOTE,
|
|
1345
|
+
RIGHTCORNERBRACKET,
|
|
1346
|
+
RIGHTWHITECORNERBRACKET,
|
|
1347
|
+
SCHEME,
|
|
1348
|
+
SEMI,
|
|
1349
|
+
SLASH,
|
|
1350
|
+
SLASH_SCHEME,
|
|
1351
|
+
SYM,
|
|
1352
|
+
TILDE,
|
|
1353
|
+
TLD,
|
|
1354
|
+
UNDERSCORE,
|
|
1355
|
+
UTLD,
|
|
1356
|
+
UWORD,
|
|
1357
|
+
WORD,
|
|
1358
|
+
WS
|
|
1359
|
+
});
|
|
1360
|
+
var ASCII_LETTER = /[a-z]/;
|
|
1361
|
+
var LETTER = /\p{L}/u;
|
|
1362
|
+
var EMOJI = /\p{Emoji}/u;
|
|
1363
|
+
var DIGIT = /\d/;
|
|
1364
|
+
var SPACE = /\s/;
|
|
1365
|
+
var CR = "\r";
|
|
1366
|
+
var LF = "\n";
|
|
1367
|
+
var EMOJI_VARIATION = "\uFE0F";
|
|
1368
|
+
var EMOJI_JOINER = "\u200D";
|
|
1369
|
+
var OBJECT_REPLACEMENT = "\uFFFC";
|
|
1370
|
+
var tlds = null;
|
|
1371
|
+
var utlds = null;
|
|
1372
|
+
function init$2(customSchemes = []) {
|
|
1373
|
+
const groups = {};
|
|
1374
|
+
State.groups = groups;
|
|
1375
|
+
const Start = new State();
|
|
1376
|
+
if (tlds == null) {
|
|
1377
|
+
tlds = decodeTlds(encodedTlds);
|
|
1378
|
+
}
|
|
1379
|
+
if (utlds == null) {
|
|
1380
|
+
utlds = decodeTlds(encodedUtlds);
|
|
1381
|
+
}
|
|
1382
|
+
tt(Start, "'", APOSTROPHE);
|
|
1383
|
+
tt(Start, "{", OPENBRACE);
|
|
1384
|
+
tt(Start, "}", CLOSEBRACE);
|
|
1385
|
+
tt(Start, "[", OPENBRACKET);
|
|
1386
|
+
tt(Start, "]", CLOSEBRACKET);
|
|
1387
|
+
tt(Start, "(", OPENPAREN);
|
|
1388
|
+
tt(Start, ")", CLOSEPAREN);
|
|
1389
|
+
tt(Start, "<", OPENANGLEBRACKET);
|
|
1390
|
+
tt(Start, ">", CLOSEANGLEBRACKET);
|
|
1391
|
+
tt(Start, "\uFF08", FULLWIDTHLEFTPAREN);
|
|
1392
|
+
tt(Start, "\uFF09", FULLWIDTHRIGHTPAREN);
|
|
1393
|
+
tt(Start, "\u300C", LEFTCORNERBRACKET);
|
|
1394
|
+
tt(Start, "\u300D", RIGHTCORNERBRACKET);
|
|
1395
|
+
tt(Start, "\u300E", LEFTWHITECORNERBRACKET);
|
|
1396
|
+
tt(Start, "\u300F", RIGHTWHITECORNERBRACKET);
|
|
1397
|
+
tt(Start, "\uFF1C", FULLWIDTHLESSTHAN);
|
|
1398
|
+
tt(Start, "\uFF1E", FULLWIDTHGREATERTHAN);
|
|
1399
|
+
tt(Start, "&", AMPERSAND);
|
|
1400
|
+
tt(Start, "*", ASTERISK);
|
|
1401
|
+
tt(Start, "@", AT);
|
|
1402
|
+
tt(Start, "`", BACKTICK);
|
|
1403
|
+
tt(Start, "^", CARET);
|
|
1404
|
+
tt(Start, ":", COLON);
|
|
1405
|
+
tt(Start, ",", COMMA);
|
|
1406
|
+
tt(Start, "$", DOLLAR);
|
|
1407
|
+
tt(Start, ".", DOT);
|
|
1408
|
+
tt(Start, "=", EQUALS);
|
|
1409
|
+
tt(Start, "!", EXCLAMATION);
|
|
1410
|
+
tt(Start, "-", HYPHEN);
|
|
1411
|
+
tt(Start, "%", PERCENT);
|
|
1412
|
+
tt(Start, "|", PIPE);
|
|
1413
|
+
tt(Start, "+", PLUS);
|
|
1414
|
+
tt(Start, "#", POUND);
|
|
1415
|
+
tt(Start, "?", QUERY);
|
|
1416
|
+
tt(Start, '"', QUOTE);
|
|
1417
|
+
tt(Start, "/", SLASH);
|
|
1418
|
+
tt(Start, ";", SEMI);
|
|
1419
|
+
tt(Start, "~", TILDE);
|
|
1420
|
+
tt(Start, "_", UNDERSCORE);
|
|
1421
|
+
tt(Start, "\\", BACKSLASH);
|
|
1422
|
+
tt(Start, "\u30FB", FULLWIDTHMIDDLEDOT);
|
|
1423
|
+
const Num = tr(Start, DIGIT, NUM, {
|
|
1424
|
+
[numeric]: true
|
|
1425
|
+
});
|
|
1426
|
+
tr(Num, DIGIT, Num);
|
|
1427
|
+
const Asciinumeric = tr(Num, ASCII_LETTER, ASCIINUMERICAL, {
|
|
1428
|
+
[asciinumeric]: true
|
|
1429
|
+
});
|
|
1430
|
+
const Alphanumeric = tr(Num, LETTER, ALPHANUMERICAL, {
|
|
1431
|
+
[alphanumeric]: true
|
|
1432
|
+
});
|
|
1433
|
+
const Word = tr(Start, ASCII_LETTER, WORD, {
|
|
1434
|
+
[ascii]: true
|
|
1435
|
+
});
|
|
1436
|
+
tr(Word, DIGIT, Asciinumeric);
|
|
1437
|
+
tr(Word, ASCII_LETTER, Word);
|
|
1438
|
+
tr(Asciinumeric, DIGIT, Asciinumeric);
|
|
1439
|
+
tr(Asciinumeric, ASCII_LETTER, Asciinumeric);
|
|
1440
|
+
const UWord = tr(Start, LETTER, UWORD, {
|
|
1441
|
+
[alpha]: true
|
|
1442
|
+
});
|
|
1443
|
+
tr(UWord, ASCII_LETTER);
|
|
1444
|
+
tr(UWord, DIGIT, Alphanumeric);
|
|
1445
|
+
tr(UWord, LETTER, UWord);
|
|
1446
|
+
tr(Alphanumeric, DIGIT, Alphanumeric);
|
|
1447
|
+
tr(Alphanumeric, ASCII_LETTER);
|
|
1448
|
+
tr(Alphanumeric, LETTER, Alphanumeric);
|
|
1449
|
+
const Nl2 = tt(Start, LF, NL, {
|
|
1450
|
+
[whitespace]: true
|
|
1451
|
+
});
|
|
1452
|
+
const Cr = tt(Start, CR, WS, {
|
|
1453
|
+
[whitespace]: true
|
|
1454
|
+
});
|
|
1455
|
+
const Ws = tr(Start, SPACE, WS, {
|
|
1456
|
+
[whitespace]: true
|
|
1457
|
+
});
|
|
1458
|
+
tt(Start, OBJECT_REPLACEMENT, Ws);
|
|
1459
|
+
tt(Cr, LF, Nl2);
|
|
1460
|
+
tt(Cr, OBJECT_REPLACEMENT, Ws);
|
|
1461
|
+
tr(Cr, SPACE, Ws);
|
|
1462
|
+
tt(Ws, CR);
|
|
1463
|
+
tt(Ws, LF);
|
|
1464
|
+
tr(Ws, SPACE, Ws);
|
|
1465
|
+
tt(Ws, OBJECT_REPLACEMENT, Ws);
|
|
1466
|
+
const Emoji = tr(Start, EMOJI, EMOJI$1, {
|
|
1467
|
+
[emoji]: true
|
|
1468
|
+
});
|
|
1469
|
+
tt(Emoji, "#");
|
|
1470
|
+
tr(Emoji, EMOJI, Emoji);
|
|
1471
|
+
tt(Emoji, EMOJI_VARIATION, Emoji);
|
|
1472
|
+
const EmojiJoiner = tt(Emoji, EMOJI_JOINER);
|
|
1473
|
+
tt(EmojiJoiner, "#");
|
|
1474
|
+
tr(EmojiJoiner, EMOJI, Emoji);
|
|
1475
|
+
const wordjr = [[ASCII_LETTER, Word], [DIGIT, Asciinumeric]];
|
|
1476
|
+
const uwordjr = [[ASCII_LETTER, null], [LETTER, UWord], [DIGIT, Alphanumeric]];
|
|
1477
|
+
for (let i = 0; i < tlds.length; i++) {
|
|
1478
|
+
fastts(Start, tlds[i], TLD, WORD, wordjr);
|
|
1479
|
+
}
|
|
1480
|
+
for (let i = 0; i < utlds.length; i++) {
|
|
1481
|
+
fastts(Start, utlds[i], UTLD, UWORD, uwordjr);
|
|
1482
|
+
}
|
|
1483
|
+
addToGroups(TLD, {
|
|
1484
|
+
tld: true,
|
|
1485
|
+
ascii: true
|
|
1486
|
+
}, groups);
|
|
1487
|
+
addToGroups(UTLD, {
|
|
1488
|
+
utld: true,
|
|
1489
|
+
alpha: true
|
|
1490
|
+
}, groups);
|
|
1491
|
+
fastts(Start, "file", SCHEME, WORD, wordjr);
|
|
1492
|
+
fastts(Start, "mailto", SCHEME, WORD, wordjr);
|
|
1493
|
+
fastts(Start, "http", SLASH_SCHEME, WORD, wordjr);
|
|
1494
|
+
fastts(Start, "https", SLASH_SCHEME, WORD, wordjr);
|
|
1495
|
+
fastts(Start, "ftp", SLASH_SCHEME, WORD, wordjr);
|
|
1496
|
+
fastts(Start, "ftps", SLASH_SCHEME, WORD, wordjr);
|
|
1497
|
+
addToGroups(SCHEME, {
|
|
1498
|
+
scheme: true,
|
|
1499
|
+
ascii: true
|
|
1500
|
+
}, groups);
|
|
1501
|
+
addToGroups(SLASH_SCHEME, {
|
|
1502
|
+
slashscheme: true,
|
|
1503
|
+
ascii: true
|
|
1504
|
+
}, groups);
|
|
1505
|
+
customSchemes = customSchemes.sort((a, b) => a[0] > b[0] ? 1 : -1);
|
|
1506
|
+
for (let i = 0; i < customSchemes.length; i++) {
|
|
1507
|
+
const sch = customSchemes[i][0];
|
|
1508
|
+
const optionalSlashSlash = customSchemes[i][1];
|
|
1509
|
+
const flags = optionalSlashSlash ? {
|
|
1510
|
+
[scheme]: true
|
|
1511
|
+
} : {
|
|
1512
|
+
[slashscheme]: true
|
|
1513
|
+
};
|
|
1514
|
+
if (sch.indexOf("-") >= 0) {
|
|
1515
|
+
flags[domain] = true;
|
|
1516
|
+
} else if (!ASCII_LETTER.test(sch)) {
|
|
1517
|
+
flags[numeric] = true;
|
|
1518
|
+
} else if (DIGIT.test(sch)) {
|
|
1519
|
+
flags[asciinumeric] = true;
|
|
1520
|
+
} else {
|
|
1521
|
+
flags[ascii] = true;
|
|
1522
|
+
}
|
|
1523
|
+
ts(Start, sch, sch, flags);
|
|
1524
|
+
}
|
|
1525
|
+
ts(Start, "localhost", LOCALHOST, {
|
|
1526
|
+
ascii: true
|
|
1527
|
+
});
|
|
1528
|
+
Start.jd = new State(SYM);
|
|
1529
|
+
return {
|
|
1530
|
+
start: Start,
|
|
1531
|
+
tokens: Object.assign({
|
|
1532
|
+
groups
|
|
1533
|
+
}, tk)
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
function run$1(start, str) {
|
|
1537
|
+
const iterable = stringToArray(str.replace(/[A-Z]/g, (c) => c.toLowerCase()));
|
|
1538
|
+
const charCount = iterable.length;
|
|
1539
|
+
const tokens = [];
|
|
1540
|
+
let cursor = 0;
|
|
1541
|
+
let charCursor = 0;
|
|
1542
|
+
while (charCursor < charCount) {
|
|
1543
|
+
let state = start;
|
|
1544
|
+
let nextState = null;
|
|
1545
|
+
let tokenLength = 0;
|
|
1546
|
+
let latestAccepting = null;
|
|
1547
|
+
let sinceAccepts = -1;
|
|
1548
|
+
let charsSinceAccepts = -1;
|
|
1549
|
+
while (charCursor < charCount && (nextState = state.go(iterable[charCursor]))) {
|
|
1550
|
+
state = nextState;
|
|
1551
|
+
if (state.accepts()) {
|
|
1552
|
+
sinceAccepts = 0;
|
|
1553
|
+
charsSinceAccepts = 0;
|
|
1554
|
+
latestAccepting = state;
|
|
1555
|
+
} else if (sinceAccepts >= 0) {
|
|
1556
|
+
sinceAccepts += iterable[charCursor].length;
|
|
1557
|
+
charsSinceAccepts++;
|
|
1558
|
+
}
|
|
1559
|
+
tokenLength += iterable[charCursor].length;
|
|
1560
|
+
cursor += iterable[charCursor].length;
|
|
1561
|
+
charCursor++;
|
|
1562
|
+
}
|
|
1563
|
+
cursor -= sinceAccepts;
|
|
1564
|
+
charCursor -= charsSinceAccepts;
|
|
1565
|
+
tokenLength -= sinceAccepts;
|
|
1566
|
+
tokens.push({
|
|
1567
|
+
t: latestAccepting.t,
|
|
1568
|
+
// token type/name
|
|
1569
|
+
v: str.slice(cursor - tokenLength, cursor),
|
|
1570
|
+
// string value
|
|
1571
|
+
s: cursor - tokenLength,
|
|
1572
|
+
// start index
|
|
1573
|
+
e: cursor
|
|
1574
|
+
// end index (excluding)
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
return tokens;
|
|
1578
|
+
}
|
|
1579
|
+
function stringToArray(str) {
|
|
1580
|
+
const result = [];
|
|
1581
|
+
const len = str.length;
|
|
1582
|
+
let index = 0;
|
|
1583
|
+
while (index < len) {
|
|
1584
|
+
let first = str.charCodeAt(index);
|
|
1585
|
+
let second;
|
|
1586
|
+
let char = first < 55296 || first > 56319 || index + 1 === len || (second = str.charCodeAt(index + 1)) < 56320 || second > 57343 ? str[index] : str.slice(index, index + 2);
|
|
1587
|
+
result.push(char);
|
|
1588
|
+
index += char.length;
|
|
1589
|
+
}
|
|
1590
|
+
return result;
|
|
1591
|
+
}
|
|
1592
|
+
function fastts(state, input, t, defaultt, jr) {
|
|
1593
|
+
let next;
|
|
1594
|
+
const len = input.length;
|
|
1595
|
+
for (let i = 0; i < len - 1; i++) {
|
|
1596
|
+
const char = input[i];
|
|
1597
|
+
if (state.j[char]) {
|
|
1598
|
+
next = state.j[char];
|
|
1599
|
+
} else {
|
|
1600
|
+
next = new State(defaultt);
|
|
1601
|
+
next.jr = jr.slice();
|
|
1602
|
+
state.j[char] = next;
|
|
1603
|
+
}
|
|
1604
|
+
state = next;
|
|
1605
|
+
}
|
|
1606
|
+
next = new State(t);
|
|
1607
|
+
next.jr = jr.slice();
|
|
1608
|
+
state.j[input[len - 1]] = next;
|
|
1609
|
+
return next;
|
|
1610
|
+
}
|
|
1611
|
+
function decodeTlds(encoded) {
|
|
1612
|
+
const words = [];
|
|
1613
|
+
const stack = [];
|
|
1614
|
+
let i = 0;
|
|
1615
|
+
let digits = "0123456789";
|
|
1616
|
+
while (i < encoded.length) {
|
|
1617
|
+
let popDigitCount = 0;
|
|
1618
|
+
while (digits.indexOf(encoded[i + popDigitCount]) >= 0) {
|
|
1619
|
+
popDigitCount++;
|
|
1620
|
+
}
|
|
1621
|
+
if (popDigitCount > 0) {
|
|
1622
|
+
words.push(stack.join(""));
|
|
1623
|
+
for (let popCount = parseInt(encoded.substring(i, i + popDigitCount), 10); popCount > 0; popCount--) {
|
|
1624
|
+
stack.pop();
|
|
1625
|
+
}
|
|
1626
|
+
i += popDigitCount;
|
|
1627
|
+
} else {
|
|
1628
|
+
stack.push(encoded[i]);
|
|
1629
|
+
i++;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
return words;
|
|
1633
|
+
}
|
|
1634
|
+
var defaults = {
|
|
1635
|
+
defaultProtocol: "http",
|
|
1636
|
+
events: null,
|
|
1637
|
+
format: noop,
|
|
1638
|
+
formatHref: noop,
|
|
1639
|
+
nl2br: false,
|
|
1640
|
+
tagName: "a",
|
|
1641
|
+
target: null,
|
|
1642
|
+
rel: null,
|
|
1643
|
+
validate: true,
|
|
1644
|
+
truncate: Infinity,
|
|
1645
|
+
className: null,
|
|
1646
|
+
attributes: null,
|
|
1647
|
+
ignoreTags: [],
|
|
1648
|
+
render: null
|
|
1649
|
+
};
|
|
1650
|
+
function Options(opts, defaultRender = null) {
|
|
1651
|
+
let o = Object.assign({}, defaults);
|
|
1652
|
+
if (opts) {
|
|
1653
|
+
o = Object.assign(o, opts instanceof Options ? opts.o : opts);
|
|
1654
|
+
}
|
|
1655
|
+
const ignoredTags = o.ignoreTags;
|
|
1656
|
+
const uppercaseIgnoredTags = [];
|
|
1657
|
+
for (let i = 0; i < ignoredTags.length; i++) {
|
|
1658
|
+
uppercaseIgnoredTags.push(ignoredTags[i].toUpperCase());
|
|
1659
|
+
}
|
|
1660
|
+
this.o = o;
|
|
1661
|
+
if (defaultRender) {
|
|
1662
|
+
this.defaultRender = defaultRender;
|
|
1663
|
+
}
|
|
1664
|
+
this.ignoreTags = uppercaseIgnoredTags;
|
|
1665
|
+
}
|
|
1666
|
+
Options.prototype = {
|
|
1667
|
+
o: defaults,
|
|
1668
|
+
/**
|
|
1669
|
+
* @type string[]
|
|
1670
|
+
*/
|
|
1671
|
+
ignoreTags: [],
|
|
1672
|
+
/**
|
|
1673
|
+
* @param {IntermediateRepresentation} ir
|
|
1674
|
+
* @returns {any}
|
|
1675
|
+
*/
|
|
1676
|
+
defaultRender(ir) {
|
|
1677
|
+
return ir;
|
|
1678
|
+
},
|
|
1679
|
+
/**
|
|
1680
|
+
* Returns true or false based on whether a token should be displayed as a
|
|
1681
|
+
* link based on the user options.
|
|
1682
|
+
* @param {MultiToken} token
|
|
1683
|
+
* @returns {boolean}
|
|
1684
|
+
*/
|
|
1685
|
+
check(token) {
|
|
1686
|
+
return this.get("validate", token.toString(), token);
|
|
1687
|
+
},
|
|
1688
|
+
// Private methods
|
|
1689
|
+
/**
|
|
1690
|
+
* Resolve an option's value based on the value of the option and the given
|
|
1691
|
+
* params. If operator and token are specified and the target option is
|
|
1692
|
+
* callable, automatically calls the function with the given argument.
|
|
1693
|
+
* @template {keyof Opts} K
|
|
1694
|
+
* @param {K} key Name of option to use
|
|
1695
|
+
* @param {string} [operator] will be passed to the target option if it's a
|
|
1696
|
+
* function. If not specified, RAW function value gets returned
|
|
1697
|
+
* @param {MultiToken} [token] The token from linkify.tokenize
|
|
1698
|
+
* @returns {Opts[K] | any}
|
|
1699
|
+
*/
|
|
1700
|
+
get(key, operator, token) {
|
|
1701
|
+
const isCallable = operator != null;
|
|
1702
|
+
let option = this.o[key];
|
|
1703
|
+
if (!option) {
|
|
1704
|
+
return option;
|
|
1705
|
+
}
|
|
1706
|
+
if (typeof option === "object") {
|
|
1707
|
+
option = token.t in option ? option[token.t] : defaults[key];
|
|
1708
|
+
if (typeof option === "function" && isCallable) {
|
|
1709
|
+
option = option(operator, token);
|
|
1710
|
+
}
|
|
1711
|
+
} else if (typeof option === "function" && isCallable) {
|
|
1712
|
+
option = option(operator, token.t, token);
|
|
1713
|
+
}
|
|
1714
|
+
return option;
|
|
1715
|
+
},
|
|
1716
|
+
/**
|
|
1717
|
+
* @template {keyof Opts} L
|
|
1718
|
+
* @param {L} key Name of options object to use
|
|
1719
|
+
* @param {string} [operator]
|
|
1720
|
+
* @param {MultiToken} [token]
|
|
1721
|
+
* @returns {Opts[L] | any}
|
|
1722
|
+
*/
|
|
1723
|
+
getObj(key, operator, token) {
|
|
1724
|
+
let obj = this.o[key];
|
|
1725
|
+
if (typeof obj === "function" && operator != null) {
|
|
1726
|
+
obj = obj(operator, token.t, token);
|
|
1727
|
+
}
|
|
1728
|
+
return obj;
|
|
1729
|
+
},
|
|
1730
|
+
/**
|
|
1731
|
+
* Convert the given token to a rendered element that may be added to the
|
|
1732
|
+
* calling-interface's DOM
|
|
1733
|
+
* @param {MultiToken} token Token to render to an HTML element
|
|
1734
|
+
* @returns {any} Render result; e.g., HTML string, DOM element, React
|
|
1735
|
+
* Component, etc.
|
|
1736
|
+
*/
|
|
1737
|
+
render(token) {
|
|
1738
|
+
const ir = token.render(this);
|
|
1739
|
+
const renderFn = this.get("render", null, token) || this.defaultRender;
|
|
1740
|
+
return renderFn(ir, token.t, token);
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
function noop(val) {
|
|
1744
|
+
return val;
|
|
1745
|
+
}
|
|
1746
|
+
function MultiToken(value, tokens) {
|
|
1747
|
+
this.t = "token";
|
|
1748
|
+
this.v = value;
|
|
1749
|
+
this.tk = tokens;
|
|
1750
|
+
}
|
|
1751
|
+
MultiToken.prototype = {
|
|
1752
|
+
isLink: false,
|
|
1753
|
+
/**
|
|
1754
|
+
* Return the string this token represents.
|
|
1755
|
+
* @return {string}
|
|
1756
|
+
*/
|
|
1757
|
+
toString() {
|
|
1758
|
+
return this.v;
|
|
1759
|
+
},
|
|
1760
|
+
/**
|
|
1761
|
+
* What should the value for this token be in the `href` HTML attribute?
|
|
1762
|
+
* Returns the `.toString` value by default.
|
|
1763
|
+
* @param {string} [scheme]
|
|
1764
|
+
* @return {string}
|
|
1765
|
+
*/
|
|
1766
|
+
toHref(scheme2) {
|
|
1767
|
+
return this.toString();
|
|
1768
|
+
},
|
|
1769
|
+
/**
|
|
1770
|
+
* @param {Options} options Formatting options
|
|
1771
|
+
* @returns {string}
|
|
1772
|
+
*/
|
|
1773
|
+
toFormattedString(options) {
|
|
1774
|
+
const val = this.toString();
|
|
1775
|
+
const truncate = options.get("truncate", val, this);
|
|
1776
|
+
const formatted = options.get("format", val, this);
|
|
1777
|
+
return truncate && formatted.length > truncate ? formatted.substring(0, truncate) + "\u2026" : formatted;
|
|
1778
|
+
},
|
|
1779
|
+
/**
|
|
1780
|
+
*
|
|
1781
|
+
* @param {Options} options
|
|
1782
|
+
* @returns {string}
|
|
1783
|
+
*/
|
|
1784
|
+
toFormattedHref(options) {
|
|
1785
|
+
return options.get("formatHref", this.toHref(options.get("defaultProtocol")), this);
|
|
1786
|
+
},
|
|
1787
|
+
/**
|
|
1788
|
+
* The start index of this token in the original input string
|
|
1789
|
+
* @returns {number}
|
|
1790
|
+
*/
|
|
1791
|
+
startIndex() {
|
|
1792
|
+
return this.tk[0].s;
|
|
1793
|
+
},
|
|
1794
|
+
/**
|
|
1795
|
+
* The end index of this token in the original input string (up to this
|
|
1796
|
+
* index but not including it)
|
|
1797
|
+
* @returns {number}
|
|
1798
|
+
*/
|
|
1799
|
+
endIndex() {
|
|
1800
|
+
return this.tk[this.tk.length - 1].e;
|
|
1801
|
+
},
|
|
1802
|
+
/**
|
|
1803
|
+
Returns an object of relevant values for this token, which includes keys
|
|
1804
|
+
* type - Kind of token ('url', 'email', etc.)
|
|
1805
|
+
* value - Original text
|
|
1806
|
+
* href - The value that should be added to the anchor tag's href
|
|
1807
|
+
attribute
|
|
1808
|
+
@method toObject
|
|
1809
|
+
@param {string} [protocol] `'http'` by default
|
|
1810
|
+
*/
|
|
1811
|
+
toObject(protocol = defaults.defaultProtocol) {
|
|
1812
|
+
return {
|
|
1813
|
+
type: this.t,
|
|
1814
|
+
value: this.toString(),
|
|
1815
|
+
isLink: this.isLink,
|
|
1816
|
+
href: this.toHref(protocol),
|
|
1817
|
+
start: this.startIndex(),
|
|
1818
|
+
end: this.endIndex()
|
|
1819
|
+
};
|
|
1820
|
+
},
|
|
1821
|
+
/**
|
|
1822
|
+
*
|
|
1823
|
+
* @param {Options} options Formatting option
|
|
1824
|
+
*/
|
|
1825
|
+
toFormattedObject(options) {
|
|
1826
|
+
return {
|
|
1827
|
+
type: this.t,
|
|
1828
|
+
value: this.toFormattedString(options),
|
|
1829
|
+
isLink: this.isLink,
|
|
1830
|
+
href: this.toFormattedHref(options),
|
|
1831
|
+
start: this.startIndex(),
|
|
1832
|
+
end: this.endIndex()
|
|
1833
|
+
};
|
|
1834
|
+
},
|
|
1835
|
+
/**
|
|
1836
|
+
* Whether this token should be rendered as a link according to the given options
|
|
1837
|
+
* @param {Options} options
|
|
1838
|
+
* @returns {boolean}
|
|
1839
|
+
*/
|
|
1840
|
+
validate(options) {
|
|
1841
|
+
return options.get("validate", this.toString(), this);
|
|
1842
|
+
},
|
|
1843
|
+
/**
|
|
1844
|
+
* Return an object that represents how this link should be rendered.
|
|
1845
|
+
* @param {Options} options Formattinng options
|
|
1846
|
+
*/
|
|
1847
|
+
render(options) {
|
|
1848
|
+
const token = this;
|
|
1849
|
+
const href = this.toHref(options.get("defaultProtocol"));
|
|
1850
|
+
const formattedHref = options.get("formatHref", href, this);
|
|
1851
|
+
const tagName = options.get("tagName", href, token);
|
|
1852
|
+
const content = this.toFormattedString(options);
|
|
1853
|
+
const attributes = {};
|
|
1854
|
+
const className = options.get("className", href, token);
|
|
1855
|
+
const target = options.get("target", href, token);
|
|
1856
|
+
const rel = options.get("rel", href, token);
|
|
1857
|
+
const attrs = options.getObj("attributes", href, token);
|
|
1858
|
+
const eventListeners = options.getObj("events", href, token);
|
|
1859
|
+
attributes.href = formattedHref;
|
|
1860
|
+
if (className) {
|
|
1861
|
+
attributes.class = className;
|
|
1862
|
+
}
|
|
1863
|
+
if (target) {
|
|
1864
|
+
attributes.target = target;
|
|
1865
|
+
}
|
|
1866
|
+
if (rel) {
|
|
1867
|
+
attributes.rel = rel;
|
|
1868
|
+
}
|
|
1869
|
+
if (attrs) {
|
|
1870
|
+
Object.assign(attributes, attrs);
|
|
1871
|
+
}
|
|
1872
|
+
return {
|
|
1873
|
+
tagName,
|
|
1874
|
+
attributes,
|
|
1875
|
+
content,
|
|
1876
|
+
eventListeners
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
function createTokenClass(type, props) {
|
|
1881
|
+
class Token extends MultiToken {
|
|
1882
|
+
constructor(value, tokens) {
|
|
1883
|
+
super(value, tokens);
|
|
1884
|
+
this.t = type;
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
for (const p in props) {
|
|
1888
|
+
Token.prototype[p] = props[p];
|
|
1889
|
+
}
|
|
1890
|
+
Token.t = type;
|
|
1891
|
+
return Token;
|
|
1892
|
+
}
|
|
1893
|
+
var Email = createTokenClass("email", {
|
|
1894
|
+
isLink: true,
|
|
1895
|
+
toHref() {
|
|
1896
|
+
return "mailto:" + this.toString();
|
|
1897
|
+
}
|
|
1898
|
+
});
|
|
1899
|
+
var Text2 = createTokenClass("text");
|
|
1900
|
+
var Nl = createTokenClass("nl");
|
|
1901
|
+
var Url = createTokenClass("url", {
|
|
1902
|
+
isLink: true,
|
|
1903
|
+
/**
|
|
1904
|
+
Lowercases relevant parts of the domain and adds the protocol if
|
|
1905
|
+
required. Note that this will not escape unsafe HTML characters in the
|
|
1906
|
+
URL.
|
|
1907
|
+
@param {string} [scheme] default scheme (e.g., 'https')
|
|
1908
|
+
@return {string} the full href
|
|
1909
|
+
*/
|
|
1910
|
+
toHref(scheme2 = defaults.defaultProtocol) {
|
|
1911
|
+
return this.hasProtocol() ? this.v : `${scheme2}://${this.v}`;
|
|
1912
|
+
},
|
|
1913
|
+
/**
|
|
1914
|
+
* Check whether this URL token has a protocol
|
|
1915
|
+
* @return {boolean}
|
|
1916
|
+
*/
|
|
1917
|
+
hasProtocol() {
|
|
1918
|
+
const tokens = this.tk;
|
|
1919
|
+
return tokens.length >= 2 && tokens[0].t !== LOCALHOST && tokens[1].t === COLON;
|
|
1920
|
+
}
|
|
1921
|
+
});
|
|
1922
|
+
var makeState = (arg) => new State(arg);
|
|
1923
|
+
function init$1({
|
|
1924
|
+
groups
|
|
1925
|
+
}) {
|
|
1926
|
+
const qsAccepting = groups.domain.concat([AMPERSAND, ASTERISK, AT, BACKSLASH, BACKTICK, CARET, DOLLAR, EQUALS, HYPHEN, NUM, PERCENT, PIPE, PLUS, POUND, SLASH, SYM, TILDE, UNDERSCORE]);
|
|
1927
|
+
const qsNonAccepting = [APOSTROPHE, COLON, COMMA, DOT, EXCLAMATION, PERCENT, QUERY, QUOTE, SEMI, OPENANGLEBRACKET, CLOSEANGLEBRACKET, OPENBRACE, CLOSEBRACE, CLOSEBRACKET, OPENBRACKET, OPENPAREN, CLOSEPAREN, FULLWIDTHLEFTPAREN, FULLWIDTHRIGHTPAREN, LEFTCORNERBRACKET, RIGHTCORNERBRACKET, LEFTWHITECORNERBRACKET, RIGHTWHITECORNERBRACKET, FULLWIDTHLESSTHAN, FULLWIDTHGREATERTHAN];
|
|
1928
|
+
const localpartAccepting = [AMPERSAND, APOSTROPHE, ASTERISK, BACKSLASH, BACKTICK, CARET, DOLLAR, EQUALS, HYPHEN, OPENBRACE, CLOSEBRACE, PERCENT, PIPE, PLUS, POUND, QUERY, SLASH, SYM, TILDE, UNDERSCORE];
|
|
1929
|
+
const Start = makeState();
|
|
1930
|
+
const Localpart = tt(Start, TILDE);
|
|
1931
|
+
ta(Localpart, localpartAccepting, Localpart);
|
|
1932
|
+
ta(Localpart, groups.domain, Localpart);
|
|
1933
|
+
const Domain = makeState(), Scheme = makeState(), SlashScheme = makeState();
|
|
1934
|
+
ta(Start, groups.domain, Domain);
|
|
1935
|
+
ta(Start, groups.scheme, Scheme);
|
|
1936
|
+
ta(Start, groups.slashscheme, SlashScheme);
|
|
1937
|
+
ta(Domain, localpartAccepting, Localpart);
|
|
1938
|
+
ta(Domain, groups.domain, Domain);
|
|
1939
|
+
const LocalpartAt = tt(Domain, AT);
|
|
1940
|
+
tt(Localpart, AT, LocalpartAt);
|
|
1941
|
+
tt(Scheme, AT, LocalpartAt);
|
|
1942
|
+
tt(SlashScheme, AT, LocalpartAt);
|
|
1943
|
+
const LocalpartDot = tt(Localpart, DOT);
|
|
1944
|
+
ta(LocalpartDot, localpartAccepting, Localpart);
|
|
1945
|
+
ta(LocalpartDot, groups.domain, Localpart);
|
|
1946
|
+
const EmailDomain = makeState();
|
|
1947
|
+
ta(LocalpartAt, groups.domain, EmailDomain);
|
|
1948
|
+
ta(EmailDomain, groups.domain, EmailDomain);
|
|
1949
|
+
const EmailDomainDot = tt(EmailDomain, DOT);
|
|
1950
|
+
ta(EmailDomainDot, groups.domain, EmailDomain);
|
|
1951
|
+
const Email$1 = makeState(Email);
|
|
1952
|
+
ta(EmailDomainDot, groups.tld, Email$1);
|
|
1953
|
+
ta(EmailDomainDot, groups.utld, Email$1);
|
|
1954
|
+
tt(LocalpartAt, LOCALHOST, Email$1);
|
|
1955
|
+
const EmailDomainHyphen = tt(EmailDomain, HYPHEN);
|
|
1956
|
+
tt(EmailDomainHyphen, HYPHEN, EmailDomainHyphen);
|
|
1957
|
+
ta(EmailDomainHyphen, groups.domain, EmailDomain);
|
|
1958
|
+
ta(Email$1, groups.domain, EmailDomain);
|
|
1959
|
+
tt(Email$1, DOT, EmailDomainDot);
|
|
1960
|
+
tt(Email$1, HYPHEN, EmailDomainHyphen);
|
|
1961
|
+
const EmailColon = tt(Email$1, COLON);
|
|
1962
|
+
ta(EmailColon, groups.numeric, Email);
|
|
1963
|
+
const DomainHyphen = tt(Domain, HYPHEN);
|
|
1964
|
+
const DomainDot = tt(Domain, DOT);
|
|
1965
|
+
tt(DomainHyphen, HYPHEN, DomainHyphen);
|
|
1966
|
+
ta(DomainHyphen, groups.domain, Domain);
|
|
1967
|
+
ta(DomainDot, localpartAccepting, Localpart);
|
|
1968
|
+
ta(DomainDot, groups.domain, Domain);
|
|
1969
|
+
const DomainDotTld = makeState(Url);
|
|
1970
|
+
ta(DomainDot, groups.tld, DomainDotTld);
|
|
1971
|
+
ta(DomainDot, groups.utld, DomainDotTld);
|
|
1972
|
+
ta(DomainDotTld, groups.domain, Domain);
|
|
1973
|
+
ta(DomainDotTld, localpartAccepting, Localpart);
|
|
1974
|
+
tt(DomainDotTld, DOT, DomainDot);
|
|
1975
|
+
tt(DomainDotTld, HYPHEN, DomainHyphen);
|
|
1976
|
+
tt(DomainDotTld, AT, LocalpartAt);
|
|
1977
|
+
const DomainDotTldColon = tt(DomainDotTld, COLON);
|
|
1978
|
+
const DomainDotTldColonPort = makeState(Url);
|
|
1979
|
+
ta(DomainDotTldColon, groups.numeric, DomainDotTldColonPort);
|
|
1980
|
+
const Url$1 = makeState(Url);
|
|
1981
|
+
const UrlNonaccept = makeState();
|
|
1982
|
+
ta(Url$1, qsAccepting, Url$1);
|
|
1983
|
+
ta(Url$1, qsNonAccepting, UrlNonaccept);
|
|
1984
|
+
ta(UrlNonaccept, qsAccepting, Url$1);
|
|
1985
|
+
ta(UrlNonaccept, qsNonAccepting, UrlNonaccept);
|
|
1986
|
+
tt(DomainDotTld, SLASH, Url$1);
|
|
1987
|
+
tt(DomainDotTldColonPort, SLASH, Url$1);
|
|
1988
|
+
const SchemeColon = tt(Scheme, COLON);
|
|
1989
|
+
const SlashSchemeColon = tt(SlashScheme, COLON);
|
|
1990
|
+
const SlashSchemeColonSlash = tt(SlashSchemeColon, SLASH);
|
|
1991
|
+
const UriPrefix = tt(SlashSchemeColonSlash, SLASH);
|
|
1992
|
+
ta(Scheme, groups.domain, Domain);
|
|
1993
|
+
tt(Scheme, DOT, DomainDot);
|
|
1994
|
+
tt(Scheme, HYPHEN, DomainHyphen);
|
|
1995
|
+
ta(SlashScheme, groups.domain, Domain);
|
|
1996
|
+
tt(SlashScheme, DOT, DomainDot);
|
|
1997
|
+
tt(SlashScheme, HYPHEN, DomainHyphen);
|
|
1998
|
+
ta(SchemeColon, groups.domain, Url$1);
|
|
1999
|
+
tt(SchemeColon, SLASH, Url$1);
|
|
2000
|
+
tt(SchemeColon, QUERY, Url$1);
|
|
2001
|
+
ta(UriPrefix, groups.domain, Url$1);
|
|
2002
|
+
ta(UriPrefix, qsAccepting, Url$1);
|
|
2003
|
+
tt(UriPrefix, SLASH, Url$1);
|
|
2004
|
+
const bracketPairs = [
|
|
2005
|
+
[OPENBRACE, CLOSEBRACE],
|
|
2006
|
+
// {}
|
|
2007
|
+
[OPENBRACKET, CLOSEBRACKET],
|
|
2008
|
+
// []
|
|
2009
|
+
[OPENPAREN, CLOSEPAREN],
|
|
2010
|
+
// ()
|
|
2011
|
+
[OPENANGLEBRACKET, CLOSEANGLEBRACKET],
|
|
2012
|
+
// <>
|
|
2013
|
+
[FULLWIDTHLEFTPAREN, FULLWIDTHRIGHTPAREN],
|
|
2014
|
+
// ()
|
|
2015
|
+
[LEFTCORNERBRACKET, RIGHTCORNERBRACKET],
|
|
2016
|
+
// 「」
|
|
2017
|
+
[LEFTWHITECORNERBRACKET, RIGHTWHITECORNERBRACKET],
|
|
2018
|
+
// 『』
|
|
2019
|
+
[FULLWIDTHLESSTHAN, FULLWIDTHGREATERTHAN]
|
|
2020
|
+
// <>
|
|
2021
|
+
];
|
|
2022
|
+
for (let i = 0; i < bracketPairs.length; i++) {
|
|
2023
|
+
const [OPEN, CLOSE] = bracketPairs[i];
|
|
2024
|
+
const UrlOpen = tt(Url$1, OPEN);
|
|
2025
|
+
tt(UrlNonaccept, OPEN, UrlOpen);
|
|
2026
|
+
tt(UrlOpen, CLOSE, Url$1);
|
|
2027
|
+
const UrlOpenQ = makeState(Url);
|
|
2028
|
+
ta(UrlOpen, qsAccepting, UrlOpenQ);
|
|
2029
|
+
const UrlOpenSyms = makeState();
|
|
2030
|
+
ta(UrlOpen, qsNonAccepting);
|
|
2031
|
+
ta(UrlOpenQ, qsAccepting, UrlOpenQ);
|
|
2032
|
+
ta(UrlOpenQ, qsNonAccepting, UrlOpenSyms);
|
|
2033
|
+
ta(UrlOpenSyms, qsAccepting, UrlOpenQ);
|
|
2034
|
+
ta(UrlOpenSyms, qsNonAccepting, UrlOpenSyms);
|
|
2035
|
+
tt(UrlOpenQ, CLOSE, Url$1);
|
|
2036
|
+
tt(UrlOpenSyms, CLOSE, Url$1);
|
|
2037
|
+
}
|
|
2038
|
+
tt(Start, LOCALHOST, DomainDotTld);
|
|
2039
|
+
tt(Start, NL, Nl);
|
|
2040
|
+
return {
|
|
2041
|
+
start: Start,
|
|
2042
|
+
tokens: tk
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
function run(start, input, tokens) {
|
|
2046
|
+
let len = tokens.length;
|
|
2047
|
+
let cursor = 0;
|
|
2048
|
+
let multis = [];
|
|
2049
|
+
let textTokens = [];
|
|
2050
|
+
while (cursor < len) {
|
|
2051
|
+
let state = start;
|
|
2052
|
+
let secondState = null;
|
|
2053
|
+
let nextState = null;
|
|
2054
|
+
let multiLength = 0;
|
|
2055
|
+
let latestAccepting = null;
|
|
2056
|
+
let sinceAccepts = -1;
|
|
2057
|
+
while (cursor < len && !(secondState = state.go(tokens[cursor].t))) {
|
|
2058
|
+
textTokens.push(tokens[cursor++]);
|
|
2059
|
+
}
|
|
2060
|
+
while (cursor < len && (nextState = secondState || state.go(tokens[cursor].t))) {
|
|
2061
|
+
secondState = null;
|
|
2062
|
+
state = nextState;
|
|
2063
|
+
if (state.accepts()) {
|
|
2064
|
+
sinceAccepts = 0;
|
|
2065
|
+
latestAccepting = state;
|
|
2066
|
+
} else if (sinceAccepts >= 0) {
|
|
2067
|
+
sinceAccepts++;
|
|
2068
|
+
}
|
|
2069
|
+
cursor++;
|
|
2070
|
+
multiLength++;
|
|
2071
|
+
}
|
|
2072
|
+
if (sinceAccepts < 0) {
|
|
2073
|
+
cursor -= multiLength;
|
|
2074
|
+
if (cursor < len) {
|
|
2075
|
+
textTokens.push(tokens[cursor]);
|
|
2076
|
+
cursor++;
|
|
2077
|
+
}
|
|
2078
|
+
} else {
|
|
2079
|
+
if (textTokens.length > 0) {
|
|
2080
|
+
multis.push(initMultiToken(Text2, input, textTokens));
|
|
2081
|
+
textTokens = [];
|
|
2082
|
+
}
|
|
2083
|
+
cursor -= sinceAccepts;
|
|
2084
|
+
multiLength -= sinceAccepts;
|
|
2085
|
+
const Multi = latestAccepting.t;
|
|
2086
|
+
const subtokens = tokens.slice(cursor - multiLength, cursor);
|
|
2087
|
+
multis.push(initMultiToken(Multi, input, subtokens));
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
if (textTokens.length > 0) {
|
|
2091
|
+
multis.push(initMultiToken(Text2, input, textTokens));
|
|
2092
|
+
}
|
|
2093
|
+
return multis;
|
|
2094
|
+
}
|
|
2095
|
+
function initMultiToken(Multi, input, tokens) {
|
|
2096
|
+
const startIdx = tokens[0].s;
|
|
2097
|
+
const endIdx = tokens[tokens.length - 1].e;
|
|
2098
|
+
const value = input.slice(startIdx, endIdx);
|
|
2099
|
+
return new Multi(value, tokens);
|
|
2100
|
+
}
|
|
2101
|
+
var warn = typeof console !== "undefined" && console && console.warn || (() => {
|
|
2102
|
+
});
|
|
2103
|
+
var warnAdvice = "until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.";
|
|
2104
|
+
var INIT = {
|
|
2105
|
+
scanner: null,
|
|
2106
|
+
parser: null,
|
|
2107
|
+
tokenQueue: [],
|
|
2108
|
+
pluginQueue: [],
|
|
2109
|
+
customSchemes: [],
|
|
2110
|
+
initialized: false
|
|
2111
|
+
};
|
|
2112
|
+
function reset() {
|
|
2113
|
+
State.groups = {};
|
|
2114
|
+
INIT.scanner = null;
|
|
2115
|
+
INIT.parser = null;
|
|
2116
|
+
INIT.tokenQueue = [];
|
|
2117
|
+
INIT.pluginQueue = [];
|
|
2118
|
+
INIT.customSchemes = [];
|
|
2119
|
+
INIT.initialized = false;
|
|
2120
|
+
return INIT;
|
|
2121
|
+
}
|
|
2122
|
+
function registerCustomProtocol(scheme2, optionalSlashSlash = false) {
|
|
2123
|
+
if (INIT.initialized) {
|
|
2124
|
+
warn(`linkifyjs: already initialized - will not register custom scheme "${scheme2}" ${warnAdvice}`);
|
|
2125
|
+
}
|
|
2126
|
+
if (!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(scheme2)) {
|
|
2127
|
+
throw new Error(`linkifyjs: incorrect scheme format.
|
|
2128
|
+
1. Must only contain digits, lowercase ASCII letters or "-"
|
|
2129
|
+
2. Cannot start or end with "-"
|
|
2130
|
+
3. "-" cannot repeat`);
|
|
2131
|
+
}
|
|
2132
|
+
INIT.customSchemes.push([scheme2, optionalSlashSlash]);
|
|
2133
|
+
}
|
|
2134
|
+
function init() {
|
|
2135
|
+
INIT.scanner = init$2(INIT.customSchemes);
|
|
2136
|
+
for (let i = 0; i < INIT.tokenQueue.length; i++) {
|
|
2137
|
+
INIT.tokenQueue[i][1]({
|
|
2138
|
+
scanner: INIT.scanner
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
INIT.parser = init$1(INIT.scanner.tokens);
|
|
2142
|
+
for (let i = 0; i < INIT.pluginQueue.length; i++) {
|
|
2143
|
+
INIT.pluginQueue[i][1]({
|
|
2144
|
+
scanner: INIT.scanner,
|
|
2145
|
+
parser: INIT.parser
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
INIT.initialized = true;
|
|
2149
|
+
return INIT;
|
|
2150
|
+
}
|
|
2151
|
+
function tokenize(str) {
|
|
2152
|
+
if (!INIT.initialized) {
|
|
2153
|
+
init();
|
|
2154
|
+
}
|
|
2155
|
+
return run(INIT.parser.start, str, run$1(INIT.scanner.start, str));
|
|
2156
|
+
}
|
|
2157
|
+
tokenize.scan = run$1;
|
|
2158
|
+
function find(str, type = null, opts = null) {
|
|
2159
|
+
if (type && typeof type === "object") {
|
|
2160
|
+
if (opts) {
|
|
2161
|
+
throw Error(`linkifyjs: Invalid link type ${type}; must be a string`);
|
|
2162
|
+
}
|
|
2163
|
+
opts = type;
|
|
2164
|
+
type = null;
|
|
2165
|
+
}
|
|
2166
|
+
const options = new Options(opts);
|
|
2167
|
+
const tokens = tokenize(str);
|
|
2168
|
+
const filtered = [];
|
|
2169
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
2170
|
+
const token = tokens[i];
|
|
2171
|
+
if (token.isLink && (!type || token.t === type) && options.check(token)) {
|
|
2172
|
+
filtered.push(token.toFormattedObject(options));
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
return filtered;
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
// ../../node_modules/.pnpm/@tiptap+extension-link@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/extension-link/dist/index.js
|
|
2179
|
+
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
2180
|
+
var UNICODE_WHITESPACE_PATTERN = "[\0- \xA0\u1680\u180E\u2000-\u2029\u205F\u3000]";
|
|
2181
|
+
var UNICODE_WHITESPACE_REGEX = new RegExp(UNICODE_WHITESPACE_PATTERN);
|
|
2182
|
+
var UNICODE_WHITESPACE_REGEX_END = new RegExp(`${UNICODE_WHITESPACE_PATTERN}$`);
|
|
2183
|
+
var UNICODE_WHITESPACE_REGEX_GLOBAL = new RegExp(UNICODE_WHITESPACE_PATTERN, "g");
|
|
2184
|
+
function isValidLinkStructure(tokens) {
|
|
2185
|
+
if (tokens.length === 1) {
|
|
2186
|
+
return tokens[0].isLink;
|
|
2187
|
+
}
|
|
2188
|
+
if (tokens.length === 3 && tokens[1].isLink) {
|
|
2189
|
+
return ["()", "[]"].includes(tokens[0].value + tokens[2].value);
|
|
2190
|
+
}
|
|
2191
|
+
return false;
|
|
2192
|
+
}
|
|
2193
|
+
function autolink(options) {
|
|
2194
|
+
return new Plugin({
|
|
2195
|
+
key: new PluginKey("autolink"),
|
|
2196
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
2197
|
+
const docChanges = transactions.some((transaction) => transaction.docChanged) && !oldState.doc.eq(newState.doc);
|
|
2198
|
+
const preventAutolink = transactions.some((transaction) => transaction.getMeta("preventAutolink"));
|
|
2199
|
+
if (!docChanges || preventAutolink) {
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
const { tr: tr2 } = newState;
|
|
2203
|
+
const transform = combineTransactionSteps(oldState.doc, [...transactions]);
|
|
2204
|
+
const changes = getChangedRanges(transform);
|
|
2205
|
+
changes.forEach(({ newRange }) => {
|
|
2206
|
+
const nodesInChangedRanges = findChildrenInRange(newState.doc, newRange, (node) => node.isTextblock);
|
|
2207
|
+
let textBlock;
|
|
2208
|
+
let textBeforeWhitespace;
|
|
2209
|
+
if (nodesInChangedRanges.length > 1) {
|
|
2210
|
+
textBlock = nodesInChangedRanges[0];
|
|
2211
|
+
textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, textBlock.pos + textBlock.node.nodeSize, void 0, " ");
|
|
2212
|
+
} else if (nodesInChangedRanges.length) {
|
|
2213
|
+
const endText = newState.doc.textBetween(newRange.from, newRange.to, " ", " ");
|
|
2214
|
+
if (!UNICODE_WHITESPACE_REGEX_END.test(endText)) {
|
|
2215
|
+
return;
|
|
2216
|
+
}
|
|
2217
|
+
textBlock = nodesInChangedRanges[0];
|
|
2218
|
+
textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, newRange.to, void 0, " ");
|
|
2219
|
+
}
|
|
2220
|
+
if (textBlock && textBeforeWhitespace) {
|
|
2221
|
+
const wordsBeforeWhitespace = textBeforeWhitespace.split(UNICODE_WHITESPACE_REGEX).filter(Boolean);
|
|
2222
|
+
if (wordsBeforeWhitespace.length <= 0) {
|
|
2223
|
+
return false;
|
|
2224
|
+
}
|
|
2225
|
+
const lastWordBeforeSpace = wordsBeforeWhitespace[wordsBeforeWhitespace.length - 1];
|
|
2226
|
+
const lastWordAndBlockOffset = textBlock.pos + textBeforeWhitespace.lastIndexOf(lastWordBeforeSpace);
|
|
2227
|
+
if (!lastWordBeforeSpace) {
|
|
2228
|
+
return false;
|
|
2229
|
+
}
|
|
2230
|
+
const linksBeforeSpace = tokenize(lastWordBeforeSpace).map((t) => t.toObject(options.defaultProtocol));
|
|
2231
|
+
if (!isValidLinkStructure(linksBeforeSpace)) {
|
|
2232
|
+
return false;
|
|
2233
|
+
}
|
|
2234
|
+
linksBeforeSpace.filter((link) => link.isLink).map((link) => ({
|
|
2235
|
+
...link,
|
|
2236
|
+
from: lastWordAndBlockOffset + link.start + 1,
|
|
2237
|
+
to: lastWordAndBlockOffset + link.end + 1
|
|
2238
|
+
})).filter((link) => {
|
|
2239
|
+
if (!newState.schema.marks.code) {
|
|
2240
|
+
return true;
|
|
2241
|
+
}
|
|
2242
|
+
return !newState.doc.rangeHasMark(link.from, link.to, newState.schema.marks.code);
|
|
2243
|
+
}).filter((link) => options.validate(link.value)).filter((link) => options.shouldAutoLink(link.value)).forEach((link) => {
|
|
2244
|
+
if (getMarksBetween(link.from, link.to, newState.doc).some((item) => item.mark.type === options.type)) {
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
tr2.addMark(link.from, link.to, options.type.create({
|
|
2248
|
+
href: link.href
|
|
2249
|
+
}));
|
|
2250
|
+
});
|
|
2251
|
+
}
|
|
2252
|
+
});
|
|
2253
|
+
if (!tr2.steps.length) {
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
return tr2;
|
|
2257
|
+
}
|
|
2258
|
+
});
|
|
2259
|
+
}
|
|
2260
|
+
function clickHandler(options) {
|
|
2261
|
+
return new Plugin({
|
|
2262
|
+
key: new PluginKey("handleClickLink"),
|
|
2263
|
+
props: {
|
|
2264
|
+
handleClick: (view, pos, event) => {
|
|
2265
|
+
var _a, _b;
|
|
2266
|
+
if (event.button !== 0) {
|
|
2267
|
+
return false;
|
|
2268
|
+
}
|
|
2269
|
+
if (!view.editable) {
|
|
2270
|
+
return false;
|
|
2271
|
+
}
|
|
2272
|
+
let a = event.target;
|
|
2273
|
+
const els = [];
|
|
2274
|
+
while (a.nodeName !== "DIV") {
|
|
2275
|
+
els.push(a);
|
|
2276
|
+
a = a.parentNode;
|
|
2277
|
+
}
|
|
2278
|
+
if (!els.find((value) => value.nodeName === "A")) {
|
|
2279
|
+
return false;
|
|
2280
|
+
}
|
|
2281
|
+
const attrs = getAttributes(view.state, options.type.name);
|
|
2282
|
+
const link = event.target;
|
|
2283
|
+
const href = (_a = link === null || link === void 0 ? void 0 : link.href) !== null && _a !== void 0 ? _a : attrs.href;
|
|
2284
|
+
const target = (_b = link === null || link === void 0 ? void 0 : link.target) !== null && _b !== void 0 ? _b : attrs.target;
|
|
2285
|
+
if (link && href) {
|
|
2286
|
+
window.open(href, target);
|
|
2287
|
+
return true;
|
|
2288
|
+
}
|
|
2289
|
+
return false;
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
function pasteHandler(options) {
|
|
2295
|
+
return new Plugin({
|
|
2296
|
+
key: new PluginKey("handlePasteLink"),
|
|
2297
|
+
props: {
|
|
2298
|
+
handlePaste: (view, event, slice) => {
|
|
2299
|
+
const { state } = view;
|
|
2300
|
+
const { selection } = state;
|
|
2301
|
+
const { empty } = selection;
|
|
2302
|
+
if (empty) {
|
|
2303
|
+
return false;
|
|
2304
|
+
}
|
|
2305
|
+
let textContent = "";
|
|
2306
|
+
slice.content.forEach((node) => {
|
|
2307
|
+
textContent += node.textContent;
|
|
2308
|
+
});
|
|
2309
|
+
const link = find(textContent, { defaultProtocol: options.defaultProtocol }).find((item) => item.isLink && item.value === textContent);
|
|
2310
|
+
if (!textContent || !link) {
|
|
2311
|
+
return false;
|
|
2312
|
+
}
|
|
2313
|
+
return options.editor.commands.setMark(options.type, {
|
|
2314
|
+
href: link.href
|
|
2315
|
+
});
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
function isAllowedUri(uri, protocols) {
|
|
2321
|
+
const allowedProtocols = [
|
|
2322
|
+
"http",
|
|
2323
|
+
"https",
|
|
2324
|
+
"ftp",
|
|
2325
|
+
"ftps",
|
|
2326
|
+
"mailto",
|
|
2327
|
+
"tel",
|
|
2328
|
+
"callto",
|
|
2329
|
+
"sms",
|
|
2330
|
+
"cid",
|
|
2331
|
+
"xmpp"
|
|
2332
|
+
];
|
|
2333
|
+
if (protocols) {
|
|
2334
|
+
protocols.forEach((protocol) => {
|
|
2335
|
+
const nextProtocol = typeof protocol === "string" ? protocol : protocol.scheme;
|
|
2336
|
+
if (nextProtocol) {
|
|
2337
|
+
allowedProtocols.push(nextProtocol);
|
|
2338
|
+
}
|
|
2339
|
+
});
|
|
2340
|
+
}
|
|
2341
|
+
return !uri || uri.replace(UNICODE_WHITESPACE_REGEX_GLOBAL, "").match(new RegExp(
|
|
2342
|
+
// eslint-disable-next-line no-useless-escape
|
|
2343
|
+
`^(?:(?:${allowedProtocols.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,
|
|
2344
|
+
"i"
|
|
2345
|
+
));
|
|
2346
|
+
}
|
|
2347
|
+
var Link = Mark5.create({
|
|
2348
|
+
name: "link",
|
|
2349
|
+
priority: 1e3,
|
|
2350
|
+
keepOnSplit: false,
|
|
2351
|
+
exitable: true,
|
|
2352
|
+
onCreate() {
|
|
2353
|
+
if (this.options.validate && !this.options.shouldAutoLink) {
|
|
2354
|
+
this.options.shouldAutoLink = this.options.validate;
|
|
2355
|
+
console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.");
|
|
2356
|
+
}
|
|
2357
|
+
this.options.protocols.forEach((protocol) => {
|
|
2358
|
+
if (typeof protocol === "string") {
|
|
2359
|
+
registerCustomProtocol(protocol);
|
|
2360
|
+
return;
|
|
2361
|
+
}
|
|
2362
|
+
registerCustomProtocol(protocol.scheme, protocol.optionalSlashes);
|
|
2363
|
+
});
|
|
2364
|
+
},
|
|
2365
|
+
onDestroy() {
|
|
2366
|
+
reset();
|
|
2367
|
+
},
|
|
2368
|
+
inclusive() {
|
|
2369
|
+
return this.options.autolink;
|
|
2370
|
+
},
|
|
2371
|
+
addOptions() {
|
|
2372
|
+
return {
|
|
2373
|
+
openOnClick: true,
|
|
2374
|
+
linkOnPaste: true,
|
|
2375
|
+
autolink: true,
|
|
2376
|
+
protocols: [],
|
|
2377
|
+
defaultProtocol: "http",
|
|
2378
|
+
HTMLAttributes: {
|
|
2379
|
+
target: "_blank",
|
|
2380
|
+
rel: "noopener noreferrer nofollow",
|
|
2381
|
+
class: null
|
|
2382
|
+
},
|
|
2383
|
+
isAllowedUri: (url, ctx) => !!isAllowedUri(url, ctx.protocols),
|
|
2384
|
+
validate: (url) => !!url,
|
|
2385
|
+
shouldAutoLink: (url) => !!url
|
|
2386
|
+
};
|
|
2387
|
+
},
|
|
2388
|
+
addAttributes() {
|
|
2389
|
+
return {
|
|
2390
|
+
href: {
|
|
2391
|
+
default: null,
|
|
2392
|
+
parseHTML(element) {
|
|
2393
|
+
return element.getAttribute("href");
|
|
2394
|
+
}
|
|
2395
|
+
},
|
|
2396
|
+
target: {
|
|
2397
|
+
default: this.options.HTMLAttributes.target
|
|
2398
|
+
},
|
|
2399
|
+
rel: {
|
|
2400
|
+
default: this.options.HTMLAttributes.rel
|
|
2401
|
+
},
|
|
2402
|
+
class: {
|
|
2403
|
+
default: this.options.HTMLAttributes.class
|
|
2404
|
+
}
|
|
2405
|
+
};
|
|
2406
|
+
},
|
|
2407
|
+
parseHTML() {
|
|
2408
|
+
return [
|
|
2409
|
+
{
|
|
2410
|
+
tag: "a[href]",
|
|
2411
|
+
getAttrs: (dom) => {
|
|
2412
|
+
const href = dom.getAttribute("href");
|
|
2413
|
+
if (!href || !this.options.isAllowedUri(href, {
|
|
2414
|
+
defaultValidate: (url) => !!isAllowedUri(url, this.options.protocols),
|
|
2415
|
+
protocols: this.options.protocols,
|
|
2416
|
+
defaultProtocol: this.options.defaultProtocol
|
|
2417
|
+
})) {
|
|
2418
|
+
return false;
|
|
2419
|
+
}
|
|
2420
|
+
return null;
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
];
|
|
2424
|
+
},
|
|
2425
|
+
renderHTML({ HTMLAttributes }) {
|
|
2426
|
+
if (!this.options.isAllowedUri(HTMLAttributes.href, {
|
|
2427
|
+
defaultValidate: (href) => !!isAllowedUri(href, this.options.protocols),
|
|
2428
|
+
protocols: this.options.protocols,
|
|
2429
|
+
defaultProtocol: this.options.defaultProtocol
|
|
2430
|
+
})) {
|
|
2431
|
+
return [
|
|
2432
|
+
"a",
|
|
2433
|
+
mergeAttributes15(this.options.HTMLAttributes, { ...HTMLAttributes, href: "" }),
|
|
2434
|
+
0
|
|
2435
|
+
];
|
|
2436
|
+
}
|
|
2437
|
+
return ["a", mergeAttributes15(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
2438
|
+
},
|
|
2439
|
+
addCommands() {
|
|
2440
|
+
return {
|
|
2441
|
+
setLink: (attributes) => ({ chain }) => {
|
|
2442
|
+
const { href } = attributes;
|
|
2443
|
+
if (!this.options.isAllowedUri(href, {
|
|
2444
|
+
defaultValidate: (url) => !!isAllowedUri(url, this.options.protocols),
|
|
2445
|
+
protocols: this.options.protocols,
|
|
2446
|
+
defaultProtocol: this.options.defaultProtocol
|
|
2447
|
+
})) {
|
|
2448
|
+
return false;
|
|
2449
|
+
}
|
|
2450
|
+
return chain().setMark(this.name, attributes).setMeta("preventAutolink", true).run();
|
|
2451
|
+
},
|
|
2452
|
+
toggleLink: (attributes) => ({ chain }) => {
|
|
2453
|
+
const { href } = attributes;
|
|
2454
|
+
if (!this.options.isAllowedUri(href, {
|
|
2455
|
+
defaultValidate: (url) => !!isAllowedUri(url, this.options.protocols),
|
|
2456
|
+
protocols: this.options.protocols,
|
|
2457
|
+
defaultProtocol: this.options.defaultProtocol
|
|
2458
|
+
})) {
|
|
2459
|
+
return false;
|
|
2460
|
+
}
|
|
2461
|
+
return chain().toggleMark(this.name, attributes, { extendEmptyMarkRange: true }).setMeta("preventAutolink", true).run();
|
|
2462
|
+
},
|
|
2463
|
+
unsetLink: () => ({ chain }) => {
|
|
2464
|
+
return chain().unsetMark(this.name, { extendEmptyMarkRange: true }).setMeta("preventAutolink", true).run();
|
|
2465
|
+
}
|
|
2466
|
+
};
|
|
2467
|
+
},
|
|
2468
|
+
addPasteRules() {
|
|
2469
|
+
return [
|
|
2470
|
+
markPasteRule4({
|
|
2471
|
+
find: (text) => {
|
|
2472
|
+
const foundLinks = [];
|
|
2473
|
+
if (text) {
|
|
2474
|
+
const { protocols, defaultProtocol } = this.options;
|
|
2475
|
+
const links = find(text).filter((item) => item.isLink && this.options.isAllowedUri(item.value, {
|
|
2476
|
+
defaultValidate: (href) => !!isAllowedUri(href, protocols),
|
|
2477
|
+
protocols,
|
|
2478
|
+
defaultProtocol
|
|
2479
|
+
}));
|
|
2480
|
+
if (links.length) {
|
|
2481
|
+
links.forEach((link) => foundLinks.push({
|
|
2482
|
+
text: link.value,
|
|
2483
|
+
data: {
|
|
2484
|
+
href: link.href
|
|
2485
|
+
},
|
|
2486
|
+
index: link.start
|
|
2487
|
+
}));
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
return foundLinks;
|
|
2491
|
+
},
|
|
2492
|
+
type: this.type,
|
|
2493
|
+
getAttributes: (match) => {
|
|
2494
|
+
var _a;
|
|
2495
|
+
return {
|
|
2496
|
+
href: (_a = match.data) === null || _a === void 0 ? void 0 : _a.href
|
|
2497
|
+
};
|
|
2498
|
+
}
|
|
2499
|
+
})
|
|
2500
|
+
];
|
|
2501
|
+
},
|
|
2502
|
+
addProseMirrorPlugins() {
|
|
2503
|
+
const plugins = [];
|
|
2504
|
+
const { protocols, defaultProtocol } = this.options;
|
|
2505
|
+
if (this.options.autolink) {
|
|
2506
|
+
plugins.push(autolink({
|
|
2507
|
+
type: this.type,
|
|
2508
|
+
defaultProtocol: this.options.defaultProtocol,
|
|
2509
|
+
validate: (url) => this.options.isAllowedUri(url, {
|
|
2510
|
+
defaultValidate: (href) => !!isAllowedUri(href, protocols),
|
|
2511
|
+
protocols,
|
|
2512
|
+
defaultProtocol
|
|
2513
|
+
}),
|
|
2514
|
+
shouldAutoLink: this.options.shouldAutoLink
|
|
2515
|
+
}));
|
|
2516
|
+
}
|
|
2517
|
+
if (this.options.openOnClick === true) {
|
|
2518
|
+
plugins.push(clickHandler({
|
|
2519
|
+
type: this.type
|
|
2520
|
+
}));
|
|
2521
|
+
}
|
|
2522
|
+
if (this.options.linkOnPaste) {
|
|
2523
|
+
plugins.push(pasteHandler({
|
|
2524
|
+
editor: this.editor,
|
|
2525
|
+
defaultProtocol: this.options.defaultProtocol,
|
|
2526
|
+
type: this.type
|
|
2527
|
+
}));
|
|
2528
|
+
}
|
|
2529
|
+
return plugins;
|
|
2530
|
+
}
|
|
2531
|
+
});
|
|
2532
|
+
|
|
2533
|
+
// ../../node_modules/.pnpm/@tiptap+extension-image@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-image/dist/index.js
|
|
2534
|
+
import { Node as Node13, mergeAttributes as mergeAttributes16, nodeInputRule as nodeInputRule2 } from "@tiptap/core";
|
|
2535
|
+
var inputRegex6 = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
|
|
2536
|
+
var Image = Node13.create({
|
|
2537
|
+
name: "image",
|
|
2538
|
+
addOptions() {
|
|
2539
|
+
return {
|
|
2540
|
+
inline: false,
|
|
2541
|
+
allowBase64: false,
|
|
2542
|
+
HTMLAttributes: {}
|
|
2543
|
+
};
|
|
2544
|
+
},
|
|
2545
|
+
inline() {
|
|
2546
|
+
return this.options.inline;
|
|
2547
|
+
},
|
|
2548
|
+
group() {
|
|
2549
|
+
return this.options.inline ? "inline" : "block";
|
|
2550
|
+
},
|
|
2551
|
+
draggable: true,
|
|
2552
|
+
addAttributes() {
|
|
2553
|
+
return {
|
|
2554
|
+
src: {
|
|
2555
|
+
default: null
|
|
2556
|
+
},
|
|
2557
|
+
alt: {
|
|
2558
|
+
default: null
|
|
2559
|
+
},
|
|
2560
|
+
title: {
|
|
2561
|
+
default: null
|
|
2562
|
+
}
|
|
2563
|
+
};
|
|
2564
|
+
},
|
|
2565
|
+
parseHTML() {
|
|
2566
|
+
return [
|
|
2567
|
+
{
|
|
2568
|
+
tag: this.options.allowBase64 ? "img[src]" : 'img[src]:not([src^="data:"])'
|
|
2569
|
+
}
|
|
2570
|
+
];
|
|
2571
|
+
},
|
|
2572
|
+
renderHTML({ HTMLAttributes }) {
|
|
2573
|
+
return ["img", mergeAttributes16(this.options.HTMLAttributes, HTMLAttributes)];
|
|
2574
|
+
},
|
|
2575
|
+
addCommands() {
|
|
2576
|
+
return {
|
|
2577
|
+
setImage: (options) => ({ commands }) => {
|
|
2578
|
+
return commands.insertContent({
|
|
2579
|
+
type: this.name,
|
|
2580
|
+
attrs: options
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
};
|
|
2584
|
+
},
|
|
2585
|
+
addInputRules() {
|
|
2586
|
+
return [
|
|
2587
|
+
nodeInputRule2({
|
|
2588
|
+
find: inputRegex6,
|
|
2589
|
+
type: this.type,
|
|
2590
|
+
getAttributes: (match) => {
|
|
2591
|
+
const [, , alt, src, title] = match;
|
|
2592
|
+
return { src, alt, title };
|
|
2593
|
+
}
|
|
2594
|
+
})
|
|
2595
|
+
];
|
|
2596
|
+
}
|
|
2597
|
+
});
|
|
2598
|
+
|
|
2599
|
+
// ../../node_modules/.pnpm/@tiptap+extension-highlight@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-highlight/dist/index.js
|
|
2600
|
+
import { Mark as Mark6, mergeAttributes as mergeAttributes17, markInputRule as markInputRule4, markPasteRule as markPasteRule5 } from "@tiptap/core";
|
|
2601
|
+
var inputRegex7 = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/;
|
|
2602
|
+
var pasteRegex2 = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g;
|
|
2603
|
+
var Highlight = Mark6.create({
|
|
2604
|
+
name: "highlight",
|
|
2605
|
+
addOptions() {
|
|
2606
|
+
return {
|
|
2607
|
+
multicolor: false,
|
|
2608
|
+
HTMLAttributes: {}
|
|
2609
|
+
};
|
|
2610
|
+
},
|
|
2611
|
+
addAttributes() {
|
|
2612
|
+
if (!this.options.multicolor) {
|
|
2613
|
+
return {};
|
|
2614
|
+
}
|
|
2615
|
+
return {
|
|
2616
|
+
color: {
|
|
2617
|
+
default: null,
|
|
2618
|
+
parseHTML: (element) => element.getAttribute("data-color") || element.style.backgroundColor,
|
|
2619
|
+
renderHTML: (attributes) => {
|
|
2620
|
+
if (!attributes.color) {
|
|
2621
|
+
return {};
|
|
2622
|
+
}
|
|
2623
|
+
return {
|
|
2624
|
+
"data-color": attributes.color,
|
|
2625
|
+
style: `background-color: ${attributes.color}; color: inherit`
|
|
2626
|
+
};
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
};
|
|
2630
|
+
},
|
|
2631
|
+
parseHTML() {
|
|
2632
|
+
return [
|
|
2633
|
+
{
|
|
2634
|
+
tag: "mark"
|
|
2635
|
+
}
|
|
2636
|
+
];
|
|
2637
|
+
},
|
|
2638
|
+
renderHTML({ HTMLAttributes }) {
|
|
2639
|
+
return ["mark", mergeAttributes17(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
2640
|
+
},
|
|
2641
|
+
addCommands() {
|
|
2642
|
+
return {
|
|
2643
|
+
setHighlight: (attributes) => ({ commands }) => {
|
|
2644
|
+
return commands.setMark(this.name, attributes);
|
|
2645
|
+
},
|
|
2646
|
+
toggleHighlight: (attributes) => ({ commands }) => {
|
|
2647
|
+
return commands.toggleMark(this.name, attributes);
|
|
2648
|
+
},
|
|
2649
|
+
unsetHighlight: () => ({ commands }) => {
|
|
2650
|
+
return commands.unsetMark(this.name);
|
|
2651
|
+
}
|
|
2652
|
+
};
|
|
2653
|
+
},
|
|
2654
|
+
addKeyboardShortcuts() {
|
|
2655
|
+
return {
|
|
2656
|
+
"Mod-Shift-h": () => this.editor.commands.toggleHighlight()
|
|
2657
|
+
};
|
|
2658
|
+
},
|
|
2659
|
+
addInputRules() {
|
|
2660
|
+
return [
|
|
2661
|
+
markInputRule4({
|
|
2662
|
+
find: inputRegex7,
|
|
2663
|
+
type: this.type
|
|
2664
|
+
})
|
|
2665
|
+
];
|
|
2666
|
+
},
|
|
2667
|
+
addPasteRules() {
|
|
2668
|
+
return [
|
|
2669
|
+
markPasteRule5({
|
|
2670
|
+
find: pasteRegex2,
|
|
2671
|
+
type: this.type
|
|
2672
|
+
})
|
|
2673
|
+
];
|
|
2674
|
+
}
|
|
2675
|
+
});
|
|
2676
|
+
|
|
2677
|
+
// ../../node_modules/.pnpm/@tiptap+extension-typography@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-typography/dist/index.js
|
|
2678
|
+
import { Extension as Extension4, textInputRule } from "@tiptap/core";
|
|
2679
|
+
var emDash = (override) => textInputRule({
|
|
2680
|
+
find: /--$/,
|
|
2681
|
+
replace: override !== null && override !== void 0 ? override : "\u2014"
|
|
2682
|
+
});
|
|
2683
|
+
var ellipsis = (override) => textInputRule({
|
|
2684
|
+
find: /\.\.\.$/,
|
|
2685
|
+
replace: override !== null && override !== void 0 ? override : "\u2026"
|
|
2686
|
+
});
|
|
2687
|
+
var openDoubleQuote = (override) => textInputRule({
|
|
2688
|
+
find: /(?:^|[\s{[(<'"\u2018\u201C])(")$/,
|
|
2689
|
+
replace: override !== null && override !== void 0 ? override : "\u201C"
|
|
2690
|
+
});
|
|
2691
|
+
var closeDoubleQuote = (override) => textInputRule({
|
|
2692
|
+
find: /"$/,
|
|
2693
|
+
replace: override !== null && override !== void 0 ? override : "\u201D"
|
|
2694
|
+
});
|
|
2695
|
+
var openSingleQuote = (override) => textInputRule({
|
|
2696
|
+
find: /(?:^|[\s{[(<'"\u2018\u201C])(')$/,
|
|
2697
|
+
replace: override !== null && override !== void 0 ? override : "\u2018"
|
|
2698
|
+
});
|
|
2699
|
+
var closeSingleQuote = (override) => textInputRule({
|
|
2700
|
+
find: /'$/,
|
|
2701
|
+
replace: override !== null && override !== void 0 ? override : "\u2019"
|
|
2702
|
+
});
|
|
2703
|
+
var leftArrow = (override) => textInputRule({
|
|
2704
|
+
find: /<-$/,
|
|
2705
|
+
replace: override !== null && override !== void 0 ? override : "\u2190"
|
|
2706
|
+
});
|
|
2707
|
+
var rightArrow = (override) => textInputRule({
|
|
2708
|
+
find: /->$/,
|
|
2709
|
+
replace: override !== null && override !== void 0 ? override : "\u2192"
|
|
2710
|
+
});
|
|
2711
|
+
var copyright = (override) => textInputRule({
|
|
2712
|
+
find: /\(c\)$/,
|
|
2713
|
+
replace: override !== null && override !== void 0 ? override : "\xA9"
|
|
2714
|
+
});
|
|
2715
|
+
var trademark = (override) => textInputRule({
|
|
2716
|
+
find: /\(tm\)$/,
|
|
2717
|
+
replace: override !== null && override !== void 0 ? override : "\u2122"
|
|
2718
|
+
});
|
|
2719
|
+
var servicemark = (override) => textInputRule({
|
|
2720
|
+
find: /\(sm\)$/,
|
|
2721
|
+
replace: override !== null && override !== void 0 ? override : "\u2120"
|
|
2722
|
+
});
|
|
2723
|
+
var registeredTrademark = (override) => textInputRule({
|
|
2724
|
+
find: /\(r\)$/,
|
|
2725
|
+
replace: override !== null && override !== void 0 ? override : "\xAE"
|
|
2726
|
+
});
|
|
2727
|
+
var oneHalf = (override) => textInputRule({
|
|
2728
|
+
find: /(?:^|\s)(1\/2)\s$/,
|
|
2729
|
+
replace: override !== null && override !== void 0 ? override : "\xBD"
|
|
2730
|
+
});
|
|
2731
|
+
var plusMinus = (override) => textInputRule({
|
|
2732
|
+
find: /\+\/-$/,
|
|
2733
|
+
replace: override !== null && override !== void 0 ? override : "\xB1"
|
|
2734
|
+
});
|
|
2735
|
+
var notEqual = (override) => textInputRule({
|
|
2736
|
+
find: /!=$/,
|
|
2737
|
+
replace: override !== null && override !== void 0 ? override : "\u2260"
|
|
2738
|
+
});
|
|
2739
|
+
var laquo = (override) => textInputRule({
|
|
2740
|
+
find: /<<$/,
|
|
2741
|
+
replace: override !== null && override !== void 0 ? override : "\xAB"
|
|
2742
|
+
});
|
|
2743
|
+
var raquo = (override) => textInputRule({
|
|
2744
|
+
find: />>$/,
|
|
2745
|
+
replace: override !== null && override !== void 0 ? override : "\xBB"
|
|
2746
|
+
});
|
|
2747
|
+
var multiplication = (override) => textInputRule({
|
|
2748
|
+
find: /\d+\s?([*x])\s?\d+$/,
|
|
2749
|
+
replace: override !== null && override !== void 0 ? override : "\xD7"
|
|
2750
|
+
});
|
|
2751
|
+
var superscriptTwo = (override) => textInputRule({
|
|
2752
|
+
find: /\^2$/,
|
|
2753
|
+
replace: override !== null && override !== void 0 ? override : "\xB2"
|
|
2754
|
+
});
|
|
2755
|
+
var superscriptThree = (override) => textInputRule({
|
|
2756
|
+
find: /\^3$/,
|
|
2757
|
+
replace: override !== null && override !== void 0 ? override : "\xB3"
|
|
2758
|
+
});
|
|
2759
|
+
var oneQuarter = (override) => textInputRule({
|
|
2760
|
+
find: /(?:^|\s)(1\/4)\s$/,
|
|
2761
|
+
replace: override !== null && override !== void 0 ? override : "\xBC"
|
|
2762
|
+
});
|
|
2763
|
+
var threeQuarters = (override) => textInputRule({
|
|
2764
|
+
find: /(?:^|\s)(3\/4)\s$/,
|
|
2765
|
+
replace: override !== null && override !== void 0 ? override : "\xBE"
|
|
2766
|
+
});
|
|
2767
|
+
var Typography = Extension4.create({
|
|
2768
|
+
name: "typography",
|
|
2769
|
+
addOptions() {
|
|
2770
|
+
return {
|
|
2771
|
+
closeDoubleQuote: "\u201D",
|
|
2772
|
+
closeSingleQuote: "\u2019",
|
|
2773
|
+
copyright: "\xA9",
|
|
2774
|
+
ellipsis: "\u2026",
|
|
2775
|
+
emDash: "\u2014",
|
|
2776
|
+
laquo: "\xAB",
|
|
2777
|
+
leftArrow: "\u2190",
|
|
2778
|
+
multiplication: "\xD7",
|
|
2779
|
+
notEqual: "\u2260",
|
|
2780
|
+
oneHalf: "\xBD",
|
|
2781
|
+
oneQuarter: "\xBC",
|
|
2782
|
+
openDoubleQuote: "\u201C",
|
|
2783
|
+
openSingleQuote: "\u2018",
|
|
2784
|
+
plusMinus: "\xB1",
|
|
2785
|
+
raquo: "\xBB",
|
|
2786
|
+
registeredTrademark: "\xAE",
|
|
2787
|
+
rightArrow: "\u2192",
|
|
2788
|
+
servicemark: "\u2120",
|
|
2789
|
+
superscriptThree: "\xB3",
|
|
2790
|
+
superscriptTwo: "\xB2",
|
|
2791
|
+
threeQuarters: "\xBE",
|
|
2792
|
+
trademark: "\u2122"
|
|
2793
|
+
};
|
|
2794
|
+
},
|
|
2795
|
+
addInputRules() {
|
|
2796
|
+
const rules = [];
|
|
2797
|
+
if (this.options.emDash !== false) {
|
|
2798
|
+
rules.push(emDash(this.options.emDash));
|
|
2799
|
+
}
|
|
2800
|
+
if (this.options.ellipsis !== false) {
|
|
2801
|
+
rules.push(ellipsis(this.options.ellipsis));
|
|
2802
|
+
}
|
|
2803
|
+
if (this.options.openDoubleQuote !== false) {
|
|
2804
|
+
rules.push(openDoubleQuote(this.options.openDoubleQuote));
|
|
2805
|
+
}
|
|
2806
|
+
if (this.options.closeDoubleQuote !== false) {
|
|
2807
|
+
rules.push(closeDoubleQuote(this.options.closeDoubleQuote));
|
|
2808
|
+
}
|
|
2809
|
+
if (this.options.openSingleQuote !== false) {
|
|
2810
|
+
rules.push(openSingleQuote(this.options.openSingleQuote));
|
|
2811
|
+
}
|
|
2812
|
+
if (this.options.closeSingleQuote !== false) {
|
|
2813
|
+
rules.push(closeSingleQuote(this.options.closeSingleQuote));
|
|
2814
|
+
}
|
|
2815
|
+
if (this.options.leftArrow !== false) {
|
|
2816
|
+
rules.push(leftArrow(this.options.leftArrow));
|
|
2817
|
+
}
|
|
2818
|
+
if (this.options.rightArrow !== false) {
|
|
2819
|
+
rules.push(rightArrow(this.options.rightArrow));
|
|
2820
|
+
}
|
|
2821
|
+
if (this.options.copyright !== false) {
|
|
2822
|
+
rules.push(copyright(this.options.copyright));
|
|
2823
|
+
}
|
|
2824
|
+
if (this.options.trademark !== false) {
|
|
2825
|
+
rules.push(trademark(this.options.trademark));
|
|
2826
|
+
}
|
|
2827
|
+
if (this.options.servicemark !== false) {
|
|
2828
|
+
rules.push(servicemark(this.options.servicemark));
|
|
2829
|
+
}
|
|
2830
|
+
if (this.options.registeredTrademark !== false) {
|
|
2831
|
+
rules.push(registeredTrademark(this.options.registeredTrademark));
|
|
2832
|
+
}
|
|
2833
|
+
if (this.options.oneHalf !== false) {
|
|
2834
|
+
rules.push(oneHalf(this.options.oneHalf));
|
|
2835
|
+
}
|
|
2836
|
+
if (this.options.plusMinus !== false) {
|
|
2837
|
+
rules.push(plusMinus(this.options.plusMinus));
|
|
2838
|
+
}
|
|
2839
|
+
if (this.options.notEqual !== false) {
|
|
2840
|
+
rules.push(notEqual(this.options.notEqual));
|
|
2841
|
+
}
|
|
2842
|
+
if (this.options.laquo !== false) {
|
|
2843
|
+
rules.push(laquo(this.options.laquo));
|
|
2844
|
+
}
|
|
2845
|
+
if (this.options.raquo !== false) {
|
|
2846
|
+
rules.push(raquo(this.options.raquo));
|
|
2847
|
+
}
|
|
2848
|
+
if (this.options.multiplication !== false) {
|
|
2849
|
+
rules.push(multiplication(this.options.multiplication));
|
|
2850
|
+
}
|
|
2851
|
+
if (this.options.superscriptTwo !== false) {
|
|
2852
|
+
rules.push(superscriptTwo(this.options.superscriptTwo));
|
|
2853
|
+
}
|
|
2854
|
+
if (this.options.superscriptThree !== false) {
|
|
2855
|
+
rules.push(superscriptThree(this.options.superscriptThree));
|
|
2856
|
+
}
|
|
2857
|
+
if (this.options.oneQuarter !== false) {
|
|
2858
|
+
rules.push(oneQuarter(this.options.oneQuarter));
|
|
2859
|
+
}
|
|
2860
|
+
if (this.options.threeQuarters !== false) {
|
|
2861
|
+
rules.push(threeQuarters(this.options.threeQuarters));
|
|
2862
|
+
}
|
|
2863
|
+
return rules;
|
|
2864
|
+
}
|
|
2865
|
+
});
|
|
2866
|
+
|
|
2867
|
+
// ../../node_modules/.pnpm/@tiptap+extension-placeholder@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/extension-placeholder/dist/index.js
|
|
2868
|
+
import { Extension as Extension5, isNodeEmpty } from "@tiptap/core";
|
|
2869
|
+
import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
|
|
2870
|
+
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
2871
|
+
var Placeholder = Extension5.create({
|
|
2872
|
+
name: "placeholder",
|
|
2873
|
+
addOptions() {
|
|
2874
|
+
return {
|
|
2875
|
+
emptyEditorClass: "is-editor-empty",
|
|
2876
|
+
emptyNodeClass: "is-empty",
|
|
2877
|
+
placeholder: "Write something \u2026",
|
|
2878
|
+
showOnlyWhenEditable: true,
|
|
2879
|
+
showOnlyCurrent: true,
|
|
2880
|
+
includeChildren: false
|
|
2881
|
+
};
|
|
2882
|
+
},
|
|
2883
|
+
addProseMirrorPlugins() {
|
|
2884
|
+
return [
|
|
2885
|
+
new Plugin2({
|
|
2886
|
+
key: new PluginKey2("placeholder"),
|
|
2887
|
+
props: {
|
|
2888
|
+
decorations: ({ doc, selection }) => {
|
|
2889
|
+
const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
|
|
2890
|
+
const { anchor } = selection;
|
|
2891
|
+
const decorations = [];
|
|
2892
|
+
if (!active) {
|
|
2893
|
+
return null;
|
|
2894
|
+
}
|
|
2895
|
+
const isEmptyDoc = this.editor.isEmpty;
|
|
2896
|
+
doc.descendants((node, pos) => {
|
|
2897
|
+
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
|
|
2898
|
+
const isEmpty = !node.isLeaf && isNodeEmpty(node);
|
|
2899
|
+
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
2900
|
+
const classes = [this.options.emptyNodeClass];
|
|
2901
|
+
if (isEmptyDoc) {
|
|
2902
|
+
classes.push(this.options.emptyEditorClass);
|
|
2903
|
+
}
|
|
2904
|
+
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
2905
|
+
class: classes.join(" "),
|
|
2906
|
+
"data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
|
|
2907
|
+
editor: this.editor,
|
|
2908
|
+
node,
|
|
2909
|
+
pos,
|
|
2910
|
+
hasAnchor
|
|
2911
|
+
}) : this.options.placeholder
|
|
2912
|
+
});
|
|
2913
|
+
decorations.push(decoration);
|
|
2914
|
+
}
|
|
2915
|
+
return this.options.includeChildren;
|
|
2916
|
+
});
|
|
2917
|
+
return DecorationSet.create(doc, decorations);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
})
|
|
2921
|
+
];
|
|
2922
|
+
}
|
|
2923
|
+
});
|
|
2924
|
+
|
|
2925
|
+
// ../../node_modules/.pnpm/@tiptap+extension-code@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-code/dist/index.js
|
|
2926
|
+
import { Mark as Mark7, mergeAttributes as mergeAttributes18, markInputRule as markInputRule5, markPasteRule as markPasteRule6 } from "@tiptap/core";
|
|
2927
|
+
var inputRegex8 = /(^|[^`])`([^`]+)`(?!`)/;
|
|
2928
|
+
var pasteRegex3 = /(^|[^`])`([^`]+)`(?!`)/g;
|
|
2929
|
+
var Code = Mark7.create({
|
|
2930
|
+
name: "code",
|
|
2931
|
+
addOptions() {
|
|
2932
|
+
return {
|
|
2933
|
+
HTMLAttributes: {}
|
|
2934
|
+
};
|
|
2935
|
+
},
|
|
2936
|
+
excludes: "_",
|
|
2937
|
+
code: true,
|
|
2938
|
+
exitable: true,
|
|
2939
|
+
parseHTML() {
|
|
2940
|
+
return [
|
|
2941
|
+
{ tag: "code" }
|
|
2942
|
+
];
|
|
2943
|
+
},
|
|
2944
|
+
renderHTML({ HTMLAttributes }) {
|
|
2945
|
+
return ["code", mergeAttributes18(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
2946
|
+
},
|
|
2947
|
+
addCommands() {
|
|
2948
|
+
return {
|
|
2949
|
+
setCode: () => ({ commands }) => {
|
|
2950
|
+
return commands.setMark(this.name);
|
|
2951
|
+
},
|
|
2952
|
+
toggleCode: () => ({ commands }) => {
|
|
2953
|
+
return commands.toggleMark(this.name);
|
|
2954
|
+
},
|
|
2955
|
+
unsetCode: () => ({ commands }) => {
|
|
2956
|
+
return commands.unsetMark(this.name);
|
|
2957
|
+
}
|
|
2958
|
+
};
|
|
2959
|
+
},
|
|
2960
|
+
addKeyboardShortcuts() {
|
|
2961
|
+
return {
|
|
2962
|
+
"Mod-e": () => this.editor.commands.toggleCode()
|
|
2963
|
+
};
|
|
2964
|
+
},
|
|
2965
|
+
addInputRules() {
|
|
2966
|
+
return [
|
|
2967
|
+
markInputRule5({
|
|
2968
|
+
find: inputRegex8,
|
|
2969
|
+
type: this.type
|
|
2970
|
+
})
|
|
2971
|
+
];
|
|
2972
|
+
},
|
|
2973
|
+
addPasteRules() {
|
|
2974
|
+
return [
|
|
2975
|
+
markPasteRule6({
|
|
2976
|
+
find: pasteRegex3,
|
|
2977
|
+
type: this.type
|
|
2978
|
+
})
|
|
2979
|
+
];
|
|
2980
|
+
}
|
|
2981
|
+
});
|
|
2982
|
+
|
|
2983
|
+
// ../../node_modules/.pnpm/@tiptap+extension-code-block@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/extension-code-block/dist/index.js
|
|
2984
|
+
import { Node as Node14, mergeAttributes as mergeAttributes19, textblockTypeInputRule as textblockTypeInputRule2 } from "@tiptap/core";
|
|
2985
|
+
import { Selection, Plugin as Plugin3, PluginKey as PluginKey3, TextSelection as TextSelection2 } from "@tiptap/pm/state";
|
|
2986
|
+
var backtickInputRegex = /^```([a-z]+)?[\s\n]$/;
|
|
2987
|
+
var tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/;
|
|
2988
|
+
var CodeBlock = Node14.create({
|
|
2989
|
+
name: "codeBlock",
|
|
2990
|
+
addOptions() {
|
|
2991
|
+
return {
|
|
2992
|
+
languageClassPrefix: "language-",
|
|
2993
|
+
exitOnTripleEnter: true,
|
|
2994
|
+
exitOnArrowDown: true,
|
|
2995
|
+
defaultLanguage: null,
|
|
2996
|
+
HTMLAttributes: {}
|
|
2997
|
+
};
|
|
2998
|
+
},
|
|
2999
|
+
content: "text*",
|
|
3000
|
+
marks: "",
|
|
3001
|
+
group: "block",
|
|
3002
|
+
code: true,
|
|
3003
|
+
defining: true,
|
|
3004
|
+
addAttributes() {
|
|
3005
|
+
return {
|
|
3006
|
+
language: {
|
|
3007
|
+
default: this.options.defaultLanguage,
|
|
3008
|
+
parseHTML: (element) => {
|
|
3009
|
+
var _a;
|
|
3010
|
+
const { languageClassPrefix } = this.options;
|
|
3011
|
+
const classNames = [...((_a = element.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList) || []];
|
|
3012
|
+
const languages = classNames.filter((className) => className.startsWith(languageClassPrefix)).map((className) => className.replace(languageClassPrefix, ""));
|
|
3013
|
+
const language = languages[0];
|
|
3014
|
+
if (!language) {
|
|
3015
|
+
return null;
|
|
3016
|
+
}
|
|
3017
|
+
return language;
|
|
3018
|
+
},
|
|
3019
|
+
rendered: false
|
|
3020
|
+
}
|
|
3021
|
+
};
|
|
3022
|
+
},
|
|
3023
|
+
parseHTML() {
|
|
3024
|
+
return [
|
|
3025
|
+
{
|
|
3026
|
+
tag: "pre",
|
|
3027
|
+
preserveWhitespace: "full"
|
|
3028
|
+
}
|
|
3029
|
+
];
|
|
3030
|
+
},
|
|
3031
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
3032
|
+
return [
|
|
3033
|
+
"pre",
|
|
3034
|
+
mergeAttributes19(this.options.HTMLAttributes, HTMLAttributes),
|
|
3035
|
+
[
|
|
3036
|
+
"code",
|
|
3037
|
+
{
|
|
3038
|
+
class: node.attrs.language ? this.options.languageClassPrefix + node.attrs.language : null
|
|
3039
|
+
},
|
|
3040
|
+
0
|
|
3041
|
+
]
|
|
3042
|
+
];
|
|
3043
|
+
},
|
|
3044
|
+
addCommands() {
|
|
3045
|
+
return {
|
|
3046
|
+
setCodeBlock: (attributes) => ({ commands }) => {
|
|
3047
|
+
return commands.setNode(this.name, attributes);
|
|
3048
|
+
},
|
|
3049
|
+
toggleCodeBlock: (attributes) => ({ commands }) => {
|
|
3050
|
+
return commands.toggleNode(this.name, "paragraph", attributes);
|
|
3051
|
+
}
|
|
3052
|
+
};
|
|
3053
|
+
},
|
|
3054
|
+
addKeyboardShortcuts() {
|
|
3055
|
+
return {
|
|
3056
|
+
"Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),
|
|
3057
|
+
// remove code block when at start of document or code block is empty
|
|
3058
|
+
Backspace: () => {
|
|
3059
|
+
const { empty, $anchor } = this.editor.state.selection;
|
|
3060
|
+
const isAtStart = $anchor.pos === 1;
|
|
3061
|
+
if (!empty || $anchor.parent.type.name !== this.name) {
|
|
3062
|
+
return false;
|
|
3063
|
+
}
|
|
3064
|
+
if (isAtStart || !$anchor.parent.textContent.length) {
|
|
3065
|
+
return this.editor.commands.clearNodes();
|
|
3066
|
+
}
|
|
3067
|
+
return false;
|
|
3068
|
+
},
|
|
3069
|
+
// exit node on triple enter
|
|
3070
|
+
Enter: ({ editor }) => {
|
|
3071
|
+
if (!this.options.exitOnTripleEnter) {
|
|
3072
|
+
return false;
|
|
3073
|
+
}
|
|
3074
|
+
const { state } = editor;
|
|
3075
|
+
const { selection } = state;
|
|
3076
|
+
const { $from, empty } = selection;
|
|
3077
|
+
if (!empty || $from.parent.type !== this.type) {
|
|
3078
|
+
return false;
|
|
3079
|
+
}
|
|
3080
|
+
const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
|
|
3081
|
+
const endsWithDoubleNewline = $from.parent.textContent.endsWith("\n\n");
|
|
3082
|
+
if (!isAtEnd || !endsWithDoubleNewline) {
|
|
3083
|
+
return false;
|
|
3084
|
+
}
|
|
3085
|
+
return editor.chain().command(({ tr: tr2 }) => {
|
|
3086
|
+
tr2.delete($from.pos - 2, $from.pos);
|
|
3087
|
+
return true;
|
|
3088
|
+
}).exitCode().run();
|
|
3089
|
+
},
|
|
3090
|
+
// exit node on arrow down
|
|
3091
|
+
ArrowDown: ({ editor }) => {
|
|
3092
|
+
if (!this.options.exitOnArrowDown) {
|
|
3093
|
+
return false;
|
|
3094
|
+
}
|
|
3095
|
+
const { state } = editor;
|
|
3096
|
+
const { selection, doc } = state;
|
|
3097
|
+
const { $from, empty } = selection;
|
|
3098
|
+
if (!empty || $from.parent.type !== this.type) {
|
|
3099
|
+
return false;
|
|
3100
|
+
}
|
|
3101
|
+
const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
|
|
3102
|
+
if (!isAtEnd) {
|
|
3103
|
+
return false;
|
|
3104
|
+
}
|
|
3105
|
+
const after = $from.after();
|
|
3106
|
+
if (after === void 0) {
|
|
3107
|
+
return false;
|
|
3108
|
+
}
|
|
3109
|
+
const nodeAfter = doc.nodeAt(after);
|
|
3110
|
+
if (nodeAfter) {
|
|
3111
|
+
return editor.commands.command(({ tr: tr2 }) => {
|
|
3112
|
+
tr2.setSelection(Selection.near(doc.resolve(after)));
|
|
3113
|
+
return true;
|
|
3114
|
+
});
|
|
3115
|
+
}
|
|
3116
|
+
return editor.commands.exitCode();
|
|
3117
|
+
}
|
|
3118
|
+
};
|
|
3119
|
+
},
|
|
3120
|
+
addInputRules() {
|
|
3121
|
+
return [
|
|
3122
|
+
textblockTypeInputRule2({
|
|
3123
|
+
find: backtickInputRegex,
|
|
3124
|
+
type: this.type,
|
|
3125
|
+
getAttributes: (match) => ({
|
|
3126
|
+
language: match[1]
|
|
3127
|
+
})
|
|
3128
|
+
}),
|
|
3129
|
+
textblockTypeInputRule2({
|
|
3130
|
+
find: tildeInputRegex,
|
|
3131
|
+
type: this.type,
|
|
3132
|
+
getAttributes: (match) => ({
|
|
3133
|
+
language: match[1]
|
|
3134
|
+
})
|
|
3135
|
+
})
|
|
3136
|
+
];
|
|
3137
|
+
},
|
|
3138
|
+
addProseMirrorPlugins() {
|
|
3139
|
+
return [
|
|
3140
|
+
// this plugin creates a code block for pasted content from VS Code
|
|
3141
|
+
// we can also detect the copied code language
|
|
3142
|
+
new Plugin3({
|
|
3143
|
+
key: new PluginKey3("codeBlockVSCodeHandler"),
|
|
3144
|
+
props: {
|
|
3145
|
+
handlePaste: (view, event) => {
|
|
3146
|
+
if (!event.clipboardData) {
|
|
3147
|
+
return false;
|
|
3148
|
+
}
|
|
3149
|
+
if (this.editor.isActive(this.type.name)) {
|
|
3150
|
+
return false;
|
|
3151
|
+
}
|
|
3152
|
+
const text = event.clipboardData.getData("text/plain");
|
|
3153
|
+
const vscode = event.clipboardData.getData("vscode-editor-data");
|
|
3154
|
+
const vscodeData = vscode ? JSON.parse(vscode) : void 0;
|
|
3155
|
+
const language = vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;
|
|
3156
|
+
if (!text || !language) {
|
|
3157
|
+
return false;
|
|
3158
|
+
}
|
|
3159
|
+
const { tr: tr2, schema } = view.state;
|
|
3160
|
+
const textNode = schema.text(text.replace(/\r\n?/g, "\n"));
|
|
3161
|
+
tr2.replaceSelectionWith(this.type.create({ language }, textNode));
|
|
3162
|
+
if (tr2.selection.$from.parent.type !== this.type) {
|
|
3163
|
+
tr2.setSelection(TextSelection2.near(tr2.doc.resolve(Math.max(0, tr2.selection.from - 2))));
|
|
3164
|
+
}
|
|
3165
|
+
tr2.setMeta("paste", true);
|
|
3166
|
+
view.dispatch(tr2);
|
|
3167
|
+
return true;
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
})
|
|
3171
|
+
];
|
|
3172
|
+
}
|
|
3173
|
+
});
|
|
3174
|
+
|
|
3175
|
+
// ../../node_modules/.pnpm/@tiptap+extension-table-row@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-table-row/dist/index.js
|
|
3176
|
+
import { Node as Node15, mergeAttributes as mergeAttributes20 } from "@tiptap/core";
|
|
3177
|
+
var TableRow = Node15.create({
|
|
3178
|
+
name: "tableRow",
|
|
3179
|
+
addOptions() {
|
|
3180
|
+
return {
|
|
3181
|
+
HTMLAttributes: {}
|
|
3182
|
+
};
|
|
3183
|
+
},
|
|
3184
|
+
content: "(tableCell | tableHeader)*",
|
|
3185
|
+
tableRole: "row",
|
|
3186
|
+
parseHTML() {
|
|
3187
|
+
return [
|
|
3188
|
+
{ tag: "tr" }
|
|
3189
|
+
];
|
|
3190
|
+
},
|
|
3191
|
+
renderHTML({ HTMLAttributes }) {
|
|
3192
|
+
return ["tr", mergeAttributes20(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
3193
|
+
}
|
|
3194
|
+
});
|
|
3195
|
+
|
|
3196
|
+
// src/extensions/list-behavior.ts
|
|
3197
|
+
import { Extension as Extension6 } from "@tiptap/core";
|
|
3198
|
+
function isEmptyParagraphAtStart(editor) {
|
|
3199
|
+
const { selection } = editor.state;
|
|
3200
|
+
return selection.empty && selection.$from.parent.isTextblock && selection.$from.parent.content.size === 0 && selection.$from.parentOffset === 0;
|
|
3201
|
+
}
|
|
3202
|
+
var LoomaListBehavior = Extension6.create({
|
|
3203
|
+
name: "loomaListBehavior",
|
|
3204
|
+
addKeyboardShortcuts() {
|
|
3205
|
+
return {
|
|
3206
|
+
Enter: () => {
|
|
3207
|
+
if (this.editor.isActive("taskItem")) {
|
|
3208
|
+
return this.editor.commands.splitListItem("taskItem");
|
|
3209
|
+
}
|
|
3210
|
+
if (this.editor.isActive("listItem")) {
|
|
3211
|
+
return this.editor.commands.splitListItem("listItem");
|
|
3212
|
+
}
|
|
3213
|
+
return false;
|
|
3214
|
+
},
|
|
3215
|
+
Backspace: () => {
|
|
3216
|
+
if (!isEmptyParagraphAtStart(this.editor)) {
|
|
3217
|
+
return false;
|
|
3218
|
+
}
|
|
3219
|
+
if (this.editor.isActive("taskItem")) {
|
|
3220
|
+
return this.editor.commands.liftListItem("taskItem");
|
|
3221
|
+
}
|
|
3222
|
+
if (this.editor.isActive("listItem")) {
|
|
3223
|
+
return this.editor.commands.liftListItem("listItem");
|
|
3224
|
+
}
|
|
3225
|
+
return false;
|
|
3226
|
+
}
|
|
3227
|
+
};
|
|
3228
|
+
}
|
|
3229
|
+
});
|
|
3230
|
+
|
|
3231
|
+
// ../../node_modules/.pnpm/@tiptap+extension-table@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2__@tiptap+pm@2.27.2/node_modules/@tiptap/extension-table/dist/index.js
|
|
3232
|
+
import { findParentNodeClosestToPos, Node as Node16, mergeAttributes as mergeAttributes21, callOrReturn as callOrReturn2, getExtensionField as getExtensionField2 } from "@tiptap/core";
|
|
3233
|
+
import { TextSelection as TextSelection3 } from "@tiptap/pm/state";
|
|
3234
|
+
import { CellSelection, addColumnBefore, addColumnAfter, deleteColumn, addRowBefore, addRowAfter, deleteRow, deleteTable, mergeCells, splitCell, toggleHeader, toggleHeaderCell, setCellAttr, goToNextCell, fixTables, columnResizing, tableEditing } from "@tiptap/pm/tables";
|
|
3235
|
+
function getColStyleDeclaration(minWidth, width) {
|
|
3236
|
+
if (width) {
|
|
3237
|
+
return ["width", `${Math.max(width, minWidth)}px`];
|
|
3238
|
+
}
|
|
3239
|
+
return ["min-width", `${minWidth}px`];
|
|
3240
|
+
}
|
|
3241
|
+
function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
|
|
3242
|
+
var _a;
|
|
3243
|
+
let totalWidth = 0;
|
|
3244
|
+
let fixedWidth = true;
|
|
3245
|
+
let nextDOM = colgroup.firstChild;
|
|
3246
|
+
const row = node.firstChild;
|
|
3247
|
+
if (row !== null) {
|
|
3248
|
+
for (let i = 0, col = 0; i < row.childCount; i += 1) {
|
|
3249
|
+
const { colspan, colwidth } = row.child(i).attrs;
|
|
3250
|
+
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
3251
|
+
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
|
|
3252
|
+
const cssWidth = hasWidth ? `${hasWidth}px` : "";
|
|
3253
|
+
totalWidth += hasWidth || cellMinWidth;
|
|
3254
|
+
if (!hasWidth) {
|
|
3255
|
+
fixedWidth = false;
|
|
3256
|
+
}
|
|
3257
|
+
if (!nextDOM) {
|
|
3258
|
+
const colElement = document.createElement("col");
|
|
3259
|
+
const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
3260
|
+
colElement.style.setProperty(propertyKey, propertyValue);
|
|
3261
|
+
colgroup.appendChild(colElement);
|
|
3262
|
+
} else {
|
|
3263
|
+
if (nextDOM.style.width !== cssWidth) {
|
|
3264
|
+
const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
3265
|
+
nextDOM.style.setProperty(propertyKey, propertyValue);
|
|
3266
|
+
}
|
|
3267
|
+
nextDOM = nextDOM.nextSibling;
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
while (nextDOM) {
|
|
3273
|
+
const after = nextDOM.nextSibling;
|
|
3274
|
+
(_a = nextDOM.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(nextDOM);
|
|
3275
|
+
nextDOM = after;
|
|
3276
|
+
}
|
|
3277
|
+
if (fixedWidth) {
|
|
3278
|
+
table.style.width = `${totalWidth}px`;
|
|
3279
|
+
table.style.minWidth = "";
|
|
3280
|
+
} else {
|
|
3281
|
+
table.style.width = "";
|
|
3282
|
+
table.style.minWidth = `${totalWidth}px`;
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
var TableView = class {
|
|
3286
|
+
constructor(node, cellMinWidth) {
|
|
3287
|
+
this.node = node;
|
|
3288
|
+
this.cellMinWidth = cellMinWidth;
|
|
3289
|
+
this.dom = document.createElement("div");
|
|
3290
|
+
this.dom.className = "tableWrapper";
|
|
3291
|
+
this.table = this.dom.appendChild(document.createElement("table"));
|
|
3292
|
+
this.colgroup = this.table.appendChild(document.createElement("colgroup"));
|
|
3293
|
+
updateColumns(node, this.colgroup, this.table, cellMinWidth);
|
|
3294
|
+
this.contentDOM = this.table.appendChild(document.createElement("tbody"));
|
|
3295
|
+
}
|
|
3296
|
+
update(node) {
|
|
3297
|
+
if (node.type !== this.node.type) {
|
|
3298
|
+
return false;
|
|
3299
|
+
}
|
|
3300
|
+
this.node = node;
|
|
3301
|
+
updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
|
|
3302
|
+
return true;
|
|
3303
|
+
}
|
|
3304
|
+
ignoreMutation(mutation) {
|
|
3305
|
+
return mutation.type === "attributes" && (mutation.target === this.table || this.colgroup.contains(mutation.target));
|
|
3306
|
+
}
|
|
3307
|
+
};
|
|
3308
|
+
function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
|
|
3309
|
+
let totalWidth = 0;
|
|
3310
|
+
let fixedWidth = true;
|
|
3311
|
+
const cols = [];
|
|
3312
|
+
const row = node.firstChild;
|
|
3313
|
+
if (!row) {
|
|
3314
|
+
return {};
|
|
3315
|
+
}
|
|
3316
|
+
for (let i = 0, col = 0; i < row.childCount; i += 1) {
|
|
3317
|
+
const { colspan, colwidth } = row.child(i).attrs;
|
|
3318
|
+
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
3319
|
+
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
|
|
3320
|
+
totalWidth += hasWidth || cellMinWidth;
|
|
3321
|
+
if (!hasWidth) {
|
|
3322
|
+
fixedWidth = false;
|
|
3323
|
+
}
|
|
3324
|
+
const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth);
|
|
3325
|
+
cols.push([
|
|
3326
|
+
"col",
|
|
3327
|
+
{ style: `${property}: ${value}` }
|
|
3328
|
+
]);
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
const tableWidth = fixedWidth ? `${totalWidth}px` : "";
|
|
3332
|
+
const tableMinWidth = fixedWidth ? "" : `${totalWidth}px`;
|
|
3333
|
+
const colgroup = ["colgroup", {}, ...cols];
|
|
3334
|
+
return { colgroup, tableWidth, tableMinWidth };
|
|
3335
|
+
}
|
|
3336
|
+
function createCell(cellType, cellContent) {
|
|
3337
|
+
if (cellContent) {
|
|
3338
|
+
return cellType.createChecked(null, cellContent);
|
|
3339
|
+
}
|
|
3340
|
+
return cellType.createAndFill();
|
|
3341
|
+
}
|
|
3342
|
+
function getTableNodeTypes(schema) {
|
|
3343
|
+
if (schema.cached.tableNodeTypes) {
|
|
3344
|
+
return schema.cached.tableNodeTypes;
|
|
3345
|
+
}
|
|
3346
|
+
const roles = {};
|
|
3347
|
+
Object.keys(schema.nodes).forEach((type) => {
|
|
3348
|
+
const nodeType = schema.nodes[type];
|
|
3349
|
+
if (nodeType.spec.tableRole) {
|
|
3350
|
+
roles[nodeType.spec.tableRole] = nodeType;
|
|
3351
|
+
}
|
|
3352
|
+
});
|
|
3353
|
+
schema.cached.tableNodeTypes = roles;
|
|
3354
|
+
return roles;
|
|
3355
|
+
}
|
|
3356
|
+
function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
|
|
3357
|
+
const types = getTableNodeTypes(schema);
|
|
3358
|
+
const headerCells = [];
|
|
3359
|
+
const cells = [];
|
|
3360
|
+
for (let index = 0; index < colsCount; index += 1) {
|
|
3361
|
+
const cell = createCell(types.cell, cellContent);
|
|
3362
|
+
if (cell) {
|
|
3363
|
+
cells.push(cell);
|
|
3364
|
+
}
|
|
3365
|
+
if (withHeaderRow) {
|
|
3366
|
+
const headerCell = createCell(types.header_cell, cellContent);
|
|
3367
|
+
if (headerCell) {
|
|
3368
|
+
headerCells.push(headerCell);
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
const rows = [];
|
|
3373
|
+
for (let index = 0; index < rowsCount; index += 1) {
|
|
3374
|
+
rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
|
|
3375
|
+
}
|
|
3376
|
+
return types.table.createChecked(null, rows);
|
|
3377
|
+
}
|
|
3378
|
+
function isCellSelection(value) {
|
|
3379
|
+
return value instanceof CellSelection;
|
|
3380
|
+
}
|
|
3381
|
+
var deleteTableWhenAllCellsSelected = ({ editor }) => {
|
|
3382
|
+
const { selection } = editor.state;
|
|
3383
|
+
if (!isCellSelection(selection)) {
|
|
3384
|
+
return false;
|
|
3385
|
+
}
|
|
3386
|
+
let cellCount = 0;
|
|
3387
|
+
const table = findParentNodeClosestToPos(selection.ranges[0].$from, (node) => {
|
|
3388
|
+
return node.type.name === "table";
|
|
3389
|
+
});
|
|
3390
|
+
table === null || table === void 0 ? void 0 : table.node.descendants((node) => {
|
|
3391
|
+
if (node.type.name === "table") {
|
|
3392
|
+
return false;
|
|
3393
|
+
}
|
|
3394
|
+
if (["tableCell", "tableHeader"].includes(node.type.name)) {
|
|
3395
|
+
cellCount += 1;
|
|
3396
|
+
}
|
|
3397
|
+
});
|
|
3398
|
+
const allCellsSelected = cellCount === selection.ranges.length;
|
|
3399
|
+
if (!allCellsSelected) {
|
|
3400
|
+
return false;
|
|
3401
|
+
}
|
|
3402
|
+
editor.commands.deleteTable();
|
|
3403
|
+
return true;
|
|
3404
|
+
};
|
|
3405
|
+
var Table = Node16.create({
|
|
3406
|
+
name: "table",
|
|
3407
|
+
// @ts-ignore
|
|
3408
|
+
addOptions() {
|
|
3409
|
+
return {
|
|
3410
|
+
HTMLAttributes: {},
|
|
3411
|
+
resizable: false,
|
|
3412
|
+
renderWrapper: false,
|
|
3413
|
+
handleWidth: 5,
|
|
3414
|
+
cellMinWidth: 25,
|
|
3415
|
+
// TODO: fix
|
|
3416
|
+
View: TableView,
|
|
3417
|
+
lastColumnResizable: true,
|
|
3418
|
+
allowTableNodeSelection: false
|
|
3419
|
+
};
|
|
3420
|
+
},
|
|
3421
|
+
content: "tableRow+",
|
|
3422
|
+
tableRole: "table",
|
|
3423
|
+
isolating: true,
|
|
3424
|
+
group: "block",
|
|
3425
|
+
parseHTML() {
|
|
3426
|
+
return [{ tag: "table" }];
|
|
3427
|
+
},
|
|
3428
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
3429
|
+
const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth);
|
|
3430
|
+
const table = [
|
|
3431
|
+
"table",
|
|
3432
|
+
mergeAttributes21(this.options.HTMLAttributes, HTMLAttributes, {
|
|
3433
|
+
style: tableWidth ? `width: ${tableWidth}` : `min-width: ${tableMinWidth}`
|
|
3434
|
+
}),
|
|
3435
|
+
colgroup,
|
|
3436
|
+
["tbody", 0]
|
|
3437
|
+
];
|
|
3438
|
+
return this.options.renderWrapper ? ["div", { class: "tableWrapper" }, table] : table;
|
|
3439
|
+
},
|
|
3440
|
+
addCommands() {
|
|
3441
|
+
return {
|
|
3442
|
+
insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr: tr2, dispatch, editor }) => {
|
|
3443
|
+
const node = createTable(editor.schema, rows, cols, withHeaderRow);
|
|
3444
|
+
if (dispatch) {
|
|
3445
|
+
const offset = tr2.selection.from + 1;
|
|
3446
|
+
tr2.replaceSelectionWith(node).scrollIntoView().setSelection(TextSelection3.near(tr2.doc.resolve(offset)));
|
|
3447
|
+
}
|
|
3448
|
+
return true;
|
|
3449
|
+
},
|
|
3450
|
+
addColumnBefore: () => ({ state, dispatch }) => {
|
|
3451
|
+
return addColumnBefore(state, dispatch);
|
|
3452
|
+
},
|
|
3453
|
+
addColumnAfter: () => ({ state, dispatch }) => {
|
|
3454
|
+
return addColumnAfter(state, dispatch);
|
|
3455
|
+
},
|
|
3456
|
+
deleteColumn: () => ({ state, dispatch }) => {
|
|
3457
|
+
return deleteColumn(state, dispatch);
|
|
3458
|
+
},
|
|
3459
|
+
addRowBefore: () => ({ state, dispatch }) => {
|
|
3460
|
+
return addRowBefore(state, dispatch);
|
|
3461
|
+
},
|
|
3462
|
+
addRowAfter: () => ({ state, dispatch }) => {
|
|
3463
|
+
return addRowAfter(state, dispatch);
|
|
3464
|
+
},
|
|
3465
|
+
deleteRow: () => ({ state, dispatch }) => {
|
|
3466
|
+
return deleteRow(state, dispatch);
|
|
3467
|
+
},
|
|
3468
|
+
deleteTable: () => ({ state, dispatch }) => {
|
|
3469
|
+
return deleteTable(state, dispatch);
|
|
3470
|
+
},
|
|
3471
|
+
mergeCells: () => ({ state, dispatch }) => {
|
|
3472
|
+
return mergeCells(state, dispatch);
|
|
3473
|
+
},
|
|
3474
|
+
splitCell: () => ({ state, dispatch }) => {
|
|
3475
|
+
return splitCell(state, dispatch);
|
|
3476
|
+
},
|
|
3477
|
+
toggleHeaderColumn: () => ({ state, dispatch }) => {
|
|
3478
|
+
return toggleHeader("column")(state, dispatch);
|
|
3479
|
+
},
|
|
3480
|
+
toggleHeaderRow: () => ({ state, dispatch }) => {
|
|
3481
|
+
return toggleHeader("row")(state, dispatch);
|
|
3482
|
+
},
|
|
3483
|
+
toggleHeaderCell: () => ({ state, dispatch }) => {
|
|
3484
|
+
return toggleHeaderCell(state, dispatch);
|
|
3485
|
+
},
|
|
3486
|
+
mergeOrSplit: () => ({ state, dispatch }) => {
|
|
3487
|
+
if (mergeCells(state, dispatch)) {
|
|
3488
|
+
return true;
|
|
3489
|
+
}
|
|
3490
|
+
return splitCell(state, dispatch);
|
|
3491
|
+
},
|
|
3492
|
+
setCellAttribute: (name, value) => ({ state, dispatch }) => {
|
|
3493
|
+
return setCellAttr(name, value)(state, dispatch);
|
|
3494
|
+
},
|
|
3495
|
+
goToNextCell: () => ({ state, dispatch }) => {
|
|
3496
|
+
return goToNextCell(1)(state, dispatch);
|
|
3497
|
+
},
|
|
3498
|
+
goToPreviousCell: () => ({ state, dispatch }) => {
|
|
3499
|
+
return goToNextCell(-1)(state, dispatch);
|
|
3500
|
+
},
|
|
3501
|
+
fixTables: () => ({ state, dispatch }) => {
|
|
3502
|
+
if (dispatch) {
|
|
3503
|
+
fixTables(state);
|
|
3504
|
+
}
|
|
3505
|
+
return true;
|
|
3506
|
+
},
|
|
3507
|
+
setCellSelection: (position) => ({ tr: tr2, dispatch }) => {
|
|
3508
|
+
if (dispatch) {
|
|
3509
|
+
const selection = CellSelection.create(tr2.doc, position.anchorCell, position.headCell);
|
|
3510
|
+
tr2.setSelection(selection);
|
|
3511
|
+
}
|
|
3512
|
+
return true;
|
|
3513
|
+
}
|
|
3514
|
+
};
|
|
3515
|
+
},
|
|
3516
|
+
addKeyboardShortcuts() {
|
|
3517
|
+
return {
|
|
3518
|
+
Tab: () => {
|
|
3519
|
+
if (this.editor.commands.goToNextCell()) {
|
|
3520
|
+
return true;
|
|
3521
|
+
}
|
|
3522
|
+
if (!this.editor.can().addRowAfter()) {
|
|
3523
|
+
return false;
|
|
3524
|
+
}
|
|
3525
|
+
return this.editor.chain().addRowAfter().goToNextCell().run();
|
|
3526
|
+
},
|
|
3527
|
+
"Shift-Tab": () => this.editor.commands.goToPreviousCell(),
|
|
3528
|
+
Backspace: deleteTableWhenAllCellsSelected,
|
|
3529
|
+
"Mod-Backspace": deleteTableWhenAllCellsSelected,
|
|
3530
|
+
Delete: deleteTableWhenAllCellsSelected,
|
|
3531
|
+
"Mod-Delete": deleteTableWhenAllCellsSelected
|
|
3532
|
+
};
|
|
3533
|
+
},
|
|
3534
|
+
addProseMirrorPlugins() {
|
|
3535
|
+
const isResizable = this.options.resizable && this.editor.isEditable;
|
|
3536
|
+
return [
|
|
3537
|
+
...isResizable ? [
|
|
3538
|
+
columnResizing({
|
|
3539
|
+
handleWidth: this.options.handleWidth,
|
|
3540
|
+
cellMinWidth: this.options.cellMinWidth,
|
|
3541
|
+
defaultCellMinWidth: this.options.cellMinWidth,
|
|
3542
|
+
View: this.options.View,
|
|
3543
|
+
lastColumnResizable: this.options.lastColumnResizable
|
|
3544
|
+
})
|
|
3545
|
+
] : [],
|
|
3546
|
+
tableEditing({
|
|
3547
|
+
allowTableNodeSelection: this.options.allowTableNodeSelection
|
|
3548
|
+
})
|
|
3549
|
+
];
|
|
3550
|
+
},
|
|
3551
|
+
extendNodeSchema(extension) {
|
|
3552
|
+
const context = {
|
|
3553
|
+
name: extension.name,
|
|
3554
|
+
options: extension.options,
|
|
3555
|
+
storage: extension.storage
|
|
3556
|
+
};
|
|
3557
|
+
return {
|
|
3558
|
+
tableRole: callOrReturn2(getExtensionField2(extension, "tableRole", context))
|
|
3559
|
+
};
|
|
3560
|
+
}
|
|
3561
|
+
});
|
|
3562
|
+
|
|
3563
|
+
// ../../node_modules/.pnpm/@tiptap+extension-table-cell@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-table-cell/dist/index.js
|
|
3564
|
+
import { Node as Node17, mergeAttributes as mergeAttributes22 } from "@tiptap/core";
|
|
3565
|
+
var TableCell = Node17.create({
|
|
3566
|
+
name: "tableCell",
|
|
3567
|
+
addOptions() {
|
|
3568
|
+
return {
|
|
3569
|
+
HTMLAttributes: {}
|
|
3570
|
+
};
|
|
3571
|
+
},
|
|
3572
|
+
content: "block+",
|
|
3573
|
+
addAttributes() {
|
|
3574
|
+
return {
|
|
3575
|
+
colspan: {
|
|
3576
|
+
default: 1
|
|
3577
|
+
},
|
|
3578
|
+
rowspan: {
|
|
3579
|
+
default: 1
|
|
3580
|
+
},
|
|
3581
|
+
colwidth: {
|
|
3582
|
+
default: null,
|
|
3583
|
+
parseHTML: (element) => {
|
|
3584
|
+
const colwidth = element.getAttribute("colwidth");
|
|
3585
|
+
const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
|
|
3586
|
+
return value;
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
};
|
|
3590
|
+
},
|
|
3591
|
+
tableRole: "cell",
|
|
3592
|
+
isolating: true,
|
|
3593
|
+
parseHTML() {
|
|
3594
|
+
return [
|
|
3595
|
+
{ tag: "td" }
|
|
3596
|
+
];
|
|
3597
|
+
},
|
|
3598
|
+
renderHTML({ HTMLAttributes }) {
|
|
3599
|
+
return ["td", mergeAttributes22(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
3600
|
+
}
|
|
3601
|
+
});
|
|
3602
|
+
|
|
3603
|
+
// ../../node_modules/.pnpm/@tiptap+extension-table-header@2.27.2_@tiptap+core@2.27.2_@tiptap+pm@2.27.2_/node_modules/@tiptap/extension-table-header/dist/index.js
|
|
3604
|
+
import { Node as Node18, mergeAttributes as mergeAttributes23 } from "@tiptap/core";
|
|
3605
|
+
var TableHeader = Node18.create({
|
|
3606
|
+
name: "tableHeader",
|
|
3607
|
+
addOptions() {
|
|
3608
|
+
return {
|
|
3609
|
+
HTMLAttributes: {}
|
|
3610
|
+
};
|
|
3611
|
+
},
|
|
3612
|
+
content: "block+",
|
|
3613
|
+
addAttributes() {
|
|
3614
|
+
return {
|
|
3615
|
+
colspan: {
|
|
3616
|
+
default: 1
|
|
3617
|
+
},
|
|
3618
|
+
rowspan: {
|
|
3619
|
+
default: 1
|
|
3620
|
+
},
|
|
3621
|
+
colwidth: {
|
|
3622
|
+
default: null,
|
|
3623
|
+
parseHTML: (element) => {
|
|
3624
|
+
const colwidth = element.getAttribute("colwidth");
|
|
3625
|
+
const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
|
|
3626
|
+
return value;
|
|
3627
|
+
}
|
|
3628
|
+
}
|
|
3629
|
+
};
|
|
3630
|
+
},
|
|
3631
|
+
tableRole: "header_cell",
|
|
3632
|
+
isolating: true,
|
|
3633
|
+
parseHTML() {
|
|
3634
|
+
return [
|
|
3635
|
+
{ tag: "th" }
|
|
3636
|
+
];
|
|
3637
|
+
},
|
|
3638
|
+
renderHTML({ HTMLAttributes }) {
|
|
3639
|
+
return ["th", mergeAttributes23(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
3640
|
+
}
|
|
3641
|
+
});
|
|
3642
|
+
|
|
3643
|
+
// src/extensions/table-formatting.ts
|
|
3644
|
+
var TABLE_CELL_BACKGROUND_PRESETS = {
|
|
3645
|
+
none: null,
|
|
3646
|
+
gray: "#f3f4f6",
|
|
3647
|
+
yellow: "#fef3c7",
|
|
3648
|
+
blue: "#dbeafe",
|
|
3649
|
+
green: "#dcfce7",
|
|
3650
|
+
red: "#fee2e2"
|
|
3651
|
+
};
|
|
3652
|
+
var LoomaTable = Table.configure({
|
|
3653
|
+
resizable: true,
|
|
3654
|
+
lastColumnResizable: false
|
|
3655
|
+
});
|
|
3656
|
+
function normalizeTableCellAlignment(value) {
|
|
3657
|
+
if (value === "left" || value === "center" || value === "right") {
|
|
3658
|
+
return value;
|
|
3659
|
+
}
|
|
3660
|
+
return null;
|
|
3661
|
+
}
|
|
3662
|
+
function normalizeTableCellBackground(value) {
|
|
3663
|
+
if (typeof value !== "string") {
|
|
3664
|
+
return null;
|
|
3665
|
+
}
|
|
3666
|
+
const normalized = value.trim();
|
|
3667
|
+
return normalized.length > 0 ? normalized : null;
|
|
3668
|
+
}
|
|
3669
|
+
function renderTableCellStyle(attributes) {
|
|
3670
|
+
const styleFragments = [];
|
|
3671
|
+
const textAlign = normalizeTableCellAlignment(attributes.textAlign);
|
|
3672
|
+
const backgroundColor = normalizeTableCellBackground(attributes.backgroundColor);
|
|
3673
|
+
if (textAlign && textAlign !== "left") {
|
|
3674
|
+
styleFragments.push(`text-align: ${textAlign}`);
|
|
3675
|
+
}
|
|
3676
|
+
if (backgroundColor) {
|
|
3677
|
+
styleFragments.push(`background-color: ${backgroundColor}`);
|
|
3678
|
+
}
|
|
3679
|
+
return styleFragments.length > 0 ? `${styleFragments.join("; ")};` : null;
|
|
3680
|
+
}
|
|
3681
|
+
var tableAlignmentAttributes = {
|
|
3682
|
+
textAlign: {
|
|
3683
|
+
default: null,
|
|
3684
|
+
parseHTML: (element) => normalizeTableCellAlignment(element.style.textAlign),
|
|
3685
|
+
renderHTML: (attributes) => {
|
|
3686
|
+
const style = renderTableCellStyle(attributes);
|
|
3687
|
+
return style ? { style } : {};
|
|
3688
|
+
}
|
|
3689
|
+
},
|
|
3690
|
+
backgroundColor: {
|
|
3691
|
+
default: null,
|
|
3692
|
+
parseHTML: (element) => normalizeTableCellBackground(element.style.backgroundColor),
|
|
3693
|
+
renderHTML: (attributes) => {
|
|
3694
|
+
const style = renderTableCellStyle(attributes);
|
|
3695
|
+
return style ? { style } : {};
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
};
|
|
3699
|
+
var LoomaTableHeader = TableHeader.extend({
|
|
3700
|
+
addAttributes() {
|
|
3701
|
+
return {
|
|
3702
|
+
...this.parent?.(),
|
|
3703
|
+
...tableAlignmentAttributes
|
|
3704
|
+
};
|
|
3705
|
+
}
|
|
3706
|
+
});
|
|
3707
|
+
var LoomaTableCell = TableCell.extend({
|
|
3708
|
+
addAttributes() {
|
|
3709
|
+
return {
|
|
3710
|
+
...this.parent?.(),
|
|
3711
|
+
...tableAlignmentAttributes
|
|
3712
|
+
};
|
|
3713
|
+
}
|
|
3714
|
+
});
|
|
3715
|
+
function getActiveTableCellAlignment(editor) {
|
|
3716
|
+
const { $from } = editor.state.selection;
|
|
3717
|
+
for (let depth = $from.depth; depth > 0; depth -= 1) {
|
|
3718
|
+
const node = $from.node(depth);
|
|
3719
|
+
if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
|
|
3720
|
+
return normalizeTableCellAlignment(node.attrs.textAlign) ?? "left";
|
|
3721
|
+
}
|
|
3722
|
+
}
|
|
3723
|
+
return "left";
|
|
3724
|
+
}
|
|
3725
|
+
function getActiveTableCellBackground(editor) {
|
|
3726
|
+
const { $from } = editor.state.selection;
|
|
3727
|
+
for (let depth = $from.depth; depth > 0; depth -= 1) {
|
|
3728
|
+
const node = $from.node(depth);
|
|
3729
|
+
if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
|
|
3730
|
+
return normalizeTableCellBackground(node.attrs.backgroundColor);
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3733
|
+
return null;
|
|
3734
|
+
}
|
|
3735
|
+
function setActiveTableCellAlignment(editor, alignment) {
|
|
3736
|
+
const textAlign = alignment === "left" ? null : alignment;
|
|
3737
|
+
if (editor.isActive("tableHeader")) {
|
|
3738
|
+
return editor.chain().focus().updateAttributes("tableHeader", { textAlign }).run();
|
|
3739
|
+
}
|
|
3740
|
+
if (editor.isActive("tableCell")) {
|
|
3741
|
+
return editor.chain().focus().updateAttributes("tableCell", { textAlign }).run();
|
|
3742
|
+
}
|
|
3743
|
+
return false;
|
|
3744
|
+
}
|
|
3745
|
+
function setActiveTableCellBackground(editor, backgroundColor) {
|
|
3746
|
+
const normalizedBackgroundColor = normalizeTableCellBackground(backgroundColor);
|
|
3747
|
+
if (editor.isActive("tableHeader")) {
|
|
3748
|
+
return editor.chain().focus().updateAttributes("tableHeader", {
|
|
3749
|
+
backgroundColor: normalizedBackgroundColor
|
|
3750
|
+
}).run();
|
|
3751
|
+
}
|
|
3752
|
+
if (editor.isActive("tableCell")) {
|
|
3753
|
+
return editor.chain().focus().updateAttributes("tableCell", {
|
|
3754
|
+
backgroundColor: normalizedBackgroundColor
|
|
3755
|
+
}).run();
|
|
3756
|
+
}
|
|
3757
|
+
return false;
|
|
3758
|
+
}
|
|
3759
|
+
|
|
3760
|
+
// src/extensions/preset.ts
|
|
3761
|
+
function getDefaultEditorExtensions(options = {}) {
|
|
3762
|
+
const {
|
|
3763
|
+
placeholder = "Type \u201C/\u201D for commands, or start writing\u2026",
|
|
3764
|
+
linkOpenOnClick = false,
|
|
3765
|
+
imageInline = false
|
|
3766
|
+
} = options;
|
|
3767
|
+
return [
|
|
3768
|
+
Document,
|
|
3769
|
+
Paragraph,
|
|
3770
|
+
Text,
|
|
3771
|
+
Bold,
|
|
3772
|
+
Italic,
|
|
3773
|
+
Strike,
|
|
3774
|
+
Underline,
|
|
3775
|
+
Heading.configure({ levels: [1, 2, 3] }),
|
|
3776
|
+
BulletList,
|
|
3777
|
+
OrderedList,
|
|
3778
|
+
ListItem,
|
|
3779
|
+
TaskList,
|
|
3780
|
+
TaskItem.configure({ nested: false }),
|
|
3781
|
+
Blockquote,
|
|
3782
|
+
HorizontalRule,
|
|
3783
|
+
HardBreak,
|
|
3784
|
+
History,
|
|
3785
|
+
Dropcursor,
|
|
3786
|
+
Gapcursor,
|
|
3787
|
+
Link.configure({
|
|
3788
|
+
openOnClick: linkOpenOnClick,
|
|
3789
|
+
HTMLAttributes: { rel: "noopener noreferrer", target: "_blank" }
|
|
3790
|
+
}),
|
|
3791
|
+
Image.configure({ inline: imageInline }),
|
|
3792
|
+
Highlight.configure({ multicolor: false }),
|
|
3793
|
+
Code,
|
|
3794
|
+
CodeBlock,
|
|
3795
|
+
Typography,
|
|
3796
|
+
Placeholder.configure({
|
|
3797
|
+
placeholder: ({ node }) => node.type.name === "paragraph" ? placeholder : "",
|
|
3798
|
+
emptyNodeClass: "is-editor-empty"
|
|
3799
|
+
}),
|
|
3800
|
+
LoomaTable,
|
|
3801
|
+
TableRow,
|
|
3802
|
+
LoomaTableHeader,
|
|
3803
|
+
LoomaTableCell,
|
|
3804
|
+
LoomaListBehavior
|
|
3805
|
+
];
|
|
3806
|
+
}
|
|
3807
|
+
|
|
3808
|
+
// src/extensions/table-commands.ts
|
|
3809
|
+
import { TableMap } from "@tiptap/pm/tables";
|
|
3810
|
+
function arrayEquals(left, right) {
|
|
3811
|
+
if (!left || left.length !== right.length) {
|
|
3812
|
+
return false;
|
|
3813
|
+
}
|
|
3814
|
+
return left.every((value, index) => value === right[index]);
|
|
3815
|
+
}
|
|
3816
|
+
function readRenderedColumnWidths(tableElement) {
|
|
3817
|
+
const colElements = Array.from(tableElement.querySelectorAll("colgroup col"));
|
|
3818
|
+
if (colElements.length > 0) {
|
|
3819
|
+
return colElements.map((column) => Math.max(1, Math.round(column.getBoundingClientRect().width)));
|
|
3820
|
+
}
|
|
3821
|
+
const firstRow = tableElement.rows.item(0);
|
|
3822
|
+
if (!firstRow) {
|
|
3823
|
+
return [];
|
|
3824
|
+
}
|
|
3825
|
+
return Array.from(firstRow.cells).map((cell) => Math.max(1, Math.round(cell.getBoundingClientRect().width)));
|
|
3826
|
+
}
|
|
3827
|
+
function distributeWidthDelta(widths, availableWidth, minWidth) {
|
|
3828
|
+
const normalized = [...widths];
|
|
3829
|
+
let delta = availableWidth - normalized.reduce((sum, width) => sum + width, 0);
|
|
3830
|
+
while (delta !== 0) {
|
|
3831
|
+
const adjustableIndices = normalized.map((width, index) => ({ width, index })).filter(({ width }) => delta > 0 || width > minWidth).sort((left, right) => {
|
|
3832
|
+
if (delta > 0) {
|
|
3833
|
+
return left.width - right.width;
|
|
3834
|
+
}
|
|
3835
|
+
return right.width - left.width;
|
|
3836
|
+
});
|
|
3837
|
+
if (adjustableIndices.length === 0) {
|
|
3838
|
+
break;
|
|
3839
|
+
}
|
|
3840
|
+
for (const { index } of adjustableIndices) {
|
|
3841
|
+
if (delta === 0) {
|
|
3842
|
+
break;
|
|
3843
|
+
}
|
|
3844
|
+
const currentWidth = normalized[index];
|
|
3845
|
+
if (currentWidth === void 0) {
|
|
3846
|
+
continue;
|
|
3847
|
+
}
|
|
3848
|
+
if (delta > 0) {
|
|
3849
|
+
normalized[index] = currentWidth + 1;
|
|
3850
|
+
delta -= 1;
|
|
3851
|
+
continue;
|
|
3852
|
+
}
|
|
3853
|
+
if (currentWidth <= minWidth) {
|
|
3854
|
+
continue;
|
|
3855
|
+
}
|
|
3856
|
+
normalized[index] = currentWidth - 1;
|
|
3857
|
+
delta += 1;
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3860
|
+
return normalized;
|
|
3861
|
+
}
|
|
3862
|
+
function normalizeColumnWidths(widths, availableWidth, minWidth) {
|
|
3863
|
+
if (widths.length === 0 || availableWidth <= 0) {
|
|
3864
|
+
return widths;
|
|
3865
|
+
}
|
|
3866
|
+
const totalWidth = widths.reduce((sum, width) => sum + width, 0);
|
|
3867
|
+
if (totalWidth <= 0) {
|
|
3868
|
+
return widths;
|
|
3869
|
+
}
|
|
3870
|
+
const scaled = widths.map(
|
|
3871
|
+
(width) => Math.max(minWidth, Math.round(width / totalWidth * availableWidth))
|
|
3872
|
+
);
|
|
3873
|
+
return distributeWidthDelta(scaled, availableWidth, minWidth);
|
|
3874
|
+
}
|
|
3875
|
+
function getTextPositionInCell(tablePos, table, rowIndex, colIndex) {
|
|
3876
|
+
let pos = tablePos + 1;
|
|
3877
|
+
for (let r = 0; r < rowIndex; r++) {
|
|
3878
|
+
pos += table.child(r).nodeSize;
|
|
3879
|
+
}
|
|
3880
|
+
const row = table.child(rowIndex);
|
|
3881
|
+
for (let c = 0; c < colIndex; c++) {
|
|
3882
|
+
pos += row.child(c).nodeSize;
|
|
3883
|
+
}
|
|
3884
|
+
return pos + 3;
|
|
3885
|
+
}
|
|
3886
|
+
function findTable(editor) {
|
|
3887
|
+
const { $from } = editor.state.selection;
|
|
3888
|
+
for (let d = $from.depth; d > 0; d--) {
|
|
3889
|
+
const node = $from.node(d);
|
|
3890
|
+
if (node.type.name === "table") {
|
|
3891
|
+
return { pos: $from.before(d), node };
|
|
3892
|
+
}
|
|
3893
|
+
}
|
|
3894
|
+
return null;
|
|
3895
|
+
}
|
|
3896
|
+
function insertTableAtRange(editor, range, options = {}) {
|
|
3897
|
+
const rows = Math.min(10, Math.max(1, options.rows ?? 3));
|
|
3898
|
+
const cols = Math.min(10, Math.max(1, options.cols ?? 3));
|
|
3899
|
+
const withHeaderRow = options.withHeaderRow ?? true;
|
|
3900
|
+
return editor.chain().focus().deleteRange(range).insertTable({ rows, cols, withHeaderRow }).run();
|
|
3901
|
+
}
|
|
3902
|
+
function normalizeActiveTableColumnWidths(editor, tableElement, minWidth = 25) {
|
|
3903
|
+
const tableInfo = findTable(editor);
|
|
3904
|
+
if (!tableInfo) {
|
|
3905
|
+
return false;
|
|
3906
|
+
}
|
|
3907
|
+
const renderedColumnWidths = readRenderedColumnWidths(tableElement);
|
|
3908
|
+
if (renderedColumnWidths.length === 0) {
|
|
3909
|
+
return false;
|
|
3910
|
+
}
|
|
3911
|
+
const availableWidth = Math.max(1, Math.round(tableElement.getBoundingClientRect().width));
|
|
3912
|
+
const normalizedColumnWidths = normalizeColumnWidths(
|
|
3913
|
+
renderedColumnWidths,
|
|
3914
|
+
availableWidth,
|
|
3915
|
+
minWidth
|
|
3916
|
+
);
|
|
3917
|
+
const { pos: tablePos, node: table } = tableInfo;
|
|
3918
|
+
const map = TableMap.get(table);
|
|
3919
|
+
const tableStart = tablePos + 1;
|
|
3920
|
+
let tr2 = editor.state.tr;
|
|
3921
|
+
let changed = false;
|
|
3922
|
+
for (let row = 0; row < map.height; row += 1) {
|
|
3923
|
+
for (let col = 0; col < map.width; col += 1) {
|
|
3924
|
+
const mapIndex = row * map.width + col;
|
|
3925
|
+
const cellPos = map.map[mapIndex];
|
|
3926
|
+
if (cellPos === void 0) {
|
|
3927
|
+
continue;
|
|
3928
|
+
}
|
|
3929
|
+
if (col > 0 && map.map[mapIndex - 1] === cellPos || row > 0 && map.map[mapIndex - map.width] === cellPos) {
|
|
3930
|
+
continue;
|
|
3931
|
+
}
|
|
3932
|
+
const cellNode = table.nodeAt(cellPos);
|
|
3933
|
+
if (!cellNode) {
|
|
3934
|
+
continue;
|
|
3935
|
+
}
|
|
3936
|
+
const startCol = map.colCount(cellPos);
|
|
3937
|
+
const cellWidths = normalizedColumnWidths.slice(startCol, startCol + cellNode.attrs.colspan);
|
|
3938
|
+
if (cellWidths.length !== cellNode.attrs.colspan || arrayEquals(cellNode.attrs.colwidth, cellWidths)) {
|
|
3939
|
+
continue;
|
|
3940
|
+
}
|
|
3941
|
+
tr2 = tr2.setNodeMarkup(tableStart + cellPos, null, {
|
|
3942
|
+
...cellNode.attrs,
|
|
3943
|
+
colwidth: cellWidths
|
|
3944
|
+
});
|
|
3945
|
+
changed = true;
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
if (changed) {
|
|
3949
|
+
editor.view.dispatch(tr2);
|
|
3950
|
+
}
|
|
3951
|
+
return changed;
|
|
3952
|
+
}
|
|
3953
|
+
function handleTableOverlayAction(editor, detail) {
|
|
3954
|
+
const tableInfo = findTable(editor);
|
|
3955
|
+
if (!tableInfo) return false;
|
|
3956
|
+
const { action, boundaryIndex } = detail;
|
|
3957
|
+
const { pos: tablePos, node: table } = tableInfo;
|
|
3958
|
+
const rows = table.childCount;
|
|
3959
|
+
const cols = rows > 0 ? table.child(0).childCount : 0;
|
|
3960
|
+
let cellPos;
|
|
3961
|
+
let command;
|
|
3962
|
+
switch (action) {
|
|
3963
|
+
case "add-row-before": {
|
|
3964
|
+
const rowIndex = Math.min(boundaryIndex, rows - 1);
|
|
3965
|
+
if (rowIndex < 0) return false;
|
|
3966
|
+
cellPos = getTextPositionInCell(tablePos, table, rowIndex, 0);
|
|
3967
|
+
command = () => editor.chain().focus().setTextSelection(cellPos).addRowBefore().run();
|
|
3968
|
+
break;
|
|
3969
|
+
}
|
|
3970
|
+
case "add-row-after": {
|
|
3971
|
+
const rowIndex = Math.min(boundaryIndex, rows - 1);
|
|
3972
|
+
if (rowIndex < 0) return false;
|
|
3973
|
+
cellPos = getTextPositionInCell(tablePos, table, rowIndex, 0);
|
|
3974
|
+
command = () => editor.chain().focus().setTextSelection(cellPos).addRowAfter().run();
|
|
3975
|
+
break;
|
|
3976
|
+
}
|
|
3977
|
+
case "add-column-before": {
|
|
3978
|
+
const colIndex = Math.min(boundaryIndex, cols - 1);
|
|
3979
|
+
if (colIndex < 0) return false;
|
|
3980
|
+
cellPos = getTextPositionInCell(tablePos, table, 0, colIndex);
|
|
3981
|
+
command = () => editor.chain().focus().setTextSelection(cellPos).addColumnBefore().run();
|
|
3982
|
+
break;
|
|
3983
|
+
}
|
|
3984
|
+
case "add-column-after": {
|
|
3985
|
+
const colIndex = Math.min(boundaryIndex, cols - 1);
|
|
3986
|
+
if (colIndex < 0) return false;
|
|
3987
|
+
cellPos = getTextPositionInCell(tablePos, table, 0, colIndex);
|
|
3988
|
+
command = () => editor.chain().focus().setTextSelection(cellPos).addColumnAfter().run();
|
|
3989
|
+
break;
|
|
3990
|
+
}
|
|
3991
|
+
default:
|
|
3992
|
+
return false;
|
|
3993
|
+
}
|
|
3994
|
+
return command();
|
|
3995
|
+
}
|
|
3996
|
+
|
|
3997
|
+
export {
|
|
3998
|
+
TABLE_CELL_BACKGROUND_PRESETS,
|
|
3999
|
+
LoomaTable,
|
|
4000
|
+
LoomaTableHeader,
|
|
4001
|
+
LoomaTableCell,
|
|
4002
|
+
getActiveTableCellAlignment,
|
|
4003
|
+
getActiveTableCellBackground,
|
|
4004
|
+
setActiveTableCellAlignment,
|
|
4005
|
+
setActiveTableCellBackground,
|
|
4006
|
+
getDefaultEditorExtensions,
|
|
4007
|
+
insertTableAtRange,
|
|
4008
|
+
normalizeActiveTableColumnWidths,
|
|
4009
|
+
handleTableOverlayAction
|
|
4010
|
+
};
|