@hw-component/form 1.6.3 → 1.6.4

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.
@@ -1,154 +1,10 @@
1
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
2
  import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
8
- import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
9
- import _defineProperty from '@babel/runtime-corejs3/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
3
  import 'core-js/modules/es.array.map.js';
14
4
  import { useState, useEffect } from 'react';
15
5
  import { itemOpProvider } from '../utils.js';
6
+ import { matchNotFind } from './util.js';
16
7
 
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
- labelInValue = _ref5.labelInValue;
130
- if (labelInValue) {
131
- return value;
132
- }
133
- if (!mode) {
134
- return single({
135
- options: options,
136
- value: value,
137
- noMatchItemRender: noMatchItemRender
138
- });
139
- }
140
- if (mode === "multiple") {
141
- return multiple({
142
- options: options,
143
- value: value,
144
- noMatchItemRender: noMatchItemRender
145
- }, oldVale) || [];
146
- }
147
- return tag({
148
- options: options,
149
- value: value
150
- }, oldVale);
151
- };
152
8
  var useValueChange = function useValueChange(params) {
153
9
  var labelInValue = params.labelInValue,
154
10
  onChange = params.onChange,
@@ -197,9 +53,40 @@ var useValueChange = function useValueChange(params) {
197
53
  return matchNotFind(params, oldVale);
198
54
  });
199
55
  }
200
- }, [value, options, mode, noMatchItemRender, labelInValue]);
56
+ }, [value, options, mode]);
57
+ var itemMaker = function itemMaker(item) {
58
+ var itemVal = item.value,
59
+ label = item.label,
60
+ noMatch = item.noMatch;
61
+ if (noMatch) {
62
+ return {
63
+ value: itemVal,
64
+ label: (noMatchItemRender === null || noMatchItemRender === void 0 ? void 0 : noMatchItemRender({
65
+ value: value
66
+ })) || value
67
+ };
68
+ }
69
+ return {
70
+ value: itemVal,
71
+ label: label
72
+ };
73
+ };
74
+ var valuesMaker = function valuesMaker() {
75
+ if (labelInValue) {
76
+ return val;
77
+ }
78
+ if (!val) {
79
+ return val;
80
+ }
81
+ if (Array.isArray(val)) {
82
+ return val.map(function (item) {
83
+ return itemMaker(item);
84
+ });
85
+ }
86
+ return itemMaker(val);
87
+ };
201
88
  return {
202
- val: val,
89
+ val: valuesMaker(),
203
90
  change: change
204
91
  };
205
92
  };
@@ -0,0 +1,10 @@
1
+ import { OptionType, PartialHSelectProps } from "@/components/Select/modal";
2
+ export declare const matchNotFind: ({ options, value, mode }: PartialHSelectProps, oldVale?: OptionType[]) => any[] | {
3
+ value: any;
4
+ label: any;
5
+ noMatch?: undefined;
6
+ } | {
7
+ value: any;
8
+ label: any;
9
+ noMatch: boolean;
10
+ };
@@ -0,0 +1,138 @@
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 _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
8
+ import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
9
+ import 'core-js/modules/es.array.find-index.js';
10
+ import 'core-js/modules/es.object.to-string.js';
11
+ import 'core-js/modules/web.dom-collections.for-each.js';
12
+ import 'core-js/modules/es.array.map.js';
13
+
14
+ var _excluded = ["index"],
15
+ _excluded2 = ["index"];
16
+ 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; }
17
+ 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; }
18
+ var findNewValInOldVal = function findNewValInOldVal(val, oldVal) {
19
+ if (!oldVal) {
20
+ return -1;
21
+ }
22
+ return oldVal.findIndex(function (item) {
23
+ return item.value === val;
24
+ });
25
+ };
26
+ var sourceDataProvider = function sourceDataProvider(_ref, oldVal) {
27
+ var value = _ref.value;
28
+ var oldData = [];
29
+ var newData = [];
30
+ value.forEach(function (item, i) {
31
+ var index = findNewValInOldVal(item, oldVal);
32
+ if (index === -1) {
33
+ newData.push({
34
+ value: item,
35
+ index: i
36
+ });
37
+ return;
38
+ }
39
+ var newVal = oldVal === null || oldVal === void 0 ? void 0 : oldVal[index];
40
+ oldData.push(_objectSpread(_objectSpread({}, newVal), {}, {
41
+ index: i
42
+ }));
43
+ });
44
+ return {
45
+ oldData: oldData,
46
+ newData: newData
47
+ };
48
+ };
49
+ var single = function single(_ref2) {
50
+ var options = _ref2.options,
51
+ value = _ref2.value;
52
+ var newOptions = options || [];
53
+ var index = newOptions.findIndex(function (item) {
54
+ return item.value === value;
55
+ });
56
+ if (index !== -1) {
57
+ var label = newOptions[index].label;
58
+ return {
59
+ value: value,
60
+ label: label
61
+ };
62
+ }
63
+ return {
64
+ value: value,
65
+ label: value,
66
+ noMatch: true
67
+ };
68
+ };
69
+ var resultProvider = function resultProvider(newData, oldData, value) {
70
+ var newResult = new Array(value.length);
71
+ oldData.forEach(function (item) {
72
+ var index = item.index,
73
+ val = _objectWithoutProperties(item, _excluded);
74
+ newResult[index] = _objectSpread({}, val);
75
+ });
76
+ newData.forEach(function (item) {
77
+ var index = item.index,
78
+ val = _objectWithoutProperties(item, _excluded2);
79
+ newResult[index] = _objectSpread({}, val);
80
+ });
81
+ return newResult;
82
+ };
83
+ var multiple = function multiple(_ref3, oldVal) {
84
+ var options = _ref3.options,
85
+ value = _ref3.value;
86
+ var _sourceDataProvider = sourceDataProvider({
87
+ value: value
88
+ }, oldVal),
89
+ newData = _sourceDataProvider.newData,
90
+ oldData = _sourceDataProvider.oldData;
91
+ var newMatchVal = newData.map(function (item) {
92
+ var itemVal = item.value,
93
+ index = item.index;
94
+ var newItem = single({
95
+ options: options,
96
+ value: itemVal
97
+ });
98
+ return _objectSpread(_objectSpread({}, newItem), {}, {
99
+ index: index
100
+ });
101
+ });
102
+ return resultProvider(newMatchVal, oldData, value);
103
+ };
104
+ var tag = function tag(_ref4, oldVal) {
105
+ var options = _ref4.options,
106
+ value = _ref4.value;
107
+ var _sourceDataProvider2 = sourceDataProvider({
108
+ options: options,
109
+ value: value
110
+ }, oldVal),
111
+ newData = _sourceDataProvider2.newData,
112
+ oldData = _sourceDataProvider2.oldData;
113
+ return resultProvider(newData, oldData, value);
114
+ };
115
+ var matchNotFind = function matchNotFind(_ref5, oldVale) {
116
+ var options = _ref5.options,
117
+ value = _ref5.value,
118
+ mode = _ref5.mode;
119
+ if (!mode) {
120
+ return single({
121
+ options: options,
122
+ value: value
123
+ });
124
+ }
125
+ if (mode === "multiple") {
126
+ return multiple({
127
+ options: options,
128
+ value: value
129
+ }, oldVale) || [];
130
+ }
131
+ return tag({
132
+ options: options,
133
+ value: value
134
+ }, oldVale);
135
+ };
136
+
137
+ export { matchNotFind };
138
+ // powered by hdj
@@ -1,155 +1,11 @@
1
1
  'use strict';
2
2
 
3
- require('core-js/modules/es.object.keys.js');
4
- require('core-js/modules/es.symbol.js');
5
- require('core-js/modules/es.array.filter.js');
6
- require('core-js/modules/es.object.get-own-property-descriptor.js');
7
- require('core-js/modules/es.object.get-own-property-descriptors.js');
8
3
  var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
9
- var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
10
- var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
11
- require('core-js/modules/es.array.find-index.js');
12
- require('core-js/modules/es.object.to-string.js');
13
- require('core-js/modules/web.dom-collections.for-each.js');
14
4
  require('core-js/modules/es.array.map.js');
15
5
  var React = require('react');
16
6
  var utils = require('../utils.js');
7
+ var util = require('./util.js');
17
8
 
18
- var _excluded = ["index"],
19
- _excluded2 = ["index"];
20
- 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; }
21
- 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; }
22
- var single = function single(_ref) {
23
- var options = _ref.options,
24
- value = _ref.value,
25
- noMatchItemRender = _ref.noMatchItemRender;
26
- var newOptions = options || [];
27
- var index = newOptions.findIndex(function (item) {
28
- return item.value === value;
29
- });
30
- if (index !== -1) {
31
- var label = newOptions[index].label;
32
- return {
33
- value: value,
34
- label: label
35
- };
36
- }
37
- return {
38
- value: value,
39
- label: (noMatchItemRender === null || noMatchItemRender === void 0 ? void 0 : noMatchItemRender({
40
- value: value
41
- })) || value
42
- };
43
- };
44
- var findNewValInOldVal = function findNewValInOldVal(val, oldVal) {
45
- if (!oldVal) {
46
- return -1;
47
- }
48
- return oldVal.findIndex(function (item) {
49
- return item.value === val;
50
- });
51
- };
52
- var sourceDataProvider = function sourceDataProvider(_ref2, oldVal) {
53
- _ref2.options;
54
- var value = _ref2.value;
55
- var oldData = [];
56
- var newData = [];
57
- value.forEach(function (item, i) {
58
- var index = findNewValInOldVal(item, oldVal);
59
- if (index === -1) {
60
- newData.push({
61
- value: item,
62
- index: i
63
- });
64
- return;
65
- }
66
- var newVal = oldVal === null || oldVal === void 0 ? void 0 : oldVal[index];
67
- oldData.push(_objectSpread(_objectSpread({}, newVal), {}, {
68
- index: i
69
- }));
70
- });
71
- return {
72
- oldData: oldData,
73
- newData: newData
74
- };
75
- };
76
- var resultProvider = function resultProvider(newData, oldData, value) {
77
- var newResult = new Array(value.length);
78
- oldData.forEach(function (item) {
79
- var index = item.index,
80
- val = _objectWithoutProperties(item, _excluded);
81
- newResult[index] = _objectSpread({}, val);
82
- });
83
- newData.forEach(function (item) {
84
- var index = item.index,
85
- val = _objectWithoutProperties(item, _excluded2);
86
- newResult[index] = _objectSpread({}, val);
87
- });
88
- return newResult;
89
- };
90
- var multiple = function multiple(_ref3, oldVal) {
91
- var options = _ref3.options,
92
- value = _ref3.value,
93
- noMatchItemRender = _ref3.noMatchItemRender;
94
- var _sourceDataProvider = sourceDataProvider({
95
- options: options,
96
- value: value
97
- }, oldVal),
98
- newData = _sourceDataProvider.newData,
99
- oldData = _sourceDataProvider.oldData;
100
- var newMatchVal = newData.map(function (item) {
101
- var itemVal = item.value,
102
- index = item.index;
103
- var newItem = single({
104
- options: options,
105
- value: itemVal,
106
- noMatchItemRender: noMatchItemRender
107
- });
108
- return _objectSpread(_objectSpread({}, newItem), {}, {
109
- index: index
110
- });
111
- });
112
- return resultProvider(newMatchVal, oldData, value);
113
- };
114
- var tag = function tag(_ref4, oldVal) {
115
- var options = _ref4.options,
116
- value = _ref4.value;
117
- var _sourceDataProvider2 = sourceDataProvider({
118
- options: options,
119
- value: value
120
- }, oldVal),
121
- newData = _sourceDataProvider2.newData,
122
- oldData = _sourceDataProvider2.oldData;
123
- return resultProvider(newData, oldData, value);
124
- };
125
- var matchNotFind = function matchNotFind(_ref5, oldVale) {
126
- var options = _ref5.options,
127
- value = _ref5.value,
128
- mode = _ref5.mode,
129
- noMatchItemRender = _ref5.noMatchItemRender,
130
- labelInValue = _ref5.labelInValue;
131
- if (labelInValue) {
132
- return value;
133
- }
134
- if (!mode) {
135
- return single({
136
- options: options,
137
- value: value,
138
- noMatchItemRender: noMatchItemRender
139
- });
140
- }
141
- if (mode === "multiple") {
142
- return multiple({
143
- options: options,
144
- value: value,
145
- noMatchItemRender: noMatchItemRender
146
- }, oldVale) || [];
147
- }
148
- return tag({
149
- options: options,
150
- value: value
151
- }, oldVale);
152
- };
153
9
  var useValueChange = function useValueChange(params) {
154
10
  var labelInValue = params.labelInValue,
155
11
  onChange = params.onChange,
@@ -195,12 +51,43 @@ var useValueChange = function useValueChange(params) {
195
51
  }
196
52
  if (options) {
197
53
  setVal(function (oldVale) {
198
- return matchNotFind(params, oldVale);
54
+ return util.matchNotFind(params, oldVale);
55
+ });
56
+ }
57
+ }, [value, options, mode]);
58
+ var itemMaker = function itemMaker(item) {
59
+ var itemVal = item.value,
60
+ label = item.label,
61
+ noMatch = item.noMatch;
62
+ if (noMatch) {
63
+ return {
64
+ value: itemVal,
65
+ label: (noMatchItemRender === null || noMatchItemRender === void 0 ? void 0 : noMatchItemRender({
66
+ value: value
67
+ })) || value
68
+ };
69
+ }
70
+ return {
71
+ value: itemVal,
72
+ label: label
73
+ };
74
+ };
75
+ var valuesMaker = function valuesMaker() {
76
+ if (labelInValue) {
77
+ return val;
78
+ }
79
+ if (!val) {
80
+ return val;
81
+ }
82
+ if (Array.isArray(val)) {
83
+ return val.map(function (item) {
84
+ return itemMaker(item);
199
85
  });
200
86
  }
201
- }, [value, options, mode, noMatchItemRender, labelInValue]);
87
+ return itemMaker(val);
88
+ };
202
89
  return {
203
- val: val,
90
+ val: valuesMaker(),
204
91
  change: change
205
92
  };
206
93
  };
@@ -0,0 +1,10 @@
1
+ import { OptionType, PartialHSelectProps } from "@/components/Select/modal";
2
+ export declare const matchNotFind: ({ options, value, mode }: PartialHSelectProps, oldVale?: OptionType[]) => any[] | {
3
+ value: any;
4
+ label: any;
5
+ noMatch?: undefined;
6
+ } | {
7
+ value: any;
8
+ label: any;
9
+ noMatch: boolean;
10
+ };
@@ -0,0 +1,139 @@
1
+ 'use strict';
2
+
3
+ require('core-js/modules/es.object.keys.js');
4
+ require('core-js/modules/es.symbol.js');
5
+ require('core-js/modules/es.array.filter.js');
6
+ require('core-js/modules/es.object.get-own-property-descriptor.js');
7
+ require('core-js/modules/es.object.get-own-property-descriptors.js');
8
+ var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
9
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
10
+ require('core-js/modules/es.array.find-index.js');
11
+ require('core-js/modules/es.object.to-string.js');
12
+ require('core-js/modules/web.dom-collections.for-each.js');
13
+ require('core-js/modules/es.array.map.js');
14
+
15
+ var _excluded = ["index"],
16
+ _excluded2 = ["index"];
17
+ 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; }
18
+ 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; }
19
+ var findNewValInOldVal = function findNewValInOldVal(val, oldVal) {
20
+ if (!oldVal) {
21
+ return -1;
22
+ }
23
+ return oldVal.findIndex(function (item) {
24
+ return item.value === val;
25
+ });
26
+ };
27
+ var sourceDataProvider = function sourceDataProvider(_ref, oldVal) {
28
+ var value = _ref.value;
29
+ var oldData = [];
30
+ var newData = [];
31
+ value.forEach(function (item, i) {
32
+ var index = findNewValInOldVal(item, oldVal);
33
+ if (index === -1) {
34
+ newData.push({
35
+ value: item,
36
+ index: i
37
+ });
38
+ return;
39
+ }
40
+ var newVal = oldVal === null || oldVal === void 0 ? void 0 : oldVal[index];
41
+ oldData.push(_objectSpread(_objectSpread({}, newVal), {}, {
42
+ index: i
43
+ }));
44
+ });
45
+ return {
46
+ oldData: oldData,
47
+ newData: newData
48
+ };
49
+ };
50
+ var single = function single(_ref2) {
51
+ var options = _ref2.options,
52
+ value = _ref2.value;
53
+ var newOptions = options || [];
54
+ var index = newOptions.findIndex(function (item) {
55
+ return item.value === value;
56
+ });
57
+ if (index !== -1) {
58
+ var label = newOptions[index].label;
59
+ return {
60
+ value: value,
61
+ label: label
62
+ };
63
+ }
64
+ return {
65
+ value: value,
66
+ label: value,
67
+ noMatch: true
68
+ };
69
+ };
70
+ var resultProvider = function resultProvider(newData, oldData, value) {
71
+ var newResult = new Array(value.length);
72
+ oldData.forEach(function (item) {
73
+ var index = item.index,
74
+ val = _objectWithoutProperties(item, _excluded);
75
+ newResult[index] = _objectSpread({}, val);
76
+ });
77
+ newData.forEach(function (item) {
78
+ var index = item.index,
79
+ val = _objectWithoutProperties(item, _excluded2);
80
+ newResult[index] = _objectSpread({}, val);
81
+ });
82
+ return newResult;
83
+ };
84
+ var multiple = function multiple(_ref3, oldVal) {
85
+ var options = _ref3.options,
86
+ value = _ref3.value;
87
+ var _sourceDataProvider = sourceDataProvider({
88
+ value: value
89
+ }, oldVal),
90
+ newData = _sourceDataProvider.newData,
91
+ oldData = _sourceDataProvider.oldData;
92
+ var newMatchVal = newData.map(function (item) {
93
+ var itemVal = item.value,
94
+ index = item.index;
95
+ var newItem = single({
96
+ options: options,
97
+ value: itemVal
98
+ });
99
+ return _objectSpread(_objectSpread({}, newItem), {}, {
100
+ index: index
101
+ });
102
+ });
103
+ return resultProvider(newMatchVal, oldData, value);
104
+ };
105
+ var tag = function tag(_ref4, oldVal) {
106
+ var options = _ref4.options,
107
+ value = _ref4.value;
108
+ var _sourceDataProvider2 = sourceDataProvider({
109
+ options: options,
110
+ value: value
111
+ }, oldVal),
112
+ newData = _sourceDataProvider2.newData,
113
+ oldData = _sourceDataProvider2.oldData;
114
+ return resultProvider(newData, oldData, value);
115
+ };
116
+ var matchNotFind = function matchNotFind(_ref5, oldVale) {
117
+ var options = _ref5.options,
118
+ value = _ref5.value,
119
+ mode = _ref5.mode;
120
+ if (!mode) {
121
+ return single({
122
+ options: options,
123
+ value: value
124
+ });
125
+ }
126
+ if (mode === "multiple") {
127
+ return multiple({
128
+ options: options,
129
+ value: value
130
+ }, oldVale) || [];
131
+ }
132
+ return tag({
133
+ options: options,
134
+ value: value
135
+ }, oldVale);
136
+ };
137
+
138
+ exports.matchNotFind = matchNotFind;
139
+ // powered by h
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,116 +1,9 @@
1
1
  import type {
2
- OptionType,
3
2
  PartialHSelectProps,
4
3
  } from "@/components/Select/modal";
5
4
  import { useEffect, useState } from "react";
6
- import type { FilterDataModal } from "@/components/Select/modal";
7
5
  import { itemOpProvider } from "../utils";
8
-
9
- const single = ({ options, value, noMatchItemRender }: PartialHSelectProps) => {
10
- const newOptions = options || [];
11
- const index = newOptions.findIndex((item) => {
12
- return item.value === value;
13
- });
14
- if (index !== -1) {
15
- const { label } = newOptions[index];
16
- return {
17
- value,
18
- label,
19
- };
20
- }
21
- return {
22
- value,
23
- label: noMatchItemRender?.({ value }) || value,
24
- };
25
- }; //单选模式
26
- const findNewValInOldVal = (val, oldVal?: any[]) => {
27
- if (!oldVal) {
28
- return -1;
29
- }
30
- return oldVal.findIndex((item) => {
31
- return item.value === val;
32
- });
33
- }; //查询新增的 value
34
- const sourceDataProvider = (
35
- { options, value }: PartialHSelectProps,
36
- oldVal?: any[]
37
- ) => {
38
- const oldData: FilterDataModal[] = [];
39
- const newData: FilterDataModal[] = [];
40
- value.forEach((item, i) => {
41
- const index = findNewValInOldVal(item, oldVal);
42
- if (index === -1) {
43
- newData.push({
44
- value: item,
45
- index: i,
46
- });
47
- return;
48
- }
49
- const newVal = oldVal?.[index];
50
- oldData.push({
51
- ...newVal,
52
- index: i,
53
- });
54
- });
55
- return {
56
- oldData,
57
- newData,
58
- };
59
- }; //创建新旧数据
60
- const resultProvider = (
61
- newData: FilterDataModal[],
62
- oldData: FilterDataModal[],
63
- value: any[]
64
- ) => {
65
- const newResult = new Array(value.length);
66
- oldData.forEach((item) => {
67
- const { index, ...val } = item;
68
- newResult[index] = {
69
- ...val,
70
- };
71
- });
72
- newData.forEach((item) => {
73
- const { index, ...val } = item;
74
- newResult[index] = {
75
- ...val,
76
- };
77
- });
78
- return newResult;
79
- };
80
- const multiple = (
81
- { options, value, noMatchItemRender }: PartialHSelectProps,
82
- oldVal?: any[]
83
- ) => {
84
- const { newData, oldData } = sourceDataProvider({ options, value }, oldVal);
85
- const newMatchVal = newData.map((item) => {
86
- const { value: itemVal, index } = item;
87
- const newItem = single({ options, value: itemVal, noMatchItemRender });
88
- return {
89
- ...newItem,
90
- index,
91
- };
92
- });
93
- return resultProvider(newMatchVal, oldData, value);
94
- }; //多选
95
- const tag = ({ options, value }: PartialHSelectProps, oldVal?: any[]) => {
96
- const { newData, oldData } = sourceDataProvider({ options, value }, oldVal);
97
- return resultProvider(newData, oldData, value);
98
- }; //tags模式
99
- const matchNotFind = (
100
- { options, value, mode, noMatchItemRender ,labelInValue}: PartialHSelectProps,
101
- oldVale?: OptionType[]
102
- ) => {
103
- if (labelInValue){
104
- return value;
105
- }
106
- if (!mode) {
107
- return single({ options, value, noMatchItemRender });
108
- }
109
- if (mode === "multiple") {
110
- return multiple({ options, value, noMatchItemRender }, oldVale) || [];
111
- }
112
- return tag({ options, value }, oldVale);
113
- }; //不匹配
6
+ import {matchNotFind} from './util'
114
7
  export const useValueChange = (params: PartialHSelectProps) => {
115
8
  const {
116
9
  labelInValue,
@@ -158,9 +51,36 @@ export const useValueChange = (params: PartialHSelectProps) => {
158
51
  return matchNotFind(params, oldVale);
159
52
  });
160
53
  }
161
- }, [value, options, mode, noMatchItemRender,labelInValue]);
54
+ }, [value, options, mode]);
55
+ const itemMaker=(item)=>{
56
+ const {value:itemVal,label,noMatch}=item;
57
+ if (noMatch){
58
+ return {
59
+ value:itemVal,
60
+ label: noMatchItemRender?.({ value }) || value,
61
+ }
62
+ }
63
+ return {
64
+ value:itemVal,
65
+ label
66
+ }
67
+ }
68
+ const valuesMaker=()=>{
69
+ if (labelInValue){
70
+ return val;
71
+ }
72
+ if (!val){
73
+ return val;
74
+ }
75
+ if (Array.isArray(val)){
76
+ return val.map((item)=>{
77
+ return itemMaker(item);
78
+ })
79
+ }
80
+ return itemMaker(val);
81
+ }
162
82
  return {
163
- val,
83
+ val:valuesMaker(),
164
84
  change,
165
85
  };
166
86
  };
@@ -0,0 +1,109 @@
1
+ import {FilterDataModal, OptionType, PartialHSelectProps} from "@/components/Select/modal";
2
+
3
+ const findNewValInOldVal = (val, oldVal?: any[]) => {
4
+ if (!oldVal) {
5
+ return -1;
6
+ }
7
+ return oldVal.findIndex((item) => {
8
+ return item.value === val;
9
+ });
10
+ }; //查询新增的 value
11
+
12
+ const sourceDataProvider = (
13
+ { value }: PartialHSelectProps,
14
+ oldVal?: any[]
15
+ ) => {
16
+ const oldData: FilterDataModal[] = [];
17
+ const newData: FilterDataModal[] = [];
18
+ value.forEach((item, i) => {
19
+ const index = findNewValInOldVal(item, oldVal);
20
+ if (index === -1) {
21
+ newData.push({
22
+ value: item,
23
+ index: i,
24
+ });
25
+ return;
26
+ }
27
+ const newVal = oldVal?.[index];
28
+ oldData.push({
29
+ ...newVal,
30
+ index: i,
31
+ });
32
+ });
33
+ return {
34
+ oldData,
35
+ newData,
36
+ };
37
+ }; //创建新旧数据
38
+
39
+
40
+ const single = ({ options, value }: PartialHSelectProps) => {
41
+ const newOptions = options || [];
42
+ const index = newOptions.findIndex((item) => {
43
+ return item.value === value;
44
+ });
45
+ if (index !== -1) {
46
+ const { label } = newOptions[index];
47
+ return {
48
+ value,
49
+ label,
50
+ };
51
+ }
52
+ return {
53
+ value,
54
+ label:value,
55
+ noMatch:true
56
+ };
57
+ }; //单选模式
58
+ const resultProvider = (
59
+ newData: FilterDataModal[],
60
+ oldData: FilterDataModal[],
61
+ value: any[]
62
+ ) => {
63
+ const newResult = new Array(value.length);
64
+ oldData.forEach((item) => {
65
+ const { index, ...val } = item;
66
+ newResult[index] = {
67
+ ...val,
68
+ };
69
+ });
70
+ newData.forEach((item) => {
71
+ const { index, ...val } = item;
72
+ newResult[index] = {
73
+ ...val,
74
+ };
75
+ });
76
+ return newResult;
77
+ };
78
+ const multiple = (
79
+ { options, value }: PartialHSelectProps,
80
+ oldVal?: any[]
81
+ ) => {
82
+ const { newData, oldData } = sourceDataProvider({ value }, oldVal);
83
+ const newMatchVal = newData.map((item) => {
84
+ const { value: itemVal, index } = item;
85
+ const newItem = single({ options, value: itemVal });
86
+ return {
87
+ ...newItem,
88
+ index,
89
+ };
90
+ });
91
+ return resultProvider(newMatchVal, oldData, value);
92
+ }; //多选
93
+
94
+ const tag = ({ options, value }: PartialHSelectProps, oldVal?: any[]) => {
95
+ const { newData, oldData } = sourceDataProvider({ options, value }, oldVal);
96
+ return resultProvider(newData, oldData, value);
97
+ }; //tags模式
98
+ export const matchNotFind = (
99
+ { options, value, mode }: PartialHSelectProps,
100
+ oldVale?: OptionType[]
101
+ ) => {
102
+ if (!mode) {
103
+ return single({ options, value });
104
+ }
105
+ if (mode === "multiple") {
106
+ return multiple({ options, value }, oldVale) || [];
107
+ }
108
+ return tag({ options, value }, oldVale);
109
+ }; //不匹配
@@ -24,16 +24,6 @@ const Test3 = ({ value, onChange }) => {
24
24
  );
25
25
  };
26
26
  const formData = (options) => {
27
- const op = [
28
- {
29
- key: 1,
30
- value: "是",
31
- },
32
- {
33
- key: 0,
34
- value: "否",
35
- },
36
- ];
37
27
  return [
38
28
  {
39
29
  label: "12321",
@@ -45,7 +35,7 @@ const formData = (options) => {
45
35
  },
46
36
  },
47
37
  {
48
- label: "测试12312",
38
+ label: "下拉",
49
39
  className: "hdjd",
50
40
  type: "select",
51
41
  name: "test321",
@@ -7,7 +7,7 @@ export default () => {
7
7
  <Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
8
8
  <HSelect
9
9
  options={[{ label: "测试", value: 1 }]}
10
- value={100}
10
+ value={1}
11
11
  placeholder="基础"
12
12
  allowClear={true}
13
13
  />
@@ -18,7 +18,7 @@ export default () => {
18
18
  { name: "测试2", value: 20, userId: 112321 },
19
19
  ]}
20
20
  placeholder="多选"
21
- value={selectVal}
21
+ value={[10,20]}
22
22
  onChange={(val, option) => {
23
23
  setSelectVal(val);
24
24
  }}