@ones-editor/editor 3.1.6 → 3.1.7-beta.ONES22303263.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/@ones-editor/paste-special/src/paste-special-button.d.ts +7 -1
- package/@ones-editor/tsconfig.tsbuildinfo +1 -1
- package/@ones-editor/ui-base/src/command-bar/manual-command-bar.d.ts +6 -0
- package/@ones-editor/ui-base/src/command-bar/types.d.ts +1 -0
- package/dist/index.js +110 -25
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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();
|
|
@@ -76200,6 +76240,8 @@ ${codeText}
|
|
|
76200
76240
|
__publicField(this, "item");
|
|
76201
76241
|
__publicField(this, "docs", null);
|
|
76202
76242
|
__publicField(this, "checkedId");
|
|
76243
|
+
__publicField(this, "focusTimer", null);
|
|
76244
|
+
__publicField(this, "destroyed", false);
|
|
76203
76245
|
__publicField(this, "handlePasteSpecial", (bar2, item) => {
|
|
76204
76246
|
if (!item.data) {
|
|
76205
76247
|
return;
|
|
@@ -76210,24 +76252,37 @@ ${codeText}
|
|
|
76210
76252
|
this.checkedId = item.id;
|
|
76211
76253
|
}
|
|
76212
76254
|
this.onPasteSpecial(this.cleaningDoc(item), item.id);
|
|
76213
|
-
|
|
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
|
+
}
|
|
76214
76263
|
if (this.docs) {
|
|
76215
76264
|
this.show(this.docs);
|
|
76216
76265
|
}
|
|
76217
76266
|
this.editor.focus();
|
|
76218
76267
|
});
|
|
76219
76268
|
});
|
|
76220
|
-
__publicField(this, "handleClose", () => {
|
|
76221
|
-
|
|
76222
|
-
|
|
76223
|
-
if (tagName === "input" || tagName === "textarea") {
|
|
76269
|
+
__publicField(this, "handleClose", (bar2) => {
|
|
76270
|
+
if (bar2.closeReason === "clickBackground") {
|
|
76271
|
+
this.clearFocusTimer();
|
|
76224
76272
|
return;
|
|
76225
76273
|
}
|
|
76226
|
-
this.
|
|
76274
|
+
if (bar2.closeReason === "cancelBar" && this.canRestoreFocus()) {
|
|
76275
|
+
this.editor.focus();
|
|
76276
|
+
}
|
|
76227
76277
|
});
|
|
76228
76278
|
__publicField(this, "handleSelectionChange", () => {
|
|
76229
76279
|
if (this.toolbar.isVisible) {
|
|
76230
|
-
this.handleClose();
|
|
76280
|
+
this.handleClose(this.toolbar);
|
|
76281
|
+
}
|
|
76282
|
+
});
|
|
76283
|
+
__publicField(this, "handleFocusInteraction", (event) => {
|
|
76284
|
+
if (!this.isFocusOwner(event.target)) {
|
|
76285
|
+
this.clearFocusTimer();
|
|
76231
76286
|
}
|
|
76232
76287
|
});
|
|
76233
76288
|
this.editor = editor;
|
|
@@ -76251,6 +76306,10 @@ ${codeText}
|
|
|
76251
76306
|
this.toolbar.addListener("close", this.handleClose);
|
|
76252
76307
|
}
|
|
76253
76308
|
show(docs) {
|
|
76309
|
+
this.clearFocusTimer();
|
|
76310
|
+
if (this.destroyed || this.editor.destroyed) {
|
|
76311
|
+
return;
|
|
76312
|
+
}
|
|
76254
76313
|
this.docs = docs;
|
|
76255
76314
|
const editor = this.editor;
|
|
76256
76315
|
const range = editor.selection.range;
|
|
@@ -76309,13 +76368,39 @@ ${codeText}
|
|
|
76309
76368
|
return doc2;
|
|
76310
76369
|
}
|
|
76311
76370
|
hide() {
|
|
76371
|
+
this.clearFocusTimer();
|
|
76312
76372
|
this.toolbar.close("selectionChange");
|
|
76313
76373
|
}
|
|
76314
76374
|
clearCheckedState() {
|
|
76315
76375
|
this.checkedId = void 0;
|
|
76316
76376
|
}
|
|
76317
76377
|
destroy() {
|
|
76378
|
+
var _a;
|
|
76379
|
+
this.destroyed = true;
|
|
76380
|
+
this.clearFocusTimer();
|
|
76318
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);
|
|
76319
76404
|
}
|
|
76320
76405
|
getCommandItems(docs) {
|
|
76321
76406
|
const getKeepFormatCommand = (format2) => {
|
|
@@ -97387,7 +97472,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
97387
97472
|
}
|
|
97388
97473
|
}
|
|
97389
97474
|
});
|
|
97390
|
-
editor.version = "3.1.
|
|
97475
|
+
editor.version = "3.1.7-beta.ONES22303263.1";
|
|
97391
97476
|
return editor;
|
|
97392
97477
|
}
|
|
97393
97478
|
function isDoc(doc2) {
|
|
@@ -97528,7 +97613,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
97528
97613
|
OnesEditorDropTarget.register(editor);
|
|
97529
97614
|
OnesEditorTocProvider.register(editor);
|
|
97530
97615
|
OnesEditorExclusiveBlock.register(editor);
|
|
97531
|
-
editor.version = "3.1.
|
|
97616
|
+
editor.version = "3.1.7-beta.ONES22303263.1";
|
|
97532
97617
|
return editor;
|
|
97533
97618
|
} catch (error2) {
|
|
97534
97619
|
if (editorForCleanup) {
|