@tiptap/core 3.22.1 → 3.22.2
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 +81 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/commands/toggleList.ts +69 -7
- package/src/pasteRules/markPasteRule.ts +10 -1
package/dist/index.js
CHANGED
|
@@ -2656,6 +2656,7 @@ var splitListItem = (typeOrName, overrideAttrs = {}) => ({ tr, state, dispatch,
|
|
|
2656
2656
|
};
|
|
2657
2657
|
|
|
2658
2658
|
// src/commands/toggleList.ts
|
|
2659
|
+
import { TextSelection as TextSelection8 } from "@tiptap/pm/state";
|
|
2659
2660
|
import { canJoin } from "@tiptap/pm/transform";
|
|
2660
2661
|
var joinListBackwards = (tr, listType) => {
|
|
2661
2662
|
const list = findParentNode((node) => node.type === listType)(tr.selection);
|
|
@@ -2691,6 +2692,16 @@ var joinListForwards = (tr, listType) => {
|
|
|
2691
2692
|
tr.join(after);
|
|
2692
2693
|
return true;
|
|
2693
2694
|
};
|
|
2695
|
+
function createInnerSelectionForWholeDocList(tr) {
|
|
2696
|
+
const doc = tr.doc;
|
|
2697
|
+
const list = doc.firstChild;
|
|
2698
|
+
if (!list) {
|
|
2699
|
+
return null;
|
|
2700
|
+
}
|
|
2701
|
+
const from = 1;
|
|
2702
|
+
const to = list.nodeSize - 1;
|
|
2703
|
+
return TextSelection8.create(doc, from, to);
|
|
2704
|
+
}
|
|
2694
2705
|
var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) => ({ editor, tr, state, dispatch, chain, commands, can }) => {
|
|
2695
2706
|
const { extensions, splittableMarks } = editor.extensionManager;
|
|
2696
2707
|
const listType = getNodeType(listTypeOrName, state.schema);
|
|
@@ -2703,13 +2714,37 @@ var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) =>
|
|
|
2703
2714
|
return false;
|
|
2704
2715
|
}
|
|
2705
2716
|
const parentList = findParentNode((node) => isList(node.type.name, extensions))(selection);
|
|
2706
|
-
|
|
2707
|
-
|
|
2717
|
+
const isAllSelection = selection.from === 0 && selection.to === state.doc.content.size;
|
|
2718
|
+
const topLevelNodes = state.doc.content.content;
|
|
2719
|
+
const soleTopLevelNode = topLevelNodes.length === 1 ? topLevelNodes[0] : null;
|
|
2720
|
+
const allSelectionList = isAllSelection && soleTopLevelNode && isList(soleTopLevelNode.type.name, extensions) ? {
|
|
2721
|
+
node: soleTopLevelNode,
|
|
2722
|
+
pos: 0,
|
|
2723
|
+
depth: 0
|
|
2724
|
+
} : null;
|
|
2725
|
+
const currentList = parentList != null ? parentList : allSelectionList;
|
|
2726
|
+
const isInsideExistingList = !!parentList && range.depth >= 1 && range.depth - parentList.depth <= 1;
|
|
2727
|
+
const hasWholeDocSelectedList = !!allSelectionList;
|
|
2728
|
+
if ((isInsideExistingList || hasWholeDocSelectedList) && currentList) {
|
|
2729
|
+
if (currentList.node.type === listType) {
|
|
2730
|
+
if (isAllSelection && hasWholeDocSelectedList) {
|
|
2731
|
+
return chain().command(({ tr: trx, dispatch: disp }) => {
|
|
2732
|
+
const nextSelection = createInnerSelectionForWholeDocList(trx);
|
|
2733
|
+
if (!nextSelection) {
|
|
2734
|
+
return false;
|
|
2735
|
+
}
|
|
2736
|
+
trx.setSelection(nextSelection);
|
|
2737
|
+
if (disp) {
|
|
2738
|
+
disp(trx);
|
|
2739
|
+
}
|
|
2740
|
+
return true;
|
|
2741
|
+
}).liftListItem(itemType).run();
|
|
2742
|
+
}
|
|
2708
2743
|
return commands.liftListItem(itemType);
|
|
2709
2744
|
}
|
|
2710
|
-
if (isList(
|
|
2745
|
+
if (isList(currentList.node.type.name, extensions) && listType.validContent(currentList.node.content)) {
|
|
2711
2746
|
return chain().command(() => {
|
|
2712
|
-
tr.setNodeMarkup(
|
|
2747
|
+
tr.setNodeMarkup(currentList.pos, listType);
|
|
2713
2748
|
return true;
|
|
2714
2749
|
}).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
|
|
2715
2750
|
}
|
|
@@ -6849,7 +6884,10 @@ function markPasteRule(config) {
|
|
|
6849
6884
|
}
|
|
6850
6885
|
markEnd = range.from + startSpaces + captureGroup.length;
|
|
6851
6886
|
tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}));
|
|
6852
|
-
|
|
6887
|
+
const isMatchAtEndOfText = match.index !== void 0 && match.input !== void 0 && match.index + match[0].length >= match.input.length;
|
|
6888
|
+
if (!isMatchAtEndOfText) {
|
|
6889
|
+
tr.removeStoredMark(config.type);
|
|
6890
|
+
}
|
|
6853
6891
|
}
|
|
6854
6892
|
}
|
|
6855
6893
|
});
|