@rageshpikalmunde/rp-image-editor-react 1.5.11 → 1.5.13
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.
|
@@ -11,6 +11,11 @@ const rp_image_editor_1 = require("@rageshpikalmunde/rp-image-editor");
|
|
|
11
11
|
const RpImageEditorComponent = ({ image, config, onImageEdited, onError, className, style, }) => {
|
|
12
12
|
const containerRef = (0, react_1.useRef)(null);
|
|
13
13
|
const editorRef = (0, react_1.useRef)(null);
|
|
14
|
+
// Latest callbacks, so the editor (created once per image) never calls stale ones.
|
|
15
|
+
const onImageEditedRef = (0, react_1.useRef)(onImageEdited);
|
|
16
|
+
const onErrorRef = (0, react_1.useRef)(onError);
|
|
17
|
+
onImageEditedRef.current = onImageEdited;
|
|
18
|
+
onErrorRef.current = onError;
|
|
14
19
|
(0, react_1.useEffect)(() => {
|
|
15
20
|
if (!image || !containerRef.current)
|
|
16
21
|
return;
|
|
@@ -18,10 +23,24 @@ const RpImageEditorComponent = ({ image, config, onImageEdited, onError, classNa
|
|
|
18
23
|
if (editorRef.current) {
|
|
19
24
|
editorRef.current.destroy();
|
|
20
25
|
}
|
|
21
|
-
const
|
|
26
|
+
const userOnApply = config?.onApply;
|
|
27
|
+
const editor = new rp_image_editor_1.RpImageEditor(containerRef.current, {
|
|
28
|
+
...config,
|
|
29
|
+
onApply: onImageEditedRef.current || userOnApply
|
|
30
|
+
? () => {
|
|
31
|
+
userOnApply?.();
|
|
32
|
+
if (!onImageEditedRef.current)
|
|
33
|
+
return;
|
|
34
|
+
editor
|
|
35
|
+
.getResult()
|
|
36
|
+
.then((result) => onImageEditedRef.current?.(result))
|
|
37
|
+
.catch((err) => onErrorRef.current?.(err));
|
|
38
|
+
}
|
|
39
|
+
: undefined,
|
|
40
|
+
});
|
|
22
41
|
editorRef.current = editor;
|
|
23
|
-
editor.on('error', (err) =>
|
|
24
|
-
editor.loadImage(image).catch((err) =>
|
|
42
|
+
editor.on('error', (err) => onErrorRef.current?.(err));
|
|
43
|
+
editor.loadImage(image).catch((err) => onErrorRef.current?.(err));
|
|
25
44
|
return () => {
|
|
26
45
|
editor.destroy();
|
|
27
46
|
editorRef.current = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpImageEditor.js","sourceRoot":"","sources":["../../src/RpImageEditor.tsx"],"names":[],"mappings":";;;;AAAA,iCAA8D;AAC9D,uEAAkG;
|
|
1
|
+
{"version":3,"file":"RpImageEditor.js","sourceRoot":"","sources":["../../src/RpImageEditor.tsx"],"names":[],"mappings":";;;;AAAA,iCAA8D;AAC9D,uEAAkG;AAyBlG;;;GAGG;AACI,MAAM,sBAAsB,GAAiC,CAAC,EACnE,KAAK,EACL,MAAM,EACN,aAAa,EACb,OAAO,EACP,SAAS,EACT,KAAK,GACN,EAAE,EAAE;IACH,MAAM,YAAY,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,IAAA,cAAM,EAAuB,IAAI,CAAC,CAAC;IAErD,mFAAmF;IACnF,MAAM,gBAAgB,GAAG,IAAA,cAAM,EAAC,aAAa,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAA,cAAM,EAAC,OAAO,CAAC,CAAC;IACnC,gBAAgB,CAAC,OAAO,GAAG,aAAa,CAAC;IACzC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC,OAAO;YAAE,OAAO;QAE5C,0BAA0B;QAC1B,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;YACtB,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,EAAE,OAAO,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,+BAAa,CAAC,YAAY,CAAC,OAAO,EAAE;YACrD,GAAG,MAAM;YACT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sBAAsB,0BAiEjC"}
|
|
@@ -8,6 +8,11 @@ import { RpImageEditor } from '@rageshpikalmunde/rp-image-editor';
|
|
|
8
8
|
export const RpImageEditorComponent = ({ image, config, onImageEdited, onError, className, style, }) => {
|
|
9
9
|
const containerRef = useRef(null);
|
|
10
10
|
const editorRef = useRef(null);
|
|
11
|
+
// Latest callbacks, so the editor (created once per image) never calls stale ones.
|
|
12
|
+
const onImageEditedRef = useRef(onImageEdited);
|
|
13
|
+
const onErrorRef = useRef(onError);
|
|
14
|
+
onImageEditedRef.current = onImageEdited;
|
|
15
|
+
onErrorRef.current = onError;
|
|
11
16
|
useEffect(() => {
|
|
12
17
|
if (!image || !containerRef.current)
|
|
13
18
|
return;
|
|
@@ -15,10 +20,24 @@ export const RpImageEditorComponent = ({ image, config, onImageEdited, onError,
|
|
|
15
20
|
if (editorRef.current) {
|
|
16
21
|
editorRef.current.destroy();
|
|
17
22
|
}
|
|
18
|
-
const
|
|
23
|
+
const userOnApply = config?.onApply;
|
|
24
|
+
const editor = new RpImageEditor(containerRef.current, {
|
|
25
|
+
...config,
|
|
26
|
+
onApply: onImageEditedRef.current || userOnApply
|
|
27
|
+
? () => {
|
|
28
|
+
userOnApply?.();
|
|
29
|
+
if (!onImageEditedRef.current)
|
|
30
|
+
return;
|
|
31
|
+
editor
|
|
32
|
+
.getResult()
|
|
33
|
+
.then((result) => onImageEditedRef.current?.(result))
|
|
34
|
+
.catch((err) => onErrorRef.current?.(err));
|
|
35
|
+
}
|
|
36
|
+
: undefined,
|
|
37
|
+
});
|
|
19
38
|
editorRef.current = editor;
|
|
20
|
-
editor.on('error', (err) =>
|
|
21
|
-
editor.loadImage(image).catch((err) =>
|
|
39
|
+
editor.on('error', (err) => onErrorRef.current?.(err));
|
|
40
|
+
editor.loadImage(image).catch((err) => onErrorRef.current?.(err));
|
|
22
41
|
return () => {
|
|
23
42
|
editor.destroy();
|
|
24
43
|
editorRef.current = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpImageEditor.js","sourceRoot":"","sources":["../../src/RpImageEditor.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,MAAM,EAAE,SAAS,EAAe,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAkC,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"RpImageEditor.js","sourceRoot":"","sources":["../../src/RpImageEditor.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,MAAM,EAAE,SAAS,EAAe,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAkC,MAAM,mCAAmC,CAAC;AAyBlG;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAiC,CAAC,EACnE,KAAK,EACL,MAAM,EACN,aAAa,EACb,OAAO,EACP,SAAS,EACT,KAAK,GACN,EAAE,EAAE;IACH,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,MAAM,CAAuB,IAAI,CAAC,CAAC;IAErD,mFAAmF;IACnF,MAAM,gBAAgB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,gBAAgB,CAAC,OAAO,GAAG,aAAa,CAAC;IACzC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC,OAAO;YAAE,OAAO;QAE5C,0BAA0B;QAC1B,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;YACtB,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,EAAE,OAAO,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,YAAY,CAAC,OAAO,EAAE;YACrD,GAAG,MAAM;YACT,OAAO,EAAE,gBAAgB,CAAC,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
|
|
|
5
5
|
image: File | Blob | string | null;
|
|
6
6
|
/** Editor configuration */
|
|
7
7
|
config?: Partial<RpEditorConfig>;
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Called with the edited image when the user clicks Apply. Providing it
|
|
10
|
+
* shows the editor's Apply button (any `config.onApply` still runs too).
|
|
11
|
+
*/
|
|
9
12
|
onImageEdited?: (result: RpEditorResult) => void;
|
|
10
13
|
/** Called when editor encounters an error */
|
|
11
14
|
onError?: (error: Error) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rageshpikalmunde/rp-image-editor-react",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.13",
|
|
4
4
|
"description": "React wrapper for rp-image-editor with crop, annotation, filters, and native-resolution export support",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@rageshpikalmunde/rp-image-editor": "^1.5.
|
|
47
|
+
"@rageshpikalmunde/rp-image-editor": "^1.5.13"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": ">=17.0.0",
|