@celestia-island/hikari 0.55.294 → 0.55.297
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
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineComponent,
|
|
3
|
-
inject,
|
|
4
|
-
onMounted,
|
|
5
|
-
onUnmounted,
|
|
6
|
-
ref,
|
|
7
|
-
type Component,
|
|
8
|
-
type PropType,
|
|
9
|
-
} from "vue";
|
|
1
|
+
import { defineComponent, type Component, type PropType } from "vue";
|
|
10
2
|
import { HAlert, HCard, HEmptyState, HSpinner, HTable, useI18n } from "@celestia-island/hikari";
|
|
11
3
|
import HkCrossfade from "./HkCrossfade";
|
|
12
4
|
import { HkPageHeader } from "./HkPageHeader";
|
|
13
|
-
import { HK_SCROLL_PROGRESS_REGISTRAR, type HkScrollProgressHandle } from "./HkScrollProgress";
|
|
14
5
|
import type { HkRowManageGate } from "./HkTable";
|
|
15
6
|
|
|
16
7
|
|
|
@@ -76,9 +67,9 @@ export const HkAdminTablePage = defineComponent({
|
|
|
76
67
|
},
|
|
77
68
|
/** Authoritative row total the scroll-progress pill uses as its
|
|
78
69
|
* denominator (the server count behind a paged list — chest's
|
|
79
|
-
* usePagedTableFetch total).
|
|
80
|
-
*
|
|
81
|
-
*
|
|
70
|
+
* usePagedTableFetch total). Forwarded to HTable, which
|
|
71
|
+
* self-registers with the enclosing shell viewport's registrar.
|
|
72
|
+
* Omitted: the pill falls back to counting the delivered DOM rows. */
|
|
82
73
|
total: { type: Number, default: undefined },
|
|
83
74
|
},
|
|
84
75
|
emits: {
|
|
@@ -86,28 +77,6 @@ export const HkAdminTablePage = defineComponent({
|
|
|
86
77
|
manage: (_row: Record<string, unknown>, _opener: HTMLElement) => true,
|
|
87
78
|
},
|
|
88
79
|
setup(props, { emit, slots }) {
|
|
89
|
-
// Scroll-progress registration: the nearest enclosing HkScrollContainer
|
|
90
|
-
// with `scrollProgress` on provides the registrar (provide/inject
|
|
91
|
-
// scoping resolves the shell viewport for admin pages and keeps an
|
|
92
|
-
// inner container's lists out of the shell). The handle exposes the
|
|
93
|
-
// table card as the row root plus the `total` prop live — the pill's
|
|
94
|
-
// denominator follows it as pages load.
|
|
95
|
-
const registrar = inject(HK_SCROLL_PROGRESS_REGISTRAR, null);
|
|
96
|
-
const tableCardRef = ref<HTMLElement | null>(null);
|
|
97
|
-
let handle: HkScrollProgressHandle | null = null;
|
|
98
|
-
onMounted(() => {
|
|
99
|
-
if (!registrar) return;
|
|
100
|
-
handle = {
|
|
101
|
-
getRoot: () => tableCardRef.value,
|
|
102
|
-
getTotal: () => props.total,
|
|
103
|
-
};
|
|
104
|
-
registrar.register(handle);
|
|
105
|
-
});
|
|
106
|
-
onUnmounted(() => {
|
|
107
|
-
if (registrar && handle) registrar.unregister(handle);
|
|
108
|
-
handle = null;
|
|
109
|
-
});
|
|
110
|
-
|
|
111
80
|
return () => {
|
|
112
81
|
const { t } = useI18n();
|
|
113
82
|
const emptyTitle = props.emptyTitle || t("hikari::tablePage.emptyTitle", "No data");
|
|
@@ -165,23 +134,22 @@ export const HkAdminTablePage = defineComponent({
|
|
|
165
134
|
) : slots.body ? (
|
|
166
135
|
<div class="hk-admin-table-page-body">{slots.body()}</div>
|
|
167
136
|
) : (
|
|
168
|
-
<
|
|
169
|
-
<
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
</div>
|
|
137
|
+
<HCard padded={false}>
|
|
138
|
+
<HTable
|
|
139
|
+
columns={props.columns}
|
|
140
|
+
rows={props.rows}
|
|
141
|
+
rowKey={props.rowKey}
|
|
142
|
+
total={props.total}
|
|
143
|
+
draggable={props.draggable}
|
|
144
|
+
manageable={props.manageable}
|
|
145
|
+
onReorder={(from: number, to: number) => emit("reorder", from, to)}
|
|
146
|
+
onManage={(row: Record<string, unknown>, opener: HTMLElement) =>
|
|
147
|
+
emit("manage", row, opener)
|
|
148
|
+
}
|
|
149
|
+
>
|
|
150
|
+
{slots}
|
|
151
|
+
</HTable>
|
|
152
|
+
</HCard>
|
|
185
153
|
)}
|
|
186
154
|
</HkCrossfade>
|
|
187
155
|
{slots["create-modal"]?.()}
|
|
@@ -546,3 +546,118 @@ describe("HkModal chrome / content split", () => {
|
|
|
546
546
|
});
|
|
547
547
|
});
|
|
548
548
|
});
|
|
549
|
+
|
|
550
|
+
describe("HkModal Escape precedence", () => {
|
|
551
|
+
it("lets a nested control own Escape while a bare Escape still closes", async () => {
|
|
552
|
+
const container = document.createElement("div");
|
|
553
|
+
document.body.appendChild(container);
|
|
554
|
+
containers.push(container);
|
|
555
|
+
|
|
556
|
+
const open = ref(true);
|
|
557
|
+
const emitted: boolean[] = [];
|
|
558
|
+
const Wrapper = defineComponent({
|
|
559
|
+
setup() {
|
|
560
|
+
return () =>
|
|
561
|
+
h(HkModal, {
|
|
562
|
+
modelValue: open.value,
|
|
563
|
+
closable: true,
|
|
564
|
+
title: "Escape precedence",
|
|
565
|
+
"onUpdate:modelValue": (v: boolean) => { emitted.push(v); open.value = v; },
|
|
566
|
+
}, {
|
|
567
|
+
default: () => h("div", {
|
|
568
|
+
class: "escape-owner",
|
|
569
|
+
onKeydown: (e: KeyboardEvent) => {
|
|
570
|
+
if (e.key === "Escape") e.preventDefault();
|
|
571
|
+
},
|
|
572
|
+
}, "nested control"),
|
|
573
|
+
});
|
|
574
|
+
},
|
|
575
|
+
});
|
|
576
|
+
const app = createApp(Wrapper);
|
|
577
|
+
mounts.push(app);
|
|
578
|
+
app.mount(container);
|
|
579
|
+
|
|
580
|
+
await vi.waitFor(() => {
|
|
581
|
+
expect(document.body.querySelector(".escape-owner")).not.toBeNull();
|
|
582
|
+
});
|
|
583
|
+
const owner = document.body.querySelector<HTMLElement>(".escape-owner")!;
|
|
584
|
+
|
|
585
|
+
// The nested control consumes Escape: the window must stay open.
|
|
586
|
+
owner.dispatchEvent(
|
|
587
|
+
new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }),
|
|
588
|
+
);
|
|
589
|
+
await nextTick();
|
|
590
|
+
expect(emitted, "a consumed Escape must not close the window").toEqual([]);
|
|
591
|
+
expect(open.value).toBe(true);
|
|
592
|
+
|
|
593
|
+
// A bare Escape (nothing below consumed it) still closes.
|
|
594
|
+
const content = document.body.querySelector<HTMLElement>(".hk-modal-content")!;
|
|
595
|
+
content.dispatchEvent(
|
|
596
|
+
new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }),
|
|
597
|
+
);
|
|
598
|
+
await nextTick();
|
|
599
|
+
expect(emitted).toEqual([false]);
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it("keeps a consumed Escape from reaching page-level Escape listeners", async () => {
|
|
603
|
+
// One press must mean one action: before the precedence rule a closable
|
|
604
|
+
// window swallowed every Escape at its root, so a handled press travelling
|
|
605
|
+
// on would hand the same key to a page-level listener (a revealed strip, a
|
|
606
|
+
// pointer-reorder cancel) while the nested control also acted on it.
|
|
607
|
+
const container = document.createElement("div");
|
|
608
|
+
document.body.appendChild(container);
|
|
609
|
+
containers.push(container);
|
|
610
|
+
const open = ref(true);
|
|
611
|
+
const emitted: boolean[] = [];
|
|
612
|
+
const Wrapper = defineComponent({
|
|
613
|
+
setup() {
|
|
614
|
+
return () =>
|
|
615
|
+
h(HkModal, {
|
|
616
|
+
modelValue: open.value,
|
|
617
|
+
closable: true,
|
|
618
|
+
title: "Escape propagation",
|
|
619
|
+
"onUpdate:modelValue": (v: boolean) => { emitted.push(v); open.value = v; },
|
|
620
|
+
}, {
|
|
621
|
+
default: () => h("div", {
|
|
622
|
+
class: "escape-owner",
|
|
623
|
+
onKeydown: (e: KeyboardEvent) => {
|
|
624
|
+
if (e.key === "Escape") e.preventDefault();
|
|
625
|
+
},
|
|
626
|
+
}, "nested control"),
|
|
627
|
+
});
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
const app = createApp(Wrapper);
|
|
631
|
+
mounts.push(app);
|
|
632
|
+
app.mount(container);
|
|
633
|
+
await vi.waitFor(() => {
|
|
634
|
+
expect(document.body.querySelector(".escape-owner")).not.toBeNull();
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
const pageHits: string[] = [];
|
|
638
|
+
const pageListener = (e: KeyboardEvent) => {
|
|
639
|
+
if (e.key === "Escape") pageHits.push("escape");
|
|
640
|
+
};
|
|
641
|
+
document.addEventListener("keydown", pageListener);
|
|
642
|
+
try {
|
|
643
|
+
const owner = document.body.querySelector<HTMLElement>(".escape-owner")!;
|
|
644
|
+
owner.dispatchEvent(
|
|
645
|
+
new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }),
|
|
646
|
+
);
|
|
647
|
+
await nextTick();
|
|
648
|
+
expect(emitted, "a consumed Escape must not close the window").toEqual([]);
|
|
649
|
+
expect(pageHits, "a consumed Escape must not reach page-level listeners").toEqual([]);
|
|
650
|
+
|
|
651
|
+
// A bare Escape closes AND is still swallowed (the pre-existing rule).
|
|
652
|
+
const content = document.body.querySelector<HTMLElement>(".hk-modal-content")!;
|
|
653
|
+
content.dispatchEvent(
|
|
654
|
+
new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }),
|
|
655
|
+
);
|
|
656
|
+
await nextTick();
|
|
657
|
+
expect(emitted).toEqual([false]);
|
|
658
|
+
expect(pageHits, "a closing Escape is swallowed by the window").toEqual([]);
|
|
659
|
+
} finally {
|
|
660
|
+
document.removeEventListener("keydown", pageListener);
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
});
|
|
@@ -489,6 +489,23 @@ export default defineComponent({
|
|
|
489
489
|
|
|
490
490
|
function onKeydown(e: KeyboardEvent) {
|
|
491
491
|
if (e.key === "Escape") {
|
|
492
|
+
// Cross-component precedence: a nested control that already consumed
|
|
493
|
+
// Escape (the range ribbon's "Escape resets the range" is the live
|
|
494
|
+
// case) owns the key, so the window must not close underneath it.
|
|
495
|
+
// `defaultPrevented` is the DOM-canonical "I handled this" signal for
|
|
496
|
+
// inline, preventDefault-only consumers — the package's pickers and
|
|
497
|
+
// panels instead stopPropagation (or teleport out of this subtree)
|
|
498
|
+
// and therefore never reach this handler either way.
|
|
499
|
+
//
|
|
500
|
+
// Keep swallowing the press here (`stopPropagation`) like a bare
|
|
501
|
+
// Escape does: before this precedence rule, a closable window consumed
|
|
502
|
+
// every Escape at this root, so letting a handled one travel on would
|
|
503
|
+
// hand the same press to page-level Escape listeners (a revealed strip,
|
|
504
|
+
// a pointer-reorder cancel) and produce one-press-two-actions.
|
|
505
|
+
if (e.defaultPrevented) {
|
|
506
|
+
if (props.closable) e.stopPropagation();
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
492
509
|
if (props.closable) {
|
|
493
510
|
e.preventDefault();
|
|
494
511
|
e.stopPropagation();
|
|
@@ -439,11 +439,11 @@ describe("HkAdminTablePage scroll-progress registration", () => {
|
|
|
439
439
|
rects.push(vi.spyOn(viewport, "getBoundingClientRect").mockReturnValue({
|
|
440
440
|
left: 0, top: 0, right: 300, bottom: 400, width: 300, height: 400, x: 0, y: 0,
|
|
441
441
|
} as DOMRect));
|
|
442
|
-
// The list root is
|
|
443
|
-
//
|
|
442
|
+
// The list root is HkTable's own host element — the table
|
|
443
|
+
// self-registers (the page only forwards the total).
|
|
444
444
|
const card = container.querySelector("table");
|
|
445
445
|
expect(card).not.toBeNull();
|
|
446
|
-
const cardHost = container.querySelector<HTMLElement>(".hk-
|
|
446
|
+
const cardHost = container.querySelector<HTMLElement>(".hk-table-host")!;
|
|
447
447
|
expect(cardHost.contains(card!)).toBe(true);
|
|
448
448
|
rects.push(vi.spyOn(cardHost, "getBoundingClientRect").mockReturnValue({
|
|
449
449
|
left: 0, top: -200, right: 300, bottom: 3800, width: 300, height: 4000, x: 0, y: -200,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, defineComponent, onBeforeUnmount, onMounted, ref, watch, type PropType } from "vue";
|
|
1
|
+
import { computed, defineComponent, inject, onBeforeUnmount, onMounted, ref, watch, type PropType } from "vue";
|
|
2
2
|
|
|
3
3
|
import { useI18n } from "../i18n/context";
|
|
4
4
|
import { usePointerReorder } from "../composables/usePointerReorder";
|
|
@@ -10,6 +10,7 @@ import { ancestorZoom } from "../runtime/cssZoom";
|
|
|
10
10
|
import { useClipboardWithToast } from "../runtime/useClipboard";
|
|
11
11
|
import { useToast } from "../runtime/useToast";
|
|
12
12
|
import HkRowActions from "./HkRowActions";
|
|
13
|
+
import { HK_SCROLL_PROGRESS_REGISTRAR, type HkScrollProgressHandle } from "./HkScrollProgress";
|
|
13
14
|
import "./HkTable.scss";
|
|
14
15
|
|
|
15
16
|
interface Column {
|
|
@@ -91,6 +92,14 @@ export default defineComponent({
|
|
|
91
92
|
default: false,
|
|
92
93
|
},
|
|
93
94
|
emptyText: { type: String, default: "" },
|
|
95
|
+
/** Authoritative row total the scroll-progress pill uses as its
|
|
96
|
+
* denominator (the server count behind a paged list). Omitted: the
|
|
97
|
+
* pill falls back to counting the delivered DOM rows. Every HkTable
|
|
98
|
+
* self-registers with the nearest enclosing HkScrollContainer that
|
|
99
|
+
* has `scrollProgress` on — no wrapper needed (2026-11-06: moved
|
|
100
|
+
* here from HkAdminTablePage so the 17 bare-HkTable views inherit
|
|
101
|
+
* the pill too). */
|
|
102
|
+
total: { type: Number, default: undefined },
|
|
94
103
|
},
|
|
95
104
|
emits: {
|
|
96
105
|
"update:selectedRows": (_rows: Record<string, unknown>[]) => true,
|
|
@@ -195,6 +204,24 @@ export default defineComponent({
|
|
|
195
204
|
wrapperScrollbar = null;
|
|
196
205
|
});
|
|
197
206
|
|
|
207
|
+
// Scroll-progress registration: the nearest enclosing HkScrollContainer
|
|
208
|
+
// with `scrollProgress` on provides the registrar (provide/inject
|
|
209
|
+
// scoping resolves the shell viewport for admin pages and keeps an
|
|
210
|
+
// inner container's lists out of the shell). The handle exposes the
|
|
211
|
+
// table host as the row root plus the `total` prop live — the pill's
|
|
212
|
+
// denominator follows it as pages load.
|
|
213
|
+
const progressRegistrar = inject(HK_SCROLL_PROGRESS_REGISTRAR, null);
|
|
214
|
+
const progressHandle: HkScrollProgressHandle = {
|
|
215
|
+
getRoot: () => wrapperHostRef.value ?? null,
|
|
216
|
+
getTotal: () => props.total,
|
|
217
|
+
};
|
|
218
|
+
onMounted(() => {
|
|
219
|
+
progressRegistrar?.register(progressHandle);
|
|
220
|
+
});
|
|
221
|
+
onBeforeUnmount(() => {
|
|
222
|
+
progressRegistrar?.unregister(progressHandle);
|
|
223
|
+
});
|
|
224
|
+
|
|
198
225
|
function getRowKey(row: Record<string, unknown>, index: number): string {
|
|
199
226
|
if (props.rowKey && row[props.rowKey] != null) return String(row[props.rowKey]);
|
|
200
227
|
return String(index);
|