@tiptap/extension-list-keymap 2.6.2 → 3.0.0-next.1
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 +273 -256
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +254 -253
- package/dist/index.js.map +1 -1
- package/package.json +6 -8
- package/dist/index.umd.js +0 -291
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -163
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -344
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -452
- package/dist/packages/core/src/Node.d.ts +0 -612
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -16
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -16
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -14
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -14
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -253
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/packages/extension-list-keymap/src/index.d.ts +0 -4
- package/dist/packages/extension-list-keymap/src/list-keymap.d.ts +0 -20
- package/dist/packages/extension-list-keymap/src/listHelpers/findListItemPos.d.ts +0 -6
- package/dist/packages/extension-list-keymap/src/listHelpers/getNextListDepth.d.ts +0 -2
- package/dist/packages/extension-list-keymap/src/listHelpers/handleBackspace.d.ts +0 -2
- package/dist/packages/extension-list-keymap/src/listHelpers/handleDelete.d.ts +0 -2
- package/dist/packages/extension-list-keymap/src/listHelpers/hasListBefore.d.ts +0 -2
- package/dist/packages/extension-list-keymap/src/listHelpers/hasListItemAfter.d.ts +0 -2
- package/dist/packages/extension-list-keymap/src/listHelpers/hasListItemBefore.d.ts +0 -2
- package/dist/packages/extension-list-keymap/src/listHelpers/index.d.ts +0 -10
- package/dist/packages/extension-list-keymap/src/listHelpers/listItemHasSubList.d.ts +0 -3
- package/dist/packages/extension-list-keymap/src/listHelpers/nextListIsDeeper.d.ts +0 -2
- package/dist/packages/extension-list-keymap/src/listHelpers/nextListIsHigher.d.ts +0 -2
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Extension, Editor } from '@tiptap/core';
|
|
2
|
+
import * as prosemirror_model from 'prosemirror-model';
|
|
3
|
+
import { NodeType, Node } from '@tiptap/pm/model';
|
|
4
|
+
import { EditorState } from '@tiptap/pm/state';
|
|
5
|
+
|
|
6
|
+
type ListKeymapOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* An array of list types. This is used for item and wrapper list matching.
|
|
9
|
+
* @default []
|
|
10
|
+
* @example [{ itemName: 'listItem', wrapperNames: ['bulletList', 'orderedList'] }]
|
|
11
|
+
*/
|
|
12
|
+
listTypes: Array<{
|
|
13
|
+
itemName: string;
|
|
14
|
+
wrapperNames: string[];
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* This extension registers custom keymaps to change the behaviour of the backspace and delete keys.
|
|
19
|
+
* By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into
|
|
20
|
+
* the adjacent or previous list item. This extension will prevent this behaviour and instead will
|
|
21
|
+
* try to join paragraphs from two list items into a single list item.
|
|
22
|
+
* @see https://www.tiptap.dev/api/extensions/list-keymap
|
|
23
|
+
*/
|
|
24
|
+
declare const ListKeymap: Extension<ListKeymapOptions, any>;
|
|
25
|
+
|
|
26
|
+
declare const findListItemPos: (typeOrName: string | NodeType, state: EditorState) => {
|
|
27
|
+
$pos: prosemirror_model.ResolvedPos;
|
|
28
|
+
depth: number;
|
|
29
|
+
} | null;
|
|
30
|
+
|
|
31
|
+
declare const getNextListDepth: (typeOrName: string, state: EditorState) => number | false;
|
|
32
|
+
|
|
33
|
+
declare const handleBackspace: (editor: Editor, name: string, parentListTypes: string[]) => boolean;
|
|
34
|
+
|
|
35
|
+
declare const handleDelete: (editor: Editor, name: string) => boolean;
|
|
36
|
+
|
|
37
|
+
declare const hasListBefore: (editorState: EditorState, name: string, parentListTypes: string[]) => boolean;
|
|
38
|
+
|
|
39
|
+
declare const hasListItemAfter: (typeOrName: string, state: EditorState) => boolean;
|
|
40
|
+
|
|
41
|
+
declare const hasListItemBefore: (typeOrName: string, state: EditorState) => boolean;
|
|
42
|
+
|
|
43
|
+
declare const listItemHasSubList: (typeOrName: string, state: EditorState, node?: Node) => boolean;
|
|
44
|
+
|
|
45
|
+
declare const nextListIsDeeper: (typeOrName: string, state: EditorState) => boolean;
|
|
46
|
+
|
|
47
|
+
declare const nextListIsHigher: (typeOrName: string, state: EditorState) => boolean;
|
|
48
|
+
|
|
49
|
+
declare const index_findListItemPos: typeof findListItemPos;
|
|
50
|
+
declare const index_getNextListDepth: typeof getNextListDepth;
|
|
51
|
+
declare const index_handleBackspace: typeof handleBackspace;
|
|
52
|
+
declare const index_handleDelete: typeof handleDelete;
|
|
53
|
+
declare const index_hasListBefore: typeof hasListBefore;
|
|
54
|
+
declare const index_hasListItemAfter: typeof hasListItemAfter;
|
|
55
|
+
declare const index_hasListItemBefore: typeof hasListItemBefore;
|
|
56
|
+
declare const index_listItemHasSubList: typeof listItemHasSubList;
|
|
57
|
+
declare const index_nextListIsDeeper: typeof nextListIsDeeper;
|
|
58
|
+
declare const index_nextListIsHigher: typeof nextListIsHigher;
|
|
59
|
+
declare namespace index {
|
|
60
|
+
export { index_findListItemPos as findListItemPos, index_getNextListDepth as getNextListDepth, index_handleBackspace as handleBackspace, index_handleDelete as handleDelete, index_hasListBefore as hasListBefore, index_hasListItemAfter as hasListItemAfter, index_hasListItemBefore as hasListItemBefore, index_listItemHasSubList as listItemHasSubList, index_nextListIsDeeper as nextListIsDeeper, index_nextListIsHigher as nextListIsHigher };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { ListKeymap, type ListKeymapOptions, ListKeymap as default, index as listHelpers };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Extension, Editor } from '@tiptap/core';
|
|
2
|
+
import * as prosemirror_model from 'prosemirror-model';
|
|
3
|
+
import { NodeType, Node } from '@tiptap/pm/model';
|
|
4
|
+
import { EditorState } from '@tiptap/pm/state';
|
|
5
|
+
|
|
6
|
+
type ListKeymapOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* An array of list types. This is used for item and wrapper list matching.
|
|
9
|
+
* @default []
|
|
10
|
+
* @example [{ itemName: 'listItem', wrapperNames: ['bulletList', 'orderedList'] }]
|
|
11
|
+
*/
|
|
12
|
+
listTypes: Array<{
|
|
13
|
+
itemName: string;
|
|
14
|
+
wrapperNames: string[];
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* This extension registers custom keymaps to change the behaviour of the backspace and delete keys.
|
|
19
|
+
* By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into
|
|
20
|
+
* the adjacent or previous list item. This extension will prevent this behaviour and instead will
|
|
21
|
+
* try to join paragraphs from two list items into a single list item.
|
|
22
|
+
* @see https://www.tiptap.dev/api/extensions/list-keymap
|
|
23
|
+
*/
|
|
24
|
+
declare const ListKeymap: Extension<ListKeymapOptions, any>;
|
|
25
|
+
|
|
26
|
+
declare const findListItemPos: (typeOrName: string | NodeType, state: EditorState) => {
|
|
27
|
+
$pos: prosemirror_model.ResolvedPos;
|
|
28
|
+
depth: number;
|
|
29
|
+
} | null;
|
|
30
|
+
|
|
31
|
+
declare const getNextListDepth: (typeOrName: string, state: EditorState) => number | false;
|
|
32
|
+
|
|
33
|
+
declare const handleBackspace: (editor: Editor, name: string, parentListTypes: string[]) => boolean;
|
|
34
|
+
|
|
35
|
+
declare const handleDelete: (editor: Editor, name: string) => boolean;
|
|
36
|
+
|
|
37
|
+
declare const hasListBefore: (editorState: EditorState, name: string, parentListTypes: string[]) => boolean;
|
|
38
|
+
|
|
39
|
+
declare const hasListItemAfter: (typeOrName: string, state: EditorState) => boolean;
|
|
40
|
+
|
|
41
|
+
declare const hasListItemBefore: (typeOrName: string, state: EditorState) => boolean;
|
|
42
|
+
|
|
43
|
+
declare const listItemHasSubList: (typeOrName: string, state: EditorState, node?: Node) => boolean;
|
|
44
|
+
|
|
45
|
+
declare const nextListIsDeeper: (typeOrName: string, state: EditorState) => boolean;
|
|
46
|
+
|
|
47
|
+
declare const nextListIsHigher: (typeOrName: string, state: EditorState) => boolean;
|
|
48
|
+
|
|
49
|
+
declare const index_findListItemPos: typeof findListItemPos;
|
|
50
|
+
declare const index_getNextListDepth: typeof getNextListDepth;
|
|
51
|
+
declare const index_handleBackspace: typeof handleBackspace;
|
|
52
|
+
declare const index_handleDelete: typeof handleDelete;
|
|
53
|
+
declare const index_hasListBefore: typeof hasListBefore;
|
|
54
|
+
declare const index_hasListItemAfter: typeof hasListItemAfter;
|
|
55
|
+
declare const index_hasListItemBefore: typeof hasListItemBefore;
|
|
56
|
+
declare const index_listItemHasSubList: typeof listItemHasSubList;
|
|
57
|
+
declare const index_nextListIsDeeper: typeof nextListIsDeeper;
|
|
58
|
+
declare const index_nextListIsHigher: typeof nextListIsHigher;
|
|
59
|
+
declare namespace index {
|
|
60
|
+
export { index_findListItemPos as findListItemPos, index_getNextListDepth as getNextListDepth, index_handleBackspace as handleBackspace, index_handleDelete as handleDelete, index_hasListBefore as hasListBefore, index_hasListItemAfter as hasListItemAfter, index_hasListItemBefore as hasListItemBefore, index_listItemHasSubList as listItemHasSubList, index_nextListIsDeeper as nextListIsDeeper, index_nextListIsHigher as nextListIsHigher };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { ListKeymap, type ListKeymapOptions, ListKeymap as default, index as listHelpers };
|
package/dist/index.js
CHANGED
|
@@ -1,281 +1,282 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const nodeType = getNodeType(typeOrName, state.schema);
|
|
6
|
-
let currentNode = null;
|
|
7
|
-
let currentDepth = $from.depth;
|
|
8
|
-
let currentPos = $from.pos;
|
|
9
|
-
let targetDepth = null;
|
|
10
|
-
while (currentDepth > 0 && targetDepth === null) {
|
|
11
|
-
currentNode = $from.node(currentDepth);
|
|
12
|
-
if (currentNode.type === nodeType) {
|
|
13
|
-
targetDepth = currentDepth;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
currentDepth -= 1;
|
|
17
|
-
currentPos -= 1;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
if (targetDepth === null) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
5
|
};
|
|
25
6
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
7
|
+
// src/list-keymap.ts
|
|
8
|
+
import { Extension } from "@tiptap/core";
|
|
9
|
+
|
|
10
|
+
// src/listHelpers/index.ts
|
|
11
|
+
var listHelpers_exports = {};
|
|
12
|
+
__export(listHelpers_exports, {
|
|
13
|
+
findListItemPos: () => findListItemPos,
|
|
14
|
+
getNextListDepth: () => getNextListDepth,
|
|
15
|
+
handleBackspace: () => handleBackspace,
|
|
16
|
+
handleDelete: () => handleDelete,
|
|
17
|
+
hasListBefore: () => hasListBefore,
|
|
18
|
+
hasListItemAfter: () => hasListItemAfter,
|
|
19
|
+
hasListItemBefore: () => hasListItemBefore,
|
|
20
|
+
listItemHasSubList: () => listItemHasSubList,
|
|
21
|
+
nextListIsDeeper: () => nextListIsDeeper,
|
|
22
|
+
nextListIsHigher: () => nextListIsHigher
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// src/listHelpers/findListItemPos.ts
|
|
26
|
+
import { getNodeType } from "@tiptap/core";
|
|
27
|
+
var findListItemPos = (typeOrName, state) => {
|
|
28
|
+
const { $from } = state.selection;
|
|
29
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
30
|
+
let currentNode = null;
|
|
31
|
+
let currentDepth = $from.depth;
|
|
32
|
+
let currentPos = $from.pos;
|
|
33
|
+
let targetDepth = null;
|
|
34
|
+
while (currentDepth > 0 && targetDepth === null) {
|
|
35
|
+
currentNode = $from.node(currentDepth);
|
|
36
|
+
if (currentNode.type === nodeType) {
|
|
37
|
+
targetDepth = currentDepth;
|
|
38
|
+
} else {
|
|
39
|
+
currentDepth -= 1;
|
|
40
|
+
currentPos -= 1;
|
|
30
41
|
}
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
}
|
|
43
|
+
if (targetDepth === null) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
|
|
33
47
|
};
|
|
34
48
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
// src/listHelpers/getNextListDepth.ts
|
|
50
|
+
import { getNodeAtPosition } from "@tiptap/core";
|
|
51
|
+
var getNextListDepth = (typeOrName, state) => {
|
|
52
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
53
|
+
if (!listItemPos) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
|
|
57
|
+
return depth;
|
|
43
58
|
};
|
|
44
59
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
// src/listHelpers/handleBackspace.ts
|
|
61
|
+
import { isAtStartOfNode, isNodeActive } from "@tiptap/core";
|
|
62
|
+
|
|
63
|
+
// src/listHelpers/hasListBefore.ts
|
|
64
|
+
var hasListBefore = (editorState, name, parentListTypes) => {
|
|
65
|
+
const { $anchor } = editorState.selection;
|
|
66
|
+
const previousNodePos = Math.max(0, $anchor.pos - 2);
|
|
67
|
+
const previousNode = editorState.doc.resolve(previousNodePos).node();
|
|
68
|
+
if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
56
72
|
};
|
|
57
73
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
// src/listHelpers/hasListItemBefore.ts
|
|
75
|
+
var hasListItemBefore = (typeOrName, state) => {
|
|
76
|
+
var _a;
|
|
77
|
+
const { $anchor } = state.selection;
|
|
78
|
+
const $targetPos = state.doc.resolve($anchor.pos - 2);
|
|
79
|
+
if ($targetPos.index() === 0) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (((_a = $targetPos.nodeBefore) == null ? void 0 : _a.type.name) !== typeOrName) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
70
86
|
};
|
|
71
87
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const listDescendants = [];
|
|
84
|
-
$listPos.node().descendants((node, pos) => {
|
|
85
|
-
if (node.type.name === name) {
|
|
86
|
-
listDescendants.push({ node, pos });
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
const lastItem = listDescendants.at(-1);
|
|
90
|
-
if (!lastItem) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
|
|
94
|
-
return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
|
|
95
|
-
}
|
|
96
|
-
// if the cursor is not inside the current node type
|
|
97
|
-
// do nothing and proceed
|
|
98
|
-
if (!isNodeActive(editor.state, name)) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
// if the cursor is not at the start of a node
|
|
102
|
-
// do nothing and proceed
|
|
103
|
-
if (!isAtStartOfNode(editor.state)) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
const listItemPos = findListItemPos(name, editor.state);
|
|
107
|
-
if (!listItemPos) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
|
|
111
|
-
const prevNode = $prev.node(listItemPos.depth);
|
|
112
|
-
const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
|
|
113
|
-
// if the previous item is a list item and doesn't have a sublist, join the list items
|
|
114
|
-
if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
|
|
115
|
-
return editor.commands.joinItemBackward();
|
|
88
|
+
// src/listHelpers/listItemHasSubList.ts
|
|
89
|
+
import { getNodeType as getNodeType2 } from "@tiptap/core";
|
|
90
|
+
var listItemHasSubList = (typeOrName, state, node) => {
|
|
91
|
+
if (!node) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const nodeType = getNodeType2(typeOrName, state.schema);
|
|
95
|
+
let hasSubList = false;
|
|
96
|
+
node.descendants((child) => {
|
|
97
|
+
if (child.type === nodeType) {
|
|
98
|
+
hasSubList = true;
|
|
116
99
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// joining / merging is not possible
|
|
120
|
-
return editor.chain().liftListItem(name).run();
|
|
100
|
+
});
|
|
101
|
+
return hasSubList;
|
|
121
102
|
};
|
|
122
103
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
104
|
+
// src/listHelpers/handleBackspace.ts
|
|
105
|
+
var handleBackspace = (editor, name, parentListTypes) => {
|
|
106
|
+
if (editor.commands.undoInputRule()) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
|
|
110
|
+
const { $anchor } = editor.state.selection;
|
|
111
|
+
const $listPos = editor.state.doc.resolve($anchor.before() - 1);
|
|
112
|
+
const listDescendants = [];
|
|
113
|
+
$listPos.node().descendants((node, pos) => {
|
|
114
|
+
if (node.type.name === name) {
|
|
115
|
+
listDescendants.push({ node, pos });
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const lastItem = listDescendants.at(-1);
|
|
119
|
+
if (!lastItem) {
|
|
120
|
+
return false;
|
|
131
121
|
}
|
|
122
|
+
const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
|
|
123
|
+
return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
|
|
124
|
+
}
|
|
125
|
+
if (!isNodeActive(editor.state, name)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (!isAtStartOfNode(editor.state)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const listItemPos = findListItemPos(name, editor.state);
|
|
132
|
+
if (!listItemPos) {
|
|
132
133
|
return false;
|
|
134
|
+
}
|
|
135
|
+
const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
|
|
136
|
+
const prevNode = $prev.node(listItemPos.depth);
|
|
137
|
+
const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
|
|
138
|
+
if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
|
|
139
|
+
return editor.commands.joinItemBackward();
|
|
140
|
+
}
|
|
141
|
+
return editor.chain().liftListItem(name).run();
|
|
133
142
|
};
|
|
134
143
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
+
// src/listHelpers/handleDelete.ts
|
|
145
|
+
import { isAtEndOfNode, isNodeActive as isNodeActive2 } from "@tiptap/core";
|
|
146
|
+
|
|
147
|
+
// src/listHelpers/nextListIsDeeper.ts
|
|
148
|
+
var nextListIsDeeper = (typeOrName, state) => {
|
|
149
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
150
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
151
|
+
if (!listItemPos || !listDepth) {
|
|
144
152
|
return false;
|
|
153
|
+
}
|
|
154
|
+
if (listDepth > listItemPos.depth) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
145
158
|
};
|
|
146
159
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// check if the next node is a list with a deeper depth
|
|
159
|
-
if (nextListIsDeeper(name, editor.state)) {
|
|
160
|
-
return editor
|
|
161
|
-
.chain()
|
|
162
|
-
.focus(editor.state.selection.from + 4)
|
|
163
|
-
.lift(name)
|
|
164
|
-
.joinBackward()
|
|
165
|
-
.run();
|
|
166
|
-
}
|
|
167
|
-
if (nextListIsHigher(name, editor.state)) {
|
|
168
|
-
return editor.chain()
|
|
169
|
-
.joinForward()
|
|
170
|
-
.joinBackward()
|
|
171
|
-
.run();
|
|
172
|
-
}
|
|
173
|
-
return editor.commands.joinItemForward();
|
|
160
|
+
// src/listHelpers/nextListIsHigher.ts
|
|
161
|
+
var nextListIsHigher = (typeOrName, state) => {
|
|
162
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
163
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
164
|
+
if (!listItemPos || !listDepth) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
if (listDepth < listItemPos.depth) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
174
171
|
};
|
|
175
172
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
173
|
+
// src/listHelpers/handleDelete.ts
|
|
174
|
+
var handleDelete = (editor, name) => {
|
|
175
|
+
if (!isNodeActive2(editor.state, name)) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
if (!isAtEndOfNode(editor.state, name)) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
if (nextListIsDeeper(name, editor.state)) {
|
|
182
|
+
return editor.chain().focus(editor.state.selection.from + 4).lift(name).joinBackward().run();
|
|
183
|
+
}
|
|
184
|
+
if (nextListIsHigher(name, editor.state)) {
|
|
185
|
+
return editor.chain().joinForward().joinBackward().run();
|
|
186
|
+
}
|
|
187
|
+
return editor.commands.joinItemForward();
|
|
187
188
|
};
|
|
188
189
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
190
|
+
// src/listHelpers/hasListItemAfter.ts
|
|
191
|
+
var hasListItemAfter = (typeOrName, state) => {
|
|
192
|
+
var _a;
|
|
193
|
+
const { $anchor } = state.selection;
|
|
194
|
+
const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
|
|
195
|
+
if ($targetPos.index() === $targetPos.parent.childCount - 1) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
if (((_a = $targetPos.nodeAfter) == null ? void 0 : _a.type.name) !== typeOrName) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
return true;
|
|
202
|
+
};
|
|
202
203
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
return handled;
|
|
275
|
-
},
|
|
276
|
-
};
|
|
277
|
-
},
|
|
204
|
+
// src/list-keymap.ts
|
|
205
|
+
var ListKeymap = Extension.create({
|
|
206
|
+
name: "listKeymap",
|
|
207
|
+
addOptions() {
|
|
208
|
+
return {
|
|
209
|
+
listTypes: [
|
|
210
|
+
{
|
|
211
|
+
itemName: "listItem",
|
|
212
|
+
wrapperNames: ["bulletList", "orderedList"]
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
itemName: "taskItem",
|
|
216
|
+
wrapperNames: ["taskList"]
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
addKeyboardShortcuts() {
|
|
222
|
+
return {
|
|
223
|
+
Delete: ({ editor }) => {
|
|
224
|
+
let handled = false;
|
|
225
|
+
this.options.listTypes.forEach(({ itemName }) => {
|
|
226
|
+
if (editor.state.schema.nodes[itemName] === void 0) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (handleDelete(editor, itemName)) {
|
|
230
|
+
handled = true;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
return handled;
|
|
234
|
+
},
|
|
235
|
+
"Mod-Delete": ({ editor }) => {
|
|
236
|
+
let handled = false;
|
|
237
|
+
this.options.listTypes.forEach(({ itemName }) => {
|
|
238
|
+
if (editor.state.schema.nodes[itemName] === void 0) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (handleDelete(editor, itemName)) {
|
|
242
|
+
handled = true;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
return handled;
|
|
246
|
+
},
|
|
247
|
+
Backspace: ({ editor }) => {
|
|
248
|
+
let handled = false;
|
|
249
|
+
this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
|
|
250
|
+
if (editor.state.schema.nodes[itemName] === void 0) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (handleBackspace(editor, itemName, wrapperNames)) {
|
|
254
|
+
handled = true;
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
return handled;
|
|
258
|
+
},
|
|
259
|
+
"Mod-Backspace": ({ editor }) => {
|
|
260
|
+
let handled = false;
|
|
261
|
+
this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
|
|
262
|
+
if (editor.state.schema.nodes[itemName] === void 0) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (handleBackspace(editor, itemName, wrapperNames)) {
|
|
266
|
+
handled = true;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
return handled;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
278
273
|
});
|
|
279
274
|
|
|
280
|
-
|
|
281
|
-
|
|
275
|
+
// src/index.ts
|
|
276
|
+
var src_default = ListKeymap;
|
|
277
|
+
export {
|
|
278
|
+
ListKeymap,
|
|
279
|
+
src_default as default,
|
|
280
|
+
listHelpers_exports as listHelpers
|
|
281
|
+
};
|
|
282
|
+
//# sourceMappingURL=index.js.map
|