@k-int/stripes-kint-components 5.3.1 → 5.4.0

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 CHANGED
@@ -1,3 +1,11 @@
1
+ # [5.4.0](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.3.1...v5.4.0) (2024-02-29)
2
+
3
+
4
+ ### Features
5
+
6
+ * EditSettingValue: refdata default sort ([9e7f530](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/9e7f5301bb43050ba263b303e0e05462b1268a8a))
7
+ * matchString and highlightString improvements ([83f98e9](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/commit/83f98e9ebc678c3a893504a9959d35f9e1318b7b))
8
+
1
9
  ## [5.3.1](https://gitlab.com/knowledge-integration/folio/stripes-kint-components/compare/v5.3.0...v5.3.1) (2024-01-26)
2
10
 
3
11
 
@@ -37,10 +37,14 @@ const EditSettingValue = props => {
37
37
  if (refdata.length > 0 && refdata.length <= 4) {
38
38
  RefdataComponent = _RefdataButtons.default;
39
39
  }
40
+
41
+ // Adding default sort to refdata object in ascending order by label
42
+ const sortByLabel = (a, b) => a.label.localeCompare(b.label);
43
+ const sortedRefdata = refdata.sort(sortByLabel);
40
44
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
41
45
  "aria-label": fieldLabel,
42
46
  component: RefdataComponent,
43
- dataOptions: refdata,
47
+ dataOptions: sortedRefdata,
44
48
  name: "".concat(input.name, ".value")
45
49
  });
46
50
  case 'Password':
@@ -9,21 +9,37 @@ var _jsxRuntime = require("react/jsx-runtime");
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
10
  const highlightString = function (match, str) {
11
11
  let ignoreNull = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
12
- const [parts, regex] = (0, _matchString.default)(match, str, ignoreNull);
13
- return parts.filter(part => part).map((part, i) => regex.test(part) ? /*#__PURE__*/(0, _jsxRuntime.jsx)("mark", {
14
- children: part
15
- }, i) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
16
- children: part
17
- }, i));
12
+ let simpleSplit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
13
+ const [parts, regex] = (0, _matchString.default)(match, str, ignoreNull, simpleSplit);
14
+ return parts.map((part, i) => {
15
+ // RegExp is stateful, set up a new one to work with
16
+ const immutableRegex = new RegExp(regex);
17
+ if (immutableRegex.exec(part) !== null) {
18
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("mark", {
19
+ children: part
20
+ }, i);
21
+ }
22
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
23
+ children: part
24
+ }, i);
25
+ });
18
26
  };
19
27
  exports.highlightString = highlightString;
20
28
  const boldString = function (match, str) {
21
29
  let ignoreNull = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
22
- const [parts, regex] = (0, _matchString.default)(match, str, ignoreNull);
23
- return parts.filter(part => part).map((part, i) => regex.test(part) ? /*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
24
- children: part
25
- }, i) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
26
- children: part
27
- }, i));
30
+ let simpleSplit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
31
+ const [parts, regex] = (0, _matchString.default)(match, str, ignoreNull, simpleSplit);
32
+ return parts.map((part, i) => {
33
+ // RegExp is stateful, set up a new one to work with
34
+ const immutableRegex = new RegExp(regex);
35
+ if (immutableRegex.exec(part) !== null) {
36
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
37
+ children: part
38
+ }, i);
39
+ }
40
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
41
+ children: part
42
+ }, i);
43
+ });
28
44
  };
29
45
  exports.boldString = boldString;
@@ -7,13 +7,28 @@ exports.default = void 0;
7
7
  var _escapeRegExp = _interopRequireDefault(require("lodash/escapeRegExp"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  const matchString = function (match, str) {
10
+ var _str$split2;
10
11
  let ignoreNull = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
11
- const regex = new RegExp("".concat(match.split(/(\s+)/).filter(h => h.trim()).map(hl => '(' + (0, _escapeRegExp.default)(hl) + ')').join('|')), 'gi');
12
+ let simpleSplit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
13
+ // Simple regex split -- this is default behaviour
14
+ const regexSimple = new RegExp("".concat(match.split(/(\s+)/).filter(h => h.trim()).map(hl => '(' + (0, _escapeRegExp.default)(hl) + ')').join('|')), 'gi');
15
+
16
+ // Split Elivis "The King" Presley into [Elvis, The King, Presley]
17
+ const regex = new RegExp("".concat(match.split(/(?!\B"[^"]*)\s+(?![^"]*"\B)/).filter(h => h.trim()).map(quotedSection => {
18
+ if (quotedSection.charAt(0) === '"' && quotedSection.charAt(quotedSection.length - 1) === '"') {
19
+ return quotedSection.slice(1, quotedSection.length - 1);
20
+ }
21
+ return quotedSection;
22
+ }).map(hl => '(' + (0, _escapeRegExp.default)(hl) + ')').join('|')), 'gi');
12
23
  if (ignoreNull && !match) {
13
24
  const nullRegex = /a^/gi; // Should match nothing
14
25
 
15
26
  return [[str], nullRegex];
16
27
  }
17
- return [str.split(regex), regex];
28
+ if (simpleSplit) {
29
+ var _str$split;
30
+ return [(_str$split = str.split(regexSimple)) === null || _str$split === void 0 ? void 0 : _str$split.filter(s => s && s.trim()), regexSimple];
31
+ }
32
+ return [(_str$split2 = str.split(regex)) === null || _str$split2 === void 0 ? void 0 : _str$split2.filter(s => s && s.trim()), regex];
18
33
  };
19
34
  var _default = exports.default = matchString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k-int/stripes-kint-components",
3
- "version": "5.3.1",
3
+ "version": "5.4.0",
4
4
  "description": "Stripes Component library for K-Int specific applications",
5
5
  "sideEffects": [
6
6
  "*.css"
@@ -36,11 +36,15 @@ const EditSettingValue = (props) => {
36
36
  RefdataComponent = RefdataButtons;
37
37
  }
38
38
 
39
+ // Adding default sort to refdata object in ascending order by label
40
+ const sortByLabel = (a, b) => (a.label.localeCompare(b.label));
41
+ const sortedRefdata = refdata.sort(sortByLabel);
42
+
39
43
  return (
40
44
  <Field
41
45
  aria-label={fieldLabel}
42
46
  component={RefdataComponent}
43
- dataOptions={refdata}
47
+ dataOptions={sortedRefdata}
44
48
  name={`${input.name}.value`}
45
49
  />
46
50
  );
@@ -1,38 +1,54 @@
1
1
  import matchString from './matchString';
2
2
 
3
- const highlightString = (match, str, ignoreNull = true) => {
4
- const [parts, regex] = matchString(match, str, ignoreNull);
3
+ const highlightString = (match, str, ignoreNull = true, simpleSplit = true) => {
4
+ const [parts, regex] = matchString(match, str, ignoreNull, simpleSplit);
5
5
 
6
6
  return (
7
- parts.filter(part => part).map((part, i) => (
8
- regex.test(part) ?
9
- <mark
10
- key={i}
11
- >
12
- {part}
13
- </mark> :
7
+ parts.map((part, i) => {
8
+ // RegExp is stateful, set up a new one to work with
9
+ const immutableRegex = new RegExp(regex);
10
+ if (immutableRegex.exec(part) !== null) {
11
+ return (
12
+ <mark
13
+ key={i}
14
+ >
15
+ {part}
16
+ </mark>
17
+ );
18
+ }
19
+
20
+ return (
14
21
  <span key={i}>
15
22
  {part}
16
23
  </span>
17
- ))
24
+ );
25
+ })
18
26
  );
19
27
  };
20
28
 
21
- const boldString = (match, str, ignoreNull = true) => {
22
- const [parts, regex] = matchString(match, str, ignoreNull);
29
+ const boldString = (match, str, ignoreNull = true, simpleSplit = true) => {
30
+ const [parts, regex] = matchString(match, str, ignoreNull, simpleSplit);
23
31
 
24
32
  return (
25
- parts.filter(part => part).map((part, i) => (
26
- regex.test(part) ?
27
- <strong
28
- key={i}
29
- >
30
- {part}
31
- </strong> :
33
+ parts.map((part, i) => {
34
+ // RegExp is stateful, set up a new one to work with
35
+ const immutableRegex = new RegExp(regex);
36
+ if (immutableRegex.exec(part) !== null) {
37
+ return (
38
+ <strong
39
+ key={i}
40
+ >
41
+ {part}
42
+ </strong>
43
+ );
44
+ }
45
+
46
+ return (
32
47
  <span key={i}>
33
48
  {part}
34
49
  </span>
35
- ))
50
+ );
51
+ })
36
52
  );
37
53
  };
38
54
 
@@ -1,14 +1,35 @@
1
1
  import escapeRegExp from 'lodash/escapeRegExp';
2
2
 
3
- const matchString = (match, str, ignoreNull = true) => {
4
- const regex = new RegExp(`${match.split(/(\s+)/).filter(h => h.trim()).map(hl => '(' + escapeRegExp(hl) + ')').join('|')}`, 'gi');
3
+ const matchString = (match, str, ignoreNull = true, simpleSplit = true) => {
4
+ // Simple regex split -- this is default behaviour
5
+ const regexSimple = new RegExp(`${match.split(/(\s+)/).filter(h => h.trim()).map(hl => '(' + escapeRegExp(hl) + ')').join('|')}`, 'gi');
6
+
7
+ // Split Elivis "The King" Presley into [Elvis, The King, Presley]
8
+ const regex = new RegExp(`${
9
+ match.split(/(?!\B"[^"]*)\s+(?![^"]*"\B)/)
10
+ .filter(h => h.trim())
11
+ .map(quotedSection => {
12
+ if (quotedSection.charAt(0) === '"' && quotedSection.charAt(quotedSection.length - 1) === '"') {
13
+ return quotedSection.slice(1, quotedSection.length - 1);
14
+ }
15
+ return quotedSection;
16
+ })
17
+ .map(hl => '(' + escapeRegExp(hl) + ')')
18
+ .join('|')
19
+ }`,
20
+ 'gi');
21
+
5
22
  if (ignoreNull && !match) {
6
23
  const nullRegex = /a^/gi; // Should match nothing
7
24
 
8
25
  return [[str], nullRegex];
9
26
  }
10
27
 
11
- return [str.split(regex), regex];
28
+ if (simpleSplit) {
29
+ return [str.split(regexSimple)?.filter(s => s && s.trim()), regexSimple];
30
+ }
31
+
32
+ return [str.split(regex)?.filter(s => s && s.trim()), regex];
12
33
  };
13
34
 
14
35
  export default matchString;