@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.cjs
CHANGED
|
@@ -1309,17 +1309,14 @@ const createParagraphNear = () => ({ state, dispatch }) => {
|
|
|
1309
1309
|
return commands$1.createParagraphNear(state, dispatch);
|
|
1310
1310
|
};
|
|
1311
1311
|
|
|
1312
|
-
const cut = (originRange, targetPos) => ({ editor }) => {
|
|
1313
|
-
const { state } = editor;
|
|
1314
|
-
const contentSlice = state.doc.slice(originRange.from, originRange.to);
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
})
|
|
1321
|
-
.focus()
|
|
1322
|
-
.run();
|
|
1312
|
+
const cut = (originRange, targetPos) => ({ editor, tr }) => {
|
|
1313
|
+
const { state: state$1 } = editor;
|
|
1314
|
+
const contentSlice = state$1.doc.slice(originRange.from, originRange.to);
|
|
1315
|
+
tr.deleteRange(originRange.from, originRange.to);
|
|
1316
|
+
const newPos = tr.mapping.map(targetPos);
|
|
1317
|
+
tr.insert(newPos, contentSlice.content);
|
|
1318
|
+
tr.setSelection(new state.TextSelection(tr.doc.resolve(newPos - 1)));
|
|
1319
|
+
return true;
|
|
1323
1320
|
};
|
|
1324
1321
|
|
|
1325
1322
|
const deleteCurrentNode = () => ({ tr, dispatch }) => {
|
|
@@ -1713,6 +1710,40 @@ const joinForward = () => ({ state, dispatch }) => {
|
|
|
1713
1710
|
return commands$1.joinForward(state, dispatch);
|
|
1714
1711
|
};
|
|
1715
1712
|
|
|
1713
|
+
const joinItemBackward = () => ({ tr, state, dispatch, }) => {
|
|
1714
|
+
try {
|
|
1715
|
+
const point = transform.joinPoint(state.doc, state.selection.$from.pos, -1);
|
|
1716
|
+
if (point === null || point === undefined) {
|
|
1717
|
+
return false;
|
|
1718
|
+
}
|
|
1719
|
+
tr.join(point, 2);
|
|
1720
|
+
if (dispatch) {
|
|
1721
|
+
dispatch(tr);
|
|
1722
|
+
}
|
|
1723
|
+
return true;
|
|
1724
|
+
}
|
|
1725
|
+
catch {
|
|
1726
|
+
return false;
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
|
|
1730
|
+
const joinItemForward = () => ({ state, dispatch, tr, }) => {
|
|
1731
|
+
try {
|
|
1732
|
+
const point = transform.joinPoint(state.doc, state.selection.$from.pos, +1);
|
|
1733
|
+
if (point === null || point === undefined) {
|
|
1734
|
+
return false;
|
|
1735
|
+
}
|
|
1736
|
+
tr.join(point, 2);
|
|
1737
|
+
if (dispatch) {
|
|
1738
|
+
dispatch(tr);
|
|
1739
|
+
}
|
|
1740
|
+
return true;
|
|
1741
|
+
}
|
|
1742
|
+
catch (e) {
|
|
1743
|
+
return false;
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
|
|
1716
1747
|
function isMacOS() {
|
|
1717
1748
|
return typeof navigator !== 'undefined'
|
|
1718
1749
|
? /Mac/.test(navigator.platform)
|
|
@@ -1981,6 +2012,261 @@ function getMarkAttributes(state, typeOrName) {
|
|
|
1981
2012
|
return { ...mark.attrs };
|
|
1982
2013
|
}
|
|
1983
2014
|
|
|
2015
|
+
const findListItemPos = (typeOrName, state) => {
|
|
2016
|
+
const { $from } = state.selection;
|
|
2017
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
2018
|
+
let currentNode = null;
|
|
2019
|
+
let currentDepth = $from.depth;
|
|
2020
|
+
let currentPos = $from.pos;
|
|
2021
|
+
let targetDepth = null;
|
|
2022
|
+
while (currentDepth > 0 && targetDepth === null) {
|
|
2023
|
+
currentNode = $from.node(currentDepth);
|
|
2024
|
+
if (currentNode.type === nodeType) {
|
|
2025
|
+
targetDepth = currentDepth;
|
|
2026
|
+
}
|
|
2027
|
+
else {
|
|
2028
|
+
currentDepth -= 1;
|
|
2029
|
+
currentPos -= 1;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
if (targetDepth === null) {
|
|
2033
|
+
return null;
|
|
2034
|
+
}
|
|
2035
|
+
return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
|
|
2036
|
+
};
|
|
2037
|
+
|
|
2038
|
+
/**
|
|
2039
|
+
* Finds the first node of a given type or name in the current selection.
|
|
2040
|
+
* @param state The editor state.
|
|
2041
|
+
* @param typeOrName The node type or name.
|
|
2042
|
+
* @param pos The position to start searching from.
|
|
2043
|
+
* @param maxDepth The maximum depth to search.
|
|
2044
|
+
* @returns The node and the depth as an array.
|
|
2045
|
+
*/
|
|
2046
|
+
const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
2047
|
+
const $pos = state.doc.resolve(pos);
|
|
2048
|
+
let currentDepth = maxDepth;
|
|
2049
|
+
let node = null;
|
|
2050
|
+
while (currentDepth > 0 && node === null) {
|
|
2051
|
+
const currentNode = $pos.node(currentDepth);
|
|
2052
|
+
if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
|
|
2053
|
+
node = currentNode;
|
|
2054
|
+
}
|
|
2055
|
+
else {
|
|
2056
|
+
currentDepth -= 1;
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
return [node, currentDepth];
|
|
2060
|
+
};
|
|
2061
|
+
|
|
2062
|
+
const getNextListDepth = (typeOrName, state) => {
|
|
2063
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2064
|
+
if (!listItemPos) {
|
|
2065
|
+
return false;
|
|
2066
|
+
}
|
|
2067
|
+
const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
|
|
2068
|
+
return depth;
|
|
2069
|
+
};
|
|
2070
|
+
|
|
2071
|
+
const isAtStartOfNode = (state) => {
|
|
2072
|
+
const { $from, $to } = state.selection;
|
|
2073
|
+
if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
|
|
2074
|
+
return false;
|
|
2075
|
+
}
|
|
2076
|
+
return true;
|
|
2077
|
+
};
|
|
2078
|
+
|
|
2079
|
+
const hasListBefore = (editorState, name, parentListTypes) => {
|
|
2080
|
+
const { $anchor } = editorState.selection;
|
|
2081
|
+
const previousNodePos = Math.max(0, $anchor.pos - 2);
|
|
2082
|
+
const previousNode = editorState.doc.resolve(previousNodePos).node();
|
|
2083
|
+
if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
|
|
2084
|
+
return false;
|
|
2085
|
+
}
|
|
2086
|
+
return true;
|
|
2087
|
+
};
|
|
2088
|
+
|
|
2089
|
+
const hasListItemBefore = (typeOrName, state) => {
|
|
2090
|
+
var _a;
|
|
2091
|
+
const { $anchor } = state.selection;
|
|
2092
|
+
const $targetPos = state.doc.resolve($anchor.pos - 2);
|
|
2093
|
+
if ($targetPos.index() === 0) {
|
|
2094
|
+
return false;
|
|
2095
|
+
}
|
|
2096
|
+
if (((_a = $targetPos.nodeBefore) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
|
|
2097
|
+
return false;
|
|
2098
|
+
}
|
|
2099
|
+
return true;
|
|
2100
|
+
};
|
|
2101
|
+
|
|
2102
|
+
const listItemHasSubList = (typeOrName, state, node) => {
|
|
2103
|
+
if (!node) {
|
|
2104
|
+
return false;
|
|
2105
|
+
}
|
|
2106
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
2107
|
+
let hasSubList = false;
|
|
2108
|
+
node.descendants(child => {
|
|
2109
|
+
if (child.type === nodeType) {
|
|
2110
|
+
hasSubList = true;
|
|
2111
|
+
}
|
|
2112
|
+
});
|
|
2113
|
+
return hasSubList;
|
|
2114
|
+
};
|
|
2115
|
+
|
|
2116
|
+
const handleBackspace = (editor, name, parentListTypes) => {
|
|
2117
|
+
// this is required to still handle the undo handling
|
|
2118
|
+
if (editor.commands.undoInputRule()) {
|
|
2119
|
+
return true;
|
|
2120
|
+
}
|
|
2121
|
+
// if the current item is NOT inside a list item &
|
|
2122
|
+
// the previous item is a list (orderedList or bulletList)
|
|
2123
|
+
// move the cursor into the list and delete the current item
|
|
2124
|
+
if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
|
|
2125
|
+
const { $anchor } = editor.state.selection;
|
|
2126
|
+
const $listPos = editor.state.doc.resolve($anchor.before() - 1);
|
|
2127
|
+
const listDescendants = [];
|
|
2128
|
+
$listPos.node().descendants((node, pos) => {
|
|
2129
|
+
if (node.type.name === name) {
|
|
2130
|
+
listDescendants.push({ node, pos });
|
|
2131
|
+
}
|
|
2132
|
+
});
|
|
2133
|
+
const lastItem = listDescendants.at(-1);
|
|
2134
|
+
if (!lastItem) {
|
|
2135
|
+
return false;
|
|
2136
|
+
}
|
|
2137
|
+
const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
|
|
2138
|
+
return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
|
|
2139
|
+
}
|
|
2140
|
+
// if the cursor is not inside the current node type
|
|
2141
|
+
// do nothing and proceed
|
|
2142
|
+
if (!isNodeActive(editor.state, name)) {
|
|
2143
|
+
return false;
|
|
2144
|
+
}
|
|
2145
|
+
// if the cursor is not at the start of a node
|
|
2146
|
+
// do nothing and proceed
|
|
2147
|
+
if (!isAtStartOfNode(editor.state)) {
|
|
2148
|
+
return false;
|
|
2149
|
+
}
|
|
2150
|
+
const listItemPos = findListItemPos(name, editor.state);
|
|
2151
|
+
if (!listItemPos) {
|
|
2152
|
+
return false;
|
|
2153
|
+
}
|
|
2154
|
+
const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
|
|
2155
|
+
const prevNode = $prev.node(listItemPos.depth);
|
|
2156
|
+
const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
|
|
2157
|
+
// if the previous item is a list item and doesn't have a sublist, join the list items
|
|
2158
|
+
if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
|
|
2159
|
+
return editor.commands.joinItemBackward();
|
|
2160
|
+
}
|
|
2161
|
+
// otherwise in the end, a backspace should
|
|
2162
|
+
// always just lift the list item if
|
|
2163
|
+
// joining / merging is not possible
|
|
2164
|
+
return editor.chain().liftListItem(name).run();
|
|
2165
|
+
};
|
|
2166
|
+
|
|
2167
|
+
function findParentNodeClosestToPos($pos, predicate) {
|
|
2168
|
+
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2169
|
+
const node = $pos.node(i);
|
|
2170
|
+
if (predicate(node)) {
|
|
2171
|
+
return {
|
|
2172
|
+
pos: i > 0 ? $pos.before(i) : 0,
|
|
2173
|
+
start: $pos.start(i),
|
|
2174
|
+
depth: i,
|
|
2175
|
+
node,
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
function findParentNode(predicate) {
|
|
2182
|
+
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
const isAtEndOfNode = (state, nodeType) => {
|
|
2186
|
+
const { $from, $to, $anchor } = state.selection;
|
|
2187
|
+
if (nodeType) {
|
|
2188
|
+
const parentNode = findParentNode(node => node.type.name === nodeType)(state.selection);
|
|
2189
|
+
if (!parentNode) {
|
|
2190
|
+
return false;
|
|
2191
|
+
}
|
|
2192
|
+
const $parentPos = state.doc.resolve(parentNode.pos + 1);
|
|
2193
|
+
if ($anchor.pos + 1 === $parentPos.end()) {
|
|
2194
|
+
return true;
|
|
2195
|
+
}
|
|
2196
|
+
return false;
|
|
2197
|
+
}
|
|
2198
|
+
if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
|
|
2199
|
+
return false;
|
|
2200
|
+
}
|
|
2201
|
+
return true;
|
|
2202
|
+
};
|
|
2203
|
+
|
|
2204
|
+
const nextListIsDeeper = (typeOrName, state) => {
|
|
2205
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
2206
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2207
|
+
if (!listItemPos || !listDepth) {
|
|
2208
|
+
return false;
|
|
2209
|
+
}
|
|
2210
|
+
if (listDepth > listItemPos.depth) {
|
|
2211
|
+
return true;
|
|
2212
|
+
}
|
|
2213
|
+
return false;
|
|
2214
|
+
};
|
|
2215
|
+
|
|
2216
|
+
const nextListIsHigher = (typeOrName, state) => {
|
|
2217
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
2218
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2219
|
+
if (!listItemPos || !listDepth) {
|
|
2220
|
+
return false;
|
|
2221
|
+
}
|
|
2222
|
+
if (listDepth < listItemPos.depth) {
|
|
2223
|
+
return true;
|
|
2224
|
+
}
|
|
2225
|
+
return false;
|
|
2226
|
+
};
|
|
2227
|
+
|
|
2228
|
+
const handleDelete = (editor, name) => {
|
|
2229
|
+
// if the cursor is not inside the current node type
|
|
2230
|
+
// do nothing and proceed
|
|
2231
|
+
if (!isNodeActive(editor.state, name)) {
|
|
2232
|
+
return false;
|
|
2233
|
+
}
|
|
2234
|
+
// if the cursor is not at the end of a node
|
|
2235
|
+
// do nothing and proceed
|
|
2236
|
+
if (!isAtEndOfNode(editor.state, name)) {
|
|
2237
|
+
return false;
|
|
2238
|
+
}
|
|
2239
|
+
// check if the next node is a list with a deeper depth
|
|
2240
|
+
if (nextListIsDeeper(name, editor.state)) {
|
|
2241
|
+
return editor
|
|
2242
|
+
.chain()
|
|
2243
|
+
.focus(editor.state.selection.from + 4)
|
|
2244
|
+
.lift(name)
|
|
2245
|
+
.joinBackward()
|
|
2246
|
+
.run();
|
|
2247
|
+
}
|
|
2248
|
+
if (nextListIsHigher(name, editor.state)) {
|
|
2249
|
+
return editor.chain()
|
|
2250
|
+
.joinForward()
|
|
2251
|
+
.joinBackward()
|
|
2252
|
+
.run();
|
|
2253
|
+
}
|
|
2254
|
+
return editor.commands.joinItemForward();
|
|
2255
|
+
};
|
|
2256
|
+
|
|
2257
|
+
const hasListItemAfter = (typeOrName, state) => {
|
|
2258
|
+
var _a;
|
|
2259
|
+
const { $anchor } = state.selection;
|
|
2260
|
+
const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
|
|
2261
|
+
if ($targetPos.index() === $targetPos.parent.childCount - 1) {
|
|
2262
|
+
return false;
|
|
2263
|
+
}
|
|
2264
|
+
if (((_a = $targetPos.nodeAfter) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
|
|
2265
|
+
return false;
|
|
2266
|
+
}
|
|
2267
|
+
return true;
|
|
2268
|
+
};
|
|
2269
|
+
|
|
1984
2270
|
/**
|
|
1985
2271
|
* Returns a new `Transform` based on all steps of the passed transactions.
|
|
1986
2272
|
*/
|
|
@@ -2042,24 +2328,6 @@ function findChildrenInRange(node, range, predicate) {
|
|
|
2042
2328
|
return nodesWithPos;
|
|
2043
2329
|
}
|
|
2044
2330
|
|
|
2045
|
-
function findParentNodeClosestToPos($pos, predicate) {
|
|
2046
|
-
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2047
|
-
const node = $pos.node(i);
|
|
2048
|
-
if (predicate(node)) {
|
|
2049
|
-
return {
|
|
2050
|
-
pos: i > 0 ? $pos.before(i) : 0,
|
|
2051
|
-
start: $pos.start(i),
|
|
2052
|
-
depth: i,
|
|
2053
|
-
node,
|
|
2054
|
-
};
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
function findParentNode(predicate) {
|
|
2060
|
-
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
2331
|
function getHTMLFromFragment(fragment, schema) {
|
|
2064
2332
|
const documentFragment = model.DOMSerializer.fromSchema(schema).serializeFragment(fragment);
|
|
2065
2333
|
const temporaryDocument = document.implementation.createHTMLDocument();
|
|
@@ -2277,30 +2545,6 @@ function getMarksBetween(from, to, doc) {
|
|
|
2277
2545
|
return marks;
|
|
2278
2546
|
}
|
|
2279
2547
|
|
|
2280
|
-
/**
|
|
2281
|
-
* Finds the first node of a given type or name in the current selection.
|
|
2282
|
-
* @param state The editor state.
|
|
2283
|
-
* @param typeOrName The node type or name.
|
|
2284
|
-
* @param pos The position to start searching from.
|
|
2285
|
-
* @param maxDepth The maximum depth to search.
|
|
2286
|
-
* @returns The node and the depth as an array.
|
|
2287
|
-
*/
|
|
2288
|
-
const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
2289
|
-
const $pos = state.doc.resolve(pos);
|
|
2290
|
-
let currentDepth = maxDepth;
|
|
2291
|
-
let node = null;
|
|
2292
|
-
while (currentDepth > 0 && node === null) {
|
|
2293
|
-
const currentNode = $pos.node(currentDepth);
|
|
2294
|
-
if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
|
|
2295
|
-
node = currentNode;
|
|
2296
|
-
}
|
|
2297
|
-
else {
|
|
2298
|
-
currentDepth -= 1;
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
return [node, currentDepth];
|
|
2302
|
-
};
|
|
2303
|
-
|
|
2304
2548
|
function getSplittedAttributes(extensionAttributes, typeName, attributes) {
|
|
2305
2549
|
return Object.fromEntries(Object
|
|
2306
2550
|
.entries(attributes)
|
|
@@ -2391,22 +2635,6 @@ function isActive(state, name, attributes = {}) {
|
|
|
2391
2635
|
return false;
|
|
2392
2636
|
}
|
|
2393
2637
|
|
|
2394
|
-
const istAtEndOfNode = (state) => {
|
|
2395
|
-
const { $from, $to } = state.selection;
|
|
2396
|
-
if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
|
|
2397
|
-
return false;
|
|
2398
|
-
}
|
|
2399
|
-
return true;
|
|
2400
|
-
};
|
|
2401
|
-
|
|
2402
|
-
const isAtStartOfNode = (state) => {
|
|
2403
|
-
const { $from, $to } = state.selection;
|
|
2404
|
-
if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
|
|
2405
|
-
return false;
|
|
2406
|
-
}
|
|
2407
|
-
return true;
|
|
2408
|
-
};
|
|
2409
|
-
|
|
2410
2638
|
function isList(name, extensions) {
|
|
2411
2639
|
const { nodeExtensions } = splitExtensions(extensions);
|
|
2412
2640
|
const extension = nodeExtensions.find(item => item.name === name);
|
|
@@ -3031,6 +3259,8 @@ var commands = /*#__PURE__*/Object.freeze({
|
|
|
3031
3259
|
joinDown: joinDown,
|
|
3032
3260
|
joinBackward: joinBackward,
|
|
3033
3261
|
joinForward: joinForward,
|
|
3262
|
+
joinItemBackward: joinItemBackward,
|
|
3263
|
+
joinItemForward: joinItemForward,
|
|
3034
3264
|
keyboardShortcut: keyboardShortcut,
|
|
3035
3265
|
lift: lift,
|
|
3036
3266
|
liftEmptyBlock: liftEmptyBlock,
|
|
@@ -3332,8 +3562,8 @@ img.ProseMirror-separator {
|
|
|
3332
3562
|
opacity: 0
|
|
3333
3563
|
}`;
|
|
3334
3564
|
|
|
3335
|
-
function createStyleTag(style, nonce) {
|
|
3336
|
-
const tiptapStyleTag = document.querySelector(
|
|
3565
|
+
function createStyleTag(style, nonce, suffix) {
|
|
3566
|
+
const tiptapStyleTag = document.querySelector(`style[data-tiptap-style${suffix ? `-${suffix}` : ''}]`);
|
|
3337
3567
|
if (tiptapStyleTag !== null) {
|
|
3338
3568
|
return tiptapStyleTag;
|
|
3339
3569
|
}
|
|
@@ -3341,7 +3571,7 @@ function createStyleTag(style, nonce) {
|
|
|
3341
3571
|
if (nonce) {
|
|
3342
3572
|
styleNode.setAttribute('nonce', nonce);
|
|
3343
3573
|
}
|
|
3344
|
-
styleNode.setAttribute(
|
|
3574
|
+
styleNode.setAttribute(`data-tiptap-style${suffix ? `-${suffix}` : ''}`, '');
|
|
3345
3575
|
styleNode.innerHTML = style;
|
|
3346
3576
|
document.getElementsByTagName('head')[0].appendChild(styleNode);
|
|
3347
3577
|
return styleNode;
|
|
@@ -3753,11 +3983,13 @@ function markInputRule(config) {
|
|
|
3753
3983
|
function nodeInputRule(config) {
|
|
3754
3984
|
return new InputRule({
|
|
3755
3985
|
find: config.find,
|
|
3756
|
-
handler: ({ state, range, match }) => {
|
|
3986
|
+
handler: ({ state: state$1, range, match }) => {
|
|
3987
|
+
var _a;
|
|
3757
3988
|
const attributes = callOrReturn(config.getAttributes, undefined, match) || {};
|
|
3758
|
-
const { tr } = state;
|
|
3759
|
-
const start = range.from;
|
|
3989
|
+
const { tr } = state$1;
|
|
3990
|
+
const start = config.blockReplace ? range.from - 1 : range.from;
|
|
3760
3991
|
let end = range.to;
|
|
3992
|
+
const newNode = config.type.create(attributes);
|
|
3761
3993
|
if (match[1]) {
|
|
3762
3994
|
const offset = match[0].lastIndexOf(match[1]);
|
|
3763
3995
|
let matchStart = start + offset;
|
|
@@ -3771,10 +4003,26 @@ function nodeInputRule(config) {
|
|
|
3771
4003
|
const lastChar = match[0][match[0].length - 1];
|
|
3772
4004
|
tr.insertText(lastChar, start + match[0].length - 1);
|
|
3773
4005
|
// insert node from input rule
|
|
3774
|
-
tr.replaceWith(matchStart, end,
|
|
4006
|
+
tr.replaceWith(matchStart, end, newNode);
|
|
3775
4007
|
}
|
|
3776
4008
|
else if (match[0]) {
|
|
3777
|
-
tr.replaceWith(start, end,
|
|
4009
|
+
tr.replaceWith(start, end, newNode);
|
|
4010
|
+
}
|
|
4011
|
+
if (config.blockReplace && config.addExtraNewline) {
|
|
4012
|
+
const { $to } = tr.selection;
|
|
4013
|
+
const posAfter = $to.end();
|
|
4014
|
+
if ($to.nodeAfter) {
|
|
4015
|
+
tr.setSelection(state.TextSelection.create(tr.doc, $to.pos));
|
|
4016
|
+
}
|
|
4017
|
+
else {
|
|
4018
|
+
// add node after horizontal rule if it’s the end of the document
|
|
4019
|
+
const node = (_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create();
|
|
4020
|
+
if (node) {
|
|
4021
|
+
tr.insert(posAfter, node);
|
|
4022
|
+
tr.setSelection(state.TextSelection.create(tr.doc, posAfter));
|
|
4023
|
+
}
|
|
4024
|
+
}
|
|
4025
|
+
tr.scrollIntoView();
|
|
3778
4026
|
}
|
|
3779
4027
|
},
|
|
3780
4028
|
});
|
|
@@ -4364,6 +4612,7 @@ exports.extensions = extensions;
|
|
|
4364
4612
|
exports.findChildren = findChildren;
|
|
4365
4613
|
exports.findChildrenInRange = findChildrenInRange;
|
|
4366
4614
|
exports.findDuplicates = findDuplicates;
|
|
4615
|
+
exports.findListItemPos = findListItemPos;
|
|
4367
4616
|
exports.findParentNode = findParentNode;
|
|
4368
4617
|
exports.findParentNodeClosestToPos = findParentNodeClosestToPos;
|
|
4369
4618
|
exports.fromString = fromString;
|
|
@@ -4380,6 +4629,7 @@ exports.getMarkAttributes = getMarkAttributes;
|
|
|
4380
4629
|
exports.getMarkRange = getMarkRange;
|
|
4381
4630
|
exports.getMarkType = getMarkType;
|
|
4382
4631
|
exports.getMarksBetween = getMarksBetween;
|
|
4632
|
+
exports.getNextListDepth = getNextListDepth;
|
|
4383
4633
|
exports.getNodeAtPosition = getNodeAtPosition;
|
|
4384
4634
|
exports.getNodeAttributes = getNodeAttributes;
|
|
4385
4635
|
exports.getNodeType = getNodeType;
|
|
@@ -4393,9 +4643,15 @@ exports.getText = getText;
|
|
|
4393
4643
|
exports.getTextBetween = getTextBetween;
|
|
4394
4644
|
exports.getTextContentFromNodes = getTextContentFromNodes;
|
|
4395
4645
|
exports.getTextSerializersFromSchema = getTextSerializersFromSchema;
|
|
4646
|
+
exports.handleBackspace = handleBackspace;
|
|
4647
|
+
exports.handleDelete = handleDelete;
|
|
4648
|
+
exports.hasListBefore = hasListBefore;
|
|
4649
|
+
exports.hasListItemAfter = hasListItemAfter;
|
|
4650
|
+
exports.hasListItemBefore = hasListItemBefore;
|
|
4396
4651
|
exports.injectExtensionAttributesToParseRule = injectExtensionAttributesToParseRule;
|
|
4397
4652
|
exports.inputRulesPlugin = inputRulesPlugin;
|
|
4398
4653
|
exports.isActive = isActive;
|
|
4654
|
+
exports.isAtEndOfNode = isAtEndOfNode;
|
|
4399
4655
|
exports.isAtStartOfNode = isAtStartOfNode;
|
|
4400
4656
|
exports.isEmptyObject = isEmptyObject;
|
|
4401
4657
|
exports.isExtensionRulesEnabled = isExtensionRulesEnabled;
|
|
@@ -4412,12 +4668,14 @@ exports.isRegExp = isRegExp;
|
|
|
4412
4668
|
exports.isString = isString;
|
|
4413
4669
|
exports.isTextSelection = isTextSelection;
|
|
4414
4670
|
exports.isiOS = isiOS;
|
|
4415
|
-
exports.
|
|
4671
|
+
exports.listItemHasSubList = listItemHasSubList;
|
|
4416
4672
|
exports.markInputRule = markInputRule;
|
|
4417
4673
|
exports.markPasteRule = markPasteRule;
|
|
4418
4674
|
exports.mergeAttributes = mergeAttributes;
|
|
4419
4675
|
exports.mergeDeep = mergeDeep;
|
|
4420
4676
|
exports.minMax = minMax;
|
|
4677
|
+
exports.nextListIsDeeper = nextListIsDeeper;
|
|
4678
|
+
exports.nextListIsHigher = nextListIsHigher;
|
|
4421
4679
|
exports.nodeInputRule = nodeInputRule;
|
|
4422
4680
|
exports.nodePasteRule = nodePasteRule;
|
|
4423
4681
|
exports.objectIncludes = objectIncludes;
|