@pisell/materials 6.11.4 → 6.11.6
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/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/index.js +1 -1
- package/build/lowcode/meta.js +7 -7
- package/build/lowcode/preview.js +9 -9
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +16 -16
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +15 -15
- package/es/components/PisellSuperTabs/PisellSuperTabs.d.ts +1 -1
- package/es/components/PisellSuperTabs/PisellSuperTabs.js +7 -4
- package/es/components/PisellSuperTabs/hooks/useTabsState.js +3 -8
- package/es/components/PisellSuperTabs/types.d.ts +2 -0
- package/es/components/PisellTabbar/PisellTabbar.d.ts +1 -1
- package/es/components/PisellTabbar/PisellTabbar.js +411 -62
- package/es/components/PisellTabbar/constants.d.ts +2 -1
- package/es/components/PisellTabbar/constants.js +5 -4
- package/es/components/PisellTabbar/hooks/useActiveKey.d.ts +6 -0
- package/es/components/PisellTabbar/hooks/useActiveKey.js +21 -2
- package/es/components/PisellTabbar/hooks/useExpand.d.ts +1 -0
- package/es/components/PisellTabbar/hooks/useExpand.js +9 -1
- package/es/components/PisellTabbar/template/Template1/PisellTabbar.d.ts +3 -18
- package/es/components/PisellTabbar/template/Template1/PisellTabbar.js +124 -28
- package/es/components/PisellTabbar/template/Template1/constants.js +1 -1
- package/es/components/PisellTabbar/types.d.ts +5 -26
- package/es/components/PisellTabbar/utils/index.d.ts +2 -1
- package/es/components/PisellTabbar/utils/index.js +2 -1
- package/es/components/dataSourceComponents/dataSourceTable/hooks/useDataSourceKey.d.ts +2 -2
- package/es/components/dataSourceComponents/dataSourceTable/hooks/useTableProps.d.ts +2 -2
- package/es/components/page/index.js +6 -1
- package/es/components/pisellDataSourceContainer/hooks/useDataSourceKey.d.ts +2 -2
- package/es/components/pisellDateTimeDisplay/PisellDateTimeDisplay.js +47 -34
- package/es/components/pisellDateTimeDisplay/PisellDateTimeDisplay.stories.d.ts +19 -0
- package/es/components/pisellDateTimeDisplay/PisellDateTimeDisplay.stories.js +74 -0
- package/es/components/pisellDateTimeDisplay/components/DateDisplay.d.ts +6 -1
- package/es/components/pisellDateTimeDisplay/components/DateDisplay.js +10 -3
- package/es/components/pisellDateTimeDisplay/formats/dateTimeDisplayFormats.d.ts +7 -0
- package/es/components/pisellDateTimeDisplay/formats/dateTimeDisplayFormats.js +81 -0
- package/es/components/pisellDateTimeDisplay/formats/index.d.ts +1 -0
- package/es/components/pisellDateTimeDisplay/formats/index.js +1 -0
- package/es/components/pisellDateTimeDisplay/hooks/useCurrentTime.d.ts +2 -2
- package/es/components/pisellDateTimeDisplay/hooks/useCurrentTime.js +2 -2
- package/es/components/pisellDateTimeDisplay/index.d.ts +1 -0
- package/es/components/pisellDateTimeDisplay/index.js +2 -1
- package/es/components/pisellDateTimeDisplay/types.d.ts +48 -2
- package/es/components/pisellDateTimeDisplay/utils/formatDate.js +25 -6
- package/es/components/pisellDateTimeDisplay/utils/formatDateOrRelative.d.ts +17 -0
- package/es/components/pisellDateTimeDisplay/utils/formatDateOrRelative.js +38 -0
- package/es/components/pisellDateTimeDisplay/utils/formatWeekday.js +11 -12
- package/es/components/pisellDateTimeDisplay/utils/index.d.ts +3 -1
- package/es/components/pisellDateTimeDisplay/utils/index.js +3 -1
- package/es/components/pisellDateTimeDisplay/utils/localeUtils.d.ts +2 -7
- package/es/components/pisellDateTimeDisplay/utils/localeUtils.js +4 -17
- package/es/components/pisellDateTimeDisplay/utils/relativeDay.d.ts +23 -0
- package/es/components/pisellDateTimeDisplay/utils/relativeDay.js +45 -0
- package/es/components/pisellEmail/PisellEmail.less +2 -2
- package/es/components/pisellFind/PisellFind.stories.d.ts +45 -0
- package/es/components/pisellFind/PisellFind.stories.js +479 -0
- package/es/components/pisellFind/index.d.ts +40 -0
- package/es/components/pisellFind/index.js +72 -0
- package/es/components/pisellLongText/PisellLongText.less +2 -2
- package/es/components/pisellLookup/PisellLookup.d.ts +4 -0
- package/es/components/pisellLookup/PisellLookup.js +636 -0
- package/es/components/pisellLookup/PisellLookup.less +640 -0
- package/es/components/pisellLookup/PisellLookup.stories.d.ts +129 -0
- package/es/components/pisellLookup/PisellLookup.stories.js +1012 -0
- package/es/components/pisellLookup/components/HotWords.d.ts +7 -0
- package/es/components/pisellLookup/components/HotWords.js +49 -0
- package/es/components/pisellLookup/components/LookupAuxiliary.d.ts +7 -0
- package/es/components/pisellLookup/components/LookupAuxiliary.js +59 -0
- package/es/components/pisellLookup/components/LookupResultHost.d.ts +7 -0
- package/es/components/pisellLookup/components/LookupResultHost.js +185 -0
- package/es/components/pisellLookup/components/LookupTrigger.d.ts +3 -0
- package/es/components/pisellLookup/components/LookupTrigger.js +358 -0
- package/es/components/pisellLookup/components/SearchHistory.d.ts +7 -0
- package/es/components/pisellLookup/components/SearchHistory.js +68 -0
- package/es/components/pisellLookup/components/SuggestWords.d.ts +7 -0
- package/es/components/pisellLookup/components/SuggestWords.js +53 -0
- package/es/components/pisellLookup/components/index.d.ts +9 -0
- package/es/components/pisellLookup/components/index.js +10 -0
- package/es/components/pisellLookup/hooks/index.d.ts +6 -0
- package/es/components/pisellLookup/hooks/index.js +7 -0
- package/es/components/pisellLookup/hooks/useDebounceSearch.d.ts +40 -0
- package/es/components/pisellLookup/hooks/useDebounceSearch.js +78 -0
- package/es/components/pisellLookup/hooks/useSearchHistory.d.ts +48 -0
- package/es/components/pisellLookup/hooks/useSearchHistory.js +125 -0
- package/es/components/pisellLookup/hooks/useSearchState.d.ts +80 -0
- package/es/components/pisellLookup/hooks/useSearchState.js +113 -0
- package/es/components/pisellLookup/index.d.ts +6 -0
- package/es/components/pisellLookup/index.js +5 -0
- package/es/components/pisellLookup/types.d.ts +666 -0
- package/es/components/pisellLookup/types.js +1 -0
- package/es/components/pisellLookup/utils/index.d.ts +5 -0
- package/es/components/pisellLookup/utils/index.js +6 -0
- package/es/components/pisellLookup/utils/storage.d.ts +42 -0
- package/es/components/pisellLookup/utils/storage.js +118 -0
- package/es/components/pisellLookup/utils/trigger.d.ts +42 -0
- package/es/components/pisellLookup/utils/trigger.js +76 -0
- package/es/components/pisellMultipleSelect/PisellMultipleSelect.less +7 -7
- package/es/components/pisellSingleLineText/PisellSingleLineText.less +143 -4
- package/es/components/pisellSingleSelect/PisellSingleSelect.less +6 -6
- package/es/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.d.ts +32 -0
- package/es/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.js +197 -0
- package/es/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.less +49 -0
- package/es/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.stories.d.ts +61 -0
- package/es/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.stories.js +209 -0
- package/es/components/pisellTimeRangeDisplay/components/DateBlock.d.ts +20 -0
- package/es/components/pisellTimeRangeDisplay/components/DateBlock.js +30 -0
- package/es/components/pisellTimeRangeDisplay/components/DurationBlock.d.ts +19 -0
- package/es/components/pisellTimeRangeDisplay/components/DurationBlock.js +25 -0
- package/es/components/pisellTimeRangeDisplay/components/TimeRangeBlock.d.ts +30 -0
- package/es/components/pisellTimeRangeDisplay/components/TimeRangeBlock.js +86 -0
- package/es/components/pisellTimeRangeDisplay/components/WeekdayBlock.d.ts +18 -0
- package/es/components/pisellTimeRangeDisplay/components/WeekdayBlock.js +23 -0
- package/es/components/pisellTimeRangeDisplay/components/index.d.ts +8 -0
- package/es/components/pisellTimeRangeDisplay/components/index.js +4 -0
- package/es/components/pisellTimeRangeDisplay/index.d.ts +3 -0
- package/es/components/pisellTimeRangeDisplay/index.js +1 -0
- package/es/components/pisellTimeRangeDisplay/types.d.ts +137 -0
- package/es/components/pisellTimeRangeDisplay/types.js +1 -0
- package/es/components/pisellTimeRangeDisplay/utils/formatDuration.d.ts +14 -0
- package/es/components/pisellTimeRangeDisplay/utils/formatDuration.js +53 -0
- package/es/components/pisellTimeRangeDisplay/utils/index.d.ts +4 -0
- package/es/components/pisellTimeRangeDisplay/utils/index.js +5 -0
- package/es/components/pisellTimeRangeDisplay/utils/parseTimeRange.d.ts +23 -0
- package/es/components/pisellTimeRangeDisplay/utils/parseTimeRange.js +27 -0
- package/es/components/pisellUrl/PisellUrl.less +1 -1
- package/es/components/productCard/cartSkuCard/components/packages/utils.d.ts +1 -1
- package/es/components/productCard/components/Packages/utils.d.ts +1 -1
- package/es/components/table/Gallery/components/VirtualGrid/useGapSize.d.ts +2 -2
- package/es/components/table/Table/fields/select/filterUtil/index.d.ts +1 -1
- package/es/components/table/Table/fields/treeSelect/filterUtil/index.d.ts +1 -1
- package/es/index.d.ts +6 -0
- package/es/index.js +10 -1
- package/es/locales/en-US.d.ts +14 -0
- package/es/locales/en-US.js +16 -0
- package/es/locales/zh-CN.d.ts +14 -0
- package/es/locales/zh-CN.js +16 -0
- package/es/locales/zh-TW.d.ts +14 -0
- package/es/locales/zh-TW.js +16 -0
- package/es/theme/tokens.js +105 -125
- package/es/utils/index.d.ts +1 -1
- package/es/utils/platform.d.ts +1 -1
- package/lib/components/PisellSuperTabs/PisellSuperTabs.d.ts +1 -1
- package/lib/components/PisellSuperTabs/PisellSuperTabs.js +6 -4
- package/lib/components/PisellSuperTabs/hooks/useTabsState.js +1 -2
- package/lib/components/PisellSuperTabs/types.d.ts +2 -0
- package/lib/components/PisellTabbar/PisellTabbar.d.ts +1 -1
- package/lib/components/PisellTabbar/PisellTabbar.js +522 -139
- package/lib/components/PisellTabbar/constants.d.ts +2 -1
- package/lib/components/PisellTabbar/constants.js +5 -4
- package/lib/components/PisellTabbar/hooks/useActiveKey.d.ts +6 -0
- package/lib/components/PisellTabbar/hooks/useActiveKey.js +14 -1
- package/lib/components/PisellTabbar/hooks/useExpand.d.ts +1 -0
- package/lib/components/PisellTabbar/hooks/useExpand.js +9 -1
- package/lib/components/PisellTabbar/template/Template1/PisellTabbar.d.ts +3 -18
- package/lib/components/PisellTabbar/template/Template1/PisellTabbar.js +171 -55
- package/lib/components/PisellTabbar/template/Template1/constants.js +1 -1
- package/lib/components/PisellTabbar/types.d.ts +5 -26
- package/lib/components/PisellTabbar/utils/index.d.ts +2 -1
- package/lib/components/PisellTabbar/utils/index.js +2 -1
- package/lib/components/dataSourceComponents/dataSourceTable/hooks/useDataSourceKey.d.ts +2 -2
- package/lib/components/dataSourceComponents/dataSourceTable/hooks/useTableProps.d.ts +2 -2
- package/lib/components/page/index.js +3 -0
- package/lib/components/pisellDataSourceContainer/hooks/useDataSourceKey.d.ts +2 -2
- package/lib/components/pisellDateTimeDisplay/PisellDateTimeDisplay.js +27 -17
- package/lib/components/pisellDateTimeDisplay/PisellDateTimeDisplay.stories.d.ts +19 -0
- package/lib/components/pisellDateTimeDisplay/PisellDateTimeDisplay.stories.js +63 -0
- package/lib/components/pisellDateTimeDisplay/components/DateDisplay.d.ts +6 -1
- package/lib/components/pisellDateTimeDisplay/components/DateDisplay.js +5 -1
- package/lib/components/pisellDateTimeDisplay/formats/dateTimeDisplayFormats.d.ts +7 -0
- package/lib/components/pisellDateTimeDisplay/formats/dateTimeDisplayFormats.js +98 -0
- package/lib/components/pisellDateTimeDisplay/formats/index.d.ts +1 -0
- package/lib/components/pisellDateTimeDisplay/formats/index.js +29 -0
- package/lib/components/pisellDateTimeDisplay/hooks/useCurrentTime.d.ts +2 -2
- package/lib/components/pisellDateTimeDisplay/index.d.ts +1 -0
- package/lib/components/pisellDateTimeDisplay/index.js +3 -1
- package/lib/components/pisellDateTimeDisplay/types.d.ts +48 -2
- package/lib/components/pisellDateTimeDisplay/utils/formatDate.js +14 -1
- package/lib/components/pisellDateTimeDisplay/utils/formatDateOrRelative.d.ts +17 -0
- package/lib/components/pisellDateTimeDisplay/utils/formatDateOrRelative.js +54 -0
- package/lib/components/pisellDateTimeDisplay/utils/formatWeekday.js +6 -6
- package/lib/components/pisellDateTimeDisplay/utils/index.d.ts +3 -1
- package/lib/components/pisellDateTimeDisplay/utils/index.js +8 -2
- package/lib/components/pisellDateTimeDisplay/utils/localeUtils.d.ts +2 -7
- package/lib/components/pisellDateTimeDisplay/utils/localeUtils.js +2 -11
- package/lib/components/pisellDateTimeDisplay/utils/relativeDay.d.ts +23 -0
- package/lib/components/pisellDateTimeDisplay/utils/relativeDay.js +54 -0
- package/lib/components/pisellEmail/PisellEmail.less +2 -2
- package/lib/components/pisellFind/PisellFind.stories.d.ts +45 -0
- package/lib/components/pisellFind/PisellFind.stories.js +343 -0
- package/lib/components/pisellFind/index.d.ts +40 -0
- package/lib/components/pisellFind/index.js +68 -0
- package/lib/components/pisellLongText/PisellLongText.less +2 -2
- package/lib/components/pisellLookup/PisellLookup.d.ts +4 -0
- package/lib/components/pisellLookup/PisellLookup.js +434 -0
- package/lib/components/pisellLookup/PisellLookup.less +640 -0
- package/lib/components/pisellLookup/PisellLookup.stories.d.ts +129 -0
- package/lib/components/pisellLookup/PisellLookup.stories.js +631 -0
- package/lib/components/pisellLookup/components/HotWords.d.ts +7 -0
- package/lib/components/pisellLookup/components/HotWords.js +63 -0
- package/lib/components/pisellLookup/components/LookupAuxiliary.d.ts +7 -0
- package/lib/components/pisellLookup/components/LookupAuxiliary.js +93 -0
- package/lib/components/pisellLookup/components/LookupResultHost.d.ts +7 -0
- package/lib/components/pisellLookup/components/LookupResultHost.js +190 -0
- package/lib/components/pisellLookup/components/LookupTrigger.d.ts +3 -0
- package/lib/components/pisellLookup/components/LookupTrigger.js +293 -0
- package/lib/components/pisellLookup/components/SearchHistory.d.ts +7 -0
- package/lib/components/pisellLookup/components/SearchHistory.js +73 -0
- package/lib/components/pisellLookup/components/SuggestWords.d.ts +7 -0
- package/lib/components/pisellLookup/components/SuggestWords.js +71 -0
- package/lib/components/pisellLookup/components/index.d.ts +9 -0
- package/lib/components/pisellLookup/components/index.js +44 -0
- package/lib/components/pisellLookup/hooks/index.d.ts +6 -0
- package/lib/components/pisellLookup/hooks/index.js +27 -0
- package/lib/components/pisellLookup/hooks/useDebounceSearch.d.ts +40 -0
- package/lib/components/pisellLookup/hooks/useDebounceSearch.js +66 -0
- package/lib/components/pisellLookup/hooks/useSearchHistory.d.ts +48 -0
- package/lib/components/pisellLookup/hooks/useSearchHistory.js +107 -0
- package/lib/components/pisellLookup/hooks/useSearchState.d.ts +80 -0
- package/lib/components/pisellLookup/hooks/useSearchState.js +91 -0
- package/lib/components/pisellLookup/index.d.ts +6 -0
- package/lib/components/pisellLookup/index.js +29 -0
- package/lib/components/pisellLookup/types.d.ts +666 -0
- package/lib/components/pisellLookup/types.js +17 -0
- package/lib/components/pisellLookup/utils/index.d.ts +5 -0
- package/lib/components/pisellLookup/utils/index.js +25 -0
- package/lib/components/pisellLookup/utils/storage.d.ts +42 -0
- package/lib/components/pisellLookup/utils/storage.js +96 -0
- package/lib/components/pisellLookup/utils/trigger.d.ts +42 -0
- package/lib/components/pisellLookup/utils/trigger.js +66 -0
- package/lib/components/pisellMultipleSelect/PisellMultipleSelect.less +7 -7
- package/lib/components/pisellSingleLineText/PisellSingleLineText.less +143 -4
- package/lib/components/pisellSingleSelect/PisellSingleSelect.less +6 -6
- package/lib/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.d.ts +32 -0
- package/lib/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.js +193 -0
- package/lib/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.less +49 -0
- package/lib/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.stories.d.ts +61 -0
- package/lib/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.stories.js +187 -0
- package/lib/components/pisellTimeRangeDisplay/components/DateBlock.d.ts +20 -0
- package/lib/components/pisellTimeRangeDisplay/components/DateBlock.js +69 -0
- package/lib/components/pisellTimeRangeDisplay/components/DurationBlock.d.ts +19 -0
- package/lib/components/pisellTimeRangeDisplay/components/DurationBlock.js +65 -0
- package/lib/components/pisellTimeRangeDisplay/components/TimeRangeBlock.d.ts +30 -0
- package/lib/components/pisellTimeRangeDisplay/components/TimeRangeBlock.js +120 -0
- package/lib/components/pisellTimeRangeDisplay/components/WeekdayBlock.d.ts +18 -0
- package/lib/components/pisellTimeRangeDisplay/components/WeekdayBlock.js +64 -0
- package/lib/components/pisellTimeRangeDisplay/components/index.d.ts +8 -0
- package/lib/components/pisellTimeRangeDisplay/components/index.js +38 -0
- package/lib/components/pisellTimeRangeDisplay/index.d.ts +3 -0
- package/lib/components/{PisellTabbar/components → pisellTimeRangeDisplay}/index.js +8 -7
- package/lib/components/pisellTimeRangeDisplay/types.d.ts +137 -0
- package/lib/components/pisellTimeRangeDisplay/types.js +17 -0
- package/lib/components/pisellTimeRangeDisplay/utils/formatDuration.d.ts +14 -0
- package/lib/components/pisellTimeRangeDisplay/utils/formatDuration.js +52 -0
- package/lib/components/pisellTimeRangeDisplay/utils/index.d.ts +4 -0
- package/lib/components/pisellTimeRangeDisplay/utils/index.js +47 -0
- package/lib/components/pisellTimeRangeDisplay/utils/parseTimeRange.d.ts +23 -0
- package/lib/components/pisellTimeRangeDisplay/utils/parseTimeRange.js +49 -0
- package/lib/components/pisellUrl/PisellUrl.less +1 -1
- package/lib/components/productCard/cartSkuCard/components/packages/utils.d.ts +1 -1
- package/lib/components/productCard/components/Packages/utils.d.ts +1 -1
- package/lib/components/table/Gallery/components/VirtualGrid/useGapSize.d.ts +2 -2
- package/lib/components/table/Table/fields/select/filterUtil/index.d.ts +1 -1
- package/lib/components/table/Table/fields/treeSelect/filterUtil/index.d.ts +1 -1
- package/lib/index.d.ts +6 -0
- package/lib/index.js +9 -0
- package/lib/locales/en-US.d.ts +14 -0
- package/lib/locales/en-US.js +16 -0
- package/lib/locales/zh-CN.d.ts +14 -0
- package/lib/locales/zh-CN.js +16 -0
- package/lib/locales/zh-TW.d.ts +14 -0
- package/lib/locales/zh-TW.js +16 -0
- package/lib/theme/tokens.js +105 -114
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/platform.d.ts +1 -1
- package/lowcode/pisell-find/meta.ts +365 -0
- package/lowcode/pisell-find/snippets.ts +37 -0
- package/lowcode/pisell-lookup/meta.ts +845 -0
- package/lowcode/pisell-lookup/snippets.ts +93 -0
- package/lowcode/pisell-time-range-display/index.ts +3 -0
- package/lowcode/pisell-time-range-display/meta.ts +375 -0
- package/lowcode/pisell-time-range-display/snippets.ts +1 -0
- package/package.json +3 -3
- package/es/components/PisellTabbar/components/TabbarLevel.d.ts +0 -8
- package/es/components/PisellTabbar/components/TabbarLevel.js +0 -275
- package/es/components/PisellTabbar/components/index.d.ts +0 -1
- package/es/components/PisellTabbar/components/index.js +0 -2
- package/lib/components/PisellTabbar/components/TabbarLevel.d.ts +0 -8
- package/lib/components/PisellTabbar/components/TabbarLevel.js +0 -295
- package/lib/components/PisellTabbar/components/index.d.ts +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Tag } from 'antd';
|
|
3
|
+
import { CloseOutlined } from '@ant-design/icons';
|
|
4
|
+
/**
|
|
5
|
+
* SearchHistory 组件
|
|
6
|
+
* 展示搜索历史记录
|
|
7
|
+
*/
|
|
8
|
+
export var SearchHistory = function SearchHistory(props) {
|
|
9
|
+
var history = props.history,
|
|
10
|
+
onSelect = props.onSelect,
|
|
11
|
+
onRemove = props.onRemove,
|
|
12
|
+
onClear = props.onClear,
|
|
13
|
+
render = props.render,
|
|
14
|
+
className = props.className,
|
|
15
|
+
style = props.style;
|
|
16
|
+
|
|
17
|
+
// 如果没有历史记录,不显示
|
|
18
|
+
if (!history || history.length === 0) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 使用自定义渲染
|
|
23
|
+
if (render) {
|
|
24
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, render(history, onSelect));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 处理点击历史记录
|
|
29
|
+
*/
|
|
30
|
+
var handleClick = function handleClick(keyword) {
|
|
31
|
+
onSelect(keyword);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 处理删除历史记录
|
|
36
|
+
*/
|
|
37
|
+
var handleRemove = function handleRemove(e, keyword) {
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
onRemove === null || onRemove === void 0 || onRemove(keyword);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 处理清除全部历史记录
|
|
44
|
+
*/
|
|
45
|
+
var handleClearAll = function handleClearAll() {
|
|
46
|
+
onClear === null || onClear === void 0 || onClear();
|
|
47
|
+
};
|
|
48
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
49
|
+
className: "pisell-lookup-history ".concat(className || ''),
|
|
50
|
+
style: style
|
|
51
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
52
|
+
className: "pisell-lookup-history-list"
|
|
53
|
+
}, history.map(function (item, index) {
|
|
54
|
+
return /*#__PURE__*/React.createElement(Tag, {
|
|
55
|
+
key: "".concat(item, "-").concat(index),
|
|
56
|
+
className: "pisell-lookup-history-item",
|
|
57
|
+
onClick: function onClick() {
|
|
58
|
+
return handleClick(item);
|
|
59
|
+
},
|
|
60
|
+
closable: !!onRemove,
|
|
61
|
+
onClose: function onClose(e) {
|
|
62
|
+
return handleRemove(e, item);
|
|
63
|
+
},
|
|
64
|
+
closeIcon: /*#__PURE__*/React.createElement(CloseOutlined, null)
|
|
65
|
+
}, item);
|
|
66
|
+
})));
|
|
67
|
+
};
|
|
68
|
+
SearchHistory.displayName = 'SearchHistory';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { List } from 'antd';
|
|
3
|
+
import { SearchOutlined } from '@ant-design/icons';
|
|
4
|
+
/**
|
|
5
|
+
* SuggestWords 组件
|
|
6
|
+
* 展示搜索联想词
|
|
7
|
+
*/
|
|
8
|
+
export var SuggestWords = function SuggestWords(props) {
|
|
9
|
+
var suggestions = props.suggestions,
|
|
10
|
+
onSelect = props.onSelect,
|
|
11
|
+
render = props.render,
|
|
12
|
+
className = props.className,
|
|
13
|
+
style = props.style;
|
|
14
|
+
|
|
15
|
+
// 如果没有联想词,不显示
|
|
16
|
+
if (!suggestions || suggestions.length === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 使用自定义渲染
|
|
21
|
+
if (render) {
|
|
22
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, render(suggestions, onSelect));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 处理点击联想词
|
|
27
|
+
*/
|
|
28
|
+
var handleClick = function handleClick(keyword) {
|
|
29
|
+
onSelect(keyword);
|
|
30
|
+
};
|
|
31
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
32
|
+
className: "pisell-lookup-suggestions ".concat(className || ''),
|
|
33
|
+
style: style
|
|
34
|
+
}, /*#__PURE__*/React.createElement(List, {
|
|
35
|
+
className: "pisell-lookup-suggestions-list",
|
|
36
|
+
size: "small",
|
|
37
|
+
dataSource: suggestions,
|
|
38
|
+
renderItem: function renderItem(item) {
|
|
39
|
+
return /*#__PURE__*/React.createElement(List.Item, {
|
|
40
|
+
className: "pisell-lookup-suggestions-item",
|
|
41
|
+
onClick: function onClick() {
|
|
42
|
+
return handleClick(item);
|
|
43
|
+
}
|
|
44
|
+
}, /*#__PURE__*/React.createElement(SearchOutlined, {
|
|
45
|
+
style: {
|
|
46
|
+
marginRight: 8,
|
|
47
|
+
color: '#667085'
|
|
48
|
+
}
|
|
49
|
+
}), item);
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
SuggestWords.displayName = 'SuggestWords';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子组件统一导出
|
|
3
|
+
*/
|
|
4
|
+
export { SearchHistory } from './SearchHistory';
|
|
5
|
+
export { SuggestWords } from './SuggestWords';
|
|
6
|
+
export { HotWords } from './HotWords';
|
|
7
|
+
export { LookupAuxiliary } from './LookupAuxiliary';
|
|
8
|
+
export { LookupTrigger } from './LookupTrigger';
|
|
9
|
+
export { LookupResultHost } from './LookupResultHost';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子组件统一导出
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { SearchHistory } from "./SearchHistory";
|
|
6
|
+
export { SuggestWords } from "./SuggestWords";
|
|
7
|
+
export { HotWords } from "./HotWords";
|
|
8
|
+
export { LookupAuxiliary } from "./LookupAuxiliary";
|
|
9
|
+
export { LookupTrigger } from "./LookupTrigger";
|
|
10
|
+
export { LookupResultHost } from "./LookupResultHost";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 防抖搜索 Hook
|
|
3
|
+
*/
|
|
4
|
+
export interface UseDebounceSearchOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 关键词
|
|
7
|
+
*/
|
|
8
|
+
keyword: string;
|
|
9
|
+
/**
|
|
10
|
+
* 防抖时间(毫秒)
|
|
11
|
+
*/
|
|
12
|
+
debounceTime: number;
|
|
13
|
+
/**
|
|
14
|
+
* 搜索触发回调
|
|
15
|
+
*/
|
|
16
|
+
onSearch?: (keyword: string) => void;
|
|
17
|
+
/**
|
|
18
|
+
* 是否启用防抖
|
|
19
|
+
*/
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 上次搜索的关键词(用于去重)
|
|
23
|
+
*/
|
|
24
|
+
lastSearchKeyword?: string;
|
|
25
|
+
/**
|
|
26
|
+
* 是否跳过防抖触发(用于手动选择场景)
|
|
27
|
+
*/
|
|
28
|
+
skipDebounce?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface UseDebounceSearchResult {
|
|
31
|
+
/**
|
|
32
|
+
* 防抖后的关键词
|
|
33
|
+
*/
|
|
34
|
+
debouncedKeyword: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 防抖搜索 Hook
|
|
38
|
+
* 用于实时搜索模式的防抖处理
|
|
39
|
+
*/
|
|
40
|
+
export declare const useDebounceSearch: (options: UseDebounceSearchOptions) => UseDebounceSearchResult;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useEffect, useRef, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 防抖搜索 Hook
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 防抖搜索 Hook
|
|
15
|
+
* 用于实时搜索模式的防抖处理
|
|
16
|
+
*/
|
|
17
|
+
export var useDebounceSearch = function useDebounceSearch(options) {
|
|
18
|
+
var keyword = options.keyword,
|
|
19
|
+
debounceTime = options.debounceTime,
|
|
20
|
+
onSearch = options.onSearch,
|
|
21
|
+
_options$enabled = options.enabled,
|
|
22
|
+
enabled = _options$enabled === void 0 ? true : _options$enabled,
|
|
23
|
+
lastSearchKeyword = options.lastSearchKeyword;
|
|
24
|
+
var _useState = useState(keyword),
|
|
25
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
26
|
+
debouncedKeyword = _useState2[0],
|
|
27
|
+
setDebouncedKeyword = _useState2[1];
|
|
28
|
+
var timerRef = useRef(null);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 防抖处理
|
|
32
|
+
*/
|
|
33
|
+
useEffect(function () {
|
|
34
|
+
if (!enabled) {
|
|
35
|
+
// 不启用防抖时,直接更新
|
|
36
|
+
setDebouncedKeyword(keyword);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 清除之前的定时器
|
|
41
|
+
if (timerRef.current) {
|
|
42
|
+
clearTimeout(timerRef.current);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 设置新的定时器
|
|
46
|
+
timerRef.current = setTimeout(function () {
|
|
47
|
+
setDebouncedKeyword(keyword);
|
|
48
|
+
}, debounceTime);
|
|
49
|
+
|
|
50
|
+
// 清理函数
|
|
51
|
+
return function () {
|
|
52
|
+
if (timerRef.current) {
|
|
53
|
+
clearTimeout(timerRef.current);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}, [keyword, debounceTime, enabled]);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 触发搜索回调
|
|
60
|
+
*/
|
|
61
|
+
useEffect(function () {
|
|
62
|
+
// 只有在启用防抖时才触发搜索(包括空关键词,用于恢复数据)
|
|
63
|
+
if (enabled && onSearch && debouncedKeyword !== undefined) {
|
|
64
|
+
// 如果和上次搜索的关键词相同,跳过(避免重复触发)
|
|
65
|
+
if (lastSearchKeyword !== undefined && debouncedKeyword === lastSearchKeyword) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
onSearch(debouncedKeyword);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('Failed to trigger search:', error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}, [debouncedKeyword, onSearch, enabled, lastSearchKeyword]);
|
|
75
|
+
return {
|
|
76
|
+
debouncedKeyword: debouncedKeyword
|
|
77
|
+
};
|
|
78
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 搜索历史管理 Hook
|
|
3
|
+
*/
|
|
4
|
+
export interface UseSearchHistoryOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 存储 key
|
|
7
|
+
*/
|
|
8
|
+
historyKey: string;
|
|
9
|
+
/**
|
|
10
|
+
* 最大历史记录数量
|
|
11
|
+
*/
|
|
12
|
+
maxHistoryCount: number;
|
|
13
|
+
/**
|
|
14
|
+
* 自定义加载历史记录函数
|
|
15
|
+
*/
|
|
16
|
+
onLoadHistory?: () => string[];
|
|
17
|
+
/**
|
|
18
|
+
* 自定义保存历史记录函数
|
|
19
|
+
*/
|
|
20
|
+
onSaveHistory?: (history: string[]) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface UseSearchHistoryResult {
|
|
23
|
+
/**
|
|
24
|
+
* 历史记录数组
|
|
25
|
+
*/
|
|
26
|
+
history: string[];
|
|
27
|
+
/**
|
|
28
|
+
* 添加历史记录
|
|
29
|
+
*/
|
|
30
|
+
addHistory: (keyword: string) => void;
|
|
31
|
+
/**
|
|
32
|
+
* 删除历史记录
|
|
33
|
+
*/
|
|
34
|
+
removeHistory: (keyword: string) => void;
|
|
35
|
+
/**
|
|
36
|
+
* 清除全部历史记录
|
|
37
|
+
*/
|
|
38
|
+
clearAllHistory: () => void;
|
|
39
|
+
/**
|
|
40
|
+
* 重新加载历史记录
|
|
41
|
+
*/
|
|
42
|
+
reloadHistory: () => void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 搜索历史管理 Hook
|
|
46
|
+
* 支持自定义存储逻辑
|
|
47
|
+
*/
|
|
48
|
+
export declare const useSearchHistory: (options: UseSearchHistoryOptions) => UseSearchHistoryResult;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
12
|
+
import { addHistoryItem, clearHistory, loadHistory, removeHistoryItem } from "../utils";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 搜索历史管理 Hook
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 搜索历史管理 Hook
|
|
20
|
+
* 支持自定义存储逻辑
|
|
21
|
+
*/
|
|
22
|
+
export var useSearchHistory = function useSearchHistory(options) {
|
|
23
|
+
var historyKey = options.historyKey,
|
|
24
|
+
maxHistoryCount = options.maxHistoryCount,
|
|
25
|
+
onLoadHistory = options.onLoadHistory,
|
|
26
|
+
onSaveHistory = options.onSaveHistory;
|
|
27
|
+
var _useState = useState([]),
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
29
|
+
history = _useState2[0],
|
|
30
|
+
setHistory = _useState2[1];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 加载历史记录
|
|
34
|
+
*/
|
|
35
|
+
var reloadHistory = useCallback(function () {
|
|
36
|
+
try {
|
|
37
|
+
if (onLoadHistory) {
|
|
38
|
+
// 使用自定义加载函数
|
|
39
|
+
var loadedHistory = onLoadHistory();
|
|
40
|
+
setHistory(Array.isArray(loadedHistory) ? loadedHistory : []);
|
|
41
|
+
} else {
|
|
42
|
+
// 使用默认的 localStorage 加载
|
|
43
|
+
var _loadedHistory = loadHistory(historyKey);
|
|
44
|
+
setHistory(Array.isArray(_loadedHistory) ? _loadedHistory : []);
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error('Failed to reload history:', error);
|
|
48
|
+
setHistory([]);
|
|
49
|
+
}
|
|
50
|
+
}, [historyKey, onLoadHistory]);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 初始化:加载历史记录
|
|
54
|
+
*/
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
reloadHistory();
|
|
57
|
+
}, [reloadHistory]);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 添加历史记录
|
|
61
|
+
*/
|
|
62
|
+
var addHistory = useCallback(function (keyword) {
|
|
63
|
+
// 忽略空关键词
|
|
64
|
+
if (!keyword || !keyword.trim()) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
var trimmedKeyword = keyword.trim();
|
|
68
|
+
if (onSaveHistory) {
|
|
69
|
+
// 使用自定义保存函数
|
|
70
|
+
// 去重并添加到开头
|
|
71
|
+
var safeHistory = Array.isArray(history) ? history : [];
|
|
72
|
+
var filteredHistory = safeHistory.filter(function (h) {
|
|
73
|
+
return h !== trimmedKeyword;
|
|
74
|
+
});
|
|
75
|
+
var newHistory = [trimmedKeyword].concat(_toConsumableArray(filteredHistory)).slice(0, maxHistoryCount);
|
|
76
|
+
setHistory(newHistory);
|
|
77
|
+
onSaveHistory(newHistory);
|
|
78
|
+
} else {
|
|
79
|
+
// 使用默认的 localStorage 保存
|
|
80
|
+
var _newHistory = addHistoryItem(historyKey, trimmedKeyword, maxHistoryCount);
|
|
81
|
+
setHistory(_newHistory);
|
|
82
|
+
}
|
|
83
|
+
}, [history, historyKey, maxHistoryCount, onSaveHistory]);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 删除历史记录
|
|
87
|
+
*/
|
|
88
|
+
var removeHistory = useCallback(function (keyword) {
|
|
89
|
+
if (onSaveHistory) {
|
|
90
|
+
// 使用自定义保存函数
|
|
91
|
+
var safeHistory = Array.isArray(history) ? history : [];
|
|
92
|
+
var newHistory = safeHistory.filter(function (h) {
|
|
93
|
+
return h !== keyword;
|
|
94
|
+
});
|
|
95
|
+
setHistory(newHistory);
|
|
96
|
+
onSaveHistory(newHistory);
|
|
97
|
+
} else {
|
|
98
|
+
// 使用默认的 localStorage 删除
|
|
99
|
+
var _newHistory2 = removeHistoryItem(historyKey, keyword);
|
|
100
|
+
setHistory(_newHistory2);
|
|
101
|
+
}
|
|
102
|
+
}, [history, historyKey, onSaveHistory]);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 清除全部历史记录
|
|
106
|
+
*/
|
|
107
|
+
var clearAllHistory = useCallback(function () {
|
|
108
|
+
if (onSaveHistory) {
|
|
109
|
+
// 使用自定义保存函数
|
|
110
|
+
setHistory([]);
|
|
111
|
+
onSaveHistory([]);
|
|
112
|
+
} else {
|
|
113
|
+
// 使用默认的 localStorage 清除
|
|
114
|
+
clearHistory(historyKey);
|
|
115
|
+
setHistory([]);
|
|
116
|
+
}
|
|
117
|
+
}, [historyKey, onSaveHistory]);
|
|
118
|
+
return {
|
|
119
|
+
history: history,
|
|
120
|
+
addHistory: addHistory,
|
|
121
|
+
removeHistory: removeHistory,
|
|
122
|
+
clearAllHistory: clearAllHistory,
|
|
123
|
+
reloadHistory: reloadHistory
|
|
124
|
+
};
|
|
125
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 搜索状态管理 Hook
|
|
3
|
+
*/
|
|
4
|
+
export interface UseSearchStateOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 受控的关键词
|
|
7
|
+
*/
|
|
8
|
+
value?: string;
|
|
9
|
+
/**
|
|
10
|
+
* 默认关键词
|
|
11
|
+
*/
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
/**
|
|
14
|
+
* 受控的可见性
|
|
15
|
+
*/
|
|
16
|
+
visible?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 默认可见性
|
|
19
|
+
*/
|
|
20
|
+
defaultVisible?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 关键词变化回调
|
|
23
|
+
*/
|
|
24
|
+
onChange?: (value: string) => void;
|
|
25
|
+
/**
|
|
26
|
+
* 可见性变化回调
|
|
27
|
+
*/
|
|
28
|
+
onVisibleChange?: (visible: boolean) => void;
|
|
29
|
+
/**
|
|
30
|
+
* 打开回调
|
|
31
|
+
*/
|
|
32
|
+
onOpen?: () => void;
|
|
33
|
+
/**
|
|
34
|
+
* 关闭回调
|
|
35
|
+
*/
|
|
36
|
+
onClose?: () => void;
|
|
37
|
+
}
|
|
38
|
+
export interface UseSearchStateResult {
|
|
39
|
+
/**
|
|
40
|
+
* 当前关键词
|
|
41
|
+
*/
|
|
42
|
+
keyword: string;
|
|
43
|
+
/**
|
|
44
|
+
* 设置关键词
|
|
45
|
+
*/
|
|
46
|
+
setKeyword: (value: string) => void;
|
|
47
|
+
/**
|
|
48
|
+
* 是否可见
|
|
49
|
+
*/
|
|
50
|
+
visible: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 设置可见性
|
|
53
|
+
*/
|
|
54
|
+
setVisible: (visible: boolean) => void;
|
|
55
|
+
/**
|
|
56
|
+
* 打开
|
|
57
|
+
*/
|
|
58
|
+
open: () => void;
|
|
59
|
+
/**
|
|
60
|
+
* 关闭
|
|
61
|
+
*/
|
|
62
|
+
close: () => void;
|
|
63
|
+
/**
|
|
64
|
+
* 切换可见性
|
|
65
|
+
*/
|
|
66
|
+
toggle: () => void;
|
|
67
|
+
/**
|
|
68
|
+
* 是否为受控的关键词
|
|
69
|
+
*/
|
|
70
|
+
isControlledKeyword: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* 是否为受控的可见性
|
|
73
|
+
*/
|
|
74
|
+
isControlledVisible: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 搜索状态管理 Hook
|
|
78
|
+
* 支持受控和非受控模式
|
|
79
|
+
*/
|
|
80
|
+
export declare const useSearchState: (options: UseSearchStateOptions) => UseSearchStateResult;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useCallback, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 搜索状态管理 Hook
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 搜索状态管理 Hook
|
|
15
|
+
* 支持受控和非受控模式
|
|
16
|
+
*/
|
|
17
|
+
export var useSearchState = function useSearchState(options) {
|
|
18
|
+
var value = options.value,
|
|
19
|
+
_options$defaultValue = options.defaultValue,
|
|
20
|
+
defaultValue = _options$defaultValue === void 0 ? '' : _options$defaultValue,
|
|
21
|
+
visibleProp = options.visible,
|
|
22
|
+
_options$defaultVisib = options.defaultVisible,
|
|
23
|
+
defaultVisible = _options$defaultVisib === void 0 ? false : _options$defaultVisib,
|
|
24
|
+
onChange = options.onChange,
|
|
25
|
+
onVisibleChange = options.onVisibleChange,
|
|
26
|
+
onOpen = options.onOpen,
|
|
27
|
+
onClose = options.onClose;
|
|
28
|
+
|
|
29
|
+
// 判断是否为受控模式
|
|
30
|
+
var isControlledKeyword = value !== undefined;
|
|
31
|
+
var isControlledVisible = visibleProp !== undefined;
|
|
32
|
+
|
|
33
|
+
// 内部状态(非受控模式使用)
|
|
34
|
+
var _useState = useState(defaultValue),
|
|
35
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
36
|
+
internalKeyword = _useState2[0],
|
|
37
|
+
setInternalKeyword = _useState2[1];
|
|
38
|
+
var _useState3 = useState(defaultVisible),
|
|
39
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
40
|
+
internalVisible = _useState4[0],
|
|
41
|
+
setInternalVisible = _useState4[1];
|
|
42
|
+
|
|
43
|
+
// 当前值(受控优先)
|
|
44
|
+
var keyword = isControlledKeyword ? value : internalKeyword;
|
|
45
|
+
var visible = isControlledVisible ? visibleProp : internalVisible;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 设置关键词
|
|
49
|
+
*/
|
|
50
|
+
var setKeyword = useCallback(function (newValue) {
|
|
51
|
+
// 非受控模式下更新内部状态
|
|
52
|
+
if (!isControlledKeyword) {
|
|
53
|
+
setInternalKeyword(newValue);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 触发回调
|
|
57
|
+
onChange === null || onChange === void 0 || onChange(newValue);
|
|
58
|
+
}, [isControlledKeyword, onChange]);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 设置可见性
|
|
62
|
+
*/
|
|
63
|
+
var setVisible = useCallback(function (newVisible) {
|
|
64
|
+
var oldVisible = visible;
|
|
65
|
+
|
|
66
|
+
// 非受控模式下更新内部状态
|
|
67
|
+
if (!isControlledVisible) {
|
|
68
|
+
setInternalVisible(newVisible);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 触发回调
|
|
72
|
+
onVisibleChange === null || onVisibleChange === void 0 || onVisibleChange(newVisible);
|
|
73
|
+
|
|
74
|
+
// 触发打开/关闭回调
|
|
75
|
+
if (newVisible && !oldVisible) {
|
|
76
|
+
onOpen === null || onOpen === void 0 || onOpen();
|
|
77
|
+
} else if (!newVisible && oldVisible) {
|
|
78
|
+
onClose === null || onClose === void 0 || onClose();
|
|
79
|
+
}
|
|
80
|
+
}, [isControlledVisible, visible, onVisibleChange, onOpen, onClose]);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 打开
|
|
84
|
+
*/
|
|
85
|
+
var open = useCallback(function () {
|
|
86
|
+
setVisible(true);
|
|
87
|
+
}, [setVisible]);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 关闭
|
|
91
|
+
*/
|
|
92
|
+
var close = useCallback(function () {
|
|
93
|
+
setVisible(false);
|
|
94
|
+
}, [setVisible]);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 切换可见性
|
|
98
|
+
*/
|
|
99
|
+
var toggle = useCallback(function () {
|
|
100
|
+
setVisible(!visible);
|
|
101
|
+
}, [setVisible, visible]);
|
|
102
|
+
return {
|
|
103
|
+
keyword: keyword,
|
|
104
|
+
setKeyword: setKeyword,
|
|
105
|
+
visible: visible,
|
|
106
|
+
setVisible: setVisible,
|
|
107
|
+
open: open,
|
|
108
|
+
close: close,
|
|
109
|
+
toggle: toggle,
|
|
110
|
+
isControlledKeyword: isControlledKeyword,
|
|
111
|
+
isControlledVisible: isControlledVisible
|
|
112
|
+
};
|
|
113
|
+
};
|