@ones-editor/editor 5.0.8-beta.ONES22303263.1 → 5.0.8-beta.h1475.2

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.
package/dist/index.js CHANGED
@@ -26555,6 +26555,114 @@ var __publicField = (obj, key, value) => {
26555
26555
  };
26556
26556
  }
26557
26557
  }
26558
+ const controllers = /* @__PURE__ */ new WeakMap();
26559
+ const noop$1 = () => {
26560
+ };
26561
+ class FocusRestoration {
26562
+ constructor(input2, restore) {
26563
+ __publicField(this, "generation", 0);
26564
+ __publicField(this, "owner", null);
26565
+ __publicField(this, "destroyed", false);
26566
+ __publicField(this, "activeScope");
26567
+ __publicField(this, "timers", /* @__PURE__ */ new Set());
26568
+ this.input = input2;
26569
+ this.restore = restore;
26570
+ controllers.set(input2, this);
26571
+ }
26572
+ canFocus() {
26573
+ var _a;
26574
+ return !this.destroyed && !this.owner && !((_a = this.activeScope) == null ? void 0 : _a.cancelled) && this.input.isConnected;
26575
+ }
26576
+ hasOtherInput() {
26577
+ const active = this.input.ownerDocument.activeElement;
26578
+ return active !== this.input && !!(active == null ? void 0 : active.matches('input, textarea, select, [contenteditable="true"], [contenteditable=""]'));
26579
+ }
26580
+ schedule(callback, delay = 0, protectUserFocus = false) {
26581
+ var _a;
26582
+ return this.scheduleInScope(callback, delay, protectUserFocus, (_a = this.activeScope) != null ? _a : this.createScope());
26583
+ }
26584
+ createScope() {
26585
+ return { cancelled: false, timers: /* @__PURE__ */ new Set() };
26586
+ }
26587
+ scheduleInScope(callback, delay, protectUserFocus, scope) {
26588
+ if (scope.cancelled || !this.canFocus()) {
26589
+ return noop$1;
26590
+ }
26591
+ const generation = this.generation;
26592
+ const timer = setTimeout(() => {
26593
+ this.timers.delete(timer);
26594
+ scope.timers.delete(timer);
26595
+ if (!scope.cancelled && generation === this.generation && this.canFocus() && (!protectUserFocus || !this.hasOtherInput())) {
26596
+ const previousScope = this.activeScope;
26597
+ this.activeScope = scope;
26598
+ try {
26599
+ callback();
26600
+ } finally {
26601
+ this.activeScope = previousScope;
26602
+ }
26603
+ }
26604
+ }, delay);
26605
+ this.timers.add(timer);
26606
+ scope.timers.add(timer);
26607
+ return () => {
26608
+ scope.cancelled = true;
26609
+ scope.timers.forEach((pending) => {
26610
+ clearTimeout(pending);
26611
+ this.timers.delete(pending);
26612
+ });
26613
+ scope.timers.clear();
26614
+ };
26615
+ }
26616
+ request(delay = 0) {
26617
+ return this.scheduleInScope(this.restore, delay, !clientType.isMobile, this.createScope());
26618
+ }
26619
+ cancelPending() {
26620
+ if (this.activeScope) {
26621
+ this.activeScope.cancelled = true;
26622
+ }
26623
+ this.generation += 1;
26624
+ this.timers.forEach((timer) => clearTimeout(timer));
26625
+ this.timers.clear();
26626
+ }
26627
+ acquire() {
26628
+ this.cancelPending();
26629
+ const owner = {};
26630
+ this.owner = owner;
26631
+ return () => {
26632
+ if (this.owner === owner) {
26633
+ this.cancelPending();
26634
+ this.owner = null;
26635
+ }
26636
+ };
26637
+ }
26638
+ destroy() {
26639
+ this.destroyed = true;
26640
+ this.cancelPending();
26641
+ this.owner = null;
26642
+ controllers.delete(this.input);
26643
+ }
26644
+ }
26645
+ function requestInputFocus(input2, delay = 0) {
26646
+ var _a, _b;
26647
+ return (_b = (_a = controllers.get(input2)) == null ? void 0 : _a.request(delay)) != null ? _b : noop$1;
26648
+ }
26649
+ function requestEditorFocus(editor, delay = 0) {
26650
+ if (editor.destroyed) {
26651
+ return noop$1;
26652
+ }
26653
+ if (clientType.isMobile && delay === 0) {
26654
+ editor.focus();
26655
+ return noop$1;
26656
+ }
26657
+ return requestInputFocus(editor.input.inputElement, delay);
26658
+ }
26659
+ function acquireEditorFocus(editor) {
26660
+ var _a, _b;
26661
+ if (clientType.isMobile || editor.destroyed) {
26662
+ return noop$1;
26663
+ }
26664
+ return (_b = (_a = controllers.get(editor.input.inputElement)) == null ? void 0 : _a.acquire()) != null ? _b : noop$1;
26665
+ }
26558
26666
  const logger$3W = getLogger("editor-input");
26559
26667
  class EditorInput$1 {
26560
26668
  constructor(editor, callbacks) {
@@ -26564,6 +26672,7 @@ var __publicField = (obj, key, value) => {
26564
26672
  __publicField(this, "callbacks");
26565
26673
  __publicField(this, "inputElement");
26566
26674
  __publicField(this, "focused", false);
26675
+ __publicField(this, "focusRestoration");
26567
26676
  __publicField(this, "handleBlur", () => {
26568
26677
  this.editor.emit("blur", this.editor);
26569
26678
  this.callbacks.onBlur();
@@ -26585,12 +26694,20 @@ var __publicField = (obj, key, value) => {
26585
26694
  const isInDisableScrollMask = this.isInDisableScrollMask(target);
26586
26695
  if (target && (isInDisableScrollMask || rootElement === target || rootElement.contains(target))) {
26587
26696
  if (!isInDisableScrollMask && !isInBlockTools(target)) {
26588
- setTimeout(() => {
26697
+ const focus = () => {
26698
+ if (this.editor.destroyed || !this.focusRestoration.canFocus()) {
26699
+ return;
26700
+ }
26589
26701
  this.editor.emit("focus", this.editor);
26590
26702
  this.callbacks.onFocus();
26591
26703
  this.editor.input.focus({ preventScroll: true });
26592
26704
  this.focused = true;
26593
- });
26705
+ };
26706
+ if (clientType.isMobile) {
26707
+ setTimeout(focus);
26708
+ } else {
26709
+ this.focusRestoration.schedule(focus);
26710
+ }
26594
26711
  }
26595
26712
  return;
26596
26713
  }
@@ -26725,6 +26842,11 @@ var __publicField = (obj, key, value) => {
26725
26842
  input2.addEventListener("compositionstart", this.handleCompositionstart);
26726
26843
  input2.addEventListener("compositionend", this.handleCompositionend);
26727
26844
  this.inputElement = input2;
26845
+ this.focusRestoration = new FocusRestoration(input2, () => {
26846
+ if (!this.editor.destroyed) {
26847
+ this.editor.focus(clientType.isMobile ? void 0 : { preventScroll: true });
26848
+ }
26849
+ });
26728
26850
  if (clientType.isMobile) {
26729
26851
  document.addEventListener("touchend", this.handleDocumentClick);
26730
26852
  } else {
@@ -26747,6 +26869,7 @@ var __publicField = (obj, key, value) => {
26747
26869
  return !!(elem == null ? void 0 : elem.closest("div[data-command-bar-id]")) || !!(elem == null ? void 0 : elem.closest("[data-keep-editor-focus]")) || !!(elem == null ? void 0 : elem.closest(".data-keep-editor-focus"));
26748
26870
  }
26749
26871
  destroy() {
26872
+ this.focusRestoration.destroy();
26750
26873
  this.callbacks.destroy();
26751
26874
  if (clientType.isMobile) {
26752
26875
  document.removeEventListener("touchend", this.handleDocumentClick);
@@ -26771,24 +26894,36 @@ var __publicField = (obj, key, value) => {
26771
26894
  return this.inputElement;
26772
26895
  }
26773
26896
  focus(options) {
26897
+ if (this.editor.destroyed || !this.focusRestoration.canFocus()) {
26898
+ return;
26899
+ }
26774
26900
  if (!this.editor.selection.caret.visible()) {
26775
26901
  this.editor.selection.caret.update();
26776
26902
  }
26777
26903
  if (clientType.isMobile) {
26778
26904
  this.inputElement.focus(options);
26779
26905
  this.callbacks.onFocus();
26906
+ this.focused = true;
26780
26907
  } else {
26781
- setTimeout(() => {
26908
+ this.focusRestoration.schedule(() => {
26909
+ if (this.editor.destroyed) {
26910
+ return;
26911
+ }
26782
26912
  if (document.activeElement !== this.inputElement) {
26783
- setTimeout(() => {
26784
- this.editor.emit("focus", this.editor);
26913
+ this.focusRestoration.schedule(() => {
26914
+ if (!this.editor.destroyed && document.activeElement === this.inputElement) {
26915
+ this.editor.emit("focus", this.editor);
26916
+ }
26785
26917
  });
26786
26918
  }
26787
26919
  this.inputElement.focus(options);
26920
+ if (this.editor.destroyed || !this.focusRestoration.canFocus()) {
26921
+ return;
26922
+ }
26788
26923
  this.callbacks.onFocus();
26789
- });
26924
+ this.focused = true;
26925
+ }, 0, (options == null ? void 0 : options.preventScroll) === true);
26790
26926
  }
26791
- this.focused = true;
26792
26927
  }
26793
26928
  isInDisableScrollMask(target) {
26794
26929
  let elem = target;
@@ -32464,7 +32599,7 @@ ${codeText}
32464
32599
  editor.doc.endBatchUpdate();
32465
32600
  }
32466
32601
  if (!clientType.isMobile) {
32467
- editor.focus();
32602
+ requestEditorFocus(editor);
32468
32603
  }
32469
32604
  return rangeResult;
32470
32605
  });
@@ -42798,6 +42933,7 @@ ${codeText}
42798
42933
  });
42799
42934
  __publicField(this, "tippyInstance", null);
42800
42935
  __publicField(this, "_target", null);
42936
+ __publicField(this, "cancelFocus");
42801
42937
  __publicField(this, "focusTimer", null);
42802
42938
  __publicField(this, "handleBeforeClose", (event) => {
42803
42939
  var _a;
@@ -42849,7 +42985,7 @@ ${codeText}
42849
42985
  return;
42850
42986
  }
42851
42987
  if (!activeElement || activeElement === document.body || this.isInCommandBar(activeElement)) {
42852
- input2.focus();
42988
+ this.cancelFocus = requestInputFocus(input2);
42853
42989
  }
42854
42990
  }, 100);
42855
42991
  }
@@ -42859,6 +42995,9 @@ ${codeText}
42859
42995
  return target instanceof Node && (!!(parentEditor == null ? void 0 : parentEditor.contains(target)) || this.isInCommandBar(target));
42860
42996
  }
42861
42997
  clearFocusTimer() {
42998
+ var _a;
42999
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
43000
+ this.cancelFocus = void 0;
42862
43001
  if (this.focusTimer !== null) {
42863
43002
  clearTimeout(this.focusTimer);
42864
43003
  this.focusTimer = null;
@@ -42930,11 +43069,12 @@ ${codeText}
42930
43069
  }
42931
43070
  }
42932
43071
  destroy() {
42933
- var _a;
43072
+ var _a, _b;
42934
43073
  this.clearFocusTimer();
42935
43074
  (_a = this.tippyInstance) == null ? void 0 : _a.destroy();
42936
43075
  this.tippyInstance = null;
42937
43076
  super.destroy();
43077
+ (_b = this.cancelFocus) == null ? void 0 : _b.call(this);
42938
43078
  }
42939
43079
  getCommandBarRoot() {
42940
43080
  return this.content.closest("[data-tippy-root]");
@@ -45060,19 +45200,22 @@ ${codeText}
45060
45200
  class EditorAutoSuggestMenu extends AutoSuggestMenu {
45061
45201
  constructor(editor, editorOptions) {
45062
45202
  super(editorOptions);
45203
+ __publicField(this, "cancelFocus");
45063
45204
  __publicField(this, "handleClose", () => {
45064
- var _a, _b;
45205
+ var _a, _b, _c;
45206
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
45065
45207
  if (shouldFocusToEditor(this.editor)) {
45066
- this.editor.focus();
45208
+ this.cancelFocus = requestEditorFocus(this.editor);
45067
45209
  }
45068
- (_b = (_a = this.options).onClose) == null ? void 0 : _b.call(_a);
45210
+ (_c = (_b = this.options).onClose) == null ? void 0 : _c.call(_b);
45069
45211
  });
45070
45212
  this.editor = editor;
45071
45213
  this.editorOptions = editorOptions;
45072
45214
  }
45073
45215
  async popupInEditor(containerId, blockIndex, offset) {
45074
- var _a, _b;
45075
- if (((_b = (_a = this.editorOptions).onShow) == null ? void 0 : _b.call(_a, this, containerId, blockIndex, offset)) === false) {
45216
+ var _a, _b, _c;
45217
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
45218
+ if (((_c = (_b = this.editorOptions).onShow) == null ? void 0 : _c.call(_b, this, containerId, blockIndex, offset)) === false) {
45076
45219
  return;
45077
45220
  }
45078
45221
  if (this.options.showLoading) {
@@ -45090,6 +45233,11 @@ ${codeText}
45090
45233
  const anchor2 = createBlockAnchor(this.editor, block, "editor-auto-suggest-menu", rect);
45091
45234
  super.popup(anchor2, { noEvent: true });
45092
45235
  }
45236
+ destroy() {
45237
+ var _a;
45238
+ super.destroy();
45239
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
45240
+ }
45093
45241
  }
45094
45242
  const logger$2H = getLogger("auto-suggest-menu");
45095
45243
  class OnesEditorAutoSuggest {
@@ -54431,6 +54579,7 @@ ${codeText}
54431
54579
  });
54432
54580
  __publicField(this, "close", () => {
54433
54581
  this.linkPopup.close("cancelBar");
54582
+ this.emit("close");
54434
54583
  });
54435
54584
  __publicField(this, "createItems", (content) => [{
54436
54585
  id: "link-popup",
@@ -54452,7 +54601,6 @@ ${codeText}
54452
54601
  this.emit("finished");
54453
54602
  });
54454
54603
  __publicField(this, "handleClose", () => {
54455
- this.emit("close");
54456
54604
  this.close();
54457
54605
  });
54458
54606
  __publicField(this, "handleShown", () => {
@@ -54481,8 +54629,13 @@ ${codeText}
54481
54629
  this.linkPopup = new MobileBottomMenu(this.createItems(content), void 0, {
54482
54630
  id: "link-popup",
54483
54631
  header: this.createHeader(),
54484
- disableSelectedScroll: true
54632
+ disableSelectedScroll: true,
54633
+ beforeClose: () => {
54634
+ this.handleClose();
54635
+ return true;
54636
+ }
54485
54637
  });
54638
+ this.linkPopup.addListener("close", () => this.emit("close"));
54486
54639
  }
54487
54640
  destroy() {
54488
54641
  var _a, _b;
@@ -54501,11 +54654,11 @@ ${codeText}
54501
54654
  this.emit("finished");
54502
54655
  });
54503
54656
  __publicField(this, "handleClose", () => {
54504
- this.emit("close");
54505
54657
  this.close();
54506
54658
  });
54507
54659
  __publicField(this, "close", () => {
54508
54660
  this.linkPopup.close("cancelBar");
54661
+ this.emit("close");
54509
54662
  });
54510
54663
  __publicField(this, "disabledSubmit", () => {
54511
54664
  var _a;
@@ -54525,8 +54678,13 @@ ${codeText}
54525
54678
  this.content = content;
54526
54679
  this.options = options;
54527
54680
  this.linkPopup = new Popup(this.createPopupContent(), {
54528
- id: "link-popup"
54681
+ id: "link-popup",
54682
+ beforeClose: () => {
54683
+ this.handleClose();
54684
+ return true;
54685
+ }
54529
54686
  });
54687
+ this.linkPopup.addListener("close", () => this.emit("close"));
54530
54688
  }
54531
54689
  createPopupContent() {
54532
54690
  const container = createElement("div", ["link-popup-content"], null);
@@ -54559,46 +54717,85 @@ ${codeText}
54559
54717
  __publicField(this, "onFinished", null);
54560
54718
  __publicField(this, "onClose", null);
54561
54719
  __publicField(this, "onBeforeFormatUrl", null);
54720
+ __publicField(this, "session", 0);
54721
+ __publicField(this, "submitting", false);
54722
+ __publicField(this, "focusTimer");
54723
+ __publicField(this, "releaseFocus");
54562
54724
  __publicField(this, "handleOk", async () => {
54563
- var _a;
54725
+ if (!this.linkPopup || this.submitting || this.editor.destroyed) {
54726
+ return;
54727
+ }
54728
+ const session = this.session;
54729
+ const form = this.form;
54730
+ const onFinished = this.onFinished;
54731
+ const beforeFormatUrl = this.onBeforeFormatUrl;
54732
+ this.submitting = true;
54564
54733
  try {
54565
- await this.checkValue();
54566
- const { linkText, linkUrl } = this.form;
54734
+ await this.checkValue(form);
54735
+ if (!this.isCurrent(session)) {
54736
+ return;
54737
+ }
54738
+ const { linkText, linkUrl } = form;
54567
54739
  const inputValue = linkUrl.getInputValue();
54568
- let link2 = "";
54569
- if (this.onBeforeFormatUrl && this.onBeforeFormatUrl(inputValue) !== false) {
54570
- link2 = this.onBeforeFormatUrl(inputValue);
54571
- } else {
54572
- link2 = this.formatUrl(inputValue);
54740
+ const formatted = beforeFormatUrl == null ? void 0 : beforeFormatUrl(inputValue);
54741
+ const link2 = typeof formatted === "string" ? formatted : this.formatUrl(inputValue);
54742
+ const text2 = linkText.getInputValue() || link2;
54743
+ if (!this.isCurrent(session)) {
54744
+ return;
54573
54745
  }
54574
- (_a = this.onFinished) == null ? void 0 : _a.call(this, linkText.getInputValue() || link2, link2);
54575
54746
  this._destroy();
54747
+ onFinished == null ? void 0 : onFinished(text2, link2);
54576
54748
  } catch (error2) {
54749
+ if (this.isCurrent(session)) {
54750
+ this.submitting = false;
54751
+ }
54577
54752
  }
54578
54753
  });
54579
54754
  __publicField(this, "handleClose", () => {
54580
- var _a;
54581
- (_a = this.onClose) == null ? void 0 : _a.call(this);
54755
+ if (!this.linkPopup) {
54756
+ return;
54757
+ }
54758
+ const onClose = this.onClose;
54582
54759
  this._destroy();
54760
+ if (!this.editor.destroyed) {
54761
+ onClose == null ? void 0 : onClose();
54762
+ }
54583
54763
  });
54584
54764
  __publicField(this, "onShow", () => {
54585
- setTimeout(() => {
54586
- var _a;
54587
- (_a = this.form.linkUrl) == null ? void 0 : _a.getField().focus();
54765
+ var _a;
54766
+ const session = this.session;
54767
+ const field = (_a = this.form.linkUrl) == null ? void 0 : _a.getField();
54768
+ clearTimeout(this.focusTimer);
54769
+ this.focusTimer = setTimeout(() => {
54770
+ if (this.isCurrent(session) && (field == null ? void 0 : field.isConnected)) {
54771
+ field.focus(clientType.isMobile ? void 0 : { preventScroll: true });
54772
+ }
54588
54773
  }, 400);
54589
54774
  });
54590
54775
  __publicField(this, "showPopup", (options) => {
54591
- var _a, _b, _c, _d, _e;
54776
+ const session = this.session;
54592
54777
  if (clientType.isMobile) {
54593
54778
  this.linkPopup = new MobileLinkPopup(this.editor, this.createPopupContent(options.linkText, options.linkUrl), options);
54594
54779
  } else {
54595
54780
  this.linkPopup = new LinkPopup(this.createPopupContent(options.linkText, options.linkUrl), options);
54596
54781
  }
54597
- (_a = this.linkPopup) == null ? void 0 : _a.addListener("show", this.onShow);
54598
- (_b = this.linkPopup) == null ? void 0 : _b.manualShow();
54599
- (_c = this.linkPopup) == null ? void 0 : _c.disabledSubmit();
54600
- (_d = this.linkPopup) == null ? void 0 : _d.addListener("finished", this.handleOk);
54601
- (_e = this.linkPopup) == null ? void 0 : _e.addListener("close", this.handleClose);
54782
+ this.linkPopup.addListener("show", () => {
54783
+ if (this.isCurrent(session)) {
54784
+ this.onShow();
54785
+ }
54786
+ });
54787
+ this.linkPopup.addListener("finished", () => {
54788
+ if (this.isCurrent(session)) {
54789
+ this.handleOk();
54790
+ }
54791
+ });
54792
+ this.linkPopup.addListener("close", () => {
54793
+ if (this.isCurrent(session)) {
54794
+ this.handleClose();
54795
+ }
54796
+ });
54797
+ this.linkPopup.disabledSubmit();
54798
+ this.linkPopup.manualShow();
54602
54799
  });
54603
54800
  __publicField(this, "onChange", () => {
54604
54801
  var _a;
@@ -54610,11 +54807,14 @@ ${codeText}
54610
54807
  return;
54611
54808
  }
54612
54809
  if (event.key === "Enter") {
54613
- (_a = this.form.linkUrl) == null ? void 0 : _a.getField().focus();
54810
+ (_a = this.form.linkUrl) == null ? void 0 : _a.getField().focus(clientType.isMobile ? void 0 : { preventScroll: true });
54811
+ event.preventDefault();
54614
54812
  event.stopPropagation();
54615
54813
  return;
54616
54814
  }
54617
54815
  if (event.key === "Escape") {
54816
+ event.preventDefault();
54817
+ event.stopPropagation();
54618
54818
  this.handleClose();
54619
54819
  }
54620
54820
  });
@@ -54628,13 +54828,18 @@ ${codeText}
54628
54828
  return;
54629
54829
  }
54630
54830
  if (event.key === "Escape") {
54831
+ event.preventDefault();
54832
+ event.stopPropagation();
54631
54833
  this.handleClose();
54632
54834
  }
54633
54835
  });
54634
54836
  this.editor = editor;
54635
54837
  }
54636
- async checkValue() {
54637
- const { linkUrl } = this.form;
54838
+ isCurrent(session) {
54839
+ return session === this.session && !!this.linkPopup && !this.editor.destroyed;
54840
+ }
54841
+ async checkValue(form) {
54842
+ const { linkUrl } = form;
54638
54843
  if (!linkUrl.getInputValue()) {
54639
54844
  linkUrl.setFieldError(i18n$1.t("link.urlPlaceholder"));
54640
54845
  throw new Error(i18n$1.t("link.urlPlaceholder"));
@@ -54652,14 +54857,20 @@ ${codeText}
54652
54857
  return link2;
54653
54858
  }
54654
54859
  editLink(options) {
54655
- this.showPopup(options);
54860
+ this._destroy();
54861
+ if (this.editor.destroyed) {
54862
+ return;
54863
+ }
54864
+ this.releaseFocus = acquireEditorFocus(this.editor);
54656
54865
  const { onFinished, onClose, onBeforeFormatUrl } = options;
54657
54866
  this.onFinished = onFinished;
54658
- if (onClose) {
54659
- this.onClose = onClose;
54660
- }
54661
- if (onBeforeFormatUrl) {
54662
- this.onBeforeFormatUrl = onBeforeFormatUrl;
54867
+ this.onClose = onClose != null ? onClose : null;
54868
+ this.onBeforeFormatUrl = onBeforeFormatUrl != null ? onBeforeFormatUrl : null;
54869
+ try {
54870
+ this.showPopup(options);
54871
+ } catch (error2) {
54872
+ this._destroy();
54873
+ throw error2;
54663
54874
  }
54664
54875
  }
54665
54876
  createPopupContent(linkText, linkUrl) {
@@ -54688,12 +54899,21 @@ ${codeText}
54688
54899
  return content;
54689
54900
  }
54690
54901
  _destroy() {
54691
- var _a, _b;
54902
+ this.session += 1;
54903
+ clearTimeout(this.focusTimer);
54904
+ this.focusTimer = void 0;
54905
+ const popup = this.linkPopup;
54906
+ const releaseFocus = this.releaseFocus;
54907
+ this.linkPopup = null;
54908
+ this.releaseFocus = void 0;
54909
+ this.submitting = false;
54692
54910
  this.onFinished = null;
54693
54911
  this.onClose = null;
54912
+ this.onBeforeFormatUrl = null;
54694
54913
  this.form = {};
54695
- (_a = this.linkPopup) == null ? void 0 : _a.removeAllListeners();
54696
- (_b = this.linkPopup) == null ? void 0 : _b.destroy();
54914
+ popup == null ? void 0 : popup.removeAllListeners();
54915
+ popup == null ? void 0 : popup.destroy();
54916
+ releaseFocus == null ? void 0 : releaseFocus();
54697
54917
  }
54698
54918
  destroy() {
54699
54919
  this._destroy();
@@ -54733,14 +54953,14 @@ ${codeText}
54733
54953
  const text2 = [op1, op2];
54734
54954
  editor.insertTextToBlock(block, 0, text2);
54735
54955
  editor.selection.selectBlock(block, getTextLength(text2));
54736
- editor.focus();
54956
+ requestEditorFocus(editor);
54737
54957
  } catch (error2) {
54738
54958
  logger$21.error(error2);
54739
54959
  }
54740
54960
  });
54741
54961
  };
54742
54962
  const onClose = () => {
54743
- editor.focus();
54963
+ requestEditorFocus(editor);
54744
54964
  };
54745
54965
  editLink(editor, {
54746
54966
  target: block,
@@ -54772,21 +54992,21 @@ ${codeText}
54772
54992
  if (isCollapsed) {
54773
54993
  newText = insertText(editor.getBlockText(block), end, linkText, { link: linkUrl });
54774
54994
  editor.setBlockText(block, newText);
54775
- editor.focus();
54995
+ requestEditorFocus(editor);
54776
54996
  return;
54777
54997
  }
54778
54998
  newText = replaceText(editor.getBlockText(block), start, end, linkText);
54779
54999
  newText = rangeAddAttribute(start, linkText.length, newText, "link", linkUrl);
54780
55000
  editor.setBlockText(block, newText);
54781
55001
  editor.selection.selectBlock(block, start + linkText.length);
54782
- editor.focus();
55002
+ requestEditorFocus(editor);
54783
55003
  } catch (error2) {
54784
55004
  logger$21.error(error2);
54785
55005
  }
54786
55006
  });
54787
55007
  };
54788
55008
  const onClose = () => {
54789
- editor.focus();
55009
+ requestEditorFocus(editor);
54790
55010
  };
54791
55011
  editLink(editor, {
54792
55012
  target: anchor2,
@@ -55035,14 +55255,14 @@ ${codeText}
55035
55255
  const newText = insertText(deleted, range.start, linkText, { link: linkUrl });
55036
55256
  editor.setBlockText(block, newText);
55037
55257
  editor.selection.selectBlock(block, range.start + linkText.length);
55038
- editor.focus();
55258
+ requestEditorFocus(editor);
55039
55259
  } catch (error2) {
55040
55260
  logger$20.error(error2);
55041
55261
  }
55042
55262
  };
55043
55263
  const onClose = () => {
55044
55264
  editor.selection.selectBlock(block, range.end);
55045
- editor.focus();
55265
+ requestEditorFocus(editor);
55046
55266
  };
55047
55267
  const rect = getBlockClientRects(editor, block, editor.selection.range)[0];
55048
55268
  if (!rect) {
@@ -55544,6 +55764,7 @@ ${codeText}
55544
55764
  __publicField(this, "_disableTextToolbar", false);
55545
55765
  __publicField(this, "_lastClickTime", 0);
55546
55766
  __publicField(this, "_disabled", false);
55767
+ __publicField(this, "cancelFocus");
55547
55768
  __publicField(this, "isInToolbar", (event) => this.toolbar.isInCommandBar(event.target));
55548
55769
  __publicField(this, "handleButtonClick", (toolbar2, item) => {
55549
55770
  const tooltip = this.editor.findCustom("editor-tooltip");
@@ -55568,16 +55789,15 @@ ${codeText}
55568
55789
  this._lastClickTime = Date.now();
55569
55790
  });
55570
55791
  __publicField(this, "handleClose", () => {
55571
- var _a;
55792
+ var _a, _b;
55572
55793
  if (shouldFocusToEditor(this.editor) && !clientType.isMobile) {
55573
55794
  const activeElement = (_a = document.getSelection()) == null ? void 0 : _a.focusNode;
55574
55795
  if (activeElement && isInBlockTools(activeElement)) {
55575
55796
  logger$1_.debug("focus is in block tools, ignore focus");
55576
55797
  return;
55577
55798
  }
55578
- this.editor.focus({
55579
- preventScroll: true
55580
- });
55799
+ (_b = this.cancelFocus) == null ? void 0 : _b.call(this);
55800
+ this.cancelFocus = requestEditorFocus(this.editor);
55581
55801
  }
55582
55802
  });
55583
55803
  __publicField(this, "handleClosing", (bar2, event) => {
@@ -55706,8 +55926,10 @@ ${codeText}
55706
55926
  this.toolbar.close("selectionChange");
55707
55927
  }
55708
55928
  destroy() {
55929
+ var _a;
55709
55930
  this.unbindEvents();
55710
55931
  this.toolbar.destroy();
55932
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
55711
55933
  this.editor.removeListener("selectionChanged", this.handleSelectionChange);
55712
55934
  OnesEditorHoveringBlock.get(this.editor).removeListener("childChange", this.handleHoveringBlockChildChange);
55713
55935
  }
@@ -97316,14 +97538,13 @@ ${JSON.stringify(error2, null, 2)}`);
97316
97538
  __publicField(this, "toolbar");
97317
97539
  __publicField(this, "toolbarFullScreen");
97318
97540
  __publicField(this, "root");
97541
+ __publicField(this, "cancelFocus");
97319
97542
  __publicField(this, "handleClick", (bar2, item) => {
97320
97543
  const command = item;
97321
97544
  if (command.onClick) {
97322
97545
  command.onClick(this.editor, command, bar2);
97323
97546
  this.handleSelectionChanged();
97324
- setTimeout(() => {
97325
- this.editor.focus();
97326
- });
97547
+ this.restoreFocus();
97327
97548
  return;
97328
97549
  }
97329
97550
  const findParent = (item2, id) => {
@@ -97369,9 +97590,7 @@ ${JSON.stringify(error2, null, 2)}`);
97369
97590
  id: "main-toolbar"
97370
97591
  });
97371
97592
  this.toolbar.addListener("closing", () => {
97372
- setTimeout(() => {
97373
- editor.focus();
97374
- }, 100);
97593
+ this.restoreFocus(100);
97375
97594
  return true;
97376
97595
  });
97377
97596
  this.toolbar.addListener("click", this.handleClick);
@@ -97402,11 +97621,18 @@ ${JSON.stringify(error2, null, 2)}`);
97402
97621
  });
97403
97622
  }
97404
97623
  }
97405
- destroy() {
97624
+ restoreFocus(delay = 0) {
97406
97625
  var _a;
97626
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
97627
+ this.cancelFocus = requestEditorFocus(this.editor, delay);
97628
+ }
97629
+ destroy() {
97630
+ var _a, _b, _c;
97631
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
97407
97632
  this.toolbar.destroy();
97408
97633
  this.editor.removeListener("selectionChanged", this.handleSelectionChanged);
97409
- (_a = this.toolbarFullScreen) == null ? void 0 : _a.destroy();
97634
+ (_b = this.toolbarFullScreen) == null ? void 0 : _b.destroy();
97635
+ (_c = this.cancelFocus) == null ? void 0 : _c.call(this);
97410
97636
  this.root.remove();
97411
97637
  }
97412
97638
  setItems(items) {
@@ -98129,7 +98355,7 @@ ${JSON.stringify(error2, null, 2)}`);
98129
98355
  }
98130
98356
  }
98131
98357
  });
98132
- editor.version = "5.0.8-beta.ONES22303263.1";
98358
+ editor.version = "5.0.8-beta.h1475.2";
98133
98359
  return editor;
98134
98360
  }
98135
98361
  function isDoc(doc2) {
@@ -98265,7 +98491,7 @@ ${JSON.stringify(error2, null, 2)}`);
98265
98491
  OnesEditorDropTarget.register(editor);
98266
98492
  OnesEditorTocProvider.register(editor);
98267
98493
  OnesEditorExclusiveBlock.register(editor);
98268
- editor.version = "5.0.8-beta.ONES22303263.1";
98494
+ editor.version = "5.0.8-beta.h1475.2";
98269
98495
  return editor;
98270
98496
  } catch (error2) {
98271
98497
  try {
@@ -98408,7 +98634,7 @@ ${JSON.stringify(error2, null, 2)}`);
98408
98634
  }
98409
98635
  }
98410
98636
  });
98411
- editor.version = "5.0.8-beta.ONES22303263.1";
98637
+ editor.version = "5.0.8-beta.h1475.2";
98412
98638
  return editor;
98413
98639
  }
98414
98640
  const emojis$1 = {
@@ -144234,6 +144460,7 @@ ${JSON.stringify(error2, null, 2)}`);
144234
144460
  exports2.FindReplaceItem = FindReplaceItem;
144235
144461
  exports2.FitIcon = FitIcon;
144236
144462
  exports2.FixedToolbar = FixedToolbar;
144463
+ exports2.FocusRestoration = FocusRestoration;
144237
144464
  exports2.FontBoldItem = FontBoldItem;
144238
144465
  exports2.FontItalicItem = FontItalicItem;
144239
144466
  exports2.FontStrikethroughItem = FontStrikethroughItem;
@@ -144433,6 +144660,7 @@ ${JSON.stringify(error2, null, 2)}`);
144433
144660
  exports2.YoukuIcon = YoukuIcon;
144434
144661
  exports2.ZERO_WIDTH_SPACE_CHAR = ZERO_WIDTH_SPACE_CHAR;
144435
144662
  exports2.abbreviation = abbreviation;
144663
+ exports2.acquireEditorFocus = acquireEditorFocus;
144436
144664
  exports2.activeComment = activeComment;
144437
144665
  exports2.addAttribute = addAttribute;
144438
144666
  exports2.addClass = addClass;
@@ -144925,6 +145153,8 @@ ${JSON.stringify(error2, null, 2)}`);
144925
145153
  exports2.replaceText = replaceText;
144926
145154
  exports2.replaceWikiMacroResources = replaceWikiMacroResources;
144927
145155
  exports2.requestDownload = requestDownload;
145156
+ exports2.requestEditorFocus = requestEditorFocus;
145157
+ exports2.requestInputFocus = requestInputFocus;
144928
145158
  exports2.resetListStart = resetListStart;
144929
145159
  exports2.saveAs = saveAs$1;
144930
145160
  exports2.scrollBarIntoView = scrollBarIntoView;