@celestia-island/hikari 0.55.519 → 0.55.521
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/types/components/HkDirectionalSwap.d.ts +53 -6
- package/dist/types/components/HkInput.d.ts +1 -1
- package/dist/types/components/HkMarkdownEditor.d.ts +33 -30
- package/dist/types/components/HkMenu.d.ts +1 -1
- package/dist/types/components/HkPillToggleGroup.d.ts +13 -0
- package/dist/types/components/HkRowActions.d.ts +1 -1
- package/dist/types/components/HkTable.d.ts +1 -1
- package/dist/types/components/HkTimePicker.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/HkDirectionalSwap.test.tsx +614 -23
- package/src/components/HkDirectionalSwap.tsx +219 -26
- package/src/components/HkMarkdownEditor.barrel.test.ts +3 -3
- package/src/components/HkMarkdownEditor.rails.test.tsx +103 -0
- package/src/components/HkMarkdownEditor.scss +72 -89
- package/src/components/HkMarkdownEditor.test.tsx +319 -45
- package/src/components/HkMarkdownEditor.tsx +152 -90
- package/src/components/HkPillToggleGroup.scss +9 -2
- package/src/components/HkPillToggleGroup.test.tsx +36 -0
- package/src/components/HkPillToggleGroup.tsx +11 -2
- package/src/components/HkScrollProgressDock.scss +71 -2
- package/src/components/HkScrollProgressDock.test.tsx +508 -1
- package/src/components/HkScrollProgressDock.tsx +424 -40
- package/src/components/HkThemeToggle.test.ts +32 -1
- package/src/errorLandingStandalone/error-landing.html +1 -1
- package/src/i18n/locales/ar/components.json +9 -3
- package/src/i18n/locales/de/components.json +9 -3
- package/src/i18n/locales/en/components.json +9 -3
- package/src/i18n/locales/es/components.json +9 -3
- package/src/i18n/locales/fr/components.json +9 -3
- package/src/i18n/locales/ja/components.json +9 -3
- package/src/i18n/locales/ko/components.json +9 -3
- package/src/i18n/locales/pt/components.json +9 -3
- package/src/i18n/locales/ru/components.json +9 -3
- package/src/i18n/locales/zh-Hans/components.json +9 -3
- package/src/i18n/locales/zh-Hant/components.json +9 -3
- package/src/index.ts +1 -1
- package/src/res/themeLoaderBehaviour.test.ts +27 -0
|
@@ -44,14 +44,39 @@
|
|
|
44
44
|
* still snaps — taller the moment the exchange starts, shorter the
|
|
45
45
|
* frame it ends (measured on the docs shell's preview/source card,
|
|
46
46
|
* 2026-11-29: 360px → 278px in ONE frame). With the prop on, the
|
|
47
|
-
* wrapper
|
|
48
|
-
*
|
|
49
|
-
*
|
|
47
|
+
* wrapper tweens from the height it had BEFORE the incoming copy
|
|
48
|
+
* inserted (read in the leaving copy's before-hook — by the enter
|
|
49
|
+
* hook the row has already grown to the taller generation) to the
|
|
50
|
+
* incoming generation's OWN height (read with the item un-stretched:
|
|
51
|
+
* a grid item renders at the row's height, i.e. the outgoing copy's),
|
|
52
|
+
* over the same duration/easing as the travel, and releases back to
|
|
53
|
+
* auto once BOTH the enter has settled AND no leaving copy remains in
|
|
54
|
+
* the cell — either alone would jump. Reduced motion (duration 0)
|
|
50
55
|
* keeps the snap — the instant change IS that preference. A faster
|
|
51
56
|
* follow-up swap interrupts the running exchange: Vue cancels the
|
|
52
|
-
* enter
|
|
53
|
-
*
|
|
54
|
-
*
|
|
57
|
+
* enter, the tween STAYS ARMED at its animated mid-state, the next
|
|
58
|
+
* before-leave reads that as its start, and the next enter re-freezes
|
|
59
|
+
* from it without a jump. The Transition's own teardown (the host
|
|
60
|
+
* flipping to `disabled`, a watchdog sweep, unmount) is what releases
|
|
61
|
+
* a stranded tween.
|
|
62
|
+
* - The first cut of this tween (2026-11-29) never ran in a browser:
|
|
63
|
+
* it read BOTH ends after the insertion, so `from` and `target` were
|
|
64
|
+
* the same stretched row height and the whole change happened at the
|
|
65
|
+
* release (measured live 2026-11-30: writes 200px → 200px, the host
|
|
66
|
+
* flat for the exchange, a 200 → 189 snap the frame it ended). The
|
|
67
|
+
* tests were green because happy-dom has no layout and the stubbed
|
|
68
|
+
* heights ignored the stretch; they now model the grid (see the
|
|
69
|
+
* `stubGrid` pins).
|
|
70
|
+
* - Two contracts the tween assumes of its host. (a) Hosts do not pin
|
|
71
|
+
* `height`/`min-height` on `.hk-dswap-item`: an explicit box defeats
|
|
72
|
+
* the un-stretched read — the read returns the pin, and a pin at the
|
|
73
|
+
* row is the no-op again (see `readUnstretchedHeight`); hosts size
|
|
74
|
+
* the pane, the item's child. (b) The host is BORDER-BOX with no
|
|
75
|
+
* padding or border of its own: `offsetHeight` is a border-box figure
|
|
76
|
+
* and is written into `height`, which under `box-sizing: content-box`
|
|
77
|
+
* is the content box — a padded or bordered `.hk-dswap` would offset
|
|
78
|
+
* the tween by its box extra (the docs shell's host is border-box with
|
|
79
|
+
* neither, so the target path is exact).
|
|
55
80
|
*/
|
|
56
81
|
|
|
57
82
|
import { defineComponent, onBeforeUnmount, ref, Transition, watch, type PropType, type VNode } from "vue";
|
|
@@ -97,6 +122,37 @@ export function resolveSwapDirection(
|
|
|
97
122
|
return b < a ? "back" : "forward";
|
|
98
123
|
}
|
|
99
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Read a grid item's OWN content height. Under the cell's geometry a
|
|
127
|
+
* grid item stretches to the row (the taller generation), so its
|
|
128
|
+
* rendered height is the outgoing copy's; `align-self: start` sizes it
|
|
129
|
+
* to its content for the read. The item's inline `align-self` is put
|
|
130
|
+
* back exactly as it was — value AND priority — so a style the item
|
|
131
|
+
* arrived with survives. Exported for its own pin: the swap creates the
|
|
132
|
+
* item in the same tick its enter hook reads it, so no test can hand it
|
|
133
|
+
* a prior inline style through the component.
|
|
134
|
+
*
|
|
135
|
+
* CONTRACT: the item's box belongs to the component — hosts must not pin
|
|
136
|
+
* `height` or `min-height` on `.hk-dswap-item`. Un-stretching defeats the
|
|
137
|
+
* ROW, not an explicit box: a pinned item reads its PIN — the explicit
|
|
138
|
+
* box wins over both the row stretch and the content height — and a pin
|
|
139
|
+
* at the row turns the tween back into the no-op this component just
|
|
140
|
+
* fixed (measured, Chrome 155, R5: with the item pinned to the row's
|
|
141
|
+
* 240px, stretched and un-stretched both read 240 while the content is
|
|
142
|
+
* 100). Hosts size the PANE (the item's child); that is where the docs
|
|
143
|
+
* shell's band-fill lives, and this read runs before its attribute
|
|
144
|
+
* exists.
|
|
145
|
+
*/
|
|
146
|
+
export function readUnstretchedHeight(item: HTMLElement): number {
|
|
147
|
+
const prior = item.style.getPropertyValue("align-self");
|
|
148
|
+
const priority = item.style.getPropertyPriority("align-self");
|
|
149
|
+
item.style.alignSelf = "start";
|
|
150
|
+
const height = item.offsetHeight;
|
|
151
|
+
if (prior) item.style.setProperty("align-self", prior, priority);
|
|
152
|
+
else item.style.removeProperty("align-self");
|
|
153
|
+
return height;
|
|
154
|
+
}
|
|
155
|
+
|
|
100
156
|
export default defineComponent({
|
|
101
157
|
name: "HkDirectionalSwap",
|
|
102
158
|
props: {
|
|
@@ -182,44 +238,139 @@ export default defineComponent({
|
|
|
182
238
|
// `hostProps.style` object above — Vue patches style keys it rendered
|
|
183
239
|
// and would silently reset our inline tween height on the next render;
|
|
184
240
|
// these writes live outside the vnode on purpose.
|
|
185
|
-
/**
|
|
186
|
-
*
|
|
241
|
+
/** The exchange's START height: the host as it stood before the
|
|
242
|
+
* incoming copy inserted, read in the leaving copy's before-hook —
|
|
243
|
+
* the last moment the cell holds the outgoing generation alone. By
|
|
244
|
+
* the enter hook it is too late: the insertion has already grown
|
|
245
|
+
* the row to the taller generation (measured live: the host reads
|
|
246
|
+
* 189 at rest and 200 the instant the taller copy lands). With a
|
|
247
|
+
* leaving copy still in the cell the host's `offsetHeight` is the
|
|
248
|
+
* ROW (the taller copy), not the rendered height — so this read is
|
|
249
|
+
* only true while the tween is still ARMED (an interrupted exchange
|
|
250
|
+
* reads its animated mid-state here) or while the cell holds one
|
|
251
|
+
* generation (a swap from rest). Null until a leave arms it; a
|
|
252
|
+
* leave-less enter (none today — the component renders no `appear`)
|
|
253
|
+
* falls back to the host's own height. Consumed by the next begin,
|
|
254
|
+
* whatever it then decides; cleared again by the Transition's
|
|
255
|
+
* teardown and the watchdog sweep. */
|
|
256
|
+
let restHeight: number | null = null;
|
|
257
|
+
/** The running exchange's settled state. The explicit height
|
|
258
|
+
* releases only when the enter has settled (the tween is at its
|
|
259
|
+
* target) AND no leaving copy remains (the cell's `auto` resolves
|
|
260
|
+
* to that target); see `settleHeightAnimation`. */
|
|
261
|
+
let enterSettled = false;
|
|
262
|
+
let leaving = 0;
|
|
263
|
+
/** The element the armed tween lives on and the inline height it
|
|
264
|
+
* wrote there (see `endHeightAnimation`). */
|
|
265
|
+
let armedHost: HTMLElement | null = null;
|
|
266
|
+
let armedHeight = "";
|
|
267
|
+
|
|
268
|
+
/** Arm the tween: freeze the wrapper at the pre-insertion height,
|
|
269
|
+
* flush, then step to the incoming generation's own height — the
|
|
187
270
|
* forced layout between the two writes is what makes them a
|
|
188
271
|
* before/after pair. No-ops when the prop is off, the effective
|
|
189
272
|
* duration is zero (reduced motion keeps the snap by design), or
|
|
190
273
|
* either height is unreadable (a hidden or not-yet-laid-out surface
|
|
191
274
|
* reports 0 — animating to/from 0 would collapse the card; the snap
|
|
192
|
-
* is the safe face there, same as reduced motion).
|
|
193
|
-
* follow-up swap arrives after Vue cancelled the interrupted enter
|
|
194
|
-
* (the release runs), so its freeze reads the cell's CURRENT layout
|
|
195
|
-
* height — the interrupted tween's mid-state — never the old start. */
|
|
275
|
+
* is the safe face there, same as reduced motion). */
|
|
196
276
|
function beginHeightAnimation(incoming: Element): void {
|
|
277
|
+
// Consumed first, unconditionally: a value read for THIS exchange
|
|
278
|
+
// must never survive into the next one, whatever returns below.
|
|
279
|
+
const start = restHeight;
|
|
280
|
+
restHeight = null;
|
|
197
281
|
if (!props.animateHeight) return;
|
|
198
282
|
if (motionDuration() === 0) return;
|
|
199
283
|
const host = hostRef.value;
|
|
200
284
|
if (!host) return;
|
|
201
|
-
const
|
|
202
|
-
|
|
285
|
+
const item = incoming as HTMLElement;
|
|
286
|
+
// The cell's grid items STRETCH to the row, and the row is the
|
|
287
|
+
// taller generation — so the incoming item's rendered height is
|
|
288
|
+
// the OUTGOING copy's (measured live on the docs shell's card:
|
|
289
|
+
// both copies read 200 while the incoming pane is 189; the tween
|
|
290
|
+
// wrote 200px → 200px and never ran). Read it un-stretched; item
|
|
291
|
+
// alignment does not move the row (content-sized), so the host
|
|
292
|
+
// read below is unaffected.
|
|
293
|
+
const target = readUnstretchedHeight(item);
|
|
294
|
+
const from = start ?? host.offsetHeight;
|
|
203
295
|
if (from === 0 || target === 0) return;
|
|
204
296
|
host.style.height = `${from}px`;
|
|
205
297
|
// Flush so the frozen height is the transition's computed start
|
|
206
298
|
// (a same-frame change from auto would jump instead of tween).
|
|
207
299
|
void host.offsetHeight;
|
|
300
|
+
armedHost = host;
|
|
301
|
+
armedHeight = `${target}px`;
|
|
208
302
|
host.setAttribute("data-height-anim", "");
|
|
209
|
-
host.style.height =
|
|
303
|
+
host.style.height = armedHeight;
|
|
210
304
|
}
|
|
211
305
|
|
|
212
306
|
/** Release the explicit height back to auto and disarm the
|
|
213
307
|
* transition. Guarded on the armed attribute so it only ever
|
|
214
308
|
* unwinds THIS component's own writes: an unarmed call (default-off
|
|
215
309
|
* host, or a second after-hook) must leave a host's own inline
|
|
216
|
-
* height alone
|
|
310
|
+
* height alone — and so must a release that finds the host's
|
|
311
|
+
* inline height no longer the value this component wrote (a host
|
|
312
|
+
* that sized itself mid-exchange keeps its own number; only the
|
|
313
|
+
* arm is undone). Falls back to the element the tween was armed
|
|
314
|
+
* on: the component's own unmount nulls `hostRef` on the host vnode
|
|
315
|
+
* BEFORE the Transition child's teardown hook runs (Vue's `unmount`
|
|
316
|
+
* sets the ref, then unmounts the children), so a release keyed on
|
|
317
|
+
* the ref alone is a no-op exactly on that path (R6 measured the
|
|
318
|
+
* detached host keeping `data-height-anim` and its inline height).
|
|
319
|
+
* A node a host re-inserts (keep-alive, a manual move) must not
|
|
320
|
+
* come back frozen. */
|
|
217
321
|
function endHeightAnimation(): void {
|
|
218
|
-
const host = hostRef.value;
|
|
322
|
+
const host = hostRef.value ?? armedHost;
|
|
219
323
|
if (!host) return;
|
|
220
324
|
if (!host.hasAttribute("data-height-anim")) return;
|
|
221
325
|
host.removeAttribute("data-height-anim");
|
|
222
|
-
|
|
326
|
+
// Compared by value: this component writes integer px (offsetHeight
|
|
327
|
+
// is an integer), and a numeric compare is immune to how a browser
|
|
328
|
+
// re-serialises either side on read-back.
|
|
329
|
+
if (parseFloat(host.style.height) === parseFloat(armedHeight)) host.style.height = "";
|
|
330
|
+
armedHost = null;
|
|
331
|
+
armedHeight = "";
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** Release once the exchange has fully settled — the incoming
|
|
335
|
+
* copy's own transition at its end, and every leaving copy out of
|
|
336
|
+
* the cell. Releasing on either settle alone jumps: before the
|
|
337
|
+
* enter ends, from the mid-tween height to `auto`; with a leaving
|
|
338
|
+
* copy still present, to the taller row it still holds. Whichever
|
|
339
|
+
* hook fires LAST does the release. The order is the engine's, not
|
|
340
|
+
* this component's to pick — it is deterministic per engine (Vue's
|
|
341
|
+
* leave `done` removes the copy BEFORE `onAfterLeave`, and a
|
|
342
|
+
* same-length leave resolves first in this Chromium), but nothing
|
|
343
|
+
* here may lean on it. One path leans on the ENTER's release: a
|
|
344
|
+
* keep-alive deactivation skips the teardown, and the leaving copy's
|
|
345
|
+
* after-leave arrives with its element already detached — in the
|
|
346
|
+
* measured path it was the entering copy's timer that carried the
|
|
347
|
+
* release of a deactivated host (R7); a refactor that drops the
|
|
348
|
+
* enter side of this guard could freeze one. */
|
|
349
|
+
function settleHeightAnimation(): void {
|
|
350
|
+
if (!enterSettled || leaving > 0) return;
|
|
351
|
+
endHeightAnimation();
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** The Transition itself is going away — the host flipped to the
|
|
355
|
+
* `disabled`/suppressed branch, or the whole component unmounts.
|
|
356
|
+
* No hook of the exchange will ever run again, so an armed tween
|
|
357
|
+
* releases HERE. (R2 of the first cut: keeping the tween armed
|
|
358
|
+
* through a cancelled enter is what lets a follow-up freeze read
|
|
359
|
+
* the mid-state, and THIS is the other half of that bargain —
|
|
360
|
+
* without it a mid-exchange flip to `disabled` would freeze the
|
|
361
|
+
* height for good.) The settle-state and `restHeight` resets are
|
|
362
|
+
* defensive: Vue's own leave flow still fires an interrupted copy's
|
|
363
|
+
* after-leave once its frame callback resolves, so the counter
|
|
364
|
+
* balances with or without them (measured: deleting them leaves
|
|
365
|
+
* every pin green). They keep the state right if a copy is ever
|
|
366
|
+
* swept without that callback, and nothing pins them on their own. */
|
|
367
|
+
function teardownHeightAnimation(): void {
|
|
368
|
+
endHeightAnimation();
|
|
369
|
+
armedHost = null;
|
|
370
|
+
armedHeight = "";
|
|
371
|
+
leaving = 0;
|
|
372
|
+
enterSettled = false;
|
|
373
|
+
restHeight = null;
|
|
223
374
|
}
|
|
224
375
|
|
|
225
376
|
function armWatchdog(): void {
|
|
@@ -252,7 +403,12 @@ export default defineComponent({
|
|
|
252
403
|
suppress.value = true;
|
|
253
404
|
// A wedged engine also wedges the height tween: release the
|
|
254
405
|
// explicit height or the surface stays frozen at a stale size.
|
|
255
|
-
|
|
406
|
+
// The settle state resets with it — the swept copies never get
|
|
407
|
+
// their after-leave. Belt to a brace: `suppress` re-renders
|
|
408
|
+
// without the Transition, whose teardown (below) does the same
|
|
409
|
+
// on its own; this call is what keeps the state right if that
|
|
410
|
+
// flow ever changes, and no test pins it on its own.
|
|
411
|
+
teardownHeightAnimation();
|
|
256
412
|
}
|
|
257
413
|
}
|
|
258
414
|
|
|
@@ -327,36 +483,73 @@ export default defineComponent({
|
|
|
327
483
|
host's data attributes; the stylesheet owns the geometry. */}
|
|
328
484
|
<Transition
|
|
329
485
|
name="hk-dswap"
|
|
486
|
+
// Vue invokes this from `unmount` for ANY vnode, component
|
|
487
|
+
// included, BEFORE the subtree comes apart — the one signal
|
|
488
|
+
// that no exchange hook will run again (see
|
|
489
|
+
// `teardownHeightAnimation`). A cancelled enter is NOT that
|
|
490
|
+
// signal: the next enter follows in the same tick. (A vnode
|
|
491
|
+
// hook, typed on `VNodeProps` — not on the JSX props of a
|
|
492
|
+
// component — hence the spread.)
|
|
493
|
+
{...({ onVnodeBeforeUnmount: teardownHeightAnimation } as Record<string, unknown>)}
|
|
330
494
|
onBeforeEnter={() => {
|
|
331
495
|
armReport();
|
|
332
496
|
armWatchdog();
|
|
333
497
|
}}
|
|
334
498
|
onEnter={(el: Element) => {
|
|
335
|
-
// Runs right after the incoming item inserts
|
|
336
|
-
//
|
|
337
|
-
|
|
499
|
+
// Runs right after the incoming item inserts; the start
|
|
500
|
+
// height was captured in the before-leave hook below.
|
|
501
|
+
enterSettled = false;
|
|
338
502
|
beginHeightAnimation(el);
|
|
339
503
|
}}
|
|
340
504
|
onAfterEnter={() => {
|
|
341
|
-
|
|
505
|
+
enterSettled = true;
|
|
506
|
+
settleHeightAnimation();
|
|
342
507
|
settleReport();
|
|
343
508
|
}}
|
|
344
509
|
onEnterCancelled={() => {
|
|
345
|
-
|
|
510
|
+
// An interrupted exchange. Deliberately NOT released: the
|
|
511
|
+
// tween stays armed at its animated mid-state so the
|
|
512
|
+
// before-leave hook that follows in this same tick reads
|
|
513
|
+
// THAT as the next start, and the next enter re-freezes
|
|
514
|
+
// from it without a jump. Releasing here would drop the
|
|
515
|
+
// host to `auto` — the row, i.e. the taller copy still in
|
|
516
|
+
// the cell — and the follow-up would freeze at the row
|
|
517
|
+
// (R2 of the first cut measured exactly that). The
|
|
518
|
+
// Transition's own teardown is what releases a stranded
|
|
519
|
+
// tween.
|
|
346
520
|
settleReport();
|
|
347
521
|
}}
|
|
348
522
|
onBeforeLeave={(el: Element) => {
|
|
349
523
|
setLeavingInert(el, true);
|
|
350
524
|
armReport();
|
|
351
525
|
armWatchdog();
|
|
526
|
+
leaving += 1;
|
|
527
|
+
// The last read before the row changes (see `restHeight`):
|
|
528
|
+
// the rendered height — at rest, or the animated mid-state
|
|
529
|
+
// of an interrupted tween that is still armed.
|
|
530
|
+
if (props.animateHeight && hostRef.value) restHeight = hostRef.value.offsetHeight;
|
|
352
531
|
}}
|
|
353
532
|
onAfterLeave={() => {
|
|
354
|
-
|
|
533
|
+
// Vue removes the leaving copy BEFORE this hook runs, so
|
|
534
|
+
// the cell now holds the incoming generation alone.
|
|
535
|
+
leaving = Math.max(0, leaving - 1);
|
|
536
|
+
settleHeightAnimation();
|
|
355
537
|
settleReport();
|
|
356
538
|
}}
|
|
357
539
|
onLeaveCancelled={(el: Element) => {
|
|
358
540
|
setLeavingInert(el, false);
|
|
359
|
-
|
|
541
|
+
leaving = Math.max(0, leaving - 1);
|
|
542
|
+
// Not reachable with this component's keyed single child
|
|
543
|
+
// today: Vue only cancels a leave when the SAME element is
|
|
544
|
+
// re-entered (`beforeEnter`'s `el[leaveCbKey](true)`), and
|
|
545
|
+
// a keyed swap always mounts a fresh element — a copy whose
|
|
546
|
+
// key comes back has its leave FINISHED instead (measured:
|
|
547
|
+
// A→B→A→B fires `enter-cancelled` twice, `leave-cancelled`
|
|
548
|
+
// zero times). Kept consistent with the cancelled-enter rule
|
|
549
|
+
// above: no release here, so a following enter would re-freeze
|
|
550
|
+
// from the armed host's current rendered height. What that
|
|
551
|
+
// would look like in a browser is unmeasured — the path has
|
|
552
|
+
// never fired.
|
|
360
553
|
settleReport();
|
|
361
554
|
}}
|
|
362
555
|
>
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
HkMarkdownEditor,
|
|
5
5
|
applyLinePrefix,
|
|
6
6
|
applyWrap,
|
|
7
|
-
type
|
|
7
|
+
type HkMarkdownEditorView,
|
|
8
8
|
type MarkdownTextEdit,
|
|
9
9
|
} from "../index";
|
|
10
10
|
|
|
@@ -32,11 +32,11 @@ describe("the public barrel", () => {
|
|
|
32
32
|
// Type-only exports vanish at runtime, so each one is CONSUMED here: a
|
|
33
33
|
// dropped `type …` line fails vue-tsc on this file instead of leaving
|
|
34
34
|
// the runtime suite green.
|
|
35
|
-
const
|
|
35
|
+
const view: HkMarkdownEditorView = "preview";
|
|
36
36
|
const edit: MarkdownTextEdit = applyWrap("hi", 0, 0, "`");
|
|
37
37
|
expect(edit.text).toBe("``hi");
|
|
38
38
|
expect(edit.selectionStart).toBe(1);
|
|
39
39
|
expect(edit.selectionEnd).toBe(1);
|
|
40
|
-
expect(
|
|
40
|
+
expect(view).toBe("preview");
|
|
41
41
|
});
|
|
42
42
|
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createApp, h, nextTick } from "vue";
|
|
3
|
+
|
|
4
|
+
import HkMarkdownEditor from "./HkMarkdownEditor";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Rail lifecycle, pinned against a mocked overlay engine: the real one
|
|
8
|
+
* appends tracks the other suites already assert; what they cannot see
|
|
9
|
+
* is the HANDLE bookkeeping — a rail attached twice, or one left alive
|
|
10
|
+
* after its pane is gone, leaks listeners and a ResizeObserver. The
|
|
11
|
+
* mock keeps a registry of live handles; every attach adds one, every
|
|
12
|
+
* detach retires it, and the assertions read the registry.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const live = new Set<string>();
|
|
16
|
+
let serial = 0;
|
|
17
|
+
|
|
18
|
+
vi.mock("../composables/useOverlayScrollbar", () => ({
|
|
19
|
+
attachOverlayScrollbars: (viewport: HTMLElement) => {
|
|
20
|
+
const id = `rail-${++serial}:${viewport.className}`;
|
|
21
|
+
live.add(id);
|
|
22
|
+
return {
|
|
23
|
+
update: () => {},
|
|
24
|
+
setMapSegments: () => {},
|
|
25
|
+
setMarkers: () => {},
|
|
26
|
+
detach: () => {
|
|
27
|
+
live.delete(id);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
34
|
+
|
|
35
|
+
function mountEditor(props: Record<string, unknown>) {
|
|
36
|
+
const container = document.createElement("div");
|
|
37
|
+
document.body.appendChild(container);
|
|
38
|
+
const app = createApp({
|
|
39
|
+
data: () => ({ view: "both" as string, ...props }),
|
|
40
|
+
render() {
|
|
41
|
+
return h(HkMarkdownEditor, {
|
|
42
|
+
modelValue: this.modelValue,
|
|
43
|
+
view: this.view,
|
|
44
|
+
"onUpdate:view": (v: string) => { this.view = v; },
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
app.mount(container);
|
|
49
|
+
mounts.push({ app, container });
|
|
50
|
+
return container;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function pill(c: HTMLElement, label: string): HTMLButtonElement {
|
|
54
|
+
const btn = [...c.querySelectorAll<HTMLButtonElement>(".hk-md-editor-views .hk-pill-group-pill")].find(
|
|
55
|
+
(b) => b.textContent?.trim() === label,
|
|
56
|
+
);
|
|
57
|
+
expect(btn, `view pill "${label}"`).toBeTruthy();
|
|
58
|
+
return btn!;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
63
|
+
app.unmount();
|
|
64
|
+
container.remove();
|
|
65
|
+
}
|
|
66
|
+
live.clear();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("HkMarkdownEditor rail lifecycle", () => {
|
|
70
|
+
it("attaches one rail per scroll viewport and retires both on unmount", async () => {
|
|
71
|
+
const c = mountEditor({ modelValue: "# hi" });
|
|
72
|
+
await nextTick();
|
|
73
|
+
expect([...live].filter((id) => id.endsWith("hk-md-editor-input"))).toHaveLength(1);
|
|
74
|
+
expect([...live].filter((id) => id.endsWith("hk-md-editor-preview"))).toHaveLength(1);
|
|
75
|
+
const all = [...mounts];
|
|
76
|
+
all[0].app.unmount();
|
|
77
|
+
expect(live.size, "no rail outlives the editor").toBe(0);
|
|
78
|
+
mounts.splice(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("a view switch never leaves a rail without its pane and never stacks a second one", async () => {
|
|
82
|
+
const c = mountEditor({ modelValue: "# hi" });
|
|
83
|
+
await nextTick();
|
|
84
|
+
const inputRail = [...live].find((id) => id.endsWith("hk-md-editor-input"))!;
|
|
85
|
+
// both → preview: the source pane hides (its textarea still mounted,
|
|
86
|
+
// its rail untouched); the preview keeps its rail.
|
|
87
|
+
pill(c, "Preview only").dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
88
|
+
await nextTick();
|
|
89
|
+
expect(live.size).toBe(2);
|
|
90
|
+
// preview → text: the preview pane unmounts and its rail must go
|
|
91
|
+
// with it; the source pane shows again on the SAME rail it started
|
|
92
|
+
// with — the source's ref changes once in the editor's whole life.
|
|
93
|
+
pill(c, "Text only").dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
94
|
+
await nextTick();
|
|
95
|
+
expect([...live]).toEqual([inputRail]);
|
|
96
|
+
// text → both: the preview is back with exactly one new rail.
|
|
97
|
+
pill(c, "Both").dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
98
|
+
await nextTick();
|
|
99
|
+
expect(live.size).toBe(2);
|
|
100
|
+
expect([...live].filter((id) => id.endsWith("hk-md-editor-preview"))).toHaveLength(1);
|
|
101
|
+
expect(live.has(inputRail)).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
});
|