@eightshift/ui-components 5.4.0 → 5.5.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/dist/assets/style-admin.css +49 -10
- package/dist/assets/style-editor.css +49 -10
- package/dist/assets/style.css +49 -10
- package/dist/components/index.js +2 -0
- package/dist/components/placeholders/file-picker-shell.js +67 -39
- package/dist/components/smart-image/smart-image.js +117 -0
- package/dist/icons/icons.js +10 -0
- package/dist/index.js +2 -0
- package/dist/utilities/general.js +4142 -0
- package/dist/utilities/index.js +5 -0
- package/package.json +7 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { _ as __ } from "../../default-i18n-CN_q3KUs.js";
|
|
3
|
+
import { c as clsx } from "../../lite-DVmmD_-j.js";
|
|
4
|
+
import { useState, cloneElement } from "react";
|
|
5
|
+
import { analyzeImage } from "../../utilities/general.js";
|
|
6
|
+
import { icons } from "../../icons/icons.js";
|
|
7
|
+
import "../../react-jsx-parser.min-VUl-CuCv.js";
|
|
8
|
+
import { DecorativeTooltip } from "../tooltip/tooltip.js";
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Object} CustomImageProps
|
|
11
|
+
* @property {JSX.Element} [props.renderError] - Component to render if image analysis fails. `(error) => JSX:Element`.
|
|
12
|
+
* @property {string} [props.errorClassName] - Classes to pass to the default error view.
|
|
13
|
+
* @property {string} [props.processingClassName] - Classes to apply while the image is loading / being processed.
|
|
14
|
+
* @property {boolean} [props.hidden] - If `true`, the component is not rendered.
|
|
15
|
+
* @property {import('../../utilities/general').ImageAnalysisSettings} [imageAnalysisSettings] - Settings to pass to the image analysis function.
|
|
16
|
+
*
|
|
17
|
+
* @preserve
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {Omit<JSX.IntrinsicElements['img'], 'crossOrigin'>} BaseImageProps
|
|
21
|
+
*
|
|
22
|
+
* @preserve
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {CustomImageProps & BaseImageProps} ImageProps
|
|
26
|
+
*
|
|
27
|
+
* @preserve
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Image that analyzes its contents and can apply different classes based on image transparency.
|
|
31
|
+
* It also provides a CSS variable with the image's dominant color, and optionally custom child rendering with all the data exposed.
|
|
32
|
+
*
|
|
33
|
+
* @component
|
|
34
|
+
* @param {ImageProps} props - Component props.
|
|
35
|
+
*
|
|
36
|
+
* @returns {JSX.Element} The SmartImage component.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* <SmartImage src='https://picsum.photos/600/400' />
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* <SmartImage src='https://picsum.photos/600/400'>
|
|
43
|
+
* {({ image, dominantColors, isDark }) => (
|
|
44
|
+
* <div style={{ backgroundColor: dominantColors[0].color }}>
|
|
45
|
+
* {image}
|
|
46
|
+
* <p style={{ color: isDark ? '#000000' : '#FFFFFF' }}>Lorem ipsum</p>
|
|
47
|
+
* </div>
|
|
48
|
+
* )}
|
|
49
|
+
* </SmartImage>
|
|
50
|
+
*
|
|
51
|
+
* @preserve
|
|
52
|
+
*/
|
|
53
|
+
const SmartImage = (props) => {
|
|
54
|
+
const { imageAnalysisSettings, errorClassName, processingClassName = "es:opacity-0 es:fixed", hidden, renderError, children, ...imageProps } = props;
|
|
55
|
+
const [isLoaded, setIsLoaded] = useState(false);
|
|
56
|
+
const [hasAnalysed, setHasAnalysed] = useState(false);
|
|
57
|
+
const [isTransparent, setIsTransparent] = useState(null);
|
|
58
|
+
const [transparencyInfo, setTransparencyInfo] = useState(null);
|
|
59
|
+
const [dominantColors, setDominantColors] = useState([]);
|
|
60
|
+
const [isDark, setIsDark] = useState(false);
|
|
61
|
+
const [error, setError] = useState(null);
|
|
62
|
+
if (hidden) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const classFetchProps = { isLoaded, hasAnalysed, isTransparent, dominantColors, isDark, transparencyInfo };
|
|
66
|
+
const imageElement = /* @__PURE__ */ jsx(
|
|
67
|
+
"img",
|
|
68
|
+
{
|
|
69
|
+
decoding: "async",
|
|
70
|
+
...imageProps,
|
|
71
|
+
crossOrigin: "anonymous",
|
|
72
|
+
style: {
|
|
73
|
+
...imageProps.style || {},
|
|
74
|
+
"--es-img-dominant-color": dominantColors?.[0]?.color ?? ""
|
|
75
|
+
},
|
|
76
|
+
className: clsx(
|
|
77
|
+
"es:transition-opacity",
|
|
78
|
+
!hasAnalysed && processingClassName,
|
|
79
|
+
typeof imageProps.className === "function" ? imageProps.className(classFetchProps) : imageProps.className
|
|
80
|
+
),
|
|
81
|
+
onLoad: async (e) => {
|
|
82
|
+
setIsLoaded(true);
|
|
83
|
+
if (props.onLoad) {
|
|
84
|
+
props.onLoad(e);
|
|
85
|
+
}
|
|
86
|
+
if (!imageProps.src) {
|
|
87
|
+
setHasAnalysed(true);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const result = analyzeImage(e.target, imageAnalysisSettings);
|
|
91
|
+
if (result) {
|
|
92
|
+
const { isDark: dark, dominantColors: colors, isTransparent: transparent, transparencyInfo: transparencyInfo2 } = result;
|
|
93
|
+
setIsDark(dark);
|
|
94
|
+
setDominantColors(colors);
|
|
95
|
+
setIsTransparent(transparent);
|
|
96
|
+
setTransparencyInfo(transparencyInfo2);
|
|
97
|
+
}
|
|
98
|
+
setHasAnalysed(true);
|
|
99
|
+
},
|
|
100
|
+
onError: () => setError(new Error("Image failed to load")),
|
|
101
|
+
"data-is-transparent": isTransparent,
|
|
102
|
+
"data-is-dark": isDark
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
if (error && renderError) {
|
|
106
|
+
return renderError(error);
|
|
107
|
+
} else if (error) {
|
|
108
|
+
return /* @__PURE__ */ jsx("div", { className: clsx("es:flex es:flex-col es:gap-2 es:items-center-safe es:justify-center-safe es:p-2 es:motion-preset-fade", errorClassName), children: /* @__PURE__ */ jsx(DecorativeTooltip, { text: __("Error loading image", "eightshift-ui-components"), children: cloneElement(icons.imageError, { className: "es:text-secondary-500 es:size-8" }) }) });
|
|
109
|
+
}
|
|
110
|
+
if (!children) {
|
|
111
|
+
return imageElement;
|
|
112
|
+
}
|
|
113
|
+
return typeof children === "function" ? children({ image: imageElement, dominantColors, isDark, hasAnalysed, isTransparent, transparencyInfo }) : imageElement;
|
|
114
|
+
};
|
|
115
|
+
export {
|
|
116
|
+
SmartImage
|
|
117
|
+
};
|
package/dist/icons/icons.js
CHANGED
|
@@ -3376,6 +3376,16 @@ const icons = {
|
|
|
3376
3376
|
/* @__PURE__ */ jsx("path", { d: "m9.5.5 5 5H10a.5.5 0 0 1-.5-.5V.5Z", fill: "currentColor", fillOpacity: "0.3" }),
|
|
3377
3377
|
/* @__PURE__ */ jsx("path", { d: "m14.5 5.5-5-5m5 5H10a.5.5 0 0 1-.5-.5V.5m5 5v2m-5-7H2A1.5 1.5 0 0 0 .5 2v16A1.5 1.5 0 0 0 2 19.5h11a1.5 1.5 0 0 0 1.5-1.5v-.5", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", fill: "none" }),
|
|
3378
3378
|
/* @__PURE__ */ jsx("path", { d: "M11.236 15.5H9.499v-6h1.737s2.316 0 2.316 2.842v.316c0 2.842-2.316 2.842-2.316 2.842Zm4.263 0v-3m3.184-3H15.5v3m0 0h3.04m-15.04 3v-3m0 0v-3h1.882c.434 0 2.119 0 2.118 1.5-.001 1.5-1.566 1.5-2 1.5h-2Z", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", fill: "none" })
|
|
3379
|
+
] }),
|
|
3380
|
+
fileError: /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 20 20", width: "20", height: "20", fill: "none", children: [
|
|
3381
|
+
/* @__PURE__ */ jsx("path", { d: "m16.5 5.5-5-5m5 5H12a.5.5 0 0 1-.5-.5V.5m5 5V18a1.5 1.5 0 0 1-1.5 1.5H5A1.5 1.5 0 0 1 3.5 18V2A1.5 1.5 0 0 1 5 .5h6.5", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", fill: "none" }),
|
|
3382
|
+
/* @__PURE__ */ jsx("path", { d: "m7 9.5 3 3m3 3-3-3m0 0-3 3m3-3 3-3", stroke: "currentColor", strokeLinecap: "round", fill: "none" })
|
|
3383
|
+
] }),
|
|
3384
|
+
imageError: /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 20 20", width: "20", height: "20", fill: "none", children: [
|
|
3385
|
+
/* @__PURE__ */ jsx("path", { d: "M15.5 11.5V2A1.5 1.5 0 0 0 14 .5H2A1.5 1.5 0 0 0 .5 2v12A1.5 1.5 0 0 0 2 15.5h9.5", stroke: "currentColor", fill: "none" }),
|
|
3386
|
+
/* @__PURE__ */ jsx("circle", { cx: "5.25", cy: "5.25", r: "1.75", fill: "currentColor", fillOpacity: "0.5" }),
|
|
3387
|
+
/* @__PURE__ */ jsx("path", { d: "M18 11a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-5a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h5Zm-.12 2.12a.537.537 0 0 0-.76 0l-1.62 1.62-1.62-1.62a.537.537 0 1 0-.76.76l1.62 1.62-1.62 1.62a.537.537 0 1 0 .76.76l1.62-1.62 1.62 1.62a.537.537 0 1 0 .76-.76l-1.62-1.62 1.62-1.62c.21-.21.21-.55 0-.76Z", fill: "currentColor" }),
|
|
3388
|
+
/* @__PURE__ */ jsx("path", { d: "M3.475 10.705 1 12.79V15h10.5l1.5-2.5 1.241-.863-2.436-2.518a1.5 1.5 0 0 0-2.16.004l-1.78 1.854a1.5 1.5 0 0 1-2.114.05l-.278-.263a1.5 1.5 0 0 0-1.998-.059Z", fill: "currentColor", fillOpacity: "0.5" })
|
|
3379
3389
|
] })
|
|
3380
3390
|
};
|
|
3381
3391
|
const blockIcons = {
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ import { OptionSelect } from "./components/option-select/option-select.js";
|
|
|
50
50
|
import { OptionsPanel, OptionsPanelHeader, OptionsPanelIntro, OptionsPanelSection } from "./components/options-panel/options-panel.js";
|
|
51
51
|
import { Select } from "./components/select/single-select.js";
|
|
52
52
|
import { Slider } from "./components/slider/slider.js";
|
|
53
|
+
import { SmartImage } from "./components/smart-image/smart-image.js";
|
|
53
54
|
import { SolidColorPicker } from "./components/color-pickers/solid-color-picker.js";
|
|
54
55
|
import { Spacer } from "./components/spacer/spacer.js";
|
|
55
56
|
import { Tab, TabList, TabPanel, Tabs } from "./components/tabs/tabs.js";
|
|
@@ -129,6 +130,7 @@ export {
|
|
|
129
130
|
Select,
|
|
130
131
|
SelectNext,
|
|
131
132
|
Slider,
|
|
133
|
+
SmartImage,
|
|
132
134
|
SolidColorPicker,
|
|
133
135
|
Spacer,
|
|
134
136
|
SubMenuItem,
|