import { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js';
import ObjectID from 'bson-objectid';
export class ServerBlockNode extends DecoratorBlockNode {
  __fields;
  constructor({
    fields,
    format,
    key
  }) {
    super(format, key);
    this.__fields = fields;
  }
  static clone(node) {
    return new this({
      fields: node.__fields,
      format: node.__format,
      key: node.__key
    });
  }
  static getType() {
    return 'block';
  }
  static importDOM() {
    return {};
  }
  static importJSON(serializedNode) {
    if (serializedNode.version === 1) {
      // Convert (version 1 had the fields wrapped in another, unnecessary data property)
      serializedNode = {
        ...serializedNode,
        fields: {
          ...serializedNode.fields.data
        },
        version: 2
      };
    }
    const node = $createServerBlockNode(serializedNode.fields);
    node.setFormat(serializedNode.format);
    return node;
  }
  static isInline() {
    return false;
  }
  decorate(editor, config) {
    return null;
  }
  exportDOM() {
    const element = document.createElement('div');
    const text = document.createTextNode(this.getTextContent());
    element.append(text);
    return {
      element
    };
  }
  exportJSON() {
    return {
      ...super.exportJSON(),
      type: 'block',
      fields: this.getFields(),
      version: 2
    };
  }
  getFields() {
    return this.getLatest().__fields;
  }
  getTextContent() {
    return `Block Field`;
  }
  setFields(fields) {
    const writable = this.getWritable();
    writable.__fields = fields;
  }
}
export function $createServerBlockNode(fields) {
  return new ServerBlockNode({
    fields: {
      ...fields,
      id: fields?.id || new ObjectID.default().toHexString()
    }
  });
}
export function $isServerBlockNode(node) {
  return node instanceof ServerBlockNode;
}
//# sourceMappingURL=BlocksNode.js.map