labellife-design-tool 1.3.0 → 1.3.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/dist/lib/lib/index.js +362 -385
- package/dist/lib/wordpress.js +377 -387
- package/dist/types/CanvasEditor.d.ts +1 -1
- package/dist/types/CanvasEditor.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/lib/lib/index.js
CHANGED
|
@@ -549,9 +549,6 @@ function initJsxCompat() {
|
|
|
549
549
|
// src/CanvasEditor.tsx
|
|
550
550
|
import React17, { useRef as useRef4, useEffect as useEffect4, useMemo, useCallback as useCallback4 } from "react";
|
|
551
551
|
import { Stage, Layer, Rect as Rect2 } from "react-konva";
|
|
552
|
-
import {
|
|
553
|
-
PlusCircle
|
|
554
|
-
} from "lucide-react";
|
|
555
552
|
|
|
556
553
|
// src/elements/EditableTextElement.tsx
|
|
557
554
|
import React, { useRef, useEffect } from "react";
|
|
@@ -2717,382 +2714,113 @@ var RightSidebar = ({
|
|
|
2717
2714
|
}), /* @__PURE__ */ React16.createElement("span", null, "Delete"))));
|
|
2718
2715
|
};
|
|
2719
2716
|
var RightSidebar_default = RightSidebar;
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
};
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
callback(...args);
|
|
2760
|
-
}
|
|
2761
|
-
}
|
|
2762
|
-
get design() {
|
|
2763
|
-
return this._design;
|
|
2764
|
-
}
|
|
2765
|
-
get width() {
|
|
2766
|
-
return this._design.width;
|
|
2767
|
-
}
|
|
2768
|
-
get height() {
|
|
2769
|
-
return this._design.height;
|
|
2770
|
-
}
|
|
2771
|
-
get activePage() {
|
|
2772
|
-
const page = this._design.pages.find((p) => p.id === this._activePageId) || null;
|
|
2773
|
-
if (!page)
|
|
2774
|
-
return null;
|
|
2775
|
-
return {
|
|
2776
|
-
...page,
|
|
2777
|
-
addElement: (element) => {
|
|
2778
|
-
this.addElement(element);
|
|
2779
|
-
}
|
|
2780
|
-
};
|
|
2781
|
-
}
|
|
2782
|
-
get activePageId() {
|
|
2783
|
-
return this._activePageId;
|
|
2784
|
-
}
|
|
2785
|
-
get activePanelId() {
|
|
2786
|
-
return this._activePanelId;
|
|
2787
|
-
}
|
|
2788
|
-
get selectedId() {
|
|
2789
|
-
return this._selectedId;
|
|
2790
|
-
}
|
|
2791
|
-
get selectedIds() {
|
|
2792
|
-
return this._selectedIds;
|
|
2793
|
-
}
|
|
2794
|
-
get tool() {
|
|
2795
|
-
return this._tool;
|
|
2796
|
-
}
|
|
2797
|
-
get zoom() {
|
|
2798
|
-
return this._zoom;
|
|
2799
|
-
}
|
|
2800
|
-
get selectedShape() {
|
|
2801
|
-
return this._selectedShape;
|
|
2802
|
-
}
|
|
2803
|
-
setDesign(design) {
|
|
2804
|
-
this._design = design;
|
|
2805
|
-
if (design.pages.find((p) => p.id === this._activePageId)) {} else if (design.pages.length > 0) {
|
|
2806
|
-
this._activePageId = design.pages[0].id;
|
|
2807
|
-
}
|
|
2808
|
-
this.emit("designChanged", this._design);
|
|
2809
|
-
this.emit("activePageChanged", this._activePageId);
|
|
2810
|
-
}
|
|
2811
|
-
updateDesign(updates) {
|
|
2812
|
-
this._design = { ...this._design, ...updates };
|
|
2813
|
-
this.emit("designChanged", this._design);
|
|
2814
|
-
}
|
|
2815
|
-
setSize(width, height) {
|
|
2816
|
-
this._design.width = width;
|
|
2817
|
-
this._design.height = height;
|
|
2818
|
-
this.emit("designChanged", this._design);
|
|
2819
|
-
}
|
|
2820
|
-
addPage(page) {
|
|
2821
|
-
console.log(`addPage called - Current pages: ${this._design.pages.length}, New page ID: ${page?.id || `page-${Date.now()}`}`);
|
|
2822
|
-
const newPage = {
|
|
2823
|
-
id: page?.id || `page-${Date.now()}`,
|
|
2824
|
-
name: page?.name || `Page ${this._design.pages.length + 1}`,
|
|
2825
|
-
elements: page?.elements || [],
|
|
2826
|
-
background: page?.background || "#ffffff",
|
|
2827
|
-
backgroundImageObject: page?.backgroundImageObject
|
|
2717
|
+
|
|
2718
|
+
// src/CanvasEditor.tsx
|
|
2719
|
+
var CanvasEditor = ({
|
|
2720
|
+
name,
|
|
2721
|
+
config,
|
|
2722
|
+
store
|
|
2723
|
+
}) => {
|
|
2724
|
+
const stageRef = useRef4(null);
|
|
2725
|
+
const fileInputRef = useRef4(null);
|
|
2726
|
+
const jsonInputRef = useRef4(null);
|
|
2727
|
+
const containerRef = useRef4(null);
|
|
2728
|
+
const currentPage = store.design.pages.find((p) => p.id === store.activePageId) || store.design.pages[0] || null;
|
|
2729
|
+
const selectedElement = currentPage?.elements.find((el) => el.id === store.selectedId) || null;
|
|
2730
|
+
useEffect4(() => {
|
|
2731
|
+
const handleDesignChange = (newDesign) => {};
|
|
2732
|
+
const handleActivePageChange = (pageId) => {};
|
|
2733
|
+
const handleActivePanelChange = (panelId) => {};
|
|
2734
|
+
const handleSelectedIdChange = (selectedId) => {};
|
|
2735
|
+
const handleSelectedIdsChange = (selectedIds) => {};
|
|
2736
|
+
const handleToolChange = (tool) => {};
|
|
2737
|
+
const handleZoomChange = (zoom) => {};
|
|
2738
|
+
const handleSelectedShapeChange = (shape) => {};
|
|
2739
|
+
store.on("designChanged", handleDesignChange);
|
|
2740
|
+
store.on("activePageChanged", handleActivePageChange);
|
|
2741
|
+
store.on("activePanelChanged", handleActivePanelChange);
|
|
2742
|
+
store.on("selectedIdChanged", handleSelectedIdChange);
|
|
2743
|
+
store.on("selectedIdsChanged", handleSelectedIdsChange);
|
|
2744
|
+
store.on("toolChanged", handleToolChange);
|
|
2745
|
+
store.on("zoomChanged", handleZoomChange);
|
|
2746
|
+
store.on("selectedShapeChanged", handleSelectedShapeChange);
|
|
2747
|
+
return () => {
|
|
2748
|
+
store.off("designChanged");
|
|
2749
|
+
store.off("activePageChanged");
|
|
2750
|
+
store.off("activePanelChanged");
|
|
2751
|
+
store.off("selectedIdChanged");
|
|
2752
|
+
store.off("selectedIdsChanged");
|
|
2753
|
+
store.off("toolChanged");
|
|
2754
|
+
store.off("zoomChanged");
|
|
2755
|
+
store.off("selectedShapeChanged");
|
|
2828
2756
|
};
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2757
|
+
}, [store]);
|
|
2758
|
+
const handleStageClick = useCallback4((e) => {
|
|
2759
|
+
const clickedOnEmpty = e.target === e.target.getStage();
|
|
2760
|
+
if (clickedOnEmpty) {
|
|
2761
|
+
store.setSelectedId(null);
|
|
2762
|
+
store.setSelectedIds([]);
|
|
2833
2763
|
}
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
deletePages(pageIds) {
|
|
2838
|
-
const remainingPages = this._design.pages.filter((p) => !pageIds.includes(p.id));
|
|
2839
|
-
if (remainingPages.length === 0) {
|
|
2840
|
-
console.warn("Cannot delete all pages. At least one page must remain.");
|
|
2764
|
+
}, [store]);
|
|
2765
|
+
const addText = useCallback4(() => {
|
|
2766
|
+
if (!store.activePage)
|
|
2841
2767
|
return;
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
this
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
if (!
|
|
2853
|
-
console.warn("addElement: No active page!");
|
|
2768
|
+
store.activePage.addElement({
|
|
2769
|
+
type: "text",
|
|
2770
|
+
text: "Edit this text",
|
|
2771
|
+
x: store.design.width / 2 - 50,
|
|
2772
|
+
y: store.design.height / 2 - 15,
|
|
2773
|
+
width: 100,
|
|
2774
|
+
height: 30
|
|
2775
|
+
});
|
|
2776
|
+
}, [store]);
|
|
2777
|
+
const addShape = useCallback4((shapeType) => {
|
|
2778
|
+
if (!store.activePage)
|
|
2854
2779
|
return;
|
|
2780
|
+
store.activePage.addElement({
|
|
2781
|
+
type: "shape",
|
|
2782
|
+
shapeType,
|
|
2783
|
+
x: store.design.width / 2 - 50,
|
|
2784
|
+
y: store.design.height / 2 - 50,
|
|
2785
|
+
width: 100,
|
|
2786
|
+
height: 100
|
|
2787
|
+
});
|
|
2788
|
+
}, [store]);
|
|
2789
|
+
const updateElement = useCallback4((id, attrs) => {
|
|
2790
|
+
store.updateElement(id, attrs);
|
|
2791
|
+
}, [store]);
|
|
2792
|
+
const deleteSelected = useCallback4(() => {
|
|
2793
|
+
if (store.selectedId || store.selectedIds.length > 0) {
|
|
2794
|
+
const idsToDelete = store.selectedIds.length > 0 ? store.selectedIds : [store.selectedId];
|
|
2795
|
+
idsToDelete.forEach((id) => store.deleteElement(id));
|
|
2796
|
+
store.setSelectedId(null);
|
|
2797
|
+
store.setSelectedIds([]);
|
|
2855
2798
|
}
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
setSelectedIds(selectedIds) {
|
|
2882
|
-
this._selectedIds = selectedIds;
|
|
2883
|
-
this.emit("selectedIdsChanged", selectedIds);
|
|
2884
|
-
}
|
|
2885
|
-
setTool(tool) {
|
|
2886
|
-
this._tool = tool;
|
|
2887
|
-
this.emit("toolChanged", tool);
|
|
2888
|
-
}
|
|
2889
|
-
setZoom(zoom) {
|
|
2890
|
-
this._zoom = zoom;
|
|
2891
|
-
this.emit("zoomChanged", zoom);
|
|
2892
|
-
}
|
|
2893
|
-
setSelectedShape(shape) {
|
|
2894
|
-
this._selectedShape = shape;
|
|
2895
|
-
this.emit("selectedShapeChanged", shape);
|
|
2896
|
-
}
|
|
2897
|
-
async toBlob(type = "png") {
|
|
2898
|
-
return new Promise((resolve, reject) => {
|
|
2899
|
-
try {
|
|
2900
|
-
Promise.resolve().then(() => exports_exportImportUtils).then(({ canvasToBlob: canvasToBlob2 }) => {
|
|
2901
|
-
const canvas = document.createElement("canvas");
|
|
2902
|
-
canvas.width = this._design.width;
|
|
2903
|
-
canvas.height = this._design.height;
|
|
2904
|
-
const ctx = canvas.getContext("2d");
|
|
2905
|
-
if (!ctx) {
|
|
2906
|
-
reject(new Error("Failed to get canvas context"));
|
|
2907
|
-
return;
|
|
2908
|
-
}
|
|
2909
|
-
ctx.fillStyle = "#ffffff";
|
|
2910
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
2911
|
-
const mimeType = type === "jpg" ? "image/jpeg" : "image/png";
|
|
2912
|
-
const quality = type === "jpg" ? 0.9 : undefined;
|
|
2913
|
-
canvas.toBlob((blob) => {
|
|
2914
|
-
if (blob) {
|
|
2915
|
-
resolve(blob);
|
|
2916
|
-
} else {
|
|
2917
|
-
reject(new Error("Failed to create blob"));
|
|
2918
|
-
}
|
|
2919
|
-
}, mimeType, quality);
|
|
2920
|
-
});
|
|
2921
|
-
} catch (error) {
|
|
2922
|
-
reject(error);
|
|
2923
|
-
}
|
|
2924
|
-
});
|
|
2925
|
-
}
|
|
2926
|
-
setActivePage(pageId) {
|
|
2927
|
-
const page = this._design.pages.find((p) => p.id === pageId);
|
|
2928
|
-
if (page) {
|
|
2929
|
-
this._activePageId = pageId;
|
|
2930
|
-
this.emit("activePageChanged", pageId);
|
|
2931
|
-
this.emit("designChanged", this._design);
|
|
2932
|
-
}
|
|
2933
|
-
}
|
|
2934
|
-
updateElement(elementId, updates) {
|
|
2935
|
-
for (const page of this._design.pages) {
|
|
2936
|
-
const elementIndex = page.elements.findIndex((e) => e.id === elementId);
|
|
2937
|
-
if (elementIndex !== -1) {
|
|
2938
|
-
page.elements[elementIndex] = { ...page.elements[elementIndex], ...updates };
|
|
2939
|
-
this.emit("designChanged", this._design);
|
|
2940
|
-
return;
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
}
|
|
2944
|
-
deleteElement(elementId) {
|
|
2945
|
-
for (const page of this._design.pages) {
|
|
2946
|
-
const elementIndex = page.elements.findIndex((e) => e.id === elementId);
|
|
2947
|
-
if (elementIndex !== -1) {
|
|
2948
|
-
page.elements.splice(elementIndex, 1);
|
|
2949
|
-
this.emit("designChanged", this._design);
|
|
2950
|
-
return;
|
|
2951
|
-
}
|
|
2952
|
-
}
|
|
2953
|
-
}
|
|
2954
|
-
async loadJSON(jsonData) {
|
|
2955
|
-
return new Promise((resolve, reject) => {
|
|
2956
|
-
try {
|
|
2957
|
-
Promise.resolve().then(() => exports_exportImportUtils).then(({ importFromJSONData: importFromJSONData2 }) => {
|
|
2958
|
-
importFromJSONData2(jsonData, (loadedDesign) => {
|
|
2959
|
-
this.setDesign(loadedDesign);
|
|
2960
|
-
resolve();
|
|
2961
|
-
}, (errorMessage) => {
|
|
2962
|
-
reject(new Error(errorMessage));
|
|
2963
|
-
}, () => {
|
|
2964
|
-
reject(new Error("Templates requiring user inputs are not yet supported in standalone store"));
|
|
2965
|
-
});
|
|
2966
|
-
});
|
|
2967
|
-
} catch (error) {
|
|
2968
|
-
reject(error);
|
|
2969
|
-
}
|
|
2970
|
-
});
|
|
2971
|
-
}
|
|
2972
|
-
}
|
|
2973
|
-
var createSimpleStore = (initialDesign) => {
|
|
2974
|
-
return new SimpleCanvasStore(initialDesign);
|
|
2975
|
-
};
|
|
2976
|
-
|
|
2977
|
-
// src/CanvasEditor.tsx
|
|
2978
|
-
var CanvasEditor = ({
|
|
2979
|
-
name,
|
|
2980
|
-
config,
|
|
2981
|
-
store: externalStore
|
|
2982
|
-
}) => {
|
|
2983
|
-
const store = externalStore || createSimpleStore({
|
|
2984
|
-
name,
|
|
2985
|
-
width: 800,
|
|
2986
|
-
height: 600
|
|
2987
|
-
});
|
|
2988
|
-
const stageRef = useRef4(null);
|
|
2989
|
-
const fileInputRef = useRef4(null);
|
|
2990
|
-
const jsonInputRef = useRef4(null);
|
|
2991
|
-
const containerRef = useRef4(null);
|
|
2992
|
-
const currentPage = store.design.pages.find((p) => p.id === store.activePageId) || store.design.pages[0] || null;
|
|
2993
|
-
const selectedElement = currentPage?.elements.find((el) => el.id === store.selectedId) || null;
|
|
2994
|
-
useEffect4(() => {
|
|
2995
|
-
if (externalStore) {
|
|
2996
|
-
const handleDesignChange = (newDesign) => {};
|
|
2997
|
-
const handleActivePageChange = (pageId) => {};
|
|
2998
|
-
const handleActivePanelChange = (panelId) => {};
|
|
2999
|
-
const handleSelectedIdChange = (selectedId) => {};
|
|
3000
|
-
const handleSelectedIdsChange = (selectedIds) => {};
|
|
3001
|
-
const handleToolChange = (tool) => {};
|
|
3002
|
-
const handleZoomChange = (zoom) => {};
|
|
3003
|
-
const handleSelectedShapeChange = (shape) => {};
|
|
3004
|
-
externalStore.on("designChanged", handleDesignChange);
|
|
3005
|
-
externalStore.on("activePageChanged", handleActivePageChange);
|
|
3006
|
-
externalStore.on("activePanelChanged", handleActivePanelChange);
|
|
3007
|
-
externalStore.on("selectedIdChanged", handleSelectedIdChange);
|
|
3008
|
-
externalStore.on("selectedIdsChanged", handleSelectedIdsChange);
|
|
3009
|
-
externalStore.on("toolChanged", handleToolChange);
|
|
3010
|
-
externalStore.on("zoomChanged", handleZoomChange);
|
|
3011
|
-
externalStore.on("selectedShapeChanged", handleSelectedShapeChange);
|
|
3012
|
-
return () => {
|
|
3013
|
-
externalStore.off("designChanged");
|
|
3014
|
-
externalStore.off("activePageChanged");
|
|
3015
|
-
externalStore.off("activePanelChanged");
|
|
3016
|
-
externalStore.off("selectedIdChanged");
|
|
3017
|
-
externalStore.off("selectedIdsChanged");
|
|
3018
|
-
externalStore.off("toolChanged");
|
|
3019
|
-
externalStore.off("zoomChanged");
|
|
3020
|
-
externalStore.off("selectedShapeChanged");
|
|
3021
|
-
};
|
|
3022
|
-
}
|
|
3023
|
-
}, [externalStore]);
|
|
3024
|
-
const handleStageClick = useCallback4((e) => {
|
|
3025
|
-
const clickedOnEmpty = e.target === e.target.getStage();
|
|
3026
|
-
if (clickedOnEmpty) {
|
|
3027
|
-
store.setSelectedId(null);
|
|
3028
|
-
store.setSelectedIds([]);
|
|
3029
|
-
}
|
|
3030
|
-
}, [store]);
|
|
3031
|
-
const addText = useCallback4(() => {
|
|
3032
|
-
if (!store.activePage)
|
|
3033
|
-
return;
|
|
3034
|
-
store.activePage.addElement({
|
|
3035
|
-
type: "text",
|
|
3036
|
-
text: "Edit this text",
|
|
3037
|
-
x: store.design.width / 2 - 50,
|
|
3038
|
-
y: store.design.height / 2 - 15,
|
|
3039
|
-
width: 100,
|
|
3040
|
-
height: 30
|
|
3041
|
-
});
|
|
3042
|
-
}, [store]);
|
|
3043
|
-
const addShape = useCallback4((shapeType) => {
|
|
3044
|
-
if (!store.activePage)
|
|
3045
|
-
return;
|
|
3046
|
-
store.activePage.addElement({
|
|
3047
|
-
type: "shape",
|
|
3048
|
-
shapeType,
|
|
3049
|
-
x: store.design.width / 2 - 50,
|
|
3050
|
-
y: store.design.height / 2 - 50,
|
|
3051
|
-
width: 100,
|
|
3052
|
-
height: 100
|
|
3053
|
-
});
|
|
3054
|
-
}, [store]);
|
|
3055
|
-
const updateElement = useCallback4((id, attrs) => {
|
|
3056
|
-
store.updateElement(id, attrs);
|
|
3057
|
-
}, [store]);
|
|
3058
|
-
const deleteSelected = useCallback4(() => {
|
|
3059
|
-
if (store.selectedId || store.selectedIds.length > 0) {
|
|
3060
|
-
const idsToDelete = store.selectedIds.length > 0 ? store.selectedIds : [store.selectedId];
|
|
3061
|
-
idsToDelete.forEach((id) => store.deleteElement(id));
|
|
3062
|
-
store.setSelectedId(null);
|
|
3063
|
-
store.setSelectedIds([]);
|
|
3064
|
-
}
|
|
3065
|
-
}, [store]);
|
|
3066
|
-
const duplicateSelected = useCallback4(() => {
|
|
3067
|
-
if (selectedElement) {
|
|
3068
|
-
const newElement = {
|
|
3069
|
-
...selectedElement,
|
|
3070
|
-
id: Date.now().toString(),
|
|
3071
|
-
name: selectedElement.name + " copy",
|
|
3072
|
-
x: selectedElement.x + 20,
|
|
3073
|
-
y: selectedElement.y + 20
|
|
3074
|
-
};
|
|
3075
|
-
store.activePage?.addElement(newElement);
|
|
3076
|
-
store.setSelectedId(newElement.id);
|
|
3077
|
-
}
|
|
3078
|
-
}, [selectedElement, store]);
|
|
3079
|
-
const moveElementUp = useCallback4((id) => {}, [store]);
|
|
3080
|
-
const moveElementDown = useCallback4((id) => {}, [store]);
|
|
3081
|
-
const addPage = useCallback4(() => {
|
|
3082
|
-
store.addPage();
|
|
3083
|
-
}, [store]);
|
|
3084
|
-
const deletePage = useCallback4((pageId) => {
|
|
3085
|
-
store.deletePages([pageId]);
|
|
3086
|
-
}, [store]);
|
|
3087
|
-
const panelConfigs = useMemo(() => {
|
|
3088
|
-
const builtInConfigs = {
|
|
3089
|
-
elements: { id: "elements", title: "Elements", component: ElementPanel_default, props: { onAddShape: addShape, store } },
|
|
3090
|
-
text: { id: "text", title: "Text", component: TextPanel_default, props: { selectedElement, updateElement, onAddText: addText, store } },
|
|
3091
|
-
image: { id: "image", title: "Image", component: ImagePanel_default, props: { selectedElement, updateElement, store } },
|
|
3092
|
-
background: { id: "background", title: "Background", component: BackgroundPanel_default, props: { store } },
|
|
3093
|
-
design: { id: "design", title: "Design", component: DesignPanel_default, props: { store } },
|
|
3094
|
-
variables: { id: "variables", title: "Variables", component: VariablesPanel_default, props: { store } },
|
|
3095
|
-
export: { id: "export", title: "Export", component: ExportPanel_default, props: { store } }
|
|
2799
|
+
}, [store]);
|
|
2800
|
+
const duplicateSelected = useCallback4(() => {
|
|
2801
|
+
if (selectedElement) {
|
|
2802
|
+
const newElement = {
|
|
2803
|
+
...selectedElement,
|
|
2804
|
+
id: Date.now().toString(),
|
|
2805
|
+
name: selectedElement.name + " copy",
|
|
2806
|
+
x: selectedElement.x + 20,
|
|
2807
|
+
y: selectedElement.y + 20
|
|
2808
|
+
};
|
|
2809
|
+
store.activePage?.addElement(newElement);
|
|
2810
|
+
store.setSelectedId(newElement.id);
|
|
2811
|
+
}
|
|
2812
|
+
}, [selectedElement, store]);
|
|
2813
|
+
const moveElementUp = useCallback4((id) => {}, [store]);
|
|
2814
|
+
const moveElementDown = useCallback4((id) => {}, [store]);
|
|
2815
|
+
const panelConfigs = useMemo(() => {
|
|
2816
|
+
const builtInConfigs = {
|
|
2817
|
+
elements: { id: "elements", title: "Elements", component: ElementPanel_default, props: { onAddShape: addShape, store } },
|
|
2818
|
+
text: { id: "text", title: "Text", component: TextPanel_default, props: { selectedElement, updateElement, onAddText: addText, store } },
|
|
2819
|
+
image: { id: "image", title: "Image", component: ImagePanel_default, props: { selectedElement, updateElement, store } },
|
|
2820
|
+
background: { id: "background", title: "Background", component: BackgroundPanel_default, props: { store } },
|
|
2821
|
+
design: { id: "design", title: "Design", component: DesignPanel_default, props: { store } },
|
|
2822
|
+
variables: { id: "variables", title: "Variables", component: VariablesPanel_default, props: { store } },
|
|
2823
|
+
export: { id: "export", title: "Export", component: ExportPanel_default, props: { store } }
|
|
3096
2824
|
};
|
|
3097
2825
|
const mergedConfigs = { ...builtInConfigs };
|
|
3098
2826
|
if (config?.panels) {
|
|
@@ -3222,10 +2950,9 @@ var CanvasEditor = ({
|
|
|
3222
2950
|
className: "text-center"
|
|
3223
2951
|
}, /* @__PURE__ */ React17.createElement("p", {
|
|
3224
2952
|
className: "mb-4"
|
|
3225
|
-
}, "No pages available"), /* @__PURE__ */ React17.createElement("
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
}, "Add Page"))) : /* @__PURE__ */ React17.createElement("div", {
|
|
2953
|
+
}, "No pages available"), /* @__PURE__ */ React17.createElement("p", {
|
|
2954
|
+
className: "text-sm"
|
|
2955
|
+
}, "Please add pages through your store management"))) : /* @__PURE__ */ React17.createElement("div", {
|
|
3229
2956
|
className: "absolute inset-0 flex items-center justify-center"
|
|
3230
2957
|
}, /* @__PURE__ */ React17.createElement("div", {
|
|
3231
2958
|
className: "bg-white shadow-2xl",
|
|
@@ -3291,13 +3018,7 @@ var CanvasEditor = ({
|
|
|
3291
3018
|
key: page.id,
|
|
3292
3019
|
onClick: () => store.setActivePage(page.id),
|
|
3293
3020
|
className: `px-3 py-1 rounded text-sm ${page.id === store.activePageId ? "bg-blue-600 text-white" : "bg-gray-800 text-gray-300 hover:bg-gray-700"}`
|
|
3294
|
-
}, "Page ", index + 1)), /* @__PURE__ */ React17.createElement(
|
|
3295
|
-
onClick: addPage,
|
|
3296
|
-
className: "px-3 py-1 rounded text-sm bg-gray-800 text-gray-300 hover:bg-gray-700",
|
|
3297
|
-
title: "Add Page"
|
|
3298
|
-
}, /* @__PURE__ */ React17.createElement(PlusCircle, {
|
|
3299
|
-
className: "w-4 h-4"
|
|
3300
|
-
})))), /* @__PURE__ */ React17.createElement(RightSidebar_default, {
|
|
3021
|
+
}, "Page ", index + 1)))), /* @__PURE__ */ React17.createElement(RightSidebar_default, {
|
|
3301
3022
|
currentPageElements: currentPage?.elements || [],
|
|
3302
3023
|
selectedElement,
|
|
3303
3024
|
selectedId: store.selectedId,
|
|
@@ -3322,6 +3043,262 @@ var CanvasEditor = ({
|
|
|
3322
3043
|
}));
|
|
3323
3044
|
};
|
|
3324
3045
|
var CanvasEditor_default = CanvasEditor;
|
|
3046
|
+
// src/store/simpleStore.ts
|
|
3047
|
+
class SimpleCanvasStore {
|
|
3048
|
+
_design;
|
|
3049
|
+
_activePageId;
|
|
3050
|
+
_activePanelId;
|
|
3051
|
+
_selectedId;
|
|
3052
|
+
_selectedIds;
|
|
3053
|
+
_tool;
|
|
3054
|
+
_zoom;
|
|
3055
|
+
_selectedShape;
|
|
3056
|
+
_listeners = {};
|
|
3057
|
+
constructor(initialDesign) {
|
|
3058
|
+
this._design = {
|
|
3059
|
+
id: initialDesign?.id || `design-${Date.now()}`,
|
|
3060
|
+
name: initialDesign?.name || "Untitled Design",
|
|
3061
|
+
width: initialDesign?.width || 800,
|
|
3062
|
+
height: initialDesign?.height || 600,
|
|
3063
|
+
pages: initialDesign?.pages || [],
|
|
3064
|
+
fonts: initialDesign?.fonts || [],
|
|
3065
|
+
colors: initialDesign?.colors || [],
|
|
3066
|
+
templateInputs: initialDesign?.templateInputs
|
|
3067
|
+
};
|
|
3068
|
+
this._activePageId = initialDesign?.pages?.[0]?.id || null;
|
|
3069
|
+
this._activePanelId = null;
|
|
3070
|
+
this._selectedId = null;
|
|
3071
|
+
this._selectedIds = [];
|
|
3072
|
+
this._tool = "select";
|
|
3073
|
+
this._zoom = 1;
|
|
3074
|
+
this._selectedShape = "rect";
|
|
3075
|
+
}
|
|
3076
|
+
on(event, callback) {
|
|
3077
|
+
this._listeners[event] = callback;
|
|
3078
|
+
}
|
|
3079
|
+
off(event) {
|
|
3080
|
+
delete this._listeners[event];
|
|
3081
|
+
}
|
|
3082
|
+
emit(event, ...args) {
|
|
3083
|
+
const callback = this._listeners[event];
|
|
3084
|
+
if (callback) {
|
|
3085
|
+
callback(...args);
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
get design() {
|
|
3089
|
+
return this._design;
|
|
3090
|
+
}
|
|
3091
|
+
get width() {
|
|
3092
|
+
return this._design.width;
|
|
3093
|
+
}
|
|
3094
|
+
get height() {
|
|
3095
|
+
return this._design.height;
|
|
3096
|
+
}
|
|
3097
|
+
get activePage() {
|
|
3098
|
+
const page = this._design.pages.find((p) => p.id === this._activePageId) || null;
|
|
3099
|
+
if (!page)
|
|
3100
|
+
return null;
|
|
3101
|
+
return {
|
|
3102
|
+
...page,
|
|
3103
|
+
addElement: (element) => {
|
|
3104
|
+
this.addElement(element);
|
|
3105
|
+
}
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
get activePageId() {
|
|
3109
|
+
return this._activePageId;
|
|
3110
|
+
}
|
|
3111
|
+
get activePanelId() {
|
|
3112
|
+
return this._activePanelId;
|
|
3113
|
+
}
|
|
3114
|
+
get selectedId() {
|
|
3115
|
+
return this._selectedId;
|
|
3116
|
+
}
|
|
3117
|
+
get selectedIds() {
|
|
3118
|
+
return this._selectedIds;
|
|
3119
|
+
}
|
|
3120
|
+
get tool() {
|
|
3121
|
+
return this._tool;
|
|
3122
|
+
}
|
|
3123
|
+
get zoom() {
|
|
3124
|
+
return this._zoom;
|
|
3125
|
+
}
|
|
3126
|
+
get selectedShape() {
|
|
3127
|
+
return this._selectedShape;
|
|
3128
|
+
}
|
|
3129
|
+
setDesign(design) {
|
|
3130
|
+
this._design = design;
|
|
3131
|
+
if (design.pages.find((p) => p.id === this._activePageId)) {} else if (design.pages.length > 0) {
|
|
3132
|
+
this._activePageId = design.pages[0].id;
|
|
3133
|
+
}
|
|
3134
|
+
this.emit("designChanged", this._design);
|
|
3135
|
+
this.emit("activePageChanged", this._activePageId);
|
|
3136
|
+
}
|
|
3137
|
+
updateDesign(updates) {
|
|
3138
|
+
this._design = { ...this._design, ...updates };
|
|
3139
|
+
this.emit("designChanged", this._design);
|
|
3140
|
+
}
|
|
3141
|
+
setSize(width, height) {
|
|
3142
|
+
this._design.width = width;
|
|
3143
|
+
this._design.height = height;
|
|
3144
|
+
this.emit("designChanged", this._design);
|
|
3145
|
+
}
|
|
3146
|
+
addPage(page) {
|
|
3147
|
+
console.log(`addPage called - Current pages: ${this._design.pages.length}, New page ID: ${page?.id || `page-${Date.now()}`}`);
|
|
3148
|
+
const newPage = {
|
|
3149
|
+
id: page?.id || `page-${Date.now()}`,
|
|
3150
|
+
name: page?.name || `Page ${this._design.pages.length + 1}`,
|
|
3151
|
+
elements: page?.elements || [],
|
|
3152
|
+
background: page?.background || "#ffffff",
|
|
3153
|
+
backgroundImageObject: page?.backgroundImageObject
|
|
3154
|
+
};
|
|
3155
|
+
this._design.pages.push(newPage);
|
|
3156
|
+
if (!this._activePageId || this._design.pages.length === 1) {
|
|
3157
|
+
this._activePageId = newPage.id;
|
|
3158
|
+
this.emit("activePageChanged", this._activePageId);
|
|
3159
|
+
}
|
|
3160
|
+
this.emit("designChanged", this._design);
|
|
3161
|
+
return newPage.id;
|
|
3162
|
+
}
|
|
3163
|
+
deletePages(pageIds) {
|
|
3164
|
+
const remainingPages = this._design.pages.filter((p) => !pageIds.includes(p.id));
|
|
3165
|
+
if (remainingPages.length === 0) {
|
|
3166
|
+
console.warn("Cannot delete all pages. At least one page must remain.");
|
|
3167
|
+
return;
|
|
3168
|
+
}
|
|
3169
|
+
if (pageIds.includes(this._activePageId)) {
|
|
3170
|
+
this._activePageId = remainingPages[0].id;
|
|
3171
|
+
this.emit("activePageChanged", this._activePageId);
|
|
3172
|
+
}
|
|
3173
|
+
this._design.pages = remainingPages;
|
|
3174
|
+
this.emit("designChanged", this._design);
|
|
3175
|
+
}
|
|
3176
|
+
addElement(element) {
|
|
3177
|
+
const page = this.activePage;
|
|
3178
|
+
if (!page) {
|
|
3179
|
+
console.warn("addElement: No active page!");
|
|
3180
|
+
return;
|
|
3181
|
+
}
|
|
3182
|
+
const newElement = {
|
|
3183
|
+
id: element.id || `element-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
3184
|
+
type: element.type,
|
|
3185
|
+
name: element.name || `${element.type} element`,
|
|
3186
|
+
x: element.x || 0,
|
|
3187
|
+
y: element.y || 0,
|
|
3188
|
+
width: element.width || 100,
|
|
3189
|
+
height: element.height || 100,
|
|
3190
|
+
rotation: element.rotation || 0,
|
|
3191
|
+
visible: element.visible !== false,
|
|
3192
|
+
locked: element.locked || false,
|
|
3193
|
+
opacity: element.opacity || 1,
|
|
3194
|
+
...element
|
|
3195
|
+
};
|
|
3196
|
+
page.elements.push(newElement);
|
|
3197
|
+
this.emit("designChanged", this._design);
|
|
3198
|
+
}
|
|
3199
|
+
openSidePanel(panelId) {
|
|
3200
|
+
this._activePanelId = panelId;
|
|
3201
|
+
this.emit("activePanelChanged", panelId);
|
|
3202
|
+
}
|
|
3203
|
+
setSelectedId(selectedId) {
|
|
3204
|
+
this._selectedId = selectedId;
|
|
3205
|
+
this.emit("selectedIdChanged", selectedId);
|
|
3206
|
+
}
|
|
3207
|
+
setSelectedIds(selectedIds) {
|
|
3208
|
+
this._selectedIds = selectedIds;
|
|
3209
|
+
this.emit("selectedIdsChanged", selectedIds);
|
|
3210
|
+
}
|
|
3211
|
+
setTool(tool) {
|
|
3212
|
+
this._tool = tool;
|
|
3213
|
+
this.emit("toolChanged", tool);
|
|
3214
|
+
}
|
|
3215
|
+
setZoom(zoom) {
|
|
3216
|
+
this._zoom = zoom;
|
|
3217
|
+
this.emit("zoomChanged", zoom);
|
|
3218
|
+
}
|
|
3219
|
+
setSelectedShape(shape) {
|
|
3220
|
+
this._selectedShape = shape;
|
|
3221
|
+
this.emit("selectedShapeChanged", shape);
|
|
3222
|
+
}
|
|
3223
|
+
async toBlob(type = "png") {
|
|
3224
|
+
return new Promise((resolve, reject) => {
|
|
3225
|
+
try {
|
|
3226
|
+
Promise.resolve().then(() => exports_exportImportUtils).then(({ canvasToBlob: canvasToBlob2 }) => {
|
|
3227
|
+
const canvas = document.createElement("canvas");
|
|
3228
|
+
canvas.width = this._design.width;
|
|
3229
|
+
canvas.height = this._design.height;
|
|
3230
|
+
const ctx = canvas.getContext("2d");
|
|
3231
|
+
if (!ctx) {
|
|
3232
|
+
reject(new Error("Failed to get canvas context"));
|
|
3233
|
+
return;
|
|
3234
|
+
}
|
|
3235
|
+
ctx.fillStyle = "#ffffff";
|
|
3236
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
3237
|
+
const mimeType = type === "jpg" ? "image/jpeg" : "image/png";
|
|
3238
|
+
const quality = type === "jpg" ? 0.9 : undefined;
|
|
3239
|
+
canvas.toBlob((blob) => {
|
|
3240
|
+
if (blob) {
|
|
3241
|
+
resolve(blob);
|
|
3242
|
+
} else {
|
|
3243
|
+
reject(new Error("Failed to create blob"));
|
|
3244
|
+
}
|
|
3245
|
+
}, mimeType, quality);
|
|
3246
|
+
});
|
|
3247
|
+
} catch (error) {
|
|
3248
|
+
reject(error);
|
|
3249
|
+
}
|
|
3250
|
+
});
|
|
3251
|
+
}
|
|
3252
|
+
setActivePage(pageId) {
|
|
3253
|
+
const page = this._design.pages.find((p) => p.id === pageId);
|
|
3254
|
+
if (page) {
|
|
3255
|
+
this._activePageId = pageId;
|
|
3256
|
+
this.emit("activePageChanged", pageId);
|
|
3257
|
+
this.emit("designChanged", this._design);
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
updateElement(elementId, updates) {
|
|
3261
|
+
for (const page of this._design.pages) {
|
|
3262
|
+
const elementIndex = page.elements.findIndex((e) => e.id === elementId);
|
|
3263
|
+
if (elementIndex !== -1) {
|
|
3264
|
+
page.elements[elementIndex] = { ...page.elements[elementIndex], ...updates };
|
|
3265
|
+
this.emit("designChanged", this._design);
|
|
3266
|
+
return;
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
deleteElement(elementId) {
|
|
3271
|
+
for (const page of this._design.pages) {
|
|
3272
|
+
const elementIndex = page.elements.findIndex((e) => e.id === elementId);
|
|
3273
|
+
if (elementIndex !== -1) {
|
|
3274
|
+
page.elements.splice(elementIndex, 1);
|
|
3275
|
+
this.emit("designChanged", this._design);
|
|
3276
|
+
return;
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
async loadJSON(jsonData) {
|
|
3281
|
+
return new Promise((resolve, reject) => {
|
|
3282
|
+
try {
|
|
3283
|
+
Promise.resolve().then(() => exports_exportImportUtils).then(({ importFromJSONData: importFromJSONData2 }) => {
|
|
3284
|
+
importFromJSONData2(jsonData, (loadedDesign) => {
|
|
3285
|
+
this.setDesign(loadedDesign);
|
|
3286
|
+
resolve();
|
|
3287
|
+
}, (errorMessage) => {
|
|
3288
|
+
reject(new Error(errorMessage));
|
|
3289
|
+
}, () => {
|
|
3290
|
+
reject(new Error("Templates requiring user inputs are not yet supported in standalone store"));
|
|
3291
|
+
});
|
|
3292
|
+
});
|
|
3293
|
+
} catch (error) {
|
|
3294
|
+
reject(error);
|
|
3295
|
+
}
|
|
3296
|
+
});
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
var createSimpleStore = (initialDesign) => {
|
|
3300
|
+
return new SimpleCanvasStore(initialDesign);
|
|
3301
|
+
};
|
|
3325
3302
|
// src/context/CanvasStoreContext.tsx
|
|
3326
3303
|
import { createContext, useContext } from "react";
|
|
3327
3304
|
var CanvasStoreContext = createContext(null);
|