@univerjs/docs-drawing 0.2.1 → 0.2.3

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/README.md CHANGED
@@ -1,16 +1,27 @@
1
1
  # @univerjs/docs-drawing
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@univerjs/docs-drawing)](https://npmjs.org/packages/@univerjs/docs-drawing)
4
- [![license](https://img.shields.io/npm/l/@univerjs/docs-drawing)](https://img.shields.io/npm/l/@univerjs/docs-drawing)
3
+ ## Package Overview
5
4
 
6
- ## Introduction
5
+ | Package Name | UMD Namespace | Version | License | Downloads | Contains CSS | Contains i18n locales |
6
+ | --- | --- | --- | --- | --- | :---: | :---: |
7
+ | `@univerjs/docs-drawing` | `UniverDocsDrawing` | [![][npm-version-shield]][npm-version-link] | ![][npm-license-shield] | ![][npm-downloads-shield] | ❌ | ❌ |
7
8
 
8
- > TODO: Introduction
9
+ ## Introduction
9
10
 
10
11
  ## Usage
11
12
 
12
13
  ### Installation
13
14
 
14
15
  ```shell
15
- npm i @univerjs/docs-drawing
16
+ # Using npm
17
+ npm install @univerjs/docs-drawing
18
+
19
+ # Using pnpm
20
+ pnpm add @univerjs/docs-drawing
16
21
  ```
22
+
23
+ <!-- Links -->
24
+ [npm-version-shield]: https://img.shields.io/npm/v/@univerjs/docs-drawing?style=flat-square
25
+ [npm-version-link]: https://npmjs.com/package/@univerjs/docs-drawing
26
+ [npm-license-shield]: https://img.shields.io/npm/l/@univerjs/docs-drawing?style=flat-square
27
+ [npm-downloads-shield]: https://img.shields.io/npm/dm/@univerjs/docs-drawing?style=flat-square
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var P=Object.defineProperty;var M=(r,t,e)=>t in r?P(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var w=(r,t,e)=>M(r,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),f=require("@wendellhu/redi"),p=require("@univerjs/engine-render"),R=require("@univerjs/docs-ui"),U=require("@univerjs/drawing");class l extends U.UnitDrawingService{}const _=f.createIdentifier("univer.doc.plugin.doc-drawing.service");var O=(r=>(r[r.INSERT=0]="INSERT",r[r.REMOVE=1]="REMOVE",r[r.UPDATE=2]="UPDATE",r[r.ARRANGE=3]="ARRANGE",r[r.GROUP=4]="GROUP",r[r.UNGROUP=5]="UNGROUP",r))(O||{});const I={id:"doc.mutation.set-drawing-apply",type:s.CommandType.MUTATION,handler:(r,t)=>{const e=r.get(U.IDrawingManagerService),i=r.get(_),n=r.get(s.IUniverInstanceService),{op:o,unitId:a,subUnitId:g,type:S,objects:c}=t;switch(e.applyJson1(a,g,o),i.applyJson1(a,g,o),S){case 0:e.addNotification(c),i.addNotification(c);break;case 1:e.removeNotification(c),i.removeNotification(c);break;case 2:e.updateNotification(c),i.updateNotification(c);break;case 3:e.orderNotification(c),i.orderNotification(c);break;case 4:e.groupUpdateNotification(c);break;case 5:e.ungroupUpdateNotification(c);break}const h=n.getUnit(a);return h.getSnapshot().drawings=e.getDrawingData(a,g),h.getSnapshot().drawingsOrder=e.getDrawingOrder(a,g),!0}};var b=Object.defineProperty,E=Object.getOwnPropertyDescriptor,N=(r,t,e,i)=>{for(var n=i>1?void 0:i?E(t,e):t,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&b(t,e,n),n},d=(r,t)=>(e,i)=>t(e,i,r);const m="DOC_DRAWING_PLUGIN";let D=class extends s.Disposable{constructor(r){super(),this._commandService=r,this.disposeWithMe(this._commandService.registerCommand(I))}};D=N([s.OnLifecycle(s.LifecycleStages.Starting,D),d(0,s.ICommandService)],D);let u=class extends s.Disposable{constructor(r,t,e,i,n){super(),this._docDrawingService=r,this._drawingManagerService=t,this._resourceManagerService=e,this._univerInstanceService=i,this._textSelectionRenderManager=n,this._init()}_init(){this._initSnapshot(),this._initDataLoader()}_initSnapshot(){const r=e=>{const i=this._docDrawingService.getDrawingDataForUnit(e);return i?JSON.stringify(i):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:m,businesses:[s.UniverInstanceType.UNIVER_DOC],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._docDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e),this._setDrawingDataForUnit(e,{data:{},order:[]})},onLoad:(e,i)=>{this._docDrawingService.registerDrawingData(e,i),this._drawingManagerService.registerDrawingData(e,i),this._setDrawingDataForUnit(e,i[e])}}))}_setDrawingDataForUnit(r,t){const e=this._univerInstanceService.getUnit(r);e!=null&&e.resetDrawing(t.data,t.order)}_initDataLoader(){const r=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC);if(!r)return!1;const t=r.getUnitId(),e=t,i=r.getDrawings(),n=r.getDrawingsOrder();if(!i||!n)return!1;Object.keys(i).forEach(a=>{const g=i[a],S=g.docTransform,c=R.docDrawingPositionToTransform(S);i[a]={...g,transform:c}});const o={[e]:{unitId:t,subUnitId:e,data:i,order:n}};return this._docDrawingService.registerDrawingData(t,o),this._drawingManagerService.registerDrawingData(t,o),!0}};u=N([s.OnLifecycle(s.LifecycleStages.Rendered,u),d(0,_),d(1,U.IDrawingManagerService),d(2,s.IResourceManagerService),d(3,s.IUniverInstanceService),d(4,p.ITextSelectionRenderManager)],u);var C=Object.defineProperty,L=Object.getOwnPropertyDescriptor,G=(r,t,e,i)=>{for(var n=i>1?void 0:i?L(t,e):t,o=r.length-1,a;o>=0;o--)(a=r[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&C(t,e,n),n},j=(r,t)=>(e,i)=>t(e,i,r),v;exports.UniverDocsDrawingPlugin=(v=class extends s.Plugin{constructor(t,e){super(),this._injector=e}onStarting(t){[[D],[u],[l],[_,{useClass:l}]].forEach(e=>t.add(e))}},w(v,"pluginName",m),w(v,"type",s.UniverInstanceType.UNIVER_DOC),v);exports.UniverDocsDrawingPlugin=G([j(1,f.Inject(f.Injector))],exports.UniverDocsDrawingPlugin);exports.DocDrawingApplyType=O;exports.DocDrawingService=l;exports.IDocDrawingService=_;exports.SetDocDrawingApplyMutation=I;
1
+ "use strict";var b=Object.defineProperty;var p=(r,i,e)=>i in r?b(r,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[i]=e;var S=(r,i,e)=>p(r,typeof i!="symbol"?i+"":i,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),l=require("@wendellhu/redi"),U=require("@univerjs/drawing"),h=require("rxjs/operators");class f extends U.UnitDrawingService{}const D=l.createIdentifier("univer.doc.plugin.doc-drawing.service");var w=(r=>(r[r.INSERT=0]="INSERT",r[r.REMOVE=1]="REMOVE",r[r.UPDATE=2]="UPDATE",r[r.ARRANGE=3]="ARRANGE",r[r.GROUP=4]="GROUP",r[r.UNGROUP=5]="UNGROUP",r))(w||{});const N={id:"doc.mutation.set-drawing-apply",type:a.CommandType.MUTATION,handler:(r,i)=>{const e=r.get(U.IDrawingManagerService),t=r.get(D),n=r.get(a.IUniverInstanceService),{op:s,unitId:c,subUnitId:g,type:P,objects:o}=i;switch(e.applyJson1(c,g,s),t.applyJson1(c,g,s),P){case 0:e.addNotification(o),t.addNotification(o);break;case 1:e.removeNotification(o),t.removeNotification(o);break;case 2:e.updateNotification(o),t.updateNotification(o);break;case 3:e.orderNotification(o),t.orderNotification(o);break;case 4:e.groupUpdateNotification(o);break;case 5:e.ungroupUpdateNotification(o);break}return n.getUnit(c),!0}};var R=Object.defineProperty,M=Object.getOwnPropertyDescriptor,O=(r,i,e,t)=>{for(var n=t>1?void 0:t?M(i,e):i,s=r.length-1,c;s>=0;s--)(c=r[s])&&(n=(t?c(i,e,n):c(n))||n);return t&&n&&R(i,e,n),n},d=(r,i)=>(e,t)=>i(e,t,r);const I="DOC_DRAWING_PLUGIN";let v=class extends a.Disposable{constructor(r){super(),this._commandService=r,this.disposeWithMe(this._commandService.registerCommand(N))}};v=O([a.OnLifecycle(a.LifecycleStages.Starting,v),d(0,a.ICommandService)],v);let _=class extends a.Disposable{constructor(r,i,e,t,n){super(),this._docDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=e,this._univerInstanceService=t,this._lifecycleService=n,this._init()}_init(){this._initSnapshot(),this._drawingInitializeListener()}_initSnapshot(){const r=e=>{const t=this._docDrawingService.getDrawingDataForUnit(e);return t!=null&&t[e]?JSON.stringify(t==null?void 0:t[e]):""},i=e=>{if(!e)return{data:{},order:[]};try{return JSON.parse(e)}catch{return{data:{},order:[]}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:I,businesses:[a.UniverInstanceType.UNIVER_DOC],toJson:e=>r(e),parseJson:e=>i(e),onUnLoad:e=>{this._setDrawingDataForUnit(e,{data:{},order:[]})},onLoad:(e,t)=>{var n,s;this._setDrawingDataForUnit(e,{data:(n=t.data)!=null?n:{},order:(s=t.order)!=null?s:[]})}}))}_setDrawingDataForUnit(r,i){const e=this._univerInstanceService.getUnit(r);e!=null&&(e.resetDrawing(i.data,i.order),this._initDataLoader())}_initDataLoader(){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!r)return!1;const i=r.getUnitId(),e=i,t=r.getDrawings(),n=r.getDrawingsOrder();if(!t||!n)return!1;Object.keys(t).forEach(c=>{const g=t[c];t[c]={...g}});const s={[e]:{unitId:i,subUnitId:e,data:t,order:n}};return this._docDrawingService.registerDrawingData(i,s),this._drawingManagerService.registerDrawingData(i,s),!0}_drawingInitializeListener(){this._lifecycleService.lifecycle$.pipe(h.filter(r=>r===a.LifecycleStages.Rendered),h.first()).subscribe(r=>{var e;const i=(e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC))==null?void 0:e.getUnitId();i&&(this._docDrawingService.initializeNotification(i),this._drawingManagerService.initializeNotification(i))})}};_=O([a.OnLifecycle(a.LifecycleStages.Starting,_),d(0,D),d(1,U.IDrawingManagerService),d(2,a.IResourceManagerService),d(3,a.IUniverInstanceService),d(4,l.Inject(a.LifecycleService))],_);var C=Object.defineProperty,E=Object.getOwnPropertyDescriptor,L=(r,i,e,t)=>{for(var n=t>1?void 0:t?E(i,e):i,s=r.length-1,c;s>=0;s--)(c=r[s])&&(n=(t?c(i,e,n):c(n))||n);return t&&n&&C(i,e,n),n},m=(r,i)=>(e,t)=>i(e,t,r),u;exports.UniverDocsDrawingPlugin=(u=class extends a.Plugin{constructor(i,e){super(),this._injector=e}onStarting(i){[[v],[_],[f],[D,{useClass:f}]].forEach(e=>i.add(e))}},S(u,"pluginName",I),S(u,"type",a.UniverInstanceType.UNIVER_DOC),u);exports.UniverDocsDrawingPlugin=L([m(1,l.Inject(l.Injector))],exports.UniverDocsDrawingPlugin);exports.DOCS_DRAWING_PLUGIN=I;exports.DocDrawingApplyType=w;exports.DocDrawingService=f;exports.IDocDrawingService=D;exports.SetDocDrawingApplyMutation=N;
package/lib/es/index.js CHANGED
@@ -1,153 +1,160 @@
1
- var R = Object.defineProperty;
2
- var p = (r, t, e) => t in r ? R(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var D = (r, t, e) => p(r, typeof t != "symbol" ? t + "" : t, e);
4
- import { CommandType as b, IUniverInstanceService as U, OnLifecycle as l, LifecycleStages as N, Disposable as O, ICommandService as E, UniverInstanceType as f, IResourceManagerService as C, Plugin as G } from "@univerjs/core";
5
- import { createIdentifier as L, Inject as j, Injector as J } from "@wendellhu/redi";
6
- import { ITextSelectionRenderManager as x } from "@univerjs/engine-render";
7
- import { docDrawingPositionToTransform as F } from "@univerjs/docs-ui";
8
- import { UnitDrawingService as V, IDrawingManagerService as I } from "@univerjs/drawing";
9
- class m extends V {
1
+ var b = Object.defineProperty;
2
+ var M = (e, r, t) => r in e ? b(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
+ var f = (e, r, t) => M(e, typeof r != "symbol" ? r + "" : r, t);
4
+ import { CommandType as p, IUniverInstanceService as D, OnLifecycle as I, LifecycleStages as l, LifecycleService as C, Disposable as N, ICommandService as E, UniverInstanceType as u, IResourceManagerService as L, Plugin as G } from "@univerjs/core";
5
+ import { createIdentifier as j, Inject as O, Injector as J } from "@wendellhu/redi";
6
+ import { UnitDrawingService as F, IDrawingManagerService as w } from "@univerjs/drawing";
7
+ import { filter as V, first as x } from "rxjs/operators";
8
+ class h extends F {
10
9
  }
11
- const S = L("univer.doc.plugin.doc-drawing.service");
12
- var W = /* @__PURE__ */ ((r) => (r[r.INSERT = 0] = "INSERT", r[r.REMOVE = 1] = "REMOVE", r[r.UPDATE = 2] = "UPDATE", r[r.ARRANGE = 3] = "ARRANGE", r[r.GROUP = 4] = "GROUP", r[r.UNGROUP = 5] = "UNGROUP", r))(W || {});
13
- const $ = {
10
+ const S = j("univer.doc.plugin.doc-drawing.service");
11
+ var $ = /* @__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))($ || {});
12
+ const z = {
14
13
  id: "doc.mutation.set-drawing-apply",
15
- type: b.MUTATION,
16
- handler: (r, t) => {
17
- const e = r.get(I), i = r.get(S), n = r.get(U), { op: o, unitId: a, subUnitId: c, type: u, objects: s } = t;
18
- switch (e.applyJson1(a, c, o), i.applyJson1(a, c, o), u) {
14
+ type: p.MUTATION,
15
+ handler: (e, r) => {
16
+ const t = e.get(w), i = e.get(S), n = e.get(D), { op: a, unitId: s, subUnitId: d, type: R, objects: o } = r;
17
+ switch (t.applyJson1(s, d, a), i.applyJson1(s, d, a), R) {
19
18
  case 0:
20
- e.addNotification(s), i.addNotification(s);
19
+ t.addNotification(o), i.addNotification(o);
21
20
  break;
22
21
  case 1:
23
- e.removeNotification(s), i.removeNotification(s);
22
+ t.removeNotification(o), i.removeNotification(o);
24
23
  break;
25
24
  case 2:
26
- e.updateNotification(s), i.updateNotification(s);
25
+ t.updateNotification(o), i.updateNotification(o);
27
26
  break;
28
27
  case 3:
29
- e.orderNotification(s), i.orderNotification(s);
28
+ t.orderNotification(o), i.orderNotification(o);
30
29
  break;
31
30
  case 4:
32
- e.groupUpdateNotification(s);
31
+ t.groupUpdateNotification(o);
33
32
  break;
34
33
  case 5:
35
- e.ungroupUpdateNotification(s);
34
+ t.ungroupUpdateNotification(o);
36
35
  break;
37
36
  }
38
- const h = n.getUnit(a);
39
- return h.getSnapshot().drawings = e.getDrawingData(a, c), h.getSnapshot().drawingsOrder = e.getDrawingOrder(a, c), !0;
37
+ return n.getUnit(s), !0;
40
38
  }
41
39
  };
42
- var T = Object.defineProperty, q = Object.getOwnPropertyDescriptor, M = (r, t, e, i) => {
43
- for (var n = i > 1 ? void 0 : i ? q(t, e) : t, o = r.length - 1, a; o >= 0; o--)
44
- (a = r[o]) && (n = (i ? a(t, e, n) : a(n)) || n);
45
- return i && n && T(t, e, n), n;
46
- }, g = (r, t) => (e, i) => t(e, i, r);
40
+ var W = Object.defineProperty, q = Object.getOwnPropertyDescriptor, m = (e, r, t, i) => {
41
+ for (var n = i > 1 ? void 0 : i ? q(r, t) : r, a = e.length - 1, s; a >= 0; a--)
42
+ (s = e[a]) && (n = (i ? s(r, t, n) : s(n)) || n);
43
+ return i && n && W(r, t, n), n;
44
+ }, c = (e, r) => (t, i) => r(t, i, e);
47
45
  const P = "DOC_DRAWING_PLUGIN";
48
- let v = class extends O {
49
- constructor(r) {
50
- super(), this._commandService = r, this.disposeWithMe(this._commandService.registerCommand($));
46
+ let v = class extends N {
47
+ constructor(e) {
48
+ super(), this._commandService = e, this.disposeWithMe(this._commandService.registerCommand(z));
51
49
  }
52
50
  };
53
- v = M([
54
- l(N.Starting, v),
55
- g(0, E)
51
+ v = m([
52
+ I(l.Starting, v),
53
+ c(0, E)
56
54
  ], v);
57
- let _ = class extends O {
58
- constructor(r, t, e, i, n) {
59
- super(), this._docDrawingService = r, this._drawingManagerService = t, this._resourceManagerService = e, this._univerInstanceService = i, this._textSelectionRenderManager = n, this._init();
55
+ let _ = class extends N {
56
+ constructor(e, r, t, i, n) {
57
+ super(), this._docDrawingService = e, this._drawingManagerService = r, this._resourceManagerService = t, this._univerInstanceService = i, this._lifecycleService = n, this._init();
60
58
  }
61
59
  _init() {
62
- this._initSnapshot(), this._initDataLoader();
60
+ this._initSnapshot(), this._drawingInitializeListener();
63
61
  }
64
62
  _initSnapshot() {
65
- const r = (e) => {
66
- const i = this._docDrawingService.getDrawingDataForUnit(e);
67
- return i ? JSON.stringify(i) : "";
68
- }, t = (e) => {
69
- if (!e)
70
- return {};
63
+ const e = (t) => {
64
+ const i = this._docDrawingService.getDrawingDataForUnit(t);
65
+ return i != null && i[t] ? JSON.stringify(i == null ? void 0 : i[t]) : "";
66
+ }, r = (t) => {
67
+ if (!t)
68
+ return { data: {}, order: [] };
71
69
  try {
72
- return JSON.parse(e);
70
+ return JSON.parse(t);
73
71
  } catch {
74
- return {};
72
+ return { data: {}, order: [] };
75
73
  }
76
74
  };
77
75
  this.disposeWithMe(
78
76
  this._resourceManagerService.registerPluginResource({
79
77
  pluginName: P,
80
- businesses: [f.UNIVER_DOC],
81
- toJson: (e) => r(e),
82
- parseJson: (e) => t(e),
83
- onUnLoad: (e) => {
84
- this._docDrawingService.removeDrawingDataForUnit(e), this._drawingManagerService.removeDrawingDataForUnit(e), this._setDrawingDataForUnit(e, { data: {}, order: [] });
78
+ businesses: [u.UNIVER_DOC],
79
+ toJson: (t) => e(t),
80
+ parseJson: (t) => r(t),
81
+ onUnLoad: (t) => {
82
+ this._setDrawingDataForUnit(t, { data: {}, order: [] });
85
83
  },
86
- onLoad: (e, i) => {
87
- this._docDrawingService.registerDrawingData(e, i), this._drawingManagerService.registerDrawingData(e, i), this._setDrawingDataForUnit(e, i[e]);
84
+ onLoad: (t, i) => {
85
+ var n, a;
86
+ this._setDrawingDataForUnit(t, { data: (n = i.data) != null ? n : {}, order: (a = i.order) != null ? a : [] });
88
87
  }
89
88
  })
90
89
  );
91
90
  }
92
- _setDrawingDataForUnit(r, t) {
93
- const e = this._univerInstanceService.getUnit(r);
94
- e != null && e.resetDrawing(t.data, t.order);
91
+ _setDrawingDataForUnit(e, r) {
92
+ const t = this._univerInstanceService.getUnit(e);
93
+ t != null && (t.resetDrawing(r.data, r.order), this._initDataLoader());
95
94
  }
96
95
  _initDataLoader() {
97
- const r = this._univerInstanceService.getCurrentUnitForType(f.UNIVER_DOC);
98
- if (!r)
96
+ const e = this._univerInstanceService.getCurrentUnitForType(u.UNIVER_DOC);
97
+ if (!e)
99
98
  return !1;
100
- const t = r.getUnitId(), e = t, i = r.getDrawings(), n = r.getDrawingsOrder();
99
+ const r = e.getUnitId(), t = r, i = e.getDrawings(), n = e.getDrawingsOrder();
101
100
  if (!i || !n)
102
101
  return !1;
103
- Object.keys(i).forEach((a) => {
104
- const c = i[a], u = c.docTransform, s = F(u);
105
- i[a] = { ...c, transform: s };
102
+ Object.keys(i).forEach((s) => {
103
+ const d = i[s];
104
+ i[s] = { ...d };
106
105
  });
107
- const o = {
108
- [e]: {
109
- unitId: t,
110
- subUnitId: e,
106
+ const a = {
107
+ [t]: {
108
+ unitId: r,
109
+ subUnitId: t,
111
110
  data: i,
112
111
  order: n
113
112
  }
114
113
  };
115
- return this._docDrawingService.registerDrawingData(t, o), this._drawingManagerService.registerDrawingData(t, o), !0;
114
+ return this._docDrawingService.registerDrawingData(r, a), this._drawingManagerService.registerDrawingData(r, a), !0;
115
+ }
116
+ _drawingInitializeListener() {
117
+ this._lifecycleService.lifecycle$.pipe(V((e) => e === l.Rendered), x()).subscribe((e) => {
118
+ var t;
119
+ const r = (t = this._univerInstanceService.getCurrentUnitForType(u.UNIVER_DOC)) == null ? void 0 : t.getUnitId();
120
+ r && (this._docDrawingService.initializeNotification(r), this._drawingManagerService.initializeNotification(r));
121
+ });
116
122
  }
117
123
  };
118
- _ = M([
119
- l(N.Rendered, _),
120
- g(0, S),
121
- g(1, I),
122
- g(2, C),
123
- g(3, U),
124
- g(4, x)
124
+ _ = m([
125
+ I(l.Starting, _),
126
+ c(0, S),
127
+ c(1, w),
128
+ c(2, L),
129
+ c(3, D),
130
+ c(4, O(C))
125
131
  ], _);
126
- var z = Object.defineProperty, B = Object.getOwnPropertyDescriptor, H = (r, t, e, i) => {
127
- for (var n = i > 1 ? void 0 : i ? B(t, e) : t, o = r.length - 1, a; o >= 0; o--)
128
- (a = r[o]) && (n = (i ? a(t, e, n) : a(n)) || n);
129
- return i && n && z(t, e, n), n;
130
- }, K = (r, t) => (e, i) => t(e, i, r), d;
131
- let w = (d = class extends G {
132
- constructor(r, t) {
133
- super(), this._injector = t;
132
+ var B = Object.defineProperty, H = Object.getOwnPropertyDescriptor, K = (e, r, t, i) => {
133
+ for (var n = i > 1 ? void 0 : i ? H(r, t) : r, a = e.length - 1, s; a >= 0; a--)
134
+ (s = e[a]) && (n = (i ? s(r, t, n) : s(n)) || n);
135
+ return i && n && B(r, t, n), n;
136
+ }, Q = (e, r) => (t, i) => r(t, i, e), g;
137
+ let U = (g = class extends G {
138
+ constructor(e, r) {
139
+ super(), this._injector = r;
134
140
  }
135
- onStarting(r) {
141
+ onStarting(e) {
136
142
  [
137
143
  [v],
138
144
  [_],
139
- [m],
140
- [S, { useClass: m }]
141
- ].forEach((t) => r.add(t));
145
+ [h],
146
+ [S, { useClass: h }]
147
+ ].forEach((r) => e.add(r));
142
148
  }
143
- }, D(d, "pluginName", P), D(d, "type", f.UNIVER_DOC), d);
144
- w = H([
145
- K(1, j(J))
146
- ], w);
149
+ }, f(g, "pluginName", P), f(g, "type", u.UNIVER_DOC), g);
150
+ U = K([
151
+ Q(1, O(J))
152
+ ], U);
147
153
  export {
148
- W as DocDrawingApplyType,
149
- m as DocDrawingService,
154
+ P as DOCS_DRAWING_PLUGIN,
155
+ $ as DocDrawingApplyType,
156
+ h as DocDrawingService,
150
157
  S as IDocDrawingService,
151
- $ as SetDocDrawingApplyMutation,
152
- w as UniverDocsDrawingPlugin
158
+ z as SetDocDrawingApplyMutation,
159
+ U as UniverDocsDrawingPlugin
153
160
  };
@@ -1,9 +1,12 @@
1
- import { Disposable, ICommandService, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
2
- import { ITextSelectionRenderManager } from '@univerjs/engine-render';
1
+ import { IDocumentData, Disposable, ICommandService, IResourceManagerService, IUniverInstanceService, LifecycleService } from '@univerjs/core';
3
2
  import { IDrawingManagerService } from '@univerjs/drawing';
4
3
  import { IDocDrawingService } from '../services/doc-drawing.service';
5
4
 
6
5
  export declare const DOCS_DRAWING_PLUGIN = "DOC_DRAWING_PLUGIN";
6
+ export interface IDocDrawingModel {
7
+ drawings?: IDocumentData['drawings'];
8
+ drawingsOrder?: IDocumentData['drawingsOrder'];
9
+ }
7
10
  export declare class DocDrawingLoadController extends Disposable {
8
11
  private readonly _commandService;
9
12
  constructor(_commandService: ICommandService);
@@ -13,10 +16,11 @@ export declare class DocDrawingController extends Disposable {
13
16
  private readonly _drawingManagerService;
14
17
  private _resourceManagerService;
15
18
  private _univerInstanceService;
16
- private readonly _textSelectionRenderManager;
17
- constructor(_docDrawingService: IDocDrawingService, _drawingManagerService: IDrawingManagerService, _resourceManagerService: IResourceManagerService, _univerInstanceService: IUniverInstanceService, _textSelectionRenderManager: ITextSelectionRenderManager);
19
+ private _lifecycleService;
20
+ constructor(_docDrawingService: IDocDrawingService, _drawingManagerService: IDrawingManagerService, _resourceManagerService: IResourceManagerService, _univerInstanceService: IUniverInstanceService, _lifecycleService: LifecycleService);
18
21
  private _init;
19
22
  private _initSnapshot;
20
23
  private _setDrawingDataForUnit;
21
24
  private _initDataLoader;
25
+ private _drawingInitializeListener;
22
26
  }
@@ -15,4 +15,5 @@
15
15
  */
16
16
  export { UniverDocsDrawingPlugin } from './plugin';
17
17
  export { type IDocDrawing, IDocDrawingService, DocDrawingService } from './services/doc-drawing.service';
18
+ export { DOCS_DRAWING_PLUGIN, type IDocDrawingModel } from './controllers/doc-drawing.controller';
18
19
  export { SetDocDrawingApplyMutation, DocDrawingApplyType, type ISetDrawingApplyMutationParams } from './commands/mutations/set-drawing-apply.mutation';
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/engine-render"),require("@univerjs/docs-ui"),require("@univerjs/drawing")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/engine-render","@univerjs/docs-ui","@univerjs/drawing"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.UniverDocsDrawing={},a.UniverCore,a["@wendellhu/redi"],a.UniverEngineRender,a.UniverDocsUi,a.UniverDrawing))})(this,function(a,t,g,M,p,w){"use strict";var G=Object.defineProperty;var T=(a,t,g)=>t in a?G(a,t,{enumerable:!0,configurable:!0,writable:!0,value:g}):a[t]=g;var l=(a,t,g)=>T(a,typeof t!="symbol"?t+"":t,g);var S;class U extends w.UnitDrawingService{}const D=g.createIdentifier("univer.doc.plugin.doc-drawing.service");var O=(r=>(r[r.INSERT=0]="INSERT",r[r.REMOVE=1]="REMOVE",r[r.UPDATE=2]="UPDATE",r[r.ARRANGE=3]="ARRANGE",r[r.GROUP=4]="GROUP",r[r.UNGROUP=5]="UNGROUP",r))(O||{});const I={id:"doc.mutation.set-drawing-apply",type:t.CommandType.MUTATION,handler:(r,i)=>{const e=r.get(w.IDrawingManagerService),n=r.get(D),s=r.get(t.IUniverInstanceService),{op:c,unitId:o,subUnitId:u,type:h,objects:d}=i;switch(e.applyJson1(o,u,c),n.applyJson1(o,u,c),h){case 0:e.addNotification(d),n.addNotification(d);break;case 1:e.removeNotification(d),n.removeNotification(d);break;case 2:e.updateNotification(d),n.updateNotification(d);break;case 3:e.orderNotification(d),n.orderNotification(d);break;case 4:e.groupUpdateNotification(d);break;case 5:e.ungroupUpdateNotification(d);break}const P=s.getUnit(o);return P.getSnapshot().drawings=e.getDrawingData(o,u),P.getSnapshot().drawingsOrder=e.getDrawingOrder(o,u),!0}};var R=Object.defineProperty,j=Object.getOwnPropertyDescriptor,m=(r,i,e,n)=>{for(var s=n>1?void 0:n?j(i,e):i,c=r.length-1,o;c>=0;c--)(o=r[c])&&(s=(n?o(i,e,s):o(s))||s);return n&&s&&R(i,e,s),s},v=(r,i)=>(e,n)=>i(e,n,r);const N="DOC_DRAWING_PLUGIN";let f=class extends t.Disposable{constructor(r){super(),this._commandService=r,this.disposeWithMe(this._commandService.registerCommand(I))}};f=m([t.OnLifecycle(t.LifecycleStages.Starting,f),v(0,t.ICommandService)],f);let _=class extends t.Disposable{constructor(r,i,e,n,s){super(),this._docDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=e,this._univerInstanceService=n,this._textSelectionRenderManager=s,this._init()}_init(){this._initSnapshot(),this._initDataLoader()}_initSnapshot(){const r=e=>{const n=this._docDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):""},i=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:N,businesses:[t.UniverInstanceType.UNIVER_DOC],toJson:e=>r(e),parseJson:e=>i(e),onUnLoad:e=>{this._docDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e),this._setDrawingDataForUnit(e,{data:{},order:[]})},onLoad:(e,n)=>{this._docDrawingService.registerDrawingData(e,n),this._drawingManagerService.registerDrawingData(e,n),this._setDrawingDataForUnit(e,n[e])}}))}_setDrawingDataForUnit(r,i){const e=this._univerInstanceService.getUnit(r);e!=null&&e.resetDrawing(i.data,i.order)}_initDataLoader(){const r=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_DOC);if(!r)return!1;const i=r.getUnitId(),e=i,n=r.getDrawings(),s=r.getDrawingsOrder();if(!n||!s)return!1;Object.keys(n).forEach(o=>{const u=n[o],h=u.docTransform,d=p.docDrawingPositionToTransform(h);n[o]={...u,transform:d}});const c={[e]:{unitId:i,subUnitId:e,data:n,order:s}};return this._docDrawingService.registerDrawingData(i,c),this._drawingManagerService.registerDrawingData(i,c),!0}};_=m([t.OnLifecycle(t.LifecycleStages.Rendered,_),v(0,D),v(1,w.IDrawingManagerService),v(2,t.IResourceManagerService),v(3,t.IUniverInstanceService),v(4,M.ITextSelectionRenderManager)],_);var b=Object.defineProperty,E=Object.getOwnPropertyDescriptor,C=(r,i,e,n)=>{for(var s=n>1?void 0:n?E(i,e):i,c=r.length-1,o;c>=0;c--)(o=r[c])&&(s=(n?o(i,e,s):o(s))||s);return n&&s&&b(i,e,s),s},L=(r,i)=>(e,n)=>i(e,n,r);a.UniverDocsDrawingPlugin=(S=class extends t.Plugin{constructor(i,e){super(),this._injector=e}onStarting(i){[[f],[_],[U],[D,{useClass:U}]].forEach(e=>i.add(e))}},l(S,"pluginName",N),l(S,"type",t.UniverInstanceType.UNIVER_DOC),S),a.UniverDocsDrawingPlugin=C([L(1,g.Inject(g.Injector))],a.UniverDocsDrawingPlugin),a.DocDrawingApplyType=O,a.DocDrawingService=U,a.IDocDrawingService=D,a.SetDocDrawingApplyMutation=I,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/drawing"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/drawing","rxjs/operators"],n):(s=typeof globalThis<"u"?globalThis:s||self,n(s.UniverDocsDrawing={},s.UniverCore,s["@wendellhu/redi"],s.UniverDrawing,s.rxjs.operators))})(this,function(s,n,u,S,w){"use strict";var E=Object.defineProperty;var L=(s,n,u)=>n in s?E(s,n,{enumerable:!0,configurable:!0,writable:!0,value:u}):s[n]=u;var I=(s,n,u)=>L(s,typeof n!="symbol"?n+"":n,u);var D;class U extends S.UnitDrawingService{}const v=u.createIdentifier("univer.doc.plugin.doc-drawing.service");var N=(i=>(i[i.INSERT=0]="INSERT",i[i.REMOVE=1]="REMOVE",i[i.UPDATE=2]="UPDATE",i[i.ARRANGE=3]="ARRANGE",i[i.GROUP=4]="GROUP",i[i.UNGROUP=5]="UNGROUP",i))(N||{});const O={id:"doc.mutation.set-drawing-apply",type:n.CommandType.MUTATION,handler:(i,r)=>{const e=i.get(S.IDrawingManagerService),t=i.get(v),a=i.get(n.IUniverInstanceService),{op:c,unitId:o,subUnitId:l,type:m,objects:d}=r;switch(e.applyJson1(o,l,c),t.applyJson1(o,l,c),m){case 0:e.addNotification(d),t.addNotification(d);break;case 1:e.removeNotification(d),t.removeNotification(d);break;case 2:e.updateNotification(d),t.updateNotification(d);break;case 3:e.orderNotification(d),t.orderNotification(d);break;case 4:e.groupUpdateNotification(d);break;case 5:e.ungroupUpdateNotification(d);break}return a.getUnit(o),!0}};var p=Object.defineProperty,R=Object.getOwnPropertyDescriptor,P=(i,r,e,t)=>{for(var a=t>1?void 0:t?R(r,e):r,c=i.length-1,o;c>=0;c--)(o=i[c])&&(a=(t?o(r,e,a):o(a))||a);return t&&a&&p(r,e,a),a},g=(i,r)=>(e,t)=>r(e,t,i);const h="DOC_DRAWING_PLUGIN";let f=class extends n.Disposable{constructor(i){super(),this._commandService=i,this.disposeWithMe(this._commandService.registerCommand(O))}};f=P([n.OnLifecycle(n.LifecycleStages.Starting,f),g(0,n.ICommandService)],f);let _=class extends n.Disposable{constructor(i,r,e,t,a){super(),this._docDrawingService=i,this._drawingManagerService=r,this._resourceManagerService=e,this._univerInstanceService=t,this._lifecycleService=a,this._init()}_init(){this._initSnapshot(),this._drawingInitializeListener()}_initSnapshot(){const i=e=>{const t=this._docDrawingService.getDrawingDataForUnit(e);return t!=null&&t[e]?JSON.stringify(t==null?void 0:t[e]):""},r=e=>{if(!e)return{data:{},order:[]};try{return JSON.parse(e)}catch{return{data:{},order:[]}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:h,businesses:[n.UniverInstanceType.UNIVER_DOC],toJson:e=>i(e),parseJson:e=>r(e),onUnLoad:e=>{this._setDrawingDataForUnit(e,{data:{},order:[]})},onLoad:(e,t)=>{var a,c;this._setDrawingDataForUnit(e,{data:(a=t.data)!=null?a:{},order:(c=t.order)!=null?c:[]})}}))}_setDrawingDataForUnit(i,r){const e=this._univerInstanceService.getUnit(i);e!=null&&(e.resetDrawing(r.data,r.order),this._initDataLoader())}_initDataLoader(){const i=this._univerInstanceService.getCurrentUnitForType(n.UniverInstanceType.UNIVER_DOC);if(!i)return!1;const r=i.getUnitId(),e=r,t=i.getDrawings(),a=i.getDrawingsOrder();if(!t||!a)return!1;Object.keys(t).forEach(o=>{const l=t[o];t[o]={...l}});const c={[e]:{unitId:r,subUnitId:e,data:t,order:a}};return this._docDrawingService.registerDrawingData(r,c),this._drawingManagerService.registerDrawingData(r,c),!0}_drawingInitializeListener(){this._lifecycleService.lifecycle$.pipe(w.filter(i=>i===n.LifecycleStages.Rendered),w.first()).subscribe(i=>{var e;const r=(e=this._univerInstanceService.getCurrentUnitForType(n.UniverInstanceType.UNIVER_DOC))==null?void 0:e.getUnitId();r&&(this._docDrawingService.initializeNotification(r),this._drawingManagerService.initializeNotification(r))})}};_=P([n.OnLifecycle(n.LifecycleStages.Starting,_),g(0,v),g(1,S.IDrawingManagerService),g(2,n.IResourceManagerService),g(3,n.IUniverInstanceService),g(4,u.Inject(n.LifecycleService))],_);var M=Object.defineProperty,b=Object.getOwnPropertyDescriptor,j=(i,r,e,t)=>{for(var a=t>1?void 0:t?b(r,e):r,c=i.length-1,o;c>=0;c--)(o=i[c])&&(a=(t?o(r,e,a):o(a))||a);return t&&a&&M(r,e,a),a},C=(i,r)=>(e,t)=>r(e,t,i);s.UniverDocsDrawingPlugin=(D=class extends n.Plugin{constructor(r,e){super(),this._injector=e}onStarting(r){[[f],[_],[U],[v,{useClass:U}]].forEach(e=>r.add(e))}},I(D,"pluginName",h),I(D,"type",n.UniverInstanceType.UNIVER_DOC),D),s.UniverDocsDrawingPlugin=j([C(1,u.Inject(u.Injector))],s.UniverDocsDrawingPlugin),s.DOCS_DRAWING_PLUGIN=h,s.DocDrawingApplyType=N,s.DocDrawingService=U,s.IDocDrawingService=v,s.SetDocDrawingApplyMutation=O,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs-drawing",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -45,22 +45,20 @@
45
45
  ],
46
46
  "peerDependencies": {
47
47
  "@wendellhu/redi": "0.15.5",
48
- "@univerjs/core": "0.2.1",
49
- "@univerjs/docs-ui": "0.2.1",
50
- "@univerjs/drawing": "0.2.1",
51
- "@univerjs/engine-render": "0.2.1"
48
+ "rxjs": ">=7.0.0",
49
+ "@univerjs/core": "0.2.3",
50
+ "@univerjs/drawing": "0.2.3"
52
51
  },
53
52
  "devDependencies": {
54
53
  "@wendellhu/redi": "0.15.5",
55
54
  "typescript": "^5.5.3",
56
55
  "vite": "^5.3.3",
57
56
  "vitest": "^1.6.0",
58
- "@univerjs/core": "0.2.1",
59
- "@univerjs/docs": "0.2.1",
60
- "@univerjs/docs-ui": "0.2.1",
61
- "@univerjs/drawing": "0.2.1",
62
- "@univerjs/shared": "0.2.1",
63
- "@univerjs/engine-render": "0.2.1"
57
+ "@univerjs/docs": "0.2.3",
58
+ "@univerjs/core": "0.2.3",
59
+ "@univerjs/drawing": "0.2.3",
60
+ "@univerjs/shared": "0.2.3",
61
+ "@univerjs/engine-render": "0.2.3"
64
62
  },
65
63
  "univerSpace": {
66
64
  ".": {