@univerjs/drawing 1.0.0-alpha.1 → 1.0.0-alpha.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/lib/cjs/index.js +184 -43
- package/lib/es/index.js +187 -34
- package/lib/index.js +187 -34
- package/lib/types/index.d.ts +4 -2
- package/lib/types/services/drawing-manager-impl.service.d.ts +1 -0
- package/lib/types/utils/drawing-group.d.ts +32 -0
- package/lib/types/utils/rotate-enabled.d.ts +28 -0
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
package/lib/cjs/index.js
CHANGED
|
@@ -85,7 +85,7 @@ const SetDrawingSelectedOperation = {
|
|
|
85
85
|
//#endregion
|
|
86
86
|
//#region package.json
|
|
87
87
|
var name = "@univerjs/drawing";
|
|
88
|
-
var version = "1.0.0-alpha.
|
|
88
|
+
var version = "1.0.0-alpha.3";
|
|
89
89
|
|
|
90
90
|
//#endregion
|
|
91
91
|
//#region src/config/config.ts
|
|
@@ -137,6 +137,23 @@ function _defineProperty(e, r, t) {
|
|
|
137
137
|
|
|
138
138
|
//#endregion
|
|
139
139
|
//#region src/services/drawing-manager-impl.service.ts
|
|
140
|
+
function isNonEmptyOp(op) {
|
|
141
|
+
return Array.isArray(op) && op.length > 0;
|
|
142
|
+
}
|
|
143
|
+
function isJsonValueEqual(left, right) {
|
|
144
|
+
if (left === right) return true;
|
|
145
|
+
if (left == null || right == null || typeof left !== "object" || typeof right !== "object") return false;
|
|
146
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
147
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
148
|
+
return left.every((item, index) => isJsonValueEqual(item, right[index]));
|
|
149
|
+
}
|
|
150
|
+
const leftRecord = left;
|
|
151
|
+
const rightRecord = right;
|
|
152
|
+
const leftKeys = Object.keys(leftRecord);
|
|
153
|
+
const rightKeys = Object.keys(rightRecord);
|
|
154
|
+
if (leftKeys.length !== rightKeys.length) return false;
|
|
155
|
+
return leftKeys.every((key) => Object.prototype.hasOwnProperty.call(rightRecord, key) && isJsonValueEqual(leftRecord[key], rightRecord[key]));
|
|
156
|
+
}
|
|
140
157
|
/**
|
|
141
158
|
* unitId -> subUnitId -> drawingId -> drawingParam
|
|
142
159
|
*/
|
|
@@ -237,6 +254,7 @@ var UnitDrawingService = class {
|
|
|
237
254
|
Object.keys(data).forEach((subUnitId) => {
|
|
238
255
|
this._establishDrawingMap(unitId, subUnitId);
|
|
239
256
|
const subUnitData = data[subUnitId];
|
|
257
|
+
if ((subUnitData === null || subUnitData === void 0 ? void 0 : subUnitData.data) == null) return;
|
|
240
258
|
Object.keys(subUnitData.data).forEach((drawingId) => {
|
|
241
259
|
const drawing = subUnitData.data[drawingId];
|
|
242
260
|
drawing.unitId = unitId;
|
|
@@ -296,10 +314,23 @@ var UnitDrawingService = class {
|
|
|
296
314
|
});
|
|
297
315
|
return this.getBatchRemoveOp(removeParams);
|
|
298
316
|
}
|
|
299
|
-
|
|
300
|
-
var _allToRemove$;
|
|
317
|
+
_getExpandedBatchRemoveParams(removeParams) {
|
|
301
318
|
const seenIds = /* @__PURE__ */ new Set();
|
|
302
319
|
const allToRemove = [];
|
|
320
|
+
const addDrawing = (drawing) => {
|
|
321
|
+
if (seenIds.has(drawing.drawingId)) return;
|
|
322
|
+
seenIds.add(drawing.drawingId);
|
|
323
|
+
allToRemove.push({
|
|
324
|
+
unitId: drawing.unitId,
|
|
325
|
+
subUnitId: drawing.subUnitId,
|
|
326
|
+
drawingId: drawing.drawingId
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
const addSearch = (search) => {
|
|
330
|
+
if (seenIds.has(search.drawingId)) return;
|
|
331
|
+
seenIds.add(search.drawingId);
|
|
332
|
+
allToRemove.push(search);
|
|
333
|
+
};
|
|
303
334
|
removeParams.forEach((removeParam) => {
|
|
304
335
|
const drawing = this.getDrawingByParam(removeParam);
|
|
305
336
|
if ((drawing === null || drawing === void 0 ? void 0 : drawing.drawingType) === _univerjs_core.DrawingTypeEnum.DRAWING_GROUP) {
|
|
@@ -307,25 +338,28 @@ var UnitDrawingService = class {
|
|
|
307
338
|
if (nested) {
|
|
308
339
|
const { flatChildren, groups } = nested;
|
|
309
340
|
[...flatChildren !== null && flatChildren !== void 0 ? flatChildren : [], ...groups].forEach((d) => {
|
|
310
|
-
|
|
311
|
-
seenIds.add(d.drawingId);
|
|
312
|
-
allToRemove.push({
|
|
313
|
-
unitId: d.unitId,
|
|
314
|
-
subUnitId: d.subUnitId,
|
|
315
|
-
drawingId: d.drawingId
|
|
316
|
-
});
|
|
317
|
-
}
|
|
341
|
+
addDrawing(d);
|
|
318
342
|
});
|
|
319
|
-
} else
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
} else if (!seenIds.has(removeParam.drawingId)) {
|
|
324
|
-
seenIds.add(removeParam.drawingId);
|
|
325
|
-
allToRemove.push(removeParam);
|
|
326
|
-
}
|
|
343
|
+
} else addDrawing(drawing);
|
|
344
|
+
} else if (drawing) addDrawing(drawing);
|
|
345
|
+
else addSearch(removeParam);
|
|
327
346
|
});
|
|
328
|
-
|
|
347
|
+
return allToRemove;
|
|
348
|
+
}
|
|
349
|
+
getBatchRemoveOp(removeParams) {
|
|
350
|
+
var _ref, _allToRemove$;
|
|
351
|
+
const allToRemove = this._getExpandedBatchRemoveParams(removeParams);
|
|
352
|
+
const { unitId, subUnitId } = (_ref = (_allToRemove$ = allToRemove[0]) !== null && _allToRemove$ !== void 0 ? _allToRemove$ : removeParams[0]) !== null && _ref !== void 0 ? _ref : {
|
|
353
|
+
unitId: "",
|
|
354
|
+
subUnitId: ""
|
|
355
|
+
};
|
|
356
|
+
if (allToRemove.length === 0) return {
|
|
357
|
+
undo: null,
|
|
358
|
+
redo: null,
|
|
359
|
+
unitId,
|
|
360
|
+
subUnitId,
|
|
361
|
+
objects: []
|
|
362
|
+
};
|
|
329
363
|
const orderArr = this._getDrawingOrder(unitId, subUnitId);
|
|
330
364
|
const orderIndexMap = /* @__PURE__ */ new Map();
|
|
331
365
|
orderArr.forEach((id, idx) => orderIndexMap.set(id, idx));
|
|
@@ -364,6 +398,7 @@ var UnitDrawingService = class {
|
|
|
364
398
|
const invertOps = [];
|
|
365
399
|
updateParams.forEach((updateParam) => {
|
|
366
400
|
const { op, invertOp } = this._updateByParam(updateParam);
|
|
401
|
+
if (!isNonEmptyOp(op)) return;
|
|
367
402
|
objects.push({
|
|
368
403
|
unitId: updateParam.unitId,
|
|
369
404
|
subUnitId: updateParam.subUnitId,
|
|
@@ -372,6 +407,16 @@ var UnitDrawingService = class {
|
|
|
372
407
|
ops.push(op);
|
|
373
408
|
invertOps.push(invertOp);
|
|
374
409
|
});
|
|
410
|
+
if (ops.length === 0) {
|
|
411
|
+
const { unitId, subUnitId } = updateParams[0];
|
|
412
|
+
return {
|
|
413
|
+
undo: null,
|
|
414
|
+
redo: null,
|
|
415
|
+
unitId,
|
|
416
|
+
subUnitId,
|
|
417
|
+
objects
|
|
418
|
+
};
|
|
419
|
+
}
|
|
375
420
|
const op = ops.reduce(ot_json1.type.compose, null);
|
|
376
421
|
const invertOp = invertOps.reduce(ot_json1.type.compose, null);
|
|
377
422
|
const { unitId, subUnitId } = updateParams[0];
|
|
@@ -863,7 +908,12 @@ var UnitDrawingService = class {
|
|
|
863
908
|
op: [],
|
|
864
909
|
invertOp: []
|
|
865
910
|
};
|
|
866
|
-
const
|
|
911
|
+
const ops = this._getUpdateParamCompareOp(updateParam, object);
|
|
912
|
+
if (ops.length === 0) return {
|
|
913
|
+
op: [],
|
|
914
|
+
invertOp: []
|
|
915
|
+
};
|
|
916
|
+
const op = ops.reduce(ot_json1.type.compose, null);
|
|
867
917
|
return {
|
|
868
918
|
op,
|
|
869
919
|
invertOp: ot_json1.type.invertWithDoc(op, this.drawingManagerData)
|
|
@@ -874,15 +924,29 @@ var UnitDrawingService = class {
|
|
|
874
924
|
const ops = [];
|
|
875
925
|
Object.keys(newParam).forEach((key) => {
|
|
876
926
|
const newVal = newParam[key];
|
|
927
|
+
const hasOldKey = Object.prototype.hasOwnProperty.call(oldParam, key);
|
|
877
928
|
const oldVal = oldParam[key];
|
|
878
|
-
if (oldVal
|
|
879
|
-
|
|
929
|
+
if (hasOldKey && isJsonValueEqual(oldVal, newVal)) return;
|
|
930
|
+
const path = [
|
|
880
931
|
unitId,
|
|
881
932
|
subUnitId,
|
|
882
933
|
"data",
|
|
883
934
|
drawingId,
|
|
884
935
|
key
|
|
885
|
-
]
|
|
936
|
+
];
|
|
937
|
+
if (!hasOldKey) {
|
|
938
|
+
if (newVal === void 0) return;
|
|
939
|
+
const op = ot_json1.insertOp(path, newVal);
|
|
940
|
+
if (isNonEmptyOp(op)) ops.push(op);
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
if (newVal === void 0) {
|
|
944
|
+
const op = ot_json1.removeOp(path, true);
|
|
945
|
+
if (isNonEmptyOp(op)) ops.push(op);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
const op = ot_json1.replaceOp(path, oldVal, newVal);
|
|
949
|
+
if (isNonEmptyOp(op)) ops.push(op);
|
|
886
950
|
});
|
|
887
951
|
return ops;
|
|
888
952
|
}
|
|
@@ -1067,6 +1131,69 @@ UniverDrawingPlugin = __decorate([
|
|
|
1067
1131
|
__decorateParam(3, _univerjs_core.ICommandService)
|
|
1068
1132
|
], UniverDrawingPlugin);
|
|
1069
1133
|
|
|
1134
|
+
//#endregion
|
|
1135
|
+
//#region src/utils/drawing-group.ts
|
|
1136
|
+
const DRAWING_GROUPABLE_TYPES = [
|
|
1137
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_IMAGE,
|
|
1138
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_SHAPE,
|
|
1139
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_CHART,
|
|
1140
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_GROUP
|
|
1141
|
+
];
|
|
1142
|
+
function isGroupableDrawingType(type) {
|
|
1143
|
+
return DRAWING_GROUPABLE_TYPES.includes(type);
|
|
1144
|
+
}
|
|
1145
|
+
const DRAWING_COPY_CONTEXT_KEY = "univer.drawing.copy-plan";
|
|
1146
|
+
function cloneDrawing(drawing) {
|
|
1147
|
+
return JSON.parse(JSON.stringify(drawing));
|
|
1148
|
+
}
|
|
1149
|
+
function copyDrawingWithIdMap(drawing, idMap, options) {
|
|
1150
|
+
const copied = cloneDrawing(drawing);
|
|
1151
|
+
const copiedDrawingId = idMap.get(drawing.drawingId);
|
|
1152
|
+
if (copiedDrawingId == null) return copied;
|
|
1153
|
+
copied.unitId = options.unitId;
|
|
1154
|
+
copied.subUnitId = options.targetSubUnitId;
|
|
1155
|
+
copied.drawingId = copiedDrawingId;
|
|
1156
|
+
if (copied.groupId) {
|
|
1157
|
+
const copiedGroupId = idMap.get(copied.groupId);
|
|
1158
|
+
if (copiedGroupId) copied.groupId = copiedGroupId;
|
|
1159
|
+
else delete copied.groupId;
|
|
1160
|
+
}
|
|
1161
|
+
return copied;
|
|
1162
|
+
}
|
|
1163
|
+
function createDrawingCopyPlan(drawings, options) {
|
|
1164
|
+
const { generateId = () => (0, _univerjs_core.generateRandomId)(10) } = options;
|
|
1165
|
+
const idMap = /* @__PURE__ */ new Map();
|
|
1166
|
+
drawings.forEach((drawing) => {
|
|
1167
|
+
if (!idMap.has(drawing.drawingId)) idMap.set(drawing.drawingId, generateId());
|
|
1168
|
+
});
|
|
1169
|
+
return {
|
|
1170
|
+
idMap,
|
|
1171
|
+
drawings: drawings.map((drawing) => copyDrawingWithIdMap(drawing, idMap, options))
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
function getOrCreateDrawingCopyPlan(copyContext, drawings, options) {
|
|
1175
|
+
if (copyContext == null) return createDrawingCopyPlan(drawings, options);
|
|
1176
|
+
const cached = copyContext.get(DRAWING_COPY_CONTEXT_KEY);
|
|
1177
|
+
if (cached) {
|
|
1178
|
+
const { generateId = () => (0, _univerjs_core.generateRandomId)(10) } = options;
|
|
1179
|
+
if (!drawings.some((drawing) => !cached.idMap.has(drawing.drawingId))) return cached;
|
|
1180
|
+
drawings.forEach((drawing) => {
|
|
1181
|
+
if (!cached.idMap.has(drawing.drawingId)) cached.idMap.set(drawing.drawingId, generateId());
|
|
1182
|
+
});
|
|
1183
|
+
const incomingDrawingIds = new Set(drawings.map((drawing) => drawing.drawingId));
|
|
1184
|
+
const originalIdByCopiedId = new Map(Array.from(cached.idMap.entries()).map(([drawingId, copiedDrawingId]) => [copiedDrawingId, drawingId]));
|
|
1185
|
+
const retainedDrawings = cached.drawings.filter((drawing) => {
|
|
1186
|
+
const originalDrawingId = originalIdByCopiedId.get(drawing.drawingId);
|
|
1187
|
+
return originalDrawingId == null || !incomingDrawingIds.has(originalDrawingId);
|
|
1188
|
+
});
|
|
1189
|
+
cached.drawings = [...drawings.map((drawing) => copyDrawingWithIdMap(drawing, cached.idMap, options)), ...retainedDrawings];
|
|
1190
|
+
return cached;
|
|
1191
|
+
}
|
|
1192
|
+
const plan = createDrawingCopyPlan(drawings, options);
|
|
1193
|
+
copyContext.set(DRAWING_COPY_CONTEXT_KEY, plan);
|
|
1194
|
+
return plan;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1070
1197
|
//#endregion
|
|
1071
1198
|
//#region src/utils/get-image-shape-key.ts
|
|
1072
1199
|
function getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId }, index) {
|
|
@@ -1093,31 +1220,41 @@ const getImageSize = async (src) => {
|
|
|
1093
1220
|
};
|
|
1094
1221
|
|
|
1095
1222
|
//#endregion
|
|
1223
|
+
//#region src/utils/rotate-enabled.ts
|
|
1224
|
+
function getDrawingKey(drawing) {
|
|
1225
|
+
return `${drawing.unitId}\u0000${drawing.subUnitId}\u0000${drawing.drawingId}`;
|
|
1226
|
+
}
|
|
1227
|
+
function resolveDrawingRotateEnabled(drawing, options = {}, visiting = /* @__PURE__ */ new Set()) {
|
|
1228
|
+
var _drawing$transform, _options$getRenderObj, _options$isKnownNonRo;
|
|
1229
|
+
const drawingKey = getDrawingKey(drawing);
|
|
1230
|
+
if (visiting.has(drawingKey)) return true;
|
|
1231
|
+
if (drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_GROUP) {
|
|
1232
|
+
var _options$getChildren;
|
|
1233
|
+
visiting.add(drawingKey);
|
|
1234
|
+
const children = (_options$getChildren = options.getChildren) === null || _options$getChildren === void 0 ? void 0 : _options$getChildren.call(options, drawing);
|
|
1235
|
+
if (children != null) {
|
|
1236
|
+
const enabled = children.every((child) => resolveDrawingRotateEnabled(child, options, visiting));
|
|
1237
|
+
visiting.delete(drawingKey);
|
|
1238
|
+
return enabled;
|
|
1239
|
+
}
|
|
1240
|
+
visiting.delete(drawingKey);
|
|
1241
|
+
}
|
|
1242
|
+
if (((_drawing$transform = drawing.transform) === null || _drawing$transform === void 0 ? void 0 : _drawing$transform.rotateEnabled) === false) return false;
|
|
1243
|
+
if (((_options$getRenderObj = options.getRenderObject) === null || _options$getRenderObj === void 0 || (_options$getRenderObj = _options$getRenderObj.call(options, drawing)) === null || _options$getRenderObj === void 0 || (_options$getRenderObj = _options$getRenderObj.transformerConfig) === null || _options$getRenderObj === void 0 ? void 0 : _options$getRenderObj.rotateEnabled) === false) return false;
|
|
1244
|
+
if ((_options$isKnownNonRo = options.isKnownNonRotatableType) === null || _options$isKnownNonRo === void 0 ? void 0 : _options$isKnownNonRo.call(options, drawing.drawingType)) return false;
|
|
1245
|
+
return true;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
//#endregion
|
|
1249
|
+
exports.DRAWING_COPY_CONTEXT_KEY = DRAWING_COPY_CONTEXT_KEY;
|
|
1250
|
+
exports.DRAWING_GROUPABLE_TYPES = DRAWING_GROUPABLE_TYPES;
|
|
1096
1251
|
exports.DRAWING_IMAGE_ALLOW_IMAGE_LIST = DRAWING_IMAGE_ALLOW_IMAGE_LIST;
|
|
1097
1252
|
exports.DRAWING_IMAGE_COUNT_LIMIT = DRAWING_IMAGE_COUNT_LIMIT;
|
|
1098
1253
|
exports.DRAWING_IMAGE_HEIGHT_LIMIT = DRAWING_IMAGE_HEIGHT_LIMIT;
|
|
1099
1254
|
exports.DRAWING_IMAGE_WIDTH_LIMIT = DRAWING_IMAGE_WIDTH_LIMIT;
|
|
1100
1255
|
exports.DrawingManagerService = DrawingManagerService;
|
|
1101
1256
|
exports.IDrawingManagerService = IDrawingManagerService;
|
|
1102
|
-
Object.defineProperty(exports, 'IImageIoService', {
|
|
1103
|
-
enumerable: true,
|
|
1104
|
-
get: function () {
|
|
1105
|
-
return _univerjs_core.IImageIoService;
|
|
1106
|
-
}
|
|
1107
|
-
});
|
|
1108
1257
|
exports.ImageIoService = ImageIoService;
|
|
1109
|
-
Object.defineProperty(exports, 'ImageSourceType', {
|
|
1110
|
-
enumerable: true,
|
|
1111
|
-
get: function () {
|
|
1112
|
-
return _univerjs_core.ImageSourceType;
|
|
1113
|
-
}
|
|
1114
|
-
});
|
|
1115
|
-
Object.defineProperty(exports, 'ImageUploadStatusType', {
|
|
1116
|
-
enumerable: true,
|
|
1117
|
-
get: function () {
|
|
1118
|
-
return _univerjs_core.ImageUploadStatusType;
|
|
1119
|
-
}
|
|
1120
|
-
});
|
|
1121
1258
|
exports.SetDrawingSelectedOperation = SetDrawingSelectedOperation;
|
|
1122
1259
|
exports.URLImageService = URLImageService;
|
|
1123
1260
|
exports.UnitDrawingService = UnitDrawingService;
|
|
@@ -1127,6 +1264,10 @@ Object.defineProperty(exports, 'UniverDrawingPlugin', {
|
|
|
1127
1264
|
return UniverDrawingPlugin;
|
|
1128
1265
|
}
|
|
1129
1266
|
});
|
|
1267
|
+
exports.createDrawingCopyPlan = createDrawingCopyPlan;
|
|
1130
1268
|
exports.getDrawingImageAllowSize = getDrawingImageAllowSize;
|
|
1131
1269
|
exports.getDrawingShapeKeyByDrawingSearch = getDrawingShapeKeyByDrawingSearch;
|
|
1132
|
-
exports.getImageSize = getImageSize;
|
|
1270
|
+
exports.getImageSize = getImageSize;
|
|
1271
|
+
exports.getOrCreateDrawingCopyPlan = getOrCreateDrawingCopyPlan;
|
|
1272
|
+
exports.isGroupableDrawingType = isGroupableDrawingType;
|
|
1273
|
+
exports.resolveDrawingRotateEnabled = resolveDrawingRotateEnabled;
|
package/lib/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService,
|
|
1
|
+
import { CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService, IURLImageService, ImageSourceType, ImageUploadStatusType, Inject, Injector, Plugin, createIdentifier, generateRandomId, merge, mergeOverrideWithDependencies, sortRules, sortRulesByDesc, toDisposable } from "@univerjs/core";
|
|
2
2
|
import * as json1 from "ot-json1";
|
|
3
3
|
import { Subject } from "rxjs";
|
|
4
4
|
|
|
@@ -56,7 +56,7 @@ const SetDrawingSelectedOperation = {
|
|
|
56
56
|
//#endregion
|
|
57
57
|
//#region package.json
|
|
58
58
|
var name = "@univerjs/drawing";
|
|
59
|
-
var version = "1.0.0-alpha.
|
|
59
|
+
var version = "1.0.0-alpha.3";
|
|
60
60
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/config/config.ts
|
|
@@ -108,6 +108,23 @@ function _defineProperty(e, r, t) {
|
|
|
108
108
|
|
|
109
109
|
//#endregion
|
|
110
110
|
//#region src/services/drawing-manager-impl.service.ts
|
|
111
|
+
function isNonEmptyOp(op) {
|
|
112
|
+
return Array.isArray(op) && op.length > 0;
|
|
113
|
+
}
|
|
114
|
+
function isJsonValueEqual(left, right) {
|
|
115
|
+
if (left === right) return true;
|
|
116
|
+
if (left == null || right == null || typeof left !== "object" || typeof right !== "object") return false;
|
|
117
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
118
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
119
|
+
return left.every((item, index) => isJsonValueEqual(item, right[index]));
|
|
120
|
+
}
|
|
121
|
+
const leftRecord = left;
|
|
122
|
+
const rightRecord = right;
|
|
123
|
+
const leftKeys = Object.keys(leftRecord);
|
|
124
|
+
const rightKeys = Object.keys(rightRecord);
|
|
125
|
+
if (leftKeys.length !== rightKeys.length) return false;
|
|
126
|
+
return leftKeys.every((key) => Object.prototype.hasOwnProperty.call(rightRecord, key) && isJsonValueEqual(leftRecord[key], rightRecord[key]));
|
|
127
|
+
}
|
|
111
128
|
/**
|
|
112
129
|
* unitId -> subUnitId -> drawingId -> drawingParam
|
|
113
130
|
*/
|
|
@@ -208,6 +225,7 @@ var UnitDrawingService = class {
|
|
|
208
225
|
Object.keys(data).forEach((subUnitId) => {
|
|
209
226
|
this._establishDrawingMap(unitId, subUnitId);
|
|
210
227
|
const subUnitData = data[subUnitId];
|
|
228
|
+
if ((subUnitData === null || subUnitData === void 0 ? void 0 : subUnitData.data) == null) return;
|
|
211
229
|
Object.keys(subUnitData.data).forEach((drawingId) => {
|
|
212
230
|
const drawing = subUnitData.data[drawingId];
|
|
213
231
|
drawing.unitId = unitId;
|
|
@@ -267,10 +285,23 @@ var UnitDrawingService = class {
|
|
|
267
285
|
});
|
|
268
286
|
return this.getBatchRemoveOp(removeParams);
|
|
269
287
|
}
|
|
270
|
-
|
|
271
|
-
var _allToRemove$;
|
|
288
|
+
_getExpandedBatchRemoveParams(removeParams) {
|
|
272
289
|
const seenIds = /* @__PURE__ */ new Set();
|
|
273
290
|
const allToRemove = [];
|
|
291
|
+
const addDrawing = (drawing) => {
|
|
292
|
+
if (seenIds.has(drawing.drawingId)) return;
|
|
293
|
+
seenIds.add(drawing.drawingId);
|
|
294
|
+
allToRemove.push({
|
|
295
|
+
unitId: drawing.unitId,
|
|
296
|
+
subUnitId: drawing.subUnitId,
|
|
297
|
+
drawingId: drawing.drawingId
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
const addSearch = (search) => {
|
|
301
|
+
if (seenIds.has(search.drawingId)) return;
|
|
302
|
+
seenIds.add(search.drawingId);
|
|
303
|
+
allToRemove.push(search);
|
|
304
|
+
};
|
|
274
305
|
removeParams.forEach((removeParam) => {
|
|
275
306
|
const drawing = this.getDrawingByParam(removeParam);
|
|
276
307
|
if ((drawing === null || drawing === void 0 ? void 0 : drawing.drawingType) === DrawingTypeEnum.DRAWING_GROUP) {
|
|
@@ -278,25 +309,28 @@ var UnitDrawingService = class {
|
|
|
278
309
|
if (nested) {
|
|
279
310
|
const { flatChildren, groups } = nested;
|
|
280
311
|
[...flatChildren !== null && flatChildren !== void 0 ? flatChildren : [], ...groups].forEach((d) => {
|
|
281
|
-
|
|
282
|
-
seenIds.add(d.drawingId);
|
|
283
|
-
allToRemove.push({
|
|
284
|
-
unitId: d.unitId,
|
|
285
|
-
subUnitId: d.subUnitId,
|
|
286
|
-
drawingId: d.drawingId
|
|
287
|
-
});
|
|
288
|
-
}
|
|
312
|
+
addDrawing(d);
|
|
289
313
|
});
|
|
290
|
-
} else
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
} else if (!seenIds.has(removeParam.drawingId)) {
|
|
295
|
-
seenIds.add(removeParam.drawingId);
|
|
296
|
-
allToRemove.push(removeParam);
|
|
297
|
-
}
|
|
314
|
+
} else addDrawing(drawing);
|
|
315
|
+
} else if (drawing) addDrawing(drawing);
|
|
316
|
+
else addSearch(removeParam);
|
|
298
317
|
});
|
|
299
|
-
|
|
318
|
+
return allToRemove;
|
|
319
|
+
}
|
|
320
|
+
getBatchRemoveOp(removeParams) {
|
|
321
|
+
var _ref, _allToRemove$;
|
|
322
|
+
const allToRemove = this._getExpandedBatchRemoveParams(removeParams);
|
|
323
|
+
const { unitId, subUnitId } = (_ref = (_allToRemove$ = allToRemove[0]) !== null && _allToRemove$ !== void 0 ? _allToRemove$ : removeParams[0]) !== null && _ref !== void 0 ? _ref : {
|
|
324
|
+
unitId: "",
|
|
325
|
+
subUnitId: ""
|
|
326
|
+
};
|
|
327
|
+
if (allToRemove.length === 0) return {
|
|
328
|
+
undo: null,
|
|
329
|
+
redo: null,
|
|
330
|
+
unitId,
|
|
331
|
+
subUnitId,
|
|
332
|
+
objects: []
|
|
333
|
+
};
|
|
300
334
|
const orderArr = this._getDrawingOrder(unitId, subUnitId);
|
|
301
335
|
const orderIndexMap = /* @__PURE__ */ new Map();
|
|
302
336
|
orderArr.forEach((id, idx) => orderIndexMap.set(id, idx));
|
|
@@ -335,6 +369,7 @@ var UnitDrawingService = class {
|
|
|
335
369
|
const invertOps = [];
|
|
336
370
|
updateParams.forEach((updateParam) => {
|
|
337
371
|
const { op, invertOp } = this._updateByParam(updateParam);
|
|
372
|
+
if (!isNonEmptyOp(op)) return;
|
|
338
373
|
objects.push({
|
|
339
374
|
unitId: updateParam.unitId,
|
|
340
375
|
subUnitId: updateParam.subUnitId,
|
|
@@ -343,6 +378,16 @@ var UnitDrawingService = class {
|
|
|
343
378
|
ops.push(op);
|
|
344
379
|
invertOps.push(invertOp);
|
|
345
380
|
});
|
|
381
|
+
if (ops.length === 0) {
|
|
382
|
+
const { unitId, subUnitId } = updateParams[0];
|
|
383
|
+
return {
|
|
384
|
+
undo: null,
|
|
385
|
+
redo: null,
|
|
386
|
+
unitId,
|
|
387
|
+
subUnitId,
|
|
388
|
+
objects
|
|
389
|
+
};
|
|
390
|
+
}
|
|
346
391
|
const op = ops.reduce(json1.type.compose, null);
|
|
347
392
|
const invertOp = invertOps.reduce(json1.type.compose, null);
|
|
348
393
|
const { unitId, subUnitId } = updateParams[0];
|
|
@@ -834,7 +879,12 @@ var UnitDrawingService = class {
|
|
|
834
879
|
op: [],
|
|
835
880
|
invertOp: []
|
|
836
881
|
};
|
|
837
|
-
const
|
|
882
|
+
const ops = this._getUpdateParamCompareOp(updateParam, object);
|
|
883
|
+
if (ops.length === 0) return {
|
|
884
|
+
op: [],
|
|
885
|
+
invertOp: []
|
|
886
|
+
};
|
|
887
|
+
const op = ops.reduce(json1.type.compose, null);
|
|
838
888
|
return {
|
|
839
889
|
op,
|
|
840
890
|
invertOp: json1.type.invertWithDoc(op, this.drawingManagerData)
|
|
@@ -845,15 +895,29 @@ var UnitDrawingService = class {
|
|
|
845
895
|
const ops = [];
|
|
846
896
|
Object.keys(newParam).forEach((key) => {
|
|
847
897
|
const newVal = newParam[key];
|
|
898
|
+
const hasOldKey = Object.prototype.hasOwnProperty.call(oldParam, key);
|
|
848
899
|
const oldVal = oldParam[key];
|
|
849
|
-
if (oldVal
|
|
850
|
-
|
|
900
|
+
if (hasOldKey && isJsonValueEqual(oldVal, newVal)) return;
|
|
901
|
+
const path = [
|
|
851
902
|
unitId,
|
|
852
903
|
subUnitId,
|
|
853
904
|
"data",
|
|
854
905
|
drawingId,
|
|
855
906
|
key
|
|
856
|
-
]
|
|
907
|
+
];
|
|
908
|
+
if (!hasOldKey) {
|
|
909
|
+
if (newVal === void 0) return;
|
|
910
|
+
const op = json1.insertOp(path, newVal);
|
|
911
|
+
if (isNonEmptyOp(op)) ops.push(op);
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
if (newVal === void 0) {
|
|
915
|
+
const op = json1.removeOp(path, true);
|
|
916
|
+
if (isNonEmptyOp(op)) ops.push(op);
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
const op = json1.replaceOp(path, oldVal, newVal);
|
|
920
|
+
if (isNonEmptyOp(op)) ops.push(op);
|
|
857
921
|
});
|
|
858
922
|
return ops;
|
|
859
923
|
}
|
|
@@ -896,7 +960,7 @@ var ImageIoService = class {
|
|
|
896
960
|
getImageSourceCache(source, imageSourceType) {
|
|
897
961
|
const cachedImage = this._imageSourceCache.get(source);
|
|
898
962
|
if (cachedImage != null) return cachedImage;
|
|
899
|
-
if (imageSourceType === ImageSourceType
|
|
963
|
+
if (imageSourceType === ImageSourceType.BASE64) {
|
|
900
964
|
const image = new Image();
|
|
901
965
|
image.onload = () => this._change$.next(this._waitCount);
|
|
902
966
|
image.onerror = () => this._change$.next(this._waitCount);
|
|
@@ -906,7 +970,7 @@ var ImageIoService = class {
|
|
|
906
970
|
}
|
|
907
971
|
}
|
|
908
972
|
addImageSourceCache(source, imageSourceType, imageSource) {
|
|
909
|
-
if (imageSourceType === ImageSourceType
|
|
973
|
+
if (imageSourceType === ImageSourceType.BASE64 || imageSource == null) return;
|
|
910
974
|
this._imageSourceCache.set(source, imageSource);
|
|
911
975
|
}
|
|
912
976
|
async getImage(imageId) {
|
|
@@ -915,12 +979,12 @@ var ImageIoService = class {
|
|
|
915
979
|
async saveImage(imageFile) {
|
|
916
980
|
return new Promise((resolve, reject) => {
|
|
917
981
|
if (!DRAWING_IMAGE_ALLOW_IMAGE_LIST.includes(imageFile.type)) {
|
|
918
|
-
reject(new Error(ImageUploadStatusType
|
|
982
|
+
reject(new Error(ImageUploadStatusType.ERROR_IMAGE_TYPE));
|
|
919
983
|
this._decreaseWaiting();
|
|
920
984
|
return;
|
|
921
985
|
}
|
|
922
986
|
if (imageFile.size > getDrawingImageAllowSize()) {
|
|
923
|
-
reject(new Error(ImageUploadStatusType
|
|
987
|
+
reject(new Error(ImageUploadStatusType.ERROR_EXCEED_SIZE));
|
|
924
988
|
this._decreaseWaiting();
|
|
925
989
|
return;
|
|
926
990
|
}
|
|
@@ -930,16 +994,16 @@ var ImageIoService = class {
|
|
|
930
994
|
var _evt$target;
|
|
931
995
|
const replaceSrc = (_evt$target = evt.target) === null || _evt$target === void 0 ? void 0 : _evt$target.result;
|
|
932
996
|
if (replaceSrc == null) {
|
|
933
|
-
reject(new Error(ImageUploadStatusType
|
|
997
|
+
reject(new Error(ImageUploadStatusType.ERROR_IMAGE));
|
|
934
998
|
this._decreaseWaiting();
|
|
935
999
|
return;
|
|
936
1000
|
}
|
|
937
1001
|
resolve({
|
|
938
1002
|
imageId: generateRandomId(6),
|
|
939
|
-
imageSourceType: ImageSourceType
|
|
1003
|
+
imageSourceType: ImageSourceType.BASE64,
|
|
940
1004
|
source: replaceSrc,
|
|
941
1005
|
base64Cache: replaceSrc,
|
|
942
|
-
status: ImageUploadStatusType
|
|
1006
|
+
status: ImageUploadStatusType.SUCCUSS
|
|
943
1007
|
});
|
|
944
1008
|
this._decreaseWaiting();
|
|
945
1009
|
};
|
|
@@ -1020,7 +1084,7 @@ let UniverDrawingPlugin = class UniverDrawingPlugin extends Plugin {
|
|
|
1020
1084
|
_initDependencies() {
|
|
1021
1085
|
var _this$_config;
|
|
1022
1086
|
mergeOverrideWithDependencies([
|
|
1023
|
-
[IImageIoService
|
|
1087
|
+
[IImageIoService, { useClass: ImageIoService }],
|
|
1024
1088
|
[IURLImageService, { useClass: URLImageService }],
|
|
1025
1089
|
[IDrawingManagerService, { useClass: DrawingManagerService }]
|
|
1026
1090
|
], (_this$_config = this._config) === null || _this$_config === void 0 ? void 0 : _this$_config.override).forEach((d) => this._injector.add(d));
|
|
@@ -1038,6 +1102,69 @@ UniverDrawingPlugin = __decorate([
|
|
|
1038
1102
|
__decorateParam(3, ICommandService)
|
|
1039
1103
|
], UniverDrawingPlugin);
|
|
1040
1104
|
|
|
1105
|
+
//#endregion
|
|
1106
|
+
//#region src/utils/drawing-group.ts
|
|
1107
|
+
const DRAWING_GROUPABLE_TYPES = [
|
|
1108
|
+
DrawingTypeEnum.DRAWING_IMAGE,
|
|
1109
|
+
DrawingTypeEnum.DRAWING_SHAPE,
|
|
1110
|
+
DrawingTypeEnum.DRAWING_CHART,
|
|
1111
|
+
DrawingTypeEnum.DRAWING_GROUP
|
|
1112
|
+
];
|
|
1113
|
+
function isGroupableDrawingType(type) {
|
|
1114
|
+
return DRAWING_GROUPABLE_TYPES.includes(type);
|
|
1115
|
+
}
|
|
1116
|
+
const DRAWING_COPY_CONTEXT_KEY = "univer.drawing.copy-plan";
|
|
1117
|
+
function cloneDrawing(drawing) {
|
|
1118
|
+
return JSON.parse(JSON.stringify(drawing));
|
|
1119
|
+
}
|
|
1120
|
+
function copyDrawingWithIdMap(drawing, idMap, options) {
|
|
1121
|
+
const copied = cloneDrawing(drawing);
|
|
1122
|
+
const copiedDrawingId = idMap.get(drawing.drawingId);
|
|
1123
|
+
if (copiedDrawingId == null) return copied;
|
|
1124
|
+
copied.unitId = options.unitId;
|
|
1125
|
+
copied.subUnitId = options.targetSubUnitId;
|
|
1126
|
+
copied.drawingId = copiedDrawingId;
|
|
1127
|
+
if (copied.groupId) {
|
|
1128
|
+
const copiedGroupId = idMap.get(copied.groupId);
|
|
1129
|
+
if (copiedGroupId) copied.groupId = copiedGroupId;
|
|
1130
|
+
else delete copied.groupId;
|
|
1131
|
+
}
|
|
1132
|
+
return copied;
|
|
1133
|
+
}
|
|
1134
|
+
function createDrawingCopyPlan(drawings, options) {
|
|
1135
|
+
const { generateId = () => generateRandomId(10) } = options;
|
|
1136
|
+
const idMap = /* @__PURE__ */ new Map();
|
|
1137
|
+
drawings.forEach((drawing) => {
|
|
1138
|
+
if (!idMap.has(drawing.drawingId)) idMap.set(drawing.drawingId, generateId());
|
|
1139
|
+
});
|
|
1140
|
+
return {
|
|
1141
|
+
idMap,
|
|
1142
|
+
drawings: drawings.map((drawing) => copyDrawingWithIdMap(drawing, idMap, options))
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
function getOrCreateDrawingCopyPlan(copyContext, drawings, options) {
|
|
1146
|
+
if (copyContext == null) return createDrawingCopyPlan(drawings, options);
|
|
1147
|
+
const cached = copyContext.get(DRAWING_COPY_CONTEXT_KEY);
|
|
1148
|
+
if (cached) {
|
|
1149
|
+
const { generateId = () => generateRandomId(10) } = options;
|
|
1150
|
+
if (!drawings.some((drawing) => !cached.idMap.has(drawing.drawingId))) return cached;
|
|
1151
|
+
drawings.forEach((drawing) => {
|
|
1152
|
+
if (!cached.idMap.has(drawing.drawingId)) cached.idMap.set(drawing.drawingId, generateId());
|
|
1153
|
+
});
|
|
1154
|
+
const incomingDrawingIds = new Set(drawings.map((drawing) => drawing.drawingId));
|
|
1155
|
+
const originalIdByCopiedId = new Map(Array.from(cached.idMap.entries()).map(([drawingId, copiedDrawingId]) => [copiedDrawingId, drawingId]));
|
|
1156
|
+
const retainedDrawings = cached.drawings.filter((drawing) => {
|
|
1157
|
+
const originalDrawingId = originalIdByCopiedId.get(drawing.drawingId);
|
|
1158
|
+
return originalDrawingId == null || !incomingDrawingIds.has(originalDrawingId);
|
|
1159
|
+
});
|
|
1160
|
+
cached.drawings = [...drawings.map((drawing) => copyDrawingWithIdMap(drawing, cached.idMap, options)), ...retainedDrawings];
|
|
1161
|
+
return cached;
|
|
1162
|
+
}
|
|
1163
|
+
const plan = createDrawingCopyPlan(drawings, options);
|
|
1164
|
+
copyContext.set(DRAWING_COPY_CONTEXT_KEY, plan);
|
|
1165
|
+
return plan;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1041
1168
|
//#endregion
|
|
1042
1169
|
//#region src/utils/get-image-shape-key.ts
|
|
1043
1170
|
function getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId }, index) {
|
|
@@ -1064,4 +1191,30 @@ const getImageSize = async (src) => {
|
|
|
1064
1191
|
};
|
|
1065
1192
|
|
|
1066
1193
|
//#endregion
|
|
1067
|
-
|
|
1194
|
+
//#region src/utils/rotate-enabled.ts
|
|
1195
|
+
function getDrawingKey(drawing) {
|
|
1196
|
+
return `${drawing.unitId}\u0000${drawing.subUnitId}\u0000${drawing.drawingId}`;
|
|
1197
|
+
}
|
|
1198
|
+
function resolveDrawingRotateEnabled(drawing, options = {}, visiting = /* @__PURE__ */ new Set()) {
|
|
1199
|
+
var _drawing$transform, _options$getRenderObj, _options$isKnownNonRo;
|
|
1200
|
+
const drawingKey = getDrawingKey(drawing);
|
|
1201
|
+
if (visiting.has(drawingKey)) return true;
|
|
1202
|
+
if (drawing.drawingType === DrawingTypeEnum.DRAWING_GROUP) {
|
|
1203
|
+
var _options$getChildren;
|
|
1204
|
+
visiting.add(drawingKey);
|
|
1205
|
+
const children = (_options$getChildren = options.getChildren) === null || _options$getChildren === void 0 ? void 0 : _options$getChildren.call(options, drawing);
|
|
1206
|
+
if (children != null) {
|
|
1207
|
+
const enabled = children.every((child) => resolveDrawingRotateEnabled(child, options, visiting));
|
|
1208
|
+
visiting.delete(drawingKey);
|
|
1209
|
+
return enabled;
|
|
1210
|
+
}
|
|
1211
|
+
visiting.delete(drawingKey);
|
|
1212
|
+
}
|
|
1213
|
+
if (((_drawing$transform = drawing.transform) === null || _drawing$transform === void 0 ? void 0 : _drawing$transform.rotateEnabled) === false) return false;
|
|
1214
|
+
if (((_options$getRenderObj = options.getRenderObject) === null || _options$getRenderObj === void 0 || (_options$getRenderObj = _options$getRenderObj.call(options, drawing)) === null || _options$getRenderObj === void 0 || (_options$getRenderObj = _options$getRenderObj.transformerConfig) === null || _options$getRenderObj === void 0 ? void 0 : _options$getRenderObj.rotateEnabled) === false) return false;
|
|
1215
|
+
if ((_options$isKnownNonRo = options.isKnownNonRotatableType) === null || _options$isKnownNonRo === void 0 ? void 0 : _options$isKnownNonRo.call(options, drawing.drawingType)) return false;
|
|
1216
|
+
return true;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
//#endregion
|
|
1220
|
+
export { DRAWING_COPY_CONTEXT_KEY, DRAWING_GROUPABLE_TYPES, DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, DrawingManagerService, IDrawingManagerService, ImageIoService, SetDrawingSelectedOperation, URLImageService, UnitDrawingService, UniverDrawingPlugin, createDrawingCopyPlan, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize, getOrCreateDrawingCopyPlan, isGroupableDrawingType, resolveDrawingRotateEnabled };
|