@fountain-ui/core 2.0.0-beta.39 → 2.0.0-beta.40
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/build/commonjs/Image/Image.js +40 -34
- package/build/commonjs/Image/Image.js.map +1 -1
- package/build/commonjs/Image/ImageProps.js.map +1 -1
- package/build/commonjs/Image/index.js.map +1 -1
- package/build/commonjs/ImageCore/ImageCoreProps.js.map +1 -1
- package/build/commonjs/ImageCore/ImageCoreWeb.js +6 -5
- package/build/commonjs/ImageCore/ImageCoreWeb.js.map +1 -1
- package/build/commonjs/ImageCore/ImageFileExtensionContext.js +3 -7
- package/build/commonjs/ImageCore/ImageFileExtensionContext.js.map +1 -1
- package/build/commonjs/ImageCore/ImageFileExtensionProvider.js +2 -2
- package/build/commonjs/ImageCore/ImageFileExtensionProvider.js.map +1 -1
- package/build/commonjs/ImageCore/index.js +0 -14
- package/build/commonjs/ImageCore/index.js.map +1 -1
- package/build/commonjs/hooks/index.js +8 -0
- package/build/commonjs/hooks/index.js.map +1 -1
- package/build/commonjs/hooks/useDebounce.js +33 -0
- package/build/commonjs/hooks/useDebounce.js.map +1 -0
- package/build/module/Image/Image.js +42 -34
- package/build/module/Image/Image.js.map +1 -1
- package/build/module/Image/ImageProps.js.map +1 -1
- package/build/module/Image/index.js.map +1 -1
- package/build/module/ImageCore/ImageCoreProps.js.map +1 -1
- package/build/module/ImageCore/ImageCoreWeb.js +5 -5
- package/build/module/ImageCore/ImageCoreWeb.js.map +1 -1
- package/build/module/ImageCore/ImageFileExtensionContext.js +3 -3
- package/build/module/ImageCore/ImageFileExtensionContext.js.map +1 -1
- package/build/module/ImageCore/ImageFileExtensionProvider.js +2 -2
- package/build/module/ImageCore/ImageFileExtensionProvider.js.map +1 -1
- package/build/module/ImageCore/index.js +0 -1
- package/build/module/ImageCore/index.js.map +1 -1
- package/build/module/hooks/index.js +1 -0
- package/build/module/hooks/index.js.map +1 -1
- package/build/module/hooks/useDebounce.js +25 -0
- package/build/module/hooks/useDebounce.js.map +1 -0
- package/build/typescript/Image/ImageProps.d.ts +9 -14
- package/build/typescript/Image/index.d.ts +0 -1
- package/build/typescript/ImageCore/ImageCoreProps.d.ts +1 -1
- package/build/typescript/ImageCore/ImageFileExtensionContext.d.ts +2 -2
- package/build/typescript/ImageCore/index.d.ts +1 -1
- package/build/typescript/hooks/index.d.ts +1 -0
- package/build/typescript/hooks/useDebounce.d.ts +1 -0
- package/package.json +2 -2
- package/src/Image/Image.tsx +75 -52
- package/src/Image/ImageProps.ts +12 -17
- package/src/Image/index.ts +1 -2
- package/src/ImageCore/ImageCoreProps.ts +1 -1
- package/src/ImageCore/ImageCoreWeb.tsx +8 -10
- package/src/ImageCore/ImageFileExtensionContext.ts +4 -4
- package/src/ImageCore/ImageFileExtensionProvider.tsx +10 -9
- package/src/ImageCore/index.ts +2 -2
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useDebounce.ts +23 -0
|
@@ -36,10 +36,22 @@ const useStyles = function () {
|
|
|
36
36
|
borderWidth: _styles.StyleSheet.hairlineWidth,
|
|
37
37
|
borderStyle: 'solid',
|
|
38
38
|
borderColor: theme.palette.paper.grey
|
|
39
|
+
},
|
|
40
|
+
error: {
|
|
41
|
+
width: '100%',
|
|
42
|
+
height: '100%'
|
|
39
43
|
}
|
|
40
44
|
};
|
|
41
45
|
};
|
|
42
46
|
|
|
47
|
+
function determinePlaceholderMode(props) {
|
|
48
|
+
if (props.disablePlaceholder) {
|
|
49
|
+
return 'none';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return props.placeholder ? 'custom' : 'default';
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
function Image(props) {
|
|
44
56
|
const {
|
|
45
57
|
alt,
|
|
@@ -47,69 +59,63 @@ function Image(props) {
|
|
|
47
59
|
disableLongClick,
|
|
48
60
|
disableOutline,
|
|
49
61
|
disablePlaceholder,
|
|
50
|
-
|
|
62
|
+
error,
|
|
51
63
|
loading = 'lazy',
|
|
64
|
+
onError: onErrorProp,
|
|
65
|
+
onLoad: onLoadProp,
|
|
52
66
|
overlaidChildren,
|
|
67
|
+
placeholder,
|
|
53
68
|
resizeMode = 'cover',
|
|
54
69
|
source,
|
|
55
70
|
style,
|
|
56
71
|
square = false,
|
|
57
72
|
size,
|
|
58
|
-
onLoad,
|
|
59
|
-
onError,
|
|
60
|
-
Placeholder: PlaceholderComponent,
|
|
61
73
|
...otherProps
|
|
62
74
|
} = props;
|
|
63
|
-
|
|
64
|
-
const [failed, setFailed] = _react.default.useState(false);
|
|
65
|
-
|
|
75
|
+
const [failed, setFailed] = (0, _react.useState)(false);
|
|
66
76
|
const styles = useStyles();
|
|
67
77
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
setFailed(true);
|
|
78
|
+
const onLoad = () => {
|
|
79
|
+
setFailed(false);
|
|
80
|
+
onLoadProp === null || onLoadProp === void 0 ? void 0 : onLoadProp();
|
|
74
81
|
};
|
|
75
82
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
children
|
|
80
|
-
} = _ref;
|
|
81
|
-
return PlaceholderComponent ? /*#__PURE__*/_react.default.createElement(PlaceholderComponent, {
|
|
82
|
-
children: children,
|
|
83
|
-
failed: failed
|
|
84
|
-
}) : children;
|
|
83
|
+
const onError = () => {
|
|
84
|
+
setFailed(true);
|
|
85
|
+
onErrorProp === null || onErrorProp === void 0 ? void 0 : onErrorProp();
|
|
85
86
|
};
|
|
86
87
|
|
|
87
88
|
const sourceWithSizeParam = { ...source,
|
|
88
89
|
uri: size ? `${source.uri}?size=${size}` : source.uri
|
|
89
90
|
};
|
|
91
|
+
const placeholderMode = determinePlaceholderMode(props);
|
|
90
92
|
(0, _react.useEffect)(() => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
}, [...failDependency]);
|
|
93
|
+
setFailed(false);
|
|
94
|
+
}, [sourceWithSizeParam.uri]);
|
|
95
95
|
return /*#__PURE__*/_react.default.createElement(_reactNative.View, _extends({
|
|
96
|
-
style: (0, _styles.css)([styles.root, !disableOutline ? styles.outlined : undefined, !
|
|
97
|
-
}, otherProps), /*#__PURE__*/_react.default.createElement(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
style: (0, _styles.css)([styles.root, !disableOutline ? styles.outlined : undefined, !square ? styles.rounded : undefined, placeholderMode === 'default' ? styles.placeholder : undefined, style])
|
|
97
|
+
}, otherProps), placeholderMode === 'custom' ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
98
|
+
style: (0, _styles.css)([_styles.StyleSheet.absoluteFill, {
|
|
99
|
+
zIndex: -1
|
|
100
|
+
}])
|
|
101
|
+
}, placeholder) : null, failed ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
102
|
+
style: styles.error
|
|
103
|
+
}, error ?? /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
104
|
+
children: alt
|
|
105
|
+
})) : sourceWithSizeParam.uri ? /*#__PURE__*/_react.default.createElement(_ImageCore.default, {
|
|
106
|
+
alt: sourceWithSizeParam.uri,
|
|
101
107
|
disableDrag: disableDrag,
|
|
102
108
|
disableLongClick: disableLongClick,
|
|
103
109
|
height: '100%',
|
|
104
110
|
loading: loading,
|
|
105
|
-
onError:
|
|
111
|
+
onError: onError,
|
|
106
112
|
onLoad: onLoad,
|
|
107
113
|
resizeMode: resizeMode,
|
|
108
114
|
source: sourceWithSizeParam,
|
|
109
115
|
width: '100%'
|
|
110
|
-
}), overlaidChildren ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
116
|
+
}) : null, overlaidChildren ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
111
117
|
style: _styles.StyleSheet.absoluteFill
|
|
112
|
-
}, overlaidChildren) : null)
|
|
118
|
+
}, overlaidChildren) : null);
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useStyles","theme","useTheme","root","rounded","borderRadius","shape","roundness","overflow","placeholder","backgroundColor","palette","paper","grey","outlined","borderWidth","StyleSheet","hairlineWidth","borderStyle","borderColor","
|
|
1
|
+
{"version":3,"names":["useStyles","theme","useTheme","root","rounded","borderRadius","shape","roundness","overflow","placeholder","backgroundColor","palette","paper","grey","outlined","borderWidth","StyleSheet","hairlineWidth","borderStyle","borderColor","error","width","height","determinePlaceholderMode","props","disablePlaceholder","Image","alt","disableDrag","disableLongClick","disableOutline","loading","onError","onErrorProp","onLoad","onLoadProp","overlaidChildren","resizeMode","source","style","square","size","otherProps","failed","setFailed","useState","styles","sourceWithSizeParam","uri","placeholderMode","useEffect","css","undefined","absoluteFill","zIndex"],"sources":["Image.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport { Text, View } from 'react-native';\nimport type { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport type { ImageCoreProps } from '../ImageCore';\nimport ImageCore from '../ImageCore';\nimport { css, StyleSheet, useTheme } from '../styles';\nimport type ImageProps from './ImageProps';\n\ntype PlaceholderMode =\n | 'default'\n | 'custom'\n | 'none';\n\ntype ImageStyleKeys =\n | 'root'\n | 'rounded'\n | 'placeholder'\n | 'outlined'\n | 'error';\n\ntype ImageStyles = NamedStylesStringUnion<ImageStyleKeys>;\n\nconst useStyles: UseStyles<ImageStyles> = function (): ImageStyles {\n const theme = useTheme();\n\n return {\n root: {},\n rounded: {\n borderRadius: theme.shape.roundness,\n overflow: 'hidden',\n },\n placeholder: {\n backgroundColor: theme.palette.paper.grey,\n },\n outlined: {\n borderWidth: StyleSheet.hairlineWidth,\n borderStyle: 'solid',\n borderColor: theme.palette.paper.grey,\n },\n error: {\n width: '100%',\n height: '100%',\n },\n };\n};\n\nfunction determinePlaceholderMode(props: ImageProps): PlaceholderMode {\n if (props.disablePlaceholder) {\n return 'none';\n }\n\n return props.placeholder ? 'custom' : 'default';\n}\n\nexport default function Image(props: ImageProps) {\n const {\n alt,\n disableDrag,\n disableLongClick,\n disableOutline,\n disablePlaceholder,\n error,\n loading = 'lazy',\n onError: onErrorProp,\n onLoad: onLoadProp,\n overlaidChildren,\n placeholder,\n resizeMode = 'cover',\n source,\n style,\n square = false,\n size,\n ...otherProps\n } = props;\n\n const [failed, setFailed] = useState(false);\n\n const styles = useStyles();\n\n const onLoad: ImageCoreProps['onLoad'] = () => {\n setFailed(false);\n\n onLoadProp?.();\n };\n\n const onError: ImageCoreProps['onError'] = () => {\n setFailed(true);\n\n onErrorProp?.();\n };\n\n const sourceWithSizeParam = {\n ...source,\n uri: size ? `${source.uri}?size=${size}` : source.uri,\n };\n\n const placeholderMode = determinePlaceholderMode(props);\n\n useEffect(() => {\n setFailed(false);\n }, [sourceWithSizeParam.uri]);\n\n return (\n <View\n style={css([\n styles.root,\n !disableOutline ? styles.outlined : undefined,\n !square ? styles.rounded : undefined,\n placeholderMode === 'default' ? styles.placeholder : undefined,\n style,\n ])}\n {...otherProps}\n >\n {placeholderMode === 'custom' ? (\n <View\n style={css([\n StyleSheet.absoluteFill,\n { zIndex: -1 },\n ])}\n >\n {placeholder}\n </View>\n ) : null}\n\n {failed ? (\n <View style={styles.error}>\n {error ?? <Text children={alt}/>}\n </View>\n ) : sourceWithSizeParam.uri ? (\n <ImageCore\n alt={sourceWithSizeParam.uri}\n disableDrag={disableDrag}\n disableLongClick={disableLongClick}\n height={'100%'}\n loading={loading}\n onError={onError}\n onLoad={onLoad}\n resizeMode={resizeMode}\n source={sourceWithSizeParam}\n width={'100%'}\n />\n ) : null}\n\n {overlaidChildren ? (\n <View style={StyleSheet.absoluteFill}>\n {overlaidChildren}\n </View>\n ) : null}\n </View>\n );\n};"],"mappings":";;;;;;;AAAA;;AACA;;AAGA;;AACA;;;;;;;;;;AAiBA,MAAMA,SAAiC,GAAG,YAAyB;EAC/D,MAAMC,KAAK,GAAG,IAAAC,gBAAA,GAAd;EAEA,O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CAACC,GAD7B;IAEI,WAAW,EAAEpB,WAFjB;IAGI,gBAAgB,EAAEC,gBAHtB;IAII,MAAM,EAAE,MAJZ;IAKI,OAAO,EAAEE,OALb;IAMI,OAAO,EAAEC,OANb;IAOI,MAAM,EAAEE,MAPZ;IAQI,UAAU,EAAEG,UARhB;IASI,MAAM,EAAEU,mBATZ;IAUI,KAAK,EAAE;EAVX,EADA,GAaA,IAtCR,EAwCKX,gBAAgB,gBACb,6BAAC,iBAAD;IAAM,KAAK,EAAEpB,kBAAA,CAAWqC;EAAxB,GACKjB,gBADL,CADa,GAIb,IA5CR,CADJ;AAgDH;;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ImageProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { OverridableComponentProps } from '../types';\nimport type { ImageSource, Loading, ResizeMode } from '../ImageCore';\n\
|
|
1
|
+
{"version":3,"names":[],"sources":["ImageProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { OverridableComponentProps } from '../types';\nimport type { ImageSource, Loading, ResizeMode } from '../ImageCore';\n\n\nexport default interface ImageProps extends OverridableComponentProps<ViewProps, {\n /**\n * Indicating the alternate fallback content to be displayed\n * if the image has not been loaded.\n */\n alt?: string;\n\n /**\n * Disable drag event for web.\n * @default false\n */\n disableDrag?: boolean,\n\n /**\n * Disable Long click event for web.\n * @default false\n */\n disableLongClick?: boolean,\n\n /**\n * If `true`, the image outline is not rendered.\n * @default false\n */\n disableOutline?: boolean;\n\n /**\n * If `true`, the placeholder is not rendered.\n * @default false\n */\n disablePlaceholder?: boolean;\n\n /**\n * Custom error element. Default is simple alt text.\n */\n error?: React.ReactElement | null;\n\n /**\n * Web only. Loading the document by determining whether to load\n * the image immediately (`eager`) or on an as-needed basis (`lazy`).\n * On React Native, it always works as `lazy`.\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * error event handler\n */\n onError?: () => void;\n\n /**\n * image loaded event handler\n */\n onLoad?: () => void;\n\n /**\n * The children on top this image.\n */\n overlaidChildren?: React.ReactElement;\n\n /**\n * Custom placeholder element.\n */\n placeholder?: React.ReactElement;\n\n /**\n * Determines how to resize the image when the frame doesn't match the raw image dimensions.\n * @default 'cover'\n */\n resizeMode?: ResizeMode;\n\n /**\n * The image source.\n */\n source: ImageSource;\n\n /**\n * If `true`, rounded corners are disabled.\n * @default false\n */\n square?: boolean;\n\n /**\n * Image file size.\n * Request image by query string.\n */\n size?: 'small' | 'medium' | 'large';\n}> {}\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './Image';\nexport type { default as ImageProps } from './ImageProps'
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './Image';\nexport type { default as ImageProps } from './ImageProps';"],"mappings":";;;;;;;;;;;;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ImageCoreProps.ts"],"sourcesContent":["export interface ImageSource {\n uri
|
|
1
|
+
{"version":3,"names":[],"sources":["ImageCoreProps.ts"],"sourcesContent":["export interface ImageSource {\n uri?: string;\n}\n\nexport type ResizeMode = 'cover' | 'contain';\n\nexport type Loading = 'lazy' | 'eager';\n\nexport default interface ImageCoreProps extends Readonly<{\n alt?: string;\n disableDrag?: boolean,\n disableLongClick?: boolean,\n height?: number | string;\n loading: Loading;\n onError?: () => void;\n onLoad?: () => void;\n resizeMode: ResizeMode;\n source: ImageSource;\n width?: number | string;\n}> {}"],"mappings":""}
|
|
@@ -9,6 +9,11 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
+
const longClickDisabledStyle = {
|
|
13
|
+
'-webkit-user-select': 'none',
|
|
14
|
+
'-webkit-touch-callout': 'none'
|
|
15
|
+
};
|
|
16
|
+
|
|
12
17
|
const preventDragging = () => false;
|
|
13
18
|
|
|
14
19
|
const preventMouseDown = event => {
|
|
@@ -30,13 +35,9 @@ function ImageCore(props) {
|
|
|
30
35
|
source,
|
|
31
36
|
width
|
|
32
37
|
} = props;
|
|
33
|
-
const disableLongClickStyle = disableLongClick ? {
|
|
34
|
-
'-webkit-user-select': 'none',
|
|
35
|
-
'-webkit-touch-callout': 'none'
|
|
36
|
-
} : {};
|
|
37
38
|
const style = {
|
|
38
39
|
objectFit: resizeMode,
|
|
39
|
-
...
|
|
40
|
+
...(disableLongClick ? longClickDisabledStyle : {})
|
|
40
41
|
};
|
|
41
42
|
return /*#__PURE__*/_react.default.createElement("img", {
|
|
42
43
|
alt: alt,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["preventDragging","preventMouseDown","event","preventDefault","ImageCore","props","alt","disableDrag","disableLongClick","height","loading","onError","onLoad","resizeMode","source","width","
|
|
1
|
+
{"version":3,"names":["longClickDisabledStyle","preventDragging","preventMouseDown","event","preventDefault","ImageCore","props","alt","disableDrag","disableLongClick","height","loading","onError","onLoad","resizeMode","source","width","style","objectFit","undefined","uri"],"sources":["ImageCoreWeb.tsx"],"sourcesContent":["import React, { DragEventHandler, MouseEventHandler } from 'react';\nimport type ImageCoreProps from './ImageCoreProps';\n\nconst longClickDisabledStyle = {\n '-webkit-user-select': 'none',\n '-webkit-touch-callout': 'none',\n};\n\nconst preventDragging: DragEventHandler<HTMLImageElement> = () => false;\n\nconst preventMouseDown: MouseEventHandler<HTMLImageElement> = (event) => {\n if (event.preventDefault) {\n event.preventDefault();\n }\n};\n\nexport default function ImageCore(props: ImageCoreProps) {\n const {\n alt,\n disableDrag = false,\n disableLongClick = false,\n height,\n loading,\n onError,\n onLoad,\n resizeMode,\n source,\n width,\n } = props;\n\n const style = {\n objectFit: resizeMode,\n ...(disableLongClick ? longClickDisabledStyle : {}),\n };\n\n return (\n <img\n alt={alt}\n height={height}\n loading={loading}\n onDragStart={disableDrag ? preventDragging : undefined}\n onMouseDown={disableDrag ? preventMouseDown : undefined}\n onError={onError}\n onLoad={onLoad}\n src={source.uri}\n style={style}\n width={width}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;;;AAGA,MAAMA,sBAAsB,GAAG;EAC3B,uBAAuB,MADI;EAE3B,yBAAyB;AAFE,CAA/B;;AAKA,MAAMC,eAAmD,GAAG,MAAM,KAAlE;;AAEA,MAAMC,gBAAqD,GAAIC,KAAD,IAAW;EACrE,IAAIA,KAAK,CAACC,cAAV,EAA0B;IACtBD,KAAK,CAACC,cAAN;EACH;AACJ,CAJD;;AAMe,SAASC,SAAT,CAAmBC,KAAnB,EAA0C;EACrD,MAAM;IACFC,GADE;IAEFC,WAAW,GAAG,KAFZ;IAGFC,gBAAgB,GAAG,KAHjB;IAIFC,MAJE;IAKFC,OALE;IAMFC,OANE;IAOFC,MAPE;IAQFC,UARE;IASFC,MATE;IAUFC;EAVE,IAWFV,KAXJ;EAaA,MAAMW,KAAK,GAAG;IACVC,SAAS,EAAEJ,UADD;IAEV,IAAIL,gBAAgB,GAAGT,sBAAH,GAA4B,EAAhD;EAFU,CAAd;EAKA,oBACI;IACI,GAAG,EAAEO,GADT;IAEI,MAAM,EAAEG,MAFZ;IAGI,OAAO,EAAEC,OAHb;IAII,WAAW,EAAEH,WAAW,GAAGP,eAAH,GAAqBkB,SAJjD;IAKI,WAAW,EAAEX,WAAW,GAAGN,gBAAH,GAAsBiB,SALlD;IAMI,OAAO,EAAEP,OANb;IAOI,MAAM,EAAEC,MAPZ;IAQI,GAAG,EAAEE,MAAM,CAACK,GARhB;IASI,KAAK,EAAEH,KATX;IAUI,KAAK,EAAED;EAVX,EADJ;AAcH;;AAAA"}
|
|
@@ -5,14 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
const defaultAcceptHeader = 'image/jpg,image/png,image/*,*/*;';
|
|
13
|
-
|
|
14
|
-
const ImageFileExtensionContext = /*#__PURE__*/_react.default.createContext(defaultAcceptHeader);
|
|
8
|
+
var _react = require("react");
|
|
15
9
|
|
|
10
|
+
const DEFAULT_ACCEPT_HEADER = 'image/jpg,image/png,image/*,*/*;';
|
|
11
|
+
const ImageFileExtensionContext = /*#__PURE__*/(0, _react.createContext)(DEFAULT_ACCEPT_HEADER);
|
|
16
12
|
var _default = ImageFileExtensionContext;
|
|
17
13
|
exports.default = _default;
|
|
18
14
|
//# sourceMappingURL=ImageFileExtensionContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["DEFAULT_ACCEPT_HEADER","ImageFileExtensionContext","createContext"],"sources":["ImageFileExtensionContext.ts"],"sourcesContent":["import { createContext } from 'react';\n\nconst DEFAULT_ACCEPT_HEADER = 'image/jpg,image/png,image/*,*/*;';\n\nconst ImageFileExtensionContext = createContext<string>(DEFAULT_ACCEPT_HEADER);\n\nexport default ImageFileExtensionContext;\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAMA,qBAAqB,GAAG,kCAA9B;AAEA,MAAMC,yBAAyB,gBAAG,IAAAC,oBAAA,EAAsBF,qBAAtB,CAAlC;eAEeC,yB"}
|
|
@@ -33,8 +33,8 @@ function ImageFileExtensionProvider(props) {
|
|
|
33
33
|
children,
|
|
34
34
|
extensions
|
|
35
35
|
} = props;
|
|
36
|
-
const
|
|
37
|
-
const acceptHeader = `${
|
|
36
|
+
const supportedMediaTypes = [...R.map(extension => `image/${extension}`, extensions), 'image/*', '*/*'];
|
|
37
|
+
const acceptHeader = `${R.join(',', supportedMediaTypes)};`;
|
|
38
38
|
return /*#__PURE__*/_react.default.createElement(_ImageFileExtensionContext.default.Provider, {
|
|
39
39
|
value: acceptHeader
|
|
40
40
|
}, children);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ImageFileExtension","ImageFileExtensionProvider","props","children","extensions","
|
|
1
|
+
{"version":3,"names":["ImageFileExtension","ImageFileExtensionProvider","props","children","extensions","supportedMediaTypes","R","map","extension","acceptHeader","join"],"sources":["ImageFileExtensionProvider.tsx"],"sourcesContent":["import React from 'react';\nimport * as R from 'ramda';\nimport ImageFileExtensionContext from './ImageFileExtensionContext';\n\nexport enum ImageFileExtension {\n AVIF = 'avif',\n WEBP = 'webp',\n JPG = 'jpg',\n PNG = 'png',\n}\n\ninterface ImageFileExtensionProviderProps {\n children: React.ReactNode;\n extensions: ImageFileExtension[];\n}\n\nexport default function ImageFileExtensionProvider(props: ImageFileExtensionProviderProps) {\n const { children, extensions } = props;\n\n const supportedMediaTypes = [\n ...(R.map(extension => `image/${extension}`, extensions)),\n 'image/*',\n '*/*',\n ];\n\n const acceptHeader = `${R.join(',', supportedMediaTypes)};`;\n\n return (\n <ImageFileExtensionContext.Provider value={acceptHeader}>\n {children}\n </ImageFileExtensionContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;;;;;;;IAEYA,kB;;;WAAAA,kB;EAAAA,kB;EAAAA,kB;EAAAA,kB;EAAAA,kB;GAAAA,kB,kCAAAA,kB;;AAYG,SAASC,0BAAT,CAAoCC,KAApC,EAA4E;EACvF,MAAM;IAAEC,QAAF;IAAYC;EAAZ,IAA2BF,KAAjC;EAEA,MAAMG,mBAAmB,GAAG,CACxB,GAAIC,CAAC,CAACC,GAAF,CAAMC,SAAS,IAAK,SAAQA,SAAU,EAAtC,EAAyCJ,UAAzC,CADoB,EAExB,SAFwB,EAGxB,KAHwB,CAA5B;EAMA,MAAMK,YAAY,GAAI,GAAEH,CAAC,CAACI,IAAF,CAAO,GAAP,EAAYL,mBAAZ,CAAiC,GAAzD;EAEA,oBACI,6BAAC,kCAAD,CAA2B,QAA3B;IAAoC,KAAK,EAAEI;EAA3C,GACKN,QADL,CADJ;AAKH"}
|
|
@@ -21,20 +21,6 @@ Object.defineProperty(exports, "default", {
|
|
|
21
21
|
|
|
22
22
|
var _ImageCoreWeb = _interopRequireDefault(require("./ImageCoreWeb"));
|
|
23
23
|
|
|
24
|
-
var _ImageCoreProps = require("./ImageCoreProps");
|
|
25
|
-
|
|
26
|
-
Object.keys(_ImageCoreProps).forEach(function (key) {
|
|
27
|
-
if (key === "default" || key === "__esModule") return;
|
|
28
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
29
|
-
if (key in exports && exports[key] === _ImageCoreProps[key]) return;
|
|
30
|
-
Object.defineProperty(exports, key, {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _ImageCoreProps[key];
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
24
|
var _ImageFileExtensionProvider = _interopRequireWildcard(require("./ImageFileExtensionProvider"));
|
|
39
25
|
|
|
40
26
|
Object.keys(_ImageFileExtensionProvider).forEach(function (key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './ImageCoreWeb';\nexport
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './ImageCoreWeb';\nexport type { default as ImageCoreProps, ImageSource, Loading, ResizeMode } from './ImageCoreProps';\n\nexport { default as ImageFileExtensionProvider } from './ImageFileExtensionProvider';\nexport * from './ImageFileExtensionProvider';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AAGA;;AACA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "useContentContainerStyle", {
|
|
|
27
27
|
return _useContentContainerStyle.default;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "useDebounce", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _useDebounce.default;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
Object.defineProperty(exports, "useElevationStyle", {
|
|
31
37
|
enumerable: true,
|
|
32
38
|
get: function () {
|
|
@@ -82,6 +88,8 @@ var _useSyncAnimatedValue = _interopRequireDefault(require("./useSyncAnimatedVal
|
|
|
82
88
|
|
|
83
89
|
var _useThrottle = _interopRequireDefault(require("./useThrottle"));
|
|
84
90
|
|
|
91
|
+
var _useDebounce = _interopRequireDefault(require("./useDebounce"));
|
|
92
|
+
|
|
85
93
|
var _useValidWindowDimensions = _interopRequireDefault(require("./useValidWindowDimensions"));
|
|
86
94
|
|
|
87
95
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as useAnimatedValue } from './useAnimatedValue';\nexport { default as useBreakpointUp } from './useBreakpointUp';\nexport { default as useCollapsibleAppBar } from './useCollapsibleAppBar';\nexport { default as useContentContainerStyle } from './useContentContainerStyle';\nexport { default as useElevationStyle } from './useElevationStyle';\nexport { default as useFadeInAppBar } from './useFadeInAppBar';\nexport { default as useImperativeState } from './useImperativeState';\nexport { default as useSyncAnimatedValue } from './useSyncAnimatedValue';\nexport { default as useThrottle } from './useThrottle';\nexport { default as useValidWindowDimensions } from './useValidWindowDimensions';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as useAnimatedValue } from './useAnimatedValue';\nexport { default as useBreakpointUp } from './useBreakpointUp';\nexport { default as useCollapsibleAppBar } from './useCollapsibleAppBar';\nexport { default as useContentContainerStyle } from './useContentContainerStyle';\nexport { default as useElevationStyle } from './useElevationStyle';\nexport { default as useFadeInAppBar } from './useFadeInAppBar';\nexport { default as useImperativeState } from './useImperativeState';\nexport { default as useSyncAnimatedValue } from './useSyncAnimatedValue';\nexport { default as useThrottle } from './useThrottle';\nexport { default as useDebounce } from './useDebounce';\nexport { default as useValidWindowDimensions } from './useValidWindowDimensions';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useDebounce;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
function useDebounce(callback, debounceMillis) {
|
|
11
|
+
const debounceTimeout = (0, _react.useRef)(null);
|
|
12
|
+
(0, _react.useEffect)(() => {
|
|
13
|
+
return () => {
|
|
14
|
+
debounceTimeout.current && clearTimeout(debounceTimeout.current);
|
|
15
|
+
};
|
|
16
|
+
}, []);
|
|
17
|
+
return (0, _react.useCallback)(function () {
|
|
18
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
19
|
+
args[_key] = arguments[_key];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (debounceTimeout.current) {
|
|
23
|
+
clearTimeout(debounceTimeout.current);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (callback) {
|
|
27
|
+
debounceTimeout.current = setTimeout(() => {
|
|
28
|
+
callback(...args);
|
|
29
|
+
}, debounceMillis);
|
|
30
|
+
}
|
|
31
|
+
}, [debounceMillis, callback]);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=useDebounce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useDebounce","callback","debounceMillis","debounceTimeout","useRef","useEffect","current","clearTimeout","useCallback","args","setTimeout"],"sources":["useDebounce.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\n\nexport default function useDebounce(callback: (args?: any) => void, debounceMillis: number) {\n const debounceTimeout = useRef<NodeJS.Timeout | null>(null);\n\n useEffect(() => {\n return () => {\n debounceTimeout.current && clearTimeout(debounceTimeout.current);\n };\n }, []);\n\n return useCallback((...args: any[]) => {\n if (debounceTimeout.current) {\n clearTimeout(debounceTimeout.current);\n }\n\n if (callback) {\n debounceTimeout.current = setTimeout(() => {\n callback(...args);\n }, debounceMillis);\n }\n }, [debounceMillis, callback]);\n}"],"mappings":";;;;;;;AAAA;;AAEe,SAASA,WAAT,CAAqBC,QAArB,EAAqDC,cAArD,EAA6E;EACxF,MAAMC,eAAe,GAAG,IAAAC,aAAA,EAA8B,IAA9B,CAAxB;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACZ,OAAO,MAAM;MACTF,eAAe,CAACG,OAAhB,IAA2BC,YAAY,CAACJ,eAAe,CAACG,OAAjB,CAAvC;IACH,CAFD;EAGH,CAJD,EAIG,EAJH;EAMA,OAAO,IAAAE,kBAAA,EAAY,YAAoB;IAAA,kCAAhBC,IAAgB;MAAhBA,IAAgB;IAAA;;IACnC,IAAIN,eAAe,CAACG,OAApB,EAA6B;MACzBC,YAAY,CAACJ,eAAe,CAACG,OAAjB,CAAZ;IACH;;IAED,IAAIL,QAAJ,EAAc;MACVE,eAAe,CAACG,OAAhB,GAA0BI,UAAU,CAAC,MAAM;QACvCT,QAAQ,CAAC,GAAGQ,IAAJ,CAAR;MACH,CAFmC,EAEjCP,cAFiC,CAApC;IAGH;EACJ,CAVM,EAUJ,CAACA,cAAD,EAAiBD,QAAjB,CAVI,CAAP;AAWH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
import React, { useEffect } from 'react';
|
|
4
|
-
import { View } from 'react-native';
|
|
3
|
+
import React, { useEffect, useState } from 'react';
|
|
4
|
+
import { Text, View } from 'react-native';
|
|
5
5
|
import ImageCore from '../ImageCore';
|
|
6
6
|
import { css, StyleSheet, useTheme } from '../styles';
|
|
7
7
|
|
|
@@ -20,10 +20,22 @@ const useStyles = function () {
|
|
|
20
20
|
borderWidth: StyleSheet.hairlineWidth,
|
|
21
21
|
borderStyle: 'solid',
|
|
22
22
|
borderColor: theme.palette.paper.grey
|
|
23
|
+
},
|
|
24
|
+
error: {
|
|
25
|
+
width: '100%',
|
|
26
|
+
height: '100%'
|
|
23
27
|
}
|
|
24
28
|
};
|
|
25
29
|
};
|
|
26
30
|
|
|
31
|
+
function determinePlaceholderMode(props) {
|
|
32
|
+
if (props.disablePlaceholder) {
|
|
33
|
+
return 'none';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return props.placeholder ? 'custom' : 'default';
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
export default function Image(props) {
|
|
28
40
|
const {
|
|
29
41
|
alt,
|
|
@@ -31,67 +43,63 @@ export default function Image(props) {
|
|
|
31
43
|
disableLongClick,
|
|
32
44
|
disableOutline,
|
|
33
45
|
disablePlaceholder,
|
|
34
|
-
|
|
46
|
+
error,
|
|
35
47
|
loading = 'lazy',
|
|
48
|
+
onError: onErrorProp,
|
|
49
|
+
onLoad: onLoadProp,
|
|
36
50
|
overlaidChildren,
|
|
51
|
+
placeholder,
|
|
37
52
|
resizeMode = 'cover',
|
|
38
53
|
source,
|
|
39
54
|
style,
|
|
40
55
|
square = false,
|
|
41
56
|
size,
|
|
42
|
-
onLoad,
|
|
43
|
-
onError,
|
|
44
|
-
Placeholder: PlaceholderComponent,
|
|
45
57
|
...otherProps
|
|
46
58
|
} = props;
|
|
47
|
-
const [failed, setFailed] =
|
|
59
|
+
const [failed, setFailed] = useState(false);
|
|
48
60
|
const styles = useStyles();
|
|
49
61
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
setFailed(true);
|
|
62
|
+
const onLoad = () => {
|
|
63
|
+
setFailed(false);
|
|
64
|
+
onLoadProp === null || onLoadProp === void 0 ? void 0 : onLoadProp();
|
|
56
65
|
};
|
|
57
66
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
children
|
|
62
|
-
} = _ref;
|
|
63
|
-
return PlaceholderComponent ? /*#__PURE__*/React.createElement(PlaceholderComponent, {
|
|
64
|
-
children: children,
|
|
65
|
-
failed: failed
|
|
66
|
-
}) : children;
|
|
67
|
+
const onError = () => {
|
|
68
|
+
setFailed(true);
|
|
69
|
+
onErrorProp === null || onErrorProp === void 0 ? void 0 : onErrorProp();
|
|
67
70
|
};
|
|
68
71
|
|
|
69
72
|
const sourceWithSizeParam = { ...source,
|
|
70
73
|
uri: size ? `${source.uri}?size=${size}` : source.uri
|
|
71
74
|
};
|
|
75
|
+
const placeholderMode = determinePlaceholderMode(props);
|
|
72
76
|
useEffect(() => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
}, [...failDependency]);
|
|
77
|
+
setFailed(false);
|
|
78
|
+
}, [sourceWithSizeParam.uri]);
|
|
77
79
|
return /*#__PURE__*/React.createElement(View, _extends({
|
|
78
|
-
style: css([styles.root, !disableOutline ? styles.outlined : undefined, !
|
|
79
|
-
}, otherProps), /*#__PURE__*/React.createElement(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
style: css([styles.root, !disableOutline ? styles.outlined : undefined, !square ? styles.rounded : undefined, placeholderMode === 'default' ? styles.placeholder : undefined, style])
|
|
81
|
+
}, otherProps), placeholderMode === 'custom' ? /*#__PURE__*/React.createElement(View, {
|
|
82
|
+
style: css([StyleSheet.absoluteFill, {
|
|
83
|
+
zIndex: -1
|
|
84
|
+
}])
|
|
85
|
+
}, placeholder) : null, failed ? /*#__PURE__*/React.createElement(View, {
|
|
86
|
+
style: styles.error
|
|
87
|
+
}, error ?? /*#__PURE__*/React.createElement(Text, {
|
|
88
|
+
children: alt
|
|
89
|
+
})) : sourceWithSizeParam.uri ? /*#__PURE__*/React.createElement(ImageCore, {
|
|
90
|
+
alt: sourceWithSizeParam.uri,
|
|
83
91
|
disableDrag: disableDrag,
|
|
84
92
|
disableLongClick: disableLongClick,
|
|
85
93
|
height: '100%',
|
|
86
94
|
loading: loading,
|
|
87
|
-
onError:
|
|
95
|
+
onError: onError,
|
|
88
96
|
onLoad: onLoad,
|
|
89
97
|
resizeMode: resizeMode,
|
|
90
98
|
source: sourceWithSizeParam,
|
|
91
99
|
width: '100%'
|
|
92
|
-
}), overlaidChildren ? /*#__PURE__*/React.createElement(View, {
|
|
100
|
+
}) : null, overlaidChildren ? /*#__PURE__*/React.createElement(View, {
|
|
93
101
|
style: StyleSheet.absoluteFill
|
|
94
|
-
}, overlaidChildren) : null)
|
|
102
|
+
}, overlaidChildren) : null);
|
|
95
103
|
}
|
|
96
104
|
;
|
|
97
105
|
//# sourceMappingURL=Image.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useEffect","View","ImageCore","css","StyleSheet","useTheme","useStyles","theme","root","rounded","borderRadius","shape","roundness","overflow","placeholder","backgroundColor","palette","paper","grey","outlined","borderWidth","hairlineWidth","borderStyle","borderColor","
|
|
1
|
+
{"version":3,"names":["React","useEffect","useState","Text","View","ImageCore","css","StyleSheet","useTheme","useStyles","theme","root","rounded","borderRadius","shape","roundness","overflow","placeholder","backgroundColor","palette","paper","grey","outlined","borderWidth","hairlineWidth","borderStyle","borderColor","error","width","height","determinePlaceholderMode","props","disablePlaceholder","Image","alt","disableDrag","disableLongClick","disableOutline","loading","onError","onErrorProp","onLoad","onLoadProp","overlaidChildren","resizeMode","source","style","square","size","otherProps","failed","setFailed","styles","sourceWithSizeParam","uri","placeholderMode","undefined","absoluteFill","zIndex"],"sources":["Image.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport { Text, View } from 'react-native';\nimport type { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport type { ImageCoreProps } from '../ImageCore';\nimport ImageCore from '../ImageCore';\nimport { css, StyleSheet, useTheme } from '../styles';\nimport type ImageProps from './ImageProps';\n\ntype PlaceholderMode =\n | 'default'\n | 'custom'\n | 'none';\n\ntype ImageStyleKeys =\n | 'root'\n | 'rounded'\n | 'placeholder'\n | 'outlined'\n | 'error';\n\ntype ImageStyles = NamedStylesStringUnion<ImageStyleKeys>;\n\nconst useStyles: UseStyles<ImageStyles> = function (): ImageStyles {\n const theme = useTheme();\n\n return {\n root: {},\n rounded: {\n borderRadius: theme.shape.roundness,\n overflow: 'hidden',\n },\n placeholder: {\n backgroundColor: theme.palette.paper.grey,\n },\n outlined: {\n borderWidth: StyleSheet.hairlineWidth,\n borderStyle: 'solid',\n borderColor: theme.palette.paper.grey,\n },\n error: {\n width: '100%',\n height: '100%',\n },\n };\n};\n\nfunction determinePlaceholderMode(props: ImageProps): PlaceholderMode {\n if (props.disablePlaceholder) {\n return 'none';\n }\n\n return props.placeholder ? 'custom' : 'default';\n}\n\nexport default function Image(props: ImageProps) {\n const {\n alt,\n disableDrag,\n disableLongClick,\n disableOutline,\n disablePlaceholder,\n error,\n loading = 'lazy',\n onError: onErrorProp,\n onLoad: onLoadProp,\n overlaidChildren,\n placeholder,\n resizeMode = 'cover',\n source,\n style,\n square = false,\n size,\n ...otherProps\n } = props;\n\n const [failed, setFailed] = useState(false);\n\n const styles = useStyles();\n\n const onLoad: ImageCoreProps['onLoad'] = () => {\n setFailed(false);\n\n onLoadProp?.();\n };\n\n const onError: ImageCoreProps['onError'] = () => {\n setFailed(true);\n\n onErrorProp?.();\n };\n\n const sourceWithSizeParam = {\n ...source,\n uri: size ? `${source.uri}?size=${size}` : source.uri,\n };\n\n const placeholderMode = determinePlaceholderMode(props);\n\n useEffect(() => {\n setFailed(false);\n }, [sourceWithSizeParam.uri]);\n\n return (\n <View\n style={css([\n styles.root,\n !disableOutline ? styles.outlined : undefined,\n !square ? styles.rounded : undefined,\n placeholderMode === 'default' ? styles.placeholder : undefined,\n style,\n ])}\n {...otherProps}\n >\n {placeholderMode === 'custom' ? (\n <View\n style={css([\n StyleSheet.absoluteFill,\n { zIndex: -1 },\n ])}\n >\n {placeholder}\n </View>\n ) : null}\n\n {failed ? (\n <View style={styles.error}>\n {error ?? <Text children={alt}/>}\n </View>\n ) : sourceWithSizeParam.uri ? (\n <ImageCore\n alt={sourceWithSizeParam.uri}\n disableDrag={disableDrag}\n disableLongClick={disableLongClick}\n height={'100%'}\n loading={loading}\n onError={onError}\n onLoad={onLoad}\n resizeMode={resizeMode}\n source={sourceWithSizeParam}\n width={'100%'}\n />\n ) : null}\n\n {overlaidChildren ? (\n <View style={StyleSheet.absoluteFill}>\n {overlaidChildren}\n </View>\n ) : null}\n </View>\n );\n};"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,QAA3B,QAA2C,OAA3C;AACA,SAASC,IAAT,EAAeC,IAAf,QAA2B,cAA3B;AAGA,OAAOC,SAAP,MAAsB,cAAtB;AACA,SAASC,GAAT,EAAcC,UAAd,EAA0BC,QAA1B,QAA0C,WAA1C;;AAiBA,MAAMC,SAAiC,GAAG,YAAyB;EAC/D,MAAMC,KAAK,GAAGF,QAAQ,EAAtB;EAEA,OAAO;IACHG,IAAI,EAAE,EADH;IAEHC,OAAO,EAAE;MACLC,YAAY,EAAEH,KAAK,CAACI,KAAN,CAAYC,SADrB;MAELC,QAAQ,EAAE;IAFL,CAFN;IAMHC,WAAW,EAAE;MACTC,eAAe,EAAER,KAAK,CAACS,OAAN,CAAcC,KAAd,CAAoBC;IAD5B,CANV;IASHC,QAAQ,EAAE;MACNC,WAAW,EAAEhB,UAAU,CAACiB,aADlB;MAENC,WAAW,EAAE,OAFP;MAGNC,WAAW,EAAE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d,gBADL,CADa,GAIb,IA5CR,CADJ;AAgDH;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ImageProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { OverridableComponentProps } from '../types';\nimport type { ImageSource, Loading, ResizeMode } from '../ImageCore';\n\
|
|
1
|
+
{"version":3,"names":[],"sources":["ImageProps.ts"],"sourcesContent":["import React from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { OverridableComponentProps } from '../types';\nimport type { ImageSource, Loading, ResizeMode } from '../ImageCore';\n\n\nexport default interface ImageProps extends OverridableComponentProps<ViewProps, {\n /**\n * Indicating the alternate fallback content to be displayed\n * if the image has not been loaded.\n */\n alt?: string;\n\n /**\n * Disable drag event for web.\n * @default false\n */\n disableDrag?: boolean,\n\n /**\n * Disable Long click event for web.\n * @default false\n */\n disableLongClick?: boolean,\n\n /**\n * If `true`, the image outline is not rendered.\n * @default false\n */\n disableOutline?: boolean;\n\n /**\n * If `true`, the placeholder is not rendered.\n * @default false\n */\n disablePlaceholder?: boolean;\n\n /**\n * Custom error element. Default is simple alt text.\n */\n error?: React.ReactElement | null;\n\n /**\n * Web only. Loading the document by determining whether to load\n * the image immediately (`eager`) or on an as-needed basis (`lazy`).\n * On React Native, it always works as `lazy`.\n * @default 'lazy'\n */\n loading?: Loading;\n\n /**\n * error event handler\n */\n onError?: () => void;\n\n /**\n * image loaded event handler\n */\n onLoad?: () => void;\n\n /**\n * The children on top this image.\n */\n overlaidChildren?: React.ReactElement;\n\n /**\n * Custom placeholder element.\n */\n placeholder?: React.ReactElement;\n\n /**\n * Determines how to resize the image when the frame doesn't match the raw image dimensions.\n * @default 'cover'\n */\n resizeMode?: ResizeMode;\n\n /**\n * The image source.\n */\n source: ImageSource;\n\n /**\n * If `true`, rounded corners are disabled.\n * @default false\n */\n square?: boolean;\n\n /**\n * Image file size.\n * Request image by query string.\n */\n size?: 'small' | 'medium' | 'large';\n}> {}\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default"],"sources":["index.ts"],"sourcesContent":["export { default } from './Image';\nexport type { default as ImageProps } from './ImageProps'
|
|
1
|
+
{"version":3,"names":["default"],"sources":["index.ts"],"sourcesContent":["export { default } from './Image';\nexport type { default as ImageProps } from './ImageProps';"],"mappings":"AAAA,SAASA,OAAT,QAAwB,SAAxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ImageCoreProps.ts"],"sourcesContent":["export interface ImageSource {\n uri
|
|
1
|
+
{"version":3,"names":[],"sources":["ImageCoreProps.ts"],"sourcesContent":["export interface ImageSource {\n uri?: string;\n}\n\nexport type ResizeMode = 'cover' | 'contain';\n\nexport type Loading = 'lazy' | 'eager';\n\nexport default interface ImageCoreProps extends Readonly<{\n alt?: string;\n disableDrag?: boolean,\n disableLongClick?: boolean,\n height?: number | string;\n loading: Loading;\n onError?: () => void;\n onLoad?: () => void;\n resizeMode: ResizeMode;\n source: ImageSource;\n width?: number | string;\n}> {}"],"mappings":""}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
const longClickDisabledStyle = {
|
|
3
|
+
'-webkit-user-select': 'none',
|
|
4
|
+
'-webkit-touch-callout': 'none'
|
|
5
|
+
};
|
|
2
6
|
|
|
3
7
|
const preventDragging = () => false;
|
|
4
8
|
|
|
@@ -21,13 +25,9 @@ export default function ImageCore(props) {
|
|
|
21
25
|
source,
|
|
22
26
|
width
|
|
23
27
|
} = props;
|
|
24
|
-
const disableLongClickStyle = disableLongClick ? {
|
|
25
|
-
'-webkit-user-select': 'none',
|
|
26
|
-
'-webkit-touch-callout': 'none'
|
|
27
|
-
} : {};
|
|
28
28
|
const style = {
|
|
29
29
|
objectFit: resizeMode,
|
|
30
|
-
...
|
|
30
|
+
...(disableLongClick ? longClickDisabledStyle : {})
|
|
31
31
|
};
|
|
32
32
|
return /*#__PURE__*/React.createElement("img", {
|
|
33
33
|
alt: alt,
|