@univerjs/sheets-drawing-ui 0.15.0-insiders.20260106-79b11f9 → 0.15.0-insiders.20260107-3d1cfdf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/facade.js CHANGED
@@ -1,14 +1,14 @@
1
1
  var Q = Object.defineProperty;
2
2
  var Z = (s, t, r) => t in s ? Q(s, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[t] = r;
3
- var W = (s, t, r) => Z(s, typeof t != "symbol" ? t + "" : t, r);
4
- import { Inject as N, Injector as L, ICommandService as K, ImageSourceType as y, ArrangeTypeEnum as O, DrawingTypeEnum as v, generateRandomId as ee, toDisposable as T, CanceledError as D, UniverInstanceType as te, IUniverInstanceService as re } from "@univerjs/core";
5
- import { FBase as ne, FEnum as z, FEventName as X, FUniver as Y } from "@univerjs/core/facade";
6
- import { getImageSize as ie, IDrawingManagerService as S, SetDrawingSelectedOperation as j } from "@univerjs/drawing";
3
+ var j = (s, t, r) => Z(s, typeof t != "symbol" ? t + "" : t, r);
4
+ import { Inject as L, Injector as K, ICommandService as z, ImageSourceType as y, ArrangeTypeEnum as O, DrawingTypeEnum as v, generateRandomId as ee, toDisposable as A, CanceledError as D, UniverInstanceType as te, IUniverInstanceService as re } from "@univerjs/core";
5
+ import { FBase as ne, FEnum as X, FEventName as Y, FUniver as V } from "@univerjs/core/facade";
6
+ import { getImageSize as ie, IDrawingManagerService as S, SetDrawingSelectedOperation as M } from "@univerjs/drawing";
7
7
  import { IRenderManagerService as C, getCurrentTypeOfRenderer as se } from "@univerjs/engine-render";
8
- import { RemoveSheetDrawingCommand as k, SetSheetDrawingCommand as f, SetDrawingArrangeCommand as F, SheetCanvasFloatDomManagerService as p, transformToDrawingPosition as M, InsertSheetDrawingCommand as E, IBatchSaveImagesService as V, FileNamePart as b, SheetDrawingUpdateController as oe } from "@univerjs/sheets-drawing-ui";
9
- import { SheetSkeletonManagerService as H, ISheetSelectionRenderService as x, convertPositionSheetOverGridToAbsolute as ae, convertPositionCellToSheetOverGrid as de } from "@univerjs/sheets-ui";
8
+ import { RemoveSheetDrawingCommand as k, SetSheetDrawingCommand as f, SetDrawingArrangeCommand as F, SheetCanvasFloatDomManagerService as p, transformToDrawingPosition as H, InsertSheetDrawingCommand as b, IBatchSaveImagesService as W, FileNamePart as E, SheetDrawingUpdateController as oe } from "@univerjs/sheets-drawing-ui";
9
+ import { SheetSkeletonManagerService as N, ISheetSelectionRenderService as x, convertPositionSheetOverGridToAbsolute as ae, convertPositionCellToSheetOverGrid as de } from "@univerjs/sheets-ui";
10
10
  import { ISheetDrawingService as w, SheetDrawingAnchorType as ce } from "@univerjs/sheets-drawing";
11
- import { transformComponentKey as U } from "@univerjs/sheets-ui/facade";
11
+ import { transformComponentKey as T } from "@univerjs/sheets-ui/facade";
12
12
  import { FWorksheet as $, FRange as q } from "@univerjs/sheets/facade";
13
13
  import { ComponentManager as G } from "@univerjs/ui";
14
14
  var ge = Object.getOwnPropertyDescriptor, J = (s, t, r, e) => {
@@ -47,7 +47,7 @@ function he(s, t, r) {
47
47
  _,
48
48
  t,
49
49
  r
50
- ), { sheetTransform: u, transform: A } = l;
50
+ ), { sheetTransform: u, transform: U } = l;
51
51
  return {
52
52
  ...s,
53
53
  sheetTransform: {
@@ -59,7 +59,7 @@ function he(s, t, r) {
59
59
  skewY: m
60
60
  },
61
61
  transform: {
62
- ...A,
62
+ ...U,
63
63
  flipY: o,
64
64
  flipX: d,
65
65
  angle: g,
@@ -70,7 +70,7 @@ function he(s, t, r) {
70
70
  }
71
71
  let B = class {
72
72
  constructor(s, t, r) {
73
- W(this, "_image");
73
+ j(this, "_image");
74
74
  this._injector = r, this._image = {
75
75
  drawingId: ee(6),
76
76
  drawingType: v.DRAWING_IMAGE,
@@ -115,7 +115,7 @@ let B = class {
115
115
  const r = this._injector.get(C).getRenderById(s.unitId);
116
116
  if (!r)
117
117
  throw new Error(`Render Unit with unitId ${s.unitId} not found`);
118
- const e = r.with(H);
118
+ const e = r.with(N);
119
119
  return s.sheetTransform == null && (s.sheetTransform = {
120
120
  from: {
121
121
  column: 0,
@@ -476,7 +476,7 @@ let B = class {
476
476
  const t = this._injector.get(C).getRenderById(this._image.unitId);
477
477
  if (!t)
478
478
  throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);
479
- const r = t.with(x), e = t.with(H);
479
+ const r = t.with(x), e = t.with(N);
480
480
  if (this._image.width === 0 || this._image.height === 0) {
481
481
  const n = await ie(this._image.source), i = n.width, a = n.height;
482
482
  this._image.width === 0 && (this._image.width = i), this._image.height === 0 && (this._image.height = a);
@@ -485,7 +485,7 @@ let B = class {
485
485
  }
486
486
  };
487
487
  B = J([
488
- P(2, N(L))
488
+ P(2, L(K))
489
489
  ], B);
490
490
  let I = class extends ne {
491
491
  constructor(s, t, r) {
@@ -710,14 +710,14 @@ let I = class extends ne {
710
710
  }
711
711
  };
712
712
  I = J([
713
- P(1, K),
714
- P(2, N(L))
713
+ P(1, z),
714
+ P(2, L(K))
715
715
  ], I);
716
716
  class le extends $ {
717
717
  getFloatDomById(t) {
718
718
  const e = this._injector.get(p).getFloatDomInfo(t);
719
719
  if (!e) return null;
720
- const { unitId: n, subUnitId: i } = e, { rect: a } = e, o = a.getState(), { left: d = 0, top: g = 0, width: c = 0, height: m = 0, flipX: h = !1, flipY: _ = !1, angle: l = 0, skewX: u = 0, skewY: A = 0 } = o, R = this._injector.get(w).getDrawingByParam({
720
+ const { unitId: n, subUnitId: i } = e, { rect: a } = e, o = a.getState(), { left: d = 0, top: g = 0, width: c = 0, height: m = 0, flipX: h = !1, flipY: _ = !1, angle: l = 0, skewX: u = 0, skewY: U = 0 } = o, R = this._injector.get(w).getDrawingByParam({
721
721
  drawingId: e.id,
722
722
  unitId: n,
723
723
  subUnitId: i
@@ -732,7 +732,7 @@ class le extends $ {
732
732
  flipY: _,
733
733
  angle: l,
734
734
  skewX: u,
735
- skewY: A
735
+ skewY: U
736
736
  },
737
737
  componentKey: R.componentKey,
738
738
  allowTransform: R.allowTransform,
@@ -785,7 +785,7 @@ class le extends $ {
785
785
  componentKey: r.componentKey || o.componentKey,
786
786
  allowTransform: r.allowTransform !== void 0 ? r.allowTransform : o.allowTransform,
787
787
  data: r.data || o.data,
788
- sheetTransform: r.position && (u = M(
788
+ sheetTransform: r.position && (u = H(
789
789
  r.position,
790
790
  m
791
791
  )) != null ? u : o.sheetTransform,
@@ -820,7 +820,7 @@ class le extends $ {
820
820
  componentKey: o.config.componentKey || m.componentKey,
821
821
  allowTransform: o.config.allowTransform !== void 0 ? o.config.allowTransform : m.allowTransform,
822
822
  data: o.config.data || m.data,
823
- sheetTransform: o.config.position && (a = M(
823
+ sheetTransform: o.config.position && (a = H(
824
824
  o.config.position,
825
825
  l
826
826
  )) != null ? a : m.sheetTransform,
@@ -856,7 +856,7 @@ class le extends $ {
856
856
  return this;
857
857
  }
858
858
  addFloatDomToPosition(t, r) {
859
- const e = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), { key: i, disposableCollection: a } = U(t, this._injector.get(G)), d = this._injector.get(p).addFloatDomToPosition({ ...t, componentKey: i, unitId: e, subUnitId: n }, r);
859
+ const e = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), { key: i, disposableCollection: a } = T(t, this._injector.get(G)), d = this._injector.get(p).addFloatDomToPosition({ ...t, componentKey: i, unitId: e, subUnitId: n }, r);
860
860
  return d ? (a.add(d.dispose), {
861
861
  id: d.id,
862
862
  dispose: () => {
@@ -865,7 +865,7 @@ class le extends $ {
865
865
  }) : (a.dispose(), null);
866
866
  }
867
867
  addFloatDomToRange(t, r, e, n) {
868
- const i = this._workbook.getUnitId(), a = this._worksheet.getSheetId(), { key: o, disposableCollection: d } = U(r, this._injector.get(G)), c = this._injector.get(p).addFloatDomToRange(t.getRange(), { ...r, componentKey: o, unitId: i, subUnitId: a }, e, n);
868
+ const i = this._workbook.getUnitId(), a = this._worksheet.getSheetId(), { key: o, disposableCollection: d } = T(r, this._injector.get(G)), c = this._injector.get(p).addFloatDomToRange(t.getRange(), { ...r, componentKey: o, unitId: i, subUnitId: a }, e, n);
869
869
  return c ? (d.add(c.dispose), {
870
870
  id: c.id,
871
871
  dispose: () => {
@@ -874,7 +874,7 @@ class le extends $ {
874
874
  }) : (d.dispose(), null);
875
875
  }
876
876
  addFloatDomToColumnHeader(t, r, e, n) {
877
- const i = this._workbook.getUnitId(), a = this._worksheet.getSheetId(), { key: o, disposableCollection: d } = U(r, this._injector.get(G)), c = this._injector.get(p).addFloatDomToColumnHeader(t, { ...r, componentKey: o, unitId: i, subUnitId: a }, e, n);
877
+ const i = this._workbook.getUnitId(), a = this._worksheet.getSheetId(), { key: o, disposableCollection: d } = T(r, this._injector.get(G)), c = this._injector.get(p).addFloatDomToColumnHeader(t, { ...r, componentKey: o, unitId: i, subUnitId: a }, e, n);
878
878
  return c ? (d.add(c.dispose), {
879
879
  id: c.id,
880
880
  dispose: () => {
@@ -892,11 +892,11 @@ class le extends $ {
892
892
  }
893
893
  r !== void 0 ? a.setColumn(r) : a.setColumn(0), e !== void 0 ? a.setRow(e) : a.setRow(0), n !== void 0 ? a.setColumnOffset(n) : a.setColumnOffset(0), i !== void 0 ? a.setRowOffset(i) : a.setRowOffset(0);
894
894
  const o = await a.buildAsync();
895
- return this._commandService.syncExecuteCommand(E.id, { unitId: this._fWorkbook.getId(), drawings: [o] });
895
+ return this._commandService.syncExecuteCommand(b.id, { unitId: this._fWorkbook.getId(), drawings: [o] });
896
896
  }
897
897
  insertImages(t) {
898
898
  const r = t.map((e) => (e.unitId = this._fWorkbook.getId(), e.subUnitId = this.getSheetId(), e));
899
- return this._commandService.syncExecuteCommand(E.id, { unitId: this._fWorkbook.getId(), drawings: r }), this;
899
+ return this._commandService.syncExecuteCommand(b.id, { unitId: this._fWorkbook.getId(), drawings: r }), this;
900
900
  }
901
901
  deleteImages(t) {
902
902
  const r = t.map((e) => ({
@@ -932,7 +932,7 @@ class le extends $ {
932
932
  }
933
933
  onImageInserted(t) {
934
934
  const r = this._injector.get(w);
935
- return T(r.add$.subscribe((e) => {
935
+ return A(r.add$.subscribe((e) => {
936
936
  const n = e.map(
937
937
  (i) => this._injector.createInstance(I, r.getDrawingByParam(i))
938
938
  );
@@ -941,7 +941,7 @@ class le extends $ {
941
941
  }
942
942
  onImageDeleted(t) {
943
943
  const r = this._injector.get(w);
944
- return T(r.remove$.subscribe((e) => {
944
+ return A(r.remove$.subscribe((e) => {
945
945
  const n = e.map(
946
946
  (i) => this._injector.createInstance(I, r.getDrawingByParam(i))
947
947
  );
@@ -950,7 +950,7 @@ class le extends $ {
950
950
  }
951
951
  onImageChanged(t) {
952
952
  const r = this._injector.get(w);
953
- return T(r.update$.subscribe((e) => {
953
+ return A(r.update$.subscribe((e) => {
954
954
  const n = e.map(
955
955
  (i) => this._injector.createInstance(I, r.getDrawingByParam(i))
956
956
  );
@@ -963,7 +963,7 @@ class le extends $ {
963
963
  }
964
964
  async saveCellImagesAsync(t, r) {
965
965
  var m;
966
- const e = this._injector.get(V), n = this._fWorkbook.getId(), i = this.getSheetId(), a = r ? r.map((h) => h.getRange()) : [this._worksheet.getCellMatrix().getDataRange()], o = e.getCellImagesFromRanges(n, i, a);
966
+ const e = this._injector.get(W), n = this._fWorkbook.getId(), i = this.getSheetId(), a = r ? r.map((h) => h.getRange()) : [this._worksheet.getCellMatrix().getDataRange()], o = e.getCellImagesFromRanges(n, i, a);
967
967
  if (o.length === 0)
968
968
  return !1;
969
969
  if (o.length === 1)
@@ -973,7 +973,7 @@ class le extends $ {
973
973
  return console.error("Failed to download image:", h), !1;
974
974
  }
975
975
  const d = [], g = (m = t == null ? void 0 : t.useCellAddress) != null ? m : !0, c = t == null ? void 0 : t.useColumnIndex;
976
- g && d.push(b.CELL_ADDRESS), c !== void 0 && d.push(b.COLUMN_VALUE), d.length === 0 && d.push(b.CELL_ADDRESS);
976
+ g && d.push(E.CELL_ADDRESS), c !== void 0 && d.push(E.COLUMN_VALUE), d.length === 0 && d.push(E.CELL_ADDRESS);
977
977
  try {
978
978
  return await e.saveImagesWithContext(o, {
979
979
  fileNameParts: d,
@@ -985,7 +985,7 @@ class le extends $ {
985
985
  }
986
986
  }
987
987
  $.extend(le);
988
- class ue extends z {
988
+ class ue extends X {
989
989
  get DrawingType() {
990
990
  return v;
991
991
  }
@@ -996,8 +996,8 @@ class ue extends z {
996
996
  return ce;
997
997
  }
998
998
  }
999
- z.extend(ue);
1000
- class fe extends X {
999
+ X.extend(ue);
1000
+ class fe extends Y {
1001
1001
  get BeforeFloatDomAdd() {
1002
1002
  return "BeforeFloatDomAdd";
1003
1003
  }
@@ -1041,18 +1041,18 @@ class fe extends X {
1041
1041
  return "OverGridImageSelected";
1042
1042
  }
1043
1043
  }
1044
- X.extend(fe);
1045
- class we extends Y {
1044
+ Y.extend(fe);
1045
+ class we extends V {
1046
1046
  /**
1047
1047
  * @ignore
1048
1048
  */
1049
1049
  // eslint-disable-next-line max-lines-per-function
1050
1050
  _initialize(t) {
1051
- const r = t.get(K);
1051
+ const r = t.get(z);
1052
1052
  this.registerEventHandler(
1053
1053
  this.Event.BeforeFloatDomAdd,
1054
1054
  () => r.beforeCommandExecuted((e) => {
1055
- if (e.id !== E.id) return;
1055
+ if (e.id !== b.id) return;
1056
1056
  const n = e.params, i = this.getActiveWorkbook();
1057
1057
  if (i == null || n == null)
1058
1058
  return;
@@ -1071,7 +1071,7 @@ class we extends Y {
1071
1071
  ), this.registerEventHandler(
1072
1072
  this.Event.FloatDomAdded,
1073
1073
  () => r.onCommandExecuted((e) => {
1074
- if (e.id !== E.id) return;
1074
+ if (e.id !== b.id) return;
1075
1075
  const n = e.params, i = this.getActiveWorkbook();
1076
1076
  if (i == null || n == null)
1077
1077
  return;
@@ -1086,7 +1086,7 @@ class we extends Y {
1086
1086
  ), this.registerEventHandler(
1087
1087
  this.Event.BeforeOverGridImageInsert,
1088
1088
  () => r.beforeCommandExecuted((e) => {
1089
- if (e.id !== E.id) return;
1089
+ if (e.id !== b.id) return;
1090
1090
  const n = e.params, i = this.getActiveWorkbook();
1091
1091
  if (i == null || n == null)
1092
1092
  return;
@@ -1204,7 +1204,7 @@ class we extends Y {
1204
1204
  ), this.registerEventHandler(
1205
1205
  this.Event.BeforeOverGridImageSelect,
1206
1206
  () => r.beforeCommandExecuted((e) => {
1207
- if (e.id !== j.id) return;
1207
+ if (e.id !== M.id) return;
1208
1208
  const n = e.params, i = this.getActiveWorkbook();
1209
1209
  if (i == null)
1210
1210
  return;
@@ -1219,7 +1219,7 @@ class we extends Y {
1219
1219
  ), this.registerEventHandler(
1220
1220
  this.Event.OverGridImageInserted,
1221
1221
  () => r.onCommandExecuted((e) => {
1222
- if (e.id !== E.id) return;
1222
+ if (e.id !== b.id) return;
1223
1223
  const n = e.params, i = this.getActiveWorkbook();
1224
1224
  if (i == null || n == null)
1225
1225
  return;
@@ -1258,7 +1258,7 @@ class we extends Y {
1258
1258
  ), this.registerEventHandler(
1259
1259
  this.Event.OverGridImageSelected,
1260
1260
  () => r.onCommandExecuted((e) => {
1261
- if (e.id !== j.id) return;
1261
+ if (e.id !== M.id) return;
1262
1262
  const n = e.params, i = this.getActiveWorkbook();
1263
1263
  if (i == null)
1264
1264
  return;
@@ -1273,8 +1273,29 @@ class we extends Y {
1273
1273
  _createFOverGridImage(t) {
1274
1274
  return t.map((r) => this._injector.createInstance(I, r));
1275
1275
  }
1276
+ /**
1277
+ * Register a custom image downloader for URL images
1278
+ * @param downloader The downloader function that takes a URL and returns a base64 string
1279
+ * @returns A disposable object to unregister the downloader
1280
+ * @example
1281
+ * ```ts
1282
+ * const disposable = univerAPI.registerURLImageDownloader(async (url) => {
1283
+ * const response = await fetch(url);
1284
+ * const blob = await response.blob();
1285
+ * const base64 = await new Promise<string>((resolve) => {
1286
+ * const reader = new FileReader();
1287
+ * reader.onloadend = () => resolve(reader.result as string);
1288
+ * reader.readAsDataURL(blob);
1289
+ * });
1290
+ * return base64;
1291
+ * });
1292
+ * ```
1293
+ */
1294
+ registerURLImageDownloader(t) {
1295
+ return this._injector.get(W).registerURLImageDownloader(t);
1296
+ }
1276
1297
  }
1277
- Y.extend(we);
1298
+ V.extend(we);
1278
1299
  class Ie extends q {
1279
1300
  async insertCellImageAsync(t) {
1280
1301
  var i;
@@ -1291,7 +1312,7 @@ class Ie extends q {
1291
1312
  }
1292
1313
  async saveCellImagesAsync(t) {
1293
1314
  var c;
1294
- const r = this._injector.get(V), e = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), i = this.getRange(), a = r.getCellImagesFromRanges(e, n, [i]);
1315
+ const r = this._injector.get(W), e = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), i = this.getRange(), a = r.getCellImagesFromRanges(e, n, [i]);
1295
1316
  if (a.length === 0)
1296
1317
  return !1;
1297
1318
  if (a.length === 1)
@@ -1301,7 +1322,7 @@ class Ie extends q {
1301
1322
  return console.error("Failed to download image:", m), !1;
1302
1323
  }
1303
1324
  const o = [], d = (c = t == null ? void 0 : t.useCellAddress) != null ? c : !0, g = t == null ? void 0 : t.useColumnIndex;
1304
- d && o.push(b.CELL_ADDRESS), g !== void 0 && o.push(b.COLUMN_VALUE), o.length === 0 && o.push(b.CELL_ADDRESS);
1325
+ d && o.push(E.CELL_ADDRESS), g !== void 0 && o.push(E.COLUMN_VALUE), o.length === 0 && o.push(E.CELL_ADDRESS);
1305
1326
  try {
1306
1327
  return await r.saveImagesWithContext(a, {
1307
1328
  fileNameParts: o,