"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var extension_exports = {};
__export(extension_exports, {
  checkboxList: () => checkboxList
});
module.exports = __toCommonJS(extension_exports);
var import_core = require("./../../tiptap/core/index.js");
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_checkbox_list_style = require("./../../_shared/list-checkbox/checkbox-list-style.js");
var import_is_checkbox_list_element = require("./../../_shared/list-checkbox/is-checkbox-list-element.js");
var import_plugin_commons = require("./../../plugin-commons/index.js");
var import_list_input_rule_handler = require("../list-input-rule-handler.js");
var import_styles_scss = __toESM(require("../statics/styles-scss.js"));
const checkboxInputRegex = /^\s*(\[\]|\[ \])\s$/;
const checkboxList = (0, import_plugin_commons.createRicosNodeExtension)({
  groups: ["no-trailing-node"],
  type: "html-node",
  name: import_v1.Node_Type.CHECKBOX_LIST,
  createExtensionConfig() {
    return {
      name: this.name,
      // Must be higher than bulletedList (default 100) so `<ul data-list-style="checkbox">`
      // is parsed as a checkbox list before a regular bullet list can claim it.
      // Must stay BELOW paragraph's priority (1000) so paragraph remains the
      // `defaultType` for the `block+` content expression. If checkbox-list ties
      // with paragraph, it can become the default block type, which causes
      // `normalizeNodes` (used by `toggleLists`) to try retyping textblocks into
      // CHECKBOX_LIST and throw "Invalid content for node type CHECKBOX_LIST".
      priority: 200,
      addOptions() {
        return {
          HTMLAttributes: { class: import_styles_scss.default.checkboxList },
          itemTypeName: import_v1.Node_Type.LIST_ITEM
        };
      },
      group: "block list listItemSecondChildContent smartBlockCellContent layoutCellContent collapsibleListItemTitleContent collapsibleListItemBodyContent tableCellContent",
      content() {
        return "LIST_ITEM+";
      },
      parseHTML() {
        return [
          {
            tag: "ul",
            getAttrs: (element) => (0, import_is_checkbox_list_element.isCheckboxListElement)(element) ? {} : false
          }
        ];
      },
      addAttributes() {
        return {
          indentation: { default: 0 },
          offset: { default: 0 }
        };
      },
      renderHTML({ HTMLAttributes }) {
        return (0, import_plugin_commons.withBreakoutContainer)([
          "ul",
          (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {
            "data-list-style": import_checkbox_list_style.CHECKBOX_LIST_STYLE_ATTRIBUTE_VALUE
          }),
          0
        ]);
      },
      addCommands() {
        return {
          toggleCheckboxList: () => ({ commands }) => commands.toggleLists(this.name, this.options.itemTypeName),
          toggleOffCheckboxList: () => ({ state, commands }) => {
            const isActive = (0, import_core.isNodeActive)(state, (0, import_core.getNodeType)(this.name, state.schema));
            return isActive ? commands.toggleCheckboxList() : true;
          }
        };
      },
      addInputRules() {
        return [
          new import_core.InputRule({
            find: checkboxInputRegex,
            handler: (0, import_list_input_rule_handler.createListInputRuleHandler)({
              type: this.type,
              getItemAttributes: { checked: false }
            })
          })
        ];
      }
    };
  }
});
//# sourceMappingURL=extension.js.map
