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

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"],
@@ -7945,6 +7948,13 @@ const ListExtension = () => Extension.create({
7945
7948
  ({ node }) => {
7946
7949
  if (node.isMatch({ tag: "ol" }) || node.isMatch({ tag: "ul" })) {
7947
7950
  node.type = "block";
7951
+ if (!node.hasStyles()) {
7952
+ node.styles = {
7953
+ listStyleType: node.isMatch({ tag: "ol" }) ? "decimal" : "disc"
7954
+ };
7955
+ } else if (!node.styles.listStyleType) {
7956
+ node.styles.listStyleType = node.isMatch({ tag: "ol" }) ? "decimal" : "disc";
7957
+ }
7948
7958
  }
7949
7959
  },
7950
7960
  //列表项处理
@@ -7988,6 +7998,16 @@ const ListExtension = () => Extension.create({
7988
7998
  }
7989
7999
  return true;
7990
8000
  },
8001
+ onKeydown(event2) {
8002
+ var _a, _b, _c, _d;
8003
+ if (isOnlyTab(event2)) {
8004
+ const result = (_b = (_a = this.commands).canCreateInnerList) == null ? void 0 : _b.call(_a);
8005
+ if (!!result) {
8006
+ event2.preventDefault();
8007
+ (_d = (_c = this.commands).createInnerList) == null ? void 0 : _d.call(_c);
8008
+ }
8009
+ }
8010
+ },
7991
8011
  addCommands() {
7992
8012
  const getList = (options) => {
7993
8013
  if (options.listType) {
@@ -8054,12 +8074,58 @@ const ListExtension = () => Extension.create({
8054
8074
  }
8055
8075
  await this.updateView();
8056
8076
  };
8077
+ const canCreateInnerList = () => {
8078
+ const node = this.getMatchNodeBySelection({ tag: "li" });
8079
+ if (!node || !node.parent) {
8080
+ return null;
8081
+ }
8082
+ const previousNode = node.getPrevious(node.parent.children);
8083
+ if (!previousNode || !previousNode.isMatch({ tag: "li" })) {
8084
+ return null;
8085
+ }
8086
+ return { node, previousNode };
8087
+ };
8088
+ const createInnerList = async () => {
8089
+ const result = canCreateInnerList();
8090
+ if (!result) {
8091
+ return;
8092
+ }
8093
+ const { node, previousNode } = result;
8094
+ if (!previousNode.children.some((item) => item.isBlock())) {
8095
+ const paragraph = KNode.create({
8096
+ tag: this.blockRenderTag,
8097
+ type: "block",
8098
+ marks: {},
8099
+ styles: {},
8100
+ fixed: false,
8101
+ nested: false,
8102
+ locked: false,
8103
+ namespace: ""
8104
+ });
8105
+ paragraph.children = previousNode.children;
8106
+ paragraph.children.forEach((child) => {
8107
+ child.parent = paragraph;
8108
+ });
8109
+ previousNode.children = [paragraph];
8110
+ paragraph.parent = previousNode;
8111
+ }
8112
+ const innerList = node.parent.clone(false);
8113
+ const index = node.parent.children.findIndex((item) => item.isEqual(node));
8114
+ node.parent.children.splice(index, 1);
8115
+ node.parent = innerList;
8116
+ innerList.children = [node];
8117
+ innerList.parent = previousNode;
8118
+ previousNode.children.push(innerList);
8119
+ await this.updateView();
8120
+ };
8057
8121
  return {
8058
8122
  getList,
8059
8123
  hasList,
8060
8124
  allList,
8061
8125
  setList,
8062
- unsetList
8126
+ unsetList,
8127
+ canCreateInnerList,
8128
+ createInnerList
8063
8129
  };
8064
8130
  }
8065
8131
  });