@ones-editor/editor 4.0.7-beta.h1474.2 → 4.0.7-beta.h1474.3

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.
@@ -25,7 +25,7 @@ export default class OnesEditorToolbar implements OnesEditorHoveringBlockFilter,
25
25
  isInToolbar: (event: MouseEvent) => boolean;
26
26
  isInBlock(block: BlockElement, event: MouseEvent): boolean;
27
27
  handleButtonClick: (toolbar: AbstractCommandBar, item: CommandItem) => void;
28
- handleClose: () => void;
28
+ handleClose: (toolbar: AbstractCommandBar) => void;
29
29
  handleClosing: (bar: unknown, event: MouseEvent | TouchEvent) => boolean;
30
30
  bindEvents(): void;
31
31
  unbindEvents(): void;
@@ -8,12 +8,14 @@ export default abstract class ManualCommandBar extends CommandBar implements Abs
8
8
  _target: HTMLElement | null;
9
9
  private cancelFocus?;
10
10
  private focusTimer;
11
+ private focusRestoreGeneration;
11
12
  constructor(items: CommandItem[], closeable?: Closeable, manualCommandBarOptions?: CommandBarOptions | undefined);
12
13
  handleBeforeClose: (event?: MouseEvent | TouchEvent) => boolean;
13
14
  private getFocusOwner;
14
15
  private restoreFocusAfterClose;
15
16
  private isFocusOwner;
16
17
  private handleFocusInteraction;
18
+ private handleWindowBlur;
17
19
  private clearFocusTimer;
18
20
  setProps: (props: ManualShowCommandBarOptions) => void;
19
21
  manualShow(target: HTMLElement, options?: ManualShowCommandBarOptions): void;
package/dist/index.js CHANGED
@@ -42731,6 +42731,7 @@ ${codeText}
42731
42731
  __publicField(this, "_target", null);
42732
42732
  __publicField(this, "cancelFocus");
42733
42733
  __publicField(this, "focusTimer", null);
42734
+ __publicField(this, "focusRestoreGeneration", 0);
42734
42735
  __publicField(this, "handleBeforeClose", (event) => {
42735
42736
  var _a;
42736
42737
  const focusOwner = this.getFocusOwner();
@@ -42750,6 +42751,9 @@ ${codeText}
42750
42751
  this.clearFocusTimer();
42751
42752
  }
42752
42753
  });
42754
+ __publicField(this, "handleWindowBlur", () => {
42755
+ this.clearFocusTimer();
42756
+ });
42753
42757
  __publicField(this, "setProps", (props) => {
42754
42758
  var _a;
42755
42759
  (_a = this.tippyInstance) == null ? void 0 : _a.setProps(props);
@@ -42768,19 +42772,24 @@ ${codeText}
42768
42772
  if (!parentEditor || event && !this.isFocusOwner(event.target)) {
42769
42773
  return;
42770
42774
  }
42771
- document.addEventListener("mousedown", this.handleFocusInteraction);
42772
- document.addEventListener("focusin", this.handleFocusInteraction);
42775
+ const generation = this.focusRestoreGeneration;
42776
+ document.addEventListener("mousedown", this.handleFocusInteraction, true);
42777
+ document.addEventListener("focusin", this.handleFocusInteraction, true);
42778
+ window.addEventListener("blur", this.handleWindowBlur);
42773
42779
  this.focusTimer = setTimeout(() => {
42780
+ if (generation !== this.focusRestoreGeneration) {
42781
+ return;
42782
+ }
42774
42783
  this.clearFocusTimer();
42775
42784
  const input2 = parentEditor.querySelector(".editor-input");
42776
- if (!target.isConnected || !parentEditor.isConnected || !(input2 == null ? void 0 : input2.isConnected)) {
42785
+ if (this._target !== target || !target.isConnected || !parentEditor.isConnected || !(input2 == null ? void 0 : input2.isConnected) || !document.hasFocus()) {
42777
42786
  return;
42778
42787
  }
42779
42788
  const activeElement = document.activeElement;
42780
42789
  if (parentEditor.contains(activeElement)) {
42781
42790
  return;
42782
42791
  }
42783
- if (!activeElement || activeElement === document.body || this.isInCommandBar(activeElement)) {
42792
+ if (!activeElement || activeElement === document.body || activeElement === document.documentElement || this.isInCommandBar(activeElement)) {
42784
42793
  this.cancelFocus = requestInputFocus(input2);
42785
42794
  }
42786
42795
  }, 100);
@@ -42792,14 +42801,16 @@ ${codeText}
42792
42801
  }
42793
42802
  clearFocusTimer() {
42794
42803
  var _a;
42804
+ this.focusRestoreGeneration += 1;
42795
42805
  (_a = this.cancelFocus) == null ? void 0 : _a.call(this);
42796
42806
  this.cancelFocus = void 0;
42797
42807
  if (this.focusTimer !== null) {
42798
42808
  clearTimeout(this.focusTimer);
42799
42809
  this.focusTimer = null;
42800
42810
  }
42801
- document.removeEventListener("mousedown", this.handleFocusInteraction);
42802
- document.removeEventListener("focusin", this.handleFocusInteraction);
42811
+ document.removeEventListener("mousedown", this.handleFocusInteraction, true);
42812
+ document.removeEventListener("focusin", this.handleFocusInteraction, true);
42813
+ window.removeEventListener("blur", this.handleWindowBlur);
42803
42814
  }
42804
42815
  manualShow(target, options) {
42805
42816
  var _a, _b, _c, _d;
@@ -42852,7 +42863,7 @@ ${codeText}
42852
42863
  }
42853
42864
  close(reason, e2) {
42854
42865
  var _a, _b;
42855
- if (reason && reason !== "clickBackground" && reason !== "cancelBar" && reason !== "clickItem") {
42866
+ if (reason === "clickBackground" || reason && reason !== "cancelBar" && reason !== "clickItem") {
42856
42867
  this.clearFocusTimer();
42857
42868
  }
42858
42869
  super.close(reason);
@@ -55584,8 +55595,15 @@ ${codeText}
55584
55595
  }
55585
55596
  this._lastClickTime = Date.now();
55586
55597
  });
55587
- __publicField(this, "handleClose", () => {
55598
+ __publicField(this, "handleClose", (toolbar2) => {
55588
55599
  var _a, _b;
55600
+ if (toolbar2.closeReason === "clickBackground" || !this.editor.rootElement.isConnected) {
55601
+ return;
55602
+ }
55603
+ const focusedElement = document.activeElement;
55604
+ if (focusedElement && focusedElement !== document.body && focusedElement !== document.documentElement && !this.editor.rootElement.contains(focusedElement) && !toolbar2.isInCommandBar(focusedElement)) {
55605
+ return;
55606
+ }
55589
55607
  if (shouldFocusToEditor(this.editor) && !clientType.isMobile) {
55590
55608
  const activeElement = (_a = document.getSelection()) == null ? void 0 : _a.focusNode;
55591
55609
  if (activeElement && isInBlockTools(activeElement)) {
@@ -97843,7 +97861,7 @@ ${JSON.stringify(error2, null, 2)}`);
97843
97861
  }
97844
97862
  }
97845
97863
  });
97846
- editor.version = "4.0.7-beta.h1474.2";
97864
+ editor.version = "4.0.7-beta.h1474.3";
97847
97865
  return editor;
97848
97866
  }
97849
97867
  function isDoc(doc2) {
@@ -97979,7 +97997,7 @@ ${JSON.stringify(error2, null, 2)}`);
97979
97997
  OnesEditorDropTarget.register(editor);
97980
97998
  OnesEditorTocProvider.register(editor);
97981
97999
  OnesEditorExclusiveBlock.register(editor);
97982
- editor.version = "4.0.7-beta.h1474.2";
98000
+ editor.version = "4.0.7-beta.h1474.3";
97983
98001
  return editor;
97984
98002
  } catch (error2) {
97985
98003
  try {
@@ -98122,7 +98140,7 @@ ${JSON.stringify(error2, null, 2)}`);
98122
98140
  }
98123
98141
  }
98124
98142
  });
98125
- editor.version = "4.0.7-beta.h1474.2";
98143
+ editor.version = "4.0.7-beta.h1474.3";
98126
98144
  return editor;
98127
98145
  }
98128
98146
  const emojis$1 = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "4.0.7-beta.h1474.2",
3
+ "version": "4.0.7-beta.h1474.3",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {