/**
 * Manager for storing and retrieving the extension context associated with each rich text editor host element.
 *
 * @todo Currently, there are three types of contexts in RTE: toolbar render context, extension context, and DTO render context. The second and third types are bound to the extension context via host props. We are considering optimizing these three types of contexts to make the program more flexible and easier to maintain.
 */
class RTEExtensionContextManager {
  constructor() {
    this.extensionContextMap = new WeakMap();
  }
  /**
   * Store the extension context for the given rich text editor host element.
   *
   * @param {RTEExtensionContext} context - The extension context to store.
   */
  setExtensionContext(context) {
    if (context && context.host) {
      this.extensionContextMap.set(context.host, context);
    }
  }
  /**
   * Get the extension context for the given rich text editor host element.
   *
   * @typedef HTMLVegaRichTextEditorElement - The type definition for the rich text editor host element.
   * @param {Nullable<HTMLVegaRichTextEditorElement>} el - The host rich text editor element.
   * @returns {Nullable<RTEExtensionContext>} - The extension context associated with the host.
   */
  getExtensionContext(el) {
    return el ? this.extensionContextMap.get(el) : null;
  }
}
export default new RTEExtensionContextManager();
