@ones-editor/editor 3.1.7-beta.ONES22303310.1 → 3.1.7-beta.h1473.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.
@@ -6,8 +6,14 @@ export default abstract class ManualCommandBar extends CommandBar implements Abs
6
6
  private manualCommandBarOptions?;
7
7
  tippyInstance: Instance | null;
8
8
  _target: HTMLElement | null;
9
+ private focusTimer;
9
10
  constructor(items: CommandItem[], closeable?: Closeable, manualCommandBarOptions?: CommandBarOptions | undefined);
10
11
  handleBeforeClose: (event?: MouseEvent | TouchEvent) => boolean;
12
+ private getFocusOwner;
13
+ private restoreFocusAfterClose;
14
+ private isFocusOwner;
15
+ private handleFocusInteraction;
16
+ private clearFocusTimer;
11
17
  setProps: (props: ManualShowCommandBarOptions) => void;
12
18
  manualShow(target: HTMLElement, options?: ManualShowCommandBarOptions): void;
13
19
  close(reason: CloseReason, e?: MouseEvent | null): void;
@@ -24,6 +24,7 @@ export interface ManualShowCommandBarOptions {
24
24
  }
25
25
  export interface AbstractCommandBar extends TypedEmitter<CommandBarEvents> {
26
26
  readonly isVisible: boolean;
27
+ readonly closeReason: CloseReason;
27
28
  readonly parentItem: CommandItem | null;
28
29
  closeable: Closeable | null;
29
30
  close: (reason: CloseReason, e?: MouseEvent | null) => void;
package/dist/index.js CHANGED
@@ -42516,8 +42516,11 @@ ${codeText}
42516
42516
  });
42517
42517
  __publicField(this, "tippyInstance", null);
42518
42518
  __publicField(this, "_target", null);
42519
+ __publicField(this, "focusTimer", null);
42519
42520
  __publicField(this, "handleBeforeClose", (event) => {
42520
42521
  var _a;
42522
+ const focusOwner = this.getFocusOwner();
42523
+ focusOwner.clearFocusTimer();
42521
42524
  let ret = false;
42522
42525
  if ((_a = this.manualCommandBarOptions) == null ? void 0 : _a.beforeClose) {
42523
42526
  ret = this.manualCommandBarOptions.beforeClose(event);
@@ -42525,32 +42528,65 @@ ${codeText}
42525
42528
  if (ret) {
42526
42529
  return ret;
42527
42530
  }
42528
- if (!this._target) {
42529
- return ret;
42530
- }
42531
- 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
- }
42542
- }
42543
- }, 100);
42531
+ focusOwner.restoreFocusAfterClose(event);
42544
42532
  return ret;
42545
42533
  });
42534
+ __publicField(this, "handleFocusInteraction", (event) => {
42535
+ if (!this.isFocusOwner(event.target)) {
42536
+ this.clearFocusTimer();
42537
+ }
42538
+ });
42546
42539
  __publicField(this, "setProps", (props) => {
42547
42540
  var _a;
42548
42541
  (_a = this.tippyInstance) == null ? void 0 : _a.setProps(props);
42549
42542
  });
42550
42543
  this.manualCommandBarOptions = manualCommandBarOptions;
42551
42544
  }
42545
+ getFocusOwner() {
42546
+ return this.closeable instanceof ManualCommandBar ? this.closeable.getFocusOwner() : this;
42547
+ }
42548
+ restoreFocusAfterClose(event) {
42549
+ if (!this._target) {
42550
+ return;
42551
+ }
42552
+ const target = this._target;
42553
+ const parentEditor = target.closest(".editor-root");
42554
+ if (!parentEditor || event && !this.isFocusOwner(event.target)) {
42555
+ return;
42556
+ }
42557
+ document.addEventListener("mousedown", this.handleFocusInteraction);
42558
+ document.addEventListener("focusin", this.handleFocusInteraction);
42559
+ this.focusTimer = setTimeout(() => {
42560
+ this.clearFocusTimer();
42561
+ const input2 = parentEditor.querySelector(".editor-input");
42562
+ if (!target.isConnected || !parentEditor.isConnected || !(input2 == null ? void 0 : input2.isConnected)) {
42563
+ return;
42564
+ }
42565
+ const activeElement = document.activeElement;
42566
+ if (parentEditor.contains(activeElement)) {
42567
+ return;
42568
+ }
42569
+ if (!activeElement || activeElement === document.body || this.isInCommandBar(activeElement)) {
42570
+ input2.focus();
42571
+ }
42572
+ }, 100);
42573
+ }
42574
+ isFocusOwner(target) {
42575
+ var _a;
42576
+ const parentEditor = (_a = this._target) == null ? void 0 : _a.closest(".editor-root");
42577
+ return target instanceof Node && (!!(parentEditor == null ? void 0 : parentEditor.contains(target)) || this.isInCommandBar(target));
42578
+ }
42579
+ clearFocusTimer() {
42580
+ if (this.focusTimer !== null) {
42581
+ clearTimeout(this.focusTimer);
42582
+ this.focusTimer = null;
42583
+ }
42584
+ document.removeEventListener("mousedown", this.handleFocusInteraction);
42585
+ document.removeEventListener("focusin", this.handleFocusInteraction);
42586
+ }
42552
42587
  manualShow(target, options) {
42553
42588
  var _a, _b, _c, _d;
42589
+ this.getFocusOwner().clearFocusTimer();
42554
42590
  this._target = target;
42555
42591
  if (this.isVisible) {
42556
42592
  return;
@@ -42599,6 +42635,9 @@ ${codeText}
42599
42635
  }
42600
42636
  close(reason, e2) {
42601
42637
  var _a, _b;
42638
+ if (reason && reason !== "clickBackground" && reason !== "cancelBar" && reason !== "clickItem") {
42639
+ this.clearFocusTimer();
42640
+ }
42602
42641
  super.close(reason);
42603
42642
  if (this.isVisible) {
42604
42643
  if (e2) {
@@ -42610,6 +42649,7 @@ ${codeText}
42610
42649
  }
42611
42650
  destroy() {
42612
42651
  var _a;
42652
+ this.clearFocusTimer();
42613
42653
  (_a = this.tippyInstance) == null ? void 0 : _a.destroy();
42614
42654
  this.tippyInstance = null;
42615
42655
  super.destroy();
@@ -73838,11 +73878,10 @@ ${codeText}
73838
73878
  createTableBorderBar(editor, tableBlock);
73839
73879
  }
73840
73880
  function hideTableBorderBar(editor, tableBlock) {
73841
- var _a, _b;
73842
73881
  assert(logger$14, isTableBlock(tableBlock), "invalid table block");
73843
- const tools = (_a = getBlockContent(tableBlock).querySelector("div[data-type=table-content]")) == null ? void 0 : _a.querySelector(":scope >div[data-type=table-tools]");
73882
+ const tools = getTableTools(editor, tableBlock);
73844
73883
  const blockTools = getBlockTools(tableBlock);
73845
- const topTableBorderBar = (_b = tools == null ? void 0 : tools.querySelectorAll(".table-border-bar-container")) != null ? _b : [];
73884
+ const topTableBorderBar = tools.querySelectorAll(".table-border-bar-container");
73846
73885
  const leftTableBorderBar = blockTools.querySelectorAll(".table-border-bar-container");
73847
73886
  topTableBorderBar.forEach((elem) => {
73848
73887
  editor.domEvents.removeEventListener(elem, "click", handleBorderBarClicked);
@@ -76201,6 +76240,8 @@ ${codeText}
76201
76240
  __publicField(this, "item");
76202
76241
  __publicField(this, "docs", null);
76203
76242
  __publicField(this, "checkedId");
76243
+ __publicField(this, "focusTimer", null);
76244
+ __publicField(this, "destroyed", false);
76204
76245
  __publicField(this, "handlePasteSpecial", (bar2, item) => {
76205
76246
  if (!item.data) {
76206
76247
  return;
@@ -76211,24 +76252,37 @@ ${codeText}
76211
76252
  this.checkedId = item.id;
76212
76253
  }
76213
76254
  this.onPasteSpecial(this.cleaningDoc(item), item.id);
76214
- setTimeout(() => {
76255
+ this.clearFocusTimer();
76256
+ document.addEventListener("mousedown", this.handleFocusInteraction);
76257
+ document.addEventListener("focusin", this.handleFocusInteraction);
76258
+ this.focusTimer = setTimeout(() => {
76259
+ this.clearFocusTimer();
76260
+ if (!this.canRestoreFocus()) {
76261
+ return;
76262
+ }
76215
76263
  if (this.docs) {
76216
76264
  this.show(this.docs);
76217
76265
  }
76218
76266
  this.editor.focus();
76219
76267
  });
76220
76268
  });
76221
- __publicField(this, "handleClose", () => {
76222
- const activeElem = document.activeElement;
76223
- const tagName = activeElem ? activeElem.tagName.toLowerCase() : "";
76224
- if (tagName === "input" || tagName === "textarea") {
76269
+ __publicField(this, "handleClose", (bar2) => {
76270
+ if (bar2.closeReason === "clickBackground") {
76271
+ this.clearFocusTimer();
76225
76272
  return;
76226
76273
  }
76227
- this.editor.focus();
76274
+ if (bar2.closeReason === "cancelBar" && this.canRestoreFocus()) {
76275
+ this.editor.focus();
76276
+ }
76228
76277
  });
76229
76278
  __publicField(this, "handleSelectionChange", () => {
76230
76279
  if (this.toolbar.isVisible) {
76231
- this.handleClose();
76280
+ this.handleClose(this.toolbar);
76281
+ }
76282
+ });
76283
+ __publicField(this, "handleFocusInteraction", (event) => {
76284
+ if (!this.isFocusOwner(event.target)) {
76285
+ this.clearFocusTimer();
76232
76286
  }
76233
76287
  });
76234
76288
  this.editor = editor;
@@ -76252,6 +76306,10 @@ ${codeText}
76252
76306
  this.toolbar.addListener("close", this.handleClose);
76253
76307
  }
76254
76308
  show(docs) {
76309
+ this.clearFocusTimer();
76310
+ if (this.destroyed || this.editor.destroyed) {
76311
+ return;
76312
+ }
76255
76313
  this.docs = docs;
76256
76314
  const editor = this.editor;
76257
76315
  const range = editor.selection.range;
@@ -76310,13 +76368,39 @@ ${codeText}
76310
76368
  return doc2;
76311
76369
  }
76312
76370
  hide() {
76371
+ this.clearFocusTimer();
76313
76372
  this.toolbar.close("selectionChange");
76314
76373
  }
76315
76374
  clearCheckedState() {
76316
76375
  this.checkedId = void 0;
76317
76376
  }
76318
76377
  destroy() {
76378
+ var _a;
76379
+ this.destroyed = true;
76380
+ this.clearFocusTimer();
76319
76381
  this.toolbar.destroy();
76382
+ (_a = this.anchor) == null ? void 0 : _a.remove();
76383
+ this.anchor = null;
76384
+ this.docs = null;
76385
+ }
76386
+ canRestoreFocus() {
76387
+ var _a;
76388
+ if (this.destroyed || this.editor.destroyed || !this.editor.rootElement.isConnected || !((_a = this.anchor) == null ? void 0 : _a.isConnected)) {
76389
+ return false;
76390
+ }
76391
+ const activeElement = document.activeElement;
76392
+ return !activeElement || activeElement === document.body || this.isFocusOwner(activeElement);
76393
+ }
76394
+ isFocusOwner(target) {
76395
+ return target instanceof Node && (this.editor.rootElement.contains(target) || this.toolbar.isInCommandBar(target));
76396
+ }
76397
+ clearFocusTimer() {
76398
+ if (this.focusTimer !== null) {
76399
+ clearTimeout(this.focusTimer);
76400
+ this.focusTimer = null;
76401
+ }
76402
+ document.removeEventListener("mousedown", this.handleFocusInteraction);
76403
+ document.removeEventListener("focusin", this.handleFocusInteraction);
76320
76404
  }
76321
76405
  getCommandItems(docs) {
76322
76406
  const getKeepFormatCommand = (format2) => {
@@ -97388,7 +97472,7 @@ ${JSON.stringify(error2, null, 2)}`);
97388
97472
  }
97389
97473
  }
97390
97474
  });
97391
- editor.version = "3.1.7-beta.ONES22303310.1";
97475
+ editor.version = "3.1.7-beta.h1473.1";
97392
97476
  return editor;
97393
97477
  }
97394
97478
  function isDoc(doc2) {
@@ -97529,7 +97613,7 @@ ${JSON.stringify(error2, null, 2)}`);
97529
97613
  OnesEditorDropTarget.register(editor);
97530
97614
  OnesEditorTocProvider.register(editor);
97531
97615
  OnesEditorExclusiveBlock.register(editor);
97532
- editor.version = "3.1.7-beta.ONES22303310.1";
97616
+ editor.version = "3.1.7-beta.h1473.1";
97533
97617
  return editor;
97534
97618
  } catch (error2) {
97535
97619
  if (editorForCleanup) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "3.1.7-beta.ONES22303310.1",
3
+ "version": "3.1.7-beta.h1473.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {