@tiptap/core 2.3.2 → 2.5.0-beta.0
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 +277 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +277 -67
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +277 -67
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/EventEmitter.d.ts +2 -2
- package/dist/packages/core/src/Extension.d.ts +129 -14
- package/dist/packages/core/src/ExtensionManager.d.ts +37 -0
- package/dist/packages/core/src/Mark.d.ts +129 -14
- package/dist/packages/core/src/Node.d.ts +226 -30
- package/dist/packages/core/src/NodeView.d.ts +4 -0
- package/dist/packages/core/src/PasteRule.d.ts +4 -0
- package/dist/packages/core/src/commands/blur.d.ts +1 -0
- package/dist/packages/core/src/commands/clearContent.d.ts +2 -0
- package/dist/packages/core/src/commands/clearNodes.d.ts +1 -0
- package/dist/packages/core/src/commands/command.d.ts +6 -0
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +1 -0
- package/dist/packages/core/src/commands/cut.d.ts +5 -0
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +1 -0
- package/dist/packages/core/src/commands/deleteNode.d.ts +3 -1
- package/dist/packages/core/src/commands/deleteRange.d.ts +2 -0
- package/dist/packages/core/src/commands/deleteSelection.d.ts +1 -0
- package/dist/packages/core/src/commands/enter.d.ts +1 -0
- package/dist/packages/core/src/commands/exitCode.d.ts +1 -0
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +14 -2
- package/dist/packages/core/src/commands/first.d.ts +2 -0
- package/dist/packages/core/src/commands/focus.d.ts +14 -1
- package/dist/packages/core/src/commands/insertContent.d.ts +17 -1
- package/dist/packages/core/src/commands/insertContentAt.d.ts +20 -1
- package/dist/packages/core/src/commands/join.d.ts +12 -4
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +2 -1
- package/dist/packages/core/src/commands/joinItemForward.d.ts +2 -1
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +2 -0
- package/dist/packages/core/src/commands/lift.d.ts +5 -1
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +2 -1
- package/dist/packages/core/src/commands/liftListItem.d.ts +3 -1
- package/dist/packages/core/src/commands/newlineInCode.d.ts +1 -0
- package/dist/packages/core/src/commands/resetAttributes.d.ts +3 -0
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +1 -0
- package/dist/packages/core/src/commands/selectAll.d.ts +1 -0
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +1 -0
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +1 -0
- package/dist/packages/core/src/commands/selectParentNode.d.ts +1 -0
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +1 -0
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +1 -0
- package/dist/packages/core/src/commands/setContent.d.ts +19 -1
- package/dist/packages/core/src/commands/setMark.d.ts +2 -0
- package/dist/packages/core/src/commands/setMeta.d.ts +3 -0
- package/dist/packages/core/src/commands/setNode.d.ts +3 -0
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +2 -0
- package/dist/packages/core/src/commands/setTextSelection.d.ts +2 -0
- package/dist/packages/core/src/commands/sinkListItem.d.ts +2 -0
- package/dist/packages/core/src/commands/splitBlock.d.ts +3 -0
- package/dist/packages/core/src/commands/splitListItem.d.ts +2 -0
- package/dist/packages/core/src/commands/toggleList.d.ts +5 -0
- package/dist/packages/core/src/commands/toggleMark.d.ts +13 -1
- package/dist/packages/core/src/commands/toggleNode.d.ts +4 -0
- package/dist/packages/core/src/commands/toggleWrap.d.ts +3 -0
- package/dist/packages/core/src/commands/undoInputRule.d.ts +1 -0
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +1 -0
- package/dist/packages/core/src/commands/unsetMark.d.ts +8 -1
- package/dist/packages/core/src/commands/updateAttributes.d.ts +12 -1
- package/dist/packages/core/src/commands/wrapIn.d.ts +3 -0
- package/dist/packages/core/src/commands/wrapInList.d.ts +3 -0
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +3 -0
- package/dist/packages/core/src/helpers/createChainableState.d.ts +5 -0
- package/dist/packages/core/src/helpers/createDocument.d.ts +7 -0
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +7 -0
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +5 -0
- package/dist/packages/core/src/helpers/findChildren.d.ts +6 -0
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +4 -0
- package/dist/packages/core/src/helpers/findParentNode.d.ts +8 -0
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +9 -0
- package/dist/packages/core/src/helpers/generateHTML.d.ts +6 -0
- package/dist/packages/core/src/helpers/generateJSON.d.ts +6 -0
- package/dist/packages/core/src/helpers/generateText.d.ts +7 -0
- package/dist/packages/core/src/helpers/getAttributes.d.ts +6 -0
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +7 -0
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +6 -0
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +6 -0
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +6 -0
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +7 -0
- package/dist/packages/core/src/helpers/getText.d.ts +9 -0
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +8 -0
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +6 -0
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +5 -0
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +1 -0
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +1 -0
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +1 -0
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +1 -0
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +1 -0
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +1 -0
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +1 -0
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +1 -0
- package/package.json +2 -2
- package/src/EventEmitter.ts +2 -2
- package/src/Extension.ts +130 -14
- package/src/ExtensionManager.ts +117 -85
- package/src/Mark.ts +129 -14
- package/src/Node.ts +226 -30
- package/src/NodeView.ts +4 -0
- package/src/PasteRule.ts +4 -0
- package/src/commands/blur.ts +1 -0
- package/src/commands/clearContent.ts +2 -0
- package/src/commands/clearNodes.ts +1 -0
- package/src/commands/command.ts +6 -0
- package/src/commands/createParagraphNear.ts +1 -0
- package/src/commands/cut.ts +5 -0
- package/src/commands/deleteCurrentNode.ts +1 -0
- package/src/commands/deleteNode.ts +3 -1
- package/src/commands/deleteRange.ts +2 -0
- package/src/commands/deleteSelection.ts +1 -0
- package/src/commands/enter.ts +1 -0
- package/src/commands/exitCode.ts +1 -0
- package/src/commands/extendMarkRange.ts +12 -1
- package/src/commands/first.ts +2 -0
- package/src/commands/focus.ts +12 -0
- package/src/commands/insertContent.ts +16 -0
- package/src/commands/insertContentAt.ts +19 -0
- package/src/commands/join.ts +12 -4
- package/src/commands/joinItemBackward.ts +6 -3
- package/src/commands/joinItemForward.ts +2 -1
- package/src/commands/keyboardShortcut.ts +2 -0
- package/src/commands/lift.ts +5 -1
- package/src/commands/liftEmptyBlock.ts +2 -1
- package/src/commands/liftListItem.ts +3 -1
- package/src/commands/newlineInCode.ts +1 -0
- package/src/commands/resetAttributes.ts +3 -0
- package/src/commands/scrollIntoView.ts +1 -0
- package/src/commands/selectAll.ts +1 -0
- package/src/commands/selectNodeBackward.ts +1 -0
- package/src/commands/selectNodeForward.ts +1 -0
- package/src/commands/selectParentNode.ts +1 -0
- package/src/commands/selectTextblockEnd.ts +1 -0
- package/src/commands/selectTextblockStart.ts +1 -0
- package/src/commands/setContent.ts +17 -0
- package/src/commands/setMark.ts +2 -0
- package/src/commands/setMeta.ts +3 -0
- package/src/commands/setNode.ts +3 -0
- package/src/commands/setNodeSelection.ts +2 -0
- package/src/commands/setTextSelection.ts +2 -0
- package/src/commands/sinkListItem.ts +2 -0
- package/src/commands/splitBlock.ts +3 -0
- package/src/commands/splitListItem.ts +2 -0
- package/src/commands/toggleList.ts +5 -0
- package/src/commands/toggleMark.ts +12 -0
- package/src/commands/toggleNode.ts +4 -0
- package/src/commands/toggleWrap.ts +3 -0
- package/src/commands/undoInputRule.ts +1 -0
- package/src/commands/unsetAllMarks.ts +1 -0
- package/src/commands/unsetMark.ts +7 -0
- package/src/commands/updateAttributes.ts +10 -0
- package/src/commands/wrapIn.ts +3 -0
- package/src/commands/wrapInList.ts +3 -0
- package/src/extensions/keymap.ts +7 -1
- package/src/helpers/combineTransactionSteps.ts +3 -0
- package/src/helpers/createChainableState.ts +5 -0
- package/src/helpers/createDocument.ts +7 -0
- package/src/helpers/createNodeFromContent.ts +16 -3
- package/src/helpers/defaultBlockAt.ts +5 -0
- package/src/helpers/findChildren.ts +6 -0
- package/src/helpers/findChildrenInRange.ts +4 -0
- package/src/helpers/findParentNode.ts +8 -0
- package/src/helpers/findParentNodeClosestToPos.ts +9 -0
- package/src/helpers/generateHTML.ts +6 -0
- package/src/helpers/generateJSON.ts +6 -0
- package/src/helpers/generateText.ts +7 -0
- package/src/helpers/getAttributes.ts +6 -0
- package/src/helpers/getExtensionField.ts +7 -0
- package/src/helpers/getSchemaByResolvedExtensions.ts +6 -0
- package/src/helpers/getSchemaTypeByName.ts +6 -0
- package/src/helpers/getSchemaTypeNameByName.ts +6 -0
- package/src/helpers/getSplittedAttributes.ts +7 -0
- package/src/helpers/getText.ts +9 -0
- package/src/helpers/getTextBetween.ts +12 -10
- package/src/helpers/getTextContentFromNodes.ts +6 -0
- package/src/helpers/getTextSerializersFromSchema.ts +5 -0
- package/src/inputRules/markInputRule.ts +1 -0
- package/src/inputRules/nodeInputRule.ts +4 -1
- package/src/inputRules/textInputRule.ts +1 -0
- package/src/inputRules/textblockTypeInputRule.ts +1 -0
- package/src/inputRules/wrappingInputRule.ts +1 -0
- package/src/pasteRules/markPasteRule.ts +1 -0
- package/src/pasteRules/nodePasteRule.ts +1 -0
- package/src/pasteRules/textPasteRule.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -10,6 +10,11 @@ var transform = require('@tiptap/pm/transform');
|
|
|
10
10
|
var commands$1 = require('@tiptap/pm/commands');
|
|
11
11
|
var schemaList = require('@tiptap/pm/schema-list');
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Takes a Transaction & Editor State and turns it into a chainable state object
|
|
15
|
+
* @param config The transaction and state to create the chainable state from
|
|
16
|
+
* @returns A chainable Editor state object
|
|
17
|
+
*/
|
|
13
18
|
function createChainableState(config) {
|
|
14
19
|
const { state, transaction } = config;
|
|
15
20
|
let { selection } = transaction;
|
|
@@ -176,6 +181,13 @@ class EventEmitter {
|
|
|
176
181
|
}
|
|
177
182
|
}
|
|
178
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Returns a field from an extension
|
|
186
|
+
* @param extension The Tiptap extension
|
|
187
|
+
* @param field The field, for example `renderHTML` or `priority`
|
|
188
|
+
* @param context The context object that should be passed as `this` into the function
|
|
189
|
+
* @returns The field value
|
|
190
|
+
*/
|
|
179
191
|
function getExtensionField(extension, field, context) {
|
|
180
192
|
if (extension.config[field] === undefined && extension.parent) {
|
|
181
193
|
return getExtensionField(extension.parent, field, context);
|
|
@@ -420,6 +432,12 @@ function cleanUpSchemaItem(data) {
|
|
|
420
432
|
return value !== null && value !== undefined;
|
|
421
433
|
}));
|
|
422
434
|
}
|
|
435
|
+
/**
|
|
436
|
+
* Creates a new Prosemirror schema based on the given extensions.
|
|
437
|
+
* @param extensions An array of Tiptap extensions
|
|
438
|
+
* @param editor The editor instance
|
|
439
|
+
* @returns A Prosemirror schema
|
|
440
|
+
*/
|
|
423
441
|
function getSchemaByResolvedExtensions(extensions, editor) {
|
|
424
442
|
var _a;
|
|
425
443
|
const allAttributes = getAttributesFromExtensions(extensions);
|
|
@@ -521,6 +539,12 @@ function getSchemaByResolvedExtensions(extensions, editor) {
|
|
|
521
539
|
});
|
|
522
540
|
}
|
|
523
541
|
|
|
542
|
+
/**
|
|
543
|
+
* Tries to get a node or mark type by its name.
|
|
544
|
+
* @param name The name of the node or mark type
|
|
545
|
+
* @param schema The Prosemiror schema to search in
|
|
546
|
+
* @returns The node or mark type, or null if it doesn't exist
|
|
547
|
+
*/
|
|
524
548
|
function getSchemaTypeByName(name, schema) {
|
|
525
549
|
return schema.nodes[name] || schema.marks[name] || null;
|
|
526
550
|
}
|
|
@@ -537,6 +561,12 @@ function isExtensionRulesEnabled(extension, enabled) {
|
|
|
537
561
|
return enabled;
|
|
538
562
|
}
|
|
539
563
|
|
|
564
|
+
/**
|
|
565
|
+
* Returns the text content of a resolved prosemirror position
|
|
566
|
+
* @param $from The resolved position to get the text content from
|
|
567
|
+
* @param maxMatch The maximum number of characters to match
|
|
568
|
+
* @returns The text content
|
|
569
|
+
*/
|
|
540
570
|
const getTextContentFromNodes = ($from, maxMatch = 500) => {
|
|
541
571
|
let textBefore = '';
|
|
542
572
|
const sliceEndPos = $from.parentOffset;
|
|
@@ -744,6 +774,10 @@ function isNumber(value) {
|
|
|
744
774
|
return typeof value === 'number';
|
|
745
775
|
}
|
|
746
776
|
|
|
777
|
+
/**
|
|
778
|
+
* Paste rules are used to react to pasted content.
|
|
779
|
+
* @see https://tiptap.dev/guide/custom-extensions/#paste-rules
|
|
780
|
+
*/
|
|
747
781
|
class PasteRule {
|
|
748
782
|
constructor(config) {
|
|
749
783
|
this.find = config.find;
|
|
@@ -942,57 +976,14 @@ class ExtensionManager {
|
|
|
942
976
|
this.editor = editor;
|
|
943
977
|
this.extensions = ExtensionManager.resolve(extensions);
|
|
944
978
|
this.schema = getSchemaByResolvedExtensions(this.extensions, editor);
|
|
945
|
-
this.
|
|
946
|
-
var _a;
|
|
947
|
-
// store extension storage in editor
|
|
948
|
-
this.editor.extensionStorage[extension.name] = extension.storage;
|
|
949
|
-
const context = {
|
|
950
|
-
name: extension.name,
|
|
951
|
-
options: extension.options,
|
|
952
|
-
storage: extension.storage,
|
|
953
|
-
editor: this.editor,
|
|
954
|
-
type: getSchemaTypeByName(extension.name, this.schema),
|
|
955
|
-
};
|
|
956
|
-
if (extension.type === 'mark') {
|
|
957
|
-
const keepOnSplit = (_a = callOrReturn(getExtensionField(extension, 'keepOnSplit', context))) !== null && _a !== void 0 ? _a : true;
|
|
958
|
-
if (keepOnSplit) {
|
|
959
|
-
this.splittableMarks.push(extension.name);
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
const onBeforeCreate = getExtensionField(extension, 'onBeforeCreate', context);
|
|
963
|
-
if (onBeforeCreate) {
|
|
964
|
-
this.editor.on('beforeCreate', onBeforeCreate);
|
|
965
|
-
}
|
|
966
|
-
const onCreate = getExtensionField(extension, 'onCreate', context);
|
|
967
|
-
if (onCreate) {
|
|
968
|
-
this.editor.on('create', onCreate);
|
|
969
|
-
}
|
|
970
|
-
const onUpdate = getExtensionField(extension, 'onUpdate', context);
|
|
971
|
-
if (onUpdate) {
|
|
972
|
-
this.editor.on('update', onUpdate);
|
|
973
|
-
}
|
|
974
|
-
const onSelectionUpdate = getExtensionField(extension, 'onSelectionUpdate', context);
|
|
975
|
-
if (onSelectionUpdate) {
|
|
976
|
-
this.editor.on('selectionUpdate', onSelectionUpdate);
|
|
977
|
-
}
|
|
978
|
-
const onTransaction = getExtensionField(extension, 'onTransaction', context);
|
|
979
|
-
if (onTransaction) {
|
|
980
|
-
this.editor.on('transaction', onTransaction);
|
|
981
|
-
}
|
|
982
|
-
const onFocus = getExtensionField(extension, 'onFocus', context);
|
|
983
|
-
if (onFocus) {
|
|
984
|
-
this.editor.on('focus', onFocus);
|
|
985
|
-
}
|
|
986
|
-
const onBlur = getExtensionField(extension, 'onBlur', context);
|
|
987
|
-
if (onBlur) {
|
|
988
|
-
this.editor.on('blur', onBlur);
|
|
989
|
-
}
|
|
990
|
-
const onDestroy = getExtensionField(extension, 'onDestroy', context);
|
|
991
|
-
if (onDestroy) {
|
|
992
|
-
this.editor.on('destroy', onDestroy);
|
|
993
|
-
}
|
|
994
|
-
});
|
|
979
|
+
this.setupExtensions();
|
|
995
980
|
}
|
|
981
|
+
/**
|
|
982
|
+
* Returns a flattened and sorted extension list while
|
|
983
|
+
* also checking for duplicated extensions and warns the user.
|
|
984
|
+
* @param extensions An array of Tiptap extensions
|
|
985
|
+
* @returns An flattened and sorted array of Tiptap extensions
|
|
986
|
+
*/
|
|
996
987
|
static resolve(extensions) {
|
|
997
988
|
const resolvedExtensions = ExtensionManager.sort(ExtensionManager.flatten(extensions));
|
|
998
989
|
const duplicatedNames = findDuplicates(resolvedExtensions.map(extension => extension.name));
|
|
@@ -1003,6 +994,11 @@ class ExtensionManager {
|
|
|
1003
994
|
}
|
|
1004
995
|
return resolvedExtensions;
|
|
1005
996
|
}
|
|
997
|
+
/**
|
|
998
|
+
* Create a flattened array of extensions by traversing the `addExtensions` field.
|
|
999
|
+
* @param extensions An array of Tiptap extensions
|
|
1000
|
+
* @returns A flattened array of Tiptap extensions
|
|
1001
|
+
*/
|
|
1006
1002
|
static flatten(extensions) {
|
|
1007
1003
|
return (extensions
|
|
1008
1004
|
.map(extension => {
|
|
@@ -1020,6 +1016,11 @@ class ExtensionManager {
|
|
|
1020
1016
|
// `Infinity` will break TypeScript so we set a number that is probably high enough
|
|
1021
1017
|
.flat(10));
|
|
1022
1018
|
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Sort extensions by priority.
|
|
1021
|
+
* @param extensions An array of Tiptap extensions
|
|
1022
|
+
* @returns A sorted array of Tiptap extensions by priority
|
|
1023
|
+
*/
|
|
1023
1024
|
static sort(extensions) {
|
|
1024
1025
|
const defaultPriority = 100;
|
|
1025
1026
|
return extensions.sort((a, b) => {
|
|
@@ -1034,6 +1035,10 @@ class ExtensionManager {
|
|
|
1034
1035
|
return 0;
|
|
1035
1036
|
});
|
|
1036
1037
|
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Get all commands from the extensions.
|
|
1040
|
+
* @returns An object with all commands where the key is the command name and the value is the command function
|
|
1041
|
+
*/
|
|
1037
1042
|
get commands() {
|
|
1038
1043
|
return this.extensions.reduce((commands, extension) => {
|
|
1039
1044
|
const context = {
|
|
@@ -1053,6 +1058,10 @@ class ExtensionManager {
|
|
|
1053
1058
|
};
|
|
1054
1059
|
}, {});
|
|
1055
1060
|
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Get all registered Prosemirror plugins from the extensions.
|
|
1063
|
+
* @returns An array of Prosemirror plugins
|
|
1064
|
+
*/
|
|
1056
1065
|
get plugins() {
|
|
1057
1066
|
const { editor } = this;
|
|
1058
1067
|
// With ProseMirror, first plugins within an array are executed first.
|
|
@@ -1115,9 +1124,17 @@ class ExtensionManager {
|
|
|
1115
1124
|
...allPlugins,
|
|
1116
1125
|
];
|
|
1117
1126
|
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Get all attributes from the extensions.
|
|
1129
|
+
* @returns An array of attributes
|
|
1130
|
+
*/
|
|
1118
1131
|
get attributes() {
|
|
1119
1132
|
return getAttributesFromExtensions(this.extensions);
|
|
1120
1133
|
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Get all node views from the extensions.
|
|
1136
|
+
* @returns An object with all node views where the key is the node name and the value is the node view function
|
|
1137
|
+
*/
|
|
1121
1138
|
get nodeViews() {
|
|
1122
1139
|
const { editor } = this;
|
|
1123
1140
|
const { nodeExtensions } = splitExtensions(this.extensions);
|
|
@@ -1150,6 +1167,62 @@ class ExtensionManager {
|
|
|
1150
1167
|
return [extension.name, nodeview];
|
|
1151
1168
|
}));
|
|
1152
1169
|
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Go through all extensions, create extension storages & setup marks
|
|
1172
|
+
* & bind editor event listener.
|
|
1173
|
+
*/
|
|
1174
|
+
setupExtensions() {
|
|
1175
|
+
this.extensions.forEach(extension => {
|
|
1176
|
+
var _a;
|
|
1177
|
+
// store extension storage in editor
|
|
1178
|
+
this.editor.extensionStorage[extension.name] = extension.storage;
|
|
1179
|
+
const context = {
|
|
1180
|
+
name: extension.name,
|
|
1181
|
+
options: extension.options,
|
|
1182
|
+
storage: extension.storage,
|
|
1183
|
+
editor: this.editor,
|
|
1184
|
+
type: getSchemaTypeByName(extension.name, this.schema),
|
|
1185
|
+
};
|
|
1186
|
+
if (extension.type === 'mark') {
|
|
1187
|
+
const keepOnSplit = (_a = callOrReturn(getExtensionField(extension, 'keepOnSplit', context))) !== null && _a !== void 0 ? _a : true;
|
|
1188
|
+
if (keepOnSplit) {
|
|
1189
|
+
this.splittableMarks.push(extension.name);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
const onBeforeCreate = getExtensionField(extension, 'onBeforeCreate', context);
|
|
1193
|
+
const onCreate = getExtensionField(extension, 'onCreate', context);
|
|
1194
|
+
const onUpdate = getExtensionField(extension, 'onUpdate', context);
|
|
1195
|
+
const onSelectionUpdate = getExtensionField(extension, 'onSelectionUpdate', context);
|
|
1196
|
+
const onTransaction = getExtensionField(extension, 'onTransaction', context);
|
|
1197
|
+
const onFocus = getExtensionField(extension, 'onFocus', context);
|
|
1198
|
+
const onBlur = getExtensionField(extension, 'onBlur', context);
|
|
1199
|
+
const onDestroy = getExtensionField(extension, 'onDestroy', context);
|
|
1200
|
+
if (onBeforeCreate) {
|
|
1201
|
+
this.editor.on('beforeCreate', onBeforeCreate);
|
|
1202
|
+
}
|
|
1203
|
+
if (onCreate) {
|
|
1204
|
+
this.editor.on('create', onCreate);
|
|
1205
|
+
}
|
|
1206
|
+
if (onUpdate) {
|
|
1207
|
+
this.editor.on('update', onUpdate);
|
|
1208
|
+
}
|
|
1209
|
+
if (onSelectionUpdate) {
|
|
1210
|
+
this.editor.on('selectionUpdate', onSelectionUpdate);
|
|
1211
|
+
}
|
|
1212
|
+
if (onTransaction) {
|
|
1213
|
+
this.editor.on('transaction', onTransaction);
|
|
1214
|
+
}
|
|
1215
|
+
if (onFocus) {
|
|
1216
|
+
this.editor.on('focus', onFocus);
|
|
1217
|
+
}
|
|
1218
|
+
if (onBlur) {
|
|
1219
|
+
this.editor.on('blur', onBlur);
|
|
1220
|
+
}
|
|
1221
|
+
if (onDestroy) {
|
|
1222
|
+
this.editor.on('destroy', onDestroy);
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1153
1226
|
}
|
|
1154
1227
|
|
|
1155
1228
|
// see: https://github.com/mesqueeb/is-what/blob/88d6e4ca92fb2baab6003c54e02eedf4e729e5ab/src/index.ts
|
|
@@ -1183,6 +1256,10 @@ function mergeDeep(target, source) {
|
|
|
1183
1256
|
return output;
|
|
1184
1257
|
}
|
|
1185
1258
|
|
|
1259
|
+
/**
|
|
1260
|
+
* The Extension class is the base class for all extensions.
|
|
1261
|
+
* @see https://tiptap.dev/api/extensions#create-a-new-extension
|
|
1262
|
+
*/
|
|
1186
1263
|
class Extension {
|
|
1187
1264
|
constructor(config = {}) {
|
|
1188
1265
|
this.type = 'extension';
|
|
@@ -1220,6 +1297,7 @@ class Extension {
|
|
|
1220
1297
|
// return a new instance so we can use the same extension
|
|
1221
1298
|
// with different calls of `configure`
|
|
1222
1299
|
const extension = this.extend();
|
|
1300
|
+
extension.parent = this.parent;
|
|
1223
1301
|
extension.options = mergeDeep(this.options, options);
|
|
1224
1302
|
extension.storage = callOrReturn(getExtensionField(extension, 'addStorage', {
|
|
1225
1303
|
name: extension.name,
|
|
@@ -1246,19 +1324,25 @@ class Extension {
|
|
|
1246
1324
|
}
|
|
1247
1325
|
}
|
|
1248
1326
|
|
|
1327
|
+
/**
|
|
1328
|
+
* Gets the text between two positions in a Prosemirror node
|
|
1329
|
+
* and serializes it using the given text serializers and block separator (see getText)
|
|
1330
|
+
* @param startNode The Prosemirror node to start from
|
|
1331
|
+
* @param range The range of the text to get
|
|
1332
|
+
* @param options Options for the text serializer & block separator
|
|
1333
|
+
* @returns The text between the two positions
|
|
1334
|
+
*/
|
|
1249
1335
|
function getTextBetween(startNode, range, options) {
|
|
1250
1336
|
const { from, to } = range;
|
|
1251
1337
|
const { blockSeparator = '\n\n', textSerializers = {} } = options || {};
|
|
1252
1338
|
let text = '';
|
|
1253
|
-
let separated = true;
|
|
1254
1339
|
startNode.nodesBetween(from, to, (node, pos, parent, index) => {
|
|
1255
1340
|
var _a;
|
|
1341
|
+
if (node.isBlock && pos > from) {
|
|
1342
|
+
text += blockSeparator;
|
|
1343
|
+
}
|
|
1256
1344
|
const textSerializer = textSerializers === null || textSerializers === void 0 ? void 0 : textSerializers[node.type.name];
|
|
1257
1345
|
if (textSerializer) {
|
|
1258
|
-
if (node.isBlock && !separated) {
|
|
1259
|
-
text += blockSeparator;
|
|
1260
|
-
separated = true;
|
|
1261
|
-
}
|
|
1262
1346
|
if (parent) {
|
|
1263
1347
|
text += textSerializer({
|
|
1264
1348
|
node,
|
|
@@ -1273,16 +1357,16 @@ function getTextBetween(startNode, range, options) {
|
|
|
1273
1357
|
}
|
|
1274
1358
|
if (node.isText) {
|
|
1275
1359
|
text += (_a = node === null || node === void 0 ? void 0 : node.text) === null || _a === void 0 ? void 0 : _a.slice(Math.max(from, pos) - pos, to - pos); // eslint-disable-line
|
|
1276
|
-
separated = false;
|
|
1277
|
-
}
|
|
1278
|
-
else if (node.isBlock && !separated) {
|
|
1279
|
-
text += blockSeparator;
|
|
1280
|
-
separated = true;
|
|
1281
1360
|
}
|
|
1282
1361
|
});
|
|
1283
1362
|
return text;
|
|
1284
1363
|
}
|
|
1285
1364
|
|
|
1365
|
+
/**
|
|
1366
|
+
* Find text serializers `toText` in a Prosemirror schema
|
|
1367
|
+
* @param schema The Prosemirror schema to search in
|
|
1368
|
+
* @returns A record of text serializers by node name
|
|
1369
|
+
*/
|
|
1286
1370
|
function getTextSerializersFromSchema(schema) {
|
|
1287
1371
|
return Object.fromEntries(Object.entries(schema.nodes)
|
|
1288
1372
|
.filter(([, node]) => node.spec.toText)
|
|
@@ -1665,15 +1749,26 @@ function elementFromString(value) {
|
|
|
1665
1749
|
return removeWhitespaces(html);
|
|
1666
1750
|
}
|
|
1667
1751
|
|
|
1752
|
+
/**
|
|
1753
|
+
* Takes a JSON or HTML content and creates a Prosemirror node or fragment from it.
|
|
1754
|
+
* @param content The JSON or HTML content to create the node from
|
|
1755
|
+
* @param schema The Prosemirror schema to use for the node
|
|
1756
|
+
* @param options Options for the parser
|
|
1757
|
+
* @returns The created Prosemirror node or fragment
|
|
1758
|
+
*/
|
|
1668
1759
|
function createNodeFromContent(content, schema, options) {
|
|
1669
1760
|
options = {
|
|
1670
1761
|
slice: true,
|
|
1671
1762
|
parseOptions: {},
|
|
1672
1763
|
...options,
|
|
1673
1764
|
};
|
|
1674
|
-
|
|
1765
|
+
const isJSONContent = typeof content === 'object' && content !== null;
|
|
1766
|
+
const isTextContent = typeof content === 'string';
|
|
1767
|
+
if (isJSONContent) {
|
|
1675
1768
|
try {
|
|
1676
|
-
|
|
1769
|
+
const isArrayContent = Array.isArray(content) && content.length > 0;
|
|
1770
|
+
// if the JSON Content is an array of nodes, create a fragment for each node
|
|
1771
|
+
if (isArrayContent) {
|
|
1677
1772
|
return model.Fragment.fromArray(content.map(item => schema.nodeFromJSON(item)));
|
|
1678
1773
|
}
|
|
1679
1774
|
return schema.nodeFromJSON(content);
|
|
@@ -1683,7 +1778,7 @@ function createNodeFromContent(content, schema, options) {
|
|
|
1683
1778
|
return createNodeFromContent('', schema, options);
|
|
1684
1779
|
}
|
|
1685
1780
|
}
|
|
1686
|
-
if (
|
|
1781
|
+
if (isTextContent) {
|
|
1687
1782
|
const parser = model.DOMParser.fromSchema(schema);
|
|
1688
1783
|
return options.slice
|
|
1689
1784
|
? parser.parseSlice(elementFromString(content), options.parseOptions).content
|
|
@@ -1805,7 +1900,7 @@ const joinForward = () => ({ state, dispatch }) => {
|
|
|
1805
1900
|
return commands$1.joinForward(state, dispatch);
|
|
1806
1901
|
};
|
|
1807
1902
|
|
|
1808
|
-
const joinItemBackward = () => ({
|
|
1903
|
+
const joinItemBackward = () => ({ state, dispatch, tr, }) => {
|
|
1809
1904
|
try {
|
|
1810
1905
|
const point = transform.joinPoint(state.doc, state.selection.$from.pos, -1);
|
|
1811
1906
|
if (point === null || point === undefined) {
|
|
@@ -1817,7 +1912,7 @@ const joinItemBackward = () => ({ tr, state, dispatch, }) => {
|
|
|
1817
1912
|
}
|
|
1818
1913
|
return true;
|
|
1819
1914
|
}
|
|
1820
|
-
catch {
|
|
1915
|
+
catch (e) {
|
|
1821
1916
|
return false;
|
|
1822
1917
|
}
|
|
1823
1918
|
};
|
|
@@ -1983,6 +2078,12 @@ const newlineInCode = () => ({ state, dispatch }) => {
|
|
|
1983
2078
|
return commands$1.newlineInCode(state, dispatch);
|
|
1984
2079
|
};
|
|
1985
2080
|
|
|
2081
|
+
/**
|
|
2082
|
+
* Get the type of a schema item by its name.
|
|
2083
|
+
* @param name The name of the schema item
|
|
2084
|
+
* @param schema The Prosemiror schema to search in
|
|
2085
|
+
* @returns The type of the schema item (`node` or `mark`), or null if it doesn't exist
|
|
2086
|
+
*/
|
|
1986
2087
|
function getSchemaTypeNameByName(name, schema) {
|
|
1987
2088
|
if (schema.nodes[name]) {
|
|
1988
2089
|
return 'node';
|
|
@@ -2080,6 +2181,13 @@ const selectTextblockStart = () => ({ state, dispatch }) => {
|
|
|
2080
2181
|
return commands$1.selectTextblockStart(state, dispatch);
|
|
2081
2182
|
};
|
|
2082
2183
|
|
|
2184
|
+
/**
|
|
2185
|
+
* Create a new Prosemirror document node from content.
|
|
2186
|
+
* @param content The JSON or HTML content to create the document from
|
|
2187
|
+
* @param schema The Prosemirror schema to use for the document
|
|
2188
|
+
* @param parseOptions Options for the parser
|
|
2189
|
+
* @returns The created Prosemirror document node
|
|
2190
|
+
*/
|
|
2083
2191
|
function createDocument(content, schema, parseOptions = {}) {
|
|
2084
2192
|
return createNodeFromContent(content, schema, { slice: false, parseOptions });
|
|
2085
2193
|
}
|
|
@@ -2117,6 +2225,9 @@ function getMarkAttributes(state, typeOrName) {
|
|
|
2117
2225
|
|
|
2118
2226
|
/**
|
|
2119
2227
|
* Returns a new `Transform` based on all steps of the passed transactions.
|
|
2228
|
+
* @param oldDoc The Prosemirror node to start from
|
|
2229
|
+
* @param transactions The transactions to combine
|
|
2230
|
+
* @returns A new `Transform` with all steps of the passed transactions
|
|
2120
2231
|
*/
|
|
2121
2232
|
function combineTransactionSteps(oldDoc, transactions) {
|
|
2122
2233
|
const transform$1 = new transform.Transform(oldDoc);
|
|
@@ -2128,6 +2239,11 @@ function combineTransactionSteps(oldDoc, transactions) {
|
|
|
2128
2239
|
return transform$1;
|
|
2129
2240
|
}
|
|
2130
2241
|
|
|
2242
|
+
/**
|
|
2243
|
+
* Gets the default block type at a given match
|
|
2244
|
+
* @param match The content match to get the default block type from
|
|
2245
|
+
* @returns The default block type or null
|
|
2246
|
+
*/
|
|
2131
2247
|
function defaultBlockAt(match) {
|
|
2132
2248
|
for (let i = 0; i < match.edgeCount; i += 1) {
|
|
2133
2249
|
const { type } = match.edge(i);
|
|
@@ -2138,6 +2254,12 @@ function defaultBlockAt(match) {
|
|
|
2138
2254
|
return null;
|
|
2139
2255
|
}
|
|
2140
2256
|
|
|
2257
|
+
/**
|
|
2258
|
+
* Find children inside a Prosemirror node that match a predicate.
|
|
2259
|
+
* @param node The Prosemirror node to search in
|
|
2260
|
+
* @param predicate The predicate to match
|
|
2261
|
+
* @returns An array of nodes with their positions
|
|
2262
|
+
*/
|
|
2141
2263
|
function findChildren(node, predicate) {
|
|
2142
2264
|
const nodesWithPos = [];
|
|
2143
2265
|
node.descendants((child, pos) => {
|
|
@@ -2153,6 +2275,10 @@ function findChildren(node, predicate) {
|
|
|
2153
2275
|
|
|
2154
2276
|
/**
|
|
2155
2277
|
* Same as `findChildren` but searches only within a `range`.
|
|
2278
|
+
* @param node The Prosemirror node to search in
|
|
2279
|
+
* @param range The range to search in
|
|
2280
|
+
* @param predicate The predicate to match
|
|
2281
|
+
* @returns An array of nodes with their positions
|
|
2156
2282
|
*/
|
|
2157
2283
|
function findChildrenInRange(node, range, predicate) {
|
|
2158
2284
|
const nodesWithPos = [];
|
|
@@ -2176,6 +2302,15 @@ function findChildrenInRange(node, range, predicate) {
|
|
|
2176
2302
|
return nodesWithPos;
|
|
2177
2303
|
}
|
|
2178
2304
|
|
|
2305
|
+
/**
|
|
2306
|
+
* Finds the closest parent node to a resolved position that matches a predicate.
|
|
2307
|
+
* @param $pos The resolved position to search from
|
|
2308
|
+
* @param predicate The predicate to match
|
|
2309
|
+
* @returns The closest parent node to the resolved position that matches the predicate
|
|
2310
|
+
* @example ```js
|
|
2311
|
+
* findParentNodeClosestToPos($from, node => node.type.name === 'paragraph')
|
|
2312
|
+
* ```
|
|
2313
|
+
*/
|
|
2179
2314
|
function findParentNodeClosestToPos($pos, predicate) {
|
|
2180
2315
|
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2181
2316
|
const node = $pos.node(i);
|
|
@@ -2190,6 +2325,14 @@ function findParentNodeClosestToPos($pos, predicate) {
|
|
|
2190
2325
|
}
|
|
2191
2326
|
}
|
|
2192
2327
|
|
|
2328
|
+
/**
|
|
2329
|
+
* Finds the closest parent node to the current selection that matches a predicate.
|
|
2330
|
+
* @param predicate The predicate to match
|
|
2331
|
+
* @returns A command that finds the closest parent node to the current selection that matches the predicate
|
|
2332
|
+
* @example ```js
|
|
2333
|
+
* findParentNode(node => node.type.name === 'paragraph')
|
|
2334
|
+
* ```
|
|
2335
|
+
*/
|
|
2193
2336
|
function findParentNode(predicate) {
|
|
2194
2337
|
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2195
2338
|
}
|
|
@@ -2207,18 +2350,39 @@ function getSchema(extensions, editor) {
|
|
|
2207
2350
|
return getSchemaByResolvedExtensions(resolvedExtensions, editor);
|
|
2208
2351
|
}
|
|
2209
2352
|
|
|
2353
|
+
/**
|
|
2354
|
+
* Generate HTML from a JSONContent
|
|
2355
|
+
* @param doc The JSONContent to generate HTML from
|
|
2356
|
+
* @param extensions The extensions to use for the schema
|
|
2357
|
+
* @returns The generated HTML
|
|
2358
|
+
*/
|
|
2210
2359
|
function generateHTML(doc, extensions) {
|
|
2211
2360
|
const schema = getSchema(extensions);
|
|
2212
2361
|
const contentNode = model.Node.fromJSON(schema, doc);
|
|
2213
2362
|
return getHTMLFromFragment(contentNode.content, schema);
|
|
2214
2363
|
}
|
|
2215
2364
|
|
|
2365
|
+
/**
|
|
2366
|
+
* Generate JSONContent from HTML
|
|
2367
|
+
* @param html The HTML to generate JSONContent from
|
|
2368
|
+
* @param extensions The extensions to use for the schema
|
|
2369
|
+
* @returns The generated JSONContent
|
|
2370
|
+
*/
|
|
2216
2371
|
function generateJSON(html, extensions) {
|
|
2217
2372
|
const schema = getSchema(extensions);
|
|
2218
2373
|
const dom = elementFromString(html);
|
|
2219
2374
|
return model.DOMParser.fromSchema(schema).parse(dom).toJSON();
|
|
2220
2375
|
}
|
|
2221
2376
|
|
|
2377
|
+
/**
|
|
2378
|
+
* Gets the text of a Prosemirror node
|
|
2379
|
+
* @param node The Prosemirror node
|
|
2380
|
+
* @param options Options for the text serializer & block separator
|
|
2381
|
+
* @returns The text of the node
|
|
2382
|
+
* @example ```js
|
|
2383
|
+
* const text = getText(node, { blockSeparator: '\n' })
|
|
2384
|
+
* ```
|
|
2385
|
+
*/
|
|
2222
2386
|
function getText(node, options) {
|
|
2223
2387
|
const range = {
|
|
2224
2388
|
from: 0,
|
|
@@ -2227,6 +2391,13 @@ function getText(node, options) {
|
|
|
2227
2391
|
return getTextBetween(node, range, options);
|
|
2228
2392
|
}
|
|
2229
2393
|
|
|
2394
|
+
/**
|
|
2395
|
+
* Generate raw text from a JSONContent
|
|
2396
|
+
* @param doc The JSONContent to generate text from
|
|
2397
|
+
* @param extensions The extensions to use for the schema
|
|
2398
|
+
* @param options Options for the text generation f.e. blockSeparator or textSerializers
|
|
2399
|
+
* @returns The generated text
|
|
2400
|
+
*/
|
|
2230
2401
|
function generateText(doc, extensions, options) {
|
|
2231
2402
|
const { blockSeparator = '\n\n', textSerializers = {} } = options || {};
|
|
2232
2403
|
const schema = getSchema(extensions);
|
|
@@ -2254,6 +2425,12 @@ function getNodeAttributes(state, typeOrName) {
|
|
|
2254
2425
|
return { ...node.attrs };
|
|
2255
2426
|
}
|
|
2256
2427
|
|
|
2428
|
+
/**
|
|
2429
|
+
* Get node or mark attributes by type or name on the current editor state
|
|
2430
|
+
* @param state The current editor state
|
|
2431
|
+
* @param typeOrName The node or mark type or name
|
|
2432
|
+
* @returns The attributes of the node or mark or an empty object
|
|
2433
|
+
*/
|
|
2257
2434
|
function getAttributes(state, typeOrName) {
|
|
2258
2435
|
const schemaType = getSchemaTypeNameByName(typeof typeOrName === 'string' ? typeOrName : typeOrName.name, state.schema);
|
|
2259
2436
|
if (schemaType === 'node') {
|
|
@@ -2438,6 +2615,13 @@ const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
|
2438
2615
|
return [node, currentDepth];
|
|
2439
2616
|
};
|
|
2440
2617
|
|
|
2618
|
+
/**
|
|
2619
|
+
* Return attributes of an extension that should be splitted by keepOnSplit flag
|
|
2620
|
+
* @param extensionAttributes Array of extension attributes
|
|
2621
|
+
* @param typeName The type of the extension
|
|
2622
|
+
* @param attributes The attributes of the extension
|
|
2623
|
+
* @returns The splitted attributes
|
|
2624
|
+
*/
|
|
2441
2625
|
function getSplittedAttributes(extensionAttributes, typeName, attributes) {
|
|
2442
2626
|
return Object.fromEntries(Object
|
|
2443
2627
|
.entries(attributes)
|
|
@@ -3288,7 +3472,12 @@ const Keymap = Extension.create({
|
|
|
3288
3472
|
const isAtStart = (parentIsIsolating && $parentPos.parent.childCount === 1)
|
|
3289
3473
|
? parentPos === $anchor.pos
|
|
3290
3474
|
: state.Selection.atStart(doc).from === pos;
|
|
3291
|
-
if (!empty
|
|
3475
|
+
if (!empty
|
|
3476
|
+
|| !parent.type.isTextblock
|
|
3477
|
+
|| parent.textContent.length
|
|
3478
|
+
|| !isAtStart
|
|
3479
|
+
|| (isAtStart && $anchor.parent.type.name === 'paragraph') // prevent clearNodes when no nodes to clear, otherwise history stack is appended
|
|
3480
|
+
) {
|
|
3292
3481
|
return false;
|
|
3293
3482
|
}
|
|
3294
3483
|
return commands.clearNodes();
|
|
@@ -4060,6 +4249,7 @@ class Editor extends EventEmitter {
|
|
|
4060
4249
|
/**
|
|
4061
4250
|
* Build an input rule that adds a mark when the
|
|
4062
4251
|
* matched text is typed into it.
|
|
4252
|
+
* @see https://tiptap.dev/guide/custom-extensions/#input-rules
|
|
4063
4253
|
*/
|
|
4064
4254
|
function markInputRule(config) {
|
|
4065
4255
|
return new InputRule({
|
|
@@ -4103,6 +4293,7 @@ function markInputRule(config) {
|
|
|
4103
4293
|
/**
|
|
4104
4294
|
* Build an input rule that adds a node when the
|
|
4105
4295
|
* matched text is typed into it.
|
|
4296
|
+
* @see https://tiptap.dev/guide/custom-extensions/#input-rules
|
|
4106
4297
|
*/
|
|
4107
4298
|
function nodeInputRule(config) {
|
|
4108
4299
|
return new InputRule({
|
|
@@ -4129,7 +4320,8 @@ function nodeInputRule(config) {
|
|
|
4129
4320
|
tr.replaceWith(matchStart, end, newNode);
|
|
4130
4321
|
}
|
|
4131
4322
|
else if (match[0]) {
|
|
4132
|
-
|
|
4323
|
+
const insertionStart = config.type.isInline ? start : start - 1;
|
|
4324
|
+
tr.insert(insertionStart, config.type.create(attributes)).delete(tr.mapping.map(start), tr.mapping.map(end));
|
|
4133
4325
|
}
|
|
4134
4326
|
tr.scrollIntoView();
|
|
4135
4327
|
},
|
|
@@ -4141,6 +4333,7 @@ function nodeInputRule(config) {
|
|
|
4141
4333
|
* matched text is typed into it. When using a regular expresion you’ll
|
|
4142
4334
|
* probably want the regexp to start with `^`, so that the pattern can
|
|
4143
4335
|
* only occur at the start of a textblock.
|
|
4336
|
+
* @see https://tiptap.dev/guide/custom-extensions/#input-rules
|
|
4144
4337
|
*/
|
|
4145
4338
|
function textblockTypeInputRule(config) {
|
|
4146
4339
|
return new InputRule({
|
|
@@ -4161,6 +4354,7 @@ function textblockTypeInputRule(config) {
|
|
|
4161
4354
|
/**
|
|
4162
4355
|
* Build an input rule that replaces text when the
|
|
4163
4356
|
* matched text is typed into it.
|
|
4357
|
+
* @see https://tiptap.dev/guide/custom-extensions/#input-rules
|
|
4164
4358
|
*/
|
|
4165
4359
|
function textInputRule(config) {
|
|
4166
4360
|
return new InputRule({
|
|
@@ -4197,6 +4391,7 @@ function textInputRule(config) {
|
|
|
4197
4391
|
* two nodes. You can pass a join predicate, which takes a regular
|
|
4198
4392
|
* expression match and the node before the wrapped node, and can
|
|
4199
4393
|
* return a boolean to indicate whether a join should happen.
|
|
4394
|
+
* @see https://tiptap.dev/guide/custom-extensions/#input-rules
|
|
4200
4395
|
*/
|
|
4201
4396
|
function wrappingInputRule(config) {
|
|
4202
4397
|
return new InputRule({
|
|
@@ -4236,6 +4431,10 @@ function wrappingInputRule(config) {
|
|
|
4236
4431
|
});
|
|
4237
4432
|
}
|
|
4238
4433
|
|
|
4434
|
+
/**
|
|
4435
|
+
* The Mark class is used to create custom mark extensions.
|
|
4436
|
+
* @see https://tiptap.dev/api/extensions#create-a-new-extension
|
|
4437
|
+
*/
|
|
4239
4438
|
class Mark {
|
|
4240
4439
|
constructor(config = {}) {
|
|
4241
4440
|
this.type = 'mark';
|
|
@@ -4319,6 +4518,10 @@ class Mark {
|
|
|
4319
4518
|
}
|
|
4320
4519
|
}
|
|
4321
4520
|
|
|
4521
|
+
/**
|
|
4522
|
+
* The Node class is used to create custom node extensions.
|
|
4523
|
+
* @see https://tiptap.dev/api/extensions#create-a-new-extension
|
|
4524
|
+
*/
|
|
4322
4525
|
class Node {
|
|
4323
4526
|
constructor(config = {}) {
|
|
4324
4527
|
this.type = 'node';
|
|
@@ -4386,6 +4589,10 @@ function isAndroid() {
|
|
|
4386
4589
|
return navigator.platform === 'Android' || /android/i.test(navigator.userAgent);
|
|
4387
4590
|
}
|
|
4388
4591
|
|
|
4592
|
+
/**
|
|
4593
|
+
* Node views are used to customize the rendered DOM structure of a node.
|
|
4594
|
+
* @see https://tiptap.dev/guide/node-views
|
|
4595
|
+
*/
|
|
4389
4596
|
class NodeView {
|
|
4390
4597
|
constructor(component, props, options) {
|
|
4391
4598
|
this.isDragging = false;
|
|
@@ -4576,6 +4783,7 @@ class NodeView {
|
|
|
4576
4783
|
/**
|
|
4577
4784
|
* Build an paste rule that adds a mark when the
|
|
4578
4785
|
* matched text is pasted into it.
|
|
4786
|
+
* @see https://tiptap.dev/guide/custom-extensions/#paste-rules
|
|
4579
4787
|
*/
|
|
4580
4788
|
function markPasteRule(config) {
|
|
4581
4789
|
return new PasteRule({
|
|
@@ -4629,6 +4837,7 @@ function isString(value) {
|
|
|
4629
4837
|
/**
|
|
4630
4838
|
* Build an paste rule that adds a node when the
|
|
4631
4839
|
* matched text is pasted into it.
|
|
4840
|
+
* @see https://tiptap.dev/guide/custom-extensions/#paste-rules
|
|
4632
4841
|
*/
|
|
4633
4842
|
function nodePasteRule(config) {
|
|
4634
4843
|
return new PasteRule({
|
|
@@ -4651,6 +4860,7 @@ function nodePasteRule(config) {
|
|
|
4651
4860
|
/**
|
|
4652
4861
|
* Build an paste rule that replaces text when the
|
|
4653
4862
|
* matched text is pasted into it.
|
|
4863
|
+
* @see https://tiptap.dev/guide/custom-extensions/#paste-rules
|
|
4654
4864
|
*/
|
|
4655
4865
|
function textPasteRule(config) {
|
|
4656
4866
|
return new PasteRule({
|