@sheinx/hooks 3.8.0-beta.11 → 3.8.0-beta.13
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/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-control/use-form-control.js +12 -3
- package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts +6 -0
- package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +4 -0
- package/cjs/utils/highlight.d.ts.map +1 -1
- package/cjs/utils/highlight.js +24 -11
- package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
- package/esm/components/use-form/use-form-control/use-form-control.js +12 -3
- package/esm/components/use-form/use-form-control/use-form-control.type.d.ts +6 -0
- package/esm/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +4 -0
- package/esm/utils/highlight.d.ts.map +1 -1
- package/esm/utils/highlight.js +24 -10
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,yBAAyB,CAAC;AA4BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;
|
1
|
+
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,yBAAyB,CAAC;AA4BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBA0JpC,CAAC,YAAY,GAAG,EAAE;;;;;EA4DrD"}
|
@@ -57,7 +57,8 @@ function useFormControl(props) {
|
|
57
57
|
defaultValue = props.defaultValue,
|
58
58
|
rules = props.rules,
|
59
59
|
onError = props.onError,
|
60
|
-
getValidateProps = props.getValidateProps
|
60
|
+
getValidateProps = props.getValidateProps,
|
61
|
+
clearToUndefined = props.clearToUndefined;
|
61
62
|
var _useFieldSetConsumer = (0, _fieldsetContext.useFieldSetConsumer)({
|
62
63
|
name: props.name,
|
63
64
|
bind: props.bind
|
@@ -115,7 +116,11 @@ function useFormControl(props) {
|
|
115
116
|
var nextValue = [];
|
116
117
|
name.forEach(function (n, index) {
|
117
118
|
if (_value[index] === undefined && dv[index] !== undefined) {
|
118
|
-
|
119
|
+
if (clearToUndefined) {
|
120
|
+
nextValue[index] = undefined;
|
121
|
+
} else {
|
122
|
+
nextValue[index] = dv[index];
|
123
|
+
}
|
119
124
|
} else {
|
120
125
|
nextValue[index] = _value[index];
|
121
126
|
}
|
@@ -129,7 +134,11 @@ function useFormControl(props) {
|
|
129
134
|
}
|
130
135
|
if (!(0, _shallowEqual.shallowEqual)(_value2, latestInfo.valueState)) {
|
131
136
|
if (_value2 === undefined && defaultValue !== undefined) {
|
132
|
-
|
137
|
+
if (clearToUndefined) {
|
138
|
+
setValueState(undefined);
|
139
|
+
} else {
|
140
|
+
setValueState(defaultValue);
|
141
|
+
}
|
133
142
|
} else {
|
134
143
|
setValueState(_value2);
|
135
144
|
}
|
@@ -32,6 +32,12 @@ export interface BaseFormControlProps<T> {
|
|
32
32
|
* @private 内部属性 for validate
|
33
33
|
*/
|
34
34
|
getValidateProps: (() => ObjectType) | undefined;
|
35
|
+
/**
|
36
|
+
* @en If set to true, the form will not automatically delete the data after the component is uninstalled
|
37
|
+
* @cn 设置为 true 组件后,有defaultValue时,允许undefined作为最终值
|
38
|
+
* @version 3.8.0
|
39
|
+
*/
|
40
|
+
clearToUndefined?: boolean;
|
35
41
|
}
|
36
42
|
export interface FormControlContext {
|
37
43
|
mounted: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-control.type.d.ts","sourceRoot":"","sources":["use-form-control.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB;;;OAGG;IACH,YAAY,EAAE,CAAC,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5D;;;OAGG;IACH,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACnC;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1D;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3B;;OAEG;IACH,gBAAgB,EAAE,CAAC,MAAM,UAAU,CAAC,GAAG,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"use-form-control.type.d.ts","sourceRoot":"","sources":["use-form-control.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB;;;OAGG;IACH,YAAY,EAAE,CAAC,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5D;;;OAGG;IACH,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACnC;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1D;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3B;;OAEG;IACH,gBAAgB,EAAE,CAAC,MAAM,UAAU,CAAC,GAAG,SAAS,CAAC;IAEjD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AAiCA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAmSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BApPnB,MAAM;
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AAiCA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAmSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BApPnB,MAAM;oCAmUD,OAAO,aAAoB,MAAM,IAAI;;6BAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA9RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCAiWvB,MAAM,WAAW,gBAAgB;gCAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCArJpD,MAAM,0BAAyB,qBAAqB;;;;;;oBA2EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;0BApPnB,MAAM;gCAmUD,OAAO,aAAoB,MAAM,IAAI;;yBAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA9RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCAiWvB,MAAM,WAAW,gBAAgB;4BAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BArJpD,MAAM,0BAAyB,qBAAqB;;CA8b9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -339,6 +339,10 @@ var useForm = function useForm(props) {
|
|
339
339
|
Object.keys(context.defaultValues).forEach(function (df) {
|
340
340
|
var latestDefaultValue = getValue(df);
|
341
341
|
if (latestDefaultValue === undefined) {
|
342
|
+
// todo: Form组件传了clearToUndefined时,加入这部分判断?
|
343
|
+
// if(context.value.hasOwnProperty(df) && clearToUndefined){
|
344
|
+
// return;
|
345
|
+
// }
|
342
346
|
setValue(_defineProperty({}, df, context.defaultValues[df]), {
|
343
347
|
validate: false
|
344
348
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["highlight.tsx"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,EAClC,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,MAAM,GACP,EAAE;IACD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,CAAC,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,GAAG,CAAC,
|
1
|
+
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["highlight.tsx"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,EAClC,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,MAAM,GACP,EAAE;IACD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,CAAC,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,GAAG,CAAC,CAkCJ"}
|
package/cjs/utils/highlight.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
5
4
|
value: true
|
6
5
|
});
|
@@ -11,6 +10,12 @@ var _is = require("./is");
|
|
11
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
12
11
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
13
12
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
13
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
16
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
18
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
14
19
|
function getHighlightText(_ref) {
|
15
20
|
var nodeList = _ref.nodeList,
|
16
21
|
searchWords = _ref.searchWords,
|
@@ -19,22 +24,31 @@ function getHighlightText(_ref) {
|
|
19
24
|
if (!enable || !searchWords) {
|
20
25
|
return nodeList;
|
21
26
|
}
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
|
28
|
+
// 递归转换节点
|
29
|
+
var transformNode = function transformNode(node, index) {
|
30
|
+
// 如果是合法的 React 元素
|
31
|
+
if ( /*#__PURE__*/_react.default.isValidElement(node) && node.props && node.props.children) {
|
32
|
+
// 对 children 递归调用 getHighlightText 进行转换
|
33
|
+
var transformedChildren = getHighlightText({
|
34
|
+
nodeList: node.props.children,
|
27
35
|
searchWords: searchWords,
|
28
|
-
highlightClassName: highlightClassName
|
29
|
-
|
36
|
+
highlightClassName: highlightClassName,
|
37
|
+
enable: enable
|
38
|
+
});
|
39
|
+
return /*#__PURE__*/(0, _react.cloneElement)(node, _objectSpread(_objectSpread({}, node.props), {}, {
|
40
|
+
key: index
|
41
|
+
}), transformedChildren);
|
30
42
|
}
|
31
|
-
|
43
|
+
// 如果节点为字符串,则直接高亮替换
|
44
|
+
if (typeof node === 'string') {
|
32
45
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(HighlightText, {
|
33
46
|
textToHighlight: node,
|
34
47
|
searchWords: searchWords,
|
35
48
|
highlightClassName: highlightClassName
|
36
49
|
});
|
37
50
|
}
|
51
|
+
// 其他情况直接返回原节点
|
38
52
|
return node;
|
39
53
|
};
|
40
54
|
return (0, _is.isArray)(nodeList) ? nodeList.map(transformNode) : transformNode(nodeList);
|
@@ -50,8 +64,7 @@ function HighlightText(_ref2) {
|
|
50
64
|
searchWords = searchWords.slice(0, 500);
|
51
65
|
}
|
52
66
|
|
53
|
-
//
|
54
|
-
// 从而在strArr中可以保留匹配文本
|
67
|
+
// 带 capture group 的正则用于 split 保留匹配文本
|
55
68
|
var re = new RegExp("(".concat((0, _string.escapeRegExp)(searchWords), ")"), 'i');
|
56
69
|
var strArr = textToHighlight.split(re);
|
57
70
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,yBAAyB,CAAC;AA4BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;
|
1
|
+
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,yBAAyB,CAAC;AA4BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBA0JpC,CAAC,YAAY,GAAG,EAAE;;;;;EA4DrD"}
|
@@ -48,7 +48,8 @@ export default function useFormControl(props) {
|
|
48
48
|
defaultValue = props.defaultValue,
|
49
49
|
rules = props.rules,
|
50
50
|
onError = props.onError,
|
51
|
-
getValidateProps = props.getValidateProps
|
51
|
+
getValidateProps = props.getValidateProps,
|
52
|
+
clearToUndefined = props.clearToUndefined;
|
52
53
|
var _useFieldSetConsumer = useFieldSetConsumer({
|
53
54
|
name: props.name,
|
54
55
|
bind: props.bind
|
@@ -106,7 +107,11 @@ export default function useFormControl(props) {
|
|
106
107
|
var nextValue = [];
|
107
108
|
name.forEach(function (n, index) {
|
108
109
|
if (_value[index] === undefined && dv[index] !== undefined) {
|
109
|
-
|
110
|
+
if (clearToUndefined) {
|
111
|
+
nextValue[index] = undefined;
|
112
|
+
} else {
|
113
|
+
nextValue[index] = dv[index];
|
114
|
+
}
|
110
115
|
} else {
|
111
116
|
nextValue[index] = _value[index];
|
112
117
|
}
|
@@ -120,7 +125,11 @@ export default function useFormControl(props) {
|
|
120
125
|
}
|
121
126
|
if (!shallowEqual(_value2, latestInfo.valueState)) {
|
122
127
|
if (_value2 === undefined && defaultValue !== undefined) {
|
123
|
-
|
128
|
+
if (clearToUndefined) {
|
129
|
+
setValueState(undefined);
|
130
|
+
} else {
|
131
|
+
setValueState(defaultValue);
|
132
|
+
}
|
124
133
|
} else {
|
125
134
|
setValueState(_value2);
|
126
135
|
}
|
@@ -32,6 +32,12 @@ export interface BaseFormControlProps<T> {
|
|
32
32
|
* @private 内部属性 for validate
|
33
33
|
*/
|
34
34
|
getValidateProps: (() => ObjectType) | undefined;
|
35
|
+
/**
|
36
|
+
* @en If set to true, the form will not automatically delete the data after the component is uninstalled
|
37
|
+
* @cn 设置为 true 组件后,有defaultValue时,允许undefined作为最终值
|
38
|
+
* @version 3.8.0
|
39
|
+
*/
|
40
|
+
clearToUndefined?: boolean;
|
35
41
|
}
|
36
42
|
export interface FormControlContext {
|
37
43
|
mounted: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-control.type.d.ts","sourceRoot":"","sources":["use-form-control.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB;;;OAGG;IACH,YAAY,EAAE,CAAC,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5D;;;OAGG;IACH,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACnC;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1D;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3B;;OAEG;IACH,gBAAgB,EAAE,CAAC,MAAM,UAAU,CAAC,GAAG,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"use-form-control.type.d.ts","sourceRoot":"","sources":["use-form-control.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB;;;OAGG;IACH,YAAY,EAAE,CAAC,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5D;;;OAGG;IACH,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACnC;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1D;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3B;;OAEG;IACH,gBAAgB,EAAE,CAAC,MAAM,UAAU,CAAC,GAAG,SAAS,CAAC;IAEjD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AAiCA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAmSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BApPnB,MAAM;
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AAiCA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAmSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BApPnB,MAAM;oCAmUD,OAAO,aAAoB,MAAM,IAAI;;6BAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA9RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCAiWvB,MAAM,WAAW,gBAAgB;gCAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCArJpD,MAAM,0BAAyB,qBAAqB;;;;;;oBA2EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;0BApPnB,MAAM;gCAmUD,OAAO,aAAoB,MAAM,IAAI;;yBAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA9RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCAiWvB,MAAM,WAAW,gBAAgB;4BAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BArJpD,MAAM,0BAAyB,qBAAqB;;CA8b9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -330,6 +330,10 @@ var useForm = function useForm(props) {
|
|
330
330
|
Object.keys(context.defaultValues).forEach(function (df) {
|
331
331
|
var latestDefaultValue = getValue(df);
|
332
332
|
if (latestDefaultValue === undefined) {
|
333
|
+
// todo: Form组件传了clearToUndefined时,加入这部分判断?
|
334
|
+
// if(context.value.hasOwnProperty(df) && clearToUndefined){
|
335
|
+
// return;
|
336
|
+
// }
|
333
337
|
setValue(_defineProperty({}, df, context.defaultValues[df]), {
|
334
338
|
validate: false
|
335
339
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["highlight.tsx"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,EAClC,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,MAAM,GACP,EAAE;IACD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,CAAC,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,GAAG,CAAC,
|
1
|
+
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["highlight.tsx"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,EAClC,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,MAAM,GACP,EAAE;IACD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,CAAC,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,GAAG,CAAC,CAkCJ"}
|
package/esm/utils/highlight.js
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
1
7
|
import React, { cloneElement } from 'react';
|
2
8
|
import { escapeRegExp } from "./string";
|
3
9
|
import { isArray } from "./is";
|
@@ -11,22 +17,31 @@ export function getHighlightText(_ref) {
|
|
11
17
|
if (!enable || !searchWords) {
|
12
18
|
return nodeList;
|
13
19
|
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
|
21
|
+
// 递归转换节点
|
22
|
+
var transformNode = function transformNode(node, index) {
|
23
|
+
// 如果是合法的 React 元素
|
24
|
+
if ( /*#__PURE__*/React.isValidElement(node) && node.props && node.props.children) {
|
25
|
+
// 对 children 递归调用 getHighlightText 进行转换
|
26
|
+
var transformedChildren = getHighlightText({
|
27
|
+
nodeList: node.props.children,
|
19
28
|
searchWords: searchWords,
|
20
|
-
highlightClassName: highlightClassName
|
21
|
-
|
29
|
+
highlightClassName: highlightClassName,
|
30
|
+
enable: enable
|
31
|
+
});
|
32
|
+
return /*#__PURE__*/cloneElement(node, _objectSpread(_objectSpread({}, node.props), {}, {
|
33
|
+
key: index
|
34
|
+
}), transformedChildren);
|
22
35
|
}
|
23
|
-
|
36
|
+
// 如果节点为字符串,则直接高亮替换
|
37
|
+
if (typeof node === 'string') {
|
24
38
|
return /*#__PURE__*/_jsx(HighlightText, {
|
25
39
|
textToHighlight: node,
|
26
40
|
searchWords: searchWords,
|
27
41
|
highlightClassName: highlightClassName
|
28
42
|
});
|
29
43
|
}
|
44
|
+
// 其他情况直接返回原节点
|
30
45
|
return node;
|
31
46
|
};
|
32
47
|
return isArray(nodeList) ? nodeList.map(transformNode) : transformNode(nodeList);
|
@@ -42,8 +57,7 @@ function HighlightText(_ref2) {
|
|
42
57
|
searchWords = searchWords.slice(0, 500);
|
43
58
|
}
|
44
59
|
|
45
|
-
//
|
46
|
-
// 从而在strArr中可以保留匹配文本
|
60
|
+
// 带 capture group 的正则用于 split 保留匹配文本
|
47
61
|
var re = new RegExp("(".concat(escapeRegExp(searchWords), ")"), 'i');
|
48
62
|
var strArr = textToHighlight.split(re);
|
49
63
|
return /*#__PURE__*/_jsx(_Fragment, {
|