import { Node_Type } from "./../../ricos-schema/legacy/wix/rich_content/v1/index.js";
import { Plugin, PluginKey } from "./../../tiptap/pm/state.js";
import { findParentList } from "../list-item/commands/commons.js";
const createCheckboxStateNormalizingTransactionPlugin = () => new Plugin({
  key: new PluginKey("normalize-checkbox-state"),
  appendTransaction: (_, oldState, newState) => {
    if (newState.doc === oldState.doc) {
      return;
    }
    const tr = newState.tr;
    let changed = false;
    newState.doc.descendants((node, pos) => {
      if (node.type.name !== Node_Type.LIST_ITEM || node.attrs.checked === null) {
        return;
      }
      const parentList = findParentList(newState.doc.resolve(pos));
      if (!parentList || parentList.node.type.name !== Node_Type.CHECKBOX_LIST) {
        tr.setNodeAttribute(pos, "checked", null);
        changed = true;
      }
    });
    return changed ? tr : void 0;
  }
});
export {
  createCheckboxStateNormalizingTransactionPlugin
};
//# sourceMappingURL=checkbox-state-normalizing.js.map
