@cyberyozh/text-editor 0.5.2 → 0.5.4
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/dist/editor.d.mts +11 -0
- package/dist/editor.d.ts +11 -0
- package/dist/editor.js +93 -38
- package/dist/editor.js.map +1 -1
- package/dist/editor.mjs +93 -38
- package/dist/editor.mjs.map +1 -1
- package/dist/html.d.mts +28 -0
- package/dist/html.d.ts +28 -0
- package/dist/html.js +2803 -0
- package/dist/html.js.map +1 -0
- package/dist/html.mjs +2771 -0
- package/dist/html.mjs.map +1 -0
- package/dist/render.d.mts +5 -0
- package/dist/render.d.ts +5 -0
- package/dist/render.js +47 -40
- package/dist/render.js.map +1 -1
- package/dist/render.mjs +47 -40
- package/dist/render.mjs.map +1 -1
- package/package.json +9 -3
- package/src/editor/editor.tsx +8 -0
- package/src/extensions/base/code-block.test.ts +39 -0
- package/src/extensions/base/code-block.ts +15 -1
- package/src/extensions/base/link.test.ts +54 -1
- package/src/extensions/base/link.ts +47 -41
- package/src/extensions/editor/get-editor-extensions.ts +3 -1
- package/src/extensions/render/get-render-extensions.ts +6 -3
- package/src/html/html.test.ts +154 -0
- package/src/html/index.ts +29 -0
- package/src/utils/get-shared-extensions.ts +9 -1
- package/src/utils/html-to-tiptap-content.ts +5 -13
package/dist/html.js
ADDED
|
@@ -0,0 +1,2803 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/html/index.ts
|
|
31
|
+
var html_exports = {};
|
|
32
|
+
__export(html_exports, {
|
|
33
|
+
htmlToTiptapContent: () => htmlToTiptapContent,
|
|
34
|
+
tiptapContentToHtml: () => tiptapContentToHtml
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(html_exports);
|
|
37
|
+
var import_server = require("@tiptap/html/server");
|
|
38
|
+
|
|
39
|
+
// src/extensions/render/get-render-extensions.ts
|
|
40
|
+
var import_extension_mathematics = require("@tiptap/extension-mathematics");
|
|
41
|
+
var import_extension_table = require("@tiptap/extension-table");
|
|
42
|
+
|
|
43
|
+
// src/utils/handle-exit-node.ts
|
|
44
|
+
var import_state = require("@tiptap/pm/state");
|
|
45
|
+
function handleExitNode(editor, nodeName) {
|
|
46
|
+
const { view, schema } = editor;
|
|
47
|
+
const { state } = view;
|
|
48
|
+
const { selection } = state;
|
|
49
|
+
const $pos = selection.$from;
|
|
50
|
+
const currentNode = $pos.node();
|
|
51
|
+
let depth = $pos.depth;
|
|
52
|
+
let isInsideTargetNode = false;
|
|
53
|
+
let targetNodeDepth = 0;
|
|
54
|
+
while (depth > 0) {
|
|
55
|
+
const parentNode = $pos.node(depth);
|
|
56
|
+
if (parentNode.type.name === nodeName) {
|
|
57
|
+
isInsideTargetNode = true;
|
|
58
|
+
targetNodeDepth = depth;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
depth--;
|
|
62
|
+
}
|
|
63
|
+
const isCurrentNodeEmptyParagraph = currentNode.type.name === "paragraph" && currentNode.content.size === 0;
|
|
64
|
+
if (!isInsideTargetNode || !isCurrentNodeEmptyParagraph) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const { tr: tr2 } = state;
|
|
68
|
+
const posAfterTargetNode = $pos.after(targetNodeDepth);
|
|
69
|
+
const targetNode = $pos.node(targetNodeDepth);
|
|
70
|
+
let newPosAfterTargetNode = posAfterTargetNode;
|
|
71
|
+
if (targetNode.childCount > 1) {
|
|
72
|
+
const emptyParagraphStart = $pos.before();
|
|
73
|
+
const emptyParagraphEnd = $pos.after();
|
|
74
|
+
const deletionLength = emptyParagraphEnd - emptyParagraphStart;
|
|
75
|
+
tr2.delete(emptyParagraphStart, emptyParagraphEnd);
|
|
76
|
+
newPosAfterTargetNode = posAfterTargetNode - deletionLength;
|
|
77
|
+
}
|
|
78
|
+
const paragraphNode = schema.nodes.paragraph.createAndFill();
|
|
79
|
+
if (!paragraphNode) return false;
|
|
80
|
+
tr2.insert(newPosAfterTargetNode, paragraphNode);
|
|
81
|
+
tr2.setSelection(import_state.TextSelection.create(tr2.doc, newPosAfterTargetNode + 1));
|
|
82
|
+
view.dispatch(tr2);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/utils/migrate-legacy-callouts.ts
|
|
87
|
+
var legacyTypeMap = {
|
|
88
|
+
question: "info",
|
|
89
|
+
idea: "warning",
|
|
90
|
+
info: "success",
|
|
91
|
+
error: "error"
|
|
92
|
+
};
|
|
93
|
+
function migrateLegacyCallouts(editor) {
|
|
94
|
+
const { doc, schema } = editor.state;
|
|
95
|
+
const calloutsToMigrate = [];
|
|
96
|
+
doc.descendants((node, pos) => {
|
|
97
|
+
if (node.type.name === "callout" && node.attrs.calloutType) {
|
|
98
|
+
calloutsToMigrate.push({ node, pos });
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (calloutsToMigrate.length === 0) return;
|
|
102
|
+
const tr2 = editor.state.tr;
|
|
103
|
+
calloutsToMigrate.sort((a, b) => b.pos - a.pos);
|
|
104
|
+
for (const { node, pos } of calloutsToMigrate) {
|
|
105
|
+
const oldType = node.attrs.calloutType;
|
|
106
|
+
const newType = legacyTypeMap[oldType] || oldType;
|
|
107
|
+
const hasInlineContent = node.content.size > 0 && !node.firstChild?.isBlock;
|
|
108
|
+
if (hasInlineContent) {
|
|
109
|
+
const paragraph = schema.nodes.paragraph?.create(null, node.content);
|
|
110
|
+
const newContent = paragraph ? [paragraph] : [];
|
|
111
|
+
tr2.replaceRangeWith(
|
|
112
|
+
pos,
|
|
113
|
+
pos + node.nodeSize,
|
|
114
|
+
schema.nodes.callout.create(
|
|
115
|
+
{
|
|
116
|
+
type: newType,
|
|
117
|
+
calloutType: null,
|
|
118
|
+
callout: null
|
|
119
|
+
},
|
|
120
|
+
newContent
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
} else {
|
|
124
|
+
tr2.setNodeMarkup(pos, void 0, {
|
|
125
|
+
...node.attrs,
|
|
126
|
+
type: newType,
|
|
127
|
+
calloutType: null,
|
|
128
|
+
callout: null
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
editor.view.dispatch(tr2);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/extensions/base/callout.ts
|
|
136
|
+
var import_core = require("@tiptap/core");
|
|
137
|
+
var legacyTypeMap2 = {
|
|
138
|
+
question: "info",
|
|
139
|
+
idea: "warning",
|
|
140
|
+
info: "success",
|
|
141
|
+
error: "error"
|
|
142
|
+
};
|
|
143
|
+
var BaseCallout = import_core.Node.create({
|
|
144
|
+
name: "callout",
|
|
145
|
+
group: "block",
|
|
146
|
+
content: "block+",
|
|
147
|
+
draggable: true,
|
|
148
|
+
isolating: true,
|
|
149
|
+
addAttributes() {
|
|
150
|
+
return {
|
|
151
|
+
type: {
|
|
152
|
+
default: "info",
|
|
153
|
+
parseHTML: (element) => {
|
|
154
|
+
if (typeof element === "string") return "info";
|
|
155
|
+
const dataCallout = element.getAttribute("data-callout");
|
|
156
|
+
if (dataCallout) {
|
|
157
|
+
return dataCallout;
|
|
158
|
+
}
|
|
159
|
+
const legacyType = element.getAttribute("calloutType");
|
|
160
|
+
if (legacyType) {
|
|
161
|
+
return legacyTypeMap2[legacyType];
|
|
162
|
+
}
|
|
163
|
+
if (element.classList) {
|
|
164
|
+
if (element.classList.contains("callout--error")) return "error";
|
|
165
|
+
if (element.classList.contains("callout--question")) return "info";
|
|
166
|
+
if (element.classList.contains("callout--idea")) return "warning";
|
|
167
|
+
if (element.classList.contains("callout--info")) return "success";
|
|
168
|
+
}
|
|
169
|
+
return "info";
|
|
170
|
+
},
|
|
171
|
+
renderHTML: (attributes) => {
|
|
172
|
+
return {
|
|
173
|
+
"data-callout": attributes.type
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
bgColor: {
|
|
178
|
+
default: null,
|
|
179
|
+
parseHTML: (element) => {
|
|
180
|
+
if (typeof element === "string") return null;
|
|
181
|
+
return element.getAttribute("data-bg-color");
|
|
182
|
+
},
|
|
183
|
+
renderHTML: (attributes) => {
|
|
184
|
+
if (!attributes.bgColor) return {};
|
|
185
|
+
return {
|
|
186
|
+
"data-bg-color": attributes.bgColor
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
emoji: {
|
|
191
|
+
default: null,
|
|
192
|
+
parseHTML: (element) => {
|
|
193
|
+
if (typeof element === "string") return null;
|
|
194
|
+
return element.getAttribute("data-emoji");
|
|
195
|
+
},
|
|
196
|
+
renderHTML: (attributes) => {
|
|
197
|
+
if (!attributes.emoji) return {};
|
|
198
|
+
return {
|
|
199
|
+
"data-emoji": attributes.emoji
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
calloutType: {
|
|
204
|
+
default: null,
|
|
205
|
+
parseHTML: (element) => element.getAttribute("calloutType"),
|
|
206
|
+
renderHTML: () => ({})
|
|
207
|
+
},
|
|
208
|
+
callout: {
|
|
209
|
+
default: null,
|
|
210
|
+
parseHTML: (element) => element.getAttribute("callout"),
|
|
211
|
+
renderHTML: () => ({})
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
onCreate() {
|
|
216
|
+
migrateLegacyCallouts(this.editor);
|
|
217
|
+
},
|
|
218
|
+
addKeyboardShortcuts() {
|
|
219
|
+
return {
|
|
220
|
+
Enter: () => handleExitNode(this.editor, this.name)
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
parseHTML() {
|
|
224
|
+
return [
|
|
225
|
+
{
|
|
226
|
+
tag: "div[data-callout]"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
tag: "callout",
|
|
230
|
+
priority: 51
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
tag: "div",
|
|
234
|
+
priority: 50,
|
|
235
|
+
getAttrs: (element) => {
|
|
236
|
+
if (typeof element === "string") return false;
|
|
237
|
+
if (element.classList.contains("callout") || element.classList.contains("callout--error") || element.classList.contains("callout--question") || element.classList.contains("callout--idea") || element.classList.contains("callout--info")) {
|
|
238
|
+
return {};
|
|
239
|
+
}
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
];
|
|
244
|
+
},
|
|
245
|
+
renderHTML({ HTMLAttributes }) {
|
|
246
|
+
return ["div", (0, import_core.mergeAttributes)(HTMLAttributes), 0];
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// src/extensions/base/code-block.ts
|
|
251
|
+
var import_extension_code_block_lowlight = require("@tiptap/extension-code-block-lowlight");
|
|
252
|
+
var import_xml = __toESM(require("highlight.js/lib/languages/xml"));
|
|
253
|
+
var import_lowlight = require("lowlight");
|
|
254
|
+
var lowlight = (0, import_lowlight.createLowlight)(import_lowlight.common);
|
|
255
|
+
lowlight.register("html", import_xml.default);
|
|
256
|
+
function languageFromClass(code, prefix) {
|
|
257
|
+
const languageClass = Array.from(code?.classList ?? []).find(
|
|
258
|
+
(className) => className.startsWith(prefix)
|
|
259
|
+
);
|
|
260
|
+
return languageClass ? languageClass.slice(prefix.length) : null;
|
|
261
|
+
}
|
|
262
|
+
var BaseCodeBlock = import_extension_code_block_lowlight.CodeBlockLowlight.configure({
|
|
263
|
+
lowlight
|
|
264
|
+
}).extend({
|
|
265
|
+
selectable: false,
|
|
266
|
+
draggable: true,
|
|
267
|
+
addAttributes() {
|
|
268
|
+
const { languageClassPrefix } = this.options;
|
|
269
|
+
return {
|
|
270
|
+
language: {
|
|
271
|
+
default: null,
|
|
272
|
+
rendered: false,
|
|
273
|
+
parseHTML: (element) => {
|
|
274
|
+
const code = element.querySelector("code");
|
|
275
|
+
const fromClass = languageClassPrefix ? languageFromClass(code, languageClassPrefix) : null;
|
|
276
|
+
return fromClass || code?.getAttribute("data-language") || "bash";
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// src/extensions/base/copyable-text.ts
|
|
284
|
+
var import_core2 = require("@tiptap/core");
|
|
285
|
+
var CopyableText = import_core2.Mark.create({
|
|
286
|
+
name: "copyable-text",
|
|
287
|
+
addOptions() {
|
|
288
|
+
return {
|
|
289
|
+
HTMLAttributes: {
|
|
290
|
+
class: "copyable"
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
},
|
|
294
|
+
parseHTML() {
|
|
295
|
+
return [
|
|
296
|
+
{
|
|
297
|
+
tag: "span",
|
|
298
|
+
getAttrs: (element) => element.classList.contains("copyable") ? {} : false
|
|
299
|
+
}
|
|
300
|
+
];
|
|
301
|
+
},
|
|
302
|
+
renderHTML({ HTMLAttributes }) {
|
|
303
|
+
return ["span", (0, import_core2.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
304
|
+
},
|
|
305
|
+
addCommands() {
|
|
306
|
+
return {
|
|
307
|
+
setCopyable: (attributes) => ({ commands }) => {
|
|
308
|
+
return commands.setMark(this.name, attributes);
|
|
309
|
+
},
|
|
310
|
+
toggleCopyable: (attributes) => ({ commands }) => {
|
|
311
|
+
return commands.toggleMark(this.name, attributes);
|
|
312
|
+
},
|
|
313
|
+
unsetCopyable: () => ({ commands }) => {
|
|
314
|
+
return commands.unsetMark(this.name);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// src/extensions/base/custom-quote.ts
|
|
321
|
+
var import_core3 = require("@tiptap/core");
|
|
322
|
+
var import_state2 = require("@tiptap/pm/state");
|
|
323
|
+
var BaseCustomQuote = import_core3.Node.create({
|
|
324
|
+
name: "customQuote",
|
|
325
|
+
group: "block",
|
|
326
|
+
content: "customQuoteText customQuoteAuthor customQuoteSign",
|
|
327
|
+
selectable: false,
|
|
328
|
+
draggable: true,
|
|
329
|
+
isolating: true,
|
|
330
|
+
addKeyboardShortcuts() {
|
|
331
|
+
return {
|
|
332
|
+
Enter: () => {
|
|
333
|
+
const { view, schema } = this.editor;
|
|
334
|
+
const { state } = view;
|
|
335
|
+
const { selection } = state;
|
|
336
|
+
const $pos = selection.$from;
|
|
337
|
+
let depth = $pos.depth;
|
|
338
|
+
let isInsideCustomQuote = false;
|
|
339
|
+
while (depth > 0) {
|
|
340
|
+
const parentNode = $pos.node(depth);
|
|
341
|
+
if (parentNode.type.name === this.name) {
|
|
342
|
+
isInsideCustomQuote = true;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
depth--;
|
|
346
|
+
}
|
|
347
|
+
if (!isInsideCustomQuote) {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
const { tr: tr2 } = state;
|
|
351
|
+
const posAfter = $pos.after(depth);
|
|
352
|
+
const paragraphNode = schema.nodes.paragraph.createAndFill();
|
|
353
|
+
if (!paragraphNode) return false;
|
|
354
|
+
tr2.insert(posAfter, paragraphNode);
|
|
355
|
+
tr2.setSelection(import_state2.TextSelection.create(tr2.doc, posAfter + 1));
|
|
356
|
+
view.dispatch(tr2);
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
},
|
|
361
|
+
parseHTML() {
|
|
362
|
+
return [
|
|
363
|
+
{
|
|
364
|
+
tag: "div[data-custom-quote]"
|
|
365
|
+
}
|
|
366
|
+
];
|
|
367
|
+
},
|
|
368
|
+
renderHTML({ HTMLAttributes }) {
|
|
369
|
+
return ["div", (0, import_core3.mergeAttributes)(HTMLAttributes, { "data-custom-quote": "" }), 0];
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
var BaseCustomQuoteText = import_core3.Node.create({
|
|
373
|
+
name: "customQuoteText",
|
|
374
|
+
group: "block",
|
|
375
|
+
content: "inline*",
|
|
376
|
+
draggable: false,
|
|
377
|
+
selectable: true,
|
|
378
|
+
addAttributes() {
|
|
379
|
+
return {
|
|
380
|
+
open: {
|
|
381
|
+
default: true
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
},
|
|
385
|
+
addKeyboardShortcuts() {
|
|
386
|
+
return {
|
|
387
|
+
Enter: () => {
|
|
388
|
+
const { view, state } = this.editor;
|
|
389
|
+
const { tr: tr2, selection } = state;
|
|
390
|
+
const { $from } = selection;
|
|
391
|
+
if ($from.parent.type.name !== "customQuoteText") {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
const posAfter = $from.after();
|
|
395
|
+
const nextNode = state.doc.nodeAt(posAfter);
|
|
396
|
+
if (!nextNode || nextNode.type.name !== "customQuoteAuthor") return false;
|
|
397
|
+
const nextNodeEnd = posAfter + nextNode.nodeSize - 1;
|
|
398
|
+
tr2.setSelection(import_state2.TextSelection.create(tr2.doc, nextNodeEnd));
|
|
399
|
+
view.dispatch(tr2);
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
},
|
|
404
|
+
parseHTML() {
|
|
405
|
+
return [
|
|
406
|
+
{
|
|
407
|
+
tag: "div[data-custom-quote-text]"
|
|
408
|
+
}
|
|
409
|
+
];
|
|
410
|
+
},
|
|
411
|
+
renderHTML({ HTMLAttributes }) {
|
|
412
|
+
return ["div", (0, import_core3.mergeAttributes)(HTMLAttributes, { "data-custom-quote-text": "" }), 0];
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
var BaseCustomQuoteAuthor = import_core3.Node.create({
|
|
416
|
+
name: "customQuoteAuthor",
|
|
417
|
+
group: "block",
|
|
418
|
+
content: "inline*",
|
|
419
|
+
selectable: true,
|
|
420
|
+
addKeyboardShortcuts() {
|
|
421
|
+
return {
|
|
422
|
+
Enter: () => {
|
|
423
|
+
const { view, state } = this.editor;
|
|
424
|
+
const { tr: tr2, selection } = state;
|
|
425
|
+
const { $from } = selection;
|
|
426
|
+
if ($from.parent.type.name !== "customQuoteAuthor") {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
const posAfter = $from.after();
|
|
430
|
+
const nextNode = state.doc.nodeAt(posAfter);
|
|
431
|
+
if (!nextNode || nextNode.type.name !== "customQuoteSign") return false;
|
|
432
|
+
const nextNodeEnd = posAfter + nextNode.nodeSize - 1;
|
|
433
|
+
tr2.setSelection(import_state2.TextSelection.create(tr2.doc, nextNodeEnd));
|
|
434
|
+
view.dispatch(tr2);
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
},
|
|
439
|
+
parseHTML() {
|
|
440
|
+
return [
|
|
441
|
+
{
|
|
442
|
+
tag: "div[data-custom-quote-author]"
|
|
443
|
+
}
|
|
444
|
+
];
|
|
445
|
+
},
|
|
446
|
+
renderHTML({ HTMLAttributes }) {
|
|
447
|
+
return ["div", (0, import_core3.mergeAttributes)(HTMLAttributes, { "data-custom-quote-author": "" }), 0];
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
var BaseCustomQuoteSign = import_core3.Node.create({
|
|
451
|
+
name: "customQuoteSign",
|
|
452
|
+
group: "block",
|
|
453
|
+
content: "inline*",
|
|
454
|
+
selectable: true,
|
|
455
|
+
parseHTML() {
|
|
456
|
+
return [
|
|
457
|
+
{
|
|
458
|
+
tag: "div[data-custom-quote-sign]"
|
|
459
|
+
}
|
|
460
|
+
];
|
|
461
|
+
},
|
|
462
|
+
renderHTML({ HTMLAttributes }) {
|
|
463
|
+
return ["div", (0, import_core3.mergeAttributes)(HTMLAttributes, { "data-custom-quote-sign": "" }), 0];
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
// src/extensions/base/link.ts
|
|
468
|
+
var import_extension_link = __toESM(require("@tiptap/extension-link"));
|
|
469
|
+
var import_core4 = require("@tiptap/core");
|
|
470
|
+
var import_state3 = require("@tiptap/pm/state");
|
|
471
|
+
|
|
472
|
+
// node_modules/linkifyjs/dist/linkify.mjs
|
|
473
|
+
var encodedTlds = "aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2odyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rck0msd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5m\xF6gensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2oodside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2";
|
|
474
|
+
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";
|
|
475
|
+
var numeric = "numeric";
|
|
476
|
+
var ascii = "ascii";
|
|
477
|
+
var alpha = "alpha";
|
|
478
|
+
var asciinumeric = "asciinumeric";
|
|
479
|
+
var alphanumeric = "alphanumeric";
|
|
480
|
+
var domain = "domain";
|
|
481
|
+
var emoji = "emoji";
|
|
482
|
+
var scheme = "scheme";
|
|
483
|
+
var slashscheme = "slashscheme";
|
|
484
|
+
var whitespace = "whitespace";
|
|
485
|
+
function registerGroup(name, groups) {
|
|
486
|
+
if (!(name in groups)) {
|
|
487
|
+
groups[name] = [];
|
|
488
|
+
}
|
|
489
|
+
return groups[name];
|
|
490
|
+
}
|
|
491
|
+
function addToGroups(t, flags, groups) {
|
|
492
|
+
if (flags[numeric]) {
|
|
493
|
+
flags[asciinumeric] = true;
|
|
494
|
+
flags[alphanumeric] = true;
|
|
495
|
+
}
|
|
496
|
+
if (flags[ascii]) {
|
|
497
|
+
flags[asciinumeric] = true;
|
|
498
|
+
flags[alpha] = true;
|
|
499
|
+
}
|
|
500
|
+
if (flags[asciinumeric]) {
|
|
501
|
+
flags[alphanumeric] = true;
|
|
502
|
+
}
|
|
503
|
+
if (flags[alpha]) {
|
|
504
|
+
flags[alphanumeric] = true;
|
|
505
|
+
}
|
|
506
|
+
if (flags[alphanumeric]) {
|
|
507
|
+
flags[domain] = true;
|
|
508
|
+
}
|
|
509
|
+
if (flags[emoji]) {
|
|
510
|
+
flags[domain] = true;
|
|
511
|
+
}
|
|
512
|
+
for (const k in flags) {
|
|
513
|
+
const group = registerGroup(k, groups);
|
|
514
|
+
if (group.indexOf(t) < 0) {
|
|
515
|
+
group.push(t);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
function flagsForToken(t, groups) {
|
|
520
|
+
const result = {};
|
|
521
|
+
for (const c in groups) {
|
|
522
|
+
if (groups[c].indexOf(t) >= 0) {
|
|
523
|
+
result[c] = true;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return result;
|
|
527
|
+
}
|
|
528
|
+
function State(token = null) {
|
|
529
|
+
this.j = {};
|
|
530
|
+
this.jr = [];
|
|
531
|
+
this.jd = null;
|
|
532
|
+
this.t = token;
|
|
533
|
+
}
|
|
534
|
+
State.groups = {};
|
|
535
|
+
State.prototype = {
|
|
536
|
+
accepts() {
|
|
537
|
+
return !!this.t;
|
|
538
|
+
},
|
|
539
|
+
/**
|
|
540
|
+
* Follow an existing transition from the given input to the next state.
|
|
541
|
+
* Does not mutate.
|
|
542
|
+
* @param {string} input character or token type to transition on
|
|
543
|
+
* @returns {?State<T>} the next state, if any
|
|
544
|
+
*/
|
|
545
|
+
go(input) {
|
|
546
|
+
const state = this;
|
|
547
|
+
const nextState = state.j[input];
|
|
548
|
+
if (nextState) {
|
|
549
|
+
return nextState;
|
|
550
|
+
}
|
|
551
|
+
for (let i = 0; i < state.jr.length; i++) {
|
|
552
|
+
const regex = state.jr[i][0];
|
|
553
|
+
const nextState2 = state.jr[i][1];
|
|
554
|
+
if (nextState2 && regex.test(input)) {
|
|
555
|
+
return nextState2;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return state.jd;
|
|
559
|
+
},
|
|
560
|
+
/**
|
|
561
|
+
* Whether the state has a transition for the given input. Set the second
|
|
562
|
+
* argument to true to only look for an exact match (and not a default or
|
|
563
|
+
* regular-expression-based transition)
|
|
564
|
+
* @param {string} input
|
|
565
|
+
* @param {boolean} exactOnly
|
|
566
|
+
*/
|
|
567
|
+
has(input, exactOnly = false) {
|
|
568
|
+
return exactOnly ? input in this.j : !!this.go(input);
|
|
569
|
+
},
|
|
570
|
+
/**
|
|
571
|
+
* Short for "transition all"; create a transition from the array of items
|
|
572
|
+
* in the given list to the same final resulting state.
|
|
573
|
+
* @param {string | string[]} inputs Group of inputs to transition on
|
|
574
|
+
* @param {Transition<T> | State<T>} [next] Transition options
|
|
575
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
576
|
+
* @param {Collections<T>} [groups] Master list of token groups
|
|
577
|
+
*/
|
|
578
|
+
ta(inputs, next, flags, groups) {
|
|
579
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
580
|
+
this.tt(inputs[i], next, flags, groups);
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
/**
|
|
584
|
+
* Short for "take regexp transition"; defines a transition for this state
|
|
585
|
+
* when it encounters a token which matches the given regular expression
|
|
586
|
+
* @param {RegExp} regexp Regular expression transition (populate first)
|
|
587
|
+
* @param {T | State<T>} [next] Transition options
|
|
588
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
589
|
+
* @param {Collections<T>} [groups] Master list of token groups
|
|
590
|
+
* @returns {State<T>} taken after the given input
|
|
591
|
+
*/
|
|
592
|
+
tr(regexp, next, flags, groups) {
|
|
593
|
+
groups = groups || State.groups;
|
|
594
|
+
let nextState;
|
|
595
|
+
if (next && next.j) {
|
|
596
|
+
nextState = next;
|
|
597
|
+
} else {
|
|
598
|
+
nextState = new State(next);
|
|
599
|
+
if (flags && groups) {
|
|
600
|
+
addToGroups(next, flags, groups);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
this.jr.push([regexp, nextState]);
|
|
604
|
+
return nextState;
|
|
605
|
+
},
|
|
606
|
+
/**
|
|
607
|
+
* Short for "take transitions", will take as many sequential transitions as
|
|
608
|
+
* the length of the given input and returns the
|
|
609
|
+
* resulting final state.
|
|
610
|
+
* @param {string | string[]} input
|
|
611
|
+
* @param {T | State<T>} [next] Transition options
|
|
612
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
613
|
+
* @param {Collections<T>} [groups] Master list of token groups
|
|
614
|
+
* @returns {State<T>} taken after the given input
|
|
615
|
+
*/
|
|
616
|
+
ts(input, next, flags, groups) {
|
|
617
|
+
let state = this;
|
|
618
|
+
const len = input.length;
|
|
619
|
+
if (!len) {
|
|
620
|
+
return state;
|
|
621
|
+
}
|
|
622
|
+
for (let i = 0; i < len - 1; i++) {
|
|
623
|
+
state = state.tt(input[i]);
|
|
624
|
+
}
|
|
625
|
+
return state.tt(input[len - 1], next, flags, groups);
|
|
626
|
+
},
|
|
627
|
+
/**
|
|
628
|
+
* Short for "take transition", this is a method for building/working with
|
|
629
|
+
* state machines.
|
|
630
|
+
*
|
|
631
|
+
* If a state already exists for the given input, returns it.
|
|
632
|
+
*
|
|
633
|
+
* If a token is specified, that state will emit that token when reached by
|
|
634
|
+
* the linkify engine.
|
|
635
|
+
*
|
|
636
|
+
* If no state exists, it will be initialized with some default transitions
|
|
637
|
+
* that resemble existing default transitions.
|
|
638
|
+
*
|
|
639
|
+
* If a state is given for the second argument, that state will be
|
|
640
|
+
* transitioned to on the given input regardless of what that input
|
|
641
|
+
* previously did.
|
|
642
|
+
*
|
|
643
|
+
* Specify a token group flags to define groups that this token belongs to.
|
|
644
|
+
* The token will be added to corresponding entires in the given groups
|
|
645
|
+
* object.
|
|
646
|
+
*
|
|
647
|
+
* @param {string} input character, token type to transition on
|
|
648
|
+
* @param {T | State<T>} [next] Transition options
|
|
649
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
650
|
+
* @param {Collections<T>} [groups] Master list of groups
|
|
651
|
+
* @returns {State<T>} taken after the given input
|
|
652
|
+
*/
|
|
653
|
+
tt(input, next, flags, groups) {
|
|
654
|
+
groups = groups || State.groups;
|
|
655
|
+
const state = this;
|
|
656
|
+
if (next && next.j) {
|
|
657
|
+
state.j[input] = next;
|
|
658
|
+
return next;
|
|
659
|
+
}
|
|
660
|
+
const t = next;
|
|
661
|
+
let nextState, templateState = state.go(input);
|
|
662
|
+
if (templateState) {
|
|
663
|
+
nextState = new State();
|
|
664
|
+
Object.assign(nextState.j, templateState.j);
|
|
665
|
+
nextState.jr.push.apply(nextState.jr, templateState.jr);
|
|
666
|
+
nextState.jd = templateState.jd;
|
|
667
|
+
nextState.t = templateState.t;
|
|
668
|
+
} else {
|
|
669
|
+
nextState = new State();
|
|
670
|
+
}
|
|
671
|
+
if (t) {
|
|
672
|
+
if (groups) {
|
|
673
|
+
if (nextState.t && typeof nextState.t === "string") {
|
|
674
|
+
const allFlags = Object.assign(flagsForToken(nextState.t, groups), flags);
|
|
675
|
+
addToGroups(t, allFlags, groups);
|
|
676
|
+
} else if (flags) {
|
|
677
|
+
addToGroups(t, flags, groups);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
nextState.t = t;
|
|
681
|
+
}
|
|
682
|
+
state.j[input] = nextState;
|
|
683
|
+
return nextState;
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
var ta = (state, input, next, flags, groups) => state.ta(input, next, flags, groups);
|
|
687
|
+
var tr = (state, regexp, next, flags, groups) => state.tr(regexp, next, flags, groups);
|
|
688
|
+
var ts = (state, input, next, flags, groups) => state.ts(input, next, flags, groups);
|
|
689
|
+
var tt = (state, input, next, flags, groups) => state.tt(input, next, flags, groups);
|
|
690
|
+
var WORD = "WORD";
|
|
691
|
+
var UWORD = "UWORD";
|
|
692
|
+
var ASCIINUMERICAL = "ASCIINUMERICAL";
|
|
693
|
+
var ALPHANUMERICAL = "ALPHANUMERICAL";
|
|
694
|
+
var LOCALHOST = "LOCALHOST";
|
|
695
|
+
var TLD = "TLD";
|
|
696
|
+
var UTLD = "UTLD";
|
|
697
|
+
var SCHEME = "SCHEME";
|
|
698
|
+
var SLASH_SCHEME = "SLASH_SCHEME";
|
|
699
|
+
var NUM = "NUM";
|
|
700
|
+
var WS = "WS";
|
|
701
|
+
var NL = "NL";
|
|
702
|
+
var OPENBRACE = "OPENBRACE";
|
|
703
|
+
var CLOSEBRACE = "CLOSEBRACE";
|
|
704
|
+
var OPENBRACKET = "OPENBRACKET";
|
|
705
|
+
var CLOSEBRACKET = "CLOSEBRACKET";
|
|
706
|
+
var OPENPAREN = "OPENPAREN";
|
|
707
|
+
var CLOSEPAREN = "CLOSEPAREN";
|
|
708
|
+
var OPENANGLEBRACKET = "OPENANGLEBRACKET";
|
|
709
|
+
var CLOSEANGLEBRACKET = "CLOSEANGLEBRACKET";
|
|
710
|
+
var FULLWIDTHLEFTPAREN = "FULLWIDTHLEFTPAREN";
|
|
711
|
+
var FULLWIDTHRIGHTPAREN = "FULLWIDTHRIGHTPAREN";
|
|
712
|
+
var LEFTCORNERBRACKET = "LEFTCORNERBRACKET";
|
|
713
|
+
var RIGHTCORNERBRACKET = "RIGHTCORNERBRACKET";
|
|
714
|
+
var LEFTWHITECORNERBRACKET = "LEFTWHITECORNERBRACKET";
|
|
715
|
+
var RIGHTWHITECORNERBRACKET = "RIGHTWHITECORNERBRACKET";
|
|
716
|
+
var FULLWIDTHLESSTHAN = "FULLWIDTHLESSTHAN";
|
|
717
|
+
var FULLWIDTHGREATERTHAN = "FULLWIDTHGREATERTHAN";
|
|
718
|
+
var AMPERSAND = "AMPERSAND";
|
|
719
|
+
var APOSTROPHE = "APOSTROPHE";
|
|
720
|
+
var ASTERISK = "ASTERISK";
|
|
721
|
+
var AT = "AT";
|
|
722
|
+
var BACKSLASH = "BACKSLASH";
|
|
723
|
+
var BACKTICK = "BACKTICK";
|
|
724
|
+
var CARET = "CARET";
|
|
725
|
+
var COLON = "COLON";
|
|
726
|
+
var COMMA = "COMMA";
|
|
727
|
+
var DOLLAR = "DOLLAR";
|
|
728
|
+
var DOT = "DOT";
|
|
729
|
+
var EQUALS = "EQUALS";
|
|
730
|
+
var EXCLAMATION = "EXCLAMATION";
|
|
731
|
+
var HYPHEN = "HYPHEN";
|
|
732
|
+
var PERCENT = "PERCENT";
|
|
733
|
+
var PIPE = "PIPE";
|
|
734
|
+
var PLUS = "PLUS";
|
|
735
|
+
var POUND = "POUND";
|
|
736
|
+
var QUERY = "QUERY";
|
|
737
|
+
var QUOTE = "QUOTE";
|
|
738
|
+
var FULLWIDTHMIDDLEDOT = "FULLWIDTHMIDDLEDOT";
|
|
739
|
+
var SEMI = "SEMI";
|
|
740
|
+
var SLASH = "SLASH";
|
|
741
|
+
var TILDE = "TILDE";
|
|
742
|
+
var UNDERSCORE = "UNDERSCORE";
|
|
743
|
+
var EMOJI$1 = "EMOJI";
|
|
744
|
+
var SYM = "SYM";
|
|
745
|
+
var tk = /* @__PURE__ */ Object.freeze({
|
|
746
|
+
__proto__: null,
|
|
747
|
+
ALPHANUMERICAL,
|
|
748
|
+
AMPERSAND,
|
|
749
|
+
APOSTROPHE,
|
|
750
|
+
ASCIINUMERICAL,
|
|
751
|
+
ASTERISK,
|
|
752
|
+
AT,
|
|
753
|
+
BACKSLASH,
|
|
754
|
+
BACKTICK,
|
|
755
|
+
CARET,
|
|
756
|
+
CLOSEANGLEBRACKET,
|
|
757
|
+
CLOSEBRACE,
|
|
758
|
+
CLOSEBRACKET,
|
|
759
|
+
CLOSEPAREN,
|
|
760
|
+
COLON,
|
|
761
|
+
COMMA,
|
|
762
|
+
DOLLAR,
|
|
763
|
+
DOT,
|
|
764
|
+
EMOJI: EMOJI$1,
|
|
765
|
+
EQUALS,
|
|
766
|
+
EXCLAMATION,
|
|
767
|
+
FULLWIDTHGREATERTHAN,
|
|
768
|
+
FULLWIDTHLEFTPAREN,
|
|
769
|
+
FULLWIDTHLESSTHAN,
|
|
770
|
+
FULLWIDTHMIDDLEDOT,
|
|
771
|
+
FULLWIDTHRIGHTPAREN,
|
|
772
|
+
HYPHEN,
|
|
773
|
+
LEFTCORNERBRACKET,
|
|
774
|
+
LEFTWHITECORNERBRACKET,
|
|
775
|
+
LOCALHOST,
|
|
776
|
+
NL,
|
|
777
|
+
NUM,
|
|
778
|
+
OPENANGLEBRACKET,
|
|
779
|
+
OPENBRACE,
|
|
780
|
+
OPENBRACKET,
|
|
781
|
+
OPENPAREN,
|
|
782
|
+
PERCENT,
|
|
783
|
+
PIPE,
|
|
784
|
+
PLUS,
|
|
785
|
+
POUND,
|
|
786
|
+
QUERY,
|
|
787
|
+
QUOTE,
|
|
788
|
+
RIGHTCORNERBRACKET,
|
|
789
|
+
RIGHTWHITECORNERBRACKET,
|
|
790
|
+
SCHEME,
|
|
791
|
+
SEMI,
|
|
792
|
+
SLASH,
|
|
793
|
+
SLASH_SCHEME,
|
|
794
|
+
SYM,
|
|
795
|
+
TILDE,
|
|
796
|
+
TLD,
|
|
797
|
+
UNDERSCORE,
|
|
798
|
+
UTLD,
|
|
799
|
+
UWORD,
|
|
800
|
+
WORD,
|
|
801
|
+
WS
|
|
802
|
+
});
|
|
803
|
+
var ASCII_LETTER = /[a-z]/;
|
|
804
|
+
var LETTER = /\p{L}/u;
|
|
805
|
+
var EMOJI = /\p{Emoji}/u;
|
|
806
|
+
var DIGIT = /\d/;
|
|
807
|
+
var SPACE = /\s/;
|
|
808
|
+
var CR = "\r";
|
|
809
|
+
var LF = "\n";
|
|
810
|
+
var EMOJI_VARIATION = "\uFE0F";
|
|
811
|
+
var EMOJI_JOINER = "\u200D";
|
|
812
|
+
var OBJECT_REPLACEMENT = "\uFFFC";
|
|
813
|
+
var tlds = null;
|
|
814
|
+
var utlds = null;
|
|
815
|
+
function init$2(customSchemes = []) {
|
|
816
|
+
const groups = {};
|
|
817
|
+
State.groups = groups;
|
|
818
|
+
const Start = new State();
|
|
819
|
+
if (tlds == null) {
|
|
820
|
+
tlds = decodeTlds(encodedTlds);
|
|
821
|
+
}
|
|
822
|
+
if (utlds == null) {
|
|
823
|
+
utlds = decodeTlds(encodedUtlds);
|
|
824
|
+
}
|
|
825
|
+
tt(Start, "'", APOSTROPHE);
|
|
826
|
+
tt(Start, "{", OPENBRACE);
|
|
827
|
+
tt(Start, "}", CLOSEBRACE);
|
|
828
|
+
tt(Start, "[", OPENBRACKET);
|
|
829
|
+
tt(Start, "]", CLOSEBRACKET);
|
|
830
|
+
tt(Start, "(", OPENPAREN);
|
|
831
|
+
tt(Start, ")", CLOSEPAREN);
|
|
832
|
+
tt(Start, "<", OPENANGLEBRACKET);
|
|
833
|
+
tt(Start, ">", CLOSEANGLEBRACKET);
|
|
834
|
+
tt(Start, "\uFF08", FULLWIDTHLEFTPAREN);
|
|
835
|
+
tt(Start, "\uFF09", FULLWIDTHRIGHTPAREN);
|
|
836
|
+
tt(Start, "\u300C", LEFTCORNERBRACKET);
|
|
837
|
+
tt(Start, "\u300D", RIGHTCORNERBRACKET);
|
|
838
|
+
tt(Start, "\u300E", LEFTWHITECORNERBRACKET);
|
|
839
|
+
tt(Start, "\u300F", RIGHTWHITECORNERBRACKET);
|
|
840
|
+
tt(Start, "\uFF1C", FULLWIDTHLESSTHAN);
|
|
841
|
+
tt(Start, "\uFF1E", FULLWIDTHGREATERTHAN);
|
|
842
|
+
tt(Start, "&", AMPERSAND);
|
|
843
|
+
tt(Start, "*", ASTERISK);
|
|
844
|
+
tt(Start, "@", AT);
|
|
845
|
+
tt(Start, "`", BACKTICK);
|
|
846
|
+
tt(Start, "^", CARET);
|
|
847
|
+
tt(Start, ":", COLON);
|
|
848
|
+
tt(Start, ",", COMMA);
|
|
849
|
+
tt(Start, "$", DOLLAR);
|
|
850
|
+
tt(Start, ".", DOT);
|
|
851
|
+
tt(Start, "=", EQUALS);
|
|
852
|
+
tt(Start, "!", EXCLAMATION);
|
|
853
|
+
tt(Start, "-", HYPHEN);
|
|
854
|
+
tt(Start, "%", PERCENT);
|
|
855
|
+
tt(Start, "|", PIPE);
|
|
856
|
+
tt(Start, "+", PLUS);
|
|
857
|
+
tt(Start, "#", POUND);
|
|
858
|
+
tt(Start, "?", QUERY);
|
|
859
|
+
tt(Start, '"', QUOTE);
|
|
860
|
+
tt(Start, "/", SLASH);
|
|
861
|
+
tt(Start, ";", SEMI);
|
|
862
|
+
tt(Start, "~", TILDE);
|
|
863
|
+
tt(Start, "_", UNDERSCORE);
|
|
864
|
+
tt(Start, "\\", BACKSLASH);
|
|
865
|
+
tt(Start, "\u30FB", FULLWIDTHMIDDLEDOT);
|
|
866
|
+
const Num = tr(Start, DIGIT, NUM, {
|
|
867
|
+
[numeric]: true
|
|
868
|
+
});
|
|
869
|
+
tr(Num, DIGIT, Num);
|
|
870
|
+
const Asciinumeric = tr(Num, ASCII_LETTER, ASCIINUMERICAL, {
|
|
871
|
+
[asciinumeric]: true
|
|
872
|
+
});
|
|
873
|
+
const Alphanumeric = tr(Num, LETTER, ALPHANUMERICAL, {
|
|
874
|
+
[alphanumeric]: true
|
|
875
|
+
});
|
|
876
|
+
const Word = tr(Start, ASCII_LETTER, WORD, {
|
|
877
|
+
[ascii]: true
|
|
878
|
+
});
|
|
879
|
+
tr(Word, DIGIT, Asciinumeric);
|
|
880
|
+
tr(Word, ASCII_LETTER, Word);
|
|
881
|
+
tr(Asciinumeric, DIGIT, Asciinumeric);
|
|
882
|
+
tr(Asciinumeric, ASCII_LETTER, Asciinumeric);
|
|
883
|
+
const UWord = tr(Start, LETTER, UWORD, {
|
|
884
|
+
[alpha]: true
|
|
885
|
+
});
|
|
886
|
+
tr(UWord, ASCII_LETTER);
|
|
887
|
+
tr(UWord, DIGIT, Alphanumeric);
|
|
888
|
+
tr(UWord, LETTER, UWord);
|
|
889
|
+
tr(Alphanumeric, DIGIT, Alphanumeric);
|
|
890
|
+
tr(Alphanumeric, ASCII_LETTER);
|
|
891
|
+
tr(Alphanumeric, LETTER, Alphanumeric);
|
|
892
|
+
const Nl2 = tt(Start, LF, NL, {
|
|
893
|
+
[whitespace]: true
|
|
894
|
+
});
|
|
895
|
+
const Cr = tt(Start, CR, WS, {
|
|
896
|
+
[whitespace]: true
|
|
897
|
+
});
|
|
898
|
+
const Ws = tr(Start, SPACE, WS, {
|
|
899
|
+
[whitespace]: true
|
|
900
|
+
});
|
|
901
|
+
tt(Start, OBJECT_REPLACEMENT, Ws);
|
|
902
|
+
tt(Cr, LF, Nl2);
|
|
903
|
+
tt(Cr, OBJECT_REPLACEMENT, Ws);
|
|
904
|
+
tr(Cr, SPACE, Ws);
|
|
905
|
+
tt(Ws, CR);
|
|
906
|
+
tt(Ws, LF);
|
|
907
|
+
tr(Ws, SPACE, Ws);
|
|
908
|
+
tt(Ws, OBJECT_REPLACEMENT, Ws);
|
|
909
|
+
const Emoji = tr(Start, EMOJI, EMOJI$1, {
|
|
910
|
+
[emoji]: true
|
|
911
|
+
});
|
|
912
|
+
tt(Emoji, "#");
|
|
913
|
+
tr(Emoji, EMOJI, Emoji);
|
|
914
|
+
tt(Emoji, EMOJI_VARIATION, Emoji);
|
|
915
|
+
const EmojiJoiner = tt(Emoji, EMOJI_JOINER);
|
|
916
|
+
tt(EmojiJoiner, "#");
|
|
917
|
+
tr(EmojiJoiner, EMOJI, Emoji);
|
|
918
|
+
const wordjr = [[ASCII_LETTER, Word], [DIGIT, Asciinumeric]];
|
|
919
|
+
const uwordjr = [[ASCII_LETTER, null], [LETTER, UWord], [DIGIT, Alphanumeric]];
|
|
920
|
+
for (let i = 0; i < tlds.length; i++) {
|
|
921
|
+
fastts(Start, tlds[i], TLD, WORD, wordjr);
|
|
922
|
+
}
|
|
923
|
+
for (let i = 0; i < utlds.length; i++) {
|
|
924
|
+
fastts(Start, utlds[i], UTLD, UWORD, uwordjr);
|
|
925
|
+
}
|
|
926
|
+
addToGroups(TLD, {
|
|
927
|
+
tld: true,
|
|
928
|
+
ascii: true
|
|
929
|
+
}, groups);
|
|
930
|
+
addToGroups(UTLD, {
|
|
931
|
+
utld: true,
|
|
932
|
+
alpha: true
|
|
933
|
+
}, groups);
|
|
934
|
+
fastts(Start, "file", SCHEME, WORD, wordjr);
|
|
935
|
+
fastts(Start, "mailto", SCHEME, WORD, wordjr);
|
|
936
|
+
fastts(Start, "http", SLASH_SCHEME, WORD, wordjr);
|
|
937
|
+
fastts(Start, "https", SLASH_SCHEME, WORD, wordjr);
|
|
938
|
+
fastts(Start, "ftp", SLASH_SCHEME, WORD, wordjr);
|
|
939
|
+
fastts(Start, "ftps", SLASH_SCHEME, WORD, wordjr);
|
|
940
|
+
addToGroups(SCHEME, {
|
|
941
|
+
scheme: true,
|
|
942
|
+
ascii: true
|
|
943
|
+
}, groups);
|
|
944
|
+
addToGroups(SLASH_SCHEME, {
|
|
945
|
+
slashscheme: true,
|
|
946
|
+
ascii: true
|
|
947
|
+
}, groups);
|
|
948
|
+
customSchemes = customSchemes.sort((a, b) => a[0] > b[0] ? 1 : -1);
|
|
949
|
+
for (let i = 0; i < customSchemes.length; i++) {
|
|
950
|
+
const sch = customSchemes[i][0];
|
|
951
|
+
const optionalSlashSlash = customSchemes[i][1];
|
|
952
|
+
const flags = optionalSlashSlash ? {
|
|
953
|
+
[scheme]: true
|
|
954
|
+
} : {
|
|
955
|
+
[slashscheme]: true
|
|
956
|
+
};
|
|
957
|
+
if (sch.indexOf("-") >= 0) {
|
|
958
|
+
flags[domain] = true;
|
|
959
|
+
} else if (!ASCII_LETTER.test(sch)) {
|
|
960
|
+
flags[numeric] = true;
|
|
961
|
+
} else if (DIGIT.test(sch)) {
|
|
962
|
+
flags[asciinumeric] = true;
|
|
963
|
+
} else {
|
|
964
|
+
flags[ascii] = true;
|
|
965
|
+
}
|
|
966
|
+
ts(Start, sch, sch, flags);
|
|
967
|
+
}
|
|
968
|
+
ts(Start, "localhost", LOCALHOST, {
|
|
969
|
+
ascii: true
|
|
970
|
+
});
|
|
971
|
+
Start.jd = new State(SYM);
|
|
972
|
+
return {
|
|
973
|
+
start: Start,
|
|
974
|
+
tokens: Object.assign({
|
|
975
|
+
groups
|
|
976
|
+
}, tk)
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
function run$1(start, str) {
|
|
980
|
+
const iterable = stringToArray(str.replace(/[A-Z]/g, (c) => c.toLowerCase()));
|
|
981
|
+
const charCount = iterable.length;
|
|
982
|
+
const tokens = [];
|
|
983
|
+
let cursor = 0;
|
|
984
|
+
let charCursor = 0;
|
|
985
|
+
while (charCursor < charCount) {
|
|
986
|
+
let state = start;
|
|
987
|
+
let nextState = null;
|
|
988
|
+
let tokenLength = 0;
|
|
989
|
+
let latestAccepting = null;
|
|
990
|
+
let sinceAccepts = -1;
|
|
991
|
+
let charsSinceAccepts = -1;
|
|
992
|
+
while (charCursor < charCount && (nextState = state.go(iterable[charCursor]))) {
|
|
993
|
+
state = nextState;
|
|
994
|
+
if (state.accepts()) {
|
|
995
|
+
sinceAccepts = 0;
|
|
996
|
+
charsSinceAccepts = 0;
|
|
997
|
+
latestAccepting = state;
|
|
998
|
+
} else if (sinceAccepts >= 0) {
|
|
999
|
+
sinceAccepts += iterable[charCursor].length;
|
|
1000
|
+
charsSinceAccepts++;
|
|
1001
|
+
}
|
|
1002
|
+
tokenLength += iterable[charCursor].length;
|
|
1003
|
+
cursor += iterable[charCursor].length;
|
|
1004
|
+
charCursor++;
|
|
1005
|
+
}
|
|
1006
|
+
cursor -= sinceAccepts;
|
|
1007
|
+
charCursor -= charsSinceAccepts;
|
|
1008
|
+
tokenLength -= sinceAccepts;
|
|
1009
|
+
tokens.push({
|
|
1010
|
+
t: latestAccepting.t,
|
|
1011
|
+
// token type/name
|
|
1012
|
+
v: str.slice(cursor - tokenLength, cursor),
|
|
1013
|
+
// string value
|
|
1014
|
+
s: cursor - tokenLength,
|
|
1015
|
+
// start index
|
|
1016
|
+
e: cursor
|
|
1017
|
+
// end index (excluding)
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
return tokens;
|
|
1021
|
+
}
|
|
1022
|
+
function stringToArray(str) {
|
|
1023
|
+
const result = [];
|
|
1024
|
+
const len = str.length;
|
|
1025
|
+
let index = 0;
|
|
1026
|
+
while (index < len) {
|
|
1027
|
+
let first = str.charCodeAt(index);
|
|
1028
|
+
let second;
|
|
1029
|
+
let char = first < 55296 || first > 56319 || index + 1 === len || (second = str.charCodeAt(index + 1)) < 56320 || second > 57343 ? str[index] : str.slice(index, index + 2);
|
|
1030
|
+
result.push(char);
|
|
1031
|
+
index += char.length;
|
|
1032
|
+
}
|
|
1033
|
+
return result;
|
|
1034
|
+
}
|
|
1035
|
+
function fastts(state, input, t, defaultt, jr) {
|
|
1036
|
+
let next;
|
|
1037
|
+
const len = input.length;
|
|
1038
|
+
for (let i = 0; i < len - 1; i++) {
|
|
1039
|
+
const char = input[i];
|
|
1040
|
+
if (state.j[char]) {
|
|
1041
|
+
next = state.j[char];
|
|
1042
|
+
} else {
|
|
1043
|
+
next = new State(defaultt);
|
|
1044
|
+
next.jr = jr.slice();
|
|
1045
|
+
state.j[char] = next;
|
|
1046
|
+
}
|
|
1047
|
+
state = next;
|
|
1048
|
+
}
|
|
1049
|
+
next = new State(t);
|
|
1050
|
+
next.jr = jr.slice();
|
|
1051
|
+
state.j[input[len - 1]] = next;
|
|
1052
|
+
return next;
|
|
1053
|
+
}
|
|
1054
|
+
function decodeTlds(encoded) {
|
|
1055
|
+
const words = [];
|
|
1056
|
+
const stack = [];
|
|
1057
|
+
let i = 0;
|
|
1058
|
+
let digits = "0123456789";
|
|
1059
|
+
while (i < encoded.length) {
|
|
1060
|
+
let popDigitCount = 0;
|
|
1061
|
+
while (digits.indexOf(encoded[i + popDigitCount]) >= 0) {
|
|
1062
|
+
popDigitCount++;
|
|
1063
|
+
}
|
|
1064
|
+
if (popDigitCount > 0) {
|
|
1065
|
+
words.push(stack.join(""));
|
|
1066
|
+
for (let popCount = parseInt(encoded.substring(i, i + popDigitCount), 10); popCount > 0; popCount--) {
|
|
1067
|
+
stack.pop();
|
|
1068
|
+
}
|
|
1069
|
+
i += popDigitCount;
|
|
1070
|
+
} else {
|
|
1071
|
+
stack.push(encoded[i]);
|
|
1072
|
+
i++;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
return words;
|
|
1076
|
+
}
|
|
1077
|
+
var defaults = {
|
|
1078
|
+
defaultProtocol: "http",
|
|
1079
|
+
events: null,
|
|
1080
|
+
format: noop,
|
|
1081
|
+
formatHref: noop,
|
|
1082
|
+
nl2br: false,
|
|
1083
|
+
tagName: "a",
|
|
1084
|
+
target: null,
|
|
1085
|
+
rel: null,
|
|
1086
|
+
validate: true,
|
|
1087
|
+
truncate: Infinity,
|
|
1088
|
+
className: null,
|
|
1089
|
+
attributes: null,
|
|
1090
|
+
ignoreTags: [],
|
|
1091
|
+
render: null
|
|
1092
|
+
};
|
|
1093
|
+
function Options(opts, defaultRender = null) {
|
|
1094
|
+
let o = Object.assign({}, defaults);
|
|
1095
|
+
if (opts) {
|
|
1096
|
+
o = Object.assign(o, opts instanceof Options ? opts.o : opts);
|
|
1097
|
+
}
|
|
1098
|
+
const ignoredTags = o.ignoreTags;
|
|
1099
|
+
const uppercaseIgnoredTags = [];
|
|
1100
|
+
for (let i = 0; i < ignoredTags.length; i++) {
|
|
1101
|
+
uppercaseIgnoredTags.push(ignoredTags[i].toUpperCase());
|
|
1102
|
+
}
|
|
1103
|
+
this.o = o;
|
|
1104
|
+
if (defaultRender) {
|
|
1105
|
+
this.defaultRender = defaultRender;
|
|
1106
|
+
}
|
|
1107
|
+
this.ignoreTags = uppercaseIgnoredTags;
|
|
1108
|
+
}
|
|
1109
|
+
Options.prototype = {
|
|
1110
|
+
o: defaults,
|
|
1111
|
+
/**
|
|
1112
|
+
* @type string[]
|
|
1113
|
+
*/
|
|
1114
|
+
ignoreTags: [],
|
|
1115
|
+
/**
|
|
1116
|
+
* @param {IntermediateRepresentation} ir
|
|
1117
|
+
* @returns {any}
|
|
1118
|
+
*/
|
|
1119
|
+
defaultRender(ir) {
|
|
1120
|
+
return ir;
|
|
1121
|
+
},
|
|
1122
|
+
/**
|
|
1123
|
+
* Returns true or false based on whether a token should be displayed as a
|
|
1124
|
+
* link based on the user options.
|
|
1125
|
+
* @param {MultiToken} token
|
|
1126
|
+
* @returns {boolean}
|
|
1127
|
+
*/
|
|
1128
|
+
check(token) {
|
|
1129
|
+
return this.get("validate", token.toString(), token);
|
|
1130
|
+
},
|
|
1131
|
+
// Private methods
|
|
1132
|
+
/**
|
|
1133
|
+
* Resolve an option's value based on the value of the option and the given
|
|
1134
|
+
* params. If operator and token are specified and the target option is
|
|
1135
|
+
* callable, automatically calls the function with the given argument.
|
|
1136
|
+
* @template {keyof Opts} K
|
|
1137
|
+
* @param {K} key Name of option to use
|
|
1138
|
+
* @param {string} [operator] will be passed to the target option if it's a
|
|
1139
|
+
* function. If not specified, RAW function value gets returned
|
|
1140
|
+
* @param {MultiToken} [token] The token from linkify.tokenize
|
|
1141
|
+
* @returns {Opts[K] | any}
|
|
1142
|
+
*/
|
|
1143
|
+
get(key, operator, token) {
|
|
1144
|
+
const isCallable = operator != null;
|
|
1145
|
+
let option = this.o[key];
|
|
1146
|
+
if (!option) {
|
|
1147
|
+
return option;
|
|
1148
|
+
}
|
|
1149
|
+
if (typeof option === "object") {
|
|
1150
|
+
option = token.t in option ? option[token.t] : defaults[key];
|
|
1151
|
+
if (typeof option === "function" && isCallable) {
|
|
1152
|
+
option = option(operator, token);
|
|
1153
|
+
}
|
|
1154
|
+
} else if (typeof option === "function" && isCallable) {
|
|
1155
|
+
option = option(operator, token.t, token);
|
|
1156
|
+
}
|
|
1157
|
+
return option;
|
|
1158
|
+
},
|
|
1159
|
+
/**
|
|
1160
|
+
* @template {keyof Opts} L
|
|
1161
|
+
* @param {L} key Name of options object to use
|
|
1162
|
+
* @param {string} [operator]
|
|
1163
|
+
* @param {MultiToken} [token]
|
|
1164
|
+
* @returns {Opts[L] | any}
|
|
1165
|
+
*/
|
|
1166
|
+
getObj(key, operator, token) {
|
|
1167
|
+
let obj = this.o[key];
|
|
1168
|
+
if (typeof obj === "function" && operator != null) {
|
|
1169
|
+
obj = obj(operator, token.t, token);
|
|
1170
|
+
}
|
|
1171
|
+
return obj;
|
|
1172
|
+
},
|
|
1173
|
+
/**
|
|
1174
|
+
* Convert the given token to a rendered element that may be added to the
|
|
1175
|
+
* calling-interface's DOM
|
|
1176
|
+
* @param {MultiToken} token Token to render to an HTML element
|
|
1177
|
+
* @returns {any} Render result; e.g., HTML string, DOM element, React
|
|
1178
|
+
* Component, etc.
|
|
1179
|
+
*/
|
|
1180
|
+
render(token) {
|
|
1181
|
+
const ir = token.render(this);
|
|
1182
|
+
const renderFn = this.get("render", null, token) || this.defaultRender;
|
|
1183
|
+
return renderFn(ir, token.t, token);
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
function noop(val) {
|
|
1187
|
+
return val;
|
|
1188
|
+
}
|
|
1189
|
+
function MultiToken(value, tokens) {
|
|
1190
|
+
this.t = "token";
|
|
1191
|
+
this.v = value;
|
|
1192
|
+
this.tk = tokens;
|
|
1193
|
+
}
|
|
1194
|
+
MultiToken.prototype = {
|
|
1195
|
+
isLink: false,
|
|
1196
|
+
/**
|
|
1197
|
+
* Return the string this token represents.
|
|
1198
|
+
* @return {string}
|
|
1199
|
+
*/
|
|
1200
|
+
toString() {
|
|
1201
|
+
return this.v;
|
|
1202
|
+
},
|
|
1203
|
+
/**
|
|
1204
|
+
* What should the value for this token be in the `href` HTML attribute?
|
|
1205
|
+
* Returns the `.toString` value by default.
|
|
1206
|
+
* @param {string} [scheme]
|
|
1207
|
+
* @return {string}
|
|
1208
|
+
*/
|
|
1209
|
+
toHref(scheme2) {
|
|
1210
|
+
return this.toString();
|
|
1211
|
+
},
|
|
1212
|
+
/**
|
|
1213
|
+
* @param {Options} options Formatting options
|
|
1214
|
+
* @returns {string}
|
|
1215
|
+
*/
|
|
1216
|
+
toFormattedString(options) {
|
|
1217
|
+
const val = this.toString();
|
|
1218
|
+
const truncate = options.get("truncate", val, this);
|
|
1219
|
+
const formatted = options.get("format", val, this);
|
|
1220
|
+
return truncate && formatted.length > truncate ? formatted.substring(0, truncate) + "\u2026" : formatted;
|
|
1221
|
+
},
|
|
1222
|
+
/**
|
|
1223
|
+
*
|
|
1224
|
+
* @param {Options} options
|
|
1225
|
+
* @returns {string}
|
|
1226
|
+
*/
|
|
1227
|
+
toFormattedHref(options) {
|
|
1228
|
+
return options.get("formatHref", this.toHref(options.get("defaultProtocol")), this);
|
|
1229
|
+
},
|
|
1230
|
+
/**
|
|
1231
|
+
* The start index of this token in the original input string
|
|
1232
|
+
* @returns {number}
|
|
1233
|
+
*/
|
|
1234
|
+
startIndex() {
|
|
1235
|
+
return this.tk[0].s;
|
|
1236
|
+
},
|
|
1237
|
+
/**
|
|
1238
|
+
* The end index of this token in the original input string (up to this
|
|
1239
|
+
* index but not including it)
|
|
1240
|
+
* @returns {number}
|
|
1241
|
+
*/
|
|
1242
|
+
endIndex() {
|
|
1243
|
+
return this.tk[this.tk.length - 1].e;
|
|
1244
|
+
},
|
|
1245
|
+
/**
|
|
1246
|
+
Returns an object of relevant values for this token, which includes keys
|
|
1247
|
+
* type - Kind of token ('url', 'email', etc.)
|
|
1248
|
+
* value - Original text
|
|
1249
|
+
* href - The value that should be added to the anchor tag's href
|
|
1250
|
+
attribute
|
|
1251
|
+
@method toObject
|
|
1252
|
+
@param {string} [protocol] `'http'` by default
|
|
1253
|
+
*/
|
|
1254
|
+
toObject(protocol = defaults.defaultProtocol) {
|
|
1255
|
+
return {
|
|
1256
|
+
type: this.t,
|
|
1257
|
+
value: this.toString(),
|
|
1258
|
+
isLink: this.isLink,
|
|
1259
|
+
href: this.toHref(protocol),
|
|
1260
|
+
start: this.startIndex(),
|
|
1261
|
+
end: this.endIndex()
|
|
1262
|
+
};
|
|
1263
|
+
},
|
|
1264
|
+
/**
|
|
1265
|
+
*
|
|
1266
|
+
* @param {Options} options Formatting option
|
|
1267
|
+
*/
|
|
1268
|
+
toFormattedObject(options) {
|
|
1269
|
+
return {
|
|
1270
|
+
type: this.t,
|
|
1271
|
+
value: this.toFormattedString(options),
|
|
1272
|
+
isLink: this.isLink,
|
|
1273
|
+
href: this.toFormattedHref(options),
|
|
1274
|
+
start: this.startIndex(),
|
|
1275
|
+
end: this.endIndex()
|
|
1276
|
+
};
|
|
1277
|
+
},
|
|
1278
|
+
/**
|
|
1279
|
+
* Whether this token should be rendered as a link according to the given options
|
|
1280
|
+
* @param {Options} options
|
|
1281
|
+
* @returns {boolean}
|
|
1282
|
+
*/
|
|
1283
|
+
validate(options) {
|
|
1284
|
+
return options.get("validate", this.toString(), this);
|
|
1285
|
+
},
|
|
1286
|
+
/**
|
|
1287
|
+
* Return an object that represents how this link should be rendered.
|
|
1288
|
+
* @param {Options} options Formattinng options
|
|
1289
|
+
*/
|
|
1290
|
+
render(options) {
|
|
1291
|
+
const token = this;
|
|
1292
|
+
const href = this.toHref(options.get("defaultProtocol"));
|
|
1293
|
+
const formattedHref = options.get("formatHref", href, this);
|
|
1294
|
+
const tagName = options.get("tagName", href, token);
|
|
1295
|
+
const content = this.toFormattedString(options);
|
|
1296
|
+
const attributes = {};
|
|
1297
|
+
const className = options.get("className", href, token);
|
|
1298
|
+
const target = options.get("target", href, token);
|
|
1299
|
+
const rel = options.get("rel", href, token);
|
|
1300
|
+
const attrs = options.getObj("attributes", href, token);
|
|
1301
|
+
const eventListeners = options.getObj("events", href, token);
|
|
1302
|
+
attributes.href = formattedHref;
|
|
1303
|
+
if (className) {
|
|
1304
|
+
attributes.class = className;
|
|
1305
|
+
}
|
|
1306
|
+
if (target) {
|
|
1307
|
+
attributes.target = target;
|
|
1308
|
+
}
|
|
1309
|
+
if (rel) {
|
|
1310
|
+
attributes.rel = rel;
|
|
1311
|
+
}
|
|
1312
|
+
if (attrs) {
|
|
1313
|
+
Object.assign(attributes, attrs);
|
|
1314
|
+
}
|
|
1315
|
+
return {
|
|
1316
|
+
tagName,
|
|
1317
|
+
attributes,
|
|
1318
|
+
content,
|
|
1319
|
+
eventListeners
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
function createTokenClass(type, props) {
|
|
1324
|
+
class Token extends MultiToken {
|
|
1325
|
+
constructor(value, tokens) {
|
|
1326
|
+
super(value, tokens);
|
|
1327
|
+
this.t = type;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
for (const p in props) {
|
|
1331
|
+
Token.prototype[p] = props[p];
|
|
1332
|
+
}
|
|
1333
|
+
Token.t = type;
|
|
1334
|
+
return Token;
|
|
1335
|
+
}
|
|
1336
|
+
var Email = createTokenClass("email", {
|
|
1337
|
+
isLink: true,
|
|
1338
|
+
toHref() {
|
|
1339
|
+
return "mailto:" + this.toString();
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
var Text = createTokenClass("text");
|
|
1343
|
+
var Nl = createTokenClass("nl");
|
|
1344
|
+
var Url = createTokenClass("url", {
|
|
1345
|
+
isLink: true,
|
|
1346
|
+
/**
|
|
1347
|
+
Lowercases relevant parts of the domain and adds the protocol if
|
|
1348
|
+
required. Note that this will not escape unsafe HTML characters in the
|
|
1349
|
+
URL.
|
|
1350
|
+
@param {string} [scheme] default scheme (e.g., 'https')
|
|
1351
|
+
@return {string} the full href
|
|
1352
|
+
*/
|
|
1353
|
+
toHref(scheme2 = defaults.defaultProtocol) {
|
|
1354
|
+
return this.hasProtocol() ? this.v : `${scheme2}://${this.v}`;
|
|
1355
|
+
},
|
|
1356
|
+
/**
|
|
1357
|
+
* Check whether this URL token has a protocol
|
|
1358
|
+
* @return {boolean}
|
|
1359
|
+
*/
|
|
1360
|
+
hasProtocol() {
|
|
1361
|
+
const tokens = this.tk;
|
|
1362
|
+
return tokens.length >= 2 && tokens[0].t !== LOCALHOST && tokens[1].t === COLON;
|
|
1363
|
+
}
|
|
1364
|
+
});
|
|
1365
|
+
var makeState = (arg) => new State(arg);
|
|
1366
|
+
function init$1({
|
|
1367
|
+
groups
|
|
1368
|
+
}) {
|
|
1369
|
+
const qsAccepting = groups.domain.concat([AMPERSAND, ASTERISK, AT, BACKSLASH, BACKTICK, CARET, DOLLAR, EQUALS, HYPHEN, NUM, PERCENT, PIPE, PLUS, POUND, SLASH, SYM, TILDE, UNDERSCORE]);
|
|
1370
|
+
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];
|
|
1371
|
+
const localpartAccepting = [AMPERSAND, APOSTROPHE, ASTERISK, BACKSLASH, BACKTICK, CARET, DOLLAR, EQUALS, HYPHEN, OPENBRACE, CLOSEBRACE, PERCENT, PIPE, PLUS, POUND, QUERY, SLASH, SYM, TILDE, UNDERSCORE];
|
|
1372
|
+
const Start = makeState();
|
|
1373
|
+
const Localpart = tt(Start, TILDE);
|
|
1374
|
+
ta(Localpart, localpartAccepting, Localpart);
|
|
1375
|
+
ta(Localpart, groups.domain, Localpart);
|
|
1376
|
+
const Domain = makeState(), Scheme = makeState(), SlashScheme = makeState();
|
|
1377
|
+
ta(Start, groups.domain, Domain);
|
|
1378
|
+
ta(Start, groups.scheme, Scheme);
|
|
1379
|
+
ta(Start, groups.slashscheme, SlashScheme);
|
|
1380
|
+
ta(Domain, localpartAccepting, Localpart);
|
|
1381
|
+
ta(Domain, groups.domain, Domain);
|
|
1382
|
+
const LocalpartAt = tt(Domain, AT);
|
|
1383
|
+
tt(Localpart, AT, LocalpartAt);
|
|
1384
|
+
tt(Scheme, AT, LocalpartAt);
|
|
1385
|
+
tt(SlashScheme, AT, LocalpartAt);
|
|
1386
|
+
const LocalpartDot = tt(Localpart, DOT);
|
|
1387
|
+
ta(LocalpartDot, localpartAccepting, Localpart);
|
|
1388
|
+
ta(LocalpartDot, groups.domain, Localpart);
|
|
1389
|
+
const EmailDomain = makeState();
|
|
1390
|
+
ta(LocalpartAt, groups.domain, EmailDomain);
|
|
1391
|
+
ta(EmailDomain, groups.domain, EmailDomain);
|
|
1392
|
+
const EmailDomainDot = tt(EmailDomain, DOT);
|
|
1393
|
+
ta(EmailDomainDot, groups.domain, EmailDomain);
|
|
1394
|
+
const Email$1 = makeState(Email);
|
|
1395
|
+
ta(EmailDomainDot, groups.tld, Email$1);
|
|
1396
|
+
ta(EmailDomainDot, groups.utld, Email$1);
|
|
1397
|
+
tt(LocalpartAt, LOCALHOST, Email$1);
|
|
1398
|
+
const EmailDomainHyphen = tt(EmailDomain, HYPHEN);
|
|
1399
|
+
tt(EmailDomainHyphen, HYPHEN, EmailDomainHyphen);
|
|
1400
|
+
ta(EmailDomainHyphen, groups.domain, EmailDomain);
|
|
1401
|
+
ta(Email$1, groups.domain, EmailDomain);
|
|
1402
|
+
tt(Email$1, DOT, EmailDomainDot);
|
|
1403
|
+
tt(Email$1, HYPHEN, EmailDomainHyphen);
|
|
1404
|
+
const DomainHyphen = tt(Domain, HYPHEN);
|
|
1405
|
+
const DomainDot = tt(Domain, DOT);
|
|
1406
|
+
tt(DomainHyphen, HYPHEN, DomainHyphen);
|
|
1407
|
+
ta(DomainHyphen, groups.domain, Domain);
|
|
1408
|
+
ta(DomainDot, localpartAccepting, Localpart);
|
|
1409
|
+
ta(DomainDot, groups.domain, Domain);
|
|
1410
|
+
const DomainDotTld = makeState(Url);
|
|
1411
|
+
ta(DomainDot, groups.tld, DomainDotTld);
|
|
1412
|
+
ta(DomainDot, groups.utld, DomainDotTld);
|
|
1413
|
+
ta(DomainDotTld, groups.domain, Domain);
|
|
1414
|
+
ta(DomainDotTld, localpartAccepting, Localpart);
|
|
1415
|
+
tt(DomainDotTld, DOT, DomainDot);
|
|
1416
|
+
tt(DomainDotTld, HYPHEN, DomainHyphen);
|
|
1417
|
+
tt(DomainDotTld, AT, LocalpartAt);
|
|
1418
|
+
const DomainDotTldColon = tt(DomainDotTld, COLON);
|
|
1419
|
+
const DomainDotTldColonPort = makeState(Url);
|
|
1420
|
+
ta(DomainDotTldColon, groups.numeric, DomainDotTldColonPort);
|
|
1421
|
+
const Url$1 = makeState(Url);
|
|
1422
|
+
const UrlNonaccept = makeState();
|
|
1423
|
+
ta(Url$1, qsAccepting, Url$1);
|
|
1424
|
+
ta(Url$1, qsNonAccepting, UrlNonaccept);
|
|
1425
|
+
ta(UrlNonaccept, qsAccepting, Url$1);
|
|
1426
|
+
ta(UrlNonaccept, qsNonAccepting, UrlNonaccept);
|
|
1427
|
+
tt(DomainDotTld, SLASH, Url$1);
|
|
1428
|
+
tt(DomainDotTldColonPort, SLASH, Url$1);
|
|
1429
|
+
const SchemeColon = tt(Scheme, COLON);
|
|
1430
|
+
const SlashSchemeColon = tt(SlashScheme, COLON);
|
|
1431
|
+
const SlashSchemeColonSlash = tt(SlashSchemeColon, SLASH);
|
|
1432
|
+
const UriPrefix = tt(SlashSchemeColonSlash, SLASH);
|
|
1433
|
+
ta(Scheme, groups.domain, Domain);
|
|
1434
|
+
tt(Scheme, DOT, DomainDot);
|
|
1435
|
+
tt(Scheme, HYPHEN, DomainHyphen);
|
|
1436
|
+
ta(SlashScheme, groups.domain, Domain);
|
|
1437
|
+
tt(SlashScheme, DOT, DomainDot);
|
|
1438
|
+
tt(SlashScheme, HYPHEN, DomainHyphen);
|
|
1439
|
+
ta(SchemeColon, groups.domain, Url$1);
|
|
1440
|
+
tt(SchemeColon, SLASH, Url$1);
|
|
1441
|
+
tt(SchemeColon, QUERY, Url$1);
|
|
1442
|
+
ta(UriPrefix, groups.domain, Url$1);
|
|
1443
|
+
ta(UriPrefix, qsAccepting, Url$1);
|
|
1444
|
+
tt(UriPrefix, SLASH, Url$1);
|
|
1445
|
+
const bracketPairs = [
|
|
1446
|
+
[OPENBRACE, CLOSEBRACE],
|
|
1447
|
+
// {}
|
|
1448
|
+
[OPENBRACKET, CLOSEBRACKET],
|
|
1449
|
+
// []
|
|
1450
|
+
[OPENPAREN, CLOSEPAREN],
|
|
1451
|
+
// ()
|
|
1452
|
+
[OPENANGLEBRACKET, CLOSEANGLEBRACKET],
|
|
1453
|
+
// <>
|
|
1454
|
+
[FULLWIDTHLEFTPAREN, FULLWIDTHRIGHTPAREN],
|
|
1455
|
+
// ()
|
|
1456
|
+
[LEFTCORNERBRACKET, RIGHTCORNERBRACKET],
|
|
1457
|
+
// 「」
|
|
1458
|
+
[LEFTWHITECORNERBRACKET, RIGHTWHITECORNERBRACKET],
|
|
1459
|
+
// 『』
|
|
1460
|
+
[FULLWIDTHLESSTHAN, FULLWIDTHGREATERTHAN]
|
|
1461
|
+
// <>
|
|
1462
|
+
];
|
|
1463
|
+
for (let i = 0; i < bracketPairs.length; i++) {
|
|
1464
|
+
const [OPEN, CLOSE] = bracketPairs[i];
|
|
1465
|
+
const UrlOpen = tt(Url$1, OPEN);
|
|
1466
|
+
tt(UrlNonaccept, OPEN, UrlOpen);
|
|
1467
|
+
const UrlOpenQ = makeState(Url);
|
|
1468
|
+
ta(UrlOpen, qsAccepting, UrlOpenQ);
|
|
1469
|
+
const UrlOpenSyms = makeState();
|
|
1470
|
+
ta(UrlOpen, qsNonAccepting, UrlOpenSyms);
|
|
1471
|
+
tt(UrlOpen, CLOSE, Url$1);
|
|
1472
|
+
ta(UrlOpenQ, qsAccepting, UrlOpenQ);
|
|
1473
|
+
ta(UrlOpenQ, qsNonAccepting, UrlOpenSyms);
|
|
1474
|
+
ta(UrlOpenSyms, qsAccepting, UrlOpenQ);
|
|
1475
|
+
ta(UrlOpenSyms, qsNonAccepting, UrlOpenSyms);
|
|
1476
|
+
tt(UrlOpenQ, CLOSE, Url$1);
|
|
1477
|
+
tt(UrlOpenSyms, CLOSE, Url$1);
|
|
1478
|
+
}
|
|
1479
|
+
tt(Start, LOCALHOST, DomainDotTld);
|
|
1480
|
+
tt(Start, NL, Nl);
|
|
1481
|
+
return {
|
|
1482
|
+
start: Start,
|
|
1483
|
+
tokens: tk
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
function run(start, input, tokens) {
|
|
1487
|
+
let len = tokens.length;
|
|
1488
|
+
let cursor = 0;
|
|
1489
|
+
let multis = [];
|
|
1490
|
+
let textTokens = [];
|
|
1491
|
+
while (cursor < len) {
|
|
1492
|
+
let state = start;
|
|
1493
|
+
let secondState = null;
|
|
1494
|
+
let nextState = null;
|
|
1495
|
+
let multiLength = 0;
|
|
1496
|
+
let latestAccepting = null;
|
|
1497
|
+
let sinceAccepts = -1;
|
|
1498
|
+
while (cursor < len && !(secondState = state.go(tokens[cursor].t))) {
|
|
1499
|
+
textTokens.push(tokens[cursor++]);
|
|
1500
|
+
}
|
|
1501
|
+
while (cursor < len && (nextState = secondState || state.go(tokens[cursor].t))) {
|
|
1502
|
+
secondState = null;
|
|
1503
|
+
state = nextState;
|
|
1504
|
+
if (state.accepts()) {
|
|
1505
|
+
sinceAccepts = 0;
|
|
1506
|
+
latestAccepting = state;
|
|
1507
|
+
} else if (sinceAccepts >= 0) {
|
|
1508
|
+
sinceAccepts++;
|
|
1509
|
+
}
|
|
1510
|
+
cursor++;
|
|
1511
|
+
multiLength++;
|
|
1512
|
+
}
|
|
1513
|
+
if (sinceAccepts < 0) {
|
|
1514
|
+
cursor -= multiLength;
|
|
1515
|
+
if (cursor < len) {
|
|
1516
|
+
textTokens.push(tokens[cursor]);
|
|
1517
|
+
cursor++;
|
|
1518
|
+
}
|
|
1519
|
+
} else {
|
|
1520
|
+
if (textTokens.length > 0) {
|
|
1521
|
+
multis.push(initMultiToken(Text, input, textTokens));
|
|
1522
|
+
textTokens = [];
|
|
1523
|
+
}
|
|
1524
|
+
cursor -= sinceAccepts;
|
|
1525
|
+
multiLength -= sinceAccepts;
|
|
1526
|
+
const Multi = latestAccepting.t;
|
|
1527
|
+
const subtokens = tokens.slice(cursor - multiLength, cursor);
|
|
1528
|
+
multis.push(initMultiToken(Multi, input, subtokens));
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
if (textTokens.length > 0) {
|
|
1532
|
+
multis.push(initMultiToken(Text, input, textTokens));
|
|
1533
|
+
}
|
|
1534
|
+
return multis;
|
|
1535
|
+
}
|
|
1536
|
+
function initMultiToken(Multi, input, tokens) {
|
|
1537
|
+
const startIdx = tokens[0].s;
|
|
1538
|
+
const endIdx = tokens[tokens.length - 1].e;
|
|
1539
|
+
const value = input.slice(startIdx, endIdx);
|
|
1540
|
+
return new Multi(value, tokens);
|
|
1541
|
+
}
|
|
1542
|
+
var INIT = {
|
|
1543
|
+
scanner: null,
|
|
1544
|
+
parser: null,
|
|
1545
|
+
tokenQueue: [],
|
|
1546
|
+
pluginQueue: [],
|
|
1547
|
+
customSchemes: [],
|
|
1548
|
+
initialized: false
|
|
1549
|
+
};
|
|
1550
|
+
function init() {
|
|
1551
|
+
INIT.scanner = init$2(INIT.customSchemes);
|
|
1552
|
+
for (let i = 0; i < INIT.tokenQueue.length; i++) {
|
|
1553
|
+
INIT.tokenQueue[i][1]({
|
|
1554
|
+
scanner: INIT.scanner
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
INIT.parser = init$1(INIT.scanner.tokens);
|
|
1558
|
+
for (let i = 0; i < INIT.pluginQueue.length; i++) {
|
|
1559
|
+
INIT.pluginQueue[i][1]({
|
|
1560
|
+
scanner: INIT.scanner,
|
|
1561
|
+
parser: INIT.parser
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
INIT.initialized = true;
|
|
1565
|
+
return INIT;
|
|
1566
|
+
}
|
|
1567
|
+
function tokenize(str) {
|
|
1568
|
+
if (!INIT.initialized) {
|
|
1569
|
+
init();
|
|
1570
|
+
}
|
|
1571
|
+
return run(INIT.parser.start, str, run$1(INIT.scanner.start, str));
|
|
1572
|
+
}
|
|
1573
|
+
tokenize.scan = run$1;
|
|
1574
|
+
function find(str, type = null, opts = null) {
|
|
1575
|
+
if (type && typeof type === "object") {
|
|
1576
|
+
if (opts) {
|
|
1577
|
+
throw Error(`linkifyjs: Invalid link type ${type}; must be a string`);
|
|
1578
|
+
}
|
|
1579
|
+
opts = type;
|
|
1580
|
+
type = null;
|
|
1581
|
+
}
|
|
1582
|
+
const options = new Options(opts);
|
|
1583
|
+
const tokens = tokenize(str);
|
|
1584
|
+
const filtered = [];
|
|
1585
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
1586
|
+
const token = tokens[i];
|
|
1587
|
+
if (token.isLink && (!type || token.t === type) && options.check(token)) {
|
|
1588
|
+
filtered.push(token.toFormattedObject(options));
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
return filtered;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
// src/extensions/base/link.ts
|
|
1595
|
+
var hostnameOf = (url) => {
|
|
1596
|
+
try {
|
|
1597
|
+
return new URL(url).hostname.toLowerCase();
|
|
1598
|
+
} catch {
|
|
1599
|
+
return null;
|
|
1600
|
+
}
|
|
1601
|
+
};
|
|
1602
|
+
var isSameDomain = (url) => {
|
|
1603
|
+
if (typeof window === "undefined") return false;
|
|
1604
|
+
return hostnameOf(url) === window.location.hostname;
|
|
1605
|
+
};
|
|
1606
|
+
var matchesDomains = (url, domains) => {
|
|
1607
|
+
const hostname = hostnameOf(url);
|
|
1608
|
+
if (hostname === null) return false;
|
|
1609
|
+
return domains.some((candidate) => {
|
|
1610
|
+
const domain2 = candidate.toLowerCase();
|
|
1611
|
+
return hostname === domain2 || hostname.endsWith(`.${domain2}`);
|
|
1612
|
+
});
|
|
1613
|
+
};
|
|
1614
|
+
var isOwnDomain = (url, ownDomains) => isSameDomain(url) || matchesDomains(url, ownDomains);
|
|
1615
|
+
var isTrustedDomain = (url, trustedDomains) => isSameDomain(url) || matchesDomains(url, trustedDomains);
|
|
1616
|
+
var linkAttributes = (href, { ownDomains, trustedDomains }) => {
|
|
1617
|
+
const own = isOwnDomain(href, ownDomains);
|
|
1618
|
+
return {
|
|
1619
|
+
target: own ? "_self" : "_blank",
|
|
1620
|
+
rel: own || isTrustedDomain(href, trustedDomains) ? null : "noopener noreferrer nofollow"
|
|
1621
|
+
};
|
|
1622
|
+
};
|
|
1623
|
+
var LinkExtension = import_extension_link.default.extend({
|
|
1624
|
+
addOptions() {
|
|
1625
|
+
return {
|
|
1626
|
+
...this.parent?.() ?? {},
|
|
1627
|
+
ownDomains: [],
|
|
1628
|
+
trustedDomains: []
|
|
1629
|
+
};
|
|
1630
|
+
},
|
|
1631
|
+
addAttributes() {
|
|
1632
|
+
const domains = this.options;
|
|
1633
|
+
return {
|
|
1634
|
+
...this.parent?.(),
|
|
1635
|
+
target: {
|
|
1636
|
+
default: "_blank",
|
|
1637
|
+
parseHTML: (element) => linkAttributes(element.getAttribute("href") ?? "", domains).target
|
|
1638
|
+
},
|
|
1639
|
+
rel: {
|
|
1640
|
+
default: null,
|
|
1641
|
+
parseHTML: (element) => linkAttributes(element.getAttribute("href") ?? "", domains).rel
|
|
1642
|
+
}
|
|
1643
|
+
};
|
|
1644
|
+
},
|
|
1645
|
+
addPasteRules() {
|
|
1646
|
+
if (!this.options.linkOnPaste) {
|
|
1647
|
+
return this.parent?.() ?? [];
|
|
1648
|
+
}
|
|
1649
|
+
const { protocols, defaultProtocol } = this.options;
|
|
1650
|
+
return [
|
|
1651
|
+
(0, import_core4.markPasteRule)({
|
|
1652
|
+
find: (text) => find(text).filter(
|
|
1653
|
+
(link) => link.isLink && this.options.isAllowedUri(link.value, {
|
|
1654
|
+
defaultValidate: (href) => !!(0, import_extension_link.isAllowedUri)(href, protocols),
|
|
1655
|
+
protocols,
|
|
1656
|
+
defaultProtocol
|
|
1657
|
+
})
|
|
1658
|
+
).filter(
|
|
1659
|
+
(link) => this.options.shouldAutoLink?.(link.value) !== false
|
|
1660
|
+
).map((link) => ({
|
|
1661
|
+
text: link.value,
|
|
1662
|
+
data: { href: link.href },
|
|
1663
|
+
index: link.start
|
|
1664
|
+
})),
|
|
1665
|
+
type: this.type,
|
|
1666
|
+
getAttributes: (match) => {
|
|
1667
|
+
const href = match.data?.href ?? "";
|
|
1668
|
+
return { href, ...linkAttributes(href, this.options) };
|
|
1669
|
+
}
|
|
1670
|
+
})
|
|
1671
|
+
];
|
|
1672
|
+
},
|
|
1673
|
+
addProseMirrorPlugins() {
|
|
1674
|
+
return [
|
|
1675
|
+
...this.parent?.() ?? [],
|
|
1676
|
+
new import_state3.Plugin({
|
|
1677
|
+
props: {
|
|
1678
|
+
handleClick: (view, pos) => {
|
|
1679
|
+
if (!view.editable) return false;
|
|
1680
|
+
const range = (0, import_core4.getMarkRange)(view.state.doc.resolve(pos), this.type);
|
|
1681
|
+
if (!range) return false;
|
|
1682
|
+
const selection = import_state3.TextSelection.create(
|
|
1683
|
+
view.state.doc,
|
|
1684
|
+
range.from,
|
|
1685
|
+
range.to
|
|
1686
|
+
);
|
|
1687
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
1688
|
+
return true;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
})
|
|
1692
|
+
];
|
|
1693
|
+
}
|
|
1694
|
+
}).configure({
|
|
1695
|
+
openOnClick: false,
|
|
1696
|
+
linkOnPaste: true,
|
|
1697
|
+
autolink: true,
|
|
1698
|
+
protocols: ["http", "https", "mailto", "tel"]
|
|
1699
|
+
});
|
|
1700
|
+
|
|
1701
|
+
// src/extensions/base/myth-reality.ts
|
|
1702
|
+
var import_core5 = require("@tiptap/core");
|
|
1703
|
+
var BaseMythRealityBlock = import_core5.Node.create({
|
|
1704
|
+
name: "mythRealityBlock",
|
|
1705
|
+
group: "block",
|
|
1706
|
+
content: "block+",
|
|
1707
|
+
parseHTML() {
|
|
1708
|
+
return [{ tag: "div[data-myth-reality-block]" }];
|
|
1709
|
+
},
|
|
1710
|
+
renderHTML({ HTMLAttributes }) {
|
|
1711
|
+
return [
|
|
1712
|
+
"div",
|
|
1713
|
+
(0, import_core5.mergeAttributes)(HTMLAttributes, { "data-myth-reality-block": "" }),
|
|
1714
|
+
["div", { class: "myth-reality-block-content" }, 0]
|
|
1715
|
+
];
|
|
1716
|
+
}
|
|
1717
|
+
});
|
|
1718
|
+
var BaseMythReality = import_core5.Node.create({
|
|
1719
|
+
name: "mythReality",
|
|
1720
|
+
group: "block",
|
|
1721
|
+
content: "(mythRealityBlock) (mythRealityBlock)",
|
|
1722
|
+
draggable: true,
|
|
1723
|
+
isolating: true,
|
|
1724
|
+
parseHTML() {
|
|
1725
|
+
return [{ tag: "div[data-myth-reality]" }];
|
|
1726
|
+
},
|
|
1727
|
+
renderHTML({ HTMLAttributes }) {
|
|
1728
|
+
return ["div", (0, import_core5.mergeAttributes)(HTMLAttributes, { "data-myth-reality": "" }), 0];
|
|
1729
|
+
},
|
|
1730
|
+
addKeyboardShortcuts() {
|
|
1731
|
+
return {
|
|
1732
|
+
Enter: () => handleExitNode(this.editor, this.name)
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
});
|
|
1736
|
+
|
|
1737
|
+
// src/extensions/base/prompt.ts
|
|
1738
|
+
var import_core6 = require("@tiptap/core");
|
|
1739
|
+
var import_state4 = require("@tiptap/pm/state");
|
|
1740
|
+
var BasePrompt = import_core6.Node.create({
|
|
1741
|
+
name: "prompt",
|
|
1742
|
+
group: "block",
|
|
1743
|
+
content: "(promptHeader | promptV2Header) (promptContent | promptV2Content)",
|
|
1744
|
+
selectable: false,
|
|
1745
|
+
draggable: true,
|
|
1746
|
+
addKeyboardShortcuts() {
|
|
1747
|
+
return {
|
|
1748
|
+
Enter: () => {
|
|
1749
|
+
const { view, schema } = this.editor;
|
|
1750
|
+
const { state } = view;
|
|
1751
|
+
const { selection } = state;
|
|
1752
|
+
const $pos = selection.$from;
|
|
1753
|
+
let depth = $pos.depth;
|
|
1754
|
+
let isInsidePrompt = false;
|
|
1755
|
+
while (depth > 0) {
|
|
1756
|
+
const parentNode = $pos.node(depth);
|
|
1757
|
+
if (parentNode.type.name === this.name) {
|
|
1758
|
+
isInsidePrompt = true;
|
|
1759
|
+
break;
|
|
1760
|
+
}
|
|
1761
|
+
depth--;
|
|
1762
|
+
}
|
|
1763
|
+
if (!isInsidePrompt) {
|
|
1764
|
+
return false;
|
|
1765
|
+
}
|
|
1766
|
+
const { tr: tr2 } = state;
|
|
1767
|
+
const posAfter = $pos.after(depth);
|
|
1768
|
+
const paragraphNode = schema.nodes.paragraph.createAndFill();
|
|
1769
|
+
if (!paragraphNode) return false;
|
|
1770
|
+
tr2.insert(posAfter, paragraphNode);
|
|
1771
|
+
tr2.setSelection(import_state4.TextSelection.create(tr2.doc, posAfter + 1));
|
|
1772
|
+
view.dispatch(tr2);
|
|
1773
|
+
return true;
|
|
1774
|
+
}
|
|
1775
|
+
};
|
|
1776
|
+
},
|
|
1777
|
+
parseHTML() {
|
|
1778
|
+
return [
|
|
1779
|
+
{
|
|
1780
|
+
tag: "div[data-prompt]"
|
|
1781
|
+
}
|
|
1782
|
+
];
|
|
1783
|
+
},
|
|
1784
|
+
renderHTML({ HTMLAttributes }) {
|
|
1785
|
+
return ["div", (0, import_core6.mergeAttributes)(HTMLAttributes, { "data-prompt": "" }), 0];
|
|
1786
|
+
}
|
|
1787
|
+
});
|
|
1788
|
+
var BasePromptHeader = import_core6.Node.create({
|
|
1789
|
+
name: "promptHeader",
|
|
1790
|
+
group: "block",
|
|
1791
|
+
content: "inline*",
|
|
1792
|
+
selectable: true,
|
|
1793
|
+
draggable: false,
|
|
1794
|
+
parseHTML() {
|
|
1795
|
+
return [
|
|
1796
|
+
{
|
|
1797
|
+
tag: "div[data-prompt-header]"
|
|
1798
|
+
}
|
|
1799
|
+
];
|
|
1800
|
+
},
|
|
1801
|
+
renderHTML({ HTMLAttributes }) {
|
|
1802
|
+
return ["div", (0, import_core6.mergeAttributes)(HTMLAttributes, { "data-prompt-header": "" }), 0];
|
|
1803
|
+
}
|
|
1804
|
+
// addNodeView() {
|
|
1805
|
+
// return ReactNodeViewRenderer(PromptHeaderView);
|
|
1806
|
+
// },
|
|
1807
|
+
});
|
|
1808
|
+
var BasePromptContent = import_core6.Node.create({
|
|
1809
|
+
name: "promptContent",
|
|
1810
|
+
group: "block",
|
|
1811
|
+
content: "text*",
|
|
1812
|
+
draggable: false,
|
|
1813
|
+
selectable: true,
|
|
1814
|
+
parseHTML() {
|
|
1815
|
+
return [
|
|
1816
|
+
{
|
|
1817
|
+
tag: "div[data-prompt-content]"
|
|
1818
|
+
}
|
|
1819
|
+
];
|
|
1820
|
+
},
|
|
1821
|
+
renderHTML({ HTMLAttributes }) {
|
|
1822
|
+
return ["div", (0, import_core6.mergeAttributes)(HTMLAttributes, { "data-prompt-content": "" }), 0];
|
|
1823
|
+
}
|
|
1824
|
+
// addNodeView() {
|
|
1825
|
+
// return ReactNodeViewRenderer(PromptContentView);
|
|
1826
|
+
// },
|
|
1827
|
+
});
|
|
1828
|
+
|
|
1829
|
+
// src/extensions/base/video.ts
|
|
1830
|
+
var import_core7 = require("@tiptap/core");
|
|
1831
|
+
var BaseVideo = import_core7.Node.create({
|
|
1832
|
+
name: "video",
|
|
1833
|
+
group: "block",
|
|
1834
|
+
selectable: true,
|
|
1835
|
+
draggable: true,
|
|
1836
|
+
isolating: true,
|
|
1837
|
+
addAttributes() {
|
|
1838
|
+
return {
|
|
1839
|
+
src: {
|
|
1840
|
+
default: null
|
|
1841
|
+
}
|
|
1842
|
+
};
|
|
1843
|
+
},
|
|
1844
|
+
parseHTML() {
|
|
1845
|
+
return [
|
|
1846
|
+
{
|
|
1847
|
+
tag: "video-embed"
|
|
1848
|
+
}
|
|
1849
|
+
];
|
|
1850
|
+
},
|
|
1851
|
+
renderHTML({ HTMLAttributes }) {
|
|
1852
|
+
return ["video-embed", HTMLAttributes];
|
|
1853
|
+
}
|
|
1854
|
+
});
|
|
1855
|
+
|
|
1856
|
+
// src/extensions/base/figure.ts
|
|
1857
|
+
var import_core8 = require("@tiptap/core");
|
|
1858
|
+
var import_extension_image = __toESM(require("@tiptap/extension-image"));
|
|
1859
|
+
|
|
1860
|
+
// src/utils/image-src-resolver.ts
|
|
1861
|
+
function resolveImageSrc(attrs, options) {
|
|
1862
|
+
const { fileId, src } = attrs;
|
|
1863
|
+
const { getImageById } = options || {};
|
|
1864
|
+
if (fileId && getImageById) {
|
|
1865
|
+
const resolvedSrc = getImageById(fileId);
|
|
1866
|
+
if (resolvedSrc) {
|
|
1867
|
+
return resolvedSrc;
|
|
1868
|
+
}
|
|
1869
|
+
console.warn(`Failed to resolve fileId: ${fileId}`);
|
|
1870
|
+
return "";
|
|
1871
|
+
}
|
|
1872
|
+
if (src) {
|
|
1873
|
+
return src;
|
|
1874
|
+
}
|
|
1875
|
+
if (fileId) {
|
|
1876
|
+
console.warn("fileId provided but no getImageById function - cannot resolve image");
|
|
1877
|
+
return "";
|
|
1878
|
+
}
|
|
1879
|
+
return "";
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
// src/extensions/base/figure.ts
|
|
1883
|
+
var BaseFigure = import_extension_image.default.extend({
|
|
1884
|
+
name: "image",
|
|
1885
|
+
group: "block",
|
|
1886
|
+
content: "",
|
|
1887
|
+
draggable: true,
|
|
1888
|
+
isolating: true,
|
|
1889
|
+
selectable: false,
|
|
1890
|
+
addOptions() {
|
|
1891
|
+
const parentOptions = this.parent?.() || {};
|
|
1892
|
+
return {
|
|
1893
|
+
...parentOptions,
|
|
1894
|
+
getImageById: void 0,
|
|
1895
|
+
onFigureClick: void 0
|
|
1896
|
+
};
|
|
1897
|
+
},
|
|
1898
|
+
addAttributes() {
|
|
1899
|
+
return {
|
|
1900
|
+
...this.parent?.(),
|
|
1901
|
+
src: {
|
|
1902
|
+
default: null,
|
|
1903
|
+
parseHTML: (element) => {
|
|
1904
|
+
const img = element.tagName === "FIGURE" ? element.querySelector("img") : element;
|
|
1905
|
+
return img?.getAttribute("src") ?? null;
|
|
1906
|
+
}
|
|
1907
|
+
},
|
|
1908
|
+
alt: {
|
|
1909
|
+
default: null,
|
|
1910
|
+
parseHTML: (element) => {
|
|
1911
|
+
const img = element.tagName === "FIGURE" ? element.querySelector("img") : element;
|
|
1912
|
+
return img?.getAttribute("alt") ?? null;
|
|
1913
|
+
}
|
|
1914
|
+
},
|
|
1915
|
+
title: {
|
|
1916
|
+
default: null,
|
|
1917
|
+
parseHTML: (element) => {
|
|
1918
|
+
const img = element.tagName === "FIGURE" ? element.querySelector("img") : element;
|
|
1919
|
+
return img?.getAttribute("title") ?? null;
|
|
1920
|
+
}
|
|
1921
|
+
},
|
|
1922
|
+
width: {
|
|
1923
|
+
default: null,
|
|
1924
|
+
parseHTML: (element) => {
|
|
1925
|
+
const img = element.tagName === "FIGURE" ? element.querySelector("img") : element;
|
|
1926
|
+
const val = img?.getAttribute("width");
|
|
1927
|
+
return val ? parseInt(val) : null;
|
|
1928
|
+
}
|
|
1929
|
+
},
|
|
1930
|
+
height: {
|
|
1931
|
+
default: null,
|
|
1932
|
+
parseHTML: (element) => {
|
|
1933
|
+
const img = element.tagName === "FIGURE" ? element.querySelector("img") : element;
|
|
1934
|
+
const val = img?.getAttribute("height");
|
|
1935
|
+
return val ? parseInt(val) : null;
|
|
1936
|
+
}
|
|
1937
|
+
},
|
|
1938
|
+
fileId: {
|
|
1939
|
+
default: null,
|
|
1940
|
+
parseHTML: (element) => {
|
|
1941
|
+
const img = element.querySelector("img") || element;
|
|
1942
|
+
return img.getAttribute("data-file-id") || element.getAttribute("data-file-id");
|
|
1943
|
+
},
|
|
1944
|
+
renderHTML: (attributes) => {
|
|
1945
|
+
if (!attributes.fileId) return {};
|
|
1946
|
+
return { "data-file-id": attributes.fileId };
|
|
1947
|
+
}
|
|
1948
|
+
},
|
|
1949
|
+
caption: {
|
|
1950
|
+
default: null,
|
|
1951
|
+
parseHTML: (element) => element.querySelector("figcaption")?.textContent || null
|
|
1952
|
+
},
|
|
1953
|
+
storageKey: {
|
|
1954
|
+
default: null,
|
|
1955
|
+
parseHTML: (element) => element.getAttribute("data-storage-key"),
|
|
1956
|
+
renderHTML: (attributes) => ({
|
|
1957
|
+
"data-storage-key": attributes.storageKey
|
|
1958
|
+
})
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
},
|
|
1962
|
+
parseHTML() {
|
|
1963
|
+
return [
|
|
1964
|
+
{
|
|
1965
|
+
tag: "figure",
|
|
1966
|
+
getAttrs: (element) => {
|
|
1967
|
+
if (typeof element === "string") return false;
|
|
1968
|
+
const img = element.querySelector("img");
|
|
1969
|
+
return img ? {} : false;
|
|
1970
|
+
}
|
|
1971
|
+
},
|
|
1972
|
+
{
|
|
1973
|
+
tag: "img[src]",
|
|
1974
|
+
getAttrs: (element) => {
|
|
1975
|
+
if (typeof element === "string") return false;
|
|
1976
|
+
return {};
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
];
|
|
1980
|
+
},
|
|
1981
|
+
renderHTML({ node }) {
|
|
1982
|
+
const resolvedSrc = resolveImageSrc(
|
|
1983
|
+
{
|
|
1984
|
+
fileId: node.attrs.fileId,
|
|
1985
|
+
src: node.attrs.src
|
|
1986
|
+
},
|
|
1987
|
+
{ getImageById: this.options.getImageById }
|
|
1988
|
+
);
|
|
1989
|
+
const figureAttrs = (0, import_core8.mergeAttributes)(this.options.HTMLAttributes);
|
|
1990
|
+
const imgAttrs = {
|
|
1991
|
+
src: resolvedSrc
|
|
1992
|
+
};
|
|
1993
|
+
if (node.attrs.fileId) imgAttrs["data-file-id"] = node.attrs.fileId;
|
|
1994
|
+
if (node.attrs.alt) imgAttrs.alt = node.attrs.alt;
|
|
1995
|
+
if (node.attrs.title) imgAttrs.title = node.attrs.title;
|
|
1996
|
+
if (node.attrs.width) imgAttrs.width = node.attrs.width;
|
|
1997
|
+
if (node.attrs.height) imgAttrs.height = node.attrs.height;
|
|
1998
|
+
const hasCaption = node.attrs.caption && node.attrs.caption.trim().length > 0;
|
|
1999
|
+
const figcaptionContent = hasCaption ? ["figcaption", {}, node.attrs.caption] : null;
|
|
2000
|
+
return [
|
|
2001
|
+
"figure",
|
|
2002
|
+
figureAttrs,
|
|
2003
|
+
["img", imgAttrs],
|
|
2004
|
+
...figcaptionContent ? [figcaptionContent] : []
|
|
2005
|
+
];
|
|
2006
|
+
},
|
|
2007
|
+
addCommands() {
|
|
2008
|
+
return {
|
|
2009
|
+
...this.parent?.(),
|
|
2010
|
+
setFigure: (options) => ({ commands }) => {
|
|
2011
|
+
return commands.insertContent({
|
|
2012
|
+
type: this.name,
|
|
2013
|
+
attrs: options
|
|
2014
|
+
});
|
|
2015
|
+
},
|
|
2016
|
+
updateFigure: (options) => ({ commands }) => {
|
|
2017
|
+
return commands.updateAttributes(this.name, options);
|
|
2018
|
+
}
|
|
2019
|
+
};
|
|
2020
|
+
},
|
|
2021
|
+
addPasteRules() {
|
|
2022
|
+
return [
|
|
2023
|
+
(0, import_core8.nodePasteRule)({
|
|
2024
|
+
find: /!\[(.*?)\]\((.*?)(?:\s+"(.*?)")?\)/g,
|
|
2025
|
+
type: this.type,
|
|
2026
|
+
getAttributes: (match) => {
|
|
2027
|
+
const [, alt, src, title] = match;
|
|
2028
|
+
return { src, alt, title };
|
|
2029
|
+
}
|
|
2030
|
+
})
|
|
2031
|
+
];
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2034
|
+
|
|
2035
|
+
// src/utils/get-shared-extensions.ts
|
|
2036
|
+
var import_starter_kit = __toESM(require("@tiptap/starter-kit"));
|
|
2037
|
+
var import_extension_details = require("@tiptap/extension-details");
|
|
2038
|
+
var import_extension_highlight = __toESM(require("@tiptap/extension-highlight"));
|
|
2039
|
+
var import_extension_subscript = __toESM(require("@tiptap/extension-subscript"));
|
|
2040
|
+
var import_extension_superscript = __toESM(require("@tiptap/extension-superscript"));
|
|
2041
|
+
var import_extension_text_align = __toESM(require("@tiptap/extension-text-align"));
|
|
2042
|
+
|
|
2043
|
+
// node_modules/@tiptap/extension-text-style/dist/index.js
|
|
2044
|
+
var import_core9 = require("@tiptap/core");
|
|
2045
|
+
var MAX_FIND_CHILD_SPAN_DEPTH = 20;
|
|
2046
|
+
var findChildSpans = (element, depth = 0) => {
|
|
2047
|
+
const childSpans = [];
|
|
2048
|
+
if (!element.children.length || depth > MAX_FIND_CHILD_SPAN_DEPTH) return childSpans;
|
|
2049
|
+
Array.from(element.children).forEach((child) => {
|
|
2050
|
+
if (child.tagName === "SPAN") childSpans.push(child);
|
|
2051
|
+
else if (child.children.length) childSpans.push(...findChildSpans(child, depth + 1));
|
|
2052
|
+
});
|
|
2053
|
+
return childSpans;
|
|
2054
|
+
};
|
|
2055
|
+
var mergeNestedSpanStyles = (element) => {
|
|
2056
|
+
if (!element.children.length) return;
|
|
2057
|
+
const childSpans = findChildSpans(element);
|
|
2058
|
+
if (!childSpans) return;
|
|
2059
|
+
childSpans.forEach((childSpan) => {
|
|
2060
|
+
var _childSpan$parentElem;
|
|
2061
|
+
const childStyle = childSpan.getAttribute("style");
|
|
2062
|
+
const closestParentSpanStyleOfChild = (_childSpan$parentElem = childSpan.parentElement) === null || _childSpan$parentElem === void 0 || (_childSpan$parentElem = _childSpan$parentElem.closest("span")) === null || _childSpan$parentElem === void 0 ? void 0 : _childSpan$parentElem.getAttribute("style");
|
|
2063
|
+
childSpan.setAttribute("style", `${closestParentSpanStyleOfChild};${childStyle}`);
|
|
2064
|
+
});
|
|
2065
|
+
};
|
|
2066
|
+
var TextStyle = import_core9.Mark.create({
|
|
2067
|
+
name: "textStyle",
|
|
2068
|
+
priority: 101,
|
|
2069
|
+
addOptions() {
|
|
2070
|
+
return {
|
|
2071
|
+
HTMLAttributes: {},
|
|
2072
|
+
mergeNestedSpanStyles: true
|
|
2073
|
+
};
|
|
2074
|
+
},
|
|
2075
|
+
parseHTML() {
|
|
2076
|
+
return [{
|
|
2077
|
+
tag: "span",
|
|
2078
|
+
consuming: false,
|
|
2079
|
+
getAttrs: (element) => {
|
|
2080
|
+
if (!element.hasAttribute("style")) return false;
|
|
2081
|
+
if (this.options.mergeNestedSpanStyles) mergeNestedSpanStyles(element);
|
|
2082
|
+
return {};
|
|
2083
|
+
}
|
|
2084
|
+
}];
|
|
2085
|
+
},
|
|
2086
|
+
renderHTML({ HTMLAttributes }) {
|
|
2087
|
+
return [
|
|
2088
|
+
"span",
|
|
2089
|
+
(0, import_core9.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),
|
|
2090
|
+
0
|
|
2091
|
+
];
|
|
2092
|
+
},
|
|
2093
|
+
addCommands() {
|
|
2094
|
+
return {
|
|
2095
|
+
toggleTextStyle: (attributes) => ({ commands }) => {
|
|
2096
|
+
return commands.toggleMark(this.name, attributes);
|
|
2097
|
+
},
|
|
2098
|
+
removeEmptyTextStyle: () => ({ tr: tr2 }) => {
|
|
2099
|
+
const { selection } = tr2;
|
|
2100
|
+
tr2.doc.nodesBetween(selection.from, selection.to, (node, pos) => {
|
|
2101
|
+
if (!node.isInline) return true;
|
|
2102
|
+
if (!node.marks.filter((mark) => mark.type === this.type).some((mark) => Object.values(mark.attrs).some((value) => !!value))) tr2.removeMark(pos, pos + node.nodeSize, this.type);
|
|
2103
|
+
});
|
|
2104
|
+
return true;
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
var BackgroundColor = import_core9.Extension.create({
|
|
2110
|
+
name: "backgroundColor",
|
|
2111
|
+
addOptions() {
|
|
2112
|
+
return { types: ["textStyle"] };
|
|
2113
|
+
},
|
|
2114
|
+
addGlobalAttributes() {
|
|
2115
|
+
return [{
|
|
2116
|
+
types: this.options.types,
|
|
2117
|
+
attributes: { backgroundColor: {
|
|
2118
|
+
default: null,
|
|
2119
|
+
parseHTML: (element) => {
|
|
2120
|
+
var _getStyleProperty;
|
|
2121
|
+
const value = (_getStyleProperty = (0, import_core9.getStyleProperty)(element, "background-color")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.backgroundColor;
|
|
2122
|
+
return value === null || value === void 0 ? void 0 : value.replace(/['"]+/g, "");
|
|
2123
|
+
},
|
|
2124
|
+
renderHTML: (attributes) => {
|
|
2125
|
+
if (!attributes.backgroundColor) return {};
|
|
2126
|
+
return { style: `background-color: ${attributes.backgroundColor}` };
|
|
2127
|
+
}
|
|
2128
|
+
} }
|
|
2129
|
+
}];
|
|
2130
|
+
},
|
|
2131
|
+
addCommands() {
|
|
2132
|
+
return {
|
|
2133
|
+
setBackgroundColor: (backgroundColor) => ({ chain }) => {
|
|
2134
|
+
return chain().setMark("textStyle", { backgroundColor }).run();
|
|
2135
|
+
},
|
|
2136
|
+
unsetBackgroundColor: () => ({ chain }) => {
|
|
2137
|
+
return chain().setMark("textStyle", { backgroundColor: null }).removeEmptyTextStyle().run();
|
|
2138
|
+
}
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2142
|
+
var Color = import_core9.Extension.create({
|
|
2143
|
+
name: "color",
|
|
2144
|
+
addOptions() {
|
|
2145
|
+
return { types: ["textStyle"] };
|
|
2146
|
+
},
|
|
2147
|
+
addGlobalAttributes() {
|
|
2148
|
+
return [{
|
|
2149
|
+
types: this.options.types,
|
|
2150
|
+
attributes: { color: {
|
|
2151
|
+
default: null,
|
|
2152
|
+
parseHTML: (element) => {
|
|
2153
|
+
var _getStyleProperty;
|
|
2154
|
+
const value = (_getStyleProperty = (0, import_core9.getStyleProperty)(element, "color")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.color;
|
|
2155
|
+
return value === null || value === void 0 ? void 0 : value.replace(/['"]+/g, "");
|
|
2156
|
+
},
|
|
2157
|
+
renderHTML: (attributes) => {
|
|
2158
|
+
if (!attributes.color) return {};
|
|
2159
|
+
return { style: `color: ${attributes.color}` };
|
|
2160
|
+
}
|
|
2161
|
+
} }
|
|
2162
|
+
}];
|
|
2163
|
+
},
|
|
2164
|
+
addCommands() {
|
|
2165
|
+
return {
|
|
2166
|
+
setColor: (color) => ({ chain }) => {
|
|
2167
|
+
return chain().setMark("textStyle", { color }).run();
|
|
2168
|
+
},
|
|
2169
|
+
unsetColor: () => ({ chain }) => {
|
|
2170
|
+
return chain().setMark("textStyle", { color: null }).removeEmptyTextStyle().run();
|
|
2171
|
+
}
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
});
|
|
2175
|
+
var FontFamily = import_core9.Extension.create({
|
|
2176
|
+
name: "fontFamily",
|
|
2177
|
+
addOptions() {
|
|
2178
|
+
return { types: ["textStyle"] };
|
|
2179
|
+
},
|
|
2180
|
+
addGlobalAttributes() {
|
|
2181
|
+
return [{
|
|
2182
|
+
types: this.options.types,
|
|
2183
|
+
attributes: { fontFamily: {
|
|
2184
|
+
default: null,
|
|
2185
|
+
parseHTML: (element) => {
|
|
2186
|
+
var _getStyleProperty;
|
|
2187
|
+
return (_getStyleProperty = (0, import_core9.getStyleProperty)(element, "font-family")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.fontFamily;
|
|
2188
|
+
},
|
|
2189
|
+
renderHTML: (attributes) => {
|
|
2190
|
+
if (!attributes.fontFamily) return {};
|
|
2191
|
+
return { style: `font-family: ${attributes.fontFamily}` };
|
|
2192
|
+
}
|
|
2193
|
+
} }
|
|
2194
|
+
}];
|
|
2195
|
+
},
|
|
2196
|
+
addCommands() {
|
|
2197
|
+
return {
|
|
2198
|
+
setFontFamily: (fontFamily) => ({ chain }) => {
|
|
2199
|
+
return chain().setMark("textStyle", { fontFamily }).run();
|
|
2200
|
+
},
|
|
2201
|
+
unsetFontFamily: () => ({ chain }) => {
|
|
2202
|
+
return chain().setMark("textStyle", { fontFamily: null }).removeEmptyTextStyle().run();
|
|
2203
|
+
}
|
|
2204
|
+
};
|
|
2205
|
+
}
|
|
2206
|
+
});
|
|
2207
|
+
var FontSize = import_core9.Extension.create({
|
|
2208
|
+
name: "fontSize",
|
|
2209
|
+
addOptions() {
|
|
2210
|
+
return { types: ["textStyle"] };
|
|
2211
|
+
},
|
|
2212
|
+
addGlobalAttributes() {
|
|
2213
|
+
return [{
|
|
2214
|
+
types: this.options.types,
|
|
2215
|
+
attributes: { fontSize: {
|
|
2216
|
+
default: null,
|
|
2217
|
+
parseHTML: (element) => {
|
|
2218
|
+
var _getStyleProperty;
|
|
2219
|
+
return (_getStyleProperty = (0, import_core9.getStyleProperty)(element, "font-size")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.fontSize;
|
|
2220
|
+
},
|
|
2221
|
+
renderHTML: (attributes) => {
|
|
2222
|
+
if (!attributes.fontSize) return {};
|
|
2223
|
+
return { style: `font-size: ${attributes.fontSize}` };
|
|
2224
|
+
}
|
|
2225
|
+
} }
|
|
2226
|
+
}];
|
|
2227
|
+
},
|
|
2228
|
+
addCommands() {
|
|
2229
|
+
return {
|
|
2230
|
+
setFontSize: (fontSize) => ({ chain }) => {
|
|
2231
|
+
return chain().setMark("textStyle", { fontSize }).run();
|
|
2232
|
+
},
|
|
2233
|
+
unsetFontSize: () => ({ chain }) => {
|
|
2234
|
+
return chain().setMark("textStyle", { fontSize: null }).removeEmptyTextStyle().run();
|
|
2235
|
+
}
|
|
2236
|
+
};
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2239
|
+
var LineHeight = import_core9.Extension.create({
|
|
2240
|
+
name: "lineHeight",
|
|
2241
|
+
addOptions() {
|
|
2242
|
+
return { types: ["textStyle"] };
|
|
2243
|
+
},
|
|
2244
|
+
addGlobalAttributes() {
|
|
2245
|
+
return [{
|
|
2246
|
+
types: this.options.types,
|
|
2247
|
+
attributes: { lineHeight: {
|
|
2248
|
+
default: null,
|
|
2249
|
+
parseHTML: (element) => {
|
|
2250
|
+
var _getStyleProperty;
|
|
2251
|
+
return (_getStyleProperty = (0, import_core9.getStyleProperty)(element, "line-height")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.lineHeight;
|
|
2252
|
+
},
|
|
2253
|
+
renderHTML: (attributes) => {
|
|
2254
|
+
if (!attributes.lineHeight) return {};
|
|
2255
|
+
return { style: `line-height: ${attributes.lineHeight}` };
|
|
2256
|
+
}
|
|
2257
|
+
} }
|
|
2258
|
+
}];
|
|
2259
|
+
},
|
|
2260
|
+
addCommands() {
|
|
2261
|
+
return {
|
|
2262
|
+
setLineHeight: (lineHeight) => ({ chain }) => {
|
|
2263
|
+
return chain().setMark("textStyle", { lineHeight }).run();
|
|
2264
|
+
},
|
|
2265
|
+
unsetLineHeight: () => ({ chain }) => {
|
|
2266
|
+
return chain().setMark("textStyle", { lineHeight: null }).removeEmptyTextStyle().run();
|
|
2267
|
+
}
|
|
2268
|
+
};
|
|
2269
|
+
}
|
|
2270
|
+
});
|
|
2271
|
+
var TextStyleKit = import_core9.Extension.create({
|
|
2272
|
+
name: "textStyleKit",
|
|
2273
|
+
addExtensions() {
|
|
2274
|
+
const extensions = [];
|
|
2275
|
+
if (this.options.backgroundColor !== false) extensions.push(BackgroundColor.configure(this.options.backgroundColor));
|
|
2276
|
+
if (this.options.color !== false) extensions.push(Color.configure(this.options.color));
|
|
2277
|
+
if (this.options.fontFamily !== false) extensions.push(FontFamily.configure(this.options.fontFamily));
|
|
2278
|
+
if (this.options.fontSize !== false) extensions.push(FontSize.configure(this.options.fontSize));
|
|
2279
|
+
if (this.options.lineHeight !== false) extensions.push(LineHeight.configure(this.options.lineHeight));
|
|
2280
|
+
if (this.options.textStyle !== false) extensions.push(TextStyle.configure(this.options.textStyle));
|
|
2281
|
+
return extensions;
|
|
2282
|
+
}
|
|
2283
|
+
});
|
|
2284
|
+
|
|
2285
|
+
// src/extensions/base/compatibility.ts
|
|
2286
|
+
var import_core10 = require("@tiptap/core");
|
|
2287
|
+
var import_state5 = require("@tiptap/pm/state");
|
|
2288
|
+
var import_extension_image2 = __toESM(require("@tiptap/extension-image"));
|
|
2289
|
+
var BaseLegacyBookAlert = import_core10.Node.create({
|
|
2290
|
+
name: "calloutAlert",
|
|
2291
|
+
group: "block",
|
|
2292
|
+
content: "block+",
|
|
2293
|
+
draggable: true,
|
|
2294
|
+
isolating: true,
|
|
2295
|
+
addAttributes() {
|
|
2296
|
+
return {
|
|
2297
|
+
type: {
|
|
2298
|
+
default: "error"
|
|
2299
|
+
},
|
|
2300
|
+
bgColor: {
|
|
2301
|
+
default: null,
|
|
2302
|
+
parseHTML: (element) => {
|
|
2303
|
+
if (typeof element === "string") return null;
|
|
2304
|
+
return element.getAttribute("data-bg-color");
|
|
2305
|
+
},
|
|
2306
|
+
renderHTML: (attributes) => {
|
|
2307
|
+
if (!attributes.bgColor) return {};
|
|
2308
|
+
return {
|
|
2309
|
+
"data-bg-color": attributes.bgColor
|
|
2310
|
+
};
|
|
2311
|
+
}
|
|
2312
|
+
},
|
|
2313
|
+
emoji: {
|
|
2314
|
+
default: null,
|
|
2315
|
+
parseHTML: (element) => {
|
|
2316
|
+
if (typeof element === "string") return null;
|
|
2317
|
+
return element.getAttribute("data-emoji");
|
|
2318
|
+
},
|
|
2319
|
+
renderHTML: (attributes) => {
|
|
2320
|
+
if (!attributes.emoji) return {};
|
|
2321
|
+
return {
|
|
2322
|
+
"data-emoji": attributes.emoji
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
},
|
|
2328
|
+
parseHTML() {
|
|
2329
|
+
return [
|
|
2330
|
+
{
|
|
2331
|
+
tag: 'div[data-type="callout-alert"]'
|
|
2332
|
+
}
|
|
2333
|
+
];
|
|
2334
|
+
},
|
|
2335
|
+
addKeyboardShortcuts() {
|
|
2336
|
+
return {
|
|
2337
|
+
Enter: () => handleExitNode(this.editor, this.name)
|
|
2338
|
+
};
|
|
2339
|
+
},
|
|
2340
|
+
renderHTML({ HTMLAttributes }) {
|
|
2341
|
+
return ["div", (0, import_core10.mergeAttributes)(HTMLAttributes, { "data-type": "callout-alert" }), 0];
|
|
2342
|
+
}
|
|
2343
|
+
});
|
|
2344
|
+
var BaseLegacyBookTip = import_core10.Node.create({
|
|
2345
|
+
name: "calloutTip",
|
|
2346
|
+
group: "block",
|
|
2347
|
+
content: "block+",
|
|
2348
|
+
draggable: true,
|
|
2349
|
+
isolating: true,
|
|
2350
|
+
addAttributes() {
|
|
2351
|
+
return {
|
|
2352
|
+
type: {
|
|
2353
|
+
default: "info"
|
|
2354
|
+
},
|
|
2355
|
+
bgColor: {
|
|
2356
|
+
default: null,
|
|
2357
|
+
parseHTML: (element) => {
|
|
2358
|
+
if (typeof element === "string") return null;
|
|
2359
|
+
return element.getAttribute("data-bg-color");
|
|
2360
|
+
},
|
|
2361
|
+
renderHTML: (attributes) => {
|
|
2362
|
+
if (!attributes.bgColor) return {};
|
|
2363
|
+
return {
|
|
2364
|
+
"data-bg-color": attributes.bgColor
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
},
|
|
2368
|
+
emoji: {
|
|
2369
|
+
default: null,
|
|
2370
|
+
parseHTML: (element) => {
|
|
2371
|
+
if (typeof element === "string") return null;
|
|
2372
|
+
return element.getAttribute("data-emoji");
|
|
2373
|
+
},
|
|
2374
|
+
renderHTML: (attributes) => {
|
|
2375
|
+
if (!attributes.emoji) return {};
|
|
2376
|
+
return {
|
|
2377
|
+
"data-emoji": attributes.emoji
|
|
2378
|
+
};
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
};
|
|
2382
|
+
},
|
|
2383
|
+
parseHTML() {
|
|
2384
|
+
return [
|
|
2385
|
+
{
|
|
2386
|
+
tag: 'div[data-type="callout-tip"]'
|
|
2387
|
+
}
|
|
2388
|
+
];
|
|
2389
|
+
},
|
|
2390
|
+
renderHTML({ HTMLAttributes }) {
|
|
2391
|
+
return ["div", (0, import_core10.mergeAttributes)(HTMLAttributes, { "data-type": "callout-tip" }), 0];
|
|
2392
|
+
},
|
|
2393
|
+
addKeyboardShortcuts() {
|
|
2394
|
+
return {
|
|
2395
|
+
Enter: () => handleExitNode(this.editor, this.name)
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
var BaseLegacySEQuote = import_core10.Node.create({
|
|
2400
|
+
name: "customQuoteV2",
|
|
2401
|
+
group: "block",
|
|
2402
|
+
content: "customQuoteText customQuoteAuthor customQuoteSign",
|
|
2403
|
+
selectable: false,
|
|
2404
|
+
draggable: true,
|
|
2405
|
+
isolating: true,
|
|
2406
|
+
addKeyboardShortcuts() {
|
|
2407
|
+
return {
|
|
2408
|
+
Enter: () => {
|
|
2409
|
+
const { view, schema } = this.editor;
|
|
2410
|
+
const { state } = view;
|
|
2411
|
+
const { selection } = state;
|
|
2412
|
+
const $pos = selection.$from;
|
|
2413
|
+
let depth = $pos.depth;
|
|
2414
|
+
let isInsideCustomQuoteV2 = false;
|
|
2415
|
+
while (depth > 0) {
|
|
2416
|
+
const parentNode = $pos.node(depth);
|
|
2417
|
+
if (parentNode.type.name === this.name) {
|
|
2418
|
+
isInsideCustomQuoteV2 = true;
|
|
2419
|
+
break;
|
|
2420
|
+
}
|
|
2421
|
+
depth--;
|
|
2422
|
+
}
|
|
2423
|
+
if (!isInsideCustomQuoteV2) {
|
|
2424
|
+
return false;
|
|
2425
|
+
}
|
|
2426
|
+
const { tr: tr2 } = state;
|
|
2427
|
+
const posAfter = $pos.after(depth);
|
|
2428
|
+
const paragraphNode = schema.nodes.paragraph.createAndFill();
|
|
2429
|
+
if (!paragraphNode) return false;
|
|
2430
|
+
tr2.insert(posAfter, paragraphNode);
|
|
2431
|
+
tr2.setSelection(import_state5.TextSelection.create(tr2.doc, posAfter + 1));
|
|
2432
|
+
view.dispatch(tr2);
|
|
2433
|
+
return true;
|
|
2434
|
+
}
|
|
2435
|
+
};
|
|
2436
|
+
},
|
|
2437
|
+
parseHTML() {
|
|
2438
|
+
return [
|
|
2439
|
+
{
|
|
2440
|
+
tag: "div[data-custom-quote-v2]"
|
|
2441
|
+
}
|
|
2442
|
+
];
|
|
2443
|
+
},
|
|
2444
|
+
renderHTML({ HTMLAttributes }) {
|
|
2445
|
+
return ["div", (0, import_core10.mergeAttributes)(HTMLAttributes, { "data-custom-quote-v2": "" }), 0];
|
|
2446
|
+
}
|
|
2447
|
+
});
|
|
2448
|
+
var BaseLegacyPromptSE = import_core10.Node.create({
|
|
2449
|
+
name: "promptV2",
|
|
2450
|
+
group: "block",
|
|
2451
|
+
content: "(promptHeader | promptV2Header) (promptContent | promptV2Content)",
|
|
2452
|
+
selectable: false,
|
|
2453
|
+
draggable: true,
|
|
2454
|
+
addKeyboardShortcuts() {
|
|
2455
|
+
return {
|
|
2456
|
+
Enter: () => {
|
|
2457
|
+
const { view, schema } = this.editor;
|
|
2458
|
+
const { state } = view;
|
|
2459
|
+
const { selection } = state;
|
|
2460
|
+
const $pos = selection.$from;
|
|
2461
|
+
let depth = $pos.depth;
|
|
2462
|
+
let isInsidePromptV2 = false;
|
|
2463
|
+
while (depth > 0) {
|
|
2464
|
+
const parentNode = $pos.node(depth);
|
|
2465
|
+
if (parentNode.type.name === this.name) {
|
|
2466
|
+
isInsidePromptV2 = true;
|
|
2467
|
+
break;
|
|
2468
|
+
}
|
|
2469
|
+
depth--;
|
|
2470
|
+
}
|
|
2471
|
+
if (!isInsidePromptV2) {
|
|
2472
|
+
return false;
|
|
2473
|
+
}
|
|
2474
|
+
const { tr: tr2 } = state;
|
|
2475
|
+
const posAfter = $pos.after(depth);
|
|
2476
|
+
const paragraphNode = schema.nodes.paragraph.createAndFill();
|
|
2477
|
+
if (!paragraphNode) return false;
|
|
2478
|
+
tr2.insert(posAfter, paragraphNode);
|
|
2479
|
+
tr2.setSelection(import_state5.TextSelection.create(tr2.doc, posAfter + 1));
|
|
2480
|
+
view.dispatch(tr2);
|
|
2481
|
+
return true;
|
|
2482
|
+
}
|
|
2483
|
+
};
|
|
2484
|
+
},
|
|
2485
|
+
parseHTML() {
|
|
2486
|
+
return [
|
|
2487
|
+
{
|
|
2488
|
+
tag: "div[data-prompt-v2]"
|
|
2489
|
+
}
|
|
2490
|
+
];
|
|
2491
|
+
},
|
|
2492
|
+
renderHTML({ HTMLAttributes }) {
|
|
2493
|
+
return ["div", (0, import_core10.mergeAttributes)(HTMLAttributes, { "data-prompt": "" }), 0];
|
|
2494
|
+
}
|
|
2495
|
+
});
|
|
2496
|
+
var BaseLegacyPromptSEHeader = import_core10.Node.create({
|
|
2497
|
+
name: "promptV2Header",
|
|
2498
|
+
group: "block",
|
|
2499
|
+
content: "inline*",
|
|
2500
|
+
selectable: true,
|
|
2501
|
+
draggable: false,
|
|
2502
|
+
parseHTML() {
|
|
2503
|
+
return [
|
|
2504
|
+
{
|
|
2505
|
+
tag: "div[data-prompt-v2-header]"
|
|
2506
|
+
}
|
|
2507
|
+
];
|
|
2508
|
+
},
|
|
2509
|
+
renderHTML({ HTMLAttributes }) {
|
|
2510
|
+
return ["div", (0, import_core10.mergeAttributes)(HTMLAttributes, { "data-prompt-header": "" }), 0];
|
|
2511
|
+
}
|
|
2512
|
+
// addNodeView() {
|
|
2513
|
+
// return ReactNodeViewRenderer(PromptHeaderView);
|
|
2514
|
+
// },
|
|
2515
|
+
});
|
|
2516
|
+
var BaseLegacyPromptSEContent = import_core10.Node.create({
|
|
2517
|
+
name: "promptV2Content",
|
|
2518
|
+
group: "block",
|
|
2519
|
+
content: "text*",
|
|
2520
|
+
draggable: false,
|
|
2521
|
+
selectable: true,
|
|
2522
|
+
parseHTML() {
|
|
2523
|
+
return [
|
|
2524
|
+
{
|
|
2525
|
+
tag: "div[data-prompt-v2-content]"
|
|
2526
|
+
}
|
|
2527
|
+
];
|
|
2528
|
+
},
|
|
2529
|
+
renderHTML({ HTMLAttributes }) {
|
|
2530
|
+
return ["div", (0, import_core10.mergeAttributes)(HTMLAttributes, { "data-prompt-content": "" }), 0];
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
var BaseLegacyCustomBlockquote = import_core10.Node.create({
|
|
2534
|
+
name: "customBlockquote",
|
|
2535
|
+
group: "block",
|
|
2536
|
+
content: "block+",
|
|
2537
|
+
draggable: true,
|
|
2538
|
+
parseHTML() {
|
|
2539
|
+
return [
|
|
2540
|
+
{
|
|
2541
|
+
tag: 'div[data-type="custom-blockquote"]'
|
|
2542
|
+
}
|
|
2543
|
+
];
|
|
2544
|
+
},
|
|
2545
|
+
renderHTML() {
|
|
2546
|
+
return ["blockquote", 0];
|
|
2547
|
+
}
|
|
2548
|
+
});
|
|
2549
|
+
var BaseLegacyYouTube = import_core10.Node.create({
|
|
2550
|
+
name: "youtube",
|
|
2551
|
+
group: "block",
|
|
2552
|
+
selectable: true,
|
|
2553
|
+
draggable: true,
|
|
2554
|
+
isolating: true,
|
|
2555
|
+
addAttributes() {
|
|
2556
|
+
return {
|
|
2557
|
+
src: {
|
|
2558
|
+
default: null
|
|
2559
|
+
},
|
|
2560
|
+
width: {
|
|
2561
|
+
default: 640
|
|
2562
|
+
},
|
|
2563
|
+
height: {
|
|
2564
|
+
default: 480
|
|
2565
|
+
},
|
|
2566
|
+
start: {
|
|
2567
|
+
default: 0
|
|
2568
|
+
}
|
|
2569
|
+
};
|
|
2570
|
+
},
|
|
2571
|
+
parseHTML() {
|
|
2572
|
+
return [
|
|
2573
|
+
{
|
|
2574
|
+
tag: 'iframe[src*="youtube.com"]'
|
|
2575
|
+
},
|
|
2576
|
+
{
|
|
2577
|
+
tag: 'iframe[src*="youtu.be"]'
|
|
2578
|
+
}
|
|
2579
|
+
];
|
|
2580
|
+
},
|
|
2581
|
+
renderHTML({ HTMLAttributes }) {
|
|
2582
|
+
return ["video-embed", { src: HTMLAttributes.src }];
|
|
2583
|
+
}
|
|
2584
|
+
});
|
|
2585
|
+
var LegacyInlineLatexSE = import_core10.Node.create({
|
|
2586
|
+
name: "inlineLatex",
|
|
2587
|
+
group: "inline",
|
|
2588
|
+
inline: true,
|
|
2589
|
+
content: "text*",
|
|
2590
|
+
atom: true,
|
|
2591
|
+
addAttributes() {
|
|
2592
|
+
return {
|
|
2593
|
+
latex: {
|
|
2594
|
+
default: "",
|
|
2595
|
+
parseHTML: (element) => element.getAttribute("data-latex") || element.textContent || ""
|
|
2596
|
+
}
|
|
2597
|
+
};
|
|
2598
|
+
},
|
|
2599
|
+
parseHTML() {
|
|
2600
|
+
return [
|
|
2601
|
+
{
|
|
2602
|
+
tag: "span.inline-latex"
|
|
2603
|
+
}
|
|
2604
|
+
];
|
|
2605
|
+
},
|
|
2606
|
+
renderHTML({ HTMLAttributes }) {
|
|
2607
|
+
return ["code", (0, import_core10.mergeAttributes)(HTMLAttributes, { class: "inline-latex" }), 0];
|
|
2608
|
+
}
|
|
2609
|
+
});
|
|
2610
|
+
var BaseLegacyFigure = import_extension_image2.default.extend({
|
|
2611
|
+
name: "figure",
|
|
2612
|
+
group: "block",
|
|
2613
|
+
content: "inline*",
|
|
2614
|
+
draggable: true,
|
|
2615
|
+
isolating: true,
|
|
2616
|
+
selectable: false,
|
|
2617
|
+
addOptions() {
|
|
2618
|
+
const parentOptions = this.parent?.() || {};
|
|
2619
|
+
return {
|
|
2620
|
+
...parentOptions,
|
|
2621
|
+
HTMLAttributes: {},
|
|
2622
|
+
getImageById: void 0
|
|
2623
|
+
};
|
|
2624
|
+
},
|
|
2625
|
+
addAttributes() {
|
|
2626
|
+
return {
|
|
2627
|
+
...this.parent?.(),
|
|
2628
|
+
fileId: {
|
|
2629
|
+
default: null,
|
|
2630
|
+
parseHTML: (element) => {
|
|
2631
|
+
const img = element.querySelector("img");
|
|
2632
|
+
const fileIdFromImg = img?.getAttribute("fileId") || img?.getAttribute("data-file-id");
|
|
2633
|
+
const fileIdFromFigure = element.getAttribute("fileId") || element.getAttribute("data-file-id");
|
|
2634
|
+
return fileIdFromImg ?? fileIdFromFigure;
|
|
2635
|
+
},
|
|
2636
|
+
renderHTML: (attributes) => {
|
|
2637
|
+
if (!attributes.fileId) return {};
|
|
2638
|
+
return { "data-file-id": attributes.fileId };
|
|
2639
|
+
}
|
|
2640
|
+
},
|
|
2641
|
+
src: {
|
|
2642
|
+
default: null,
|
|
2643
|
+
parseHTML: (element) => {
|
|
2644
|
+
const img = element.querySelector("img") || element;
|
|
2645
|
+
return img.getAttribute("src");
|
|
2646
|
+
}
|
|
2647
|
+
},
|
|
2648
|
+
alt: {
|
|
2649
|
+
default: null,
|
|
2650
|
+
parseHTML: (element) => {
|
|
2651
|
+
const img = element.querySelector("img") || element;
|
|
2652
|
+
return img.getAttribute("alt");
|
|
2653
|
+
}
|
|
2654
|
+
},
|
|
2655
|
+
title: {
|
|
2656
|
+
default: null,
|
|
2657
|
+
parseHTML: (element) => {
|
|
2658
|
+
const img = element.querySelector("img") || element;
|
|
2659
|
+
return img.getAttribute("title");
|
|
2660
|
+
}
|
|
2661
|
+
},
|
|
2662
|
+
caption: {
|
|
2663
|
+
default: null,
|
|
2664
|
+
parseHTML: (element) => {
|
|
2665
|
+
const caption = element.querySelector("figcaption");
|
|
2666
|
+
return caption ? caption.innerText : null;
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
};
|
|
2670
|
+
},
|
|
2671
|
+
parseHTML() {
|
|
2672
|
+
return [
|
|
2673
|
+
{
|
|
2674
|
+
tag: "figure",
|
|
2675
|
+
getAttrs: (element) => {
|
|
2676
|
+
if (typeof element === "string") return false;
|
|
2677
|
+
const img = element.querySelector("img");
|
|
2678
|
+
return img ? {} : false;
|
|
2679
|
+
}
|
|
2680
|
+
},
|
|
2681
|
+
{
|
|
2682
|
+
tag: "img[src]"
|
|
2683
|
+
}
|
|
2684
|
+
];
|
|
2685
|
+
},
|
|
2686
|
+
renderHTML({ node }) {
|
|
2687
|
+
const resolvedSrc = resolveImageSrc(
|
|
2688
|
+
{
|
|
2689
|
+
fileId: node.attrs.fileId,
|
|
2690
|
+
src: node.attrs.src
|
|
2691
|
+
},
|
|
2692
|
+
{ getImageById: this.options.getImageById }
|
|
2693
|
+
);
|
|
2694
|
+
const figureAttrs = (0, import_core10.mergeAttributes)(this.options.HTMLAttributes);
|
|
2695
|
+
const imgAttrs = {
|
|
2696
|
+
src: resolvedSrc
|
|
2697
|
+
};
|
|
2698
|
+
if (node.attrs.fileId) imgAttrs["data-file-id"] = node.attrs.fileId;
|
|
2699
|
+
if (node.attrs.alt) imgAttrs.alt = node.attrs.alt;
|
|
2700
|
+
if (node.attrs.title) imgAttrs.title = node.attrs.title;
|
|
2701
|
+
if (node.attrs.width) imgAttrs.width = node.attrs.width;
|
|
2702
|
+
if (node.attrs.height) imgAttrs.height = node.attrs.height;
|
|
2703
|
+
const hasCaption = node.attrs.caption && node.attrs.caption.trim().length > 0;
|
|
2704
|
+
const figcaptionContent = hasCaption ? ["figcaption", {}, node.attrs.caption] : null;
|
|
2705
|
+
return [
|
|
2706
|
+
"figure",
|
|
2707
|
+
figureAttrs,
|
|
2708
|
+
["img", imgAttrs],
|
|
2709
|
+
...figcaptionContent ? [figcaptionContent] : []
|
|
2710
|
+
];
|
|
2711
|
+
}
|
|
2712
|
+
});
|
|
2713
|
+
|
|
2714
|
+
// src/utils/get-shared-extensions.ts
|
|
2715
|
+
function getSharedExtensions(options = {}) {
|
|
2716
|
+
return [
|
|
2717
|
+
import_starter_kit.default.configure({
|
|
2718
|
+
codeBlock: false,
|
|
2719
|
+
link: false
|
|
2720
|
+
}),
|
|
2721
|
+
import_extension_highlight.default.configure({ multicolor: true }),
|
|
2722
|
+
LinkExtension.configure({
|
|
2723
|
+
ownDomains: options.ownDomains ?? [],
|
|
2724
|
+
trustedDomains: options.trustedDomains ?? []
|
|
2725
|
+
}),
|
|
2726
|
+
import_extension_superscript.default,
|
|
2727
|
+
import_extension_subscript.default,
|
|
2728
|
+
import_extension_text_align.default.configure({
|
|
2729
|
+
types: ["heading", "paragraph"]
|
|
2730
|
+
}),
|
|
2731
|
+
TextStyleKit.configure({
|
|
2732
|
+
color: {
|
|
2733
|
+
types: ["textStyle"]
|
|
2734
|
+
}
|
|
2735
|
+
}),
|
|
2736
|
+
import_extension_details.Details.configure({
|
|
2737
|
+
persist: true,
|
|
2738
|
+
HTMLAttributes: {
|
|
2739
|
+
class: "details"
|
|
2740
|
+
}
|
|
2741
|
+
}),
|
|
2742
|
+
import_extension_details.DetailsSummary,
|
|
2743
|
+
import_extension_details.DetailsContent,
|
|
2744
|
+
BaseMythReality,
|
|
2745
|
+
BaseMythRealityBlock,
|
|
2746
|
+
LegacyInlineLatexSE
|
|
2747
|
+
];
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
// src/extensions/render/get-render-extensions.ts
|
|
2751
|
+
function getRenderExtensions(options = {}) {
|
|
2752
|
+
const sharedExtensions = getSharedExtensions(options);
|
|
2753
|
+
return [
|
|
2754
|
+
...sharedExtensions,
|
|
2755
|
+
CopyableText,
|
|
2756
|
+
BaseCallout,
|
|
2757
|
+
BaseCodeBlock,
|
|
2758
|
+
BaseCustomQuote,
|
|
2759
|
+
BaseCustomQuoteText,
|
|
2760
|
+
BaseCustomQuoteAuthor,
|
|
2761
|
+
BaseCustomQuoteSign,
|
|
2762
|
+
BasePrompt,
|
|
2763
|
+
BasePromptHeader,
|
|
2764
|
+
BasePromptContent,
|
|
2765
|
+
BaseVideo,
|
|
2766
|
+
BaseFigure,
|
|
2767
|
+
import_extension_table.TableKit.configure({
|
|
2768
|
+
table: { resizable: false, renderWrapper: true }
|
|
2769
|
+
}),
|
|
2770
|
+
import_extension_mathematics.Mathematics.configure({
|
|
2771
|
+
katexOptions: {
|
|
2772
|
+
throwOnError: false
|
|
2773
|
+
}
|
|
2774
|
+
}),
|
|
2775
|
+
// ========================================================================
|
|
2776
|
+
// Legacy Extensions (Deprecated - for backward compatibility only)
|
|
2777
|
+
// ========================================================================
|
|
2778
|
+
BaseLegacyBookAlert,
|
|
2779
|
+
BaseLegacyBookTip,
|
|
2780
|
+
BaseLegacySEQuote,
|
|
2781
|
+
BaseLegacyPromptSE,
|
|
2782
|
+
BaseLegacyPromptSEHeader,
|
|
2783
|
+
BaseLegacyPromptSEContent,
|
|
2784
|
+
BaseLegacyCustomBlockquote,
|
|
2785
|
+
BaseLegacyYouTube,
|
|
2786
|
+
BaseLegacyFigure
|
|
2787
|
+
// Update
|
|
2788
|
+
];
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2791
|
+
// src/html/index.ts
|
|
2792
|
+
function tiptapContentToHtml(content, options = {}) {
|
|
2793
|
+
return (0, import_server.generateHTML)(content, getRenderExtensions(options));
|
|
2794
|
+
}
|
|
2795
|
+
function htmlToTiptapContent(html2, options = {}) {
|
|
2796
|
+
return (0, import_server.generateJSON)(html2, getRenderExtensions(options));
|
|
2797
|
+
}
|
|
2798
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2799
|
+
0 && (module.exports = {
|
|
2800
|
+
htmlToTiptapContent,
|
|
2801
|
+
tiptapContentToHtml
|
|
2802
|
+
});
|
|
2803
|
+
//# sourceMappingURL=html.js.map
|