@hw-component/form 0.0.1
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/.babelrc +23 -0
- package/.eslintrc.js +8 -0
- package/.husky/pre-commit +4 -0
- package/.stylelintrc.js +5 -0
- package/es/Select/components/AllSelect.d.ts +7 -0
- package/es/Select/components/AllSelect.js +34 -0
- package/es/Select/components/CheckBoxOption.d.ts +7 -0
- package/es/Select/components/CheckBoxOption.js +14 -0
- package/es/Select/components/DropdownComponent.d.ts +9 -0
- package/es/Select/components/DropdownComponent.js +39 -0
- package/es/Select/components/NoFindItem.d.ts +6 -0
- package/es/Select/components/NoFindItem.js +13 -0
- package/es/Select/components/NotFoundContent.d.ts +7 -0
- package/es/Select/components/NotFoundContent.js +40 -0
- package/es/Select/defaultConfig.d.ts +7 -0
- package/es/Select/defaultConfig.js +37 -0
- package/es/Select/hooks/changeHooks.d.ts +5 -0
- package/es/Select/hooks/changeHooks.js +190 -0
- package/es/Select/hooks/norHooks.d.ts +12 -0
- package/es/Select/hooks/norHooks.js +102 -0
- package/es/Select/index.d.ts +4 -0
- package/es/Select/index.js +116 -0
- package/es/Select/index.less.js +5 -0
- package/es/Select/modal.d.ts +30 -0
- package/es/index.css +3 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +3 -0
- package/lib/Select/components/AllSelect.d.ts +7 -0
- package/lib/Select/components/AllSelect.js +37 -0
- package/lib/Select/components/CheckBoxOption.d.ts +7 -0
- package/lib/Select/components/CheckBoxOption.js +17 -0
- package/lib/Select/components/DropdownComponent.d.ts +9 -0
- package/lib/Select/components/DropdownComponent.js +42 -0
- package/lib/Select/components/NoFindItem.d.ts +6 -0
- package/lib/Select/components/NoFindItem.js +16 -0
- package/lib/Select/components/NotFoundContent.d.ts +7 -0
- package/lib/Select/components/NotFoundContent.js +43 -0
- package/lib/Select/defaultConfig.d.ts +7 -0
- package/lib/Select/defaultConfig.js +40 -0
- package/lib/Select/hooks/changeHooks.d.ts +5 -0
- package/lib/Select/hooks/changeHooks.js +191 -0
- package/lib/Select/hooks/norHooks.d.ts +12 -0
- package/lib/Select/hooks/norHooks.js +104 -0
- package/lib/Select/index.d.ts +4 -0
- package/lib/Select/index.js +119 -0
- package/lib/Select/index.less.js +8 -0
- package/lib/Select/modal.d.ts +30 -0
- package/lib/index.css +3 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -0
- package/package.json +80 -0
- package/public/index.html +19 -0
- package/scripts/rollup.config.js +80 -0
- package/scripts/webpack.config.js +72 -0
- package/src/Layout.tsx +61 -0
- package/src/app.tsx +33 -0
- package/src/components/Select/components/AllSelect.tsx +38 -0
- package/src/components/Select/components/CheckBoxOption.tsx +14 -0
- package/src/components/Select/components/DropdownComponent.tsx +35 -0
- package/src/components/Select/components/NoFindItem.tsx +7 -0
- package/src/components/Select/components/NotFoundContent.tsx +25 -0
- package/src/components/Select/defaultConfig.tsx +28 -0
- package/src/components/Select/hooks/changeHooks.tsx +141 -0
- package/src/components/Select/hooks/norHooks.ts +74 -0
- package/src/components/Select/index.less +5 -0
- package/src/components/Select/index.tsx +108 -0
- package/src/components/Select/modal.ts +30 -0
- package/src/components/index.tsx +1 -0
- package/src/components/typings.d.ts +11 -0
- package/src/index.less +20 -0
- package/src/index.tsx +12 -0
- package/src/pages/Select/index.tsx +54 -0
- package/src/routes.tsx +35 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// welcome to ww-building-blocks-tmp
|
|
2
|
+
import _extends from '@babel/runtime-corejs3/helpers/extends';
|
|
3
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
4
|
+
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
|
|
5
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
|
|
6
|
+
import { Select } from 'antd';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { useFilterOption, useOptionReq } from './hooks/norHooks.js';
|
|
9
|
+
import { useValueChange } from './hooks/changeHooks.js';
|
|
10
|
+
import { defaultModeConfig, defaultFieldNames, defaultSelectConfig } from './defaultConfig.js';
|
|
11
|
+
import Index from './components/DropdownComponent.js';
|
|
12
|
+
import AllSelect from './components/AllSelect.js';
|
|
13
|
+
|
|
14
|
+
var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect"];
|
|
15
|
+
var Option = Select.Option;
|
|
16
|
+
var index = (function (_ref) {
|
|
17
|
+
var _ref$style = _ref.style,
|
|
18
|
+
style = _ref$style === void 0 ? {
|
|
19
|
+
width: "100%"
|
|
20
|
+
} : _ref$style,
|
|
21
|
+
mode = _ref.mode,
|
|
22
|
+
options = _ref.options,
|
|
23
|
+
_ref$modeConfig = _ref.modeConfig,
|
|
24
|
+
modeConfig = _ref$modeConfig === void 0 ? defaultModeConfig : _ref$modeConfig,
|
|
25
|
+
value = _ref.value,
|
|
26
|
+
onChange = _ref.onChange,
|
|
27
|
+
_ref$fieldNames = _ref.fieldNames,
|
|
28
|
+
fieldNames = _ref$fieldNames === void 0 ? defaultFieldNames : _ref$fieldNames,
|
|
29
|
+
request = _ref.request,
|
|
30
|
+
manual = _ref.manual,
|
|
31
|
+
_ref$optionLabelProp = _ref.optionLabelProp,
|
|
32
|
+
optionLabelProp = _ref$optionLabelProp === void 0 ? "label" : _ref$optionLabelProp,
|
|
33
|
+
filterProvider = _ref.filterProvider,
|
|
34
|
+
_ref$optionFilterProp = _ref.optionFilterProp,
|
|
35
|
+
optionFilterProp = _ref$optionFilterProp === void 0 ? "filterlabel" : _ref$optionFilterProp,
|
|
36
|
+
serviceSearch = _ref.serviceSearch,
|
|
37
|
+
propsOnSearch = _ref.onSearch,
|
|
38
|
+
filterOption = _ref.filterOption,
|
|
39
|
+
showSearch = _ref.showSearch,
|
|
40
|
+
labelInValue = _ref.labelInValue,
|
|
41
|
+
_ref$noMatchItemRende = _ref.noMatchItemRender,
|
|
42
|
+
noMatchItemRender = _ref$noMatchItemRende === void 0 ? defaultSelectConfig.noMatchItemRender : _ref$noMatchItemRende,
|
|
43
|
+
allSelect = _ref.allSelect,
|
|
44
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
45
|
+
var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
|
|
46
|
+
icon = _ref2.icon,
|
|
47
|
+
render = _ref2.render;
|
|
48
|
+
var selfFilterOption = useFilterOption({
|
|
49
|
+
filterOption: filterOption,
|
|
50
|
+
serviceSearch: serviceSearch
|
|
51
|
+
});
|
|
52
|
+
var _useOptionReq = useOptionReq({
|
|
53
|
+
options: options,
|
|
54
|
+
manual: manual,
|
|
55
|
+
fieldNames: fieldNames,
|
|
56
|
+
request: request,
|
|
57
|
+
serviceSearch: serviceSearch
|
|
58
|
+
}),
|
|
59
|
+
run = _useOptionReq.run,
|
|
60
|
+
loading = _useOptionReq.loading,
|
|
61
|
+
data = _useOptionReq.data,
|
|
62
|
+
error = _useOptionReq.error,
|
|
63
|
+
onSearch = _useOptionReq.onSearch;
|
|
64
|
+
var _useValueChange = useValueChange({
|
|
65
|
+
labelInValue: labelInValue,
|
|
66
|
+
onChange: onChange,
|
|
67
|
+
value: value,
|
|
68
|
+
options: data,
|
|
69
|
+
mode: mode,
|
|
70
|
+
noMatchItemRender: noMatchItemRender
|
|
71
|
+
}),
|
|
72
|
+
val = _useValueChange.val,
|
|
73
|
+
change = _useValueChange.change;
|
|
74
|
+
return /*#__PURE__*/React.createElement(Select, _extends({
|
|
75
|
+
style: style,
|
|
76
|
+
mode: mode,
|
|
77
|
+
loading: loading,
|
|
78
|
+
value: val,
|
|
79
|
+
onSearch: propsOnSearch || onSearch,
|
|
80
|
+
onChange: change,
|
|
81
|
+
dropdownRender: function dropdownRender(node) {
|
|
82
|
+
return /*#__PURE__*/React.createElement(Index, {
|
|
83
|
+
loading: loading,
|
|
84
|
+
reload: run,
|
|
85
|
+
error: error,
|
|
86
|
+
options: data
|
|
87
|
+
}, /*#__PURE__*/React.createElement(AllSelect, {
|
|
88
|
+
allSelect: allSelect,
|
|
89
|
+
options: data,
|
|
90
|
+
mode: mode,
|
|
91
|
+
value: val,
|
|
92
|
+
onChange: change
|
|
93
|
+
}), node);
|
|
94
|
+
},
|
|
95
|
+
optionLabelProp: optionLabelProp,
|
|
96
|
+
menuItemSelectedIcon: icon,
|
|
97
|
+
optionFilterProp: optionFilterProp,
|
|
98
|
+
filterOption: selfFilterOption,
|
|
99
|
+
showSearch: showSearch,
|
|
100
|
+
labelInValue: true
|
|
101
|
+
}, props), data === null || data === void 0 ? void 0 : _mapInstanceProperty(data).call(data, function (item) {
|
|
102
|
+
var optionValue = item.value,
|
|
103
|
+
label = item.label;
|
|
104
|
+
var result = (filterProvider === null || filterProvider === void 0 ? void 0 : filterProvider(item)) || label;
|
|
105
|
+
var filer = _defineProperty({}, optionFilterProp, result);
|
|
106
|
+
return /*#__PURE__*/React.createElement(Option, _extends({
|
|
107
|
+
value: optionValue,
|
|
108
|
+
key: optionValue,
|
|
109
|
+
label: label,
|
|
110
|
+
mode: mode
|
|
111
|
+
}, filer), render ? render(item, val) : label);
|
|
112
|
+
}));
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
export { index as default };
|
|
116
|
+
// powered by ww
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SelectProps } from "antd";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
export type OptionType = Record<string, any>;
|
|
4
|
+
export type PartialHSelectProps = Partial<HSelectProps>;
|
|
5
|
+
export type RenderFn = (data: OptionType) => React.ReactNode;
|
|
6
|
+
interface ModeConfigItem {
|
|
7
|
+
icon?: React.ReactNode | null;
|
|
8
|
+
render?: (item: OptionType, value: any[]) => React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export interface ModeConfig {
|
|
11
|
+
multiple?: ModeConfigItem;
|
|
12
|
+
tags?: ModeConfigItem;
|
|
13
|
+
}
|
|
14
|
+
export interface HSelectProps extends Omit<SelectProps, "options"> {
|
|
15
|
+
style?: React.CSSProperties;
|
|
16
|
+
request?: (params: any) => Promise<OptionType[]>;
|
|
17
|
+
manual?: boolean;
|
|
18
|
+
modeConfig?: ModeConfig;
|
|
19
|
+
onChange?: (val: any) => void;
|
|
20
|
+
filterProvider?: (item: any) => string;
|
|
21
|
+
serviceSearch?: boolean;
|
|
22
|
+
options?: OptionType[];
|
|
23
|
+
noMatchItemRender?: RenderFn;
|
|
24
|
+
allSelect?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface FilterDataModal {
|
|
27
|
+
value: any;
|
|
28
|
+
index: number;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
package/es/index.css
ADDED
package/es/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as HSelect } from './Select';
|
package/es/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { HSelectProps } from "@/components/Select/modal";
|
|
3
|
+
interface IProps extends HSelectProps {
|
|
4
|
+
checked?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare const _default: ({ allSelect, mode, onChange, value, serviceSearch, options, }: IProps) => JSX.Element | null;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var antd = require('antd');
|
|
7
|
+
var index = require('../index.less.js');
|
|
8
|
+
|
|
9
|
+
var AllSelect = (function (_ref) {
|
|
10
|
+
var allSelect = _ref.allSelect,
|
|
11
|
+
mode = _ref.mode,
|
|
12
|
+
onChange = _ref.onChange,
|
|
13
|
+
value = _ref.value,
|
|
14
|
+
serviceSearch = _ref.serviceSearch,
|
|
15
|
+
options = _ref.options;
|
|
16
|
+
if (!allSelect || mode !== "multiple" || serviceSearch) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
var opLen = (options === null || options === void 0 ? void 0 : options.length) || 0;
|
|
20
|
+
var checked = (value === null || value === void 0 ? void 0 : value.length) >= opLen;
|
|
21
|
+
var change = function change() {
|
|
22
|
+
if (!checked) {
|
|
23
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(options);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
onChange === null || onChange === void 0 ? void 0 : onChange([]);
|
|
27
|
+
};
|
|
28
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
29
|
+
className: "ant-select-item ant-select-item-option ".concat(index.default.option),
|
|
30
|
+
onClick: change
|
|
31
|
+
}, /*#__PURE__*/React.createElement(antd.Space, null, /*#__PURE__*/React.createElement(antd.Checkbox, {
|
|
32
|
+
checked: checked
|
|
33
|
+
}), "\u5168\u90E8"));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
exports.default = AllSelect;
|
|
37
|
+
// powered by h
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var antd = require('antd');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
|
|
8
|
+
var CheckBoxOption = (function (_ref) {
|
|
9
|
+
var label = _ref.label,
|
|
10
|
+
checked = _ref.checked;
|
|
11
|
+
return /*#__PURE__*/React.createElement(antd.Space, null, /*#__PURE__*/React.createElement(antd.Checkbox, {
|
|
12
|
+
checked: checked
|
|
13
|
+
}), label);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
exports.default = CheckBoxOption;
|
|
17
|
+
// powered by h
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var antd = require('antd');
|
|
7
|
+
var NotFoundContent = require('./NotFoundContent.js');
|
|
8
|
+
|
|
9
|
+
var Text = antd.Typography.Text;
|
|
10
|
+
var Index = function Index(_ref) {
|
|
11
|
+
var loading = _ref.loading,
|
|
12
|
+
error = _ref.error,
|
|
13
|
+
_ref$options = _ref.options,
|
|
14
|
+
options = _ref$options === void 0 ? [] : _ref$options,
|
|
15
|
+
reload = _ref.reload,
|
|
16
|
+
children = _ref.children;
|
|
17
|
+
var len = options === null || options === void 0 ? void 0 : options.length;
|
|
18
|
+
if (loading && len === 0) {
|
|
19
|
+
return /*#__PURE__*/React.createElement(antd.Row, {
|
|
20
|
+
style: {
|
|
21
|
+
height: 125
|
|
22
|
+
},
|
|
23
|
+
justify: "center",
|
|
24
|
+
align: "middle"
|
|
25
|
+
}, /*#__PURE__*/React.createElement(antd.Space, {
|
|
26
|
+
direction: "vertical",
|
|
27
|
+
align: "center"
|
|
28
|
+
}, /*#__PURE__*/React.createElement(antd.Spin, null), /*#__PURE__*/React.createElement(Text, {
|
|
29
|
+
type: "secondary"
|
|
30
|
+
}, "\u62FC\u547D\u52A0\u8F7D\u4E2D...")));
|
|
31
|
+
}
|
|
32
|
+
if (error && len === 0) {
|
|
33
|
+
return /*#__PURE__*/React.createElement(NotFoundContent.default, {
|
|
34
|
+
error: error,
|
|
35
|
+
reload: reload
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
exports.default = Index;
|
|
42
|
+
// powered by h
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var antd = require('antd');
|
|
7
|
+
|
|
8
|
+
var NoFindItem = (function (_ref) {
|
|
9
|
+
var label = _ref.label;
|
|
10
|
+
return /*#__PURE__*/React.createElement(antd.Typography.Text, {
|
|
11
|
+
type: "danger"
|
|
12
|
+
}, label);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
exports.default = NoFindItem;
|
|
16
|
+
// powered by h
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var antd = require('antd');
|
|
7
|
+
var icons = require('@ant-design/icons');
|
|
8
|
+
|
|
9
|
+
var Text = antd.Typography.Text;
|
|
10
|
+
var NotFoundContent = (function (_ref) {
|
|
11
|
+
var error = _ref.error,
|
|
12
|
+
reload = _ref.reload;
|
|
13
|
+
if (error) {
|
|
14
|
+
return /*#__PURE__*/React.createElement(antd.Row, {
|
|
15
|
+
justify: "center",
|
|
16
|
+
align: "middle",
|
|
17
|
+
style: {
|
|
18
|
+
height: 125
|
|
19
|
+
}
|
|
20
|
+
}, /*#__PURE__*/React.createElement(antd.Space, {
|
|
21
|
+
align: "center",
|
|
22
|
+
direction: "vertical"
|
|
23
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
24
|
+
type: "danger"
|
|
25
|
+
}, /*#__PURE__*/React.createElement(icons.ExclamationCircleOutlined, {
|
|
26
|
+
style: {
|
|
27
|
+
fontSize: 24
|
|
28
|
+
}
|
|
29
|
+
})), /*#__PURE__*/React.createElement(Text, {
|
|
30
|
+
type: "danger"
|
|
31
|
+
}, error.message), /*#__PURE__*/React.createElement(antd.Button, {
|
|
32
|
+
type: "primary",
|
|
33
|
+
size: "small",
|
|
34
|
+
onClick: reload
|
|
35
|
+
}, "\u91CD\u65B0\u52A0\u8F7D")));
|
|
36
|
+
}
|
|
37
|
+
return /*#__PURE__*/React.createElement(antd.Empty, {
|
|
38
|
+
image: antd.Empty.PRESENTED_IMAGE_SIMPLE
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
exports.default = NotFoundContent;
|
|
43
|
+
// powered by h
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { HSelectProps } from "@/components/Select/modal";
|
|
3
|
+
export declare const defaultModeConfig: HSelectProps["modeConfig"];
|
|
4
|
+
export declare const defaultFieldNames: HSelectProps["fieldNames"];
|
|
5
|
+
export declare const defaultSelectConfig: {
|
|
6
|
+
noMatchItemRender: () => JSX.Element;
|
|
7
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
5
|
+
var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/index-of');
|
|
6
|
+
var CheckBoxOption = require('./components/CheckBoxOption.js');
|
|
7
|
+
var NoFindItem = require('./components/NoFindItem.js');
|
|
8
|
+
|
|
9
|
+
var defaultModeConfig = {
|
|
10
|
+
multiple: {
|
|
11
|
+
icon: null,
|
|
12
|
+
render: function render(item, value) {
|
|
13
|
+
var checkVal = value === null || value === void 0 ? void 0 : _mapInstanceProperty(value).call(value, function (itemVal) {
|
|
14
|
+
return itemVal.value;
|
|
15
|
+
});
|
|
16
|
+
var newVal = checkVal || [];
|
|
17
|
+
var checked = _indexOfInstanceProperty(newVal).call(newVal, item.value) !== -1;
|
|
18
|
+
return /*#__PURE__*/React.createElement(CheckBoxOption.default, {
|
|
19
|
+
label: item.label,
|
|
20
|
+
checked: checked
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var defaultFieldNames = {
|
|
26
|
+
label: "label",
|
|
27
|
+
value: "value"
|
|
28
|
+
};
|
|
29
|
+
var defaultSelectConfig = {
|
|
30
|
+
noMatchItemRender: function noMatchItemRender() {
|
|
31
|
+
return /*#__PURE__*/React.createElement(NoFindItem.default, {
|
|
32
|
+
label: "选项被删除,请重新选择"
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.defaultFieldNames = defaultFieldNames;
|
|
38
|
+
exports.defaultModeConfig = defaultModeConfig;
|
|
39
|
+
exports.defaultSelectConfig = defaultSelectConfig;
|
|
40
|
+
// powered by h
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
|
|
4
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js/object/get-own-property-symbols');
|
|
5
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/filter');
|
|
6
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptor');
|
|
7
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptors');
|
|
8
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
|
|
9
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
|
|
10
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
11
|
+
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
12
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
13
|
+
var _findIndexInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/find-index');
|
|
14
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
|
|
15
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
16
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js/array/is-array');
|
|
17
|
+
var React = require('react');
|
|
18
|
+
|
|
19
|
+
var _excluded = ["index"],
|
|
20
|
+
_excluded2 = ["index"];
|
|
21
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
+
var single = function single(_ref) {
|
|
24
|
+
var options = _ref.options,
|
|
25
|
+
value = _ref.value,
|
|
26
|
+
noMatchItemRender = _ref.noMatchItemRender;
|
|
27
|
+
var newOptions = options || [];
|
|
28
|
+
var index = _findIndexInstanceProperty(newOptions).call(newOptions, function (item) {
|
|
29
|
+
return item.value === value;
|
|
30
|
+
});
|
|
31
|
+
if (index !== -1) {
|
|
32
|
+
var label = newOptions[index].label;
|
|
33
|
+
return {
|
|
34
|
+
value: value,
|
|
35
|
+
label: label
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
value: value,
|
|
40
|
+
label: (noMatchItemRender === null || noMatchItemRender === void 0 ? void 0 : noMatchItemRender({
|
|
41
|
+
value: value
|
|
42
|
+
})) || value
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
var findNewValInOldVal = function findNewValInOldVal(val, oldVal) {
|
|
46
|
+
if (!oldVal) {
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
return _findIndexInstanceProperty(oldVal).call(oldVal, function (item) {
|
|
50
|
+
return item.value === val;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
var sourceDataProvider = function sourceDataProvider(_ref2, oldVal) {
|
|
54
|
+
_ref2.options;
|
|
55
|
+
var value = _ref2.value;
|
|
56
|
+
var oldData = [];
|
|
57
|
+
var newData = [];
|
|
58
|
+
_forEachInstanceProperty(value).call(value, function (item, i) {
|
|
59
|
+
var index = findNewValInOldVal(item, oldVal);
|
|
60
|
+
if (index === -1) {
|
|
61
|
+
newData.push({
|
|
62
|
+
value: item,
|
|
63
|
+
index: i
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
var newVal = oldVal === null || oldVal === void 0 ? void 0 : oldVal[index];
|
|
68
|
+
oldData.push(_objectSpread(_objectSpread({}, newVal), {}, {
|
|
69
|
+
index: i
|
|
70
|
+
}));
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
oldData: oldData,
|
|
74
|
+
newData: newData
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
var resultProvider = function resultProvider(newData, oldData, value) {
|
|
78
|
+
var newResult = new Array(value.length);
|
|
79
|
+
_forEachInstanceProperty(oldData).call(oldData, function (item) {
|
|
80
|
+
var index = item.index,
|
|
81
|
+
val = _objectWithoutProperties(item, _excluded);
|
|
82
|
+
newResult[index] = _objectSpread({}, val);
|
|
83
|
+
});
|
|
84
|
+
_forEachInstanceProperty(newData).call(newData, function (item) {
|
|
85
|
+
var index = item.index,
|
|
86
|
+
val = _objectWithoutProperties(item, _excluded2);
|
|
87
|
+
newResult[index] = _objectSpread({}, val);
|
|
88
|
+
});
|
|
89
|
+
return newResult;
|
|
90
|
+
};
|
|
91
|
+
var multiple = function multiple(_ref3, oldVal) {
|
|
92
|
+
var options = _ref3.options,
|
|
93
|
+
value = _ref3.value,
|
|
94
|
+
noMatchItemRender = _ref3.noMatchItemRender;
|
|
95
|
+
var _sourceDataProvider = sourceDataProvider({
|
|
96
|
+
options: options,
|
|
97
|
+
value: value
|
|
98
|
+
}, oldVal),
|
|
99
|
+
newData = _sourceDataProvider.newData,
|
|
100
|
+
oldData = _sourceDataProvider.oldData;
|
|
101
|
+
var newMatchVal = _mapInstanceProperty(newData).call(newData, function (item) {
|
|
102
|
+
var itemVal = item.value,
|
|
103
|
+
index = item.index;
|
|
104
|
+
var newItem = single({
|
|
105
|
+
options: options,
|
|
106
|
+
value: itemVal,
|
|
107
|
+
noMatchItemRender: noMatchItemRender
|
|
108
|
+
});
|
|
109
|
+
return _objectSpread(_objectSpread({}, newItem), {}, {
|
|
110
|
+
index: index
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
return resultProvider(newMatchVal, oldData, value);
|
|
114
|
+
};
|
|
115
|
+
var tag = function tag(_ref4, oldVal) {
|
|
116
|
+
var options = _ref4.options,
|
|
117
|
+
value = _ref4.value;
|
|
118
|
+
var _sourceDataProvider2 = sourceDataProvider({
|
|
119
|
+
options: options,
|
|
120
|
+
value: value
|
|
121
|
+
}, oldVal),
|
|
122
|
+
newData = _sourceDataProvider2.newData,
|
|
123
|
+
oldData = _sourceDataProvider2.oldData;
|
|
124
|
+
return resultProvider(newData, oldData, value);
|
|
125
|
+
};
|
|
126
|
+
var matchNotFind = function matchNotFind(_ref5, oldVale) {
|
|
127
|
+
var options = _ref5.options,
|
|
128
|
+
value = _ref5.value,
|
|
129
|
+
mode = _ref5.mode,
|
|
130
|
+
noMatchItemRender = _ref5.noMatchItemRender;
|
|
131
|
+
if (!mode) {
|
|
132
|
+
return single({
|
|
133
|
+
options: options,
|
|
134
|
+
value: value,
|
|
135
|
+
noMatchItemRender: noMatchItemRender
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (mode === "multiple") {
|
|
139
|
+
return multiple({
|
|
140
|
+
options: options,
|
|
141
|
+
value: value,
|
|
142
|
+
noMatchItemRender: noMatchItemRender
|
|
143
|
+
}, oldVale);
|
|
144
|
+
}
|
|
145
|
+
return tag({
|
|
146
|
+
options: options,
|
|
147
|
+
value: value
|
|
148
|
+
}, oldVale);
|
|
149
|
+
};
|
|
150
|
+
var useValueChange = function useValueChange(params) {
|
|
151
|
+
var labelInValue = params.labelInValue,
|
|
152
|
+
onChange = params.onChange,
|
|
153
|
+
value = params.value,
|
|
154
|
+
options = params.options,
|
|
155
|
+
mode = params.mode,
|
|
156
|
+
noMatchItemRender = params.noMatchItemRender;
|
|
157
|
+
var _useState = React.useState(),
|
|
158
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
159
|
+
val = _useState2[0],
|
|
160
|
+
setVal = _useState2[1];
|
|
161
|
+
var change = function change(changeVal) {
|
|
162
|
+
if (!onChange) {
|
|
163
|
+
setVal(changeVal);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
var newChangeVal = changeVal.value;
|
|
167
|
+
if (labelInValue) {
|
|
168
|
+
newChangeVal = changeVal;
|
|
169
|
+
}
|
|
170
|
+
if (_Array$isArray(changeVal)) {
|
|
171
|
+
newChangeVal = _mapInstanceProperty(changeVal).call(changeVal, function (item) {
|
|
172
|
+
return item.value;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
onChange(newChangeVal);
|
|
176
|
+
};
|
|
177
|
+
React.useEffect(function () {
|
|
178
|
+
if (options && value) {
|
|
179
|
+
setVal(function (oldVale) {
|
|
180
|
+
return matchNotFind(params, oldVale);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}, [value, options, mode, noMatchItemRender]);
|
|
184
|
+
return {
|
|
185
|
+
val: val,
|
|
186
|
+
change: change
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
exports.useValueChange = useValueChange;
|
|
191
|
+
// powered by h
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OptionType, PartialHSelectProps } from "@/components/Select/modal";
|
|
2
|
+
export declare const useOptionReq: ({ manual, fieldNames, request, options, serviceSearch, }: PartialHSelectProps) => {
|
|
3
|
+
run: (params?: any, type?: any) => Promise<{
|
|
4
|
+
label: any;
|
|
5
|
+
value: any;
|
|
6
|
+
}[] | undefined>;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
error: Error | undefined;
|
|
9
|
+
data: OptionType[] | undefined;
|
|
10
|
+
onSearch: (inputValue: string) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const useFilterOption: ({ filterOption, serviceSearch, }: PartialHSelectProps) => boolean | import("rc-select/lib/Select").FilterFunc<import("rc-select/lib/Select").DefaultOptionType> | undefined;
|