@exmg/exm-grid 1.2.2 → 1.2.4

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,332 +1,11 @@
1
1
  import { __decorate } from 'tslib';
2
- import { html } from 'lit';
3
- import { ExmgElement } from '@exmg/lit-base/index.js';
4
- import { property, state, customElement } from 'lit/decorators.js';
5
- import { cache } from 'lit/directives/cache.js';
6
- import '@exmg/exm-sortable/exm-sortable.js';
2
+ import { customElement } from 'lit/decorators.js';
7
3
  import { style } from '../styles/exm-grid-styles-css.js';
8
- import { ExmRowSelectable } from './featrues/exm-row-selectable.js';
9
- import { ExmQuerySelectors } from './utils/exm-query-selectors.js';
10
- import { ExmRowExpandable } from './featrues/exm-row-expandable.js';
11
- import { ExmColumnSortable } from './featrues/exm-column-sortable.js';
12
- import { ExmRowSortable } from './featrues/exm-row-sortable.js';
4
+ import { ExmGridBase } from './exm-grid-base.js';
13
5
 
14
- /**
15
- * ### Styling
16
- * The following custom properties and mixins are available for styling:
17
- *
18
- * Custom property | Description | Default
19
- * ----------------|-------------|----------
20
- * `--exm-arrow-upward-url` | Url to icon that is used for soring direction indicator | `url('/assets/arrow-upward.svg');`
21
- * `--exm-table-card-width` | table card width | `100%;`
22
- * `--exm-table-card-margin-bottom` | table bottom margin | `5px;`
23
- * `--exm-table-color` | table text color | `#02182b;`
24
- * `--exm-table-background-color` | table background color | `#ffffff;`
25
- * `--exm-table-box-shadow` | table box shadow | `#{0px 1px 5px 0px rgba($onSurface, .2), 0px 2px 2px 0px rgba($onSurface, .14), 0px 3px 1px -2px rgba($onSurface, .12)},`
26
- * `--exm-table-row-divider-color` | table rows separator color | `#dbdbdb;`
27
- * `--exm-table-row-selected-color` | selected row text color | `#02182b;`
28
- * `--exm-table-row-selected-background-color` | selected row background color | `#e2f1fe;`
29
- * `--exm-table-row-hover-color` | row hover text color | `#02182b;`
30
- * `--exm-table-row-hover-background-color` | row hover background color | `#f1f1f1;`
31
- * `--exm-table-row-dragged-background-color` | sortable row background color when dragged | `#f1f1f1;`
32
- * `--exm-table-rows-expanded-divider-border` | border between row and expanded row detail | `none;`
33
- * `--exm-table-rows-expanded-border` | border around row and expanded row detail | `1px solid #dbdbdb;`
34
- * `--exm-table-rows-expanded-background-color` | background color of row and expanded row detail | `#e2f1fe;`
35
- * `--exm-table-rows-expanded-color` | text color of row and expanded row detail | `#02182b;`
36
- * `--exm-table-th-color` | header text color | `#0071dc;`
37
- * `--exm-table-columns-background-color` | header background color | `#ffffff;`
38
- * `--exm-table-th-sortable-hover-color` | sortable header hover text color | `#02182b;`
39
- * `--exm-table-th-height` | header height | `48px;`
40
- * `--exm-table-th-sort-margin-left` | header margin after text but before icon | `0px;`
41
- * `--exm-table-td-height` | row cell height | `48px;`
42
- * `--exm-table-th-sort-icon-height` | sort icon height | `1em;`
43
- * `--exm-table-th-sort-icon-width` | sort icon width | `1em;`
44
- * `--exm-table-col-number-padding-right` | right padding of number column | `10px;`
45
- * `--exm-table-checkbox-cell-width` | width of cell with checkbox | `24px;`
46
- */
47
- let ExmGrid = class ExmGrid extends ExmgElement {
48
- constructor() {
49
- super(...arguments);
50
- /**
51
- * Array of data which mapped to rows
52
- */
53
- this.items = [];
54
- /**
55
- * Feature that turn on sort by column
56
- */
57
- this.sortable = false;
58
- /**
59
- * Feature that allow sort rows
60
- * If table has turn on feature `selectable` then it takes precedence and `rowSelectable` will be ignored
61
- */
62
- this.rowsSortable = false;
63
- /**
64
- * Feature that allow select rows
65
- */
66
- this.rowsSelectable = false;
67
- /**
68
- * By default a ros is also selactable by clicking anywhere inside the row when the rowSElectable option is enabled
69
- */
70
- this.disableRowClickSelection = false;
71
- /**
72
- * Map of column names that should be hidden
73
- */
74
- this.hiddenColumnNames = {};
75
- /**
76
- * Map of row id and selection state
77
- * Useful for setup default selection or manipulating programmatically
78
- */
79
- this.selectedRowIds = {};
80
- /**
81
- * Map of row id and expandable row state
82
- * Useful for setup default expanded rows or manipulating programmatically
83
- */
84
- this.expandedRowIds = {};
85
- /**
86
- * Set table layout. If fixed then text overflow will be hidden and ellipsis added.
87
- */
88
- this.tableLayout = 'auto';
89
- this.withToolbar = false;
90
- this.componentReady = false;
91
- }
92
- getQuerySelectors() {
93
- if (!this.querySelectors) {
94
- throw new Error('ExmQuerySelector not initialized yet');
95
- }
96
- return this.querySelectors;
97
- }
98
- getTable() {
99
- return this.getQuerySelectors().getTable();
100
- }
101
- getTableBody() {
102
- return this.getQuerySelectors().getTableBody();
103
- }
104
- findTableBody() {
105
- if (this.querySelectors) {
106
- return this.getTableBody() || undefined;
107
- }
108
- return undefined;
109
- }
110
- // eslint-disable-next-line
111
- getColumns(selector = 'th') {
112
- return this.getQuerySelectors().getColumns(selector);
113
- }
114
- getBodyRowSelector(selector = '') {
115
- return this.getQuerySelectors().getBodyRowSelector(selector);
116
- }
117
- canSortRows() {
118
- return !this.sortable && this.rowsSortable;
119
- }
120
- rowsOrderChange(e) {
121
- setTimeout(() => {
122
- const { sourceIndex, targetIndex } = e.detail;
123
- const items = [...this.items];
124
- const movedElement = items[sourceIndex];
125
- items.splice(sourceIndex, 1);
126
- items.splice(targetIndex, 0, movedElement);
127
- this.dispatchEvent(new CustomEvent('exm-grid-rows-order-updated', {
128
- composed: true,
129
- bubbles: true,
130
- detail: { sourceIndex, targetIndex },
131
- }));
132
- this.dispatchEvent(new CustomEvent('exm-grid-rows-order-changed', {
133
- composed: true,
134
- bubbles: true,
135
- detail: { items },
136
- }));
137
- }, 0);
138
- }
139
- updateColumnVisibility(previousHiddenColumnNames = {}) {
140
- let visibleColumns = 0;
141
- this.getColumns().forEach((column, index) => {
142
- const columnKey = column.getAttribute('data-column-key');
143
- visibleColumns += this.hiddenColumnNames[columnKey || ''] ? 0 : 1;
144
- if (columnKey && previousHiddenColumnNames[columnKey] !== this.hiddenColumnNames[columnKey]) {
145
- const nextDisplayValue = this.hiddenColumnNames[columnKey] ? 'none' : 'table-cell';
146
- column.style.display = nextDisplayValue;
147
- this.getTable()
148
- .querySelectorAll(`tbody.grid-data tr:not(.grid-row-detail) td:nth-child(${index + 1})`)
149
- .forEach((cell) => {
150
- cell.style.display = nextDisplayValue;
151
- });
152
- }
153
- });
154
- this.updateAutoColspan(visibleColumns);
155
- }
156
- updateAutoColspan(visibleColumns) {
157
- this.getTable()
158
- .querySelectorAll('[data-auto-colspan]')
159
- .forEach((element) => {
160
- const offset = Number.parseInt(element.getAttribute('data-auto-span') || '0', 10);
161
- element.setAttribute('colspan', (visibleColumns - offset).toString());
162
- });
163
- }
164
- observeExpandedRowIds(changedProps) {
165
- if (changedProps.has('expandedRowIds')) {
166
- Object.entries(this.expandedRowIds).forEach(([rowId, nextExpandedState]) => {
167
- const expendableToggle = this.getTableBody().querySelector(this.getBodyRowSelector(`[data-row-key="${rowId}"] ${this.expandableToggleSelector}`));
168
- if (expendableToggle) {
169
- const isExpanded = expendableToggle.hasAttribute('data-is-expanded');
170
- if (isExpanded !== nextExpandedState) {
171
- expendableToggle.dispatchEvent(new MouseEvent('click'));
172
- }
173
- }
174
- });
175
- }
176
- }
177
- observeSelectedRowIds(changedProps) {
178
- if (changedProps.has('selectedRowIds')) {
179
- Object.entries(this.selectedRowIds).forEach(([rowId, nextSelectionState]) => {
180
- const row = this.getTableBody().querySelector(this.getBodyRowSelector(`[data-row-key="${rowId}"]`));
181
- if (row) {
182
- const isSelected = row.hasAttribute('data-selected');
183
- if (isSelected !== nextSelectionState) {
184
- row.dispatchEvent(new MouseEvent('click'));
185
- }
186
- }
187
- });
188
- }
189
- }
190
- observeItems(changedProps) {
191
- if (changedProps.has('items') && this.rowSelectableFeature) {
192
- this.rowSelectableFeature.syncSelectedItems();
193
- }
194
- }
195
- async initGridAttributes() {
196
- await this.updateComplete;
197
- const toolbarSlot = this.shadowRoot.querySelector('slot[name="toolbar"]');
198
- if (toolbarSlot && toolbarSlot.assignedNodes && toolbarSlot.assignedNodes().length) {
199
- // make TS happy - this.withToolbar is declared but never read
200
- this.withToolbar = this.withToolbar || true;
201
- }
202
- }
203
- async firstUpdated() {
204
- const table = this.shadowRoot.host.querySelector('table');
205
- const tableBody = table.querySelector('tbody.grid-data');
206
- this.querySelectors = new ExmQuerySelectors(table, tableBody);
207
- this.initGridAttributes();
208
- const bodyRows = this.querySelectors.getBodyRows();
209
- if (this.sortable) {
210
- this.columnSortableFeature = new ExmColumnSortable(this.querySelectors, (event) => this.dispatchEvent(event), this.defaultSortColumn, this.defaultSortDirection);
211
- this.columnSortableFeature.initFeature();
212
- }
213
- if (this.canSortRows()) {
214
- this.rowSortableFeature = new ExmRowSortable(this.querySelectors);
215
- this.rowSortableFeature.initFeature();
216
- }
217
- if (this.rowsSelectable) {
218
- this.rowSelectableFeature = new ExmRowSelectable(this.querySelectors, (event) => this.dispatchEvent(event), this.disableRowClickSelection, this.selectableCheckboxSelector);
219
- this.rowSelectableFeature.initFeature(bodyRows);
220
- }
221
- if (this.expandableToggleSelector) {
222
- this.rowExpandableFeature = new ExmRowExpandable(this.querySelectors, this.expandableToggleSelector);
223
- this.rowExpandableFeature.initFeature();
224
- }
225
- this.updateColumnVisibility();
226
- bodyRows.forEach((row) => row.setAttribute('data-initialized', ''));
227
- this.querySelectors.getColumns('th:not([title])').forEach((col) => col.setAttribute('title', col.innerText));
228
- this.querySelectors.getTable().setAttribute('data-table-layout', this.tableLayout);
229
- await this.updateComplete;
230
- this.componentReady = true;
231
- }
232
- updated(changedProps) {
233
- if (changedProps.has('hiddenColumnNames') || changedProps.has('items')) {
234
- this.updateColumnVisibility(changedProps.get('hiddenColumnNames'));
235
- }
236
- this.observeItems(changedProps);
237
- this.observeExpandedRowIds(changedProps);
238
- this.observeSelectedRowIds(changedProps);
239
- if (this.componentReady && changedProps.has('items')) {
240
- const bodyRows = this.querySelectors.getBodyRowsNotInitialized();
241
- if (this.rowSelectableFeature) {
242
- this.rowSelectableFeature.updateFeature(bodyRows);
243
- }
244
- if (this.rowExpandableFeature) {
245
- this.rowExpandableFeature.updateFeature();
246
- }
247
- if (this.rowSortableFeature) {
248
- this.rowSortableFeature.updateFeature();
249
- }
250
- bodyRows.forEach((row) => row.setAttribute('data-initialized', ''));
251
- }
252
- }
253
- renderWithoutSortable() {
254
- return html ` <slot></slot> `;
255
- }
256
- renderWithSortable() {
257
- return html `
258
- <exm-sortable
259
- orientation="${'vertical'}"
260
- animation-enabled
261
- item-selector="tbody.grid-data &gt; tr:not(.grid-row-detail)"
262
- handle-selector=".grid-row-drag-handler"
263
- .sortableHostNode="${this.findTableBody()}"
264
- @dom-order-change="${this.rowsOrderChange}"
265
- >
266
- <slot></slot>
267
- </exm-sortable>
268
- `;
269
- }
270
- render() {
271
- return html `
272
- <div class="table-card-container">
273
- <slot name="toolbar"></slot>
274
- <div class="table-card">
275
- <div class="table-container">
276
- ${cache(this.canSortRows() ? this.renderWithSortable() : this.renderWithoutSortable())}
277
- </div>
278
- <slot name="pagination"></slot>
279
- </div>
280
- </div>
281
- `;
282
- }
6
+ let ExmGrid = class ExmGrid extends ExmGridBase {
283
7
  };
284
8
  ExmGrid.styles = [style];
285
- __decorate([
286
- property({ type: Array })
287
- ], ExmGrid.prototype, "items", void 0);
288
- __decorate([
289
- property({ type: Boolean, reflect: true })
290
- ], ExmGrid.prototype, "sortable", void 0);
291
- __decorate([
292
- property({ type: String, attribute: 'default-sort-column' })
293
- ], ExmGrid.prototype, "defaultSortColumn", void 0);
294
- __decorate([
295
- property({ type: String, attribute: 'default-sort-direction' })
296
- ], ExmGrid.prototype, "defaultSortDirection", void 0);
297
- __decorate([
298
- property({ type: Boolean, reflect: true, attribute: 'rows-sortable' })
299
- ], ExmGrid.prototype, "rowsSortable", void 0);
300
- __decorate([
301
- property({ type: Boolean, attribute: 'rows-selectable' })
302
- ], ExmGrid.prototype, "rowsSelectable", void 0);
303
- __decorate([
304
- property({ type: Boolean, attribute: 'disable-row-click-selection' })
305
- ], ExmGrid.prototype, "disableRowClickSelection", void 0);
306
- __decorate([
307
- property({ type: String, attribute: 'selectable-checkbox-selector' })
308
- ], ExmGrid.prototype, "selectableCheckboxSelector", void 0);
309
- __decorate([
310
- property({ type: Object })
311
- ], ExmGrid.prototype, "hiddenColumnNames", void 0);
312
- __decorate([
313
- property({ type: Object })
314
- ], ExmGrid.prototype, "selectedRowIds", void 0);
315
- __decorate([
316
- property({ type: Object })
317
- ], ExmGrid.prototype, "expandedRowIds", void 0);
318
- __decorate([
319
- property({ type: String, attribute: 'expandable-toggle-selector', reflect: true })
320
- ], ExmGrid.prototype, "expandableToggleSelector", void 0);
321
- __decorate([
322
- property({ type: String, attribute: 'table-layout', reflect: true })
323
- ], ExmGrid.prototype, "tableLayout", void 0);
324
- __decorate([
325
- state()
326
- ], ExmGrid.prototype, "querySelectors", void 0);
327
- __decorate([
328
- property({ type: Boolean, reflect: true, attribute: 'data-with-toolbar' })
329
- ], ExmGrid.prototype, "withToolbar", void 0);
330
9
  ExmGrid = __decorate([
331
10
  customElement('exm-grid')
332
11
  ], ExmGrid);
@@ -0,0 +1,9 @@
1
+ import { ExmGridBase } from './exm-grid-base.js';
2
+ export declare class ExmOutlinedGrid extends ExmGridBase {
3
+ static styles: import("lit").CSSResult[];
4
+ }
5
+ declare global {
6
+ interface HTMLElementTagNameMap {
7
+ 'exm-outlined-grid': ExmOutlinedGrid;
8
+ }
9
+ }
@@ -0,0 +1,14 @@
1
+ import { __decorate } from 'tslib';
2
+ import { customElement } from 'lit/decorators.js';
3
+ import { style, gridOutlineStyles } from '../styles/exm-grid-styles-css.js';
4
+ import { ExmGridBase } from './exm-grid-base.js';
5
+
6
+ let ExmOutlinedGrid = class ExmOutlinedGrid extends ExmGridBase {
7
+ };
8
+ ExmOutlinedGrid.styles = [style, gridOutlineStyles];
9
+ ExmOutlinedGrid = __decorate([
10
+ customElement('exm-outlined-grid')
11
+ ], ExmOutlinedGrid);
12
+
13
+ export { ExmOutlinedGrid };
14
+ //# sourceMappingURL=exm-outlined-grid.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exmg/exm-grid",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "type": "module",
5
5
  "description": "exmg grid element",
6
6
  "contributors": [
@@ -22,6 +22,8 @@
22
22
  "./exm-grid-smart-toolbar.js": "./dist/table/exm-grid-smart-toolbar.js",
23
23
  "./exm-grid-toolbar-filters.js": "./dist/table/exm-grid-toolbar-filters.js",
24
24
  "./exm-grid-toolbar.js": "./dist/table/exm-grid-toolbar.js",
25
+ "./exm-outlined-grid.js": "./dist/table/exm-outlined-grid.js",
26
+ "./exm-grid-base.js": "./dist/table/exm-grid-base.js",
25
27
  "./exm-grid.js": "./dist/table/exm-grid.js",
26
28
  "./exm-toolbar-search.js": "./dist/search/exm-toolbar-search.js"
27
29
  },
@@ -37,8 +39,8 @@
37
39
  "directory": "packages/exm-grid"
38
40
  },
39
41
  "dependencies": {
40
- "@exmg/exm-search": "^1.2.2",
41
- "@exmg/exm-sortable": "^1.2.2"
42
+ "@exmg/exm-search": "^1.2.4",
43
+ "@exmg/exm-sortable": "^1.2.4"
42
44
  },
43
45
  "peerDependencies": {
44
46
  "@exmg/lit-base": "^3.0.0",
@@ -52,5 +54,5 @@
52
54
  "publishConfig": {
53
55
  "access": "public"
54
56
  },
55
- "gitHead": "ebeff1e4708e98ba6b71e4a88ea8a4860cf3c61e"
57
+ "gitHead": "7d2d8b74ef0b3f65870699ed2aa8e1ff54d8809d"
56
58
  }