@sheinx/hooks 3.7.6-beta.1 → 3.7.6-beta.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.
@@ -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,CA8BJ"}
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"}
@@ -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
- var transformNode = function transformNode(node) {
23
- var _node$props;
24
- if (node && typeof ((_node$props = node.props) === null || _node$props === void 0 ? void 0 : _node$props.children) === 'string') {
25
- return /*#__PURE__*/(0, _react.cloneElement)(node, undefined, /*#__PURE__*/(0, _jsxRuntime.jsx)(HighlightText, {
26
- textToHighlight: node.props.children,
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
- if (node && typeof node === 'string') {
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
- // 注意这里的括号,这里使用了带capture group功能的正则,来split字符串
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":"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,CA8BJ"}
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"}
@@ -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
- var transformNode = function transformNode(node) {
15
- var _node$props;
16
- if (node && typeof ((_node$props = node.props) === null || _node$props === void 0 ? void 0 : _node$props.children) === 'string') {
17
- return /*#__PURE__*/cloneElement(node, undefined, /*#__PURE__*/_jsx(HighlightText, {
18
- textToHighlight: node.props.children,
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
- if (node && typeof node === 'string') {
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
- // 注意这里的括号,这里使用了带capture group功能的正则,来split字符串
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, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.7.6-beta.1",
3
+ "version": "3.7.6-beta.2",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",