index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. var w = Object.defineProperty;
  2. var S = (t, r, e) => r in t ? w(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
  3. var D = (t, r, e) => S(t, typeof r != "symbol" ? r + "" : r, e);
  4. import { createIdentifier as O, Disposable as U, UniverInstanceType as g, IResourceManagerService as I, IUniverInstanceService as P, Plugin as C, merge as N, touchDependencies as M, Inject as b, Injector as j, IConfigService as m } from "@univerjs/core";
  5. import { UnitDrawingService as R, IDrawingManagerService as E } from "@univerjs/drawing";
  6. const G = "docs-drawing.config", d = {};
  7. class v extends R {
  8. }
  9. const h = O("univer.doc.plugin.doc-drawing.service");
  10. var F = Object.defineProperty, J = Object.getOwnPropertyDescriptor, y = (t, r, e, n) => {
  11. for (var i = n > 1 ? void 0 : n ? J(r, e) : r, a = t.length - 1, s; a >= 0; a--)
  12. (s = t[a]) && (i = (n ? s(r, e, i) : s(i)) || i);
  13. return n && i && F(r, e, i), i;
  14. }, o = (t, r) => (e, n) => r(e, n, t);
  15. const l = "DOC_DRAWING_PLUGIN";
  16. let _ = class extends U {
  17. constructor(t, r, e, n) {
  18. super(), this._docDrawingService = t, this._drawingManagerService = r, this._resourceManagerService = e, this._univerInstanceService = n, this._init();
  19. }
  20. _init() {
  21. this._initSnapshot();
  22. }
  23. _initSnapshot() {
  24. const t = (e) => {
  25. const n = this._univerInstanceService.getUnit(e, g.UNIVER_DOC);
  26. if (n) {
  27. const i = n.getSnapshot().drawings, a = n.getSnapshot().drawingsOrder, s = {
  28. data: i != null ? i : {},
  29. order: a != null ? a : []
  30. };
  31. return JSON.stringify(s);
  32. }
  33. return "";
  34. }, r = (e) => {
  35. if (!e)
  36. return { data: {}, order: [] };
  37. try {
  38. return JSON.parse(e);
  39. } catch {
  40. return { data: {}, order: [] };
  41. }
  42. };
  43. this.disposeWithMe(
  44. this._resourceManagerService.registerPluginResource({
  45. pluginName: l,
  46. businesses: [g.UNIVER_DOC],
  47. toJson: (e) => t(e),
  48. parseJson: (e) => r(e),
  49. onUnLoad: (e) => {
  50. this._setDrawingDataForUnit(e, { data: {}, order: [] });
  51. },
  52. onLoad: (e, n) => {
  53. var i, a;
  54. this._setDrawingDataForUnit(e, { data: (i = n.data) != null ? i : {}, order: (a = n.order) != null ? a : [] });
  55. }
  56. })
  57. );
  58. }
  59. _setDrawingDataForUnit(t, r) {
  60. const e = this._univerInstanceService.getUnit(t);
  61. e != null && (e.resetDrawing(r.data, r.order), this.loadDrawingDataForUnit(t));
  62. }
  63. loadDrawingDataForUnit(t) {
  64. const r = this._univerInstanceService.getUnit(t, g.UNIVER_DOC);
  65. if (!r)
  66. return !1;
  67. const e = t, n = r.getDrawings(), i = r.getDrawingsOrder();
  68. if (!n || !i)
  69. return !1;
  70. Object.keys(n).forEach((s) => {
  71. const p = n[s];
  72. n[s] = { ...p };
  73. });
  74. const a = {
  75. [e]: {
  76. unitId: t,
  77. subUnitId: e,
  78. data: n,
  79. order: i
  80. }
  81. };
  82. return this._docDrawingService.registerDrawingData(t, a), this._drawingManagerService.registerDrawingData(t, a), !0;
  83. }
  84. };
  85. _ = y([
  86. o(0, h),
  87. o(1, E),
  88. o(2, I),
  89. o(3, P)
  90. ], _);
  91. var L = Object.defineProperty, x = Object.getOwnPropertyDescriptor, V = (t, r, e, n) => {
  92. for (var i = n > 1 ? void 0 : n ? x(r, e) : r, a = t.length - 1, s; a >= 0; a--)
  93. (s = t[a]) && (i = (n ? s(r, e, i) : s(i)) || i);
  94. return n && i && L(r, e, i), i;
  95. }, u = (t, r) => (e, n) => r(e, n, t), c;
  96. let f = (c = class extends C {
  97. constructor(t = d, r, e) {
  98. super(), this._config = t, this._injector = r, this._configService = e;
  99. const { ...n } = N(
  100. {},
  101. d,
  102. this._config
  103. );
  104. this._configService.setConfig(G, n);
  105. }
  106. onStarting() {
  107. [
  108. [_],
  109. [v],
  110. [h, { useClass: v }]
  111. ].forEach((t) => this._injector.add(t)), M(this._injector, [
  112. [_]
  113. ]);
  114. }
  115. }, D(c, "pluginName", l), D(c, "type", g.UNIVER_DOC), c);
  116. f = V([
  117. u(1, b(j)),
  118. u(2, m)
  119. ], f);
  120. export {
  121. l as DOCS_DRAWING_PLUGIN,
  122. _ as DocDrawingController,
  123. v as DocDrawingService,
  124. h as IDocDrawingService,
  125. f as UniverDocsDrawingPlugin
  126. };