bj-web-components 0.2.26 → 0.2.28
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/favicon.ico +0 -0
- package/dist/file.svg +1 -0
- package/dist/globe.svg +1 -0
- package/dist/index.d.ts +1141 -0
- package/dist/index.js +51 -0
- package/dist/index.mjs +51 -0
- package/dist/miniapp.d.ts +1 -0
- package/dist/miniapp.js +1 -0
- package/dist/miniapp.mjs +1 -0
- package/dist/mobile.d.ts +1 -0
- package/dist/mobile.js +1 -0
- package/dist/mobile.mjs +1 -0
- package/dist/next.svg +1 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +1 -0
- package/dist/react.mjs +1 -0
- package/dist/shared.d.ts +1 -0
- package/dist/shared.js +1 -0
- package/dist/shared.mjs +1 -0
- package/dist/style.css +3744 -0
- package/dist/vercel.svg +1 -0
- package/dist/web/BasicInput/BInput.js +208 -0
- package/dist/web/BasicInput/BInput.mjs +209 -0
- package/dist/web/BasicInput/utils.js +47 -0
- package/dist/web/BasicInput/utils.mjs +47 -0
- package/dist/web/CategoryDropdown/CategoryDropdown.js +307 -0
- package/dist/web/CategoryDropdown/CategoryDropdown.mjs +308 -0
- package/dist/web/CheckBox/BCheckBox.js +116 -0
- package/dist/web/CheckBox/BCheckBox.mjs +117 -0
- package/dist/web/CheckBox/Group.js +73 -0
- package/dist/web/CheckBox/Group.mjs +74 -0
- package/dist/web/CheckBox/context.js +5 -0
- package/dist/web/CheckBox/context.mjs +5 -0
- package/dist/web/CheckBox/index.js +8 -0
- package/dist/web/CheckBox/index.mjs +8 -0
- package/dist/web/Dropdown/BDropdown.js +186 -0
- package/dist/web/Dropdown/BDropdown.mjs +186 -0
- package/dist/web/EmptyInputBox/EmptyInputBox.js +77 -0
- package/dist/web/EmptyInputBox/EmptyInputBox.mjs +78 -0
- package/dist/web/FileCard/FileCard.js +157 -0
- package/dist/web/FileCard/FileCard.mjs +158 -0
- package/dist/web/Icon/Icon.js +9 -0
- package/dist/web/Icon/Icon.mjs +10 -0
- package/dist/web/Input/Input.js +181 -0
- package/dist/web/Input/Input.mjs +182 -0
- package/dist/web/InputNumber/BInputNumber.js +311 -0
- package/dist/web/InputNumber/BInputNumber.mjs +312 -0
- package/dist/web/InputNumber/StepHandler.js +69 -0
- package/dist/web/InputNumber/StepHandler.mjs +70 -0
- package/dist/web/InputNumber/hooks/useCursor.js +40 -0
- package/dist/web/InputNumber/hooks/useCursor.mjs +41 -0
- package/dist/web/InputNumber/hooks/useFrame.js +12 -0
- package/dist/web/InputNumber/hooks/useFrame.mjs +13 -0
- package/dist/web/InputNumber/utils/decimal.js +147 -0
- package/dist/web/InputNumber/utils/decimal.mjs +147 -0
- package/dist/web/Modal/Modal.js +84 -0
- package/dist/web/Modal/Modal.mjs +85 -0
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.js +232 -0
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.mjs +233 -0
- package/dist/web/Pagination/Pagination.js +328 -0
- package/dist/web/Pagination/Pagination.mjs +329 -0
- package/dist/web/ProductField/ProductField.js +272 -0
- package/dist/web/ProductField/ProductField.mjs +273 -0
- package/dist/web/ProductField/arrow-up.svg.js +3 -0
- package/dist/web/ProductField/arrow-up.svg.mjs +4 -0
- package/dist/web/ProductField/checkbox-no.svg.js +3 -0
- package/dist/web/ProductField/checkbox-no.svg.mjs +4 -0
- package/dist/web/ProductField/checkbox-ok.svg.js +3 -0
- package/dist/web/ProductField/checkbox-ok.svg.mjs +4 -0
- package/dist/web/ProductField/no_data_light.svg.js +3 -0
- package/dist/web/ProductField/no_data_light.svg.mjs +4 -0
- package/dist/web/ProductField/search.svg.js +3 -0
- package/dist/web/ProductField/search.svg.mjs +4 -0
- package/dist/web/ProductField/sort.svg.js +3 -0
- package/dist/web/ProductField/sort.svg.mjs +4 -0
- package/dist/web/SkuInputCard/SkuInputCard.js +276 -0
- package/dist/web/SkuInputCard/SkuInputCard.mjs +277 -0
- package/dist/web/SkuInputCard/spin_loading_red.gif.js +3 -0
- package/dist/web/SkuInputCard/spin_loading_red.gif.mjs +4 -0
- package/dist/web/Switch/Switch.js +70 -0
- package/dist/web/Switch/Switch.mjs +71 -0
- package/dist/web/Table/BTable.js +950 -0
- package/dist/web/Table/BTable.mjs +950 -0
- package/dist/web/Table/Column.js +5 -0
- package/dist/web/Table/Column.mjs +6 -0
- package/dist/web/Table/ColumnGroup.js +5 -0
- package/dist/web/Table/ColumnGroup.mjs +6 -0
- package/dist/web/Table/utils/columns.js +48 -0
- package/dist/web/Table/utils/columns.mjs +48 -0
- package/dist/web/Table/utils/sortFilter.js +84 -0
- package/dist/web/Table/utils/sortFilter.mjs +84 -0
- package/dist/web/Tabs/BTabs.js +150 -0
- package/dist/web/Tabs/BTabs.mjs +150 -0
- package/dist/web/Tabs/TabPane.js +8 -0
- package/dist/web/Tabs/TabPane.mjs +8 -0
- package/dist/web/Tooltip/ConfirmTooltip.js +26 -0
- package/dist/web/Tooltip/ConfirmTooltip.mjs +27 -0
- package/dist/web/Tooltip/ContentTooltip.js +94 -0
- package/dist/web/Tooltip/ContentTooltip.mjs +95 -0
- package/dist/web/Tooltip/ProgressTooltip.js +36 -0
- package/dist/web/Tooltip/ProgressTooltip.mjs +37 -0
- package/dist/web/Tooltip/TooltipWrapper.js +12 -0
- package/dist/web/Tooltip/TooltipWrapper.mjs +13 -0
- package/dist/web/Tooltip/useAutoPlacement.js +41 -0
- package/dist/web/Tooltip/useAutoPlacement.mjs +41 -0
- package/dist/web.d.ts +1141 -0
- package/dist/web.js +51 -0
- package/dist/web.mjs +51 -0
- package/package.json +1 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const sortImg = "data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M10.3576%2017.528C10.3576%2017.7887%2010.1444%2018%209.88136%2018C9.61835%2018%209.40513%2017.7887%209.40513%2017.528V7.58313L6.67551%2010.8295C6.50712%2011.0297%206.20676%2011.0568%206.00473%2010.8899C5.80272%2010.723%205.77545%2010.4254%205.9438%2010.2251L9.23476%206.31136C9.61494%205.85923%2010.3575%206.12565%2010.3576%206.71418V17.528ZM17.9981%2013.1613C18.1989%2013.3296%2018.2239%2013.6275%2018.0541%2013.8265L14.683%2017.7758C14.3009%2018.2233%2013.5632%2017.9556%2013.5632%2017.3694V6.47196C13.5632%206.21131%2013.7765%206.00001%2014.0395%206C14.3025%206%2014.5157%206.2113%2014.5157%206.47196V16.5101L17.327%2013.2169C17.4969%2013.0179%2017.7973%2012.993%2017.9981%2013.1613Z'%20fill='%23333333'/%3e%3cpath%20d='M10.3576%2017.528C10.3576%2017.7887%2010.1444%2018%209.88136%2018C9.61835%2018%209.40513%2017.7887%209.40513%2017.528V7.58313L6.67551%2010.8295C6.50712%2011.0297%206.20676%2011.0568%206.00473%2010.8899C5.80272%2010.723%205.77545%2010.4254%205.9438%2010.2251L9.23476%206.31136C9.61494%205.85923%2010.3575%206.12565%2010.3576%206.71418V17.528ZM17.9981%2013.1613C18.1989%2013.3296%2018.2239%2013.6275%2018.0541%2013.8265L14.683%2017.7758C14.3009%2018.2233%2013.5632%2017.9556%2013.5632%2017.3694V6.47196C13.5632%206.21131%2013.7765%206.00001%2014.0395%206C14.3025%206%2014.5157%206.2113%2014.5157%206.47196V16.5101L17.327%2013.2169C17.4969%2013.0179%2017.7973%2012.993%2017.9981%2013.1613Z'%20fill='black'%20fill-opacity='0.2'/%3e%3c/svg%3e";
|
|
2
|
+
export {
|
|
3
|
+
sortImg as default
|
|
4
|
+
};
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const react = require("react");
|
|
4
|
+
;/* empty css */
|
|
5
|
+
const spin_loading_red = require("./spin_loading_red.gif.js");
|
|
6
|
+
function DragIcon() {
|
|
7
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12.8333 8.66683H16.1666V5.3335H12.8333M12.8333 13.6668H16.1666V10.3335H12.8333M7.83331 13.6668H11.1666V10.3335H7.83331M7.83331 18.6668H11.1666V15.3335H7.83331M12.8333 18.6668H16.1666V15.3335H12.8333M7.83331 8.66683H11.1666V5.3335H7.83331V8.66683Z", fill: "currentColor" }) });
|
|
8
|
+
}
|
|
9
|
+
function DeleteIcon() {
|
|
10
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M14.1667 5.3335C15.1792 5.3335 16 6.15431 16 7.16683V8.00016H19C19.2761 8.00016 19.5 8.22402 19.5 8.50016C19.5 8.7763 19.2761 9.00016 19 9.00016H17.3333V16.8335C17.3333 17.846 16.5125 18.6668 15.5 18.6668H8.5C7.48748 18.6668 6.66667 17.846 6.66667 16.8335V9.00016H5C4.72386 9.00016 4.5 8.7763 4.5 8.50016C4.5 8.22402 4.72386 8.00016 5 8.00016H8V7.16683C8 6.15431 8.82081 5.3335 9.83333 5.3335H14.1667ZM7.66667 16.8335C7.66667 17.2937 8.03976 17.6668 8.5 17.6668H15.5C15.9602 17.6668 16.3333 17.2937 16.3333 16.8335V9.00016H7.66667V16.8335ZM10.5 11.3335C10.7761 11.3335 11 11.5574 11 11.8335V15.0002C11 15.2763 10.7761 15.5002 10.5 15.5002C10.2239 15.5002 10 15.2763 10 15.0002V11.8335C10 11.5574 10.2239 11.3335 10.5 11.3335ZM13.5 11.3335C13.7761 11.3335 14 11.5574 14 11.8335V15.0002C14 15.2763 13.7761 15.5002 13.5 15.5002C13.2239 15.5002 13 15.2763 13 15.0002V11.8335C13 11.5574 13.2239 11.3335 13.5 11.3335ZM9.83333 6.3335C9.3731 6.3335 9 6.70659 9 7.16683V8.00016H15V7.16683C15 6.70659 14.6269 6.3335 14.1667 6.3335H9.83333Z", fill: "currentColor" }) });
|
|
11
|
+
}
|
|
12
|
+
function AddIcon() {
|
|
13
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 1024 1024", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M515.512889 227.555556a21.070222 21.070222 0 0 1 21.070222 21.070222v245.816889h238.791111a21.070222 21.070222 0 0 1 0 42.140444h-238.791111v238.791111a21.070222 21.070222 0 0 1-42.140444 0v-238.791111H248.625778a21.070222 21.070222 0 0 1 0-42.140444h245.816889V248.625778A21.070222 21.070222 0 0 1 515.512889 227.555556z", fill: "currentColor" }) });
|
|
14
|
+
}
|
|
15
|
+
function PreviewThinIcon() {
|
|
16
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "32", height: "32", viewBox: "0 0 32 32", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
|
|
17
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8.68576 19.3333C9.0645 19.3333 9.37153 19.6404 9.37153 20.0191V22.1714C9.37153 22.4239 9.5761 22.6285 9.82856 22.6285H11.9809C12.3596 22.6285 12.6667 22.9355 12.6667 23.3142C12.6667 23.693 12.3596 24 11.9809 24H9.82856L9.73438 23.9976C8.79946 23.9502 8.04983 23.2005 8.00239 22.2656L8 22.1714V20.0191C8 19.6404 8.30703 19.3333 8.68576 19.3333Z", fill: "currentColor" }),
|
|
18
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M23.3142 19.3333C23.693 19.3333 24 19.6404 24 20.0191V22.1714C24 23.1497 23.2317 23.9486 22.2656 23.9976L22.1714 24H20.0191C19.6404 24 19.3333 23.693 19.3333 23.3142C19.3333 22.9355 19.6404 22.6285 20.0191 22.6285H22.1714C22.4239 22.6285 22.6285 22.4239 22.6285 22.1714V20.0191C22.6285 19.6404 22.9355 19.3333 23.3142 19.3333Z", fill: "currentColor" }),
|
|
19
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M15.5573 11.2413C17.8315 11.2989 19.6575 13.1607 19.6576 15.4488L19.656 15.5573C19.6337 16.4372 19.3411 17.2497 18.8585 17.9156L20.5647 19.6217C20.825 19.8821 20.825 20.3043 20.5647 20.5647C20.3043 20.825 19.8823 20.825 19.622 20.5647L17.9156 18.8585C17.2224 19.3609 16.3703 19.6575 15.4488 19.6576L15.3401 19.656C13.102 19.5993 11.298 17.7954 11.2413 15.5573L11.24 15.4488C11.24 13.1244 13.1244 11.24 15.4488 11.24L15.5573 11.2413ZM15.4488 12.5734C13.8608 12.5734 12.5734 13.8608 12.5734 15.4488C12.5734 17.0368 13.8608 18.3242 15.4488 18.3242C17.0368 18.3242 18.3242 17.0368 18.3242 15.4488C18.3242 13.8608 17.0368 12.5734 15.4488 12.5734Z", fill: "currentColor" }),
|
|
20
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M11.9809 8C12.3596 8 12.6667 8.30703 12.6667 8.68576C12.6667 9.0645 12.3596 9.37153 11.9809 9.37153H9.82856C9.5761 9.37153 9.37153 9.5761 9.37153 9.82856V11.9809C9.37153 12.3596 9.0645 12.6667 8.68576 12.6667C8.30703 12.6667 8 12.3596 8 11.9809V9.82856C8.00001 8.81868 8.81868 8.00001 9.82856 8H11.9809Z", fill: "currentColor" }),
|
|
21
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M22.1714 8C23.1813 8.00001 24 8.81868 24 9.82856V11.9809C24 12.3596 23.693 12.6667 23.3142 12.6667C22.9355 12.6667 22.6285 12.3596 22.6285 11.9809V9.82856C22.6285 9.5761 22.4239 9.37153 22.1714 9.37153H20.0191C19.6404 9.37153 19.3333 9.0645 19.3333 8.68576C19.3333 8.30703 19.6404 8 20.0191 8H22.1714Z", fill: "currentColor" })
|
|
22
|
+
] });
|
|
23
|
+
}
|
|
24
|
+
function DeleteThinIcon() {
|
|
25
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M14.1667 5.3335C15.1792 5.3335 16 6.15431 16 7.16683V8.00016H19C19.2761 8.00016 19.5 8.22402 19.5 8.50016C19.5 8.7763 19.2761 9.00016 19 9.00016H17.3333V16.8335C17.3333 17.846 16.5125 18.6668 15.5 18.6668H8.5C7.48748 18.6668 6.66667 17.846 6.66667 16.8335V9.00016H5C4.72386 9.00016 4.5 8.7763 4.5 8.50016C4.5 8.22402 4.72386 8.00016 5 8.00016H8V7.16683C8 6.15431 8.82081 5.3335 9.83333 5.3335H14.1667ZM7.66667 16.8335C7.66667 17.2937 8.03976 17.6668 8.5 17.6668H15.5C15.9602 17.6668 16.3333 17.2937 16.3333 16.8335V9.00016H7.66667V16.8335ZM10.5 11.3335C10.7761 11.3335 11 11.5574 11 11.8335V15.0002C11 15.2763 10.7761 15.5002 10.5 15.5002C10.2239 15.5002 10 15.2763 10 15.0002V11.8335C10 11.5574 10.2239 11.3335 10.5 11.3335ZM13.5 11.3335C13.7761 11.3335 14 11.5574 14 11.8335V15.0002C14 15.2763 13.7761 15.5002 13.5 15.5002C13.2239 15.5002 13 15.2763 13 15.0002V11.8335C13 11.5574 13.2239 11.3335 13.5 11.3335ZM9.83333 6.3335C9.3731 6.3335 9 6.70659 9 7.16683V8.00016H15V7.16683C15 6.70659 14.6269 6.3335 14.1667 6.3335H9.83333Z", fill: "currentColor" }) });
|
|
26
|
+
}
|
|
27
|
+
function defaultFilter(option, input) {
|
|
28
|
+
const label = typeof option.label === "string" ? option.label : option.value;
|
|
29
|
+
return label.toLowerCase().includes(input.toLowerCase());
|
|
30
|
+
}
|
|
31
|
+
function HighlightText({ text, keyword }) {
|
|
32
|
+
if (!keyword) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: text });
|
|
33
|
+
const idx = text.toLowerCase().indexOf(keyword.toLowerCase());
|
|
34
|
+
if (idx === -1) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: text });
|
|
35
|
+
const before = text.slice(0, idx);
|
|
36
|
+
const match = text.slice(idx, idx + keyword.length);
|
|
37
|
+
const after = text.slice(idx + keyword.length);
|
|
38
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
39
|
+
before,
|
|
40
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sku-input-card__dropdown-highlight", children: match }),
|
|
41
|
+
after
|
|
42
|
+
] });
|
|
43
|
+
}
|
|
44
|
+
function SkuInputCard({
|
|
45
|
+
id,
|
|
46
|
+
name = "",
|
|
47
|
+
onNameChange,
|
|
48
|
+
mode = "single",
|
|
49
|
+
activeLang = "zh",
|
|
50
|
+
onLangChange,
|
|
51
|
+
showBody = true,
|
|
52
|
+
error = false,
|
|
53
|
+
onDelete,
|
|
54
|
+
onPreviewImage,
|
|
55
|
+
onDeleteImage,
|
|
56
|
+
onUpload,
|
|
57
|
+
onAssociate,
|
|
58
|
+
images,
|
|
59
|
+
labels,
|
|
60
|
+
inputEvents,
|
|
61
|
+
className,
|
|
62
|
+
style,
|
|
63
|
+
options,
|
|
64
|
+
optionFilterProp,
|
|
65
|
+
onSelect,
|
|
66
|
+
onSearch,
|
|
67
|
+
open: controlledOpen,
|
|
68
|
+
onDropdownVisibleChange
|
|
69
|
+
}) {
|
|
70
|
+
const namePlaceholder = (labels == null ? void 0 : labels.namePlaceholder) ?? "请填写产品名称";
|
|
71
|
+
const uploadLocalLabel = (labels == null ? void 0 : labels.uploadLocal) ?? "本地上传";
|
|
72
|
+
const associateImageLabel = (labels == null ? void 0 : labels.associateImage) ?? "关联图片";
|
|
73
|
+
const fileInputRef = react.useRef(null);
|
|
74
|
+
const uploadOptionsRef = react.useRef(null);
|
|
75
|
+
const dropdownRef = react.useRef(null);
|
|
76
|
+
const nameWrapRef = react.useRef(null);
|
|
77
|
+
const [localImages, setLocalImages] = react.useState([]);
|
|
78
|
+
const [showUploadOptions, setShowUploadOptions] = react.useState(false);
|
|
79
|
+
const [internalDropdownOpen, setInternalDropdownOpen] = react.useState(false);
|
|
80
|
+
const [uploading, setUploading] = react.useState(false);
|
|
81
|
+
const hasOptions = Array.isArray(options) && options.length > 0;
|
|
82
|
+
const dropdownOpen = controlledOpen !== void 0 ? controlledOpen : hasOptions && internalDropdownOpen;
|
|
83
|
+
const filteredOptions = hasOptions ? name ? options.filter(
|
|
84
|
+
(o) => optionFilterProp ? optionFilterProp(o, name) : defaultFilter(o, name)
|
|
85
|
+
) : options : [];
|
|
86
|
+
react.useEffect(() => {
|
|
87
|
+
if (!showUploadOptions) return;
|
|
88
|
+
function handleMouseDown(e) {
|
|
89
|
+
if (uploadOptionsRef.current && !uploadOptionsRef.current.contains(e.target)) {
|
|
90
|
+
setShowUploadOptions(false);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
94
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
95
|
+
}, [showUploadOptions]);
|
|
96
|
+
react.useEffect(() => {
|
|
97
|
+
if (!dropdownOpen) return;
|
|
98
|
+
function handleMouseDown(e) {
|
|
99
|
+
var _a, _b;
|
|
100
|
+
const target = e.target;
|
|
101
|
+
if (((_a = dropdownRef.current) == null ? void 0 : _a.contains(target)) || ((_b = nameWrapRef.current) == null ? void 0 : _b.contains(target))) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
setInternalDropdownOpen(false);
|
|
105
|
+
onDropdownVisibleChange == null ? void 0 : onDropdownVisibleChange(false);
|
|
106
|
+
}
|
|
107
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
108
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
109
|
+
}, [dropdownOpen, onDropdownVisibleChange]);
|
|
110
|
+
const displayImages = images ?? localImages;
|
|
111
|
+
async function handleFileChange(e) {
|
|
112
|
+
var _a;
|
|
113
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
114
|
+
if (!file) return;
|
|
115
|
+
e.target.value = "";
|
|
116
|
+
setShowUploadOptions(false);
|
|
117
|
+
setUploading(true);
|
|
118
|
+
try {
|
|
119
|
+
if (onUpload) {
|
|
120
|
+
const url = await onUpload(file);
|
|
121
|
+
if (url && images === void 0) {
|
|
122
|
+
setLocalImages((prev) => [...prev, url]);
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
const url = URL.createObjectURL(file);
|
|
126
|
+
setLocalImages((prev) => [...prev, url]);
|
|
127
|
+
}
|
|
128
|
+
} finally {
|
|
129
|
+
setUploading(false);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function handleLocalUpload() {
|
|
133
|
+
var _a;
|
|
134
|
+
(_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
135
|
+
}
|
|
136
|
+
function handleAssociate() {
|
|
137
|
+
setShowUploadOptions(false);
|
|
138
|
+
onAssociate == null ? void 0 : onAssociate();
|
|
139
|
+
}
|
|
140
|
+
const cardCls = [
|
|
141
|
+
"sku-input-card",
|
|
142
|
+
error && "sku-input-card--error",
|
|
143
|
+
className
|
|
144
|
+
].filter(Boolean).join(" ");
|
|
145
|
+
const inputCls = [
|
|
146
|
+
"sku-input-card__name-input",
|
|
147
|
+
mode === "bilingual" && "sku-input-card__name-input--with-toggle",
|
|
148
|
+
error && "sku-input-card__name-input--error"
|
|
149
|
+
].filter(Boolean).join(" ");
|
|
150
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cardCls, style, children: [
|
|
151
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sku-input-card__drag", id, children: /* @__PURE__ */ jsxRuntime.jsx(DragIcon, {}) }),
|
|
152
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sku-input-card__main", children: [
|
|
153
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sku-input-card__header", children: [
|
|
154
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sku-input-card__name-wrap", ref: nameWrapRef, children: [
|
|
155
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
156
|
+
"input",
|
|
157
|
+
{
|
|
158
|
+
className: inputCls,
|
|
159
|
+
value: name,
|
|
160
|
+
onChange: (e) => {
|
|
161
|
+
onNameChange == null ? void 0 : onNameChange(e.target.value);
|
|
162
|
+
onSearch == null ? void 0 : onSearch(e.target.value);
|
|
163
|
+
},
|
|
164
|
+
onFocus: () => {
|
|
165
|
+
if (hasOptions && controlledOpen === void 0) {
|
|
166
|
+
setInternalDropdownOpen(true);
|
|
167
|
+
onDropdownVisibleChange == null ? void 0 : onDropdownVisibleChange(true);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
placeholder: namePlaceholder,
|
|
171
|
+
...inputEvents
|
|
172
|
+
}
|
|
173
|
+
),
|
|
174
|
+
dropdownOpen && filteredOptions.length > 0 && /* 绝对定位锚定在 name-wrap(position: relative)下方,随输入框跟随滚动/视口变化。
|
|
175
|
+
不再用 portal + position:fixed + getBoundingClientRect 定位:iOS 软键盘弹出时
|
|
176
|
+
fixed 与 getBoundingClientRect 的视口基准不一致,会导致下拉框位置偏移。 */
|
|
177
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sku-input-card__dropdown", ref: dropdownRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sku-input-card__dropdown-list", children: filteredOptions.map((opt) => {
|
|
178
|
+
const label = typeof opt.label === "string" ? opt.label : opt.value;
|
|
179
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
180
|
+
"div",
|
|
181
|
+
{
|
|
182
|
+
className: [
|
|
183
|
+
"sku-input-card__dropdown-item",
|
|
184
|
+
opt.disabled && "sku-input-card__dropdown-item--disabled",
|
|
185
|
+
opt.value === name && "sku-input-card__dropdown-item--selected"
|
|
186
|
+
].filter(Boolean).join(" "),
|
|
187
|
+
onMouseDown: (e) => {
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
if (opt.disabled) return;
|
|
190
|
+
onNameChange == null ? void 0 : onNameChange(opt.value);
|
|
191
|
+
onSelect == null ? void 0 : onSelect(opt.value, opt);
|
|
192
|
+
setInternalDropdownOpen(false);
|
|
193
|
+
onDropdownVisibleChange == null ? void 0 : onDropdownVisibleChange(false);
|
|
194
|
+
},
|
|
195
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(HighlightText, { text: label, keyword: name })
|
|
196
|
+
},
|
|
197
|
+
opt.value
|
|
198
|
+
);
|
|
199
|
+
}) }) }),
|
|
200
|
+
mode === "bilingual" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sku-input-card__lang-toggle", children: [
|
|
201
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
202
|
+
"button",
|
|
203
|
+
{
|
|
204
|
+
className: `sku-input-card__lang-btn sku-input-card__lang-btn--${activeLang === "zh" ? "active" : "inactive"}`,
|
|
205
|
+
onClick: () => onLangChange == null ? void 0 : onLangChange("zh"),
|
|
206
|
+
children: "中文"
|
|
207
|
+
}
|
|
208
|
+
),
|
|
209
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
210
|
+
"button",
|
|
211
|
+
{
|
|
212
|
+
className: `sku-input-card__lang-btn sku-input-card__lang-btn--${activeLang === "en" ? "active" : "inactive"}`,
|
|
213
|
+
onClick: () => onLangChange == null ? void 0 : onLangChange("en"),
|
|
214
|
+
children: "EN"
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
] })
|
|
218
|
+
] }),
|
|
219
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { className: "sku-input-card__delete", onClick: onDelete, children: /* @__PURE__ */ jsxRuntime.jsx(DeleteIcon, {}) })
|
|
220
|
+
] }),
|
|
221
|
+
showBody && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sku-input-card__body", children: [
|
|
222
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
223
|
+
"input",
|
|
224
|
+
{
|
|
225
|
+
ref: fileInputRef,
|
|
226
|
+
type: "file",
|
|
227
|
+
accept: "image/jpeg,image/png,image/webp",
|
|
228
|
+
className: "sku-input-card__file-input",
|
|
229
|
+
onChange: handleFileChange
|
|
230
|
+
}
|
|
231
|
+
),
|
|
232
|
+
uploading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sku-input-card__loading", children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: spin_loading_red, alt: "上传中", className: "sku-input-card__loading-img" }) }) : displayImages[0] ? (
|
|
233
|
+
/* Single image preview */
|
|
234
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sku-input-card__image-item", children: [
|
|
235
|
+
/* @__PURE__ */ jsxRuntime.jsx("img", { src: displayImages[0], alt: "图片", className: "sku-input-card__image-thumb" }),
|
|
236
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sku-input-card__image-overlay", children: [
|
|
237
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
238
|
+
"button",
|
|
239
|
+
{
|
|
240
|
+
className: "sku-input-card__image-action-btn",
|
|
241
|
+
onClick: () => onPreviewImage == null ? void 0 : onPreviewImage(displayImages[0]),
|
|
242
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(PreviewThinIcon, {})
|
|
243
|
+
}
|
|
244
|
+
),
|
|
245
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
246
|
+
"button",
|
|
247
|
+
{
|
|
248
|
+
className: "sku-input-card__image-action-btn",
|
|
249
|
+
onClick: () => onDeleteImage == null ? void 0 : onDeleteImage(displayImages[0]),
|
|
250
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(DeleteThinIcon, {})
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
] })
|
|
254
|
+
] })
|
|
255
|
+
) : showUploadOptions ? (
|
|
256
|
+
/* Upload options — local upload / associate image */
|
|
257
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sku-input-card__upload-options", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: uploadOptionsRef, className: "sku-input-card__upload-options-box", children: [
|
|
258
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { className: "sku-input-card__upload-opt-btn", onClick: handleLocalUpload, children: uploadLocalLabel }),
|
|
259
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { className: "sku-input-card__upload-opt-btn", onClick: handleAssociate, children: associateImageLabel })
|
|
260
|
+
] }) })
|
|
261
|
+
) : (
|
|
262
|
+
/* Large add button — fills the body */
|
|
263
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
264
|
+
"button",
|
|
265
|
+
{
|
|
266
|
+
className: "sku-input-card__add-btn",
|
|
267
|
+
onClick: () => setShowUploadOptions(true),
|
|
268
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AddIcon, {})
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
)
|
|
272
|
+
] })
|
|
273
|
+
] })
|
|
274
|
+
] });
|
|
275
|
+
}
|
|
276
|
+
module.exports = SkuInputCard;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useEffect } from "react";
|
|
3
|
+
/* empty css */
|
|
4
|
+
import loadingIndicator from "./spin_loading_red.gif.mjs";
|
|
5
|
+
function DragIcon() {
|
|
6
|
+
return /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M12.8333 8.66683H16.1666V5.3335H12.8333M12.8333 13.6668H16.1666V10.3335H12.8333M7.83331 13.6668H11.1666V10.3335H7.83331M7.83331 18.6668H11.1666V15.3335H7.83331M12.8333 18.6668H16.1666V15.3335H12.8333M7.83331 8.66683H11.1666V5.3335H7.83331V8.66683Z", fill: "currentColor" }) });
|
|
7
|
+
}
|
|
8
|
+
function DeleteIcon() {
|
|
9
|
+
return /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M14.1667 5.3335C15.1792 5.3335 16 6.15431 16 7.16683V8.00016H19C19.2761 8.00016 19.5 8.22402 19.5 8.50016C19.5 8.7763 19.2761 9.00016 19 9.00016H17.3333V16.8335C17.3333 17.846 16.5125 18.6668 15.5 18.6668H8.5C7.48748 18.6668 6.66667 17.846 6.66667 16.8335V9.00016H5C4.72386 9.00016 4.5 8.7763 4.5 8.50016C4.5 8.22402 4.72386 8.00016 5 8.00016H8V7.16683C8 6.15431 8.82081 5.3335 9.83333 5.3335H14.1667ZM7.66667 16.8335C7.66667 17.2937 8.03976 17.6668 8.5 17.6668H15.5C15.9602 17.6668 16.3333 17.2937 16.3333 16.8335V9.00016H7.66667V16.8335ZM10.5 11.3335C10.7761 11.3335 11 11.5574 11 11.8335V15.0002C11 15.2763 10.7761 15.5002 10.5 15.5002C10.2239 15.5002 10 15.2763 10 15.0002V11.8335C10 11.5574 10.2239 11.3335 10.5 11.3335ZM13.5 11.3335C13.7761 11.3335 14 11.5574 14 11.8335V15.0002C14 15.2763 13.7761 15.5002 13.5 15.5002C13.2239 15.5002 13 15.2763 13 15.0002V11.8335C13 11.5574 13.2239 11.3335 13.5 11.3335ZM9.83333 6.3335C9.3731 6.3335 9 6.70659 9 7.16683V8.00016H15V7.16683C15 6.70659 14.6269 6.3335 14.1667 6.3335H9.83333Z", fill: "currentColor" }) });
|
|
10
|
+
}
|
|
11
|
+
function AddIcon() {
|
|
12
|
+
return /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 1024 1024", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M515.512889 227.555556a21.070222 21.070222 0 0 1 21.070222 21.070222v245.816889h238.791111a21.070222 21.070222 0 0 1 0 42.140444h-238.791111v238.791111a21.070222 21.070222 0 0 1-42.140444 0v-238.791111H248.625778a21.070222 21.070222 0 0 1 0-42.140444h245.816889V248.625778A21.070222 21.070222 0 0 1 515.512889 227.555556z", fill: "currentColor" }) });
|
|
13
|
+
}
|
|
14
|
+
function PreviewThinIcon() {
|
|
15
|
+
return /* @__PURE__ */ jsxs("svg", { width: "32", height: "32", viewBox: "0 0 32 32", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
|
|
16
|
+
/* @__PURE__ */ jsx("path", { d: "M8.68576 19.3333C9.0645 19.3333 9.37153 19.6404 9.37153 20.0191V22.1714C9.37153 22.4239 9.5761 22.6285 9.82856 22.6285H11.9809C12.3596 22.6285 12.6667 22.9355 12.6667 23.3142C12.6667 23.693 12.3596 24 11.9809 24H9.82856L9.73438 23.9976C8.79946 23.9502 8.04983 23.2005 8.00239 22.2656L8 22.1714V20.0191C8 19.6404 8.30703 19.3333 8.68576 19.3333Z", fill: "currentColor" }),
|
|
17
|
+
/* @__PURE__ */ jsx("path", { d: "M23.3142 19.3333C23.693 19.3333 24 19.6404 24 20.0191V22.1714C24 23.1497 23.2317 23.9486 22.2656 23.9976L22.1714 24H20.0191C19.6404 24 19.3333 23.693 19.3333 23.3142C19.3333 22.9355 19.6404 22.6285 20.0191 22.6285H22.1714C22.4239 22.6285 22.6285 22.4239 22.6285 22.1714V20.0191C22.6285 19.6404 22.9355 19.3333 23.3142 19.3333Z", fill: "currentColor" }),
|
|
18
|
+
/* @__PURE__ */ jsx("path", { d: "M15.5573 11.2413C17.8315 11.2989 19.6575 13.1607 19.6576 15.4488L19.656 15.5573C19.6337 16.4372 19.3411 17.2497 18.8585 17.9156L20.5647 19.6217C20.825 19.8821 20.825 20.3043 20.5647 20.5647C20.3043 20.825 19.8823 20.825 19.622 20.5647L17.9156 18.8585C17.2224 19.3609 16.3703 19.6575 15.4488 19.6576L15.3401 19.656C13.102 19.5993 11.298 17.7954 11.2413 15.5573L11.24 15.4488C11.24 13.1244 13.1244 11.24 15.4488 11.24L15.5573 11.2413ZM15.4488 12.5734C13.8608 12.5734 12.5734 13.8608 12.5734 15.4488C12.5734 17.0368 13.8608 18.3242 15.4488 18.3242C17.0368 18.3242 18.3242 17.0368 18.3242 15.4488C18.3242 13.8608 17.0368 12.5734 15.4488 12.5734Z", fill: "currentColor" }),
|
|
19
|
+
/* @__PURE__ */ jsx("path", { d: "M11.9809 8C12.3596 8 12.6667 8.30703 12.6667 8.68576C12.6667 9.0645 12.3596 9.37153 11.9809 9.37153H9.82856C9.5761 9.37153 9.37153 9.5761 9.37153 9.82856V11.9809C9.37153 12.3596 9.0645 12.6667 8.68576 12.6667C8.30703 12.6667 8 12.3596 8 11.9809V9.82856C8.00001 8.81868 8.81868 8.00001 9.82856 8H11.9809Z", fill: "currentColor" }),
|
|
20
|
+
/* @__PURE__ */ jsx("path", { d: "M22.1714 8C23.1813 8.00001 24 8.81868 24 9.82856V11.9809C24 12.3596 23.693 12.6667 23.3142 12.6667C22.9355 12.6667 22.6285 12.3596 22.6285 11.9809V9.82856C22.6285 9.5761 22.4239 9.37153 22.1714 9.37153H20.0191C19.6404 9.37153 19.3333 9.0645 19.3333 8.68576C19.3333 8.30703 19.6404 8 20.0191 8H22.1714Z", fill: "currentColor" })
|
|
21
|
+
] });
|
|
22
|
+
}
|
|
23
|
+
function DeleteThinIcon() {
|
|
24
|
+
return /* @__PURE__ */ jsx("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M14.1667 5.3335C15.1792 5.3335 16 6.15431 16 7.16683V8.00016H19C19.2761 8.00016 19.5 8.22402 19.5 8.50016C19.5 8.7763 19.2761 9.00016 19 9.00016H17.3333V16.8335C17.3333 17.846 16.5125 18.6668 15.5 18.6668H8.5C7.48748 18.6668 6.66667 17.846 6.66667 16.8335V9.00016H5C4.72386 9.00016 4.5 8.7763 4.5 8.50016C4.5 8.22402 4.72386 8.00016 5 8.00016H8V7.16683C8 6.15431 8.82081 5.3335 9.83333 5.3335H14.1667ZM7.66667 16.8335C7.66667 17.2937 8.03976 17.6668 8.5 17.6668H15.5C15.9602 17.6668 16.3333 17.2937 16.3333 16.8335V9.00016H7.66667V16.8335ZM10.5 11.3335C10.7761 11.3335 11 11.5574 11 11.8335V15.0002C11 15.2763 10.7761 15.5002 10.5 15.5002C10.2239 15.5002 10 15.2763 10 15.0002V11.8335C10 11.5574 10.2239 11.3335 10.5 11.3335ZM13.5 11.3335C13.7761 11.3335 14 11.5574 14 11.8335V15.0002C14 15.2763 13.7761 15.5002 13.5 15.5002C13.2239 15.5002 13 15.2763 13 15.0002V11.8335C13 11.5574 13.2239 11.3335 13.5 11.3335ZM9.83333 6.3335C9.3731 6.3335 9 6.70659 9 7.16683V8.00016H15V7.16683C15 6.70659 14.6269 6.3335 14.1667 6.3335H9.83333Z", fill: "currentColor" }) });
|
|
25
|
+
}
|
|
26
|
+
function defaultFilter(option, input) {
|
|
27
|
+
const label = typeof option.label === "string" ? option.label : option.value;
|
|
28
|
+
return label.toLowerCase().includes(input.toLowerCase());
|
|
29
|
+
}
|
|
30
|
+
function HighlightText({ text, keyword }) {
|
|
31
|
+
if (!keyword) return /* @__PURE__ */ jsx(Fragment, { children: text });
|
|
32
|
+
const idx = text.toLowerCase().indexOf(keyword.toLowerCase());
|
|
33
|
+
if (idx === -1) return /* @__PURE__ */ jsx(Fragment, { children: text });
|
|
34
|
+
const before = text.slice(0, idx);
|
|
35
|
+
const match = text.slice(idx, idx + keyword.length);
|
|
36
|
+
const after = text.slice(idx + keyword.length);
|
|
37
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
38
|
+
before,
|
|
39
|
+
/* @__PURE__ */ jsx("span", { className: "sku-input-card__dropdown-highlight", children: match }),
|
|
40
|
+
after
|
|
41
|
+
] });
|
|
42
|
+
}
|
|
43
|
+
function SkuInputCard({
|
|
44
|
+
id,
|
|
45
|
+
name = "",
|
|
46
|
+
onNameChange,
|
|
47
|
+
mode = "single",
|
|
48
|
+
activeLang = "zh",
|
|
49
|
+
onLangChange,
|
|
50
|
+
showBody = true,
|
|
51
|
+
error = false,
|
|
52
|
+
onDelete,
|
|
53
|
+
onPreviewImage,
|
|
54
|
+
onDeleteImage,
|
|
55
|
+
onUpload,
|
|
56
|
+
onAssociate,
|
|
57
|
+
images,
|
|
58
|
+
labels,
|
|
59
|
+
inputEvents,
|
|
60
|
+
className,
|
|
61
|
+
style,
|
|
62
|
+
options,
|
|
63
|
+
optionFilterProp,
|
|
64
|
+
onSelect,
|
|
65
|
+
onSearch,
|
|
66
|
+
open: controlledOpen,
|
|
67
|
+
onDropdownVisibleChange
|
|
68
|
+
}) {
|
|
69
|
+
const namePlaceholder = (labels == null ? void 0 : labels.namePlaceholder) ?? "请填写产品名称";
|
|
70
|
+
const uploadLocalLabel = (labels == null ? void 0 : labels.uploadLocal) ?? "本地上传";
|
|
71
|
+
const associateImageLabel = (labels == null ? void 0 : labels.associateImage) ?? "关联图片";
|
|
72
|
+
const fileInputRef = useRef(null);
|
|
73
|
+
const uploadOptionsRef = useRef(null);
|
|
74
|
+
const dropdownRef = useRef(null);
|
|
75
|
+
const nameWrapRef = useRef(null);
|
|
76
|
+
const [localImages, setLocalImages] = useState([]);
|
|
77
|
+
const [showUploadOptions, setShowUploadOptions] = useState(false);
|
|
78
|
+
const [internalDropdownOpen, setInternalDropdownOpen] = useState(false);
|
|
79
|
+
const [uploading, setUploading] = useState(false);
|
|
80
|
+
const hasOptions = Array.isArray(options) && options.length > 0;
|
|
81
|
+
const dropdownOpen = controlledOpen !== void 0 ? controlledOpen : hasOptions && internalDropdownOpen;
|
|
82
|
+
const filteredOptions = hasOptions ? name ? options.filter(
|
|
83
|
+
(o) => optionFilterProp ? optionFilterProp(o, name) : defaultFilter(o, name)
|
|
84
|
+
) : options : [];
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (!showUploadOptions) return;
|
|
87
|
+
function handleMouseDown(e) {
|
|
88
|
+
if (uploadOptionsRef.current && !uploadOptionsRef.current.contains(e.target)) {
|
|
89
|
+
setShowUploadOptions(false);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
93
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
94
|
+
}, [showUploadOptions]);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!dropdownOpen) return;
|
|
97
|
+
function handleMouseDown(e) {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
const target = e.target;
|
|
100
|
+
if (((_a = dropdownRef.current) == null ? void 0 : _a.contains(target)) || ((_b = nameWrapRef.current) == null ? void 0 : _b.contains(target))) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
setInternalDropdownOpen(false);
|
|
104
|
+
onDropdownVisibleChange == null ? void 0 : onDropdownVisibleChange(false);
|
|
105
|
+
}
|
|
106
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
107
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
108
|
+
}, [dropdownOpen, onDropdownVisibleChange]);
|
|
109
|
+
const displayImages = images ?? localImages;
|
|
110
|
+
async function handleFileChange(e) {
|
|
111
|
+
var _a;
|
|
112
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
113
|
+
if (!file) return;
|
|
114
|
+
e.target.value = "";
|
|
115
|
+
setShowUploadOptions(false);
|
|
116
|
+
setUploading(true);
|
|
117
|
+
try {
|
|
118
|
+
if (onUpload) {
|
|
119
|
+
const url = await onUpload(file);
|
|
120
|
+
if (url && images === void 0) {
|
|
121
|
+
setLocalImages((prev) => [...prev, url]);
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
const url = URL.createObjectURL(file);
|
|
125
|
+
setLocalImages((prev) => [...prev, url]);
|
|
126
|
+
}
|
|
127
|
+
} finally {
|
|
128
|
+
setUploading(false);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function handleLocalUpload() {
|
|
132
|
+
var _a;
|
|
133
|
+
(_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
134
|
+
}
|
|
135
|
+
function handleAssociate() {
|
|
136
|
+
setShowUploadOptions(false);
|
|
137
|
+
onAssociate == null ? void 0 : onAssociate();
|
|
138
|
+
}
|
|
139
|
+
const cardCls = [
|
|
140
|
+
"sku-input-card",
|
|
141
|
+
error && "sku-input-card--error",
|
|
142
|
+
className
|
|
143
|
+
].filter(Boolean).join(" ");
|
|
144
|
+
const inputCls = [
|
|
145
|
+
"sku-input-card__name-input",
|
|
146
|
+
mode === "bilingual" && "sku-input-card__name-input--with-toggle",
|
|
147
|
+
error && "sku-input-card__name-input--error"
|
|
148
|
+
].filter(Boolean).join(" ");
|
|
149
|
+
return /* @__PURE__ */ jsxs("div", { className: cardCls, style, children: [
|
|
150
|
+
/* @__PURE__ */ jsx("span", { className: "sku-input-card__drag", id, children: /* @__PURE__ */ jsx(DragIcon, {}) }),
|
|
151
|
+
/* @__PURE__ */ jsxs("div", { className: "sku-input-card__main", children: [
|
|
152
|
+
/* @__PURE__ */ jsxs("div", { className: "sku-input-card__header", children: [
|
|
153
|
+
/* @__PURE__ */ jsxs("div", { className: "sku-input-card__name-wrap", ref: nameWrapRef, children: [
|
|
154
|
+
/* @__PURE__ */ jsx(
|
|
155
|
+
"input",
|
|
156
|
+
{
|
|
157
|
+
className: inputCls,
|
|
158
|
+
value: name,
|
|
159
|
+
onChange: (e) => {
|
|
160
|
+
onNameChange == null ? void 0 : onNameChange(e.target.value);
|
|
161
|
+
onSearch == null ? void 0 : onSearch(e.target.value);
|
|
162
|
+
},
|
|
163
|
+
onFocus: () => {
|
|
164
|
+
if (hasOptions && controlledOpen === void 0) {
|
|
165
|
+
setInternalDropdownOpen(true);
|
|
166
|
+
onDropdownVisibleChange == null ? void 0 : onDropdownVisibleChange(true);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
placeholder: namePlaceholder,
|
|
170
|
+
...inputEvents
|
|
171
|
+
}
|
|
172
|
+
),
|
|
173
|
+
dropdownOpen && filteredOptions.length > 0 && /* 绝对定位锚定在 name-wrap(position: relative)下方,随输入框跟随滚动/视口变化。
|
|
174
|
+
不再用 portal + position:fixed + getBoundingClientRect 定位:iOS 软键盘弹出时
|
|
175
|
+
fixed 与 getBoundingClientRect 的视口基准不一致,会导致下拉框位置偏移。 */
|
|
176
|
+
/* @__PURE__ */ jsx("div", { className: "sku-input-card__dropdown", ref: dropdownRef, children: /* @__PURE__ */ jsx("div", { className: "sku-input-card__dropdown-list", children: filteredOptions.map((opt) => {
|
|
177
|
+
const label = typeof opt.label === "string" ? opt.label : opt.value;
|
|
178
|
+
return /* @__PURE__ */ jsx(
|
|
179
|
+
"div",
|
|
180
|
+
{
|
|
181
|
+
className: [
|
|
182
|
+
"sku-input-card__dropdown-item",
|
|
183
|
+
opt.disabled && "sku-input-card__dropdown-item--disabled",
|
|
184
|
+
opt.value === name && "sku-input-card__dropdown-item--selected"
|
|
185
|
+
].filter(Boolean).join(" "),
|
|
186
|
+
onMouseDown: (e) => {
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
if (opt.disabled) return;
|
|
189
|
+
onNameChange == null ? void 0 : onNameChange(opt.value);
|
|
190
|
+
onSelect == null ? void 0 : onSelect(opt.value, opt);
|
|
191
|
+
setInternalDropdownOpen(false);
|
|
192
|
+
onDropdownVisibleChange == null ? void 0 : onDropdownVisibleChange(false);
|
|
193
|
+
},
|
|
194
|
+
children: /* @__PURE__ */ jsx(HighlightText, { text: label, keyword: name })
|
|
195
|
+
},
|
|
196
|
+
opt.value
|
|
197
|
+
);
|
|
198
|
+
}) }) }),
|
|
199
|
+
mode === "bilingual" && /* @__PURE__ */ jsxs("div", { className: "sku-input-card__lang-toggle", children: [
|
|
200
|
+
/* @__PURE__ */ jsx(
|
|
201
|
+
"button",
|
|
202
|
+
{
|
|
203
|
+
className: `sku-input-card__lang-btn sku-input-card__lang-btn--${activeLang === "zh" ? "active" : "inactive"}`,
|
|
204
|
+
onClick: () => onLangChange == null ? void 0 : onLangChange("zh"),
|
|
205
|
+
children: "中文"
|
|
206
|
+
}
|
|
207
|
+
),
|
|
208
|
+
/* @__PURE__ */ jsx(
|
|
209
|
+
"button",
|
|
210
|
+
{
|
|
211
|
+
className: `sku-input-card__lang-btn sku-input-card__lang-btn--${activeLang === "en" ? "active" : "inactive"}`,
|
|
212
|
+
onClick: () => onLangChange == null ? void 0 : onLangChange("en"),
|
|
213
|
+
children: "EN"
|
|
214
|
+
}
|
|
215
|
+
)
|
|
216
|
+
] })
|
|
217
|
+
] }),
|
|
218
|
+
/* @__PURE__ */ jsx("button", { className: "sku-input-card__delete", onClick: onDelete, children: /* @__PURE__ */ jsx(DeleteIcon, {}) })
|
|
219
|
+
] }),
|
|
220
|
+
showBody && /* @__PURE__ */ jsxs("div", { className: "sku-input-card__body", children: [
|
|
221
|
+
/* @__PURE__ */ jsx(
|
|
222
|
+
"input",
|
|
223
|
+
{
|
|
224
|
+
ref: fileInputRef,
|
|
225
|
+
type: "file",
|
|
226
|
+
accept: "image/jpeg,image/png,image/webp",
|
|
227
|
+
className: "sku-input-card__file-input",
|
|
228
|
+
onChange: handleFileChange
|
|
229
|
+
}
|
|
230
|
+
),
|
|
231
|
+
uploading ? /* @__PURE__ */ jsx("div", { className: "sku-input-card__loading", children: /* @__PURE__ */ jsx("img", { src: loadingIndicator, alt: "上传中", className: "sku-input-card__loading-img" }) }) : displayImages[0] ? (
|
|
232
|
+
/* Single image preview */
|
|
233
|
+
/* @__PURE__ */ jsxs("div", { className: "sku-input-card__image-item", children: [
|
|
234
|
+
/* @__PURE__ */ jsx("img", { src: displayImages[0], alt: "图片", className: "sku-input-card__image-thumb" }),
|
|
235
|
+
/* @__PURE__ */ jsxs("div", { className: "sku-input-card__image-overlay", children: [
|
|
236
|
+
/* @__PURE__ */ jsx(
|
|
237
|
+
"button",
|
|
238
|
+
{
|
|
239
|
+
className: "sku-input-card__image-action-btn",
|
|
240
|
+
onClick: () => onPreviewImage == null ? void 0 : onPreviewImage(displayImages[0]),
|
|
241
|
+
children: /* @__PURE__ */ jsx(PreviewThinIcon, {})
|
|
242
|
+
}
|
|
243
|
+
),
|
|
244
|
+
/* @__PURE__ */ jsx(
|
|
245
|
+
"button",
|
|
246
|
+
{
|
|
247
|
+
className: "sku-input-card__image-action-btn",
|
|
248
|
+
onClick: () => onDeleteImage == null ? void 0 : onDeleteImage(displayImages[0]),
|
|
249
|
+
children: /* @__PURE__ */ jsx(DeleteThinIcon, {})
|
|
250
|
+
}
|
|
251
|
+
)
|
|
252
|
+
] })
|
|
253
|
+
] })
|
|
254
|
+
) : showUploadOptions ? (
|
|
255
|
+
/* Upload options — local upload / associate image */
|
|
256
|
+
/* @__PURE__ */ jsx("div", { className: "sku-input-card__upload-options", children: /* @__PURE__ */ jsxs("div", { ref: uploadOptionsRef, className: "sku-input-card__upload-options-box", children: [
|
|
257
|
+
/* @__PURE__ */ jsx("button", { className: "sku-input-card__upload-opt-btn", onClick: handleLocalUpload, children: uploadLocalLabel }),
|
|
258
|
+
/* @__PURE__ */ jsx("button", { className: "sku-input-card__upload-opt-btn", onClick: handleAssociate, children: associateImageLabel })
|
|
259
|
+
] }) })
|
|
260
|
+
) : (
|
|
261
|
+
/* Large add button — fills the body */
|
|
262
|
+
/* @__PURE__ */ jsx(
|
|
263
|
+
"button",
|
|
264
|
+
{
|
|
265
|
+
className: "sku-input-card__add-btn",
|
|
266
|
+
onClick: () => setShowUploadOptions(true),
|
|
267
|
+
children: /* @__PURE__ */ jsx(AddIcon, {})
|
|
268
|
+
}
|
|
269
|
+
)
|
|
270
|
+
)
|
|
271
|
+
] })
|
|
272
|
+
] })
|
|
273
|
+
] });
|
|
274
|
+
}
|
|
275
|
+
export {
|
|
276
|
+
SkuInputCard as default
|
|
277
|
+
};
|