labellife-design-tool 1.0.4 → 1.0.6

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/README.md CHANGED
@@ -128,7 +128,8 @@ import {
128
128
  exportToJPG,
129
129
  exportToJSON,
130
130
  canvasToBlob,
131
- importFromJSON
131
+ importFromJSON,
132
+ importFromJSONData
132
133
  } from 'labellife-design-tool';
133
134
  import type { CanvasElement } from 'labellife-design-tool';
134
135
 
@@ -143,6 +144,122 @@ function MyEditor() {
143
144
  }
144
145
  ```
145
146
 
147
+ ### Template Import
148
+
149
+ The library provides two ways to import template designs:
150
+
151
+ #### File-Based Import
152
+
153
+ ```tsx
154
+ import { importFromJSON } from 'labellife-design-tool';
155
+
156
+ // Use with file input
157
+ function handleFileImport(event) {
158
+ importFromJSON(
159
+ event,
160
+ (design) => {
161
+ console.log('Design loaded:', design);
162
+ // Use the design
163
+ },
164
+ (error) => {
165
+ alert('Import failed: ' + error);
166
+ }
167
+ );
168
+ }
169
+ ```
170
+
171
+ #### Direct JSON Data Import
172
+
173
+ ```tsx
174
+ import { importFromJSONData } from 'labellife-design-tool';
175
+
176
+ // Import JSON data directly (no file needed)
177
+ const templateData = {
178
+ width: 800,
179
+ height: 600,
180
+ pages: [{
181
+ id: "1",
182
+ name: "Page 1",
183
+ elements: [
184
+ {
185
+ type: "text",
186
+ text: "Hello World",
187
+ x: 100,
188
+ y: 100,
189
+ fontSize: 24
190
+ }
191
+ ],
192
+ background: "white"
193
+ }]
194
+ };
195
+
196
+ importFromJSONData(
197
+ templateData,
198
+ (design) => {
199
+ console.log('Design loaded:', design);
200
+ // Use the design in CanvasEditor
201
+ },
202
+ (error) => {
203
+ console.error('Import failed:', error);
204
+ }
205
+ );
206
+ ```
207
+
208
+ #### Import from API
209
+
210
+ ```tsx
211
+ // Load template from API
212
+ async function loadTemplateFromAPI(templateId: string) {
213
+ try {
214
+ const response = await fetch(`/api/templates/${templateId}`);
215
+ const templateData = await response.json();
216
+
217
+ importFromJSONData(
218
+ templateData,
219
+ (design) => {
220
+ // Template loaded successfully
221
+ setDesign(design);
222
+ },
223
+ (error) => {
224
+ alert('Failed to load template: ' + error);
225
+ }
226
+ );
227
+ } catch (error) {
228
+ console.error('API error:', error);
229
+ }
230
+ }
231
+ ```
232
+
233
+ #### Import with User Inputs
234
+
235
+ ```tsx
236
+ importFromJSONData(
237
+ templateData,
238
+ (design) => {
239
+ // Design loaded with user inputs applied
240
+ setDesign(design);
241
+ },
242
+ (error) => {
243
+ alert('Import failed: ' + error);
244
+ },
245
+ (inputs, onComplete) => {
246
+ // Show custom input modal
247
+ showInputModal(inputs, (values) => {
248
+ onComplete(values);
249
+ });
250
+ }
251
+ );
252
+ ```
253
+
254
+ **Comparison:**
255
+
256
+ | Feature | `importFromJSON` | `importFromJSONData` |
257
+ |---------|------------------|---------------------|
258
+ | **Input Source** | File upload event | JSON data object |
259
+ | **File Reading** | Built-in FileReader | Not needed |
260
+ | **Use Case** | User file uploads | API data, database, programmatic imports |
261
+ | **Processing** | Identical | Identical |
262
+
146
263
  ### Canvas to Blob Export
147
264
 
148
265
  The library provides a flexible `canvasToBlob` function that allows converting the canvas to a Blob for various use cases:
@@ -252,9 +369,68 @@ function App() {
252
369
  }
253
370
  ```
254
371
 
372
+ ## WordPress Integration
373
+
374
+ The library includes a special WordPress-compatible entry point that ensures proper compatibility with WordPress's React environment.
375
+
376
+ ### Using with WordPress
377
+
378
+ When using this library in a WordPress environment, import from the WordPress-specific entry point:
379
+
380
+ ```tsx
381
+ // Import from the WordPress-specific entry point
382
+ import { CanvasEditor } from 'labellife-design-tool/wordpress';
383
+ import 'labellife-design-tool/styles'; // Import CSS
384
+
385
+ // Use as normal
386
+ function MyWordPressComponent() {
387
+ return (
388
+ <CanvasEditor
389
+ name="WordPress Design Editor"
390
+ config={{
391
+ export: { png: true, jpg: true, json: true },
392
+ multiPage: true
393
+ }}
394
+ />
395
+ );
396
+ }
397
+ ```
398
+
399
+ ### WordPress Helper Function
400
+
401
+ For simpler integration with vanilla WordPress plugins, a helper function is provided:
402
+
403
+ ```javascript
404
+ import { initWordPressCanvasEditor } from 'labellife-design-tool/wordpress';
405
+ import 'labellife-design-tool/styles'; // Import CSS
406
+
407
+ // Initialize when DOM is ready
408
+ document.addEventListener('DOMContentLoaded', () => {
409
+ const containerId = 'editor-container'; // ID of your container element
410
+
411
+ initWordPressCanvasEditor(containerId, {
412
+ name: "WordPress Editor",
413
+ config: {
414
+ export: { png: true, jpg: true, json: true },
415
+ multiPage: true,
416
+ variables: true
417
+ }
418
+ });
419
+ });
420
+ ```
421
+
422
+ ### How the WordPress Compatibility Works
423
+
424
+ The WordPress integration automatically handles compatibility with WordPress's React environment by:
425
+
426
+ 1. Detecting when React is available globally (as in WordPress)
427
+ 2. Adding necessary JSX runtime compatibility functions
428
+ 3. Making the library work seamlessly in WordPress's React environment
429
+
255
430
  ## Project Structure
256
431
 
257
432
  - `src/lib/index.ts` - Library entry point (npm package)
433
+ - `src/wordpress.tsx` - WordPress-specific entry point
258
434
  - `src/CanvasEditor.tsx` - Main editor component
259
435
  - `src/types/` - TypeScript type definitions
260
436
  - `src/components/` - React components
@@ -11,6 +11,8 @@
11
11
  --color-red-500: oklch(63.7% 0.237 25.331);
12
12
  --color-red-600: oklch(57.7% 0.245 27.325);
13
13
  --color-red-700: oklch(50.5% 0.213 27.518);
14
+ --color-green-600: oklch(62.7% 0.194 149.214);
15
+ --color-green-700: oklch(52.7% 0.154 150.069);
14
16
  --color-blue-400: oklch(70.7% 0.165 254.624);
15
17
  --color-blue-500: oklch(62.3% 0.214 259.815);
16
18
  --color-blue-600: oklch(54.6% 0.245 262.881);
@@ -215,6 +217,12 @@
215
217
  .inset-0 {
216
218
  inset: calc(var(--spacing) * 0);
217
219
  }
220
+ .-top-1 {
221
+ top: calc(var(--spacing) * -1);
222
+ }
223
+ .-right-1 {
224
+ right: calc(var(--spacing) * -1);
225
+ }
218
226
  .bottom-4 {
219
227
  bottom: calc(var(--spacing) * 4);
220
228
  }
@@ -257,6 +265,9 @@
257
265
  .mt-2 {
258
266
  margin-top: calc(var(--spacing) * 2);
259
267
  }
268
+ .mt-4 {
269
+ margin-top: calc(var(--spacing) * 4);
270
+ }
260
271
  .mt-6 {
261
272
  margin-top: calc(var(--spacing) * 6);
262
273
  }
@@ -320,6 +331,9 @@
320
331
  .h-12 {
321
332
  height: calc(var(--spacing) * 12);
322
333
  }
334
+ .h-64 {
335
+ height: calc(var(--spacing) * 64);
336
+ }
323
337
  .h-full {
324
338
  height: 100%;
325
339
  }
@@ -329,6 +343,9 @@
329
343
  .max-h-32 {
330
344
  max-height: calc(var(--spacing) * 32);
331
345
  }
346
+ .max-h-\[80vh\] {
347
+ max-height: 80vh;
348
+ }
332
349
  .max-h-\[90vh\] {
333
350
  max-height: 90vh;
334
351
  }
@@ -395,6 +412,9 @@
395
412
  .resize {
396
413
  resize: both;
397
414
  }
415
+ .resize-none {
416
+ resize: none;
417
+ }
398
418
  .grid-cols-2 {
399
419
  grid-template-columns: repeat(2, minmax(0, 1fr));
400
420
  }
@@ -419,6 +439,9 @@
419
439
  .justify-center {
420
440
  justify-content: center;
421
441
  }
442
+ .justify-end {
443
+ justify-content: flex-end;
444
+ }
422
445
  .gap-2 {
423
446
  gap: calc(var(--spacing) * 2);
424
447
  }
@@ -482,6 +505,9 @@
482
505
  text-overflow: ellipsis;
483
506
  white-space: nowrap;
484
507
  }
508
+ .overflow-auto {
509
+ overflow: auto;
510
+ }
485
511
  .overflow-hidden {
486
512
  overflow: hidden;
487
513
  }
@@ -570,6 +596,12 @@
570
596
  .bg-gray-900 {
571
597
  background-color: var(--color-gray-900);
572
598
  }
599
+ .bg-green-600 {
600
+ background-color: var(--color-green-600);
601
+ }
602
+ .bg-red-500 {
603
+ background-color: var(--color-red-500);
604
+ }
573
605
  .bg-red-700 {
574
606
  background-color: var(--color-red-700);
575
607
  }
@@ -636,6 +668,9 @@
636
668
  .text-right {
637
669
  text-align: right;
638
670
  }
671
+ .font-mono {
672
+ font-family: var(--font-mono);
673
+ }
639
674
  .text-2xl {
640
675
  font-size: var(--text-2xl);
641
676
  line-height: var(--tw-leading, var(--text-2xl--line-height));
@@ -828,6 +863,13 @@
828
863
  }
829
864
  }
830
865
  }
866
+ .hover\:bg-green-700 {
867
+ &:hover {
868
+ @media (hover: hover) {
869
+ background-color: var(--color-green-700);
870
+ }
871
+ }
872
+ }
831
873
  .hover\:bg-red-500 {
832
874
  &:hover {
833
875
  @media (hover: hover) {