"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const reactBinding = require("@contember/react-binding");
const useRichTextFieldNodes = ({
  editor,
  fieldAccessor,
  contemberFieldElementCache
}) => {
  if (contemberFieldElementCache.has(fieldAccessor)) {
    return contemberFieldElementCache.get(fieldAccessor);
  }
  const fieldValue = fieldAccessor.value;
  if (typeof fieldValue !== "string" && fieldValue !== null) {
    throw new reactBinding.BindingError(`RichTextField: the underlying field does not contain a string value.`);
  }
  const elements = fieldValue === null || fieldValue === "" ? [editor.createDefaultElement([{ text: "" }])] : [
    editor.createDefaultElement(
      editor.deserializeNodes(
        fieldValue,
        `RichTextField: the underlying field contains invalid JSON.`
      )
    )
  ];
  contemberFieldElementCache.set(fieldAccessor, elements);
  return elements;
};
exports.useRichTextFieldNodes = useRichTextFieldNodes;
//# sourceMappingURL=useRichTextFieldNodes.cjs.map
