@fairys/taro-tools-simple-form 0.0.2 → 0.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 (46) hide show
  1. package/esm/components/calendar/index.d.ts +10 -0
  2. package/esm/components/calendar/index.js +35 -0
  3. package/esm/components/cascader/index.d.ts +10 -0
  4. package/esm/components/cascader/index.js +85 -0
  5. package/esm/components/checkbox.group/index.d.ts +5 -0
  6. package/esm/components/checkbox.group/index.js +14 -0
  7. package/esm/components/clear/index.d.ts +21 -0
  8. package/esm/components/clear/index.js +31 -0
  9. package/esm/components/date.picker/index.d.ts +18 -0
  10. package/esm/components/date.picker/index.js +122 -0
  11. package/esm/components/index.d.ts +8 -0
  12. package/esm/components/index.js +8 -0
  13. package/esm/components/picker/index.d.ts +9 -0
  14. package/esm/components/picker/index.js +45 -0
  15. package/esm/components/popup.search/base.d.ts +2 -0
  16. package/esm/components/popup.search/base.js +70 -0
  17. package/esm/components/popup.search/index.d.ts +9 -0
  18. package/esm/components/popup.search/index.js +157 -0
  19. package/esm/components/popup.search/instance.d.ts +169 -0
  20. package/esm/components/popup.search/instance.js +319 -0
  21. package/esm/components/popup.search/list.table.d.ts +1 -0
  22. package/esm/components/popup.search/list.table.js +89 -0
  23. package/esm/components/popup.search/list.virtual.d.ts +1 -0
  24. package/esm/components/popup.search/list.virtual.js +60 -0
  25. package/esm/components/radio.group/index.d.ts +5 -0
  26. package/esm/components/radio.group/index.js +13 -0
  27. package/esm/index.d.ts +17 -0
  28. package/esm/index.js +15 -0
  29. package/esm/interface.d.ts +3 -0
  30. package/esm/interface.js +0 -0
  31. package/esm/item.config.d.ts +57 -0
  32. package/esm/item.config.js +125 -0
  33. package/esm/styles/index.css +167 -0
  34. package/lib/index.js +91 -0
  35. package/package.json +2 -2
  36. package/src/components/calendar/index.tsx +10 -11
  37. package/src/components/cascader/index.tsx +9 -11
  38. package/src/components/clear/index.tsx +49 -0
  39. package/src/components/date.picker/index.tsx +11 -11
  40. package/src/components/index.ts +8 -0
  41. package/src/components/picker/index.tsx +9 -11
  42. package/src/components/popup.search/index.tsx +86 -64
  43. package/src/components/popup.search/instance.ts +40 -9
  44. package/src/components/popup.search/list.table.tsx +3 -2
  45. package/src/components/popup.search/list.virtual.tsx +3 -2
  46. package/src/index.tsx +4 -1
@@ -0,0 +1,157 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Text, View } from "@tarojs/components";
3
+ import { Popup } from "@nutui/nutui-react-taro";
4
+ import { Fragment, useEffect, useMemo } from "react";
5
+ import { FairysTaroPopupSearchBaseInstanceContext, useFairysTaroPopupSearchBaseInstance, useFairysTaroPopupSearchBaseInstanceContext } from "./instance.js";
6
+ import { FairysTaroPopupSearchFooterBase, FairysTaroPopupSearchInputBase } from "./base.js";
7
+ import { FairysTaroPopupSearchListVirtual } from "./list.virtual.js";
8
+ import { FairysTaroPopupSearchListTable } from "./list.table.js";
9
+ import { FairysTaroTextClearBase } from "../clear/index.js";
10
+ function RenderList() {
11
+ const [state, instance] = useFairysTaroPopupSearchBaseInstanceContext();
12
+ const renderList = instance.renderList;
13
+ const _tempFilterDataList = state._tempFilterDataList;
14
+ const operationStatus = state.operationStatus;
15
+ return renderList?.(_tempFilterDataList || [], operationStatus, instance) || /*#__PURE__*/ jsx(Fragment, {});
16
+ }
17
+ function FairysTaroPopupSearchBodyBase() {
18
+ const [state, instance] = useFairysTaroPopupSearchBaseInstanceContext();
19
+ const renderType = instance.renderType;
20
+ const showSearch = instance.showSearch;
21
+ const mode = instance.mode;
22
+ const columns = instance.columns;
23
+ const options = instance.options;
24
+ const isNeedManage = instance.isNeedManage;
25
+ const value = instance.value;
26
+ const visible = state.visible;
27
+ useMemo(()=>{
28
+ if (isNeedManage || instance.isUseOptions()) instance.updateState({
29
+ value,
30
+ _tempValue: value
31
+ });
32
+ else instance.updateState({
33
+ value,
34
+ _tempValue: void 0
35
+ });
36
+ }, [
37
+ value,
38
+ isNeedManage,
39
+ visible
40
+ ]);
41
+ useMemo(()=>instance.updateState({
42
+ dataList: options || [],
43
+ _tempFilterDataList: options || []
44
+ }), [
45
+ options
46
+ ]);
47
+ useMemo(()=>instance.updateState({
48
+ mode
49
+ }), [
50
+ mode
51
+ ]);
52
+ useMemo(()=>instance.updateState({
53
+ columns
54
+ }), [
55
+ columns
56
+ ]);
57
+ useEffect(()=>{
58
+ if (visible && 'function' == typeof instance.onLoadData) instance.onSearch('');
59
+ }, [
60
+ visible
61
+ ]);
62
+ return /*#__PURE__*/ jsxs(View, {
63
+ className: "fairys-taro-popup-search-content-inner fairystaroform__flex fairystaroform__flex-1 fairystaroform__flex-col fairystaroform__overflow-hidden",
64
+ children: [
65
+ showSearch ? /*#__PURE__*/ jsx(FairysTaroPopupSearchInputBase, {}) : /*#__PURE__*/ jsx(Fragment, {}),
66
+ /*#__PURE__*/ jsx(View, {
67
+ style: {
68
+ flex: 1,
69
+ overflow: 'hidden'
70
+ },
71
+ children: 'list' === renderType ? /*#__PURE__*/ jsx(FairysTaroPopupSearchListVirtual, {}) : 'table' === renderType ? /*#__PURE__*/ jsx(FairysTaroPopupSearchListTable, {}) : 'custom' === renderType ? /*#__PURE__*/ jsx(RenderList, {}) : /*#__PURE__*/ jsx(Fragment, {})
72
+ }),
73
+ 'multiple' === mode ? /*#__PURE__*/ jsx(FairysTaroPopupSearchFooterBase, {}) : /*#__PURE__*/ jsx(Fragment, {})
74
+ ]
75
+ });
76
+ }
77
+ function FairysTaroPopupSearchBase(props) {
78
+ const { placeholder = "\u8BF7\u9009\u62E9", className, style, value, onChange, onLoadData, otherRequestParams, maxWidth, maxHeight, renderText, renderListItemText, showRowDeleteButton = true, showSearch = true, renderList, options, columns, mode = 'single', rowKey = 'value', displayField = 'label', renderType = 'list', maxTagCount = 9, tableProps = {}, useTableProps, isNeedManage = false, isUseOptionsChecked = true, ...rest } = props;
79
+ const [state, instance] = useFairysTaroPopupSearchBaseInstance();
80
+ instance.maxWidth = maxWidth;
81
+ instance.maxHeight = maxHeight;
82
+ instance.renderText = renderText;
83
+ instance.renderList = renderList;
84
+ instance.onLoadData = onLoadData;
85
+ instance.otherRequestParams = otherRequestParams;
86
+ instance.onChange = onChange;
87
+ instance.renderListItemText = renderListItemText;
88
+ instance.tableProps = tableProps;
89
+ instance.useTableProps = useTableProps;
90
+ instance.isNeedManage = isNeedManage;
91
+ instance.isUseOptionsChecked = isUseOptionsChecked;
92
+ instance.rowKey = rowKey;
93
+ instance.displayField = displayField;
94
+ instance.mode = mode;
95
+ instance.columns = columns;
96
+ instance.renderType = renderType;
97
+ instance.showRowDeleteButton = showRowDeleteButton;
98
+ instance.showSearch = showSearch;
99
+ instance.maxTagCount = maxTagCount;
100
+ instance.options = options;
101
+ instance.value = value;
102
+ const operationStatus = state.operationStatus;
103
+ const visible = state.visible;
104
+ useMemo(()=>instance.ctor(), [
105
+ maxWidth,
106
+ maxHeight
107
+ ]);
108
+ const renderTextValue = useMemo(()=>{
109
+ if (instance.renderText) return instance.renderText(value, instance);
110
+ if ('multiple' === instance.mode) {
111
+ if (Array.isArray(value)) {
112
+ if (value.length > maxTagCount) return `${value.slice(0, maxTagCount).map((item)=>item[instance.displayField]).join(',')}...`;
113
+ return value.map((item)=>item[instance.displayField]).join(',');
114
+ }
115
+ return '';
116
+ }
117
+ return value?.[instance.displayField];
118
+ }, [
119
+ value,
120
+ mode,
121
+ maxTagCount
122
+ ]);
123
+ return /*#__PURE__*/ jsxs(View, {
124
+ className: `fairys-taro-popup-search ${className || ''}`,
125
+ style: style,
126
+ children: [
127
+ /*#__PURE__*/ jsx(FairysTaroTextClearBase, {
128
+ warpClassName: "fairys-taro-popup-search-text-container",
129
+ isValue: !!renderTextValue,
130
+ onTextClick: ()=>instance.updateState({
131
+ visible: true
132
+ }),
133
+ onClearClick: ()=>onChange?.(void 0),
134
+ children: renderTextValue || placeholder
135
+ }),
136
+ /*#__PURE__*/ jsx(Popup, {
137
+ lockScroll: true,
138
+ position: "bottom",
139
+ closeable: true,
140
+ ...rest,
141
+ left: 'multiple' === mode && isNeedManage ? /*#__PURE__*/ jsx(Text, {
142
+ onClick: instance.updateOperationStatus,
143
+ children: 'select' == operationStatus ? "\u7BA1\u7406" : "\u5B8C\u6210"
144
+ }) : /*#__PURE__*/ jsx(Fragment, {}),
145
+ visible: visible,
146
+ onClose: instance.onClose,
147
+ overlayClassName: "fairys-taro-popup-search-overlay",
148
+ className: "fairys-taro-popup-search-content fairystaroform__flex fairystaroform__flex-col fairystaroform__overflow-hidden",
149
+ children: /*#__PURE__*/ jsx(FairysTaroPopupSearchBaseInstanceContext.Provider, {
150
+ value: instance,
151
+ children: visible ? /*#__PURE__*/ jsx(FairysTaroPopupSearchBodyBase, {}) : /*#__PURE__*/ jsx(Fragment, {})
152
+ })
153
+ })
154
+ ]
155
+ });
156
+ }
157
+ export { FairysTaroPopupSearchBase };
@@ -0,0 +1,169 @@
1
+ import { TableColumnProps, TaroTableProps } from '@nutui/nutui-react-taro';
2
+ export declare class FairysTaroPopupSearchBaseInstanceMount<T = any> {
3
+ /**选中项改变时触发*/
4
+ onChange?: (value: T[] | T | undefined) => void;
5
+ onLoadData?: (params: any, instance: FairysTaroPopupSearchBaseInstanceMount<T>) => Promise<T[]>;
6
+ /**其他请求参数*/
7
+ otherRequestParams?: (params: any, instance: FairysTaroPopupSearchBaseInstanceMount<T>) => any;
8
+ /**自定义输入框显示文本*/
9
+ renderText?: (data: T | T[], instance: FairysTaroPopupSearchBaseInstanceMount<T>) => React.ReactNode;
10
+ /**自定义渲染列表项文本*/
11
+ renderListItemText?: (data: T, instance: FairysTaroPopupSearchBaseInstanceMount<T>) => React.ReactNode;
12
+ /**自定义渲染列表数据*/
13
+ renderList?: (dataList: T[], type: 'select' | 'manage', instance: FairysTaroPopupSearchBaseInstanceMount<T>) => React.ReactNode;
14
+ /**选择模式*/
15
+ mode?: 'multiple' | 'single';
16
+ /**列表项的唯一键值*/
17
+ rowKey?: string;
18
+ /**提示框 显示字段*/
19
+ displayField?: string;
20
+ /**列表列配置*/
21
+ columns?: TableColumnProps[];
22
+ /**最大弹窗宽度*/
23
+ maxWidth?: number;
24
+ /**最大弹窗高度*/
25
+ maxHeight?: number;
26
+ /**是否需要管理已选择的数据*/
27
+ isNeedManage?: boolean;
28
+ /**是否选中状态,在使用 options 参数渲染固定列数据的时候是否需要选中状态*/
29
+ isUseOptionsChecked?: boolean;
30
+ /**
31
+ * 渲染类型
32
+ * @default 'list'
33
+ * */
34
+ renderType?: 'list' | 'table' | 'custom';
35
+ /**表格属性*/
36
+ tableProps?: Partial<TaroTableProps>;
37
+ /**自定义表格属性*/
38
+ useTableProps?: (tableProps: Partial<TaroTableProps>, instance: FairysTaroPopupSearchBaseInstanceMount<T>) => Partial<TaroTableProps>;
39
+ /**是否显示删除按钮*/
40
+ showRowDeleteButton?: boolean;
41
+ /**是否显示搜索框*/
42
+ showSearch?: boolean;
43
+ /**选中项*/
44
+ value?: T | T[];
45
+ /**选择数据*/
46
+ options?: ({
47
+ label?: string;
48
+ value?: string | number;
49
+ [x: string]: any;
50
+ } & T)[];
51
+ /**
52
+ * 最大渲染个数数量
53
+ */
54
+ maxTagCount?: number;
55
+ }
56
+ export interface FairysTaroPopupSearchBaseInstanceState<T = any> {
57
+ /**无用默认值*/
58
+ __defaultValue: string;
59
+ visible: boolean;
60
+ /**选中项*/
61
+ value: T | T[] | undefined;
62
+ dataList: T[];
63
+ /**
64
+ * 临时过滤数据列表
65
+ * 使用 options 参数并且在 operationStatus = select 时使用,根据主键字段值和显示字段值进行过滤
66
+ * 在 operationStatus = manage 时,过滤 _tempValue 中的值,根据主键字段值和显示字段值进行过滤
67
+ */
68
+ _tempFilterDataList: T[];
69
+ search?: string;
70
+ /**
71
+ * 临时值(多选时使用),用于临时存在,点击保存后赋值给 value
72
+ */
73
+ _tempValue: T | T[] | undefined;
74
+ /**操作状态
75
+ * @default 'select'
76
+ */
77
+ operationStatus: 'manage' | 'select';
78
+ /**选中列表数据*/
79
+ manageSelectedDataList: T[];
80
+ /**全选按钮是否选中状态*/
81
+ allChecked: boolean;
82
+ /**选择模式
83
+ * @default 'single'
84
+ */
85
+ mode?: 'multiple' | 'single';
86
+ /**列表列配置*/
87
+ columns?: TableColumnProps[];
88
+ }
89
+ export declare class FairysTaroPopupSearchBaseInstance<T = any> extends FairysTaroPopupSearchBaseInstanceMount<T> {
90
+ /**窗口高度*/
91
+ windowHeight: number;
92
+ /**窗口宽度*/
93
+ windowWidth: number;
94
+ /**弹窗宽度*/
95
+ popupWidth: number;
96
+ /**弹窗高度*/
97
+ popupHeight: number;
98
+ state: FairysTaroPopupSearchBaseInstanceState<T>;
99
+ ctor(): void;
100
+ /**更新状态*/
101
+ updateState: (state: Partial<typeof this.state>) => void;
102
+ /**判断是否使用 options 参数,并且不是管理模式*/
103
+ isUseOptions: () => boolean;
104
+ /**搜索*/
105
+ onSearch: (keyword: string) => Promise<void>;
106
+ /**保存数据*/
107
+ onSave: () => void;
108
+ /**清空数据*/
109
+ onClear: () => void;
110
+ /**是否选中数据*/
111
+ isCheckedData: (data: T) => boolean;
112
+ /**单个选中数据*/
113
+ onCheckedData: (data: T, checked: boolean) => void;
114
+ /**全选按钮*/
115
+ onAllChecked: () => void;
116
+ /**关闭弹窗*/
117
+ onClose: () => void;
118
+ /**更新操作状态*/
119
+ updateOperationStatus: () => void;
120
+ /**删除选中数据*/
121
+ onDeleteData: (data?: T) => void;
122
+ }
123
+ export declare function useFairysTaroPopupSearchBaseInstance<T = any>(): readonly [{
124
+ readonly __defaultValue: string;
125
+ readonly visible: boolean;
126
+ readonly value: import("valtio").Snapshot<T> | readonly import("valtio").Snapshot<T>[];
127
+ readonly dataList: readonly import("valtio").Snapshot<T>[];
128
+ readonly _tempFilterDataList: readonly import("valtio").Snapshot<T>[];
129
+ readonly search?: string;
130
+ readonly _tempValue: import("valtio").Snapshot<T> | readonly import("valtio").Snapshot<T>[];
131
+ readonly operationStatus: "manage" | "select";
132
+ readonly manageSelectedDataList: readonly import("valtio").Snapshot<T>[];
133
+ readonly allChecked: boolean;
134
+ readonly mode?: "multiple" | "single";
135
+ readonly columns?: readonly {
136
+ readonly key: string;
137
+ readonly title?: string;
138
+ readonly align?: string;
139
+ readonly sorter?: ((a: any, b: any) => number) | boolean | string;
140
+ readonly render?: (rowData: any, rowIndex: number) => string | import("react").ReactNode;
141
+ readonly fixed?: import("@nutui/nutui-react-taro").PositionX;
142
+ readonly width?: number;
143
+ }[];
144
+ }, FairysTaroPopupSearchBaseInstance<T>, string];
145
+ export declare const FairysTaroPopupSearchBaseInstanceContext: import("react").Context<FairysTaroPopupSearchBaseInstance<any>>;
146
+ export declare function useFairysTaroPopupSearchBaseInstanceContext<T = any>(options?: {
147
+ sync?: boolean;
148
+ }): readonly [{
149
+ readonly __defaultValue: string;
150
+ readonly visible: boolean;
151
+ readonly value: import("valtio").Snapshot<T> | readonly import("valtio").Snapshot<T>[];
152
+ readonly dataList: readonly import("valtio").Snapshot<T>[];
153
+ readonly _tempFilterDataList: readonly import("valtio").Snapshot<T>[];
154
+ readonly search?: string;
155
+ readonly _tempValue: import("valtio").Snapshot<T> | readonly import("valtio").Snapshot<T>[];
156
+ readonly operationStatus: "manage" | "select";
157
+ readonly manageSelectedDataList: readonly import("valtio").Snapshot<T>[];
158
+ readonly allChecked: boolean;
159
+ readonly mode?: "multiple" | "single";
160
+ readonly columns?: readonly {
161
+ readonly key: string;
162
+ readonly title?: string;
163
+ readonly align?: string;
164
+ readonly sorter?: ((a: any, b: any) => number) | boolean | string;
165
+ readonly render?: (rowData: any, rowIndex: number) => string | import("react").ReactNode;
166
+ readonly fixed?: import("@nutui/nutui-react-taro").PositionX;
167
+ readonly width?: number;
168
+ }[];
169
+ }, FairysTaroPopupSearchBaseInstance<T>, string];
@@ -0,0 +1,319 @@
1
+ import { createContext, useContext, useRef } from "react";
2
+ import { proxy, ref, useSnapshot } from "valtio";
3
+ import taro from "@tarojs/taro";
4
+ class FairysTaroPopupSearchBaseInstanceMount {
5
+ onChange;
6
+ onLoadData;
7
+ otherRequestParams;
8
+ renderText;
9
+ renderListItemText;
10
+ renderList;
11
+ mode = 'single';
12
+ rowKey = 'value';
13
+ displayField = 'label';
14
+ columns = [];
15
+ maxWidth;
16
+ maxHeight;
17
+ isNeedManage = false;
18
+ isUseOptionsChecked = true;
19
+ renderType = 'list';
20
+ tableProps = {};
21
+ useTableProps;
22
+ showRowDeleteButton;
23
+ showSearch;
24
+ value;
25
+ options;
26
+ maxTagCount;
27
+ }
28
+ class FairysTaroPopupSearchBaseInstance extends FairysTaroPopupSearchBaseInstanceMount {
29
+ windowHeight = 0;
30
+ windowWidth = 0;
31
+ popupWidth = 0;
32
+ popupHeight = 0;
33
+ state = proxy({
34
+ mode: 'single',
35
+ columns: [],
36
+ __defaultValue: '',
37
+ visible: false,
38
+ value: void 0,
39
+ dataList: [],
40
+ _tempFilterDataList: [],
41
+ search: '',
42
+ _tempValue: void 0,
43
+ operationStatus: 'select',
44
+ manageSelectedDataList: [],
45
+ allChecked: false
46
+ });
47
+ ctor() {
48
+ const isWeb = taro.getEnv() === taro.ENV_TYPE.WEB;
49
+ if (isWeb) {
50
+ this.windowHeight = window.document.documentElement.clientHeight;
51
+ this.windowWidth = window.document.documentElement.clientWidth;
52
+ } else {
53
+ const windowInfo = taro.getWindowInfo();
54
+ this.windowHeight = windowInfo.windowHeight;
55
+ this.windowWidth = windowInfo.windowWidth;
56
+ }
57
+ this.popupHeight = 0.6 * this.windowHeight;
58
+ if (this.maxHeight) this.popupHeight = Math.min(this.popupHeight, this.maxHeight);
59
+ this.popupWidth = 0.8 * this.windowWidth;
60
+ if (this.maxWidth) this.popupWidth = Math.min(this.popupWidth, this.maxWidth);
61
+ }
62
+ updateState = (state)=>{
63
+ for(const key in state){
64
+ const value = state[key];
65
+ if (Array.isArray(value) || '[object Object]' === Object.prototype.toString.call(value)) this.state[key] = ref(value);
66
+ else this.state[key] = value;
67
+ }
68
+ };
69
+ isUseOptions = ()=>{
70
+ if (Array.isArray(this.options) && !this.onLoadData && !this.isNeedManage) return this.isUseOptionsChecked;
71
+ return false;
72
+ };
73
+ onSearch = async (keyword)=>{
74
+ this.state.search = keyword;
75
+ const _keyword = `${keyword || ''}`.trim();
76
+ try {
77
+ if (this.onLoadData && 'select' === this.state.operationStatus) {
78
+ await new Promise((resolve)=>setTimeout(resolve, 500));
79
+ const search = {
80
+ keyword: _keyword
81
+ };
82
+ const dataList = await this.onLoadData(this.otherRequestParams?.(search, this) || search, this);
83
+ if (Array.isArray(dataList)) this.updateState({
84
+ _tempFilterDataList: dataList || [],
85
+ dataList: dataList || []
86
+ });
87
+ else this.updateState({
88
+ _tempFilterDataList: []
89
+ });
90
+ } else if ('select' === this.state.operationStatus) {
91
+ if (!_keyword) return void this.updateState({
92
+ _tempFilterDataList: this.state.dataList || []
93
+ });
94
+ const filterData = (this.state.dataList || []).filter((item)=>{
95
+ const displayText = item[this.displayField]?.toString() || '';
96
+ const valueText = item[this.rowKey]?.toString() || '';
97
+ return displayText.includes(_keyword) || valueText.includes(_keyword);
98
+ });
99
+ this.updateState({
100
+ _tempFilterDataList: filterData
101
+ });
102
+ } else if ('multiple' === this.mode) {
103
+ const v = this.state._tempValue;
104
+ if (Array.isArray(v)) {
105
+ if (!_keyword) return void this.updateState({
106
+ _tempFilterDataList: v || []
107
+ });
108
+ const filterData = v.filter((item)=>{
109
+ const displayText = item[this.displayField]?.toString() || '';
110
+ const valueText = item[this.rowKey]?.toString() || '';
111
+ return displayText.includes(_keyword) || valueText.includes(_keyword);
112
+ });
113
+ this.updateState({
114
+ _tempFilterDataList: filterData
115
+ });
116
+ }
117
+ }
118
+ } catch (error) {
119
+ console.error(error);
120
+ }
121
+ };
122
+ onSave = ()=>{
123
+ if ('multiple' === this.mode) {
124
+ const dataList = this.state._tempValue || [];
125
+ this.updateState({
126
+ value: dataList,
127
+ _tempValue: dataList,
128
+ allChecked: false
129
+ });
130
+ this.onChange?.(dataList);
131
+ this.onClose();
132
+ }
133
+ };
134
+ onClear = ()=>{
135
+ this.state.value = void 0;
136
+ this.state._tempValue = void 0;
137
+ this.state.allChecked = false;
138
+ this.onChange?.(void 0);
139
+ };
140
+ isCheckedData = (data)=>{
141
+ if ('multiple' === this.mode) {
142
+ if ('manage' === this.state.operationStatus) return -1 !== (this.state.manageSelectedDataList || []).findIndex((item)=>item[this.rowKey] === data[this.rowKey]);
143
+ if (Array.isArray(this.state._tempValue)) {
144
+ const findx = this.state._tempValue.findIndex((item)=>item[this.rowKey] === data[this.rowKey]);
145
+ return -1 !== findx;
146
+ }
147
+ } else if (this.state._tempValue) return this.state._tempValue?.[this.rowKey] === data?.[this.rowKey];
148
+ return false;
149
+ };
150
+ onCheckedData = (data, checked)=>{
151
+ if ('multiple' === this.mode) {
152
+ if ('manage' === this.state.operationStatus) {
153
+ if (checked) {
154
+ const newList = (this.state.manageSelectedDataList || []).filter((item)=>item[this.rowKey] !== data[this.rowKey]);
155
+ this.updateState({
156
+ manageSelectedDataList: [
157
+ ...newList
158
+ ]
159
+ });
160
+ } else {
161
+ const newList = [
162
+ ...this.state.manageSelectedDataList || []
163
+ ].concat([
164
+ data
165
+ ]);
166
+ this.updateState({
167
+ manageSelectedDataList: newList
168
+ });
169
+ }
170
+ return;
171
+ }
172
+ const _tempValue = this.state._tempValue || [];
173
+ if (Array.isArray(_tempValue)) if (checked) {
174
+ const newList = _tempValue.filter((item)=>item[this.rowKey] !== data[this.rowKey]);
175
+ this.updateState({
176
+ _tempValue: [
177
+ ...newList
178
+ ]
179
+ });
180
+ } else {
181
+ const findx = _tempValue.find((item)=>item[this.rowKey] === data[this.rowKey]);
182
+ if (!findx) {
183
+ const newList = [
184
+ ..._tempValue
185
+ ].concat([
186
+ data
187
+ ]);
188
+ this.updateState({
189
+ _tempValue: newList
190
+ });
191
+ }
192
+ }
193
+ } else {
194
+ this.updateState({
195
+ value: data,
196
+ _tempValue: data
197
+ });
198
+ this.onChange?.(data);
199
+ this.onClose();
200
+ }
201
+ };
202
+ onAllChecked = ()=>{
203
+ if ('multiple' === this.mode) if (this.state.allChecked) {
204
+ if ('manage' === this.state.operationStatus) {
205
+ const _tempFilterDataList = this.state._tempFilterDataList || [];
206
+ const manageSelectedDataList = this.state.manageSelectedDataList || [];
207
+ const selectedList = manageSelectedDataList.filter((item)=>!_tempFilterDataList.find((dataItem)=>dataItem[this.rowKey] === item[this.rowKey]));
208
+ this.updateState({
209
+ manageSelectedDataList: [
210
+ ...selectedList
211
+ ],
212
+ allChecked: false
213
+ });
214
+ return;
215
+ }
216
+ const _tempValue = this.state._tempValue || [];
217
+ const dataList = this.state.dataList || [];
218
+ const newList = _tempValue.filter((item)=>!dataList.find((dataItem)=>dataItem[this.rowKey] === item[this.rowKey]));
219
+ this.updateState({
220
+ _tempValue: newList,
221
+ allChecked: false
222
+ });
223
+ } else {
224
+ if ('manage' === this.state.operationStatus) {
225
+ console.log(this.state._tempFilterDataList);
226
+ this.updateState({
227
+ manageSelectedDataList: this.state._tempFilterDataList || [],
228
+ allChecked: true
229
+ });
230
+ return;
231
+ }
232
+ const _tempValue = this.state._tempValue || [];
233
+ const dataList = this.state.dataList || [];
234
+ const newList = [
235
+ ..._tempValue
236
+ ].concat(dataList);
237
+ this.updateState({
238
+ _tempValue: newList,
239
+ allChecked: true
240
+ });
241
+ }
242
+ };
243
+ onClose = ()=>{
244
+ this.updateState({
245
+ visible: false,
246
+ allChecked: false,
247
+ manageSelectedDataList: [],
248
+ search: '',
249
+ _tempValue: this.state.value,
250
+ operationStatus: 'select',
251
+ _tempFilterDataList: this.state.dataList || []
252
+ });
253
+ };
254
+ updateOperationStatus = ()=>{
255
+ if ('multiple' === this.mode) if ('manage' === this.state.operationStatus) this.updateState({
256
+ operationStatus: 'select',
257
+ manageSelectedDataList: [],
258
+ _tempFilterDataList: this.state.dataList || [],
259
+ allChecked: false,
260
+ search: ''
261
+ });
262
+ else this.updateState({
263
+ operationStatus: 'manage',
264
+ manageSelectedDataList: [],
265
+ _tempFilterDataList: this.state._tempValue || [],
266
+ allChecked: false,
267
+ search: ''
268
+ });
269
+ };
270
+ onDeleteData = (data)=>{
271
+ if ('multiple' === this.mode) if (data) {
272
+ const _newValue = this.state._tempValue || [];
273
+ const _tempFilterDataList = this.state._tempFilterDataList || [];
274
+ if (Array.isArray(_newValue)) {
275
+ const newList = _newValue.filter((item)=>item[this.rowKey] !== data[this.rowKey]);
276
+ const newFilterList = _tempFilterDataList.filter((item)=>item[this.rowKey] !== data[this.rowKey]);
277
+ this.updateState({
278
+ _tempValue: newList,
279
+ _tempFilterDataList: newFilterList
280
+ });
281
+ }
282
+ } else {
283
+ const manageSelectedDataList = this.state.manageSelectedDataList || [];
284
+ const _newValue = this.state._tempValue || [];
285
+ const _tempFilterDataList = this.state._tempFilterDataList || [];
286
+ if (Array.isArray(_newValue)) {
287
+ const newList = _newValue.filter((item)=>!manageSelectedDataList.find((manageItem)=>manageItem[this.rowKey] === item[this.rowKey]));
288
+ const newFilterList = _tempFilterDataList.filter((item)=>!manageSelectedDataList.find((manageItem)=>manageItem[this.rowKey] === item[this.rowKey]));
289
+ this.updateState({
290
+ _tempValue: newList,
291
+ _tempFilterDataList: newFilterList,
292
+ manageSelectedDataList: []
293
+ });
294
+ }
295
+ }
296
+ };
297
+ }
298
+ function useFairysTaroPopupSearchBaseInstance() {
299
+ const instanceRef = useRef(new FairysTaroPopupSearchBaseInstance());
300
+ const state = useSnapshot(instanceRef.current.state);
301
+ const __defaultValue = state.__defaultValue;
302
+ return [
303
+ state,
304
+ instanceRef.current,
305
+ __defaultValue
306
+ ];
307
+ }
308
+ const FairysTaroPopupSearchBaseInstanceContext = createContext(new FairysTaroPopupSearchBaseInstance());
309
+ function useFairysTaroPopupSearchBaseInstanceContext(options) {
310
+ const instance = useContext(FairysTaroPopupSearchBaseInstanceContext);
311
+ const state = useSnapshot(instance.state, options);
312
+ const __defaultValue = state.__defaultValue;
313
+ return [
314
+ state,
315
+ instance,
316
+ __defaultValue
317
+ ];
318
+ }
319
+ export { FairysTaroPopupSearchBaseInstance, FairysTaroPopupSearchBaseInstanceContext, FairysTaroPopupSearchBaseInstanceMount, useFairysTaroPopupSearchBaseInstance, useFairysTaroPopupSearchBaseInstanceContext };
@@ -0,0 +1 @@
1
+ export declare function FairysTaroPopupSearchListTable<T = any>(): import("react/jsx-runtime").JSX.Element;