@hw-component/form 0.0.5-beta-v5 → 0.0.5-beta-v7

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 (148) hide show
  1. package/es/Form/config.d.ts +2 -2
  2. package/es/config.d.ts +4 -0
  3. package/es/index.d.ts +1 -26
  4. package/es/index.js +4 -30
  5. package/lib/Form/config.d.ts +2 -2
  6. package/lib/config.d.ts +4 -0
  7. package/lib/index.d.ts +1 -26
  8. package/lib/index.js +4 -53
  9. package/package.json +8 -2
  10. package/scripts/rollup.config.js +11 -14
  11. package/src/components/config.ts +4 -0
  12. package/src/components/index.tsx +3 -30
  13. package/es/CheckboxGroup/CheckBox/index.js +0 -42
  14. package/es/CheckboxGroup/hooks.js +0 -120
  15. package/es/CheckboxGroup/index.js +0 -93
  16. package/es/DialogForm/DrawerForm/Footer.js +0 -27
  17. package/es/DialogForm/DrawerForm/Title.js +0 -21
  18. package/es/DialogForm/DrawerForm/index.js +0 -137
  19. package/es/DialogForm/ModalForm.js +0 -118
  20. package/es/DialogForm/hooks.js +0 -148
  21. package/es/Form/Context/FormConfigProvider.js +0 -48
  22. package/es/Form/Context/index.js +0 -11
  23. package/es/Form/FormItem/BasicItem.js +0 -92
  24. package/es/Form/FormItem/Helper.js +0 -26
  25. package/es/Form/FormItem/RegularFormItem.js +0 -24
  26. package/es/Form/FormItem/UpFormItem.js +0 -42
  27. package/es/Form/FormItem/hooks.js +0 -38
  28. package/es/Form/FormItem/index.js +0 -21
  29. package/es/Form/HFormConnect.js +0 -68
  30. package/es/Form/InitSet.js +0 -16
  31. package/es/Form/Label.js +0 -49
  32. package/es/Form/config.js +0 -45
  33. package/es/Form/hooks/index.js +0 -157
  34. package/es/Form/hooks/useDefaultRender.js +0 -48
  35. package/es/Form/hooks/useHForm.js +0 -193
  36. package/es/Form/hooks/useInitConfigData.js +0 -169
  37. package/es/Form/index.js +0 -102
  38. package/es/Input/ButtonInput.js +0 -94
  39. package/es/Input/ColorInput/Picker.js +0 -22
  40. package/es/Input/ColorInput/data.js +0 -5
  41. package/es/Input/ColorInput/index.js +0 -93
  42. package/es/Input/InputNumber.js +0 -29
  43. package/es/Input/SelectInput.js +0 -95
  44. package/es/Input/defaultConfig.js +0 -11
  45. package/es/Input/index.js +0 -23
  46. package/es/PageHandler/ErrorComponent.js +0 -38
  47. package/es/PageHandler/LoadingComponent.js +0 -19
  48. package/es/PageHandler/index.js +0 -26
  49. package/es/RadioGroup/index.js +0 -58
  50. package/es/Select/components/AllSelect.js +0 -55
  51. package/es/Select/components/CheckBoxOption.js +0 -16
  52. package/es/Select/components/DropdownComponent.js +0 -44
  53. package/es/Select/components/NoFindItem.js +0 -14
  54. package/es/Select/components/NotFoundContent.js +0 -43
  55. package/es/Select/defaultConfig.js +0 -32
  56. package/es/Select/hooks/changeHooks.js +0 -196
  57. package/es/Select/hooks/norHooks.js +0 -118
  58. package/es/Select/index.js +0 -149
  59. package/es/Select/utils.js +0 -37
  60. package/es/Submit/index.js +0 -54
  61. package/es/Switch/index.js +0 -59
  62. package/es/TDPicker/RangePicker.js +0 -125
  63. package/es/TDPicker/TimePicker.js +0 -44
  64. package/es/TDPicker/hooks.js +0 -132
  65. package/es/TDPicker/index.js +0 -47
  66. package/es/TextArea/index.js +0 -30
  67. package/es/Upload/Btn.js +0 -36
  68. package/es/Upload/MediaTypeEle/TypeEle.js +0 -42
  69. package/es/Upload/MediaTypeEle/index.js +0 -36
  70. package/es/Upload/Preview/index.js +0 -22
  71. package/es/Upload/UrlUpload/index.js +0 -133
  72. package/es/Upload/enums.js +0 -10
  73. package/es/Upload/hooks/change.js +0 -107
  74. package/es/Upload/hooks/customRequest.js +0 -131
  75. package/es/Upload/hooks/propsMaker.js +0 -36
  76. package/es/Upload/index.js +0 -145
  77. package/es/Upload/util.js +0 -34
  78. package/es/config.js +0 -65
  79. package/es/hooks/index.js +0 -74
  80. package/es/index.css +0 -44
  81. package/lib/CheckboxGroup/CheckBox/index.js +0 -45
  82. package/lib/CheckboxGroup/hooks.js +0 -121
  83. package/lib/CheckboxGroup/index.js +0 -96
  84. package/lib/DialogForm/DrawerForm/Footer.js +0 -30
  85. package/lib/DialogForm/DrawerForm/Title.js +0 -24
  86. package/lib/DialogForm/DrawerForm/index.js +0 -140
  87. package/lib/DialogForm/ModalForm.js +0 -121
  88. package/lib/DialogForm/hooks.js +0 -152
  89. package/lib/Form/Context/FormConfigProvider.js +0 -52
  90. package/lib/Form/Context/index.js +0 -14
  91. package/lib/Form/FormItem/BasicItem.js +0 -95
  92. package/lib/Form/FormItem/Helper.js +0 -29
  93. package/lib/Form/FormItem/RegularFormItem.js +0 -27
  94. package/lib/Form/FormItem/UpFormItem.js +0 -45
  95. package/lib/Form/FormItem/hooks.js +0 -41
  96. package/lib/Form/FormItem/index.js +0 -24
  97. package/lib/Form/HFormConnect.js +0 -71
  98. package/lib/Form/InitSet.js +0 -19
  99. package/lib/Form/Label.js +0 -52
  100. package/lib/Form/config.js +0 -49
  101. package/lib/Form/hooks/index.js +0 -161
  102. package/lib/Form/hooks/useDefaultRender.js +0 -49
  103. package/lib/Form/hooks/useHForm.js +0 -196
  104. package/lib/Form/hooks/useInitConfigData.js +0 -172
  105. package/lib/Form/index.js +0 -105
  106. package/lib/Input/ButtonInput.js +0 -97
  107. package/lib/Input/ColorInput/Picker.js +0 -25
  108. package/lib/Input/ColorInput/data.js +0 -6
  109. package/lib/Input/ColorInput/index.js +0 -96
  110. package/lib/Input/InputNumber.js +0 -32
  111. package/lib/Input/SelectInput.js +0 -99
  112. package/lib/Input/defaultConfig.js +0 -13
  113. package/lib/Input/index.js +0 -26
  114. package/lib/PageHandler/ErrorComponent.js +0 -41
  115. package/lib/PageHandler/LoadingComponent.js +0 -22
  116. package/lib/PageHandler/index.js +0 -29
  117. package/lib/RadioGroup/index.js +0 -61
  118. package/lib/Select/components/AllSelect.js +0 -58
  119. package/lib/Select/components/CheckBoxOption.js +0 -19
  120. package/lib/Select/components/DropdownComponent.js +0 -47
  121. package/lib/Select/components/NoFindItem.js +0 -17
  122. package/lib/Select/components/NotFoundContent.js +0 -46
  123. package/lib/Select/defaultConfig.js +0 -34
  124. package/lib/Select/hooks/changeHooks.js +0 -197
  125. package/lib/Select/hooks/norHooks.js +0 -120
  126. package/lib/Select/index.js +0 -152
  127. package/lib/Select/utils.js +0 -39
  128. package/lib/Submit/index.js +0 -57
  129. package/lib/Switch/index.js +0 -62
  130. package/lib/TDPicker/RangePicker.js +0 -128
  131. package/lib/TDPicker/TimePicker.js +0 -47
  132. package/lib/TDPicker/hooks.js +0 -139
  133. package/lib/TDPicker/index.js +0 -50
  134. package/lib/TextArea/index.js +0 -33
  135. package/lib/Upload/Btn.js +0 -39
  136. package/lib/Upload/MediaTypeEle/TypeEle.js +0 -45
  137. package/lib/Upload/MediaTypeEle/index.js +0 -39
  138. package/lib/Upload/Preview/index.js +0 -25
  139. package/lib/Upload/UrlUpload/index.js +0 -136
  140. package/lib/Upload/enums.js +0 -9
  141. package/lib/Upload/hooks/change.js +0 -108
  142. package/lib/Upload/hooks/customRequest.js +0 -132
  143. package/lib/Upload/hooks/propsMaker.js +0 -37
  144. package/lib/Upload/index.js +0 -148
  145. package/lib/Upload/util.js +0 -38
  146. package/lib/config.js +0 -66
  147. package/lib/hooks/index.js +0 -77
  148. package/lib/index.css +0 -44
@@ -1,38 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { Typography, Row, Space, Button } from 'antd';
4
- import { ExclamationCircleOutlined } from '@ant-design/icons';
5
-
6
- var Text = Typography.Text;
7
- var ErrorComponent = (function (_ref) {
8
- var error = _ref.error,
9
- reload = _ref.reload;
10
- return jsx(Row, {
11
- justify: "center",
12
- align: "middle",
13
- style: {
14
- height: 125
15
- },
16
- children: jsxs(Space, {
17
- align: "center",
18
- direction: "vertical",
19
- children: [jsx(Text, {
20
- type: "danger",
21
- children: jsx(ExclamationCircleOutlined, {
22
- size: 24
23
- })
24
- }), jsx(Text, {
25
- type: "danger",
26
- children: error === null || error === void 0 ? void 0 : error.message
27
- }), jsx(Button, {
28
- type: "primary",
29
- size: "small",
30
- onClick: reload,
31
- children: "\u91CD\u65B0\u52A0\u8F7D"
32
- })]
33
- })
34
- });
35
- });
36
-
37
- export { ErrorComponent as default };
38
- // powered by hdj
@@ -1,19 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import { jsx } from 'react/jsx-runtime';
3
- import { Row, Spin } from 'antd';
4
-
5
- var Loading = (function () {
6
- return jsx(Row, {
7
- justify: "center",
8
- align: "middle",
9
- style: {
10
- height: 125
11
- },
12
- children: jsx(Spin, {
13
- size: "large"
14
- })
15
- });
16
- });
17
-
18
- export { Loading as default };
19
- // powered by hdj
@@ -1,26 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import { jsx, Fragment } from 'react/jsx-runtime';
3
- import Loading from './LoadingComponent.js';
4
- import ErrorComponent from './ErrorComponent.js';
5
-
6
- var Index = function Index(_ref) {
7
- var error = _ref.error,
8
- data = _ref.data,
9
- reload = _ref.reload,
10
- children = _ref.children;
11
- if (error) {
12
- return jsx(ErrorComponent, {
13
- error: error,
14
- reload: reload
15
- });
16
- }
17
- if (data) {
18
- return jsx(Fragment, {
19
- children: children
20
- });
21
- }
22
- return jsx(Loading, {});
23
- };
24
-
25
- export { Index as default };
26
- // powered by hdj
@@ -1,58 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
- import _typeof from '@babel/runtime/helpers/typeof';
4
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
- import 'core-js/modules/es.array.map.js';
6
- import 'core-js/modules/es.object.keys.js';
7
- import 'core-js/modules/es.symbol.js';
8
- import 'core-js/modules/es.array.filter.js';
9
- import 'core-js/modules/es.object.to-string.js';
10
- import 'core-js/modules/es.object.get-own-property-descriptor.js';
11
- import 'core-js/modules/web.dom-collections.for-each.js';
12
- import 'core-js/modules/es.object.get-own-property-descriptors.js';
13
- import { jsx } from 'react/jsx-runtime';
14
- import { Radio } from 'antd';
15
- import { useMemo } from 'react';
16
- import { useMatchConfigProps } from '../hooks/index.js';
17
-
18
- var _excluded = ["value", "options", "onChange", "fieldNames"];
19
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
20
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
- var HRadioGroup = (function (_ref) {
22
- var value = _ref.value,
23
- options = _ref.options,
24
- _onChange = _ref.onChange,
25
- propsFieldNames = _ref.fieldNames,
26
- props = _objectWithoutProperties(_ref, _excluded);
27
- var _useMatchConfigProps = useMatchConfigProps({
28
- fieldNames: propsFieldNames
29
- }),
30
- _useMatchConfigProps$ = _useMatchConfigProps.fieldNames,
31
- fieldNames = _useMatchConfigProps$ === void 0 ? {} : _useMatchConfigProps$;
32
- var relOptions = useMemo(function () {
33
- return options === null || options === void 0 ? void 0 : options.map(function (item) {
34
- var type = _typeof(item);
35
- if (type === "string" || type === "number") {
36
- return item;
37
- }
38
- var _fieldNames$label = fieldNames.label,
39
- labelKey = _fieldNames$label === void 0 ? "" : _fieldNames$label,
40
- _fieldNames$value = fieldNames.value,
41
- valueKey = _fieldNames$value === void 0 ? "" : _fieldNames$value;
42
- return {
43
- label: item[labelKey],
44
- value: item[valueKey]
45
- };
46
- });
47
- }, [options, fieldNames]);
48
- return jsx(Radio.Group, _objectSpread({
49
- options: relOptions,
50
- value: value,
51
- onChange: function onChange(e) {
52
- _onChange === null || _onChange === void 0 || _onChange(e.target.value);
53
- }
54
- }, props));
55
- });
56
-
57
- export { HRadioGroup as default };
58
- // powered by hdj
@@ -1,55 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import 'core-js/modules/es.array.concat.js';
3
- import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
4
- import { Space, Checkbox } from 'antd';
5
- import { itemOpProvider } from '../utils.js';
6
- import { useClassName } from '../../hooks/index.js';
7
-
8
- var useRootClassName = function useRootClassName(checked) {
9
- var norClassNames = ["select-item", "select-item-option"];
10
- return checked ? [].concat(norClassNames, ["select-item-option-selected"]) : norClassNames;
11
- };
12
- var Index = function Index(_ref) {
13
- var allSelect = _ref.allSelect,
14
- mode = _ref.mode,
15
- onChange = _ref.onChange,
16
- value = _ref.value,
17
- serviceSearch = _ref.serviceSearch,
18
- options = _ref.options,
19
- _ref$fieldNames = _ref.fieldNames,
20
- fieldNames = _ref$fieldNames === void 0 ? {} : _ref$fieldNames,
21
- children = _ref.children;
22
- var opLen = (options === null || options === void 0 ? void 0 : options.length) || 0;
23
- var checked = (value === null || value === void 0 ? void 0 : value.length) >= opLen;
24
- var classNames = useRootClassName(checked);
25
- var optionsClassName = useClassName(classNames);
26
- var allCheckBox = useClassName("hw-all-check-box");
27
- var change = function change() {
28
- if (!checked) {
29
- var subItemOps = itemOpProvider(options, fieldNames);
30
- onChange === null || onChange === void 0 || onChange(options, subItemOps);
31
- return;
32
- }
33
- onChange === null || onChange === void 0 || onChange([], []);
34
- };
35
- if (!allSelect || mode !== "multiple" || serviceSearch) {
36
- return jsx(Fragment, {
37
- children: children
38
- });
39
- }
40
- return jsxs("div", {
41
- className: allCheckBox,
42
- children: [jsx("div", {
43
- className: optionsClassName,
44
- onClick: change,
45
- children: jsxs(Space, {
46
- children: [jsx(Checkbox, {
47
- checked: checked
48
- }), "\u5168\u90E8"]
49
- })
50
- }), children]
51
- });
52
- };
53
-
54
- export { Index as default };
55
- // powered by hdj
@@ -1,16 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { Space, Checkbox } from 'antd';
4
-
5
- var CheckBoxOption = (function (_ref) {
6
- var label = _ref.label,
7
- checked = _ref.checked;
8
- return jsxs(Space, {
9
- children: [jsx(Checkbox, {
10
- checked: checked
11
- }), label]
12
- });
13
- });
14
-
15
- export { CheckBoxOption as default };
16
- // powered by hdj
@@ -1,44 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
- import { Typography, Row, Space, Spin } from 'antd';
4
- import NotFoundContent from './NotFoundContent.js';
5
-
6
- var Text = Typography.Text;
7
- var Index = function Index(_ref) {
8
- var loading = _ref.loading,
9
- error = _ref.error,
10
- _ref$options = _ref.options,
11
- options = _ref$options === void 0 ? [] : _ref$options,
12
- reload = _ref.reload,
13
- children = _ref.children;
14
- var len = options === null || options === void 0 ? void 0 : options.length;
15
- if (loading && len === 0) {
16
- return jsx(Row, {
17
- style: {
18
- height: 125
19
- },
20
- justify: "center",
21
- align: "middle",
22
- children: jsxs(Space, {
23
- direction: "vertical",
24
- align: "center",
25
- children: [jsx(Spin, {}), jsx(Text, {
26
- type: "secondary",
27
- children: "\u62FC\u547D\u52A0\u8F7D\u4E2D..."
28
- })]
29
- })
30
- });
31
- }
32
- if (error && len === 0) {
33
- return jsx(NotFoundContent, {
34
- error: error,
35
- reload: reload
36
- });
37
- }
38
- return jsx(Fragment, {
39
- children: children
40
- });
41
- };
42
-
43
- export { Index as default };
44
- // powered by hdj
@@ -1,14 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import { jsx } from 'react/jsx-runtime';
3
- import { Typography } from 'antd';
4
-
5
- var NoFindItem = (function (_ref) {
6
- var label = _ref.label;
7
- return jsx(Typography.Text, {
8
- type: "danger",
9
- children: label
10
- });
11
- });
12
-
13
- export { NoFindItem as default };
14
- // powered by hdj
@@ -1,43 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { Typography, Row, Space, Button, Empty } from 'antd';
4
- import { ExclamationCircleOutlined } from '@ant-design/icons';
5
-
6
- var Text = Typography.Text;
7
- var NotFoundContent = (function (_ref) {
8
- var error = _ref.error,
9
- reload = _ref.reload;
10
- if (error) {
11
- return jsx(Row, {
12
- justify: "center",
13
- align: "middle",
14
- style: {
15
- height: 125
16
- },
17
- children: jsxs(Space, {
18
- align: "center",
19
- direction: "vertical",
20
- children: [jsx(Text, {
21
- type: "danger",
22
- children: jsx(ExclamationCircleOutlined, {
23
- size: 24
24
- })
25
- }), jsx(Text, {
26
- type: "danger",
27
- children: error.message
28
- }), jsx(Button, {
29
- type: "primary",
30
- size: "small",
31
- onClick: reload,
32
- children: "\u91CD\u65B0\u52A0\u8F7D"
33
- })]
34
- })
35
- });
36
- }
37
- return jsx(Empty, {
38
- image: Empty.PRESENTED_IMAGE_SIMPLE
39
- });
40
- });
41
-
42
- export { NotFoundContent as default };
43
- // powered by hdj
@@ -1,32 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import 'core-js/modules/es.array.map.js';
3
- import { jsx } from 'react/jsx-runtime';
4
- import CheckBoxOption from './components/CheckBoxOption.js';
5
- import NoFindItem from './components/NoFindItem.js';
6
-
7
- var defaultModeConfig = {
8
- multiple: {
9
- icon: null,
10
- render: function render(item, value) {
11
- var checkVal = value === null || value === void 0 ? void 0 : value.map(function (itemVal) {
12
- return itemVal.value;
13
- });
14
- var newVal = checkVal || [];
15
- var checked = newVal.indexOf(item.value) !== -1;
16
- return jsx(CheckBoxOption, {
17
- label: item.label,
18
- checked: checked
19
- });
20
- }
21
- }
22
- };
23
- var defaultSelectConfig = {
24
- noMatchItemRender: function noMatchItemRender() {
25
- return jsx(NoFindItem, {
26
- label: "选项被删除,请重新选择"
27
- });
28
- }
29
- };
30
-
31
- export { defaultModeConfig, defaultSelectConfig };
32
- // powered by hdj
@@ -1,196 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import 'core-js/modules/es.object.keys.js';
3
- import 'core-js/modules/es.symbol.js';
4
- import 'core-js/modules/es.array.filter.js';
5
- import 'core-js/modules/es.object.get-own-property-descriptor.js';
6
- import 'core-js/modules/es.object.get-own-property-descriptors.js';
7
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
8
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
9
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
10
- import 'core-js/modules/es.array.find-index.js';
11
- import 'core-js/modules/es.object.to-string.js';
12
- import 'core-js/modules/web.dom-collections.for-each.js';
13
- import 'core-js/modules/es.array.map.js';
14
- import { useState, useEffect } from 'react';
15
- import { itemOpProvider } from '../utils.js';
16
-
17
- var _excluded = ["index"],
18
- _excluded2 = ["index"];
19
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
20
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
- var single = function single(_ref) {
22
- var options = _ref.options,
23
- value = _ref.value,
24
- noMatchItemRender = _ref.noMatchItemRender;
25
- var newOptions = options || [];
26
- var index = newOptions.findIndex(function (item) {
27
- return item.value === value;
28
- });
29
- if (index !== -1) {
30
- var label = newOptions[index].label;
31
- return {
32
- value: value,
33
- label: label
34
- };
35
- }
36
- return {
37
- value: value,
38
- label: (noMatchItemRender === null || noMatchItemRender === void 0 ? void 0 : noMatchItemRender({
39
- value: value
40
- })) || value
41
- };
42
- };
43
- var findNewValInOldVal = function findNewValInOldVal(val, oldVal) {
44
- if (!oldVal) {
45
- return -1;
46
- }
47
- return oldVal.findIndex(function (item) {
48
- return item.value === val;
49
- });
50
- };
51
- var sourceDataProvider = function sourceDataProvider(_ref2, oldVal) {
52
- _ref2.options;
53
- var value = _ref2.value;
54
- var oldData = [];
55
- var newData = [];
56
- value.forEach(function (item, i) {
57
- var index = findNewValInOldVal(item, oldVal);
58
- if (index === -1) {
59
- newData.push({
60
- value: item,
61
- index: i
62
- });
63
- return;
64
- }
65
- var newVal = oldVal === null || oldVal === void 0 ? void 0 : oldVal[index];
66
- oldData.push(_objectSpread(_objectSpread({}, newVal), {}, {
67
- index: i
68
- }));
69
- });
70
- return {
71
- oldData: oldData,
72
- newData: newData
73
- };
74
- };
75
- var resultProvider = function resultProvider(newData, oldData, value) {
76
- var newResult = new Array(value.length);
77
- oldData.forEach(function (item) {
78
- var index = item.index,
79
- val = _objectWithoutProperties(item, _excluded);
80
- newResult[index] = _objectSpread({}, val);
81
- });
82
- newData.forEach(function (item) {
83
- var index = item.index,
84
- val = _objectWithoutProperties(item, _excluded2);
85
- newResult[index] = _objectSpread({}, val);
86
- });
87
- return newResult;
88
- };
89
- var multiple = function multiple(_ref3, oldVal) {
90
- var options = _ref3.options,
91
- value = _ref3.value,
92
- noMatchItemRender = _ref3.noMatchItemRender;
93
- var _sourceDataProvider = sourceDataProvider({
94
- options: options,
95
- value: value
96
- }, oldVal),
97
- newData = _sourceDataProvider.newData,
98
- oldData = _sourceDataProvider.oldData;
99
- var newMatchVal = newData.map(function (item) {
100
- var itemVal = item.value,
101
- index = item.index;
102
- var newItem = single({
103
- options: options,
104
- value: itemVal,
105
- noMatchItemRender: noMatchItemRender
106
- });
107
- return _objectSpread(_objectSpread({}, newItem), {}, {
108
- index: index
109
- });
110
- });
111
- return resultProvider(newMatchVal, oldData, value);
112
- };
113
- var tag = function tag(_ref4, oldVal) {
114
- var options = _ref4.options,
115
- value = _ref4.value;
116
- var _sourceDataProvider2 = sourceDataProvider({
117
- options: options,
118
- value: value
119
- }, oldVal),
120
- newData = _sourceDataProvider2.newData,
121
- oldData = _sourceDataProvider2.oldData;
122
- return resultProvider(newData, oldData, value);
123
- };
124
- var matchNotFind = function matchNotFind(_ref5, oldVale) {
125
- var options = _ref5.options,
126
- value = _ref5.value,
127
- mode = _ref5.mode,
128
- noMatchItemRender = _ref5.noMatchItemRender;
129
- if (!mode) {
130
- return single({
131
- options: options,
132
- value: value,
133
- noMatchItemRender: noMatchItemRender
134
- });
135
- }
136
- if (mode === "multiple") {
137
- return multiple({
138
- options: options,
139
- value: value,
140
- noMatchItemRender: noMatchItemRender
141
- }, oldVale);
142
- }
143
- return tag({
144
- options: options,
145
- value: value
146
- }, oldVale);
147
- };
148
- var useValueChange = function useValueChange(params) {
149
- var labelInValue = params.labelInValue,
150
- onChange = params.onChange,
151
- value = params.value,
152
- options = params.options,
153
- mode = params.mode,
154
- noMatchItemRender = params.noMatchItemRender,
155
- _params$fieldNames = params.fieldNames,
156
- fieldNames = _params$fieldNames === void 0 ? {} : _params$fieldNames;
157
- var _useState = useState(),
158
- _useState2 = _slicedToArray(_useState, 2),
159
- val = _useState2[0],
160
- setVal = _useState2[1];
161
- var change = function change(changeVal, itemOps) {
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 = changeVal.map(function (item) {
172
- return item.value;
173
- });
174
- }
175
- var subItemOps = itemOpProvider(itemOps, fieldNames);
176
- onChange(newChangeVal, subItemOps);
177
- };
178
- useEffect(function () {
179
- if (mode === "tags" || value === null || value === undefined) {
180
- setVal(value);
181
- return;
182
- }
183
- if (options && value) {
184
- setVal(function (oldVale) {
185
- return matchNotFind(params, oldVale);
186
- });
187
- }
188
- }, [value, options, mode, noMatchItemRender]);
189
- return {
190
- val: val,
191
- change: change
192
- };
193
- };
194
-
195
- export { useValueChange };
196
- // powered by hdj
@@ -1,118 +0,0 @@
1
- // welcome to hoo hoo hoo
2
- import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
3
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
- import _regeneratorRuntime from '@babel/runtime/regenerator';
5
- import 'core-js/modules/es.array.iterator.js';
6
- import 'core-js/modules/es.object.to-string.js';
7
- import 'core-js/modules/web.dom-collections.iterator.js';
8
- import 'core-js/modules/es.promise.js';
9
- import { useState, useEffect } from 'react';
10
- import { useRequest } from 'ahooks';
11
- import { useFormContext } from '../../Form/Context/index.js';
12
-
13
- var useOptionReq = function useOptionReq(_ref) {
14
- var manual = _ref.manual,
15
- request = _ref.request,
16
- options = _ref.options,
17
- serviceSearch = _ref.serviceSearch,
18
- showSearch = _ref.showSearch,
19
- propsOnSearch = _ref.onSearch,
20
- _ref$dispatch = _ref.dispatch,
21
- dispatch = _ref$dispatch === void 0 ? {} : _ref$dispatch;
22
- var dispatchManual = dispatch.manual;
23
- var _useFormContext = useFormContext(),
24
- form = _useFormContext.form;
25
- var _useState = useState(),
26
- _useState2 = _slicedToArray(_useState, 2),
27
- data = _useState2[0],
28
- setData = _useState2[1];
29
- var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
30
- var requestParams,
31
- _requestParams$params,
32
- params,
33
- values,
34
- _requestParams$type,
35
- type,
36
- formData,
37
- _args = arguments;
38
- return _regeneratorRuntime.wrap(function _callee$(_context) {
39
- while (1) switch (_context.prev = _context.next) {
40
- case 0:
41
- requestParams = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
42
- _requestParams$params = requestParams.params, params = _requestParams$params === void 0 ? {} : _requestParams$params, values = requestParams.values, _requestParams$type = requestParams.type, type = _requestParams$type === void 0 ? "init" : _requestParams$type;
43
- formData = values || (form === null || form === void 0 ? void 0 : form.getFieldsValue());
44
- if (type === "init") {
45
- setData(undefined);
46
- }
47
- if (!request) {
48
- _context.next = 6;
49
- break;
50
- }
51
- return _context.abrupt("return", request(params, formData));
52
- case 6:
53
- return _context.abrupt("return", Promise.resolve(options));
54
- case 7:
55
- case "end":
56
- return _context.stop();
57
- }
58
- }, _callee);
59
- })), {
60
- manual: dispatchManual === false ? true : manual,
61
- debounceInterval: 300,
62
- onSuccess: function onSuccess(resultData) {
63
- setData(resultData);
64
- }
65
- }),
66
- run = _useRequest.run,
67
- loading = _useRequest.loading,
68
- error = _useRequest.error;
69
- var reload = function reload(_ref3) {
70
- var changeOpts = _ref3.options,
71
- params = _ref3.params;
72
- if (changeOpts) {
73
- return setData(changeOpts);
74
- }
75
- return run({
76
- params: params
77
- });
78
- };
79
- var onSearch = function onSearch(inputValue) {
80
- if (!serviceSearch) {
81
- propsOnSearch === null || propsOnSearch === void 0 || propsOnSearch(inputValue);
82
- return;
83
- }
84
- run({
85
- params: {
86
- inputValue: inputValue
87
- }
88
- });
89
- };
90
- useEffect(function () {
91
- if (options) {
92
- setData(options);
93
- }
94
- }, [options]);
95
- var mathShowSearch = showSearch || serviceSearch;
96
- return {
97
- run: run,
98
- loading: loading,
99
- error: error,
100
- data: data,
101
- onSearch: mathShowSearch ? onSearch : propsOnSearch,
102
- mathShowSearch: showSearch || serviceSearch,
103
- reload: reload
104
- };
105
- };
106
- var useFilterOption = function useFilterOption(_ref4) {
107
- var filterOption = _ref4.filterOption,
108
- serviceSearch = _ref4.serviceSearch;
109
- if (serviceSearch) {
110
- return function () {
111
- return true;
112
- };
113
- }
114
- return filterOption;
115
- };
116
-
117
- export { useFilterOption, useOptionReq };
118
- // powered by hdj