| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021 |
- import { FUniver as ue, ICommandService as I, IUniverInstanceService as L, CanceledError as G, RichTextValue as q, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as A, LifecycleService as Q, DisposableCollection as W, LifecycleStages as ee, UniverInstanceType as fe, ILogService as D, toDisposable as C, awaitTime as Ee, InterceptorEffectEnum as we, FEventName as ve, generateRandomId as _e } from "@univerjs/core";
- import { RichTextEditingMutation as ke } from "@univerjs/docs";
- import { IRenderManagerService as m, DeviceInputEventType as te, SHEET_VIEWPORT_KEY as Ie, sheetContentViewportKeys as Pe } from "@univerjs/engine-render";
- import { SheetsSelectionsService as Me, COMMAND_LISTENER_SKELETON_CHANGE as Re, getSkeletonChangedEffectedRange as ye, SheetInterceptorService as Ue, INTERCEPTOR_POINT as He, InterceptCellContentPriority as xe } from "@univerjs/sheets";
- import { SetCellEditVisibleOperation as P, IEditorBridgeService as $, SetZoomRatioCommand as re, HoverManagerService as _, DragManagerService as U, SheetScrollManagerService as T, SheetPasteShortKeyCommand as ne, ISheetClipboardService as Se, SHEET_VIEW_KEY as R, ISheetSelectionRenderService as H, SheetSkeletonManagerService as x, ChangeZoomRatioCommand as De, SheetsScrollRenderController as Te, SetWorksheetColAutoWidthCommand as Be, SheetCanvasPopManagerService as ie, CellAlertManagerService as Le, IMarkSelectionService as Ae } from "@univerjs/sheets-ui";
- import { FSheetHooks as j, FWorkbook as Ce, FWorksheet as be, FPermission as pe, FRange as me } from "@univerjs/sheets/facade";
- import { KeyCode as B, CutCommand as oe, CopyCommand as se, PasteCommand as ae, IClipboardInterfaceService as $e, PLAIN_TEXT_CLIPBOARD_MIME_TYPE as ce, HTML_CLIPBOARD_MIME_TYPE as de, supportClipboardAPI as he, ISidebarService as We, IDialogService as je, ComponentManager as le } from "@univerjs/ui";
- import { filter as v, combineLatest as Oe } from "rxjs";
- class Fe extends ue {
- // eslint-disable-next-line max-lines-per-function
- _initSheetUIEvent(e) {
- const r = e.get(I);
- this.disposeWithMe(r.beforeCommandExecuted((t) => {
- if (t.id === P.id) {
- if (!this._eventListend(this.Event.BeforeSheetEditStart) && !this._eventListend(this.Event.BeforeSheetEditEnd))
- return;
- const i = this.getCommandSheetTarget(t);
- if (!i)
- return;
- const { workbook: o, worksheet: s } = i, c = e.get($), g = e.get(L), b = t.params, { visible: l, keycode: h, eventType: S } = b, d = c.getEditLocation();
- if (l) {
- const f = {
- row: d.row,
- column: d.column,
- eventType: S,
- keycode: h,
- workbook: o,
- worksheet: s,
- isZenEditor: !1
- };
- if (this.fireEvent(this.Event.BeforeSheetEditStart, f), f.cancel)
- throw new G();
- } else {
- const f = {
- row: d.row,
- column: d.column,
- eventType: S,
- keycode: h,
- workbook: o,
- worksheet: s,
- isZenEditor: !1,
- value: q.create(g.getUnit(A).getSnapshot()),
- isConfirm: h !== B.ESC
- };
- if (this.fireEvent(this.Event.BeforeSheetEditEnd, f), f.cancel)
- throw new G();
- }
- }
- if (t.id === re.id) {
- if (!this._eventListend(this.Event.BeforeSheetZoomChange))
- return;
- const i = this.getCommandSheetTarget(t);
- if (!i)
- return;
- const { workbook: o, worksheet: s } = i;
- this.fireEvent(this.Event.BeforeSheetZoomChange, {
- zoom: t.params.zoomRatio,
- workbook: o,
- worksheet: s
- });
- }
- })), this.disposeWithMe(r.onCommandExecuted((t) => {
- if (t.id === P.id) {
- if (!this._eventListend(this.Event.SheetEditStarted) && !this._eventListend(this.Event.SheetEditEnded))
- return;
- const i = this.getCommandSheetTarget(t);
- if (!i)
- return;
- const { workbook: o, worksheet: s } = i, c = e.get($), g = t.params, { visible: b, keycode: l, eventType: h } = g, S = c.getEditLocation();
- if (b) {
- const d = {
- row: S.row,
- column: S.column,
- eventType: h,
- keycode: l,
- workbook: o,
- worksheet: s,
- isZenEditor: !1
- };
- this.fireEvent(this.Event.SheetEditStarted, d);
- } else {
- const d = {
- row: S.row,
- column: S.column,
- eventType: h,
- keycode: l,
- workbook: o,
- worksheet: s,
- isZenEditor: !1,
- isConfirm: l !== B.ESC
- };
- this.fireEvent(this.Event.SheetEditEnded, d);
- }
- }
- if (t.id === ke.id) {
- if (!this._eventListend(this.Event.SheetEditChanging))
- return;
- const i = this.getCommandSheetTarget(t);
- if (!i)
- return;
- const { workbook: o, worksheet: s } = i, c = e.get($), g = e.get(L), b = t.params;
- if (!c.isVisible().visible) return;
- const { unitId: l } = b;
- if (l === A) {
- const { row: h, column: S } = c.getEditLocation(), d = {
- workbook: o,
- worksheet: s,
- row: h,
- column: S,
- value: q.create(g.getUnit(A).getSnapshot()),
- isZenEditor: !1
- };
- this.fireEvent(this.Event.SheetEditChanging, d);
- }
- }
- if (t.id === re.id) {
- if (!this._eventListend(this.Event.SheetZoomChanged))
- return;
- const i = this.getCommandSheetTarget(t);
- if (!i)
- return;
- const { workbook: o, worksheet: s } = i;
- this.fireEvent(this.Event.SheetZoomChanged, {
- zoom: s.getZoom(),
- workbook: o,
- worksheet: s
- });
- }
- })), this._initObserverListener(e);
- }
- // eslint-disable-next-line max-lines-per-function
- _initObserverListener(e) {
- const t = e.get(L).getFocusedUnit(), i = t == null ? void 0 : t.getUnitId(), o = e.get(m);
- if (i) {
- const l = e.get(Q), h = new W();
- this.disposeWithMe(l.lifecycle$.subscribe((S) => {
- var k, M, u, p, E, O, F, N, V, Z, K, z, Y, X, J;
- if (S < ee.Rendered) return;
- h.dispose();
- const d = e.get(_), f = e.get(U);
- d && (h.add(
- (k = d.currentClickedCell$) == null ? void 0 : k.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.CellClicked)) return;
- const a = this.getSheetTarget(n.location.unitId, n.location.subUnitId);
- a && this.fireEvent(this.Event.CellClicked, {
- ...a,
- ...n,
- row: n.location.row,
- column: n.location.col
- });
- })
- ), h.add(
- (M = d.currentRichText$) == null ? void 0 : M.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.CellHover)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.CellHover, {
- ...a,
- ...n,
- row: n.row,
- column: n.col
- });
- })
- ), h.add(
- (u = d.currentPointerDownCell$) == null ? void 0 : u.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.CellPointerDown)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.CellPointerDown, {
- ...a,
- ...n,
- row: n.row,
- column: n.col
- });
- })
- ), h.add(
- (p = d.currentPointerUpCell$) == null ? void 0 : p.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.CellPointerUp)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.CellPointerUp, {
- ...a,
- ...n,
- row: n.row,
- column: n.col
- });
- })
- ), h.add(
- (E = d.currentCellPosWithEvent$) == null ? void 0 : E.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.CellPointerMove)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.CellPointerMove, {
- ...a,
- ...n,
- row: n.row,
- column: n.col
- });
- })
- ), h.add(
- (O = f.currentCell$) == null ? void 0 : O.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.DragOver)) return;
- const a = this.getSheetTarget(n.location.unitId, n.location.subUnitId);
- a && this.fireEvent(this.Event.DragOver, {
- ...a,
- ...n,
- row: n.location.row,
- column: n.location.col
- });
- })
- ), h.add(
- (F = f.endCell$) == null ? void 0 : F.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.Drop)) return;
- const a = this.getSheetTarget(n.location.unitId, n.location.subUnitId);
- a && this.fireEvent(this.Event.Drop, {
- ...a,
- ...n,
- row: n.location.row,
- column: n.location.col
- });
- })
- ), h.add(
- (N = d.currentRowHeaderClick$) == null ? void 0 : N.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.RowHeaderClick)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.RowHeaderClick, {
- ...a,
- row: n.index
- });
- })
- ), h.add(
- (V = d.currentRowHeaderPointerDown$) == null ? void 0 : V.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.RowHeaderPointerDown)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.RowHeaderPointerDown, {
- ...a,
- row: n.index
- });
- })
- ), h.add(
- (Z = d.currentRowHeaderPointerUp$) == null ? void 0 : Z.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.RowHeaderPointerUp)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.RowHeaderPointerUp, {
- ...a,
- row: n.index
- });
- })
- ), h.add(
- (K = d.currentHoveredRowHeader$) == null ? void 0 : K.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.RowHeaderHover)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.RowHeaderHover, {
- ...a,
- row: n.index
- });
- })
- ), h.add(
- (z = d.currentColHeaderClick$) == null ? void 0 : z.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.ColumnHeaderClick)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.ColumnHeaderClick, {
- ...a,
- column: n.index
- });
- })
- ), h.add(
- (Y = d.currentColHeaderPointerDown$) == null ? void 0 : Y.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.ColumnHeaderPointerDown)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.ColumnHeaderPointerDown, {
- ...a,
- column: n.index
- });
- })
- ), h.add(
- (X = d.currentColHeaderPointerUp$) == null ? void 0 : X.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.ColumnHeaderPointerUp)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.ColumnHeaderPointerUp, {
- ...a,
- column: n.index
- });
- })
- ), h.add(
- (J = d.currentHoveredColHeader$) == null ? void 0 : J.pipe(v((n) => !!n)).subscribe((n) => {
- if (!this._eventListend(this.Event.ColumnHeaderHover)) return;
- const a = this.getSheetTarget(n.unitId, n.subUnitId);
- a && this.fireEvent(this.Event.ColumnHeaderHover, {
- ...a,
- column: n.index
- });
- })
- ));
- })), this.disposeWithMe(h);
- }
- const s = /* @__PURE__ */ new Map();
- let c;
- const g = e.get(Q), b = Oe([
- o.created$,
- g.lifecycle$
- ]);
- this.disposeWithMe(b.subscribe(([l, h]) => {
- var M;
- if (l.type === fe.UNIVER_SHEET && (c = l), h <= ee.Rendered) return;
- const S = new W();
- if (!c) return;
- const d = this.getWorkbook(c.unitId);
- if (!d) return;
- s.get(c.unitId) && ((M = s.get(c.unitId)) == null || M.dispose()), s.set(c.unitId, S);
- const f = c.with(T);
- S.add(f.validViewportScrollInfo$.subscribe((u) => {
- u && this._eventListend(this.Event.Scroll) && this.fireEvent(this.Event.Scroll, {
- workbook: d,
- worksheet: d.getActiveSheet(),
- ...u
- });
- }));
- const k = c.with(Me);
- S.add(k.selectionMoveStart$.subscribe((u) => {
- var p;
- this._eventListend(this.Event.SelectionMoveStart) && this.fireEvent(this.Event.SelectionMoveStart, {
- workbook: d,
- worksheet: d.getActiveSheet(),
- selections: (p = u == null ? void 0 : u.map((E) => E.range)) != null ? p : []
- });
- })), S.add(k.selectionMoving$.subscribe((u) => {
- var p;
- this._eventListend(this.Event.SelectionMoving) && this.fireEvent(this.Event.SelectionMoving, {
- workbook: d,
- worksheet: d.getActiveSheet(),
- selections: (p = u == null ? void 0 : u.map((E) => E.range)) != null ? p : []
- });
- })), S.add(k.selectionMoveEnd$.subscribe((u) => {
- var p;
- this._eventListend(this.Event.SelectionMoveEnd) && this.fireEvent(this.Event.SelectionMoveEnd, {
- workbook: d,
- worksheet: d.getActiveSheet(),
- selections: (p = u == null ? void 0 : u.map((E) => E.range)) != null ? p : []
- });
- })), S.add(k.selectionChanged$.subscribe((u) => {
- var p;
- this._eventListend(this.Event.SelectionChanged) && this.fireEvent(this.Event.SelectionChanged, {
- workbook: d,
- worksheet: d.getActiveSheet(),
- selections: (p = u == null ? void 0 : u.map((E) => E.range)) != null ? p : []
- });
- })), c = null, this.disposeWithMe(S);
- })), this.disposeWithMe(o.disposed$.subscribe((l) => {
- var h;
- (h = s.get(l)) == null || h.dispose(), s.delete(l);
- })), this.disposeWithMe(() => {
- s.forEach((l) => {
- l.dispose();
- });
- });
- }
- _initialize(e) {
- this._initSheetUIEvent(e);
- const r = e.get(I);
- this.disposeWithMe(r.beforeCommandExecuted((t) => {
- switch (t.id) {
- case se.id:
- case oe.id:
- this._beforeClipboardChange();
- break;
- case ne.id:
- this._beforeClipboardPaste(t.params);
- break;
- }
- })), this.disposeWithMe(r.onCommandExecuted((t) => {
- if (Re.indexOf(t.id) > -1) {
- if (!this._eventListend(this.Event.SheetSkeletonChanged)) return;
- const i = this.getActiveSheet();
- if (!i) return;
- const o = ye(t).map((s) => {
- var c, g;
- return (g = (c = this.getWorkbook(s.unitId)) == null ? void 0 : c.getSheetBySheetId(s.subUnitId)) == null ? void 0 : g.getRange(s.range);
- }).filter(Boolean);
- if (!o.length) return;
- this.fireEvent(this.Event.SheetSkeletonChanged, {
- workbook: i.workbook,
- worksheet: i.worksheet,
- payload: t,
- skeleton: i.worksheet.getSkeleton(),
- effectedRanges: o
- });
- return;
- }
- switch (t.id) {
- case se.id:
- case oe.id:
- this._clipboardChanged();
- break;
- case ne.id:
- this._clipboardPaste();
- break;
- case ae.id:
- this._clipboardPasteAsync();
- break;
- }
- })), this.disposeWithMe(r.beforeCommandExecuted(async (t) => {
- switch (t.id) {
- case ae.id:
- await this._beforeClipboardPasteAsync();
- break;
- }
- }));
- }
- _generateClipboardCopyParam() {
- const e = this.getActiveWorkbook(), r = e == null ? void 0 : e.getActiveSheet(), t = e == null ? void 0 : e.getActiveRange();
- if (!e || !r || !t)
- return;
- const o = this._injector.get(Se).generateCopyContent(e.getId(), r.getSheetId(), t.getRange());
- if (!o)
- return;
- const { html: s, plain: c } = o;
- return {
- workbook: e,
- worksheet: r,
- text: c,
- html: s,
- fromSheet: r,
- fromRange: t
- };
- }
- _beforeClipboardChange() {
- if (!this.hasEventCallback(this.Event.BeforeClipboardChange))
- return;
- const e = this._generateClipboardCopyParam();
- if (e && (this.fireEvent(this.Event.BeforeClipboardChange, e), e.cancel))
- throw new Error("Before clipboard change is canceled");
- }
- _clipboardChanged() {
- if (!this.hasEventCallback(this.Event.ClipboardChanged))
- return;
- const e = this._generateClipboardCopyParam();
- if (e && (this.fireEvent(this.Event.ClipboardChanged, e), e.cancel))
- throw new Error("Clipboard changed is canceled");
- }
- _generateClipboardPasteParam(e) {
- if (!e)
- return;
- const { htmlContent: r, textContent: t } = e, i = this.getActiveWorkbook(), o = i == null ? void 0 : i.getActiveSheet();
- return !i || !o ? void 0 : {
- workbook: i,
- worksheet: o,
- text: t,
- html: r
- };
- }
- async _generateClipboardPasteParamAsync() {
- const e = this.getActiveWorkbook(), r = e == null ? void 0 : e.getActiveSheet();
- if (!e || !r)
- return;
- const o = (await this._injector.get($e).read())[0];
- let s;
- if (o) {
- const c = o.types, g = c.indexOf(ce) !== -1 ? await o.getType(ce).then((l) => l && l.text()) : "", b = c.indexOf(de) !== -1 ? await o.getType(de).then((l) => l && l.text()) : "";
- s = {
- workbook: e,
- worksheet: r,
- text: g,
- html: b
- };
- }
- return s;
- }
- _beforeClipboardPaste(e) {
- if (!this.hasEventCallback(this.Event.BeforeClipboardPaste))
- return;
- const r = this._generateClipboardPasteParam(e);
- if (r && (this.fireEvent(this.Event.BeforeClipboardPaste, r), r.cancel))
- throw new Error("Before clipboard paste is canceled");
- }
- _clipboardPaste(e) {
- if (!this.hasEventCallback(this.Event.BeforeClipboardPaste))
- return;
- const r = this._generateClipboardPasteParam(e);
- if (r && (this.fireEvent(this.Event.BeforeClipboardPaste, r), r.cancel))
- throw new Error("Clipboard pasted is canceled");
- }
- async _beforeClipboardPasteAsync() {
- if (!this.hasEventCallback(this.Event.BeforeClipboardPaste))
- return;
- if (!he()) {
- this._injector.get(D).warn("[Facade]: The navigator object only supports the browser environment");
- return;
- }
- const e = await this._generateClipboardPasteParamAsync();
- if (e && (this.fireEvent(this.Event.BeforeClipboardPaste, e), e.cancel))
- throw new Error("Before clipboard paste is canceled");
- }
- async _clipboardPasteAsync() {
- if (!this.hasEventCallback(this.Event.ClipboardPasted))
- return;
- if (!he()) {
- this._injector.get(D).warn("[Facade]: The navigator object only supports the browser environment");
- return;
- }
- const e = await this._generateClipboardPasteParamAsync();
- if (e && (this.fireEvent(this.Event.ClipboardPasted, e), e.cancel))
- throw new Error("Clipboard pasted is canceled");
- }
- customizeColumnHeader(e) {
- const r = this.getActiveWorkbook();
- if (!r) {
- console.error("WorkBook not exist");
- return;
- }
- const t = r == null ? void 0 : r.getId();
- this._getSheetRenderComponent(t, R.COLUMN).setCustomHeader(e);
- }
- customizeRowHeader(e) {
- const r = this.getActiveWorkbook();
- if (!r) {
- console.error("WorkBook not exist");
- return;
- }
- const t = r == null ? void 0 : r.getId();
- this._getSheetRenderComponent(t, R.ROW).setCustomHeader(e);
- }
- registerSheetRowHeaderExtension(e, ...r) {
- const t = this._getSheetRenderComponent(e, R.ROW), i = t.register(...r);
- return C(() => {
- i.dispose(), t.makeDirty(!0);
- });
- }
- registerSheetColumnHeaderExtension(e, ...r) {
- const t = this._getSheetRenderComponent(e, R.COLUMN), i = t.register(...r);
- return C(() => {
- i.dispose(), t.makeDirty(!0);
- });
- }
- registerSheetMainExtension(e, ...r) {
- const t = this._getSheetRenderComponent(e, R.MAIN), i = t.register(...r);
- return C(() => {
- i.dispose(), t.makeDirty(!0);
- });
- }
- /**
- * Get sheet render component from render by unitId and view key.
- * @private
- * @param {string} unitId The unit id of the spreadsheet.
- * @param {SHEET_VIEW_KEY} viewKey The view key of the spreadsheet.
- * @returns {Nullable<RenderComponentType>} The render component.
- */
- _getSheetRenderComponent(e, r) {
- const i = this._injector.get(m).getRenderById(e);
- if (!i)
- throw new Error(`Render Unit with unitId ${e} not found`);
- const { components: o } = i, s = o.get(r);
- if (!s)
- throw new Error("Render component not found");
- return s;
- }
- /**
- * Get sheet hooks.
- * @returns {FSheetHooks} FSheetHooks instance
- */
- getSheetHooks() {
- return this._injector.createInstance(j);
- }
- }
- ue.extend(Fe);
- class Ne extends Ce {
- openSiderbar(e) {
- return this._logDeprecation("openSiderbar"), this._injector.get(We).open(e);
- }
- openDialog(e) {
- this._logDeprecation("openDialog");
- const t = this._injector.get(je).open({
- ...e,
- onClose: () => {
- t.dispose();
- }
- });
- return t;
- }
- _logDeprecation(e) {
- this._injector.get(D).warn("[FWorkbook]", `${e} is deprecated. Please use the function of the same name on "FUniver".`);
- }
- generateCellParams(e) {
- const r = this.getActiveSheet();
- return {
- row: e.row,
- column: e.col,
- workbook: this,
- worksheet: r
- };
- }
- onCellClick(e) {
- const r = this._injector.get(_);
- return C(
- r.currentClickedCell$.pipe(v((t) => !!t)).subscribe((t) => {
- e(t);
- })
- );
- }
- onCellHover(e) {
- const r = this._injector.get(_);
- return C(
- r.currentRichText$.pipe(v((t) => !!t)).subscribe(e)
- );
- }
- onCellPointerDown(e) {
- const r = this._injector.get(_);
- return C(
- r.currentPointerDownCell$.subscribe(e)
- );
- }
- onCellPointerUp(e) {
- const r = this._injector.get(_);
- return C(
- r.currentPointerUpCell$.subscribe(e)
- );
- }
- onCellPointerMove(e) {
- const r = this._injector.get(_);
- return C(
- r.currentCellPosWithEvent$.pipe(v((t) => !!t)).subscribe((t) => {
- e(t, t.event);
- })
- );
- }
- onDragOver(e) {
- const r = this._injector.get(U);
- return C(
- r.currentCell$.pipe(v((t) => !!t)).subscribe((t) => {
- e(t);
- })
- );
- }
- onDrop(e) {
- const r = this._injector.get(U);
- return C(
- r.endCell$.pipe(v((t) => !!t)).subscribe((t) => {
- e(t);
- })
- );
- }
- startEditing() {
- return this._injector.get(I).syncExecuteCommand(P.id, {
- eventType: te.Dblclick,
- unitId: this._workbook.getUnitId(),
- visible: !0
- });
- }
- async endEditing(e) {
- return this._injector.get(I).syncExecuteCommand(P.id, {
- eventType: te.Keyboard,
- keycode: e ? B.ENTER : B.ESC,
- visible: !1,
- unitId: this._workbook.getUnitId()
- }), await Ee(0), !0;
- }
- endEditingAsync(e = !0) {
- return this.endEditing(e);
- }
- /**
- * Get scroll state of specified sheet.
- * @param {string} sheetId - sheet id
- * @returns {IScrollState} scroll state
- * @example
- * ``` ts
- * univerAPI.getActiveWorkbook().getScrollStateBySheetId($sheetId)
- * ```
- */
- getScrollStateBySheetId(e) {
- const r = this._workbook.getUnitId(), i = this._injector.get(m).getRenderById(r);
- return i ? i.with(T).getScrollStateByParam({ unitId: r, sheetId: e }) : null;
- }
- disableSelection() {
- const e = this._workbook.getUnitId(), t = this._injector.get(m).getRenderById(e);
- return t && t.with(H).disableSelection(), this;
- }
- enableSelection() {
- const e = this._workbook.getUnitId(), t = this._injector.get(m).getRenderById(e);
- return t && t.with(H).enableSelection(), this;
- }
- transparentSelection() {
- const e = this._workbook.getUnitId(), t = this._injector.get(m).getRenderById(e);
- return t && t.with(H).transparentSelection(), this;
- }
- showSelection() {
- const e = this._workbook.getUnitId(), t = this._injector.get(m).getRenderById(e);
- return t && t.with(H).showSelection(), this;
- }
- }
- Ce.extend(Ne);
- class Ve extends be {
- refreshCanvas() {
- const e = this._injector.get(m), r = this._fWorkbook.id, t = e.getRenderById(r);
- if (!t)
- throw new Error(`Render Unit with unitId ${r} not found`);
- t.with(x).reCalculate();
- const i = t.mainComponent;
- if (!i)
- throw new Error("Main component not found");
- return i.makeDirty(), this;
- }
- zoom(e) {
- return this._injector.get(I).syncExecuteCommand(De.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- zoomRatio: e
- }), this;
- }
- getZoom() {
- return this._worksheet.getZoomRatio();
- }
- getVisibleRange() {
- const e = this._workbook.getUnitId(), t = this._injector.get(m).getRenderById(e);
- let i = {
- startColumn: 0,
- startRow: 0,
- endColumn: 0,
- endRow: 0
- };
- if (!t) return i;
- const s = t.with(x).getCurrentSkeleton();
- if (!s) return i;
- const c = s == null ? void 0 : s.getVisibleRanges();
- if (!c) return i;
- i = s.getVisibleRangeByViewport(Ie.VIEW_MAIN);
- for (const [g, b] of c)
- Pe.indexOf(g) !== -1 && (i.startColumn = Math.min(i.startColumn, b.startColumn), i.startRow = Math.min(i.startRow, b.startRow), i.endColumn = Math.max(i.endColumn, b.endColumn), i.endRow = Math.max(i.endRow, b.endRow));
- return i;
- }
- scrollToCell(e, r) {
- const t = this._workbook.getUnitId(), o = this._injector.get(m).getRenderById(t);
- return o && (o == null ? void 0 : o.with(Te)).scrollToCell(e, r), this;
- }
- getScrollState() {
- const e = {
- offsetX: 0,
- offsetY: 0,
- sheetViewStartColumn: 0,
- sheetViewStartRow: 0
- }, r = this._workbook.getUnitId(), t = this._worksheet.getSheetId(), o = this._injector.get(m).getRenderById(r);
- return o && o.with(T).getScrollStateByParam({ unitId: r, sheetId: t }) || e;
- }
- onScroll(e) {
- var o;
- const r = this._workbook.getUnitId(), i = (o = this._injector.get(m).getRenderById(r)) == null ? void 0 : o.with(T);
- if (i) {
- const s = i.validViewportScrollInfo$.subscribe((c) => {
- e(c);
- });
- return C(s);
- }
- return C(() => {
- });
- }
- getSkeleton() {
- var r, t;
- const e = (r = this._injector.get(m).getRenderById(this._workbook.getUnitId())) == null ? void 0 : r.with(x);
- return (t = e == null ? void 0 : e.getWorksheetSkeleton(this._worksheet.getSheetId())) == null ? void 0 : t.skeleton;
- }
- setColumnAutoWidth(e, r) {
- const t = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), o = [
- {
- startColumn: e,
- endColumn: e + r - 1,
- startRow: 0,
- endRow: this._worksheet.getRowCount() - 1
- }
- ];
- return this._commandService.syncExecuteCommand(Be.id, {
- unitId: t,
- subUnitId: i,
- ranges: o
- }), this;
- }
- }
- be.extend(Ve);
- class Ze extends pe {
- setPermissionDialogVisible(e) {
- this._permissionService.setShowComponents(e);
- }
- }
- pe.extend(Ze);
- class Ke extends j {
- onCellPointerMove(e) {
- return C(this._injector.get(_).currentPosition$.subscribe(e));
- }
- onCellPointerOver(e) {
- return C(this._injector.get(_).currentCell$.subscribe(e));
- }
- onCellDragOver(e) {
- return C(this._injector.get(U).currentCell$.subscribe(e));
- }
- onCellDrop(e) {
- return C(this._injector.get(U).endCell$.subscribe(e));
- }
- onCellRender(e, r = we.Style, t = xe.DATA_VALIDATION) {
- return this._injector.get(Ue).intercept(He.CELL_CONTENT, {
- effect: r,
- handler: (i, o, s) => s({
- ...i,
- customRender: [
- ...(i == null ? void 0 : i.customRender) || [],
- ...e || []
- ]
- }),
- priority: t
- });
- }
- onBeforeCellEdit(e) {
- return this._injector.get(I).beforeCommandExecuted((r) => {
- const t = r.params;
- r.id === P.id && t.visible && e(t);
- });
- }
- onAfterCellEdit(e) {
- return this._injector.get(I).onCommandExecuted((r) => {
- const t = r.params;
- r.id === P.id && !t.visible && e(t);
- });
- }
- }
- j.extend(Ke);
- const y = {
- CellClicked: "CellClicked",
- CellPointerDown: "CellPointerDown",
- CellPointerUp: "CellPointerUp",
- CellPointerMove: "CellPointerMove",
- CellHover: "CellHover",
- DragOver: "DragOver",
- Drop: "Drop",
- Scroll: "Scroll",
- SelectionMoveStart: "SelectionMoveStart",
- SelectionMoving: "SelectionMoving",
- SelectionMoveEnd: "SelectionMoveEnd",
- SelectionChanged: "SelectionChanged"
- };
- class ze extends ve {
- get BeforeClipboardChange() {
- return "BeforeClipboardChange";
- }
- get ClipboardChanged() {
- return "ClipboardChanged";
- }
- get BeforeClipboardPaste() {
- return "BeforeClipboardPaste";
- }
- get ClipboardPasted() {
- return "ClipboardPasted";
- }
- get BeforeSheetEditStart() {
- return "BeforeSheetEditStart";
- }
- get SheetEditStarted() {
- return "SheetEditStarted";
- }
- get SheetEditChanging() {
- return "SheetEditChanging";
- }
- get BeforeSheetEditEnd() {
- return "BeforeSheetEditEnd";
- }
- get SheetEditEnded() {
- return "SheetEditEnded";
- }
- get CellClicked() {
- return y.CellClicked;
- }
- get CellHover() {
- return y.CellHover;
- }
- get CellPointerDown() {
- return y.CellPointerDown;
- }
- get CellPointerUp() {
- return y.CellPointerUp;
- }
- get CellPointerMove() {
- return y.CellPointerMove;
- }
- get DragOver() {
- return "DragOver";
- }
- get Drop() {
- return "Drop";
- }
- get Scroll() {
- return "Scroll";
- }
- get SelectionMoveStart() {
- return "SelectionMoveStart";
- }
- get SelectionChanged() {
- return "SelectionChanged";
- }
- get SelectionMoving() {
- return "SelectionMoving";
- }
- get SelectionMoveEnd() {
- return "SelectionMoveEnd";
- }
- get RowHeaderClick() {
- return "RowHeaderClick";
- }
- get RowHeaderPointerDown() {
- return "RowHeaderPointerDown";
- }
- get RowHeaderPointerUp() {
- return "RowHeaderPointerUp";
- }
- get RowHeaderHover() {
- return "RowHeaderHover";
- }
- get ColumnHeaderClick() {
- return "ColumnHeaderClick";
- }
- get ColumnHeaderPointerDown() {
- return "ColumnHeaderPointerDown";
- }
- get ColumnHeaderPointerUp() {
- return "ColumnHeaderPointerUp";
- }
- get ColumnHeaderHover() {
- return "ColumnHeaderHover";
- }
- get SheetSkeletonChanged() {
- return "SheetSkeletonChanged";
- }
- }
- ve.extend(ze);
- class Ye extends me {
- getCell() {
- var c;
- const e = this._injector.get(m), r = this._injector.get(D), t = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), o = e.getRenderById(t), s = (c = o == null ? void 0 : o.with(x).getWorksheetSkeleton(i)) == null ? void 0 : c.skeleton;
- if (!s)
- throw r.error("[Facade]: `FRange.getCell` can only be called in current worksheet"), new Error("`FRange.getCell` can only be called in current worksheet");
- return s.getCellWithCoordByIndex(this._range.startRow, this._range.startColumn);
- }
- getCellRect() {
- const { startX: e, startY: r, endX: t, endY: i } = this.getCell(), o = { x: e, y: r, width: t - e, height: i - r, top: r, left: e, bottom: i, right: t };
- return { ...o, toJSON: () => JSON.stringify(o) };
- }
- generateHTML() {
- var r;
- const e = this._injector.get(Se).generateCopyContent(
- this._workbook.getUnitId(),
- this._worksheet.getSheetId(),
- this._range
- );
- return (r = e == null ? void 0 : e.html) != null ? r : "";
- }
- attachPopup(e) {
- var s, c, g;
- e.direction = (s = e.direction) != null ? s : "horizontal", e.extraProps = (c = e.extraProps) != null ? c : {}, e.offset = (g = e.offset) != null ? g : [0, 0];
- const { key: r, disposableCollection: t } = ge(e, this._injector.get(le)), o = this._injector.get(ie).attachPopupToCell(
- this._range.startRow,
- this._range.startColumn,
- { ...e, componentKey: r },
- this.getUnitId(),
- this._worksheet.getSheetId()
- );
- return o ? (t.add(o), t) : (t.dispose(), null);
- }
- attachAlertPopup(e) {
- const r = this._injector.get(Le), t = {
- workbook: this._workbook,
- worksheet: this._worksheet,
- row: this._range.startRow,
- col: this._range.startColumn,
- unitId: this.getUnitId(),
- subUnitId: this._worksheet.getSheetId()
- };
- return r.showAlert({
- ...e,
- location: t
- }), {
- dispose: () => {
- r.removeAlert(e.key);
- }
- };
- }
- /**
- * attachDOMPopup
- * @param popup
- * @returns {IDisposable} disposable
- let sheet = univerAPI.getActiveWorkbook().getActiveSheet();
- let range = sheet.getRange(2, 2, 3, 3);
- univerAPI.getActiveWorkbook().setActiveRange(range);
- let disposable = range.attachDOMPopup({
- componentKey: 'univer.sheet.single-dom-popup',
- extraProps: { alert: { type: 0, title: 'This is an Info', message: 'This is an info message' } },
- });
- */
- attachRangePopup(e) {
- var s, c, g;
- e.direction = (s = e.direction) != null ? s : "horizontal", e.extraProps = (c = e.extraProps) != null ? c : {}, e.offset = (g = e.offset) != null ? g : [0, 0];
- const { key: r, disposableCollection: t } = ge(e, this._injector.get(le)), o = this._injector.get(ie).attachRangePopup(
- this._range,
- { ...e, componentKey: r },
- this.getUnitId(),
- this._worksheet.getSheetId()
- );
- return o ? (t.add(o), t) : (t.dispose(), null);
- }
- highlight(e, r) {
- const t = this._injector.get(Ae), i = t.addShape({ range: this._range, style: e, primary: r });
- if (!i)
- throw new Error("Failed to highlight current range");
- return C(() => {
- t.removeShape(i);
- });
- }
- }
- me.extend(Ye);
- function ge(w, e) {
- const { componentKey: r, isVue3: t } = w;
- let i;
- const o = new W();
- return typeof r == "string" ? i = r : (i = `External_${_e(6)}`, o.add(e.register(i, r, { framework: t ? "vue3" : "react" }))), {
- key: i,
- disposableCollection: o
- };
- }
- export {
- ge as transformComponentKey
- };
|