@univerjs/docs-drawing 0.20.1 → 0.21.0

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/cjs/index.js CHANGED
@@ -1 +1,231 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/drawing`);var n=class extends t.UnitDrawingService{};const r=(0,e.createIdentifier)(`univer.doc.plugin.doc-drawing.service`);function i(e,t){return function(n,r){t(n,r,e)}}function a(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const o=`DOC_DRAWING_PLUGIN`;let s=class extends e.Disposable{constructor(e,t,n,r){super(),this._docDrawingService=e,this._drawingManagerService=t,this._resourceManagerService=n,this._univerInstanceService=r,this._init()}_init(){this._initSnapshot()}_initSnapshot(){let t=t=>{let n=this._univerInstanceService.getUnit(t,e.UniverInstanceType.UNIVER_DOC);if(n){let e=n.getSnapshot().drawings,t=n.getSnapshot().drawingsOrder,r={data:e==null?{}:e,order:t==null?[]:t};return JSON.stringify(r)}return``},n=e=>{if(!e)return{data:{},order:[]};try{return JSON.parse(e)}catch{return{data:{},order:[]}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:o,businesses:[e.UniverInstanceType.UNIVER_DOC],toJson:e=>t(e),parseJson:e=>n(e),onUnLoad:e=>{this._setDrawingDataForUnit(e,{data:{},order:[]})},onLoad:(e,t)=>{var n,r;this._setDrawingDataForUnit(e,{data:(n=t.data)==null?{}:n,order:(r=t.order)==null?[]:r})}}))}_setDrawingDataForUnit(e,t){let n=this._univerInstanceService.getUnit(e);n!=null&&(n.resetDrawing(t.data,t.order),this.loadDrawingDataForUnit(e))}loadDrawingDataForUnit(t){let n=this._univerInstanceService.getUnit(t,e.UniverInstanceType.UNIVER_DOC);if(!n)return!1;let r=t,i=n.getDrawings(),a=n.getDrawingsOrder();if(!i||!a)return!1;Object.keys(i).forEach(e=>{i[e]={...i[e]}});let o={[r]:{unitId:t,subUnitId:r,data:i,order:a}};return this._docDrawingService.registerDrawingData(t,o),this._drawingManagerService.registerDrawingData(t,o),!0}};s=a([i(0,r),i(1,t.IDrawingManagerService),i(2,e.IResourceManagerService),i(3,e.IUniverInstanceService)],s);var c=`@univerjs/docs-drawing`,l=`0.20.1`;const u=`docs-drawing.config`;Symbol(u);const d={};function f(e){"@babel/helpers - typeof";return f=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},f(e)}function p(e,t){if(f(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(f(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function m(e){var t=p(e,`string`);return f(t)==`symbol`?t:t+``}function h(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let g=class extends e.Plugin{constructor(t=d,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{...i}=(0,e.merge)({},d,this._config);this._configService.setConfig(u,i)}onStarting(){[[s],[n],[r,{useClass:n}]].forEach(e=>this._injector.add(e)),(0,e.touchDependencies)(this._injector,[[s]])}};h(g,`pluginName`,o),h(g,`packageName`,c),h(g,`version`,l),h(g,`type`,e.UniverInstanceType.UNIVER_DOC),g=a([i(1,(0,e.Inject)(e.Injector)),i(2,e.IConfigService)],g),exports.DOCS_DRAWING_PLUGIN=o,Object.defineProperty(exports,`DocDrawingController`,{enumerable:!0,get:function(){return s}}),exports.DocDrawingService=n,exports.IDocDrawingService=r,Object.defineProperty(exports,`UniverDocsDrawingPlugin`,{enumerable:!0,get:function(){return g}});
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_core = require("@univerjs/core");
3
+ let _univerjs_drawing = require("@univerjs/drawing");
4
+
5
+ //#region src/services/doc-drawing.service.ts
6
+ var DocDrawingService = class extends _univerjs_drawing.UnitDrawingService {};
7
+ const IDocDrawingService = (0, _univerjs_core.createIdentifier)("univer.doc.plugin.doc-drawing.service");
8
+
9
+ //#endregion
10
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
11
+ function __decorateParam(paramIndex, decorator) {
12
+ return function(target, key) {
13
+ decorator(target, key, paramIndex);
14
+ };
15
+ }
16
+
17
+ //#endregion
18
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
19
+ function __decorate(decorators, target, key, desc) {
20
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
21
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
22
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
23
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
24
+ }
25
+
26
+ //#endregion
27
+ //#region src/controllers/doc-drawing.controller.ts
28
+ const DOCS_DRAWING_PLUGIN = "DOC_DRAWING_PLUGIN";
29
+ let DocDrawingController = class DocDrawingController extends _univerjs_core.Disposable {
30
+ constructor(_docDrawingService, _drawingManagerService, _resourceManagerService, _univerInstanceService) {
31
+ super();
32
+ this._docDrawingService = _docDrawingService;
33
+ this._drawingManagerService = _drawingManagerService;
34
+ this._resourceManagerService = _resourceManagerService;
35
+ this._univerInstanceService = _univerInstanceService;
36
+ this._init();
37
+ }
38
+ _init() {
39
+ this._initSnapshot();
40
+ }
41
+ _initSnapshot() {
42
+ const toJson = (unitId) => {
43
+ const doc = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
44
+ if (doc) {
45
+ const drawings = doc.getSnapshot().drawings;
46
+ const drawingOrder = doc.getSnapshot().drawingsOrder;
47
+ return JSON.stringify({
48
+ data: drawings !== null && drawings !== void 0 ? drawings : {},
49
+ order: drawingOrder !== null && drawingOrder !== void 0 ? drawingOrder : []
50
+ });
51
+ }
52
+ return "";
53
+ };
54
+ const parseJson = (json) => {
55
+ if (!json) return {
56
+ data: {},
57
+ order: []
58
+ };
59
+ try {
60
+ return JSON.parse(json);
61
+ } catch (err) {
62
+ return {
63
+ data: {},
64
+ order: []
65
+ };
66
+ }
67
+ };
68
+ this.disposeWithMe(this._resourceManagerService.registerPluginResource({
69
+ pluginName: DOCS_DRAWING_PLUGIN,
70
+ businesses: [_univerjs_core.UniverInstanceType.UNIVER_DOC],
71
+ toJson: (unitId) => toJson(unitId),
72
+ parseJson: (json) => parseJson(json),
73
+ onUnLoad: (unitId) => {
74
+ this._setDrawingDataForUnit(unitId, {
75
+ data: {},
76
+ order: []
77
+ });
78
+ },
79
+ onLoad: (unitId, value) => {
80
+ var _value$data, _value$order;
81
+ this._setDrawingDataForUnit(unitId, {
82
+ data: (_value$data = value.data) !== null && _value$data !== void 0 ? _value$data : {},
83
+ order: (_value$order = value.order) !== null && _value$order !== void 0 ? _value$order : []
84
+ });
85
+ }
86
+ }));
87
+ }
88
+ _setDrawingDataForUnit(unitId, drawingMapItem) {
89
+ const documentDataModel = this._univerInstanceService.getUnit(unitId);
90
+ if (documentDataModel == null) return;
91
+ documentDataModel.resetDrawing(drawingMapItem.data, drawingMapItem.order);
92
+ this.loadDrawingDataForUnit(unitId);
93
+ }
94
+ loadDrawingDataForUnit(unitId) {
95
+ const dataModel = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
96
+ if (!dataModel) return false;
97
+ const subUnitId = unitId;
98
+ const drawingDataModels = dataModel.getDrawings();
99
+ const drawingOrderModel = dataModel.getDrawingsOrder();
100
+ if (!drawingDataModels || !drawingOrderModel) return false;
101
+ Object.keys(drawingDataModels).forEach((drawingId) => {
102
+ drawingDataModels[drawingId] = { ...drawingDataModels[drawingId] };
103
+ });
104
+ const subDrawings = { [subUnitId]: {
105
+ unitId,
106
+ subUnitId,
107
+ data: drawingDataModels,
108
+ order: drawingOrderModel
109
+ } };
110
+ this._docDrawingService.registerDrawingData(unitId, subDrawings);
111
+ this._drawingManagerService.registerDrawingData(unitId, subDrawings);
112
+ return true;
113
+ }
114
+ };
115
+ DocDrawingController = __decorate([
116
+ __decorateParam(0, IDocDrawingService),
117
+ __decorateParam(1, _univerjs_drawing.IDrawingManagerService),
118
+ __decorateParam(2, _univerjs_core.IResourceManagerService),
119
+ __decorateParam(3, _univerjs_core.IUniverInstanceService)
120
+ ], DocDrawingController);
121
+
122
+ //#endregion
123
+ //#region package.json
124
+ var name = "@univerjs/docs-drawing";
125
+ var version = "0.21.0";
126
+
127
+ //#endregion
128
+ //#region src/config/config.ts
129
+ /**
130
+ * Copyright 2023-present DreamNum Co., Ltd.
131
+ *
132
+ * Licensed under the Apache License, Version 2.0 (the "License");
133
+ * you may not use this file except in compliance with the License.
134
+ * You may obtain a copy of the License at
135
+ *
136
+ * http://www.apache.org/licenses/LICENSE-2.0
137
+ *
138
+ * Unless required by applicable law or agreed to in writing, software
139
+ * distributed under the License is distributed on an "AS IS" BASIS,
140
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141
+ * See the License for the specific language governing permissions and
142
+ * limitations under the License.
143
+ */
144
+ const DOCS_DRAWING_PLUGIN_CONFIG_KEY = "docs-drawing.config";
145
+ const configSymbol = Symbol(DOCS_DRAWING_PLUGIN_CONFIG_KEY);
146
+ const defaultPluginConfig = {};
147
+
148
+ //#endregion
149
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
150
+ function _typeof(o) {
151
+ "@babel/helpers - typeof";
152
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
153
+ return typeof o;
154
+ } : function(o) {
155
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
156
+ }, _typeof(o);
157
+ }
158
+
159
+ //#endregion
160
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
161
+ function toPrimitive(t, r) {
162
+ if ("object" != _typeof(t) || !t) return t;
163
+ var e = t[Symbol.toPrimitive];
164
+ if (void 0 !== e) {
165
+ var i = e.call(t, r || "default");
166
+ if ("object" != _typeof(i)) return i;
167
+ throw new TypeError("@@toPrimitive must return a primitive value.");
168
+ }
169
+ return ("string" === r ? String : Number)(t);
170
+ }
171
+
172
+ //#endregion
173
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
174
+ function toPropertyKey(t) {
175
+ var i = toPrimitive(t, "string");
176
+ return "symbol" == _typeof(i) ? i : i + "";
177
+ }
178
+
179
+ //#endregion
180
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
181
+ function _defineProperty(e, r, t) {
182
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
183
+ value: t,
184
+ enumerable: !0,
185
+ configurable: !0,
186
+ writable: !0
187
+ }) : e[r] = t, e;
188
+ }
189
+
190
+ //#endregion
191
+ //#region src/plugin.ts
192
+ let UniverDocsDrawingPlugin = class UniverDocsDrawingPlugin extends _univerjs_core.Plugin {
193
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
194
+ super();
195
+ this._config = _config;
196
+ this._injector = _injector;
197
+ this._configService = _configService;
198
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
199
+ this._configService.setConfig(DOCS_DRAWING_PLUGIN_CONFIG_KEY, rest);
200
+ }
201
+ onStarting() {
202
+ [
203
+ [DocDrawingController],
204
+ [DocDrawingService],
205
+ [IDocDrawingService, { useClass: DocDrawingService }]
206
+ ].forEach((dependency) => this._injector.add(dependency));
207
+ (0, _univerjs_core.touchDependencies)(this._injector, [[DocDrawingController]]);
208
+ }
209
+ };
210
+ _defineProperty(UniverDocsDrawingPlugin, "pluginName", DOCS_DRAWING_PLUGIN);
211
+ _defineProperty(UniverDocsDrawingPlugin, "packageName", name);
212
+ _defineProperty(UniverDocsDrawingPlugin, "version", version);
213
+ _defineProperty(UniverDocsDrawingPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_DOC);
214
+ UniverDocsDrawingPlugin = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(2, _univerjs_core.IConfigService)], UniverDocsDrawingPlugin);
215
+
216
+ //#endregion
217
+ exports.DOCS_DRAWING_PLUGIN = DOCS_DRAWING_PLUGIN;
218
+ Object.defineProperty(exports, 'DocDrawingController', {
219
+ enumerable: true,
220
+ get: function () {
221
+ return DocDrawingController;
222
+ }
223
+ });
224
+ exports.DocDrawingService = DocDrawingService;
225
+ exports.IDocDrawingService = IDocDrawingService;
226
+ Object.defineProperty(exports, 'UniverDocsDrawingPlugin', {
227
+ enumerable: true,
228
+ get: function () {
229
+ return UniverDocsDrawingPlugin;
230
+ }
231
+ });
package/lib/es/index.js CHANGED
@@ -1 +1,216 @@
1
- import{Disposable as e,IConfigService as t,IResourceManagerService as n,IUniverInstanceService as r,Inject as i,Injector as a,Plugin as o,UniverInstanceType as s,createIdentifier as c,merge as l,touchDependencies as u}from"@univerjs/core";import{IDrawingManagerService as d,UnitDrawingService as f}from"@univerjs/drawing";var p=class extends f{};const m=c(`univer.doc.plugin.doc-drawing.service`);function h(e,t){return function(n,r){t(n,r,e)}}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const _=`DOC_DRAWING_PLUGIN`;let v=class extends e{constructor(e,t,n,r){super(),this._docDrawingService=e,this._drawingManagerService=t,this._resourceManagerService=n,this._univerInstanceService=r,this._init()}_init(){this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._univerInstanceService.getUnit(e,s.UNIVER_DOC);if(t){let e=t.getSnapshot().drawings,n=t.getSnapshot().drawingsOrder,r={data:e==null?{}:e,order:n==null?[]:n};return JSON.stringify(r)}return``},t=e=>{if(!e)return{data:{},order:[]};try{return JSON.parse(e)}catch{return{data:{},order:[]}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:_,businesses:[s.UNIVER_DOC],toJson:t=>e(t),parseJson:e=>t(e),onUnLoad:e=>{this._setDrawingDataForUnit(e,{data:{},order:[]})},onLoad:(e,t)=>{var n,r;this._setDrawingDataForUnit(e,{data:(n=t.data)==null?{}:n,order:(r=t.order)==null?[]:r})}}))}_setDrawingDataForUnit(e,t){let n=this._univerInstanceService.getUnit(e);n!=null&&(n.resetDrawing(t.data,t.order),this.loadDrawingDataForUnit(e))}loadDrawingDataForUnit(e){let t=this._univerInstanceService.getUnit(e,s.UNIVER_DOC);if(!t)return!1;let n=e,r=t.getDrawings(),i=t.getDrawingsOrder();if(!r||!i)return!1;Object.keys(r).forEach(e=>{r[e]={...r[e]}});let a={[n]:{unitId:e,subUnitId:n,data:r,order:i}};return this._docDrawingService.registerDrawingData(e,a),this._drawingManagerService.registerDrawingData(e,a),!0}};v=g([h(0,m),h(1,d),h(2,n),h(3,r)],v);var y=`@univerjs/docs-drawing`,b=`0.20.1`;const x=`docs-drawing.config`;Symbol(x);const S={};function C(e){"@babel/helpers - typeof";return C=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let D=class extends o{constructor(e=S,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=l({},S,this._config);this._configService.setConfig(x,r)}onStarting(){[[v],[p],[m,{useClass:p}]].forEach(e=>this._injector.add(e)),u(this._injector,[[v]])}};E(D,`pluginName`,_),E(D,`packageName`,y),E(D,`version`,b),E(D,`type`,s.UNIVER_DOC),D=g([h(1,i(a)),h(2,t)],D);export{_ as DOCS_DRAWING_PLUGIN,v as DocDrawingController,p as DocDrawingService,m as IDocDrawingService,D as UniverDocsDrawingPlugin};
1
+ import { Disposable, IConfigService, IResourceManagerService, IUniverInstanceService, Inject, Injector, Plugin, UniverInstanceType, createIdentifier, merge, touchDependencies } from "@univerjs/core";
2
+ import { IDrawingManagerService, UnitDrawingService } from "@univerjs/drawing";
3
+
4
+ //#region src/services/doc-drawing.service.ts
5
+ var DocDrawingService = class extends UnitDrawingService {};
6
+ const IDocDrawingService = createIdentifier("univer.doc.plugin.doc-drawing.service");
7
+
8
+ //#endregion
9
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
10
+ function __decorateParam(paramIndex, decorator) {
11
+ return function(target, key) {
12
+ decorator(target, key, paramIndex);
13
+ };
14
+ }
15
+
16
+ //#endregion
17
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
18
+ function __decorate(decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ }
24
+
25
+ //#endregion
26
+ //#region src/controllers/doc-drawing.controller.ts
27
+ const DOCS_DRAWING_PLUGIN = "DOC_DRAWING_PLUGIN";
28
+ let DocDrawingController = class DocDrawingController extends Disposable {
29
+ constructor(_docDrawingService, _drawingManagerService, _resourceManagerService, _univerInstanceService) {
30
+ super();
31
+ this._docDrawingService = _docDrawingService;
32
+ this._drawingManagerService = _drawingManagerService;
33
+ this._resourceManagerService = _resourceManagerService;
34
+ this._univerInstanceService = _univerInstanceService;
35
+ this._init();
36
+ }
37
+ _init() {
38
+ this._initSnapshot();
39
+ }
40
+ _initSnapshot() {
41
+ const toJson = (unitId) => {
42
+ const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
43
+ if (doc) {
44
+ const drawings = doc.getSnapshot().drawings;
45
+ const drawingOrder = doc.getSnapshot().drawingsOrder;
46
+ return JSON.stringify({
47
+ data: drawings !== null && drawings !== void 0 ? drawings : {},
48
+ order: drawingOrder !== null && drawingOrder !== void 0 ? drawingOrder : []
49
+ });
50
+ }
51
+ return "";
52
+ };
53
+ const parseJson = (json) => {
54
+ if (!json) return {
55
+ data: {},
56
+ order: []
57
+ };
58
+ try {
59
+ return JSON.parse(json);
60
+ } catch (err) {
61
+ return {
62
+ data: {},
63
+ order: []
64
+ };
65
+ }
66
+ };
67
+ this.disposeWithMe(this._resourceManagerService.registerPluginResource({
68
+ pluginName: DOCS_DRAWING_PLUGIN,
69
+ businesses: [UniverInstanceType.UNIVER_DOC],
70
+ toJson: (unitId) => toJson(unitId),
71
+ parseJson: (json) => parseJson(json),
72
+ onUnLoad: (unitId) => {
73
+ this._setDrawingDataForUnit(unitId, {
74
+ data: {},
75
+ order: []
76
+ });
77
+ },
78
+ onLoad: (unitId, value) => {
79
+ var _value$data, _value$order;
80
+ this._setDrawingDataForUnit(unitId, {
81
+ data: (_value$data = value.data) !== null && _value$data !== void 0 ? _value$data : {},
82
+ order: (_value$order = value.order) !== null && _value$order !== void 0 ? _value$order : []
83
+ });
84
+ }
85
+ }));
86
+ }
87
+ _setDrawingDataForUnit(unitId, drawingMapItem) {
88
+ const documentDataModel = this._univerInstanceService.getUnit(unitId);
89
+ if (documentDataModel == null) return;
90
+ documentDataModel.resetDrawing(drawingMapItem.data, drawingMapItem.order);
91
+ this.loadDrawingDataForUnit(unitId);
92
+ }
93
+ loadDrawingDataForUnit(unitId) {
94
+ const dataModel = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
95
+ if (!dataModel) return false;
96
+ const subUnitId = unitId;
97
+ const drawingDataModels = dataModel.getDrawings();
98
+ const drawingOrderModel = dataModel.getDrawingsOrder();
99
+ if (!drawingDataModels || !drawingOrderModel) return false;
100
+ Object.keys(drawingDataModels).forEach((drawingId) => {
101
+ drawingDataModels[drawingId] = { ...drawingDataModels[drawingId] };
102
+ });
103
+ const subDrawings = { [subUnitId]: {
104
+ unitId,
105
+ subUnitId,
106
+ data: drawingDataModels,
107
+ order: drawingOrderModel
108
+ } };
109
+ this._docDrawingService.registerDrawingData(unitId, subDrawings);
110
+ this._drawingManagerService.registerDrawingData(unitId, subDrawings);
111
+ return true;
112
+ }
113
+ };
114
+ DocDrawingController = __decorate([
115
+ __decorateParam(0, IDocDrawingService),
116
+ __decorateParam(1, IDrawingManagerService),
117
+ __decorateParam(2, IResourceManagerService),
118
+ __decorateParam(3, IUniverInstanceService)
119
+ ], DocDrawingController);
120
+
121
+ //#endregion
122
+ //#region package.json
123
+ var name = "@univerjs/docs-drawing";
124
+ var version = "0.21.0";
125
+
126
+ //#endregion
127
+ //#region src/config/config.ts
128
+ /**
129
+ * Copyright 2023-present DreamNum Co., Ltd.
130
+ *
131
+ * Licensed under the Apache License, Version 2.0 (the "License");
132
+ * you may not use this file except in compliance with the License.
133
+ * You may obtain a copy of the License at
134
+ *
135
+ * http://www.apache.org/licenses/LICENSE-2.0
136
+ *
137
+ * Unless required by applicable law or agreed to in writing, software
138
+ * distributed under the License is distributed on an "AS IS" BASIS,
139
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140
+ * See the License for the specific language governing permissions and
141
+ * limitations under the License.
142
+ */
143
+ const DOCS_DRAWING_PLUGIN_CONFIG_KEY = "docs-drawing.config";
144
+ const configSymbol = Symbol(DOCS_DRAWING_PLUGIN_CONFIG_KEY);
145
+ const defaultPluginConfig = {};
146
+
147
+ //#endregion
148
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
149
+ function _typeof(o) {
150
+ "@babel/helpers - typeof";
151
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
152
+ return typeof o;
153
+ } : function(o) {
154
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
155
+ }, _typeof(o);
156
+ }
157
+
158
+ //#endregion
159
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
160
+ function toPrimitive(t, r) {
161
+ if ("object" != _typeof(t) || !t) return t;
162
+ var e = t[Symbol.toPrimitive];
163
+ if (void 0 !== e) {
164
+ var i = e.call(t, r || "default");
165
+ if ("object" != _typeof(i)) return i;
166
+ throw new TypeError("@@toPrimitive must return a primitive value.");
167
+ }
168
+ return ("string" === r ? String : Number)(t);
169
+ }
170
+
171
+ //#endregion
172
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
173
+ function toPropertyKey(t) {
174
+ var i = toPrimitive(t, "string");
175
+ return "symbol" == _typeof(i) ? i : i + "";
176
+ }
177
+
178
+ //#endregion
179
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
180
+ function _defineProperty(e, r, t) {
181
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
182
+ value: t,
183
+ enumerable: !0,
184
+ configurable: !0,
185
+ writable: !0
186
+ }) : e[r] = t, e;
187
+ }
188
+
189
+ //#endregion
190
+ //#region src/plugin.ts
191
+ let UniverDocsDrawingPlugin = class UniverDocsDrawingPlugin extends Plugin {
192
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
193
+ super();
194
+ this._config = _config;
195
+ this._injector = _injector;
196
+ this._configService = _configService;
197
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
198
+ this._configService.setConfig(DOCS_DRAWING_PLUGIN_CONFIG_KEY, rest);
199
+ }
200
+ onStarting() {
201
+ [
202
+ [DocDrawingController],
203
+ [DocDrawingService],
204
+ [IDocDrawingService, { useClass: DocDrawingService }]
205
+ ].forEach((dependency) => this._injector.add(dependency));
206
+ touchDependencies(this._injector, [[DocDrawingController]]);
207
+ }
208
+ };
209
+ _defineProperty(UniverDocsDrawingPlugin, "pluginName", DOCS_DRAWING_PLUGIN);
210
+ _defineProperty(UniverDocsDrawingPlugin, "packageName", name);
211
+ _defineProperty(UniverDocsDrawingPlugin, "version", version);
212
+ _defineProperty(UniverDocsDrawingPlugin, "type", UniverInstanceType.UNIVER_DOC);
213
+ UniverDocsDrawingPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverDocsDrawingPlugin);
214
+
215
+ //#endregion
216
+ export { DOCS_DRAWING_PLUGIN, DocDrawingController, DocDrawingService, IDocDrawingService, UniverDocsDrawingPlugin };
package/lib/index.js CHANGED
@@ -1 +1,216 @@
1
- import{Disposable as e,IConfigService as t,IResourceManagerService as n,IUniverInstanceService as r,Inject as i,Injector as a,Plugin as o,UniverInstanceType as s,createIdentifier as c,merge as l,touchDependencies as u}from"@univerjs/core";import{IDrawingManagerService as d,UnitDrawingService as f}from"@univerjs/drawing";var p=class extends f{};const m=c(`univer.doc.plugin.doc-drawing.service`);function h(e,t){return function(n,r){t(n,r,e)}}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const _=`DOC_DRAWING_PLUGIN`;let v=class extends e{constructor(e,t,n,r){super(),this._docDrawingService=e,this._drawingManagerService=t,this._resourceManagerService=n,this._univerInstanceService=r,this._init()}_init(){this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._univerInstanceService.getUnit(e,s.UNIVER_DOC);if(t){let e=t.getSnapshot().drawings,n=t.getSnapshot().drawingsOrder,r={data:e==null?{}:e,order:n==null?[]:n};return JSON.stringify(r)}return``},t=e=>{if(!e)return{data:{},order:[]};try{return JSON.parse(e)}catch{return{data:{},order:[]}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:_,businesses:[s.UNIVER_DOC],toJson:t=>e(t),parseJson:e=>t(e),onUnLoad:e=>{this._setDrawingDataForUnit(e,{data:{},order:[]})},onLoad:(e,t)=>{var n,r;this._setDrawingDataForUnit(e,{data:(n=t.data)==null?{}:n,order:(r=t.order)==null?[]:r})}}))}_setDrawingDataForUnit(e,t){let n=this._univerInstanceService.getUnit(e);n!=null&&(n.resetDrawing(t.data,t.order),this.loadDrawingDataForUnit(e))}loadDrawingDataForUnit(e){let t=this._univerInstanceService.getUnit(e,s.UNIVER_DOC);if(!t)return!1;let n=e,r=t.getDrawings(),i=t.getDrawingsOrder();if(!r||!i)return!1;Object.keys(r).forEach(e=>{r[e]={...r[e]}});let a={[n]:{unitId:e,subUnitId:n,data:r,order:i}};return this._docDrawingService.registerDrawingData(e,a),this._drawingManagerService.registerDrawingData(e,a),!0}};v=g([h(0,m),h(1,d),h(2,n),h(3,r)],v);var y=`@univerjs/docs-drawing`,b=`0.20.1`;const x=`docs-drawing.config`;Symbol(x);const S={};function C(e){"@babel/helpers - typeof";return C=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let D=class extends o{constructor(e=S,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=l({},S,this._config);this._configService.setConfig(x,r)}onStarting(){[[v],[p],[m,{useClass:p}]].forEach(e=>this._injector.add(e)),u(this._injector,[[v]])}};E(D,`pluginName`,_),E(D,`packageName`,y),E(D,`version`,b),E(D,`type`,s.UNIVER_DOC),D=g([h(1,i(a)),h(2,t)],D);export{_ as DOCS_DRAWING_PLUGIN,v as DocDrawingController,p as DocDrawingService,m as IDocDrawingService,D as UniverDocsDrawingPlugin};
1
+ import { Disposable, IConfigService, IResourceManagerService, IUniverInstanceService, Inject, Injector, Plugin, UniverInstanceType, createIdentifier, merge, touchDependencies } from "@univerjs/core";
2
+ import { IDrawingManagerService, UnitDrawingService } from "@univerjs/drawing";
3
+
4
+ //#region src/services/doc-drawing.service.ts
5
+ var DocDrawingService = class extends UnitDrawingService {};
6
+ const IDocDrawingService = createIdentifier("univer.doc.plugin.doc-drawing.service");
7
+
8
+ //#endregion
9
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
10
+ function __decorateParam(paramIndex, decorator) {
11
+ return function(target, key) {
12
+ decorator(target, key, paramIndex);
13
+ };
14
+ }
15
+
16
+ //#endregion
17
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
18
+ function __decorate(decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ }
24
+
25
+ //#endregion
26
+ //#region src/controllers/doc-drawing.controller.ts
27
+ const DOCS_DRAWING_PLUGIN = "DOC_DRAWING_PLUGIN";
28
+ let DocDrawingController = class DocDrawingController extends Disposable {
29
+ constructor(_docDrawingService, _drawingManagerService, _resourceManagerService, _univerInstanceService) {
30
+ super();
31
+ this._docDrawingService = _docDrawingService;
32
+ this._drawingManagerService = _drawingManagerService;
33
+ this._resourceManagerService = _resourceManagerService;
34
+ this._univerInstanceService = _univerInstanceService;
35
+ this._init();
36
+ }
37
+ _init() {
38
+ this._initSnapshot();
39
+ }
40
+ _initSnapshot() {
41
+ const toJson = (unitId) => {
42
+ const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
43
+ if (doc) {
44
+ const drawings = doc.getSnapshot().drawings;
45
+ const drawingOrder = doc.getSnapshot().drawingsOrder;
46
+ return JSON.stringify({
47
+ data: drawings !== null && drawings !== void 0 ? drawings : {},
48
+ order: drawingOrder !== null && drawingOrder !== void 0 ? drawingOrder : []
49
+ });
50
+ }
51
+ return "";
52
+ };
53
+ const parseJson = (json) => {
54
+ if (!json) return {
55
+ data: {},
56
+ order: []
57
+ };
58
+ try {
59
+ return JSON.parse(json);
60
+ } catch (err) {
61
+ return {
62
+ data: {},
63
+ order: []
64
+ };
65
+ }
66
+ };
67
+ this.disposeWithMe(this._resourceManagerService.registerPluginResource({
68
+ pluginName: DOCS_DRAWING_PLUGIN,
69
+ businesses: [UniverInstanceType.UNIVER_DOC],
70
+ toJson: (unitId) => toJson(unitId),
71
+ parseJson: (json) => parseJson(json),
72
+ onUnLoad: (unitId) => {
73
+ this._setDrawingDataForUnit(unitId, {
74
+ data: {},
75
+ order: []
76
+ });
77
+ },
78
+ onLoad: (unitId, value) => {
79
+ var _value$data, _value$order;
80
+ this._setDrawingDataForUnit(unitId, {
81
+ data: (_value$data = value.data) !== null && _value$data !== void 0 ? _value$data : {},
82
+ order: (_value$order = value.order) !== null && _value$order !== void 0 ? _value$order : []
83
+ });
84
+ }
85
+ }));
86
+ }
87
+ _setDrawingDataForUnit(unitId, drawingMapItem) {
88
+ const documentDataModel = this._univerInstanceService.getUnit(unitId);
89
+ if (documentDataModel == null) return;
90
+ documentDataModel.resetDrawing(drawingMapItem.data, drawingMapItem.order);
91
+ this.loadDrawingDataForUnit(unitId);
92
+ }
93
+ loadDrawingDataForUnit(unitId) {
94
+ const dataModel = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
95
+ if (!dataModel) return false;
96
+ const subUnitId = unitId;
97
+ const drawingDataModels = dataModel.getDrawings();
98
+ const drawingOrderModel = dataModel.getDrawingsOrder();
99
+ if (!drawingDataModels || !drawingOrderModel) return false;
100
+ Object.keys(drawingDataModels).forEach((drawingId) => {
101
+ drawingDataModels[drawingId] = { ...drawingDataModels[drawingId] };
102
+ });
103
+ const subDrawings = { [subUnitId]: {
104
+ unitId,
105
+ subUnitId,
106
+ data: drawingDataModels,
107
+ order: drawingOrderModel
108
+ } };
109
+ this._docDrawingService.registerDrawingData(unitId, subDrawings);
110
+ this._drawingManagerService.registerDrawingData(unitId, subDrawings);
111
+ return true;
112
+ }
113
+ };
114
+ DocDrawingController = __decorate([
115
+ __decorateParam(0, IDocDrawingService),
116
+ __decorateParam(1, IDrawingManagerService),
117
+ __decorateParam(2, IResourceManagerService),
118
+ __decorateParam(3, IUniverInstanceService)
119
+ ], DocDrawingController);
120
+
121
+ //#endregion
122
+ //#region package.json
123
+ var name = "@univerjs/docs-drawing";
124
+ var version = "0.21.0";
125
+
126
+ //#endregion
127
+ //#region src/config/config.ts
128
+ /**
129
+ * Copyright 2023-present DreamNum Co., Ltd.
130
+ *
131
+ * Licensed under the Apache License, Version 2.0 (the "License");
132
+ * you may not use this file except in compliance with the License.
133
+ * You may obtain a copy of the License at
134
+ *
135
+ * http://www.apache.org/licenses/LICENSE-2.0
136
+ *
137
+ * Unless required by applicable law or agreed to in writing, software
138
+ * distributed under the License is distributed on an "AS IS" BASIS,
139
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140
+ * See the License for the specific language governing permissions and
141
+ * limitations under the License.
142
+ */
143
+ const DOCS_DRAWING_PLUGIN_CONFIG_KEY = "docs-drawing.config";
144
+ const configSymbol = Symbol(DOCS_DRAWING_PLUGIN_CONFIG_KEY);
145
+ const defaultPluginConfig = {};
146
+
147
+ //#endregion
148
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
149
+ function _typeof(o) {
150
+ "@babel/helpers - typeof";
151
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
152
+ return typeof o;
153
+ } : function(o) {
154
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
155
+ }, _typeof(o);
156
+ }
157
+
158
+ //#endregion
159
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
160
+ function toPrimitive(t, r) {
161
+ if ("object" != _typeof(t) || !t) return t;
162
+ var e = t[Symbol.toPrimitive];
163
+ if (void 0 !== e) {
164
+ var i = e.call(t, r || "default");
165
+ if ("object" != _typeof(i)) return i;
166
+ throw new TypeError("@@toPrimitive must return a primitive value.");
167
+ }
168
+ return ("string" === r ? String : Number)(t);
169
+ }
170
+
171
+ //#endregion
172
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
173
+ function toPropertyKey(t) {
174
+ var i = toPrimitive(t, "string");
175
+ return "symbol" == _typeof(i) ? i : i + "";
176
+ }
177
+
178
+ //#endregion
179
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
180
+ function _defineProperty(e, r, t) {
181
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
182
+ value: t,
183
+ enumerable: !0,
184
+ configurable: !0,
185
+ writable: !0
186
+ }) : e[r] = t, e;
187
+ }
188
+
189
+ //#endregion
190
+ //#region src/plugin.ts
191
+ let UniverDocsDrawingPlugin = class UniverDocsDrawingPlugin extends Plugin {
192
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
193
+ super();
194
+ this._config = _config;
195
+ this._injector = _injector;
196
+ this._configService = _configService;
197
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
198
+ this._configService.setConfig(DOCS_DRAWING_PLUGIN_CONFIG_KEY, rest);
199
+ }
200
+ onStarting() {
201
+ [
202
+ [DocDrawingController],
203
+ [DocDrawingService],
204
+ [IDocDrawingService, { useClass: DocDrawingService }]
205
+ ].forEach((dependency) => this._injector.add(dependency));
206
+ touchDependencies(this._injector, [[DocDrawingController]]);
207
+ }
208
+ };
209
+ _defineProperty(UniverDocsDrawingPlugin, "pluginName", DOCS_DRAWING_PLUGIN);
210
+ _defineProperty(UniverDocsDrawingPlugin, "packageName", name);
211
+ _defineProperty(UniverDocsDrawingPlugin, "version", version);
212
+ _defineProperty(UniverDocsDrawingPlugin, "type", UniverInstanceType.UNIVER_DOC);
213
+ UniverDocsDrawingPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverDocsDrawingPlugin);
214
+
215
+ //#endregion
216
+ export { DOCS_DRAWING_PLUGIN, DocDrawingController, DocDrawingService, IDocDrawingService, UniverDocsDrawingPlugin };
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/drawing`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/drawing`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsDrawing={},e.UniverCore,e.UniverDrawing))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=class extends n.UnitDrawingService{};let i=(0,t.createIdentifier)(`univer.doc.plugin.doc-drawing.service`);function a(e,t){return function(n,r){t(n,r,e)}}function o(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let s=`DOC_DRAWING_PLUGIN`,c=class extends t.Disposable{constructor(e,t,n,r){super(),this._docDrawingService=e,this._drawingManagerService=t,this._resourceManagerService=n,this._univerInstanceService=r,this._init()}_init(){this._initSnapshot()}_initSnapshot(){let e=e=>{let n=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_DOC);if(n){let e=n.getSnapshot().drawings,t=n.getSnapshot().drawingsOrder,r={data:e==null?{}:e,order:t==null?[]:t};return JSON.stringify(r)}return``},n=e=>{if(!e)return{data:{},order:[]};try{return JSON.parse(e)}catch{return{data:{},order:[]}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:s,businesses:[t.UniverInstanceType.UNIVER_DOC],toJson:t=>e(t),parseJson:e=>n(e),onUnLoad:e=>{this._setDrawingDataForUnit(e,{data:{},order:[]})},onLoad:(e,t)=>{var n,r;this._setDrawingDataForUnit(e,{data:(n=t.data)==null?{}:n,order:(r=t.order)==null?[]:r})}}))}_setDrawingDataForUnit(e,t){let n=this._univerInstanceService.getUnit(e);n!=null&&(n.resetDrawing(t.data,t.order),this.loadDrawingDataForUnit(e))}loadDrawingDataForUnit(e){let n=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_DOC);if(!n)return!1;let r=e,i=n.getDrawings(),a=n.getDrawingsOrder();if(!i||!a)return!1;Object.keys(i).forEach(e=>{i[e]={...i[e]}});let o={[r]:{unitId:e,subUnitId:r,data:i,order:a}};return this._docDrawingService.registerDrawingData(e,o),this._drawingManagerService.registerDrawingData(e,o),!0}};c=o([a(0,i),a(1,n.IDrawingManagerService),a(2,t.IResourceManagerService),a(3,t.IUniverInstanceService)],c);var l=`@univerjs/docs-drawing`,u=`0.20.1`;let d=`docs-drawing.config`;Symbol(d);let f={};function p(e){"@babel/helpers - typeof";return p=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},p(e)}function m(e,t){if(p(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(p(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function h(e){var t=m(e,`string`);return p(t)==`symbol`?t:t+``}function g(e,t,n){return(t=h(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let _=class extends t.Plugin{constructor(e=f,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},f,this._config);this._configService.setConfig(d,i)}onStarting(){[[c],[r],[i,{useClass:r}]].forEach(e=>this._injector.add(e)),(0,t.touchDependencies)(this._injector,[[c]])}};g(_,`pluginName`,s),g(_,`packageName`,l),g(_,`version`,u),g(_,`type`,t.UniverInstanceType.UNIVER_DOC),_=o([a(1,(0,t.Inject)(t.Injector)),a(2,t.IConfigService)],_),e.DOCS_DRAWING_PLUGIN=s,Object.defineProperty(e,`DocDrawingController`,{enumerable:!0,get:function(){return c}}),e.DocDrawingService=r,e.IDocDrawingService=i,Object.defineProperty(e,`UniverDocsDrawingPlugin`,{enumerable:!0,get:function(){return _}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/drawing`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/drawing`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsDrawing={},e.UniverCore,e.UniverDrawing))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=class extends n.UnitDrawingService{};let i=(0,t.createIdentifier)(`univer.doc.plugin.doc-drawing.service`);function a(e,t){return function(n,r){t(n,r,e)}}function o(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let s=`DOC_DRAWING_PLUGIN`,c=class extends t.Disposable{constructor(e,t,n,r){super(),this._docDrawingService=e,this._drawingManagerService=t,this._resourceManagerService=n,this._univerInstanceService=r,this._init()}_init(){this._initSnapshot()}_initSnapshot(){let e=e=>{let n=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_DOC);if(n){let e=n.getSnapshot().drawings,t=n.getSnapshot().drawingsOrder;return JSON.stringify({data:e==null?{}:e,order:t==null?[]:t})}return``},n=e=>{if(!e)return{data:{},order:[]};try{return JSON.parse(e)}catch{return{data:{},order:[]}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:s,businesses:[t.UniverInstanceType.UNIVER_DOC],toJson:t=>e(t),parseJson:e=>n(e),onUnLoad:e=>{this._setDrawingDataForUnit(e,{data:{},order:[]})},onLoad:(e,t)=>{var n,r;this._setDrawingDataForUnit(e,{data:(n=t.data)==null?{}:n,order:(r=t.order)==null?[]:r})}}))}_setDrawingDataForUnit(e,t){let n=this._univerInstanceService.getUnit(e);n!=null&&(n.resetDrawing(t.data,t.order),this.loadDrawingDataForUnit(e))}loadDrawingDataForUnit(e){let n=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_DOC);if(!n)return!1;let r=e,i=n.getDrawings(),a=n.getDrawingsOrder();if(!i||!a)return!1;Object.keys(i).forEach(e=>{i[e]={...i[e]}});let o={[r]:{unitId:e,subUnitId:r,data:i,order:a}};return this._docDrawingService.registerDrawingData(e,o),this._drawingManagerService.registerDrawingData(e,o),!0}};c=o([a(0,i),a(1,n.IDrawingManagerService),a(2,t.IResourceManagerService),a(3,t.IUniverInstanceService)],c);var l=`@univerjs/docs-drawing`,u=`0.21.0`;let d=`docs-drawing.config`;Symbol(d);let f={};function p(e){"@babel/helpers - typeof";return p=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},p(e)}function m(e,t){if(p(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(p(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function h(e){var t=m(e,`string`);return p(t)==`symbol`?t:t+``}function g(e,t,n){return(t=h(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let _=class extends t.Plugin{constructor(e=f,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},f,this._config);this._configService.setConfig(d,i)}onStarting(){[[c],[r],[i,{useClass:r}]].forEach(e=>this._injector.add(e)),(0,t.touchDependencies)(this._injector,[[c]])}};g(_,`pluginName`,s),g(_,`packageName`,l),g(_,`version`,u),g(_,`type`,t.UniverInstanceType.UNIVER_DOC),_=o([a(1,(0,t.Inject)(t.Injector)),a(2,t.IConfigService)],_),e.DOCS_DRAWING_PLUGIN=s,Object.defineProperty(e,`DocDrawingController`,{enumerable:!0,get:function(){return c}}),e.DocDrawingService=r,e.IDocDrawingService=i,Object.defineProperty(e,`UniverDocsDrawingPlugin`,{enumerable:!0,get:function(){return _}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs-drawing",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -43,13 +43,13 @@
43
43
  "lib"
44
44
  ],
45
45
  "dependencies": {
46
- "@univerjs/core": "0.20.1",
47
- "@univerjs/drawing": "0.20.1"
46
+ "@univerjs/core": "0.21.0",
47
+ "@univerjs/drawing": "0.21.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "typescript": "^6.0.2",
51
- "vitest": "^4.1.1",
52
- "@univerjs-infra/shared": "0.20.1"
51
+ "vitest": "^4.1.4",
52
+ "@univerjs-infra/shared": "0.21.0"
53
53
  },
54
54
  "scripts": {
55
55
  "test": "vitest run",