@kaitify/core 0.0.1-beta.13 → 0.0.1-beta.14

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.
@@ -13,6 +13,11 @@ declare module '../../model' {
13
13
  allList?: (options: ListOptionsType) => boolean;
14
14
  setList?: (options: ListOptionsType) => Promise<void>;
15
15
  unsetList?: (options: ListOptionsType) => Promise<void>;
16
+ canCreateInnerList?: () => {
17
+ node: KNode;
18
+ previousNode: KNode;
19
+ } | null;
20
+ createInnerList?: () => Promise<void>;
16
21
  }
17
22
  }
18
23
  export declare const ListExtension: () => Extension;
@@ -7927,6 +7927,9 @@ const listMergeHandler = ({ editor, node }) => {
7927
7927
  }
7928
7928
  }
7929
7929
  };
7930
+ const isOnlyTab = (e) => {
7931
+ return e.key.toLocaleLowerCase() == "tab" && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey;
7932
+ };
7930
7933
  const ListExtension = () => Extension.create({
7931
7934
  name: "list",
7932
7935
  extraKeepTags: ["ul", "ol", "li"],
@@ -7988,6 +7991,16 @@ const ListExtension = () => Extension.create({
7988
7991
  }
7989
7992
  return true;
7990
7993
  },
7994
+ onKeydown(event2) {
7995
+ var _a, _b, _c, _d;
7996
+ if (isOnlyTab(event2)) {
7997
+ const result = (_b = (_a = this.commands).canCreateInnerList) == null ? void 0 : _b.call(_a);
7998
+ if (!!result) {
7999
+ event2.preventDefault();
8000
+ (_d = (_c = this.commands).createInnerList) == null ? void 0 : _d.call(_c);
8001
+ }
8002
+ }
8003
+ },
7991
8004
  addCommands() {
7992
8005
  const getList = (options) => {
7993
8006
  if (options.listType) {
@@ -8054,12 +8067,58 @@ const ListExtension = () => Extension.create({
8054
8067
  }
8055
8068
  await this.updateView();
8056
8069
  };
8070
+ const canCreateInnerList = () => {
8071
+ const node = this.getMatchNodeBySelection({ tag: "li" });
8072
+ if (!node || !node.parent) {
8073
+ return null;
8074
+ }
8075
+ const previousNode = node.getPrevious(node.parent.children);
8076
+ if (!previousNode || !previousNode.isMatch({ tag: "li" })) {
8077
+ return null;
8078
+ }
8079
+ return { node, previousNode };
8080
+ };
8081
+ const createInnerList = async () => {
8082
+ const result = canCreateInnerList();
8083
+ if (!result) {
8084
+ return;
8085
+ }
8086
+ const { node, previousNode } = result;
8087
+ if (!previousNode.children.some((item) => item.isBlock())) {
8088
+ const paragraph = KNode.create({
8089
+ tag: this.blockRenderTag,
8090
+ type: "block",
8091
+ marks: {},
8092
+ styles: {},
8093
+ fixed: false,
8094
+ nested: false,
8095
+ locked: false,
8096
+ namespace: ""
8097
+ });
8098
+ paragraph.children = previousNode.children;
8099
+ paragraph.children.forEach((child) => {
8100
+ child.parent = paragraph;
8101
+ });
8102
+ previousNode.children = [paragraph];
8103
+ paragraph.parent = previousNode;
8104
+ }
8105
+ const innerList = node.parent.clone(false);
8106
+ const index = node.parent.children.findIndex((item) => item.isEqual(node));
8107
+ node.parent.children.splice(index, 1);
8108
+ node.parent = innerList;
8109
+ innerList.children = [node];
8110
+ innerList.parent = previousNode;
8111
+ previousNode.children.push(innerList);
8112
+ await this.updateView();
8113
+ };
8057
8114
  return {
8058
8115
  getList,
8059
8116
  hasList,
8060
8117
  allList,
8061
8118
  setList,
8062
- unsetList
8119
+ unsetList,
8120
+ canCreateInnerList,
8121
+ createInnerList
8063
8122
  };
8064
8123
  }
8065
8124
  });