@human-kit/ui 1.1.2 → 1.1.3
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/table/row/table-row.svelte +11 -13
- package/package.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onDestroy } from 'svelte';
|
|
3
|
-
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
|
|
4
3
|
import {
|
|
5
4
|
setTableRowContext,
|
|
6
5
|
useTableContext,
|
|
@@ -24,9 +23,12 @@
|
|
|
24
23
|
const table = useTableContext();
|
|
25
24
|
const section = useTableSectionContext();
|
|
26
25
|
const rowToken = table.createInstanceToken('row');
|
|
26
|
+
// Plain, not reactive: the epoch below is what announces a change. These used to be a
|
|
27
|
+
// `SvelteSet` and a `SvelteMap` whose indexes were rewritten for every cell after the one that
|
|
28
|
+
// left, so a virtualized row of fourteen columns leaving the viewport made ~100 reactive writes
|
|
29
|
+
// — the whole cost of scrolling a wide table. A row has a handful of cells: `indexOf` over them
|
|
30
|
+
// is cheaper than keeping an index map in step.
|
|
27
31
|
const cellOrder: string[] = [];
|
|
28
|
-
const cellOrderSet = new SvelteSet<string>();
|
|
29
|
-
const cellIndexByToken = new SvelteMap<string, number>();
|
|
30
32
|
const cellElements: Record<string, () => HTMLElement | undefined> = {};
|
|
31
33
|
// Counter-based on purpose: cell indexes are resolved against the live DOM
|
|
32
34
|
// (`rowElement.children`), so order changes are event-like (registration /
|
|
@@ -101,10 +103,8 @@
|
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
function registerCellToken(token: string, getElement?: () => HTMLElement | undefined) {
|
|
104
|
-
const alreadyOrdered =
|
|
106
|
+
const alreadyOrdered = cellOrder.includes(token);
|
|
105
107
|
if (!alreadyOrdered) {
|
|
106
|
-
cellOrderSet.add(token);
|
|
107
|
-
cellIndexByToken.set(token, cellOrder.length);
|
|
108
108
|
cellOrder.push(token);
|
|
109
109
|
}
|
|
110
110
|
if (getElement) {
|
|
@@ -125,17 +125,15 @@
|
|
|
125
125
|
|
|
126
126
|
function unregisterCellToken(token: string) {
|
|
127
127
|
delete cellElements[token];
|
|
128
|
-
const index =
|
|
128
|
+
const index = cellOrder.indexOf(token);
|
|
129
129
|
if (index >= 0) {
|
|
130
130
|
cellOrder.splice(index, 1);
|
|
131
|
-
cellOrderSet.delete(token);
|
|
132
|
-
cellIndexByToken.delete(token);
|
|
133
|
-
for (let nextIndex = index; nextIndex < cellOrder.length; nextIndex += 1) {
|
|
134
|
-
cellIndexByToken.set(cellOrder[nextIndex], nextIndex);
|
|
135
|
-
}
|
|
136
131
|
if (isBodyRow && !tracksDynamicBodyCellOrder) {
|
|
137
132
|
if (bodyCellOrderSealed) {
|
|
138
133
|
promoteBodyCellOrderTracking();
|
|
134
|
+
} else if (index < cellOrder.length) {
|
|
135
|
+
// The cells after it moved down one: the index map used to say so by itself.
|
|
136
|
+
notifyCellOrderChange();
|
|
139
137
|
}
|
|
140
138
|
return;
|
|
141
139
|
}
|
|
@@ -150,7 +148,7 @@
|
|
|
150
148
|
const index = Array.from(rowElement.children).indexOf(element);
|
|
151
149
|
if (index >= 0) return index;
|
|
152
150
|
}
|
|
153
|
-
return
|
|
151
|
+
return cellOrder.indexOf(token);
|
|
154
152
|
}
|
|
155
153
|
|
|
156
154
|
setTableRowContext({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@human-kit/ui",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Accessible, typed UI components for Svelte 5 — shipped as native ESM with per-component subpath exports so bundlers only include what you import.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Agustin Delgado <agustindariodelgado@gmail.com>",
|