@oscarpalmer/tabela 0.1.0 → 0.3.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 +49 -0
- package/dist/components/body.component.js +49 -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 +32 -0
- package/dist/components/row.component.js +32 -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/managers/virtualization.manager.cjs +75 -0
- package/dist/managers/virtualization.manager.js +75 -0
- 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 +60 -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 +37 -0
- package/src/helpers/dom.helpers.ts +44 -0
- package/src/index.ts +1 -0
- package/src/managers/virtualization.manager.ts +98 -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 +86 -0
- package/types/components/body.component.d.ts +14 -0
- package/types/components/cell.component.d.cts +86 -0
- package/types/components/cell.component.d.ts +10 -0
- package/types/components/column.component.d.cts +86 -0
- package/types/components/column.component.d.ts +8 -0
- package/types/components/footer.component.d.cts +86 -0
- package/types/components/footer.component.d.ts +8 -0
- package/types/components/header.component.d.cts +86 -0
- package/types/components/header.component.d.ts +9 -0
- package/types/components/row.component.d.cts +86 -0
- package/types/components/row.component.d.ts +11 -0
- package/types/helpers/dom.helpers.d.cts +12 -0
- package/types/helpers/dom.helpers.d.ts +9 -0
- package/types/index.d.cts +84 -0
- package/types/index.d.ts +1 -1
- package/types/managers/virtualization.manager.d.cts +86 -0
- package/types/managers/virtualization.manager.d.ts +10 -0
- 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 +87 -0
- package/types/tabela.d.ts +13 -0
|
@@ -0,0 +1,49 @@
|
|
|
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 managers_virtualization_manager = require("../managers/virtualization.manager.cjs");
|
|
8
|
+
const components_row_component = require("./row.component.cjs");
|
|
9
|
+
function createFaker() {
|
|
10
|
+
const element = document.createElement("div");
|
|
11
|
+
element.style.height = "0";
|
|
12
|
+
element.style.inset = "0 auto auto 0";
|
|
13
|
+
element.style.opacity = "0";
|
|
14
|
+
element.style.pointerEvents = "none";
|
|
15
|
+
element.style.position = "absolute";
|
|
16
|
+
element.style.width = "1px";
|
|
17
|
+
return element;
|
|
18
|
+
}
|
|
19
|
+
class BodyComponent {
|
|
20
|
+
constructor(tabela) {
|
|
21
|
+
__publicField(this, "faker", createFaker());
|
|
22
|
+
__publicField(this, "group");
|
|
23
|
+
__publicField(this, "rows", []);
|
|
24
|
+
__publicField(this, "virtualization");
|
|
25
|
+
this.tabela = tabela;
|
|
26
|
+
this.group = helpers_dom_helpers.createRowGroup(false);
|
|
27
|
+
this.virtualization = new managers_virtualization_manager.VirtualizationManager(this);
|
|
28
|
+
this.group.className += " tabela__rowgroup-body";
|
|
29
|
+
this.group.style.height = "100%";
|
|
30
|
+
this.group.style.overflow = "auto";
|
|
31
|
+
this.group.style.position = "relative";
|
|
32
|
+
this.group.append(this.faker);
|
|
33
|
+
void this.addData(tabela.options.data).then(() => {
|
|
34
|
+
this.virtualization.update(true);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async addData(data) {
|
|
38
|
+
const { length } = data;
|
|
39
|
+
for (let index = 0; index < length; index += 1) {
|
|
40
|
+
this.rows.push(new components_row_component.RowComponent(this.tabela, data[index]));
|
|
41
|
+
}
|
|
42
|
+
this.updateVirtualization();
|
|
43
|
+
}
|
|
44
|
+
updateVirtualization() {
|
|
45
|
+
this.faker.style.height = `${this.rows.length * 32}px`;
|
|
46
|
+
this.virtualization.update(true);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.BodyComponent = BodyComponent;
|
|
@@ -0,0 +1,49 @@
|
|
|
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 { VirtualizationManager } from "../managers/virtualization.manager.js";
|
|
6
|
+
import { RowComponent } from "./row.component.js";
|
|
7
|
+
function createFaker() {
|
|
8
|
+
const element = document.createElement("div");
|
|
9
|
+
element.style.height = "0";
|
|
10
|
+
element.style.inset = "0 auto auto 0";
|
|
11
|
+
element.style.opacity = "0";
|
|
12
|
+
element.style.pointerEvents = "none";
|
|
13
|
+
element.style.position = "absolute";
|
|
14
|
+
element.style.width = "1px";
|
|
15
|
+
return element;
|
|
16
|
+
}
|
|
17
|
+
class BodyComponent {
|
|
18
|
+
constructor(tabela) {
|
|
19
|
+
__publicField(this, "faker", createFaker());
|
|
20
|
+
__publicField(this, "group");
|
|
21
|
+
__publicField(this, "rows", []);
|
|
22
|
+
__publicField(this, "virtualization");
|
|
23
|
+
this.tabela = tabela;
|
|
24
|
+
this.group = createRowGroup(false);
|
|
25
|
+
this.virtualization = new VirtualizationManager(this);
|
|
26
|
+
this.group.className += " tabela__rowgroup-body";
|
|
27
|
+
this.group.style.height = "100%";
|
|
28
|
+
this.group.style.overflow = "auto";
|
|
29
|
+
this.group.style.position = "relative";
|
|
30
|
+
this.group.append(this.faker);
|
|
31
|
+
void this.addData(tabela.options.data).then(() => {
|
|
32
|
+
this.virtualization.update(true);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async addData(data) {
|
|
36
|
+
const { length } = data;
|
|
37
|
+
for (let index = 0; index < length; index += 1) {
|
|
38
|
+
this.rows.push(new RowComponent(this.tabela, data[index]));
|
|
39
|
+
}
|
|
40
|
+
this.updateVirtualization();
|
|
41
|
+
}
|
|
42
|
+
updateVirtualization() {
|
|
43
|
+
this.faker.style.height = `${this.rows.length * 32}px`;
|
|
44
|
+
this.virtualization.update(true);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
BodyComponent
|
|
49
|
+
};
|
|
@@ -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 ?? options.title.length * 1.5);
|
|
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 ?? options.title.length * 1.5);
|
|
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,32 @@
|
|
|
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
|
+
}
|
|
17
|
+
render() {
|
|
18
|
+
if (this.element.innerHTML !== "") {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const { tabela } = this;
|
|
22
|
+
const { columns } = tabela.header;
|
|
23
|
+
const { length } = columns;
|
|
24
|
+
for (let index = 0; index < length; index += 1) {
|
|
25
|
+
const cell = new components_cell_component.CellComponent(tabela, columns[index], this);
|
|
26
|
+
cell.element.className += " tabela__cell-body";
|
|
27
|
+
this.cells.push(cell);
|
|
28
|
+
this.element.append(cell.element);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.RowComponent = RowComponent;
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
if (this.element.innerHTML !== "") {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const { tabela } = this;
|
|
20
|
+
const { columns } = tabela.header;
|
|
21
|
+
const { length } = columns;
|
|
22
|
+
for (let index = 0; index < length; index += 1) {
|
|
23
|
+
const cell = new CellComponent(tabela, columns[index], this);
|
|
24
|
+
cell.element.className += " tabela__cell-body";
|
|
25
|
+
this.cells.push(cell);
|
|
26
|
+
this.element.append(cell.element);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
RowComponent
|
|
32
|
+
};
|
|
@@ -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,75 @@
|
|
|
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 getRange(body, down) {
|
|
7
|
+
const { group, rows } = body;
|
|
8
|
+
const { clientHeight, scrollTop } = group;
|
|
9
|
+
const first = Math.floor(scrollTop / 32);
|
|
10
|
+
const last = Math.min(
|
|
11
|
+
rows.length - 1,
|
|
12
|
+
Math.ceil((scrollTop + clientHeight) / 32) - 1
|
|
13
|
+
);
|
|
14
|
+
const before = Math.ceil(clientHeight / 32) * (down ? 1 : 2);
|
|
15
|
+
const after = Math.ceil(clientHeight / 32) * (down ? 2 : 1);
|
|
16
|
+
const start = Math.max(0, first - before);
|
|
17
|
+
const end = Math.min(rows.length - 1, last + after);
|
|
18
|
+
return { end, start };
|
|
19
|
+
}
|
|
20
|
+
class VirtualizationManager {
|
|
21
|
+
constructor(body) {
|
|
22
|
+
__publicField(this, "active", false);
|
|
23
|
+
__publicField(this, "top", 0);
|
|
24
|
+
__publicField(this, "visible", /* @__PURE__ */ new Map());
|
|
25
|
+
this.body = body;
|
|
26
|
+
this.body.group.addEventListener(
|
|
27
|
+
"scroll",
|
|
28
|
+
() => {
|
|
29
|
+
this.onScroll();
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
passive: true
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
update(down) {
|
|
37
|
+
const { body, visible } = this;
|
|
38
|
+
const indices = /* @__PURE__ */ new Set();
|
|
39
|
+
const range = getRange(body, down);
|
|
40
|
+
for (let index = range.start; index <= range.end; index += 1) {
|
|
41
|
+
indices.add(index);
|
|
42
|
+
}
|
|
43
|
+
for (const [index, row] of visible) {
|
|
44
|
+
if (!indices.has(index)) {
|
|
45
|
+
visible.delete(index);
|
|
46
|
+
row.element.remove();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const fragment = document.createDocumentFragment();
|
|
50
|
+
for (let index = range.start; index <= range.end; index += 1) {
|
|
51
|
+
if (!visible.has(index)) {
|
|
52
|
+
const row = body.rows[index];
|
|
53
|
+
row.element.style.inset = "0 auto auto 0";
|
|
54
|
+
row.element.style.position = "absolute";
|
|
55
|
+
row.element.style.transform = `translateY(${index * 32}px)`;
|
|
56
|
+
row.render();
|
|
57
|
+
visible.set(index, row);
|
|
58
|
+
fragment.append(row.element);
|
|
59
|
+
}
|
|
60
|
+
body.group.append(fragment);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
onScroll() {
|
|
64
|
+
if (!this.active) {
|
|
65
|
+
requestAnimationFrame(() => {
|
|
66
|
+
const top = this.body.group.scrollTop;
|
|
67
|
+
this.update(top > this.top);
|
|
68
|
+
this.active = false;
|
|
69
|
+
this.top = top;
|
|
70
|
+
});
|
|
71
|
+
this.active = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.VirtualizationManager = VirtualizationManager;
|
|
@@ -0,0 +1,75 @@
|
|
|
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 getRange(body, down) {
|
|
5
|
+
const { group, rows } = body;
|
|
6
|
+
const { clientHeight, scrollTop } = group;
|
|
7
|
+
const first = Math.floor(scrollTop / 32);
|
|
8
|
+
const last = Math.min(
|
|
9
|
+
rows.length - 1,
|
|
10
|
+
Math.ceil((scrollTop + clientHeight) / 32) - 1
|
|
11
|
+
);
|
|
12
|
+
const before = Math.ceil(clientHeight / 32) * (down ? 1 : 2);
|
|
13
|
+
const after = Math.ceil(clientHeight / 32) * (down ? 2 : 1);
|
|
14
|
+
const start = Math.max(0, first - before);
|
|
15
|
+
const end = Math.min(rows.length - 1, last + after);
|
|
16
|
+
return { end, start };
|
|
17
|
+
}
|
|
18
|
+
class VirtualizationManager {
|
|
19
|
+
constructor(body) {
|
|
20
|
+
__publicField(this, "active", false);
|
|
21
|
+
__publicField(this, "top", 0);
|
|
22
|
+
__publicField(this, "visible", /* @__PURE__ */ new Map());
|
|
23
|
+
this.body = body;
|
|
24
|
+
this.body.group.addEventListener(
|
|
25
|
+
"scroll",
|
|
26
|
+
() => {
|
|
27
|
+
this.onScroll();
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
passive: true
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
update(down) {
|
|
35
|
+
const { body, visible } = this;
|
|
36
|
+
const indices = /* @__PURE__ */ new Set();
|
|
37
|
+
const range = getRange(body, down);
|
|
38
|
+
for (let index = range.start; index <= range.end; index += 1) {
|
|
39
|
+
indices.add(index);
|
|
40
|
+
}
|
|
41
|
+
for (const [index, row] of visible) {
|
|
42
|
+
if (!indices.has(index)) {
|
|
43
|
+
visible.delete(index);
|
|
44
|
+
row.element.remove();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const fragment = document.createDocumentFragment();
|
|
48
|
+
for (let index = range.start; index <= range.end; index += 1) {
|
|
49
|
+
if (!visible.has(index)) {
|
|
50
|
+
const row = body.rows[index];
|
|
51
|
+
row.element.style.inset = "0 auto auto 0";
|
|
52
|
+
row.element.style.position = "absolute";
|
|
53
|
+
row.element.style.transform = `translateY(${index * 32}px)`;
|
|
54
|
+
row.render();
|
|
55
|
+
visible.set(index, row);
|
|
56
|
+
fragment.append(row.element);
|
|
57
|
+
}
|
|
58
|
+
body.group.append(fragment);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
onScroll() {
|
|
62
|
+
if (!this.active) {
|
|
63
|
+
requestAnimationFrame(() => {
|
|
64
|
+
const top = this.body.group.scrollTop;
|
|
65
|
+
this.update(top > this.top);
|
|
66
|
+
this.active = false;
|
|
67
|
+
this.top = top;
|
|
68
|
+
});
|
|
69
|
+
this.active = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
VirtualizationManager
|
|
75
|
+
};
|
|
@@ -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
|
+
};
|