import { BindingError } from "@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 BindingError(`RichTextField: the underlying field does not contain a string value.`);
  }
  const elements = fieldValue === null || fieldValue === "" ? [editor.createDefaultElement([{ text: "" }])] : editor.deserializeNodes(
    fieldValue,
    `RichTextField: the underlying field contains invalid JSON.`
  );
  contemberFieldElementCache.set(fieldAccessor, elements);
  return elements;
};
export {
  useRichTextFieldNodes
};
//# sourceMappingURL=useRichTextFieldNodes.js.map
