"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 node_exports = {};
__export(node_exports, {
  Node: () => Node
});
module.exports = __toCommonJS(node_exports);
var import_get_extension_field = require("./helpers/get-extension-field.js");
var import_call_or_return = require("./utilities/call-or-return.js");
var import_merge_deep = require("./utilities/merge-deep.js");
class Node {
  constructor(config = {}) {
    this.type = "node";
    this.name = "node";
    this.parent = null;
    this.child = null;
    this.config = {
      name: this.name,
      defaultOptions: {}
    };
    this.config = {
      ...this.config,
      ...config
    };
    this.name = this.config.name;
    if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
      console.warn(
        `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`
      );
    }
    this.options = this.config.defaultOptions;
    if (this.config.addOptions) {
      this.options = (0, import_call_or_return.callOrReturn)(
        (0, import_get_extension_field.getExtensionField)(this, "addOptions", {
          name: this.name
        })
      );
    }
    this.storage = (0, import_call_or_return.callOrReturn)(
      (0, import_get_extension_field.getExtensionField)(this, "addStorage", {
        name: this.name,
        options: this.options
      })
    ) || {};
  }
  static create(config = {}) {
    return new Node(config);
  }
  configure(options = {}) {
    const extension = this.extend({
      ...this.config,
      addOptions: () => {
        return (0, import_merge_deep.mergeDeep)(this.options, options);
      }
    });
    extension.name = this.name;
    extension.parent = this.parent;
    return extension;
  }
  extend(extendedConfig = {}) {
    const extension = new Node(extendedConfig);
    extension.parent = this;
    this.child = extension;
    extension.name = extendedConfig.name ? extendedConfig.name : extension.parent.name;
    if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
      console.warn(
        `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`
      );
    }
    extension.options = (0, import_call_or_return.callOrReturn)(
      (0, import_get_extension_field.getExtensionField)(extension, "addOptions", {
        name: extension.name
      })
    );
    extension.storage = (0, import_call_or_return.callOrReturn)(
      (0, import_get_extension_field.getExtensionField)(extension, "addStorage", {
        name: extension.name,
        options: extension.options
      })
    );
    return extension;
  }
}
//# sourceMappingURL=node.js.map
