@oscarpalmer/tabela 0.1.0 → 0.2.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.
- package/dist/components/body.component.cjs +26 -0
- package/dist/components/body.component.js +26 -0
- package/dist/components/cell.component.cjs +17 -0
- package/dist/components/cell.component.js +17 -0
- package/dist/components/column.component.cjs +27 -0
- package/dist/components/column.component.js +27 -0
- package/dist/components/footer.component.cjs +29 -0
- package/dist/components/footer.component.js +29 -0
- package/dist/components/header.component.cjs +25 -0
- package/dist/components/header.component.js +25 -0
- package/dist/components/row.component.cjs +26 -0
- package/dist/components/row.component.js +26 -0
- package/dist/helpers/dom.helpers.cjs +29 -0
- package/dist/helpers/dom.helpers.js +29 -0
- package/dist/index.cjs +4 -0
- package/dist/index.js +5 -1
- package/dist/models/column.model.cjs +1 -0
- package/dist/models/column.model.js +1 -0
- package/dist/models/tabela.options.cjs +1 -0
- package/dist/models/tabela.options.js +1 -0
- package/dist/tabela.cjs +29 -0
- package/dist/tabela.js +29 -0
- package/package.json +3 -1
- package/src/components/body.component.ts +28 -0
- package/src/components/cell.component.ts +18 -0
- package/src/components/column.component.ts +34 -0
- package/src/components/footer.component.ts +31 -0
- package/src/components/header.component.ts +25 -0
- package/src/components/row.component.ts +30 -0
- package/src/helpers/dom.helpers.ts +44 -0
- package/src/index.ts +1 -0
- package/src/models/column.model.ts +21 -0
- package/src/models/tabela.options.ts +8 -0
- package/src/tabela.ts +30 -0
- package/types/components/body.component.d.cts +73 -0
- package/types/components/body.component.d.ts +10 -0
- package/types/components/cell.component.d.cts +73 -0
- package/types/components/cell.component.d.ts +10 -0
- package/types/components/column.component.d.cts +73 -0
- package/types/components/column.component.d.ts +8 -0
- package/types/components/footer.component.d.cts +73 -0
- package/types/components/footer.component.d.ts +8 -0
- package/types/components/header.component.d.cts +73 -0
- package/types/components/header.component.d.ts +9 -0
- package/types/components/row.component.d.cts +73 -0
- package/types/components/row.component.d.ts +10 -0
- package/types/helpers/dom.helpers.d.cts +12 -0
- package/types/helpers/dom.helpers.d.ts +9 -0
- package/types/index.d.cts +71 -0
- package/types/index.d.ts +1 -1
- package/types/models/column.model.d.cts +17 -0
- package/types/models/column.model.d.ts +13 -0
- package/types/models/tabela.options.d.cts +18 -0
- package/types/models/tabela.options.d.ts +7 -0
- package/types/tabela.d.cts +74 -0
- package/types/tabela.d.ts +13 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const helpers_dom_helpers = require("../helpers/dom.helpers.cjs");
|
|
7
|
+
const components_row_component = require("./row.component.cjs");
|
|
8
|
+
class BodyComponent {
|
|
9
|
+
constructor(tabela) {
|
|
10
|
+
__publicField(this, "group");
|
|
11
|
+
__publicField(this, "rows", []);
|
|
12
|
+
this.tabela = tabela;
|
|
13
|
+
this.group = helpers_dom_helpers.createRowGroup(false);
|
|
14
|
+
this.group.className += " tabela__rowgroup-body";
|
|
15
|
+
this.addData(tabela.options.data);
|
|
16
|
+
}
|
|
17
|
+
addData(data) {
|
|
18
|
+
const { length } = data;
|
|
19
|
+
for (let index = 0; index < length; index += 1) {
|
|
20
|
+
const row = new components_row_component.RowComponent(this.tabela, data[index]);
|
|
21
|
+
this.rows.push(row);
|
|
22
|
+
this.group.append(row.element);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.BodyComponent = BodyComponent;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { createRowGroup } from "../helpers/dom.helpers.js";
|
|
5
|
+
import { RowComponent } from "./row.component.js";
|
|
6
|
+
class BodyComponent {
|
|
7
|
+
constructor(tabela) {
|
|
8
|
+
__publicField(this, "group");
|
|
9
|
+
__publicField(this, "rows", []);
|
|
10
|
+
this.tabela = tabela;
|
|
11
|
+
this.group = createRowGroup(false);
|
|
12
|
+
this.group.className += " tabela__rowgroup-body";
|
|
13
|
+
this.addData(tabela.options.data);
|
|
14
|
+
}
|
|
15
|
+
addData(data) {
|
|
16
|
+
const { length } = data;
|
|
17
|
+
for (let index = 0; index < length; index += 1) {
|
|
18
|
+
const row = new RowComponent(this.tabela, data[index]);
|
|
19
|
+
this.rows.push(row);
|
|
20
|
+
this.group.append(row.element);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
BodyComponent
|
|
26
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const helpers_dom_helpers = require("../helpers/dom.helpers.cjs");
|
|
7
|
+
class CellComponent {
|
|
8
|
+
constructor(tabela, column, row) {
|
|
9
|
+
__publicField(this, "element");
|
|
10
|
+
this.tabela = tabela;
|
|
11
|
+
this.column = column;
|
|
12
|
+
this.row = row;
|
|
13
|
+
this.element = helpers_dom_helpers.createCell(column.options.width);
|
|
14
|
+
this.element.textContent = String(this.row.data[column.options.field]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.CellComponent = CellComponent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { createCell } from "../helpers/dom.helpers.js";
|
|
5
|
+
class CellComponent {
|
|
6
|
+
constructor(tabela, column, row) {
|
|
7
|
+
__publicField(this, "element");
|
|
8
|
+
this.tabela = tabela;
|
|
9
|
+
this.column = column;
|
|
10
|
+
this.row = row;
|
|
11
|
+
this.element = createCell(column.options.width);
|
|
12
|
+
this.element.textContent = String(this.row.data[column.options.field]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
CellComponent
|
|
17
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
function createElement(title, width) {
|
|
7
|
+
const cell = document.createElement("div");
|
|
8
|
+
cell.className = "tabela__heading";
|
|
9
|
+
cell.role = "columnheader";
|
|
10
|
+
cell.style.width = `${width}px`;
|
|
11
|
+
cell.textContent = title;
|
|
12
|
+
return cell;
|
|
13
|
+
}
|
|
14
|
+
class ColumnComponent {
|
|
15
|
+
constructor(tabela, options) {
|
|
16
|
+
__publicField(this, "element");
|
|
17
|
+
__publicField(this, "options");
|
|
18
|
+
this.tabela = tabela;
|
|
19
|
+
const width = Number.parseInt(getComputedStyle(tabela.element).fontSize, 10) * (options.width ?? 4);
|
|
20
|
+
this.options = {
|
|
21
|
+
...options,
|
|
22
|
+
width
|
|
23
|
+
};
|
|
24
|
+
this.element = createElement(options.title, width);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.ColumnComponent = ColumnComponent;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
function createElement(title, width) {
|
|
5
|
+
const cell = document.createElement("div");
|
|
6
|
+
cell.className = "tabela__heading";
|
|
7
|
+
cell.role = "columnheader";
|
|
8
|
+
cell.style.width = `${width}px`;
|
|
9
|
+
cell.textContent = title;
|
|
10
|
+
return cell;
|
|
11
|
+
}
|
|
12
|
+
class ColumnComponent {
|
|
13
|
+
constructor(tabela, options) {
|
|
14
|
+
__publicField(this, "element");
|
|
15
|
+
__publicField(this, "options");
|
|
16
|
+
this.tabela = tabela;
|
|
17
|
+
const width = Number.parseInt(getComputedStyle(tabela.element).fontSize, 10) * (options.width ?? 4);
|
|
18
|
+
this.options = {
|
|
19
|
+
...options,
|
|
20
|
+
width
|
|
21
|
+
};
|
|
22
|
+
this.element = createElement(options.title, width);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
ColumnComponent
|
|
27
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const helpers_dom_helpers = require("../helpers/dom.helpers.cjs");
|
|
7
|
+
class FooterComponent {
|
|
8
|
+
constructor(tabela) {
|
|
9
|
+
__publicField(this, "cells", []);
|
|
10
|
+
__publicField(this, "group");
|
|
11
|
+
__publicField(this, "row");
|
|
12
|
+
this.tabela = tabela;
|
|
13
|
+
const { group, row } = helpers_dom_helpers.createRowGroup();
|
|
14
|
+
this.group = group;
|
|
15
|
+
this.row = row;
|
|
16
|
+
this.group.className += " tabela__rowgroup-footer";
|
|
17
|
+
this.row.className += " tabela__row-footer";
|
|
18
|
+
const { columns } = tabela.header;
|
|
19
|
+
const { length } = columns;
|
|
20
|
+
for (let index = 0; index < length; index += 1) {
|
|
21
|
+
const cell = helpers_dom_helpers.createCell(columns[index].options.width ?? 4);
|
|
22
|
+
cell.className += " tabela__cell-footer";
|
|
23
|
+
cell.innerHTML = " ";
|
|
24
|
+
this.cells.push(cell);
|
|
25
|
+
row.append(cell);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.FooterComponent = FooterComponent;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { createRowGroup, createCell } from "../helpers/dom.helpers.js";
|
|
5
|
+
class FooterComponent {
|
|
6
|
+
constructor(tabela) {
|
|
7
|
+
__publicField(this, "cells", []);
|
|
8
|
+
__publicField(this, "group");
|
|
9
|
+
__publicField(this, "row");
|
|
10
|
+
this.tabela = tabela;
|
|
11
|
+
const { group, row } = createRowGroup();
|
|
12
|
+
this.group = group;
|
|
13
|
+
this.row = row;
|
|
14
|
+
this.group.className += " tabela__rowgroup-footer";
|
|
15
|
+
this.row.className += " tabela__row-footer";
|
|
16
|
+
const { columns } = tabela.header;
|
|
17
|
+
const { length } = columns;
|
|
18
|
+
for (let index = 0; index < length; index += 1) {
|
|
19
|
+
const cell = createCell(columns[index].options.width ?? 4);
|
|
20
|
+
cell.className += " tabela__cell-footer";
|
|
21
|
+
cell.innerHTML = " ";
|
|
22
|
+
this.cells.push(cell);
|
|
23
|
+
row.append(cell);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
FooterComponent
|
|
29
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const helpers_dom_helpers = require("../helpers/dom.helpers.cjs");
|
|
7
|
+
const components_column_component = require("./column.component.cjs");
|
|
8
|
+
class HeaderComponent {
|
|
9
|
+
constructor(tabela) {
|
|
10
|
+
__publicField(this, "columns");
|
|
11
|
+
__publicField(this, "group");
|
|
12
|
+
__publicField(this, "row");
|
|
13
|
+
this.tabela = tabela;
|
|
14
|
+
this.columns = tabela.options.columns.map(
|
|
15
|
+
(column) => new components_column_component.ColumnComponent(tabela, column)
|
|
16
|
+
);
|
|
17
|
+
const { group, row } = helpers_dom_helpers.createRowGroup();
|
|
18
|
+
this.group = group;
|
|
19
|
+
this.row = row;
|
|
20
|
+
this.group.className += " tabela__rowgroup-header";
|
|
21
|
+
this.row.className += " tabela__row-header";
|
|
22
|
+
row.append(...this.columns.map((column) => column.element));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.HeaderComponent = HeaderComponent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { createRowGroup } from "../helpers/dom.helpers.js";
|
|
5
|
+
import { ColumnComponent } from "./column.component.js";
|
|
6
|
+
class HeaderComponent {
|
|
7
|
+
constructor(tabela) {
|
|
8
|
+
__publicField(this, "columns");
|
|
9
|
+
__publicField(this, "group");
|
|
10
|
+
__publicField(this, "row");
|
|
11
|
+
this.tabela = tabela;
|
|
12
|
+
this.columns = tabela.options.columns.map(
|
|
13
|
+
(column) => new ColumnComponent(tabela, column)
|
|
14
|
+
);
|
|
15
|
+
const { group, row } = createRowGroup();
|
|
16
|
+
this.group = group;
|
|
17
|
+
this.row = row;
|
|
18
|
+
this.group.className += " tabela__rowgroup-header";
|
|
19
|
+
this.row.className += " tabela__row-header";
|
|
20
|
+
row.append(...this.columns.map((column) => column.element));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
HeaderComponent
|
|
25
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const helpers_dom_helpers = require("../helpers/dom.helpers.cjs");
|
|
7
|
+
const components_cell_component = require("./cell.component.cjs");
|
|
8
|
+
class RowComponent {
|
|
9
|
+
constructor(tabela, data) {
|
|
10
|
+
__publicField(this, "cells", []);
|
|
11
|
+
__publicField(this, "element");
|
|
12
|
+
this.tabela = tabela;
|
|
13
|
+
this.data = data;
|
|
14
|
+
this.element = helpers_dom_helpers.createRow();
|
|
15
|
+
this.element.className += " tabela__row-body";
|
|
16
|
+
const { columns } = tabela.header;
|
|
17
|
+
const { length } = columns;
|
|
18
|
+
for (let index = 0; index < length; index += 1) {
|
|
19
|
+
const cell = new components_cell_component.CellComponent(tabela, columns[index], this);
|
|
20
|
+
cell.element.className += " tabela__cell-body";
|
|
21
|
+
this.cells.push(cell);
|
|
22
|
+
this.element.append(cell.element);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.RowComponent = RowComponent;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { createRow } from "../helpers/dom.helpers.js";
|
|
5
|
+
import { CellComponent } from "./cell.component.js";
|
|
6
|
+
class RowComponent {
|
|
7
|
+
constructor(tabela, data) {
|
|
8
|
+
__publicField(this, "cells", []);
|
|
9
|
+
__publicField(this, "element");
|
|
10
|
+
this.tabela = tabela;
|
|
11
|
+
this.data = data;
|
|
12
|
+
this.element = createRow();
|
|
13
|
+
this.element.className += " tabela__row-body";
|
|
14
|
+
const { columns } = tabela.header;
|
|
15
|
+
const { length } = columns;
|
|
16
|
+
for (let index = 0; index < length; index += 1) {
|
|
17
|
+
const cell = new CellComponent(tabela, columns[index], this);
|
|
18
|
+
cell.element.className += " tabela__cell-body";
|
|
19
|
+
this.cells.push(cell);
|
|
20
|
+
this.element.append(cell.element);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
RowComponent
|
|
26
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function createCell(width) {
|
|
4
|
+
const cell = document.createElement("div");
|
|
5
|
+
cell.className = "tabela__cell";
|
|
6
|
+
cell.role = "cell";
|
|
7
|
+
cell.style.width = `${width}px`;
|
|
8
|
+
return cell;
|
|
9
|
+
}
|
|
10
|
+
function createRowGroup(withRow) {
|
|
11
|
+
const group = document.createElement("div");
|
|
12
|
+
group.className = "tabela__rowgroup";
|
|
13
|
+
group.role = "rowgroup";
|
|
14
|
+
if (!(withRow ?? true)) {
|
|
15
|
+
return group;
|
|
16
|
+
}
|
|
17
|
+
const row = createRow();
|
|
18
|
+
group.append(row);
|
|
19
|
+
return { group, row };
|
|
20
|
+
}
|
|
21
|
+
function createRow() {
|
|
22
|
+
const row = document.createElement("div");
|
|
23
|
+
row.className = "tabela__row";
|
|
24
|
+
row.role = "row";
|
|
25
|
+
return row;
|
|
26
|
+
}
|
|
27
|
+
exports.createCell = createCell;
|
|
28
|
+
exports.createRow = createRow;
|
|
29
|
+
exports.createRowGroup = createRowGroup;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function createCell(width) {
|
|
2
|
+
const cell = document.createElement("div");
|
|
3
|
+
cell.className = "tabela__cell";
|
|
4
|
+
cell.role = "cell";
|
|
5
|
+
cell.style.width = `${width}px`;
|
|
6
|
+
return cell;
|
|
7
|
+
}
|
|
8
|
+
function createRowGroup(withRow) {
|
|
9
|
+
const group = document.createElement("div");
|
|
10
|
+
group.className = "tabela__rowgroup";
|
|
11
|
+
group.role = "rowgroup";
|
|
12
|
+
if (!(withRow ?? true)) {
|
|
13
|
+
return group;
|
|
14
|
+
}
|
|
15
|
+
const row = createRow();
|
|
16
|
+
group.append(row);
|
|
17
|
+
return { group, row };
|
|
18
|
+
}
|
|
19
|
+
function createRow() {
|
|
20
|
+
const row = document.createElement("div");
|
|
21
|
+
row.className = "tabela__row";
|
|
22
|
+
row.role = "row";
|
|
23
|
+
return row;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
createCell,
|
|
27
|
+
createRow,
|
|
28
|
+
createRowGroup
|
|
29
|
+
};
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/tabela.cjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const components_body_component = require("./components/body.component.cjs");
|
|
7
|
+
const components_footer_component = require("./components/footer.component.cjs");
|
|
8
|
+
const components_header_component = require("./components/header.component.cjs");
|
|
9
|
+
class Tabela {
|
|
10
|
+
constructor(element, options) {
|
|
11
|
+
__publicField(this, "body");
|
|
12
|
+
__publicField(this, "footer");
|
|
13
|
+
__publicField(this, "header");
|
|
14
|
+
this.element = element;
|
|
15
|
+
this.options = options;
|
|
16
|
+
element.role = "table";
|
|
17
|
+
element.classList.add("tabela");
|
|
18
|
+
element.setAttribute("aria-label", options.label);
|
|
19
|
+
this.header = new components_header_component.HeaderComponent(this);
|
|
20
|
+
this.body = new components_body_component.BodyComponent(this);
|
|
21
|
+
this.footer = new components_footer_component.FooterComponent(this);
|
|
22
|
+
element.append(this.header.group, this.body.group, this.footer.group);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function tabela(element, options) {
|
|
26
|
+
return new Tabela(element, options);
|
|
27
|
+
}
|
|
28
|
+
exports.Tabela = Tabela;
|
|
29
|
+
exports.tabela = tabela;
|
package/dist/tabela.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { BodyComponent } from "./components/body.component.js";
|
|
5
|
+
import { FooterComponent } from "./components/footer.component.js";
|
|
6
|
+
import { HeaderComponent } from "./components/header.component.js";
|
|
7
|
+
class Tabela {
|
|
8
|
+
constructor(element, options) {
|
|
9
|
+
__publicField(this, "body");
|
|
10
|
+
__publicField(this, "footer");
|
|
11
|
+
__publicField(this, "header");
|
|
12
|
+
this.element = element;
|
|
13
|
+
this.options = options;
|
|
14
|
+
element.role = "table";
|
|
15
|
+
element.classList.add("tabela");
|
|
16
|
+
element.setAttribute("aria-label", options.label);
|
|
17
|
+
this.header = new HeaderComponent(this);
|
|
18
|
+
this.body = new BodyComponent(this);
|
|
19
|
+
this.footer = new FooterComponent(this);
|
|
20
|
+
element.append(this.header.group, this.body.group, this.footer.group);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function tabela(element, options) {
|
|
24
|
+
return new Tabela(element, options);
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
Tabela,
|
|
28
|
+
tabela
|
|
29
|
+
};
|
package/package.json
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
"description": "A modern table.",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@biomejs/biome": "^1.9",
|
|
9
|
+
"@oscarpalmer/atoms": "^0.89",
|
|
10
|
+
"@oscarpalmer/oui": "^0.8",
|
|
9
11
|
"@types/node": "^22.13",
|
|
10
12
|
"@vitest/coverage-istanbul": "^3",
|
|
11
13
|
"dts-bundle-generator": "^9.5",
|
|
@@ -46,5 +48,5 @@
|
|
|
46
48
|
},
|
|
47
49
|
"type": "module",
|
|
48
50
|
"types": "./types/index.d.cts",
|
|
49
|
-
"version": "0.
|
|
51
|
+
"version": "0.2.0"
|
|
50
52
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type {PlainObject} from '@oscarpalmer/atoms/models';
|
|
2
|
+
import {createRowGroup} from '../helpers/dom.helpers';
|
|
3
|
+
import type {Tabela} from '../tabela';
|
|
4
|
+
import {RowComponent} from './row.component';
|
|
5
|
+
|
|
6
|
+
export class BodyComponent {
|
|
7
|
+
readonly group: HTMLDivElement;
|
|
8
|
+
readonly rows: RowComponent[] = [];
|
|
9
|
+
|
|
10
|
+
constructor(readonly tabela: Tabela) {
|
|
11
|
+
this.group = createRowGroup(false);
|
|
12
|
+
|
|
13
|
+
this.group.className += ' tabela__rowgroup-body';
|
|
14
|
+
|
|
15
|
+
this.addData(tabela.options.data);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
addData(data: PlainObject[]): void {
|
|
19
|
+
const {length} = data;
|
|
20
|
+
|
|
21
|
+
for (let index = 0; index < length; index += 1) {
|
|
22
|
+
const row = new RowComponent(this.tabela, data[index]);
|
|
23
|
+
|
|
24
|
+
this.rows.push(row);
|
|
25
|
+
this.group.append(row.element);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {createCell} from '../helpers/dom.helpers';
|
|
2
|
+
import type {Tabela} from '../tabela';
|
|
3
|
+
import type {ColumnComponent} from './column.component';
|
|
4
|
+
import type {RowComponent} from './row.component';
|
|
5
|
+
|
|
6
|
+
export class CellComponent {
|
|
7
|
+
readonly element: HTMLDivElement;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
readonly tabela: Tabela,
|
|
11
|
+
readonly column: ColumnComponent,
|
|
12
|
+
readonly row: RowComponent,
|
|
13
|
+
) {
|
|
14
|
+
this.element = createCell(column.options.width);
|
|
15
|
+
|
|
16
|
+
this.element.textContent = String(this.row.data[column.options.field]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {TabelaColumn, TabelaColumnOptions} from '../models/column.model';
|
|
2
|
+
import type {Tabela} from '../tabela';
|
|
3
|
+
|
|
4
|
+
function createElement(title: string, width: number): HTMLDivElement {
|
|
5
|
+
const cell = document.createElement('div');
|
|
6
|
+
|
|
7
|
+
cell.className = 'tabela__heading';
|
|
8
|
+
cell.role = 'columnheader';
|
|
9
|
+
cell.style.width = `${width}px`;
|
|
10
|
+
cell.textContent = title;
|
|
11
|
+
|
|
12
|
+
return cell;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class ColumnComponent {
|
|
16
|
+
readonly element: HTMLDivElement;
|
|
17
|
+
readonly options: TabelaColumn;
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
readonly tabela: Tabela,
|
|
21
|
+
options: TabelaColumnOptions,
|
|
22
|
+
) {
|
|
23
|
+
const width =
|
|
24
|
+
Number.parseInt(getComputedStyle(tabela.element).fontSize, 10) *
|
|
25
|
+
(options.width ?? 4);
|
|
26
|
+
|
|
27
|
+
this.options = {
|
|
28
|
+
...options,
|
|
29
|
+
width,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
this.element = createElement(options.title, width);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {createCell, createRowGroup} from '../helpers/dom.helpers';
|
|
2
|
+
import type {Tabela} from '../tabela';
|
|
3
|
+
|
|
4
|
+
export class FooterComponent {
|
|
5
|
+
readonly cells: HTMLDivElement[] = [];
|
|
6
|
+
readonly group: HTMLDivElement;
|
|
7
|
+
readonly row: HTMLDivElement;
|
|
8
|
+
|
|
9
|
+
constructor(readonly tabela: Tabela) {
|
|
10
|
+
const {group, row} = createRowGroup();
|
|
11
|
+
|
|
12
|
+
this.group = group;
|
|
13
|
+
this.row = row;
|
|
14
|
+
|
|
15
|
+
this.group.className += ' tabela__rowgroup-footer';
|
|
16
|
+
this.row.className += ' tabela__row-footer';
|
|
17
|
+
|
|
18
|
+
const {columns} = tabela.header;
|
|
19
|
+
const {length} = columns;
|
|
20
|
+
|
|
21
|
+
for (let index = 0; index < length; index += 1) {
|
|
22
|
+
const cell = createCell(columns[index].options.width ?? 4);
|
|
23
|
+
|
|
24
|
+
cell.className += ' tabela__cell-footer';
|
|
25
|
+
cell.innerHTML = ' ';
|
|
26
|
+
|
|
27
|
+
this.cells.push(cell);
|
|
28
|
+
row.append(cell);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {createRowGroup} from '../helpers/dom.helpers';
|
|
2
|
+
import type {Tabela} from '../tabela';
|
|
3
|
+
import {ColumnComponent} from './column.component';
|
|
4
|
+
|
|
5
|
+
export class HeaderComponent {
|
|
6
|
+
readonly columns: ColumnComponent[];
|
|
7
|
+
readonly group: HTMLDivElement;
|
|
8
|
+
readonly row: HTMLDivElement;
|
|
9
|
+
|
|
10
|
+
constructor(readonly tabela: Tabela) {
|
|
11
|
+
this.columns = tabela.options.columns.map(
|
|
12
|
+
column => new ColumnComponent(tabela, column),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const {group, row} = createRowGroup();
|
|
16
|
+
|
|
17
|
+
this.group = group;
|
|
18
|
+
this.row = row;
|
|
19
|
+
|
|
20
|
+
this.group.className += ' tabela__rowgroup-header';
|
|
21
|
+
this.row.className += ' tabela__row-header';
|
|
22
|
+
|
|
23
|
+
row.append(...this.columns.map(column => column.element));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type {PlainObject} from '@oscarpalmer/atoms/models';
|
|
2
|
+
import {createRow} from '../helpers/dom.helpers';
|
|
3
|
+
import type {Tabela} from '../tabela';
|
|
4
|
+
import {CellComponent} from './cell.component';
|
|
5
|
+
|
|
6
|
+
export class RowComponent {
|
|
7
|
+
readonly cells: CellComponent[] = [];
|
|
8
|
+
readonly element: HTMLDivElement;
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
readonly tabela: Tabela,
|
|
12
|
+
readonly data: PlainObject,
|
|
13
|
+
) {
|
|
14
|
+
this.element = createRow();
|
|
15
|
+
|
|
16
|
+
this.element.className += ' tabela__row-body';
|
|
17
|
+
|
|
18
|
+
const {columns} = tabela.header;
|
|
19
|
+
const {length} = columns;
|
|
20
|
+
|
|
21
|
+
for (let index = 0; index < length; index += 1) {
|
|
22
|
+
const cell = new CellComponent(tabela, columns[index], this);
|
|
23
|
+
|
|
24
|
+
cell.element.className += ' tabela__cell-body';
|
|
25
|
+
|
|
26
|
+
this.cells.push(cell);
|
|
27
|
+
this.element.append(cell.element);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|