@c2n/table 0.0.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Nguyen Thai Vinh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @c2n/table
2
+
3
+ `c2-table` is a virtualized data grid: one CSS grid whose header and body rows are `subgrid` items, so columns stay aligned with no scroll syncing and pinned columns are sticky cells rather than separate containers. Columns are declared as `c2-table-column` children — definitions that render nothing themselves.
4
+
5
+ ```html
6
+ <c2-table row-key="id" sortable stripe selection="multiple" checkbox-selection style="height: 320px" rows='[{ "id": "1", "name": "Ada", "score": 128000 }]'>
7
+ <c2-table-column field="name" header="Name" width="2fr" pinned="start"></c2-table-column>
8
+ <c2-table-column field="score" header="Score" width="120px" align="end" format="number"></c2-table-column>
9
+ </c2-table>
10
+ ```
11
+
12
+ - Rows come from `rows` (an array in the property, JSON in the attribute) or from an async `dataSource` that is asked for one block at a time as rows scroll into view.
13
+ - Columns: `field` (dotted paths allowed), `header`, `width` (any grid track), `min-width`, `align`, `sortable`, `resizable`, `pinned="start|end"`, `hidden`, `format` (`number`, `percent`, `currency`, `date`, `datetime`, `time`) with `format-options` / `currency` / `locale`, `cell-class`, and the `renderCell` / `renderHeader` / `comparator` properties.
14
+ - Table: `selection="single|multiple"`, `checkbox-selection`, `value` (selected row keys), `sort` (`field:asc;other:desc`), `multi-sort`, `sortable`, `resizable`, `stripe`, `virtual="auto|always|never"`, `row-height`, `overscan`, `virtual-threshold`, `block-size`, `page`, `page-size`, `loading`, `error`, `empty-message`.
15
+ - **Paging**: slot a `c2-pagination` into `footer` and the table pages, driving the pager's `page` / `page-size` / `total-items` through the `@c2n/core` pager context. `page-size` turns it on, or the table adopts the pager's. `rows` are sliced in place; a `dataSource` is asked for one page per request. `@c2n/pagination` is not a dependency — install it yourself.
16
+ - Events: `selection-change`, `sort-change`, `row-click`, `cell-click`, `column-resize`, `page-change`. Slots: `toolbar`, `footer`, `empty`, `loading`, `error`.
17
+ - Keyboard: arrows walk cells, Home/End and ⌘/ctrl+Home/End jump, PageUp/PageDown page, Enter sorts the focused column, Space selects the focused row.
18
+ - Theming: `--c2-table--*` (surface), `--c2-table__header--*` / `__header-cell--*`, `--c2-table__row--*` (plus `__hover`, `__selected`, `__odd`), `--c2-table__cell--*`, `--c2-table__sort-icon--*`, `--c2-table__resizer--*`. See the docs site for the full list.
19
+
20
+ Virtualization needs a uniform row height: it measures the first rendered row, so theme the height with `--c2-table__row--height` (`row-height` is only the estimate used for the first paint), and give the host a height or `--c2-table--max-height`.
@@ -0,0 +1,92 @@
1
+ import { LitElement, unsafeCSS } from "lit";
2
+ import { property } from "lit/decorators.js";
3
+ import { customElement } from "@c2n/core/element-helper.js";
4
+ import { jsonPropertyConverter } from "@c2n/core/lit-helper.js";
5
+ //#region src/table-column.scss?inline
6
+ var table_column_default = ":host {\n display: none;\n}";
7
+ //#endregion
8
+ //#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
9
+ function __decorate(decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
+ 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;
13
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ }
15
+ //#endregion
16
+ //#region src/table-column.ts
17
+ /** Fired at the parent table whenever a column definition changes. */
18
+ var COLUMN_CHANGE_EVENT = "c2-table-column-change";
19
+ var TableColumn = class TableColumn extends LitElement {
20
+ constructor(..._args) {
21
+ super(..._args);
22
+ this.field = "";
23
+ this.width = "1fr";
24
+ this.minWidth = 64;
25
+ this.align = "start";
26
+ this.hidden = false;
27
+ this.format = "text";
28
+ this.cellSlot = false;
29
+ }
30
+ static {
31
+ this.styles = unsafeCSS(table_column_default);
32
+ }
33
+ connectedCallback() {
34
+ super.connectedCallback();
35
+ this.#notify();
36
+ }
37
+ disconnectedCallback() {
38
+ super.disconnectedCallback();
39
+ this.#notify();
40
+ }
41
+ updated(_changed) {
42
+ this.#notify();
43
+ }
44
+ #notify() {
45
+ this.dispatchEvent(new CustomEvent(COLUMN_CHANGE_EVENT, {
46
+ bubbles: true,
47
+ composed: true
48
+ }));
49
+ }
50
+ };
51
+ __decorate([property({ type: String })], TableColumn.prototype, "field", void 0);
52
+ __decorate([property({ type: String })], TableColumn.prototype, "header", void 0);
53
+ __decorate([property({ type: String })], TableColumn.prototype, "width", void 0);
54
+ __decorate([property({
55
+ type: Number,
56
+ attribute: "min-width"
57
+ })], TableColumn.prototype, "minWidth", void 0);
58
+ __decorate([property({ type: String })], TableColumn.prototype, "align", void 0);
59
+ __decorate([property({
60
+ type: Boolean,
61
+ converter: { fromAttribute: (value) => value !== null }
62
+ })], TableColumn.prototype, "sortable", void 0);
63
+ __decorate([property({
64
+ type: Boolean,
65
+ converter: { fromAttribute: (value) => value !== null }
66
+ })], TableColumn.prototype, "resizable", void 0);
67
+ __decorate([property({ type: String })], TableColumn.prototype, "pinned", void 0);
68
+ __decorate([property({
69
+ type: Boolean,
70
+ reflect: true
71
+ })], TableColumn.prototype, "hidden", void 0);
72
+ __decorate([property({ type: String })], TableColumn.prototype, "format", void 0);
73
+ __decorate([property({
74
+ converter: jsonPropertyConverter,
75
+ attribute: "format-options"
76
+ })], TableColumn.prototype, "formatOptions", void 0);
77
+ __decorate([property({ type: String })], TableColumn.prototype, "currency", void 0);
78
+ __decorate([property({ type: String })], TableColumn.prototype, "locale", void 0);
79
+ __decorate([property({
80
+ type: String,
81
+ attribute: "cell-class"
82
+ })], TableColumn.prototype, "cellClass", void 0);
83
+ __decorate([property({
84
+ type: Boolean,
85
+ attribute: "cell-slot"
86
+ })], TableColumn.prototype, "cellSlot", void 0);
87
+ __decorate([property({ attribute: false })], TableColumn.prototype, "renderCell", void 0);
88
+ __decorate([property({ attribute: false })], TableColumn.prototype, "renderHeader", void 0);
89
+ __decorate([property({ attribute: false })], TableColumn.prototype, "comparator", void 0);
90
+ TableColumn = __decorate([customElement("c2-table-column")], TableColumn);
91
+ //#endregion
92
+ export { TableColumn as n, __decorate as r, COLUMN_CHANGE_EVENT as t };
@@ -0,0 +1,2 @@
1
+ import { n as TableColumn, t as COLUMN_CHANGE_EVENT } from "./table-column-Dsv4HKrd.js";
2
+ export { COLUMN_CHANGE_EVENT, TableColumn };
@@ -0,0 +1,18 @@
1
+ import { getFieldValue } from "@c2n/core/data-helper.js";
2
+ //#region src/table-types.ts
3
+ /** `name:asc;age:desc` ⇄ `SortModel[]`, so the sort can be set from markup. */
4
+ var sortModelConverter = {
5
+ toAttribute: (value) => Array.isArray(value) && value.length ? value.map((item) => `${item.field}:${item.direction}`).join(";") : null,
6
+ fromAttribute: (value) => {
7
+ if (!value) return [];
8
+ return value.split(";").map((entry) => entry.trim()).filter(Boolean).map((entry) => {
9
+ const [field, direction] = entry.split(":");
10
+ return {
11
+ field: field.trim(),
12
+ direction: direction?.trim() === "desc" ? "desc" : "asc"
13
+ };
14
+ });
15
+ }
16
+ };
17
+ //#endregion
18
+ export { getFieldValue, sortModelConverter };