@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.umd.js
CHANGED
|
@@ -1303,17 +1303,14 @@
|
|
|
1303
1303
|
return commands$1.createParagraphNear(state, dispatch);
|
|
1304
1304
|
};
|
|
1305
1305
|
|
|
1306
|
-
const cut = (originRange, targetPos) => ({ editor }) => {
|
|
1307
|
-
const { state } = editor;
|
|
1308
|
-
const contentSlice = state.doc.slice(originRange.from, originRange.to);
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
})
|
|
1315
|
-
.focus()
|
|
1316
|
-
.run();
|
|
1306
|
+
const cut = (originRange, targetPos) => ({ editor, tr }) => {
|
|
1307
|
+
const { state: state$1 } = editor;
|
|
1308
|
+
const contentSlice = state$1.doc.slice(originRange.from, originRange.to);
|
|
1309
|
+
tr.deleteRange(originRange.from, originRange.to);
|
|
1310
|
+
const newPos = tr.mapping.map(targetPos);
|
|
1311
|
+
tr.insert(newPos, contentSlice.content);
|
|
1312
|
+
tr.setSelection(new state.TextSelection(tr.doc.resolve(newPos - 1)));
|
|
1313
|
+
return true;
|
|
1317
1314
|
};
|
|
1318
1315
|
|
|
1319
1316
|
const deleteCurrentNode = () => ({ tr, dispatch }) => {
|
|
@@ -1707,6 +1704,40 @@
|
|
|
1707
1704
|
return commands$1.joinForward(state, dispatch);
|
|
1708
1705
|
};
|
|
1709
1706
|
|
|
1707
|
+
const joinItemBackward = () => ({ tr, state, dispatch, }) => {
|
|
1708
|
+
try {
|
|
1709
|
+
const point = transform.joinPoint(state.doc, state.selection.$from.pos, -1);
|
|
1710
|
+
if (point === null || point === undefined) {
|
|
1711
|
+
return false;
|
|
1712
|
+
}
|
|
1713
|
+
tr.join(point, 2);
|
|
1714
|
+
if (dispatch) {
|
|
1715
|
+
dispatch(tr);
|
|
1716
|
+
}
|
|
1717
|
+
return true;
|
|
1718
|
+
}
|
|
1719
|
+
catch {
|
|
1720
|
+
return false;
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1724
|
+
const joinItemForward = () => ({ state, dispatch, tr, }) => {
|
|
1725
|
+
try {
|
|
1726
|
+
const point = transform.joinPoint(state.doc, state.selection.$from.pos, +1);
|
|
1727
|
+
if (point === null || point === undefined) {
|
|
1728
|
+
return false;
|
|
1729
|
+
}
|
|
1730
|
+
tr.join(point, 2);
|
|
1731
|
+
if (dispatch) {
|
|
1732
|
+
dispatch(tr);
|
|
1733
|
+
}
|
|
1734
|
+
return true;
|
|
1735
|
+
}
|
|
1736
|
+
catch (e) {
|
|
1737
|
+
return false;
|
|
1738
|
+
}
|
|
1739
|
+
};
|
|
1740
|
+
|
|
1710
1741
|
function isMacOS() {
|
|
1711
1742
|
return typeof navigator !== 'undefined'
|
|
1712
1743
|
? /Mac/.test(navigator.platform)
|
|
@@ -1975,6 +2006,261 @@
|
|
|
1975
2006
|
return { ...mark.attrs };
|
|
1976
2007
|
}
|
|
1977
2008
|
|
|
2009
|
+
const findListItemPos = (typeOrName, state) => {
|
|
2010
|
+
const { $from } = state.selection;
|
|
2011
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
2012
|
+
let currentNode = null;
|
|
2013
|
+
let currentDepth = $from.depth;
|
|
2014
|
+
let currentPos = $from.pos;
|
|
2015
|
+
let targetDepth = null;
|
|
2016
|
+
while (currentDepth > 0 && targetDepth === null) {
|
|
2017
|
+
currentNode = $from.node(currentDepth);
|
|
2018
|
+
if (currentNode.type === nodeType) {
|
|
2019
|
+
targetDepth = currentDepth;
|
|
2020
|
+
}
|
|
2021
|
+
else {
|
|
2022
|
+
currentDepth -= 1;
|
|
2023
|
+
currentPos -= 1;
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
if (targetDepth === null) {
|
|
2027
|
+
return null;
|
|
2028
|
+
}
|
|
2029
|
+
return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
|
|
2030
|
+
};
|
|
2031
|
+
|
|
2032
|
+
/**
|
|
2033
|
+
* Finds the first node of a given type or name in the current selection.
|
|
2034
|
+
* @param state The editor state.
|
|
2035
|
+
* @param typeOrName The node type or name.
|
|
2036
|
+
* @param pos The position to start searching from.
|
|
2037
|
+
* @param maxDepth The maximum depth to search.
|
|
2038
|
+
* @returns The node and the depth as an array.
|
|
2039
|
+
*/
|
|
2040
|
+
const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
2041
|
+
const $pos = state.doc.resolve(pos);
|
|
2042
|
+
let currentDepth = maxDepth;
|
|
2043
|
+
let node = null;
|
|
2044
|
+
while (currentDepth > 0 && node === null) {
|
|
2045
|
+
const currentNode = $pos.node(currentDepth);
|
|
2046
|
+
if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
|
|
2047
|
+
node = currentNode;
|
|
2048
|
+
}
|
|
2049
|
+
else {
|
|
2050
|
+
currentDepth -= 1;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
return [node, currentDepth];
|
|
2054
|
+
};
|
|
2055
|
+
|
|
2056
|
+
const getNextListDepth = (typeOrName, state) => {
|
|
2057
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2058
|
+
if (!listItemPos) {
|
|
2059
|
+
return false;
|
|
2060
|
+
}
|
|
2061
|
+
const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
|
|
2062
|
+
return depth;
|
|
2063
|
+
};
|
|
2064
|
+
|
|
2065
|
+
const isAtStartOfNode = (state) => {
|
|
2066
|
+
const { $from, $to } = state.selection;
|
|
2067
|
+
if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
|
|
2068
|
+
return false;
|
|
2069
|
+
}
|
|
2070
|
+
return true;
|
|
2071
|
+
};
|
|
2072
|
+
|
|
2073
|
+
const hasListBefore = (editorState, name, parentListTypes) => {
|
|
2074
|
+
const { $anchor } = editorState.selection;
|
|
2075
|
+
const previousNodePos = Math.max(0, $anchor.pos - 2);
|
|
2076
|
+
const previousNode = editorState.doc.resolve(previousNodePos).node();
|
|
2077
|
+
if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
|
|
2078
|
+
return false;
|
|
2079
|
+
}
|
|
2080
|
+
return true;
|
|
2081
|
+
};
|
|
2082
|
+
|
|
2083
|
+
const hasListItemBefore = (typeOrName, state) => {
|
|
2084
|
+
var _a;
|
|
2085
|
+
const { $anchor } = state.selection;
|
|
2086
|
+
const $targetPos = state.doc.resolve($anchor.pos - 2);
|
|
2087
|
+
if ($targetPos.index() === 0) {
|
|
2088
|
+
return false;
|
|
2089
|
+
}
|
|
2090
|
+
if (((_a = $targetPos.nodeBefore) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
|
|
2091
|
+
return false;
|
|
2092
|
+
}
|
|
2093
|
+
return true;
|
|
2094
|
+
};
|
|
2095
|
+
|
|
2096
|
+
const listItemHasSubList = (typeOrName, state, node) => {
|
|
2097
|
+
if (!node) {
|
|
2098
|
+
return false;
|
|
2099
|
+
}
|
|
2100
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
2101
|
+
let hasSubList = false;
|
|
2102
|
+
node.descendants(child => {
|
|
2103
|
+
if (child.type === nodeType) {
|
|
2104
|
+
hasSubList = true;
|
|
2105
|
+
}
|
|
2106
|
+
});
|
|
2107
|
+
return hasSubList;
|
|
2108
|
+
};
|
|
2109
|
+
|
|
2110
|
+
const handleBackspace = (editor, name, parentListTypes) => {
|
|
2111
|
+
// this is required to still handle the undo handling
|
|
2112
|
+
if (editor.commands.undoInputRule()) {
|
|
2113
|
+
return true;
|
|
2114
|
+
}
|
|
2115
|
+
// if the current item is NOT inside a list item &
|
|
2116
|
+
// the previous item is a list (orderedList or bulletList)
|
|
2117
|
+
// move the cursor into the list and delete the current item
|
|
2118
|
+
if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
|
|
2119
|
+
const { $anchor } = editor.state.selection;
|
|
2120
|
+
const $listPos = editor.state.doc.resolve($anchor.before() - 1);
|
|
2121
|
+
const listDescendants = [];
|
|
2122
|
+
$listPos.node().descendants((node, pos) => {
|
|
2123
|
+
if (node.type.name === name) {
|
|
2124
|
+
listDescendants.push({ node, pos });
|
|
2125
|
+
}
|
|
2126
|
+
});
|
|
2127
|
+
const lastItem = listDescendants.at(-1);
|
|
2128
|
+
if (!lastItem) {
|
|
2129
|
+
return false;
|
|
2130
|
+
}
|
|
2131
|
+
const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
|
|
2132
|
+
return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
|
|
2133
|
+
}
|
|
2134
|
+
// if the cursor is not inside the current node type
|
|
2135
|
+
// do nothing and proceed
|
|
2136
|
+
if (!isNodeActive(editor.state, name)) {
|
|
2137
|
+
return false;
|
|
2138
|
+
}
|
|
2139
|
+
// if the cursor is not at the start of a node
|
|
2140
|
+
// do nothing and proceed
|
|
2141
|
+
if (!isAtStartOfNode(editor.state)) {
|
|
2142
|
+
return false;
|
|
2143
|
+
}
|
|
2144
|
+
const listItemPos = findListItemPos(name, editor.state);
|
|
2145
|
+
if (!listItemPos) {
|
|
2146
|
+
return false;
|
|
2147
|
+
}
|
|
2148
|
+
const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
|
|
2149
|
+
const prevNode = $prev.node(listItemPos.depth);
|
|
2150
|
+
const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
|
|
2151
|
+
// if the previous item is a list item and doesn't have a sublist, join the list items
|
|
2152
|
+
if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
|
|
2153
|
+
return editor.commands.joinItemBackward();
|
|
2154
|
+
}
|
|
2155
|
+
// otherwise in the end, a backspace should
|
|
2156
|
+
// always just lift the list item if
|
|
2157
|
+
// joining / merging is not possible
|
|
2158
|
+
return editor.chain().liftListItem(name).run();
|
|
2159
|
+
};
|
|
2160
|
+
|
|
2161
|
+
function findParentNodeClosestToPos($pos, predicate) {
|
|
2162
|
+
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2163
|
+
const node = $pos.node(i);
|
|
2164
|
+
if (predicate(node)) {
|
|
2165
|
+
return {
|
|
2166
|
+
pos: i > 0 ? $pos.before(i) : 0,
|
|
2167
|
+
start: $pos.start(i),
|
|
2168
|
+
depth: i,
|
|
2169
|
+
node,
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
function findParentNode(predicate) {
|
|
2176
|
+
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2179
|
+
const isAtEndOfNode = (state, nodeType) => {
|
|
2180
|
+
const { $from, $to, $anchor } = state.selection;
|
|
2181
|
+
if (nodeType) {
|
|
2182
|
+
const parentNode = findParentNode(node => node.type.name === nodeType)(state.selection);
|
|
2183
|
+
if (!parentNode) {
|
|
2184
|
+
return false;
|
|
2185
|
+
}
|
|
2186
|
+
const $parentPos = state.doc.resolve(parentNode.pos + 1);
|
|
2187
|
+
if ($anchor.pos + 1 === $parentPos.end()) {
|
|
2188
|
+
return true;
|
|
2189
|
+
}
|
|
2190
|
+
return false;
|
|
2191
|
+
}
|
|
2192
|
+
if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
|
|
2193
|
+
return false;
|
|
2194
|
+
}
|
|
2195
|
+
return true;
|
|
2196
|
+
};
|
|
2197
|
+
|
|
2198
|
+
const nextListIsDeeper = (typeOrName, state) => {
|
|
2199
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
2200
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2201
|
+
if (!listItemPos || !listDepth) {
|
|
2202
|
+
return false;
|
|
2203
|
+
}
|
|
2204
|
+
if (listDepth > listItemPos.depth) {
|
|
2205
|
+
return true;
|
|
2206
|
+
}
|
|
2207
|
+
return false;
|
|
2208
|
+
};
|
|
2209
|
+
|
|
2210
|
+
const nextListIsHigher = (typeOrName, state) => {
|
|
2211
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
2212
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
2213
|
+
if (!listItemPos || !listDepth) {
|
|
2214
|
+
return false;
|
|
2215
|
+
}
|
|
2216
|
+
if (listDepth < listItemPos.depth) {
|
|
2217
|
+
return true;
|
|
2218
|
+
}
|
|
2219
|
+
return false;
|
|
2220
|
+
};
|
|
2221
|
+
|
|
2222
|
+
const handleDelete = (editor, name) => {
|
|
2223
|
+
// if the cursor is not inside the current node type
|
|
2224
|
+
// do nothing and proceed
|
|
2225
|
+
if (!isNodeActive(editor.state, name)) {
|
|
2226
|
+
return false;
|
|
2227
|
+
}
|
|
2228
|
+
// if the cursor is not at the end of a node
|
|
2229
|
+
// do nothing and proceed
|
|
2230
|
+
if (!isAtEndOfNode(editor.state, name)) {
|
|
2231
|
+
return false;
|
|
2232
|
+
}
|
|
2233
|
+
// check if the next node is a list with a deeper depth
|
|
2234
|
+
if (nextListIsDeeper(name, editor.state)) {
|
|
2235
|
+
return editor
|
|
2236
|
+
.chain()
|
|
2237
|
+
.focus(editor.state.selection.from + 4)
|
|
2238
|
+
.lift(name)
|
|
2239
|
+
.joinBackward()
|
|
2240
|
+
.run();
|
|
2241
|
+
}
|
|
2242
|
+
if (nextListIsHigher(name, editor.state)) {
|
|
2243
|
+
return editor.chain()
|
|
2244
|
+
.joinForward()
|
|
2245
|
+
.joinBackward()
|
|
2246
|
+
.run();
|
|
2247
|
+
}
|
|
2248
|
+
return editor.commands.joinItemForward();
|
|
2249
|
+
};
|
|
2250
|
+
|
|
2251
|
+
const hasListItemAfter = (typeOrName, state) => {
|
|
2252
|
+
var _a;
|
|
2253
|
+
const { $anchor } = state.selection;
|
|
2254
|
+
const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
|
|
2255
|
+
if ($targetPos.index() === $targetPos.parent.childCount - 1) {
|
|
2256
|
+
return false;
|
|
2257
|
+
}
|
|
2258
|
+
if (((_a = $targetPos.nodeAfter) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
|
|
2259
|
+
return false;
|
|
2260
|
+
}
|
|
2261
|
+
return true;
|
|
2262
|
+
};
|
|
2263
|
+
|
|
1978
2264
|
/**
|
|
1979
2265
|
* Returns a new `Transform` based on all steps of the passed transactions.
|
|
1980
2266
|
*/
|
|
@@ -2036,24 +2322,6 @@
|
|
|
2036
2322
|
return nodesWithPos;
|
|
2037
2323
|
}
|
|
2038
2324
|
|
|
2039
|
-
function findParentNodeClosestToPos($pos, predicate) {
|
|
2040
|
-
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
2041
|
-
const node = $pos.node(i);
|
|
2042
|
-
if (predicate(node)) {
|
|
2043
|
-
return {
|
|
2044
|
-
pos: i > 0 ? $pos.before(i) : 0,
|
|
2045
|
-
start: $pos.start(i),
|
|
2046
|
-
depth: i,
|
|
2047
|
-
node,
|
|
2048
|
-
};
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
|
|
2053
|
-
function findParentNode(predicate) {
|
|
2054
|
-
return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
|
|
2055
|
-
}
|
|
2056
|
-
|
|
2057
2325
|
function getHTMLFromFragment(fragment, schema) {
|
|
2058
2326
|
const documentFragment = model.DOMSerializer.fromSchema(schema).serializeFragment(fragment);
|
|
2059
2327
|
const temporaryDocument = document.implementation.createHTMLDocument();
|
|
@@ -2271,30 +2539,6 @@
|
|
|
2271
2539
|
return marks;
|
|
2272
2540
|
}
|
|
2273
2541
|
|
|
2274
|
-
/**
|
|
2275
|
-
* Finds the first node of a given type or name in the current selection.
|
|
2276
|
-
* @param state The editor state.
|
|
2277
|
-
* @param typeOrName The node type or name.
|
|
2278
|
-
* @param pos The position to start searching from.
|
|
2279
|
-
* @param maxDepth The maximum depth to search.
|
|
2280
|
-
* @returns The node and the depth as an array.
|
|
2281
|
-
*/
|
|
2282
|
-
const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
|
|
2283
|
-
const $pos = state.doc.resolve(pos);
|
|
2284
|
-
let currentDepth = maxDepth;
|
|
2285
|
-
let node = null;
|
|
2286
|
-
while (currentDepth > 0 && node === null) {
|
|
2287
|
-
const currentNode = $pos.node(currentDepth);
|
|
2288
|
-
if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
|
|
2289
|
-
node = currentNode;
|
|
2290
|
-
}
|
|
2291
|
-
else {
|
|
2292
|
-
currentDepth -= 1;
|
|
2293
|
-
}
|
|
2294
|
-
}
|
|
2295
|
-
return [node, currentDepth];
|
|
2296
|
-
};
|
|
2297
|
-
|
|
2298
2542
|
function getSplittedAttributes(extensionAttributes, typeName, attributes) {
|
|
2299
2543
|
return Object.fromEntries(Object
|
|
2300
2544
|
.entries(attributes)
|
|
@@ -2385,22 +2629,6 @@
|
|
|
2385
2629
|
return false;
|
|
2386
2630
|
}
|
|
2387
2631
|
|
|
2388
|
-
const istAtEndOfNode = (state) => {
|
|
2389
|
-
const { $from, $to } = state.selection;
|
|
2390
|
-
if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
|
|
2391
|
-
return false;
|
|
2392
|
-
}
|
|
2393
|
-
return true;
|
|
2394
|
-
};
|
|
2395
|
-
|
|
2396
|
-
const isAtStartOfNode = (state) => {
|
|
2397
|
-
const { $from, $to } = state.selection;
|
|
2398
|
-
if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
|
|
2399
|
-
return false;
|
|
2400
|
-
}
|
|
2401
|
-
return true;
|
|
2402
|
-
};
|
|
2403
|
-
|
|
2404
2632
|
function isList(name, extensions) {
|
|
2405
2633
|
const { nodeExtensions } = splitExtensions(extensions);
|
|
2406
2634
|
const extension = nodeExtensions.find(item => item.name === name);
|
|
@@ -3025,6 +3253,8 @@
|
|
|
3025
3253
|
joinDown: joinDown,
|
|
3026
3254
|
joinBackward: joinBackward,
|
|
3027
3255
|
joinForward: joinForward,
|
|
3256
|
+
joinItemBackward: joinItemBackward,
|
|
3257
|
+
joinItemForward: joinItemForward,
|
|
3028
3258
|
keyboardShortcut: keyboardShortcut,
|
|
3029
3259
|
lift: lift,
|
|
3030
3260
|
liftEmptyBlock: liftEmptyBlock,
|
|
@@ -3326,8 +3556,8 @@ img.ProseMirror-separator {
|
|
|
3326
3556
|
opacity: 0
|
|
3327
3557
|
}`;
|
|
3328
3558
|
|
|
3329
|
-
function createStyleTag(style, nonce) {
|
|
3330
|
-
const tiptapStyleTag = document.querySelector(
|
|
3559
|
+
function createStyleTag(style, nonce, suffix) {
|
|
3560
|
+
const tiptapStyleTag = document.querySelector(`style[data-tiptap-style${suffix ? `-${suffix}` : ''}]`);
|
|
3331
3561
|
if (tiptapStyleTag !== null) {
|
|
3332
3562
|
return tiptapStyleTag;
|
|
3333
3563
|
}
|
|
@@ -3335,7 +3565,7 @@ img.ProseMirror-separator {
|
|
|
3335
3565
|
if (nonce) {
|
|
3336
3566
|
styleNode.setAttribute('nonce', nonce);
|
|
3337
3567
|
}
|
|
3338
|
-
styleNode.setAttribute(
|
|
3568
|
+
styleNode.setAttribute(`data-tiptap-style${suffix ? `-${suffix}` : ''}`, '');
|
|
3339
3569
|
styleNode.innerHTML = style;
|
|
3340
3570
|
document.getElementsByTagName('head')[0].appendChild(styleNode);
|
|
3341
3571
|
return styleNode;
|
|
@@ -3747,11 +3977,13 @@ img.ProseMirror-separator {
|
|
|
3747
3977
|
function nodeInputRule(config) {
|
|
3748
3978
|
return new InputRule({
|
|
3749
3979
|
find: config.find,
|
|
3750
|
-
handler: ({ state, range, match }) => {
|
|
3980
|
+
handler: ({ state: state$1, range, match }) => {
|
|
3981
|
+
var _a;
|
|
3751
3982
|
const attributes = callOrReturn(config.getAttributes, undefined, match) || {};
|
|
3752
|
-
const { tr } = state;
|
|
3753
|
-
const start = range.from;
|
|
3983
|
+
const { tr } = state$1;
|
|
3984
|
+
const start = config.blockReplace ? range.from - 1 : range.from;
|
|
3754
3985
|
let end = range.to;
|
|
3986
|
+
const newNode = config.type.create(attributes);
|
|
3755
3987
|
if (match[1]) {
|
|
3756
3988
|
const offset = match[0].lastIndexOf(match[1]);
|
|
3757
3989
|
let matchStart = start + offset;
|
|
@@ -3765,10 +3997,26 @@ img.ProseMirror-separator {
|
|
|
3765
3997
|
const lastChar = match[0][match[0].length - 1];
|
|
3766
3998
|
tr.insertText(lastChar, start + match[0].length - 1);
|
|
3767
3999
|
// insert node from input rule
|
|
3768
|
-
tr.replaceWith(matchStart, end,
|
|
4000
|
+
tr.replaceWith(matchStart, end, newNode);
|
|
3769
4001
|
}
|
|
3770
4002
|
else if (match[0]) {
|
|
3771
|
-
tr.replaceWith(start, end,
|
|
4003
|
+
tr.replaceWith(start, end, newNode);
|
|
4004
|
+
}
|
|
4005
|
+
if (config.blockReplace && config.addExtraNewline) {
|
|
4006
|
+
const { $to } = tr.selection;
|
|
4007
|
+
const posAfter = $to.end();
|
|
4008
|
+
if ($to.nodeAfter) {
|
|
4009
|
+
tr.setSelection(state.TextSelection.create(tr.doc, $to.pos));
|
|
4010
|
+
}
|
|
4011
|
+
else {
|
|
4012
|
+
// add node after horizontal rule if it’s the end of the document
|
|
4013
|
+
const node = (_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create();
|
|
4014
|
+
if (node) {
|
|
4015
|
+
tr.insert(posAfter, node);
|
|
4016
|
+
tr.setSelection(state.TextSelection.create(tr.doc, posAfter));
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4019
|
+
tr.scrollIntoView();
|
|
3772
4020
|
}
|
|
3773
4021
|
},
|
|
3774
4022
|
});
|
|
@@ -4358,6 +4606,7 @@ img.ProseMirror-separator {
|
|
|
4358
4606
|
exports.findChildren = findChildren;
|
|
4359
4607
|
exports.findChildrenInRange = findChildrenInRange;
|
|
4360
4608
|
exports.findDuplicates = findDuplicates;
|
|
4609
|
+
exports.findListItemPos = findListItemPos;
|
|
4361
4610
|
exports.findParentNode = findParentNode;
|
|
4362
4611
|
exports.findParentNodeClosestToPos = findParentNodeClosestToPos;
|
|
4363
4612
|
exports.fromString = fromString;
|
|
@@ -4374,6 +4623,7 @@ img.ProseMirror-separator {
|
|
|
4374
4623
|
exports.getMarkRange = getMarkRange;
|
|
4375
4624
|
exports.getMarkType = getMarkType;
|
|
4376
4625
|
exports.getMarksBetween = getMarksBetween;
|
|
4626
|
+
exports.getNextListDepth = getNextListDepth;
|
|
4377
4627
|
exports.getNodeAtPosition = getNodeAtPosition;
|
|
4378
4628
|
exports.getNodeAttributes = getNodeAttributes;
|
|
4379
4629
|
exports.getNodeType = getNodeType;
|
|
@@ -4387,9 +4637,15 @@ img.ProseMirror-separator {
|
|
|
4387
4637
|
exports.getTextBetween = getTextBetween;
|
|
4388
4638
|
exports.getTextContentFromNodes = getTextContentFromNodes;
|
|
4389
4639
|
exports.getTextSerializersFromSchema = getTextSerializersFromSchema;
|
|
4640
|
+
exports.handleBackspace = handleBackspace;
|
|
4641
|
+
exports.handleDelete = handleDelete;
|
|
4642
|
+
exports.hasListBefore = hasListBefore;
|
|
4643
|
+
exports.hasListItemAfter = hasListItemAfter;
|
|
4644
|
+
exports.hasListItemBefore = hasListItemBefore;
|
|
4390
4645
|
exports.injectExtensionAttributesToParseRule = injectExtensionAttributesToParseRule;
|
|
4391
4646
|
exports.inputRulesPlugin = inputRulesPlugin;
|
|
4392
4647
|
exports.isActive = isActive;
|
|
4648
|
+
exports.isAtEndOfNode = isAtEndOfNode;
|
|
4393
4649
|
exports.isAtStartOfNode = isAtStartOfNode;
|
|
4394
4650
|
exports.isEmptyObject = isEmptyObject;
|
|
4395
4651
|
exports.isExtensionRulesEnabled = isExtensionRulesEnabled;
|
|
@@ -4406,12 +4662,14 @@ img.ProseMirror-separator {
|
|
|
4406
4662
|
exports.isString = isString;
|
|
4407
4663
|
exports.isTextSelection = isTextSelection;
|
|
4408
4664
|
exports.isiOS = isiOS;
|
|
4409
|
-
exports.
|
|
4665
|
+
exports.listItemHasSubList = listItemHasSubList;
|
|
4410
4666
|
exports.markInputRule = markInputRule;
|
|
4411
4667
|
exports.markPasteRule = markPasteRule;
|
|
4412
4668
|
exports.mergeAttributes = mergeAttributes;
|
|
4413
4669
|
exports.mergeDeep = mergeDeep;
|
|
4414
4670
|
exports.minMax = minMax;
|
|
4671
|
+
exports.nextListIsDeeper = nextListIsDeeper;
|
|
4672
|
+
exports.nextListIsHigher = nextListIsHigher;
|
|
4415
4673
|
exports.nodeInputRule = nodeInputRule;
|
|
4416
4674
|
exports.nodePasteRule = nodePasteRule;
|
|
4417
4675
|
exports.objectIncludes = objectIncludes;
|