index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { createIdentifier as U, CommandType as E, Disposable as l, UniverInstanceType as h, ICommandService as D, IResourceManagerService as I, DependentOn as w, Inject as O, Injector as R, Plugin as b, merge as p, IConfigService as M } from "@univerjs/core";
  2. import { UnitDrawingService as G, IDrawingManagerService as d, UniverDrawingPlugin as C } from "@univerjs/drawing";
  3. const J = "sheets-drawing.config", v = {};
  4. var j = /* @__PURE__ */ ((e) => (e.Position = "0", e.Both = "1", e.None = "2", e))(j || {});
  5. class L extends G {
  6. }
  7. const u = U("sheets-drawing.sheet-drawing.service");
  8. var F = /* @__PURE__ */ ((e) => (e[e.INSERT = 0] = "INSERT", e[e.REMOVE = 1] = "REMOVE", e[e.UPDATE = 2] = "UPDATE", e[e.ARRANGE = 3] = "ARRANGE", e[e.GROUP = 4] = "GROUP", e[e.UNGROUP = 5] = "UNGROUP", e))(F || {});
  9. const H = {
  10. id: "sheet.mutation.set-drawing-apply",
  11. type: E.MUTATION,
  12. handler: (e, i) => {
  13. const r = e.get(d), t = e.get(u), { op: n, unitId: a, subUnitId: s, type: P, objects: o } = i;
  14. switch (r.applyJson1(a, s, n), t.applyJson1(a, s, n), P) {
  15. case 0:
  16. r.addNotification(o), t.addNotification(o);
  17. break;
  18. case 1:
  19. r.removeNotification(o), t.removeNotification(o);
  20. break;
  21. case 2:
  22. r.updateNotification(o), t.updateNotification(o);
  23. break;
  24. case 3:
  25. r.orderNotification(o), t.orderNotification(o);
  26. break;
  27. case 4:
  28. r.groupUpdateNotification(o);
  29. break;
  30. case 5:
  31. r.ungroupUpdateNotification(o);
  32. break;
  33. }
  34. return !0;
  35. }
  36. };
  37. var W = Object.defineProperty, x = Object.getOwnPropertyDescriptor, V = (e, i, r, t) => {
  38. for (var n = t > 1 ? void 0 : t ? x(i, r) : i, a = e.length - 1, s; a >= 0; a--)
  39. (s = e[a]) && (n = (t ? s(i, r, n) : s(n)) || n);
  40. return t && n && W(i, r, n), n;
  41. }, c = (e, i) => (r, t) => i(r, t, e);
  42. const S = "SHEET_DRAWING_PLUGIN";
  43. let g = class extends l {
  44. constructor(e, i, r, t) {
  45. super(), this._commandService = e, this._sheetDrawingService = i, this._drawingManagerService = r, this._resourceManagerService = t, this._initSnapshot(), this.disposeWithMe(this._commandService.registerCommand(H));
  46. }
  47. _initSnapshot() {
  48. const e = (r, t) => {
  49. const n = t || this._sheetDrawingService.getDrawingDataForUnit(r);
  50. return n ? JSON.stringify(n) : "";
  51. }, i = (r) => {
  52. if (!r)
  53. return {};
  54. try {
  55. return JSON.parse(r);
  56. } catch {
  57. return {};
  58. }
  59. };
  60. this.disposeWithMe(
  61. this._resourceManagerService.registerPluginResource({
  62. pluginName: S,
  63. businesses: [h.UNIVER_SHEET],
  64. toJson: (r, t) => e(r, t),
  65. parseJson: (r) => i(r),
  66. onUnLoad: (r) => {
  67. this._sheetDrawingService.removeDrawingDataForUnit(r), this._drawingManagerService.removeDrawingDataForUnit(r);
  68. },
  69. onLoad: (r, t) => {
  70. this._sheetDrawingService.registerDrawingData(r, t), this._drawingManagerService.registerDrawingData(r, t);
  71. }
  72. })
  73. );
  74. }
  75. };
  76. g = V([
  77. c(0, D),
  78. c(1, u),
  79. c(2, d),
  80. c(3, I)
  81. ], g);
  82. var N = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, B = (e, i, r) => i in e ? N(e, i, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[i] = r, K = (e, i, r, t) => {
  83. for (var n = t > 1 ? void 0 : t ? $(i, r) : i, a = e.length - 1, s; a >= 0; a--)
  84. (s = e[a]) && (n = (t ? s(i, r, n) : s(n)) || n);
  85. return t && n && N(i, r, n), n;
  86. }, f = (e, i) => (r, t) => i(r, t, e), m = (e, i, r) => B(e, typeof i != "symbol" ? i + "" : i, r);
  87. let _ = class extends b {
  88. constructor(e = v, i, r) {
  89. super(), this._config = e, this._injector = i, this._configService = r;
  90. const { ...t } = p(
  91. {},
  92. v,
  93. this._config
  94. );
  95. this._configService.setConfig(J, t);
  96. }
  97. onStarting() {
  98. [
  99. [g],
  100. [u, { useClass: L }]
  101. ].forEach((e) => this._injector.add(e)), this._injector.get(g);
  102. }
  103. };
  104. m(_, "pluginName", S);
  105. m(_, "type", h.UNIVER_SHEET);
  106. _ = K([
  107. w(C),
  108. f(1, O(R)),
  109. f(2, M)
  110. ], _);
  111. export {
  112. F as DrawingApplyType,
  113. u as ISheetDrawingService,
  114. S as SHEET_DRAWING_PLUGIN,
  115. H as SetDrawingApplyMutation,
  116. j as SheetDrawingAnchorType,
  117. _ as UniverSheetsDrawingPlugin
  118. };