123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125 |
- import {
- S,
- f,
- j,
- m,
- xe
- } from "./chunk-CLOCSTN3.js";
- import {
- Er,
- Et,
- Li as Li2,
- Ql,
- Sn,
- Wi,
- ai,
- bi as bi2,
- dt,
- me,
- qe,
- tt,
- vi,
- wi,
- ws,
- xc,
- yt
- } from "./chunk-T4NNB5UY.js";
- import {
- F,
- V,
- ea,
- et,
- gh,
- ph
- } from "./chunk-BW43Z7N3.js";
- import "./chunk-QRYBFJ3R.js";
- import "./chunk-MIOQ566M.js";
- import {
- I1,
- Li,
- Pi,
- Xs,
- bi,
- h3,
- mr,
- n1,
- rt,
- vr,
- yi
- } from "./chunk-POAJ2YNP.js";
- import "./chunk-GBYP4PB2.js";
- import {
- M
- } from "./chunk-PZD7N4BC.js";
- import {
- Ef,
- Yx,
- i2,
- vf
- } from "./chunk-2MK3Q52E.js";
- import "./chunk-BSDDCPAW.js";
- import "./chunk-QG2HZMYH.js";
- import {
- Fe,
- Ht,
- Mi,
- Mt,
- Pt,
- UR,
- Ve,
- Vn,
- Ze,
- Zt,
- _n,
- combineLatest,
- filter,
- hi,
- pi,
- qt,
- su,
- xf
- } from "./chunk-23V3HWTR.js";
- import "./chunk-GNR2UJZM.js";
- import "./chunk-2LSFTFF7.js";
- // node_modules/.pnpm/@univerjs+sheets-ui@0.5.5_@grpc+grpc-js@1.13.4_react-dom@18.3.1_react@18.3.1_rxjs@7.8.1_typescript@5.4.5/node_modules/@univerjs/sheets-ui/lib/es/facade.js
- var Fe2 = class extends pi {
- // eslint-disable-next-line max-lines-per-function
- _initSheetUIEvent(e) {
- const r = e.get(Pt);
- this.disposeWithMe(r.beforeCommandExecuted((t) => {
- if (t.id === Et.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(tt), g = e.get(_n), b = t.params, { visible: l, keycode: h, eventType: S2 } = b, d = c.getEditLocation();
- if (l) {
- const f2 = {
- row: d.row,
- column: d.column,
- eventType: S2,
- keycode: h,
- workbook: o,
- worksheet: s,
- isZenEditor: false
- };
- if (this.fireEvent(this.Event.BeforeSheetEditStart, f2), f2.cancel)
- throw new xf();
- } else {
- const f2 = {
- row: d.row,
- column: d.column,
- eventType: S2,
- keycode: h,
- workbook: o,
- worksheet: s,
- isZenEditor: false,
- value: Zt.create(g.getUnit(su).getSnapshot()),
- isConfirm: h !== I1.ESC
- };
- if (this.fireEvent(this.Event.BeforeSheetEditEnd, f2), f2.cancel)
- throw new xf();
- }
- }
- if (t.id === Wi.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 === Et.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(tt), g = t.params, { visible: b, keycode: l, eventType: h } = g, S2 = c.getEditLocation();
- if (b) {
- const d = {
- row: S2.row,
- column: S2.column,
- eventType: h,
- keycode: l,
- workbook: o,
- worksheet: s,
- isZenEditor: false
- };
- this.fireEvent(this.Event.SheetEditStarted, d);
- } else {
- const d = {
- row: S2.row,
- column: S2.column,
- eventType: h,
- keycode: l,
- workbook: o,
- worksheet: s,
- isZenEditor: false,
- isConfirm: l !== I1.ESC
- };
- this.fireEvent(this.Event.SheetEditEnded, d);
- }
- }
- if (t.id === M.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(tt), g = e.get(_n), b = t.params;
- if (!c.isVisible().visible)
- return;
- const { unitId: l } = b;
- if (l === su) {
- const { row: h, column: S2 } = c.getEditLocation(), d = {
- workbook: o,
- worksheet: s,
- row: h,
- column: S2,
- value: Zt.create(g.getUnit(su).getSnapshot()),
- isZenEditor: false
- };
- this.fireEvent(this.Event.SheetEditChanging, d);
- }
- }
- if (t.id === Wi.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(_n).getFocusedUnit(), i = t == null ? void 0 : t.getUnitId(), o = e.get(Yx);
- if (i) {
- const l = e.get(Ht), h = new Mi();
- this.disposeWithMe(l.lifecycle$.subscribe((S2) => {
- var k, M2, u, p, E, O, F2, N, V2, Z, K, z, Y, X, J;
- if (S2 < Ve.Rendered)
- return;
- h.dispose();
- const d = e.get(Er), f2 = e.get(wi);
- d && (h.add(
- (k = d.currentClickedCell$) == null ? void 0 : k.pipe(filter((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(
- (M2 = d.currentRichText$) == null ? void 0 : M2.pipe(filter((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(filter((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(filter((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(filter((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 = f2.currentCell$) == null ? void 0 : O.pipe(filter((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(
- (F2 = f2.endCell$) == null ? void 0 : F2.pipe(filter((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(filter((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(
- (V2 = d.currentRowHeaderPointerDown$) == null ? void 0 : V2.pipe(filter((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(filter((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(filter((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(filter((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(filter((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(filter((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(filter((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(Ht), b = combineLatest([
- o.created$,
- g.lifecycle$
- ]);
- this.disposeWithMe(b.subscribe(([l, h]) => {
- var M2;
- if (l.type === Fe.UNIVER_SHEET && (c = l), h <= Ve.Rendered)
- return;
- const S2 = new Mi();
- if (!c)
- return;
- const d = this.getWorkbook(c.unitId);
- if (!d)
- return;
- s.get(c.unitId) && ((M2 = s.get(c.unitId)) == null || M2.dispose()), s.set(c.unitId, S2);
- const f2 = c.with(yt);
- S2.add(f2.validViewportScrollInfo$.subscribe((u) => {
- u && this._eventListend(this.Event.Scroll) && this.fireEvent(this.Event.Scroll, {
- workbook: d,
- worksheet: d.getActiveSheet(),
- ...u
- });
- }));
- const k = c.with(F);
- S2.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 : []
- });
- })), S2.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 : []
- });
- })), S2.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 : []
- });
- })), S2.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(S2);
- })), 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(Pt);
- this.disposeWithMe(r.beforeCommandExecuted((t) => {
- switch (t.id) {
- case bi.id:
- case yi.id:
- this._beforeClipboardChange();
- break;
- case xc.id:
- this._beforeClipboardPaste(t.params);
- break;
- }
- })), this.disposeWithMe(r.onCommandExecuted((t) => {
- if (gh.indexOf(t.id) > -1) {
- if (!this._eventListend(this.Event.SheetSkeletonChanged))
- return;
- const i = this.getActiveSheet();
- if (!i)
- return;
- const o = ph(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 bi.id:
- case yi.id:
- this._clipboardChanged();
- break;
- case xc.id:
- this._clipboardPaste();
- break;
- case Li.id:
- this._clipboardPasteAsync();
- break;
- }
- })), this.disposeWithMe(r.beforeCommandExecuted(async (t) => {
- switch (t.id) {
- case Li.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(Sn).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(Pi).read())[0];
- let s;
- if (o) {
- const c = o.types, g = c.indexOf(vr) !== -1 ? await o.getType(vr).then((l) => l && l.text()) : "", b = c.indexOf(mr) !== -1 ? await o.getType(mr).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 (!Xs()) {
- this._injector.get(Mt).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 (!Xs()) {
- this._injector.get(Mt).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, qe.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, qe.ROW).setCustomHeader(e);
- }
- registerSheetRowHeaderExtension(e, ...r) {
- const t = this._getSheetRenderComponent(e, qe.ROW), i = t.register(...r);
- return Ze(() => {
- i.dispose(), t.makeDirty(true);
- });
- }
- registerSheetColumnHeaderExtension(e, ...r) {
- const t = this._getSheetRenderComponent(e, qe.COLUMN), i = t.register(...r);
- return Ze(() => {
- i.dispose(), t.makeDirty(true);
- });
- }
- registerSheetMainExtension(e, ...r) {
- const t = this._getSheetRenderComponent(e, qe.MAIN), i = t.register(...r);
- return Ze(() => {
- i.dispose(), t.makeDirty(true);
- });
- }
- /**
- * 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(Yx).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(xe);
- }
- };
- pi.extend(Fe2);
- var Ne = class extends f {
- openSiderbar(e) {
- return this._logDeprecation("openSiderbar"), this._injector.get(rt).open(e);
- }
- openDialog(e) {
- this._logDeprecation("openDialog");
- const t = this._injector.get(h3).open({
- ...e,
- onClose: () => {
- t.dispose();
- }
- });
- return t;
- }
- _logDeprecation(e) {
- this._injector.get(Mt).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(Er);
- return Ze(
- r.currentClickedCell$.pipe(filter((t) => !!t)).subscribe((t) => {
- e(t);
- })
- );
- }
- onCellHover(e) {
- const r = this._injector.get(Er);
- return Ze(
- r.currentRichText$.pipe(filter((t) => !!t)).subscribe(e)
- );
- }
- onCellPointerDown(e) {
- const r = this._injector.get(Er);
- return Ze(
- r.currentPointerDownCell$.subscribe(e)
- );
- }
- onCellPointerUp(e) {
- const r = this._injector.get(Er);
- return Ze(
- r.currentPointerUpCell$.subscribe(e)
- );
- }
- onCellPointerMove(e) {
- const r = this._injector.get(Er);
- return Ze(
- r.currentCellPosWithEvent$.pipe(filter((t) => !!t)).subscribe((t) => {
- e(t, t.event);
- })
- );
- }
- onDragOver(e) {
- const r = this._injector.get(wi);
- return Ze(
- r.currentCell$.pipe(filter((t) => !!t)).subscribe((t) => {
- e(t);
- })
- );
- }
- onDrop(e) {
- const r = this._injector.get(wi);
- return Ze(
- r.endCell$.pipe(filter((t) => !!t)).subscribe((t) => {
- e(t);
- })
- );
- }
- startEditing() {
- return this._injector.get(Pt).syncExecuteCommand(Et.id, {
- eventType: vf.Dblclick,
- unitId: this._workbook.getUnitId(),
- visible: true
- });
- }
- async endEditing(e) {
- return this._injector.get(Pt).syncExecuteCommand(Et.id, {
- eventType: vf.Keyboard,
- keycode: e ? I1.ENTER : I1.ESC,
- visible: false,
- unitId: this._workbook.getUnitId()
- }), await UR(0), true;
- }
- endEditingAsync(e = true) {
- 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(Yx).getRenderById(r);
- return i ? i.with(yt).getScrollStateByParam({ unitId: r, sheetId: e }) : null;
- }
- disableSelection() {
- const e = this._workbook.getUnitId(), t = this._injector.get(Yx).getRenderById(e);
- return t && t.with(dt).disableSelection(), this;
- }
- enableSelection() {
- const e = this._workbook.getUnitId(), t = this._injector.get(Yx).getRenderById(e);
- return t && t.with(dt).enableSelection(), this;
- }
- transparentSelection() {
- const e = this._workbook.getUnitId(), t = this._injector.get(Yx).getRenderById(e);
- return t && t.with(dt).transparentSelection(), this;
- }
- showSelection() {
- const e = this._workbook.getUnitId(), t = this._injector.get(Yx).getRenderById(e);
- return t && t.with(dt).showSelection(), this;
- }
- };
- f.extend(Ne);
- var Ve2 = class extends m {
- refreshCanvas() {
- const e = this._injector.get(Yx), r = this._fWorkbook.id, t = e.getRenderById(r);
- if (!t)
- throw new Error(`Render Unit with unitId ${r} not found`);
- t.with(me).reCalculate();
- const i = t.mainComponent;
- if (!i)
- throw new Error("Main component not found");
- return i.makeDirty(), this;
- }
- zoom(e) {
- return this._injector.get(Pt).syncExecuteCommand(Li2.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(Yx).getRenderById(e);
- let i = {
- startColumn: 0,
- startRow: 0,
- endColumn: 0,
- endRow: 0
- };
- if (!t)
- return i;
- const s = t.with(me).getCurrentSkeleton();
- if (!s)
- return i;
- const c = s == null ? void 0 : s.getVisibleRanges();
- if (!c)
- return i;
- i = s.getVisibleRangeByViewport(i2.VIEW_MAIN);
- for (const [g, b] of c)
- Ef.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(Yx).getRenderById(t);
- return o && (o == null ? void 0 : o.with(ai)).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(Yx).getRenderById(r);
- return o && o.with(yt).getScrollStateByParam({ unitId: r, sheetId: t }) || e;
- }
- onScroll(e) {
- var o;
- const r = this._workbook.getUnitId(), i = (o = this._injector.get(Yx).getRenderById(r)) == null ? void 0 : o.with(yt);
- if (i) {
- const s = i.validViewportScrollInfo$.subscribe((c) => {
- e(c);
- });
- return Ze(s);
- }
- return Ze(() => {
- });
- }
- getSkeleton() {
- var r, t;
- const e = (r = this._injector.get(Yx).getRenderById(this._workbook.getUnitId())) == null ? void 0 : r.with(me);
- 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(Ql.id, {
- unitId: t,
- subUnitId: i,
- ranges: o
- }), this;
- }
- };
- m.extend(Ve2);
- var Ze2 = class extends j {
- setPermissionDialogVisible(e) {
- this._permissionService.setShowComponents(e);
- }
- };
- j.extend(Ze2);
- var Ke = class extends xe {
- onCellPointerMove(e) {
- return Ze(this._injector.get(Er).currentPosition$.subscribe(e));
- }
- onCellPointerOver(e) {
- return Ze(this._injector.get(Er).currentCell$.subscribe(e));
- }
- onCellDragOver(e) {
- return Ze(this._injector.get(wi).currentCell$.subscribe(e));
- }
- onCellDrop(e) {
- return Ze(this._injector.get(wi).endCell$.subscribe(e));
- }
- onCellRender(e, r = Vn.Style, t = ea.DATA_VALIDATION) {
- return this._injector.get(V).intercept(et.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(Pt).beforeCommandExecuted((r) => {
- const t = r.params;
- r.id === Et.id && t.visible && e(t);
- });
- }
- onAfterCellEdit(e) {
- return this._injector.get(Pt).onCommandExecuted((r) => {
- const t = r.params;
- r.id === Et.id && !t.visible && e(t);
- });
- }
- };
- xe.extend(Ke);
- var 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"
- };
- var ze = class extends hi {
- 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";
- }
- };
- hi.extend(ze);
- var Ye = class extends S {
- getCell() {
- var c;
- const e = this._injector.get(Yx), r = this._injector.get(Mt), t = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), o = e.getRenderById(t), s = (c = o == null ? void 0 : o.with(me).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(Sn).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(n1)), o = this._injector.get(vi).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(bi2), 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(n1)), o = this._injector.get(vi).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(ws), i = t.addShape({ range: this._range, style: e, primary: r });
- if (!i)
- throw new Error("Failed to highlight current range");
- return Ze(() => {
- t.removeShape(i);
- });
- }
- };
- S.extend(Ye);
- function ge(w, e) {
- const { componentKey: r, isVue3: t } = w;
- let i;
- const o = new Mi();
- return typeof r == "string" ? i = r : (i = `External_${qt(6)}`, o.add(e.register(i, r, { framework: t ? "vue3" : "react" }))), {
- key: i,
- disposableCollection: o
- };
- }
- export {
- ge as transformComponentKey
- };
- //# sourceMappingURL=@univerjs_sheets-ui_facade.js.map
|