bj-web-components 0.2.27 → 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.
Files changed (90) hide show
  1. package/dist/index.js +51 -1
  2. package/dist/index.mjs +49 -49
  3. package/dist/style.css +3744 -1
  4. package/dist/web/BasicInput/BInput.js +208 -1
  5. package/dist/web/BasicInput/BInput.mjs +164 -132
  6. package/dist/web/BasicInput/utils.js +47 -1
  7. package/dist/web/BasicInput/utils.mjs +38 -28
  8. package/dist/web/CategoryDropdown/CategoryDropdown.js +307 -1
  9. package/dist/web/CategoryDropdown/CategoryDropdown.mjs +218 -170
  10. package/dist/web/CheckBox/BCheckBox.js +116 -1
  11. package/dist/web/CheckBox/BCheckBox.mjs +86 -70
  12. package/dist/web/CheckBox/Group.js +73 -1
  13. package/dist/web/CheckBox/Group.mjs +63 -56
  14. package/dist/web/CheckBox/context.js +5 -1
  15. package/dist/web/CheckBox/context.mjs +3 -3
  16. package/dist/web/CheckBox/index.js +8 -1
  17. package/dist/web/CheckBox/index.mjs +6 -6
  18. package/dist/web/Dropdown/BDropdown.js +186 -1
  19. package/dist/web/Dropdown/BDropdown.mjs +132 -106
  20. package/dist/web/EmptyInputBox/EmptyInputBox.js +77 -1
  21. package/dist/web/EmptyInputBox/EmptyInputBox.mjs +52 -48
  22. package/dist/web/FileCard/FileCard.js +157 -1
  23. package/dist/web/FileCard/FileCard.mjs +112 -82
  24. package/dist/web/Icon/Icon.js +9 -1
  25. package/dist/web/Icon/Icon.mjs +6 -6
  26. package/dist/web/Input/Input.js +181 -1
  27. package/dist/web/Input/Input.mjs +122 -113
  28. package/dist/web/InputNumber/BInputNumber.js +311 -1
  29. package/dist/web/InputNumber/BInputNumber.mjs +275 -167
  30. package/dist/web/InputNumber/StepHandler.js +69 -1
  31. package/dist/web/InputNumber/StepHandler.mjs +38 -32
  32. package/dist/web/InputNumber/hooks/useCursor.js +40 -1
  33. package/dist/web/InputNumber/hooks/useCursor.mjs +35 -33
  34. package/dist/web/InputNumber/hooks/useFrame.js +12 -1
  35. package/dist/web/InputNumber/hooks/useFrame.mjs +9 -6
  36. package/dist/web/InputNumber/utils/decimal.js +147 -1
  37. package/dist/web/InputNumber/utils/decimal.mjs +109 -81
  38. package/dist/web/Modal/Modal.js +84 -1
  39. package/dist/web/Modal/Modal.mjs +52 -49
  40. package/dist/web/OverlayScrollbar/BOverlayScrollbar.js +232 -1
  41. package/dist/web/OverlayScrollbar/BOverlayScrollbar.mjs +206 -125
  42. package/dist/web/Pagination/Pagination.js +328 -1
  43. package/dist/web/Pagination/Pagination.mjs +254 -178
  44. package/dist/web/ProductField/ProductField.js +272 -1
  45. package/dist/web/ProductField/ProductField.mjs +190 -143
  46. package/dist/web/ProductField/arrow-up.svg.js +3 -1
  47. package/dist/web/ProductField/arrow-up.svg.mjs +2 -2
  48. package/dist/web/ProductField/checkbox-no.svg.js +3 -1
  49. package/dist/web/ProductField/checkbox-no.svg.mjs +2 -2
  50. package/dist/web/ProductField/checkbox-ok.svg.js +3 -1
  51. package/dist/web/ProductField/checkbox-ok.svg.mjs +2 -2
  52. package/dist/web/ProductField/no_data_light.svg.js +3 -1
  53. package/dist/web/ProductField/no_data_light.svg.mjs +2 -2
  54. package/dist/web/ProductField/search.svg.js +3 -1
  55. package/dist/web/ProductField/search.svg.mjs +2 -2
  56. package/dist/web/ProductField/sort.svg.js +3 -1
  57. package/dist/web/ProductField/sort.svg.mjs +2 -2
  58. package/dist/web/SkuInputCard/SkuInputCard.js +276 -1
  59. package/dist/web/SkuInputCard/SkuInputCard.mjs +188 -149
  60. package/dist/web/SkuInputCard/spin_loading_red.gif.js +3 -1
  61. package/dist/web/SkuInputCard/spin_loading_red.gif.mjs +2 -2
  62. package/dist/web/Switch/Switch.js +70 -1
  63. package/dist/web/Switch/Switch.mjs +47 -37
  64. package/dist/web/Table/BTable.js +950 -1
  65. package/dist/web/Table/BTable.mjs +771 -519
  66. package/dist/web/Table/Column.js +5 -1
  67. package/dist/web/Table/Column.mjs +2 -2
  68. package/dist/web/Table/ColumnGroup.js +5 -1
  69. package/dist/web/Table/ColumnGroup.mjs +2 -2
  70. package/dist/web/Table/utils/columns.js +48 -1
  71. package/dist/web/Table/utils/columns.mjs +35 -30
  72. package/dist/web/Table/utils/sortFilter.js +84 -1
  73. package/dist/web/Table/utils/sortFilter.mjs +73 -52
  74. package/dist/web/Tabs/BTabs.js +150 -1
  75. package/dist/web/Tabs/BTabs.mjs +118 -98
  76. package/dist/web/Tabs/TabPane.js +8 -1
  77. package/dist/web/Tabs/TabPane.mjs +4 -4
  78. package/dist/web/Tooltip/ConfirmTooltip.js +26 -1
  79. package/dist/web/Tooltip/ConfirmTooltip.mjs +20 -19
  80. package/dist/web/Tooltip/ContentTooltip.js +94 -1
  81. package/dist/web/Tooltip/ContentTooltip.mjs +72 -62
  82. package/dist/web/Tooltip/ProgressTooltip.js +36 -1
  83. package/dist/web/Tooltip/ProgressTooltip.mjs +22 -20
  84. package/dist/web/Tooltip/TooltipWrapper.js +12 -1
  85. package/dist/web/Tooltip/TooltipWrapper.mjs +8 -8
  86. package/dist/web/Tooltip/useAutoPlacement.js +41 -1
  87. package/dist/web/Tooltip/useAutoPlacement.mjs +34 -25
  88. package/dist/web.js +51 -1
  89. package/dist/web.mjs +49 -49
  90. package/package.json +1 -1
@@ -1 +1,208 @@
1
- "use strict";const r=require("react/jsx-runtime"),t=require("react"),i=require("./utils.js");;/* empty css */function v(...a){return a.filter(Boolean).join(" ")}function K({addonAfter:a,addonBefore:d,allowClear:s,children:k,className:N,disabled:R,focused:F,handleReset:q,onClear:u,prefix:j,readOnly:p,size:b,status:E,suffix:o,triggerInputFocus:_,value:f}){const m=t.useRef(null),g=i.hasPrefixSuffix({prefix:j,suffix:o,allowClear:s}),x=t.cloneElement(k,{value:f});let c=x;if(g){const w=!!(s&&!R&&!p&&f),I=typeof s=="object"&&s.clearIcon?s.clearIcon:"×";c=r.jsxs("span",{className:v("bj-input__affix-wrapper",R&&"bj-input__affix-wrapper--disabled",F&&"bj-input__affix-wrapper--focused",p&&"bj-input__affix-wrapper--readonly",b&&`bj-input__affix-wrapper--${b}`,E&&`bj-input__affix-wrapper--${E}`),onClick:_,ref:m,children:[j&&r.jsx("span",{className:"bj-input__prefix",children:j}),x,(o||s)&&r.jsxs("span",{className:"bj-input__suffix",children:[s&&r.jsx("button",{"aria-label":"清除输入内容",className:v("bj-input__clear-icon",!w&&"bj-input__clear-icon--hidden"),onClick:l=>{q(l),u==null||u()},onMouseDown:l=>l.preventDefault(),tabIndex:-1,type:"button",children:I}),o]})]})}return i.hasAddon({addonBefore:d,addonAfter:a})&&(c=r.jsx("span",{className:"bj-input__group-wrapper",children:r.jsxs("span",{className:"bj-input__group",children:[d&&r.jsx("span",{className:"bj-input__group-addon",children:d}),c,a&&r.jsx("span",{className:"bj-input__group-addon",children:a})]})})),t.cloneElement(c,{className:v(c.props.className,N)})}const O=t.forwardRef((a,d)=>{const{addonAfter:s,addonBefore:k,allowClear:N,bordered:R=!0,className:F,defaultValue:q,disabled:u,htmlSize:j,onBlur:p,onChange:b,onClear:E,onCompositionEnd:o,onCompositionStart:_,onFocus:f,onKeyDown:m,onKeyUp:g,onPressEnter:x,prefix:c,readOnly:w,size:I="middle",status:l,suffix:V,type:H="text",value:y,...L}=a,[$,B]=t.useState(!1),[M,z]=t.useState(q),n=t.useRef(null),A=t.useRef(!1),S=t.useRef(!1),T=i.hasPrefixSuffix({prefix:c,suffix:V,allowClear:N}),P=y===void 0?M:y,C=P==null?"":String(P);t.useImperativeHandle(d,()=>({focus:e=>i.triggerFocus(n.current,e),blur:()=>{var e;return(e=n.current)==null?void 0:e.blur()},setSelectionRange:(...e)=>{var h;return(h=n.current)==null?void 0:h.setSelectionRange(...e)},select:()=>{var e;return(e=n.current)==null?void 0:e.select()},input:n.current,nativeElement:n.current})),t.useEffect(()=>B(e=>e&&!u),[u]);const D=(e,h,J)=>{J!=="compositionEnd"&&(y===void 0&&z(h),n.current&&i.resolveOnChange(n.current,e,b,h))},G=r.jsx("input",{...L,className:v("bj-input",`bj-input--${I}`,$&&!T&&"bj-input--focused",l&&`bj-input--${l}`,!R&&"bj-input--borderless",u&&"bj-input--disabled"),disabled:u,onBlur:e=>{S.current=!1,B(!1),p==null||p(e)},onChange:e=>D(e,e.target.value,"change"),onCompositionEnd:e=>{A.current=!1,D(e,e.currentTarget.value,"compositionEnd"),o==null||o(e)},onCompositionStart:e=>{A.current=!0,_==null||_(e)},onFocus:e=>{B(!0),f==null||f(e)},onKeyDown:e=>{x&&e.key==="Enter"&&!S.current&&(S.current=!0,x(e)),m==null||m(e)},onKeyUp:e=>{e.key==="Enter"&&(S.current=!1),g==null||g(e)},ref:n,size:j,type:H});return r.jsx(K,{addonAfter:s,addonBefore:k,allowClear:N,className:F,disabled:u,focused:$,handleReset:e=>{y===void 0&&z(""),i.triggerFocus(n.current),n.current&&i.resolveOnChange(n.current,e,b)},onClear:E,prefix:c,readOnly:w,size:I,status:l,suffix:V,triggerInputFocus:()=>i.triggerFocus(n.current),value:C,children:G})});O.displayName="BInput";module.exports=O;
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const react = require("react");
4
+ const utils = require("./utils.js");
5
+ ;/* empty css */
6
+ function classNames(...values) {
7
+ return values.filter(Boolean).join(" ");
8
+ }
9
+ function BaseInput({
10
+ addonAfter,
11
+ addonBefore,
12
+ allowClear,
13
+ children,
14
+ className,
15
+ disabled,
16
+ focused,
17
+ handleReset,
18
+ onClear,
19
+ prefix,
20
+ readOnly,
21
+ size,
22
+ status,
23
+ suffix,
24
+ triggerInputFocus,
25
+ value
26
+ }) {
27
+ const containerRef = react.useRef(null);
28
+ const hasAffix = utils.hasPrefixSuffix({ prefix, suffix, allowClear });
29
+ const inputElement = react.cloneElement(children, { value });
30
+ let element = inputElement;
31
+ if (hasAffix) {
32
+ const needClear = Boolean(allowClear && !disabled && !readOnly && value);
33
+ const clearIcon = typeof allowClear === "object" && allowClear.clearIcon ? allowClear.clearIcon : "×";
34
+ element = /* @__PURE__ */ jsxRuntime.jsxs(
35
+ "span",
36
+ {
37
+ className: classNames(
38
+ "bj-input__affix-wrapper",
39
+ disabled && "bj-input__affix-wrapper--disabled",
40
+ focused && "bj-input__affix-wrapper--focused",
41
+ readOnly && "bj-input__affix-wrapper--readonly",
42
+ size && `bj-input__affix-wrapper--${size}`,
43
+ status && `bj-input__affix-wrapper--${status}`
44
+ ),
45
+ onClick: triggerInputFocus,
46
+ ref: containerRef,
47
+ children: [
48
+ prefix && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bj-input__prefix", children: prefix }),
49
+ inputElement,
50
+ (suffix || allowClear) && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "bj-input__suffix", children: [
51
+ allowClear && /* @__PURE__ */ jsxRuntime.jsx(
52
+ "button",
53
+ {
54
+ "aria-label": "清除输入内容",
55
+ className: classNames("bj-input__clear-icon", !needClear && "bj-input__clear-icon--hidden"),
56
+ onClick: (event) => {
57
+ handleReset(event);
58
+ onClear == null ? void 0 : onClear();
59
+ },
60
+ onMouseDown: (event) => event.preventDefault(),
61
+ tabIndex: -1,
62
+ type: "button",
63
+ children: clearIcon
64
+ }
65
+ ),
66
+ suffix
67
+ ] })
68
+ ]
69
+ }
70
+ );
71
+ }
72
+ if (utils.hasAddon({ addonBefore, addonAfter })) {
73
+ element = /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bj-input__group-wrapper", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "bj-input__group", children: [
74
+ addonBefore && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bj-input__group-addon", children: addonBefore }),
75
+ element,
76
+ addonAfter && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bj-input__group-addon", children: addonAfter })
77
+ ] }) });
78
+ }
79
+ return react.cloneElement(element, { className: classNames(element.props.className, className) });
80
+ }
81
+ const BInput = react.forwardRef((props, ref) => {
82
+ const {
83
+ addonAfter,
84
+ addonBefore,
85
+ allowClear,
86
+ bordered = true,
87
+ className,
88
+ defaultValue,
89
+ disabled,
90
+ htmlSize,
91
+ onBlur,
92
+ onChange,
93
+ onClear,
94
+ onCompositionEnd,
95
+ onCompositionStart,
96
+ onFocus,
97
+ onKeyDown,
98
+ onKeyUp,
99
+ onPressEnter,
100
+ prefix,
101
+ readOnly,
102
+ size = "middle",
103
+ status,
104
+ suffix,
105
+ type = "text",
106
+ value: controlledValue,
107
+ ...restProps
108
+ } = props;
109
+ const [focused, setFocused] = react.useState(false);
110
+ const [innerValue, setInnerValue] = react.useState(defaultValue);
111
+ const inputRef = react.useRef(null);
112
+ const compositionRef = react.useRef(false);
113
+ const keyLockRef = react.useRef(false);
114
+ const hasAffix = utils.hasPrefixSuffix({ prefix, suffix, allowClear });
115
+ const value = controlledValue === void 0 ? innerValue : controlledValue;
116
+ const formattedValue = value === void 0 || value === null ? "" : String(value);
117
+ react.useImperativeHandle(ref, () => ({
118
+ focus: (option) => utils.triggerFocus(inputRef.current, option),
119
+ blur: () => {
120
+ var _a;
121
+ return (_a = inputRef.current) == null ? void 0 : _a.blur();
122
+ },
123
+ setSelectionRange: (...argumentsList) => {
124
+ var _a;
125
+ return (_a = inputRef.current) == null ? void 0 : _a.setSelectionRange(...argumentsList);
126
+ },
127
+ select: () => {
128
+ var _a;
129
+ return (_a = inputRef.current) == null ? void 0 : _a.select();
130
+ },
131
+ input: inputRef.current,
132
+ nativeElement: inputRef.current
133
+ }));
134
+ react.useEffect(() => setFocused((previous) => previous && !disabled), [disabled]);
135
+ const triggerChange = (event, nextValue, source) => {
136
+ if (source === "compositionEnd") return;
137
+ if (controlledValue === void 0) setInnerValue(nextValue);
138
+ if (inputRef.current) utils.resolveOnChange(inputRef.current, event, onChange, nextValue);
139
+ };
140
+ const input = /* @__PURE__ */ jsxRuntime.jsx(
141
+ "input",
142
+ {
143
+ ...restProps,
144
+ className: classNames("bj-input", `bj-input--${size}`, focused && !hasAffix && "bj-input--focused", status && `bj-input--${status}`, !bordered && "bj-input--borderless", disabled && "bj-input--disabled"),
145
+ disabled,
146
+ onBlur: (event) => {
147
+ keyLockRef.current = false;
148
+ setFocused(false);
149
+ onBlur == null ? void 0 : onBlur(event);
150
+ },
151
+ onChange: (event) => triggerChange(event, event.target.value, "change"),
152
+ onCompositionEnd: (event) => {
153
+ compositionRef.current = false;
154
+ triggerChange(event, event.currentTarget.value, "compositionEnd");
155
+ onCompositionEnd == null ? void 0 : onCompositionEnd(event);
156
+ },
157
+ onCompositionStart: (event) => {
158
+ compositionRef.current = true;
159
+ onCompositionStart == null ? void 0 : onCompositionStart(event);
160
+ },
161
+ onFocus: (event) => {
162
+ setFocused(true);
163
+ onFocus == null ? void 0 : onFocus(event);
164
+ },
165
+ onKeyDown: (event) => {
166
+ if (onPressEnter && event.key === "Enter" && !keyLockRef.current) {
167
+ keyLockRef.current = true;
168
+ onPressEnter(event);
169
+ }
170
+ onKeyDown == null ? void 0 : onKeyDown(event);
171
+ },
172
+ onKeyUp: (event) => {
173
+ if (event.key === "Enter") keyLockRef.current = false;
174
+ onKeyUp == null ? void 0 : onKeyUp(event);
175
+ },
176
+ ref: inputRef,
177
+ size: htmlSize,
178
+ type
179
+ }
180
+ );
181
+ return /* @__PURE__ */ jsxRuntime.jsx(
182
+ BaseInput,
183
+ {
184
+ addonAfter,
185
+ addonBefore,
186
+ allowClear,
187
+ className,
188
+ disabled,
189
+ focused,
190
+ handleReset: (event) => {
191
+ if (controlledValue === void 0) setInnerValue("");
192
+ utils.triggerFocus(inputRef.current);
193
+ if (inputRef.current) utils.resolveOnChange(inputRef.current, event, onChange);
194
+ },
195
+ onClear,
196
+ prefix,
197
+ readOnly,
198
+ size,
199
+ status,
200
+ suffix,
201
+ triggerInputFocus: () => utils.triggerFocus(inputRef.current),
202
+ value: formattedValue,
203
+ children: input
204
+ }
205
+ );
206
+ });
207
+ BInput.displayName = "BInput";
208
+ module.exports = BInput;
@@ -1,177 +1,209 @@
1
- import { jsx as a, jsxs as F } from "react/jsx-runtime";
2
- import { forwardRef as Y, useState as M, useRef as y, useImperativeHandle as Z, useEffect as C, cloneElement as O } from "react";
3
- import { triggerFocus as P, resolveOnChange as T, hasPrefixSuffix as q, hasAddon as ee } from "./utils.mjs";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useState, useRef, useImperativeHandle, useEffect, cloneElement } from "react";
3
+ import { triggerFocus, resolveOnChange, hasPrefixSuffix, hasAddon } from "./utils.mjs";
4
4
  /* empty css */
5
- function k(...c) {
6
- return c.filter(Boolean).join(" ");
5
+ function classNames(...values) {
6
+ return values.filter(Boolean).join(" ");
7
7
  }
8
- function ne({
9
- addonAfter: c,
10
- addonBefore: l,
11
- allowClear: t,
12
- children: v,
13
- className: g,
14
- disabled: x,
15
- focused: S,
16
- handleReset: w,
17
- onClear: r,
18
- prefix: f,
19
- readOnly: o,
20
- size: d,
21
- status: N,
22
- suffix: i,
23
- triggerInputFocus: m,
24
- value: p
8
+ function BaseInput({
9
+ addonAfter,
10
+ addonBefore,
11
+ allowClear,
12
+ children,
13
+ className,
14
+ disabled,
15
+ focused,
16
+ handleReset,
17
+ onClear,
18
+ prefix,
19
+ readOnly,
20
+ size,
21
+ status,
22
+ suffix,
23
+ triggerInputFocus,
24
+ value
25
25
  }) {
26
- const b = y(null), _ = q({ prefix: f, suffix: i, allowClear: t }), j = O(v, { value: p });
27
- let s = j;
28
- if (_) {
29
- const B = !!(t && !x && !o && p), I = typeof t == "object" && t.clearIcon ? t.clearIcon : "×";
30
- s = /* @__PURE__ */ F(
26
+ const containerRef = useRef(null);
27
+ const hasAffix = hasPrefixSuffix({ prefix, suffix, allowClear });
28
+ const inputElement = cloneElement(children, { value });
29
+ let element = inputElement;
30
+ if (hasAffix) {
31
+ const needClear = Boolean(allowClear && !disabled && !readOnly && value);
32
+ const clearIcon = typeof allowClear === "object" && allowClear.clearIcon ? allowClear.clearIcon : "×";
33
+ element = /* @__PURE__ */ jsxs(
31
34
  "span",
32
35
  {
33
- className: k(
36
+ className: classNames(
34
37
  "bj-input__affix-wrapper",
35
- x && "bj-input__affix-wrapper--disabled",
36
- S && "bj-input__affix-wrapper--focused",
37
- o && "bj-input__affix-wrapper--readonly",
38
- d && `bj-input__affix-wrapper--${d}`,
39
- N && `bj-input__affix-wrapper--${N}`
38
+ disabled && "bj-input__affix-wrapper--disabled",
39
+ focused && "bj-input__affix-wrapper--focused",
40
+ readOnly && "bj-input__affix-wrapper--readonly",
41
+ size && `bj-input__affix-wrapper--${size}`,
42
+ status && `bj-input__affix-wrapper--${status}`
40
43
  ),
41
- onClick: m,
42
- ref: b,
44
+ onClick: triggerInputFocus,
45
+ ref: containerRef,
43
46
  children: [
44
- f && /* @__PURE__ */ a("span", { className: "bj-input__prefix", children: f }),
45
- j,
46
- (i || t) && /* @__PURE__ */ F("span", { className: "bj-input__suffix", children: [
47
- t && /* @__PURE__ */ a(
47
+ prefix && /* @__PURE__ */ jsx("span", { className: "bj-input__prefix", children: prefix }),
48
+ inputElement,
49
+ (suffix || allowClear) && /* @__PURE__ */ jsxs("span", { className: "bj-input__suffix", children: [
50
+ allowClear && /* @__PURE__ */ jsx(
48
51
  "button",
49
52
  {
50
53
  "aria-label": "清除输入内容",
51
- className: k("bj-input__clear-icon", !B && "bj-input__clear-icon--hidden"),
52
- onClick: (u) => {
53
- w(u), r == null || r();
54
+ className: classNames("bj-input__clear-icon", !needClear && "bj-input__clear-icon--hidden"),
55
+ onClick: (event) => {
56
+ handleReset(event);
57
+ onClear == null ? void 0 : onClear();
54
58
  },
55
- onMouseDown: (u) => u.preventDefault(),
59
+ onMouseDown: (event) => event.preventDefault(),
56
60
  tabIndex: -1,
57
61
  type: "button",
58
- children: I
62
+ children: clearIcon
59
63
  }
60
64
  ),
61
- i
65
+ suffix
62
66
  ] })
63
67
  ]
64
68
  }
65
69
  );
66
70
  }
67
- return ee({ addonBefore: l, addonAfter: c }) && (s = /* @__PURE__ */ a("span", { className: "bj-input__group-wrapper", children: /* @__PURE__ */ F("span", { className: "bj-input__group", children: [
68
- l && /* @__PURE__ */ a("span", { className: "bj-input__group-addon", children: l }),
69
- s,
70
- c && /* @__PURE__ */ a("span", { className: "bj-input__group-addon", children: c })
71
- ] }) })), O(s, { className: k(s.props.className, g) });
71
+ if (hasAddon({ addonBefore, addonAfter })) {
72
+ element = /* @__PURE__ */ jsx("span", { className: "bj-input__group-wrapper", children: /* @__PURE__ */ jsxs("span", { className: "bj-input__group", children: [
73
+ addonBefore && /* @__PURE__ */ jsx("span", { className: "bj-input__group-addon", children: addonBefore }),
74
+ element,
75
+ addonAfter && /* @__PURE__ */ jsx("span", { className: "bj-input__group-addon", children: addonAfter })
76
+ ] }) });
77
+ }
78
+ return cloneElement(element, { className: classNames(element.props.className, className) });
72
79
  }
73
- const te = Y((c, l) => {
80
+ const BInput = forwardRef((props, ref) => {
74
81
  const {
75
- addonAfter: t,
76
- addonBefore: v,
77
- allowClear: g,
78
- bordered: x = !0,
79
- className: S,
80
- defaultValue: w,
81
- disabled: r,
82
- htmlSize: f,
83
- onBlur: o,
84
- onChange: d,
85
- onClear: N,
86
- onCompositionEnd: i,
87
- onCompositionStart: m,
88
- onFocus: p,
89
- onKeyDown: b,
90
- onKeyUp: _,
91
- onPressEnter: j,
92
- prefix: s,
93
- readOnly: B,
94
- size: I = "middle",
95
- status: u,
96
- suffix: z,
97
- type: G = "text",
98
- value: E,
99
- ...J
100
- } = c, [A, V] = M(!1), [K, D] = M(w), n = y(null), H = y(!1), R = y(!1), Q = q({ prefix: s, suffix: z, allowClear: g }), $ = E === void 0 ? K : E, U = $ == null ? "" : String($);
101
- Z(l, () => ({
102
- focus: (e) => P(n.current, e),
82
+ addonAfter,
83
+ addonBefore,
84
+ allowClear,
85
+ bordered = true,
86
+ className,
87
+ defaultValue,
88
+ disabled,
89
+ htmlSize,
90
+ onBlur,
91
+ onChange,
92
+ onClear,
93
+ onCompositionEnd,
94
+ onCompositionStart,
95
+ onFocus,
96
+ onKeyDown,
97
+ onKeyUp,
98
+ onPressEnter,
99
+ prefix,
100
+ readOnly,
101
+ size = "middle",
102
+ status,
103
+ suffix,
104
+ type = "text",
105
+ value: controlledValue,
106
+ ...restProps
107
+ } = props;
108
+ const [focused, setFocused] = useState(false);
109
+ const [innerValue, setInnerValue] = useState(defaultValue);
110
+ const inputRef = useRef(null);
111
+ const compositionRef = useRef(false);
112
+ const keyLockRef = useRef(false);
113
+ const hasAffix = hasPrefixSuffix({ prefix, suffix, allowClear });
114
+ const value = controlledValue === void 0 ? innerValue : controlledValue;
115
+ const formattedValue = value === void 0 || value === null ? "" : String(value);
116
+ useImperativeHandle(ref, () => ({
117
+ focus: (option) => triggerFocus(inputRef.current, option),
103
118
  blur: () => {
104
- var e;
105
- return (e = n.current) == null ? void 0 : e.blur();
119
+ var _a;
120
+ return (_a = inputRef.current) == null ? void 0 : _a.blur();
106
121
  },
107
- setSelectionRange: (...e) => {
108
- var h;
109
- return (h = n.current) == null ? void 0 : h.setSelectionRange(...e);
122
+ setSelectionRange: (...argumentsList) => {
123
+ var _a;
124
+ return (_a = inputRef.current) == null ? void 0 : _a.setSelectionRange(...argumentsList);
110
125
  },
111
126
  select: () => {
112
- var e;
113
- return (e = n.current) == null ? void 0 : e.select();
127
+ var _a;
128
+ return (_a = inputRef.current) == null ? void 0 : _a.select();
114
129
  },
115
- input: n.current,
116
- nativeElement: n.current
117
- })), C(() => V((e) => e && !r), [r]);
118
- const L = (e, h, X) => {
119
- X !== "compositionEnd" && (E === void 0 && D(h), n.current && T(n.current, e, d, h));
120
- }, W = /* @__PURE__ */ a(
130
+ input: inputRef.current,
131
+ nativeElement: inputRef.current
132
+ }));
133
+ useEffect(() => setFocused((previous) => previous && !disabled), [disabled]);
134
+ const triggerChange = (event, nextValue, source) => {
135
+ if (source === "compositionEnd") return;
136
+ if (controlledValue === void 0) setInnerValue(nextValue);
137
+ if (inputRef.current) resolveOnChange(inputRef.current, event, onChange, nextValue);
138
+ };
139
+ const input = /* @__PURE__ */ jsx(
121
140
  "input",
122
141
  {
123
- ...J,
124
- className: k("bj-input", `bj-input--${I}`, A && !Q && "bj-input--focused", u && `bj-input--${u}`, !x && "bj-input--borderless", r && "bj-input--disabled"),
125
- disabled: r,
126
- onBlur: (e) => {
127
- R.current = !1, V(!1), o == null || o(e);
142
+ ...restProps,
143
+ className: classNames("bj-input", `bj-input--${size}`, focused && !hasAffix && "bj-input--focused", status && `bj-input--${status}`, !bordered && "bj-input--borderless", disabled && "bj-input--disabled"),
144
+ disabled,
145
+ onBlur: (event) => {
146
+ keyLockRef.current = false;
147
+ setFocused(false);
148
+ onBlur == null ? void 0 : onBlur(event);
128
149
  },
129
- onChange: (e) => L(e, e.target.value, "change"),
130
- onCompositionEnd: (e) => {
131
- H.current = !1, L(e, e.currentTarget.value, "compositionEnd"), i == null || i(e);
150
+ onChange: (event) => triggerChange(event, event.target.value, "change"),
151
+ onCompositionEnd: (event) => {
152
+ compositionRef.current = false;
153
+ triggerChange(event, event.currentTarget.value, "compositionEnd");
154
+ onCompositionEnd == null ? void 0 : onCompositionEnd(event);
132
155
  },
133
- onCompositionStart: (e) => {
134
- H.current = !0, m == null || m(e);
156
+ onCompositionStart: (event) => {
157
+ compositionRef.current = true;
158
+ onCompositionStart == null ? void 0 : onCompositionStart(event);
135
159
  },
136
- onFocus: (e) => {
137
- V(!0), p == null || p(e);
160
+ onFocus: (event) => {
161
+ setFocused(true);
162
+ onFocus == null ? void 0 : onFocus(event);
138
163
  },
139
- onKeyDown: (e) => {
140
- j && e.key === "Enter" && !R.current && (R.current = !0, j(e)), b == null || b(e);
164
+ onKeyDown: (event) => {
165
+ if (onPressEnter && event.key === "Enter" && !keyLockRef.current) {
166
+ keyLockRef.current = true;
167
+ onPressEnter(event);
168
+ }
169
+ onKeyDown == null ? void 0 : onKeyDown(event);
141
170
  },
142
- onKeyUp: (e) => {
143
- e.key === "Enter" && (R.current = !1), _ == null || _(e);
171
+ onKeyUp: (event) => {
172
+ if (event.key === "Enter") keyLockRef.current = false;
173
+ onKeyUp == null ? void 0 : onKeyUp(event);
144
174
  },
145
- ref: n,
146
- size: f,
147
- type: G
175
+ ref: inputRef,
176
+ size: htmlSize,
177
+ type
148
178
  }
149
179
  );
150
- return /* @__PURE__ */ a(
151
- ne,
180
+ return /* @__PURE__ */ jsx(
181
+ BaseInput,
152
182
  {
153
- addonAfter: t,
154
- addonBefore: v,
155
- allowClear: g,
156
- className: S,
157
- disabled: r,
158
- focused: A,
159
- handleReset: (e) => {
160
- E === void 0 && D(""), P(n.current), n.current && T(n.current, e, d);
183
+ addonAfter,
184
+ addonBefore,
185
+ allowClear,
186
+ className,
187
+ disabled,
188
+ focused,
189
+ handleReset: (event) => {
190
+ if (controlledValue === void 0) setInnerValue("");
191
+ triggerFocus(inputRef.current);
192
+ if (inputRef.current) resolveOnChange(inputRef.current, event, onChange);
161
193
  },
162
- onClear: N,
163
- prefix: s,
164
- readOnly: B,
165
- size: I,
166
- status: u,
167
- suffix: z,
168
- triggerInputFocus: () => P(n.current),
169
- value: U,
170
- children: W
194
+ onClear,
195
+ prefix,
196
+ readOnly,
197
+ size,
198
+ status,
199
+ suffix,
200
+ triggerInputFocus: () => triggerFocus(inputRef.current),
201
+ value: formattedValue,
202
+ children: input
171
203
  }
172
204
  );
173
205
  });
174
- te.displayName = "BInput";
206
+ BInput.displayName = "BInput";
175
207
  export {
176
- te as default
208
+ BInput as default
177
209
  };
@@ -1 +1,47 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function f(e){return!!(e.addonBefore||e.addonAfter)}function s(e){return!!(e.prefix||e.suffix||e.allowClear)}function c(e,n,r){const t=n.cloneNode(!0),u=Object.create(e,{target:{value:t},currentTarget:{value:t}});return t.value=r,typeof n.selectionStart=="number"&&typeof n.selectionEnd=="number"&&(t.selectionStart=n.selectionStart,t.selectionEnd=n.selectionEnd),t.setSelectionRange=(...i)=>n.setSelectionRange(...i),u}function l(e,n,r,t){if(r){if(n.type==="click"){r(c(n,e,""));return}if(e.type!=="file"&&t!==void 0){r(c(n,e,t));return}r(n)}}function o(e,n){if(!e||(e.focus(n),!(n!=null&&n.cursor)))return;const r=e.value.length;n.cursor==="start"?e.setSelectionRange(0,0):n.cursor==="end"?e.setSelectionRange(r,r):e.setSelectionRange(0,r)}exports.hasAddon=f;exports.hasPrefixSuffix=s;exports.resolveOnChange=l;exports.triggerFocus=o;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function hasAddon(props) {
4
+ return Boolean(props.addonBefore || props.addonAfter);
5
+ }
6
+ function hasPrefixSuffix(props) {
7
+ return Boolean(props.prefix || props.suffix || props.allowClear);
8
+ }
9
+ function cloneEvent(event, target, value) {
10
+ const currentTarget = target.cloneNode(true);
11
+ const nextEvent = Object.create(event, {
12
+ target: { value: currentTarget },
13
+ currentTarget: { value: currentTarget }
14
+ });
15
+ currentTarget.value = value;
16
+ if (typeof target.selectionStart === "number" && typeof target.selectionEnd === "number") {
17
+ currentTarget.selectionStart = target.selectionStart;
18
+ currentTarget.selectionEnd = target.selectionEnd;
19
+ }
20
+ currentTarget.setSelectionRange = (...argumentsList) => target.setSelectionRange(...argumentsList);
21
+ return nextEvent;
22
+ }
23
+ function resolveOnChange(target, event, onChange, targetValue) {
24
+ if (!onChange) return;
25
+ if (event.type === "click") {
26
+ onChange(cloneEvent(event, target, ""));
27
+ return;
28
+ }
29
+ if (target.type !== "file" && targetValue !== void 0) {
30
+ onChange(cloneEvent(event, target, targetValue));
31
+ return;
32
+ }
33
+ onChange(event);
34
+ }
35
+ function triggerFocus(element, option) {
36
+ if (!element) return;
37
+ element.focus(option);
38
+ if (!(option == null ? void 0 : option.cursor)) return;
39
+ const length = element.value.length;
40
+ if (option.cursor === "start") element.setSelectionRange(0, 0);
41
+ else if (option.cursor === "end") element.setSelectionRange(length, length);
42
+ else element.setSelectionRange(0, length);
43
+ }
44
+ exports.hasAddon = hasAddon;
45
+ exports.hasPrefixSuffix = hasPrefixSuffix;
46
+ exports.resolveOnChange = resolveOnChange;
47
+ exports.triggerFocus = triggerFocus;