"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var editor_exports = {};
__export(editor_exports, {
  pluginSmartBlock: () => pluginSmartBlock,
  resolveSmartBlockReferenceElement: () => import_resolve_smart_block_reference_element2.resolveSmartBlockReferenceElement
});
module.exports = __toCommonJS(editor_exports);
var import_consts = require("./../ricos-content/consts.js");
var import_ricos_types = require("./../ricos-types/index.js");
var import_pm_node_types = require("./../_shared/pm-node-types.js");
var import_core = require("./../tiptap/core.js");
var import_get_add_buttons = require("./get-add-buttons.js");
var import_get_quick_actions = require("./get-quick-actions.js");
var import_get_toolbar_buttons = require("./get-toolbar-buttons.js");
var import_smart_block_cell_converter = require("./smart-block-cell-converter.js");
var import_smart_block_converter = require("./smart-block-converter.js");
var import_smart_block_cell_extension = require("./tiptap/smart-block-cell-extension.js");
var import_smart_block_extension = require("./tiptap/smart-block-extension.js");
var import_resolve_smart_block_reference_element = require("./toolbar/resolve-smart-block-reference-element.js");
var import_resolve_smart_block_reference_element2 = require("./toolbar/resolve-smart-block-reference-element.js");
const pluginSmartBlock = (config = {}) => {
  return {
    config: { ...config, type: "smartBlock" },
    type: import_consts.SMART_BLOCK_TYPE,
    pmMarkConverters: [],
    pmNodeConverters: [import_smart_block_converter.smartBlockConverter, import_smart_block_cell_converter.smartBlockCellConverter],
    tiptapExtensions: [import_smart_block_extension.smartBlockExtension, import_smart_block_cell_extension.smartBlockCellExtension],
    toolbar: {
      names: [import_ricos_types.RicosPluginToolbarNames.SMART_BLOCK, import_ricos_types.RicosPluginToolbarNames.SMART_BLOCK_CELL],
      isVisible: isToolbarVisible,
      getButtons: (config2, services) => (0, import_get_toolbar_buttons.getToolbarButtons)(config2, services),
      resolveReferenceElement: import_resolve_smart_block_reference_element.resolveSmartBlockReferenceElement
    },
    getAddButtons: (config2, services) => (0, import_get_add_buttons.getAddButtons)(config2, services),
    getQuickActions: ({ pluginServices, config: config2 }) => (0, import_get_quick_actions.getQuickActions)(config2, pluginServices)
  };
};
const isToolbarVisible = (selection) => {
  if ("node" in selection && selection.node?.type.name === import_pm_node_types.PmNodeType.SMART_BLOCK) {
    return true;
  }
  if ("node" in selection && selection.node?.type.name === import_pm_node_types.PmNodeType.SMART_BLOCK_CELL) {
    return true;
  }
  if ("node" in selection) {
    return false;
  }
  const closestContainer = (0, import_core.findParentNodeClosestToPos)(
    selection.$from,
    (node) => node.type.name === import_pm_node_types.PmNodeType.SMART_BLOCK || node.type.name === import_consts.TIPTAP_COLLAPSIBLE_LIST_TYPE
  );
  return closestContainer?.node.type.name === import_pm_node_types.PmNodeType.SMART_BLOCK;
};
//# sourceMappingURL=editor.js.map
