"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 control_exports = {};
__export(control_exports, {
  RichTextControl: () => RichTextControl
});
module.exports = __toCommonJS(control_exports);
var import_builder_edit_mode = require("../../state/modules/builder-edit-mode");
var import_controls = require("@makeswift/controls");
class RichTextControl extends import_controls.ControlInstance {
  static CHANGE_BUILDER_EDIT_MODE = "CHANGE_BUILDER_EDIT_MODE";
  static INITIALIZE_EDITOR = "INITIALIZE_EDITOR";
  static CHANGE_EDITOR_VALUE = "CHANGE_EDITOR_VALUE";
  static FOCUS = "FOCUS";
  static BLUR = "BLUR";
  static UNDO = "UNDO";
  static REDO = "REDO";
  static CHANGE_BOX_MODEL = "CHANGE_BOX_MODEL";
  editor = null;
  child(_key) {
    return void 0;
  }
  recv = (message) => {
    if (!this.editor)
      return;
    switch (message.type) {
      case RichTextControl.CHANGE_BUILDER_EDIT_MODE: {
        switch (message.payload.editMode) {
          case import_builder_edit_mode.BuilderEditMode.BUILD:
          case import_builder_edit_mode.BuilderEditMode.INTERACT:
            this.editor.deselectAndBlur();
        }
        break;
      }
      case RichTextControl.FOCUS: {
        this.editor.focusAndSelectAll();
        break;
      }
    }
  };
  setSlateEditor(editor) {
    this.editor = editor;
    this.sendMessage({
      type: RichTextControl.INITIALIZE_EDITOR,
      value: (0, import_controls.richTextDAOToDTO)(editor.children, editor.selection)
    });
    const _onChange = editor.onChange;
    this.editor.onChange = (options) => {
      _onChange(options);
      if (options?.operation != null) {
        this.sendMessage({
          type: RichTextControl.CHANGE_EDITOR_VALUE,
          value: (0, import_controls.richTextDAOToDTO)(editor.children, editor.selection)
        });
      }
    };
  }
  focus() {
    this.sendMessage({ type: RichTextControl.FOCUS });
  }
  blur() {
    this.sendMessage({ type: RichTextControl.BLUR });
  }
  undo() {
    this.sendMessage({ type: RichTextControl.UNDO });
  }
  redo() {
    this.sendMessage({ type: RichTextControl.REDO });
  }
  changeBoxModel(boxModel) {
    this.sendMessage({
      type: RichTextControl.CHANGE_BOX_MODEL,
      payload: { boxModel }
    });
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  RichTextControl
});
//# sourceMappingURL=control.js.map