labellife-design-tool 0.8.0 → 0.9.0

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
@@ -66,6 +66,57 @@ setUnsplashAccessKey('your-unsplash-access-key');
66
66
  // UNSPLASH_ACCESS_KEY=your-key npm start
67
67
  ```
68
68
 
69
+ ### Using Refs with CanvasEditor
70
+
71
+ The `CanvasEditor` component supports React refs, allowing you to access internal methods and properties:
72
+
73
+ ```tsx
74
+ import { useRef } from 'react';
75
+ import { CanvasEditor, CanvasEditorRef } from 'labellife-design-tool';
76
+
77
+ function MyEditor() {
78
+ const editorRef = useRef<CanvasEditorRef>(null);
79
+
80
+ const handleExport = () => {
81
+ // Access methods via the ref
82
+ if (editorRef.current) {
83
+ // Export to PNG
84
+ editorRef.current.exportToPNG();
85
+
86
+ // Or get the current design
87
+ const currentDesign = editorRef.current.getDesign();
88
+ console.log('Current design:', currentDesign);
89
+
90
+ // Access the Konva Stage directly
91
+ const stage = editorRef.current.stage;
92
+ // Do something with the stage...
93
+ }
94
+ };
95
+
96
+ return (
97
+ <div>
98
+ <CanvasEditor
99
+ ref={editorRef}
100
+ name="Editor with Ref"
101
+ config={{
102
+ export: { png: true, jpg: true, json: true },
103
+ multiPage: true
104
+ }}
105
+ />
106
+ <button onClick={handleExport}>Export</button>
107
+ </div>
108
+ );
109
+ }
110
+ ```
111
+
112
+ The `CanvasEditorRef` interface provides the following properties and methods:
113
+
114
+ - `stage`: Direct access to the Konva.Stage instance
115
+ - `exportToPNG()`: Export the canvas to a PNG file
116
+ - `exportToJPG()`: Export the canvas to a JPG file
117
+ - `exportToJSON()`: Export the design to a JSON file
118
+ - `getDesign()`: Get the current design object
119
+
69
120
  ### Advanced Usage with Types
70
121
 
71
122
  ```tsx
@@ -1,8 +1,17 @@
1
1
  import React from "react";
2
+ import Konva from "konva";
3
+ import { CanvasDesign } from "./types";
2
4
  import { Config } from "./types/Config";
3
- declare const CanvasEditor: React.FC<{
5
+ export interface CanvasEditorRef {
6
+ stage: Konva.Stage | null;
7
+ exportToPNG: () => void;
8
+ exportToJPG: () => void;
9
+ exportToJSON: () => void;
10
+ getDesign: () => CanvasDesign;
11
+ }
12
+ declare const CanvasEditor: React.ForwardRefExoticComponent<{
4
13
  name: string;
5
14
  config?: Config;
6
- }>;
15
+ } & React.RefAttributes<CanvasEditorRef>>;
7
16
  export default CanvasEditor;
8
17
  //# sourceMappingURL=CanvasEditor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CanvasEditor.d.ts","sourceRoot":"","sources":["../../src/CanvasEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAmFxE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,QAAA,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CA88B7D,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"CanvasEditor.d.ts","sourceRoot":"","sources":["../../src/CanvasEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoF,MAAM,OAAO,CAAC;AAGzG,OAAO,KAAK,MAAM,OAAO,CAAC;AAyC1B,OAAO,EAEL,YAAY,EAKb,MAAM,SAAS,CAAC;AAgCjB,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,YAAY,CAAC;CAC/B;AAED,QAAA,MAAM,YAAY;UAAuC,MAAM;aAAW,MAAM;yCA29B9E,CAAC;AAEH,eAAe,YAAY,CAAC"}
package/dist/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/CanvasEditor.tsx
2
- import { useState as useState3, useRef as useRef5, useEffect as useEffect4, useCallback as useCallback2 } from "react";
2
+ import { useState as useState3, useRef as useRef5, useEffect as useEffect4, useCallback as useCallback2, forwardRef, useImperativeHandle } from "react";
3
3
  import { Stage, Layer, Rect as Rect2 } from "react-konva";
4
4
  import {
5
5
  PlusCircle
@@ -3596,10 +3596,10 @@ var TemplateInputModal_default = TemplateInputModal;
3596
3596
 
3597
3597
  // src/CanvasEditor.tsx
3598
3598
  import { jsxDEV as jsxDEV18 } from "react/jsx-dev-runtime";
3599
- var CanvasEditor = ({
3599
+ var CanvasEditor = forwardRef(({
3600
3600
  name,
3601
3601
  config
3602
- }) => {
3602
+ }, ref) => {
3603
3603
  const [design, setDesign] = useState3({
3604
3604
  id: Date.now().toString(),
3605
3605
  name: "Untitled Design",
@@ -3632,6 +3632,19 @@ var CanvasEditor = ({
3632
3632
  const [showInputModal, setShowInputModal] = useState3(false);
3633
3633
  const [pendingInputs, setPendingInputs] = useState3([]);
3634
3634
  const stageRef = useRef5(null);
3635
+ useImperativeHandle(ref, () => ({
3636
+ stage: stageRef.current,
3637
+ exportToPNG: () => {
3638
+ if (stageRef.current)
3639
+ exportToPNG(stageRef.current, design);
3640
+ },
3641
+ exportToJPG: () => {
3642
+ if (stageRef.current)
3643
+ exportToJPG(stageRef.current, design);
3644
+ },
3645
+ exportToJSON: () => exportToJSON(design),
3646
+ getDesign: () => design
3647
+ }), [design]);
3635
3648
  const fileInputRef = useRef5(null);
3636
3649
  const jsonInputRef = useRef5(null);
3637
3650
  const containerRef = useRef5(null);
@@ -4393,7 +4406,7 @@ var CanvasEditor = ({
4393
4406
  }, undefined, false, undefined, this)
4394
4407
  ]
4395
4408
  }, undefined, true, undefined, this);
4396
- };
4409
+ });
4397
4410
  var CanvasEditor_default = CanvasEditor;
4398
4411
  export {
4399
4412
  setUnsplashAccessKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labellife-design-tool",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Professional canvas editor built with React, TypeScript, and Konva",
5
5
  "main": "./dist/lib/index.js",
6
6
  "module": "./dist/lib/index.js",