@hi-ui/highlighter 4.1.1 → 4.1.2
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/CHANGELOG.md +6 -0
- package/lib/cjs/Highlighter.js +8 -1
- package/lib/esm/Highlighter.js +8 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @hi-ui/highlighter
|
|
2
2
|
|
|
3
|
+
## 4.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3179](https://github.com/XiaoMi/hiui/pull/3179) [`7bf0630`](https://github.com/XiaoMi/hiui/commit/7bf063053a73923af41c33370c31371325206276) Thanks [@fcppddl](https://github.com/fcppddl)! - fix(highlighter): 修复 CheckSelect 搜索模式下搜索(时报错(#3178)
|
|
8
|
+
|
|
3
9
|
## 4.1.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/lib/cjs/Highlighter.js
CHANGED
|
@@ -24,6 +24,10 @@ function _interopDefaultCompat(e) {
|
|
|
24
24
|
}
|
|
25
25
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
26
26
|
var HIGHLIGHTER_PREFIX = classname.getPrefixCls('highlighter');
|
|
27
|
+
var addGlobalFlag = function addGlobalFlag(regex) {
|
|
28
|
+
var newFlags = regex.flags.includes('g') ? regex.flags : regex.flags + 'g';
|
|
29
|
+
return new RegExp(regex.source, newFlags);
|
|
30
|
+
};
|
|
27
31
|
/**
|
|
28
32
|
* 高亮文本内容
|
|
29
33
|
*/
|
|
@@ -43,7 +47,10 @@ var Highlighter = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
43
47
|
if (typeof children !== 'string') return children;
|
|
44
48
|
// 支持多个匹配高亮
|
|
45
49
|
var parts = children.split(keyword);
|
|
46
|
-
var matches
|
|
50
|
+
var matches;
|
|
51
|
+
if (keyword instanceof RegExp) {
|
|
52
|
+
matches = children.match(addGlobalFlag(keyword));
|
|
53
|
+
}
|
|
47
54
|
// 未匹配到
|
|
48
55
|
if (parts.length < 2) return children;
|
|
49
56
|
var lastPart = parts.pop();
|
package/lib/esm/Highlighter.js
CHANGED
|
@@ -12,6 +12,10 @@ import React, { forwardRef, useRef } from 'react';
|
|
|
12
12
|
import { getPrefixCls, cx } from '@hi-ui/classname';
|
|
13
13
|
import { __DEV__ } from '@hi-ui/env';
|
|
14
14
|
var HIGHLIGHTER_PREFIX = getPrefixCls('highlighter');
|
|
15
|
+
var addGlobalFlag = function addGlobalFlag(regex) {
|
|
16
|
+
var newFlags = regex.flags.includes('g') ? regex.flags : regex.flags + 'g';
|
|
17
|
+
return new RegExp(regex.source, newFlags);
|
|
18
|
+
};
|
|
15
19
|
/**
|
|
16
20
|
* 高亮文本内容
|
|
17
21
|
*/
|
|
@@ -31,7 +35,10 @@ var Highlighter = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
31
35
|
if (typeof children !== 'string') return children;
|
|
32
36
|
// 支持多个匹配高亮
|
|
33
37
|
var parts = children.split(keyword);
|
|
34
|
-
var matches
|
|
38
|
+
var matches;
|
|
39
|
+
if (keyword instanceof RegExp) {
|
|
40
|
+
matches = children.match(addGlobalFlag(keyword));
|
|
41
|
+
}
|
|
35
42
|
// 未匹配到
|
|
36
43
|
if (parts.length < 2) return children;
|
|
37
44
|
var lastPart = parts.pop();
|