"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 BuilderPlugin_exports = {};
__export(BuilderPlugin_exports, {
  withBuilder: () => withBuilder
});
module.exports = __toCommonJS(BuilderPlugin_exports);
var import_slate = require("slate");
var import_slate_react = require("slate-react");
var import_controls = require("@makeswift/controls");
function withBuilder(editor) {
  editor.resetValue = function(value) {
    const firstRootBlock = import_slate.Node.has(editor, [0]) && import_slate.Node.get(editor, [0]);
    const textAlignOfFirstBlock = firstRootBlock && import_controls.Slate.isRootBlock(firstRootBlock) ? firstRootBlock.textAlign : void 0;
    const typographyOfFirstText = Array.from(import_slate.Node.texts(editor)).at(0)?.[0].typography;
    import_slate_react.ReactEditor.deselect(editor);
    import_slate_react.ReactEditor.blur(editor);
    editor.children = value;
    editor.onChange();
    if (typographyOfFirstText) {
      import_slate.Transforms.setNodes(
        editor,
        { typography: typographyOfFirstText },
        {
          match: import_slate.Text.isText,
          at: {
            anchor: import_slate.Editor.start(editor, []),
            focus: import_slate.Editor.end(editor, [])
          }
        }
      );
    }
    if (textAlignOfFirstBlock) {
      import_slate.Transforms.setNodes(
        editor,
        { textAlign: textAlignOfFirstBlock },
        {
          match: import_controls.Slate.isRootBlock,
          at: {
            anchor: import_slate.Editor.start(editor, []),
            focus: import_slate.Editor.end(editor, [])
          }
        }
      );
    }
  };
  editor.deselectAndBlur = function() {
    import_slate_react.ReactEditor.deselect(editor);
    import_slate_react.ReactEditor.blur(editor);
  };
  editor.focusAndSelectAll = function() {
    import_slate_react.ReactEditor.focus(editor);
    import_slate.Transforms.select(editor, {
      anchor: import_slate.Editor.start(editor, []),
      focus: import_slate.Editor.end(editor, [])
    });
  };
  return editor;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  withBuilder
});
//# sourceMappingURL=index.js.map