1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Img = void 0;
|
4 | const jsx_runtime_1 = require("react/jsx-runtime");
|
5 | const react_1 = require("react");
|
6 | const ready_manager_1 = require("./ready-manager");
|
7 | const ImgRefForwarding = ({ onLoad, onError, ...props }, ref) => {
|
8 | const [handle] = (0, react_1.useState)(() => (0, ready_manager_1.delayRender)());
|
9 | (0, react_1.useEffect)(() => {
|
10 | if (ref &&
|
11 | ref.current.complete) {
|
12 | (0, ready_manager_1.continueRender)(handle);
|
13 | }
|
14 | }, [handle, ref]);
|
15 | const didLoad = (0, react_1.useCallback)((e) => {
|
16 | (0, ready_manager_1.continueRender)(handle);
|
17 | onLoad === null || onLoad === void 0 ? void 0 : onLoad(e);
|
18 | }, [handle, onLoad]);
|
19 | const didGetError = (0, react_1.useCallback)((e) => {
|
20 | (0, ready_manager_1.continueRender)(handle);
|
21 | if (onError) {
|
22 | onError(e);
|
23 | }
|
24 | else {
|
25 | console.error('Error loading image:', e, 'Handle the event using the onError() prop to make this message disappear.');
|
26 | }
|
27 | }, [handle, onError]);
|
28 | return (0, jsx_runtime_1.jsx)("img", Object.assign({}, props, { ref: ref, onLoad: didLoad, onError: didGetError }), void 0);
|
29 | };
|
30 | exports.Img = (0, react_1.forwardRef)(ImgRefForwarding);
|
31 |
|
\ | No newline at end of file |