@tiptap/core 2.3.1 → 2.4.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 +290 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +290 -79
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +290 -79
- package/dist/index.umd.js.map +1 -1
- 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/Extension.ts +130 -14
- package/src/ExtensionManager.ts +117 -85
- package/src/Mark.ts +129 -14
- package/src/Node.ts +226 -30
- package/src/NodePos.ts +19 -18
- 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 +2 -1
- 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 +1 -0
- 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
|
@@ -2,6 +2,12 @@ import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
|
2
2
|
|
|
3
3
|
import { NodeWithPos, Predicate } from '../types.js'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Find children inside a Prosemirror node that match a predicate.
|
|
7
|
+
* @param node The Prosemirror node to search in
|
|
8
|
+
* @param predicate The predicate to match
|
|
9
|
+
* @returns An array of nodes with their positions
|
|
10
|
+
*/
|
|
5
11
|
export function findChildren(node: ProseMirrorNode, predicate: Predicate): NodeWithPos[] {
|
|
6
12
|
const nodesWithPos: NodeWithPos[] = []
|
|
7
13
|
|
|
@@ -4,6 +4,10 @@ import { NodeWithPos, Predicate, Range } from '../types.js'
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Same as `findChildren` but searches only within a `range`.
|
|
7
|
+
* @param node The Prosemirror node to search in
|
|
8
|
+
* @param range The range to search in
|
|
9
|
+
* @param predicate The predicate to match
|
|
10
|
+
* @returns An array of nodes with their positions
|
|
7
11
|
*/
|
|
8
12
|
export function findChildrenInRange(
|
|
9
13
|
node: ProseMirrorNode,
|
|
@@ -3,6 +3,14 @@ import { Selection } from '@tiptap/pm/state'
|
|
|
3
3
|
import { Predicate } from '../types.js'
|
|
4
4
|
import { findParentNodeClosestToPos } from './findParentNodeClosestToPos.js'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Finds the closest parent node to the current selection that matches a predicate.
|
|
8
|
+
* @param predicate The predicate to match
|
|
9
|
+
* @returns A command that finds the closest parent node to the current selection that matches the predicate
|
|
10
|
+
* @example ```js
|
|
11
|
+
* findParentNode(node => node.type.name === 'paragraph')
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
6
14
|
export function findParentNode(predicate: Predicate) {
|
|
7
15
|
return (selection: Selection) => findParentNodeClosestToPos(selection.$from, predicate)
|
|
8
16
|
}
|
|
@@ -2,6 +2,15 @@ import { Node as ProseMirrorNode, ResolvedPos } from '@tiptap/pm/model'
|
|
|
2
2
|
|
|
3
3
|
import { Predicate } from '../types.js'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Finds the closest parent node to a resolved position that matches a predicate.
|
|
7
|
+
* @param $pos The resolved position to search from
|
|
8
|
+
* @param predicate The predicate to match
|
|
9
|
+
* @returns The closest parent node to the resolved position that matches the predicate
|
|
10
|
+
* @example ```js
|
|
11
|
+
* findParentNodeClosestToPos($from, node => node.type.name === 'paragraph')
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
5
14
|
export function findParentNodeClosestToPos(
|
|
6
15
|
$pos: ResolvedPos,
|
|
7
16
|
predicate: Predicate,
|
|
@@ -4,6 +4,12 @@ import { Extensions, JSONContent } from '../types.js'
|
|
|
4
4
|
import { getHTMLFromFragment } from './getHTMLFromFragment.js'
|
|
5
5
|
import { getSchema } from './getSchema.js'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Generate HTML from a JSONContent
|
|
9
|
+
* @param doc The JSONContent to generate HTML from
|
|
10
|
+
* @param extensions The extensions to use for the schema
|
|
11
|
+
* @returns The generated HTML
|
|
12
|
+
*/
|
|
7
13
|
export function generateHTML(doc: JSONContent, extensions: Extensions): string {
|
|
8
14
|
const schema = getSchema(extensions)
|
|
9
15
|
const contentNode = Node.fromJSON(schema, doc)
|
|
@@ -4,6 +4,12 @@ import { Extensions } from '../types.js'
|
|
|
4
4
|
import { elementFromString } from '../utilities/elementFromString.js'
|
|
5
5
|
import { getSchema } from './getSchema.js'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Generate JSONContent from HTML
|
|
9
|
+
* @param html The HTML to generate JSONContent from
|
|
10
|
+
* @param extensions The extensions to use for the schema
|
|
11
|
+
* @returns The generated JSONContent
|
|
12
|
+
*/
|
|
7
13
|
export function generateJSON(html: string, extensions: Extensions): Record<string, any> {
|
|
8
14
|
const schema = getSchema(extensions)
|
|
9
15
|
const dom = elementFromString(html)
|
|
@@ -5,6 +5,13 @@ import { getSchema } from './getSchema.js'
|
|
|
5
5
|
import { getText } from './getText.js'
|
|
6
6
|
import { getTextSerializersFromSchema } from './getTextSerializersFromSchema.js'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Generate raw text from a JSONContent
|
|
10
|
+
* @param doc The JSONContent to generate text from
|
|
11
|
+
* @param extensions The extensions to use for the schema
|
|
12
|
+
* @param options Options for the text generation f.e. blockSeparator or textSerializers
|
|
13
|
+
* @returns The generated text
|
|
14
|
+
*/
|
|
8
15
|
export function generateText(
|
|
9
16
|
doc: JSONContent,
|
|
10
17
|
extensions: Extensions,
|
|
@@ -5,6 +5,12 @@ import { getMarkAttributes } from './getMarkAttributes.js'
|
|
|
5
5
|
import { getNodeAttributes } from './getNodeAttributes.js'
|
|
6
6
|
import { getSchemaTypeNameByName } from './getSchemaTypeNameByName.js'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Get node or mark attributes by type or name on the current editor state
|
|
10
|
+
* @param state The current editor state
|
|
11
|
+
* @param typeOrName The node or mark type or name
|
|
12
|
+
* @returns The attributes of the node or mark or an empty object
|
|
13
|
+
*/
|
|
8
14
|
export function getAttributes(
|
|
9
15
|
state: EditorState,
|
|
10
16
|
typeOrName: string | NodeType | MarkType,
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { AnyExtension, MaybeThisParameterType, RemoveThis } from '../types.js'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Returns a field from an extension
|
|
5
|
+
* @param extension The Tiptap extension
|
|
6
|
+
* @param field The field, for example `renderHTML` or `priority`
|
|
7
|
+
* @param context The context object that should be passed as `this` into the function
|
|
8
|
+
* @returns The field value
|
|
9
|
+
*/
|
|
3
10
|
export function getExtensionField<T = any>(
|
|
4
11
|
extension: AnyExtension,
|
|
5
12
|
field: string,
|
|
@@ -23,6 +23,12 @@ function cleanUpSchemaItem<T>(data: T) {
|
|
|
23
23
|
) as T
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new Prosemirror schema based on the given extensions.
|
|
28
|
+
* @param extensions An array of Tiptap extensions
|
|
29
|
+
* @param editor The editor instance
|
|
30
|
+
* @returns A Prosemirror schema
|
|
31
|
+
*/
|
|
26
32
|
export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: Editor): Schema {
|
|
27
33
|
const allAttributes = getAttributesFromExtensions(extensions)
|
|
28
34
|
const { nodeExtensions, markExtensions } = splitExtensions(extensions)
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { MarkType, NodeType, Schema } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Tries to get a node or mark type by its name.
|
|
5
|
+
* @param name The name of the node or mark type
|
|
6
|
+
* @param schema The Prosemiror schema to search in
|
|
7
|
+
* @returns The node or mark type, or null if it doesn't exist
|
|
8
|
+
*/
|
|
3
9
|
export function getSchemaTypeByName(name: string, schema: Schema): NodeType | MarkType | null {
|
|
4
10
|
return schema.nodes[name] || schema.marks[name] || null
|
|
5
11
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Schema } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Get the type of a schema item by its name.
|
|
5
|
+
* @param name The name of the schema item
|
|
6
|
+
* @param schema The Prosemiror schema to search in
|
|
7
|
+
* @returns The type of the schema item (`node` or `mark`), or null if it doesn't exist
|
|
8
|
+
*/
|
|
3
9
|
export function getSchemaTypeNameByName(name: string, schema: Schema): 'node' | 'mark' | null {
|
|
4
10
|
if (schema.nodes[name]) {
|
|
5
11
|
return 'node'
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ExtensionAttribute } from '../types.js'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Return attributes of an extension that should be splitted by keepOnSplit flag
|
|
5
|
+
* @param extensionAttributes Array of extension attributes
|
|
6
|
+
* @param typeName The type of the extension
|
|
7
|
+
* @param attributes The attributes of the extension
|
|
8
|
+
* @returns The splitted attributes
|
|
9
|
+
*/
|
|
3
10
|
export function getSplittedAttributes(
|
|
4
11
|
extensionAttributes: ExtensionAttribute[],
|
|
5
12
|
typeName: string,
|
package/src/helpers/getText.ts
CHANGED
|
@@ -3,6 +3,15 @@ import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
|
3
3
|
import { TextSerializer } from '../types.js'
|
|
4
4
|
import { getTextBetween } from './getTextBetween.js'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Gets the text of a Prosemirror node
|
|
8
|
+
* @param node The Prosemirror node
|
|
9
|
+
* @param options Options for the text serializer & block separator
|
|
10
|
+
* @returns The text of the node
|
|
11
|
+
* @example ```js
|
|
12
|
+
* const text = getText(node, { blockSeparator: '\n' })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
6
15
|
export function getText(
|
|
7
16
|
node: ProseMirrorNode,
|
|
8
17
|
options?: {
|
|
@@ -2,6 +2,14 @@ import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
|
2
2
|
|
|
3
3
|
import { Range, TextSerializer } from '../types.js'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Gets the text between two positions in a Prosemirror node
|
|
7
|
+
* and serializes it using the given text serializers and block separator (see getText)
|
|
8
|
+
* @param startNode The Prosemirror node to start from
|
|
9
|
+
* @param range The range of the text to get
|
|
10
|
+
* @param options Options for the text serializer & block separator
|
|
11
|
+
* @returns The text between the two positions
|
|
12
|
+
*/
|
|
5
13
|
export function getTextBetween(
|
|
6
14
|
startNode: ProseMirrorNode,
|
|
7
15
|
range: Range,
|
|
@@ -13,17 +21,15 @@ export function getTextBetween(
|
|
|
13
21
|
const { from, to } = range
|
|
14
22
|
const { blockSeparator = '\n\n', textSerializers = {} } = options || {}
|
|
15
23
|
let text = ''
|
|
16
|
-
let separated = true
|
|
17
24
|
|
|
18
25
|
startNode.nodesBetween(from, to, (node, pos, parent, index) => {
|
|
26
|
+
if (node.isBlock && pos > from) {
|
|
27
|
+
text += blockSeparator
|
|
28
|
+
}
|
|
29
|
+
|
|
19
30
|
const textSerializer = textSerializers?.[node.type.name]
|
|
20
31
|
|
|
21
32
|
if (textSerializer) {
|
|
22
|
-
if (node.isBlock && !separated) {
|
|
23
|
-
text += blockSeparator
|
|
24
|
-
separated = true
|
|
25
|
-
}
|
|
26
|
-
|
|
27
33
|
if (parent) {
|
|
28
34
|
text += textSerializer({
|
|
29
35
|
node,
|
|
@@ -39,10 +45,6 @@ export function getTextBetween(
|
|
|
39
45
|
|
|
40
46
|
if (node.isText) {
|
|
41
47
|
text += node?.text?.slice(Math.max(from, pos) - pos, to - pos) // eslint-disable-line
|
|
42
|
-
separated = false
|
|
43
|
-
} else if (node.isBlock && !separated) {
|
|
44
|
-
text += blockSeparator
|
|
45
|
-
separated = true
|
|
46
48
|
}
|
|
47
49
|
})
|
|
48
50
|
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { ResolvedPos } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Returns the text content of a resolved prosemirror position
|
|
5
|
+
* @param $from The resolved position to get the text content from
|
|
6
|
+
* @param maxMatch The maximum number of characters to match
|
|
7
|
+
* @returns The text content
|
|
8
|
+
*/
|
|
3
9
|
export const getTextContentFromNodes = ($from: ResolvedPos, maxMatch = 500) => {
|
|
4
10
|
let textBefore = ''
|
|
5
11
|
|
|
@@ -2,6 +2,11 @@ import { Schema } from '@tiptap/pm/model'
|
|
|
2
2
|
|
|
3
3
|
import { TextSerializer } from '../types.js'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Find text serializers `toText` in a Prosemirror schema
|
|
7
|
+
* @param schema The Prosemirror schema to search in
|
|
8
|
+
* @returns A record of text serializers by node name
|
|
9
|
+
*/
|
|
5
10
|
export function getTextSerializersFromSchema(schema: Schema): Record<string, TextSerializer> {
|
|
6
11
|
return Object.fromEntries(
|
|
7
12
|
Object.entries(schema.nodes)
|
|
@@ -8,6 +8,7 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
|
8
8
|
/**
|
|
9
9
|
* Build an input rule that adds a mark when the
|
|
10
10
|
* matched text is typed into it.
|
|
11
|
+
* @see https://tiptap.dev/guide/custom-extensions/#input-rules
|
|
11
12
|
*/
|
|
12
13
|
export function markInputRule(config: {
|
|
13
14
|
find: InputRuleFinder
|
|
@@ -7,6 +7,7 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
|
7
7
|
/**
|
|
8
8
|
* Build an input rule that adds a node when the
|
|
9
9
|
* matched text is typed into it.
|
|
10
|
+
* @see https://tiptap.dev/guide/custom-extensions/#input-rules
|
|
10
11
|
*/
|
|
11
12
|
export function nodeInputRule(config: {
|
|
12
13
|
/**
|
|
@@ -3,6 +3,7 @@ import { InputRule, InputRuleFinder } from '../InputRule.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Build an input rule that replaces text when the
|
|
5
5
|
* matched text is typed into it.
|
|
6
|
+
* @see https://tiptap.dev/guide/custom-extensions/#input-rules
|
|
6
7
|
*/
|
|
7
8
|
export function textInputRule(config: {
|
|
8
9
|
find: InputRuleFinder,
|
|
@@ -9,6 +9,7 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
|
9
9
|
* matched text is typed into it. When using a regular expresion you’ll
|
|
10
10
|
* probably want the regexp to start with `^`, so that the pattern can
|
|
11
11
|
* only occur at the start of a textblock.
|
|
12
|
+
* @see https://tiptap.dev/guide/custom-extensions/#input-rules
|
|
12
13
|
*/
|
|
13
14
|
export function textblockTypeInputRule(config: {
|
|
14
15
|
find: InputRuleFinder
|
|
@@ -19,6 +19,7 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
|
19
19
|
* two nodes. You can pass a join predicate, which takes a regular
|
|
20
20
|
* expression match and the node before the wrapped node, and can
|
|
21
21
|
* return a boolean to indicate whether a join should happen.
|
|
22
|
+
* @see https://tiptap.dev/guide/custom-extensions/#input-rules
|
|
22
23
|
*/
|
|
23
24
|
export function wrappingInputRule(config: {
|
|
24
25
|
find: InputRuleFinder,
|
|
@@ -8,6 +8,7 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
|
8
8
|
/**
|
|
9
9
|
* Build an paste rule that adds a mark when the
|
|
10
10
|
* matched text is pasted into it.
|
|
11
|
+
* @see https://tiptap.dev/guide/custom-extensions/#paste-rules
|
|
11
12
|
*/
|
|
12
13
|
export function markPasteRule(config: {
|
|
13
14
|
find: PasteRuleFinder
|
|
@@ -7,6 +7,7 @@ import { callOrReturn } from '../utilities/index.js'
|
|
|
7
7
|
/**
|
|
8
8
|
* Build an paste rule that adds a node when the
|
|
9
9
|
* matched text is pasted into it.
|
|
10
|
+
* @see https://tiptap.dev/guide/custom-extensions/#paste-rules
|
|
10
11
|
*/
|
|
11
12
|
export function nodePasteRule(config: {
|
|
12
13
|
find: PasteRuleFinder
|
|
@@ -3,6 +3,7 @@ import { PasteRule, PasteRuleFinder } from '../PasteRule.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Build an paste rule that replaces text when the
|
|
5
5
|
* matched text is pasted into it.
|
|
6
|
+
* @see https://tiptap.dev/guide/custom-extensions/#paste-rules
|
|
6
7
|
*/
|
|
7
8
|
export function textPasteRule(config: {
|
|
8
9
|
find: PasteRuleFinder,
|