@celestia-island/hikari 0.55.435 → 0.55.436
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/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import { HAlert, HCard, HEmptyState, HSpinner, HTable, useI18n } from "@celestia
|
|
|
3
3
|
import HkCrossfade from "./HkCrossfade";
|
|
4
4
|
import HkScrollProgressDock from "./HkScrollProgressDock";
|
|
5
5
|
import { HkPageHeader } from "./HkPageHeader";
|
|
6
|
-
import type { HkRowManageGate } from "./HkTable";
|
|
6
|
+
import type { HkRowManageGate, HkTableRow } from "./HkTable";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
/** Column definition passed through to HTable. */
|
|
@@ -50,7 +50,7 @@ export const HkAdminTablePage = defineComponent({
|
|
|
50
50
|
/** Refresh failed while rows are still on screen — banner, not a
|
|
51
51
|
* replacement of the table. */
|
|
52
52
|
staleError: { type: String as PropType<string | undefined>, default: undefined },
|
|
53
|
-
rows: { type: Array as PropType<
|
|
53
|
+
rows: { type: Array as PropType<readonly HkTableRow[]>, required: true },
|
|
54
54
|
columns: { type: Array as PropType<HTableColumn[]>, required: true },
|
|
55
55
|
rowKey: { type: String, default: "id" },
|
|
56
56
|
emptyTitle: { type: String, default: "" },
|
|
@@ -92,8 +92,10 @@
|
|
|
92
92
|
.hk-serpentine-hint {
|
|
93
93
|
// In-flow under the lane: an absolutely-positioned hint hung below the
|
|
94
94
|
// box got clipped by the confirmation window's padding (device feedback).
|
|
95
|
+
// The generous top padding keeps the copy clear of the lane stroke —
|
|
96
|
+
// a second device pass showed 8px reading as part of the graphic.
|
|
95
97
|
display: block;
|
|
96
|
-
padding: var(--space-
|
|
98
|
+
padding: var(--space-16, 16px) var(--space-12, 12px) var(--space-4, 4px);
|
|
97
99
|
text-align: center;
|
|
98
100
|
font-size: var(--text-xs, 0.75rem);
|
|
99
101
|
color: rgb(var(--color-muted));
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { createApp, h } from "vue";
|
|
3
|
+
|
|
4
|
+
import { HkAdminTablePage, HkTable, type HkTableSection, type HkTableRow } from "../index";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The L38 row-typing contract. The old `rows: Record<string, unknown>[]`
|
|
8
|
+
* forced every interface-typed row array through a downstream assertion
|
|
9
|
+
* bridge (chest: 43 `tableRows(...)` sites); `rows: readonly HkTableRow[]`
|
|
10
|
+
* (object) accepts interfaces structurally. These pins hold both halves:
|
|
11
|
+
*
|
|
12
|
+
* - TYPE level (enforced by `pnpm build`, which typechecks this file): an
|
|
13
|
+
* interface row array — the exact shape that needed a bridge before —
|
|
14
|
+
* assigns to `rows` and to `HkTableSection.rows` with NO cast anywhere in
|
|
15
|
+
* this file; a `Record<string, unknown>[]` (the legacy bridge output)
|
|
16
|
+
* still assigns (existing call sites keep compiling).
|
|
17
|
+
* - RUNTIME level: interface rows render their column values through the
|
|
18
|
+
* internal `as Record` confinement casts (two, one per pipeline entry),
|
|
19
|
+
* and the row objects reaching cell slots are the consumer's own
|
|
20
|
+
* instances (reference identity — what chest's downstream
|
|
21
|
+
* `tableRows(arr) === arr` pin protects) is preserved by a copy-per-sort
|
|
22
|
+
* pipeline that never clones on input.
|
|
23
|
+
*
|
|
24
|
+
* (Repo test convention: raw createApp + document queries, no
|
|
25
|
+
* @vue/test-utils.)
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** The bridge-needing shape: an interface (NO implicit index signature). */
|
|
29
|
+
interface PanelRow {
|
|
30
|
+
id: string;
|
|
31
|
+
label: string;
|
|
32
|
+
count: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const PANEL_COLUMNS = [
|
|
36
|
+
{ key: "label", title: "Label" },
|
|
37
|
+
{ key: "count", title: "Count" },
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
while (mounts.length) {
|
|
44
|
+
const { app, container } = mounts.pop()!;
|
|
45
|
+
app.unmount();
|
|
46
|
+
container.remove();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function mountRows(rows: readonly HkTableRow[], sections?: HkTableSection[]): HTMLElement {
|
|
51
|
+
const container = document.createElement("div");
|
|
52
|
+
document.body.appendChild(container);
|
|
53
|
+
const app = createApp({
|
|
54
|
+
render: () => h(HkTable, { columns: PANEL_COLUMNS, rows, sections }),
|
|
55
|
+
});
|
|
56
|
+
app.mount(container);
|
|
57
|
+
mounts.push({ app, container });
|
|
58
|
+
return container;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe("HkTable row typing (L38)", () => {
|
|
62
|
+
it("accepts interface-typed rows without any bridge (type level pinned by vue-tsc on this file)", () => {
|
|
63
|
+
// No cast: this exact array needed `tableRows(rows)` before L38.
|
|
64
|
+
const rows: PanelRow[] = [
|
|
65
|
+
{ id: "a", label: "Alpha", count: 2 },
|
|
66
|
+
{ id: "b", label: "Beta", count: 5 },
|
|
67
|
+
];
|
|
68
|
+
const container = mountRows(rows);
|
|
69
|
+
expect(container.textContent).toContain("Alpha");
|
|
70
|
+
expect(container.textContent).toContain("Beta");
|
|
71
|
+
expect(container.textContent).toContain("5");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("accepts interface-typed sections the same way (R3 M2 pin: the rows must be interface-typed ARRAYS, not inline literals)", () => {
|
|
75
|
+
// Inline section-row literals carry implicit index signatures and stay
|
|
76
|
+
// assignable to the OLD Record type too — this pin routes declared
|
|
77
|
+
// `PanelRow[]` consts through `sections` so reverting the widening in
|
|
78
|
+
// HkTableSection fails THIS file's compile (R3 mutation M2 survived
|
|
79
|
+
// the first version of this test for exactly that reason).
|
|
80
|
+
const oneRows: PanelRow[] = [{ id: "a", label: "Alpha", count: 1 }];
|
|
81
|
+
const twoRows: PanelRow[] = [{ id: "b", label: "Beta", count: 7 }];
|
|
82
|
+
const sections: HkTableSection[] = [
|
|
83
|
+
{ key: "one", label: "One", rows: oneRows },
|
|
84
|
+
{ key: "two", label: "Two", rows: twoRows },
|
|
85
|
+
];
|
|
86
|
+
const container = mountRows([], sections);
|
|
87
|
+
expect(container.textContent).toContain("One");
|
|
88
|
+
expect(container.textContent).toContain("Two");
|
|
89
|
+
expect(container.textContent).toContain("Alpha");
|
|
90
|
+
expect(container.textContent).toContain("7");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("keeps accepting legacy Record-typed rows (existing bridge outputs stay assignable)", () => {
|
|
94
|
+
const legacy: Record<string, unknown>[] = [{ id: "x", label: "Legacy", count: 9 }];
|
|
95
|
+
const container = mountRows(legacy);
|
|
96
|
+
expect(container.textContent).toContain("Legacy");
|
|
97
|
+
expect(container.textContent).toContain("9");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("HkTableRow is the object family root (interfaces and Records both count)", () => {
|
|
101
|
+
const rows: HkTableRow[] = [
|
|
102
|
+
{ id: "i", label: "Interface", count: 0 } satisfies PanelRow,
|
|
103
|
+
{ id: "r", label: "Record", count: 0 } as Record<string, unknown>,
|
|
104
|
+
];
|
|
105
|
+
expect(rows.length).toBe(2);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("cell slots receive the consumer's own row instances (reference identity through the confinement casts)", () => {
|
|
109
|
+
// The slot fn's param is CONSUMER-annotated (chest's AvatarSourcesCard
|
|
110
|
+
// pattern); HkTable deliberately declares no slots type, so the
|
|
111
|
+
// annotation faces no contravariance constraint. The row objects ride
|
|
112
|
+
// the pipeline's copy-per-sort arrays BY REFERENCE — sorting copies the
|
|
113
|
+
// array, never the rows.
|
|
114
|
+
const seen: PanelRow[] = [];
|
|
115
|
+
const rows: PanelRow[] = [{ id: "a", label: "Alpha", count: 3 }];
|
|
116
|
+
const container = document.createElement("div");
|
|
117
|
+
document.body.appendChild(container);
|
|
118
|
+
const app = createApp({
|
|
119
|
+
render: () =>
|
|
120
|
+
h(
|
|
121
|
+
HkTable,
|
|
122
|
+
{ columns: PANEL_COLUMNS, rows },
|
|
123
|
+
{
|
|
124
|
+
"cell-count": ({ row, index }: { row: PanelRow; value: unknown; index: number }) => {
|
|
125
|
+
seen.push(row);
|
|
126
|
+
return h("span", {}, `${row.count}x@${index}`);
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
),
|
|
130
|
+
});
|
|
131
|
+
app.mount(container);
|
|
132
|
+
mounts.push({ app, container });
|
|
133
|
+
expect(container.textContent).toContain("Alpha");
|
|
134
|
+
expect(container.textContent).toContain("3x@0");
|
|
135
|
+
expect(seen[0]).toBe(rows[0]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("HkAdminTablePage accepts interface rows too (R5 S2 pin — it forwards rows verbatim to HkTable)", () => {
|
|
139
|
+
// HkAdminTablePage only reads `.length` and forwards `rows={props.rows}`
|
|
140
|
+
// to the widened HkTable, so its own prop must be the SAME family or
|
|
141
|
+
// every chest site routed through it keeps needing the bridge
|
|
142
|
+
// (MyTasksView-style: `interface UserTask` rows). Declared const, not
|
|
143
|
+
// an inline literal, so reverting THIS prop to Record fails the compile.
|
|
144
|
+
const pageRows: PanelRow[] = [
|
|
145
|
+
{ id: "a", label: "PageAlpha", count: 4 },
|
|
146
|
+
{ id: "b", label: "PageBeta", count: 6 },
|
|
147
|
+
];
|
|
148
|
+
const container = document.createElement("div");
|
|
149
|
+
document.body.appendChild(container);
|
|
150
|
+
const app = createApp({
|
|
151
|
+
render: () =>
|
|
152
|
+
h(HkAdminTablePage, {
|
|
153
|
+
title: "Panels",
|
|
154
|
+
columns: PANEL_COLUMNS,
|
|
155
|
+
rows: pageRows,
|
|
156
|
+
rowKey: "id",
|
|
157
|
+
}),
|
|
158
|
+
});
|
|
159
|
+
app.mount(container);
|
|
160
|
+
mounts.push({ app, container });
|
|
161
|
+
expect(container.textContent).toContain("PageAlpha");
|
|
162
|
+
expect(container.textContent).toContain("6");
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -48,9 +48,21 @@ export interface HkTableSection {
|
|
|
48
48
|
key: string;
|
|
49
49
|
/** Default band text; the `section` slot overrides the whole band content. */
|
|
50
50
|
label?: string;
|
|
51
|
-
rows:
|
|
51
|
+
rows: readonly HkTableRow[];
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* The row shape `HkTable` accepts (L38): any object, interfaces included.
|
|
56
|
+
* The old `Record<string, unknown>` forced every consumer whose rows are an
|
|
57
|
+
* `interface` (no implicit index signature) through a downstream assertion
|
|
58
|
+
* bridge — chest carried 43. Indexing is the library's business, not the
|
|
59
|
+
* consumer's, so the prop side is `object` and the ONE `as Record` cast per
|
|
60
|
+
* pipeline entry lives inside this file (search `L38 confinement`); the
|
|
61
|
+
* out-direction payloads (emits, `HkRowManageGate`) stay
|
|
62
|
+
* `Record<string, unknown>` so existing bridges keep compiling.
|
|
63
|
+
*/
|
|
64
|
+
export type HkTableRow = object;
|
|
65
|
+
|
|
54
66
|
/** A section's live display state: the sorted rows plus the flat offset
|
|
55
67
|
* its first row occupies in the concatenation of every section's rows
|
|
56
68
|
* (the index space `reorder` emits and selection walks). */
|
|
@@ -108,7 +120,7 @@ export default defineComponent({
|
|
|
108
120
|
name: "HkTable",
|
|
109
121
|
props: {
|
|
110
122
|
columns: { type: Array as PropType<Column[]>, required: true },
|
|
111
|
-
rows: { type: Array as PropType<
|
|
123
|
+
rows: { type: Array as PropType<readonly HkTableRow[]>, default: () => [] },
|
|
112
124
|
/** Grouped mode: when provided, `rows` is unused and the body renders
|
|
113
125
|
* ONE `<tbody class="hk-table-section-body">` per section, each led by
|
|
114
126
|
* a band row (`<th scope="rowgroup">`, `colspan` = total columns).
|
|
@@ -349,7 +361,7 @@ export default defineComponent({
|
|
|
349
361
|
});
|
|
350
362
|
}
|
|
351
363
|
|
|
352
|
-
const sortedRows = computed(() => sortRows(props.rows));
|
|
364
|
+
const sortedRows = computed(() => sortRows(props.rows as Record<string, unknown>[])); // ts-escape-ok: L38 confinement — the ONE cast on the unsectioned rows entry (interface rows carry no index signature; indexing is ours, not the consumer's)
|
|
353
365
|
|
|
354
366
|
/** The sectioned display plan: each section's rows sorted WITHIN the
|
|
355
367
|
* section, section order untouched, plus the flat offset its first row
|
|
@@ -359,7 +371,7 @@ export default defineComponent({
|
|
|
359
371
|
if (!props.sections) return [];
|
|
360
372
|
let offset = 0;
|
|
361
373
|
return props.sections.map((section, index) => {
|
|
362
|
-
const rows = sortRows(section.rows);
|
|
374
|
+
const rows = sortRows(section.rows as Record<string, unknown>[]); // ts-escape-ok: L38 confinement — the ONE cast on the sectioned rows entry
|
|
363
375
|
const view: SectionView = { section, index, rows, offset };
|
|
364
376
|
offset += rows.length;
|
|
365
377
|
return view;
|
package/src/index.ts
CHANGED
|
@@ -970,7 +970,7 @@ export { default as HkSliderField } from "./components/HkSliderField";
|
|
|
970
970
|
export { default as HkSpinner } from "./components/HkSpinner";
|
|
971
971
|
export { default as HkSupplementInset } from "./components/HkSupplementInset";
|
|
972
972
|
export { default as HkSwitch } from "./components/HkSwitch";
|
|
973
|
-
export { default as HkTable, type HkRowManageGate, type HkTableSection } from "./components/HkTable";
|
|
973
|
+
export { default as HkTable, type HkRowManageGate, type HkTableRow, type HkTableSection } from "./components/HkTable";
|
|
974
974
|
export { default as HkTabs } from "./components/HkTabs";
|
|
975
975
|
export { default as HkTag } from "./components/HkTag";
|
|
976
976
|
export { default as HkTextarea } from "./components/HkTextarea";
|