labellife-design-tool 1.1.4 → 1.1.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
@@ -146,7 +146,42 @@ interface CustomPanelDefinition {
146
146
 
147
147
  #### Add Elements from a Custom Panel
148
148
 
149
- **Option 1: Use the `useCanvasStore` hook (recommended)**
149
+ **Option 1: Use standalone store (Polotno-like - recommended)**
150
+
151
+ Create a standalone store that you can use anywhere:
152
+
153
+ ```tsx
154
+ import { createSimpleStore } from 'labellife-design-tool';
155
+
156
+ // Create store instance
157
+ const store = createSimpleStore({
158
+ name: "My Design",
159
+ width: 800,
160
+ height: 600,
161
+ });
162
+
163
+ // Use store anywhere
164
+ store.addPage();
165
+ store.activePage.addElement({
166
+ type: "image",
167
+ src: "https://example.com/img.jpg",
168
+ x: 100,
169
+ y: 100,
170
+ width: 200,
171
+ height: 200,
172
+ });
173
+
174
+ // Load templates
175
+ await store.loadJSON(templateData);
176
+
177
+ // Use with CanvasEditor (optional)
178
+ <CanvasEditor name="Editor" config={{ panels: ["text", "elements"] }} />
179
+
180
+ // Export store for use across your app
181
+ export const store = createSimpleStore();
182
+ ```
183
+
184
+ **Option 2: Use the `useCanvasStore` hook (inside CanvasEditor only)**
150
185
 
151
186
  Any component inside `CanvasEditor` can access the store using the hook:
152
187
 
@@ -167,11 +202,42 @@ const MyComponent = () => {
167
202
  });
168
203
  };
169
204
 
205
+ const handleLoadTemplate = async () => {
206
+ try {
207
+ const templateData = {
208
+ name: "My Template",
209
+ width: 800,
210
+ height: 600,
211
+ pages: [
212
+ {
213
+ id: "page-1",
214
+ name: "Page 1",
215
+ elements: [
216
+ {
217
+ type: "text",
218
+ text: "Hello World",
219
+ x: 100,
220
+ y: 100,
221
+ fontSize: 24,
222
+ },
223
+ ],
224
+ },
225
+ ],
226
+ };
227
+
228
+ await store.loadJSON(templateData);
229
+ console.log("Template loaded successfully!");
230
+ } catch (error) {
231
+ console.error("Failed to load template:", error);
232
+ }
233
+ };
234
+
170
235
  return (
171
236
  <div style={{ color: "white", padding: 16 }}>
172
237
  <p>Current page: {store.activePage.id}</p>
173
238
  <p>Canvas size: {store.width} × {store.height}</p>
174
239
  <button onClick={handleAddImage}>Add Image</button>
240
+ <button onClick={handleLoadTemplate}>Load Template</button>
175
241
  </div>
176
242
  );
177
243
  };
@@ -220,25 +286,39 @@ const MyImagesPanel = ({ store }) => {
220
286
  />
221
287
  ```
222
288
 
223
- **CanvasStore interface**
289
+ **SimpleStore interface (Standalone)**
224
290
 
225
291
  ```typescript
226
- interface CanvasStore {
227
- activePage: {
228
- id: string;
229
- addElement: (element: {
230
- type: string;
231
- src?: string;
232
- x: number;
233
- y: number;
234
- width: number;
235
- height: number;
236
- }) => void;
237
- };
292
+ interface SimpleStore {
293
+ // Design properties
294
+ design: CanvasDesign;
238
295
  width: number;
239
296
  height: number;
240
- openSidePanel: (panelId: string | null) => void;
241
- deletePages: (pageIds: string[]) => void;
297
+
298
+ // Page operations
299
+ activePage: Page | null;
300
+ activePageId: string;
301
+ addPage(page?: Partial<Page>): string;
302
+ deletePages(pageIds: string[]): void;
303
+ setActivePage(pageId: string): void;
304
+
305
+ // Element operations
306
+ addElement(element: Partial<CanvasElement>): void;
307
+ updateElement(elementId: string, updates: Partial<CanvasElement>): void;
308
+ deleteElement(elementId: string): void;
309
+
310
+ // Panel operations
311
+ openSidePanel(panelId: string | null): void;
312
+ activePanelId: string | null;
313
+
314
+ // Design operations
315
+ setDesign(design: CanvasDesign): void;
316
+ updateDesign(updates: Partial<CanvasDesign>): void;
317
+ loadJSON(jsonData: any): Promise<void>;
318
+
319
+ // Events
320
+ on(event: 'designChanged' | 'activePageChanged' | 'activePanelChanged', callback: Function): void;
321
+ off(event: string): void;
242
322
  }
243
323
  ```
244
324
 
@@ -217,12 +217,6 @@
217
217
  .inset-0 {
218
218
  inset: calc(var(--spacing) * 0);
219
219
  }
220
- .-top-1 {
221
- top: calc(var(--spacing) * -1);
222
- }
223
- .-right-1 {
224
- right: calc(var(--spacing) * -1);
225
- }
226
220
  .bottom-4 {
227
221
  bottom: calc(var(--spacing) * 4);
228
222
  }
@@ -265,9 +259,6 @@
265
259
  .mt-2 {
266
260
  margin-top: calc(var(--spacing) * 2);
267
261
  }
268
- .mt-4 {
269
- margin-top: calc(var(--spacing) * 4);
270
- }
271
262
  .mt-6 {
272
263
  margin-top: calc(var(--spacing) * 6);
273
264
  }
@@ -331,9 +322,6 @@
331
322
  .h-12 {
332
323
  height: calc(var(--spacing) * 12);
333
324
  }
334
- .h-64 {
335
- height: calc(var(--spacing) * 64);
336
- }
337
325
  .h-full {
338
326
  height: 100%;
339
327
  }
@@ -343,9 +331,6 @@
343
331
  .max-h-32 {
344
332
  max-height: calc(var(--spacing) * 32);
345
333
  }
346
- .max-h-\[80vh\] {
347
- max-height: 80vh;
348
- }
349
334
  .max-h-\[90vh\] {
350
335
  max-height: 90vh;
351
336
  }
@@ -412,9 +397,6 @@
412
397
  .resize {
413
398
  resize: both;
414
399
  }
415
- .resize-none {
416
- resize: none;
417
- }
418
400
  .grid-cols-2 {
419
401
  grid-template-columns: repeat(2, minmax(0, 1fr));
420
402
  }
@@ -439,9 +421,6 @@
439
421
  .justify-center {
440
422
  justify-content: center;
441
423
  }
442
- .justify-end {
443
- justify-content: flex-end;
444
- }
445
424
  .gap-2 {
446
425
  gap: calc(var(--spacing) * 2);
447
426
  }
@@ -505,9 +484,6 @@
505
484
  text-overflow: ellipsis;
506
485
  white-space: nowrap;
507
486
  }
508
- .overflow-auto {
509
- overflow: auto;
510
- }
511
487
  .overflow-hidden {
512
488
  overflow: hidden;
513
489
  }
@@ -599,9 +575,6 @@
599
575
  .bg-green-600 {
600
576
  background-color: var(--color-green-600);
601
577
  }
602
- .bg-red-500 {
603
- background-color: var(--color-red-500);
604
- }
605
578
  .bg-red-700 {
606
579
  background-color: var(--color-red-700);
607
580
  }
@@ -668,9 +641,6 @@
668
641
  .text-right {
669
642
  text-align: right;
670
643
  }
671
- .font-mono {
672
- font-family: var(--font-mono);
673
- }
674
644
  .text-2xl {
675
645
  font-size: var(--text-2xl);
676
646
  line-height: var(--tw-leading, var(--text-2xl--line-height));