@cloudtower/eagle 481.0.2 → 481.0.3

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 (30) hide show
  1. package/dist/cjs/core/Cascader/cascader.widget.js +12 -12
  2. package/dist/cjs/core/SearchInput/SearchInput.hook.js +124 -0
  3. package/dist/cjs/core/SearchInput/SearchInput.js +253 -0
  4. package/dist/cjs/core/SearchInput/SearchInput.style.js +13 -0
  5. package/dist/cjs/core/index.js +6 -6
  6. package/dist/cjs/index.js +172 -172
  7. package/dist/cjs/legacy-antd.js +89 -89
  8. package/dist/cjs/stats1.html +1 -1
  9. package/dist/components.css +2240 -2217
  10. package/dist/esm/core/Cascader/cascader.widget.js +1 -1
  11. package/dist/esm/core/SearchInput/SearchInput.hook.js +117 -0
  12. package/dist/esm/core/SearchInput/SearchInput.js +247 -0
  13. package/dist/esm/core/SearchInput/SearchInput.style.js +7 -0
  14. package/dist/esm/index.js +1 -1
  15. package/dist/esm/legacy-antd.js +1 -1
  16. package/dist/esm/stats1.html +1 -1
  17. package/dist/linaria.merged.scss +2372 -2343
  18. package/dist/src/core/Cascader/cascader.type.d.ts +1 -1
  19. package/dist/src/core/SearchInput/SearchInput.d.ts +2 -0
  20. package/dist/src/core/SearchInput/SearchInput.hook.d.ts +9 -0
  21. package/dist/src/core/SearchInput/SearchInput.style.d.ts +5 -0
  22. package/dist/src/core/SearchInput/{searchInput.type.d.ts → SearchInput.type.d.ts} +18 -2
  23. package/dist/src/core/SearchInput/__test__/SearchInput.hook.test.d.ts +1 -0
  24. package/dist/src/core/SearchInput/index.d.ts +2 -4
  25. package/dist/src/core/index.d.ts +0 -1
  26. package/dist/stories/docs/core/SearchInput.stories.d.ts +6 -1
  27. package/dist/style.css +2240 -2217
  28. package/package.json +4 -4
  29. package/dist/cjs/core/SearchInput/index.js +0 -164
  30. package/dist/esm/core/SearchInput/index.js +0 -157
@@ -6,9 +6,9 @@ import useParrotTranslation from '../../hooks/useParrotTranslation.js';
6
6
  import { Flex } from 'antd5';
7
7
  import cs from 'classnames';
8
8
  import React__default, { useState } from 'react';
9
- import SearchInput from '../SearchInput/index.js';
10
9
  import { Typo } from '../Typo/index.js';
11
10
  import { CascaderNotData, CascaderDefaultHeaderContainer, CascaderDefaultHeaderSearch, CascaderDefaultHeader, DoubleRowOptionStyleWrapper, Hide, CascaderDefaultOptionLabel } from './cascader.style.js';
11
+ import { SearchInput } from '../SearchInput/SearchInput.js';
12
12
 
13
13
  var __defProp = Object.defineProperty;
14
14
  var __defProps = Object.defineProperties;
@@ -0,0 +1,117 @@
1
+ import { Search24Icon, Search24BlueIcon } from '@cloudtower/icons-react';
2
+ import { cx } from '@linaria/core';
3
+ import Icon from '../Icon/index.js';
4
+ import { Typo } from '../Typo/index.js';
5
+ import useParrotTranslation from '../../hooks/useParrotTranslation.js';
6
+ import { debounce } from 'lodash';
7
+ import React__default, { useState, useEffect, useRef, useMemo } from 'react';
8
+ import OverflowTooltip from '../../coreX/OverflowTooltip/index.js';
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __defProps = Object.defineProperties;
12
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
13
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
16
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
+ var __spreadValues = (a, b) => {
18
+ for (var prop in b || (b = {}))
19
+ if (__hasOwnProp.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ if (__getOwnPropSymbols)
22
+ for (var prop of __getOwnPropSymbols(b)) {
23
+ if (__propIsEnum.call(b, prop))
24
+ __defNormalProp(a, prop, b[prop]);
25
+ }
26
+ return a;
27
+ };
28
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
29
+ const searchInputRecentSearchLocalStorageKey = "search-input-recent-search";
30
+ const useRecentSearch = (recentSearchLocalStorageKey, maxRecentCount, setValue, onChange) => {
31
+ const { t } = useParrotTranslation();
32
+ const [recentSearchKeys, setRecentSearchKeys] = useState([]);
33
+ useEffect(() => {
34
+ if (!recentSearchLocalStorageKey)
35
+ return;
36
+ try {
37
+ const currRecentSearchKeys = JSON.parse(
38
+ localStorage.getItem(searchInputRecentSearchLocalStorageKey) || "{}"
39
+ )[recentSearchLocalStorageKey];
40
+ setRecentSearchKeys(currRecentSearchKeys || []);
41
+ } catch (error) {
42
+ setRecentSearchKeys([]);
43
+ }
44
+ }, [recentSearchLocalStorageKey]);
45
+ const setRecentSearchKeysDebounceRef = useRef();
46
+ useEffect(() => {
47
+ if (!recentSearchLocalStorageKey)
48
+ return;
49
+ const fn = debounce((val) => {
50
+ if (!val || !recentSearchLocalStorageKey)
51
+ return;
52
+ setRecentSearchKeys((preState) => {
53
+ const newState = [...preState].filter((item) => item !== val);
54
+ if (newState.length >= maxRecentCount)
55
+ newState.pop();
56
+ newState.unshift(val);
57
+ try {
58
+ const recentSearchMap = JSON.parse(
59
+ localStorage.getItem(searchInputRecentSearchLocalStorageKey) || "{}"
60
+ );
61
+ localStorage.setItem(
62
+ searchInputRecentSearchLocalStorageKey,
63
+ JSON.stringify(__spreadProps(__spreadValues({}, recentSearchMap), {
64
+ [recentSearchLocalStorageKey]: newState
65
+ }))
66
+ );
67
+ } catch (err) {
68
+ console.error(err);
69
+ }
70
+ return newState;
71
+ });
72
+ }, 400);
73
+ setRecentSearchKeysDebounceRef.current = fn;
74
+ return () => fn.cancel();
75
+ }, [maxRecentCount, recentSearchLocalStorageKey]);
76
+ const antd5DropdownMenu = useMemo(
77
+ () => ({
78
+ onClick: ({ key: val }) => {
79
+ var _a;
80
+ setValue(val);
81
+ onChange == null ? void 0 : onChange(val);
82
+ (_a = setRecentSearchKeysDebounceRef.current) == null ? void 0 : _a.call(setRecentSearchKeysDebounceRef, val);
83
+ },
84
+ items: [
85
+ {
86
+ key: "recent-search",
87
+ className: cx("recent-search-menu-item", Typo.Label.l4_regular),
88
+ disabled: true,
89
+ label: /* @__PURE__ */ React__default.createElement("span", null, t("components.recent_search"))
90
+ },
91
+ ...recentSearchKeys.map((k) => ({
92
+ key: k,
93
+ label: /* @__PURE__ */ React__default.createElement(
94
+ Icon,
95
+ {
96
+ src: Search24Icon,
97
+ hoverSrc: Search24BlueIcon,
98
+ iconHeight: 24,
99
+ iconWidth: 24
100
+ },
101
+ /* @__PURE__ */ React__default.createElement(OverflowTooltip, { content: k })
102
+ )
103
+ }))
104
+ ],
105
+ // 避免 Dropdown 点击时被 Input blur 关闭
106
+ onMouseDown: (e) => e.preventDefault()
107
+ }),
108
+ [onChange, recentSearchKeys, setRecentSearchKeysDebounceRef, setValue, t]
109
+ );
110
+ return {
111
+ recentSearchKeys,
112
+ setRecentSearchKeysDebounceRef,
113
+ antd5DropdownMenu
114
+ };
115
+ };
116
+
117
+ export { searchInputRecentSearchLocalStorageKey, useRecentSearch };
@@ -0,0 +1,247 @@
1
+ import { SearchOutlined } from '@ant-design/icons';
2
+ import { ArrowChevronUp16SecondaryIcon, ArrowChevronUp16BlueIcon, ArrowChevronDown16SecondaryIcon, ArrowChevronDown16BlueIcon, XmarkCloseCircleFill16TertiaryIcon, XmarkCloseCircleFill16SecondaryIcon } from '@cloudtower/icons-react';
3
+ import { cx } from '@linaria/core';
4
+ import Icon from '../Icon/index.js';
5
+ import Input from '../Input/index.js';
6
+ import Tooltip from '../Tooltip/index.js';
7
+ import { Typo } from '../Typo/index.js';
8
+ import useParrotTranslation from '../../hooks/useParrotTranslation.js';
9
+ import { debounce } from 'lodash';
10
+ import React__default, { useState, useRef, useEffect, useCallback } from 'react';
11
+ import { useRecentSearch } from './SearchInput.hook.js';
12
+ import { CountTextStyles, IconContainerStyles, DisabledIconStyles, SearchInputStyles, SearchInputDropdownStyles } from './SearchInput.style.js';
13
+ import { Antd5Dropdown } from '../Antd5Dropdown/Antd5Dropdown.js';
14
+
15
+ var __defProp = Object.defineProperty;
16
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
17
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
18
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
19
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
20
+ var __spreadValues = (a, b) => {
21
+ for (var prop in b || (b = {}))
22
+ if (__hasOwnProp.call(b, prop))
23
+ __defNormalProp(a, prop, b[prop]);
24
+ if (__getOwnPropSymbols)
25
+ for (var prop of __getOwnPropSymbols(b)) {
26
+ if (__propIsEnum.call(b, prop))
27
+ __defNormalProp(a, prop, b[prop]);
28
+ }
29
+ return a;
30
+ };
31
+ var __objRest = (source, exclude) => {
32
+ var target = {};
33
+ for (var prop in source)
34
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
35
+ target[prop] = source[prop];
36
+ if (source != null && __getOwnPropSymbols)
37
+ for (var prop of __getOwnPropSymbols(source)) {
38
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
39
+ target[prop] = source[prop];
40
+ }
41
+ return target;
42
+ };
43
+ const SearchInput = (props) => {
44
+ const _a = props, {
45
+ className,
46
+ debounceWait = 300,
47
+ total = 0,
48
+ onSearchNext,
49
+ onSearchPrev,
50
+ prefixHoverIcon,
51
+ nextHoverIcon,
52
+ clearHoverIcon,
53
+ prefixIcon,
54
+ nextIcon,
55
+ clearIcon,
56
+ width = 276,
57
+ searchIcon,
58
+ enableRecentSearch,
59
+ recentSearchLocalStorageKey,
60
+ maxRecentCount = 5,
61
+ current: externalCurrent,
62
+ onChange,
63
+ onFocus,
64
+ onBlur
65
+ } = _a, restProps = __objRest(_a, [
66
+ "className",
67
+ "debounceWait",
68
+ "total",
69
+ "onSearchNext",
70
+ "onSearchPrev",
71
+ "prefixHoverIcon",
72
+ "nextHoverIcon",
73
+ "clearHoverIcon",
74
+ "prefixIcon",
75
+ "nextIcon",
76
+ "clearIcon",
77
+ "width",
78
+ "searchIcon",
79
+ "enableRecentSearch",
80
+ "recentSearchLocalStorageKey",
81
+ "maxRecentCount",
82
+ "current",
83
+ "onChange",
84
+ "onFocus",
85
+ "onBlur"
86
+ ]);
87
+ const [internalCurrent, setInternalCurrent] = useState(0);
88
+ const [value, setValue] = useState(props.value || "");
89
+ const { t } = useParrotTranslation();
90
+ const isNoMatch = total === 0;
91
+ const [inputFocused, setInputFocused] = useState(false);
92
+ const {
93
+ recentSearchKeys,
94
+ setRecentSearchKeysDebounceRef,
95
+ antd5DropdownMenu
96
+ } = useRecentSearch(
97
+ recentSearchLocalStorageKey,
98
+ maxRecentCount,
99
+ setValue,
100
+ onChange
101
+ );
102
+ const debounceOnChangeRef = useRef();
103
+ useEffect(() => {
104
+ const fn = debounce((val) => {
105
+ var _a2;
106
+ onChange == null ? void 0 : onChange(val);
107
+ if (enableRecentSearch && val) {
108
+ (_a2 = setRecentSearchKeysDebounceRef.current) == null ? void 0 : _a2.call(setRecentSearchKeysDebounceRef, val);
109
+ }
110
+ }, debounceWait);
111
+ debounceOnChangeRef.current = fn;
112
+ return () => fn.cancel();
113
+ }, [
114
+ onChange,
115
+ enableRecentSearch,
116
+ debounceWait,
117
+ setRecentSearchKeysDebounceRef
118
+ ]);
119
+ const current = externalCurrent !== void 0 ? externalCurrent : internalCurrent;
120
+ const setCurrent = useCallback(
121
+ (newCurrent) => {
122
+ if (externalCurrent === void 0) {
123
+ setInternalCurrent(newCurrent);
124
+ }
125
+ },
126
+ [externalCurrent]
127
+ );
128
+ const next = useCallback(() => {
129
+ if (total) {
130
+ const nextCurrent = current + 1 > total ? 1 : current + 1;
131
+ onSearchNext == null ? void 0 : onSearchNext(value, nextCurrent);
132
+ setCurrent(nextCurrent);
133
+ }
134
+ }, [onSearchNext, current, total, value, setCurrent]);
135
+ const prev = useCallback(() => {
136
+ if (total) {
137
+ const prevCurrent = current - 1 < 1 ? total : current - 1;
138
+ onSearchPrev == null ? void 0 : onSearchPrev(value, prevCurrent);
139
+ setCurrent(prevCurrent);
140
+ }
141
+ }, [onSearchPrev, current, total, value, setCurrent]);
142
+ const suffix = onSearchNext && onSearchPrev && value ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, typeof total === "number" ? /* @__PURE__ */ React__default.createElement(
143
+ "span",
144
+ {
145
+ className: cx(
146
+ Typo.Label.l4_regular,
147
+ "counter-text",
148
+ CountTextStyles
149
+ )
150
+ },
151
+ current,
152
+ "/",
153
+ total
154
+ ) : null, /* @__PURE__ */ React__default.createElement("span", { className: IconContainerStyles }, isNoMatch ? /* @__PURE__ */ React__default.createElement(
155
+ Icon,
156
+ {
157
+ className: DisabledIconStyles,
158
+ src: ArrowChevronUp16SecondaryIcon,
159
+ style: { opacity: 0.5 }
160
+ }
161
+ ) : /* @__PURE__ */ React__default.createElement(Tooltip, { title: t("components.prev") }, /* @__PURE__ */ React__default.createElement(
162
+ Icon,
163
+ {
164
+ src: prefixIcon != null ? prefixIcon : ArrowChevronUp16SecondaryIcon,
165
+ hoverSrc: prefixHoverIcon != null ? prefixHoverIcon : ArrowChevronUp16BlueIcon,
166
+ onClick: prev
167
+ }
168
+ )), isNoMatch ? /* @__PURE__ */ React__default.createElement(
169
+ Icon,
170
+ {
171
+ className: DisabledIconStyles,
172
+ src: ArrowChevronDown16SecondaryIcon,
173
+ style: { opacity: 0.5 }
174
+ }
175
+ ) : /* @__PURE__ */ React__default.createElement(Tooltip, { title: t("components.next") }, /* @__PURE__ */ React__default.createElement(
176
+ Icon,
177
+ {
178
+ src: nextIcon != null ? nextIcon : ArrowChevronDown16SecondaryIcon,
179
+ hoverSrc: nextHoverIcon != null ? nextHoverIcon : ArrowChevronDown16BlueIcon,
180
+ onClick: next
181
+ }
182
+ )), /* @__PURE__ */ React__default.createElement(Tooltip, { title: t("components.clear") }, /* @__PURE__ */ React__default.createElement(
183
+ Icon,
184
+ {
185
+ src: clearIcon != null ? clearIcon : XmarkCloseCircleFill16TertiaryIcon,
186
+ hoverSrc: clearHoverIcon != null ? clearHoverIcon : XmarkCloseCircleFill16SecondaryIcon,
187
+ onClick: () => {
188
+ var _a2;
189
+ setValue("");
190
+ (_a2 = debounceOnChangeRef.current) == null ? void 0 : _a2.call(debounceOnChangeRef, "");
191
+ }
192
+ }
193
+ )))) : null;
194
+ useEffect(() => {
195
+ setValue(props.value || "");
196
+ }, [props.value]);
197
+ useEffect(() => {
198
+ if (externalCurrent === void 0) {
199
+ setCurrent(total ? 1 : 0);
200
+ }
201
+ }, [value, total, externalCurrent, setCurrent]);
202
+ const InputComponent = /* @__PURE__ */ React__default.createElement(
203
+ Input,
204
+ __spreadValues({
205
+ className: cx(SearchInputStyles, className),
206
+ style: { width },
207
+ prefix: searchIcon ? /* @__PURE__ */ React__default.createElement(Icon, { src: searchIcon }) : /* @__PURE__ */ React__default.createElement(SearchOutlined, null),
208
+ suffix,
209
+ onPressEnter: next,
210
+ value,
211
+ onChange: (e) => {
212
+ var _a2;
213
+ const newValue = e.target.value || "";
214
+ setValue(newValue);
215
+ (_a2 = debounceOnChangeRef.current) == null ? void 0 : _a2.call(debounceOnChangeRef, newValue);
216
+ },
217
+ onFocus: (e) => {
218
+ setInputFocused(true);
219
+ onFocus == null ? void 0 : onFocus(e);
220
+ },
221
+ onBlur: (e) => {
222
+ setInputFocused(false);
223
+ onBlur == null ? void 0 : onBlur(e);
224
+ }
225
+ }, restProps)
226
+ );
227
+ if (enableRecentSearch)
228
+ return /* @__PURE__ */ React__default.createElement(
229
+ Antd5Dropdown,
230
+ {
231
+ overlayClassName: cx(
232
+ "recent-search-dropdown",
233
+ SearchInputDropdownStyles
234
+ ),
235
+ overlayStyle: { width },
236
+ transitionName: "",
237
+ placement: "bottomLeft",
238
+ trigger: ["click"],
239
+ open: inputFocused && !value && !!recentSearchKeys.length,
240
+ menu: antd5DropdownMenu
241
+ },
242
+ InputComponent
243
+ );
244
+ return InputComponent;
245
+ };
246
+
247
+ export { SearchInput };
@@ -0,0 +1,7 @@
1
+ const SearchInputStyles = "E_s1n7hav7";
2
+ const CountTextStyles = "E_c1tgpyn0";
3
+ const IconContainerStyles = "E_i1cmbu8m";
4
+ const DisabledIconStyles = "E_dxmfsc9";
5
+ const SearchInputDropdownStyles = "E_slbf45q";
6
+
7
+ export { CountTextStyles, DisabledIconStyles, IconContainerStyles, SearchInputDropdownStyles, SearchInputStyles };
package/dist/esm/index.js CHANGED
@@ -60,7 +60,6 @@ export { ExtraOverflow, default as Overflow } from './core/Overflow/index.js';
60
60
  export { default as Pagination, PaginationStyle } from './core/Pagination/index.js';
61
61
  export { default as Percent } from './core/Percent/index.js';
62
62
  export { default as Radio, RadioButton, RadioGroup } from './core/Radio/index.js';
63
- export { default as SearchInput } from './core/SearchInput/index.js';
64
63
  export { default as Second } from './core/Second/index.js';
65
64
  export { default as SegmentControl } from './core/SegmentControl/index.js';
66
65
  export { default as Select } from './core/Select/index.js';
@@ -110,6 +109,7 @@ export { GraphType, TimeUnit } from './core/Metric/type.js';
110
109
  export { ParrotTrans } from './core/ParrotTrans/index.js';
111
110
  export { Area, TitleArea } from './core/Progress/progress.widgets.js';
112
111
  export { Progress } from './core/Progress/index.js';
112
+ export { SearchInput } from './core/SearchInput/SearchInput.js';
113
113
  export { getOptions } from './core/Select/select.widgets.js';
114
114
  export { SidebarMenu } from './core/SidebarMenu/SidebarMenu.js';
115
115
  export { default as Skeleton } from './core/Skeleton/index.js';
@@ -36,7 +36,6 @@ import _message from './core/message/message.js';
36
36
  import Pagination from './core/Pagination/index.js';
37
37
  import Percent from './core/Percent/index.js';
38
38
  import Radio, { RadioGroup, RadioButton } from './core/Radio/index.js';
39
- import SearchInput from './core/SearchInput/index.js';
40
39
  import Second from './core/Second/index.js';
41
40
  import SegmentControl from './core/SegmentControl/index.js';
42
41
  import Select from './core/Select/index.js';
@@ -72,6 +71,7 @@ import SummaryTable from './coreX/SummaryTable/index.js';
72
71
  import SwitchWithText from './coreX/SwitchWithText/index.js';
73
72
  import UnitWithChart from './coreX/UnitWithChart/index.js';
74
73
  import DateRangePicker from './coreX/DateRangePicker/index.js';
74
+ import { SearchInput } from './core/SearchInput/SearchInput.js';
75
75
 
76
76
  function getAntdKit() {
77
77
  const kit = {