"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 name2 in all)
    __defProp(target, name2, { get: all[name2], 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 tiptap_exports = {};
__export(tiptap_exports, {
  tiptapExtensions: () => tiptapExtensions
});
module.exports = __toCommonJS(tiptap_exports);
var import_ricos_content = require("./../../ricos-content/index.js");
var import_state = require("./../../tiptap/pm/state.js");
var import_general_scss = __toESM(require("./../../editor-common/statics/styles/general-scss.js"));
var import_plugin_commons = require("./../../plugin-commons/index.js");
var import_data_hooks = require("../data-hooks.js");
var import_component = require("./component.js");
const name = import_ricos_content.TIPTAP_AUDIO_TYPE;
const tiptapExtensions = [
  (0, import_plugin_commons.createRicosNodeExtension)({
    groups: [
      "overlay",
      "draggable",
      "not-overtypable",
      { group: "resizable", options: { minWidth: 90 } }
    ],
    type: "react-node",
    name,
    reconfigure: (config, _extensions, _props, settings) => ({
      ...config,
      addOptions: () => settings
    }),
    Component: import_component.Audio,
    renderingOptions: {
      onDragStart({ editor, dragHandle, target, event }) {
        if (!this.dom || !dragHandle || this.contentDOM?.contains(target)) {
          return;
        }
        const audioRoot = this.dom.querySelector(`[data-hook="${import_data_hooks.ROOT}"]`) ?? this.dom;
        const nativeEvent = "nativeEvent" in event ? event.nativeEvent : event;
        const rootBox = audioRoot.getBoundingClientRect();
        const clientX = nativeEvent.clientX;
        const clientY = nativeEvent.clientY;
        const x = Math.min(Math.max(clientX - rootBox.left, 0), rootBox.width - 1);
        const y = Math.min(Math.max(clientY - rootBox.top, 0), rootBox.height - 1);
        audioRoot.classList.add(import_general_scss.default.dragImageView);
        audioRoot.style.overflow = "hidden";
        audioRoot.style.isolation = "isolate";
        event.dataTransfer?.setDragImage(audioRoot, x, y);
        setTimeout(() => {
          audioRoot.classList.remove(import_general_scss.default.dragImageView);
          audioRoot.style.overflow = "";
          audioRoot.style.isolation = "";
        }, 0);
        const selection = import_state.NodeSelection.create(editor.view.state.doc, this.getPos());
        const transaction = editor.view.state.tr.setSelection(selection);
        editor.view.dispatch(transaction);
      }
    },
    createExtensionConfig() {
      return {
        name: this.name,
        group: "block smartBlockCellContent layoutCellContent collapsibleListItemBodyContent tableCellContent",
        selectable: true,
        draggable: true,
        addAttributes: () => ({
          containerData: null,
          audio: null,
          disableDownload: null,
          coverImage: null,
          name: null,
          authorName: null,
          html: null,
          loading: {
            default: false
          },
          error: null
        }),
        addCommands() {
          return {};
        }
      };
    }
  })
];
//# sourceMappingURL=tiptap.js.map
