| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873 |
- var L = Object.defineProperty;
- var X = (r, t, e) => t in r ? L(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
- var T = (r, t, e) => X(r, typeof t != "symbol" ? t + "" : t, e);
- import { Inject as x, Injector as P, ICommandService as W, generateRandomId as Y, DrawingTypeEnum as _, ImageSourceType as I, FBase as V, ArrangeTypeEnum as v, toDisposable as C, FEnum as M, FEventName as z, FUniver as N } from "@univerjs/core";
- import { getImageSize as q, SetDrawingSelectedOperation as A, IDrawingManagerService as l } from "@univerjs/drawing";
- import { IRenderManagerService as F } from "@univerjs/engine-render";
- import { SetSheetDrawingCommand as m, SetDrawingArrangeCommand as w, SheetCanvasFloatDomManagerService as G, InsertSheetDrawingCommand as S, RemoveSheetDrawingCommand as D } from "@univerjs/sheets-drawing-ui";
- import { SheetSkeletonManagerService as U, ISheetSelectionRenderService as J, convertPositionSheetOverGridToAbsolute as Q, convertPositionCellToSheetOverGrid as Z } from "@univerjs/sheets-ui";
- import { ISheetDrawingService as u, SheetDrawingAnchorType as ee } from "@univerjs/sheets-drawing";
- import { transformComponentKey as E } from "@univerjs/sheets-ui/facade";
- import { FWorksheet as $ } from "@univerjs/sheets/facade";
- import { ComponentManager as y } from "@univerjs/ui";
- var te = Object.defineProperty, ie = Object.getOwnPropertyDescriptor, H = (r, t, e, i) => {
- for (var n = i > 1 ? void 0 : i ? ie(t, e) : t, s = r.length - 1, o; s >= 0; s--)
- (o = r[s]) && (n = (i ? o(t, e, n) : o(n)) || n);
- return i && n && te(t, e, n), n;
- }, R = (r, t) => (e, i) => t(e, i, r);
- function re(r, t) {
- const { from: e, to: i, flipY: n = !1, flipX: s = !1, angle: o = 0, skewX: c = 0, skewY: a = 0 } = r.sheetTransform, { column: h, columnOffset: d, row: f, rowOffset: p } = e, k = Q(
- r.unitId,
- r.subUnitId,
- { from: e, to: i },
- t
- ), { left: B, top: j, width: O, height: K } = k;
- return {
- ...r,
- column: h,
- columnOffset: d,
- row: f,
- rowOffset: p,
- width: O,
- height: K,
- flipY: n,
- flipX: s,
- angle: o,
- skewX: c,
- skewY: a
- };
- }
- function ne(r, t, e) {
- const { column: i, columnOffset: n, row: s, rowOffset: o, flipY: c = !1, flipX: a = !1, angle: h = 0, skewX: d = 0, skewY: f = 0, width: p, height: k } = r, B = Z(
- r.unitId,
- r.subUnitId,
- { column: i, columnOffset: n, row: s, rowOffset: o },
- p,
- k,
- t,
- e
- ), { sheetTransform: j, transform: O } = B;
- return {
- ...r,
- sheetTransform: {
- ...j,
- flipY: c,
- flipX: a,
- angle: h,
- skewX: d,
- skewY: f
- },
- transform: {
- ...O,
- flipY: c,
- flipX: a,
- angle: h,
- skewX: d,
- skewY: f
- }
- };
- }
- let b = class {
- constructor(r, t, e) {
- T(this, "_image");
- this._injector = e, this._image = {
- drawingId: Y(6),
- drawingType: _.DRAWING_IMAGE,
- imageSourceType: I.BASE64,
- source: "",
- unitId: r,
- subUnitId: t,
- column: 0,
- columnOffset: 0,
- row: 0,
- rowOffset: 0,
- width: 0,
- height: 0
- };
- }
- /**
- * Set the initial image configuration for the image builder.
- * @param image The image to be set. {@link ISheetImage}
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setImage({
- * drawingId: '123456',
- * drawingType: univerAPI.Enum.DrawingType.DRAWING_IMAGE,
- * imageSourceType: univerAPI.Enum.ImageSourceType.BASE64,
- * source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
- * unitId: activeSpreadsheet.getId(),
- * subUnitId: activeSheet.getSheetId(),
- * }).setColumn(5).setRow(5).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setImage(r) {
- const e = this._injector.get(F).getRenderById(r.unitId);
- if (!e)
- throw new Error(`Render Unit with unitId ${r.unitId} not found`);
- const i = e.with(U);
- return r.sheetTransform == null && (r.sheetTransform = {
- from: {
- column: 0,
- columnOffset: 0,
- row: 0,
- rowOffset: 0
- },
- to: {
- column: 0,
- columnOffset: 0,
- row: 0,
- rowOffset: 0
- }
- }), this._image = re(r, i), this;
- }
- setSource(r, t) {
- const e = t != null ? t : I.URL;
- return this._image.source = r, this._image.imageSourceType = e, this;
- }
- getsource() {
- return this._image.source;
- }
- getSourceType() {
- return this._image.imageSourceType;
- }
- /**
- * Set the position of the image
- * @param column The sheet start column of the image
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setColumn(r) {
- return this._image.column = r, this;
- }
- /**
- * Set the position of the image
- * @param row The sheet start row of the image
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setRow(r) {
- return this._image.row = r, this;
- }
- /**
- * Set the column offset of the image in a unit
- * @param offset The offset in pixels
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setColumnOffset(10).setRowOffset(10).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setColumnOffset(r) {
- return this._image.columnOffset = r, this;
- }
- /**
- * Set the row offset of the image in a unit
- * @param offset The offset in pixels
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setColumnOffset(10).setRowOffset(10).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setRowOffset(r) {
- return this._image.rowOffset = r, this;
- }
- /**
- * set the width of the image
- * @param width The width of the image, in pixels
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setWidth(120).setHeight(50).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setWidth(r) {
- return this._image.width = r, this;
- }
- /**
- * Set the height of the image
- * @param height The height of the image, in pixels
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setWidth(120).setHeight(50).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setHeight(r) {
- return this._image.height = r, this;
- }
- /**
- * Set the anchor type of the image, whether the position and size change with the cell
- * @param anchorType The anchor type {@link SheetDrawingAnchorType}
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.None).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setAnchorType(r) {
- return this._image.anchorType = r, this;
- }
- /**
- * Set the cropping region of the image by defining the top edges, thereby displaying the specific part of the image you want.
- * @param top The number of pixels to crop from the top of the image.
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setCropTop(10).setCropLeft(10).setCropBottom(10).setCropRight(10).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setCropTop(r) {
- return this._initializeSrcRect(), this._image.srcRect.top = r, this;
- }
- /**
- * Set the cropping region of the image by defining the left edges, thereby displaying the specific part of the image you want.
- * @param left The number of pixels to crop from the left side of the image.
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setCropTop(10).setCropLeft(10).setCropBottom(10).setCropRight(10).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setCropLeft(r) {
- return this._initializeSrcRect(), this._image.srcRect.left = r, this;
- }
- /**
- * Set the cropping region of the image by defining the bottom edges, thereby displaying the specific part of the image you want.
- * @param bottom The number of pixels to crop from the bottom of the image.
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setCropTop(10).setCropLeft(10).setCropBottom(10).setCropRight(10).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setCropBottom(r) {
- return this._initializeSrcRect(), this._image.srcRect.bottom = r, this;
- }
- /**
- * Set the cropping region of the image by defining the right edges, thereby displaying the specific part of the image you want.
- * @param right The number of pixels to crop from the right side of the image.
- * @returns The builder. {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setCropTop(10).setCropLeft(10).setCropBottom(10).setCropRight(10).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setCropRight(r) {
- return this._initializeSrcRect(), this._image.srcRect.right = r, this;
- }
- _initializeSrcRect() {
- this._image.srcRect == null && (this._image.srcRect = {
- top: 0,
- left: 0,
- bottom: 0,
- right: 0
- });
- }
- /**
- * Set the rotation angle of the image
- * @param angle Degree of rotation of the image, for example, 90, 180, 270, etc.
- * @returns The builder {@link FOverGridImageBuilder}
- * @example
- * ```ts
- * // create a new image builder.
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const imageBuilder = activeSheet.newOverGridImage();
- * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setRotate(90).buildAsync();
- * activeSheet.insertImages([param]);
- * ```
- */
- setRotate(r) {
- return this._image.angle = r, this;
- }
- // setPresetGeometry(prstGeom: PresetGeometryType): FOverGridImageBuilder {
- // this._image.prstGeom = prstGeom;
- // return this;
- // }
- setUnitId(r) {
- return this._image.unitId = r, this;
- }
- setSubUnitId(r) {
- return this._image.subUnitId = r, this;
- }
- async buildAsync() {
- const t = this._injector.get(F).getRenderById(this._image.unitId);
- if (!t)
- throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);
- const e = t.with(J), i = t.with(U);
- if (this._image.width === 0 || this._image.height === 0) {
- const n = await q(this._image.source), s = n.width, o = n.height;
- this._image.width === 0 && (this._image.width = s), this._image.height === 0 && (this._image.height = o);
- }
- return ne(this._image, e, i);
- }
- };
- b = H([
- R(2, x(P))
- ], b);
- let g = class extends V {
- constructor(r, t, e) {
- super(), this._image = r, this._commandService = t, this._injector = e;
- }
- getId() {
- return this._image.drawingId;
- }
- getType() {
- return this._image.drawingType;
- }
- /**
- * Remove the image from the sheet
- * @returns success or not
- * @example
- * ```ts
- * // remove the image from the sheet
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const image = activeSheet.getImages()[0];
- * console.log('Delete state is ', image?.remove());
- * ```
- */
- remove() {
- return this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [this._image] });
- }
- /**
- * Convert the image to a FOverGridImageBuilder
- * @returns The builder FOverGridImageBuilder
- * @example
- * ```ts
- * // convert the image to a builder
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const image = activeSheet.getImages()[0];
- * const builder = image.toBuilder();
- * const param = await builder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).buildAsync();
- * activeSheet.updateImages([param]);
- * ```
- */
- toBuilder() {
- const r = this._injector.createInstance(b);
- return r.setImage(this._image), r;
- }
- setSource(r, t) {
- const e = t != null ? t : I.URL;
- return this._image.source = r, this._image.imageSourceType = e, this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [this._image] });
- }
- async setPositionAsync(r, t, e, i) {
- const n = this.toBuilder();
- n.setColumn(t), n.setRow(r), e != null && n.setRowOffset(e), i != null && n.setColumnOffset(i);
- const s = await n.buildAsync();
- return this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [s] });
- }
- /**
- * Set the size of the image
- * @param width The width of the image
- * @param height The height of the image
- * @returns success or not
- * @example
- * ```ts
- * // set the size of the image
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const image = activeSheet.getImages()[0];
- * console.log('Set size state is ', image.setSize(50, 120));
- */
- async setSizeAsync(r, t) {
- const e = this.toBuilder();
- e.setWidth(r), e.setHeight(t);
- const i = await e.buildAsync();
- return this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [i] });
- }
- /**
- * Set the cropping region of the image by defining the top, bottom, left, and right edges, thereby displaying the specific part of the image you want.
- * @param top The number of pixels to crop from the top of the image.
- * @param left The number of pixels to crop from the left side of the image.
- * @param bottom The number of pixels to crop from the bottom of the image.
- * @param right The number of pixels to crop from the right side of the image.
- * @returns success or not
- * @example
- * ```ts
- * // set the crop of the image
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const image = activeSheet.getImages()[0];
- * console.log('Set crop state is ', image.setCrop(10, 10, 10, 10));
- * ```
- */
- setCrop(r, t, e, i) {
- return this._image.srcRect == null && (this._image.srcRect = {
- top: 0,
- left: 0,
- bottom: 0,
- right: 0
- }), r != null && (this._image.srcRect.top = r), t != null && (this._image.srcRect.left = t), e != null && (this._image.srcRect.bottom = e), i != null && (this._image.srcRect.right = i), this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [this._image] });
- }
- // setPresetGeometry(prstGeom: PresetGeometryType): boolean {
- // this._image.prstGeom = prstGeom;
- // return this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, { unitId: this._image.unitId, drawings: [this._image] });
- // }
- /**
- * Set the rotation angle of the image
- * @param angle Degree of rotation of the image, for example, 90, 180, 270, etc.
- * @returns success or not
- * @example
- * ```ts
- * // set the rotation angle of the image
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const image = activeSheet.getImages()[0];
- * console.log('Set rotate state is ', image.setRotate(90));
- * ```
- */
- setRotate(r) {
- return this._image.sheetTransform.angle = r, this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [this._image] });
- }
- /**
- * Move the image layer forward by one level
- * @returns success or not
- * @example
- * ```ts
- * // move the image forward
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const image = activeSheet.getImages()[0];
- * console.log('Move forward state is ', image.setForward());
- * ```
- */
- setForward() {
- return this._commandService.syncExecuteCommand(w.id, {
- unitId: this._image.unitId,
- subUnitId: this._image.subUnitId,
- drawingIds: [this._image.drawingId],
- arrangeType: v.forward
- });
- }
- /**
- * Move the image layer backward by one level
- * @returns success or not
- * @example
- * ```ts
- * // move the image backward
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const image = activeSheet.getImages()[0];
- * console.log('Move backward state is ', image.setBackward());
- * ```
- */
- setBackward() {
- return this._commandService.syncExecuteCommand(w.id, {
- unitId: this._image.unitId,
- subUnitId: this._image.subUnitId,
- drawingIds: [this._image.drawingId],
- arrangeType: v.backward
- });
- }
- /**
- * Move the image layer to the back
- * @returns success or not
- * @example
- * ```ts
- * // move the image to the back
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const image = activeSheet.getImages()[0];
- * console.log('Move back state is ', image.setBack());
- * ```
- */
- setBack() {
- return this._commandService.syncExecuteCommand(w.id, {
- unitId: this._image.unitId,
- subUnitId: this._image.subUnitId,
- drawingIds: [this._image.drawingId],
- arrangeType: v.back
- });
- }
- /**
- * Move the image layer to the front
- * @returns success or not
- * @example
- * ```ts
- * // move the image to the front
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * const image = activeSheet.getImages()[0];
- * console.log('Move front state is ', image.setFront());
- * ```
- */
- setFront() {
- return this._commandService.syncExecuteCommand(w.id, {
- unitId: this._image.unitId,
- subUnitId: this._image.subUnitId,
- drawingIds: [this._image.drawingId],
- arrangeType: v.front
- });
- }
- };
- g = H([
- R(1, W),
- R(2, x(P))
- ], g);
- class se extends $ {
- addFloatDomToPosition(t, e) {
- const i = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), { key: s, disposableCollection: o } = E(t, this._injector.get(y)), a = this._injector.get(G).addFloatDomToPosition({ ...t, componentKey: s, unitId: i, subUnitId: n }, e);
- return a ? (o.add(a.dispose), {
- id: a.id,
- dispose: () => {
- o.dispose(), a.dispose();
- }
- }) : (o.dispose(), null);
- }
- addFloatDomToRange(t, e, i, n) {
- const s = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), { key: c, disposableCollection: a } = E(e, this._injector.get(y)), d = this._injector.get(G).addFloatDomToRange(t.getRange(), { ...e, componentKey: c, unitId: s, subUnitId: o }, i, n);
- return d ? (a.add(d.dispose), {
- id: d.id,
- dispose: () => {
- a.dispose(), d.dispose();
- }
- }) : (a.dispose(), null);
- }
- addFloatDomToColumnHeader(t, e, i, n) {
- const s = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), { key: c, disposableCollection: a } = E(e, this._injector.get(y)), d = this._injector.get(G).addFloatDomToColumnHeader(t, { ...e, componentKey: c, unitId: s, subUnitId: o }, i, n);
- return d ? (a.add(d.dispose), {
- id: d.id,
- dispose: () => {
- a.dispose(), d.dispose();
- }
- }) : (a.dispose(), null);
- }
- async insertImage(t, e, i, n, s) {
- const o = this.newOverGridImage();
- if (typeof t == "string")
- o.setSource(t);
- else {
- const h = await t.getBlob().getDataAsString();
- o.setSource(h, I.BASE64);
- }
- e !== void 0 ? o.setColumn(e) : o.setColumn(0), i !== void 0 ? o.setRow(i) : o.setRow(0), n !== void 0 ? o.setColumnOffset(n) : o.setColumnOffset(0), s !== void 0 ? o.setRowOffset(s) : o.setRowOffset(0);
- const c = await o.buildAsync();
- return this._commandService.syncExecuteCommand(S.id, { unitId: this._fWorkbook.getId(), drawings: [c] });
- }
- insertImages(t) {
- const e = t.map((i) => (i.unitId = this._fWorkbook.getId(), i.subUnitId = this.getSheetId(), i));
- return this._commandService.syncExecuteCommand(S.id, { unitId: this._fWorkbook.getId(), drawings: e }), this;
- }
- deleteImages(t) {
- const e = t.map((i) => ({
- unitId: this._fWorkbook.getId(),
- drawingId: i.getId(),
- subUnitId: this.getSheetId(),
- drawingType: i.getType()
- }));
- return this._commandService.syncExecuteCommand(D.id, { unitId: this._fWorkbook.getId(), drawings: e }), this;
- }
- getImages() {
- const e = this._injector.get(u).getDrawingData(this._fWorkbook.getId(), this.getSheetId()), i = [];
- for (const n in e) {
- const s = e[n];
- s.drawingType === _.DRAWING_IMAGE && i.push(this._injector.createInstance(g, s));
- }
- return i;
- }
- getImageById(t) {
- const i = this._injector.get(u).getDrawingByParam({ unitId: this._fWorkbook.getId(), subUnitId: this.getSheetId(), drawingId: t });
- return i && i.drawingType === _.DRAWING_IMAGE ? this._injector.createInstance(g, i) : null;
- }
- getActiveImages() {
- const e = this._injector.get(u).getFocusDrawings(), i = [];
- for (const n in e) {
- const s = e[n];
- i.push(this._injector.createInstance(g, s));
- }
- return i;
- }
- updateImages(t) {
- return this._commandService.syncExecuteCommand(m.id, { unitId: this._fWorkbook.getId(), drawings: t }), this;
- }
- onImageInserted(t) {
- const e = this._injector.get(u);
- return C(e.add$.subscribe((i) => {
- const n = i.map(
- (s) => this._injector.createInstance(g, e.getDrawingByParam(s))
- );
- t(n);
- }));
- }
- onImageDeleted(t) {
- const e = this._injector.get(u);
- return C(e.remove$.subscribe((i) => {
- const n = i.map(
- (s) => this._injector.createInstance(g, e.getDrawingByParam(s))
- );
- t(n);
- }));
- }
- onImageChanged(t) {
- const e = this._injector.get(u);
- return C(e.update$.subscribe((i) => {
- const n = i.map(
- (s) => this._injector.createInstance(g, e.getDrawingByParam(s))
- );
- t(n);
- }));
- }
- newOverGridImage() {
- const t = this._fWorkbook.getId(), e = this.getSheetId();
- return this._injector.createInstance(b, t, e);
- }
- }
- $.extend(se);
- class oe extends M {
- get DrawingType() {
- return _;
- }
- get ImageSourceType() {
- return I;
- }
- get SheetDrawingAnchorType() {
- return ee;
- }
- }
- M.extend(oe);
- class ae extends z {
- get BeforeOverGridImageChange() {
- return "BeforeOverGridImageChange";
- }
- get OverGridImageChanged() {
- return "OverGridImageChanged";
- }
- get BeforeOverGridImageInsert() {
- return "BeforeOverGridImageInsert";
- }
- get OverGridImageInserted() {
- return "OverGridImageInserted";
- }
- get BeforeOverGridImageRemove() {
- return "BeforeOverGridImageRemove";
- }
- get OverGridImageRemoved() {
- return "OverGridImageRemoved";
- }
- get BeforeOverGridImageSelect() {
- return "BeforeOverGridImageSelect";
- }
- get OverGridImageSelected() {
- return "OverGridImageSelected";
- }
- }
- z.extend(ae);
- class ce extends N {
- _initialize(t) {
- const e = t.get(W);
- this.disposeWithMe(e.beforeCommandExecuted((i) => {
- switch (i.id) {
- case S.id:
- this._beforeOverGridImageInsert(i.params);
- break;
- case D.id:
- this._beforeOverGridImageRemove(i.params);
- break;
- case m.id:
- this._beforeOverGridImageChange(i.params);
- break;
- case A.id:
- this._beforeOverGridImageSelect(i.params);
- break;
- }
- })), this.disposeWithMe(e.onCommandExecuted((i) => {
- switch (i.id) {
- case S.id:
- this._overGridImageInserted(i.params);
- break;
- case D.id:
- this._overGridImageRemoved(i.params);
- break;
- case m.id:
- this._overGridImageChanged(i.params);
- break;
- case A.id:
- this._overGridImageSelected(i.params);
- break;
- }
- }));
- }
- _beforeOverGridImageInsert(t) {
- if (!this.hasEventCallback(this.Event.BeforeOverGridImageInsert))
- return;
- const e = this.getActiveWorkbook();
- if (e == null || t == null)
- return;
- const { drawings: i } = t, n = {
- workbook: e,
- insertImageParams: i
- };
- if (this.fireEvent(this.Event.BeforeOverGridImageInsert, n), n.cancel)
- throw new Error("Canceled by BeforeOverGridImageInsert event");
- }
- _overGridImageInserted(t) {
- if (!this.hasEventCallback(this.Event.OverGridImageInserted))
- return;
- const e = this.getActiveWorkbook();
- if (e == null || t == null)
- return;
- const { drawings: i } = t;
- this.fireEvent(this.Event.OverGridImageInserted, {
- workbook: e,
- images: this._createFOverGridImage(i)
- });
- }
- _beforeOverGridImageRemove(t) {
- if (!this.hasEventCallback(this.Event.BeforeOverGridImageRemove))
- return;
- const e = this.getActiveWorkbook();
- if (e == null || t == null)
- return;
- const { drawings: i } = t, n = this._injector.get(l), s = i.map((c) => n.getDrawingByParam(c)), o = {
- workbook: e,
- images: this._createFOverGridImage(s)
- };
- if (this.fireEvent(this.Event.BeforeOverGridImageRemove, o), o.cancel)
- throw new Error("Canceled by BeforeOverGridImageRemove event");
- }
- _overGridImageRemoved(t) {
- if (!this.hasEventCallback(this.Event.OverGridImageRemoved))
- return;
- const e = this.getActiveWorkbook();
- if (e == null || t == null)
- return;
- const { drawings: i } = t;
- this.fireEvent(this.Event.OverGridImageRemoved, {
- workbook: e,
- removeImageParams: i
- });
- }
- _beforeOverGridImageChange(t) {
- if (!this.hasEventCallback(this.Event.BeforeOverGridImageChange))
- return;
- const e = this.getActiveWorkbook();
- if (e == null || t == null)
- return;
- const { drawings: i } = t, n = this._injector.get(l), s = [];
- i.forEach((c) => {
- const a = n.getDrawingByParam(c);
- a != null && s.push({
- changeParam: c,
- image: this._injector.createInstance(g, a)
- });
- });
- const o = {
- workbook: e,
- images: s
- };
- if (this.fireEvent(this.Event.BeforeOverGridImageChange, o), o.cancel)
- throw n.updateNotification(i), new Error("Canceled by BeforeOverGridImageChange event");
- }
- _overGridImageChanged(t) {
- if (!this.hasEventCallback(this.Event.OverGridImageChanged))
- return;
- const e = this.getActiveWorkbook();
- if (e == null || t == null)
- return;
- const { drawings: i } = t, n = this._injector.get(l), s = i.map((o) => this._injector.createInstance(g, n.getDrawingByParam(o)));
- this.fireEvent(this.Event.OverGridImageChanged, {
- workbook: e,
- images: s
- });
- }
- _beforeOverGridImageSelect(t) {
- if (!this.hasEventCallback(this.Event.BeforeOverGridImageSelect))
- return;
- const e = this._injector.get(l), i = this.getActiveWorkbook();
- if (i == null)
- return;
- const n = e.getFocusDrawings(), s = t.map((c) => e.getDrawingByParam(c)), o = {
- workbook: i,
- selectedImages: this._createFOverGridImage(s),
- oldSelectedImages: this._createFOverGridImage(n)
- };
- if (this.fireEvent(this.Event.BeforeOverGridImageSelect, o), o.cancel)
- throw new Error("Canceled by BeforeOverGridImageSelect event");
- }
- _overGridImageSelected(t) {
- if (!this.hasEventCallback(this.Event.OverGridImageSelected))
- return;
- const e = this.getActiveWorkbook(), i = this._injector.get(l);
- if (e == null)
- return;
- const n = t.map((s) => i.getDrawingByParam(s));
- this.fireEvent(this.Event.OverGridImageSelected, {
- workbook: e,
- selectedImages: this._createFOverGridImage(n)
- });
- }
- _createFOverGridImage(t) {
- return t.map((e) => this._injector.createInstance(g, e));
- }
- }
- N.extend(ce);
|