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

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);
@@ -48910,6 +48921,8 @@ ${codeText}
48910
48921
  }
48911
48922
  function resetScrollbarCore(scrollCore, scrollWrap) {
48912
48923
  const scrollContainer = getScrollContainer(scrollWrap);
48924
+ if (!scrollContainer || !getContainerOption(scrollCore, getContainer(scrollContainer)))
48925
+ return;
48913
48926
  const scrollbarContainer = getScrollbarContainer(scrollContainer);
48914
48927
  const { scrollWidth, clientWidth } = getElementScrollSize(scrollContainer);
48915
48928
  const { paddingLeft, paddingRight } = getScrollWrapPaddingSize(scrollWrap);
@@ -48926,7 +48939,7 @@ ${codeText}
48926
48939
  }
48927
48940
  function debounceByArgs(func, wait) {
48928
48941
  const debouncers = /* @__PURE__ */ new Map();
48929
- return function(...args) {
48942
+ const debounced = function(...args) {
48930
48943
  var _a;
48931
48944
  const scrollWrap = args[1];
48932
48945
  let key = (scrollWrap == null ? void 0 : scrollWrap.genId) || "";
@@ -48938,17 +48951,30 @@ ${codeText}
48938
48951
  if (!debouncers.has(key)) {
48939
48952
  debouncers.set(key, debounce__default.default(
48940
48953
  (...innerArgs) => {
48941
- const result = func.apply(this, innerArgs);
48942
- if (scrollWrap)
48943
- scrollWrap.genId = void 0;
48944
- debouncers.delete(key);
48945
- return result;
48954
+ try {
48955
+ return func.apply(this, innerArgs);
48956
+ } finally {
48957
+ if (scrollWrap)
48958
+ scrollWrap.genId = void 0;
48959
+ debouncers.delete(key);
48960
+ }
48946
48961
  },
48947
48962
  wait
48948
48963
  ));
48949
48964
  }
48950
48965
  return (_a = debouncers.get(key)) == null ? void 0 : _a.apply(this, args);
48951
48966
  };
48967
+ debounced.cancel = (scrollWrap) => {
48968
+ var _a, _b;
48969
+ const target = scrollWrap;
48970
+ const key = target.genId;
48971
+ if (!key)
48972
+ return;
48973
+ (_b = (_a = debouncers.get(key)) == null ? void 0 : _a.cancel) == null ? void 0 : _b.call(_a);
48974
+ debouncers.delete(key);
48975
+ target.genId = void 0;
48976
+ };
48977
+ return debounced;
48952
48978
  }
48953
48979
  const resetScrollbar = debounceByArgs(resetScrollbarCore, 50);
48954
48980
  function resetScrollbarLeft(scrollContainer, scrollbarContainer) {
@@ -49443,6 +49469,7 @@ ${codeText}
49443
49469
  }
49444
49470
  unbindCore(scrollContainer, scrollWrap) {
49445
49471
  var _a, _b, _c, _d, _e, _f;
49472
+ resetScrollbar.cancel(scrollWrap);
49446
49473
  if (!this.boundContainers.delete(scrollContainer))
49447
49474
  return;
49448
49475
  const scrollbarContainer = getScrollbarContainer(scrollContainer);
@@ -55584,8 +55611,15 @@ ${codeText}
55584
55611
  }
55585
55612
  this._lastClickTime = Date.now();
55586
55613
  });
55587
- __publicField(this, "handleClose", () => {
55614
+ __publicField(this, "handleClose", (toolbar2) => {
55588
55615
  var _a, _b;
55616
+ if (toolbar2.closeReason === "clickBackground" || !this.editor.rootElement.isConnected) {
55617
+ return;
55618
+ }
55619
+ const focusedElement = document.activeElement;
55620
+ if (focusedElement && focusedElement !== document.body && focusedElement !== document.documentElement && !this.editor.rootElement.contains(focusedElement) && !toolbar2.isInCommandBar(focusedElement)) {
55621
+ return;
55622
+ }
55589
55623
  if (shouldFocusToEditor(this.editor) && !clientType.isMobile) {
55590
55624
  const activeElement = (_a = document.getSelection()) == null ? void 0 : _a.focusNode;
55591
55625
  if (activeElement && isInBlockTools(activeElement)) {
@@ -74207,10 +74241,11 @@ ${codeText}
74207
74241
  createTableBorderBar(editor, tableBlock);
74208
74242
  }
74209
74243
  function hideTableBorderBar(editor, tableBlock) {
74244
+ var _a, _b;
74210
74245
  assert(logger$14, isTableBlock(tableBlock), "invalid table block");
74211
- const tools = getTableTools(editor, tableBlock);
74246
+ const tools = (_a = getBlockContent(tableBlock).querySelector("div[data-type=table-content]")) == null ? void 0 : _a.querySelector(":scope >div[data-type=table-tools]");
74212
74247
  const blockTools = getBlockTools(tableBlock);
74213
- const topTableBorderBar = tools.querySelectorAll(".table-border-bar-container");
74248
+ const topTableBorderBar = (_b = tools == null ? void 0 : tools.querySelectorAll(".table-border-bar-container")) != null ? _b : [];
74214
74249
  const leftTableBorderBar = blockTools.querySelectorAll(".table-border-bar-container");
74215
74250
  topTableBorderBar.forEach((elem) => {
74216
74251
  editor.domEvents.removeEventListener(elem, "click", handleBorderBarClicked);
@@ -97843,7 +97878,7 @@ ${JSON.stringify(error2, null, 2)}`);
97843
97878
  }
97844
97879
  }
97845
97880
  });
97846
- editor.version = "4.0.7-beta.h1474.2";
97881
+ editor.version = "4.0.7-beta.h1474.4";
97847
97882
  return editor;
97848
97883
  }
97849
97884
  function isDoc(doc2) {
@@ -97979,7 +98014,7 @@ ${JSON.stringify(error2, null, 2)}`);
97979
98014
  OnesEditorDropTarget.register(editor);
97980
98015
  OnesEditorTocProvider.register(editor);
97981
98016
  OnesEditorExclusiveBlock.register(editor);
97982
- editor.version = "4.0.7-beta.h1474.2";
98017
+ editor.version = "4.0.7-beta.h1474.4";
97983
98018
  return editor;
97984
98019
  } catch (error2) {
97985
98020
  try {
@@ -98122,7 +98157,7 @@ ${JSON.stringify(error2, null, 2)}`);
98122
98157
  }
98123
98158
  }
98124
98159
  });
98125
- editor.version = "4.0.7-beta.h1474.2";
98160
+ editor.version = "4.0.7-beta.h1474.4";
98126
98161
  return editor;
98127
98162
  }
98128
98163
  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.4",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {