@editora/core 1.0.27 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3185,7 +3185,7 @@ function bi() {
3185
3185
  }
3186
3186
  class W extends HTMLElement {
3187
3187
  constructor() {
3188
- if (super(), this.pluginLoader = bi(), this.config = {}, this.isInitialized = !1, this.keyboardShortcutManager = new vn(), this.lastAutosavedContent = "", this.preservedContent = null, this.loadedPlugins = [], this.lastBeforeInputType = null, this.pendingHistorySnapshot = null, gi(), !this.hasAttribute("data-initial-content")) {
3188
+ if (super(), this.pluginLoader = bi(), this.config = {}, this.isInitialized = !1, this.buildGeneration = 0, this.keyboardShortcutManager = new vn(), this.lastAutosavedContent = "", this.preservedContent = null, this.loadedPlugins = [], this.lastBeforeInputType = null, this.pendingHistorySnapshot = null, gi(), !this.hasAttribute("data-initial-content")) {
3189
3189
  const t = this.innerHTML.trim();
3190
3190
  t && this.setAttribute("data-initial-content", t);
3191
3191
  }
@@ -3285,31 +3285,33 @@ class W extends HTMLElement {
3285
3285
  * Initialize the editor
3286
3286
  */
3287
3287
  async initialize() {
3288
- var r;
3288
+ var a;
3289
3289
  if (this.querySelector(".editora-toolbar") || this.isInitialized) return;
3290
+ const t = ++this.buildGeneration;
3290
3291
  this.setAttribute("data-editora-editor", "true"), Ae.add(this), Q || (Q = this), mi(), this.config.height && (this.style.height = typeof this.config.height == "number" ? `${this.config.height}px` : this.config.height), this.config.width && (this.style.width = typeof this.config.width == "number" ? `${this.config.width}px` : this.config.width), this.classList.add("editora-editor"), this.config.theme && this.classList.add(`editora-theme-${this.config.theme}`);
3291
- const t = await this.loadPlugins();
3292
- if (this.loadedPlugins = t, t.forEach((a) => {
3293
- if (a.init && typeof a.init == "function")
3292
+ const e = await this.loadPlugins();
3293
+ if (t !== this.buildGeneration || !this.isConnected) return;
3294
+ if (this.loadedPlugins = e, e.forEach((l) => {
3295
+ if (l.init && typeof l.init == "function")
3294
3296
  try {
3295
- a.init({ editorElement: this });
3296
- } catch (l) {
3297
- console.error(`[RichTextEditor] Error initializing plugin ${a.name}:`, l);
3297
+ l.init({ editorElement: this });
3298
+ } catch (c) {
3299
+ console.error(`[RichTextEditor] Error initializing plugin ${l.name}:`, c);
3298
3300
  }
3299
3301
  }), !this.hasAttribute("data-initial-content") && !this.contentElement) {
3300
- const a = this.innerHTML.trim();
3301
- a && this.setAttribute("data-initial-content", a);
3302
+ const l = this.innerHTML.trim();
3303
+ l && this.setAttribute("data-initial-content", l);
3302
3304
  }
3303
- const e = this.preservedContent;
3305
+ const o = this.preservedContent;
3304
3306
  this.preservedContent = null;
3305
- const o = this.sanitizeLoadedContent(
3306
- (r = e != null ? e : this.restoreAutosavedContent()) != null ? r : this.getAttribute("data-initial-content") || ""
3307
+ const r = this.sanitizeLoadedContent(
3308
+ (a = o != null ? o : this.restoreAutosavedContent()) != null ? a : this.getAttribute("data-initial-content") || ""
3307
3309
  );
3308
3310
  this.engine = new un({
3309
- content: o,
3310
- plugins: t,
3311
+ content: r,
3312
+ plugins: e,
3311
3313
  readonly: this.config.readonly
3312
- }), this.createUI(t, o), this.setupEventListeners(), this.startAutosave(), this.isInitialized = !0, this.dispatchEvent(new CustomEvent("editor-ready", {
3314
+ }), this.createUI(e, r), this.setupEventListeners(), this.startAutosave(), this.isInitialized = !0, this.dispatchEvent(new CustomEvent("editor-ready", {
3313
3315
  detail: { api: this.getAPI() },
3314
3316
  bubbles: !0
3315
3317
  }));
@@ -3969,7 +3971,7 @@ class W extends HTMLElement {
3969
3971
  */
3970
3972
  destroy() {
3971
3973
  var t, e, o, r;
3972
- this.contentChangeDebounceTimer && (clearTimeout(this.contentChangeDebounceTimer), this.contentChangeDebounceTimer = void 0), this.contentElement && (this.preservedContent = xt(this.contentElement), this.persistAutosave(this.preservedContent)), this.stopAutosave(), this.selectionChangeHandler && (document.removeEventListener("selectionchange", this.selectionChangeHandler), this.selectionChangeHandler = void 0), (t = this.engine) == null || t.destroy(), (e = this.toolbar) == null || e.destroy(), (o = this.floatingToolbar) == null || o.destroy(), (r = this.statusBar) == null || r.destroy(), this.innerHTML = "", this.contentElement = void 0, this.toolbarElement = void 0, this.statusBarElement = void 0, this.loadedPlugins = [], this.isInitialized = !1, Ae.delete(this), Q === this && (Q = null), this.dispatchEvent(new Event("editor-destroy", { bubbles: !0 }));
3974
+ this.buildGeneration += 1, this.contentChangeDebounceTimer && (clearTimeout(this.contentChangeDebounceTimer), this.contentChangeDebounceTimer = void 0), this.contentElement && (this.preservedContent = xt(this.contentElement), this.persistAutosave(this.preservedContent)), this.stopAutosave(), this.selectionChangeHandler && (document.removeEventListener("selectionchange", this.selectionChangeHandler), this.selectionChangeHandler = void 0), (t = this.engine) == null || t.destroy(), (e = this.toolbar) == null || e.destroy(), (o = this.floatingToolbar) == null || o.destroy(), (r = this.statusBar) == null || r.destroy(), this.innerHTML = "", this.contentElement = void 0, this.toolbarElement = void 0, this.statusBarElement = void 0, this.loadedPlugins = [], this.isInitialized = !1, Ae.delete(this), Q === this && (Q = null), this.dispatchEvent(new Event("editor-destroy", { bubbles: !0 }));
3973
3975
  }
3974
3976
  // Public API methods
3975
3977
  getContent() {