@ones-editor/editor 3.1.7-beta.ONES22302172.5 → 3.1.7-beta.ONES22302592.1

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,114 +26414,6 @@ 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
- }
26525
26417
  const logger$3V = getLogger("editor-input");
26526
26418
  class EditorInput$1 {
26527
26419
  constructor(editor, callbacks) {
@@ -26531,7 +26423,6 @@ var __publicField = (obj, key, value) => {
26531
26423
  __publicField(this, "callbacks");
26532
26424
  __publicField(this, "inputElement");
26533
26425
  __publicField(this, "focused", false);
26534
- __publicField(this, "focusRestoration");
26535
26426
  __publicField(this, "handleBlur", () => {
26536
26427
  this.editor.emit("blur", this.editor);
26537
26428
  this.callbacks.onBlur();
@@ -26553,20 +26444,12 @@ var __publicField = (obj, key, value) => {
26553
26444
  const isInDisableScrollMask = this.isInDisableScrollMask(target);
26554
26445
  if (target && (isInDisableScrollMask || rootElement === target || rootElement.contains(target))) {
26555
26446
  if (!isInDisableScrollMask && !isInBlockTools(target)) {
26556
- const focus = () => {
26557
- if (this.editor.destroyed || !this.focusRestoration.canFocus()) {
26558
- return;
26559
- }
26447
+ setTimeout(() => {
26560
26448
  this.editor.emit("focus", this.editor);
26561
26449
  this.callbacks.onFocus();
26562
26450
  this.editor.input.focus();
26563
26451
  this.focused = true;
26564
- };
26565
- if (clientType.isMobile) {
26566
- setTimeout(focus);
26567
- } else {
26568
- this.focusRestoration.schedule(focus);
26569
- }
26452
+ });
26570
26453
  }
26571
26454
  return;
26572
26455
  }
@@ -26701,11 +26584,6 @@ var __publicField = (obj, key, value) => {
26701
26584
  input2.addEventListener("compositionstart", this.handleCompositionstart);
26702
26585
  input2.addEventListener("compositionend", this.handleCompositionend);
26703
26586
  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
- });
26709
26587
  if (clientType.isMobile) {
26710
26588
  document.addEventListener("touchend", this.handleDocumentClick);
26711
26589
  } else {
@@ -26728,7 +26606,6 @@ var __publicField = (obj, key, value) => {
26728
26606
  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"));
26729
26607
  }
26730
26608
  destroy() {
26731
- this.focusRestoration.destroy();
26732
26609
  this.callbacks.destroy();
26733
26610
  if (clientType.isMobile) {
26734
26611
  document.removeEventListener("touchend", this.handleDocumentClick);
@@ -26753,36 +26630,24 @@ var __publicField = (obj, key, value) => {
26753
26630
  return this.inputElement;
26754
26631
  }
26755
26632
  focus(options) {
26756
- if (this.editor.destroyed || !this.focusRestoration.canFocus()) {
26757
- return;
26758
- }
26759
26633
  if (!this.editor.selection.caret.visible()) {
26760
26634
  this.editor.selection.caret.update();
26761
26635
  }
26762
26636
  if (clientType.isMobile) {
26763
26637
  this.inputElement.focus(options);
26764
26638
  this.callbacks.onFocus();
26765
- this.focused = true;
26766
26639
  } else {
26767
- this.focusRestoration.schedule(() => {
26768
- if (this.editor.destroyed) {
26769
- return;
26770
- }
26640
+ setTimeout(() => {
26771
26641
  if (document.activeElement !== this.inputElement) {
26772
- this.focusRestoration.schedule(() => {
26773
- if (!this.editor.destroyed && document.activeElement === this.inputElement) {
26774
- this.editor.emit("focus", this.editor);
26775
- }
26642
+ setTimeout(() => {
26643
+ this.editor.emit("focus", this.editor);
26776
26644
  });
26777
26645
  }
26778
26646
  this.inputElement.focus(options);
26779
- if (this.editor.destroyed || !this.focusRestoration.canFocus()) {
26780
- return;
26781
- }
26782
26647
  this.callbacks.onFocus();
26783
- this.focused = true;
26784
- }, 0, (options == null ? void 0 : options.preventScroll) === true);
26648
+ });
26785
26649
  }
26650
+ this.focused = true;
26786
26651
  }
26787
26652
  isInDisableScrollMask(target) {
26788
26653
  let elem = target;
@@ -32341,7 +32206,7 @@ ${codeText}
32341
32206
  editor.doc.endBatchUpdate();
32342
32207
  }
32343
32208
  if (!clientType.isMobile) {
32344
- requestEditorFocus(editor);
32209
+ editor.focus();
32345
32210
  }
32346
32211
  return rangeResult;
32347
32212
  });
@@ -42651,12 +42516,13 @@ ${codeText}
42651
42516
  });
42652
42517
  __publicField(this, "tippyInstance", null);
42653
42518
  __publicField(this, "_target", null);
42654
- __publicField(this, "cancelFocus");
42519
+ __publicField(this, "focusRestoreTimer", null);
42520
+ __publicField(this, "focusRestoreGeneration", 0);
42655
42521
  __publicField(this, "handleBeforeClose", (event) => {
42656
- var _a, _b;
42657
- (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
42522
+ var _a;
42523
+ this.cancelFocusRestore();
42658
42524
  let ret = false;
42659
- if ((_b = this.manualCommandBarOptions) == null ? void 0 : _b.beforeClose) {
42525
+ if ((_a = this.manualCommandBarOptions) == null ? void 0 : _a.beforeClose) {
42660
42526
  ret = this.manualCommandBarOptions.beforeClose(event);
42661
42527
  }
42662
42528
  if (ret) {
@@ -42668,16 +42534,51 @@ ${codeText}
42668
42534
  const target = this._target;
42669
42535
  const parentEditor = target.closest(".editor-root");
42670
42536
  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);
42677
- }
42537
+ if (!parentEditor || !input2) {
42538
+ return ret;
42539
+ }
42540
+ if (event && !parentEditor.contains(event.target) && !this.isInCommandBar(event.target)) {
42541
+ return ret;
42678
42542
  }
42543
+ const generation = this.focusRestoreGeneration;
42544
+ document.addEventListener("mousedown", this.cancelFocusRestore, true);
42545
+ document.addEventListener("focusin", this.handleFocusRestoreFocus, true);
42546
+ window.addEventListener("blur", this.cancelFocusRestore);
42547
+ this.focusRestoreTimer = setTimeout(() => {
42548
+ if (generation !== this.focusRestoreGeneration) {
42549
+ return;
42550
+ }
42551
+ this.cancelFocusRestore();
42552
+ if (this._target !== target || !target.isConnected || !input2.isConnected || !document.hasFocus()) {
42553
+ return;
42554
+ }
42555
+ const activeElement = document.activeElement;
42556
+ if (parentEditor.contains(activeElement)) {
42557
+ return;
42558
+ }
42559
+ if (activeElement && activeElement !== document.body && activeElement !== document.documentElement && !this.isInCommandBar(activeElement)) {
42560
+ return;
42561
+ }
42562
+ input2.focus({ preventScroll: true });
42563
+ }, 100);
42679
42564
  return ret;
42680
42565
  });
42566
+ __publicField(this, "cancelFocusRestore", () => {
42567
+ this.focusRestoreGeneration += 1;
42568
+ if (this.focusRestoreTimer !== null) {
42569
+ clearTimeout(this.focusRestoreTimer);
42570
+ this.focusRestoreTimer = null;
42571
+ }
42572
+ document.removeEventListener("mousedown", this.cancelFocusRestore, true);
42573
+ document.removeEventListener("focusin", this.handleFocusRestoreFocus, true);
42574
+ window.removeEventListener("blur", this.cancelFocusRestore);
42575
+ });
42576
+ __publicField(this, "handleFocusRestoreFocus", (event) => {
42577
+ var _a, _b;
42578
+ if (!((_b = (_a = this._target) == null ? void 0 : _a.closest(".editor-root")) == null ? void 0 : _b.contains(event.target)) && !this.isInCommandBar(event.target)) {
42579
+ this.cancelFocusRestore();
42580
+ }
42581
+ });
42681
42582
  __publicField(this, "setProps", (props) => {
42682
42583
  var _a;
42683
42584
  (_a = this.tippyInstance) == null ? void 0 : _a.setProps(props);
@@ -42685,8 +42586,8 @@ ${codeText}
42685
42586
  this.manualCommandBarOptions = manualCommandBarOptions;
42686
42587
  }
42687
42588
  manualShow(target, options) {
42688
- var _a, _b, _c, _d, _e;
42689
- (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
42589
+ var _a, _b, _c, _d;
42590
+ this.cancelFocusRestore();
42690
42591
  this._target = target;
42691
42592
  if (this.isVisible) {
42692
42593
  return;
@@ -42701,16 +42602,16 @@ ${codeText}
42701
42602
  trigger: "manual",
42702
42603
  triggerTarget: null,
42703
42604
  hideOnClick: false,
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,
42605
+ placement: (_a = options == null ? void 0 : options.placement) != null ? _a : "bottom-start",
42606
+ maxWidth: (_b = this.options.maxWidth) != null ? _b : 650,
42607
+ arrow: (_c = options == null ? void 0 : options.arrow) != null ? _c : this.options.tippyArrow,
42707
42608
  appendTo: this.options.appendTo || target.closest(".command-bar-container") || document.body,
42708
42609
  onShow: this.handleShow,
42709
42610
  onHidden: this.handleHidden,
42710
42611
  onShown: this.handleShown,
42711
42612
  theme: options == null ? void 0 : options.theme,
42712
42613
  getReferenceClientRect: options == null ? void 0 : options.getReferenceClientRect,
42713
- offset: (_e = options == null ? void 0 : options.offset) != null ? _e : [0, 0],
42614
+ offset: (_d = options == null ? void 0 : options.offset) != null ? _d : [0, 0],
42714
42615
  popperOptions: this.createPopperOptions(),
42715
42616
  delay: 500
42716
42617
  });
@@ -42735,6 +42636,9 @@ ${codeText}
42735
42636
  }
42736
42637
  close(reason, e2) {
42737
42638
  var _a, _b;
42639
+ if (reason === "clickBackground") {
42640
+ this.cancelFocusRestore();
42641
+ }
42738
42642
  super.close(reason);
42739
42643
  if (this.isVisible) {
42740
42644
  if (e2) {
@@ -42745,12 +42649,11 @@ ${codeText}
42745
42649
  }
42746
42650
  }
42747
42651
  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();
42652
+ var _a;
42653
+ this.cancelFocusRestore();
42654
+ (_a = this.tippyInstance) == null ? void 0 : _a.destroy();
42751
42655
  this.tippyInstance = null;
42752
42656
  super.destroy();
42753
- (_c = this.cancelFocus) == null ? void 0 : _c.call(this);
42754
42657
  }
42755
42658
  getCommandBarRoot() {
42756
42659
  return this.content.closest("[data-tippy-root]");
@@ -44870,22 +44773,19 @@ ${codeText}
44870
44773
  class EditorAutoSuggestMenu extends AutoSuggestMenu {
44871
44774
  constructor(editor, editorOptions) {
44872
44775
  super(editorOptions);
44873
- __publicField(this, "cancelFocus");
44874
44776
  __publicField(this, "handleClose", () => {
44875
- var _a, _b, _c;
44876
- (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
44777
+ var _a, _b;
44877
44778
  if (shouldFocusToEditor(this.editor)) {
44878
- this.cancelFocus = requestEditorFocus(this.editor);
44779
+ this.editor.focus();
44879
44780
  }
44880
- (_c = (_b = this.options).onClose) == null ? void 0 : _c.call(_b);
44781
+ (_b = (_a = this.options).onClose) == null ? void 0 : _b.call(_a);
44881
44782
  });
44882
44783
  this.editor = editor;
44883
44784
  this.editorOptions = editorOptions;
44884
44785
  }
44885
44786
  async popupInEditor(containerId, blockIndex, offset) {
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) {
44787
+ var _a, _b;
44788
+ if (((_b = (_a = this.editorOptions).onShow) == null ? void 0 : _b.call(_a, this, containerId, blockIndex, offset)) === false) {
44889
44789
  return;
44890
44790
  }
44891
44791
  if (this.options.showLoading) {
@@ -44903,11 +44803,6 @@ ${codeText}
44903
44803
  const anchor2 = createBlockAnchor(this.editor, block, "editor-auto-suggest-menu", rect);
44904
44804
  super.popup(anchor2, { noEvent: true });
44905
44805
  }
44906
- destroy() {
44907
- var _a;
44908
- super.destroy();
44909
- (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
44910
- }
44911
44806
  }
44912
44807
  const logger$2G = getLogger("auto-suggest-menu");
44913
44808
  class OnesEditorAutoSuggest {
@@ -54234,7 +54129,6 @@ ${codeText}
54234
54129
  });
54235
54130
  __publicField(this, "close", () => {
54236
54131
  this.linkPopup.close("cancelBar");
54237
- this.emit("close");
54238
54132
  });
54239
54133
  __publicField(this, "createItems", (content) => [{
54240
54134
  id: "link-popup",
@@ -54256,6 +54150,7 @@ ${codeText}
54256
54150
  this.emit("finished");
54257
54151
  });
54258
54152
  __publicField(this, "handleClose", () => {
54153
+ this.emit("close");
54259
54154
  this.close();
54260
54155
  });
54261
54156
  __publicField(this, "handleShown", () => {
@@ -54284,13 +54179,8 @@ ${codeText}
54284
54179
  this.linkPopup = new MobileBottomMenu(this.createItems(content), void 0, {
54285
54180
  id: "link-popup",
54286
54181
  header: this.createHeader(),
54287
- disableSelectedScroll: true,
54288
- beforeClose: () => {
54289
- this.handleClose();
54290
- return true;
54291
- }
54182
+ disableSelectedScroll: true
54292
54183
  });
54293
- this.linkPopup.addListener("close", () => this.emit("close"));
54294
54184
  }
54295
54185
  destroy() {
54296
54186
  var _a, _b;
@@ -54309,11 +54199,11 @@ ${codeText}
54309
54199
  this.emit("finished");
54310
54200
  });
54311
54201
  __publicField(this, "handleClose", () => {
54202
+ this.emit("close");
54312
54203
  this.close();
54313
54204
  });
54314
54205
  __publicField(this, "close", () => {
54315
54206
  this.linkPopup.close("cancelBar");
54316
- this.emit("close");
54317
54207
  });
54318
54208
  __publicField(this, "disabledSubmit", () => {
54319
54209
  var _a;
@@ -54333,13 +54223,8 @@ ${codeText}
54333
54223
  this.content = content;
54334
54224
  this.options = options;
54335
54225
  this.linkPopup = new Popup(this.createPopupContent(), {
54336
- id: "link-popup",
54337
- beforeClose: () => {
54338
- this.handleClose();
54339
- return true;
54340
- }
54226
+ id: "link-popup"
54341
54227
  });
54342
- this.linkPopup.addListener("close", () => this.emit("close"));
54343
54228
  }
54344
54229
  createPopupContent() {
54345
54230
  const container = createElement("div", ["link-popup-content"], null);
@@ -54372,85 +54257,46 @@ ${codeText}
54372
54257
  __publicField(this, "onFinished", null);
54373
54258
  __publicField(this, "onClose", null);
54374
54259
  __publicField(this, "onBeforeFormatUrl", null);
54375
- __publicField(this, "session", 0);
54376
- __publicField(this, "submitting", false);
54377
- __publicField(this, "focusTimer");
54378
- __publicField(this, "releaseFocus");
54379
54260
  __publicField(this, "handleOk", async () => {
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;
54261
+ var _a;
54388
54262
  try {
54389
- await this.checkValue(form);
54390
- if (!this.isCurrent(session)) {
54391
- return;
54392
- }
54393
- const { linkText, linkUrl } = form;
54263
+ await this.checkValue();
54264
+ const { linkText, linkUrl } = this.form;
54394
54265
  const inputValue = linkUrl.getInputValue();
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;
54266
+ let link2 = "";
54267
+ if (this.onBeforeFormatUrl && this.onBeforeFormatUrl(inputValue) !== false) {
54268
+ link2 = this.onBeforeFormatUrl(inputValue);
54269
+ } else {
54270
+ link2 = this.formatUrl(inputValue);
54400
54271
  }
54272
+ (_a = this.onFinished) == null ? void 0 : _a.call(this, linkText.getInputValue() || link2, link2);
54401
54273
  this._destroy();
54402
- onFinished == null ? void 0 : onFinished(text2, link2);
54403
54274
  } catch (error2) {
54404
- if (this.isCurrent(session)) {
54405
- this.submitting = false;
54406
- }
54407
54275
  }
54408
54276
  });
54409
54277
  __publicField(this, "handleClose", () => {
54410
- if (!this.linkPopup) {
54411
- return;
54412
- }
54413
- const onClose = this.onClose;
54278
+ var _a;
54279
+ (_a = this.onClose) == null ? void 0 : _a.call(this);
54414
54280
  this._destroy();
54415
- if (!this.editor.destroyed) {
54416
- onClose == null ? void 0 : onClose();
54417
- }
54418
54281
  });
54419
54282
  __publicField(this, "onShow", () => {
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
- }
54283
+ setTimeout(() => {
54284
+ var _a;
54285
+ (_a = this.form.linkUrl) == null ? void 0 : _a.getField().focus();
54428
54286
  }, 400);
54429
54287
  });
54430
54288
  __publicField(this, "showPopup", (options) => {
54431
- const session = this.session;
54289
+ var _a, _b, _c, _d, _e;
54432
54290
  if (clientType.isMobile) {
54433
54291
  this.linkPopup = new MobileLinkPopup(this.editor, this.createPopupContent(options.linkText, options.linkUrl), options);
54434
54292
  } else {
54435
54293
  this.linkPopup = new LinkPopup(this.createPopupContent(options.linkText, options.linkUrl), options);
54436
54294
  }
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();
54295
+ (_a = this.linkPopup) == null ? void 0 : _a.addListener("show", this.onShow);
54296
+ (_b = this.linkPopup) == null ? void 0 : _b.manualShow();
54297
+ (_c = this.linkPopup) == null ? void 0 : _c.disabledSubmit();
54298
+ (_d = this.linkPopup) == null ? void 0 : _d.addListener("finished", this.handleOk);
54299
+ (_e = this.linkPopup) == null ? void 0 : _e.addListener("close", this.handleClose);
54454
54300
  });
54455
54301
  __publicField(this, "onChange", () => {
54456
54302
  var _a;
@@ -54462,14 +54308,11 @@ ${codeText}
54462
54308
  return;
54463
54309
  }
54464
54310
  if (event.key === "Enter") {
54465
- (_a = this.form.linkUrl) == null ? void 0 : _a.getField().focus(clientType.isMobile ? void 0 : { preventScroll: true });
54466
- event.preventDefault();
54311
+ (_a = this.form.linkUrl) == null ? void 0 : _a.getField().focus();
54467
54312
  event.stopPropagation();
54468
54313
  return;
54469
54314
  }
54470
54315
  if (event.key === "Escape") {
54471
- event.preventDefault();
54472
- event.stopPropagation();
54473
54316
  this.handleClose();
54474
54317
  }
54475
54318
  });
@@ -54483,18 +54326,13 @@ ${codeText}
54483
54326
  return;
54484
54327
  }
54485
54328
  if (event.key === "Escape") {
54486
- event.preventDefault();
54487
- event.stopPropagation();
54488
54329
  this.handleClose();
54489
54330
  }
54490
54331
  });
54491
54332
  this.editor = editor;
54492
54333
  }
54493
- isCurrent(session) {
54494
- return session === this.session && !!this.linkPopup && !this.editor.destroyed;
54495
- }
54496
- async checkValue(form) {
54497
- const { linkUrl } = form;
54334
+ async checkValue() {
54335
+ const { linkUrl } = this.form;
54498
54336
  if (!linkUrl.getInputValue()) {
54499
54337
  linkUrl.setFieldError(i18n$1.t("link.urlPlaceholder"));
54500
54338
  throw new Error(i18n$1.t("link.urlPlaceholder"));
@@ -54512,20 +54350,14 @@ ${codeText}
54512
54350
  return link2;
54513
54351
  }
54514
54352
  editLink(options) {
54515
- this._destroy();
54516
- if (this.editor.destroyed) {
54517
- return;
54518
- }
54519
- this.releaseFocus = acquireEditorFocus(this.editor);
54353
+ this.showPopup(options);
54520
54354
  const { onFinished, onClose, onBeforeFormatUrl } = options;
54521
54355
  this.onFinished = onFinished;
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;
54356
+ if (onClose) {
54357
+ this.onClose = onClose;
54358
+ }
54359
+ if (onBeforeFormatUrl) {
54360
+ this.onBeforeFormatUrl = onBeforeFormatUrl;
54529
54361
  }
54530
54362
  }
54531
54363
  createPopupContent(linkText, linkUrl) {
@@ -54554,21 +54386,12 @@ ${codeText}
54554
54386
  return content;
54555
54387
  }
54556
54388
  _destroy() {
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;
54389
+ var _a, _b;
54565
54390
  this.onFinished = null;
54566
54391
  this.onClose = null;
54567
- this.onBeforeFormatUrl = null;
54568
54392
  this.form = {};
54569
- popup == null ? void 0 : popup.removeAllListeners();
54570
- popup == null ? void 0 : popup.destroy();
54571
- releaseFocus == null ? void 0 : releaseFocus();
54393
+ (_a = this.linkPopup) == null ? void 0 : _a.removeAllListeners();
54394
+ (_b = this.linkPopup) == null ? void 0 : _b.destroy();
54572
54395
  }
54573
54396
  destroy() {
54574
54397
  this._destroy();
@@ -54608,14 +54431,14 @@ ${codeText}
54608
54431
  const text2 = [op1, op2];
54609
54432
  editor.insertTextToBlock(block, 0, text2);
54610
54433
  editor.selection.selectBlock(block, getTextLength(text2));
54611
- requestEditorFocus(editor);
54434
+ editor.focus();
54612
54435
  } catch (error2) {
54613
54436
  logger$20.error(error2);
54614
54437
  }
54615
54438
  });
54616
54439
  };
54617
54440
  const onClose = () => {
54618
- requestEditorFocus(editor);
54441
+ editor.focus();
54619
54442
  };
54620
54443
  editLink(editor, {
54621
54444
  target: block,
@@ -54647,21 +54470,21 @@ ${codeText}
54647
54470
  if (isCollapsed) {
54648
54471
  newText = insertText(editor.getBlockText(block), end, linkText, { link: linkUrl });
54649
54472
  editor.setBlockText(block, newText);
54650
- requestEditorFocus(editor);
54473
+ editor.focus();
54651
54474
  return;
54652
54475
  }
54653
54476
  newText = replaceText(editor.getBlockText(block), start, end, linkText);
54654
54477
  newText = rangeAddAttribute(start, linkText.length, newText, "link", linkUrl);
54655
54478
  editor.setBlockText(block, newText);
54656
54479
  editor.selection.selectBlock(block, start + linkText.length);
54657
- requestEditorFocus(editor);
54480
+ editor.focus();
54658
54481
  } catch (error2) {
54659
54482
  logger$20.error(error2);
54660
54483
  }
54661
54484
  });
54662
54485
  };
54663
54486
  const onClose = () => {
54664
- requestEditorFocus(editor);
54487
+ editor.focus();
54665
54488
  };
54666
54489
  editLink(editor, {
54667
54490
  target: anchor2,
@@ -54910,14 +54733,14 @@ ${codeText}
54910
54733
  const newText = insertText(deleted, range.start, linkText, { link: linkUrl });
54911
54734
  editor.setBlockText(block, newText);
54912
54735
  editor.selection.selectBlock(block, range.start + linkText.length);
54913
- requestEditorFocus(editor);
54736
+ editor.focus();
54914
54737
  } catch (error2) {
54915
54738
  logger$1$.error(error2);
54916
54739
  }
54917
54740
  };
54918
54741
  const onClose = () => {
54919
54742
  editor.selection.selectBlock(block, range.end);
54920
- requestEditorFocus(editor);
54743
+ editor.focus();
54921
54744
  };
54922
54745
  const rect = getBlockClientRects(editor, block, editor.selection.range)[0];
54923
54746
  if (!rect) {
@@ -55419,7 +55242,6 @@ ${codeText}
55419
55242
  __publicField(this, "_disableTextToolbar", false);
55420
55243
  __publicField(this, "_lastClickTime", 0);
55421
55244
  __publicField(this, "_disabled", false);
55422
- __publicField(this, "cancelFocus");
55423
55245
  __publicField(this, "isInToolbar", (event) => this.toolbar.isInCommandBar(event.target));
55424
55246
  __publicField(this, "handleButtonClick", (toolbar2, item) => {
55425
55247
  const tooltip = this.editor.findCustom("editor-tooltip");
@@ -55443,16 +55265,24 @@ ${codeText}
55443
55265
  }
55444
55266
  this._lastClickTime = Date.now();
55445
55267
  });
55446
- __publicField(this, "handleClose", () => {
55447
- var _a, _b;
55268
+ __publicField(this, "handleClose", (toolbar2) => {
55269
+ var _a;
55270
+ if (toolbar2.closeReason === "clickBackground" || !this.editor.rootElement.isConnected) {
55271
+ return;
55272
+ }
55273
+ const focusedElement = document.activeElement;
55274
+ if (focusedElement && focusedElement !== document.body && focusedElement !== document.documentElement && !this.editor.rootElement.contains(focusedElement) && !toolbar2.isInCommandBar(focusedElement)) {
55275
+ return;
55276
+ }
55448
55277
  if (shouldFocusToEditor(this.editor) && !clientType.isMobile) {
55449
55278
  const activeElement = (_a = document.getSelection()) == null ? void 0 : _a.focusNode;
55450
55279
  if (activeElement && isInBlockTools(activeElement)) {
55451
55280
  logger$1Z.debug("focus is in block tools, ignore focus");
55452
55281
  return;
55453
55282
  }
55454
- (_b = this.cancelFocus) == null ? void 0 : _b.call(this);
55455
- this.cancelFocus = requestEditorFocus(this.editor);
55283
+ this.editor.focus({
55284
+ preventScroll: true
55285
+ });
55456
55286
  }
55457
55287
  });
55458
55288
  __publicField(this, "handleClosing", (bar2, event) => {
@@ -55581,10 +55411,8 @@ ${codeText}
55581
55411
  this.toolbar.close("selectionChange");
55582
55412
  }
55583
55413
  destroy() {
55584
- var _a;
55585
55414
  this.unbindEvents();
55586
55415
  this.toolbar.destroy();
55587
- (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
55588
55416
  this.editor.removeListener("selectionChanged", this.handleSelectionChange);
55589
55417
  OnesEditorHoveringBlock.get(this.editor).removeListener("childChange", this.handleHoveringBlockChildChange);
55590
55418
  }
@@ -96924,13 +96752,14 @@ ${JSON.stringify(error2, null, 2)}`);
96924
96752
  __publicField(this, "toolbar");
96925
96753
  __publicField(this, "toolbarFullScreen");
96926
96754
  __publicField(this, "root");
96927
- __publicField(this, "cancelFocus");
96928
96755
  __publicField(this, "handleClick", (bar2, item) => {
96929
96756
  const command = item;
96930
96757
  if (command.onClick) {
96931
96758
  command.onClick(this.editor, command, bar2);
96932
96759
  this.handleSelectionChanged();
96933
- this.restoreFocus();
96760
+ setTimeout(() => {
96761
+ this.editor.focus();
96762
+ });
96934
96763
  return;
96935
96764
  }
96936
96765
  const findParent = (item2, id) => {
@@ -96976,7 +96805,9 @@ ${JSON.stringify(error2, null, 2)}`);
96976
96805
  id: "main-toolbar"
96977
96806
  });
96978
96807
  this.toolbar.addListener("closing", () => {
96979
- this.restoreFocus(100);
96808
+ setTimeout(() => {
96809
+ editor.focus();
96810
+ }, 100);
96980
96811
  return true;
96981
96812
  });
96982
96813
  this.toolbar.addListener("click", this.handleClick);
@@ -97007,18 +96838,11 @@ ${JSON.stringify(error2, null, 2)}`);
97007
96838
  });
97008
96839
  }
97009
96840
  }
97010
- restoreFocus(delay = 0) {
97011
- var _a;
97012
- (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
97013
- this.cancelFocus = requestEditorFocus(this.editor, delay);
97014
- }
97015
96841
  destroy() {
97016
- var _a, _b, _c;
97017
- (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
96842
+ var _a;
97018
96843
  this.toolbar.destroy();
97019
96844
  this.editor.removeListener("selectionChanged", this.handleSelectionChanged);
97020
- (_b = this.toolbarFullScreen) == null ? void 0 : _b.destroy();
97021
- (_c = this.cancelFocus) == null ? void 0 : _c.call(this);
96845
+ (_a = this.toolbarFullScreen) == null ? void 0 : _a.destroy();
97022
96846
  this.root.remove();
97023
96847
  }
97024
96848
  setItems(items) {
@@ -97611,7 +97435,7 @@ ${JSON.stringify(error2, null, 2)}`);
97611
97435
  }
97612
97436
  }
97613
97437
  });
97614
- editor.version = "3.1.7-beta.ONES22302172.5";
97438
+ editor.version = "3.1.7-beta.ONES22302592.1";
97615
97439
  return editor;
97616
97440
  }
97617
97441
  function isDoc(doc2) {
@@ -97752,7 +97576,7 @@ ${JSON.stringify(error2, null, 2)}`);
97752
97576
  OnesEditorDropTarget.register(editor);
97753
97577
  OnesEditorTocProvider.register(editor);
97754
97578
  OnesEditorExclusiveBlock.register(editor);
97755
- editor.version = "3.1.7-beta.ONES22302172.5";
97579
+ editor.version = "3.1.7-beta.ONES22302592.1";
97756
97580
  return editor;
97757
97581
  } catch (error2) {
97758
97582
  if (editorForCleanup) {
@@ -143655,7 +143479,6 @@ ${JSON.stringify(error2, null, 2)}`);
143655
143479
  exports2.FindReplaceItem = FindReplaceItem;
143656
143480
  exports2.FitIcon = FitIcon;
143657
143481
  exports2.FixedToolbar = FixedToolbar;
143658
- exports2.FocusRestoration = FocusRestoration;
143659
143482
  exports2.FontBoldItem = FontBoldItem;
143660
143483
  exports2.FontItalicItem = FontItalicItem;
143661
143484
  exports2.FontStrikethroughItem = FontStrikethroughItem;
@@ -143851,7 +143674,6 @@ ${JSON.stringify(error2, null, 2)}`);
143851
143674
  exports2.YoukuIcon = YoukuIcon;
143852
143675
  exports2.ZERO_WIDTH_SPACE_CHAR = ZERO_WIDTH_SPACE_CHAR;
143853
143676
  exports2.abbreviation = abbreviation;
143854
- exports2.acquireEditorFocus = acquireEditorFocus;
143855
143677
  exports2.activeComment = activeComment;
143856
143678
  exports2.addAttribute = addAttribute;
143857
143679
  exports2.addClass = addClass;
@@ -144335,8 +144157,6 @@ ${JSON.stringify(error2, null, 2)}`);
144335
144157
  exports2.replaceAllText = replaceAllText;
144336
144158
  exports2.replaceText = replaceText;
144337
144159
  exports2.requestDownload = requestDownload;
144338
- exports2.requestEditorFocus = requestEditorFocus;
144339
- exports2.requestInputFocus = requestInputFocus;
144340
144160
  exports2.resetListStart = resetListStart;
144341
144161
  exports2.saveAs = saveAs$1;
144342
144162
  exports2.scrollBarIntoView = scrollBarIntoView;