@tiptap/extension-code-block
Advanced tools
+16
-8
@@ -33,2 +33,3 @@ "use strict"; | ||
| var import_state = require("@tiptap/pm/state"); | ||
| var DEFAULT_TAB_SIZE = 4; | ||
| var backtickInputRegex = /^```([a-z]+)?[\s\n]$/; | ||
@@ -45,3 +46,3 @@ var tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/; | ||
| enableTabIndentation: false, | ||
| tabSize: 4, | ||
| tabSize: DEFAULT_TAB_SIZE, | ||
| HTMLAttributes: {} | ||
@@ -62,2 +63,5 @@ }; | ||
| const { languageClassPrefix } = this.options; | ||
| if (!languageClassPrefix) { | ||
| return null; | ||
| } | ||
| const classNames = [...((_a = element.firstElementChild) == null ? void 0 : _a.classList) || []]; | ||
@@ -123,5 +127,7 @@ const languages = classNames.filter((className) => className.startsWith(languageClassPrefix)).map((className) => className.replace(languageClassPrefix, "")); | ||
| Tab: ({ editor }) => { | ||
| var _a; | ||
| if (!this.options.enableTabIndentation) { | ||
| return false; | ||
| } | ||
| const tabSize = (_a = this.options.tabSize) != null ? _a : DEFAULT_TAB_SIZE; | ||
| const { state } = editor; | ||
@@ -133,3 +139,3 @@ const { selection } = state; | ||
| } | ||
| const indent = " ".repeat(this.options.tabSize); | ||
| const indent = " ".repeat(tabSize); | ||
| if (empty) { | ||
@@ -149,5 +155,7 @@ return editor.commands.insertContent(indent); | ||
| "Shift-Tab": ({ editor }) => { | ||
| var _a; | ||
| if (!this.options.enableTabIndentation) { | ||
| return false; | ||
| } | ||
| const tabSize = (_a = this.options.tabSize) != null ? _a : DEFAULT_TAB_SIZE; | ||
| const { state } = editor; | ||
@@ -161,3 +169,3 @@ const { selection } = state; | ||
| return editor.commands.command(({ tr }) => { | ||
| var _a; | ||
| var _a2; | ||
| const { pos } = $from; | ||
@@ -179,4 +187,4 @@ const codeBlockStart = $from.start(); | ||
| const currentLine = lines[currentLineIndex]; | ||
| const leadingSpaces = ((_a = currentLine.match(/^ */)) == null ? void 0 : _a[0]) || ""; | ||
| const spacesToRemove = Math.min(leadingSpaces.length, this.options.tabSize); | ||
| const leadingSpaces = ((_a2 = currentLine.match(/^ */)) == null ? void 0 : _a2[0]) || ""; | ||
| const spacesToRemove = Math.min(leadingSpaces.length, tabSize); | ||
| if (spacesToRemove === 0) { | ||
@@ -202,5 +210,5 @@ return true; | ||
| const reverseIndentText = lines.map((line) => { | ||
| var _a; | ||
| const leadingSpaces = ((_a = line.match(/^ */)) == null ? void 0 : _a[0]) || ""; | ||
| const spacesToRemove = Math.min(leadingSpaces.length, this.options.tabSize); | ||
| var _a2; | ||
| const leadingSpaces = ((_a2 = line.match(/^ */)) == null ? void 0 : _a2[0]) || ""; | ||
| const spacesToRemove = Math.min(leadingSpaces.length, tabSize); | ||
| return line.slice(spacesToRemove); | ||
@@ -207,0 +215,0 @@ }).join("\n"); |
+5
-5
@@ -8,3 +8,3 @@ import { Node } from '@tiptap/core'; | ||
| */ | ||
| languageClassPrefix: string; | ||
| languageClassPrefix: string | null | undefined; | ||
| /** | ||
@@ -14,3 +14,3 @@ * Define whether the node should be exited on triple enter. | ||
| */ | ||
| exitOnTripleEnter: boolean; | ||
| exitOnTripleEnter: boolean | null | undefined; | ||
| /** | ||
@@ -20,3 +20,3 @@ * Define whether the node should be exited on arrow down if there is no node after it. | ||
| */ | ||
| exitOnArrowDown: boolean; | ||
| exitOnArrowDown: boolean | null | undefined; | ||
| /** | ||
@@ -32,3 +32,3 @@ * The default language. | ||
| */ | ||
| enableTabIndentation: boolean; | ||
| enableTabIndentation: boolean | null | undefined; | ||
| /** | ||
@@ -38,3 +38,3 @@ * The number of spaces to use for tab indentation. | ||
| */ | ||
| tabSize: number; | ||
| tabSize: number | null | undefined; | ||
| /** | ||
@@ -41,0 +41,0 @@ * Custom HTML attributes that should be added to the rendered HTML tag. |
+5
-5
@@ -8,3 +8,3 @@ import { Node } from '@tiptap/core'; | ||
| */ | ||
| languageClassPrefix: string; | ||
| languageClassPrefix: string | null | undefined; | ||
| /** | ||
@@ -14,3 +14,3 @@ * Define whether the node should be exited on triple enter. | ||
| */ | ||
| exitOnTripleEnter: boolean; | ||
| exitOnTripleEnter: boolean | null | undefined; | ||
| /** | ||
@@ -20,3 +20,3 @@ * Define whether the node should be exited on arrow down if there is no node after it. | ||
| */ | ||
| exitOnArrowDown: boolean; | ||
| exitOnArrowDown: boolean | null | undefined; | ||
| /** | ||
@@ -32,3 +32,3 @@ * The default language. | ||
| */ | ||
| enableTabIndentation: boolean; | ||
| enableTabIndentation: boolean | null | undefined; | ||
| /** | ||
@@ -38,3 +38,3 @@ * The number of spaces to use for tab indentation. | ||
| */ | ||
| tabSize: number; | ||
| tabSize: number | null | undefined; | ||
| /** | ||
@@ -41,0 +41,0 @@ * Custom HTML attributes that should be added to the rendered HTML tag. |
+16
-8
| // src/code-block.ts | ||
| import { mergeAttributes, Node, textblockTypeInputRule } from "@tiptap/core"; | ||
| import { Plugin, PluginKey, Selection, TextSelection } from "@tiptap/pm/state"; | ||
| var DEFAULT_TAB_SIZE = 4; | ||
| var backtickInputRegex = /^```([a-z]+)?[\s\n]$/; | ||
@@ -15,3 +16,3 @@ var tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/; | ||
| enableTabIndentation: false, | ||
| tabSize: 4, | ||
| tabSize: DEFAULT_TAB_SIZE, | ||
| HTMLAttributes: {} | ||
@@ -32,2 +33,5 @@ }; | ||
| const { languageClassPrefix } = this.options; | ||
| if (!languageClassPrefix) { | ||
| return null; | ||
| } | ||
| const classNames = [...((_a = element.firstElementChild) == null ? void 0 : _a.classList) || []]; | ||
@@ -93,5 +97,7 @@ const languages = classNames.filter((className) => className.startsWith(languageClassPrefix)).map((className) => className.replace(languageClassPrefix, "")); | ||
| Tab: ({ editor }) => { | ||
| var _a; | ||
| if (!this.options.enableTabIndentation) { | ||
| return false; | ||
| } | ||
| const tabSize = (_a = this.options.tabSize) != null ? _a : DEFAULT_TAB_SIZE; | ||
| const { state } = editor; | ||
@@ -103,3 +109,3 @@ const { selection } = state; | ||
| } | ||
| const indent = " ".repeat(this.options.tabSize); | ||
| const indent = " ".repeat(tabSize); | ||
| if (empty) { | ||
@@ -119,5 +125,7 @@ return editor.commands.insertContent(indent); | ||
| "Shift-Tab": ({ editor }) => { | ||
| var _a; | ||
| if (!this.options.enableTabIndentation) { | ||
| return false; | ||
| } | ||
| const tabSize = (_a = this.options.tabSize) != null ? _a : DEFAULT_TAB_SIZE; | ||
| const { state } = editor; | ||
@@ -131,3 +139,3 @@ const { selection } = state; | ||
| return editor.commands.command(({ tr }) => { | ||
| var _a; | ||
| var _a2; | ||
| const { pos } = $from; | ||
@@ -149,4 +157,4 @@ const codeBlockStart = $from.start(); | ||
| const currentLine = lines[currentLineIndex]; | ||
| const leadingSpaces = ((_a = currentLine.match(/^ */)) == null ? void 0 : _a[0]) || ""; | ||
| const spacesToRemove = Math.min(leadingSpaces.length, this.options.tabSize); | ||
| const leadingSpaces = ((_a2 = currentLine.match(/^ */)) == null ? void 0 : _a2[0]) || ""; | ||
| const spacesToRemove = Math.min(leadingSpaces.length, tabSize); | ||
| if (spacesToRemove === 0) { | ||
@@ -172,5 +180,5 @@ return true; | ||
| const reverseIndentText = lines.map((line) => { | ||
| var _a; | ||
| const leadingSpaces = ((_a = line.match(/^ */)) == null ? void 0 : _a[0]) || ""; | ||
| const spacesToRemove = Math.min(leadingSpaces.length, this.options.tabSize); | ||
| var _a2; | ||
| const leadingSpaces = ((_a2 = line.match(/^ */)) == null ? void 0 : _a2[0]) || ""; | ||
| const spacesToRemove = Math.min(leadingSpaces.length, tabSize); | ||
| return line.slice(spacesToRemove); | ||
@@ -177,0 +185,0 @@ }).join("\n"); |
+5
-5
| { | ||
| "name": "@tiptap/extension-code-block", | ||
| "description": "code block extension for tiptap", | ||
| "version": "3.6.2", | ||
| "version": "3.6.3", | ||
| "homepage": "https://tiptap.dev", | ||
@@ -34,8 +34,8 @@ "keywords": [ | ||
| "devDependencies": { | ||
| "@tiptap/core": "^3.6.2", | ||
| "@tiptap/pm": "^3.6.2" | ||
| "@tiptap/core": "^3.6.3", | ||
| "@tiptap/pm": "^3.6.3" | ||
| }, | ||
| "peerDependencies": { | ||
| "@tiptap/core": "^3.6.2", | ||
| "@tiptap/pm": "^3.6.2" | ||
| "@tiptap/core": "^3.6.3", | ||
| "@tiptap/pm": "^3.6.3" | ||
| }, | ||
@@ -42,0 +42,0 @@ "repository": { |
+18
-9
| import { mergeAttributes, Node, textblockTypeInputRule } from '@tiptap/core' | ||
| import { Plugin, PluginKey, Selection, TextSelection } from '@tiptap/pm/state' | ||
| const DEFAULT_TAB_SIZE = 4 | ||
| export interface CodeBlockOptions { | ||
@@ -9,3 +11,3 @@ /** | ||
| */ | ||
| languageClassPrefix: string | ||
| languageClassPrefix: string | null | undefined | ||
| /** | ||
@@ -15,3 +17,3 @@ * Define whether the node should be exited on triple enter. | ||
| */ | ||
| exitOnTripleEnter: boolean | ||
| exitOnTripleEnter: boolean | null | undefined | ||
| /** | ||
@@ -21,3 +23,3 @@ * Define whether the node should be exited on arrow down if there is no node after it. | ||
| */ | ||
| exitOnArrowDown: boolean | ||
| exitOnArrowDown: boolean | null | undefined | ||
| /** | ||
@@ -33,3 +35,3 @@ * The default language. | ||
| */ | ||
| enableTabIndentation: boolean | ||
| enableTabIndentation: boolean | null | undefined | ||
| /** | ||
@@ -39,3 +41,3 @@ * The number of spaces to use for tab indentation. | ||
| */ | ||
| tabSize: number | ||
| tabSize: number | null | undefined | ||
| /** | ||
@@ -92,3 +94,3 @@ * Custom HTML attributes that should be added to the rendered HTML tag. | ||
| enableTabIndentation: false, | ||
| tabSize: 4, | ||
| tabSize: DEFAULT_TAB_SIZE, | ||
| HTMLAttributes: {}, | ||
@@ -114,2 +116,7 @@ } | ||
| const { languageClassPrefix } = this.options | ||
| if (!languageClassPrefix) { | ||
| return null | ||
| } | ||
| const classNames = [...(element.firstElementChild?.classList || [])] | ||
@@ -196,2 +203,3 @@ const languages = classNames | ||
| const tabSize = this.options.tabSize ?? DEFAULT_TAB_SIZE | ||
| const { state } = editor | ||
@@ -205,3 +213,3 @@ const { selection } = state | ||
| const indent = ' '.repeat(this.options.tabSize) | ||
| const indent = ' '.repeat(tabSize) | ||
@@ -229,2 +237,3 @@ if (empty) { | ||
| const tabSize = this.options.tabSize ?? DEFAULT_TAB_SIZE | ||
| const { state } = editor | ||
@@ -261,3 +270,3 @@ const { selection } = state | ||
| const leadingSpaces = currentLine.match(/^ */)?.[0] || '' | ||
| const spacesToRemove = Math.min(leadingSpaces.length, this.options.tabSize) | ||
| const spacesToRemove = Math.min(leadingSpaces.length, tabSize) | ||
@@ -291,3 +300,3 @@ if (spacesToRemove === 0) { | ||
| const leadingSpaces = line.match(/^ */)?.[0] || '' | ||
| const spacesToRemove = Math.min(leadingSpaces.length, this.options.tabSize) | ||
| const spacesToRemove = Math.min(leadingSpaces.length, tabSize) | ||
| return line.slice(spacesToRemove) | ||
@@ -294,0 +303,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
79962
2.59%1063
2.11%