@oscarpalmer/tabela 0.3.0 → 0.4.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 +18 -9
- package/dist/components/body.component.js +18 -9
- package/dist/components/footer.component.cjs +15 -9
- package/dist/components/footer.component.js +15 -9
- package/dist/components/header.component.cjs +9 -6
- package/dist/components/header.component.js +9 -6
- package/dist/components/row.component.cjs +17 -11
- package/dist/components/row.component.js +18 -12
- package/dist/helpers/dom.helpers.cjs +10 -3
- package/dist/helpers/dom.helpers.js +10 -3
- package/dist/managers/virtualization.manager.cjs +25 -12
- package/dist/managers/virtualization.manager.js +25 -12
- package/dist/tabela.cjs +19 -1
- package/dist/tabela.js +19 -1
- package/package.json +7 -7
- package/src/components/body.component.ts +27 -9
- package/src/components/footer.component.ts +22 -9
- package/src/components/header.component.ts +15 -6
- package/src/components/row.component.ts +36 -23
- package/src/helpers/dom.helpers.ts +12 -3
- package/src/managers/virtualization.manager.ts +38 -13
- package/src/tabela.ts +39 -15
- package/types/components/body.component.d.cts +47 -35
- package/types/components/body.component.d.ts +7 -2
- package/types/components/column.component.d.cts +47 -35
- package/types/components/footer.component.d.cts +47 -35
- package/types/components/footer.component.d.ts +8 -3
- package/types/components/header.component.d.cts +47 -35
- package/types/components/header.component.d.ts +7 -2
- package/types/components/row.component.d.cts +47 -35
- package/types/components/row.component.d.ts +4 -4
- package/types/helpers/dom.helpers.d.cts +2 -2
- package/types/helpers/dom.helpers.d.ts +2 -2
- package/types/index.d.cts +47 -35
- package/types/managers/virtualization.manager.d.cts +47 -35
- package/types/managers/virtualization.manager.d.ts +6 -0
- package/types/tabela.d.cts +47 -35
- package/types/tabela.d.ts +2 -1
- package/dist/components/cell.component.cjs +0 -17
- package/dist/components/cell.component.js +0 -17
- package/src/components/cell.component.ts +0 -18
- package/types/components/cell.component.d.cts +0 -86
- package/types/components/cell.component.d.ts +0 -10
|
@@ -18,18 +18,21 @@ function createFaker() {
|
|
|
18
18
|
}
|
|
19
19
|
class BodyComponent {
|
|
20
20
|
constructor(tabela) {
|
|
21
|
-
__publicField(this, "
|
|
22
|
-
|
|
21
|
+
__publicField(this, "elements", {
|
|
22
|
+
faker: createFaker(),
|
|
23
|
+
group: void 0
|
|
24
|
+
});
|
|
23
25
|
__publicField(this, "rows", []);
|
|
24
26
|
__publicField(this, "virtualization");
|
|
25
27
|
this.tabela = tabela;
|
|
26
|
-
|
|
28
|
+
const group = helpers_dom_helpers.createRowGroup(false);
|
|
29
|
+
this.elements.group = group;
|
|
27
30
|
this.virtualization = new managers_virtualization_manager.VirtualizationManager(this);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
group.className += " tabela__rowgroup-body";
|
|
32
|
+
group.style.height = "100%";
|
|
33
|
+
group.style.overflow = "auto";
|
|
34
|
+
group.style.position = "relative";
|
|
35
|
+
group.append(this.elements.faker);
|
|
33
36
|
void this.addData(tabela.options.data).then(() => {
|
|
34
37
|
this.virtualization.update(true);
|
|
35
38
|
});
|
|
@@ -41,8 +44,14 @@ class BodyComponent {
|
|
|
41
44
|
}
|
|
42
45
|
this.updateVirtualization();
|
|
43
46
|
}
|
|
47
|
+
destroy() {
|
|
48
|
+
this.virtualization.destroy();
|
|
49
|
+
this.elements.faker = void 0;
|
|
50
|
+
this.elements.group = void 0;
|
|
51
|
+
this.rows.length = 0;
|
|
52
|
+
}
|
|
44
53
|
updateVirtualization() {
|
|
45
|
-
this.faker.style.height = `${this.rows.length * 32}px`;
|
|
54
|
+
this.elements.faker.style.height = `${this.rows.length * 32}px`;
|
|
46
55
|
this.virtualization.update(true);
|
|
47
56
|
}
|
|
48
57
|
}
|
|
@@ -16,18 +16,21 @@ function createFaker() {
|
|
|
16
16
|
}
|
|
17
17
|
class BodyComponent {
|
|
18
18
|
constructor(tabela) {
|
|
19
|
-
__publicField(this, "
|
|
20
|
-
|
|
19
|
+
__publicField(this, "elements", {
|
|
20
|
+
faker: createFaker(),
|
|
21
|
+
group: void 0
|
|
22
|
+
});
|
|
21
23
|
__publicField(this, "rows", []);
|
|
22
24
|
__publicField(this, "virtualization");
|
|
23
25
|
this.tabela = tabela;
|
|
24
|
-
|
|
26
|
+
const group = createRowGroup(false);
|
|
27
|
+
this.elements.group = group;
|
|
25
28
|
this.virtualization = new VirtualizationManager(this);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
group.className += " tabela__rowgroup-body";
|
|
30
|
+
group.style.height = "100%";
|
|
31
|
+
group.style.overflow = "auto";
|
|
32
|
+
group.style.position = "relative";
|
|
33
|
+
group.append(this.elements.faker);
|
|
31
34
|
void this.addData(tabela.options.data).then(() => {
|
|
32
35
|
this.virtualization.update(true);
|
|
33
36
|
});
|
|
@@ -39,8 +42,14 @@ class BodyComponent {
|
|
|
39
42
|
}
|
|
40
43
|
this.updateVirtualization();
|
|
41
44
|
}
|
|
45
|
+
destroy() {
|
|
46
|
+
this.virtualization.destroy();
|
|
47
|
+
this.elements.faker = void 0;
|
|
48
|
+
this.elements.group = void 0;
|
|
49
|
+
this.rows.length = 0;
|
|
50
|
+
}
|
|
42
51
|
updateVirtualization() {
|
|
43
|
-
this.faker.style.height = `${this.rows.length * 32}px`;
|
|
52
|
+
this.elements.faker.style.height = `${this.rows.length * 32}px`;
|
|
44
53
|
this.virtualization.update(true);
|
|
45
54
|
}
|
|
46
55
|
}
|
|
@@ -6,24 +6,30 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
6
6
|
const helpers_dom_helpers = require("../helpers/dom.helpers.cjs");
|
|
7
7
|
class FooterComponent {
|
|
8
8
|
constructor(tabela) {
|
|
9
|
-
__publicField(this, "
|
|
10
|
-
__publicField(this, "group");
|
|
11
|
-
__publicField(this, "row");
|
|
9
|
+
__publicField(this, "elements");
|
|
12
10
|
this.tabela = tabela;
|
|
13
11
|
const { group, row } = helpers_dom_helpers.createRowGroup();
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
this.elements = {
|
|
13
|
+
group,
|
|
14
|
+
row,
|
|
15
|
+
cells: []
|
|
16
|
+
};
|
|
17
|
+
group.className += " tabela__rowgroup-footer";
|
|
18
|
+
row.className += " tabela__row-footer";
|
|
18
19
|
const { columns } = tabela.header;
|
|
19
20
|
const { length } = columns;
|
|
20
21
|
for (let index = 0; index < length; index += 1) {
|
|
21
|
-
const cell = helpers_dom_helpers.createCell(columns[index].options.width ?? 4);
|
|
22
|
+
const cell = helpers_dom_helpers.createCell(columns[index].options.width ?? 4, false);
|
|
22
23
|
cell.className += " tabela__cell-footer";
|
|
23
24
|
cell.innerHTML = " ";
|
|
24
|
-
this.cells.push(cell);
|
|
25
|
+
this.elements.cells.push(cell);
|
|
25
26
|
row.append(cell);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
29
|
+
destroy() {
|
|
30
|
+
this.elements.cells = [];
|
|
31
|
+
this.elements.group = void 0;
|
|
32
|
+
this.elements.row = void 0;
|
|
33
|
+
}
|
|
28
34
|
}
|
|
29
35
|
exports.FooterComponent = FooterComponent;
|
|
@@ -4,25 +4,31 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4
4
|
import { createRowGroup, createCell } from "../helpers/dom.helpers.js";
|
|
5
5
|
class FooterComponent {
|
|
6
6
|
constructor(tabela) {
|
|
7
|
-
__publicField(this, "
|
|
8
|
-
__publicField(this, "group");
|
|
9
|
-
__publicField(this, "row");
|
|
7
|
+
__publicField(this, "elements");
|
|
10
8
|
this.tabela = tabela;
|
|
11
9
|
const { group, row } = createRowGroup();
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
this.elements = {
|
|
11
|
+
group,
|
|
12
|
+
row,
|
|
13
|
+
cells: []
|
|
14
|
+
};
|
|
15
|
+
group.className += " tabela__rowgroup-footer";
|
|
16
|
+
row.className += " tabela__row-footer";
|
|
16
17
|
const { columns } = tabela.header;
|
|
17
18
|
const { length } = columns;
|
|
18
19
|
for (let index = 0; index < length; index += 1) {
|
|
19
|
-
const cell = createCell(columns[index].options.width ?? 4);
|
|
20
|
+
const cell = createCell(columns[index].options.width ?? 4, false);
|
|
20
21
|
cell.className += " tabela__cell-footer";
|
|
21
22
|
cell.innerHTML = " ";
|
|
22
|
-
this.cells.push(cell);
|
|
23
|
+
this.elements.cells.push(cell);
|
|
23
24
|
row.append(cell);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
27
|
+
destroy() {
|
|
28
|
+
this.elements.cells = [];
|
|
29
|
+
this.elements.group = void 0;
|
|
30
|
+
this.elements.row = void 0;
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
export {
|
|
28
34
|
FooterComponent
|
|
@@ -8,18 +8,21 @@ const components_column_component = require("./column.component.cjs");
|
|
|
8
8
|
class HeaderComponent {
|
|
9
9
|
constructor(tabela) {
|
|
10
10
|
__publicField(this, "columns");
|
|
11
|
-
__publicField(this, "
|
|
12
|
-
__publicField(this, "row");
|
|
11
|
+
__publicField(this, "elements");
|
|
13
12
|
this.tabela = tabela;
|
|
14
13
|
this.columns = tabela.options.columns.map(
|
|
15
14
|
(column) => new components_column_component.ColumnComponent(tabela, column)
|
|
16
15
|
);
|
|
17
16
|
const { group, row } = helpers_dom_helpers.createRowGroup();
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.row.className += " tabela__row-header";
|
|
17
|
+
this.elements = { group, row };
|
|
18
|
+
group.className += " tabela__rowgroup-header";
|
|
19
|
+
row.className += " tabela__row-header";
|
|
22
20
|
row.append(...this.columns.map((column) => column.element));
|
|
23
21
|
}
|
|
22
|
+
destroy() {
|
|
23
|
+
this.columns.length = 0;
|
|
24
|
+
this.elements.group = void 0;
|
|
25
|
+
this.elements.row = void 0;
|
|
26
|
+
}
|
|
24
27
|
}
|
|
25
28
|
exports.HeaderComponent = HeaderComponent;
|
|
@@ -6,19 +6,22 @@ import { ColumnComponent } from "./column.component.js";
|
|
|
6
6
|
class HeaderComponent {
|
|
7
7
|
constructor(tabela) {
|
|
8
8
|
__publicField(this, "columns");
|
|
9
|
-
__publicField(this, "
|
|
10
|
-
__publicField(this, "row");
|
|
9
|
+
__publicField(this, "elements");
|
|
11
10
|
this.tabela = tabela;
|
|
12
11
|
this.columns = tabela.options.columns.map(
|
|
13
12
|
(column) => new ColumnComponent(tabela, column)
|
|
14
13
|
);
|
|
15
14
|
const { group, row } = createRowGroup();
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.row.className += " tabela__row-header";
|
|
15
|
+
this.elements = { group, row };
|
|
16
|
+
group.className += " tabela__rowgroup-header";
|
|
17
|
+
row.className += " tabela__row-header";
|
|
20
18
|
row.append(...this.columns.map((column) => column.element));
|
|
21
19
|
}
|
|
20
|
+
destroy() {
|
|
21
|
+
this.columns.length = 0;
|
|
22
|
+
this.elements.group = void 0;
|
|
23
|
+
this.elements.row = void 0;
|
|
24
|
+
}
|
|
22
25
|
}
|
|
23
26
|
export {
|
|
24
27
|
HeaderComponent
|
|
@@ -4,28 +4,34 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
6
|
const helpers_dom_helpers = require("../helpers/dom.helpers.cjs");
|
|
7
|
-
const components_cell_component = require("./cell.component.cjs");
|
|
8
7
|
class RowComponent {
|
|
9
8
|
constructor(tabela, data) {
|
|
10
|
-
__publicField(this, "cells", []);
|
|
11
9
|
__publicField(this, "element");
|
|
12
10
|
this.tabela = tabela;
|
|
13
11
|
this.data = data;
|
|
14
|
-
this.element = helpers_dom_helpers.createRow();
|
|
15
|
-
this.element.className += " tabela__row-body";
|
|
16
12
|
}
|
|
17
|
-
|
|
18
|
-
if (this.element
|
|
19
|
-
|
|
13
|
+
remove(pool) {
|
|
14
|
+
if (this.element != null) {
|
|
15
|
+
this.element.innerHTML = "";
|
|
16
|
+
pool.rows.push(this.element);
|
|
17
|
+
this.element.remove();
|
|
18
|
+
this.element = void 0;
|
|
20
19
|
}
|
|
20
|
+
}
|
|
21
|
+
render(pool) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const element = this.element ?? pool.rows.shift() ?? helpers_dom_helpers.createRow();
|
|
24
|
+
this.element = element;
|
|
25
|
+
element.innerHTML = "";
|
|
21
26
|
const { tabela } = this;
|
|
22
27
|
const { columns } = tabela.header;
|
|
23
28
|
const { length } = columns;
|
|
24
29
|
for (let index = 0; index < length; index += 1) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.
|
|
30
|
+
const { options } = columns[index];
|
|
31
|
+
(_a = pool.cells)[_b = options.field] ?? (_a[_b] = []);
|
|
32
|
+
const cell = pool.cells[columns[index].options.field].shift() ?? helpers_dom_helpers.createCell(options.width);
|
|
33
|
+
cell.textContent = String(this.data[options.field]);
|
|
34
|
+
element.append(cell);
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
}
|
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
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";
|
|
4
|
+
import { createRow, createCell } from "../helpers/dom.helpers.js";
|
|
6
5
|
class RowComponent {
|
|
7
6
|
constructor(tabela, data) {
|
|
8
|
-
__publicField(this, "cells", []);
|
|
9
7
|
__publicField(this, "element");
|
|
10
8
|
this.tabela = tabela;
|
|
11
9
|
this.data = data;
|
|
12
|
-
this.element = createRow();
|
|
13
|
-
this.element.className += " tabela__row-body";
|
|
14
10
|
}
|
|
15
|
-
|
|
16
|
-
if (this.element
|
|
17
|
-
|
|
11
|
+
remove(pool) {
|
|
12
|
+
if (this.element != null) {
|
|
13
|
+
this.element.innerHTML = "";
|
|
14
|
+
pool.rows.push(this.element);
|
|
15
|
+
this.element.remove();
|
|
16
|
+
this.element = void 0;
|
|
18
17
|
}
|
|
18
|
+
}
|
|
19
|
+
render(pool) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const element = this.element ?? pool.rows.shift() ?? createRow();
|
|
22
|
+
this.element = element;
|
|
23
|
+
element.innerHTML = "";
|
|
19
24
|
const { tabela } = this;
|
|
20
25
|
const { columns } = tabela.header;
|
|
21
26
|
const { length } = columns;
|
|
22
27
|
for (let index = 0; index < length; index += 1) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.
|
|
28
|
+
const { options } = columns[index];
|
|
29
|
+
(_a = pool.cells)[_b = options.field] ?? (_a[_b] = []);
|
|
30
|
+
const cell = pool.cells[columns[index].options.field].shift() ?? createCell(options.width);
|
|
31
|
+
cell.textContent = String(this.data[options.field]);
|
|
32
|
+
element.append(cell);
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
35
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
function createCell(width) {
|
|
3
|
+
function createCell(width, body) {
|
|
4
4
|
const cell = document.createElement("div");
|
|
5
5
|
cell.className = "tabela__cell";
|
|
6
6
|
cell.role = "cell";
|
|
7
7
|
cell.style.width = `${width}px`;
|
|
8
|
+
if (body ?? true) {
|
|
9
|
+
cell.classList.add("tabela__cell-body");
|
|
10
|
+
}
|
|
8
11
|
return cell;
|
|
9
12
|
}
|
|
10
13
|
function createRowGroup(withRow) {
|
|
@@ -14,14 +17,18 @@ function createRowGroup(withRow) {
|
|
|
14
17
|
if (!(withRow ?? true)) {
|
|
15
18
|
return group;
|
|
16
19
|
}
|
|
17
|
-
const row = createRow();
|
|
20
|
+
const row = createRow(false);
|
|
18
21
|
group.append(row);
|
|
19
22
|
return { group, row };
|
|
20
23
|
}
|
|
21
|
-
function createRow() {
|
|
24
|
+
function createRow(withStyle) {
|
|
22
25
|
const row = document.createElement("div");
|
|
23
26
|
row.className = "tabela__row";
|
|
24
27
|
row.role = "row";
|
|
28
|
+
if (withStyle ?? true) {
|
|
29
|
+
row.style.inset = "0 auto auto 0";
|
|
30
|
+
row.style.position = "absolute";
|
|
31
|
+
}
|
|
25
32
|
return row;
|
|
26
33
|
}
|
|
27
34
|
exports.createCell = createCell;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
function createCell(width) {
|
|
1
|
+
function createCell(width, body) {
|
|
2
2
|
const cell = document.createElement("div");
|
|
3
3
|
cell.className = "tabela__cell";
|
|
4
4
|
cell.role = "cell";
|
|
5
5
|
cell.style.width = `${width}px`;
|
|
6
|
+
if (body ?? true) {
|
|
7
|
+
cell.classList.add("tabela__cell-body");
|
|
8
|
+
}
|
|
6
9
|
return cell;
|
|
7
10
|
}
|
|
8
11
|
function createRowGroup(withRow) {
|
|
@@ -12,14 +15,18 @@ function createRowGroup(withRow) {
|
|
|
12
15
|
if (!(withRow ?? true)) {
|
|
13
16
|
return group;
|
|
14
17
|
}
|
|
15
|
-
const row = createRow();
|
|
18
|
+
const row = createRow(false);
|
|
16
19
|
group.append(row);
|
|
17
20
|
return { group, row };
|
|
18
21
|
}
|
|
19
|
-
function createRow() {
|
|
22
|
+
function createRow(withStyle) {
|
|
20
23
|
const row = document.createElement("div");
|
|
21
24
|
row.className = "tabela__row";
|
|
22
25
|
row.role = "row";
|
|
26
|
+
if (withStyle ?? true) {
|
|
27
|
+
row.style.inset = "0 auto auto 0";
|
|
28
|
+
row.style.position = "absolute";
|
|
29
|
+
}
|
|
23
30
|
return row;
|
|
24
31
|
}
|
|
25
32
|
export {
|
|
@@ -4,8 +4,8 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
6
|
function getRange(body, down) {
|
|
7
|
-
const {
|
|
8
|
-
const { clientHeight, scrollTop } = group;
|
|
7
|
+
const { elements, rows } = body;
|
|
8
|
+
const { clientHeight, scrollTop } = elements.group;
|
|
9
9
|
const first = Math.floor(scrollTop / 32);
|
|
10
10
|
const last = Math.min(
|
|
11
11
|
rows.length - 1,
|
|
@@ -20,10 +20,14 @@ function getRange(body, down) {
|
|
|
20
20
|
class VirtualizationManager {
|
|
21
21
|
constructor(body) {
|
|
22
22
|
__publicField(this, "active", false);
|
|
23
|
+
__publicField(this, "pool", {
|
|
24
|
+
cells: {},
|
|
25
|
+
rows: []
|
|
26
|
+
});
|
|
23
27
|
__publicField(this, "top", 0);
|
|
24
28
|
__publicField(this, "visible", /* @__PURE__ */ new Map());
|
|
25
29
|
this.body = body;
|
|
26
|
-
this.body.group.addEventListener(
|
|
30
|
+
this.body.elements.group.addEventListener(
|
|
27
31
|
"scroll",
|
|
28
32
|
() => {
|
|
29
33
|
this.onScroll();
|
|
@@ -33,8 +37,17 @@ class VirtualizationManager {
|
|
|
33
37
|
}
|
|
34
38
|
);
|
|
35
39
|
}
|
|
40
|
+
destroy() {
|
|
41
|
+
const { visible, pool } = this;
|
|
42
|
+
for (const [index, row] of visible) {
|
|
43
|
+
row.remove(pool);
|
|
44
|
+
visible.delete(index);
|
|
45
|
+
}
|
|
46
|
+
pool.cells = {};
|
|
47
|
+
pool.rows = [];
|
|
48
|
+
}
|
|
36
49
|
update(down) {
|
|
37
|
-
const { body, visible } = this;
|
|
50
|
+
const { body, pool, visible } = this;
|
|
38
51
|
const indices = /* @__PURE__ */ new Set();
|
|
39
52
|
const range = getRange(body, down);
|
|
40
53
|
for (let index = range.start; index <= range.end; index += 1) {
|
|
@@ -43,27 +56,27 @@ class VirtualizationManager {
|
|
|
43
56
|
for (const [index, row] of visible) {
|
|
44
57
|
if (!indices.has(index)) {
|
|
45
58
|
visible.delete(index);
|
|
46
|
-
row.
|
|
59
|
+
row.remove(pool);
|
|
47
60
|
}
|
|
48
61
|
}
|
|
49
62
|
const fragment = document.createDocumentFragment();
|
|
50
63
|
for (let index = range.start; index <= range.end; index += 1) {
|
|
51
64
|
if (!visible.has(index)) {
|
|
52
65
|
const row = body.rows[index];
|
|
53
|
-
row.
|
|
54
|
-
row.element.style.position = "absolute";
|
|
55
|
-
row.element.style.transform = `translateY(${index * 32}px)`;
|
|
56
|
-
row.render();
|
|
66
|
+
row.render(pool);
|
|
57
67
|
visible.set(index, row);
|
|
58
|
-
|
|
68
|
+
if (row.element != null) {
|
|
69
|
+
row.element.style.transform = `translateY(${index * 32}px)`;
|
|
70
|
+
fragment.append(row.element);
|
|
71
|
+
}
|
|
59
72
|
}
|
|
60
|
-
body.group.append(fragment);
|
|
73
|
+
body.elements.group.append(fragment);
|
|
61
74
|
}
|
|
62
75
|
}
|
|
63
76
|
onScroll() {
|
|
64
77
|
if (!this.active) {
|
|
65
78
|
requestAnimationFrame(() => {
|
|
66
|
-
const top = this.body.group.scrollTop;
|
|
79
|
+
const top = this.body.elements.group.scrollTop;
|
|
67
80
|
this.update(top > this.top);
|
|
68
81
|
this.active = false;
|
|
69
82
|
this.top = top;
|
|
@@ -2,8 +2,8 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
function getRange(body, down) {
|
|
5
|
-
const {
|
|
6
|
-
const { clientHeight, scrollTop } = group;
|
|
5
|
+
const { elements, rows } = body;
|
|
6
|
+
const { clientHeight, scrollTop } = elements.group;
|
|
7
7
|
const first = Math.floor(scrollTop / 32);
|
|
8
8
|
const last = Math.min(
|
|
9
9
|
rows.length - 1,
|
|
@@ -18,10 +18,14 @@ function getRange(body, down) {
|
|
|
18
18
|
class VirtualizationManager {
|
|
19
19
|
constructor(body) {
|
|
20
20
|
__publicField(this, "active", false);
|
|
21
|
+
__publicField(this, "pool", {
|
|
22
|
+
cells: {},
|
|
23
|
+
rows: []
|
|
24
|
+
});
|
|
21
25
|
__publicField(this, "top", 0);
|
|
22
26
|
__publicField(this, "visible", /* @__PURE__ */ new Map());
|
|
23
27
|
this.body = body;
|
|
24
|
-
this.body.group.addEventListener(
|
|
28
|
+
this.body.elements.group.addEventListener(
|
|
25
29
|
"scroll",
|
|
26
30
|
() => {
|
|
27
31
|
this.onScroll();
|
|
@@ -31,8 +35,17 @@ class VirtualizationManager {
|
|
|
31
35
|
}
|
|
32
36
|
);
|
|
33
37
|
}
|
|
38
|
+
destroy() {
|
|
39
|
+
const { visible, pool } = this;
|
|
40
|
+
for (const [index, row] of visible) {
|
|
41
|
+
row.remove(pool);
|
|
42
|
+
visible.delete(index);
|
|
43
|
+
}
|
|
44
|
+
pool.cells = {};
|
|
45
|
+
pool.rows = [];
|
|
46
|
+
}
|
|
34
47
|
update(down) {
|
|
35
|
-
const { body, visible } = this;
|
|
48
|
+
const { body, pool, visible } = this;
|
|
36
49
|
const indices = /* @__PURE__ */ new Set();
|
|
37
50
|
const range = getRange(body, down);
|
|
38
51
|
for (let index = range.start; index <= range.end; index += 1) {
|
|
@@ -41,27 +54,27 @@ class VirtualizationManager {
|
|
|
41
54
|
for (const [index, row] of visible) {
|
|
42
55
|
if (!indices.has(index)) {
|
|
43
56
|
visible.delete(index);
|
|
44
|
-
row.
|
|
57
|
+
row.remove(pool);
|
|
45
58
|
}
|
|
46
59
|
}
|
|
47
60
|
const fragment = document.createDocumentFragment();
|
|
48
61
|
for (let index = range.start; index <= range.end; index += 1) {
|
|
49
62
|
if (!visible.has(index)) {
|
|
50
63
|
const row = body.rows[index];
|
|
51
|
-
row.
|
|
52
|
-
row.element.style.position = "absolute";
|
|
53
|
-
row.element.style.transform = `translateY(${index * 32}px)`;
|
|
54
|
-
row.render();
|
|
64
|
+
row.render(pool);
|
|
55
65
|
visible.set(index, row);
|
|
56
|
-
|
|
66
|
+
if (row.element != null) {
|
|
67
|
+
row.element.style.transform = `translateY(${index * 32}px)`;
|
|
68
|
+
fragment.append(row.element);
|
|
69
|
+
}
|
|
57
70
|
}
|
|
58
|
-
body.group.append(fragment);
|
|
71
|
+
body.elements.group.append(fragment);
|
|
59
72
|
}
|
|
60
73
|
}
|
|
61
74
|
onScroll() {
|
|
62
75
|
if (!this.active) {
|
|
63
76
|
requestAnimationFrame(() => {
|
|
64
|
-
const top = this.body.group.scrollTop;
|
|
77
|
+
const top = this.body.elements.group.scrollTop;
|
|
65
78
|
this.update(top > this.top);
|
|
66
79
|
this.active = false;
|
|
67
80
|
this.top = top;
|
package/dist/tabela.cjs
CHANGED
|
@@ -13,13 +13,31 @@ class Tabela {
|
|
|
13
13
|
__publicField(this, "header");
|
|
14
14
|
this.element = element;
|
|
15
15
|
this.options = options;
|
|
16
|
+
element.innerHTML = "";
|
|
16
17
|
element.role = "table";
|
|
17
18
|
element.classList.add("tabela");
|
|
18
19
|
element.setAttribute("aria-label", options.label);
|
|
19
20
|
this.header = new components_header_component.HeaderComponent(this);
|
|
20
21
|
this.body = new components_body_component.BodyComponent(this);
|
|
21
22
|
this.footer = new components_footer_component.FooterComponent(this);
|
|
22
|
-
element.append(
|
|
23
|
+
element.append(
|
|
24
|
+
this.header.elements.group,
|
|
25
|
+
this.body.elements.group,
|
|
26
|
+
this.footer.elements.group
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
destroy() {
|
|
30
|
+
this.body.destroy();
|
|
31
|
+
this.footer.destroy();
|
|
32
|
+
this.header.destroy();
|
|
33
|
+
this.options.columns = [];
|
|
34
|
+
this.options.data = [];
|
|
35
|
+
this.element.innerHTML = "";
|
|
36
|
+
this.element.role = "";
|
|
37
|
+
this.element.classList.remove("tabela");
|
|
38
|
+
this.element.removeAttribute("aria-label");
|
|
39
|
+
this.element.removeAttribute("role");
|
|
40
|
+
this.element = void 0;
|
|
23
41
|
}
|
|
24
42
|
}
|
|
25
43
|
function tabela(element, options) {
|
package/dist/tabela.js
CHANGED
|
@@ -11,13 +11,31 @@ class Tabela {
|
|
|
11
11
|
__publicField(this, "header");
|
|
12
12
|
this.element = element;
|
|
13
13
|
this.options = options;
|
|
14
|
+
element.innerHTML = "";
|
|
14
15
|
element.role = "table";
|
|
15
16
|
element.classList.add("tabela");
|
|
16
17
|
element.setAttribute("aria-label", options.label);
|
|
17
18
|
this.header = new HeaderComponent(this);
|
|
18
19
|
this.body = new BodyComponent(this);
|
|
19
20
|
this.footer = new FooterComponent(this);
|
|
20
|
-
element.append(
|
|
21
|
+
element.append(
|
|
22
|
+
this.header.elements.group,
|
|
23
|
+
this.body.elements.group,
|
|
24
|
+
this.footer.elements.group
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
destroy() {
|
|
28
|
+
this.body.destroy();
|
|
29
|
+
this.footer.destroy();
|
|
30
|
+
this.header.destroy();
|
|
31
|
+
this.options.columns = [];
|
|
32
|
+
this.options.data = [];
|
|
33
|
+
this.element.innerHTML = "";
|
|
34
|
+
this.element.role = "";
|
|
35
|
+
this.element.classList.remove("tabela");
|
|
36
|
+
this.element.removeAttribute("aria-label");
|
|
37
|
+
this.element.removeAttribute("role");
|
|
38
|
+
this.element = void 0;
|
|
21
39
|
}
|
|
22
40
|
}
|
|
23
41
|
function tabela(element, options) {
|
package/package.json
CHANGED
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
"description": "A modern table.",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@biomejs/biome": "^1.9",
|
|
9
|
-
"@oscarpalmer/atoms": "^0.
|
|
10
|
-
"@oscarpalmer/oui": "^0.
|
|
11
|
-
"@types/node": "^22.
|
|
12
|
-
"@vitest/coverage-istanbul": "^3",
|
|
9
|
+
"@oscarpalmer/atoms": "^0.95",
|
|
10
|
+
"@oscarpalmer/oui": "^0.9",
|
|
11
|
+
"@types/node": "^22.14",
|
|
12
|
+
"@vitest/coverage-istanbul": "^3.1",
|
|
13
13
|
"dts-bundle-generator": "^9.5",
|
|
14
14
|
"glob": "^11",
|
|
15
15
|
"happy-dom": "^17.4",
|
|
16
16
|
"typescript": "^5.8",
|
|
17
|
-
"vite": "^6.
|
|
18
|
-
"vitest": "^3"
|
|
17
|
+
"vite": "^6.3",
|
|
18
|
+
"vitest": "^3.1"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
},
|
|
49
49
|
"type": "module",
|
|
50
50
|
"types": "./types/index.d.cts",
|
|
51
|
-
"version": "0.
|
|
51
|
+
"version": "0.4.0"
|
|
52
52
|
}
|