@tiptap/core 2.1.0-rc.11 → 2.1.0-rc.13
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 +336 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +323 -75
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +336 -78
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/commands/index.d.ts +2 -0
- 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/helpers/index.d.ts +1 -0
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +1 -1
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +20 -0
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
- 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/commands/cut.ts +11 -9
- package/src/commands/index.ts +2 -0
- package/src/commands/joinItemBackward.ts +36 -0
- package/src/commands/joinItemForward.ts +38 -0
- package/src/extensions/keymap.ts +2 -0
- package/src/helpers/index.ts +1 -0
- package/src/helpers/isAtEndOfNode.ts +20 -2
- package/src/inputRules/nodeInputRule.ts +49 -3
- package/src/utilities/createStyleTag.ts +3 -3
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Plugin, PluginKey, TextSelection, Selection, NodeSelection, EditorState
|
|
|
2
2
|
import { EditorView } from '@tiptap/pm/view';
|
|
3
3
|
import { keymap } from '@tiptap/pm/keymap';
|
|
4
4
|
import { Schema, Fragment, DOMParser, DOMSerializer, Node as Node$1, Slice } from '@tiptap/pm/model';
|
|
5
|
-
import { liftTarget, ReplaceStep, ReplaceAroundStep, Transform, canSplit, canJoin, findWrapping } from '@tiptap/pm/transform';
|
|
5
|
+
import { liftTarget, ReplaceStep, ReplaceAroundStep, joinPoint, Transform, canSplit, canJoin, findWrapping } from '@tiptap/pm/transform';
|
|
6
6
|
import { createParagraphNear as createParagraphNear$1, deleteSelection as deleteSelection$1, exitCode as exitCode$1, joinUp as joinUp$1, joinDown as joinDown$1, joinBackward as joinBackward$1, joinForward as joinForward$1, lift as lift$1, liftEmptyBlock as liftEmptyBlock$1, newlineInCode as newlineInCode$1, selectNodeBackward as selectNodeBackward$1, selectNodeForward as selectNodeForward$1, selectParentNode as selectParentNode$1, selectTextblockEnd as selectTextblockEnd$1, selectTextblockStart as selectTextblockStart$1, setBlockType, wrapIn as wrapIn$1 } from '@tiptap/pm/commands';
|
|
7
7
|
import { liftListItem as liftListItem$1, sinkListItem as sinkListItem$1, wrapInList as wrapInList$1 } from '@tiptap/pm/schema-list';
|
|
8
8
|
|
|
@@ -1305,17 +1305,14 @@ const createParagraphNear = () => ({ state, dispatch }) => {
|
|
|
1305
1305
|
return createParagraphNear$1(state, dispatch);
|
|
1306
1306
|
};
|
|
1307
1307
|
|
|
1308
|
-
const cut = (originRange, targetPos) => ({ editor }) => {
|
|
1308
|
+
const cut = (originRange, targetPos) => ({ editor, tr }) => {
|
|
1309
1309
|
const { state } = editor;
|
|
1310
1310
|
const contentSlice = state.doc.slice(originRange.from, originRange.to);
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
})
|
|
1317
|
-
.focus()
|
|
1318
|
-
.run();
|
|
1311
|
+
tr.deleteRange(originRange.from, originRange.to);
|
|
1312
|
+
const newPos = tr.mapping.map(targetPos);
|
|
1313
|
+
tr.insert(newPos, contentSlice.content);
|
|
1314
|
+
tr.setSelection(new TextSelection(tr.doc.resolve(newPos - 1)));
|
|
1315
|
+
return true;
|
|
1319
1316
|
};
|
|
1320
1317
|
|
|
1321
1318
|
const deleteCurrentNode = () => ({ tr, dispatch }) => {
|
|
@@ -1709,6 +1706,40 @@ const joinForward = () => ({ state, dispatch }) => {
|
|
|
1709
1706
|
return joinForward$1(state, dispatch);
|
|
1710
1707
|
};
|
|
1711
1708
|
|
|
1709
|
+
const joinItemBackward = () => ({ tr, state, dispatch, }) => {
|
|
1710
|
+
try {
|
|
1711
|
+
const point = joinPoint(state.doc, state.selection.$from.pos, -1);
|
|
1712
|
+
if (point === null || point === undefined) {
|
|
1713
|
+
return false;
|
|
1714
|
+
}
|
|
1715
|
+
tr.join(point, 2);
|
|
1716
|
+
if (dispatch) {
|
|
1717
|
+
dispatch(tr);
|
|
1718
|
+
}
|
|
1719
|
+
return true;
|
|
1720
|
+
}
|
|
1721
|
+
catch {
|
|
1722
|
+
return false;
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
|
|
1726
|
+
const joinItemForward = () => ({ state, dispatch, tr, }) => {
|
|
1727
|
+
try {
|
|
1728
|
+
const point = joinPoint(state.doc, state.selection.$from.pos, +1);
|
|
1729
|
+
if (point === null || point === undefined) {
|
|
1730
|
+
return false;
|
|
1731
|
+
}
|
|
1732
|
+
tr.join(point, 2);
|
|
1733
|
+
if (dispatch) {
|
|
1734
|
+
dispatch(tr);
|
|
1735
|
+
}
|
|
1736
|
+
return true;
|
|
1737
|
+
}
|
|
1738
|
+
catch (e) {
|
|
1739
|
+
return false;
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
|
|
1712
1743
|
function isMacOS() {
|
|
1713
1744
|
return typeof navigator !== 'undefined'
|
|
1714
1745
|
? /Mac/.test(navigator.platform)
|
|
@@ -1977,6 +2008,261 @@ function getMarkAttributes(state, typeOrName) {
|
|
|
1977
2008
|
return { ...mark.attrs };
|
|
1978
2009
|
}
|
|
1979
2010
|
|
|
2011
|
+
const findListItemPos = (typeOrName, state) => {
|
|
2012
|
+
const { $from } = state.selection;
|
|
2013
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
2014
|
+
let currentNode = null;
|
|
2015
|
+
let currentDepth = $from.depth;
|
|
2016
|
+
let currentPos = $from.pos;
|
|
2017
|
+
let targetDepth = null;
|
|
2018
|
+
while (currentDepth > 0 && targetDepth === null) {
|
|
2019
|
+
currentNode = $from.node(currentDepth);
|
|
2020
|
+
if (currentNode.type === nodeType) {
|
|
2021
|
+
targetDepth = currentDepth;
|
|
2022
|
+
}
|
|
2023
|
+
else {
|
|
2024
|
+
currentDepth -= 1;
|
|
2025
|
+
currentPos -= 1;
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
if (targetDepth === null) {
|
|
2029
|
+
return null;
|
|
2030
|
+
}
|
|
2031
|
+
return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
|
|
2032
|
+
};
|
|
2033
|
+
|
|
2034
|
+
/**
|
|
2035
|
+
* Finds the first node of a given type or name in the current selection.
|
|
2036
|
+
* @param state The editor state.
|
|
2037
|
+
* @param typeOrName The node type or name.
|
|
2038
|
+
* @param pos The position to start searching from.
|
|
2039
|
+
* @param maxDepth The maximum depth to search.
|
|
2040
|
+
* @returns The node and the depth as an array.
|
|
2041
|
+
*/
|
|
2042
|
+
const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
2043
|
+
const $pos = state.doc.resolve(pos);
|
|
2044
|
+
let currentDepth = maxDepth;
|
|
2045
|
+
let node = null;
|
|
2046
|
+
while (currentDepth > 0 && node === null) {
|
|
2047
|
+
const currentNode = $pos.node(currentDepth);
|
|
2048
|
+
if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
|
|
2049
|
+
node = currentNode;
|
|
2050
|
+
}
|
|
2051
|
+
else {
|
|
2052
|
+
currentDepth -= 1;
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
return [node, currentDepth];
|
|
2056
|
+
};
|
|
2057
|
+
|
|
2058
|
+
const getNextListDepth = (typeOrName, state) => {
|
|
2059
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2060
|
+
if (!listItemPos) {
|
|
2061
|
+
return false;
|
|
2062
|
+
}
|
|
2063
|
+
const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
|
|
2064
|
+
return depth;
|
|
2065
|
+
};
|
|
2066
|
+
|
|
2067
|
+
const isAtStartOfNode = (state) => {
|
|
2068
|
+
const { $from, $to } = state.selection;
|
|
2069
|
+
if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
|
|
2070
|
+
return false;
|
|
2071
|
+
}
|
|
2072
|
+
return true;
|
|
2073
|
+
};
|
|
2074
|
+
|
|
2075
|
+
const hasListBefore = (editorState, name, parentListTypes) => {
|
|
2076
|
+
const { $anchor } = editorState.selection;
|
|
2077
|
+
const previousNodePos = Math.max(0, $anchor.pos - 2);
|
|
2078
|
+
const previousNode = editorState.doc.resolve(previousNodePos).node();
|
|
2079
|
+
if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
|
|
2080
|
+
return false;
|
|
2081
|
+
}
|
|
2082
|
+
return true;
|
|
2083
|
+
};
|
|
2084
|
+
|
|
2085
|
+
const hasListItemBefore = (typeOrName, state) => {
|
|
2086
|
+
var _a;
|
|
2087
|
+
const { $anchor } = state.selection;
|
|
2088
|
+
const $targetPos = state.doc.resolve($anchor.pos - 2);
|
|
2089
|
+
if ($targetPos.index() === 0) {
|
|
2090
|
+
return false;
|
|
2091
|
+
}
|
|
2092
|
+
if (((_a = $targetPos.nodeBefore) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
|
|
2093
|
+
return false;
|
|
2094
|
+
}
|
|
2095
|
+
return true;
|
|
2096
|
+
};
|
|
2097
|
+
|
|
2098
|
+
const listItemHasSubList = (typeOrName, state, node) => {
|
|
2099
|
+
if (!node) {
|
|
2100
|
+
return false;
|
|
2101
|
+
}
|
|
2102
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
2103
|
+
let hasSubList = false;
|
|
2104
|
+
node.descendants(child => {
|
|
2105
|
+
if (child.type === nodeType) {
|
|
2106
|
+
hasSubList = true;
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
return hasSubList;
|
|
2110
|
+
};
|
|
2111
|
+
|
|
2112
|
+
const handleBackspace = (editor, name, parentListTypes) => {
|
|
2113
|
+
// this is required to still handle the undo handling
|
|
2114
|
+
if (editor.commands.undoInputRule()) {
|
|
2115
|
+
return true;
|
|
2116
|
+
}
|
|
2117
|
+
// if the current item is NOT inside a list item &
|
|
2118
|
+
// the previous item is a list (orderedList or bulletList)
|
|
2119
|
+
// move the cursor into the list and delete the current item
|
|
2120
|
+
if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
|
|
2121
|
+
const { $anchor } = editor.state.selection;
|
|
2122
|
+
const $listPos = editor.state.doc.resolve($anchor.before() - 1);
|
|
2123
|
+
const listDescendants = [];
|
|
2124
|
+
$listPos.node().descendants((node, pos) => {
|
|
2125
|
+
if (node.type.name === name) {
|
|
2126
|
+
listDescendants.push({ node, pos });
|
|
2127
|
+
}
|
|
2128
|
+
});
|
|
2129
|
+
const lastItem = listDescendants.at(-1);
|
|
2130
|
+
if (!lastItem) {
|
|
2131
|
+
return false;
|
|
2132
|
+
}
|
|
2133
|
+
const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
|
|
2134
|
+
return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
|
|
2135
|
+
}
|
|
2136
|
+
// if the cursor is not inside the current node type
|
|
2137
|
+
// do nothing and proceed
|
|
2138
|
+
if (!isNodeActive(editor.state, name)) {
|
|
2139
|
+
return false;
|
|
2140
|
+
}
|
|
2141
|
+
// if the cursor is not at the start of a node
|
|
2142
|
+
// do nothing and proceed
|
|
2143
|
+
if (!isAtStartOfNode(editor.state)) {
|
|
2144
|
+
return false;
|
|
2145
|
+
}
|
|
2146
|
+
const listItemPos = findListItemPos(name, editor.state);
|
|
2147
|
+
if (!listItemPos) {
|
|
2148
|
+
return false;
|
|
2149
|
+
}
|
|
2150
|
+
const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
|
|
2151
|
+
const prevNode = $prev.node(listItemPos.depth);
|
|
2152
|
+
const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
|
|
2153
|
+
// if the previous item is a list item and doesn't have a sublist, join the list items
|
|
2154
|
+
if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
|
|
2155
|
+
return editor.commands.joinItemBackward();
|
|
2156
|
+
}
|
|
2157
|
+
// otherwise in the end, a backspace should
|
|
2158
|
+
// always just lift the list item if
|
|
2159
|
+
// joining / merging is not possible
|
|
2160
|
+
return editor.chain().liftListItem(name).run();
|
|
2161
|
+
};
|
|
2162
|
+
|
|
2163
|
+
function findParentNodeClosestToPos($pos, predicate) {
|
|
2164
|
+
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2165
|
+
const node = $pos.node(i);
|
|
2166
|
+
if (predicate(node)) {
|
|
2167
|
+
return {
|
|
2168
|
+
pos: i > 0 ? $pos.before(i) : 0,
|
|
2169
|
+
start: $pos.start(i),
|
|
2170
|
+
depth: i,
|
|
2171
|
+
node,
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
function findParentNode(predicate) {
|
|
2178
|
+
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
const isAtEndOfNode = (state, nodeType) => {
|
|
2182
|
+
const { $from, $to, $anchor } = state.selection;
|
|
2183
|
+
if (nodeType) {
|
|
2184
|
+
const parentNode = findParentNode(node => node.type.name === nodeType)(state.selection);
|
|
2185
|
+
if (!parentNode) {
|
|
2186
|
+
return false;
|
|
2187
|
+
}
|
|
2188
|
+
const $parentPos = state.doc.resolve(parentNode.pos + 1);
|
|
2189
|
+
if ($anchor.pos + 1 === $parentPos.end()) {
|
|
2190
|
+
return true;
|
|
2191
|
+
}
|
|
2192
|
+
return false;
|
|
2193
|
+
}
|
|
2194
|
+
if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
|
|
2195
|
+
return false;
|
|
2196
|
+
}
|
|
2197
|
+
return true;
|
|
2198
|
+
};
|
|
2199
|
+
|
|
2200
|
+
const nextListIsDeeper = (typeOrName, state) => {
|
|
2201
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
2202
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2203
|
+
if (!listItemPos || !listDepth) {
|
|
2204
|
+
return false;
|
|
2205
|
+
}
|
|
2206
|
+
if (listDepth > listItemPos.depth) {
|
|
2207
|
+
return true;
|
|
2208
|
+
}
|
|
2209
|
+
return false;
|
|
2210
|
+
};
|
|
2211
|
+
|
|
2212
|
+
const nextListIsHigher = (typeOrName, state) => {
|
|
2213
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
2214
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2215
|
+
if (!listItemPos || !listDepth) {
|
|
2216
|
+
return false;
|
|
2217
|
+
}
|
|
2218
|
+
if (listDepth < listItemPos.depth) {
|
|
2219
|
+
return true;
|
|
2220
|
+
}
|
|
2221
|
+
return false;
|
|
2222
|
+
};
|
|
2223
|
+
|
|
2224
|
+
const handleDelete = (editor, name) => {
|
|
2225
|
+
// if the cursor is not inside the current node type
|
|
2226
|
+
// do nothing and proceed
|
|
2227
|
+
if (!isNodeActive(editor.state, name)) {
|
|
2228
|
+
return false;
|
|
2229
|
+
}
|
|
2230
|
+
// if the cursor is not at the end of a node
|
|
2231
|
+
// do nothing and proceed
|
|
2232
|
+
if (!isAtEndOfNode(editor.state, name)) {
|
|
2233
|
+
return false;
|
|
2234
|
+
}
|
|
2235
|
+
// check if the next node is a list with a deeper depth
|
|
2236
|
+
if (nextListIsDeeper(name, editor.state)) {
|
|
2237
|
+
return editor
|
|
2238
|
+
.chain()
|
|
2239
|
+
.focus(editor.state.selection.from + 4)
|
|
2240
|
+
.lift(name)
|
|
2241
|
+
.joinBackward()
|
|
2242
|
+
.run();
|
|
2243
|
+
}
|
|
2244
|
+
if (nextListIsHigher(name, editor.state)) {
|
|
2245
|
+
return editor.chain()
|
|
2246
|
+
.joinForward()
|
|
2247
|
+
.joinBackward()
|
|
2248
|
+
.run();
|
|
2249
|
+
}
|
|
2250
|
+
return editor.commands.joinItemForward();
|
|
2251
|
+
};
|
|
2252
|
+
|
|
2253
|
+
const hasListItemAfter = (typeOrName, state) => {
|
|
2254
|
+
var _a;
|
|
2255
|
+
const { $anchor } = state.selection;
|
|
2256
|
+
const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
|
|
2257
|
+
if ($targetPos.index() === $targetPos.parent.childCount - 1) {
|
|
2258
|
+
return false;
|
|
2259
|
+
}
|
|
2260
|
+
if (((_a = $targetPos.nodeAfter) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
|
|
2261
|
+
return false;
|
|
2262
|
+
}
|
|
2263
|
+
return true;
|
|
2264
|
+
};
|
|
2265
|
+
|
|
1980
2266
|
/**
|
|
1981
2267
|
* Returns a new `Transform` based on all steps of the passed transactions.
|
|
1982
2268
|
*/
|
|
@@ -2038,24 +2324,6 @@ function findChildrenInRange(node, range, predicate) {
|
|
|
2038
2324
|
return nodesWithPos;
|
|
2039
2325
|
}
|
|
2040
2326
|
|
|
2041
|
-
function findParentNodeClosestToPos($pos, predicate) {
|
|
2042
|
-
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2043
|
-
const node = $pos.node(i);
|
|
2044
|
-
if (predicate(node)) {
|
|
2045
|
-
return {
|
|
2046
|
-
pos: i > 0 ? $pos.before(i) : 0,
|
|
2047
|
-
start: $pos.start(i),
|
|
2048
|
-
depth: i,
|
|
2049
|
-
node,
|
|
2050
|
-
};
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
function findParentNode(predicate) {
|
|
2056
|
-
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
2327
|
function getHTMLFromFragment(fragment, schema) {
|
|
2060
2328
|
const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
|
|
2061
2329
|
const temporaryDocument = document.implementation.createHTMLDocument();
|
|
@@ -2273,30 +2541,6 @@ function getMarksBetween(from, to, doc) {
|
|
|
2273
2541
|
return marks;
|
|
2274
2542
|
}
|
|
2275
2543
|
|
|
2276
|
-
/**
|
|
2277
|
-
* Finds the first node of a given type or name in the current selection.
|
|
2278
|
-
* @param state The editor state.
|
|
2279
|
-
* @param typeOrName The node type or name.
|
|
2280
|
-
* @param pos The position to start searching from.
|
|
2281
|
-
* @param maxDepth The maximum depth to search.
|
|
2282
|
-
* @returns The node and the depth as an array.
|
|
2283
|
-
*/
|
|
2284
|
-
const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
2285
|
-
const $pos = state.doc.resolve(pos);
|
|
2286
|
-
let currentDepth = maxDepth;
|
|
2287
|
-
let node = null;
|
|
2288
|
-
while (currentDepth > 0 && node === null) {
|
|
2289
|
-
const currentNode = $pos.node(currentDepth);
|
|
2290
|
-
if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
|
|
2291
|
-
node = currentNode;
|
|
2292
|
-
}
|
|
2293
|
-
else {
|
|
2294
|
-
currentDepth -= 1;
|
|
2295
|
-
}
|
|
2296
|
-
}
|
|
2297
|
-
return [node, currentDepth];
|
|
2298
|
-
};
|
|
2299
|
-
|
|
2300
2544
|
function getSplittedAttributes(extensionAttributes, typeName, attributes) {
|
|
2301
2545
|
return Object.fromEntries(Object
|
|
2302
2546
|
.entries(attributes)
|
|
@@ -2387,22 +2631,6 @@ function isActive(state, name, attributes = {}) {
|
|
|
2387
2631
|
return false;
|
|
2388
2632
|
}
|
|
2389
2633
|
|
|
2390
|
-
const istAtEndOfNode = (state) => {
|
|
2391
|
-
const { $from, $to } = state.selection;
|
|
2392
|
-
if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
|
|
2393
|
-
return false;
|
|
2394
|
-
}
|
|
2395
|
-
return true;
|
|
2396
|
-
};
|
|
2397
|
-
|
|
2398
|
-
const isAtStartOfNode = (state) => {
|
|
2399
|
-
const { $from, $to } = state.selection;
|
|
2400
|
-
if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
|
|
2401
|
-
return false;
|
|
2402
|
-
}
|
|
2403
|
-
return true;
|
|
2404
|
-
};
|
|
2405
|
-
|
|
2406
2634
|
function isList(name, extensions) {
|
|
2407
2635
|
const { nodeExtensions } = splitExtensions(extensions);
|
|
2408
2636
|
const extension = nodeExtensions.find(item => item.name === name);
|
|
@@ -3027,6 +3255,8 @@ var commands = /*#__PURE__*/Object.freeze({
|
|
|
3027
3255
|
joinDown: joinDown,
|
|
3028
3256
|
joinBackward: joinBackward,
|
|
3029
3257
|
joinForward: joinForward,
|
|
3258
|
+
joinItemBackward: joinItemBackward,
|
|
3259
|
+
joinItemForward: joinItemForward,
|
|
3030
3260
|
keyboardShortcut: keyboardShortcut,
|
|
3031
3261
|
lift: lift,
|
|
3032
3262
|
liftEmptyBlock: liftEmptyBlock,
|
|
@@ -3328,8 +3558,8 @@ img.ProseMirror-separator {
|
|
|
3328
3558
|
opacity: 0
|
|
3329
3559
|
}`;
|
|
3330
3560
|
|
|
3331
|
-
function createStyleTag(style, nonce) {
|
|
3332
|
-
const tiptapStyleTag = document.querySelector(
|
|
3561
|
+
function createStyleTag(style, nonce, suffix) {
|
|
3562
|
+
const tiptapStyleTag = document.querySelector(`style[data-tiptap-style${suffix ? `-${suffix}` : ''}]`);
|
|
3333
3563
|
if (tiptapStyleTag !== null) {
|
|
3334
3564
|
return tiptapStyleTag;
|
|
3335
3565
|
}
|
|
@@ -3337,7 +3567,7 @@ function createStyleTag(style, nonce) {
|
|
|
3337
3567
|
if (nonce) {
|
|
3338
3568
|
styleNode.setAttribute('nonce', nonce);
|
|
3339
3569
|
}
|
|
3340
|
-
styleNode.setAttribute(
|
|
3570
|
+
styleNode.setAttribute(`data-tiptap-style${suffix ? `-${suffix}` : ''}`, '');
|
|
3341
3571
|
styleNode.innerHTML = style;
|
|
3342
3572
|
document.getElementsByTagName('head')[0].appendChild(styleNode);
|
|
3343
3573
|
return styleNode;
|
|
@@ -3750,10 +3980,12 @@ function nodeInputRule(config) {
|
|
|
3750
3980
|
return new InputRule({
|
|
3751
3981
|
find: config.find,
|
|
3752
3982
|
handler: ({ state, range, match }) => {
|
|
3983
|
+
var _a;
|
|
3753
3984
|
const attributes = callOrReturn(config.getAttributes, undefined, match) || {};
|
|
3754
3985
|
const { tr } = state;
|
|
3755
|
-
const start = range.from;
|
|
3986
|
+
const start = config.blockReplace ? range.from - 1 : range.from;
|
|
3756
3987
|
let end = range.to;
|
|
3988
|
+
const newNode = config.type.create(attributes);
|
|
3757
3989
|
if (match[1]) {
|
|
3758
3990
|
const offset = match[0].lastIndexOf(match[1]);
|
|
3759
3991
|
let matchStart = start + offset;
|
|
@@ -3767,10 +3999,26 @@ function nodeInputRule(config) {
|
|
|
3767
3999
|
const lastChar = match[0][match[0].length - 1];
|
|
3768
4000
|
tr.insertText(lastChar, start + match[0].length - 1);
|
|
3769
4001
|
// insert node from input rule
|
|
3770
|
-
tr.replaceWith(matchStart, end,
|
|
4002
|
+
tr.replaceWith(matchStart, end, newNode);
|
|
3771
4003
|
}
|
|
3772
4004
|
else if (match[0]) {
|
|
3773
|
-
tr.replaceWith(start, end,
|
|
4005
|
+
tr.replaceWith(start, end, newNode);
|
|
4006
|
+
}
|
|
4007
|
+
if (config.blockReplace && config.addExtraNewline) {
|
|
4008
|
+
const { $to } = tr.selection;
|
|
4009
|
+
const posAfter = $to.end();
|
|
4010
|
+
if ($to.nodeAfter) {
|
|
4011
|
+
tr.setSelection(TextSelection.create(tr.doc, $to.pos));
|
|
4012
|
+
}
|
|
4013
|
+
else {
|
|
4014
|
+
// add node after horizontal rule if it’s the end of the document
|
|
4015
|
+
const node = (_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create();
|
|
4016
|
+
if (node) {
|
|
4017
|
+
tr.insert(posAfter, node);
|
|
4018
|
+
tr.setSelection(TextSelection.create(tr.doc, posAfter));
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
4021
|
+
tr.scrollIntoView();
|
|
3774
4022
|
}
|
|
3775
4023
|
},
|
|
3776
4024
|
});
|
|
@@ -4337,5 +4585,5 @@ class Tracker {
|
|
|
4337
4585
|
}
|
|
4338
4586
|
}
|
|
4339
4587
|
|
|
4340
|
-
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAtPosition, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, injectExtensionAttributesToParseRule, inputRulesPlugin, isActive, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS,
|
|
4588
|
+
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, extensions, findChildren, findChildrenInRange, findDuplicates, findListItemPos, findParentNode, findParentNodeClosestToPos, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNextListDepth, getNodeAtPosition, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, handleBackspace, handleDelete, hasListBefore, hasListItemAfter, hasListItemBefore, injectExtensionAttributesToParseRule, inputRulesPlugin, isActive, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, listItemHasSubList, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nextListIsDeeper, nextListIsHigher, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, resolveFocusPosition, selectionToInsertionEnd, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
|
|
4341
4589
|
//# sourceMappingURL=index.js.map
|