| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- import { FUniver as k, ICommandService as l, IUniverInstanceService as w, CanceledError as f, RichTextValue as p, DOCS_ZEN_EDITOR_UNIT_ID_KEY as g } from "@univerjs/core";
- import { RichTextEditingMutation as x } from "@univerjs/docs";
- import { IEditorBridgeService as m } from "@univerjs/sheets-ui";
- import { OpenZenEditorCommand as u, CancelZenEditCommand as C, ConfirmZenEditCommand as S } from "@univerjs/sheets-zen-editor";
- import { FWorkbook as Z } from "@univerjs/sheets/facade";
- class T extends k {
- // eslint-disable-next-line max-lines-per-function
- _initSheetZenEditorEvent(t) {
- const E = t.get(l);
- this.disposeWithMe(E.beforeCommandExecuted((e) => {
- if (e.id === u.id || e.id === C.id || e.id === S.id) {
- if (!this._eventListend(this.Event.BeforeSheetEditStart) && !this._eventListend(this.Event.BeforeSheetEditEnd))
- return;
- const r = this.getCommandSheetTarget(e);
- if (!r)
- return;
- const { workbook: s, worksheet: o } = r, h = t.get(m), v = t.get(w), a = e.params, { keycode: d, eventType: n } = a, i = h.getEditLocation();
- if (e.id === u.id) {
- const c = {
- row: i.row,
- column: i.column,
- eventType: n,
- keycode: d,
- workbook: s,
- worksheet: o,
- isZenEditor: !0
- };
- if (this.fireEvent(this.Event.BeforeSheetEditStart, c), c.cancel)
- throw new f();
- } else {
- const c = {
- row: i.row,
- column: i.column,
- eventType: n,
- keycode: d,
- workbook: s,
- worksheet: o,
- isZenEditor: !0,
- value: p.create(v.getUnit(g).getSnapshot()),
- isConfirm: e.id === S.id
- };
- if (this.fireEvent(this.Event.BeforeSheetEditEnd, c), c.cancel)
- throw new f();
- }
- }
- })), this.disposeWithMe(E.onCommandExecuted((e) => {
- if (e.id === u.id || e.id === C.id || e.id === S.id) {
- if (!this._eventListend(this.Event.SheetEditStarted) && !this._eventListend(this.Event.SheetEditEnded))
- return;
- const r = this.getCommandSheetTarget(e);
- if (!r)
- return;
- const { workbook: s, worksheet: o } = r, h = t.get(m), v = e.params, { keycode: a, eventType: d } = v, n = h.getEditLocation();
- if (e.id === u.id) {
- const i = {
- row: n.row,
- column: n.column,
- eventType: d,
- keycode: a,
- workbook: s,
- worksheet: o,
- isZenEditor: !0
- };
- this.fireEvent(this.Event.SheetEditStarted, i);
- } else {
- const i = {
- row: n.row,
- column: n.column,
- eventType: d,
- keycode: a,
- workbook: s,
- worksheet: o,
- isZenEditor: !0,
- isConfirm: e.id === S.id
- };
- this.fireEvent(this.Event.SheetEditEnded, i);
- }
- }
- if (e.id === x.id) {
- if (!this._eventListend(this.Event.SheetEditChanging))
- return;
- const r = this.getCommandSheetTarget(e);
- if (!r)
- return;
- const { workbook: s, worksheet: o } = r, h = t.get(m), v = t.get(w), a = e.params;
- if (!h.isVisible().visible) return;
- const { unitId: d } = a;
- if (d === g) {
- const { row: n, column: i } = h.getEditLocation(), c = {
- workbook: s,
- worksheet: o,
- row: n,
- column: i,
- value: p.create(v.getUnit(g).getSnapshot()),
- isZenEditor: !0
- };
- this.fireEvent(this.Event.SheetEditChanging, c);
- }
- }
- }));
- }
- _initialize(t) {
- this._initSheetZenEditorEvent(t);
- }
- }
- k.extend(T);
- class b extends Z {
- startZenEditingAsync() {
- return this._injector.get(l).executeCommand(u.id);
- }
- endZenEditingAsync(t = !0) {
- const E = this._injector.get(l);
- return t ? E.executeCommand(S.id) : E.executeCommand(C.id);
- }
- }
- Z.extend(b);
|