"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 use_node_attrs_exports = {};
__export(use_node_attrs_exports, {
  useNodeAttrs: () => useNodeAttrs
});
module.exports = __toCommonJS(use_node_attrs_exports);
var import_react = require("react");
var import_ricos_context = require("./../ricos-context/index.js");
var import_wix_rich_content_common = require("./../wix-rich-content-common/index.js");
var import_helpers = require("./../tiptap-editor/helpers/index.js");
const useNodeAttrs = (nodeId, nodeType) => {
  const { adapter } = (0, import_react.useContext)(import_ricos_context.EditorContext);
  const devPmNodeAttrs = (0, import_ricos_context.useDevPmNodeAttrs)();
  const patchPmNodeAttrs = (0, import_react.useMemo)(
    () => (
      // @ts-ignore $TSFixMe
      (0, import_wix_rich_content_common.createThrottle)((attrs, options) => {
        adapter.tiptapEditor.commands.updateNodeAttrsById(nodeId, attrs, options);
      })
    ),
    []
  );
  if (devPmNodeAttrs) {
    return {
      pmNodeAttrs: devPmNodeAttrs,
      patchPmNodeAttrs: () => {
      }
    };
  }
  const tr = adapter.tiptapEditor.view.state.tr;
  const nodeWithPos = (0, import_helpers.findNodeById)(tr, nodeId);
  const { node } = nodeWithPos?.[0] ?? {};
  if (!node || node.type.name !== nodeType) {
    return { pmNodeAttrs: void 0, patchPmNodeAttrs: void 0 };
  }
  return {
    pmNodeAttrs: node.attrs,
    patchPmNodeAttrs
  };
};
//# sourceMappingURL=use-node-attrs.js.map
