canvas-editor-engine 2.3.41 → 2.3.43

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
@@ -1388,6 +1388,10 @@ var DrawLayersState = function() {
1388
1388
  case "ADD_LAYER":
1389
1389
  reducer.addLayer(payload);
1390
1390
  break;
1391
+
1392
+ case "REMOVE_LAYER":
1393
+ reducer.removeLayer(payload);
1394
+ break;
1391
1395
  }
1392
1396
  };
1393
1397
  DrawLayersState.prototype.emerge = function(completeIt) {
@@ -1438,6 +1442,21 @@ var Reducer$1 = function() {
1438
1442
  this.state._emergeCompleteIt(this.state._layers);
1439
1443
  }
1440
1444
  };
1445
+ Reducer.prototype.removeLayer = function(payload) {
1446
+ var isUpdate = false;
1447
+ if (!!payload) {
1448
+ var targetLayerIndex = this.state._layers.findIndex((function(layer) {
1449
+ return layer.id === payload.id;
1450
+ }));
1451
+ if (targetLayerIndex != -1) {
1452
+ this.state._layers.splice(targetLayerIndex, 1);
1453
+ isUpdate = true;
1454
+ }
1455
+ }
1456
+ if (isUpdate && !!this.state._emergeCompleteIt) {
1457
+ this.state._emergeCompleteIt(this.state._layers);
1458
+ }
1459
+ };
1441
1460
  Reducer.prototype.popLayer = function() {
1442
1461
  this.state._layers.pop();
1443
1462
  if (!!this.state._emergeCompleteIt) {
@@ -2448,17 +2467,27 @@ var DrawLayersService = function() {
2448
2467
  this.appStoreRepository.store.drawLayersState.reduce("UPDATE_LAYER", layer);
2449
2468
  };
2450
2469
  DrawLayersService.prototype.updateLayer = function(id, updateData) {
2451
- var layerIndex = this.layerList.findIndex((function(layer) {
2452
- return layer.id === id;
2453
- }));
2454
- var fields = Object.keys(updateData);
2455
- if (!fields.length || layerIndex === -1) return;
2456
- var layer = this.layerList[layerIndex];
2457
- fields.forEach((function(field) {
2458
- layer[field] = updateData[field];
2470
+ var _this = this;
2471
+ return new Promise((function(resolve, reject) {
2472
+ var layerIndex = _this.layerList.findIndex((function(layer) {
2473
+ return layer.id === id;
2474
+ }));
2475
+ var fields = Object.keys(updateData);
2476
+ if (!fields.length || layerIndex === -1) return reject({
2477
+ status: "error",
2478
+ message: "Layer not found"
2479
+ });
2480
+ var layer = _this.layerList[layerIndex];
2481
+ fields.forEach((function(field) {
2482
+ layer[field] = updateData[field];
2483
+ }));
2484
+ _this.layerList[layerIndex] = layer;
2485
+ _this.appStoreRepository.store.drawLayersState.reduce("UPDATE_LAYER", layer);
2486
+ resolve({
2487
+ status: "success",
2488
+ message: "Layer updated"
2489
+ });
2459
2490
  }));
2460
- this.layerList[layerIndex] = layer;
2461
- this.appStoreRepository.store.drawLayersState.reduce("UPDATE_LAYER", layer);
2462
2491
  };
2463
2492
  DrawLayersService.prototype.removePainter = function(id) {
2464
2493
  var layerIndex = this.layerList.findIndex((function(layer) {
@@ -2487,6 +2516,25 @@ var DrawLayersService = function() {
2487
2516
  var layer = this.layerList[layerIndex];
2488
2517
  this.appStoreRepository.store.drawLayersState.reduce("UPDATE_LAYER", layer);
2489
2518
  };
2519
+ DrawLayersService.prototype.removeLayer = function(id) {
2520
+ var _this = this;
2521
+ return new Promise((function(resolve, reject) {
2522
+ var layerIndex = _this.layerList.findIndex((function(layer) {
2523
+ return layer.id === id;
2524
+ }));
2525
+ if (layerIndex === -1) return reject({
2526
+ status: "error",
2527
+ message: "Layer not found"
2528
+ });
2529
+ var layer = _this.layerList[layerIndex];
2530
+ _this.layerList.splice(layerIndex, 1);
2531
+ _this.appStoreRepository.store.drawLayersState.reduce("REMOVE_LAYER", layer);
2532
+ resolve({
2533
+ status: "success",
2534
+ message: "Layer removed"
2535
+ });
2536
+ }));
2537
+ };
2490
2538
  DrawLayersService.prototype.changeLayerOrder = function(id, options) {
2491
2539
  return __awaiter(this, void 0, void 0, (function() {
2492
2540
  var _this = this;
@@ -2635,7 +2683,7 @@ var DrawAccumulatorService = function() {
2635
2683
  };
2636
2684
  DrawAccumulatorService.prototype.removePainter = function(painterId) {
2637
2685
  return __awaiter(this, void 0, void 0, (function() {
2638
- var painter, filteredPainters;
2686
+ var painter, filteredPainters, len;
2639
2687
  var _this = this;
2640
2688
  return __generator(this, (function(_a) {
2641
2689
  painter = this.painters.find((function(painter) {
@@ -2646,11 +2694,21 @@ var DrawAccumulatorService = function() {
2646
2694
  return painter.id !== painterId;
2647
2695
  }));
2648
2696
  this.painters = createDynamicPainterStore();
2649
- filteredPainters.forEach((function(painter) {
2650
- _this.painters.push({
2651
- object: painter,
2652
- update: _this.update.bind(_this)
2653
- });
2697
+ len = filteredPainters === null || filteredPainters === void 0 ? void 0 : filteredPainters.length;
2698
+ filteredPainters.forEach((function(painter, index) {
2699
+ if (len - 1 === index) {
2700
+ _this.painters.push({
2701
+ object: painter,
2702
+ update: _this.update.bind(_this)
2703
+ });
2704
+ } else {
2705
+ _this.painters.push({
2706
+ object: painter,
2707
+ update: function() {
2708
+ return undefined;
2709
+ }
2710
+ });
2711
+ }
2654
2712
  }));
2655
2713
  this.drawLayersService.removePainter(painterId);
2656
2714
  this.update();
@@ -2688,6 +2746,49 @@ var DrawAccumulatorService = function() {
2688
2746
  }));
2689
2747
  }));
2690
2748
  };
2749
+ DrawAccumulatorService.prototype.renameLayer = function(id, newName) {
2750
+ return __awaiter(this, void 0, void 0, (function() {
2751
+ var updateData;
2752
+ var _this = this;
2753
+ return __generator(this, (function(_a) {
2754
+ updateData = {
2755
+ name: newName
2756
+ };
2757
+ this.drawLayersService.updateLayer(id, updateData).then((function(res) {
2758
+ if (res.status === "success") {
2759
+ _this.update();
2760
+ } else {
2761
+ console.warn(res === null || res === void 0 ? void 0 : res.message);
2762
+ }
2763
+ })).catch((function(ex) {
2764
+ console.warn("".concat(ex.status, ": ").concat(ex.message));
2765
+ }));
2766
+ return [ 2 ];
2767
+ }));
2768
+ }));
2769
+ };
2770
+ DrawAccumulatorService.prototype.removeLayer = function(layerId) {
2771
+ return __awaiter(this, void 0, void 0, (function() {
2772
+ var layer;
2773
+ var _this = this;
2774
+ return __generator(this, (function(_a) {
2775
+ layer = this.drawLayersService.getLayerById(layerId);
2776
+ layer.painters.map((function(painter) {
2777
+ return painter.id;
2778
+ })).forEach((function(painterId) {
2779
+ _this.removePainter(painterId);
2780
+ }));
2781
+ this.drawLayersService.removeLayer(layerId).then((function(res) {
2782
+ if (res.status === "success") {
2783
+ _this.update();
2784
+ }
2785
+ })).catch((function(ex) {
2786
+ console.warn("".concat(ex.status, ": ").concat(ex.message));
2787
+ }));
2788
+ return [ 2 ];
2789
+ }));
2790
+ }));
2791
+ };
2691
2792
  DrawAccumulatorService.prototype.updateLayerOrder = function(layerId, options) {
2692
2793
  var _this = this;
2693
2794
  this.drawLayersService.changeLayerOrder(layerId, options).then((function(res) {
@@ -1,6 +1,6 @@
1
1
  import AppConfig from "../config";
2
2
  import AppStoreRepository from "../store/storeRepository";
3
- import { ILayer, IUpdateLayerOptions } from "../types/draw-layers";
3
+ import { ILayer, ILayerUpdate, IUpdateLayerOptions } from "../types/draw-layers";
4
4
  import { IPainter, ISmoothFilterOptions, TDrawType } from "../types/draw-service";
5
5
  import { ITempCanvasOptions } from "../types/temp-canvas";
6
6
  import Painter from "../utils/painter";
@@ -18,6 +18,8 @@ export default class DrawAccumulatorService {
18
18
  removePainter(painterId: string): Promise<void>;
19
19
  renamePainter(painterId: IPainter['id'], name: string): void;
20
20
  smoothFilter(painterId: IPainter['id'], smoothFilterOptions: ISmoothFilterOptions): Promise<void>;
21
+ renameLayer(id: ILayer["id"], newName: ILayerUpdate['name']): Promise<void>;
22
+ removeLayer(layerId: ILayer['id']): Promise<void>;
21
23
  updateLayerOrder(layerId: ILayer['id'], options: IUpdateLayerOptions): void;
22
24
  private update;
23
25
  private get gradient();
@@ -14,8 +14,9 @@ export default class DrawLayersService {
14
14
  getLayersByOrder(order: number): ILayer[];
15
15
  getLayerById(layerId: ILayer['id']): ILayer;
16
16
  addToLayer(id: ILayer['id'], painter: IPainter): void;
17
- updateLayer(id: ILayer['id'], updateData?: ILayerUpdate): void;
17
+ updateLayer(id: ILayer['id'], updateData?: ILayerUpdate): Promise<unknown>;
18
18
  removePainter(id: IPainter['id']): void;
19
19
  updatePainterData(painter: Painter): void;
20
+ removeLayer(id: ILayer['id']): Promise<unknown>;
20
21
  changeLayerOrder(id: ILayer['id'], options: IUpdateLayerOptions): Promise<unknown>;
21
22
  }
@@ -10,7 +10,7 @@ export interface ILayerUpdate {
10
10
  order?: ILayer['order'];
11
11
  name?: ILayer['name'];
12
12
  }
13
- export type TReducerNames = 'SET_LAYERS' | 'UPDATE_LAYER' | 'ADD_LAYER';
13
+ export type TReducerNames = 'SET_LAYERS' | 'UPDATE_LAYER' | 'ADD_LAYER' | 'REMOVE_LAYER';
14
14
  export interface IUpdateLayerOptions {
15
15
  to?: number;
16
16
  direction?: 'up' | 'down';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "2.3.41",
3
+ "version": "2.3.43",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",