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

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.
@@ -7930,6 +7930,26 @@ const listMergeHandler = ({ editor, node }) => {
7930
7930
  const isOnlyTab = (e) => {
7931
7931
  return e.key.toLocaleLowerCase() == "tab" && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey;
7932
7932
  };
7933
+ const getUnsetListItemNode = (matchNode, options) => {
7934
+ while (true) {
7935
+ if (!matchNode) {
7936
+ break;
7937
+ }
7938
+ const params = {
7939
+ tag: options.ordered ? "ol" : "ul"
7940
+ };
7941
+ if (options.listType) {
7942
+ params.styles = {
7943
+ listStyleType: options.listType
7944
+ };
7945
+ }
7946
+ if (matchNode.parent.isMatch(params)) {
7947
+ break;
7948
+ }
7949
+ matchNode = matchNode.parent.getMatchNode({ tag: "li" });
7950
+ }
7951
+ return matchNode;
7952
+ };
7933
7953
  const ListExtension = () => Extension.create({
7934
7954
  name: "list",
7935
7955
  extraKeepTags: ["ul", "ol", "li"],
@@ -8010,37 +8030,37 @@ const ListExtension = () => Extension.create({
8010
8030
  },
8011
8031
  addCommands() {
8012
8032
  const getList = (options) => {
8033
+ const params = {
8034
+ tag: options.ordered ? "ol" : "ul"
8035
+ };
8013
8036
  if (options.listType) {
8014
- return this.getMatchNodeBySelection({
8015
- tag: options.ordered ? "ol" : "ul",
8016
- styles: {
8017
- listStyleType: options.listType
8018
- }
8019
- });
8037
+ params.styles = {
8038
+ listStyleType: options.listType
8039
+ };
8020
8040
  }
8021
- return this.getMatchNodeBySelection({ tag: options.ordered ? "ol" : "ul" });
8041
+ return this.getMatchNodeBySelection(params);
8022
8042
  };
8023
8043
  const hasList = (options) => {
8044
+ const params = {
8045
+ tag: options.ordered ? "ol" : "ul"
8046
+ };
8024
8047
  if (options.listType) {
8025
- return this.isSelectionNodesSomeMatch({
8026
- tag: options.ordered ? "ol" : "ul",
8027
- styles: {
8028
- listStyleType: options.listType
8029
- }
8030
- });
8048
+ params.styles = {
8049
+ listStyleType: options.listType
8050
+ };
8031
8051
  }
8032
- return this.isSelectionNodesSomeMatch({ tag: options.ordered ? "ol" : "ul" });
8052
+ return this.isSelectionNodesSomeMatch(params);
8033
8053
  };
8034
8054
  const allList = (options) => {
8055
+ const params = {
8056
+ tag: options.ordered ? "ol" : "ul"
8057
+ };
8035
8058
  if (options.listType) {
8036
- return this.isSelectionNodesAllMatch({
8037
- tag: options.ordered ? "ol" : "ul",
8038
- styles: {
8039
- listStyleType: options.listType
8040
- }
8041
- });
8059
+ params.styles = {
8060
+ listStyleType: options.listType
8061
+ };
8042
8062
  }
8043
- return this.isSelectionNodesAllMatch({ tag: options.ordered ? "ol" : "ul" });
8063
+ return this.isSelectionNodesAllMatch(params);
8044
8064
  };
8045
8065
  const setList = async (options) => {
8046
8066
  if (allList(options)) {
@@ -8063,12 +8083,12 @@ const ListExtension = () => Extension.create({
8063
8083
  }
8064
8084
  if (this.selection.collapsed()) {
8065
8085
  const blockNode = this.selection.start.node.getBlock();
8066
- const matchNode = blockNode.getMatchNode({ tag: "li" });
8086
+ const matchNode = getUnsetListItemNode(blockNode.getMatchNode({ tag: "li" }), options);
8067
8087
  if (matchNode) ListItemToParagraph(this, matchNode);
8068
8088
  } else {
8069
8089
  const blockNodes = getSelectionBlockNodes.apply(this);
8070
8090
  blockNodes.forEach((item) => {
8071
- const matchNode = item.getMatchNode({ tag: "li" });
8091
+ const matchNode = getUnsetListItemNode(item.getMatchNode({ tag: "li" }), options);
8072
8092
  if (matchNode) ListItemToParagraph(this, matchNode);
8073
8093
  });
8074
8094
  }