@ones-editor/editor 3.1.6 → 3.1.7-beta.ONES22302172.5

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
@@ -26414,6 +26414,114 @@ var __publicField = (obj, key, value) => {
26414
26414
  };
26415
26415
  }
26416
26416
  }
26417
+ const controllers = /* @__PURE__ */ new WeakMap();
26418
+ const noop$1 = () => {
26419
+ };
26420
+ class FocusRestoration {
26421
+ constructor(input2, restore) {
26422
+ __publicField(this, "generation", 0);
26423
+ __publicField(this, "owner", null);
26424
+ __publicField(this, "destroyed", false);
26425
+ __publicField(this, "activeScope");
26426
+ __publicField(this, "timers", /* @__PURE__ */ new Set());
26427
+ this.input = input2;
26428
+ this.restore = restore;
26429
+ controllers.set(input2, this);
26430
+ }
26431
+ canFocus() {
26432
+ var _a;
26433
+ return !this.destroyed && !this.owner && !((_a = this.activeScope) == null ? void 0 : _a.cancelled) && this.input.isConnected;
26434
+ }
26435
+ hasOtherInput() {
26436
+ const active = this.input.ownerDocument.activeElement;
26437
+ return active !== this.input && !!(active == null ? void 0 : active.matches('input, textarea, select, [contenteditable="true"], [contenteditable=""]'));
26438
+ }
26439
+ schedule(callback, delay = 0, protectUserFocus = false) {
26440
+ var _a;
26441
+ return this.scheduleInScope(callback, delay, protectUserFocus, (_a = this.activeScope) != null ? _a : this.createScope());
26442
+ }
26443
+ createScope() {
26444
+ return { cancelled: false, timers: /* @__PURE__ */ new Set() };
26445
+ }
26446
+ scheduleInScope(callback, delay, protectUserFocus, scope) {
26447
+ if (scope.cancelled || !this.canFocus()) {
26448
+ return noop$1;
26449
+ }
26450
+ const generation = this.generation;
26451
+ const timer = setTimeout(() => {
26452
+ this.timers.delete(timer);
26453
+ scope.timers.delete(timer);
26454
+ if (!scope.cancelled && generation === this.generation && this.canFocus() && (!protectUserFocus || !this.hasOtherInput())) {
26455
+ const previousScope = this.activeScope;
26456
+ this.activeScope = scope;
26457
+ try {
26458
+ callback();
26459
+ } finally {
26460
+ this.activeScope = previousScope;
26461
+ }
26462
+ }
26463
+ }, delay);
26464
+ this.timers.add(timer);
26465
+ scope.timers.add(timer);
26466
+ return () => {
26467
+ scope.cancelled = true;
26468
+ scope.timers.forEach((pending) => {
26469
+ clearTimeout(pending);
26470
+ this.timers.delete(pending);
26471
+ });
26472
+ scope.timers.clear();
26473
+ };
26474
+ }
26475
+ request(delay = 0) {
26476
+ return this.scheduleInScope(this.restore, delay, !clientType.isMobile, this.createScope());
26477
+ }
26478
+ cancelPending() {
26479
+ if (this.activeScope) {
26480
+ this.activeScope.cancelled = true;
26481
+ }
26482
+ this.generation += 1;
26483
+ this.timers.forEach((timer) => clearTimeout(timer));
26484
+ this.timers.clear();
26485
+ }
26486
+ acquire() {
26487
+ this.cancelPending();
26488
+ const owner = {};
26489
+ this.owner = owner;
26490
+ return () => {
26491
+ if (this.owner === owner) {
26492
+ this.cancelPending();
26493
+ this.owner = null;
26494
+ }
26495
+ };
26496
+ }
26497
+ destroy() {
26498
+ this.destroyed = true;
26499
+ this.cancelPending();
26500
+ this.owner = null;
26501
+ controllers.delete(this.input);
26502
+ }
26503
+ }
26504
+ function requestInputFocus(input2, delay = 0) {
26505
+ var _a, _b;
26506
+ return (_b = (_a = controllers.get(input2)) == null ? void 0 : _a.request(delay)) != null ? _b : noop$1;
26507
+ }
26508
+ function requestEditorFocus(editor, delay = 0) {
26509
+ if (editor.destroyed) {
26510
+ return noop$1;
26511
+ }
26512
+ if (clientType.isMobile && delay === 0) {
26513
+ editor.focus();
26514
+ return noop$1;
26515
+ }
26516
+ return requestInputFocus(editor.input.inputElement, delay);
26517
+ }
26518
+ function acquireEditorFocus(editor) {
26519
+ var _a, _b;
26520
+ if (clientType.isMobile || editor.destroyed) {
26521
+ return noop$1;
26522
+ }
26523
+ return (_b = (_a = controllers.get(editor.input.inputElement)) == null ? void 0 : _a.acquire()) != null ? _b : noop$1;
26524
+ }
26417
26525
  const logger$3V = getLogger("editor-input");
26418
26526
  class EditorInput$1 {
26419
26527
  constructor(editor, callbacks) {
@@ -26423,6 +26531,7 @@ var __publicField = (obj, key, value) => {
26423
26531
  __publicField(this, "callbacks");
26424
26532
  __publicField(this, "inputElement");
26425
26533
  __publicField(this, "focused", false);
26534
+ __publicField(this, "focusRestoration");
26426
26535
  __publicField(this, "handleBlur", () => {
26427
26536
  this.editor.emit("blur", this.editor);
26428
26537
  this.callbacks.onBlur();
@@ -26444,12 +26553,20 @@ var __publicField = (obj, key, value) => {
26444
26553
  const isInDisableScrollMask = this.isInDisableScrollMask(target);
26445
26554
  if (target && (isInDisableScrollMask || rootElement === target || rootElement.contains(target))) {
26446
26555
  if (!isInDisableScrollMask && !isInBlockTools(target)) {
26447
- setTimeout(() => {
26556
+ const focus = () => {
26557
+ if (this.editor.destroyed || !this.focusRestoration.canFocus()) {
26558
+ return;
26559
+ }
26448
26560
  this.editor.emit("focus", this.editor);
26449
26561
  this.callbacks.onFocus();
26450
26562
  this.editor.input.focus();
26451
26563
  this.focused = true;
26452
- });
26564
+ };
26565
+ if (clientType.isMobile) {
26566
+ setTimeout(focus);
26567
+ } else {
26568
+ this.focusRestoration.schedule(focus);
26569
+ }
26453
26570
  }
26454
26571
  return;
26455
26572
  }
@@ -26584,6 +26701,11 @@ var __publicField = (obj, key, value) => {
26584
26701
  input2.addEventListener("compositionstart", this.handleCompositionstart);
26585
26702
  input2.addEventListener("compositionend", this.handleCompositionend);
26586
26703
  this.inputElement = input2;
26704
+ this.focusRestoration = new FocusRestoration(input2, () => {
26705
+ if (!this.editor.destroyed) {
26706
+ this.editor.focus(clientType.isMobile ? void 0 : { preventScroll: true });
26707
+ }
26708
+ });
26587
26709
  if (clientType.isMobile) {
26588
26710
  document.addEventListener("touchend", this.handleDocumentClick);
26589
26711
  } else {
@@ -26606,6 +26728,7 @@ var __publicField = (obj, key, value) => {
26606
26728
  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"));
26607
26729
  }
26608
26730
  destroy() {
26731
+ this.focusRestoration.destroy();
26609
26732
  this.callbacks.destroy();
26610
26733
  if (clientType.isMobile) {
26611
26734
  document.removeEventListener("touchend", this.handleDocumentClick);
@@ -26630,24 +26753,36 @@ var __publicField = (obj, key, value) => {
26630
26753
  return this.inputElement;
26631
26754
  }
26632
26755
  focus(options) {
26756
+ if (this.editor.destroyed || !this.focusRestoration.canFocus()) {
26757
+ return;
26758
+ }
26633
26759
  if (!this.editor.selection.caret.visible()) {
26634
26760
  this.editor.selection.caret.update();
26635
26761
  }
26636
26762
  if (clientType.isMobile) {
26637
26763
  this.inputElement.focus(options);
26638
26764
  this.callbacks.onFocus();
26765
+ this.focused = true;
26639
26766
  } else {
26640
- setTimeout(() => {
26767
+ this.focusRestoration.schedule(() => {
26768
+ if (this.editor.destroyed) {
26769
+ return;
26770
+ }
26641
26771
  if (document.activeElement !== this.inputElement) {
26642
- setTimeout(() => {
26643
- this.editor.emit("focus", this.editor);
26772
+ this.focusRestoration.schedule(() => {
26773
+ if (!this.editor.destroyed && document.activeElement === this.inputElement) {
26774
+ this.editor.emit("focus", this.editor);
26775
+ }
26644
26776
  });
26645
26777
  }
26646
26778
  this.inputElement.focus(options);
26779
+ if (this.editor.destroyed || !this.focusRestoration.canFocus()) {
26780
+ return;
26781
+ }
26647
26782
  this.callbacks.onFocus();
26648
- });
26783
+ this.focused = true;
26784
+ }, 0, (options == null ? void 0 : options.preventScroll) === true);
26649
26785
  }
26650
- this.focused = true;
26651
26786
  }
26652
26787
  isInDisableScrollMask(target) {
26653
26788
  let elem = target;
@@ -32206,7 +32341,7 @@ ${codeText}
32206
32341
  editor.doc.endBatchUpdate();
32207
32342
  }
32208
32343
  if (!clientType.isMobile) {
32209
- editor.focus();
32344
+ requestEditorFocus(editor);
32210
32345
  }
32211
32346
  return rangeResult;
32212
32347
  });
@@ -42516,10 +42651,12 @@ ${codeText}
42516
42651
  });
42517
42652
  __publicField(this, "tippyInstance", null);
42518
42653
  __publicField(this, "_target", null);
42654
+ __publicField(this, "cancelFocus");
42519
42655
  __publicField(this, "handleBeforeClose", (event) => {
42520
- var _a;
42656
+ var _a, _b;
42657
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
42521
42658
  let ret = false;
42522
- if ((_a = this.manualCommandBarOptions) == null ? void 0 : _a.beforeClose) {
42659
+ if ((_b = this.manualCommandBarOptions) == null ? void 0 : _b.beforeClose) {
42523
42660
  ret = this.manualCommandBarOptions.beforeClose(event);
42524
42661
  }
42525
42662
  if (ret) {
@@ -42529,18 +42666,16 @@ ${codeText}
42529
42666
  return ret;
42530
42667
  }
42531
42668
  const target = this._target;
42532
- setTimeout(() => {
42533
- const parentEditor = target.closest(".editor-root");
42534
- if (parentEditor) {
42535
- const input2 = parentEditor.querySelector(".editor-input");
42536
- if (input2) {
42537
- if (parentEditor.contains(document.activeElement)) {
42538
- return;
42539
- }
42540
- input2.focus();
42541
- }
42669
+ const parentEditor = target.closest(".editor-root");
42670
+ const input2 = parentEditor == null ? void 0 : parentEditor.querySelector(".editor-input");
42671
+ if (input2 && !(parentEditor == null ? void 0 : parentEditor.contains(document.activeElement))) {
42672
+ if (clientType.isMobile) {
42673
+ const timer = setTimeout(() => input2.focus(), 100);
42674
+ this.cancelFocus = () => clearTimeout(timer);
42675
+ } else {
42676
+ this.cancelFocus = requestInputFocus(input2, 100);
42542
42677
  }
42543
- }, 100);
42678
+ }
42544
42679
  return ret;
42545
42680
  });
42546
42681
  __publicField(this, "setProps", (props) => {
@@ -42550,7 +42685,8 @@ ${codeText}
42550
42685
  this.manualCommandBarOptions = manualCommandBarOptions;
42551
42686
  }
42552
42687
  manualShow(target, options) {
42553
- var _a, _b, _c, _d;
42688
+ var _a, _b, _c, _d, _e;
42689
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
42554
42690
  this._target = target;
42555
42691
  if (this.isVisible) {
42556
42692
  return;
@@ -42565,16 +42701,16 @@ ${codeText}
42565
42701
  trigger: "manual",
42566
42702
  triggerTarget: null,
42567
42703
  hideOnClick: false,
42568
- placement: (_a = options == null ? void 0 : options.placement) != null ? _a : "bottom-start",
42569
- maxWidth: (_b = this.options.maxWidth) != null ? _b : 650,
42570
- arrow: (_c = options == null ? void 0 : options.arrow) != null ? _c : this.options.tippyArrow,
42704
+ placement: (_b = options == null ? void 0 : options.placement) != null ? _b : "bottom-start",
42705
+ maxWidth: (_c = this.options.maxWidth) != null ? _c : 650,
42706
+ arrow: (_d = options == null ? void 0 : options.arrow) != null ? _d : this.options.tippyArrow,
42571
42707
  appendTo: this.options.appendTo || target.closest(".command-bar-container") || document.body,
42572
42708
  onShow: this.handleShow,
42573
42709
  onHidden: this.handleHidden,
42574
42710
  onShown: this.handleShown,
42575
42711
  theme: options == null ? void 0 : options.theme,
42576
42712
  getReferenceClientRect: options == null ? void 0 : options.getReferenceClientRect,
42577
- offset: (_d = options == null ? void 0 : options.offset) != null ? _d : [0, 0],
42713
+ offset: (_e = options == null ? void 0 : options.offset) != null ? _e : [0, 0],
42578
42714
  popperOptions: this.createPopperOptions(),
42579
42715
  delay: 500
42580
42716
  });
@@ -42609,10 +42745,12 @@ ${codeText}
42609
42745
  }
42610
42746
  }
42611
42747
  destroy() {
42612
- var _a;
42613
- (_a = this.tippyInstance) == null ? void 0 : _a.destroy();
42748
+ var _a, _b, _c;
42749
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
42750
+ (_b = this.tippyInstance) == null ? void 0 : _b.destroy();
42614
42751
  this.tippyInstance = null;
42615
42752
  super.destroy();
42753
+ (_c = this.cancelFocus) == null ? void 0 : _c.call(this);
42616
42754
  }
42617
42755
  getCommandBarRoot() {
42618
42756
  return this.content.closest("[data-tippy-root]");
@@ -44732,19 +44870,22 @@ ${codeText}
44732
44870
  class EditorAutoSuggestMenu extends AutoSuggestMenu {
44733
44871
  constructor(editor, editorOptions) {
44734
44872
  super(editorOptions);
44873
+ __publicField(this, "cancelFocus");
44735
44874
  __publicField(this, "handleClose", () => {
44736
- var _a, _b;
44875
+ var _a, _b, _c;
44876
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
44737
44877
  if (shouldFocusToEditor(this.editor)) {
44738
- this.editor.focus();
44878
+ this.cancelFocus = requestEditorFocus(this.editor);
44739
44879
  }
44740
- (_b = (_a = this.options).onClose) == null ? void 0 : _b.call(_a);
44880
+ (_c = (_b = this.options).onClose) == null ? void 0 : _c.call(_b);
44741
44881
  });
44742
44882
  this.editor = editor;
44743
44883
  this.editorOptions = editorOptions;
44744
44884
  }
44745
44885
  async popupInEditor(containerId, blockIndex, offset) {
44746
- var _a, _b;
44747
- if (((_b = (_a = this.editorOptions).onShow) == null ? void 0 : _b.call(_a, this, containerId, blockIndex, offset)) === false) {
44886
+ var _a, _b, _c;
44887
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
44888
+ if (((_c = (_b = this.editorOptions).onShow) == null ? void 0 : _c.call(_b, this, containerId, blockIndex, offset)) === false) {
44748
44889
  return;
44749
44890
  }
44750
44891
  if (this.options.showLoading) {
@@ -44762,6 +44903,11 @@ ${codeText}
44762
44903
  const anchor2 = createBlockAnchor(this.editor, block, "editor-auto-suggest-menu", rect);
44763
44904
  super.popup(anchor2, { noEvent: true });
44764
44905
  }
44906
+ destroy() {
44907
+ var _a;
44908
+ super.destroy();
44909
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
44910
+ }
44765
44911
  }
44766
44912
  const logger$2G = getLogger("auto-suggest-menu");
44767
44913
  class OnesEditorAutoSuggest {
@@ -54088,6 +54234,7 @@ ${codeText}
54088
54234
  });
54089
54235
  __publicField(this, "close", () => {
54090
54236
  this.linkPopup.close("cancelBar");
54237
+ this.emit("close");
54091
54238
  });
54092
54239
  __publicField(this, "createItems", (content) => [{
54093
54240
  id: "link-popup",
@@ -54109,7 +54256,6 @@ ${codeText}
54109
54256
  this.emit("finished");
54110
54257
  });
54111
54258
  __publicField(this, "handleClose", () => {
54112
- this.emit("close");
54113
54259
  this.close();
54114
54260
  });
54115
54261
  __publicField(this, "handleShown", () => {
@@ -54138,8 +54284,13 @@ ${codeText}
54138
54284
  this.linkPopup = new MobileBottomMenu(this.createItems(content), void 0, {
54139
54285
  id: "link-popup",
54140
54286
  header: this.createHeader(),
54141
- disableSelectedScroll: true
54287
+ disableSelectedScroll: true,
54288
+ beforeClose: () => {
54289
+ this.handleClose();
54290
+ return true;
54291
+ }
54142
54292
  });
54293
+ this.linkPopup.addListener("close", () => this.emit("close"));
54143
54294
  }
54144
54295
  destroy() {
54145
54296
  var _a, _b;
@@ -54158,11 +54309,11 @@ ${codeText}
54158
54309
  this.emit("finished");
54159
54310
  });
54160
54311
  __publicField(this, "handleClose", () => {
54161
- this.emit("close");
54162
54312
  this.close();
54163
54313
  });
54164
54314
  __publicField(this, "close", () => {
54165
54315
  this.linkPopup.close("cancelBar");
54316
+ this.emit("close");
54166
54317
  });
54167
54318
  __publicField(this, "disabledSubmit", () => {
54168
54319
  var _a;
@@ -54182,8 +54333,13 @@ ${codeText}
54182
54333
  this.content = content;
54183
54334
  this.options = options;
54184
54335
  this.linkPopup = new Popup(this.createPopupContent(), {
54185
- id: "link-popup"
54336
+ id: "link-popup",
54337
+ beforeClose: () => {
54338
+ this.handleClose();
54339
+ return true;
54340
+ }
54186
54341
  });
54342
+ this.linkPopup.addListener("close", () => this.emit("close"));
54187
54343
  }
54188
54344
  createPopupContent() {
54189
54345
  const container = createElement("div", ["link-popup-content"], null);
@@ -54216,46 +54372,85 @@ ${codeText}
54216
54372
  __publicField(this, "onFinished", null);
54217
54373
  __publicField(this, "onClose", null);
54218
54374
  __publicField(this, "onBeforeFormatUrl", null);
54375
+ __publicField(this, "session", 0);
54376
+ __publicField(this, "submitting", false);
54377
+ __publicField(this, "focusTimer");
54378
+ __publicField(this, "releaseFocus");
54219
54379
  __publicField(this, "handleOk", async () => {
54220
- var _a;
54380
+ if (!this.linkPopup || this.submitting || this.editor.destroyed) {
54381
+ return;
54382
+ }
54383
+ const session = this.session;
54384
+ const form = this.form;
54385
+ const onFinished = this.onFinished;
54386
+ const beforeFormatUrl = this.onBeforeFormatUrl;
54387
+ this.submitting = true;
54221
54388
  try {
54222
- await this.checkValue();
54223
- const { linkText, linkUrl } = this.form;
54389
+ await this.checkValue(form);
54390
+ if (!this.isCurrent(session)) {
54391
+ return;
54392
+ }
54393
+ const { linkText, linkUrl } = form;
54224
54394
  const inputValue = linkUrl.getInputValue();
54225
- let link2 = "";
54226
- if (this.onBeforeFormatUrl && this.onBeforeFormatUrl(inputValue) !== false) {
54227
- link2 = this.onBeforeFormatUrl(inputValue);
54228
- } else {
54229
- link2 = this.formatUrl(inputValue);
54395
+ const formatted = beforeFormatUrl == null ? void 0 : beforeFormatUrl(inputValue);
54396
+ const link2 = typeof formatted === "string" ? formatted : this.formatUrl(inputValue);
54397
+ const text2 = linkText.getInputValue() || link2;
54398
+ if (!this.isCurrent(session)) {
54399
+ return;
54230
54400
  }
54231
- (_a = this.onFinished) == null ? void 0 : _a.call(this, linkText.getInputValue() || link2, link2);
54232
54401
  this._destroy();
54402
+ onFinished == null ? void 0 : onFinished(text2, link2);
54233
54403
  } catch (error2) {
54404
+ if (this.isCurrent(session)) {
54405
+ this.submitting = false;
54406
+ }
54234
54407
  }
54235
54408
  });
54236
54409
  __publicField(this, "handleClose", () => {
54237
- var _a;
54238
- (_a = this.onClose) == null ? void 0 : _a.call(this);
54410
+ if (!this.linkPopup) {
54411
+ return;
54412
+ }
54413
+ const onClose = this.onClose;
54239
54414
  this._destroy();
54415
+ if (!this.editor.destroyed) {
54416
+ onClose == null ? void 0 : onClose();
54417
+ }
54240
54418
  });
54241
54419
  __publicField(this, "onShow", () => {
54242
- setTimeout(() => {
54243
- var _a;
54244
- (_a = this.form.linkUrl) == null ? void 0 : _a.getField().focus();
54420
+ var _a;
54421
+ const session = this.session;
54422
+ const field = (_a = this.form.linkUrl) == null ? void 0 : _a.getField();
54423
+ clearTimeout(this.focusTimer);
54424
+ this.focusTimer = setTimeout(() => {
54425
+ if (this.isCurrent(session) && (field == null ? void 0 : field.isConnected)) {
54426
+ field.focus(clientType.isMobile ? void 0 : { preventScroll: true });
54427
+ }
54245
54428
  }, 400);
54246
54429
  });
54247
54430
  __publicField(this, "showPopup", (options) => {
54248
- var _a, _b, _c, _d, _e;
54431
+ const session = this.session;
54249
54432
  if (clientType.isMobile) {
54250
54433
  this.linkPopup = new MobileLinkPopup(this.editor, this.createPopupContent(options.linkText, options.linkUrl), options);
54251
54434
  } else {
54252
54435
  this.linkPopup = new LinkPopup(this.createPopupContent(options.linkText, options.linkUrl), options);
54253
54436
  }
54254
- (_a = this.linkPopup) == null ? void 0 : _a.addListener("show", this.onShow);
54255
- (_b = this.linkPopup) == null ? void 0 : _b.manualShow();
54256
- (_c = this.linkPopup) == null ? void 0 : _c.disabledSubmit();
54257
- (_d = this.linkPopup) == null ? void 0 : _d.addListener("finished", this.handleOk);
54258
- (_e = this.linkPopup) == null ? void 0 : _e.addListener("close", this.handleClose);
54437
+ this.linkPopup.addListener("show", () => {
54438
+ if (this.isCurrent(session)) {
54439
+ this.onShow();
54440
+ }
54441
+ });
54442
+ this.linkPopup.addListener("finished", () => {
54443
+ if (this.isCurrent(session)) {
54444
+ this.handleOk();
54445
+ }
54446
+ });
54447
+ this.linkPopup.addListener("close", () => {
54448
+ if (this.isCurrent(session)) {
54449
+ this.handleClose();
54450
+ }
54451
+ });
54452
+ this.linkPopup.disabledSubmit();
54453
+ this.linkPopup.manualShow();
54259
54454
  });
54260
54455
  __publicField(this, "onChange", () => {
54261
54456
  var _a;
@@ -54267,11 +54462,14 @@ ${codeText}
54267
54462
  return;
54268
54463
  }
54269
54464
  if (event.key === "Enter") {
54270
- (_a = this.form.linkUrl) == null ? void 0 : _a.getField().focus();
54465
+ (_a = this.form.linkUrl) == null ? void 0 : _a.getField().focus(clientType.isMobile ? void 0 : { preventScroll: true });
54466
+ event.preventDefault();
54271
54467
  event.stopPropagation();
54272
54468
  return;
54273
54469
  }
54274
54470
  if (event.key === "Escape") {
54471
+ event.preventDefault();
54472
+ event.stopPropagation();
54275
54473
  this.handleClose();
54276
54474
  }
54277
54475
  });
@@ -54285,13 +54483,18 @@ ${codeText}
54285
54483
  return;
54286
54484
  }
54287
54485
  if (event.key === "Escape") {
54486
+ event.preventDefault();
54487
+ event.stopPropagation();
54288
54488
  this.handleClose();
54289
54489
  }
54290
54490
  });
54291
54491
  this.editor = editor;
54292
54492
  }
54293
- async checkValue() {
54294
- const { linkUrl } = this.form;
54493
+ isCurrent(session) {
54494
+ return session === this.session && !!this.linkPopup && !this.editor.destroyed;
54495
+ }
54496
+ async checkValue(form) {
54497
+ const { linkUrl } = form;
54295
54498
  if (!linkUrl.getInputValue()) {
54296
54499
  linkUrl.setFieldError(i18n$1.t("link.urlPlaceholder"));
54297
54500
  throw new Error(i18n$1.t("link.urlPlaceholder"));
@@ -54309,14 +54512,20 @@ ${codeText}
54309
54512
  return link2;
54310
54513
  }
54311
54514
  editLink(options) {
54312
- this.showPopup(options);
54515
+ this._destroy();
54516
+ if (this.editor.destroyed) {
54517
+ return;
54518
+ }
54519
+ this.releaseFocus = acquireEditorFocus(this.editor);
54313
54520
  const { onFinished, onClose, onBeforeFormatUrl } = options;
54314
54521
  this.onFinished = onFinished;
54315
- if (onClose) {
54316
- this.onClose = onClose;
54317
- }
54318
- if (onBeforeFormatUrl) {
54319
- this.onBeforeFormatUrl = onBeforeFormatUrl;
54522
+ this.onClose = onClose != null ? onClose : null;
54523
+ this.onBeforeFormatUrl = onBeforeFormatUrl != null ? onBeforeFormatUrl : null;
54524
+ try {
54525
+ this.showPopup(options);
54526
+ } catch (error2) {
54527
+ this._destroy();
54528
+ throw error2;
54320
54529
  }
54321
54530
  }
54322
54531
  createPopupContent(linkText, linkUrl) {
@@ -54345,12 +54554,21 @@ ${codeText}
54345
54554
  return content;
54346
54555
  }
54347
54556
  _destroy() {
54348
- var _a, _b;
54557
+ this.session += 1;
54558
+ clearTimeout(this.focusTimer);
54559
+ this.focusTimer = void 0;
54560
+ const popup = this.linkPopup;
54561
+ const releaseFocus = this.releaseFocus;
54562
+ this.linkPopup = null;
54563
+ this.releaseFocus = void 0;
54564
+ this.submitting = false;
54349
54565
  this.onFinished = null;
54350
54566
  this.onClose = null;
54567
+ this.onBeforeFormatUrl = null;
54351
54568
  this.form = {};
54352
- (_a = this.linkPopup) == null ? void 0 : _a.removeAllListeners();
54353
- (_b = this.linkPopup) == null ? void 0 : _b.destroy();
54569
+ popup == null ? void 0 : popup.removeAllListeners();
54570
+ popup == null ? void 0 : popup.destroy();
54571
+ releaseFocus == null ? void 0 : releaseFocus();
54354
54572
  }
54355
54573
  destroy() {
54356
54574
  this._destroy();
@@ -54390,14 +54608,14 @@ ${codeText}
54390
54608
  const text2 = [op1, op2];
54391
54609
  editor.insertTextToBlock(block, 0, text2);
54392
54610
  editor.selection.selectBlock(block, getTextLength(text2));
54393
- editor.focus();
54611
+ requestEditorFocus(editor);
54394
54612
  } catch (error2) {
54395
54613
  logger$20.error(error2);
54396
54614
  }
54397
54615
  });
54398
54616
  };
54399
54617
  const onClose = () => {
54400
- editor.focus();
54618
+ requestEditorFocus(editor);
54401
54619
  };
54402
54620
  editLink(editor, {
54403
54621
  target: block,
@@ -54429,21 +54647,21 @@ ${codeText}
54429
54647
  if (isCollapsed) {
54430
54648
  newText = insertText(editor.getBlockText(block), end, linkText, { link: linkUrl });
54431
54649
  editor.setBlockText(block, newText);
54432
- editor.focus();
54650
+ requestEditorFocus(editor);
54433
54651
  return;
54434
54652
  }
54435
54653
  newText = replaceText(editor.getBlockText(block), start, end, linkText);
54436
54654
  newText = rangeAddAttribute(start, linkText.length, newText, "link", linkUrl);
54437
54655
  editor.setBlockText(block, newText);
54438
54656
  editor.selection.selectBlock(block, start + linkText.length);
54439
- editor.focus();
54657
+ requestEditorFocus(editor);
54440
54658
  } catch (error2) {
54441
54659
  logger$20.error(error2);
54442
54660
  }
54443
54661
  });
54444
54662
  };
54445
54663
  const onClose = () => {
54446
- editor.focus();
54664
+ requestEditorFocus(editor);
54447
54665
  };
54448
54666
  editLink(editor, {
54449
54667
  target: anchor2,
@@ -54692,14 +54910,14 @@ ${codeText}
54692
54910
  const newText = insertText(deleted, range.start, linkText, { link: linkUrl });
54693
54911
  editor.setBlockText(block, newText);
54694
54912
  editor.selection.selectBlock(block, range.start + linkText.length);
54695
- editor.focus();
54913
+ requestEditorFocus(editor);
54696
54914
  } catch (error2) {
54697
54915
  logger$1$.error(error2);
54698
54916
  }
54699
54917
  };
54700
54918
  const onClose = () => {
54701
54919
  editor.selection.selectBlock(block, range.end);
54702
- editor.focus();
54920
+ requestEditorFocus(editor);
54703
54921
  };
54704
54922
  const rect = getBlockClientRects(editor, block, editor.selection.range)[0];
54705
54923
  if (!rect) {
@@ -55201,6 +55419,7 @@ ${codeText}
55201
55419
  __publicField(this, "_disableTextToolbar", false);
55202
55420
  __publicField(this, "_lastClickTime", 0);
55203
55421
  __publicField(this, "_disabled", false);
55422
+ __publicField(this, "cancelFocus");
55204
55423
  __publicField(this, "isInToolbar", (event) => this.toolbar.isInCommandBar(event.target));
55205
55424
  __publicField(this, "handleButtonClick", (toolbar2, item) => {
55206
55425
  const tooltip = this.editor.findCustom("editor-tooltip");
@@ -55225,16 +55444,15 @@ ${codeText}
55225
55444
  this._lastClickTime = Date.now();
55226
55445
  });
55227
55446
  __publicField(this, "handleClose", () => {
55228
- var _a;
55447
+ var _a, _b;
55229
55448
  if (shouldFocusToEditor(this.editor) && !clientType.isMobile) {
55230
55449
  const activeElement = (_a = document.getSelection()) == null ? void 0 : _a.focusNode;
55231
55450
  if (activeElement && isInBlockTools(activeElement)) {
55232
55451
  logger$1Z.debug("focus is in block tools, ignore focus");
55233
55452
  return;
55234
55453
  }
55235
- this.editor.focus({
55236
- preventScroll: true
55237
- });
55454
+ (_b = this.cancelFocus) == null ? void 0 : _b.call(this);
55455
+ this.cancelFocus = requestEditorFocus(this.editor);
55238
55456
  }
55239
55457
  });
55240
55458
  __publicField(this, "handleClosing", (bar2, event) => {
@@ -55363,8 +55581,10 @@ ${codeText}
55363
55581
  this.toolbar.close("selectionChange");
55364
55582
  }
55365
55583
  destroy() {
55584
+ var _a;
55366
55585
  this.unbindEvents();
55367
55586
  this.toolbar.destroy();
55587
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
55368
55588
  this.editor.removeListener("selectionChanged", this.handleSelectionChange);
55369
55589
  OnesEditorHoveringBlock.get(this.editor).removeListener("childChange", this.handleHoveringBlockChildChange);
55370
55590
  }
@@ -96704,14 +96924,13 @@ ${JSON.stringify(error2, null, 2)}`);
96704
96924
  __publicField(this, "toolbar");
96705
96925
  __publicField(this, "toolbarFullScreen");
96706
96926
  __publicField(this, "root");
96927
+ __publicField(this, "cancelFocus");
96707
96928
  __publicField(this, "handleClick", (bar2, item) => {
96708
96929
  const command = item;
96709
96930
  if (command.onClick) {
96710
96931
  command.onClick(this.editor, command, bar2);
96711
96932
  this.handleSelectionChanged();
96712
- setTimeout(() => {
96713
- this.editor.focus();
96714
- });
96933
+ this.restoreFocus();
96715
96934
  return;
96716
96935
  }
96717
96936
  const findParent = (item2, id) => {
@@ -96757,9 +96976,7 @@ ${JSON.stringify(error2, null, 2)}`);
96757
96976
  id: "main-toolbar"
96758
96977
  });
96759
96978
  this.toolbar.addListener("closing", () => {
96760
- setTimeout(() => {
96761
- editor.focus();
96762
- }, 100);
96979
+ this.restoreFocus(100);
96763
96980
  return true;
96764
96981
  });
96765
96982
  this.toolbar.addListener("click", this.handleClick);
@@ -96790,11 +97007,18 @@ ${JSON.stringify(error2, null, 2)}`);
96790
97007
  });
96791
97008
  }
96792
97009
  }
96793
- destroy() {
97010
+ restoreFocus(delay = 0) {
96794
97011
  var _a;
97012
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
97013
+ this.cancelFocus = requestEditorFocus(this.editor, delay);
97014
+ }
97015
+ destroy() {
97016
+ var _a, _b, _c;
97017
+ (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
96795
97018
  this.toolbar.destroy();
96796
97019
  this.editor.removeListener("selectionChanged", this.handleSelectionChanged);
96797
- (_a = this.toolbarFullScreen) == null ? void 0 : _a.destroy();
97020
+ (_b = this.toolbarFullScreen) == null ? void 0 : _b.destroy();
97021
+ (_c = this.cancelFocus) == null ? void 0 : _c.call(this);
96798
97022
  this.root.remove();
96799
97023
  }
96800
97024
  setItems(items) {
@@ -97387,7 +97611,7 @@ ${JSON.stringify(error2, null, 2)}`);
97387
97611
  }
97388
97612
  }
97389
97613
  });
97390
- editor.version = "3.1.6";
97614
+ editor.version = "3.1.7-beta.ONES22302172.5";
97391
97615
  return editor;
97392
97616
  }
97393
97617
  function isDoc(doc2) {
@@ -97528,7 +97752,7 @@ ${JSON.stringify(error2, null, 2)}`);
97528
97752
  OnesEditorDropTarget.register(editor);
97529
97753
  OnesEditorTocProvider.register(editor);
97530
97754
  OnesEditorExclusiveBlock.register(editor);
97531
- editor.version = "3.1.6";
97755
+ editor.version = "3.1.7-beta.ONES22302172.5";
97532
97756
  return editor;
97533
97757
  } catch (error2) {
97534
97758
  if (editorForCleanup) {
@@ -143431,6 +143655,7 @@ ${JSON.stringify(error2, null, 2)}`);
143431
143655
  exports2.FindReplaceItem = FindReplaceItem;
143432
143656
  exports2.FitIcon = FitIcon;
143433
143657
  exports2.FixedToolbar = FixedToolbar;
143658
+ exports2.FocusRestoration = FocusRestoration;
143434
143659
  exports2.FontBoldItem = FontBoldItem;
143435
143660
  exports2.FontItalicItem = FontItalicItem;
143436
143661
  exports2.FontStrikethroughItem = FontStrikethroughItem;
@@ -143626,6 +143851,7 @@ ${JSON.stringify(error2, null, 2)}`);
143626
143851
  exports2.YoukuIcon = YoukuIcon;
143627
143852
  exports2.ZERO_WIDTH_SPACE_CHAR = ZERO_WIDTH_SPACE_CHAR;
143628
143853
  exports2.abbreviation = abbreviation;
143854
+ exports2.acquireEditorFocus = acquireEditorFocus;
143629
143855
  exports2.activeComment = activeComment;
143630
143856
  exports2.addAttribute = addAttribute;
143631
143857
  exports2.addClass = addClass;
@@ -144109,6 +144335,8 @@ ${JSON.stringify(error2, null, 2)}`);
144109
144335
  exports2.replaceAllText = replaceAllText;
144110
144336
  exports2.replaceText = replaceText;
144111
144337
  exports2.requestDownload = requestDownload;
144338
+ exports2.requestEditorFocus = requestEditorFocus;
144339
+ exports2.requestInputFocus = requestInputFocus;
144112
144340
  exports2.resetListStart = resetListStart;
144113
144341
  exports2.saveAs = saveAs$1;
144114
144342
  exports2.scrollBarIntoView = scrollBarIntoView;