@tiptap/extension-code-block 2.0.0-beta.21 → 2.0.0-beta.210

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/index.cjs ADDED
@@ -0,0 +1,189 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/code-block.ts
2
+ var _core = require('@tiptap/core');
3
+ var _state = require('@tiptap/pm/state');
4
+ var backtickInputRegex = /^```([a-z]+)?[\s\n]$/;
5
+ var tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/;
6
+ var CodeBlock = _core.Node.create({
7
+ name: "codeBlock",
8
+ addOptions() {
9
+ return {
10
+ languageClassPrefix: "language-",
11
+ exitOnTripleEnter: true,
12
+ exitOnArrowDown: true,
13
+ HTMLAttributes: {}
14
+ };
15
+ },
16
+ content: "text*",
17
+ marks: "",
18
+ group: "block",
19
+ code: true,
20
+ defining: true,
21
+ addAttributes() {
22
+ return {
23
+ language: {
24
+ default: null,
25
+ parseHTML: (element) => {
26
+ var _a;
27
+ const { languageClassPrefix } = this.options;
28
+ const classNames = [...((_a = element.firstElementChild) == null ? void 0 : _a.classList) || []];
29
+ const languages = classNames.filter((className) => className.startsWith(languageClassPrefix)).map((className) => className.replace(languageClassPrefix, ""));
30
+ const language = languages[0];
31
+ if (!language) {
32
+ return null;
33
+ }
34
+ return language;
35
+ },
36
+ rendered: false
37
+ }
38
+ };
39
+ },
40
+ parseHTML() {
41
+ return [
42
+ {
43
+ tag: "pre",
44
+ preserveWhitespace: "full"
45
+ }
46
+ ];
47
+ },
48
+ renderHTML({ node, HTMLAttributes }) {
49
+ return [
50
+ "pre",
51
+ _core.mergeAttributes.call(void 0, this.options.HTMLAttributes, HTMLAttributes),
52
+ [
53
+ "code",
54
+ {
55
+ class: node.attrs.language ? this.options.languageClassPrefix + node.attrs.language : null
56
+ },
57
+ 0
58
+ ]
59
+ ];
60
+ },
61
+ addCommands() {
62
+ return {
63
+ setCodeBlock: (attributes) => ({ commands }) => {
64
+ return commands.setNode(this.name, attributes);
65
+ },
66
+ toggleCodeBlock: (attributes) => ({ commands }) => {
67
+ return commands.toggleNode(this.name, "paragraph", attributes);
68
+ }
69
+ };
70
+ },
71
+ addKeyboardShortcuts() {
72
+ return {
73
+ "Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),
74
+ Backspace: () => {
75
+ const { empty, $anchor } = this.editor.state.selection;
76
+ const isAtStart = $anchor.pos === 1;
77
+ if (!empty || $anchor.parent.type.name !== this.name) {
78
+ return false;
79
+ }
80
+ if (isAtStart || !$anchor.parent.textContent.length) {
81
+ return this.editor.commands.clearNodes();
82
+ }
83
+ return false;
84
+ },
85
+ Enter: ({ editor }) => {
86
+ if (!this.options.exitOnTripleEnter) {
87
+ return false;
88
+ }
89
+ const { state } = editor;
90
+ const { selection } = state;
91
+ const { $from, empty } = selection;
92
+ if (!empty || $from.parent.type !== this.type) {
93
+ return false;
94
+ }
95
+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
96
+ const endsWithDoubleNewline = $from.parent.textContent.endsWith("\n\n");
97
+ if (!isAtEnd || !endsWithDoubleNewline) {
98
+ return false;
99
+ }
100
+ return editor.chain().command(({ tr }) => {
101
+ tr.delete($from.pos - 2, $from.pos);
102
+ return true;
103
+ }).exitCode().run();
104
+ },
105
+ ArrowDown: ({ editor }) => {
106
+ if (!this.options.exitOnArrowDown) {
107
+ return false;
108
+ }
109
+ const { state } = editor;
110
+ const { selection, doc } = state;
111
+ const { $from, empty } = selection;
112
+ if (!empty || $from.parent.type !== this.type) {
113
+ return false;
114
+ }
115
+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
116
+ if (!isAtEnd) {
117
+ return false;
118
+ }
119
+ const after = $from.after();
120
+ if (after === void 0) {
121
+ return false;
122
+ }
123
+ const nodeAfter = doc.nodeAt(after);
124
+ if (nodeAfter) {
125
+ return false;
126
+ }
127
+ return editor.commands.exitCode();
128
+ }
129
+ };
130
+ },
131
+ addInputRules() {
132
+ return [
133
+ _core.textblockTypeInputRule.call(void 0, {
134
+ find: backtickInputRegex,
135
+ type: this.type,
136
+ getAttributes: (match) => ({
137
+ language: match[1]
138
+ })
139
+ }),
140
+ _core.textblockTypeInputRule.call(void 0, {
141
+ find: tildeInputRegex,
142
+ type: this.type,
143
+ getAttributes: (match) => ({
144
+ language: match[1]
145
+ })
146
+ })
147
+ ];
148
+ },
149
+ addProseMirrorPlugins() {
150
+ return [
151
+ new (0, _state.Plugin)({
152
+ key: new (0, _state.PluginKey)("codeBlockVSCodeHandler"),
153
+ props: {
154
+ handlePaste: (view, event) => {
155
+ if (!event.clipboardData) {
156
+ return false;
157
+ }
158
+ if (this.editor.isActive(this.type.name)) {
159
+ return false;
160
+ }
161
+ const text = event.clipboardData.getData("text/plain");
162
+ const vscode = event.clipboardData.getData("vscode-editor-data");
163
+ const vscodeData = vscode ? JSON.parse(vscode) : void 0;
164
+ const language = vscodeData == null ? void 0 : vscodeData.mode;
165
+ if (!text || !language) {
166
+ return false;
167
+ }
168
+ const { tr } = view.state;
169
+ tr.replaceSelectionWith(this.type.create({ language }));
170
+ tr.setSelection(_state.TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))));
171
+ tr.insertText(text.replace(/\r\n?/g, "\n"));
172
+ tr.setMeta("paste", true);
173
+ view.dispatch(tr);
174
+ return true;
175
+ }
176
+ }
177
+ })
178
+ ];
179
+ }
180
+ });
181
+
182
+ // src/index.ts
183
+ var src_default = CodeBlock;
184
+
185
+
186
+
187
+
188
+
189
+ exports.CodeBlock = CodeBlock; exports.backtickInputRegex = backtickInputRegex; exports.default = src_default; exports.tildeInputRegex = tildeInputRegex;
@@ -0,0 +1,46 @@
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
+ * Defaults to `'language-'`.
7
+ */
8
+ languageClassPrefix: string;
9
+ /**
10
+ * Define whether the node should be exited on triple enter.
11
+ * Defaults to `true`.
12
+ */
13
+ exitOnTripleEnter: boolean;
14
+ /**
15
+ * Define whether the node should be exited on arrow down if there is no node after it.
16
+ * Defaults to `true`.
17
+ */
18
+ exitOnArrowDown: boolean;
19
+ /**
20
+ * Custom HTML attributes that should be added to the rendered HTML tag.
21
+ */
22
+ HTMLAttributes: Record<string, any>;
23
+ }
24
+ declare module '@tiptap/core' {
25
+ interface Commands<ReturnType> {
26
+ codeBlock: {
27
+ /**
28
+ * Set a code block
29
+ */
30
+ setCodeBlock: (attributes?: {
31
+ language: string;
32
+ }) => ReturnType;
33
+ /**
34
+ * Toggle a code block
35
+ */
36
+ toggleCodeBlock: (attributes?: {
37
+ language: string;
38
+ }) => ReturnType;
39
+ };
40
+ }
41
+ }
42
+ declare const backtickInputRegex: RegExp;
43
+ declare const tildeInputRegex: RegExp;
44
+ declare const CodeBlock: Node<CodeBlockOptions, any>;
45
+
46
+ export { CodeBlock, CodeBlockOptions, backtickInputRegex, CodeBlock as default, tildeInputRegex };
package/dist/index.js ADDED
@@ -0,0 +1,189 @@
1
+ // src/code-block.ts
2
+ import { mergeAttributes, Node, textblockTypeInputRule } from "@tiptap/core";
3
+ import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
4
+ var backtickInputRegex = /^```([a-z]+)?[\s\n]$/;
5
+ var tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/;
6
+ var CodeBlock = Node.create({
7
+ name: "codeBlock",
8
+ addOptions() {
9
+ return {
10
+ languageClassPrefix: "language-",
11
+ exitOnTripleEnter: true,
12
+ exitOnArrowDown: true,
13
+ HTMLAttributes: {}
14
+ };
15
+ },
16
+ content: "text*",
17
+ marks: "",
18
+ group: "block",
19
+ code: true,
20
+ defining: true,
21
+ addAttributes() {
22
+ return {
23
+ language: {
24
+ default: null,
25
+ parseHTML: (element) => {
26
+ var _a;
27
+ const { languageClassPrefix } = this.options;
28
+ const classNames = [...((_a = element.firstElementChild) == null ? void 0 : _a.classList) || []];
29
+ const languages = classNames.filter((className) => className.startsWith(languageClassPrefix)).map((className) => className.replace(languageClassPrefix, ""));
30
+ const language = languages[0];
31
+ if (!language) {
32
+ return null;
33
+ }
34
+ return language;
35
+ },
36
+ rendered: false
37
+ }
38
+ };
39
+ },
40
+ parseHTML() {
41
+ return [
42
+ {
43
+ tag: "pre",
44
+ preserveWhitespace: "full"
45
+ }
46
+ ];
47
+ },
48
+ renderHTML({ node, HTMLAttributes }) {
49
+ return [
50
+ "pre",
51
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
52
+ [
53
+ "code",
54
+ {
55
+ class: node.attrs.language ? this.options.languageClassPrefix + node.attrs.language : null
56
+ },
57
+ 0
58
+ ]
59
+ ];
60
+ },
61
+ addCommands() {
62
+ return {
63
+ setCodeBlock: (attributes) => ({ commands }) => {
64
+ return commands.setNode(this.name, attributes);
65
+ },
66
+ toggleCodeBlock: (attributes) => ({ commands }) => {
67
+ return commands.toggleNode(this.name, "paragraph", attributes);
68
+ }
69
+ };
70
+ },
71
+ addKeyboardShortcuts() {
72
+ return {
73
+ "Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),
74
+ Backspace: () => {
75
+ const { empty, $anchor } = this.editor.state.selection;
76
+ const isAtStart = $anchor.pos === 1;
77
+ if (!empty || $anchor.parent.type.name !== this.name) {
78
+ return false;
79
+ }
80
+ if (isAtStart || !$anchor.parent.textContent.length) {
81
+ return this.editor.commands.clearNodes();
82
+ }
83
+ return false;
84
+ },
85
+ Enter: ({ editor }) => {
86
+ if (!this.options.exitOnTripleEnter) {
87
+ return false;
88
+ }
89
+ const { state } = editor;
90
+ const { selection } = state;
91
+ const { $from, empty } = selection;
92
+ if (!empty || $from.parent.type !== this.type) {
93
+ return false;
94
+ }
95
+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
96
+ const endsWithDoubleNewline = $from.parent.textContent.endsWith("\n\n");
97
+ if (!isAtEnd || !endsWithDoubleNewline) {
98
+ return false;
99
+ }
100
+ return editor.chain().command(({ tr }) => {
101
+ tr.delete($from.pos - 2, $from.pos);
102
+ return true;
103
+ }).exitCode().run();
104
+ },
105
+ ArrowDown: ({ editor }) => {
106
+ if (!this.options.exitOnArrowDown) {
107
+ return false;
108
+ }
109
+ const { state } = editor;
110
+ const { selection, doc } = state;
111
+ const { $from, empty } = selection;
112
+ if (!empty || $from.parent.type !== this.type) {
113
+ return false;
114
+ }
115
+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
116
+ if (!isAtEnd) {
117
+ return false;
118
+ }
119
+ const after = $from.after();
120
+ if (after === void 0) {
121
+ return false;
122
+ }
123
+ const nodeAfter = doc.nodeAt(after);
124
+ if (nodeAfter) {
125
+ return false;
126
+ }
127
+ return editor.commands.exitCode();
128
+ }
129
+ };
130
+ },
131
+ addInputRules() {
132
+ return [
133
+ textblockTypeInputRule({
134
+ find: backtickInputRegex,
135
+ type: this.type,
136
+ getAttributes: (match) => ({
137
+ language: match[1]
138
+ })
139
+ }),
140
+ textblockTypeInputRule({
141
+ find: tildeInputRegex,
142
+ type: this.type,
143
+ getAttributes: (match) => ({
144
+ language: match[1]
145
+ })
146
+ })
147
+ ];
148
+ },
149
+ addProseMirrorPlugins() {
150
+ return [
151
+ new Plugin({
152
+ key: new PluginKey("codeBlockVSCodeHandler"),
153
+ props: {
154
+ handlePaste: (view, event) => {
155
+ if (!event.clipboardData) {
156
+ return false;
157
+ }
158
+ if (this.editor.isActive(this.type.name)) {
159
+ return false;
160
+ }
161
+ const text = event.clipboardData.getData("text/plain");
162
+ const vscode = event.clipboardData.getData("vscode-editor-data");
163
+ const vscodeData = vscode ? JSON.parse(vscode) : void 0;
164
+ const language = vscodeData == null ? void 0 : vscodeData.mode;
165
+ if (!text || !language) {
166
+ return false;
167
+ }
168
+ const { tr } = view.state;
169
+ tr.replaceSelectionWith(this.type.create({ language }));
170
+ tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))));
171
+ tr.insertText(text.replace(/\r\n?/g, "\n"));
172
+ tr.setMeta("paste", true);
173
+ view.dispatch(tr);
174
+ return true;
175
+ }
176
+ }
177
+ })
178
+ ];
179
+ }
180
+ });
181
+
182
+ // src/index.ts
183
+ var src_default = CodeBlock;
184
+ export {
185
+ CodeBlock,
186
+ backtickInputRegex,
187
+ src_default as default,
188
+ tildeInputRegex
189
+ };
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": "2.0.0-beta.21",
4
+ "version": "2.0.0-beta.210",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -12,24 +12,46 @@
12
12
  "type": "github",
13
13
  "url": "https://github.com/sponsors/ueberdosis"
14
14
  },
15
- "main": "dist/tiptap-extension-code-block.cjs.js",
16
- "umd": "dist/tiptap-extension-code-block.umd.js",
17
- "module": "dist/tiptap-extension-code-block.esm.js",
18
- "types": "dist/packages/extension-code-block/src/index.d.ts",
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
21
+ }
22
+ },
23
+ "main": "dist/index.cjs",
24
+ "module": "dist/index.js",
25
+ "types": "dist/index.d.ts",
19
26
  "files": [
20
27
  "src",
21
28
  "dist"
22
29
  ],
23
30
  "peerDependencies": {
24
- "@tiptap/core": "^2.0.0-beta.1"
31
+ "@tiptap/core": "^2.0.0-beta.209",
32
+ "@tiptap/pm": "^2.0.0-beta.209"
25
33
  },
26
- "dependencies": {
27
- "prosemirror-state": "^1.3.4"
34
+ "devDependencies": {
35
+ "@tiptap/core": "^2.0.0-beta.210",
36
+ "@tiptap/pm": "^2.0.0-beta.210"
28
37
  },
29
38
  "repository": {
30
39
  "type": "git",
31
40
  "url": "https://github.com/ueberdosis/tiptap",
32
41
  "directory": "packages/extension-code-block"
33
42
  },
34
- "gitHead": "a06213f137672b1a08d76a1374002a32fd35cf23"
43
+ "scripts": {
44
+ "build": "tsup"
45
+ },
46
+ "tsup": {
47
+ "entry": [
48
+ "src/index.ts"
49
+ ],
50
+ "dts": true,
51
+ "splitting": true,
52
+ "format": [
53
+ "esm",
54
+ "cjs"
55
+ ]
56
+ }
35
57
  }
package/src/code-block.ts CHANGED
@@ -1,9 +1,26 @@
1
- import { Node, textblockTypeInputRule } from '@tiptap/core'
2
- import { Plugin, PluginKey, TextSelection } from 'prosemirror-state'
1
+ import { mergeAttributes, Node, textblockTypeInputRule } from '@tiptap/core'
2
+ import { Plugin, PluginKey, TextSelection } from '@tiptap/pm/state'
3
3
 
4
4
  export interface CodeBlockOptions {
5
- languageClassPrefix: string,
6
- HTMLAttributes: Record<string, any>,
5
+ /**
6
+ * Adds a prefix to language classes that are applied to code tags.
7
+ * Defaults to `'language-'`.
8
+ */
9
+ languageClassPrefix: string
10
+ /**
11
+ * Define whether the node should be exited on triple enter.
12
+ * Defaults to `true`.
13
+ */
14
+ exitOnTripleEnter: boolean
15
+ /**
16
+ * Define whether the node should be exited on arrow down if there is no node after it.
17
+ * Defaults to `true`.
18
+ */
19
+ exitOnArrowDown: boolean
20
+ /**
21
+ * Custom HTML attributes that should be added to the rendered HTML tag.
22
+ */
23
+ HTMLAttributes: Record<string, any>
7
24
  }
8
25
 
9
26
  declare module '@tiptap/core' {
@@ -12,24 +29,28 @@ declare module '@tiptap/core' {
12
29
  /**
13
30
  * Set a code block
14
31
  */
15
- setCodeBlock: (attributes?: { language: string }) => ReturnType,
32
+ setCodeBlock: (attributes?: { language: string }) => ReturnType
16
33
  /**
17
34
  * Toggle a code block
18
35
  */
19
- toggleCodeBlock: (attributes?: { language: string }) => ReturnType,
36
+ toggleCodeBlock: (attributes?: { language: string }) => ReturnType
20
37
  }
21
38
  }
22
39
  }
23
40
 
24
- export const backtickInputRegex = /^```(?<language>[a-z]*)?[\s\n]$/
25
- export const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/
41
+ export const backtickInputRegex = /^```([a-z]+)?[\s\n]$/
42
+ export const tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/
26
43
 
27
44
  export const CodeBlock = Node.create<CodeBlockOptions>({
28
45
  name: 'codeBlock',
29
46
 
30
- defaultOptions: {
31
- languageClassPrefix: 'language-',
32
- HTMLAttributes: {},
47
+ addOptions() {
48
+ return {
49
+ languageClassPrefix: 'language-',
50
+ exitOnTripleEnter: true,
51
+ exitOnArrowDown: true,
52
+ HTMLAttributes: {},
53
+ }
33
54
  },
34
55
 
35
56
  content: 'text*',
@@ -48,7 +69,7 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
48
69
  default: null,
49
70
  parseHTML: element => {
50
71
  const { languageClassPrefix } = this.options
51
- const classNames = [...element.firstElementChild?.classList || []]
72
+ const classNames = [...(element.firstElementChild?.classList || [])]
52
73
  const languages = classNames
53
74
  .filter(className => className.startsWith(languageClassPrefix))
54
75
  .map(className => className.replace(languageClassPrefix, ''))
@@ -60,15 +81,7 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
60
81
 
61
82
  return language
62
83
  },
63
- renderHTML: attributes => {
64
- if (!attributes.language) {
65
- return null
66
- }
67
-
68
- return {
69
- class: this.options.languageClassPrefix + attributes.language,
70
- }
71
- },
84
+ rendered: false,
72
85
  },
73
86
  }
74
87
  },
@@ -82,18 +95,32 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
82
95
  ]
83
96
  },
84
97
 
85
- renderHTML({ HTMLAttributes }) {
86
- return ['pre', this.options.HTMLAttributes, ['code', HTMLAttributes, 0]]
98
+ renderHTML({ node, HTMLAttributes }) {
99
+ return [
100
+ 'pre',
101
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
102
+ [
103
+ 'code',
104
+ {
105
+ class: node.attrs.language
106
+ ? this.options.languageClassPrefix + node.attrs.language
107
+ : null,
108
+ },
109
+ 0,
110
+ ],
111
+ ]
87
112
  },
88
113
 
89
114
  addCommands() {
90
115
  return {
91
- setCodeBlock: attributes => ({ commands }) => {
92
- return commands.setNode('codeBlock', attributes)
93
- },
94
- toggleCodeBlock: attributes => ({ commands }) => {
95
- return commands.toggleNode('codeBlock', 'paragraph', attributes)
96
- },
116
+ setCodeBlock:
117
+ attributes => ({ commands }) => {
118
+ return commands.setNode(this.name, attributes)
119
+ },
120
+ toggleCodeBlock:
121
+ attributes => ({ commands }) => {
122
+ return commands.toggleNode(this.name, 'paragraph', attributes)
123
+ },
97
124
  }
98
125
  },
99
126
 
@@ -116,6 +143,73 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
116
143
 
117
144
  return false
118
145
  },
146
+
147
+ // exit node on triple enter
148
+ Enter: ({ editor }) => {
149
+ if (!this.options.exitOnTripleEnter) {
150
+ return false
151
+ }
152
+
153
+ const { state } = editor
154
+ const { selection } = state
155
+ const { $from, empty } = selection
156
+
157
+ if (!empty || $from.parent.type !== this.type) {
158
+ return false
159
+ }
160
+
161
+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2
162
+ const endsWithDoubleNewline = $from.parent.textContent.endsWith('\n\n')
163
+
164
+ if (!isAtEnd || !endsWithDoubleNewline) {
165
+ return false
166
+ }
167
+
168
+ return editor
169
+ .chain()
170
+ .command(({ tr }) => {
171
+ tr.delete($from.pos - 2, $from.pos)
172
+
173
+ return true
174
+ })
175
+ .exitCode()
176
+ .run()
177
+ },
178
+
179
+ // exit node on arrow down
180
+ ArrowDown: ({ editor }) => {
181
+ if (!this.options.exitOnArrowDown) {
182
+ return false
183
+ }
184
+
185
+ const { state } = editor
186
+ const { selection, doc } = state
187
+ const { $from, empty } = selection
188
+
189
+ if (!empty || $from.parent.type !== this.type) {
190
+ return false
191
+ }
192
+
193
+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2
194
+
195
+ if (!isAtEnd) {
196
+ return false
197
+ }
198
+
199
+ const after = $from.after()
200
+
201
+ if (after === undefined) {
202
+ return false
203
+ }
204
+
205
+ const nodeAfter = doc.nodeAt(after)
206
+
207
+ if (nodeAfter) {
208
+ return false
209
+ }
210
+
211
+ return editor.commands.exitCode()
212
+ },
119
213
  }
120
214
  },
121
215
 
@@ -124,12 +218,16 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
124
218
  textblockTypeInputRule({
125
219
  find: backtickInputRegex,
126
220
  type: this.type,
127
- getAttributes: ({ groups }) => groups,
221
+ getAttributes: match => ({
222
+ language: match[1],
223
+ }),
128
224
  }),
129
225
  textblockTypeInputRule({
130
226
  find: tildeInputRegex,
131
227
  type: this.type,
132
- getAttributes: ({ groups }) => groups,
228
+ getAttributes: match => ({
229
+ language: match[1],
230
+ }),
133
231
  }),
134
232
  ]
135
233
  },
@@ -153,9 +251,7 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
153
251
 
154
252
  const text = event.clipboardData.getData('text/plain')
155
253
  const vscode = event.clipboardData.getData('vscode-editor-data')
156
- const vscodeData = vscode
157
- ? JSON.parse(vscode)
158
- : undefined
254
+ const vscodeData = vscode ? JSON.parse(vscode) : undefined
159
255
  const language = vscodeData?.mode
160
256
 
161
257
  if (!text || !language) {
@@ -171,7 +267,14 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
171
267
  tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))))
172
268
 
173
269
  // add text to code block
174
- tr.insertText(text)
270
+ // strip carriage return chars from text pasted as code
271
+ // see: https://github.com/ProseMirror/prosemirror-view/commit/a50a6bcceb4ce52ac8fcc6162488d8875613aacd
272
+ tr.insertText(text.replace(/\r\n?/g, '\n'))
273
+
274
+ // store meta information
275
+ // this is useful for other plugins that depends on the paste event
276
+ // like the paste rule plugin
277
+ tr.setMeta('paste', true)
175
278
 
176
279
  view.dispatch(tr)
177
280
 
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021, überdosis GbR
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,26 +0,0 @@
1
- import { Node } from '@tiptap/core';
2
- export interface CodeBlockOptions {
3
- languageClassPrefix: string;
4
- HTMLAttributes: Record<string, any>;
5
- }
6
- declare module '@tiptap/core' {
7
- interface Commands<ReturnType> {
8
- codeBlock: {
9
- /**
10
- * Set a code block
11
- */
12
- setCodeBlock: (attributes?: {
13
- language: string;
14
- }) => ReturnType;
15
- /**
16
- * Toggle a code block
17
- */
18
- toggleCodeBlock: (attributes?: {
19
- language: string;
20
- }) => ReturnType;
21
- };
22
- }
23
- }
24
- export declare const backtickInputRegex: RegExp;
25
- export declare const tildeInputRegex: RegExp;
26
- export declare const CodeBlock: Node<CodeBlockOptions>;
@@ -1,3 +0,0 @@
1
- import { CodeBlock } from './code-block';
2
- export * from './code-block';
3
- export default CodeBlock;
@@ -1,145 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var core = require('@tiptap/core');
6
- var prosemirrorState = require('prosemirror-state');
7
-
8
- const backtickInputRegex = /^```(?<language>[a-z]*)?[\s\n]$/;
9
- const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/;
10
- const CodeBlock = core.Node.create({
11
- name: 'codeBlock',
12
- defaultOptions: {
13
- languageClassPrefix: 'language-',
14
- HTMLAttributes: {},
15
- },
16
- content: 'text*',
17
- marks: '',
18
- group: 'block',
19
- code: true,
20
- defining: true,
21
- addAttributes() {
22
- return {
23
- language: {
24
- default: null,
25
- parseHTML: element => {
26
- var _a;
27
- const { languageClassPrefix } = this.options;
28
- const classNames = [...((_a = element.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList) || []];
29
- const languages = classNames
30
- .filter(className => className.startsWith(languageClassPrefix))
31
- .map(className => className.replace(languageClassPrefix, ''));
32
- const language = languages[0];
33
- if (!language) {
34
- return null;
35
- }
36
- return language;
37
- },
38
- renderHTML: attributes => {
39
- if (!attributes.language) {
40
- return null;
41
- }
42
- return {
43
- class: this.options.languageClassPrefix + attributes.language,
44
- };
45
- },
46
- },
47
- };
48
- },
49
- parseHTML() {
50
- return [
51
- {
52
- tag: 'pre',
53
- preserveWhitespace: 'full',
54
- },
55
- ];
56
- },
57
- renderHTML({ HTMLAttributes }) {
58
- return ['pre', this.options.HTMLAttributes, ['code', HTMLAttributes, 0]];
59
- },
60
- addCommands() {
61
- return {
62
- setCodeBlock: attributes => ({ commands }) => {
63
- return commands.setNode('codeBlock', attributes);
64
- },
65
- toggleCodeBlock: attributes => ({ commands }) => {
66
- return commands.toggleNode('codeBlock', 'paragraph', attributes);
67
- },
68
- };
69
- },
70
- addKeyboardShortcuts() {
71
- return {
72
- 'Mod-Alt-c': () => this.editor.commands.toggleCodeBlock(),
73
- // remove code block when at start of document or code block is empty
74
- Backspace: () => {
75
- const { empty, $anchor } = this.editor.state.selection;
76
- const isAtStart = $anchor.pos === 1;
77
- if (!empty || $anchor.parent.type.name !== this.name) {
78
- return false;
79
- }
80
- if (isAtStart || !$anchor.parent.textContent.length) {
81
- return this.editor.commands.clearNodes();
82
- }
83
- return false;
84
- },
85
- };
86
- },
87
- addInputRules() {
88
- return [
89
- core.textblockTypeInputRule({
90
- find: backtickInputRegex,
91
- type: this.type,
92
- getAttributes: ({ groups }) => groups,
93
- }),
94
- core.textblockTypeInputRule({
95
- find: tildeInputRegex,
96
- type: this.type,
97
- getAttributes: ({ groups }) => groups,
98
- }),
99
- ];
100
- },
101
- addProseMirrorPlugins() {
102
- return [
103
- // this plugin creates a code block for pasted content from VS Code
104
- // we can also detect the copied code language
105
- new prosemirrorState.Plugin({
106
- key: new prosemirrorState.PluginKey('codeBlockVSCodeHandler'),
107
- props: {
108
- handlePaste: (view, event) => {
109
- if (!event.clipboardData) {
110
- return false;
111
- }
112
- // don’t create a new code block within code blocks
113
- if (this.editor.isActive(this.type.name)) {
114
- return false;
115
- }
116
- const text = event.clipboardData.getData('text/plain');
117
- const vscode = event.clipboardData.getData('vscode-editor-data');
118
- const vscodeData = vscode
119
- ? JSON.parse(vscode)
120
- : undefined;
121
- const language = vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;
122
- if (!text || !language) {
123
- return false;
124
- }
125
- const { tr } = view.state;
126
- // create an empty code block
127
- tr.replaceSelectionWith(this.type.create({ language }));
128
- // put cursor inside the newly created code block
129
- tr.setSelection(prosemirrorState.TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))));
130
- // add text to code block
131
- tr.insertText(text);
132
- view.dispatch(tr);
133
- return true;
134
- },
135
- },
136
- }),
137
- ];
138
- },
139
- });
140
-
141
- exports.CodeBlock = CodeBlock;
142
- exports.backtickInputRegex = backtickInputRegex;
143
- exports["default"] = CodeBlock;
144
- exports.tildeInputRegex = tildeInputRegex;
145
- //# sourceMappingURL=tiptap-extension-code-block.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiptap-extension-code-block.cjs.js","sources":["../src/code-block.ts"],"sourcesContent":["import { Node, textblockTypeInputRule } from '@tiptap/core'\nimport { Plugin, PluginKey, TextSelection } from 'prosemirror-state'\n\nexport interface CodeBlockOptions {\n languageClassPrefix: string,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n codeBlock: {\n /**\n * Set a code block\n */\n setCodeBlock: (attributes?: { language: string }) => ReturnType,\n /**\n * Toggle a code block\n */\n toggleCodeBlock: (attributes?: { language: string }) => ReturnType,\n }\n }\n}\n\nexport const backtickInputRegex = /^```(?<language>[a-z]*)?[\\s\\n]$/\nexport const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\\s\\n]$/\n\nexport const CodeBlock = Node.create<CodeBlockOptions>({\n name: 'codeBlock',\n\n defaultOptions: {\n languageClassPrefix: 'language-',\n HTMLAttributes: {},\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: null,\n parseHTML: element => {\n const { languageClassPrefix } = this.options\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 renderHTML: attributes => {\n if (!attributes.language) {\n return null\n }\n\n return {\n class: this.options.languageClassPrefix + attributes.language,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['pre', this.options.HTMLAttributes, ['code', HTMLAttributes, 0]]\n },\n\n addCommands() {\n return {\n setCodeBlock: attributes => ({ commands }) => {\n return commands.setNode('codeBlock', attributes)\n },\n toggleCodeBlock: attributes => ({ commands }) => {\n return commands.toggleNode('codeBlock', '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 },\n\n addInputRules() {\n return [\n textblockTypeInputRule({\n find: backtickInputRegex,\n type: this.type,\n getAttributes: ({ groups }) => groups,\n }),\n textblockTypeInputRule({\n find: tildeInputRegex,\n type: this.type,\n getAttributes: ({ groups }) => groups,\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\n ? JSON.parse(vscode)\n : undefined\n const language = vscodeData?.mode\n\n if (!text || !language) {\n return false\n }\n\n const { tr } = view.state\n\n // create an empty code block\n tr.replaceSelectionWith(this.type.create({ language }))\n\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 // add text to code block\n tr.insertText(text)\n\n view.dispatch(tr)\n\n return true\n },\n },\n }),\n ]\n },\n})\n"],"names":["Node","textblockTypeInputRule","Plugin","PluginKey","TextSelection"],"mappings":";;;;;;;MAuBa,kBAAkB,GAAG,kCAAiC;MACtD,eAAe,GAAG,kCAAiC;MAEnD,SAAS,GAAGA,SAAI,CAAC,MAAM,CAAmB;IACrD,IAAI,EAAE,WAAW;IAEjB,cAAc,EAAE;QACd,mBAAmB,EAAE,WAAW;QAChC,cAAc,EAAE,EAAE;KACnB;IAED,OAAO,EAAE,OAAO;IAEhB,KAAK,EAAE,EAAE;IAET,KAAK,EAAE,OAAO;IAEd,IAAI,EAAE,IAAI;IAEV,QAAQ,EAAE,IAAI;IAEd,aAA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
@@ -1,138 +0,0 @@
1
- import { Node, textblockTypeInputRule } from '@tiptap/core';
2
- import { Plugin, PluginKey, TextSelection } from 'prosemirror-state';
3
-
4
- const backtickInputRegex = /^```(?<language>[a-z]*)?[\s\n]$/;
5
- const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/;
6
- const CodeBlock = Node.create({
7
- name: 'codeBlock',
8
- defaultOptions: {
9
- languageClassPrefix: 'language-',
10
- HTMLAttributes: {},
11
- },
12
- content: 'text*',
13
- marks: '',
14
- group: 'block',
15
- code: true,
16
- defining: true,
17
- addAttributes() {
18
- return {
19
- language: {
20
- default: null,
21
- parseHTML: element => {
22
- var _a;
23
- const { languageClassPrefix } = this.options;
24
- const classNames = [...((_a = element.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList) || []];
25
- const languages = classNames
26
- .filter(className => className.startsWith(languageClassPrefix))
27
- .map(className => className.replace(languageClassPrefix, ''));
28
- const language = languages[0];
29
- if (!language) {
30
- return null;
31
- }
32
- return language;
33
- },
34
- renderHTML: attributes => {
35
- if (!attributes.language) {
36
- return null;
37
- }
38
- return {
39
- class: this.options.languageClassPrefix + attributes.language,
40
- };
41
- },
42
- },
43
- };
44
- },
45
- parseHTML() {
46
- return [
47
- {
48
- tag: 'pre',
49
- preserveWhitespace: 'full',
50
- },
51
- ];
52
- },
53
- renderHTML({ HTMLAttributes }) {
54
- return ['pre', this.options.HTMLAttributes, ['code', HTMLAttributes, 0]];
55
- },
56
- addCommands() {
57
- return {
58
- setCodeBlock: attributes => ({ commands }) => {
59
- return commands.setNode('codeBlock', attributes);
60
- },
61
- toggleCodeBlock: attributes => ({ commands }) => {
62
- return commands.toggleNode('codeBlock', 'paragraph', attributes);
63
- },
64
- };
65
- },
66
- addKeyboardShortcuts() {
67
- return {
68
- 'Mod-Alt-c': () => this.editor.commands.toggleCodeBlock(),
69
- // remove code block when at start of document or code block is empty
70
- Backspace: () => {
71
- const { empty, $anchor } = this.editor.state.selection;
72
- const isAtStart = $anchor.pos === 1;
73
- if (!empty || $anchor.parent.type.name !== this.name) {
74
- return false;
75
- }
76
- if (isAtStart || !$anchor.parent.textContent.length) {
77
- return this.editor.commands.clearNodes();
78
- }
79
- return false;
80
- },
81
- };
82
- },
83
- addInputRules() {
84
- return [
85
- textblockTypeInputRule({
86
- find: backtickInputRegex,
87
- type: this.type,
88
- getAttributes: ({ groups }) => groups,
89
- }),
90
- textblockTypeInputRule({
91
- find: tildeInputRegex,
92
- type: this.type,
93
- getAttributes: ({ groups }) => groups,
94
- }),
95
- ];
96
- },
97
- addProseMirrorPlugins() {
98
- return [
99
- // this plugin creates a code block for pasted content from VS Code
100
- // we can also detect the copied code language
101
- new Plugin({
102
- key: new PluginKey('codeBlockVSCodeHandler'),
103
- props: {
104
- handlePaste: (view, event) => {
105
- if (!event.clipboardData) {
106
- return false;
107
- }
108
- // don’t create a new code block within code blocks
109
- if (this.editor.isActive(this.type.name)) {
110
- return false;
111
- }
112
- const text = event.clipboardData.getData('text/plain');
113
- const vscode = event.clipboardData.getData('vscode-editor-data');
114
- const vscodeData = vscode
115
- ? JSON.parse(vscode)
116
- : undefined;
117
- const language = vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;
118
- if (!text || !language) {
119
- return false;
120
- }
121
- const { tr } = view.state;
122
- // create an empty code block
123
- tr.replaceSelectionWith(this.type.create({ language }));
124
- // put cursor inside the newly created code block
125
- tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))));
126
- // add text to code block
127
- tr.insertText(text);
128
- view.dispatch(tr);
129
- return true;
130
- },
131
- },
132
- }),
133
- ];
134
- },
135
- });
136
-
137
- export { CodeBlock, backtickInputRegex, CodeBlock as default, tildeInputRegex };
138
- //# sourceMappingURL=tiptap-extension-code-block.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiptap-extension-code-block.esm.js","sources":["../src/code-block.ts"],"sourcesContent":["import { Node, textblockTypeInputRule } from '@tiptap/core'\nimport { Plugin, PluginKey, TextSelection } from 'prosemirror-state'\n\nexport interface CodeBlockOptions {\n languageClassPrefix: string,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n codeBlock: {\n /**\n * Set a code block\n */\n setCodeBlock: (attributes?: { language: string }) => ReturnType,\n /**\n * Toggle a code block\n */\n toggleCodeBlock: (attributes?: { language: string }) => ReturnType,\n }\n }\n}\n\nexport const backtickInputRegex = /^```(?<language>[a-z]*)?[\\s\\n]$/\nexport const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\\s\\n]$/\n\nexport const CodeBlock = Node.create<CodeBlockOptions>({\n name: 'codeBlock',\n\n defaultOptions: {\n languageClassPrefix: 'language-',\n HTMLAttributes: {},\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: null,\n parseHTML: element => {\n const { languageClassPrefix } = this.options\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 renderHTML: attributes => {\n if (!attributes.language) {\n return null\n }\n\n return {\n class: this.options.languageClassPrefix + attributes.language,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['pre', this.options.HTMLAttributes, ['code', HTMLAttributes, 0]]\n },\n\n addCommands() {\n return {\n setCodeBlock: attributes => ({ commands }) => {\n return commands.setNode('codeBlock', attributes)\n },\n toggleCodeBlock: attributes => ({ commands }) => {\n return commands.toggleNode('codeBlock', '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 },\n\n addInputRules() {\n return [\n textblockTypeInputRule({\n find: backtickInputRegex,\n type: this.type,\n getAttributes: ({ groups }) => groups,\n }),\n textblockTypeInputRule({\n find: tildeInputRegex,\n type: this.type,\n getAttributes: ({ groups }) => groups,\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\n ? JSON.parse(vscode)\n : undefined\n const language = vscodeData?.mode\n\n if (!text || !language) {\n return false\n }\n\n const { tr } = view.state\n\n // create an empty code block\n tr.replaceSelectionWith(this.type.create({ language }))\n\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 // add text to code block\n tr.insertText(text)\n\n view.dispatch(tr)\n\n return true\n },\n },\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;MAuBa,kBAAkB,GAAG,kCAAiC;MACtD,eAAe,GAAG,kCAAiC;MAEnD,SAAS,GAAG,IAAI,CAAC,MAAM,CAAmB;IACrD,IAAI,EAAE,WAAW;IAEjB,cAAc,EAAE;QACd,mBAAmB,EAAE,WAAW;QAChC,cAAc,EAAE,EAAE;KACnB;IAED,OAAO,EAAE,OAAO;IAEhB,KAAK,EAAE,EAAE;IAET,KAAK,EAAE,OAAO;IAEd,IAAI,EAAE,IAAI;IAEV,QAAQ,EAAE,IAAI;IAEd,aAAa;Q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 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-state')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', 'prosemirror-state'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-code-block"] = {}, global.core, global.prosemirrorState));
5
- })(this, (function (exports, core, prosemirrorState) { 'use strict';
6
-
7
- const backtickInputRegex = /^```(?<language>[a-z]*)?[\s\n]$/;
8
- const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/;
9
- const CodeBlock = core.Node.create({
10
- name: 'codeBlock',
11
- defaultOptions: {
12
- languageClassPrefix: 'language-',
13
- HTMLAttributes: {},
14
- },
15
- content: 'text*',
16
- marks: '',
17
- group: 'block',
18
- code: true,
19
- defining: true,
20
- addAttributes() {
21
- return {
22
- language: {
23
- default: null,
24
- parseHTML: element => {
25
- var _a;
26
- const { languageClassPrefix } = this.options;
27
- const classNames = [...((_a = element.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList) || []];
28
- const languages = classNames
29
- .filter(className => className.startsWith(languageClassPrefix))
30
- .map(className => className.replace(languageClassPrefix, ''));
31
- const language = languages[0];
32
- if (!language) {
33
- return null;
34
- }
35
- return language;
36
- },
37
- renderHTML: attributes => {
38
- if (!attributes.language) {
39
- return null;
40
- }
41
- return {
42
- class: this.options.languageClassPrefix + attributes.language,
43
- };
44
- },
45
- },
46
- };
47
- },
48
- parseHTML() {
49
- return [
50
- {
51
- tag: 'pre',
52
- preserveWhitespace: 'full',
53
- },
54
- ];
55
- },
56
- renderHTML({ HTMLAttributes }) {
57
- return ['pre', this.options.HTMLAttributes, ['code', HTMLAttributes, 0]];
58
- },
59
- addCommands() {
60
- return {
61
- setCodeBlock: attributes => ({ commands }) => {
62
- return commands.setNode('codeBlock', attributes);
63
- },
64
- toggleCodeBlock: attributes => ({ commands }) => {
65
- return commands.toggleNode('codeBlock', 'paragraph', attributes);
66
- },
67
- };
68
- },
69
- addKeyboardShortcuts() {
70
- return {
71
- 'Mod-Alt-c': () => this.editor.commands.toggleCodeBlock(),
72
- // remove code block when at start of document or code block is empty
73
- Backspace: () => {
74
- const { empty, $anchor } = this.editor.state.selection;
75
- const isAtStart = $anchor.pos === 1;
76
- if (!empty || $anchor.parent.type.name !== this.name) {
77
- return false;
78
- }
79
- if (isAtStart || !$anchor.parent.textContent.length) {
80
- return this.editor.commands.clearNodes();
81
- }
82
- return false;
83
- },
84
- };
85
- },
86
- addInputRules() {
87
- return [
88
- core.textblockTypeInputRule({
89
- find: backtickInputRegex,
90
- type: this.type,
91
- getAttributes: ({ groups }) => groups,
92
- }),
93
- core.textblockTypeInputRule({
94
- find: tildeInputRegex,
95
- type: this.type,
96
- getAttributes: ({ groups }) => groups,
97
- }),
98
- ];
99
- },
100
- addProseMirrorPlugins() {
101
- return [
102
- // this plugin creates a code block for pasted content from VS Code
103
- // we can also detect the copied code language
104
- new prosemirrorState.Plugin({
105
- key: new prosemirrorState.PluginKey('codeBlockVSCodeHandler'),
106
- props: {
107
- handlePaste: (view, event) => {
108
- if (!event.clipboardData) {
109
- return false;
110
- }
111
- // don’t create a new code block within code blocks
112
- if (this.editor.isActive(this.type.name)) {
113
- return false;
114
- }
115
- const text = event.clipboardData.getData('text/plain');
116
- const vscode = event.clipboardData.getData('vscode-editor-data');
117
- const vscodeData = vscode
118
- ? JSON.parse(vscode)
119
- : undefined;
120
- const language = vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;
121
- if (!text || !language) {
122
- return false;
123
- }
124
- const { tr } = view.state;
125
- // create an empty code block
126
- tr.replaceSelectionWith(this.type.create({ language }));
127
- // put cursor inside the newly created code block
128
- tr.setSelection(prosemirrorState.TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))));
129
- // add text to code block
130
- tr.insertText(text);
131
- view.dispatch(tr);
132
- return true;
133
- },
134
- },
135
- }),
136
- ];
137
- },
138
- });
139
-
140
- exports.CodeBlock = CodeBlock;
141
- exports.backtickInputRegex = backtickInputRegex;
142
- exports["default"] = CodeBlock;
143
- exports.tildeInputRegex = tildeInputRegex;
144
-
145
- Object.defineProperty(exports, '__esModule', { value: true });
146
-
147
- }));
148
- //# sourceMappingURL=tiptap-extension-code-block.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiptap-extension-code-block.umd.js","sources":["../src/code-block.ts"],"sourcesContent":["import { Node, textblockTypeInputRule } from '@tiptap/core'\nimport { Plugin, PluginKey, TextSelection } from 'prosemirror-state'\n\nexport interface CodeBlockOptions {\n languageClassPrefix: string,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n codeBlock: {\n /**\n * Set a code block\n */\n setCodeBlock: (attributes?: { language: string }) => ReturnType,\n /**\n * Toggle a code block\n */\n toggleCodeBlock: (attributes?: { language: string }) => ReturnType,\n }\n }\n}\n\nexport const backtickInputRegex = /^```(?<language>[a-z]*)?[\\s\\n]$/\nexport const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\\s\\n]$/\n\nexport const CodeBlock = Node.create<CodeBlockOptions>({\n name: 'codeBlock',\n\n defaultOptions: {\n languageClassPrefix: 'language-',\n HTMLAttributes: {},\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: null,\n parseHTML: element => {\n const { languageClassPrefix } = this.options\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 renderHTML: attributes => {\n if (!attributes.language) {\n return null\n }\n\n return {\n class: this.options.languageClassPrefix + attributes.language,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['pre', this.options.HTMLAttributes, ['code', HTMLAttributes, 0]]\n },\n\n addCommands() {\n return {\n setCodeBlock: attributes => ({ commands }) => {\n return commands.setNode('codeBlock', attributes)\n },\n toggleCodeBlock: attributes => ({ commands }) => {\n return commands.toggleNode('codeBlock', '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 },\n\n addInputRules() {\n return [\n textblockTypeInputRule({\n find: backtickInputRegex,\n type: this.type,\n getAttributes: ({ groups }) => groups,\n }),\n textblockTypeInputRule({\n find: tildeInputRegex,\n type: this.type,\n getAttributes: ({ groups }) => groups,\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\n ? JSON.parse(vscode)\n : undefined\n const language = vscodeData?.mode\n\n if (!text || !language) {\n return false\n }\n\n const { tr } = view.state\n\n // create an empty code block\n tr.replaceSelectionWith(this.type.create({ language }))\n\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 // add text to code block\n tr.insertText(text)\n\n view.dispatch(tr)\n\n return true\n },\n },\n }),\n ]\n },\n})\n"],"names":["Node","textblockTypeInputRule","Plugin","Plu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