@merchi/product-editor 0.1.9

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.
Files changed (123) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/README.md +174 -0
  3. package/dist/components/AlignMenu.d.ts +3 -0
  4. package/dist/components/AlignMenu.js +61 -0
  5. package/dist/components/FloatingToolbar.d.ts +4 -0
  6. package/dist/components/FloatingToolbar.js +97 -0
  7. package/dist/components/FormatButtons.d.ts +2 -0
  8. package/dist/components/FormatButtons.js +22 -0
  9. package/dist/components/ImageNavButton.d.ts +7 -0
  10. package/dist/components/ImageNavButton.js +14 -0
  11. package/dist/components/ImageZoomModal.d.ts +12 -0
  12. package/dist/components/ImageZoomModal.js +129 -0
  13. package/dist/components/LayerPanel.d.ts +4 -0
  14. package/dist/components/LayerPanel.js +223 -0
  15. package/dist/components/LoadingOverlay.d.ts +9 -0
  16. package/dist/components/LoadingOverlay.js +17 -0
  17. package/dist/components/ProductEditor.d.ts +4 -0
  18. package/dist/components/ProductEditor.js +67 -0
  19. package/dist/components/ProductImageGallery.d.ts +6 -0
  20. package/dist/components/ProductImageGallery.js +148 -0
  21. package/dist/components/ProductPreviews.d.ts +7 -0
  22. package/dist/components/ProductPreviews.js +281 -0
  23. package/dist/components/TextToolbar.d.ts +4 -0
  24. package/dist/components/TextToolbar.js +117 -0
  25. package/dist/components/Toolbar.d.ts +3 -0
  26. package/dist/components/Toolbar.js +47 -0
  27. package/dist/config/colorConfig.d.ts +1 -0
  28. package/dist/config/colorConfig.js +10 -0
  29. package/dist/config/fontConfig.d.ts +5 -0
  30. package/dist/config/fontConfig.js +21 -0
  31. package/dist/context/ProductEditorContext.d.ts +60 -0
  32. package/dist/context/ProductEditorContext.js +743 -0
  33. package/dist/hooks/useSwipeNavigate.d.ts +11 -0
  34. package/dist/hooks/useSwipeNavigate.js +35 -0
  35. package/dist/index.d.ts +6 -0
  36. package/dist/index.js +30 -0
  37. package/dist/styles/BottomPreviewDisplay.css +65 -0
  38. package/dist/styles/FloatingToolbar.css +41 -0
  39. package/dist/styles/ImageGallery.css +147 -0
  40. package/dist/styles/ImageNavButton.css +35 -0
  41. package/dist/styles/ImageZoomModal.css +101 -0
  42. package/dist/styles/LayerPanel.css +179 -0
  43. package/dist/styles/LoadingOverlay.css +48 -0
  44. package/dist/styles/ProductEditor.css +192 -0
  45. package/dist/styles/TextToolbar.css +327 -0
  46. package/dist/styles/Toolbar.css +125 -0
  47. package/dist/styles/index.css +5 -0
  48. package/dist/styles/textToolbarSelectStyles.d.ts +3 -0
  49. package/dist/styles/textToolbarSelectStyles.js +30 -0
  50. package/dist/types.d.ts +228 -0
  51. package/dist/types.js +17 -0
  52. package/dist/utils/canvasAddText.d.ts +11 -0
  53. package/dist/utils/canvasAddText.js +66 -0
  54. package/dist/utils/canvasUtils.d.ts +37 -0
  55. package/dist/utils/canvasUtils.js +342 -0
  56. package/dist/utils/deviceUtils.d.ts +5 -0
  57. package/dist/utils/deviceUtils.js +33 -0
  58. package/dist/utils/draftTemplateUtils.d.ts +23 -0
  59. package/dist/utils/draftTemplateUtils.js +66 -0
  60. package/dist/utils/grid.d.ts +32 -0
  61. package/dist/utils/grid.js +151 -0
  62. package/dist/utils/imageUtils.d.ts +12 -0
  63. package/dist/utils/imageUtils.js +178 -0
  64. package/dist/utils/job.d.ts +40 -0
  65. package/dist/utils/job.js +115 -0
  66. package/dist/utils/keyboard.d.ts +1 -0
  67. package/dist/utils/keyboard.js +26 -0
  68. package/dist/utils/previewUtils.d.ts +9 -0
  69. package/dist/utils/previewUtils.js +39 -0
  70. package/dist/utils/psdConverter.d.ts +40 -0
  71. package/dist/utils/psdConverter.js +516 -0
  72. package/dist/utils/psdRenderUtils.d.ts +12 -0
  73. package/dist/utils/psdRenderUtils.js +465 -0
  74. package/dist/utils/renderUtils.d.ts +2 -0
  75. package/dist/utils/renderUtils.js +85 -0
  76. package/package.json +66 -0
  77. package/src/components/AlignMenu.tsx +49 -0
  78. package/src/components/FloatingToolbar.tsx +83 -0
  79. package/src/components/FormatButtons.tsx +31 -0
  80. package/src/components/ImageNavButton.tsx +23 -0
  81. package/src/components/ImageZoomModal.tsx +163 -0
  82. package/src/components/LayerPanel.tsx +256 -0
  83. package/src/components/LoadingOverlay.tsx +27 -0
  84. package/src/components/ProductEditor.tsx +104 -0
  85. package/src/components/ProductImageGallery.tsx +181 -0
  86. package/src/components/ProductPreviews.tsx +243 -0
  87. package/src/components/TextToolbar.tsx +164 -0
  88. package/src/components/Toolbar.tsx +86 -0
  89. package/src/config/colorConfig.ts +7 -0
  90. package/src/config/fontConfig.ts +23 -0
  91. package/src/context/ProductEditorContext.tsx +829 -0
  92. package/src/hooks/useSwipeNavigate.ts +40 -0
  93. package/src/index.ts +6 -0
  94. package/src/styles/BottomPreviewDisplay.css +65 -0
  95. package/src/styles/FloatingToolbar.css +41 -0
  96. package/src/styles/ImageGallery.css +147 -0
  97. package/src/styles/ImageNavButton.css +35 -0
  98. package/src/styles/ImageZoomModal.css +101 -0
  99. package/src/styles/LayerPanel.css +179 -0
  100. package/src/styles/LoadingOverlay.css +48 -0
  101. package/src/styles/ProductEditor.css +192 -0
  102. package/src/styles/TextToolbar.css +327 -0
  103. package/src/styles/Toolbar.css +125 -0
  104. package/src/styles/index.css +5 -0
  105. package/src/styles/textToolbarSelectStyles.ts +60 -0
  106. package/src/types/ag-psd/index.d.ts +1 -0
  107. package/src/types/fabric.d.ts +14 -0
  108. package/src/types/lodash/index.d.ts +1 -0
  109. package/src/types/psd.d.ts +53 -0
  110. package/src/types.ts +247 -0
  111. package/src/utils/canvasAddText.ts +72 -0
  112. package/src/utils/canvasUtils.ts +406 -0
  113. package/src/utils/deviceUtils.ts +31 -0
  114. package/src/utils/draftTemplateUtils.ts +70 -0
  115. package/src/utils/grid.ts +154 -0
  116. package/src/utils/imageUtils.ts +218 -0
  117. package/src/utils/job.ts +128 -0
  118. package/src/utils/keyboard.ts +28 -0
  119. package/src/utils/previewUtils.ts +43 -0
  120. package/src/utils/psdConverter.ts +595 -0
  121. package/src/utils/psdRenderUtils.ts +453 -0
  122. package/src/utils/renderUtils.ts +44 -0
  123. package/tsconfig.json +17 -0
@@ -0,0 +1,228 @@
1
+ export declare enum FieldType {
2
+ TEXT_INPUT = 1,
3
+ SELECT = 2,
4
+ FILE_UPLOAD = 3,
5
+ TEXT_AREA = 4,
6
+ NUMBER_INPUT = 5,
7
+ CHECKBOX = 6,
8
+ RADIO = 7,
9
+ FIELD_INSTRUCTIONS = 8,
10
+ IMAGE_SELECT = 9,
11
+ COLOUR_PICKER = 10,
12
+ COLOUR_SELECT = 11
13
+ }
14
+ export interface Draft {
15
+ id?: number;
16
+ }
17
+ export interface MerchiFile {
18
+ id?: number;
19
+ uploadId?: string;
20
+ name?: string | null;
21
+ mimetype?: string | null;
22
+ size?: number;
23
+ creationDate?: Date | null;
24
+ cachedViewUrl?: string | null;
25
+ viewUrlExpires?: Date | null;
26
+ cachedDownloadUrl?: string | null;
27
+ downloadUrlExpires?: Date | null;
28
+ viewUrl: string;
29
+ downloadUrl?: string;
30
+ thumbnailUrl?: string;
31
+ previewUrl?: string;
32
+ }
33
+ export interface DraftTemplate {
34
+ id?: number;
35
+ name?: string;
36
+ description?: string;
37
+ width?: number;
38
+ height?: number;
39
+ file?: MerchiFile;
40
+ product?: Product | null;
41
+ editedByVariationFields?: VariationField[];
42
+ selectedByVariationFieldOptions?: VariationFieldsOption[];
43
+ draftPreviewLayers?: DraftPreviewLayer[];
44
+ }
45
+ export interface DraftPreview {
46
+ id?: number;
47
+ file?: MerchiFile;
48
+ product?: Product;
49
+ description?: string | null;
50
+ name?: string | null;
51
+ date?: Date | null;
52
+ height?: number;
53
+ width?: number;
54
+ draftPreviewLayers?: DraftPreviewLayer[];
55
+ }
56
+ export interface DraftPreviewLayer {
57
+ id?: number;
58
+ layerName?: string;
59
+ draftPreview?: DraftPreview;
60
+ draftTemplate?: DraftTemplate;
61
+ }
62
+ export interface VariationFieldsOption {
63
+ id?: number;
64
+ archived?: Date | null;
65
+ value?: string | null;
66
+ colour?: string | null;
67
+ currency?: string;
68
+ default?: boolean;
69
+ include?: boolean;
70
+ noInventory?: boolean;
71
+ position?: number;
72
+ variationCost?: number;
73
+ variationUnitCost?: number;
74
+ buyUnitCost?: number;
75
+ buyCost?: number;
76
+ variationField?: VariationField | null;
77
+ linkedFile?: MerchiFile | null;
78
+ selectedByVariations?: Variation[];
79
+ }
80
+ export interface VariationField {
81
+ id?: number;
82
+ archived?: Date | null;
83
+ position?: number;
84
+ required?: boolean;
85
+ independent?: boolean;
86
+ name?: string;
87
+ instructions?: string;
88
+ placeholder?: string | null;
89
+ defaultValue?: string;
90
+ currency?: string;
91
+ fieldType?: FieldType;
92
+ margin?: number;
93
+ variationCost?: number;
94
+ variationUnitCost?: number;
95
+ buyUnitCost?: number;
96
+ buyCost?: number;
97
+ rows?: number;
98
+ fieldMin?: number | null;
99
+ fieldMax?: number | null;
100
+ allowDecimal?: boolean;
101
+ sellerProductEditable?: boolean;
102
+ multipleSelect?: boolean;
103
+ showFilePreview?: boolean;
104
+ allowFileMultiple?: boolean;
105
+ allowFileJpeg?: boolean;
106
+ allowFileGif?: boolean;
107
+ allowFilePdf?: boolean;
108
+ allowFilePng?: boolean;
109
+ allowFileAi?: boolean;
110
+ product?: Product;
111
+ variations?: Variation[];
112
+ options?: VariationFieldsOption[];
113
+ }
114
+ export interface VariationOption {
115
+ optionId?: number;
116
+ value?: string | null;
117
+ colour?: string | null;
118
+ position?: number;
119
+ available?: boolean;
120
+ default?: boolean;
121
+ include?: boolean;
122
+ linkedFile?: MerchiFile | null;
123
+ fieldName?: string;
124
+ quantity?: number;
125
+ currency?: string;
126
+ onceOffCost?: number;
127
+ unitCost?: number;
128
+ unitCostTotal?: number;
129
+ totalCost?: number;
130
+ }
131
+ export interface Variation {
132
+ id?: number;
133
+ archived?: Date | null;
134
+ value?: string | null;
135
+ currency?: string;
136
+ cost?: number;
137
+ quantity?: number;
138
+ onceOffCost?: number;
139
+ unitCost?: number;
140
+ unitCostTotal?: number;
141
+ variationField?: VariationField;
142
+ variationsGroup?: VariationsGroup | null;
143
+ job?: Job | null;
144
+ variationFiles?: MerchiFile[];
145
+ selectedOptions?: VariationOption[];
146
+ selectableOptions?: VariationOption[];
147
+ }
148
+ export interface VariationsGroup {
149
+ id?: number;
150
+ archived?: Date | null;
151
+ quantity?: number;
152
+ groupCost?: number | null;
153
+ job?: Job | null;
154
+ variations?: Variation[];
155
+ inventoryCount?: number;
156
+ inventorySufficient?: boolean;
157
+ }
158
+ export interface Product {
159
+ id?: number;
160
+ name?: string;
161
+ description?: string | null;
162
+ draftTemplates?: DraftTemplate[];
163
+ draftPreviews?: DraftPreview[];
164
+ featureImage?: MerchiFile;
165
+ groupVariationFields?: VariationField[];
166
+ independentVariationFields?: VariationField[];
167
+ images?: MerchiFile[];
168
+ }
169
+ export interface Job {
170
+ id?: number;
171
+ quantity?: number;
172
+ currency?: string;
173
+ jobInfoApprovedByClient?: boolean;
174
+ costPerUnit?: number | null;
175
+ cost?: number | null;
176
+ taxAmount?: number | null;
177
+ totalCost?: number | null;
178
+ drafts?: Draft[];
179
+ sharedDrafts?: Draft[];
180
+ ownDrafts?: Draft[];
181
+ product?: Product;
182
+ variationsGroups?: VariationsGroup[];
183
+ variations?: Variation[];
184
+ }
185
+ export interface ProductEditorProps {
186
+ product: Product;
187
+ width?: number;
188
+ height?: number;
189
+ onSave?: (editedImage: string) => void;
190
+ onCancel?: () => void;
191
+ psdTemplateUrl?: string;
192
+ }
193
+ export interface SavedCanvasObject {
194
+ fieldId: string;
195
+ fileId?: string;
196
+ uniqueId?: string;
197
+ type: string;
198
+ left: number;
199
+ top: number;
200
+ scaleX: number;
201
+ scaleY: number;
202
+ angle: number;
203
+ text?: string;
204
+ fontSize?: number;
205
+ fontFamily?: string;
206
+ fill?: string;
207
+ width?: number;
208
+ height?: number;
209
+ src?: string;
210
+ [key: string]: any;
211
+ }
212
+ export interface DraftTemplateData {
213
+ template: DraftTemplate;
214
+ variationFieldIds: number[];
215
+ variationObjects: any[];
216
+ }
217
+ export interface RenderedDraftPreview {
218
+ templateId: number;
219
+ draft: string;
220
+ canvasPreview: string;
221
+ }
222
+ export interface MappedPreview {
223
+ draftPreview: DraftPreview;
224
+ draftPreviewLayers: {
225
+ layerName: string | undefined;
226
+ renderedLayer: RenderedDraftPreview | null;
227
+ }[];
228
+ }
package/dist/types.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FieldType = void 0;
4
+ var FieldType;
5
+ (function (FieldType) {
6
+ FieldType[FieldType["TEXT_INPUT"] = 1] = "TEXT_INPUT";
7
+ FieldType[FieldType["SELECT"] = 2] = "SELECT";
8
+ FieldType[FieldType["FILE_UPLOAD"] = 3] = "FILE_UPLOAD";
9
+ FieldType[FieldType["TEXT_AREA"] = 4] = "TEXT_AREA";
10
+ FieldType[FieldType["NUMBER_INPUT"] = 5] = "NUMBER_INPUT";
11
+ FieldType[FieldType["CHECKBOX"] = 6] = "CHECKBOX";
12
+ FieldType[FieldType["RADIO"] = 7] = "RADIO";
13
+ FieldType[FieldType["FIELD_INSTRUCTIONS"] = 8] = "FIELD_INSTRUCTIONS";
14
+ FieldType[FieldType["IMAGE_SELECT"] = 9] = "IMAGE_SELECT";
15
+ FieldType[FieldType["COLOUR_PICKER"] = 10] = "COLOUR_PICKER";
16
+ FieldType[FieldType["COLOUR_SELECT"] = 11] = "COLOUR_SELECT";
17
+ })(FieldType = exports.FieldType || (exports.FieldType = {}));
@@ -0,0 +1,11 @@
1
+ import { fabric } from 'fabric';
2
+ /**
3
+ * Adds an editable text object to the canvas
4
+ * @param canvas - The Fabric.js canvas instance
5
+ * @param width - The width of the canvas
6
+ * @param height - The height of the canvas
7
+ * @param defaultText - Optional default text (defaults to "Text")
8
+ * @param fontSize - Optional font size (defaults to 24)
9
+ * @param fontFamily - Optional font family (defaults to Arial)
10
+ */
11
+ export declare const addText: (canvas: fabric.Canvas, width: number, height: number, defaultText?: string, fontSize?: number, fontFamily?: string) => fabric.IText | null;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addText = void 0;
4
+ // add text to the canvas
5
+ var fabric_1 = require("fabric");
6
+ /**
7
+ * Adds an editable text object to the canvas
8
+ * @param canvas - The Fabric.js canvas instance
9
+ * @param width - The width of the canvas
10
+ * @param height - The height of the canvas
11
+ * @param defaultText - Optional default text (defaults to "Text")
12
+ * @param fontSize - Optional font size (defaults to 24)
13
+ * @param fontFamily - Optional font family (defaults to Arial)
14
+ */
15
+ var addText = function (canvas, width, height, defaultText, fontSize, fontFamily) {
16
+ if (defaultText === void 0) { defaultText = 'Text'; }
17
+ if (fontSize === void 0) { fontSize = 24; }
18
+ if (fontFamily === void 0) { fontFamily = 'Nunito'; }
19
+ if (!canvas)
20
+ return null;
21
+ try {
22
+ // Safe check if canvas is still valid
23
+ if (!canvas.getElement() || !canvas.getElement().parentNode) {
24
+ return null;
25
+ }
26
+ // Create a new text object with minimal options
27
+ var text_1 = new fabric_1.fabric.IText(defaultText, {
28
+ left: width / 2,
29
+ top: height / 2,
30
+ fontFamily: fontFamily,
31
+ fontSize: fontSize,
32
+ fill: '#000000',
33
+ originX: 'center',
34
+ originY: 'center',
35
+ selectable: true,
36
+ editable: false
37
+ });
38
+ // Add the text to the canvas
39
+ canvas.add(text_1);
40
+ // Ensure the text is rendered
41
+ canvas.renderAll();
42
+ // Make the text active - this is critical
43
+ var setActiveTextObject = function () {
44
+ try {
45
+ // Check if canvas is still valid
46
+ if (canvas && canvas.getElement() && canvas.getElement().parentNode) {
47
+ canvas.setActiveObject(text_1);
48
+ canvas.renderAll();
49
+ }
50
+ }
51
+ catch (err) {
52
+ console.error('Error setting active text object:', err);
53
+ }
54
+ };
55
+ // Initial selection
56
+ setActiveTextObject();
57
+ // Delayed selection to ensure text becomes active
58
+ setTimeout(setActiveTextObject, 50);
59
+ return text_1;
60
+ }
61
+ catch (error) {
62
+ console.error('Error adding text to canvas:', error);
63
+ return null;
64
+ }
65
+ };
66
+ exports.addText = addText;
@@ -0,0 +1,37 @@
1
+ import { fabric } from 'fabric';
2
+ /**
3
+ * Adds an editable text object to the canvas
4
+ * @param canvas - The Fabric.js canvas instance
5
+ * @param width - The width of the canvas
6
+ * @param height - The height of the canvas
7
+ * @param defaultText - Optional default text (defaults to "Text")
8
+ * @param fontSize - Optional font size (defaults to 24)
9
+ * @param fontFamily - Optional font family (defaults to Arial)
10
+ */
11
+ export declare const addTextToCanvas: (canvas: fabric.Canvas, width: number, height: number, defaultText?: string, fontSize?: number, fontFamily?: string) => fabric.IText | null;
12
+ /**
13
+ * Renders the entire canvas as an image without displaying grid elements
14
+ *
15
+ * @param canvas - The Fabric.js canvas instance
16
+ * @param options - Optional rendering options
17
+ * @returns A promise that resolves to the dataURL of the canvas without grid
18
+ */
19
+ export declare const renderCanvasWithoutGrid: (canvas: fabric.Canvas, options?: {
20
+ format?: string;
21
+ quality?: number;
22
+ multiplier?: number;
23
+ backgroundColor?: string | null;
24
+ }) => Promise<string | null>;
25
+ /**
26
+ * Renders an image containing only what's visible inside a clipPath on the canvas
27
+ *
28
+ * @param canvas - The Fabric.js canvas instance
29
+ * @param options - Optional rendering options
30
+ * @returns A promise that resolves to the dataURL of the contents inside the clipPath, or null if no clipped object is found
31
+ */
32
+ export declare const renderClippedImage: (canvas: fabric.Canvas, options?: {
33
+ format?: string;
34
+ quality?: number;
35
+ multiplier?: number;
36
+ backgroundColor?: string;
37
+ }) => Promise<string | null>;