bj-web-components 0.2.28 → 0.2.29
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/index.js +1 -51
- package/dist/index.mjs +49 -49
- package/dist/style.css +1 -3744
- package/dist/web/BasicInput/BInput.js +1 -208
- package/dist/web/BasicInput/BInput.mjs +132 -164
- package/dist/web/BasicInput/utils.js +1 -47
- package/dist/web/BasicInput/utils.mjs +28 -38
- package/dist/web/CategoryDropdown/CategoryDropdown.js +1 -307
- package/dist/web/CategoryDropdown/CategoryDropdown.mjs +170 -218
- package/dist/web/CheckBox/BCheckBox.js +1 -116
- package/dist/web/CheckBox/BCheckBox.mjs +70 -86
- package/dist/web/CheckBox/Group.js +1 -73
- package/dist/web/CheckBox/Group.mjs +56 -63
- package/dist/web/CheckBox/context.js +1 -5
- package/dist/web/CheckBox/context.mjs +3 -3
- package/dist/web/CheckBox/index.js +1 -8
- package/dist/web/CheckBox/index.mjs +6 -6
- package/dist/web/Dropdown/BDropdown.js +1 -186
- package/dist/web/Dropdown/BDropdown.mjs +106 -132
- package/dist/web/EmptyInputBox/EmptyInputBox.js +1 -77
- package/dist/web/EmptyInputBox/EmptyInputBox.mjs +48 -52
- package/dist/web/FileCard/FileCard.js +1 -157
- package/dist/web/FileCard/FileCard.mjs +82 -112
- package/dist/web/Icon/Icon.js +1 -9
- package/dist/web/Icon/Icon.mjs +6 -6
- package/dist/web/Input/Input.js +1 -181
- package/dist/web/Input/Input.mjs +113 -122
- package/dist/web/InputNumber/BInputNumber.js +1 -311
- package/dist/web/InputNumber/BInputNumber.mjs +167 -275
- package/dist/web/InputNumber/StepHandler.js +1 -69
- package/dist/web/InputNumber/StepHandler.mjs +32 -38
- package/dist/web/InputNumber/hooks/useCursor.js +1 -40
- package/dist/web/InputNumber/hooks/useCursor.mjs +33 -35
- package/dist/web/InputNumber/hooks/useFrame.js +1 -12
- package/dist/web/InputNumber/hooks/useFrame.mjs +6 -9
- package/dist/web/InputNumber/utils/decimal.js +1 -147
- package/dist/web/InputNumber/utils/decimal.mjs +81 -109
- package/dist/web/Modal/Modal.js +1 -84
- package/dist/web/Modal/Modal.mjs +49 -52
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.js +1 -232
- package/dist/web/OverlayScrollbar/BOverlayScrollbar.mjs +125 -206
- package/dist/web/Pagination/Pagination.js +1 -328
- package/dist/web/Pagination/Pagination.mjs +178 -254
- package/dist/web/ProductField/ProductField.js +1 -272
- package/dist/web/ProductField/ProductField.mjs +143 -190
- package/dist/web/ProductField/arrow-up.svg.js +1 -3
- package/dist/web/ProductField/arrow-up.svg.mjs +2 -2
- package/dist/web/ProductField/checkbox-no.svg.js +1 -3
- package/dist/web/ProductField/checkbox-no.svg.mjs +2 -2
- package/dist/web/ProductField/checkbox-ok.svg.js +1 -3
- package/dist/web/ProductField/checkbox-ok.svg.mjs +2 -2
- package/dist/web/ProductField/no_data_light.svg.js +1 -3
- package/dist/web/ProductField/no_data_light.svg.mjs +2 -2
- package/dist/web/ProductField/search.svg.js +1 -3
- package/dist/web/ProductField/search.svg.mjs +2 -2
- package/dist/web/ProductField/sort.svg.js +1 -3
- package/dist/web/ProductField/sort.svg.mjs +2 -2
- package/dist/web/SkuInputCard/SkuInputCard.js +1 -276
- package/dist/web/SkuInputCard/SkuInputCard.mjs +149 -188
- package/dist/web/SkuInputCard/spin_loading_red.gif.js +1 -3
- package/dist/web/SkuInputCard/spin_loading_red.gif.mjs +2 -2
- package/dist/web/Switch/Switch.js +1 -70
- package/dist/web/Switch/Switch.mjs +37 -47
- package/dist/web/Table/BTable.js +1 -950
- package/dist/web/Table/BTable.mjs +521 -767
- package/dist/web/Table/Column.js +1 -5
- package/dist/web/Table/Column.mjs +2 -2
- package/dist/web/Table/ColumnGroup.js +1 -5
- package/dist/web/Table/ColumnGroup.mjs +2 -2
- package/dist/web/Table/utils/columns.js +1 -48
- package/dist/web/Table/utils/columns.mjs +30 -35
- package/dist/web/Table/utils/sortFilter.js +1 -84
- package/dist/web/Table/utils/sortFilter.mjs +52 -73
- package/dist/web/Tabs/BTabs.js +1 -150
- package/dist/web/Tabs/BTabs.mjs +98 -118
- package/dist/web/Tabs/TabPane.js +1 -8
- package/dist/web/Tabs/TabPane.mjs +4 -4
- package/dist/web/Tooltip/ConfirmTooltip.js +1 -26
- package/dist/web/Tooltip/ConfirmTooltip.mjs +19 -20
- package/dist/web/Tooltip/ContentTooltip.js +1 -94
- package/dist/web/Tooltip/ContentTooltip.mjs +62 -72
- package/dist/web/Tooltip/ProgressTooltip.js +1 -36
- package/dist/web/Tooltip/ProgressTooltip.mjs +20 -22
- package/dist/web/Tooltip/TooltipWrapper.js +1 -12
- package/dist/web/Tooltip/TooltipWrapper.mjs +8 -8
- package/dist/web/Tooltip/useAutoPlacement.js +1 -41
- package/dist/web/Tooltip/useAutoPlacement.mjs +25 -34
- package/dist/web.js +1 -51
- package/dist/web.mjs +49 -49
- package/package.json +1 -1
|
@@ -1,272 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
-
const react = require("react");
|
|
4
|
-
const reactDom = require("react-dom");
|
|
5
|
-
;/* empty css */
|
|
6
|
-
const no_data_light = require("./no_data_light.svg.js");
|
|
7
|
-
const arrowUp = require("./arrow-up.svg.js");
|
|
8
|
-
const sort = require("./sort.svg.js");
|
|
9
|
-
const search = require("./search.svg.js");
|
|
10
|
-
const checkboxNo = require("./checkbox-no.svg.js");
|
|
11
|
-
const checkboxOk = require("./checkbox-ok.svg.js");
|
|
12
|
-
function CloseIcon({ size = 20 }) {
|
|
13
|
-
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M16.5613 6.73027C16.7558 6.53571 17.0723 6.53442 17.2684 6.72736C17.4644 6.92032 17.4657 7.23444 17.2713 7.42901L12.7036 12.0002L17.2713 16.5714C17.4657 16.766 17.4644 17.0801 17.2684 17.273C17.0723 17.4659 16.7558 17.4646 16.5613 17.2701L11.9996 12.7047L7.43794 17.2701C7.24352 17.4647 6.92699 17.4659 6.73091 17.273C6.53485 17.0801 6.53355 16.7659 6.72798 16.5714L11.2955 12.0002L6.72798 7.42901C6.53355 7.23442 6.53485 6.92032 6.73091 6.72736C6.92698 6.53442 7.2435 6.53571 7.43794 6.73027L11.9996 11.2955L16.5613 6.73027Z", fill: "currentColor" }) });
|
|
14
|
-
}
|
|
15
|
-
function BuProductField({
|
|
16
|
-
options = [],
|
|
17
|
-
value = [],
|
|
18
|
-
onChange,
|
|
19
|
-
placeholder = "请选择",
|
|
20
|
-
emptyText = "暂无产品数据",
|
|
21
|
-
onManageField,
|
|
22
|
-
multiple = true,
|
|
23
|
-
showSearch = true,
|
|
24
|
-
showSort = true,
|
|
25
|
-
addButtonText,
|
|
26
|
-
onAdd,
|
|
27
|
-
labels,
|
|
28
|
-
className,
|
|
29
|
-
style,
|
|
30
|
-
getPopupContainer
|
|
31
|
-
}) {
|
|
32
|
-
const searchPlaceholder = (labels == null ? void 0 : labels.searchPlaceholder) ?? "搜索";
|
|
33
|
-
const sortDefault = (labels == null ? void 0 : labels.sortDefault) ?? "默认顺序";
|
|
34
|
-
const sortAsc = (labels == null ? void 0 : labels.sortAsc) ?? "名称A-Z";
|
|
35
|
-
const sortDesc = (labels == null ? void 0 : labels.sortDesc) ?? "名称Z-A";
|
|
36
|
-
const noMatchText = (labels == null ? void 0 : labels.noMatchText) ?? "暂无选项";
|
|
37
|
-
const manageFieldPre = (labels == null ? void 0 : labels.manageFieldPre) ?? "请前往";
|
|
38
|
-
const manageFieldLink = (labels == null ? void 0 : labels.manageFieldLink) ?? "管理字段";
|
|
39
|
-
const manageFieldPost = (labels == null ? void 0 : labels.manageFieldPost) ?? "添加";
|
|
40
|
-
const [open, setOpen] = react.useState(false);
|
|
41
|
-
const [search$1, setSearch] = react.useState("");
|
|
42
|
-
const [sortOrder, setSortOrder] = react.useState("none");
|
|
43
|
-
const [sortDropdownOpen, setSortDropdownOpen] = react.useState(false);
|
|
44
|
-
const rootRef = react.useRef(null);
|
|
45
|
-
const sortBtnRef = react.useRef(null);
|
|
46
|
-
const portalRef = react.useRef(null);
|
|
47
|
-
const [dropdownPos, setDropdownPos] = react.useState({ top: 0, left: 0, width: 0 });
|
|
48
|
-
const updatePosition = react.useCallback(() => {
|
|
49
|
-
if (!rootRef.current) return;
|
|
50
|
-
const rect = rootRef.current.getBoundingClientRect();
|
|
51
|
-
setDropdownPos({
|
|
52
|
-
top: rect.bottom + 4,
|
|
53
|
-
left: rect.left,
|
|
54
|
-
width: rect.width
|
|
55
|
-
});
|
|
56
|
-
}, []);
|
|
57
|
-
react.useLayoutEffect(() => {
|
|
58
|
-
if (open) updatePosition();
|
|
59
|
-
}, [open, updatePosition]);
|
|
60
|
-
react.useEffect(() => {
|
|
61
|
-
if (!open) return;
|
|
62
|
-
const handler = (e) => {
|
|
63
|
-
var _a, _b;
|
|
64
|
-
const target = e.target;
|
|
65
|
-
if (((_a = portalRef.current) == null ? void 0 : _a.contains(target)) || ((_b = rootRef.current) == null ? void 0 : _b.contains(target))) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
close();
|
|
69
|
-
};
|
|
70
|
-
document.addEventListener("mousedown", handler);
|
|
71
|
-
window.addEventListener("scroll", updatePosition, true);
|
|
72
|
-
window.addEventListener("resize", updatePosition);
|
|
73
|
-
return () => {
|
|
74
|
-
document.removeEventListener("mousedown", handler);
|
|
75
|
-
window.removeEventListener("scroll", updatePosition, true);
|
|
76
|
-
window.removeEventListener("resize", updatePosition);
|
|
77
|
-
};
|
|
78
|
-
}, [open, updatePosition]);
|
|
79
|
-
react.useEffect(() => {
|
|
80
|
-
if (!sortDropdownOpen) return;
|
|
81
|
-
const handler = (e) => {
|
|
82
|
-
if (sortBtnRef.current && !sortBtnRef.current.contains(e.target)) {
|
|
83
|
-
setSortDropdownOpen(false);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
document.addEventListener("mousedown", handler);
|
|
87
|
-
return () => document.removeEventListener("mousedown", handler);
|
|
88
|
-
}, [sortDropdownOpen]);
|
|
89
|
-
const tagsRef = react.useRef(null);
|
|
90
|
-
const triggerTagsRef = react.useRef(null);
|
|
91
|
-
const dragState = react.useRef({ dragging: false, startX: 0, scrollLeft: 0, target: null });
|
|
92
|
-
const makeDragHandlers = react.useCallback((ref) => ({
|
|
93
|
-
onMouseDown: (e) => {
|
|
94
|
-
const el = ref.current;
|
|
95
|
-
if (!el) return;
|
|
96
|
-
dragState.current = { dragging: true, startX: e.clientX, scrollLeft: el.scrollLeft, target: el };
|
|
97
|
-
},
|
|
98
|
-
onMouseMove: (e) => {
|
|
99
|
-
const { dragging, startX, scrollLeft, target } = dragState.current;
|
|
100
|
-
if (!dragging || !target) return;
|
|
101
|
-
e.preventDefault();
|
|
102
|
-
target.scrollLeft = scrollLeft - (e.clientX - startX);
|
|
103
|
-
},
|
|
104
|
-
onMouseUp: () => {
|
|
105
|
-
dragState.current.dragging = false;
|
|
106
|
-
},
|
|
107
|
-
onMouseLeave: () => {
|
|
108
|
-
dragState.current.dragging = false;
|
|
109
|
-
}
|
|
110
|
-
}), []);
|
|
111
|
-
function toggleOption(val) {
|
|
112
|
-
if (!multiple) {
|
|
113
|
-
onChange == null ? void 0 : onChange(value.includes(val) ? [] : [val]);
|
|
114
|
-
if (!value.includes(val)) close();
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
const next = value.includes(val) ? value.filter((v) => v !== val) : [...value, val];
|
|
118
|
-
onChange == null ? void 0 : onChange(next);
|
|
119
|
-
}
|
|
120
|
-
function removeTag(val) {
|
|
121
|
-
onChange == null ? void 0 : onChange(value.filter((v) => v !== val));
|
|
122
|
-
}
|
|
123
|
-
function close() {
|
|
124
|
-
setOpen(false);
|
|
125
|
-
setSearch("");
|
|
126
|
-
setSortOrder("none");
|
|
127
|
-
}
|
|
128
|
-
function selectSort(order) {
|
|
129
|
-
setSortOrder(order);
|
|
130
|
-
setSortDropdownOpen(false);
|
|
131
|
-
}
|
|
132
|
-
const filteredOptions = react.useMemo(() => {
|
|
133
|
-
let list = options.filter((o) => {
|
|
134
|
-
const text = o.searchText ?? (typeof o.label === "string" ? o.label : "");
|
|
135
|
-
return text.toLowerCase().includes(search$1.toLowerCase());
|
|
136
|
-
});
|
|
137
|
-
const getText = (o) => o.searchText ?? (typeof o.label === "string" ? o.label : "");
|
|
138
|
-
if (sortOrder === "asc") list = [...list].sort((a, b) => getText(a).localeCompare(getText(b)));
|
|
139
|
-
if (sortOrder === "desc") list = [...list].sort((a, b) => getText(b).localeCompare(getText(a)));
|
|
140
|
-
return list;
|
|
141
|
-
}, [options, search$1, sortOrder]);
|
|
142
|
-
const selectedOptions = options.filter((o) => value.includes(o.value));
|
|
143
|
-
const hasOptions = options.length > 0;
|
|
144
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: rootRef, className: ["bu-pf", className].filter(Boolean).join(" "), style, children: [
|
|
145
|
-
!open && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `bu-pf__trigger${selectedOptions.length > 0 ? " bu-pf__trigger--selected" : ""}`, onClick: () => setOpen(true), children: [
|
|
146
|
-
selectedOptions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
147
|
-
"div",
|
|
148
|
-
{
|
|
149
|
-
className: "bu-pf__trigger-tags",
|
|
150
|
-
ref: triggerTagsRef,
|
|
151
|
-
...makeDragHandlers(triggerTagsRef),
|
|
152
|
-
children: selectedOptions.map((opt) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: `bu-pf__tag${!multiple ? " bu-pf__tag--single" : ""}`, children: [
|
|
153
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "bu-pf__tag-text", children: opt.label }),
|
|
154
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
155
|
-
"button",
|
|
156
|
-
{
|
|
157
|
-
type: "button",
|
|
158
|
-
className: "bu-pf__tag-close",
|
|
159
|
-
onClick: (e) => {
|
|
160
|
-
e.stopPropagation();
|
|
161
|
-
removeTag(opt.value);
|
|
162
|
-
},
|
|
163
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, { size: 12 })
|
|
164
|
-
}
|
|
165
|
-
)
|
|
166
|
-
] }, opt.value))
|
|
167
|
-
}
|
|
168
|
-
) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bu-pf__placeholder", children: placeholder }),
|
|
169
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "bu-pf__arrow", children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: arrowUp, width: 24, height: 24, alt: "" }) })
|
|
170
|
-
] }),
|
|
171
|
-
open && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
172
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bu-pf__panel", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-pf__header", children: [
|
|
173
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
174
|
-
"div",
|
|
175
|
-
{
|
|
176
|
-
className: "bu-pf__tags",
|
|
177
|
-
ref: tagsRef,
|
|
178
|
-
...makeDragHandlers(tagsRef),
|
|
179
|
-
children: selectedOptions.length > 0 ? selectedOptions.map((opt) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: `bu-pf__tag${!multiple ? " bu-pf__tag--single" : ""}`, children: [
|
|
180
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "bu-pf__tag-text", children: opt.label }),
|
|
181
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
182
|
-
"button",
|
|
183
|
-
{
|
|
184
|
-
type: "button",
|
|
185
|
-
className: "bu-pf__tag-close",
|
|
186
|
-
onClick: () => removeTag(opt.value),
|
|
187
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, { size: 12 })
|
|
188
|
-
}
|
|
189
|
-
)
|
|
190
|
-
] }, opt.value)) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bu-pf__placeholder-inline", children: placeholder })
|
|
191
|
-
}
|
|
192
|
-
),
|
|
193
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "bu-pf__close", onClick: close, children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: arrowUp, width: 24, height: 24, alt: "" }) })
|
|
194
|
-
] }) }),
|
|
195
|
-
reactDom.createPortal(
|
|
196
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: portalRef, className: "bu-pf__portal", style: { position: "fixed", top: dropdownPos.top, left: dropdownPos.left, width: dropdownPos.width, zIndex: 1050 }, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-pf__dropdown", children: [
|
|
197
|
-
(showSearch || showSort) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-pf__toolbar", children: [
|
|
198
|
-
showSearch && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-pf__search", children: [
|
|
199
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "bu-pf__search-icon", children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: search, width: 20, height: 20, alt: "" }) }),
|
|
200
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
201
|
-
"input",
|
|
202
|
-
{
|
|
203
|
-
className: "bu-pf__search-input",
|
|
204
|
-
placeholder: searchPlaceholder,
|
|
205
|
-
value: search$1,
|
|
206
|
-
onChange: (e) => setSearch(e.target.value)
|
|
207
|
-
}
|
|
208
|
-
)
|
|
209
|
-
] }),
|
|
210
|
-
showSort && /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: sortBtnRef, className: "bu-pf__sort-wrap", children: [
|
|
211
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
212
|
-
"button",
|
|
213
|
-
{
|
|
214
|
-
type: "button",
|
|
215
|
-
className: `bu-pf__sort-btn${sortOrder !== "none" ? " bu-pf__sort-btn--active" : ""}`,
|
|
216
|
-
onClick: () => setSortDropdownOpen((v) => !v),
|
|
217
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: sort, width: 24, height: 24, alt: "" })
|
|
218
|
-
}
|
|
219
|
-
),
|
|
220
|
-
sortDropdownOpen && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bu-pf__sort-dropdown", children: [
|
|
221
|
-
{ key: "none", label: sortDefault },
|
|
222
|
-
{ key: "asc", label: sortAsc },
|
|
223
|
-
{ key: "desc", label: sortDesc }
|
|
224
|
-
].map(({ key, label }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
225
|
-
"div",
|
|
226
|
-
{
|
|
227
|
-
className: `bu-pf__sort-option${sortOrder === key ? " bu-pf__sort-option--active" : ""}`,
|
|
228
|
-
onClick: () => selectSort(key),
|
|
229
|
-
children: label
|
|
230
|
-
},
|
|
231
|
-
key
|
|
232
|
-
)) })
|
|
233
|
-
] })
|
|
234
|
-
] }),
|
|
235
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bu-pf__list", children: hasOptions && filteredOptions.length > 0 ? filteredOptions.map((opt) => {
|
|
236
|
-
const checked = value.includes(opt.value);
|
|
237
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
238
|
-
"div",
|
|
239
|
-
{
|
|
240
|
-
className: `bu-pf__option${multiple ? " bu-pf__option--multiple" : ""}${checked && !multiple ? " bu-pf__option--selected" : ""}`,
|
|
241
|
-
onClick: () => toggleOption(opt.value),
|
|
242
|
-
children: [
|
|
243
|
-
multiple && /* @__PURE__ */ jsxRuntime.jsx(
|
|
244
|
-
"img",
|
|
245
|
-
{
|
|
246
|
-
className: "bu-pf__checkbox-img",
|
|
247
|
-
src: checked ? checkboxOk : checkboxNo,
|
|
248
|
-
alt: ""
|
|
249
|
-
}
|
|
250
|
-
),
|
|
251
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "bu-pf__option-label", children: opt.label })
|
|
252
|
-
]
|
|
253
|
-
},
|
|
254
|
-
opt.value
|
|
255
|
-
);
|
|
256
|
-
}) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-pf__no-match", children: [
|
|
257
|
-
/* @__PURE__ */ jsxRuntime.jsx("img", { className: "bu-pf__no-match-img", src: no_data_light, alt: hasOptions ? noMatchText : emptyText }),
|
|
258
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "bu-pf__no-match-text", children: hasOptions ? noMatchText : emptyText }),
|
|
259
|
-
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "bu-pf__no-match-hint", children: [
|
|
260
|
-
manageFieldPre,
|
|
261
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "bu-pf__manage-btn", onClick: onManageField, children: manageFieldLink }),
|
|
262
|
-
manageFieldPost
|
|
263
|
-
] })
|
|
264
|
-
] }) }),
|
|
265
|
-
addButtonText && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bu-pf__add-row", onClick: onAdd, children: addButtonText })
|
|
266
|
-
] }) }),
|
|
267
|
-
(getPopupContainer == null ? void 0 : getPopupContainer()) ?? document.body
|
|
268
|
-
)
|
|
269
|
-
] })
|
|
270
|
-
] });
|
|
271
|
-
}
|
|
272
|
-
module.exports = BuProductField;
|
|
1
|
+
"use strict";const t=require("react/jsx-runtime"),c=require("react"),ne=require("react-dom");;/* empty css */const ce=require("./no_data_light.svg.js"),B=require("./arrow-up.svg.js"),oe=require("./sort.svg.js"),ie=require("./search.svg.js"),ae=require("./checkbox-no.svg.js"),ue=require("./checkbox-ok.svg.js");function Z({size:u=20}){return t.jsx("svg",{width:u,height:u,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:t.jsx("path",{d:"M16.5613 6.73027C16.7558 6.53571 17.0723 6.53442 17.2684 6.72736C17.4644 6.92032 17.4657 7.23444 17.2713 7.42901L12.7036 12.0002L17.2713 16.5714C17.4657 16.766 17.4644 17.0801 17.2684 17.273C17.0723 17.4659 16.7558 17.4646 16.5613 17.2701L11.9996 12.7047L7.43794 17.2701C7.24352 17.4647 6.92699 17.4659 6.73091 17.273C6.53485 17.0801 6.53355 16.7659 6.72798 16.5714L11.2955 12.0002L6.72798 7.42901C6.53355 7.23442 6.53485 6.92032 6.73091 6.72736C6.92698 6.53442 7.2435 6.53571 7.43794 6.73027L11.9996 11.2955L16.5613 6.73027Z",fill:"currentColor"})})}function le({options:u=[],value:a=[],onChange:o,placeholder:R="请选择",emptyText:D="暂无产品数据",onManageField:I,multiple:d=!0,showSearch:E=!0,showSort:q=!0,addButtonText:y,onAdd:U,labels:s,className:H,style:G,getPopupContainer:x}){const J=(s==null?void 0:s.searchPlaceholder)??"搜索",K=(s==null?void 0:s.sortDefault)??"默认顺序",Q=(s==null?void 0:s.sortAsc)??"名称A-Z",V=(s==null?void 0:s.sortDesc)??"名称Z-A",O=(s==null?void 0:s.noMatchText)??"暂无选项",W=(s==null?void 0:s.manageFieldPre)??"请前往",Y=(s==null?void 0:s.manageFieldLink)??"管理字段",ee=(s==null?void 0:s.manageFieldPost)??"添加",[f,C]=c.useState(!1),[j,M]=c.useState(""),[p,F]=c.useState("none"),[w,N]=c.useState(!1),m=c.useRef(null),b=c.useRef(null),P=c.useRef(null),[v,te]=c.useState({top:0,left:0,width:0}),l=c.useCallback(()=>{if(!m.current)return;const e=m.current.getBoundingClientRect();te({top:e.bottom+4,left:e.left,width:e.width})},[]);c.useLayoutEffect(()=>{f&&l()},[f,l]),c.useEffect(()=>{if(!f)return;const e=r=>{var i,g;const n=r.target;(i=P.current)!=null&&i.contains(n)||(g=m.current)!=null&&g.contains(n)||L()};return document.addEventListener("mousedown",e),window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[f,l]),c.useEffect(()=>{if(!w)return;const e=r=>{b.current&&!b.current.contains(r.target)&&N(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[w]);const S=c.useRef(null),$=c.useRef(null),h=c.useRef({dragging:!1,startX:0,scrollLeft:0,target:null}),T=c.useCallback(e=>({onMouseDown:r=>{const n=e.current;n&&(h.current={dragging:!0,startX:r.clientX,scrollLeft:n.scrollLeft,target:n})},onMouseMove:r=>{const{dragging:n,startX:i,scrollLeft:g,target:A}=h.current;!n||!A||(r.preventDefault(),A.scrollLeft=g-(r.clientX-i))},onMouseUp:()=>{h.current.dragging=!1},onMouseLeave:()=>{h.current.dragging=!1}}),[]);function se(e){if(!d){o==null||o(a.includes(e)?[]:[e]),a.includes(e)||L();return}const r=a.includes(e)?a.filter(n=>n!==e):[...a,e];o==null||o(r)}function X(e){o==null||o(a.filter(r=>r!==e))}function L(){C(!1),M(""),F("none")}function re(e){F(e),N(!1)}const z=c.useMemo(()=>{let e=u.filter(n=>(n.searchText??(typeof n.label=="string"?n.label:"")).toLowerCase().includes(j.toLowerCase()));const r=n=>n.searchText??(typeof n.label=="string"?n.label:"");return p==="asc"&&(e=[...e].sort((n,i)=>r(n).localeCompare(r(i)))),p==="desc"&&(e=[...e].sort((n,i)=>r(i).localeCompare(r(n)))),e},[u,j,p]),_=u.filter(e=>a.includes(e.value)),k=u.length>0;return t.jsxs("div",{ref:m,className:["bu-pf",H].filter(Boolean).join(" "),style:G,children:[!f&&t.jsxs("div",{className:`bu-pf__trigger${_.length>0?" bu-pf__trigger--selected":""}`,onClick:()=>C(!0),children:[_.length>0?t.jsx("div",{className:"bu-pf__trigger-tags",ref:$,...T($),children:_.map(e=>t.jsxs("span",{className:`bu-pf__tag${d?"":" bu-pf__tag--single"}`,children:[t.jsx("span",{className:"bu-pf__tag-text",children:e.label}),t.jsx("button",{type:"button",className:"bu-pf__tag-close",onClick:r=>{r.stopPropagation(),X(e.value)},children:t.jsx(Z,{size:12})})]},e.value))}):t.jsx("span",{className:"bu-pf__placeholder",children:R}),t.jsx("span",{className:"bu-pf__arrow",children:t.jsx("img",{src:B,width:24,height:24,alt:""})})]}),f&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bu-pf__panel",children:t.jsxs("div",{className:"bu-pf__header",children:[t.jsx("div",{className:"bu-pf__tags",ref:S,...T(S),children:_.length>0?_.map(e=>t.jsxs("span",{className:`bu-pf__tag${d?"":" bu-pf__tag--single"}`,children:[t.jsx("span",{className:"bu-pf__tag-text",children:e.label}),t.jsx("button",{type:"button",className:"bu-pf__tag-close",onClick:()=>X(e.value),children:t.jsx(Z,{size:12})})]},e.value)):t.jsx("span",{className:"bu-pf__placeholder-inline",children:R})}),t.jsx("button",{type:"button",className:"bu-pf__close",onClick:L,children:t.jsx("img",{src:B,width:24,height:24,alt:""})})]})}),ne.createPortal(t.jsx("div",{ref:P,className:"bu-pf__portal",style:{position:"fixed",top:v.top,left:v.left,width:v.width,zIndex:1050},children:t.jsxs("div",{className:"bu-pf__dropdown",children:[(E||q)&&t.jsxs("div",{className:"bu-pf__toolbar",children:[E&&t.jsxs("div",{className:"bu-pf__search",children:[t.jsx("span",{className:"bu-pf__search-icon",children:t.jsx("img",{src:ie,width:20,height:20,alt:""})}),t.jsx("input",{className:"bu-pf__search-input",placeholder:J,value:j,onChange:e=>M(e.target.value)})]}),q&&t.jsxs("div",{ref:b,className:"bu-pf__sort-wrap",children:[t.jsx("button",{type:"button",className:`bu-pf__sort-btn${p!=="none"?" bu-pf__sort-btn--active":""}`,onClick:()=>N(e=>!e),children:t.jsx("img",{src:oe,width:24,height:24,alt:""})}),w&&t.jsx("div",{className:"bu-pf__sort-dropdown",children:[{key:"none",label:K},{key:"asc",label:Q},{key:"desc",label:V}].map(({key:e,label:r})=>t.jsx("div",{className:`bu-pf__sort-option${p===e?" bu-pf__sort-option--active":""}`,onClick:()=>re(e),children:r},e))})]})]}),t.jsx("div",{className:"bu-pf__list",children:k&&z.length>0?z.map(e=>{const r=a.includes(e.value);return t.jsxs("div",{className:`bu-pf__option${d?" bu-pf__option--multiple":""}${r&&!d?" bu-pf__option--selected":""}`,onClick:()=>se(e.value),children:[d&&t.jsx("img",{className:"bu-pf__checkbox-img",src:r?ue:ae,alt:""}),t.jsx("span",{className:"bu-pf__option-label",children:e.label})]},e.value)}):t.jsxs("div",{className:"bu-pf__no-match",children:[t.jsx("img",{className:"bu-pf__no-match-img",src:ce,alt:k?O:D}),t.jsx("p",{className:"bu-pf__no-match-text",children:k?O:D}),t.jsxs("p",{className:"bu-pf__no-match-hint",children:[W,t.jsx("button",{type:"button",className:"bu-pf__manage-btn",onClick:I,children:Y}),ee]})]})}),y&&t.jsx("div",{className:"bu-pf__add-row",onClick:U,children:y})]})}),(x==null?void 0:x())??document.body)]})]})}module.exports=le;
|