@tiptap/extension-code-block 3.20.2 → 3.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/dist/index.cjs +0 -351
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -78
- package/dist/index.d.ts +0 -78
- package/dist/index.js +0 -322
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-code-block",
|
|
3
3
|
"description": "code block extension for tiptap",
|
|
4
|
-
"version": "3.20.
|
|
4
|
+
"version": "3.20.3",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"dist"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tiptap/
|
|
35
|
-
"@tiptap/
|
|
34
|
+
"@tiptap/pm": "^3.20.3",
|
|
35
|
+
"@tiptap/core": "^3.20.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@tiptap/
|
|
39
|
-
"@tiptap/
|
|
38
|
+
"@tiptap/core": "^3.20.3",
|
|
39
|
+
"@tiptap/pm": "^3.20.3"
|
|
40
40
|
},
|
|
41
41
|
"repository": {
|
|
42
42
|
"type": "git",
|
package/dist/index.cjs
DELETED
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
CodeBlock: () => CodeBlock,
|
|
24
|
-
backtickInputRegex: () => backtickInputRegex,
|
|
25
|
-
default: () => index_default,
|
|
26
|
-
tildeInputRegex: () => tildeInputRegex
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
|
|
30
|
-
// src/code-block.ts
|
|
31
|
-
var import_core = require("@tiptap/core");
|
|
32
|
-
var import_state = require("@tiptap/pm/state");
|
|
33
|
-
var DEFAULT_TAB_SIZE = 4;
|
|
34
|
-
var backtickInputRegex = /^```([a-z]+)?[\s\n]$/;
|
|
35
|
-
var tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/;
|
|
36
|
-
var CodeBlock = import_core.Node.create({
|
|
37
|
-
name: "codeBlock",
|
|
38
|
-
addOptions() {
|
|
39
|
-
return {
|
|
40
|
-
languageClassPrefix: "language-",
|
|
41
|
-
exitOnTripleEnter: true,
|
|
42
|
-
exitOnArrowDown: true,
|
|
43
|
-
defaultLanguage: null,
|
|
44
|
-
enableTabIndentation: false,
|
|
45
|
-
tabSize: DEFAULT_TAB_SIZE,
|
|
46
|
-
HTMLAttributes: {}
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
content: "text*",
|
|
50
|
-
marks: "",
|
|
51
|
-
group: "block",
|
|
52
|
-
code: true,
|
|
53
|
-
defining: true,
|
|
54
|
-
addAttributes() {
|
|
55
|
-
return {
|
|
56
|
-
language: {
|
|
57
|
-
default: this.options.defaultLanguage,
|
|
58
|
-
parseHTML: (element) => {
|
|
59
|
-
var _a;
|
|
60
|
-
const { languageClassPrefix } = this.options;
|
|
61
|
-
if (!languageClassPrefix) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const classNames = [...((_a = element.firstElementChild) == null ? void 0 : _a.classList) || []];
|
|
65
|
-
const languages = classNames.filter((className) => className.startsWith(languageClassPrefix)).map((className) => className.replace(languageClassPrefix, ""));
|
|
66
|
-
const language = languages[0];
|
|
67
|
-
if (!language) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
return language;
|
|
71
|
-
},
|
|
72
|
-
rendered: false
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
|
-
parseHTML() {
|
|
77
|
-
return [
|
|
78
|
-
{
|
|
79
|
-
tag: "pre",
|
|
80
|
-
preserveWhitespace: "full"
|
|
81
|
-
}
|
|
82
|
-
];
|
|
83
|
-
},
|
|
84
|
-
renderHTML({ node, HTMLAttributes }) {
|
|
85
|
-
return [
|
|
86
|
-
"pre",
|
|
87
|
-
(0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),
|
|
88
|
-
[
|
|
89
|
-
"code",
|
|
90
|
-
{
|
|
91
|
-
class: node.attrs.language ? this.options.languageClassPrefix + node.attrs.language : null
|
|
92
|
-
},
|
|
93
|
-
0
|
|
94
|
-
]
|
|
95
|
-
];
|
|
96
|
-
},
|
|
97
|
-
markdownTokenName: "code",
|
|
98
|
-
parseMarkdown: (token, helpers) => {
|
|
99
|
-
var _a, _b;
|
|
100
|
-
if (((_a = token.raw) == null ? void 0 : _a.startsWith("```")) === false && ((_b = token.raw) == null ? void 0 : _b.startsWith("~~~")) === false && token.codeBlockStyle !== "indented") {
|
|
101
|
-
return [];
|
|
102
|
-
}
|
|
103
|
-
return helpers.createNode(
|
|
104
|
-
"codeBlock",
|
|
105
|
-
{ language: token.lang || null },
|
|
106
|
-
token.text ? [helpers.createTextNode(token.text)] : []
|
|
107
|
-
);
|
|
108
|
-
},
|
|
109
|
-
renderMarkdown: (node, h) => {
|
|
110
|
-
var _a;
|
|
111
|
-
let output = "";
|
|
112
|
-
const language = ((_a = node.attrs) == null ? void 0 : _a.language) || "";
|
|
113
|
-
if (!node.content) {
|
|
114
|
-
output = `\`\`\`${language}
|
|
115
|
-
|
|
116
|
-
\`\`\``;
|
|
117
|
-
} else {
|
|
118
|
-
const lines = [`\`\`\`${language}`, h.renderChildren(node.content), "```"];
|
|
119
|
-
output = lines.join("\n");
|
|
120
|
-
}
|
|
121
|
-
return output;
|
|
122
|
-
},
|
|
123
|
-
addCommands() {
|
|
124
|
-
return {
|
|
125
|
-
setCodeBlock: (attributes) => ({ commands }) => {
|
|
126
|
-
return commands.setNode(this.name, attributes);
|
|
127
|
-
},
|
|
128
|
-
toggleCodeBlock: (attributes) => ({ commands }) => {
|
|
129
|
-
return commands.toggleNode(this.name, "paragraph", attributes);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
addKeyboardShortcuts() {
|
|
134
|
-
return {
|
|
135
|
-
"Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),
|
|
136
|
-
// remove code block when at start of document or code block is empty
|
|
137
|
-
Backspace: () => {
|
|
138
|
-
const { empty, $anchor } = this.editor.state.selection;
|
|
139
|
-
const isAtStart = $anchor.pos === 1;
|
|
140
|
-
if (!empty || $anchor.parent.type.name !== this.name) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
if (isAtStart || !$anchor.parent.textContent.length) {
|
|
144
|
-
return this.editor.commands.clearNodes();
|
|
145
|
-
}
|
|
146
|
-
return false;
|
|
147
|
-
},
|
|
148
|
-
// handle tab indentation
|
|
149
|
-
Tab: ({ editor }) => {
|
|
150
|
-
var _a;
|
|
151
|
-
if (!this.options.enableTabIndentation) {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
const tabSize = (_a = this.options.tabSize) != null ? _a : DEFAULT_TAB_SIZE;
|
|
155
|
-
const { state } = editor;
|
|
156
|
-
const { selection } = state;
|
|
157
|
-
const { $from, empty } = selection;
|
|
158
|
-
if ($from.parent.type !== this.type) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
const indent = " ".repeat(tabSize);
|
|
162
|
-
if (empty) {
|
|
163
|
-
return editor.commands.insertContent(indent);
|
|
164
|
-
}
|
|
165
|
-
return editor.commands.command(({ tr }) => {
|
|
166
|
-
const { from, to } = selection;
|
|
167
|
-
const text = state.doc.textBetween(from, to, "\n", "\n");
|
|
168
|
-
const lines = text.split("\n");
|
|
169
|
-
const indentedText = lines.map((line) => indent + line).join("\n");
|
|
170
|
-
tr.replaceWith(from, to, state.schema.text(indentedText));
|
|
171
|
-
return true;
|
|
172
|
-
});
|
|
173
|
-
},
|
|
174
|
-
// handle shift+tab reverse indentation
|
|
175
|
-
"Shift-Tab": ({ editor }) => {
|
|
176
|
-
var _a;
|
|
177
|
-
if (!this.options.enableTabIndentation) {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
const tabSize = (_a = this.options.tabSize) != null ? _a : DEFAULT_TAB_SIZE;
|
|
181
|
-
const { state } = editor;
|
|
182
|
-
const { selection } = state;
|
|
183
|
-
const { $from, empty } = selection;
|
|
184
|
-
if ($from.parent.type !== this.type) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
if (empty) {
|
|
188
|
-
return editor.commands.command(({ tr }) => {
|
|
189
|
-
var _a2;
|
|
190
|
-
const { pos } = $from;
|
|
191
|
-
const codeBlockStart = $from.start();
|
|
192
|
-
const codeBlockEnd = $from.end();
|
|
193
|
-
const allText = state.doc.textBetween(codeBlockStart, codeBlockEnd, "\n", "\n");
|
|
194
|
-
const lines = allText.split("\n");
|
|
195
|
-
let currentLineIndex = 0;
|
|
196
|
-
let charCount = 0;
|
|
197
|
-
const relativeCursorPos = pos - codeBlockStart;
|
|
198
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
199
|
-
if (charCount + lines[i].length >= relativeCursorPos) {
|
|
200
|
-
currentLineIndex = i;
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
charCount += lines[i].length + 1;
|
|
204
|
-
}
|
|
205
|
-
const currentLine = lines[currentLineIndex];
|
|
206
|
-
const leadingSpaces = ((_a2 = currentLine.match(/^ */)) == null ? void 0 : _a2[0]) || "";
|
|
207
|
-
const spacesToRemove = Math.min(leadingSpaces.length, tabSize);
|
|
208
|
-
if (spacesToRemove === 0) {
|
|
209
|
-
return true;
|
|
210
|
-
}
|
|
211
|
-
let lineStartPos = codeBlockStart;
|
|
212
|
-
for (let i = 0; i < currentLineIndex; i += 1) {
|
|
213
|
-
lineStartPos += lines[i].length + 1;
|
|
214
|
-
}
|
|
215
|
-
tr.delete(lineStartPos, lineStartPos + spacesToRemove);
|
|
216
|
-
const cursorPosInLine = pos - lineStartPos;
|
|
217
|
-
if (cursorPosInLine <= spacesToRemove) {
|
|
218
|
-
tr.setSelection(import_state.TextSelection.create(tr.doc, lineStartPos));
|
|
219
|
-
}
|
|
220
|
-
return true;
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
return editor.commands.command(({ tr }) => {
|
|
224
|
-
const { from, to } = selection;
|
|
225
|
-
const text = state.doc.textBetween(from, to, "\n", "\n");
|
|
226
|
-
const lines = text.split("\n");
|
|
227
|
-
const reverseIndentText = lines.map((line) => {
|
|
228
|
-
var _a2;
|
|
229
|
-
const leadingSpaces = ((_a2 = line.match(/^ */)) == null ? void 0 : _a2[0]) || "";
|
|
230
|
-
const spacesToRemove = Math.min(leadingSpaces.length, tabSize);
|
|
231
|
-
return line.slice(spacesToRemove);
|
|
232
|
-
}).join("\n");
|
|
233
|
-
tr.replaceWith(from, to, state.schema.text(reverseIndentText));
|
|
234
|
-
return true;
|
|
235
|
-
});
|
|
236
|
-
},
|
|
237
|
-
// exit node on triple enter
|
|
238
|
-
Enter: ({ editor }) => {
|
|
239
|
-
if (!this.options.exitOnTripleEnter) {
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
const { state } = editor;
|
|
243
|
-
const { selection } = state;
|
|
244
|
-
const { $from, empty } = selection;
|
|
245
|
-
if (!empty || $from.parent.type !== this.type) {
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
|
|
249
|
-
const endsWithDoubleNewline = $from.parent.textContent.endsWith("\n\n");
|
|
250
|
-
if (!isAtEnd || !endsWithDoubleNewline) {
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
return editor.chain().command(({ tr }) => {
|
|
254
|
-
tr.delete($from.pos - 2, $from.pos);
|
|
255
|
-
return true;
|
|
256
|
-
}).exitCode().run();
|
|
257
|
-
},
|
|
258
|
-
// exit node on arrow down
|
|
259
|
-
ArrowDown: ({ editor }) => {
|
|
260
|
-
if (!this.options.exitOnArrowDown) {
|
|
261
|
-
return false;
|
|
262
|
-
}
|
|
263
|
-
const { state } = editor;
|
|
264
|
-
const { selection, doc } = state;
|
|
265
|
-
const { $from, empty } = selection;
|
|
266
|
-
if (!empty || $from.parent.type !== this.type) {
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
|
|
270
|
-
if (!isAtEnd) {
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
const after = $from.after();
|
|
274
|
-
if (after === void 0) {
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
const nodeAfter = doc.nodeAt(after);
|
|
278
|
-
if (nodeAfter) {
|
|
279
|
-
return editor.commands.command(({ tr }) => {
|
|
280
|
-
tr.setSelection(import_state.Selection.near(doc.resolve(after)));
|
|
281
|
-
return true;
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
return editor.commands.exitCode();
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
},
|
|
288
|
-
addInputRules() {
|
|
289
|
-
return [
|
|
290
|
-
(0, import_core.textblockTypeInputRule)({
|
|
291
|
-
find: backtickInputRegex,
|
|
292
|
-
type: this.type,
|
|
293
|
-
getAttributes: (match) => ({
|
|
294
|
-
language: match[1]
|
|
295
|
-
})
|
|
296
|
-
}),
|
|
297
|
-
(0, import_core.textblockTypeInputRule)({
|
|
298
|
-
find: tildeInputRegex,
|
|
299
|
-
type: this.type,
|
|
300
|
-
getAttributes: (match) => ({
|
|
301
|
-
language: match[1]
|
|
302
|
-
})
|
|
303
|
-
})
|
|
304
|
-
];
|
|
305
|
-
},
|
|
306
|
-
addProseMirrorPlugins() {
|
|
307
|
-
return [
|
|
308
|
-
// this plugin creates a code block for pasted content from VS Code
|
|
309
|
-
// we can also detect the copied code language
|
|
310
|
-
new import_state.Plugin({
|
|
311
|
-
key: new import_state.PluginKey("codeBlockVSCodeHandler"),
|
|
312
|
-
props: {
|
|
313
|
-
handlePaste: (view, event) => {
|
|
314
|
-
if (!event.clipboardData) {
|
|
315
|
-
return false;
|
|
316
|
-
}
|
|
317
|
-
if (this.editor.isActive(this.type.name)) {
|
|
318
|
-
return false;
|
|
319
|
-
}
|
|
320
|
-
const text = event.clipboardData.getData("text/plain");
|
|
321
|
-
const vscode = event.clipboardData.getData("vscode-editor-data");
|
|
322
|
-
const vscodeData = vscode ? JSON.parse(vscode) : void 0;
|
|
323
|
-
const language = vscodeData == null ? void 0 : vscodeData.mode;
|
|
324
|
-
if (!text || !language) {
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
const { tr, schema } = view.state;
|
|
328
|
-
const textNode = schema.text(text.replace(/\r\n?/g, "\n"));
|
|
329
|
-
tr.replaceSelectionWith(this.type.create({ language }, textNode));
|
|
330
|
-
if (tr.selection.$from.parent.type !== this.type) {
|
|
331
|
-
tr.setSelection(import_state.TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))));
|
|
332
|
-
}
|
|
333
|
-
tr.setMeta("paste", true);
|
|
334
|
-
view.dispatch(tr);
|
|
335
|
-
return true;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
})
|
|
339
|
-
];
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
// src/index.ts
|
|
344
|
-
var index_default = CodeBlock;
|
|
345
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
346
|
-
0 && (module.exports = {
|
|
347
|
-
CodeBlock,
|
|
348
|
-
backtickInputRegex,
|
|
349
|
-
tildeInputRegex
|
|
350
|
-
});
|
|
351
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/code-block.ts"],"sourcesContent":["import { CodeBlock } from './code-block.js'\n\nexport * from './code-block.js'\n\nexport default CodeBlock\n","import { mergeAttributes, Node, textblockTypeInputRule } from '@tiptap/core'\nimport { Plugin, PluginKey, Selection, TextSelection } from '@tiptap/pm/state'\n\nconst DEFAULT_TAB_SIZE = 4\n\nexport interface CodeBlockOptions {\n /**\n * Adds a prefix to language classes that are applied to code tags.\n * @default 'language-'\n */\n languageClassPrefix: string | null | undefined\n /**\n * Define whether the node should be exited on triple enter.\n * @default true\n */\n exitOnTripleEnter: boolean | null | undefined\n /**\n * Define whether the node should be exited on arrow down if there is no node after it.\n * @default true\n */\n exitOnArrowDown: boolean | null | undefined\n /**\n * The default language.\n * @default null\n * @example 'js'\n */\n defaultLanguage: string | null | undefined\n /**\n * Enable tab key for indentation in code blocks.\n * @default false\n */\n enableTabIndentation: boolean | null | undefined\n /**\n * The number of spaces to use for tab indentation.\n * @default 4\n */\n tabSize: number | null | undefined\n /**\n * Custom HTML attributes that should be added to the rendered HTML tag.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n codeBlock: {\n /**\n * Set a code block\n * @param attributes Code block attributes\n * @example editor.commands.setCodeBlock({ language: 'javascript' })\n */\n setCodeBlock: (attributes?: { language: string }) => ReturnType\n /**\n * Toggle a code block\n * @param attributes Code block attributes\n * @example editor.commands.toggleCodeBlock({ language: 'javascript' })\n */\n toggleCodeBlock: (attributes?: { language: string }) => ReturnType\n }\n }\n}\n\n/**\n * Matches a code block with backticks.\n */\nexport const backtickInputRegex = /^```([a-z]+)?[\\s\\n]$/\n\n/**\n * Matches a code block with tildes.\n */\nexport const tildeInputRegex = /^~~~([a-z]+)?[\\s\\n]$/\n\n/**\n * This extension allows you to create code blocks.\n * @see https://tiptap.dev/api/nodes/code-block\n */\nexport const CodeBlock = Node.create<CodeBlockOptions>({\n name: 'codeBlock',\n\n addOptions() {\n return {\n languageClassPrefix: 'language-',\n exitOnTripleEnter: true,\n exitOnArrowDown: true,\n defaultLanguage: null,\n enableTabIndentation: false,\n tabSize: DEFAULT_TAB_SIZE,\n HTMLAttributes: {},\n }\n },\n\n content: 'text*',\n\n marks: '',\n\n group: 'block',\n\n code: true,\n\n defining: true,\n\n addAttributes() {\n return {\n language: {\n default: this.options.defaultLanguage,\n parseHTML: element => {\n const { languageClassPrefix } = this.options\n\n if (!languageClassPrefix) {\n return null\n }\n\n const classNames = [...(element.firstElementChild?.classList || [])]\n const languages = classNames\n .filter(className => className.startsWith(languageClassPrefix))\n .map(className => className.replace(languageClassPrefix, ''))\n const language = languages[0]\n\n if (!language) {\n return null\n }\n\n return language\n },\n rendered: false,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'pre',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n [\n 'code',\n {\n class: node.attrs.language ? this.options.languageClassPrefix + node.attrs.language : null,\n },\n 0,\n ],\n ]\n },\n\n markdownTokenName: 'code',\n\n parseMarkdown: (token, helpers) => {\n if (\n token.raw?.startsWith('```') === false &&\n token.raw?.startsWith('~~~') === false &&\n token.codeBlockStyle !== 'indented'\n ) {\n return []\n }\n\n return helpers.createNode(\n 'codeBlock',\n { language: token.lang || null },\n token.text ? [helpers.createTextNode(token.text)] : [],\n )\n },\n\n renderMarkdown: (node, h) => {\n let output = ''\n const language = node.attrs?.language || ''\n\n if (!node.content) {\n output = `\\`\\`\\`${language}\\n\\n\\`\\`\\``\n } else {\n const lines = [`\\`\\`\\`${language}`, h.renderChildren(node.content), '```']\n output = lines.join('\\n')\n }\n\n return output\n },\n\n addCommands() {\n return {\n setCodeBlock:\n attributes =>\n ({ commands }) => {\n return commands.setNode(this.name, attributes)\n },\n toggleCodeBlock:\n attributes =>\n ({ commands }) => {\n return commands.toggleNode(this.name, 'paragraph', attributes)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Alt-c': () => this.editor.commands.toggleCodeBlock(),\n\n // remove code block when at start of document or code block is empty\n Backspace: () => {\n const { empty, $anchor } = this.editor.state.selection\n const isAtStart = $anchor.pos === 1\n\n if (!empty || $anchor.parent.type.name !== this.name) {\n return false\n }\n\n if (isAtStart || !$anchor.parent.textContent.length) {\n return this.editor.commands.clearNodes()\n }\n\n return false\n },\n\n // handle tab indentation\n Tab: ({ editor }) => {\n if (!this.options.enableTabIndentation) {\n return false\n }\n\n const tabSize = this.options.tabSize ?? DEFAULT_TAB_SIZE\n const { state } = editor\n const { selection } = state\n const { $from, empty } = selection\n\n if ($from.parent.type !== this.type) {\n return false\n }\n\n const indent = ' '.repeat(tabSize)\n\n if (empty) {\n return editor.commands.insertContent(indent)\n }\n\n return editor.commands.command(({ tr }) => {\n const { from, to } = selection\n const text = state.doc.textBetween(from, to, '\\n', '\\n')\n const lines = text.split('\\n')\n const indentedText = lines.map(line => indent + line).join('\\n')\n\n tr.replaceWith(from, to, state.schema.text(indentedText))\n return true\n })\n },\n\n // handle shift+tab reverse indentation\n 'Shift-Tab': ({ editor }) => {\n if (!this.options.enableTabIndentation) {\n return false\n }\n\n const tabSize = this.options.tabSize ?? DEFAULT_TAB_SIZE\n const { state } = editor\n const { selection } = state\n const { $from, empty } = selection\n\n if ($from.parent.type !== this.type) {\n return false\n }\n\n if (empty) {\n return editor.commands.command(({ tr }) => {\n const { pos } = $from\n const codeBlockStart = $from.start()\n const codeBlockEnd = $from.end()\n\n const allText = state.doc.textBetween(codeBlockStart, codeBlockEnd, '\\n', '\\n')\n const lines = allText.split('\\n')\n\n let currentLineIndex = 0\n let charCount = 0\n const relativeCursorPos = pos - codeBlockStart\n\n for (let i = 0; i < lines.length; i += 1) {\n if (charCount + lines[i].length >= relativeCursorPos) {\n currentLineIndex = i\n break\n }\n charCount += lines[i].length + 1\n }\n\n const currentLine = lines[currentLineIndex]\n const leadingSpaces = currentLine.match(/^ */)?.[0] || ''\n const spacesToRemove = Math.min(leadingSpaces.length, tabSize)\n\n if (spacesToRemove === 0) {\n return true\n }\n\n let lineStartPos = codeBlockStart\n for (let i = 0; i < currentLineIndex; i += 1) {\n lineStartPos += lines[i].length + 1\n }\n\n tr.delete(lineStartPos, lineStartPos + spacesToRemove)\n\n const cursorPosInLine = pos - lineStartPos\n if (cursorPosInLine <= spacesToRemove) {\n tr.setSelection(TextSelection.create(tr.doc, lineStartPos))\n }\n\n return true\n })\n }\n\n return editor.commands.command(({ tr }) => {\n const { from, to } = selection\n const text = state.doc.textBetween(from, to, '\\n', '\\n')\n const lines = text.split('\\n')\n const reverseIndentText = lines\n .map(line => {\n const leadingSpaces = line.match(/^ */)?.[0] || ''\n const spacesToRemove = Math.min(leadingSpaces.length, tabSize)\n return line.slice(spacesToRemove)\n })\n .join('\\n')\n\n tr.replaceWith(from, to, state.schema.text(reverseIndentText))\n return true\n })\n },\n\n // exit node on triple enter\n Enter: ({ editor }) => {\n if (!this.options.exitOnTripleEnter) {\n return false\n }\n\n const { state } = editor\n const { selection } = state\n const { $from, empty } = selection\n\n if (!empty || $from.parent.type !== this.type) {\n return false\n }\n\n const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2\n const endsWithDoubleNewline = $from.parent.textContent.endsWith('\\n\\n')\n\n if (!isAtEnd || !endsWithDoubleNewline) {\n return false\n }\n\n return editor\n .chain()\n .command(({ tr }) => {\n tr.delete($from.pos - 2, $from.pos)\n\n return true\n })\n .exitCode()\n .run()\n },\n\n // exit node on arrow down\n ArrowDown: ({ editor }) => {\n if (!this.options.exitOnArrowDown) {\n return false\n }\n\n const { state } = editor\n const { selection, doc } = state\n const { $from, empty } = selection\n\n if (!empty || $from.parent.type !== this.type) {\n return false\n }\n\n const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2\n\n if (!isAtEnd) {\n return false\n }\n\n const after = $from.after()\n\n if (after === undefined) {\n return false\n }\n\n const nodeAfter = doc.nodeAt(after)\n\n if (nodeAfter) {\n return editor.commands.command(({ tr }) => {\n tr.setSelection(Selection.near(doc.resolve(after)))\n return true\n })\n }\n\n return editor.commands.exitCode()\n },\n }\n },\n\n addInputRules() {\n return [\n textblockTypeInputRule({\n find: backtickInputRegex,\n type: this.type,\n getAttributes: match => ({\n language: match[1],\n }),\n }),\n textblockTypeInputRule({\n find: tildeInputRegex,\n type: this.type,\n getAttributes: match => ({\n language: match[1],\n }),\n }),\n ]\n },\n\n addProseMirrorPlugins() {\n return [\n // this plugin creates a code block for pasted content from VS Code\n // we can also detect the copied code language\n new Plugin({\n key: new PluginKey('codeBlockVSCodeHandler'),\n props: {\n handlePaste: (view, event) => {\n if (!event.clipboardData) {\n return false\n }\n\n // don’t create a new code block within code blocks\n if (this.editor.isActive(this.type.name)) {\n return false\n }\n\n const text = event.clipboardData.getData('text/plain')\n const vscode = event.clipboardData.getData('vscode-editor-data')\n const vscodeData = vscode ? JSON.parse(vscode) : undefined\n const language = vscodeData?.mode\n\n if (!text || !language) {\n return false\n }\n\n const { tr, schema } = view.state\n\n // prepare a text node\n // strip carriage return chars from text pasted as code\n // see: https://github.com/ProseMirror/prosemirror-view/commit/a50a6bcceb4ce52ac8fcc6162488d8875613aacd\n const textNode = schema.text(text.replace(/\\r\\n?/g, '\\n'))\n\n // create a code block with the text node\n // replace selection with the code block\n tr.replaceSelectionWith(this.type.create({ language }, textNode))\n\n if (tr.selection.$from.parent.type !== this.type) {\n // put cursor inside the newly created code block\n tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))))\n }\n\n // store meta information\n // this is useful for other plugins that depends on the paste event\n // like the paste rule plugin\n tr.setMeta('paste', true)\n\n view.dispatch(tr)\n\n return true\n },\n },\n }),\n ]\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA8D;AAC9D,mBAA4D;AAE5D,IAAM,mBAAmB;AAgElB,IAAM,qBAAqB;AAK3B,IAAM,kBAAkB;AAMxB,IAAM,YAAY,iBAAK,OAAyB;AAAA,EACrD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,qBAAqB;AAAA,MACrB,mBAAmB;AAAA,MACnB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,MACjB,sBAAsB;AAAA,MACtB,SAAS;AAAA,MACT,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,SAAS;AAAA,EAET,OAAO;AAAA,EAEP,OAAO;AAAA,EAEP,MAAM;AAAA,EAEN,UAAU;AAAA,EAEV,gBAAgB;AACd,WAAO;AAAA,MACL,UAAU;AAAA,QACR,SAAS,KAAK,QAAQ;AAAA,QACtB,WAAW,aAAW;AA3G9B;AA4GU,gBAAM,EAAE,oBAAoB,IAAI,KAAK;AAErC,cAAI,CAAC,qBAAqB;AACxB,mBAAO;AAAA,UACT;AAEA,gBAAM,aAAa,CAAC,KAAI,aAAQ,sBAAR,mBAA2B,cAAa,CAAC,CAAE;AACnE,gBAAM,YAAY,WACf,OAAO,eAAa,UAA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AAKA,eAAG,QAAQ,SAAS,IAAI;AAExB,iBAAK,SAAS,EAAE;AAEhB,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;ADxdD,IAAO,gBAAQ;","names":["_a"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Node } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
interface CodeBlockOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Adds a prefix to language classes that are applied to code tags.
|
|
6
|
-
* @default 'language-'
|
|
7
|
-
*/
|
|
8
|
-
languageClassPrefix: string | null | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Define whether the node should be exited on triple enter.
|
|
11
|
-
* @default true
|
|
12
|
-
*/
|
|
13
|
-
exitOnTripleEnter: boolean | null | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Define whether the node should be exited on arrow down if there is no node after it.
|
|
16
|
-
* @default true
|
|
17
|
-
*/
|
|
18
|
-
exitOnArrowDown: boolean | null | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* The default language.
|
|
21
|
-
* @default null
|
|
22
|
-
* @example 'js'
|
|
23
|
-
*/
|
|
24
|
-
defaultLanguage: string | null | undefined;
|
|
25
|
-
/**
|
|
26
|
-
* Enable tab key for indentation in code blocks.
|
|
27
|
-
* @default false
|
|
28
|
-
*/
|
|
29
|
-
enableTabIndentation: boolean | null | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* The number of spaces to use for tab indentation.
|
|
32
|
-
* @default 4
|
|
33
|
-
*/
|
|
34
|
-
tabSize: number | null | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* Custom HTML attributes that should be added to the rendered HTML tag.
|
|
37
|
-
* @default {}
|
|
38
|
-
* @example { class: 'foo' }
|
|
39
|
-
*/
|
|
40
|
-
HTMLAttributes: Record<string, any>;
|
|
41
|
-
}
|
|
42
|
-
declare module '@tiptap/core' {
|
|
43
|
-
interface Commands<ReturnType> {
|
|
44
|
-
codeBlock: {
|
|
45
|
-
/**
|
|
46
|
-
* Set a code block
|
|
47
|
-
* @param attributes Code block attributes
|
|
48
|
-
* @example editor.commands.setCodeBlock({ language: 'javascript' })
|
|
49
|
-
*/
|
|
50
|
-
setCodeBlock: (attributes?: {
|
|
51
|
-
language: string;
|
|
52
|
-
}) => ReturnType;
|
|
53
|
-
/**
|
|
54
|
-
* Toggle a code block
|
|
55
|
-
* @param attributes Code block attributes
|
|
56
|
-
* @example editor.commands.toggleCodeBlock({ language: 'javascript' })
|
|
57
|
-
*/
|
|
58
|
-
toggleCodeBlock: (attributes?: {
|
|
59
|
-
language: string;
|
|
60
|
-
}) => ReturnType;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Matches a code block with backticks.
|
|
66
|
-
*/
|
|
67
|
-
declare const backtickInputRegex: RegExp;
|
|
68
|
-
/**
|
|
69
|
-
* Matches a code block with tildes.
|
|
70
|
-
*/
|
|
71
|
-
declare const tildeInputRegex: RegExp;
|
|
72
|
-
/**
|
|
73
|
-
* This extension allows you to create code blocks.
|
|
74
|
-
* @see https://tiptap.dev/api/nodes/code-block
|
|
75
|
-
*/
|
|
76
|
-
declare const CodeBlock: Node<CodeBlockOptions, any>;
|
|
77
|
-
|
|
78
|
-
export { CodeBlock, type CodeBlockOptions, backtickInputRegex, CodeBlock as default, tildeInputRegex };
|
package/dist/index.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Node } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
interface CodeBlockOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Adds a prefix to language classes that are applied to code tags.
|
|
6
|
-
* @default 'language-'
|
|
7
|
-
*/
|
|
8
|
-
languageClassPrefix: string | null | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Define whether the node should be exited on triple enter.
|
|
11
|
-
* @default true
|
|
12
|
-
*/
|
|
13
|
-
exitOnTripleEnter: boolean | null | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Define whether the node should be exited on arrow down if there is no node after it.
|
|
16
|
-
* @default true
|
|
17
|
-
*/
|
|
18
|
-
exitOnArrowDown: boolean | null | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* The default language.
|
|
21
|
-
* @default null
|
|
22
|
-
* @example 'js'
|
|
23
|
-
*/
|
|
24
|
-
defaultLanguage: string | null | undefined;
|
|
25
|
-
/**
|
|
26
|
-
* Enable tab key for indentation in code blocks.
|
|
27
|
-
* @default false
|
|
28
|
-
*/
|
|
29
|
-
enableTabIndentation: boolean | null | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* The number of spaces to use for tab indentation.
|
|
32
|
-
* @default 4
|
|
33
|
-
*/
|
|
34
|
-
tabSize: number | null | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* Custom HTML attributes that should be added to the rendered HTML tag.
|
|
37
|
-
* @default {}
|
|
38
|
-
* @example { class: 'foo' }
|
|
39
|
-
*/
|
|
40
|
-
HTMLAttributes: Record<string, any>;
|
|
41
|
-
}
|
|
42
|
-
declare module '@tiptap/core' {
|
|
43
|
-
interface Commands<ReturnType> {
|
|
44
|
-
codeBlock: {
|
|
45
|
-
/**
|
|
46
|
-
* Set a code block
|
|
47
|
-
* @param attributes Code block attributes
|
|
48
|
-
* @example editor.commands.setCodeBlock({ language: 'javascript' })
|
|
49
|
-
*/
|
|
50
|
-
setCodeBlock: (attributes?: {
|
|
51
|
-
language: string;
|
|
52
|
-
}) => ReturnType;
|
|
53
|
-
/**
|
|
54
|
-
* Toggle a code block
|
|
55
|
-
* @param attributes Code block attributes
|
|
56
|
-
* @example editor.commands.toggleCodeBlock({ language: 'javascript' })
|
|
57
|
-
*/
|
|
58
|
-
toggleCodeBlock: (attributes?: {
|
|
59
|
-
language: string;
|
|
60
|
-
}) => ReturnType;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Matches a code block with backticks.
|
|
66
|
-
*/
|
|
67
|
-
declare const backtickInputRegex: RegExp;
|
|
68
|
-
/**
|
|
69
|
-
* Matches a code block with tildes.
|
|
70
|
-
*/
|
|
71
|
-
declare const tildeInputRegex: RegExp;
|
|
72
|
-
/**
|
|
73
|
-
* This extension allows you to create code blocks.
|
|
74
|
-
* @see https://tiptap.dev/api/nodes/code-block
|
|
75
|
-
*/
|
|
76
|
-
declare const CodeBlock: Node<CodeBlockOptions, any>;
|
|
77
|
-
|
|
78
|
-
export { CodeBlock, type CodeBlockOptions, backtickInputRegex, CodeBlock as default, tildeInputRegex };
|
package/dist/index.js
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
// src/code-block.ts
|
|
2
|
-
import { mergeAttributes, Node, textblockTypeInputRule } from "@tiptap/core";
|
|
3
|
-
import { Plugin, PluginKey, Selection, TextSelection } from "@tiptap/pm/state";
|
|
4
|
-
var DEFAULT_TAB_SIZE = 4;
|
|
5
|
-
var backtickInputRegex = /^```([a-z]+)?[\s\n]$/;
|
|
6
|
-
var tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/;
|
|
7
|
-
var CodeBlock = Node.create({
|
|
8
|
-
name: "codeBlock",
|
|
9
|
-
addOptions() {
|
|
10
|
-
return {
|
|
11
|
-
languageClassPrefix: "language-",
|
|
12
|
-
exitOnTripleEnter: true,
|
|
13
|
-
exitOnArrowDown: true,
|
|
14
|
-
defaultLanguage: null,
|
|
15
|
-
enableTabIndentation: false,
|
|
16
|
-
tabSize: DEFAULT_TAB_SIZE,
|
|
17
|
-
HTMLAttributes: {}
|
|
18
|
-
};
|
|
19
|
-
},
|
|
20
|
-
content: "text*",
|
|
21
|
-
marks: "",
|
|
22
|
-
group: "block",
|
|
23
|
-
code: true,
|
|
24
|
-
defining: true,
|
|
25
|
-
addAttributes() {
|
|
26
|
-
return {
|
|
27
|
-
language: {
|
|
28
|
-
default: this.options.defaultLanguage,
|
|
29
|
-
parseHTML: (element) => {
|
|
30
|
-
var _a;
|
|
31
|
-
const { languageClassPrefix } = this.options;
|
|
32
|
-
if (!languageClassPrefix) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
const classNames = [...((_a = element.firstElementChild) == null ? void 0 : _a.classList) || []];
|
|
36
|
-
const languages = classNames.filter((className) => className.startsWith(languageClassPrefix)).map((className) => className.replace(languageClassPrefix, ""));
|
|
37
|
-
const language = languages[0];
|
|
38
|
-
if (!language) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
return language;
|
|
42
|
-
},
|
|
43
|
-
rendered: false
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
parseHTML() {
|
|
48
|
-
return [
|
|
49
|
-
{
|
|
50
|
-
tag: "pre",
|
|
51
|
-
preserveWhitespace: "full"
|
|
52
|
-
}
|
|
53
|
-
];
|
|
54
|
-
},
|
|
55
|
-
renderHTML({ node, HTMLAttributes }) {
|
|
56
|
-
return [
|
|
57
|
-
"pre",
|
|
58
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
59
|
-
[
|
|
60
|
-
"code",
|
|
61
|
-
{
|
|
62
|
-
class: node.attrs.language ? this.options.languageClassPrefix + node.attrs.language : null
|
|
63
|
-
},
|
|
64
|
-
0
|
|
65
|
-
]
|
|
66
|
-
];
|
|
67
|
-
},
|
|
68
|
-
markdownTokenName: "code",
|
|
69
|
-
parseMarkdown: (token, helpers) => {
|
|
70
|
-
var _a, _b;
|
|
71
|
-
if (((_a = token.raw) == null ? void 0 : _a.startsWith("```")) === false && ((_b = token.raw) == null ? void 0 : _b.startsWith("~~~")) === false && token.codeBlockStyle !== "indented") {
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
return helpers.createNode(
|
|
75
|
-
"codeBlock",
|
|
76
|
-
{ language: token.lang || null },
|
|
77
|
-
token.text ? [helpers.createTextNode(token.text)] : []
|
|
78
|
-
);
|
|
79
|
-
},
|
|
80
|
-
renderMarkdown: (node, h) => {
|
|
81
|
-
var _a;
|
|
82
|
-
let output = "";
|
|
83
|
-
const language = ((_a = node.attrs) == null ? void 0 : _a.language) || "";
|
|
84
|
-
if (!node.content) {
|
|
85
|
-
output = `\`\`\`${language}
|
|
86
|
-
|
|
87
|
-
\`\`\``;
|
|
88
|
-
} else {
|
|
89
|
-
const lines = [`\`\`\`${language}`, h.renderChildren(node.content), "```"];
|
|
90
|
-
output = lines.join("\n");
|
|
91
|
-
}
|
|
92
|
-
return output;
|
|
93
|
-
},
|
|
94
|
-
addCommands() {
|
|
95
|
-
return {
|
|
96
|
-
setCodeBlock: (attributes) => ({ commands }) => {
|
|
97
|
-
return commands.setNode(this.name, attributes);
|
|
98
|
-
},
|
|
99
|
-
toggleCodeBlock: (attributes) => ({ commands }) => {
|
|
100
|
-
return commands.toggleNode(this.name, "paragraph", attributes);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
},
|
|
104
|
-
addKeyboardShortcuts() {
|
|
105
|
-
return {
|
|
106
|
-
"Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),
|
|
107
|
-
// remove code block when at start of document or code block is empty
|
|
108
|
-
Backspace: () => {
|
|
109
|
-
const { empty, $anchor } = this.editor.state.selection;
|
|
110
|
-
const isAtStart = $anchor.pos === 1;
|
|
111
|
-
if (!empty || $anchor.parent.type.name !== this.name) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
if (isAtStart || !$anchor.parent.textContent.length) {
|
|
115
|
-
return this.editor.commands.clearNodes();
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
118
|
-
},
|
|
119
|
-
// handle tab indentation
|
|
120
|
-
Tab: ({ editor }) => {
|
|
121
|
-
var _a;
|
|
122
|
-
if (!this.options.enableTabIndentation) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
const tabSize = (_a = this.options.tabSize) != null ? _a : DEFAULT_TAB_SIZE;
|
|
126
|
-
const { state } = editor;
|
|
127
|
-
const { selection } = state;
|
|
128
|
-
const { $from, empty } = selection;
|
|
129
|
-
if ($from.parent.type !== this.type) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
const indent = " ".repeat(tabSize);
|
|
133
|
-
if (empty) {
|
|
134
|
-
return editor.commands.insertContent(indent);
|
|
135
|
-
}
|
|
136
|
-
return editor.commands.command(({ tr }) => {
|
|
137
|
-
const { from, to } = selection;
|
|
138
|
-
const text = state.doc.textBetween(from, to, "\n", "\n");
|
|
139
|
-
const lines = text.split("\n");
|
|
140
|
-
const indentedText = lines.map((line) => indent + line).join("\n");
|
|
141
|
-
tr.replaceWith(from, to, state.schema.text(indentedText));
|
|
142
|
-
return true;
|
|
143
|
-
});
|
|
144
|
-
},
|
|
145
|
-
// handle shift+tab reverse indentation
|
|
146
|
-
"Shift-Tab": ({ editor }) => {
|
|
147
|
-
var _a;
|
|
148
|
-
if (!this.options.enableTabIndentation) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
const tabSize = (_a = this.options.tabSize) != null ? _a : DEFAULT_TAB_SIZE;
|
|
152
|
-
const { state } = editor;
|
|
153
|
-
const { selection } = state;
|
|
154
|
-
const { $from, empty } = selection;
|
|
155
|
-
if ($from.parent.type !== this.type) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
if (empty) {
|
|
159
|
-
return editor.commands.command(({ tr }) => {
|
|
160
|
-
var _a2;
|
|
161
|
-
const { pos } = $from;
|
|
162
|
-
const codeBlockStart = $from.start();
|
|
163
|
-
const codeBlockEnd = $from.end();
|
|
164
|
-
const allText = state.doc.textBetween(codeBlockStart, codeBlockEnd, "\n", "\n");
|
|
165
|
-
const lines = allText.split("\n");
|
|
166
|
-
let currentLineIndex = 0;
|
|
167
|
-
let charCount = 0;
|
|
168
|
-
const relativeCursorPos = pos - codeBlockStart;
|
|
169
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
170
|
-
if (charCount + lines[i].length >= relativeCursorPos) {
|
|
171
|
-
currentLineIndex = i;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
charCount += lines[i].length + 1;
|
|
175
|
-
}
|
|
176
|
-
const currentLine = lines[currentLineIndex];
|
|
177
|
-
const leadingSpaces = ((_a2 = currentLine.match(/^ */)) == null ? void 0 : _a2[0]) || "";
|
|
178
|
-
const spacesToRemove = Math.min(leadingSpaces.length, tabSize);
|
|
179
|
-
if (spacesToRemove === 0) {
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
let lineStartPos = codeBlockStart;
|
|
183
|
-
for (let i = 0; i < currentLineIndex; i += 1) {
|
|
184
|
-
lineStartPos += lines[i].length + 1;
|
|
185
|
-
}
|
|
186
|
-
tr.delete(lineStartPos, lineStartPos + spacesToRemove);
|
|
187
|
-
const cursorPosInLine = pos - lineStartPos;
|
|
188
|
-
if (cursorPosInLine <= spacesToRemove) {
|
|
189
|
-
tr.setSelection(TextSelection.create(tr.doc, lineStartPos));
|
|
190
|
-
}
|
|
191
|
-
return true;
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
return editor.commands.command(({ tr }) => {
|
|
195
|
-
const { from, to } = selection;
|
|
196
|
-
const text = state.doc.textBetween(from, to, "\n", "\n");
|
|
197
|
-
const lines = text.split("\n");
|
|
198
|
-
const reverseIndentText = lines.map((line) => {
|
|
199
|
-
var _a2;
|
|
200
|
-
const leadingSpaces = ((_a2 = line.match(/^ */)) == null ? void 0 : _a2[0]) || "";
|
|
201
|
-
const spacesToRemove = Math.min(leadingSpaces.length, tabSize);
|
|
202
|
-
return line.slice(spacesToRemove);
|
|
203
|
-
}).join("\n");
|
|
204
|
-
tr.replaceWith(from, to, state.schema.text(reverseIndentText));
|
|
205
|
-
return true;
|
|
206
|
-
});
|
|
207
|
-
},
|
|
208
|
-
// exit node on triple enter
|
|
209
|
-
Enter: ({ editor }) => {
|
|
210
|
-
if (!this.options.exitOnTripleEnter) {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
const { state } = editor;
|
|
214
|
-
const { selection } = state;
|
|
215
|
-
const { $from, empty } = selection;
|
|
216
|
-
if (!empty || $from.parent.type !== this.type) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
|
|
220
|
-
const endsWithDoubleNewline = $from.parent.textContent.endsWith("\n\n");
|
|
221
|
-
if (!isAtEnd || !endsWithDoubleNewline) {
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
return editor.chain().command(({ tr }) => {
|
|
225
|
-
tr.delete($from.pos - 2, $from.pos);
|
|
226
|
-
return true;
|
|
227
|
-
}).exitCode().run();
|
|
228
|
-
},
|
|
229
|
-
// exit node on arrow down
|
|
230
|
-
ArrowDown: ({ editor }) => {
|
|
231
|
-
if (!this.options.exitOnArrowDown) {
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
const { state } = editor;
|
|
235
|
-
const { selection, doc } = state;
|
|
236
|
-
const { $from, empty } = selection;
|
|
237
|
-
if (!empty || $from.parent.type !== this.type) {
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
|
|
241
|
-
if (!isAtEnd) {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
const after = $from.after();
|
|
245
|
-
if (after === void 0) {
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
const nodeAfter = doc.nodeAt(after);
|
|
249
|
-
if (nodeAfter) {
|
|
250
|
-
return editor.commands.command(({ tr }) => {
|
|
251
|
-
tr.setSelection(Selection.near(doc.resolve(after)));
|
|
252
|
-
return true;
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
return editor.commands.exitCode();
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
},
|
|
259
|
-
addInputRules() {
|
|
260
|
-
return [
|
|
261
|
-
textblockTypeInputRule({
|
|
262
|
-
find: backtickInputRegex,
|
|
263
|
-
type: this.type,
|
|
264
|
-
getAttributes: (match) => ({
|
|
265
|
-
language: match[1]
|
|
266
|
-
})
|
|
267
|
-
}),
|
|
268
|
-
textblockTypeInputRule({
|
|
269
|
-
find: tildeInputRegex,
|
|
270
|
-
type: this.type,
|
|
271
|
-
getAttributes: (match) => ({
|
|
272
|
-
language: match[1]
|
|
273
|
-
})
|
|
274
|
-
})
|
|
275
|
-
];
|
|
276
|
-
},
|
|
277
|
-
addProseMirrorPlugins() {
|
|
278
|
-
return [
|
|
279
|
-
// this plugin creates a code block for pasted content from VS Code
|
|
280
|
-
// we can also detect the copied code language
|
|
281
|
-
new Plugin({
|
|
282
|
-
key: new PluginKey("codeBlockVSCodeHandler"),
|
|
283
|
-
props: {
|
|
284
|
-
handlePaste: (view, event) => {
|
|
285
|
-
if (!event.clipboardData) {
|
|
286
|
-
return false;
|
|
287
|
-
}
|
|
288
|
-
if (this.editor.isActive(this.type.name)) {
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
291
|
-
const text = event.clipboardData.getData("text/plain");
|
|
292
|
-
const vscode = event.clipboardData.getData("vscode-editor-data");
|
|
293
|
-
const vscodeData = vscode ? JSON.parse(vscode) : void 0;
|
|
294
|
-
const language = vscodeData == null ? void 0 : vscodeData.mode;
|
|
295
|
-
if (!text || !language) {
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
const { tr, schema } = view.state;
|
|
299
|
-
const textNode = schema.text(text.replace(/\r\n?/g, "\n"));
|
|
300
|
-
tr.replaceSelectionWith(this.type.create({ language }, textNode));
|
|
301
|
-
if (tr.selection.$from.parent.type !== this.type) {
|
|
302
|
-
tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))));
|
|
303
|
-
}
|
|
304
|
-
tr.setMeta("paste", true);
|
|
305
|
-
view.dispatch(tr);
|
|
306
|
-
return true;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
})
|
|
310
|
-
];
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
// src/index.ts
|
|
315
|
-
var index_default = CodeBlock;
|
|
316
|
-
export {
|
|
317
|
-
CodeBlock,
|
|
318
|
-
backtickInputRegex,
|
|
319
|
-
index_default as default,
|
|
320
|
-
tildeInputRegex
|
|
321
|
-
};
|
|
322
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/code-block.ts","../src/index.ts"],"sourcesContent":["import { mergeAttributes, Node, textblockTypeInputRule } from '@tiptap/core'\nimport { Plugin, PluginKey, Selection, TextSelection } from '@tiptap/pm/state'\n\nconst DEFAULT_TAB_SIZE = 4\n\nexport interface CodeBlockOptions {\n /**\n * Adds a prefix to language classes that are applied to code tags.\n * @default 'language-'\n */\n languageClassPrefix: string | null | undefined\n /**\n * Define whether the node should be exited on triple enter.\n * @default true\n */\n exitOnTripleEnter: boolean | null | undefined\n /**\n * Define whether the node should be exited on arrow down if there is no node after it.\n * @default true\n */\n exitOnArrowDown: boolean | null | undefined\n /**\n * The default language.\n * @default null\n * @example 'js'\n */\n defaultLanguage: string | null | undefined\n /**\n * Enable tab key for indentation in code blocks.\n * @default false\n */\n enableTabIndentation: boolean | null | undefined\n /**\n * The number of spaces to use for tab indentation.\n * @default 4\n */\n tabSize: number | null | undefined\n /**\n * Custom HTML attributes that should be added to the rendered HTML tag.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n codeBlock: {\n /**\n * Set a code block\n * @param attributes Code block attributes\n * @example editor.commands.setCodeBlock({ language: 'javascript' })\n */\n setCodeBlock: (attributes?: { language: string }) => ReturnType\n /**\n * Toggle a code block\n * @param attributes Code block attributes\n * @example editor.commands.toggleCodeBlock({ language: 'javascript' })\n */\n toggleCodeBlock: (attributes?: { language: string }) => ReturnType\n }\n }\n}\n\n/**\n * Matches a code block with backticks.\n */\nexport const backtickInputRegex = /^```([a-z]+)?[\\s\\n]$/\n\n/**\n * Matches a code block with tildes.\n */\nexport const tildeInputRegex = /^~~~([a-z]+)?[\\s\\n]$/\n\n/**\n * This extension allows you to create code blocks.\n * @see https://tiptap.dev/api/nodes/code-block\n */\nexport const CodeBlock = Node.create<CodeBlockOptions>({\n name: 'codeBlock',\n\n addOptions() {\n return {\n languageClassPrefix: 'language-',\n exitOnTripleEnter: true,\n exitOnArrowDown: true,\n defaultLanguage: null,\n enableTabIndentation: false,\n tabSize: DEFAULT_TAB_SIZE,\n HTMLAttributes: {},\n }\n },\n\n content: 'text*',\n\n marks: '',\n\n group: 'block',\n\n code: true,\n\n defining: true,\n\n addAttributes() {\n return {\n language: {\n default: this.options.defaultLanguage,\n parseHTML: element => {\n const { languageClassPrefix } = this.options\n\n if (!languageClassPrefix) {\n return null\n }\n\n const classNames = [...(element.firstElementChild?.classList || [])]\n const languages = classNames\n .filter(className => className.startsWith(languageClassPrefix))\n .map(className => className.replace(languageClassPrefix, ''))\n const language = languages[0]\n\n if (!language) {\n return null\n }\n\n return language\n },\n rendered: false,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n },\n ]\n },\n\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'pre',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n [\n 'code',\n {\n class: node.attrs.language ? this.options.languageClassPrefix + node.attrs.language : null,\n },\n 0,\n ],\n ]\n },\n\n markdownTokenName: 'code',\n\n parseMarkdown: (token, helpers) => {\n if (\n token.raw?.startsWith('```') === false &&\n token.raw?.startsWith('~~~') === false &&\n token.codeBlockStyle !== 'indented'\n ) {\n return []\n }\n\n return helpers.createNode(\n 'codeBlock',\n { language: token.lang || null },\n token.text ? [helpers.createTextNode(token.text)] : [],\n )\n },\n\n renderMarkdown: (node, h) => {\n let output = ''\n const language = node.attrs?.language || ''\n\n if (!node.content) {\n output = `\\`\\`\\`${language}\\n\\n\\`\\`\\``\n } else {\n const lines = [`\\`\\`\\`${language}`, h.renderChildren(node.content), '```']\n output = lines.join('\\n')\n }\n\n return output\n },\n\n addCommands() {\n return {\n setCodeBlock:\n attributes =>\n ({ commands }) => {\n return commands.setNode(this.name, attributes)\n },\n toggleCodeBlock:\n attributes =>\n ({ commands }) => {\n return commands.toggleNode(this.name, 'paragraph', attributes)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Alt-c': () => this.editor.commands.toggleCodeBlock(),\n\n // remove code block when at start of document or code block is empty\n Backspace: () => {\n const { empty, $anchor } = this.editor.state.selection\n const isAtStart = $anchor.pos === 1\n\n if (!empty || $anchor.parent.type.name !== this.name) {\n return false\n }\n\n if (isAtStart || !$anchor.parent.textContent.length) {\n return this.editor.commands.clearNodes()\n }\n\n return false\n },\n\n // handle tab indentation\n Tab: ({ editor }) => {\n if (!this.options.enableTabIndentation) {\n return false\n }\n\n const tabSize = this.options.tabSize ?? DEFAULT_TAB_SIZE\n const { state } = editor\n const { selection } = state\n const { $from, empty } = selection\n\n if ($from.parent.type !== this.type) {\n return false\n }\n\n const indent = ' '.repeat(tabSize)\n\n if (empty) {\n return editor.commands.insertContent(indent)\n }\n\n return editor.commands.command(({ tr }) => {\n const { from, to } = selection\n const text = state.doc.textBetween(from, to, '\\n', '\\n')\n const lines = text.split('\\n')\n const indentedText = lines.map(line => indent + line).join('\\n')\n\n tr.replaceWith(from, to, state.schema.text(indentedText))\n return true\n })\n },\n\n // handle shift+tab reverse indentation\n 'Shift-Tab': ({ editor }) => {\n if (!this.options.enableTabIndentation) {\n return false\n }\n\n const tabSize = this.options.tabSize ?? DEFAULT_TAB_SIZE\n const { state } = editor\n const { selection } = state\n const { $from, empty } = selection\n\n if ($from.parent.type !== this.type) {\n return false\n }\n\n if (empty) {\n return editor.commands.command(({ tr }) => {\n const { pos } = $from\n const codeBlockStart = $from.start()\n const codeBlockEnd = $from.end()\n\n const allText = state.doc.textBetween(codeBlockStart, codeBlockEnd, '\\n', '\\n')\n const lines = allText.split('\\n')\n\n let currentLineIndex = 0\n let charCount = 0\n const relativeCursorPos = pos - codeBlockStart\n\n for (let i = 0; i < lines.length; i += 1) {\n if (charCount + lines[i].length >= relativeCursorPos) {\n currentLineIndex = i\n break\n }\n charCount += lines[i].length + 1\n }\n\n const currentLine = lines[currentLineIndex]\n const leadingSpaces = currentLine.match(/^ */)?.[0] || ''\n const spacesToRemove = Math.min(leadingSpaces.length, tabSize)\n\n if (spacesToRemove === 0) {\n return true\n }\n\n let lineStartPos = codeBlockStart\n for (let i = 0; i < currentLineIndex; i += 1) {\n lineStartPos += lines[i].length + 1\n }\n\n tr.delete(lineStartPos, lineStartPos + spacesToRemove)\n\n const cursorPosInLine = pos - lineStartPos\n if (cursorPosInLine <= spacesToRemove) {\n tr.setSelection(TextSelection.create(tr.doc, lineStartPos))\n }\n\n return true\n })\n }\n\n return editor.commands.command(({ tr }) => {\n const { from, to } = selection\n const text = state.doc.textBetween(from, to, '\\n', '\\n')\n const lines = text.split('\\n')\n const reverseIndentText = lines\n .map(line => {\n const leadingSpaces = line.match(/^ */)?.[0] || ''\n const spacesToRemove = Math.min(leadingSpaces.length, tabSize)\n return line.slice(spacesToRemove)\n })\n .join('\\n')\n\n tr.replaceWith(from, to, state.schema.text(reverseIndentText))\n return true\n })\n },\n\n // exit node on triple enter\n Enter: ({ editor }) => {\n if (!this.options.exitOnTripleEnter) {\n return false\n }\n\n const { state } = editor\n const { selection } = state\n const { $from, empty } = selection\n\n if (!empty || $from.parent.type !== this.type) {\n return false\n }\n\n const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2\n const endsWithDoubleNewline = $from.parent.textContent.endsWith('\\n\\n')\n\n if (!isAtEnd || !endsWithDoubleNewline) {\n return false\n }\n\n return editor\n .chain()\n .command(({ tr }) => {\n tr.delete($from.pos - 2, $from.pos)\n\n return true\n })\n .exitCode()\n .run()\n },\n\n // exit node on arrow down\n ArrowDown: ({ editor }) => {\n if (!this.options.exitOnArrowDown) {\n return false\n }\n\n const { state } = editor\n const { selection, doc } = state\n const { $from, empty } = selection\n\n if (!empty || $from.parent.type !== this.type) {\n return false\n }\n\n const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2\n\n if (!isAtEnd) {\n return false\n }\n\n const after = $from.after()\n\n if (after === undefined) {\n return false\n }\n\n const nodeAfter = doc.nodeAt(after)\n\n if (nodeAfter) {\n return editor.commands.command(({ tr }) => {\n tr.setSelection(Selection.near(doc.resolve(after)))\n return true\n })\n }\n\n return editor.commands.exitCode()\n },\n }\n },\n\n addInputRules() {\n return [\n textblockTypeInputRule({\n find: backtickInputRegex,\n type: this.type,\n getAttributes: match => ({\n language: match[1],\n }),\n }),\n textblockTypeInputRule({\n find: tildeInputRegex,\n type: this.type,\n getAttributes: match => ({\n language: match[1],\n }),\n }),\n ]\n },\n\n addProseMirrorPlugins() {\n return [\n // this plugin creates a code block for pasted content from VS Code\n // we can also detect the copied code language\n new Plugin({\n key: new PluginKey('codeBlockVSCodeHandler'),\n props: {\n handlePaste: (view, event) => {\n if (!event.clipboardData) {\n return false\n }\n\n // don’t create a new code block within code blocks\n if (this.editor.isActive(this.type.name)) {\n return false\n }\n\n const text = event.clipboardData.getData('text/plain')\n const vscode = event.clipboardData.getData('vscode-editor-data')\n const vscodeData = vscode ? JSON.parse(vscode) : undefined\n const language = vscodeData?.mode\n\n if (!text || !language) {\n return false\n }\n\n const { tr, schema } = view.state\n\n // prepare a text node\n // strip carriage return chars from text pasted as code\n // see: https://github.com/ProseMirror/prosemirror-view/commit/a50a6bcceb4ce52ac8fcc6162488d8875613aacd\n const textNode = schema.text(text.replace(/\\r\\n?/g, '\\n'))\n\n // create a code block with the text node\n // replace selection with the code block\n tr.replaceSelectionWith(this.type.create({ language }, textNode))\n\n if (tr.selection.$from.parent.type !== this.type) {\n // put cursor inside the newly created code block\n tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))))\n }\n\n // store meta information\n // this is useful for other plugins that depends on the paste event\n // like the paste rule plugin\n tr.setMeta('paste', true)\n\n view.dispatch(tr)\n\n return true\n },\n },\n }),\n ]\n },\n})\n","import { CodeBlock } from './code-block.js'\n\nexport * from './code-block.js'\n\nexport default CodeBlock\n"],"mappings":";AAAA,SAAS,iBAAiB,MAAM,8BAA8B;AAC9D,SAAS,QAAQ,WAAW,WAAW,qBAAqB;AAE5D,IAAM,mBAAmB;AAgElB,IAAM,qBAAqB;AAK3B,IAAM,kBAAkB;AAMxB,IAAM,YAAY,KAAK,OAAyB;AAAA,EACrD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,qBAAqB;AAAA,MACrB,mBAAmB;AAAA,MACnB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,MACjB,sBAAsB;AAAA,MACtB,SAAS;AAAA,MACT,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,SAAS;AAAA,EAET,OAAO;AAAA,EAEP,OAAO;AAAA,EAEP,MAAM;AAAA,EAEN,UAAU;AAAA,EAEV,gBAAgB;AACd,WAAO;AAAA,MACL,UAAU;AAAA,QACR,SAAS,KAAK,QAAQ;AAAA,QACtB,WAAW,aAAW;AA3G9B;AA4GU,gBAAM,EAAE,oBAAoB,IAAI,KAAK;AAErC,cAAI,CAAC,qBAAqB;AACxB,mBAAO;AAAA,UACT;AAEA,gBAAM,aAAa,CAAC,KAAI,aAAQ,sBAAR,mBAA2B,cAAa,CAAC,CAAE;AACnE,gBAAM,YAAY,WACf,OAAO,eAAa,UAAU,WAAW,mBAAmB,CAAC,EAC7D,IAAI,eAAa,UAAU,QAAQ,qBAAqB,EAAE,CAAC;AAC9D,gBAAM,WAAW,UAAU,CAAC;AAE5B,cAAI,CAAC,UAAU;AACb,mBAAO;AAAA,UACT;AAEA,iBAAO;AAAA,QACT;AAAA,QACA,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAAA,E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