@ones-editor/editor 3.1.7-beta.ONES22302172.4 → 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
@@ -26422,39 +26422,63 @@ var __publicField = (obj, key, value) => {
26422
26422
  __publicField(this, "generation", 0);
26423
26423
  __publicField(this, "owner", null);
26424
26424
  __publicField(this, "destroyed", false);
26425
+ __publicField(this, "activeScope");
26425
26426
  __publicField(this, "timers", /* @__PURE__ */ new Set());
26426
26427
  this.input = input2;
26427
26428
  this.restore = restore;
26428
26429
  controllers.set(input2, this);
26429
26430
  }
26430
26431
  canFocus() {
26431
- return !this.destroyed && !this.owner && this.input.isConnected;
26432
+ var _a;
26433
+ return !this.destroyed && !this.owner && !((_a = this.activeScope) == null ? void 0 : _a.cancelled) && this.input.isConnected;
26432
26434
  }
26433
26435
  hasOtherInput() {
26434
26436
  const active = this.input.ownerDocument.activeElement;
26435
26437
  return active !== this.input && !!(active == null ? void 0 : active.matches('input, textarea, select, [contenteditable="true"], [contenteditable=""]'));
26436
26438
  }
26437
26439
  schedule(callback, delay = 0, protectUserFocus = false) {
26438
- if (!this.canFocus()) {
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()) {
26439
26448
  return noop$1;
26440
26449
  }
26441
26450
  const generation = this.generation;
26442
26451
  const timer = setTimeout(() => {
26443
26452
  this.timers.delete(timer);
26444
- if (generation === this.generation && this.canFocus() && (!protectUserFocus || !this.hasOtherInput())) {
26445
- callback();
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
+ }
26446
26462
  }
26447
26463
  }, delay);
26448
26464
  this.timers.add(timer);
26465
+ scope.timers.add(timer);
26449
26466
  return () => {
26450
- clearTimeout(timer);
26451
- this.timers.delete(timer);
26467
+ scope.cancelled = true;
26468
+ scope.timers.forEach((pending) => {
26469
+ clearTimeout(pending);
26470
+ this.timers.delete(pending);
26471
+ });
26472
+ scope.timers.clear();
26452
26473
  };
26453
26474
  }
26454
26475
  request(delay = 0) {
26455
- return this.schedule(this.restore, delay, !clientType.isMobile);
26476
+ return this.scheduleInScope(this.restore, delay, !clientType.isMobile, this.createScope());
26456
26477
  }
26457
26478
  cancelPending() {
26479
+ if (this.activeScope) {
26480
+ this.activeScope.cancelled = true;
26481
+ }
26458
26482
  this.generation += 1;
26459
26483
  this.timers.forEach((timer) => clearTimeout(timer));
26460
26484
  this.timers.clear();
@@ -97587,7 +97611,7 @@ ${JSON.stringify(error2, null, 2)}`);
97587
97611
  }
97588
97612
  }
97589
97613
  });
97590
- editor.version = "3.1.7-beta.ONES22302172.4";
97614
+ editor.version = "3.1.7-beta.ONES22302172.5";
97591
97615
  return editor;
97592
97616
  }
97593
97617
  function isDoc(doc2) {
@@ -97728,7 +97752,7 @@ ${JSON.stringify(error2, null, 2)}`);
97728
97752
  OnesEditorDropTarget.register(editor);
97729
97753
  OnesEditorTocProvider.register(editor);
97730
97754
  OnesEditorExclusiveBlock.register(editor);
97731
- editor.version = "3.1.7-beta.ONES22302172.4";
97755
+ editor.version = "3.1.7-beta.ONES22302172.5";
97732
97756
  return editor;
97733
97757
  } catch (error2) {
97734
97758
  if (editorForCleanup) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "3.1.7-beta.ONES22302172.4",
3
+ "version": "3.1.7-beta.ONES22302172.5",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {