canvas-editor-engine 2.3.49 → 2.3.51

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/dist/index.mjs CHANGED
@@ -2555,17 +2555,18 @@ var DrawLayersService = function() {
2555
2555
  message: "Layer not found"
2556
2556
  });
2557
2557
  var layer = _this.layerList[layerIndex];
2558
+ var newOrder = layer.order;
2558
2559
  if (options === null || options === void 0 ? void 0 : options.to) {
2559
- layer.order = options.to;
2560
+ newOrder = options.to;
2560
2561
  }
2561
2562
  if (options === null || options === void 0 ? void 0 : options.direction) {
2562
2563
  switch (options.direction) {
2563
2564
  case "up":
2564
- layer.order = layer.order - 1;
2565
+ newOrder = layer.order - 1;
2565
2566
  break;
2566
2567
 
2567
2568
  case "down":
2568
- layer.order = layer.order + 1;
2569
+ newOrder = layer.order + 1;
2569
2570
  break;
2570
2571
  }
2571
2572
  }
@@ -2573,15 +2574,27 @@ var DrawLayersService = function() {
2573
2574
  var operation = options.addendum.operation;
2574
2575
  var operand = options.addendum.value;
2575
2576
  if (operation === "add") {
2576
- layer.order = layer.order + operand;
2577
+ newOrder = layer.order + operand;
2577
2578
  } else if (operation === "subtract") {
2578
- layer.order = layer.order - operand;
2579
+ newOrder = layer.order - operand;
2579
2580
  } else if (operation === "multiplication") {
2580
- layer.order = layer.order * operand;
2581
+ newOrder = layer.order * operand;
2581
2582
  } else if (operation === "division") {
2582
- layer.order = layer.order / operand;
2583
+ newOrder = layer.order / operand;
2583
2584
  }
2584
2585
  }
2586
+ var replaceableIndex = _this.layerList.findIndex((function(layer) {
2587
+ return layer.order === newOrder;
2588
+ }));
2589
+ if (replaceableIndex === -1) return reject({
2590
+ status: "error",
2591
+ message: "Replaceable layer not found"
2592
+ });
2593
+ var replaceable = _this.layerList[replaceableIndex];
2594
+ replaceable.order = layer.order;
2595
+ _this.layerList[replaceableIndex] = replaceable;
2596
+ _this.appStoreRepository.store.drawLayersState.reduce("UPDATE_LAYER", replaceable);
2597
+ layer.order = newOrder;
2585
2598
  _this.layerList[layerIndex] = layer;
2586
2599
  _this.appStoreRepository.store.drawLayersState.reduce("UPDATE_LAYER", layer);
2587
2600
  resolve({
@@ -19,5 +19,14 @@ export default class DrawLayersService {
19
19
  removePainter(id: IPainter['id']): void;
20
20
  updatePainterData(painter: Painter): void;
21
21
  removeLayer(id: ILayer['id']): Promise<unknown>;
22
+ /**
23
+ * options steps:
24
+ * 1. to (optional)
25
+ * 2. direction (optional)
26
+ * 3. addendum (optional)
27
+ * @param id ILayer['id']
28
+ * @param options IUpdateLayerOptions
29
+ * @returns promise { status: 'success' | 'error', message: string }
30
+ */
22
31
  changeLayerOrder(id: ILayer['id'], options: IUpdateLayerOptions): Promise<unknown>;
23
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "2.3.49",
3
+ "version": "2.3.51",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",