@meta2d/core 1.0.36 → 1.0.37-alpha.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meta2d/core",
3
- "version": "1.0.36",
3
+ "version": "1.0.37-alpha.1",
4
4
  "description": "@meta2d/core: Powerful, Beautiful, Simple, Open - Web-Based 2D At Its Best .",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -317,7 +317,8 @@ var Canvas = /** @class */ (function () {
317
317
  var _a, _b, _c;
318
318
  if (_this.store.data.locked >= LockState.DisableEdit &&
319
319
  e.target.tagName !== 'INPUT' &&
320
- e.target.tagName !== 'TEXTAREA') {
320
+ e.target.tagName !== 'TEXTAREA' &&
321
+ !e.target.dataset.meta2dIgnore) {
321
322
  _this.store.active.forEach(function (pen) {
322
323
  var _a;
323
324
  (_a = pen.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(pen, pen, e.key);
@@ -325,7 +326,8 @@ var Canvas = /** @class */ (function () {
325
326
  }
326
327
  if (_this.store.data.locked >= LockState.DisableEdit ||
327
328
  e.target.tagName === 'INPUT' ||
328
- e.target.tagName === 'TEXTAREA') {
329
+ e.target.tagName === 'TEXTAREA' ||
330
+ e.target.dataset.meta2dIgnore) {
329
331
  return;
330
332
  }
331
333
  if (_this.store.options.unavailableKeys.includes(e.key)) {
@@ -4109,6 +4111,59 @@ var Canvas = /** @class */ (function () {
4109
4111
  });
4110
4112
  action.type = EditType.Add;
4111
4113
  break;
4114
+ case EditType.Replace: {
4115
+ // undo pens则为新的pen
4116
+ var pens_9 = undo ? action.initPens : action.pens;
4117
+ var unPens_2 = undo ? action.pens : action.initPens;
4118
+ // 删除旧的
4119
+ unPens_2.forEach(function (aPen) {
4120
+ var _a;
4121
+ var pen = deepClone(aPen, true);
4122
+ var i = _this.store.data.pens.findIndex(function (item) { return item.id === pen.id; });
4123
+ if (i > -1) {
4124
+ (_a = pen.onDestroy) === null || _a === void 0 ? void 0 : _a.call(pen, _this.store.data.pens.find(function (i) { return i.id === pen.id; }));
4125
+ var i_1 = _this.store.data.pens.findIndex(function (item) { return item.id === pen.id; });
4126
+ _this.store.data.pens.splice(i_1, 1);
4127
+ _this.store.pens[pen.id] = undefined;
4128
+ if (!pen.calculative) {
4129
+ pen.calculative = {};
4130
+ }
4131
+ pen.calculative.canvas = _this;
4132
+ _this.store.animates.delete(pen);
4133
+ _this.store.animateMap.delete(pen);
4134
+ }
4135
+ });
4136
+ // 放置新的
4137
+ pens_9.reverse().forEach(function (aPen) {
4138
+ var _a, _b;
4139
+ var pen = deepClone(aPen, true);
4140
+ if (!pen.calculative) {
4141
+ pen.calculative = {};
4142
+ }
4143
+ _this.store.data.pens.splice(((_a = pen.calculative) === null || _a === void 0 ? void 0 : _a.layer) !== -1
4144
+ ? (_b = pen.calculative) === null || _b === void 0 ? void 0 : _b.layer
4145
+ : _this.store.data.pens.length, 0, pen);
4146
+ // 先放进去,pens 可能是子节点在前,而父节点在后
4147
+ _this.store.pens[pen.id] = pen;
4148
+ if (pen.type && pen.lastConnected) {
4149
+ for (var key in pen.lastConnected) {
4150
+ _this.store.pens[key].connectedLines = pen.lastConnected[key];
4151
+ }
4152
+ }
4153
+ pen.calculative.canvas = _this;
4154
+ });
4155
+ pens_9.reverse().forEach(function (aPen) {
4156
+ var pen = _this.store.data.pens.find(function (i) { return i.id === aPen.id; });
4157
+ var rect = _this.getPenRect(pen, action.origin, action.scale);
4158
+ _this.setPenRect(pen, rect, false);
4159
+ pen.calculative.image = undefined;
4160
+ pen.calculative.backgroundImage = undefined;
4161
+ pen.calculative.strokeImage = undefined;
4162
+ _this.loadImage(pen);
4163
+ });
4164
+ action.type = EditType.Replace;
4165
+ break;
4166
+ }
4112
4167
  }
4113
4168
  if (action.type === EditType.Update) {
4114
4169
  var pens = __spreadArray(__spreadArray([], __read(action.pens), false), __read(action.initPens), false);
@@ -6196,15 +6251,15 @@ var Canvas = /** @class */ (function () {
6196
6251
  var e_21, _a;
6197
6252
  var retPens = [];
6198
6253
  try {
6199
- for (var pens_9 = __values(pens), pens_9_1 = pens_9.next(); !pens_9_1.done; pens_9_1 = pens_9.next()) {
6200
- var pen = pens_9_1.value;
6254
+ for (var pens_10 = __values(pens), pens_10_1 = pens_10.next(); !pens_10_1.done; pens_10_1 = pens_10.next()) {
6255
+ var pen = pens_10_1.value;
6201
6256
  retPens.push.apply(retPens, __spreadArray([], __read(deepClone(getAllChildren(pen, this.store), true)), false));
6202
6257
  }
6203
6258
  }
6204
6259
  catch (e_21_1) { e_21 = { error: e_21_1 }; }
6205
6260
  finally {
6206
6261
  try {
6207
- if (pens_9_1 && !pens_9_1.done && (_a = pens_9.return)) _a.call(pens_9);
6262
+ if (pens_10_1 && !pens_10_1.done && (_a = pens_10.return)) _a.call(pens_10);
6208
6263
  }
6209
6264
  finally { if (e_21) throw e_21.error; }
6210
6265
  }
@@ -6330,6 +6385,8 @@ var Canvas = /** @class */ (function () {
6330
6385
  this.render();
6331
6386
  // TODO: 连线的删除 ,连接的 node 的 connectLines 会变化(删除 node ,line 的 anchors 类似),未记历史记录
6332
6387
  if (history) {
6388
+ if (deletePens.length === 0)
6389
+ return [2 /*return*/];
6333
6390
  this.pushHistory({ type: EditType.Delete, pens: deletePens });
6334
6391
  }
6335
6392
  this.store.emitter.emit('delete', pens);