@pallasoft/ps-table-components 1.7.0 → 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.
@@ -13,6 +13,6 @@ const PsTableToolbar = ({ actions, columns, filters, isSearchable, onClearFilter
13
13
  const filterableColumns = columns.filter((column) => column.filter);
14
14
  const zIndex = (0, ps_core_components_1.usePsLayerZIndex)(ps_design_system_1.PallasoftZIndex.Dropdown);
15
15
  const activeCount = filterableColumns.filter((column) => ps_table_query_service_1.PsTableQueryService.isActive(filters[column.id])).length;
16
- return ((0, jsx_runtime_1.jsxs)("div", { className: 'flex flex-wrap items-center gap-2', children: [isSearchable ? ((0, jsx_runtime_1.jsxs)("label", { className: 'relative basis-full sm:min-w-[12rem] sm:flex-1 sm:basis-auto sm:max-w-xs', children: [(0, jsx_runtime_1.jsx)("span", { className: 'sr-only', children: searchPlaceholder }), (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'pointer-events-none absolute left-3.5 top-1/2 h-4 w-4 -translate-y-1/2 text-ink/45', iconKey: ps_icons_1.PsIconKey.Search }), (0, jsx_runtime_1.jsx)("input", { className: 'ps-input-control ps-focus-ring min-h-10 rounded-full pl-10 text-sm', onChange: (event) => onSearchChange(event.target.value), placeholder: searchPlaceholder, type: 'search', value: search })] })) : null, filterableColumns.length > 0 ? ((0, jsx_runtime_1.jsxs)(react_aria_components_1.DialogTrigger, { children: [(0, jsx_runtime_1.jsxs)(react_aria_components_1.Button, { className: toolbarButtonClassName, children: [(0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4', iconKey: ps_icons_1.PsIconKey.Filter }), (0, jsx_runtime_1.jsx)("span", { className: 'sr-only sm:not-sr-only', children: "Filters" }), activeCount > 0 ? ((0, jsx_runtime_1.jsx)("span", { className: 'inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-xs font-semibold text-[color:var(--ps-color-primary-contrast)]', children: activeCount })) : null] }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Popover, { className: 'ps-floating-panel ps-scrollbar max-h-[min(34rem,80vh)] w-[min(22rem,calc(100vw-2rem))] overflow-y-auto outline-none', offset: 6, placement: 'bottom start', style: { zIndex }, children: (0, jsx_runtime_1.jsx)(react_aria_components_1.Dialog, { "aria-label": 'Filters', className: 'flex flex-col gap-4 p-4 outline-none', children: (0, jsx_runtime_1.jsxs)(ps_core_components_1.PsLayer, { zIndex: zIndex, children: [filterableColumns.map((column) => ((0, jsx_runtime_1.jsx)(ps_table_filter_field_1.PsTableFilterField, { kind: column.filter ? column.filter.kind : 'text', label: column.label, onChange: (value) => onFilterChange(column.id, value), options: ps_table_query_service_1.PsTableQueryService.options(rows, column), value: filters[column.id] ? filters[column.id] : {} }, column.id))), (0, jsx_runtime_1.jsx)("div", { className: 'flex justify-end border-t border-line pt-3', children: (0, jsx_runtime_1.jsx)("button", { className: 'ps-focus-ring rounded-lg px-2 py-1 text-sm font-semibold text-ink/65 hover:text-ink disabled:opacity-40', disabled: activeCount === 0, onClick: onClearFilters, type: 'button', children: "Clear all" }) })] }) }) })] })) : null, activeCount > 0 ? ((0, jsx_runtime_1.jsx)("button", { className: ps_design_system_1.PallasoftClassNameService.merge('ps-focus-ring rounded-full px-3 py-2 text-sm font-semibold text-ink/65 hover:text-ink'), onClick: onClearFilters, type: 'button', children: "Clear filters" })) : null, actions ? (0, jsx_runtime_1.jsx)("div", { className: 'ml-auto flex items-center gap-2', children: actions }) : null] }));
16
+ return ((0, jsx_runtime_1.jsxs)("div", { className: 'flex flex-wrap items-center gap-2', children: [isSearchable ? ((0, jsx_runtime_1.jsxs)("label", { className: 'relative basis-full sm:min-w-[12rem] sm:flex-1 sm:basis-auto sm:max-w-xs', children: [(0, jsx_runtime_1.jsx)("span", { className: 'sr-only', children: searchPlaceholder }), (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'pointer-events-none absolute left-3.5 top-1/2 h-4 w-4 -translate-y-1/2 text-ink/45', iconKey: ps_icons_1.PsIconKey.Search }), (0, jsx_runtime_1.jsx)("input", { className: 'ps-input-control ps-focus-ring min-h-10 rounded-full pl-10 text-sm', onChange: (event) => onSearchChange(event.target.value), placeholder: searchPlaceholder, type: 'search', value: search })] })) : null, filterableColumns.length > 0 ? ((0, jsx_runtime_1.jsxs)(react_aria_components_1.DialogTrigger, { children: [(0, jsx_runtime_1.jsxs)(react_aria_components_1.Button, { className: toolbarButtonClassName, children: [(0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4', iconKey: ps_icons_1.PsIconKey.Filter }), (0, jsx_runtime_1.jsx)("span", { className: 'sr-only sm:not-sr-only', children: "Filters" }), activeCount > 0 ? ((0, jsx_runtime_1.jsx)("span", { className: 'inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-xs font-semibold text-[color:var(--ps-color-primary-contrast)]', children: activeCount })) : null] }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Popover, { className: 'ps-floating-panel ps-scrollbar max-h-[min(34rem,80vh)] w-[min(22rem,calc(100vw-2rem))] overflow-y-auto outline-none', offset: 6, placement: 'bottom start', style: { zIndex }, children: (0, jsx_runtime_1.jsx)(react_aria_components_1.Dialog, { "aria-label": 'Filters', className: 'flex flex-col gap-4 p-4 outline-none', children: (0, jsx_runtime_1.jsxs)(ps_core_components_1.PsLayer, { zIndex: zIndex, children: [filterableColumns.map((column) => ((0, jsx_runtime_1.jsx)(ps_table_filter_field_1.PsTableFilterField, { kind: column.filter ? column.filter.kind : 'text', label: column.label, onChange: (value) => onFilterChange(column.id, value), options: ps_table_query_service_1.PsTableQueryService.options(rows, column), value: filters[column.id] ? filters[column.id] : {} }, column.id))), (0, jsx_runtime_1.jsx)("div", { className: 'flex justify-end border-t border-line pt-3', children: (0, jsx_runtime_1.jsx)("button", { className: 'ps-focus-ring rounded-lg px-2 py-1 text-sm font-semibold text-ink/65 hover:text-ink disabled:opacity-40', disabled: activeCount === 0, onClick: onClearFilters, type: 'button', children: "Clear all" }) })] }) }) })] })) : null, activeCount > 0 ? ((0, jsx_runtime_1.jsx)("button", { className: ps_design_system_1.PallasoftClassNameService.merge('ps-focus-ring rounded-full px-3 py-2 text-sm font-semibold text-ink/65 hover:text-ink'), onClick: onClearFilters, type: 'button', children: "Clear filters" })) : null, actions ? ((0, jsx_runtime_1.jsx)("div", { className: 'ml-auto flex min-w-0 flex-wrap items-center justify-end gap-2', children: actions })) : null] }));
17
17
  };
18
18
  exports.PsTableToolbar = PsTableToolbar;
@@ -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.0",
3
+ "version": "1.8.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -68,10 +68,10 @@
68
68
  "url": "git+https://github.com/pallasoft/ps-table-components.git"
69
69
  },
70
70
  "dependencies": {
71
- "@pallasoft/ps-core-components": "^2.2.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
- "@pallasoft/ps-input-components": "^1.8.0",
74
+ "@pallasoft/ps-input-components": "^1.9.0",
75
75
  "@pallasoft/ps-motion-components": "^1.1.0",
76
76
  "react-aria-components": "^1.21.1"
77
77
  }