@tiptap/extension-character-count 2.5.0-beta.2 → 2.5.0-beta.4
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 +86 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +85 -85
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +86 -86
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/CommandManager.d.ts +20 -0
- package/dist/packages/core/src/Editor.d.ts +161 -0
- package/dist/packages/core/src/EventEmitter.d.ts +11 -0
- package/dist/packages/core/src/Extension.d.ts +343 -0
- package/dist/packages/core/src/ExtensionManager.d.ts +55 -0
- package/dist/packages/core/src/InputRule.d.ts +42 -0
- package/dist/packages/core/src/Mark.d.ts +451 -0
- package/dist/packages/core/src/Node.d.ts +611 -0
- package/dist/packages/core/src/NodePos.d.ts +44 -0
- package/dist/packages/core/src/NodeView.d.ts +31 -0
- package/dist/packages/core/src/PasteRule.d.ts +50 -0
- package/dist/packages/core/src/Tracker.d.ts +11 -0
- package/dist/packages/core/src/commands/blur.d.ts +13 -0
- package/dist/packages/core/src/commands/clearContent.d.ts +14 -0
- package/dist/packages/core/src/commands/clearNodes.d.ts +13 -0
- package/dist/packages/core/src/commands/command.d.ts +18 -0
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +13 -0
- package/dist/packages/core/src/commands/cut.d.ts +20 -0
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +13 -0
- package/dist/packages/core/src/commands/deleteNode.d.ts +15 -0
- package/dist/packages/core/src/commands/deleteRange.d.ts +14 -0
- package/dist/packages/core/src/commands/deleteSelection.d.ts +13 -0
- package/dist/packages/core/src/commands/enter.d.ts +13 -0
- package/dist/packages/core/src/commands/exitCode.d.ts +13 -0
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +25 -0
- package/dist/packages/core/src/commands/first.d.ts +14 -0
- package/dist/packages/core/src/commands/focus.d.ts +27 -0
- package/dist/packages/core/src/commands/forEach.d.ts +14 -0
- package/dist/packages/core/src/commands/index.d.ts +55 -0
- package/dist/packages/core/src/commands/insertContent.d.ts +34 -0
- package/dist/packages/core/src/commands/insertContentAt.d.ts +47 -0
- package/dist/packages/core/src/commands/join.d.ts +41 -0
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +13 -0
- package/dist/packages/core/src/commands/joinItemForward.d.ts +13 -0
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +12 -0
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +12 -0
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +14 -0
- package/dist/packages/core/src/commands/lift.d.ts +17 -0
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +13 -0
- package/dist/packages/core/src/commands/liftListItem.d.ts +15 -0
- package/dist/packages/core/src/commands/newlineInCode.d.ts +13 -0
- package/dist/packages/core/src/commands/resetAttributes.d.ts +16 -0
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +13 -0
- package/dist/packages/core/src/commands/selectAll.d.ts +13 -0
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +13 -0
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +13 -0
- package/dist/packages/core/src/commands/selectParentNode.d.ts +13 -0
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +13 -0
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +13 -0
- package/dist/packages/core/src/commands/setContent.d.ts +40 -0
- package/dist/packages/core/src/commands/setMark.d.ts +15 -0
- package/dist/packages/core/src/commands/setMeta.d.ts +15 -0
- package/dist/packages/core/src/commands/setNode.d.ts +16 -0
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +14 -0
- package/dist/packages/core/src/commands/setTextSelection.d.ts +14 -0
- package/dist/packages/core/src/commands/sinkListItem.d.ts +15 -0
- package/dist/packages/core/src/commands/splitBlock.d.ts +17 -0
- package/dist/packages/core/src/commands/splitListItem.d.ts +15 -0
- package/dist/packages/core/src/commands/toggleList.d.ts +18 -0
- package/dist/packages/core/src/commands/toggleMark.d.ts +30 -0
- package/dist/packages/core/src/commands/toggleNode.d.ts +17 -0
- package/dist/packages/core/src/commands/toggleWrap.d.ts +16 -0
- package/dist/packages/core/src/commands/undoInputRule.d.ts +13 -0
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +13 -0
- package/dist/packages/core/src/commands/unsetMark.d.ts +25 -0
- package/dist/packages/core/src/commands/updateAttributes.d.ts +24 -0
- package/dist/packages/core/src/commands/wrapIn.d.ts +16 -0
- package/dist/packages/core/src/commands/wrapInList.d.ts +16 -0
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +5 -0
- package/dist/packages/core/src/extensions/commands.d.ts +3 -0
- package/dist/packages/core/src/extensions/editable.d.ts +2 -0
- package/dist/packages/core/src/extensions/focusEvents.d.ts +2 -0
- package/dist/packages/core/src/extensions/index.d.ts +6 -0
- package/dist/packages/core/src/extensions/keymap.d.ts +2 -0
- package/dist/packages/core/src/extensions/tabindex.d.ts +2 -0
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +10 -0
- package/dist/packages/core/src/helpers/createChainableState.d.ts +10 -0
- package/dist/packages/core/src/helpers/createDocument.d.ts +12 -0
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +15 -0
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +7 -0
- package/dist/packages/core/src/helpers/findChildren.d.ts +9 -0
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +10 -0
- package/dist/packages/core/src/helpers/findParentNode.d.ts +16 -0
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +17 -0
- package/dist/packages/core/src/helpers/generateHTML.d.ts +8 -0
- package/dist/packages/core/src/helpers/generateJSON.d.ts +8 -0
- package/dist/packages/core/src/helpers/generateText.d.ts +12 -0
- package/dist/packages/core/src/helpers/getAttributes.d.ts +9 -0
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +6 -0
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +8 -0
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +9 -0
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -0
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +3 -0
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +3 -0
- package/dist/packages/core/src/helpers/getMarkType.d.ts +2 -0
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +3 -0
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +11 -0
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +3 -0
- package/dist/packages/core/src/helpers/getNodeType.d.ts +2 -0
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +3 -0
- package/dist/packages/core/src/helpers/getSchema.d.ts +4 -0
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +10 -0
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +8 -0
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +8 -0
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +9 -0
- package/dist/packages/core/src/helpers/getText.d.ts +15 -0
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +14 -0
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +8 -0
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +8 -0
- package/dist/packages/core/src/helpers/index.d.ts +50 -0
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +9 -0
- package/dist/packages/core/src/helpers/isActive.d.ts +2 -0
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +2 -0
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +2 -0
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
- package/dist/packages/core/src/helpers/isList.d.ts +2 -0
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +3 -0
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +3 -0
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +2 -0
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +2 -0
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +2 -0
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -0
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +2 -0
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +9 -0
- package/dist/packages/core/src/index.d.ts +24 -0
- package/dist/packages/core/src/inputRules/index.d.ts +5 -0
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +13 -0
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +23 -0
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +10 -0
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +15 -0
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +28 -0
- package/dist/packages/core/src/pasteRules/index.d.ts +3 -0
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +13 -0
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +13 -0
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +10 -0
- package/dist/packages/core/src/style.d.ts +1 -0
- package/dist/packages/core/src/types.d.ts +250 -0
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +9 -0
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -0
- package/dist/packages/core/src/utilities/deleteProps.d.ts +6 -0
- package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -0
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -0
- package/dist/packages/core/src/utilities/fromString.d.ts +1 -0
- package/dist/packages/core/src/utilities/index.d.ts +20 -0
- package/dist/packages/core/src/utilities/isAndroid.d.ts +1 -0
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -0
- package/dist/packages/core/src/utilities/isFunction.d.ts +1 -0
- package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -0
- package/dist/packages/core/src/utilities/isNumber.d.ts +1 -0
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -0
- package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
- package/dist/packages/core/src/utilities/isString.d.ts +1 -0
- package/dist/packages/core/src/utilities/isiOS.d.ts +1 -0
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -0
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -0
- package/dist/packages/core/src/utilities/minMax.d.ts +1 -0
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +8 -0
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
- package/dist/packages/extension-character-count/src/character-count.d.ts +42 -42
- package/dist/packages/extension-character-count/src/index.d.ts +3 -3
- package/package.json +3 -3
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/character-count.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport interface CharacterCountOptions {\n /**\n * The maximum number of characters that should be allowed. Defaults to `0`.\n * @default null\n * @example 180\n */\n limit: number | null | undefined\n /**\n * The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n * If set to `nodeSize`, the nodeSize of the document is used.\n * @default 'textSize'\n * @example 'textSize'\n */\n mode: 'textSize' | 'nodeSize'\n}\n\nexport interface CharacterCountStorage {\n /**\n * Get the number of characters for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the characters from. Defaults to the current document.\n * @param options.mode The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n */\n characters: (options?: { node?: ProseMirrorNode; mode?: 'textSize' | 'nodeSize' }) => number\n\n /**\n * Get the number of words for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the words from. Defaults to the current document.\n */\n words: (options?: { node?: ProseMirrorNode }) => number\n}\n\n/**\n * This extension allows you to count the characters and words of your document.\n * @see https://tiptap.dev/api/extensions/character-count\n */\nexport const CharacterCount = Extension.create<CharacterCountOptions, CharacterCountStorage>({\n name: 'characterCount',\n\n addOptions() {\n return {\n limit: null,\n mode: 'textSize',\n }\n },\n\n addStorage() {\n return {\n characters: () => 0,\n words: () => 0,\n }\n },\n\n onBeforeCreate() {\n this.storage.characters = options => {\n const node = options?.node || this.editor.state.doc\n const mode = options?.mode || this.options.mode\n\n if (mode === 'textSize') {\n const text = node.textBetween(0, node.content.size, undefined, ' ')\n\n return text.length\n }\n\n return node.nodeSize\n }\n\n this.storage.words = options => {\n const node = options?.node || this.editor.state.doc\n const text = node.textBetween(0, node.content.size, ' ', ' ')\n const words = text.split(' ').filter(word => word !== '')\n\n return words.length\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('characterCount'),\n filterTransaction: (transaction, state) => {\n const limit = this.options.limit\n\n // Nothing has changed or no limit is defined. Ignore it.\n if (!transaction.docChanged || limit === 0 || limit === null || limit === undefined) {\n return true\n }\n\n const oldSize = this.storage.characters({ node: state.doc })\n const newSize = this.storage.characters({ node: transaction.doc })\n\n // Everything is in the limit. Good.\n if (newSize <= limit) {\n return true\n }\n\n // The limit has already been exceeded but will be reduced.\n if (oldSize > limit && newSize > limit && newSize <= oldSize) {\n return true\n }\n\n // The limit has already been exceeded and will be increased further.\n if (oldSize > limit && newSize > limit && newSize > oldSize) {\n return false\n }\n\n const isPaste = transaction.getMeta('paste')\n\n // Block all exceeding transactions that were not pasted.\n if (!isPaste) {\n return false\n }\n\n // For pasted content, we try to remove the exceeding content.\n const pos = transaction.selection.$head.pos\n const over = newSize - limit\n const from = pos - over\n const to = pos\n\n // It’s probably a bad idea to mutate transactions within `filterTransaction`\n // but for now this is working fine.\n transaction.deleteRange(from, to)\n\n // In some situations, the limit will continue to be exceeded after trimming.\n // This happens e.g. when truncating within a complex node (e.g. table)\n // and ProseMirror has to close this node again.\n // If this is the case, we prevent the transaction completely.\n const updatedSize = this.storage.characters({ node: transaction.doc })\n\n if (updatedSize > limit) {\n return false\n }\n\n return true\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","PluginKey"],"mappings":";;;;;;EAqCA;;;EAGG;AACU,QAAA,cAAc,GAAGA,cAAS,CAAC,MAAM,CAA+C;EAC3F,IAAA,IAAI,EAAE,gBAAgB;MAEtB,UAAU,GAAA;UACR,OAAO;EACL,YAAA,KAAK,EAAE,IAAI;EACX,YAAA,IAAI,EAAE,UAAU;WACjB,CAAA;OACF;MAED,UAAU,GAAA;UACR,OAAO;EACL,YAAA,UAAU,EAAE,MAAM,CAAC;EACnB,YAAA,KAAK,EAAE,MAAM,CAAC;WACf,CAAA;OACF;MAED,cAAc,GAAA;EACZ,QAAA,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,OAAO,IAAG;EAClC,YAAA,MAAM,IAAI,GAAG,CAAA,OAAO,KAAP,IAAA,IAAA,OAAO,uBAAP,OAAO,CAAE,IAAI,KAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAA;EACnD,YAAA,MAAM,IAAI,GAAG,CAAA,OAAO,KAAA,IAAA,IAAP,OAAO,KAAP,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,OAAO,CAAE,IAAI,KAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/character-count.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport interface CharacterCountOptions {\n /**\n * The maximum number of characters that should be allowed. Defaults to `0`.\n * @default null\n * @example 180\n */\n limit: number | null | undefined\n /**\n * The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n * If set to `nodeSize`, the nodeSize of the document is used.\n * @default 'textSize'\n * @example 'textSize'\n */\n mode: 'textSize' | 'nodeSize'\n}\n\nexport interface CharacterCountStorage {\n /**\n * Get the number of characters for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the characters from. Defaults to the current document.\n * @param options.mode The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n */\n characters: (options?: { node?: ProseMirrorNode; mode?: 'textSize' | 'nodeSize' }) => number\n\n /**\n * Get the number of words for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the words from. Defaults to the current document.\n */\n words: (options?: { node?: ProseMirrorNode }) => number\n}\n\n/**\n * This extension allows you to count the characters and words of your document.\n * @see https://tiptap.dev/api/extensions/character-count\n */\nexport const CharacterCount = Extension.create<CharacterCountOptions, CharacterCountStorage>({\n name: 'characterCount',\n\n addOptions() {\n return {\n limit: null,\n mode: 'textSize',\n }\n },\n\n addStorage() {\n return {\n characters: () => 0,\n words: () => 0,\n }\n },\n\n onBeforeCreate() {\n this.storage.characters = options => {\n const node = options?.node || this.editor.state.doc\n const mode = options?.mode || this.options.mode\n\n if (mode === 'textSize') {\n const text = node.textBetween(0, node.content.size, undefined, ' ')\n\n return text.length\n }\n\n return node.nodeSize\n }\n\n this.storage.words = options => {\n const node = options?.node || this.editor.state.doc\n const text = node.textBetween(0, node.content.size, ' ', ' ')\n const words = text.split(' ').filter(word => word !== '')\n\n return words.length\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('characterCount'),\n filterTransaction: (transaction, state) => {\n const limit = this.options.limit\n\n // Nothing has changed or no limit is defined. Ignore it.\n if (!transaction.docChanged || limit === 0 || limit === null || limit === undefined) {\n return true\n }\n\n const oldSize = this.storage.characters({ node: state.doc })\n const newSize = this.storage.characters({ node: transaction.doc })\n\n // Everything is in the limit. Good.\n if (newSize <= limit) {\n return true\n }\n\n // The limit has already been exceeded but will be reduced.\n if (oldSize > limit && newSize > limit && newSize <= oldSize) {\n return true\n }\n\n // The limit has already been exceeded and will be increased further.\n if (oldSize > limit && newSize > limit && newSize > oldSize) {\n return false\n }\n\n const isPaste = transaction.getMeta('paste')\n\n // Block all exceeding transactions that were not pasted.\n if (!isPaste) {\n return false\n }\n\n // For pasted content, we try to remove the exceeding content.\n const pos = transaction.selection.$head.pos\n const over = newSize - limit\n const from = pos - over\n const to = pos\n\n // It’s probably a bad idea to mutate transactions within `filterTransaction`\n // but for now this is working fine.\n transaction.deleteRange(from, to)\n\n // In some situations, the limit will continue to be exceeded after trimming.\n // This happens e.g. when truncating within a complex node (e.g. table)\n // and ProseMirror has to close this node again.\n // If this is the case, we prevent the transaction completely.\n const updatedSize = this.storage.characters({ node: transaction.doc })\n\n if (updatedSize > limit) {\n return false\n }\n\n return true\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","PluginKey"],"mappings":"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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
declare global {
|
|
10
|
+
interface HTMLElement {
|
|
11
|
+
editor?: Editor;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare class Editor extends EventEmitter<EditorEvents> {
|
|
15
|
+
private commandManager;
|
|
16
|
+
extensionManager: ExtensionManager;
|
|
17
|
+
private css;
|
|
18
|
+
schema: Schema;
|
|
19
|
+
view: EditorView;
|
|
20
|
+
isFocused: boolean;
|
|
21
|
+
extensionStorage: Record<string, any>;
|
|
22
|
+
options: EditorOptions;
|
|
23
|
+
constructor(options?: Partial<EditorOptions>);
|
|
24
|
+
/**
|
|
25
|
+
* Returns the editor storage.
|
|
26
|
+
*/
|
|
27
|
+
get storage(): Record<string, any>;
|
|
28
|
+
/**
|
|
29
|
+
* An object of all registered commands.
|
|
30
|
+
*/
|
|
31
|
+
get commands(): SingleCommands;
|
|
32
|
+
/**
|
|
33
|
+
* Create a command chain to call multiple commands at once.
|
|
34
|
+
*/
|
|
35
|
+
chain(): ChainedCommands;
|
|
36
|
+
/**
|
|
37
|
+
* Check if a command or a command chain can be executed. Without executing it.
|
|
38
|
+
*/
|
|
39
|
+
can(): CanCommands;
|
|
40
|
+
/**
|
|
41
|
+
* Inject CSS styles.
|
|
42
|
+
*/
|
|
43
|
+
private injectCSS;
|
|
44
|
+
/**
|
|
45
|
+
* Update editor options.
|
|
46
|
+
*
|
|
47
|
+
* @param options A list of options
|
|
48
|
+
*/
|
|
49
|
+
setOptions(options?: Partial<EditorOptions>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Update editable state of the editor.
|
|
52
|
+
*/
|
|
53
|
+
setEditable(editable: boolean, emitUpdate?: boolean): void;
|
|
54
|
+
/**
|
|
55
|
+
* Returns whether the editor is editable.
|
|
56
|
+
*/
|
|
57
|
+
get isEditable(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the editor state.
|
|
60
|
+
*/
|
|
61
|
+
get state(): EditorState;
|
|
62
|
+
/**
|
|
63
|
+
* Register a ProseMirror plugin.
|
|
64
|
+
*
|
|
65
|
+
* @param plugin A ProseMirror plugin
|
|
66
|
+
* @param handlePlugins Control how to merge the plugin into the existing plugins.
|
|
67
|
+
*/
|
|
68
|
+
registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void;
|
|
69
|
+
/**
|
|
70
|
+
* Unregister a ProseMirror plugin.
|
|
71
|
+
*
|
|
72
|
+
* @param nameOrPluginKey The plugins name
|
|
73
|
+
*/
|
|
74
|
+
unregisterPlugin(nameOrPluginKey: string | PluginKey): void;
|
|
75
|
+
/**
|
|
76
|
+
* Creates an extension manager.
|
|
77
|
+
*/
|
|
78
|
+
private createExtensionManager;
|
|
79
|
+
/**
|
|
80
|
+
* Creates an command manager.
|
|
81
|
+
*/
|
|
82
|
+
private createCommandManager;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a ProseMirror schema.
|
|
85
|
+
*/
|
|
86
|
+
private createSchema;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a ProseMirror view.
|
|
89
|
+
*/
|
|
90
|
+
private createView;
|
|
91
|
+
/**
|
|
92
|
+
* Creates all node views.
|
|
93
|
+
*/
|
|
94
|
+
createNodeViews(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Prepend class name to element.
|
|
97
|
+
*/
|
|
98
|
+
prependClass(): void;
|
|
99
|
+
isCapturingTransaction: boolean;
|
|
100
|
+
private capturedTransaction;
|
|
101
|
+
captureTransaction(fn: Function): Transaction | null;
|
|
102
|
+
/**
|
|
103
|
+
* The callback over which to send transactions (state updates) produced by the view.
|
|
104
|
+
*
|
|
105
|
+
* @param transaction An editor state transaction
|
|
106
|
+
*/
|
|
107
|
+
private dispatchTransaction;
|
|
108
|
+
/**
|
|
109
|
+
* Get attributes of the currently selected node or mark.
|
|
110
|
+
*/
|
|
111
|
+
getAttributes(nameOrType: string | NodeType | MarkType): Record<string, any>;
|
|
112
|
+
/**
|
|
113
|
+
* Returns if the currently selected node or mark is active.
|
|
114
|
+
*
|
|
115
|
+
* @param name Name of the node or mark
|
|
116
|
+
* @param attributes Attributes of the node or mark
|
|
117
|
+
*/
|
|
118
|
+
isActive(name: string, attributes?: {}): boolean;
|
|
119
|
+
isActive(attributes: {}): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Get the document as JSON.
|
|
122
|
+
*/
|
|
123
|
+
getJSON(): JSONContent;
|
|
124
|
+
/**
|
|
125
|
+
* Get the document as HTML.
|
|
126
|
+
*/
|
|
127
|
+
getHTML(): string;
|
|
128
|
+
/**
|
|
129
|
+
* Get the document as text.
|
|
130
|
+
*/
|
|
131
|
+
getText(options?: {
|
|
132
|
+
blockSeparator?: string;
|
|
133
|
+
textSerializers?: Record<string, TextSerializer>;
|
|
134
|
+
}): string;
|
|
135
|
+
/**
|
|
136
|
+
* Check if there is no content.
|
|
137
|
+
*/
|
|
138
|
+
get isEmpty(): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Get the number of characters for the current document.
|
|
141
|
+
*
|
|
142
|
+
* @deprecated
|
|
143
|
+
*/
|
|
144
|
+
getCharacterCount(): number;
|
|
145
|
+
/**
|
|
146
|
+
* Destroy the editor.
|
|
147
|
+
*/
|
|
148
|
+
destroy(): void;
|
|
149
|
+
/**
|
|
150
|
+
* Check if the editor is already destroyed.
|
|
151
|
+
*/
|
|
152
|
+
get isDestroyed(): boolean;
|
|
153
|
+
$node(selector: string, attributes?: {
|
|
154
|
+
[key: string]: any;
|
|
155
|
+
}): NodePos | null;
|
|
156
|
+
$nodes(selector: string, attributes?: {
|
|
157
|
+
[key: string]: any;
|
|
158
|
+
}): NodePos[] | null;
|
|
159
|
+
$pos(pos: number): NodePos;
|
|
160
|
+
get $doc(): NodePos;
|
|
161
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { Plugin, Transaction } from '@tiptap/pm/state';
|
|
2
|
+
import { Editor } from './Editor.js';
|
|
3
|
+
import { ExtensionConfig } from './index.js';
|
|
4
|
+
import { InputRule } from './InputRule.js';
|
|
5
|
+
import { Mark } from './Mark.js';
|
|
6
|
+
import { Node } from './Node.js';
|
|
7
|
+
import { PasteRule } from './PasteRule.js';
|
|
8
|
+
import { Extensions, GlobalAttributes, KeyboardShortcutCommand, ParentConfig, RawCommands } from './types.js';
|
|
9
|
+
declare module '@tiptap/core' {
|
|
10
|
+
interface ExtensionConfig<Options = any, Storage = any> {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
/**
|
|
13
|
+
* The extension name - this must be unique.
|
|
14
|
+
* It will be used to identify the extension.
|
|
15
|
+
*
|
|
16
|
+
* @example 'myExtension'
|
|
17
|
+
*/
|
|
18
|
+
name: string;
|
|
19
|
+
/**
|
|
20
|
+
* The priority of your extension. The higher, the later it will be called
|
|
21
|
+
* and will take precedence over other extensions with a lower priority.
|
|
22
|
+
* @default 1000
|
|
23
|
+
* @example 1001
|
|
24
|
+
*/
|
|
25
|
+
priority?: number;
|
|
26
|
+
/**
|
|
27
|
+
* The default options for this extension.
|
|
28
|
+
* @example
|
|
29
|
+
* defaultOptions: {
|
|
30
|
+
* myOption: 'foo',
|
|
31
|
+
* myOtherOption: 10,
|
|
32
|
+
* }
|
|
33
|
+
*/
|
|
34
|
+
defaultOptions?: Options;
|
|
35
|
+
/**
|
|
36
|
+
* This method will add options to this extension
|
|
37
|
+
* @see https://tiptap.dev/guide/custom-extensions#settings
|
|
38
|
+
* @example
|
|
39
|
+
* addOptions() {
|
|
40
|
+
* return {
|
|
41
|
+
* myOption: 'foo',
|
|
42
|
+
* myOtherOption: 10,
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
addOptions?: (this: {
|
|
46
|
+
name: string;
|
|
47
|
+
parent: Exclude<ParentConfig<ExtensionConfig<Options, Storage>>['addOptions'], undefined>;
|
|
48
|
+
}) => Options;
|
|
49
|
+
/**
|
|
50
|
+
* The default storage this extension can save data to.
|
|
51
|
+
* @see https://tiptap.dev/guide/custom-extensions#storage
|
|
52
|
+
* @example
|
|
53
|
+
* defaultStorage: {
|
|
54
|
+
* prefetchedUsers: [],
|
|
55
|
+
* loading: false,
|
|
56
|
+
* }
|
|
57
|
+
*/
|
|
58
|
+
addStorage?: (this: {
|
|
59
|
+
name: string;
|
|
60
|
+
options: Options;
|
|
61
|
+
parent: Exclude<ParentConfig<ExtensionConfig<Options, Storage>>['addStorage'], undefined>;
|
|
62
|
+
}) => Storage;
|
|
63
|
+
/**
|
|
64
|
+
* This function adds globalAttributes to specific nodes.
|
|
65
|
+
* @see https://tiptap.dev/guide/custom-extensions#global-attributes
|
|
66
|
+
* @example
|
|
67
|
+
* addGlobalAttributes() {
|
|
68
|
+
* return [
|
|
69
|
+
* {
|
|
70
|
+
// Extend the following extensions
|
|
71
|
+
* types: [
|
|
72
|
+
* 'heading',
|
|
73
|
+
* 'paragraph',
|
|
74
|
+
* ],
|
|
75
|
+
* // … with those attributes
|
|
76
|
+
* attributes: {
|
|
77
|
+
* textAlign: {
|
|
78
|
+
* default: 'left',
|
|
79
|
+
* renderHTML: attributes => ({
|
|
80
|
+
* style: `text-align: ${attributes.textAlign}`,
|
|
81
|
+
* }),
|
|
82
|
+
* parseHTML: element => element.style.textAlign || 'left',
|
|
83
|
+
* },
|
|
84
|
+
* },
|
|
85
|
+
* },
|
|
86
|
+
* ]
|
|
87
|
+
* }
|
|
88
|
+
*/
|
|
89
|
+
addGlobalAttributes?: (this: {
|
|
90
|
+
name: string;
|
|
91
|
+
options: Options;
|
|
92
|
+
storage: Storage;
|
|
93
|
+
extensions: (Node | Mark)[];
|
|
94
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addGlobalAttributes'];
|
|
95
|
+
}) => GlobalAttributes;
|
|
96
|
+
/**
|
|
97
|
+
* This function adds commands to the editor
|
|
98
|
+
* @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
|
|
99
|
+
* @example
|
|
100
|
+
* addCommands() {
|
|
101
|
+
* return {
|
|
102
|
+
* myCommand: () => ({ chain }) => chain().setMark('type', 'foo').run(),
|
|
103
|
+
* }
|
|
104
|
+
* }
|
|
105
|
+
*/
|
|
106
|
+
addCommands?: (this: {
|
|
107
|
+
name: string;
|
|
108
|
+
options: Options;
|
|
109
|
+
storage: Storage;
|
|
110
|
+
editor: Editor;
|
|
111
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addCommands'];
|
|
112
|
+
}) => Partial<RawCommands>;
|
|
113
|
+
/**
|
|
114
|
+
* This function registers keyboard shortcuts.
|
|
115
|
+
* @see https://tiptap.dev/guide/custom-extensions#keyboard-shortcuts
|
|
116
|
+
* @example
|
|
117
|
+
* addKeyboardShortcuts() {
|
|
118
|
+
* return {
|
|
119
|
+
* 'Mod-l': () => this.editor.commands.toggleBulletList(),
|
|
120
|
+
* }
|
|
121
|
+
* },
|
|
122
|
+
*/
|
|
123
|
+
addKeyboardShortcuts?: (this: {
|
|
124
|
+
name: string;
|
|
125
|
+
options: Options;
|
|
126
|
+
storage: Storage;
|
|
127
|
+
editor: Editor;
|
|
128
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addKeyboardShortcuts'];
|
|
129
|
+
}) => {
|
|
130
|
+
[key: string]: KeyboardShortcutCommand;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* This function adds input rules to the editor.
|
|
134
|
+
* @see https://tiptap.dev/guide/custom-extensions#input-rules
|
|
135
|
+
* @example
|
|
136
|
+
* addInputRules() {
|
|
137
|
+
* return [
|
|
138
|
+
* markInputRule({
|
|
139
|
+
* find: inputRegex,
|
|
140
|
+
* type: this.type,
|
|
141
|
+
* }),
|
|
142
|
+
* ]
|
|
143
|
+
* },
|
|
144
|
+
*/
|
|
145
|
+
addInputRules?: (this: {
|
|
146
|
+
name: string;
|
|
147
|
+
options: Options;
|
|
148
|
+
storage: Storage;
|
|
149
|
+
editor: Editor;
|
|
150
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addInputRules'];
|
|
151
|
+
}) => InputRule[];
|
|
152
|
+
/**
|
|
153
|
+
* This function adds paste rules to the editor.
|
|
154
|
+
* @see https://tiptap.dev/guide/custom-extensions#paste-rules
|
|
155
|
+
* @example
|
|
156
|
+
* addPasteRules() {
|
|
157
|
+
* return [
|
|
158
|
+
* markPasteRule({
|
|
159
|
+
* find: pasteRegex,
|
|
160
|
+
* type: this.type,
|
|
161
|
+
* }),
|
|
162
|
+
* ]
|
|
163
|
+
* },
|
|
164
|
+
*/
|
|
165
|
+
addPasteRules?: (this: {
|
|
166
|
+
name: string;
|
|
167
|
+
options: Options;
|
|
168
|
+
storage: Storage;
|
|
169
|
+
editor: Editor;
|
|
170
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addPasteRules'];
|
|
171
|
+
}) => PasteRule[];
|
|
172
|
+
/**
|
|
173
|
+
* This function adds Prosemirror plugins to the editor
|
|
174
|
+
* @see https://tiptap.dev/guide/custom-extensions#prosemirror-plugins
|
|
175
|
+
* @example
|
|
176
|
+
* addProseMirrorPlugins() {
|
|
177
|
+
* return [
|
|
178
|
+
* customPlugin(),
|
|
179
|
+
* ]
|
|
180
|
+
* }
|
|
181
|
+
*/
|
|
182
|
+
addProseMirrorPlugins?: (this: {
|
|
183
|
+
name: string;
|
|
184
|
+
options: Options;
|
|
185
|
+
storage: Storage;
|
|
186
|
+
editor: Editor;
|
|
187
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addProseMirrorPlugins'];
|
|
188
|
+
}) => Plugin[];
|
|
189
|
+
/**
|
|
190
|
+
* This function adds additional extensions to the editor. This is useful for
|
|
191
|
+
* building extension kits.
|
|
192
|
+
* @example
|
|
193
|
+
* addExtensions() {
|
|
194
|
+
* return [
|
|
195
|
+
* BulletList,
|
|
196
|
+
* OrderedList,
|
|
197
|
+
* ListItem
|
|
198
|
+
* ]
|
|
199
|
+
* }
|
|
200
|
+
*/
|
|
201
|
+
addExtensions?: (this: {
|
|
202
|
+
name: string;
|
|
203
|
+
options: Options;
|
|
204
|
+
storage: Storage;
|
|
205
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['addExtensions'];
|
|
206
|
+
}) => Extensions;
|
|
207
|
+
/**
|
|
208
|
+
* This function extends the schema of the node.
|
|
209
|
+
* @example
|
|
210
|
+
* extendNodeSchema() {
|
|
211
|
+
* return {
|
|
212
|
+
* group: 'inline',
|
|
213
|
+
* selectable: false,
|
|
214
|
+
* }
|
|
215
|
+
* }
|
|
216
|
+
*/
|
|
217
|
+
extendNodeSchema?: ((this: {
|
|
218
|
+
name: string;
|
|
219
|
+
options: Options;
|
|
220
|
+
storage: Storage;
|
|
221
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['extendNodeSchema'];
|
|
222
|
+
}, extension: Node) => Record<string, any>) | null;
|
|
223
|
+
/**
|
|
224
|
+
* This function extends the schema of the mark.
|
|
225
|
+
* @example
|
|
226
|
+
* extendMarkSchema() {
|
|
227
|
+
* return {
|
|
228
|
+
* group: 'inline',
|
|
229
|
+
* selectable: false,
|
|
230
|
+
* }
|
|
231
|
+
* }
|
|
232
|
+
*/
|
|
233
|
+
extendMarkSchema?: ((this: {
|
|
234
|
+
name: string;
|
|
235
|
+
options: Options;
|
|
236
|
+
storage: Storage;
|
|
237
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['extendMarkSchema'];
|
|
238
|
+
}, extension: Mark) => Record<string, any>) | null;
|
|
239
|
+
/**
|
|
240
|
+
* The editor is not ready yet.
|
|
241
|
+
*/
|
|
242
|
+
onBeforeCreate?: ((this: {
|
|
243
|
+
name: string;
|
|
244
|
+
options: Options;
|
|
245
|
+
storage: Storage;
|
|
246
|
+
editor: Editor;
|
|
247
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onBeforeCreate'];
|
|
248
|
+
}) => void) | null;
|
|
249
|
+
/**
|
|
250
|
+
* The editor is ready.
|
|
251
|
+
*/
|
|
252
|
+
onCreate?: ((this: {
|
|
253
|
+
name: string;
|
|
254
|
+
options: Options;
|
|
255
|
+
storage: Storage;
|
|
256
|
+
editor: Editor;
|
|
257
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onCreate'];
|
|
258
|
+
}) => void) | null;
|
|
259
|
+
/**
|
|
260
|
+
* The content has changed.
|
|
261
|
+
*/
|
|
262
|
+
onUpdate?: ((this: {
|
|
263
|
+
name: string;
|
|
264
|
+
options: Options;
|
|
265
|
+
storage: Storage;
|
|
266
|
+
editor: Editor;
|
|
267
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onUpdate'];
|
|
268
|
+
}) => void) | null;
|
|
269
|
+
/**
|
|
270
|
+
* The selection has changed.
|
|
271
|
+
*/
|
|
272
|
+
onSelectionUpdate?: ((this: {
|
|
273
|
+
name: string;
|
|
274
|
+
options: Options;
|
|
275
|
+
storage: Storage;
|
|
276
|
+
editor: Editor;
|
|
277
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onSelectionUpdate'];
|
|
278
|
+
}) => void) | null;
|
|
279
|
+
/**
|
|
280
|
+
* The editor state has changed.
|
|
281
|
+
*/
|
|
282
|
+
onTransaction?: ((this: {
|
|
283
|
+
name: string;
|
|
284
|
+
options: Options;
|
|
285
|
+
storage: Storage;
|
|
286
|
+
editor: Editor;
|
|
287
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onTransaction'];
|
|
288
|
+
}, props: {
|
|
289
|
+
transaction: Transaction;
|
|
290
|
+
}) => void) | null;
|
|
291
|
+
/**
|
|
292
|
+
* The editor is focused.
|
|
293
|
+
*/
|
|
294
|
+
onFocus?: ((this: {
|
|
295
|
+
name: string;
|
|
296
|
+
options: Options;
|
|
297
|
+
storage: Storage;
|
|
298
|
+
editor: Editor;
|
|
299
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onFocus'];
|
|
300
|
+
}, props: {
|
|
301
|
+
event: FocusEvent;
|
|
302
|
+
}) => void) | null;
|
|
303
|
+
/**
|
|
304
|
+
* The editor isn’t focused anymore.
|
|
305
|
+
*/
|
|
306
|
+
onBlur?: ((this: {
|
|
307
|
+
name: string;
|
|
308
|
+
options: Options;
|
|
309
|
+
storage: Storage;
|
|
310
|
+
editor: Editor;
|
|
311
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onBlur'];
|
|
312
|
+
}, props: {
|
|
313
|
+
event: FocusEvent;
|
|
314
|
+
}) => void) | null;
|
|
315
|
+
/**
|
|
316
|
+
* The editor is destroyed.
|
|
317
|
+
*/
|
|
318
|
+
onDestroy?: ((this: {
|
|
319
|
+
name: string;
|
|
320
|
+
options: Options;
|
|
321
|
+
storage: Storage;
|
|
322
|
+
editor: Editor;
|
|
323
|
+
parent: ParentConfig<ExtensionConfig<Options, Storage>>['onDestroy'];
|
|
324
|
+
}) => void) | null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* The Extension class is the base class for all extensions.
|
|
329
|
+
* @see https://tiptap.dev/api/extensions#create-a-new-extension
|
|
330
|
+
*/
|
|
331
|
+
export declare class Extension<Options = any, Storage = any> {
|
|
332
|
+
type: string;
|
|
333
|
+
name: string;
|
|
334
|
+
parent: Extension | null;
|
|
335
|
+
child: Extension | null;
|
|
336
|
+
options: Options;
|
|
337
|
+
storage: Storage;
|
|
338
|
+
config: ExtensionConfig;
|
|
339
|
+
constructor(config?: Partial<ExtensionConfig<Options, Storage>>);
|
|
340
|
+
static create<O = any, S = any>(config?: Partial<ExtensionConfig<O, S>>): Extension<O, S>;
|
|
341
|
+
configure(options?: Partial<Options>): Extension<any, any>;
|
|
342
|
+
extend<ExtendedOptions = Options, ExtendedStorage = Storage>(extendedConfig?: Partial<ExtensionConfig<ExtendedOptions, ExtendedStorage>>): Extension<ExtendedOptions, ExtendedStorage>;
|
|
343
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Schema } from '@tiptap/pm/model';
|
|
2
|
+
import { Plugin } from '@tiptap/pm/state';
|
|
3
|
+
import type { Editor } from './Editor.js';
|
|
4
|
+
import { Extensions, RawCommands } from './types.js';
|
|
5
|
+
export declare class ExtensionManager {
|
|
6
|
+
editor: Editor;
|
|
7
|
+
schema: Schema;
|
|
8
|
+
extensions: Extensions;
|
|
9
|
+
splittableMarks: string[];
|
|
10
|
+
constructor(extensions: Extensions, editor: Editor);
|
|
11
|
+
/**
|
|
12
|
+
* Returns a flattened and sorted extension list while
|
|
13
|
+
* also checking for duplicated extensions and warns the user.
|
|
14
|
+
* @param extensions An array of Tiptap extensions
|
|
15
|
+
* @returns An flattened and sorted array of Tiptap extensions
|
|
16
|
+
*/
|
|
17
|
+
static resolve(extensions: Extensions): Extensions;
|
|
18
|
+
/**
|
|
19
|
+
* Create a flattened array of extensions by traversing the `addExtensions` field.
|
|
20
|
+
* @param extensions An array of Tiptap extensions
|
|
21
|
+
* @returns A flattened array of Tiptap extensions
|
|
22
|
+
*/
|
|
23
|
+
static flatten(extensions: Extensions): Extensions;
|
|
24
|
+
/**
|
|
25
|
+
* Sort extensions by priority.
|
|
26
|
+
* @param extensions An array of Tiptap extensions
|
|
27
|
+
* @returns A sorted array of Tiptap extensions by priority
|
|
28
|
+
*/
|
|
29
|
+
static sort(extensions: Extensions): Extensions;
|
|
30
|
+
/**
|
|
31
|
+
* Get all commands from the extensions.
|
|
32
|
+
* @returns An object with all commands where the key is the command name and the value is the command function
|
|
33
|
+
*/
|
|
34
|
+
get commands(): RawCommands;
|
|
35
|
+
/**
|
|
36
|
+
* Get all registered Prosemirror plugins from the extensions.
|
|
37
|
+
* @returns An array of Prosemirror plugins
|
|
38
|
+
*/
|
|
39
|
+
get plugins(): Plugin[];
|
|
40
|
+
/**
|
|
41
|
+
* Get all attributes from the extensions.
|
|
42
|
+
* @returns An array of attributes
|
|
43
|
+
*/
|
|
44
|
+
get attributes(): import("@tiptap/core").ExtensionAttribute[];
|
|
45
|
+
/**
|
|
46
|
+
* Get all node views from the extensions.
|
|
47
|
+
* @returns An object with all node views where the key is the node name and the value is the node view function
|
|
48
|
+
*/
|
|
49
|
+
get nodeViews(): any;
|
|
50
|
+
/**
|
|
51
|
+
* Go through all extensions, create extension storages & setup marks
|
|
52
|
+
* & bind editor event listener.
|
|
53
|
+
*/
|
|
54
|
+
private setupExtensions;
|
|
55
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { EditorState, Plugin } from '@tiptap/pm/state';
|
|
2
|
+
import { Editor } from './Editor.js';
|
|
3
|
+
import { CanCommands, ChainedCommands, ExtendedRegExpMatchArray, Range, SingleCommands } from './types.js';
|
|
4
|
+
export type InputRuleMatch = {
|
|
5
|
+
index: number;
|
|
6
|
+
text: string;
|
|
7
|
+
replaceWith?: string;
|
|
8
|
+
match?: RegExpMatchArray;
|
|
9
|
+
data?: Record<string, any>;
|
|
10
|
+
};
|
|
11
|
+
export type InputRuleFinder = RegExp | ((text: string) => InputRuleMatch | null);
|
|
12
|
+
export declare class InputRule {
|
|
13
|
+
find: InputRuleFinder;
|
|
14
|
+
handler: (props: {
|
|
15
|
+
state: EditorState;
|
|
16
|
+
range: Range;
|
|
17
|
+
match: ExtendedRegExpMatchArray;
|
|
18
|
+
commands: SingleCommands;
|
|
19
|
+
chain: () => ChainedCommands;
|
|
20
|
+
can: () => CanCommands;
|
|
21
|
+
}) => void | null;
|
|
22
|
+
constructor(config: {
|
|
23
|
+
find: InputRuleFinder;
|
|
24
|
+
handler: (props: {
|
|
25
|
+
state: EditorState;
|
|
26
|
+
range: Range;
|
|
27
|
+
match: ExtendedRegExpMatchArray;
|
|
28
|
+
commands: SingleCommands;
|
|
29
|
+
chain: () => ChainedCommands;
|
|
30
|
+
can: () => CanCommands;
|
|
31
|
+
}) => void | null;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create an input rules plugin. When enabled, it will cause text
|
|
36
|
+
* input that matches any of the given rules to trigger the rule’s
|
|
37
|
+
* action.
|
|
38
|
+
*/
|
|
39
|
+
export declare function inputRulesPlugin(props: {
|
|
40
|
+
editor: Editor;
|
|
41
|
+
rules: InputRule[];
|
|
42
|
+
}): Plugin;
|