@tiptap/core 2.0.0-beta.209 → 2.0.0-beta.210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4311 -0
- package/dist/index.d.ts +2330 -0
- package/dist/index.js +4311 -0
- package/package.json +24 -23
- package/src/CommandManager.ts +27 -36
- package/src/Editor.ts +27 -37
- package/src/Extension.ts +193 -179
- package/src/ExtensionManager.ts +82 -98
- package/src/InputRule.ts +38 -43
- package/src/Mark.ts +277 -264
- package/src/Node.ts +349 -314
- package/src/NodeView.ts +24 -23
- package/src/PasteRule.ts +37 -44
- package/src/Tracker.ts +4 -8
- package/src/commands/clearNodes.ts +1 -1
- package/src/commands/createParagraphNear.ts +2 -2
- package/src/commands/deleteNode.ts +1 -1
- package/src/commands/deleteSelection.ts +2 -2
- package/src/commands/exitCode.ts +2 -2
- package/src/commands/extendMarkRange.ts +6 -3
- package/src/commands/insertContent.ts +9 -5
- package/src/commands/insertContentAt.ts +10 -24
- package/src/commands/join.ts +9 -6
- package/src/commands/lift.ts +3 -3
- package/src/commands/liftEmptyBlock.ts +1 -1
- package/src/commands/liftListItem.ts +3 -3
- package/src/commands/newlineInCode.ts +2 -2
- package/src/commands/resetAttributes.ts +11 -6
- package/src/commands/selectNodeBackward.ts +2 -2
- package/src/commands/selectNodeForward.ts +2 -2
- package/src/commands/selectParentNode.ts +2 -2
- package/src/commands/selectTextblockEnd.ts +2 -2
- package/src/commands/selectTextblockStart.ts +2 -2
- package/src/commands/setContent.ts +3 -4
- package/src/commands/setMark.ts +26 -16
- package/src/commands/setNode.ts +19 -17
- package/src/commands/setNodeSelection.ts +2 -2
- package/src/commands/setTextSelection.ts +3 -5
- package/src/commands/sinkListItem.ts +3 -3
- package/src/commands/splitBlock.ts +20 -25
- package/src/commands/splitListItem.ts +15 -25
- package/src/commands/toggleList.ts +27 -24
- package/src/commands/toggleMark.ts +3 -3
- package/src/commands/toggleNode.ts +6 -2
- package/src/commands/toggleWrap.ts +2 -2
- package/src/commands/unsetMark.ts +3 -3
- package/src/commands/updateAttributes.ts +14 -9
- package/src/commands/wrapIn.ts +3 -3
- package/src/commands/wrapInList.ts +3 -3
- package/src/extensions/clipboardTextSerializer.ts +1 -1
- package/src/extensions/editable.ts +1 -1
- package/src/extensions/focusEvents.ts +1 -1
- package/src/extensions/keymap.ts +2 -7
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/combineTransactionSteps.ts +7 -4
- package/src/helpers/createChainableState.ts +3 -3
- package/src/helpers/createDocument.ts +1 -1
- package/src/helpers/createNodeFromContent.ts +4 -10
- package/src/helpers/defaultBlockAt.ts +1 -1
- package/src/helpers/findChildren.ts +1 -1
- package/src/helpers/findChildrenInRange.ts +6 -2
- package/src/helpers/findParentNode.ts +1 -1
- package/src/helpers/findParentNodeClosestToPos.ts +12 -7
- package/src/helpers/generateHTML.ts +1 -1
- package/src/helpers/generateJSON.ts +2 -4
- package/src/helpers/generateText.ts +4 -7
- package/src/helpers/getAttributes.ts +3 -5
- package/src/helpers/getChangedRanges.ts +1 -1
- package/src/helpers/getDebugJSON.ts +4 -4
- package/src/helpers/getHTMLFromFragment.ts +2 -4
- package/src/helpers/getMarkAttributes.ts +6 -3
- package/src/helpers/getMarkRange.ts +1 -1
- package/src/helpers/getMarkType.ts +4 -2
- package/src/helpers/getMarksBetween.ts +8 -6
- package/src/helpers/getNodeAttributes.ts +7 -6
- package/src/helpers/getNodeType.ts +4 -2
- package/src/helpers/getRenderedAttributes.ts +5 -2
- package/src/helpers/getSchema.ts +1 -1
- package/src/helpers/getSchemaByResolvedExtensions.ts +151 -107
- package/src/helpers/getSchemaTypeByName.ts +1 -1
- package/src/helpers/getSchemaTypeNameByName.ts +1 -1
- package/src/helpers/getText.ts +3 -3
- package/src/helpers/getTextBetween.ts +4 -7
- package/src/helpers/getTextContentFromNodes.ts +8 -3
- package/src/helpers/getTextSerializersFromSchema.ts +6 -5
- package/src/helpers/injectExtensionAttributesToParseRule.ts +6 -5
- package/src/helpers/isActive.ts +6 -2
- package/src/helpers/isMarkActive.ts +12 -15
- package/src/helpers/isNodeActive.ts +4 -7
- package/src/helpers/isNodeEmpty.ts +1 -1
- package/src/helpers/isNodeSelection.ts +1 -1
- package/src/helpers/isTextSelection.ts +1 -1
- package/src/helpers/posToDOMRect.ts +1 -1
- package/src/helpers/resolveFocusPosition.ts +2 -3
- package/src/helpers/selectionToInsertionEnd.ts +2 -2
- package/src/inputRules/markInputRule.ts +3 -4
- package/src/inputRules/nodeInputRule.ts +3 -4
- package/src/inputRules/textblockTypeInputRule.ts +3 -4
- package/src/inputRules/wrappingInputRule.ts +5 -6
- package/src/pasteRules/markPasteRule.ts +3 -4
- package/src/pasteRules/nodePasteRule.ts +8 -10
- package/src/types.ts +109 -125
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -147
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -227
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -18
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -327
- package/dist/packages/core/src/Node.d.ts +0 -397
- package/dist/packages/core/src/NodeView.d.ts +0 -27
- package/dist/packages/core/src/PasteRule.d.ts +0 -42
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -12
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -12
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -12
- package/dist/packages/core/src/commands/command.d.ts +0 -12
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -12
- package/dist/packages/core/src/commands/enter.d.ts +0 -12
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -12
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -13
- package/dist/packages/core/src/commands/first.d.ts +0 -12
- package/dist/packages/core/src/commands/focus.d.ts +0 -14
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -50
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -16
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -16
- package/dist/packages/core/src/commands/join.d.ts +0 -33
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -12
- package/dist/packages/core/src/commands/lift.d.ts +0 -13
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -12
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -12
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -12
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -12
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -12
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -12
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -12
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -12
- package/dist/packages/core/src/commands/setContent.d.ts +0 -13
- package/dist/packages/core/src/commands/setMark.d.ts +0 -13
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -12
- package/dist/packages/core/src/commands/setNode.d.ts +0 -13
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -12
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -12
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -14
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -13
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -12
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -12
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -18
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -13
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -13
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -2
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -7
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -5
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -3
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -7
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -2
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -3
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -6
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -8
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -2
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -2
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -5
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -2
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -2
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -2
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -2
- package/dist/packages/core/src/helpers/getText.d.ts +0 -6
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -6
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -2
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -3
- package/dist/packages/core/src/helpers/index.d.ts +0 -33
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -23
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -12
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -12
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -9
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -14
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -23
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -12
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -12
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -9
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -214
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/tiptap-core.cjs +0 -4360
- package/dist/tiptap-core.cjs.map +0 -1
- package/dist/tiptap-core.esm.js +0 -4284
- package/dist/tiptap-core.esm.js.map +0 -1
- package/dist/tiptap-core.umd.js +0 -4358
- package/dist/tiptap-core.umd.js.map +0 -1
package/src/extensions/keymap.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin, PluginKey, Selection } from '
|
|
1
|
+
import { Plugin, PluginKey, Selection } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
3
|
import { CommandManager } from '../CommandManager'
|
|
4
4
|
import { Extension } from '../Extension'
|
|
@@ -19,12 +19,7 @@ export const Keymap = Extension.create({
|
|
|
19
19
|
const { pos, parent } = $anchor
|
|
20
20
|
const isAtStart = Selection.atStart(doc).from === pos
|
|
21
21
|
|
|
22
|
-
if (
|
|
23
|
-
!empty
|
|
24
|
-
|| !isAtStart
|
|
25
|
-
|| !parent.type.isTextblock
|
|
26
|
-
|| parent.textContent.length
|
|
27
|
-
) {
|
|
22
|
+
if (!empty || !isAtStart || !parent.type.isTextblock || parent.textContent.length) {
|
|
28
23
|
return false
|
|
29
24
|
}
|
|
30
25
|
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '
|
|
2
|
-
import { Transaction } from '
|
|
3
|
-
import { Transform } from '
|
|
1
|
+
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
|
+
import { Transaction } from '@tiptap/pm/state'
|
|
3
|
+
import { Transform } from '@tiptap/pm/transform'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns a new `Transform` based on all steps of the passed transactions.
|
|
7
7
|
*/
|
|
8
|
-
export function combineTransactionSteps(
|
|
8
|
+
export function combineTransactionSteps(
|
|
9
|
+
oldDoc: ProseMirrorNode,
|
|
10
|
+
transactions: Transaction[],
|
|
11
|
+
): Transform {
|
|
9
12
|
const transform = new Transform(oldDoc)
|
|
10
13
|
|
|
11
14
|
transactions.forEach(transaction => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EditorState, Transaction } from '
|
|
1
|
+
import { EditorState, Transaction } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
3
|
export function createChainableState(config: {
|
|
4
|
-
transaction: Transaction
|
|
5
|
-
state: EditorState
|
|
4
|
+
transaction: Transaction
|
|
5
|
+
state: EditorState
|
|
6
6
|
}): EditorState {
|
|
7
7
|
const { state, transaction } = config
|
|
8
8
|
let { selection } = transaction
|
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
Node as ProseMirrorNode,
|
|
5
5
|
ParseOptions,
|
|
6
6
|
Schema,
|
|
7
|
-
} from '
|
|
7
|
+
} from '@tiptap/pm/model'
|
|
8
8
|
|
|
9
9
|
import { Content } from '../types'
|
|
10
10
|
import { elementFromString } from '../utilities/elementFromString'
|
|
11
11
|
|
|
12
12
|
export type CreateNodeFromContentOptions = {
|
|
13
|
-
slice?: boolean
|
|
14
|
-
parseOptions?: ParseOptions
|
|
13
|
+
slice?: boolean
|
|
14
|
+
parseOptions?: ParseOptions
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function createNodeFromContent(
|
|
@@ -33,13 +33,7 @@ export function createNodeFromContent(
|
|
|
33
33
|
|
|
34
34
|
return schema.nodeFromJSON(content)
|
|
35
35
|
} catch (error) {
|
|
36
|
-
console.warn(
|
|
37
|
-
'[tiptap warn]: Invalid content.',
|
|
38
|
-
'Passed value:',
|
|
39
|
-
content,
|
|
40
|
-
'Error:',
|
|
41
|
-
error,
|
|
42
|
-
)
|
|
36
|
+
console.warn('[tiptap warn]: Invalid content.', 'Passed value:', content, 'Error:', error)
|
|
43
37
|
|
|
44
38
|
return createNodeFromContent('', schema, options)
|
|
45
39
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '
|
|
1
|
+
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { NodeWithPos, Predicate, Range } from '../types'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Same as `findChildren` but searches only within a `range`.
|
|
7
7
|
*/
|
|
8
|
-
export function findChildrenInRange(
|
|
8
|
+
export function findChildrenInRange(
|
|
9
|
+
node: ProseMirrorNode,
|
|
10
|
+
range: Range,
|
|
11
|
+
predicate: Predicate,
|
|
12
|
+
): NodeWithPos[] {
|
|
9
13
|
const nodesWithPos: NodeWithPos[] = []
|
|
10
14
|
|
|
11
15
|
// if (range.from === range.to) {
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode, ResolvedPos } from '
|
|
1
|
+
import { Node as ProseMirrorNode, ResolvedPos } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { Predicate } from '../types'
|
|
4
4
|
|
|
5
|
-
export function findParentNodeClosestToPos(
|
|
6
|
-
pos:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
export function findParentNodeClosestToPos(
|
|
6
|
+
$pos: ResolvedPos,
|
|
7
|
+
predicate: Predicate,
|
|
8
|
+
):
|
|
9
|
+
| {
|
|
10
|
+
pos: number
|
|
11
|
+
start: number
|
|
12
|
+
depth: number
|
|
13
|
+
node: ProseMirrorNode
|
|
14
|
+
}
|
|
15
|
+
| undefined {
|
|
11
16
|
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
12
17
|
const node = $pos.node(i)
|
|
13
18
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DOMParser } from '
|
|
1
|
+
import { DOMParser } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { Extensions } from '../types'
|
|
4
4
|
import { elementFromString } from '../utilities/elementFromString'
|
|
@@ -8,7 +8,5 @@ export function generateJSON(html: string, extensions: Extensions): Record<strin
|
|
|
8
8
|
const schema = getSchema(extensions)
|
|
9
9
|
const dom = elementFromString(html)
|
|
10
10
|
|
|
11
|
-
return DOMParser.fromSchema(schema)
|
|
12
|
-
.parse(dom)
|
|
13
|
-
.toJSON()
|
|
11
|
+
return DOMParser.fromSchema(schema).parse(dom).toJSON()
|
|
14
12
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node } from '
|
|
1
|
+
import { Node } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { Extensions, JSONContent, TextSerializer } from '../types'
|
|
4
4
|
import { getSchema } from './getSchema'
|
|
@@ -9,14 +9,11 @@ export function generateText(
|
|
|
9
9
|
doc: JSONContent,
|
|
10
10
|
extensions: Extensions,
|
|
11
11
|
options?: {
|
|
12
|
-
blockSeparator?: string
|
|
13
|
-
textSerializers?: Record<string, TextSerializer
|
|
12
|
+
blockSeparator?: string
|
|
13
|
+
textSerializers?: Record<string, TextSerializer>
|
|
14
14
|
},
|
|
15
15
|
): string {
|
|
16
|
-
const {
|
|
17
|
-
blockSeparator = '\n\n',
|
|
18
|
-
textSerializers = {},
|
|
19
|
-
} = options || {}
|
|
16
|
+
const { blockSeparator = '\n\n', textSerializers = {} } = options || {}
|
|
20
17
|
const schema = getSchema(extensions)
|
|
21
18
|
const contentNode = Node.fromJSON(schema, doc)
|
|
22
19
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MarkType, NodeType } from '
|
|
2
|
-
import { EditorState } from '
|
|
1
|
+
import { MarkType, NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import { EditorState } from '@tiptap/pm/state'
|
|
3
3
|
|
|
4
4
|
import { getMarkAttributes } from './getMarkAttributes'
|
|
5
5
|
import { getNodeAttributes } from './getNodeAttributes'
|
|
@@ -10,9 +10,7 @@ export function getAttributes(
|
|
|
10
10
|
typeOrName: string | NodeType | MarkType,
|
|
11
11
|
): Record<string, any> {
|
|
12
12
|
const schemaType = getSchemaTypeNameByName(
|
|
13
|
-
typeof typeOrName === 'string'
|
|
14
|
-
? typeOrName
|
|
15
|
-
: typeOrName.name,
|
|
13
|
+
typeof typeOrName === 'string' ? typeOrName : typeOrName.name,
|
|
16
14
|
state.schema,
|
|
17
15
|
)
|
|
18
16
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '
|
|
1
|
+
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { JSONContent } from '../types'
|
|
4
4
|
|
|
5
5
|
interface DebugJSONContent extends JSONContent {
|
|
6
|
-
from: number
|
|
7
|
-
to: number
|
|
6
|
+
from: number
|
|
7
|
+
to: number
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function getDebugJSON(node: ProseMirrorNode, startOffset = 0): DebugJSONContent {
|
|
@@ -13,7 +13,7 @@ export function getDebugJSON(node: ProseMirrorNode, startOffset = 0): DebugJSONC
|
|
|
13
13
|
const from = startOffset
|
|
14
14
|
const to = from + node.nodeSize
|
|
15
15
|
const marks = node.marks.map(mark => {
|
|
16
|
-
const output: { type: string
|
|
16
|
+
const output: { type: string; attrs?: Record<string, any> } = {
|
|
17
17
|
type: mark.type.name,
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { DOMSerializer, Fragment, Schema } from '
|
|
1
|
+
import { DOMSerializer, Fragment, Schema } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
export function getHTMLFromFragment(fragment: Fragment, schema: Schema): string {
|
|
4
|
-
const documentFragment = DOMSerializer
|
|
5
|
-
.fromSchema(schema)
|
|
6
|
-
.serializeFragment(fragment)
|
|
4
|
+
const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment)
|
|
7
5
|
|
|
8
6
|
const temporaryDocument = document.implementation.createHTMLDocument()
|
|
9
7
|
const container = temporaryDocument.createElement('div')
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Mark, MarkType } from '
|
|
2
|
-
import { EditorState } from '
|
|
1
|
+
import { Mark, MarkType } from '@tiptap/pm/model'
|
|
2
|
+
import { EditorState } from '@tiptap/pm/state'
|
|
3
3
|
|
|
4
4
|
import { getMarkType } from './getMarkType'
|
|
5
5
|
|
|
6
|
-
export function getMarkAttributes(
|
|
6
|
+
export function getMarkAttributes(
|
|
7
|
+
state: EditorState,
|
|
8
|
+
typeOrName: string | MarkType,
|
|
9
|
+
): Record<string, any> {
|
|
7
10
|
const type = getMarkType(typeOrName, state.schema)
|
|
8
11
|
const { from, to, empty } = state.selection
|
|
9
12
|
const marks: Mark[] = []
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { MarkType, Schema } from '
|
|
1
|
+
import { MarkType, Schema } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
export function getMarkType(nameOrType: string | MarkType, schema: Schema): MarkType {
|
|
4
4
|
if (typeof nameOrType === 'string') {
|
|
5
5
|
if (!schema.marks[nameOrType]) {
|
|
6
|
-
throw Error(
|
|
6
|
+
throw Error(
|
|
7
|
+
`There is no mark type named '${nameOrType}'. Maybe you forgot to add the extension?`,
|
|
8
|
+
)
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
return schema.marks[nameOrType]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '
|
|
1
|
+
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { MarkRange } from '../types'
|
|
4
4
|
import { getMarkRange } from './getMarkRange'
|
|
@@ -26,11 +26,13 @@ export function getMarksBetween(from: number, to: number, doc: ProseMirrorNode):
|
|
|
26
26
|
})
|
|
27
27
|
} else {
|
|
28
28
|
doc.nodesBetween(from, to, (node, pos) => {
|
|
29
|
-
marks.push(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
marks.push(
|
|
30
|
+
...node.marks.map(mark => ({
|
|
31
|
+
from: pos,
|
|
32
|
+
to: pos + node.nodeSize,
|
|
33
|
+
mark,
|
|
34
|
+
})),
|
|
35
|
+
)
|
|
34
36
|
})
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Node, NodeType } from '
|
|
2
|
-
import { EditorState } from '
|
|
1
|
+
import { Node, NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import { EditorState } from '@tiptap/pm/state'
|
|
3
3
|
|
|
4
4
|
import { getNodeType } from './getNodeType'
|
|
5
5
|
|
|
6
|
-
export function getNodeAttributes(
|
|
6
|
+
export function getNodeAttributes(
|
|
7
|
+
state: EditorState,
|
|
8
|
+
typeOrName: string | NodeType,
|
|
9
|
+
): Record<string, any> {
|
|
7
10
|
const type = getNodeType(typeOrName, state.schema)
|
|
8
11
|
const { from, to } = state.selection
|
|
9
12
|
const nodes: Node[] = []
|
|
@@ -12,9 +15,7 @@ export function getNodeAttributes(state: EditorState, typeOrName: string | NodeT
|
|
|
12
15
|
nodes.push(node)
|
|
13
16
|
})
|
|
14
17
|
|
|
15
|
-
const node = nodes
|
|
16
|
-
.reverse()
|
|
17
|
-
.find(nodeItem => nodeItem.type.name === type.name)
|
|
18
|
+
const node = nodes.reverse().find(nodeItem => nodeItem.type.name === type.name)
|
|
18
19
|
|
|
19
20
|
if (!node) {
|
|
20
21
|
return {}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { NodeType, Schema } from '
|
|
1
|
+
import { NodeType, Schema } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
export function getNodeType(nameOrType: string | NodeType, schema: Schema): NodeType {
|
|
4
4
|
if (typeof nameOrType === 'string') {
|
|
5
5
|
if (!schema.nodes[nameOrType]) {
|
|
6
|
-
throw Error(
|
|
6
|
+
throw Error(
|
|
7
|
+
`There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`,
|
|
8
|
+
)
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
return schema.nodes[nameOrType]
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Mark, Node } from '
|
|
1
|
+
import { Mark, Node } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { ExtensionAttribute } from '../types'
|
|
4
4
|
import { mergeAttributes } from '../utilities/mergeAttributes'
|
|
5
5
|
|
|
6
|
-
export function getRenderedAttributes(
|
|
6
|
+
export function getRenderedAttributes(
|
|
7
|
+
nodeOrMark: Node | Mark,
|
|
8
|
+
extensionAttributes: ExtensionAttribute[],
|
|
9
|
+
): Record<string, any> {
|
|
7
10
|
return extensionAttributes
|
|
8
11
|
.filter(item => item.attribute.rendered)
|
|
9
12
|
.map(item => {
|
package/src/helpers/getSchema.ts
CHANGED