@nuralyui/table 0.0.3 → 0.0.6

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.
Files changed (89) hide show
  1. package/bundle.js +1497 -0
  2. package/package.json +16 -2
  3. package/react.js +1 -1
  4. package/react.js.map +1 -1
  5. package/table.component.d.ts +85 -12
  6. package/table.component.js +229 -136
  7. package/table.component.js.map +1 -1
  8. package/table.style.js +253 -2
  9. package/table.style.js.map +1 -1
  10. package/table.types.d.ts +22 -4
  11. package/table.types.js +0 -23
  12. package/table.types.js.map +1 -1
  13. package/components/hy-table-actions.d.ts +0 -10
  14. package/components/hy-table-actions.d.ts.map +0 -1
  15. package/components/hy-table-actions.js +0 -39
  16. package/components/hy-table-actions.js.map +0 -1
  17. package/components/hy-table-content.d.ts +0 -25
  18. package/components/hy-table-content.d.ts.map +0 -1
  19. package/components/hy-table-content.js +0 -168
  20. package/components/hy-table-content.js.map +0 -1
  21. package/components/hy-table-filter.d.ts +0 -11
  22. package/components/hy-table-filter.d.ts.map +0 -1
  23. package/components/hy-table-filter.js +0 -59
  24. package/components/hy-table-filter.js.map +0 -1
  25. package/components/hy-table-pagination.d.ts +0 -21
  26. package/components/hy-table-pagination.d.ts.map +0 -1
  27. package/components/hy-table-pagination.js +0 -111
  28. package/components/hy-table-pagination.js.map +0 -1
  29. package/components/table-actions.style.d.ts +0 -2
  30. package/components/table-actions.style.d.ts.map +0 -1
  31. package/components/table-actions.style.js +0 -31
  32. package/components/table-actions.style.js.map +0 -1
  33. package/components/table-actions.variables.d.ts +0 -2
  34. package/components/table-actions.variables.d.ts.map +0 -1
  35. package/components/table-actions.variables.js +0 -13
  36. package/components/table-actions.variables.js.map +0 -1
  37. package/components/table-content.style.d.ts +0 -2
  38. package/components/table-content.style.d.ts.map +0 -1
  39. package/components/table-content.style.js +0 -77
  40. package/components/table-content.style.js.map +0 -1
  41. package/components/table-content.variables.d.ts +0 -2
  42. package/components/table-content.variables.d.ts.map +0 -1
  43. package/components/table-content.variables.js +0 -29
  44. package/components/table-content.variables.js.map +0 -1
  45. package/components/table-filter.style.d.ts +0 -2
  46. package/components/table-filter.style.d.ts.map +0 -1
  47. package/components/table-filter.style.js +0 -39
  48. package/components/table-filter.style.js.map +0 -1
  49. package/components/table-filter.variables.d.ts +0 -2
  50. package/components/table-filter.variables.d.ts.map +0 -1
  51. package/components/table-filter.variables.js +0 -17
  52. package/components/table-filter.variables.js.map +0 -1
  53. package/components/table-pagination.style.d.ts +0 -2
  54. package/components/table-pagination.style.d.ts.map +0 -1
  55. package/components/table-pagination.style.js +0 -102
  56. package/components/table-pagination.style.js.map +0 -1
  57. package/components/table-pagination.variables.d.ts +0 -2
  58. package/components/table-pagination.variables.d.ts.map +0 -1
  59. package/components/table-pagination.variables.js +0 -17
  60. package/components/table-pagination.variables.js.map +0 -1
  61. package/demo/table-demo.d.ts +0 -17
  62. package/demo/table-demo.d.ts.map +0 -1
  63. package/demo/table-demo.js +0 -166
  64. package/demo/table-demo.js.map +0 -1
  65. package/index.d.ts.map +0 -1
  66. package/react.d.ts.map +0 -1
  67. package/table.component.d.ts.map +0 -1
  68. package/table.style.d.ts.map +0 -1
  69. package/table.types.d.ts.map +0 -1
  70. package/test/hy-table-actions_test.d.ts +0 -2
  71. package/test/hy-table-actions_test.d.ts.map +0 -1
  72. package/test/hy-table-actions_test.js +0 -32
  73. package/test/hy-table-actions_test.js.map +0 -1
  74. package/test/hy-table-content_test.d.ts +0 -2
  75. package/test/hy-table-content_test.d.ts.map +0 -1
  76. package/test/hy-table-content_test.js +0 -168
  77. package/test/hy-table-content_test.js.map +0 -1
  78. package/test/hy-table-filter_test.d.ts +0 -2
  79. package/test/hy-table-filter_test.d.ts.map +0 -1
  80. package/test/hy-table-filter_test.js +0 -80
  81. package/test/hy-table-filter_test.js.map +0 -1
  82. package/test/hy-table-pagination_test.d.ts +0 -2
  83. package/test/hy-table-pagination_test.d.ts.map +0 -1
  84. package/test/hy-table-pagination_test.js +0 -114
  85. package/test/hy-table-pagination_test.js.map +0 -1
  86. package/test/hy-table_test.d.ts +0 -2
  87. package/test/hy-table_test.d.ts.map +0 -1
  88. package/test/hy-table_test.js +0 -145
  89. package/test/hy-table_test.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuralyui/table",
3
- "version": "0.0.3",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -11,5 +11,19 @@
11
11
  "test": "echo \"Error: no test specified\" && exit 1"
12
12
  },
13
13
  "author": "Labidi Aymen",
14
- "license": "ISC"
14
+ "license": "ISC",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./index.js"
18
+ },
19
+ "./bundle": {
20
+ "import": "./bundle.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "bundle.js",
25
+ "*.js",
26
+ "*.d.ts",
27
+ "*.js.map"
28
+ ]
15
29
  }
package/react.js CHANGED
@@ -2,7 +2,7 @@ import { createComponent } from '@lit-labs/react';
2
2
  import * as React from 'react';
3
3
  import { HyTable } from './table.component.js';
4
4
  export const HyTableComponent = createComponent({
5
- tagName: 'hy-table',
5
+ tagName: 'nr-table',
6
6
  elementClass: HyTable,
7
7
  react: React,
8
8
  events: {
package/react.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"react.js","sourceRoot":"","sources":["../../../src/components/table/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC;IAC9C,OAAO,EAAE,UAAU;IACnB,YAAY,EAAE,OAAO;IACrB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE;QACN,QAAQ,EAAE,WAAW;QACrB,UAAU,EAAE,aAAa;QACzB,eAAe,EAAE,kBAAkB;KACpC;CACF,CAAC,CAAC","sourcesContent":["import { createComponent } from '@lit-labs/react';\nimport * as React from 'react';\nimport { HyTable } from './table.component.js';\n\nexport const HyTableComponent = createComponent({\n tagName: 'hy-table',\n elementClass: HyTable,\n react: React,\n events: {\n rowClick: 'row-click',\n sortChange: 'sort-change',\n selectionChange: 'selection-change',\n },\n});\n"]}
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../../../src/components/table/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC;IAC9C,OAAO,EAAE,UAAU;IACnB,YAAY,EAAE,OAAO;IACrB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE;QACN,QAAQ,EAAE,WAAW;QACrB,UAAU,EAAE,aAAa;QACzB,eAAe,EAAE,kBAAkB;KACpC;CACF,CAAC,CAAC","sourcesContent":["import { createComponent } from '@lit-labs/react';\nimport * as React from 'react';\nimport { HyTable } from './table.component.js';\n\nexport const HyTableComponent = createComponent({\n tagName: 'nr-table',\n elementClass: HyTable,\n react: React,\n events: {\n rowClick: 'row-click',\n sortChange: 'sort-change',\n selectionChange: 'selection-change',\n },\n});\n"]}
@@ -1,39 +1,112 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Nuraly, Laabidi Aymen
4
+ * SPDX-License-Identifier: MIT
5
+ */
1
6
  import { LitElement, PropertyValueMap } from 'lit';
2
- import './components/hy-table-actions.js';
3
- import './components/hy-table-filter.js';
4
- import './components/hy-table-pagination.js';
5
- import './components/hy-table-content.js';
6
7
  import { IHeader, SelectionMode, Sizes, SortAttribute } from './table.types.js';
7
- export declare class HyTable extends LitElement {
8
+ import '../select/select.component.js';
9
+ import '../icon/icon.component.js';
10
+ import { TableHost } from './interfaces/index.js';
11
+ declare const HyTable_base: (new (...args: any[]) => import("../../shared/dependency-mixin.js").DependencyAware) & (new (...args: any[]) => import("../../shared/theme-mixin.js").ThemeAware) & (new (...args: any[]) => import("../../shared/event-handler-mixin.js").EventHandlerCapable) & typeof LitElement;
12
+ /**
13
+ * Advanced table component with sorting, filtering, pagination, and selection capabilities.
14
+ *
15
+ * @example
16
+ * ```html
17
+ * <nr-table
18
+ * .headers=${headers}
19
+ * .rows=${data}
20
+ * size="normal"
21
+ * selectionMode="multiple">
22
+ * </nr-table>
23
+ * ```
24
+ *
25
+ * @fires onPaginate - Fired when pagination changes
26
+ * @fires onSelect - Fired when row selection changes
27
+ * @fires onSearch - Fired when search/filter is applied
28
+ * @fires onSort - Fired when sorting is applied
29
+ */
30
+ export declare class HyTable extends HyTable_base implements TableHost {
8
31
  static styles: import("lit").CSSResult;
9
32
  headers: IHeader[];
10
- rows: [];
33
+ rows: any[];
11
34
  size: Sizes;
12
35
  withFilter: boolean;
13
36
  expandable: string | undefined;
14
37
  selectionMode: SelectionMode | undefined;
15
38
  itemPerPage: number[];
16
39
  selectedItemPerPage: number;
17
- displayedRows: never[];
40
+ displayedRows: any[];
18
41
  selectedItems: boolean[];
19
42
  currentPage: number;
20
- rowsCopy: [];
43
+ rowsCopy: any[];
21
44
  activeSearch: boolean;
22
45
  sortAttribute: SortAttribute;
46
+ expand: boolean[];
47
+ showFilterInput: boolean;
48
+ filterValue: string;
49
+ globalCheck?: HTMLElement;
50
+ requiredComponents: string[];
51
+ private selectionController;
52
+ private paginationController;
53
+ private sortController;
54
+ private filterController;
23
55
  connectedCallback(): void;
56
+ updated(_changedProperties: PropertyValueMap<this> | Map<PropertyKey, unknown>): void;
24
57
  willUpdate(_changedProperties: PropertyValueMap<this>): void;
25
- _initSelection(): void;
26
- _initPagination(): void;
58
+ /**
59
+ * Initialize or reset pagination state
60
+ */
61
+ private _initPagination;
62
+ /**
63
+ * Handle items per page change event
64
+ */
27
65
  _handleItemPerPage(itemPerPageEvent: CustomEvent): void;
66
+ /**
67
+ * Handle page navigation event
68
+ */
28
69
  _handleUpdatePage(updatePageEvent: CustomEvent): void;
70
+ /**
71
+ * Handle check all rows event
72
+ */
29
73
  _handleCheckAll(checkAllEvent: CustomEvent): void;
74
+ /**
75
+ * Handle check single row event
76
+ */
30
77
  _handleCheckOne(checkOneEvent: CustomEvent): void;
78
+ /**
79
+ * Handle select single row event (radio button mode)
80
+ */
31
81
  _handleSelectOne(selectOneEvent: CustomEvent): void;
82
+ /**
83
+ * Handle cancel selection action
84
+ */
32
85
  _handleCancelSelection(): void;
86
+ /**
87
+ * Handle search/filter input
88
+ */
33
89
  _handleSearch(searchEvent: CustomEvent): void;
90
+ /**
91
+ * Handle column sort order change
92
+ */
34
93
  _handleSortOrder(sortOrderEvent: CustomEvent): void;
35
- _sort(): void;
36
- _resetSort(): void;
94
+ /**
95
+ * Toggle expanded content for a row
96
+ */
97
+ private _showExpandedContent;
98
+ /**
99
+ * Toggle filter input visibility
100
+ */
101
+ private _toggleFilterInput;
102
+ /**
103
+ * Handle filter input change
104
+ */
105
+ private _handleFilterInputChange;
106
+ /**
107
+ * Render the table component with all templates
108
+ */
37
109
  render(): import("lit").TemplateResult<1>;
38
110
  }
111
+ export {};
39
112
  //# sourceMappingURL=table.component.d.ts.map
@@ -1,22 +1,49 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Nuraly, Laabidi Aymen
4
+ * SPDX-License-Identifier: MIT
5
+ */
1
6
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
7
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
8
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
9
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
10
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
11
  };
7
- import styles from './table.style.js';
8
12
  import { LitElement, html, nothing } from 'lit';
9
- import { customElement, property, state } from 'lit/decorators.js';
10
- import './components/hy-table-actions.js';
11
- import './components/hy-table-filter.js';
12
- import './components/hy-table-pagination.js';
13
- import './components/hy-table-content.js';
14
- import { Sizes, SortOrder, SortValue } from './table.types.js';
15
- let HyTable = class HyTable extends LitElement {
13
+ import { customElement, property, state, query } from 'lit/decorators.js';
14
+ import { NuralyUIBaseMixin } from '../../shared/base-mixin.js';
15
+ import styles from './table.style.js';
16
+ import { EMPTY_STRING } from './table.types.js';
17
+ // Import required components
18
+ import '../select/select.component.js';
19
+ import '../icon/icon.component.js';
20
+ // Import controllers
21
+ import { TableSelectionController, TablePaginationController, TableSortController, TableFilterController } from './controllers/index.js';
22
+ // Import templates
23
+ import { renderPaginationTemplate, renderContentTemplate, renderActionsTemplate, renderFilterTemplate } from './templates/index.js';
24
+ /**
25
+ * Advanced table component with sorting, filtering, pagination, and selection capabilities.
26
+ *
27
+ * @example
28
+ * ```html
29
+ * <nr-table
30
+ * .headers=${headers}
31
+ * .rows=${data}
32
+ * size="normal"
33
+ * selectionMode="multiple">
34
+ * </nr-table>
35
+ * ```
36
+ *
37
+ * @fires onPaginate - Fired when pagination changes
38
+ * @fires onSelect - Fired when row selection changes
39
+ * @fires onSearch - Fired when search/filter is applied
40
+ * @fires onSort - Fired when sorting is applied
41
+ */
42
+ let HyTable = class HyTable extends NuralyUIBaseMixin(LitElement) {
16
43
  constructor() {
17
44
  super(...arguments);
18
45
  this.rows = [];
19
- this.size = Sizes.Normal;
46
+ this.size = "normal" /* Sizes.Normal */;
20
47
  this.withFilter = false;
21
48
  this.itemPerPage = [5, 10, 15, 20];
22
49
  this.selectedItemPerPage = this.itemPerPage[0];
@@ -24,175 +51,229 @@ let HyTable = class HyTable extends LitElement {
24
51
  this.selectedItems = [];
25
52
  this.rowsCopy = [];
26
53
  this.activeSearch = false;
27
- this.sortAttribute = { index: -1, order: SortOrder.Default };
54
+ this.sortAttribute = { index: -1, order: "default" /* SortOrder.Default */ };
55
+ this.expand = [];
56
+ this.showFilterInput = false;
57
+ this.filterValue = EMPTY_STRING;
58
+ this.requiredComponents = ['hy-select', 'nr-icon', 'nr-checkbox'];
59
+ // Controllers
60
+ this.selectionController = new TableSelectionController(this);
61
+ this.paginationController = new TablePaginationController(this);
62
+ this.sortController = new TableSortController(this);
63
+ this.filterController = new TableFilterController(this);
28
64
  }
29
65
  connectedCallback() {
30
66
  super.connectedCallback();
31
- this._initSelection();
67
+ this.selectionController.initSelection();
68
+ }
69
+ updated(_changedProperties) {
70
+ var _a, _b;
71
+ if (this.globalCheck && (_changedProperties.has('selectedItems') || _changedProperties.has('currentPage') || _changedProperties.has('displayedRows'))) {
72
+ const checkbox = this.globalCheck;
73
+ // Get the selection state for the current page only
74
+ const startIndex = (this.currentPage - 1) * this.selectedItemPerPage;
75
+ const endIndex = Math.min(startIndex + this.displayedRows.length, this.selectedItems.length);
76
+ const currentPageSelections = this.selectedItems.slice(startIndex, endIndex);
77
+ if (currentPageSelections.length > 0 && currentPageSelections.every((isSelected) => isSelected)) {
78
+ checkbox.checked = true;
79
+ checkbox.indeterminate = false;
80
+ }
81
+ else if (currentPageSelections.some((isSelected) => isSelected)) {
82
+ checkbox.checked = false;
83
+ checkbox.indeterminate = true;
84
+ }
85
+ else {
86
+ checkbox.checked = false;
87
+ checkbox.indeterminate = false;
88
+ }
89
+ }
90
+ if (this.showFilterInput && _changedProperties.has('showFilterInput')) {
91
+ (_b = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('input')) === null || _b === void 0 ? void 0 : _b.focus();
92
+ }
32
93
  }
33
94
  willUpdate(_changedProperties) {
34
- if (_changedProperties.has('sortAttribute') && this.sortAttribute.index > -1) {
95
+ if (_changedProperties.has('rows')) {
96
+ this.expand = Array(this.rows.length).fill(false);
97
+ }
98
+ if (_changedProperties.has('sortAttribute') && this.sortController.isSortActive()) {
35
99
  this._initPagination();
36
- this._initSelection();
100
+ this.selectionController.initSelection();
37
101
  }
38
102
  if (_changedProperties.has('rowsCopy')) {
39
- if (this.activeSearch) {
103
+ if (this.filterController.isSearchActive()) {
40
104
  this._initPagination();
41
105
  }
42
106
  }
43
107
  if (_changedProperties.has('activeSearch') || _changedProperties.has('rows')) {
44
- if (!this.activeSearch) {
108
+ if (!this.filterController.isSearchActive()) {
45
109
  this.rowsCopy = [...this.rows];
46
110
  this._initPagination();
47
111
  }
48
112
  }
49
113
  }
50
- _initSelection() {
51
- if (this.selectionMode)
52
- this.selectedItems = Array(this.rows.length).fill(false);
53
- }
114
+ /**
115
+ * Initialize or reset pagination state
116
+ */
54
117
  _initPagination() {
55
- if (this.sortAttribute.index > -1) {
56
- if (this.sortAttribute.order != SortOrder.Default)
57
- this._sort();
58
- else
59
- this._resetSort();
118
+ if (this.sortController.isSortActive()) {
119
+ if (!this.sortController.isSortDefault()) {
120
+ this.sortController.sort();
121
+ }
122
+ else {
123
+ this.sortController.resetSort();
124
+ }
60
125
  }
61
- this.displayedRows = this.rowsCopy.slice(0, this.selectedItemPerPage);
62
- this.currentPage = this.rowsCopy.length > 0 ? 1 : 0;
126
+ this.paginationController.initPagination();
63
127
  }
128
+ /**
129
+ * Handle items per page change event
130
+ */
64
131
  _handleItemPerPage(itemPerPageEvent) {
65
- this.selectedItemPerPage = itemPerPageEvent.detail.selectedItemPerPage;
66
- this._initPagination();
132
+ const value = itemPerPageEvent.detail.value || itemPerPageEvent.detail.selectedItemPerPage;
133
+ this.paginationController.handleItemPerPageChange(Number(value));
67
134
  }
135
+ /**
136
+ * Handle page navigation event
137
+ */
68
138
  _handleUpdatePage(updatePageEvent) {
69
- this.currentPage = updatePageEvent.detail.page;
70
- this.displayedRows = this.rowsCopy.slice((updatePageEvent.detail.page - 1) * this.selectedItemPerPage, (updatePageEvent.detail.page - 1) * this.selectedItemPerPage + this.selectedItemPerPage);
71
- this.dispatchEvent(new CustomEvent('onPaginate', { bubbles: true, composed: true, detail: { value: this.currentPage } }));
139
+ this.paginationController.handlePageChange(updatePageEvent.detail.page);
72
140
  }
141
+ /**
142
+ * Handle check all rows event
143
+ */
73
144
  _handleCheckAll(checkAllEvent) {
74
- const everyItemChecked = checkAllEvent.detail.isEveryItemChecked;
75
- this.selectedItems = everyItemChecked ? this.selectedItems.map(() => false) : this.selectedItems.map(() => true);
76
- this.dispatchEvent(new CustomEvent('onSelect', { bubbles: true, composed: true, detail: { value: this.rowsCopy.filter((_, i) => this.selectedItems[i]) } }));
145
+ this.selectionController.handleCheckAll(checkAllEvent.detail.isEveryItemChecked);
77
146
  }
147
+ /**
148
+ * Handle check single row event
149
+ */
78
150
  _handleCheckOne(checkOneEvent) {
79
- const indexSelected = checkOneEvent.detail.index;
80
- this.selectedItems[indexSelected + (this.currentPage - 1) * this.selectedItemPerPage] = checkOneEvent.detail.value;
81
- this.selectedItems = [...this.selectedItems];
82
- this.dispatchEvent(new CustomEvent('onSelect', { bubbles: true, composed: true, detail: { value: this.rowsCopy.filter((_, i) => this.selectedItems[i]) } }));
151
+ this.selectionController.handleCheckOne(checkOneEvent.detail.index, checkOneEvent.detail.value);
83
152
  }
153
+ /**
154
+ * Handle select single row event (radio button mode)
155
+ */
84
156
  _handleSelectOne(selectOneEvent) {
85
- const previousSelected = this.selectedItems.findIndex((isSelected) => isSelected);
86
- if (previousSelected > -1) {
87
- this.selectedItems[previousSelected] = false;
88
- }
89
- const indexSelected = selectOneEvent.detail.index;
90
- this.selectedItems[indexSelected + (this.currentPage - 1) * this.selectedItemPerPage] = true;
91
- this.selectedItems = [...this.selectedItems];
92
- this.dispatchEvent(new CustomEvent('onSelect', { bubbles: true, composed: true, detail: { value: this.rowsCopy.filter((_, i) => this.selectedItems[i]) } }));
157
+ this.selectionController.handleSelectOne(selectOneEvent.detail.index);
93
158
  }
159
+ /**
160
+ * Handle cancel selection action
161
+ */
94
162
  _handleCancelSelection() {
95
- this.selectedItems = this.selectedItems.map(() => false);
96
- this.dispatchEvent(new CustomEvent('onSelect', { bubbles: true, composed: true, detail: { value: this.selectedItems } }));
163
+ this.selectionController.cancelSelection();
97
164
  }
165
+ /**
166
+ * Handle search/filter input
167
+ */
98
168
  _handleSearch(searchEvent) {
99
- const searchValue = searchEvent.detail.value;
100
- if (searchValue.trim().length > 0) {
101
- this.activeSearch = true;
102
- this.rowsCopy = this.rows.filter((rowValue) => {
103
- return Object.values(rowValue).some((attributeValue) => {
104
- const stringValue = JSON.stringify(attributeValue);
105
- return stringValue.includes(searchValue);
106
- });
107
- });
108
- this.dispatchEvent(new CustomEvent('onSearch', { bubbles: true, composed: true, detail: { value: this.rowsCopy } }));
109
- }
110
- else {
111
- this.activeSearch = false;
112
- }
169
+ this.filterController.handleSearch(searchEvent.detail.value);
113
170
  }
171
+ /**
172
+ * Handle column sort order change
173
+ */
114
174
  _handleSortOrder(sortOrderEvent) {
115
- const index = sortOrderEvent.detail.index;
116
- if (index != this.sortAttribute.index) {
117
- this.sortAttribute.index = index;
118
- this.sortAttribute.order = SortOrder.Ascending;
119
- }
120
- else {
121
- if (this.sortAttribute.order == SortOrder.Default)
122
- this.sortAttribute.order = SortOrder.Ascending;
123
- else if (this.sortAttribute.order == SortOrder.Ascending)
124
- this.sortAttribute.order = SortOrder.Descending;
125
- else
126
- this.sortAttribute.order = SortOrder.Default;
127
- }
128
- this.sortAttribute = Object.assign({}, this.sortAttribute);
129
- }
130
- _sort() {
131
- if (this.rowsCopy.length) {
132
- const sortOrder = this.sortAttribute.order == SortOrder.Default
133
- ? SortValue.Default
134
- : this.sortAttribute.order == SortOrder.Ascending
135
- ? SortValue.Ascending
136
- : SortValue.Descending;
137
- this.rowsCopy.sort((a, b) => {
138
- const stringifyA = JSON.stringify(a[this.headers[this.sortAttribute.index].key]);
139
- const stringifyB = JSON.stringify(b[this.headers[this.sortAttribute.index].key]);
140
- const result = stringifyA < stringifyB ? -1 : stringifyA > stringifyB ? 1 : 0;
141
- return result * sortOrder;
142
- });
143
- this.dispatchEvent(new CustomEvent('onSort', { bubbles: true, composed: true, detail: { value: this.rowsCopy } }));
144
- }
175
+ this.sortController.handleSortOrderChange(sortOrderEvent.detail.index);
176
+ }
177
+ /**
178
+ * Toggle expanded content for a row
179
+ */
180
+ _showExpandedContent(index) {
181
+ this.expand[index] = !this.expand[index];
182
+ this.requestUpdate();
183
+ }
184
+ /**
185
+ * Toggle filter input visibility
186
+ */
187
+ _toggleFilterInput() {
188
+ this.showFilterInput = !this.showFilterInput;
145
189
  }
146
- _resetSort() {
147
- this.rowsCopy.sort((copyA, copyB) => {
148
- const positionInOriginalArrayA = this.rows.findIndex((originalA) => JSON.stringify(originalA) === JSON.stringify(copyA));
149
- const positionInOriginalArrayB = this.rows.findIndex((originalB) => JSON.stringify(originalB) === JSON.stringify(copyB));
150
- return positionInOriginalArrayA > positionInOriginalArrayB
151
- ? SortValue.Ascending
152
- : positionInOriginalArrayA < positionInOriginalArrayB
153
- ? SortValue.Descending
154
- : SortValue.Default;
155
- });
190
+ /**
191
+ * Handle filter input change
192
+ */
193
+ _handleFilterInputChange(event) {
194
+ this.filterValue = event.target.value;
195
+ this.filterController.handleSearch(this.filterValue);
156
196
  }
197
+ /**
198
+ * Render the table component with all templates
199
+ */
157
200
  render() {
158
- return html `${this.selectionMode && !this.withFilter && this.selectedItems.some((isSelected) => isSelected)
159
- ? html `<hy-table-actions
160
- .selectedItems=${this.selectedItems.filter((isSelected) => isSelected).length}
161
- .size=${this.size}
162
- @cancel-selection=${this._handleCancelSelection}
163
- ></hy-table-actions>`
201
+ const numberOfPages = Math.ceil(this.rowsCopy.length / this.selectedItemPerPage);
202
+ const fromItem = this.currentPage > 0
203
+ ? this.currentPage * this.selectedItemPerPage - this.selectedItemPerPage + 1
204
+ : 0;
205
+ const toItem = this.currentPage * this.selectedItemPerPage <= this.rowsCopy.length
206
+ ? this.currentPage * this.selectedItemPerPage
207
+ : this.rowsCopy.length;
208
+ const enableNext = toItem < this.rowsCopy.length;
209
+ const enablePrevious = fromItem > 1;
210
+ return html `
211
+ ${this.selectionMode && !this.withFilter && this.selectionController.hasSelection()
212
+ ? renderActionsTemplate({
213
+ selectedItems: this.selectionController.getSelectedCount(),
214
+ size: this.size,
215
+ onCancelSelection: () => this._handleCancelSelection()
216
+ })
164
217
  : this.withFilter
165
218
  ? html `
166
219
  <div class="filter-container">
167
- <hy-table-filter @value-change=${this._handleSearch}></hy-table-filter>
220
+ ${renderFilterTemplate({
221
+ showInput: this.showFilterInput,
222
+ value: this.filterValue,
223
+ onToggleInput: () => this._toggleFilterInput(),
224
+ onChange: (e) => this._handleFilterInputChange(e)
225
+ })}
168
226
  </div>
169
227
  `
170
228
  : nothing}
171
- <hy-table-content
172
- .headers=${this.headers}
173
- .rows=${this.displayedRows}
174
- .expandable=${this.expandable && !this.selectionMode ? this.expandable : nothing}
175
- .selectionMode=${this.selectionMode && !this.withFilter ? this.selectionMode : nothing}
176
- .selectedItems=${this.selectedItems}
177
- .currentPage=${this.currentPage}
178
- .itemPerPage=${this.selectedItemPerPage}
179
- .sortAttribute=${this.sortAttribute}
180
- .size=${this.size}
181
- @check-all=${this._handleCheckAll}
182
- @check-one=${this._handleCheckOne}
183
- @select-one=${this._handleSelectOne}
184
- @update-sort=${this._handleSortOrder}
185
- ></hy-table-content>
186
229
 
187
- <hy-table-pagination
188
- .numberOfItems=${this.rowsCopy.length}
189
- .currentPage=${this.currentPage}
190
- .itemPerPage=${this.itemPerPage}
191
- .selectedItemPerPage=${this.selectedItemPerPage}
192
- .size=${this.size}
193
- @item-per-page=${this._handleItemPerPage}
194
- @update-page=${this._handleUpdatePage}
195
- ></hy-table-pagination> `;
230
+ <div class="table-content-wrapper">
231
+ ${renderContentTemplate({
232
+ headers: this.headers,
233
+ rows: this.displayedRows,
234
+ expandable: this.expandable && !this.selectionMode ? this.expandable : undefined,
235
+ selectionMode: this.selectionMode && !this.withFilter ? this.selectionMode : undefined,
236
+ selectedItems: this.selectedItems,
237
+ currentPage: this.currentPage,
238
+ itemPerPage: this.selectedItemPerPage,
239
+ sortAttribute: this.sortAttribute,
240
+ expand: this.expand,
241
+ onCheckAll: () => {
242
+ const startIndex = (this.currentPage - 1) * this.selectedItemPerPage;
243
+ const endIndex = Math.min(startIndex + this.selectedItemPerPage, this.selectedItems.length);
244
+ const currentPageItems = this.selectedItems.slice(startIndex, endIndex);
245
+ const isEveryItemChecked = currentPageItems.every(i => i) && currentPageItems.length > 0;
246
+ this._handleCheckAll({ detail: { isEveryItemChecked } });
247
+ },
248
+ onCheckOne: (e, index) => this._handleCheckOne({ detail: { index, value: e.detail.checked } }),
249
+ onSelectOne: (index) => this._handleSelectOne({ detail: { index } }),
250
+ onUpdateSort: (index) => this._handleSortOrder({ detail: { index } }),
251
+ onShowExpandedContent: (index) => this._showExpandedContent(index)
252
+ })}
253
+ </div>
254
+
255
+ ${renderPaginationTemplate({
256
+ numberOfItems: this.rowsCopy.length,
257
+ itemPerPage: this.itemPerPage,
258
+ selectedItemPerPage: this.selectedItemPerPage,
259
+ currentPage: this.currentPage,
260
+ size: this.size,
261
+ numberOfPages,
262
+ fromItem,
263
+ toItem,
264
+ enableNext,
265
+ enablePrevious,
266
+ onItemPerPageChange: (e) => this._handleItemPerPage(e),
267
+ onNextPage: () => {
268
+ this.currentPage++;
269
+ this._handleUpdatePage({ detail: { page: this.currentPage } });
270
+ },
271
+ onPreviousPage: () => {
272
+ this.currentPage--;
273
+ this._handleUpdatePage({ detail: { page: this.currentPage } });
274
+ }
275
+ })}
276
+ `;
196
277
  }
197
278
  };
198
279
  HyTable.styles = styles;
@@ -203,7 +284,7 @@ __decorate([
203
284
  property({ type: Array })
204
285
  ], HyTable.prototype, "rows", void 0);
205
286
  __decorate([
206
- property()
287
+ property({ type: String })
207
288
  ], HyTable.prototype, "size", void 0);
208
289
  __decorate([
209
290
  property({ type: Boolean })
@@ -212,7 +293,7 @@ __decorate([
212
293
  property({ type: String })
213
294
  ], HyTable.prototype, "expandable", void 0);
214
295
  __decorate([
215
- property()
296
+ property({ type: String })
216
297
  ], HyTable.prototype, "selectionMode", void 0);
217
298
  __decorate([
218
299
  state()
@@ -238,8 +319,20 @@ __decorate([
238
319
  __decorate([
239
320
  state()
240
321
  ], HyTable.prototype, "sortAttribute", void 0);
322
+ __decorate([
323
+ state()
324
+ ], HyTable.prototype, "expand", void 0);
325
+ __decorate([
326
+ state()
327
+ ], HyTable.prototype, "showFilterInput", void 0);
328
+ __decorate([
329
+ state()
330
+ ], HyTable.prototype, "filterValue", void 0);
331
+ __decorate([
332
+ query('#global-check')
333
+ ], HyTable.prototype, "globalCheck", void 0);
241
334
  HyTable = __decorate([
242
- customElement('hy-table')
335
+ customElement('nr-table')
243
336
  ], HyTable);
244
337
  export { HyTable };
245
338
  //# sourceMappingURL=table.component.js.map