@tiptap/core 2.1.0-rc.9 → 2.1.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 +384 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +373 -98
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +384 -99
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/CommandManager.d.ts +2 -2
- package/dist/packages/core/src/Editor.d.ts +4 -4
- package/dist/packages/core/src/Extension.d.ts +7 -7
- package/dist/packages/core/src/ExtensionManager.d.ts +2 -2
- package/dist/packages/core/src/InputRule.d.ts +2 -2
- package/dist/packages/core/src/Mark.d.ts +6 -6
- package/dist/packages/core/src/Node.d.ts +5 -5
- package/dist/packages/core/src/NodeView.d.ts +3 -3
- package/dist/packages/core/src/PasteRule.d.ts +2 -2
- package/dist/packages/core/src/commands/blur.d.ts +1 -1
- package/dist/packages/core/src/commands/clearContent.d.ts +1 -1
- package/dist/packages/core/src/commands/clearNodes.d.ts +1 -1
- package/dist/packages/core/src/commands/command.d.ts +1 -1
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +1 -1
- package/dist/packages/core/src/commands/cut.d.ts +15 -0
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +1 -1
- package/dist/packages/core/src/commands/deleteNode.d.ts +1 -1
- package/dist/packages/core/src/commands/deleteRange.d.ts +1 -1
- package/dist/packages/core/src/commands/deleteSelection.d.ts +1 -1
- package/dist/packages/core/src/commands/enter.d.ts +1 -1
- package/dist/packages/core/src/commands/exitCode.d.ts +1 -1
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +1 -1
- package/dist/packages/core/src/commands/first.d.ts +1 -1
- package/dist/packages/core/src/commands/focus.d.ts +1 -1
- package/dist/packages/core/src/commands/forEach.d.ts +1 -1
- package/dist/packages/core/src/commands/index.d.ts +53 -50
- package/dist/packages/core/src/commands/insertContent.d.ts +1 -1
- package/dist/packages/core/src/commands/insertContentAt.d.ts +1 -1
- package/dist/packages/core/src/commands/join.d.ts +1 -1
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +12 -0
- package/dist/packages/core/src/commands/joinItemForward.d.ts +12 -0
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +1 -1
- package/dist/packages/core/src/commands/lift.d.ts +1 -1
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +1 -1
- package/dist/packages/core/src/commands/liftListItem.d.ts +1 -1
- package/dist/packages/core/src/commands/newlineInCode.d.ts +1 -1
- package/dist/packages/core/src/commands/resetAttributes.d.ts +1 -1
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +1 -1
- package/dist/packages/core/src/commands/selectAll.d.ts +1 -1
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +1 -1
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +1 -1
- package/dist/packages/core/src/commands/selectParentNode.d.ts +1 -1
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +1 -1
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +1 -1
- package/dist/packages/core/src/commands/setContent.d.ts +1 -1
- package/dist/packages/core/src/commands/setMark.d.ts +1 -1
- package/dist/packages/core/src/commands/setMeta.d.ts +1 -1
- package/dist/packages/core/src/commands/setNode.d.ts +1 -1
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +1 -1
- package/dist/packages/core/src/commands/setTextSelection.d.ts +1 -1
- package/dist/packages/core/src/commands/sinkListItem.d.ts +1 -1
- package/dist/packages/core/src/commands/splitBlock.d.ts +1 -1
- package/dist/packages/core/src/commands/splitListItem.d.ts +1 -1
- package/dist/packages/core/src/commands/toggleList.d.ts +1 -1
- package/dist/packages/core/src/commands/toggleMark.d.ts +1 -1
- package/dist/packages/core/src/commands/toggleNode.d.ts +1 -1
- package/dist/packages/core/src/commands/toggleWrap.d.ts +1 -1
- package/dist/packages/core/src/commands/undoInputRule.d.ts +1 -1
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +1 -1
- package/dist/packages/core/src/commands/unsetMark.d.ts +1 -1
- package/dist/packages/core/src/commands/updateAttributes.d.ts +1 -1
- package/dist/packages/core/src/commands/wrapIn.d.ts +1 -1
- package/dist/packages/core/src/commands/wrapInList.d.ts +1 -1
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +1 -1
- package/dist/packages/core/src/extensions/commands.d.ts +2 -2
- package/dist/packages/core/src/extensions/editable.d.ts +1 -1
- package/dist/packages/core/src/extensions/focusEvents.d.ts +1 -1
- package/dist/packages/core/src/extensions/index.d.ts +6 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +1 -1
- package/dist/packages/core/src/extensions/tabindex.d.ts +1 -1
- package/dist/packages/core/src/helpers/createDocument.d.ts +1 -1
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +1 -1
- package/dist/packages/core/src/helpers/findChildren.d.ts +1 -1
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +1 -1
- package/dist/packages/core/src/helpers/findParentNode.d.ts +1 -1
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +1 -1
- package/dist/packages/core/src/helpers/generateHTML.d.ts +1 -1
- package/dist/packages/core/src/helpers/generateJSON.d.ts +1 -1
- package/dist/packages/core/src/helpers/generateText.d.ts +1 -1
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +1 -1
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +1 -1
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +1 -1
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +1 -1
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +1 -1
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +1 -1
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +1 -1
- package/dist/packages/core/src/helpers/getSchema.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +1 -1
- package/dist/packages/core/src/helpers/getText.d.ts +1 -1
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +1 -1
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +1 -1
- package/dist/packages/core/src/helpers/index.d.ts +51 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +1 -1
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +1 -1
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +1 -1
- package/dist/packages/core/src/helpers/isList.d.ts +1 -1
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +1 -1
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +4 -4
- package/dist/packages/core/src/index.d.ts +15 -15
- package/dist/packages/core/src/inputRules/index.d.ts +5 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +2 -2
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +22 -2
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +1 -1
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +2 -2
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +3 -3
- package/dist/packages/core/src/pasteRules/index.d.ts +3 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +2 -2
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +2 -2
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +1 -1
- package/dist/packages/core/src/types.d.ts +5 -5
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +1 -1
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
- package/dist/packages/core/src/utilities/index.d.ts +20 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +1 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/findListItemPos.d.ts +6 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/getNextListDepth.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/handleBackspace.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/handleDelete.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/hasListBefore.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/hasListItemAfter.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/hasListItemBefore.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/index.d.ts +10 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/listItemHasSubList.d.ts +3 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/nextListIsDeeper.d.ts +2 -0
- package/dist/packages/extension-list-keymap/src/listHelpers/nextListIsHigher.d.ts +2 -0
- package/package.json +2 -2
- package/src/CommandManager.ts +4 -8
- package/src/Editor.ts +16 -16
- package/src/Extension.ts +10 -10
- package/src/ExtensionManager.ts +15 -15
- package/src/InputRule.ts +6 -6
- package/src/Mark.ts +9 -9
- package/src/Node.ts +8 -8
- package/src/NodeView.ts +8 -6
- package/src/PasteRule.ts +6 -6
- package/src/commands/blur.ts +1 -1
- package/src/commands/clearContent.ts +1 -1
- package/src/commands/clearNodes.ts +1 -1
- package/src/commands/command.ts +1 -1
- package/src/commands/createParagraphNear.ts +1 -1
- package/src/commands/cut.ts +29 -0
- package/src/commands/deleteCurrentNode.ts +1 -1
- package/src/commands/deleteNode.ts +2 -2
- package/src/commands/deleteRange.ts +1 -1
- package/src/commands/deleteSelection.ts +1 -1
- package/src/commands/enter.ts +1 -1
- package/src/commands/exitCode.ts +1 -1
- package/src/commands/extendMarkRange.ts +3 -3
- package/src/commands/first.ts +1 -1
- package/src/commands/focus.ts +4 -4
- package/src/commands/forEach.ts +1 -1
- package/src/commands/index.ts +53 -50
- package/src/commands/insertContent.ts +1 -1
- package/src/commands/insertContentAt.ts +4 -4
- package/src/commands/join.ts +1 -1
- package/src/commands/joinItemBackward.ts +36 -0
- package/src/commands/joinItemForward.ts +38 -0
- package/src/commands/keyboardShortcut.ts +3 -3
- package/src/commands/lift.ts +3 -3
- package/src/commands/liftEmptyBlock.ts +1 -1
- package/src/commands/liftListItem.ts +2 -2
- package/src/commands/newlineInCode.ts +1 -1
- package/src/commands/resetAttributes.ts +5 -5
- package/src/commands/scrollIntoView.ts +1 -1
- package/src/commands/selectAll.ts +1 -1
- package/src/commands/selectNodeBackward.ts +1 -1
- package/src/commands/selectNodeForward.ts +1 -1
- package/src/commands/selectParentNode.ts +1 -1
- package/src/commands/selectTextblockEnd.ts +1 -1
- package/src/commands/selectTextblockStart.ts +1 -1
- package/src/commands/setContent.ts +2 -2
- package/src/commands/setMark.ts +4 -4
- package/src/commands/setMeta.ts +1 -1
- package/src/commands/setNode.ts +2 -2
- package/src/commands/setNodeSelection.ts +2 -2
- package/src/commands/setTextSelection.ts +2 -2
- package/src/commands/sinkListItem.ts +2 -2
- package/src/commands/splitBlock.ts +3 -3
- package/src/commands/splitListItem.ts +3 -3
- package/src/commands/toggleList.ts +4 -4
- package/src/commands/toggleMark.ts +3 -3
- package/src/commands/toggleNode.ts +3 -3
- package/src/commands/toggleWrap.ts +3 -3
- package/src/commands/undoInputRule.ts +1 -1
- package/src/commands/unsetAllMarks.ts +1 -1
- package/src/commands/unsetMark.ts +3 -3
- package/src/commands/updateAttributes.ts +4 -4
- package/src/commands/wrapIn.ts +2 -2
- package/src/commands/wrapInList.ts +2 -2
- package/src/extensions/clipboardTextSerializer.ts +3 -3
- package/src/extensions/commands.ts +3 -3
- package/src/extensions/editable.ts +1 -1
- package/src/extensions/focusEvents.ts +1 -1
- package/src/extensions/index.ts +6 -6
- package/src/extensions/keymap.ts +7 -5
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/createDocument.ts +2 -2
- package/src/helpers/createNodeFromContent.ts +2 -2
- package/src/helpers/findChildren.ts +1 -1
- package/src/helpers/findChildrenInRange.ts +1 -1
- package/src/helpers/findParentNode.ts +2 -2
- package/src/helpers/findParentNodeClosestToPos.ts +1 -1
- package/src/helpers/generateHTML.ts +3 -3
- package/src/helpers/generateJSON.ts +3 -3
- package/src/helpers/generateText.ts +4 -4
- package/src/helpers/getAttributes.ts +3 -3
- package/src/helpers/getAttributesFromExtensions.ts +4 -4
- package/src/helpers/getChangedRanges.ts +2 -2
- package/src/helpers/getDebugJSON.ts +1 -1
- package/src/helpers/getExtensionField.ts +1 -1
- package/src/helpers/getMarkAttributes.ts +1 -1
- package/src/helpers/getMarkRange.ts +2 -2
- package/src/helpers/getMarksBetween.ts +2 -2
- package/src/helpers/getNodeAttributes.ts +1 -1
- package/src/helpers/getRenderedAttributes.ts +2 -2
- package/src/helpers/getSchema.ts +4 -4
- package/src/helpers/getSchemaByResolvedExtensions.ts +9 -9
- package/src/helpers/getSplittedAttributes.ts +1 -1
- package/src/helpers/getText.ts +2 -2
- package/src/helpers/getTextBetween.ts +1 -1
- package/src/helpers/getTextSerializersFromSchema.ts +1 -1
- package/src/helpers/index.ts +51 -50
- package/src/helpers/injectExtensionAttributesToParseRule.ts +2 -2
- package/src/helpers/isActive.ts +3 -3
- package/src/helpers/isAtEndOfNode.ts +20 -2
- package/src/helpers/isExtensionRulesEnabled.ts +1 -1
- package/src/helpers/isList.ts +5 -5
- package/src/helpers/isMarkActive.ts +3 -3
- package/src/helpers/isNodeActive.ts +3 -3
- package/src/helpers/posToDOMRect.ts +1 -1
- package/src/helpers/resolveFocusPosition.ts +2 -2
- package/src/helpers/splitExtensions.ts +4 -4
- package/src/index.ts +15 -15
- package/src/inputRules/index.ts +5 -5
- package/src/inputRules/markInputRule.ts +5 -6
- package/src/inputRules/nodeInputRule.ts +60 -6
- package/src/inputRules/textInputRule.ts +1 -1
- package/src/inputRules/textblockTypeInputRule.ts +3 -3
- package/src/inputRules/wrappingInputRule.ts +4 -4
- package/src/pasteRules/index.ts +3 -3
- package/src/pasteRules/markPasteRule.ts +4 -4
- package/src/pasteRules/nodePasteRule.ts +3 -3
- package/src/pasteRules/textPasteRule.ts +1 -1
- package/src/types.ts +5 -5
- package/src/utilities/callOrReturn.ts +2 -2
- package/src/utilities/createStyleTag.ts +3 -3
- package/src/utilities/index.ts +20 -20
- package/src/utilities/isAndroid.ts +3 -0
- package/src/utilities/mergeAttributes.ts +8 -1
- package/src/utilities/mergeDeep.ts +1 -1
- package/src/utilities/objectIncludes.ts +1 -1
package/src/inputRules/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './markInputRule'
|
|
2
|
-
export * from './nodeInputRule'
|
|
3
|
-
export * from './textblockTypeInputRule'
|
|
4
|
-
export * from './textInputRule'
|
|
5
|
-
export * from './wrappingInputRule'
|
|
1
|
+
export * from './markInputRule.js'
|
|
2
|
+
export * from './nodeInputRule.js'
|
|
3
|
+
export * from './textblockTypeInputRule.js'
|
|
4
|
+
export * from './textInputRule.js'
|
|
5
|
+
export * from './wrappingInputRule.js'
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { MarkType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { getMarksBetween } from '../helpers/getMarksBetween'
|
|
4
|
-
import { InputRule, InputRuleFinder } from '../InputRule'
|
|
5
|
-
import { ExtendedRegExpMatchArray } from '../types'
|
|
6
|
-
import { callOrReturn } from '../utilities/callOrReturn'
|
|
3
|
+
import { getMarksBetween } from '../helpers/getMarksBetween.js'
|
|
4
|
+
import { InputRule, InputRuleFinder } from '../InputRule.js'
|
|
5
|
+
import { ExtendedRegExpMatchArray } from '../types.js'
|
|
6
|
+
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Build an input rule that adds a mark when the
|
|
@@ -30,7 +30,6 @@ export function markInputRule(config: {
|
|
|
30
30
|
const { tr } = state
|
|
31
31
|
const captureGroup = match[match.length - 1]
|
|
32
32
|
const fullMatch = match[0]
|
|
33
|
-
let markEnd = range.to
|
|
34
33
|
|
|
35
34
|
if (captureGroup) {
|
|
36
35
|
const startSpaces = fullMatch.search(/\S/)
|
|
@@ -58,7 +57,7 @@ export function markInputRule(config: {
|
|
|
58
57
|
tr.delete(range.from + startSpaces, textStart)
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
markEnd = range.from + startSpaces + captureGroup.length
|
|
60
|
+
const markEnd = range.from + startSpaces + captureGroup.length
|
|
62
61
|
|
|
63
62
|
tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}))
|
|
64
63
|
|
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import { NodeSelection, TextSelection } from '@tiptap/pm/state'
|
|
2
3
|
|
|
3
|
-
import { InputRule, InputRuleFinder } from '../InputRule'
|
|
4
|
-
import { ExtendedRegExpMatchArray } from '../types'
|
|
5
|
-
import { callOrReturn } from '../utilities/callOrReturn'
|
|
4
|
+
import { InputRule, InputRuleFinder } from '../InputRule.js'
|
|
5
|
+
import { ExtendedRegExpMatchArray } from '../types.js'
|
|
6
|
+
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Build an input rule that adds a node when the
|
|
9
10
|
* matched text is typed into it.
|
|
10
11
|
*/
|
|
11
12
|
export function nodeInputRule(config: {
|
|
13
|
+
/**
|
|
14
|
+
* The regex to match.
|
|
15
|
+
*/
|
|
12
16
|
find: InputRuleFinder
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The node type to add.
|
|
20
|
+
*/
|
|
13
21
|
type: NodeType
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Should the input rule replace the node or append to it
|
|
25
|
+
* If true, the node will be replaced
|
|
26
|
+
*/
|
|
27
|
+
blockReplace?: boolean
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Insert empty paragraph after inserting the node
|
|
31
|
+
* Only works if blockReplace is true
|
|
32
|
+
*/
|
|
33
|
+
addExtraNewline?: boolean
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A function that returns the attributes for the node
|
|
37
|
+
* can also be an object of attributes
|
|
38
|
+
*/
|
|
14
39
|
getAttributes?:
|
|
15
40
|
| Record<string, any>
|
|
16
41
|
| ((match: ExtendedRegExpMatchArray) => Record<string, any>)
|
|
@@ -22,9 +47,13 @@ export function nodeInputRule(config: {
|
|
|
22
47
|
handler: ({ state, range, match }) => {
|
|
23
48
|
const attributes = callOrReturn(config.getAttributes, undefined, match) || {}
|
|
24
49
|
const { tr } = state
|
|
25
|
-
const start = range.from
|
|
50
|
+
const start = config.blockReplace ? range.from - 1 : range.from
|
|
26
51
|
let end = range.to
|
|
27
52
|
|
|
53
|
+
const newNode = config.type.create(attributes)
|
|
54
|
+
|
|
55
|
+
const { $to } = tr.selection
|
|
56
|
+
|
|
28
57
|
if (match[1]) {
|
|
29
58
|
const offset = match[0].lastIndexOf(match[1])
|
|
30
59
|
let matchStart = start + offset
|
|
@@ -41,9 +70,34 @@ export function nodeInputRule(config: {
|
|
|
41
70
|
tr.insertText(lastChar, start + match[0].length - 1)
|
|
42
71
|
|
|
43
72
|
// insert node from input rule
|
|
44
|
-
tr.replaceWith(matchStart, end,
|
|
73
|
+
tr.replaceWith(matchStart, end, newNode)
|
|
45
74
|
} else if (match[0]) {
|
|
46
|
-
tr.replaceWith(start, end,
|
|
75
|
+
tr.replaceWith(start, end, newNode)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (config.blockReplace && config.addExtraNewline) {
|
|
79
|
+
const posAfter = $to.end()
|
|
80
|
+
|
|
81
|
+
if ($to.nodeAfter) {
|
|
82
|
+
console.log($to.node().type.name)
|
|
83
|
+
if ($to.nodeAfter.isTextblock) {
|
|
84
|
+
tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1))
|
|
85
|
+
} else if ($to.nodeAfter.isBlock) {
|
|
86
|
+
tr.setSelection(NodeSelection.create(tr.doc, $to.pos))
|
|
87
|
+
} else {
|
|
88
|
+
tr.setSelection(TextSelection.create(tr.doc, $to.pos))
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
// add node after horizontal rule if it’s the end of the document
|
|
92
|
+
const node = $to.parent.type.contentMatch.defaultType?.create()
|
|
93
|
+
|
|
94
|
+
if (node) {
|
|
95
|
+
tr.insert(posAfter, node)
|
|
96
|
+
tr.setSelection(TextSelection.create(tr.doc, posAfter + 1))
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
tr.scrollIntoView()
|
|
47
101
|
}
|
|
48
102
|
},
|
|
49
103
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { InputRule, InputRuleFinder } from '../InputRule'
|
|
4
|
-
import { ExtendedRegExpMatchArray } from '../types'
|
|
5
|
-
import { callOrReturn } from '../utilities/callOrReturn'
|
|
3
|
+
import { InputRule, InputRuleFinder } from '../InputRule.js'
|
|
4
|
+
import { ExtendedRegExpMatchArray } from '../types.js'
|
|
5
|
+
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Build an input rule that changes the type of a textblock when the
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Node as ProseMirrorNode, NodeType } from '@tiptap/pm/model'
|
|
2
2
|
import { canJoin, findWrapping } from '@tiptap/pm/transform'
|
|
3
3
|
|
|
4
|
-
import { Editor } from '../Editor'
|
|
5
|
-
import { InputRule, InputRuleFinder } from '../InputRule'
|
|
6
|
-
import { ExtendedRegExpMatchArray } from '../types'
|
|
7
|
-
import { callOrReturn } from '../utilities/callOrReturn'
|
|
4
|
+
import { Editor } from '../Editor.js'
|
|
5
|
+
import { InputRule, InputRuleFinder } from '../InputRule.js'
|
|
6
|
+
import { ExtendedRegExpMatchArray } from '../types.js'
|
|
7
|
+
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Build an input rule for automatically wrapping a textblock when a
|
package/src/pasteRules/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './markPasteRule'
|
|
2
|
-
export * from './nodePasteRule'
|
|
3
|
-
export * from './textPasteRule'
|
|
1
|
+
export * from './markPasteRule.js'
|
|
2
|
+
export * from './nodePasteRule.js'
|
|
3
|
+
export * from './textPasteRule.js'
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { MarkType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { getMarksBetween } from '../helpers/getMarksBetween'
|
|
4
|
-
import { PasteRule, PasteRuleFinder } from '../PasteRule'
|
|
5
|
-
import { ExtendedRegExpMatchArray } from '../types'
|
|
6
|
-
import { callOrReturn } from '../utilities/callOrReturn'
|
|
3
|
+
import { getMarksBetween } from '../helpers/getMarksBetween.js'
|
|
4
|
+
import { PasteRule, PasteRuleFinder } from '../PasteRule.js'
|
|
5
|
+
import { ExtendedRegExpMatchArray } from '../types.js'
|
|
6
|
+
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Build an paste rule that adds a mark when the
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { PasteRule, PasteRuleFinder } from '../PasteRule'
|
|
4
|
-
import { ExtendedRegExpMatchArray } from '../types'
|
|
5
|
-
import { callOrReturn } from '../utilities'
|
|
3
|
+
import { PasteRule, PasteRuleFinder } from '../PasteRule.js'
|
|
4
|
+
import { ExtendedRegExpMatchArray } from '../types.js'
|
|
5
|
+
import { callOrReturn } from '../utilities/index.js'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Build an paste rule that adds a node when the
|
package/src/types.ts
CHANGED
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
Decoration, EditorProps, EditorView, NodeView,
|
|
7
7
|
} from '@tiptap/pm/view'
|
|
8
8
|
|
|
9
|
+
import { Editor } from './Editor.js'
|
|
10
|
+
import { Extension } from './Extension.js'
|
|
9
11
|
import {
|
|
10
12
|
Commands, ExtensionConfig, MarkConfig, NodeConfig,
|
|
11
|
-
} from '.'
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { Mark } from './Mark'
|
|
15
|
-
import { Node } from './Node'
|
|
13
|
+
} from './index.js'
|
|
14
|
+
import { Mark } from './Mark.js'
|
|
15
|
+
import { Node } from './Node.js'
|
|
16
16
|
|
|
17
17
|
export type AnyConfig = ExtensionConfig | NodeConfig | MarkConfig
|
|
18
18
|
export type AnyExtension = Extension | Node | Mark
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function createStyleTag(style: string, nonce?: string): HTMLStyleElement {
|
|
2
|
-
const tiptapStyleTag = (<HTMLStyleElement>document.querySelector(
|
|
1
|
+
export function createStyleTag(style: string, nonce?: string, suffix?: string): HTMLStyleElement {
|
|
2
|
+
const tiptapStyleTag = (<HTMLStyleElement>document.querySelector(`style[data-tiptap-style${suffix ? `-${suffix}` : ''}]`))
|
|
3
3
|
|
|
4
4
|
if (tiptapStyleTag !== null) {
|
|
5
5
|
return tiptapStyleTag
|
|
@@ -11,7 +11,7 @@ export function createStyleTag(style: string, nonce?: string): HTMLStyleElement
|
|
|
11
11
|
styleNode.setAttribute('nonce', nonce)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
styleNode.setAttribute(
|
|
14
|
+
styleNode.setAttribute(`data-tiptap-style${suffix ? `-${suffix}` : ''}`, '')
|
|
15
15
|
styleNode.innerHTML = style
|
|
16
16
|
document.getElementsByTagName('head')[0].appendChild(styleNode)
|
|
17
17
|
|
package/src/utilities/index.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export * from './callOrReturn'
|
|
2
|
-
export * from './createStyleTag'
|
|
3
|
-
export * from './deleteProps'
|
|
4
|
-
export * from './elementFromString'
|
|
5
|
-
export * from './escapeForRegEx'
|
|
6
|
-
export * from './findDuplicates'
|
|
7
|
-
export * from './fromString'
|
|
8
|
-
export * from './isEmptyObject'
|
|
9
|
-
export * from './isFunction'
|
|
10
|
-
export * from './isiOS'
|
|
11
|
-
export * from './isMacOS'
|
|
12
|
-
export * from './isNumber'
|
|
13
|
-
export * from './isPlainObject'
|
|
14
|
-
export * from './isRegExp'
|
|
15
|
-
export * from './isString'
|
|
16
|
-
export * from './mergeAttributes'
|
|
17
|
-
export * from './mergeDeep'
|
|
18
|
-
export * from './minMax'
|
|
19
|
-
export * from './objectIncludes'
|
|
20
|
-
export * from './removeDuplicates'
|
|
1
|
+
export * from './callOrReturn.js'
|
|
2
|
+
export * from './createStyleTag.js'
|
|
3
|
+
export * from './deleteProps.js'
|
|
4
|
+
export * from './elementFromString.js'
|
|
5
|
+
export * from './escapeForRegEx.js'
|
|
6
|
+
export * from './findDuplicates.js'
|
|
7
|
+
export * from './fromString.js'
|
|
8
|
+
export * from './isEmptyObject.js'
|
|
9
|
+
export * from './isFunction.js'
|
|
10
|
+
export * from './isiOS.js'
|
|
11
|
+
export * from './isMacOS.js'
|
|
12
|
+
export * from './isNumber.js'
|
|
13
|
+
export * from './isPlainObject.js'
|
|
14
|
+
export * from './isRegExp.js'
|
|
15
|
+
export * from './isString.js'
|
|
16
|
+
export * from './mergeAttributes.js'
|
|
17
|
+
export * from './mergeDeep.js'
|
|
18
|
+
export * from './minMax.js'
|
|
19
|
+
export * from './objectIncludes.js'
|
|
20
|
+
export * from './removeDuplicates.js'
|
|
@@ -14,7 +14,14 @@ export function mergeAttributes(...objects: Record<string, any>[]): Record<strin
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
if (key === 'class') {
|
|
17
|
-
|
|
17
|
+
const valueClasses: string[] = value.split(' ')
|
|
18
|
+
const existingClasses: string[] = mergedAttributes[key].split(' ')
|
|
19
|
+
|
|
20
|
+
const insertClasses = valueClasses.filter(
|
|
21
|
+
valueClass => !existingClasses.includes(valueClass),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
mergedAttributes[key] = [...existingClasses, ...insertClasses].join(' ')
|
|
18
25
|
} else if (key === 'style') {
|
|
19
26
|
mergedAttributes[key] = [mergedAttributes[key], value].join('; ')
|
|
20
27
|
} else {
|