@tiptap/extension-code-block 3.0.0-next.0 → 3.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/dist/index.cjs +226 -224
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/{packages/extension-code-block/src/code-block.d.ts → index.d.cts} +13 -4
  4. package/dist/index.d.ts +68 -0
  5. package/dist/index.js +204 -219
  6. package/dist/index.js.map +1 -1
  7. package/package.json +8 -10
  8. package/src/code-block.ts +8 -1
  9. package/dist/index.umd.js +0 -231
  10. package/dist/index.umd.js.map +0 -1
  11. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  12. package/dist/packages/core/src/Editor.d.ts +0 -159
  13. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  14. package/dist/packages/core/src/Extension.d.ts +0 -343
  15. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  16. package/dist/packages/core/src/InputRule.d.ts +0 -42
  17. package/dist/packages/core/src/Mark.d.ts +0 -451
  18. package/dist/packages/core/src/Node.d.ts +0 -611
  19. package/dist/packages/core/src/NodePos.d.ts +0 -44
  20. package/dist/packages/core/src/NodeView.d.ts +0 -31
  21. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  22. package/dist/packages/core/src/Tracker.d.ts +0 -11
  23. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  24. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  25. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  26. package/dist/packages/core/src/commands/command.d.ts +0 -18
  27. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  28. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  29. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  30. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  31. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  32. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  33. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  34. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  35. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  36. package/dist/packages/core/src/commands/first.d.ts +0 -14
  37. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  38. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  39. package/dist/packages/core/src/commands/index.d.ts +0 -55
  40. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  41. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  42. package/dist/packages/core/src/commands/join.d.ts +0 -41
  43. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  44. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  45. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  46. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  47. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  48. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  49. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  50. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  51. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  52. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  53. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  54. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  55. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  56. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  57. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  58. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  59. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  60. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  61. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  62. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  63. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  64. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  65. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  66. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  67. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  68. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  69. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  70. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  71. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  72. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  73. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  74. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  75. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  76. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  77. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  78. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  79. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  80. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  81. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  82. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  83. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  84. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  85. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  86. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  87. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  88. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  89. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  90. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  91. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  92. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  93. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  94. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  95. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  96. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  97. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  98. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  99. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  100. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  101. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  102. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  103. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  104. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  105. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  106. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  107. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  108. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  109. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  110. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  111. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  112. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  113. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  114. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  115. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  116. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  117. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  118. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  119. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  120. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  121. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  122. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  123. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  124. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  125. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  126. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  127. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  128. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  129. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  130. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -8
  131. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  132. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  133. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  134. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  135. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  136. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  137. package/dist/packages/core/src/index.d.ts +0 -24
  138. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  139. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  140. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  141. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  142. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  143. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  144. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  145. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  146. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  147. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  148. package/dist/packages/core/src/style.d.ts +0 -1
  149. package/dist/packages/core/src/types.d.ts +0 -253
  150. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  151. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  152. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  153. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  154. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  155. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  156. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  157. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  158. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  159. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  160. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  161. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  162. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  163. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  164. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  165. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  166. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  167. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  168. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  170. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  171. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  172. package/dist/packages/extension-code-block/src/index.d.ts +0 -3
package/dist/index.umd.js DELETED
@@ -1,231 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('@tiptap/pm/state')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', '@tiptap/pm/state'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-code-block"] = {}, global.core, global.state));
5
- })(this, (function (exports, core, state) { 'use strict';
6
-
7
- /**
8
- * Matches a code block with backticks.
9
- */
10
- const backtickInputRegex = /^```([a-z]+)?[\s\n]$/;
11
- /**
12
- * Matches a code block with tildes.
13
- */
14
- const tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/;
15
- /**
16
- * This extension allows you to create code blocks.
17
- * @see https://tiptap.dev/api/nodes/code-block
18
- */
19
- const CodeBlock = core.Node.create({
20
- name: 'codeBlock',
21
- addOptions() {
22
- return {
23
- languageClassPrefix: 'language-',
24
- exitOnTripleEnter: true,
25
- exitOnArrowDown: true,
26
- HTMLAttributes: {},
27
- };
28
- },
29
- content: 'text*',
30
- marks: '',
31
- group: 'block',
32
- code: true,
33
- defining: true,
34
- addAttributes() {
35
- return {
36
- language: {
37
- default: null,
38
- parseHTML: element => {
39
- var _a;
40
- const { languageClassPrefix } = this.options;
41
- const classNames = [...(((_a = element.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList) || [])];
42
- const languages = classNames
43
- .filter(className => className.startsWith(languageClassPrefix))
44
- .map(className => className.replace(languageClassPrefix, ''));
45
- const language = languages[0];
46
- if (!language) {
47
- return null;
48
- }
49
- return language;
50
- },
51
- rendered: false,
52
- },
53
- };
54
- },
55
- parseHTML() {
56
- return [
57
- {
58
- tag: 'pre',
59
- preserveWhitespace: 'full',
60
- },
61
- ];
62
- },
63
- renderHTML({ node, HTMLAttributes }) {
64
- return [
65
- 'pre',
66
- core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
67
- [
68
- 'code',
69
- {
70
- class: node.attrs.language
71
- ? this.options.languageClassPrefix + node.attrs.language
72
- : null,
73
- },
74
- 0,
75
- ],
76
- ];
77
- },
78
- addCommands() {
79
- return {
80
- setCodeBlock: attributes => ({ commands }) => {
81
- return commands.setNode(this.name, attributes);
82
- },
83
- toggleCodeBlock: attributes => ({ commands }) => {
84
- return commands.toggleNode(this.name, 'paragraph', attributes);
85
- },
86
- };
87
- },
88
- addKeyboardShortcuts() {
89
- return {
90
- 'Mod-Alt-c': () => this.editor.commands.toggleCodeBlock(),
91
- // remove code block when at start of document or code block is empty
92
- Backspace: () => {
93
- const { empty, $anchor } = this.editor.state.selection;
94
- const isAtStart = $anchor.pos === 1;
95
- if (!empty || $anchor.parent.type.name !== this.name) {
96
- return false;
97
- }
98
- if (isAtStart || !$anchor.parent.textContent.length) {
99
- return this.editor.commands.clearNodes();
100
- }
101
- return false;
102
- },
103
- // exit node on triple enter
104
- Enter: ({ editor }) => {
105
- if (!this.options.exitOnTripleEnter) {
106
- return false;
107
- }
108
- const { state } = editor;
109
- const { selection } = state;
110
- const { $from, empty } = selection;
111
- if (!empty || $from.parent.type !== this.type) {
112
- return false;
113
- }
114
- const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
115
- const endsWithDoubleNewline = $from.parent.textContent.endsWith('\n\n');
116
- if (!isAtEnd || !endsWithDoubleNewline) {
117
- return false;
118
- }
119
- return editor
120
- .chain()
121
- .command(({ tr }) => {
122
- tr.delete($from.pos - 2, $from.pos);
123
- return true;
124
- })
125
- .exitCode()
126
- .run();
127
- },
128
- // exit node on arrow down
129
- ArrowDown: ({ editor }) => {
130
- if (!this.options.exitOnArrowDown) {
131
- return false;
132
- }
133
- const { state: state$1 } = editor;
134
- const { selection, doc } = state$1;
135
- const { $from, empty } = selection;
136
- if (!empty || $from.parent.type !== this.type) {
137
- return false;
138
- }
139
- const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
140
- if (!isAtEnd) {
141
- return false;
142
- }
143
- const after = $from.after();
144
- if (after === undefined) {
145
- return false;
146
- }
147
- const nodeAfter = doc.nodeAt(after);
148
- if (nodeAfter) {
149
- return editor.commands.command(({ tr }) => {
150
- tr.setSelection(state.Selection.near(doc.resolve(after)));
151
- return true;
152
- });
153
- }
154
- return editor.commands.exitCode();
155
- },
156
- };
157
- },
158
- addInputRules() {
159
- return [
160
- core.textblockTypeInputRule({
161
- find: backtickInputRegex,
162
- type: this.type,
163
- getAttributes: match => ({
164
- language: match[1],
165
- }),
166
- }),
167
- core.textblockTypeInputRule({
168
- find: tildeInputRegex,
169
- type: this.type,
170
- getAttributes: match => ({
171
- language: match[1],
172
- }),
173
- }),
174
- ];
175
- },
176
- addProseMirrorPlugins() {
177
- return [
178
- // this plugin creates a code block for pasted content from VS Code
179
- // we can also detect the copied code language
180
- new state.Plugin({
181
- key: new state.PluginKey('codeBlockVSCodeHandler'),
182
- props: {
183
- handlePaste: (view, event) => {
184
- if (!event.clipboardData) {
185
- return false;
186
- }
187
- // don’t create a new code block within code blocks
188
- if (this.editor.isActive(this.type.name)) {
189
- return false;
190
- }
191
- const text = event.clipboardData.getData('text/plain');
192
- const vscode = event.clipboardData.getData('vscode-editor-data');
193
- const vscodeData = vscode ? JSON.parse(vscode) : undefined;
194
- const language = vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;
195
- if (!text || !language) {
196
- return false;
197
- }
198
- const { tr, schema } = view.state;
199
- // prepare a text node
200
- // strip carriage return chars from text pasted as code
201
- // see: https://github.com/ProseMirror/prosemirror-view/commit/a50a6bcceb4ce52ac8fcc6162488d8875613aacd
202
- const textNode = schema.text(text.replace(/\r\n?/g, '\n'));
203
- // create a code block with the text node
204
- // replace selection with the code block
205
- tr.replaceSelectionWith(this.type.create({ language }, textNode));
206
- if (tr.selection.$from.parent.type !== this.type) {
207
- // put cursor inside the newly created code block
208
- tr.setSelection(state.TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))));
209
- }
210
- // store meta information
211
- // this is useful for other plugins that depends on the paste event
212
- // like the paste rule plugin
213
- tr.setMeta('paste', true);
214
- view.dispatch(tr);
215
- return true;
216
- },
217
- },
218
- }),
219
- ];
220
- },
221
- });
222
-
223
- exports.CodeBlock = CodeBlock;
224
- exports.backtickInputRegex = backtickInputRegex;
225
- exports.default = CodeBlock;
226
- exports.tildeInputRegex = tildeInputRegex;
227
-
228
- Object.defineProperty(exports, '__esModule', { value: true });
229
-
230
- }));
231
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/code-block.ts"],"sourcesContent":["import { mergeAttributes, Node, textblockTypeInputRule } from '@tiptap/core'\nimport {\n Plugin,\n PluginKey,\n Selection,\n TextSelection,\n} from '@tiptap/pm/state'\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\n /**\n * Define whether the node should be exited on triple enter.\n * @default true\n */\n exitOnTripleEnter: boolean\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\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 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: 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 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\n ? this.options.languageClassPrefix + node.attrs.language\n : null,\n },\n 0,\n ],\n ]\n },\n\n addCommands() {\n return {\n setCodeBlock:\n attributes => ({ commands }) => {\n return commands.setNode(this.name, attributes)\n },\n toggleCodeBlock:\n attributes => ({ 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 // 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"],"names":["Node","mergeAttributes","state","Selection","textblockTypeInputRule","Plugin","PluginKey","TextSelection"],"mappings":";;;;;;EAmDA;;EAEG;AACI,QAAM,kBAAkB,GAAG,uBAAsB;EAExD;;EAEG;AACI,QAAM,eAAe,GAAG,uBAAsB;EAErD;;;EAGG;AACU,QAAA,SAAS,GAAGA,SAAI,CAAC,MAAM,CAAmB;EACrD,IAAA,IAAI,EAAE,WAAW;MAEjB,UAAU,GAAA;UACR,OAAO;EACL,YAAA,mBAAmB,EAAE,WAAW;EAChC,YAAA,iBAAiB,EAAE,IAAI;EACvB,YAAA,eAAe,EAAE,IAAI;EACrB,YAAA,cAAc,EAAE,EAAE;WACnB,CAAA;OACF;EAED,IAAA,OAAO,EAAE,OAAO;EAEhB,IAAA,KAAK,EAAE,EAAE;EAET,IAAA,KAAK,EAAE,OAAO;EAEd,IAAA,IAAI,EAAE,IAAI;EAEV,IAAA,QAAQ,EAAE,IAAI;MAEd,aAAa,GAAA;UACX,OAAO;EACL,YAAA,QAAQ,EAAE;EACR,gBAAA,OAAO,EAAE,IAAI;kBACb,SAAS,EAAE,OAAO,IAAG;;EACnB,oBAAA,MAAM,EAAE,mBAAmB,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;EAC5C,oBAAA,MAAM,UAAU,GAAG,CAAC,IAAI,CAAA,CAAA,EAAA,GAAA,OAAO,CAAC,iBAAiB,0CAAE,SAAS,KAAI,EAAE,EAAE,CAAA;sBACpE,MAAM,SAAS,GAAG,UAAU;2BACzB,MAAM,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;EAC9D,yBAAA,GAAG,CAAC,SAAS,IAAI,SAAS,CAAC,OA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OAAO,EAAE,IAAI,CAAC,CAAA;EAEzB,wBAAA,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;EAEjB,wBAAA,OAAO,IAAI,CAAA;uBACZ;EACF,iBAAA;eACF,CAAC;WACH,CAAA;OACF;EACF,CAAA;;;;;;;;;;;;;"}
@@ -1,20 +0,0 @@
1
- import { EditorState, Transaction } from '@tiptap/pm/state';
2
- import { Editor } from './Editor.js';
3
- import { AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands } from './types.js';
4
- export declare class CommandManager {
5
- editor: Editor;
6
- rawCommands: AnyCommands;
7
- customState?: EditorState;
8
- constructor(props: {
9
- editor: Editor;
10
- state?: EditorState;
11
- });
12
- get hasCustomState(): boolean;
13
- get state(): EditorState;
14
- get commands(): SingleCommands;
15
- get chain(): () => ChainedCommands;
16
- get can(): () => CanCommands;
17
- createChain(startTr?: Transaction, shouldDispatch?: boolean): ChainedCommands;
18
- createCan(startTr?: Transaction): CanCommands;
19
- buildProps(tr: Transaction, shouldDispatch?: boolean): CommandProps;
20
- }
@@ -1,159 +0,0 @@
1
- import { MarkType, NodeType, Schema } from '@tiptap/pm/model';
2
- import { EditorState, Plugin, PluginKey, Transaction } from '@tiptap/pm/state';
3
- import { EditorView } from '@tiptap/pm/view';
4
- import { EventEmitter } from './EventEmitter.js';
5
- import { ExtensionManager } from './ExtensionManager.js';
6
- import { NodePos } from './NodePos.js';
7
- import { CanCommands, ChainedCommands, EditorEvents, EditorOptions, JSONContent, SingleCommands, TextSerializer } from './types.js';
8
- export * as extensions from './extensions/index.js';
9
- export interface TiptapEditorHTMLElement extends HTMLElement {
10
- editor?: Editor;
11
- }
12
- export declare class Editor extends EventEmitter<EditorEvents> {
13
- private commandManager;
14
- extensionManager: ExtensionManager;
15
- private css;
16
- schema: Schema;
17
- view: EditorView;
18
- isFocused: boolean;
19
- extensionStorage: Record<string, any>;
20
- options: EditorOptions;
21
- constructor(options?: Partial<EditorOptions>);
22
- /**
23
- * Returns the editor storage.
24
- */
25
- get storage(): Record<string, any>;
26
- /**
27
- * An object of all registered commands.
28
- */
29
- get commands(): SingleCommands;
30
- /**
31
- * Create a command chain to call multiple commands at once.
32
- */
33
- chain(): ChainedCommands;
34
- /**
35
- * Check if a command or a command chain can be executed. Without executing it.
36
- */
37
- can(): CanCommands;
38
- /**
39
- * Inject CSS styles.
40
- */
41
- private injectCSS;
42
- /**
43
- * Update editor options.
44
- *
45
- * @param options A list of options
46
- */
47
- setOptions(options?: Partial<EditorOptions>): void;
48
- /**
49
- * Update editable state of the editor.
50
- */
51
- setEditable(editable: boolean, emitUpdate?: boolean): void;
52
- /**
53
- * Returns whether the editor is editable.
54
- */
55
- get isEditable(): boolean;
56
- /**
57
- * Returns the editor state.
58
- */
59
- get state(): EditorState;
60
- /**
61
- * Register a ProseMirror plugin.
62
- *
63
- * @param plugin A ProseMirror plugin
64
- * @param handlePlugins Control how to merge the plugin into the existing plugins.
65
- */
66
- registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void;
67
- /**
68
- * Unregister a ProseMirror plugin.
69
- *
70
- * @param nameOrPluginKey The plugins name
71
- */
72
- unregisterPlugin(nameOrPluginKey: string | PluginKey): void;
73
- /**
74
- * Creates an extension manager.
75
- */
76
- private createExtensionManager;
77
- /**
78
- * Creates an command manager.
79
- */
80
- private createCommandManager;
81
- /**
82
- * Creates a ProseMirror schema.
83
- */
84
- private createSchema;
85
- /**
86
- * Creates a ProseMirror view.
87
- */
88
- private createView;
89
- /**
90
- * Creates all node views.
91
- */
92
- createNodeViews(): void;
93
- /**
94
- * Prepend class name to element.
95
- */
96
- prependClass(): void;
97
- isCapturingTransaction: boolean;
98
- private capturedTransaction;
99
- captureTransaction(fn: Function): Transaction | null;
100
- /**
101
- * The callback over which to send transactions (state updates) produced by the view.
102
- *
103
- * @param transaction An editor state transaction
104
- */
105
- private dispatchTransaction;
106
- /**
107
- * Get attributes of the currently selected node or mark.
108
- */
109
- getAttributes(nameOrType: string | NodeType | MarkType): Record<string, any>;
110
- /**
111
- * Returns if the currently selected node or mark is active.
112
- *
113
- * @param name Name of the node or mark
114
- * @param attributes Attributes of the node or mark
115
- */
116
- isActive(name: string, attributes?: {}): boolean;
117
- isActive(attributes: {}): boolean;
118
- /**
119
- * Get the document as JSON.
120
- */
121
- getJSON(): JSONContent;
122
- /**
123
- * Get the document as HTML.
124
- */
125
- getHTML(): string;
126
- /**
127
- * Get the document as text.
128
- */
129
- getText(options?: {
130
- blockSeparator?: string;
131
- textSerializers?: Record<string, TextSerializer>;
132
- }): string;
133
- /**
134
- * Check if there is no content.
135
- */
136
- get isEmpty(): boolean;
137
- /**
138
- * Get the number of characters for the current document.
139
- *
140
- * @deprecated
141
- */
142
- getCharacterCount(): number;
143
- /**
144
- * Destroy the editor.
145
- */
146
- destroy(): void;
147
- /**
148
- * Check if the editor is already destroyed.
149
- */
150
- get isDestroyed(): boolean;
151
- $node(selector: string, attributes?: {
152
- [key: string]: any;
153
- }): NodePos | null;
154
- $nodes(selector: string, attributes?: {
155
- [key: string]: any;
156
- }): NodePos[] | null;
157
- $pos(pos: number): NodePos;
158
- get $doc(): NodePos;
159
- }
@@ -1,11 +0,0 @@
1
- type StringKeyOf<T> = Extract<keyof T, string>;
2
- type CallbackType<T extends Record<string, any>, EventName extends StringKeyOf<T>> = T[EventName] extends any[] ? T[EventName] : [T[EventName]];
3
- type CallbackFunction<T extends Record<string, any>, EventName extends StringKeyOf<T>> = (...props: CallbackType<T, EventName>) => any;
4
- export declare class EventEmitter<T extends Record<string, any>> {
5
- private callbacks;
6
- on<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this;
7
- emit<EventName extends StringKeyOf<T>>(event: EventName, ...args: CallbackType<T, EventName>): this;
8
- off<EventName extends StringKeyOf<T>>(event: EventName, fn?: CallbackFunction<T, EventName>): this;
9
- removeAllListeners(): void;
10
- }
11
- export {};