@human-kit/ui 1.1.1 → 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.
|
@@ -16,6 +16,16 @@ export type CollapseTransition = {
|
|
|
16
16
|
*/
|
|
17
17
|
setPanel: (panel: HTMLElement | null, content?: HTMLElement | null) => void;
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* The content's size without the rounding `scrollHeight`/`scrollWidth` apply.
|
|
21
|
+
*
|
|
22
|
+
* Those are whole pixels: content 57.5px tall measures 58, so an open panel came out half a pixel
|
|
23
|
+
* taller than the same content laid out without the variable (on the server, before hydration),
|
|
24
|
+
* and everything under it moved when the page hydrated. Within a pixel of the laid-out box the
|
|
25
|
+
* scroll size is only that rounding, so the box's own fractional size is the answer; beyond it the
|
|
26
|
+
* content really overflows its box, and the scroll size is what the panel has to open to.
|
|
27
|
+
*/
|
|
28
|
+
export declare function exactSize(scrollSize: number, boxSize: number): number;
|
|
19
29
|
/**
|
|
20
30
|
* Drives a collapsible panel's enter/exit transitions the way Base UI's Collapsible does:
|
|
21
31
|
* - keeps the content mounted for the full exit animation, then unmounts it (or, with
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { trackMotionEnd } from './motion';
|
|
2
|
+
/**
|
|
3
|
+
* The content's size without the rounding `scrollHeight`/`scrollWidth` apply.
|
|
4
|
+
*
|
|
5
|
+
* Those are whole pixels: content 57.5px tall measures 58, so an open panel came out half a pixel
|
|
6
|
+
* taller than the same content laid out without the variable (on the server, before hydration),
|
|
7
|
+
* and everything under it moved when the page hydrated. Within a pixel of the laid-out box the
|
|
8
|
+
* scroll size is only that rounding, so the box's own fractional size is the answer; beyond it the
|
|
9
|
+
* content really overflows its box, and the scroll size is what the panel has to open to.
|
|
10
|
+
*/
|
|
11
|
+
export function exactSize(scrollSize, boxSize) {
|
|
12
|
+
return Math.abs(scrollSize - boxSize) < 1 ? boxSize : scrollSize;
|
|
13
|
+
}
|
|
2
14
|
/**
|
|
3
15
|
* Drives a collapsible panel's enter/exit transitions the way Base UI's Collapsible does:
|
|
4
16
|
* - keeps the content mounted for the full exit animation, then unmounts it (or, with
|
|
@@ -26,8 +38,8 @@ export function createCollapseTransition(open, forceMount) {
|
|
|
26
38
|
// Freeze the size while collapsing so the exit animates from the open height, not from 0.
|
|
27
39
|
if (!measured || status === 'ending')
|
|
28
40
|
return;
|
|
29
|
-
height = measured.scrollHeight;
|
|
30
|
-
width = measured.scrollWidth;
|
|
41
|
+
height = exactSize(measured.scrollHeight, measured.getBoundingClientRect().height);
|
|
42
|
+
width = exactSize(measured.scrollWidth, measured.getBoundingClientRect().width);
|
|
31
43
|
}
|
|
32
44
|
function cancelRelease() {
|
|
33
45
|
if (releaseFrame !== undefined) {
|
|
@@ -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>",
|