@univerjs/drawing 1.0.0-rc.0 → 1.0.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 +111 -98
- package/lib/es/index.js +112 -71
- package/lib/index.js +112 -71
- package/lib/types/services/drawing-manager-impl.service.d.ts +3 -3
- package/lib/types/utils/drawing-group.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +4 -5
package/lib/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService, IURLImageService, ImageSourceType, ImageUploadStatusType, Inject, Injector, Plugin, createIdentifier, generateRandomId, merge, mergeOverrideWithDependencies, normalizeDrawingOrderIndex, sortRules, sortRulesByDesc, toDisposable } from "@univerjs/core";
|
|
2
|
-
import * as json1 from "ot-json1";
|
|
1
|
+
import { CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService, IURLImageService, ImageSourceType, ImageUploadStatusType, Inject, Injector, JSON1, Plugin, createIdentifier, generateRandomId, merge, mergeOverrideWithDependencies, normalizeDrawingOrderIndex, sortRules, sortRulesByDesc, toDisposable } from "@univerjs/core";
|
|
3
2
|
import { Subject } from "rxjs";
|
|
4
3
|
|
|
5
4
|
//#region src/basics/config.ts
|
|
@@ -21,7 +20,7 @@ import { Subject } from "rxjs";
|
|
|
21
20
|
const DRAWING_IMAGE_WIDTH_LIMIT = 500;
|
|
22
21
|
const DRAWING_IMAGE_HEIGHT_LIMIT = 500;
|
|
23
22
|
const DRAWING_IMAGE_COUNT_LIMIT = 10;
|
|
24
|
-
let DRAWING_IMAGE_ALLOW_SIZE =
|
|
23
|
+
let DRAWING_IMAGE_ALLOW_SIZE = 5242880;
|
|
25
24
|
function setDrawingImageAllowSize(size) {
|
|
26
25
|
DRAWING_IMAGE_ALLOW_SIZE = size;
|
|
27
26
|
}
|
|
@@ -56,7 +55,7 @@ const SetDrawingSelectedOperation = {
|
|
|
56
55
|
//#endregion
|
|
57
56
|
//#region package.json
|
|
58
57
|
var name = "@univerjs/drawing";
|
|
59
|
-
var version = "1.0.0
|
|
58
|
+
var version = "1.0.0";
|
|
60
59
|
|
|
61
60
|
//#endregion
|
|
62
61
|
//#region src/config/config.ts
|
|
@@ -65,7 +64,7 @@ const configSymbol = Symbol(DRAWING_PLUGIN_CONFIG_KEY);
|
|
|
65
64
|
const defaultPluginConfig = {};
|
|
66
65
|
|
|
67
66
|
//#endregion
|
|
68
|
-
//#region \0@oxc-project+runtime@0.
|
|
67
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
69
68
|
function _typeof(o) {
|
|
70
69
|
"@babel/helpers - typeof";
|
|
71
70
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -76,7 +75,7 @@ function _typeof(o) {
|
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
//#endregion
|
|
79
|
-
//#region \0@oxc-project+runtime@0.
|
|
78
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
80
79
|
function toPrimitive(t, r) {
|
|
81
80
|
if ("object" != _typeof(t) || !t) return t;
|
|
82
81
|
var e = t[Symbol.toPrimitive];
|
|
@@ -89,14 +88,14 @@ function toPrimitive(t, r) {
|
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
//#endregion
|
|
92
|
-
//#region \0@oxc-project+runtime@0.
|
|
91
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
93
92
|
function toPropertyKey(t) {
|
|
94
93
|
var i = toPrimitive(t, "string");
|
|
95
94
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
//#endregion
|
|
99
|
-
//#region \0@oxc-project+runtime@0.
|
|
98
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
100
99
|
function _defineProperty(e, r, t) {
|
|
101
100
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
102
101
|
value: t,
|
|
@@ -130,7 +129,7 @@ function hasOnlyEnumerableOwnProperties(value) {
|
|
|
130
129
|
return Object.getOwnPropertyNames(value).every((key) => Object.prototype.propertyIsEnumerable.call(value, key));
|
|
131
130
|
}
|
|
132
131
|
function createJsonRemoveOp(path, value) {
|
|
133
|
-
return
|
|
132
|
+
return JSON1.type.writeCursor().writeAtPath(path, "r", value).get();
|
|
134
133
|
}
|
|
135
134
|
function normalizeJsonDocument(value) {
|
|
136
135
|
if (value === void 0) return;
|
|
@@ -150,12 +149,26 @@ function appendJsonUpdateOps(ops, path, newValue, oldValue, hasOldValue) {
|
|
|
150
149
|
const hasNormalizedOldValue = hasOldValue && normalizedOldValue !== void 0;
|
|
151
150
|
if (hasNormalizedOldValue && isJsonValueEqual(normalizedOldValue, normalizedNewValue)) return;
|
|
152
151
|
if (hasNormalizedOldValue && isPlainObject(oldValue) && isPlainObject(newValue) && hasOnlyEnumerableOwnProperties(oldValue) && hasOnlyEnumerableOwnProperties(newValue)) {
|
|
153
|
-
(/* @__PURE__ */ new Set([...Object.keys(oldValue), ...Object.keys(newValue)]))
|
|
152
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(oldValue), ...Object.keys(newValue)])) appendJsonUpdateOps(ops, [...path, key], newValue[key], oldValue[key], Object.prototype.hasOwnProperty.call(oldValue, key) && oldValue[key] !== void 0);
|
|
154
153
|
return;
|
|
155
154
|
}
|
|
156
|
-
const op = !hasNormalizedOldValue ? normalizedNewValue === void 0 ? null :
|
|
155
|
+
const op = !hasNormalizedOldValue ? normalizedNewValue === void 0 ? null : JSON1.insertOp(path, normalizedNewValue) : normalizedNewValue === void 0 ? createJsonRemoveOp(path, normalizedOldValue) : JSON1.replaceOp(path, normalizedOldValue, normalizedNewValue);
|
|
157
156
|
if (op && isNonEmptyOp(op)) ops.push(op);
|
|
158
157
|
}
|
|
158
|
+
function assertSafeDrawingKeys(...keys) {
|
|
159
|
+
for (const key of keys) if (key === "__proto__" || key === "constructor" || key === "prototype") throw new Error("Invalid drawing key");
|
|
160
|
+
}
|
|
161
|
+
function getOwn(record, key) {
|
|
162
|
+
return record != null && Object.prototype.hasOwnProperty.call(record, key) ? record[key] : void 0;
|
|
163
|
+
}
|
|
164
|
+
function validateDrawingData(data) {
|
|
165
|
+
for (const subUnitId of Object.keys(data)) {
|
|
166
|
+
assertSafeDrawingKeys(subUnitId);
|
|
167
|
+
const subUnit = data[subUnitId];
|
|
168
|
+
if (subUnit === null || subUnit === void 0 ? void 0 : subUnit.data) Object.keys(subUnit.data).forEach((key) => assertSafeDrawingKeys(key));
|
|
169
|
+
if (subUnit === null || subUnit === void 0 ? void 0 : subUnit.order) subUnit.order.forEach((key) => assertSafeDrawingKeys(key));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
159
172
|
/**
|
|
160
173
|
* unitId -> subUnitId -> drawingId -> drawingParam
|
|
161
174
|
*/
|
|
@@ -226,10 +239,10 @@ var UnitDrawingService = class {
|
|
|
226
239
|
this.refreshTransformNotification(updateParams);
|
|
227
240
|
}
|
|
228
241
|
getDrawingDataForUnit(unitId) {
|
|
229
|
-
return this.drawingManagerData
|
|
242
|
+
return getOwn(this.drawingManagerData, unitId) || {};
|
|
230
243
|
}
|
|
231
244
|
removeDrawingDataForUnit(unitId) {
|
|
232
|
-
const subUnits = this.drawingManagerData
|
|
245
|
+
const subUnits = getOwn(this.drawingManagerData, unitId);
|
|
233
246
|
if (subUnits == null) return;
|
|
234
247
|
delete this.drawingManagerData[unitId];
|
|
235
248
|
const drawings = [];
|
|
@@ -247,11 +260,13 @@ var UnitDrawingService = class {
|
|
|
247
260
|
if (drawings.length > 0) this.removeNotification(drawings);
|
|
248
261
|
}
|
|
249
262
|
registerDrawingData(unitId, data) {
|
|
263
|
+
assertSafeDrawingKeys(unitId);
|
|
264
|
+
validateDrawingData(data);
|
|
250
265
|
this.drawingManagerData[unitId] = data;
|
|
251
266
|
}
|
|
252
267
|
initializeNotification(unitId) {
|
|
253
268
|
const drawings = [];
|
|
254
|
-
const data = this.drawingManagerData
|
|
269
|
+
const data = getOwn(this.drawingManagerData, unitId);
|
|
255
270
|
if (data == null) return;
|
|
256
271
|
Object.keys(data).forEach((subUnitId) => {
|
|
257
272
|
this._establishDrawingMap(unitId, subUnitId);
|
|
@@ -270,6 +285,9 @@ var UnitDrawingService = class {
|
|
|
270
285
|
return this._getDrawingData(unitId, subUnitId);
|
|
271
286
|
}
|
|
272
287
|
setDrawingData(unitId, subUnitId, data) {
|
|
288
|
+
assertSafeDrawingKeys(unitId, subUnitId);
|
|
289
|
+
Object.keys(data).forEach((key) => assertSafeDrawingKeys(key));
|
|
290
|
+
this._establishDrawingMap(unitId, subUnitId);
|
|
273
291
|
const unitData = this.drawingManagerData[unitId];
|
|
274
292
|
const subUnitData = unitData[subUnitId];
|
|
275
293
|
this._oldDrawingManagerData = {
|
|
@@ -295,8 +313,8 @@ var UnitDrawingService = class {
|
|
|
295
313
|
ops.push(op);
|
|
296
314
|
invertOps.push(invertOp);
|
|
297
315
|
});
|
|
298
|
-
const op = ops.reduce(
|
|
299
|
-
const invertOp = invertOps.reduce(
|
|
316
|
+
const op = ops.reduce(JSON1.type.compose, null);
|
|
317
|
+
const invertOp = invertOps.reduce(JSON1.type.compose, null);
|
|
300
318
|
const { unitId, subUnitId } = insertParams[0];
|
|
301
319
|
return {
|
|
302
320
|
undo: invertOp,
|
|
@@ -391,9 +409,9 @@ var UnitDrawingService = class {
|
|
|
391
409
|
ops.unshift(op);
|
|
392
410
|
invertOps.push(invertOp);
|
|
393
411
|
});
|
|
394
|
-
const op = ops.reduce(
|
|
412
|
+
const op = ops.reduce(JSON1.type.compose, null);
|
|
395
413
|
return {
|
|
396
|
-
undo: invertOps.reduce(
|
|
414
|
+
undo: invertOps.reduce(JSON1.type.compose, null),
|
|
397
415
|
redo: op,
|
|
398
416
|
unitId,
|
|
399
417
|
subUnitId,
|
|
@@ -425,8 +443,8 @@ var UnitDrawingService = class {
|
|
|
425
443
|
objects
|
|
426
444
|
};
|
|
427
445
|
}
|
|
428
|
-
const op = ops.reduce(
|
|
429
|
-
const invertOp = invertOps.reduce(
|
|
446
|
+
const op = ops.reduce(JSON1.type.compose, null);
|
|
447
|
+
const invertOp = invertOps.reduce(JSON1.type.compose, null);
|
|
430
448
|
const { unitId, subUnitId } = updateParams[0];
|
|
431
449
|
return {
|
|
432
450
|
undo: invertOp,
|
|
@@ -463,9 +481,9 @@ var UnitDrawingService = class {
|
|
|
463
481
|
groupParams.forEach((groupParam) => {
|
|
464
482
|
ops.push(this._getGroupDrawingOp(groupParam));
|
|
465
483
|
});
|
|
466
|
-
const op = ops.reduce(
|
|
484
|
+
const op = ops.reduce(JSON1.type.compose, null);
|
|
467
485
|
return {
|
|
468
|
-
undo:
|
|
486
|
+
undo: JSON1.type.invertWithDoc(op, this.drawingManagerData),
|
|
469
487
|
redo: op,
|
|
470
488
|
unitId,
|
|
471
489
|
subUnitId,
|
|
@@ -478,9 +496,9 @@ var UnitDrawingService = class {
|
|
|
478
496
|
groupParams.forEach((groupParam) => {
|
|
479
497
|
ops.push(this._getUngroupDrawingOp(groupParam));
|
|
480
498
|
});
|
|
481
|
-
const op = ops.reduce(
|
|
499
|
+
const op = ops.reduce(JSON1.type.compose, null);
|
|
482
500
|
return {
|
|
483
|
-
undo:
|
|
501
|
+
undo: JSON1.type.invertWithDoc(op, this.drawingManagerData),
|
|
484
502
|
redo: op,
|
|
485
503
|
unitId,
|
|
486
504
|
subUnitId,
|
|
@@ -545,7 +563,7 @@ var UnitDrawingService = class {
|
|
|
545
563
|
const { parent, children } = groupParam;
|
|
546
564
|
const { unitId: groupUnitId, subUnitId: groupSubUnitId, drawingId: groupDrawingId } = parent;
|
|
547
565
|
const ops = [];
|
|
548
|
-
ops.push(
|
|
566
|
+
ops.push(JSON1.insertOp([
|
|
549
567
|
groupUnitId,
|
|
550
568
|
groupSubUnitId,
|
|
551
569
|
"data",
|
|
@@ -567,13 +585,13 @@ var UnitDrawingService = class {
|
|
|
567
585
|
})));
|
|
568
586
|
});
|
|
569
587
|
if (maxChildIndex === Number.NEGATIVE_INFINITY) maxChildIndex = this._getDrawingOrder(groupUnitId, groupSubUnitId).length;
|
|
570
|
-
ops.push(
|
|
588
|
+
ops.push(JSON1.insertOp([
|
|
571
589
|
groupUnitId,
|
|
572
590
|
groupSubUnitId,
|
|
573
591
|
"order",
|
|
574
592
|
maxChildIndex
|
|
575
593
|
], groupDrawingId));
|
|
576
|
-
return ops.reduce(
|
|
594
|
+
return ops.reduce(JSON1.type.compose, null);
|
|
577
595
|
}
|
|
578
596
|
_getUngroupDrawingOp(groupParam) {
|
|
579
597
|
const { parent, children } = groupParam;
|
|
@@ -587,24 +605,41 @@ var UnitDrawingService = class {
|
|
|
587
605
|
drawingId
|
|
588
606
|
})));
|
|
589
607
|
});
|
|
590
|
-
ops.push(
|
|
608
|
+
ops.push(JSON1.removeOp([
|
|
591
609
|
groupUnitId,
|
|
592
610
|
groupSubUnitId,
|
|
593
611
|
"data",
|
|
594
612
|
groupDrawingId
|
|
595
613
|
], true));
|
|
596
|
-
ops.push(
|
|
614
|
+
ops.push(JSON1.removeOp([
|
|
597
615
|
groupUnitId,
|
|
598
616
|
groupSubUnitId,
|
|
599
617
|
"order",
|
|
600
618
|
this._getDrawingOrder(groupUnitId, groupSubUnitId).indexOf(groupDrawingId)
|
|
601
619
|
], true));
|
|
602
|
-
return ops.reduce(
|
|
620
|
+
return ops.reduce(JSON1.type.compose, null);
|
|
603
621
|
}
|
|
604
622
|
applyJson1(unitId, subUnitId, jsonOp) {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
623
|
+
assertSafeDrawingKeys(unitId, subUnitId);
|
|
624
|
+
JSON1.type.checkValidOp(jsonOp);
|
|
625
|
+
const unitData = getOwn(this.drawingManagerData, unitId);
|
|
626
|
+
const data = {
|
|
627
|
+
...this.drawingManagerData,
|
|
628
|
+
[unitId]: {
|
|
629
|
+
...unitData,
|
|
630
|
+
[subUnitId]: getOwn(unitData, subUnitId) ?? {
|
|
631
|
+
data: {},
|
|
632
|
+
order: []
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
const nextData = JSON1.type.apply(data, jsonOp);
|
|
637
|
+
for (const id of Object.keys(nextData)) {
|
|
638
|
+
assertSafeDrawingKeys(id);
|
|
639
|
+
validateDrawingData(nextData[id]);
|
|
640
|
+
}
|
|
641
|
+
this._oldDrawingManagerData = this.drawingManagerData;
|
|
642
|
+
this.drawingManagerData = nextData;
|
|
608
643
|
}
|
|
609
644
|
featurePluginUpdateNotification(updateParams) {
|
|
610
645
|
this._featurePluginUpdate$.next(updateParams);
|
|
@@ -670,6 +705,9 @@ var UnitDrawingService = class {
|
|
|
670
705
|
return this._getDrawingOrder(unitId, subUnitId);
|
|
671
706
|
}
|
|
672
707
|
setDrawingOrder(unitId, subUnitId, order) {
|
|
708
|
+
assertSafeDrawingKeys(unitId, subUnitId);
|
|
709
|
+
order.forEach((key) => assertSafeDrawingKeys(key));
|
|
710
|
+
this._establishDrawingMap(unitId, subUnitId);
|
|
673
711
|
this.drawingManagerData[unitId][subUnitId].order = order;
|
|
674
712
|
}
|
|
675
713
|
orderUpdateNotification(orderParams) {
|
|
@@ -687,7 +725,7 @@ var UnitDrawingService = class {
|
|
|
687
725
|
drawingId
|
|
688
726
|
});
|
|
689
727
|
if (index === -1 || index === orders.length - 1) return;
|
|
690
|
-
const op =
|
|
728
|
+
const op = JSON1.moveOp([
|
|
691
729
|
unitId,
|
|
692
730
|
subUnitId,
|
|
693
731
|
"order",
|
|
@@ -701,9 +739,9 @@ var UnitDrawingService = class {
|
|
|
701
739
|
ops.push(op);
|
|
702
740
|
if (!newIds.includes(orders[index + 1])) newIds.push(orders[index + 1]);
|
|
703
741
|
});
|
|
704
|
-
const op = ops.reduce(
|
|
742
|
+
const op = ops.reduce(JSON1.type.compose, null);
|
|
705
743
|
return {
|
|
706
|
-
undo:
|
|
744
|
+
undo: JSON1.type.invertWithDoc(op, this.drawingManagerData),
|
|
707
745
|
redo: op,
|
|
708
746
|
unitId,
|
|
709
747
|
subUnitId,
|
|
@@ -725,7 +763,7 @@ var UnitDrawingService = class {
|
|
|
725
763
|
drawingId
|
|
726
764
|
});
|
|
727
765
|
if (index === -1 || index === 0) return;
|
|
728
|
-
const op =
|
|
766
|
+
const op = JSON1.moveOp([
|
|
729
767
|
unitId,
|
|
730
768
|
subUnitId,
|
|
731
769
|
"order",
|
|
@@ -739,9 +777,9 @@ var UnitDrawingService = class {
|
|
|
739
777
|
ops.push(op);
|
|
740
778
|
if (!newIds.includes(orders[index - 1])) newIds.push(orders[index - 1]);
|
|
741
779
|
});
|
|
742
|
-
const op = ops.reduce(
|
|
780
|
+
const op = ops.reduce(JSON1.type.compose, null);
|
|
743
781
|
return {
|
|
744
|
-
undo:
|
|
782
|
+
undo: JSON1.type.invertWithDoc(op, this.drawingManagerData),
|
|
745
783
|
redo: op,
|
|
746
784
|
unitId,
|
|
747
785
|
subUnitId,
|
|
@@ -760,7 +798,7 @@ var UnitDrawingService = class {
|
|
|
760
798
|
orderDrawingIds.forEach((orderDrawingId) => {
|
|
761
799
|
const { drawingId } = orderDrawingId;
|
|
762
800
|
const index = this._getDrawingCount(unitId, subUnitId) - 1;
|
|
763
|
-
const op =
|
|
801
|
+
const op = JSON1.moveOp([
|
|
764
802
|
unitId,
|
|
765
803
|
subUnitId,
|
|
766
804
|
"order",
|
|
@@ -774,9 +812,9 @@ var UnitDrawingService = class {
|
|
|
774
812
|
ops.push(op);
|
|
775
813
|
if (!newIds.includes(orders[index])) newIds.push(orders[index]);
|
|
776
814
|
});
|
|
777
|
-
const op = ops.reduce(
|
|
815
|
+
const op = ops.reduce(JSON1.type.compose, null);
|
|
778
816
|
return {
|
|
779
|
-
undo:
|
|
817
|
+
undo: JSON1.type.invertWithDoc(op, this.drawingManagerData),
|
|
780
818
|
redo: op,
|
|
781
819
|
unitId,
|
|
782
820
|
subUnitId,
|
|
@@ -794,7 +832,7 @@ var UnitDrawingService = class {
|
|
|
794
832
|
const ops = [];
|
|
795
833
|
orderSearchParams.forEach((orderSearchParam) => {
|
|
796
834
|
const { drawingId } = orderSearchParam;
|
|
797
|
-
const op =
|
|
835
|
+
const op = JSON1.moveOp([
|
|
798
836
|
unitId,
|
|
799
837
|
subUnitId,
|
|
800
838
|
"order",
|
|
@@ -808,9 +846,9 @@ var UnitDrawingService = class {
|
|
|
808
846
|
ops.push(op);
|
|
809
847
|
if (!newIds.includes(orders[0])) newIds.push(orders[0]);
|
|
810
848
|
});
|
|
811
|
-
const op = ops.reduce(
|
|
849
|
+
const op = ops.reduce(JSON1.type.compose, null);
|
|
812
850
|
return {
|
|
813
|
-
undo:
|
|
851
|
+
undo: JSON1.type.invertWithDoc(op, this.drawingManagerData),
|
|
814
852
|
redo: op,
|
|
815
853
|
unitId,
|
|
816
854
|
subUnitId,
|
|
@@ -828,7 +866,7 @@ var UnitDrawingService = class {
|
|
|
828
866
|
const currentIndex = orders.indexOf(drawingId);
|
|
829
867
|
const targetIndex = normalizeDrawingOrderIndex(zOrder, orders.length);
|
|
830
868
|
if (currentIndex < 0 || currentIndex === targetIndex) return null;
|
|
831
|
-
const op =
|
|
869
|
+
const op = JSON1.moveOp([
|
|
832
870
|
unitId,
|
|
833
871
|
subUnitId,
|
|
834
872
|
"order",
|
|
@@ -839,7 +877,7 @@ var UnitDrawingService = class {
|
|
|
839
877
|
"order",
|
|
840
878
|
targetIndex
|
|
841
879
|
]);
|
|
842
|
-
const invertOp =
|
|
880
|
+
const invertOp = JSON1.type.invertWithDoc(op, this.drawingManagerData);
|
|
843
881
|
const affectedDrawingIds = orders.slice(Math.min(currentIndex, targetIndex), Math.max(currentIndex, targetIndex) + 1);
|
|
844
882
|
return {
|
|
845
883
|
undo: invertOp,
|
|
@@ -874,44 +912,45 @@ var UnitDrawingService = class {
|
|
|
874
912
|
return this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId);
|
|
875
913
|
}
|
|
876
914
|
_getCurrentBySearch(searchParam) {
|
|
877
|
-
var
|
|
915
|
+
var _getOwn;
|
|
878
916
|
if (searchParam == null) return;
|
|
879
917
|
const { unitId, subUnitId, drawingId } = searchParam;
|
|
880
|
-
return (
|
|
918
|
+
return getOwn((_getOwn = getOwn(getOwn(this.drawingManagerData, unitId), subUnitId)) === null || _getOwn === void 0 ? void 0 : _getOwn.data, drawingId);
|
|
881
919
|
}
|
|
882
920
|
_getOldBySearch(searchParam) {
|
|
883
|
-
var
|
|
921
|
+
var _getOwn2;
|
|
884
922
|
if (searchParam == null) return;
|
|
885
923
|
const { unitId, subUnitId, drawingId } = searchParam;
|
|
886
|
-
return (
|
|
924
|
+
return getOwn((_getOwn2 = getOwn(getOwn(this._oldDrawingManagerData, unitId), subUnitId)) === null || _getOwn2 === void 0 ? void 0 : _getOwn2.data, drawingId);
|
|
887
925
|
}
|
|
888
926
|
_establishDrawingMap(unitId, subUnitId, drawingId) {
|
|
889
|
-
|
|
890
|
-
if (
|
|
891
|
-
if (!this.drawingManagerData
|
|
927
|
+
assertSafeDrawingKeys(unitId, subUnitId);
|
|
928
|
+
if (drawingId != null) assertSafeDrawingKeys(drawingId);
|
|
929
|
+
if (!getOwn(this.drawingManagerData, unitId)) this.drawingManagerData[unitId] = {};
|
|
930
|
+
if (!getOwn(this.drawingManagerData[unitId], subUnitId)) this.drawingManagerData[unitId][subUnitId] = {
|
|
892
931
|
data: {},
|
|
893
932
|
order: []
|
|
894
933
|
};
|
|
895
934
|
if (drawingId == null) return null;
|
|
896
|
-
return (
|
|
935
|
+
return getOwn(this.drawingManagerData[unitId][subUnitId].data, drawingId);
|
|
897
936
|
}
|
|
898
937
|
_addByParam(insertParam) {
|
|
899
938
|
const { unitId, subUnitId, drawingId } = insertParam;
|
|
900
939
|
this._establishDrawingMap(unitId, subUnitId, drawingId);
|
|
901
|
-
const op = [
|
|
940
|
+
const op = [JSON1.insertOp([
|
|
902
941
|
unitId,
|
|
903
942
|
subUnitId,
|
|
904
943
|
"data",
|
|
905
944
|
drawingId
|
|
906
|
-
], insertParam),
|
|
945
|
+
], insertParam), JSON1.insertOp([
|
|
907
946
|
unitId,
|
|
908
947
|
subUnitId,
|
|
909
948
|
"order",
|
|
910
949
|
this._getDrawingOrder(unitId, subUnitId).length
|
|
911
|
-
], drawingId)].reduce(
|
|
950
|
+
], drawingId)].reduce(JSON1.type.compose, null);
|
|
912
951
|
return {
|
|
913
952
|
op,
|
|
914
|
-
invertOp:
|
|
953
|
+
invertOp: JSON1.type.invertWithDoc(op, this.drawingManagerData)
|
|
915
954
|
};
|
|
916
955
|
}
|
|
917
956
|
_removeByParam(searchParam) {
|
|
@@ -924,20 +963,20 @@ var UnitDrawingService = class {
|
|
|
924
963
|
op: [],
|
|
925
964
|
invertOp: []
|
|
926
965
|
};
|
|
927
|
-
const op = [
|
|
966
|
+
const op = [JSON1.removeOp([
|
|
928
967
|
unitId,
|
|
929
968
|
subUnitId,
|
|
930
969
|
"data",
|
|
931
970
|
drawingId
|
|
932
|
-
], true),
|
|
971
|
+
], true), JSON1.removeOp([
|
|
933
972
|
unitId,
|
|
934
973
|
subUnitId,
|
|
935
974
|
"order",
|
|
936
975
|
this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId)
|
|
937
|
-
], true)].reduce(
|
|
976
|
+
], true)].reduce(JSON1.type.compose, null);
|
|
938
977
|
return {
|
|
939
978
|
op,
|
|
940
|
-
invertOp:
|
|
979
|
+
invertOp: JSON1.type.invertWithDoc(op, this.drawingManagerData)
|
|
941
980
|
};
|
|
942
981
|
}
|
|
943
982
|
_updateByParam(updateParam) {
|
|
@@ -952,10 +991,10 @@ var UnitDrawingService = class {
|
|
|
952
991
|
op: [],
|
|
953
992
|
invertOp: []
|
|
954
993
|
};
|
|
955
|
-
const op = ops.reduce(
|
|
994
|
+
const op = ops.reduce(JSON1.type.compose, null);
|
|
956
995
|
return {
|
|
957
996
|
op,
|
|
958
|
-
invertOp:
|
|
997
|
+
invertOp: JSON1.type.invert(op)
|
|
959
998
|
};
|
|
960
999
|
}
|
|
961
1000
|
_getUpdateParamCompareOp(newParam, oldParam) {
|
|
@@ -976,12 +1015,12 @@ var UnitDrawingService = class {
|
|
|
976
1015
|
return ops;
|
|
977
1016
|
}
|
|
978
1017
|
_getDrawingData(unitId, subUnitId) {
|
|
979
|
-
var
|
|
980
|
-
return ((
|
|
1018
|
+
var _getOwn3;
|
|
1019
|
+
return ((_getOwn3 = getOwn(getOwn(this.drawingManagerData, unitId), subUnitId)) === null || _getOwn3 === void 0 ? void 0 : _getOwn3.data) || {};
|
|
981
1020
|
}
|
|
982
1021
|
_getDrawingOrder(unitId, subUnitId) {
|
|
983
|
-
var
|
|
984
|
-
return ((
|
|
1022
|
+
var _getOwn4;
|
|
1023
|
+
return ((_getOwn4 = getOwn(getOwn(this.drawingManagerData, unitId), subUnitId)) === null || _getOwn4 === void 0 ? void 0 : _getOwn4.order) || [];
|
|
985
1024
|
}
|
|
986
1025
|
getDrawingVisible() {
|
|
987
1026
|
return this._visible;
|
|
@@ -1102,7 +1141,7 @@ var URLImageService = class extends Disposable {
|
|
|
1102
1141
|
};
|
|
1103
1142
|
|
|
1104
1143
|
//#endregion
|
|
1105
|
-
//#region \0@oxc-project+runtime@0.
|
|
1144
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
|
|
1106
1145
|
function __decorateParam(paramIndex, decorator) {
|
|
1107
1146
|
return function(target, key) {
|
|
1108
1147
|
decorator(target, key, paramIndex);
|
|
@@ -1110,7 +1149,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
1110
1149
|
}
|
|
1111
1150
|
|
|
1112
1151
|
//#endregion
|
|
1113
|
-
//#region \0@oxc-project+runtime@0.
|
|
1152
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
|
|
1114
1153
|
function __decorate(decorators, target, key, desc) {
|
|
1115
1154
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1116
1155
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1220,6 +1259,8 @@ const DRAWING_GROUPABLE_TYPES = [
|
|
|
1220
1259
|
DrawingTypeEnum.DRAWING_IMAGE,
|
|
1221
1260
|
DrawingTypeEnum.DRAWING_SHAPE,
|
|
1222
1261
|
DrawingTypeEnum.DRAWING_CHART,
|
|
1262
|
+
DrawingTypeEnum.DRAWING_SLICER,
|
|
1263
|
+
DrawingTypeEnum.DRAWING_TIMELINE,
|
|
1223
1264
|
DrawingTypeEnum.DRAWING_GROUP
|
|
1224
1265
|
];
|
|
1225
1266
|
function isGroupableDrawingType(type) {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
import type { IDrawingGroupNestedParam, IDrawingParam, IDrawingSearch, Nullable } from '@univerjs/core';
|
|
17
17
|
import type { Observable } from 'rxjs';
|
|
18
18
|
import type { IDrawingGroupUpdateParam, IDrawingMap, IDrawingMapItemData, IDrawingOrderMapParam, IDrawingOrderUpdateParam, IDrawingSubunitMap, IDrawingVisibleParam, IUnitDrawingService } from './drawing-manager.service';
|
|
19
|
-
import
|
|
20
|
-
type JSONOp =
|
|
21
|
-
type JSONOpList =
|
|
19
|
+
import { JSON1 } from '@univerjs/core';
|
|
20
|
+
type JSONOp = JSON1.JSONOp;
|
|
21
|
+
type JSONOpList = JSON1.JSONOpList;
|
|
22
22
|
export interface IDrawingJsonUndo1<TObjects = IDrawingSearch[] | IDrawingOrderMapParam | IDrawingGroupUpdateParam | IDrawingGroupUpdateParam[]> {
|
|
23
23
|
undo: JSONOp;
|
|
24
24
|
redo: JSONOp;
|
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { DrawingType } from '@univerjs/core';
|
|
17
17
|
import { DrawingTypeEnum } from '@univerjs/core';
|
|
18
|
-
export declare const DRAWING_GROUPABLE_TYPES: readonly [DrawingTypeEnum.DRAWING_IMAGE, DrawingTypeEnum.DRAWING_SHAPE, DrawingTypeEnum.DRAWING_CHART, DrawingTypeEnum.DRAWING_GROUP];
|
|
18
|
+
export declare const DRAWING_GROUPABLE_TYPES: readonly [DrawingTypeEnum.DRAWING_IMAGE, DrawingTypeEnum.DRAWING_SHAPE, DrawingTypeEnum.DRAWING_CHART, DrawingTypeEnum.DRAWING_SLICER, DrawingTypeEnum.DRAWING_TIMELINE, DrawingTypeEnum.DRAWING_GROUP];
|
|
19
19
|
export declare function isGroupableDrawingType(type: DrawingType): boolean;
|