@pallasoft/ps-table-components 1.7.1 → 1.8.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.
@@ -0,0 +1,6 @@
1
+ export declare const PsTableSearchConfig: {
2
+ readonly currencySymbols: RegExp;
3
+ readonly diacritics: RegExp;
4
+ readonly thousandsSeparator: RegExp;
5
+ readonly whitespace: RegExp;
6
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsTableSearchConfig = void 0;
4
+ exports.PsTableSearchConfig = {
5
+ currencySymbols: /[$€£¥]/g,
6
+ diacritics: /[̀-ͯ]/g,
7
+ thousandsSeparator: /(\d),(?=\d{3}\b)/g,
8
+ whitespace: /\s+/g,
9
+ };
package/dist/index.d.ts CHANGED
@@ -9,3 +9,4 @@ export * from './interfaces/table-query';
9
9
  export * from './interfaces/table-row-action';
10
10
  export * from './interfaces/table-sort';
11
11
  export * from './services/ps-table-query-service';
12
+ export * from './services/ps-table-search-service';
package/dist/index.js CHANGED
@@ -25,3 +25,4 @@ __exportStar(require("./interfaces/table-query"), exports);
25
25
  __exportStar(require("./interfaces/table-row-action"), exports);
26
26
  __exportStar(require("./interfaces/table-sort"), exports);
27
27
  __exportStar(require("./services/ps-table-query-service"), exports);
28
+ __exportStar(require("./services/ps-table-search-service"), exports);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PsTableQueryService = void 0;
4
4
  const table_filter_kind_1 = require("../constants/table-filter-kind");
5
+ const ps_table_search_service_1 = require("./ps-table-search-service");
5
6
  class PsTableQueryService {
6
7
  static isActive(value) {
7
8
  if (!value)
@@ -39,8 +40,7 @@ class PsTableQueryService {
39
40
  return true;
40
41
  }
41
42
  static apply(rows, columns, filters, search, getSearchText, sort) {
42
- const query = search.trim().toLowerCase();
43
- const filtered = rows.filter((row) => (query === '' || !getSearchText || getSearchText(row).toLowerCase().includes(query)) &&
43
+ const filtered = rows.filter((row) => (!getSearchText || ps_table_search_service_1.PsTableSearchService.matches(getSearchText(row), search)) &&
44
44
  columns.every((column) => PsTableQueryService.matchesFilter(row, column, filters[column.id] ? filters[column.id] : {})));
45
45
  const sortColumn = sort ? columns.find((column) => column.id === sort.columnId) : undefined;
46
46
  if (!sort || !sortColumn || !sortColumn.sortValue)
@@ -0,0 +1,5 @@
1
+ export declare class PsTableSearchService {
2
+ static normalise(value: string): string;
3
+ static tokens(query: string): string[];
4
+ static matches(text: string, query: string): boolean;
5
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsTableSearchService = void 0;
4
+ const ps_table_search_config_1 = require("../constants/ps-table-search-config");
5
+ class PsTableSearchService {
6
+ static normalise(value) {
7
+ return value
8
+ .normalize('NFD')
9
+ .replace(ps_table_search_config_1.PsTableSearchConfig.diacritics, '')
10
+ .toLowerCase()
11
+ .replace(ps_table_search_config_1.PsTableSearchConfig.thousandsSeparator, '$1')
12
+ .replace(ps_table_search_config_1.PsTableSearchConfig.currencySymbols, ' ')
13
+ .replace(ps_table_search_config_1.PsTableSearchConfig.whitespace, ' ')
14
+ .trim();
15
+ }
16
+ static tokens(query) {
17
+ const normalised = PsTableSearchService.normalise(query);
18
+ return normalised === '' ? [] : normalised.split(' ');
19
+ }
20
+ static matches(text, query) {
21
+ const tokens = PsTableSearchService.tokens(query);
22
+ if (tokens.length === 0)
23
+ return true;
24
+ const haystack = PsTableSearchService.normalise(text);
25
+ return tokens.every((token) => haystack.includes(token));
26
+ }
27
+ }
28
+ exports.PsTableSearchService = PsTableSearchService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-table-components",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -68,7 +68,7 @@
68
68
  "url": "git+https://github.com/pallasoft/ps-table-components.git"
69
69
  },
70
70
  "dependencies": {
71
- "@pallasoft/ps-core-components": "^2.3.0",
71
+ "@pallasoft/ps-core-components": "^2.3.1",
72
72
  "@pallasoft/ps-design-system": "^1.3.0",
73
73
  "@pallasoft/ps-icons": "^1.5.0",
74
74
  "@pallasoft/ps-input-components": "^1.9.0",