@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.
Files changed (38) hide show
  1. package/dist/types/components/HkDirectionalSwap.d.ts +53 -6
  2. package/dist/types/components/HkInput.d.ts +1 -1
  3. package/dist/types/components/HkMarkdownEditor.d.ts +33 -30
  4. package/dist/types/components/HkMenu.d.ts +1 -1
  5. package/dist/types/components/HkPillToggleGroup.d.ts +13 -0
  6. package/dist/types/components/HkRowActions.d.ts +1 -1
  7. package/dist/types/components/HkTable.d.ts +1 -1
  8. package/dist/types/components/HkTimePicker.d.ts +1 -1
  9. package/dist/types/index.d.ts +1 -1
  10. package/package.json +1 -1
  11. package/src/components/HkDirectionalSwap.test.tsx +614 -23
  12. package/src/components/HkDirectionalSwap.tsx +219 -26
  13. package/src/components/HkMarkdownEditor.barrel.test.ts +3 -3
  14. package/src/components/HkMarkdownEditor.rails.test.tsx +103 -0
  15. package/src/components/HkMarkdownEditor.scss +72 -89
  16. package/src/components/HkMarkdownEditor.test.tsx +319 -45
  17. package/src/components/HkMarkdownEditor.tsx +152 -90
  18. package/src/components/HkPillToggleGroup.scss +9 -2
  19. package/src/components/HkPillToggleGroup.test.tsx +36 -0
  20. package/src/components/HkPillToggleGroup.tsx +11 -2
  21. package/src/components/HkScrollProgressDock.scss +71 -2
  22. package/src/components/HkScrollProgressDock.test.tsx +508 -1
  23. package/src/components/HkScrollProgressDock.tsx +424 -40
  24. package/src/components/HkThemeToggle.test.ts +32 -1
  25. package/src/errorLandingStandalone/error-landing.html +1 -1
  26. package/src/i18n/locales/ar/components.json +9 -3
  27. package/src/i18n/locales/de/components.json +9 -3
  28. package/src/i18n/locales/en/components.json +9 -3
  29. package/src/i18n/locales/es/components.json +9 -3
  30. package/src/i18n/locales/fr/components.json +9 -3
  31. package/src/i18n/locales/ja/components.json +9 -3
  32. package/src/i18n/locales/ko/components.json +9 -3
  33. package/src/i18n/locales/pt/components.json +9 -3
  34. package/src/i18n/locales/ru/components.json +9 -3
  35. package/src/i18n/locales/zh-Hans/components.json +9 -3
  36. package/src/i18n/locales/zh-Hant/components.json +9 -3
  37. package/src/index.ts +1 -1
  38. package/src/res/themeLoaderBehaviour.test.ts +27 -0
@@ -1,14 +1,20 @@
1
- import { afterEach, describe, expect, it } from "vitest";
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
2
  import { createApp, h, nextTick } from "vue";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { compile } from "sass";
3
6
 
7
+ import { setLocale } from "../i18n/context";
4
8
  import HkMarkdownEditor, { applyLinePrefix, applyWrap } from "./HkMarkdownEditor";
5
9
 
6
10
  /**
7
11
  * HkMarkdownEditor contract: the v-model textarea, the pure toolbar
8
12
  * transforms (applyWrap / applyLinePrefix — the string algebra every
9
- * action reduces to), the mode segmented control, the split-view preview
10
- * through HkMarkdownRenderer, and the imageDrop reporting channel
11
- * (one event per image file; the editor never embeds or uploads).
13
+ * action reduces to), the view segmented control (the family's
14
+ * HkPillToggleGroup, single-choice), the three pane layouts with their
15
+ * house scrollbar rails, and the imageDrop reporting channel (one event
16
+ * per image file; the editor reports them instead of embedding or
17
+ * uploading anything itself).
12
18
  * MUT:hikari-1486-R3-M18 (emit-only-files[0] mutation → "one imageDrop per
13
19
  * file" assertion red) and MUT:hikari-1486-R3-M5 (preventDefault claim
14
20
  * mutation → defaultPrevented assertion red) pin the emission contract.
@@ -18,14 +24,14 @@ const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement
18
24
 
19
25
  interface EditorEvents {
20
26
  values: string[];
21
- modes: string[];
27
+ views: string[];
22
28
  files: File[];
23
29
  }
24
30
 
25
31
  function mountEditor(
26
32
  props: Record<string, unknown> = {},
27
33
  ): { container: HTMLElement; events: EditorEvents } {
28
- const events: EditorEvents = { values: [], modes: [], files: [] };
34
+ const events: EditorEvents = { values: [], views: [], files: [] };
29
35
  const container = document.createElement("div");
30
36
  document.body.appendChild(container);
31
37
  const app = createApp({
@@ -33,7 +39,7 @@ function mountEditor(
33
39
  h(HkMarkdownEditor, {
34
40
  ...props,
35
41
  "onUpdate:modelValue": (v: string) => { events.values.push(v); },
36
- "onUpdate:mode": (m: string) => { events.modes.push(m); },
42
+ "onUpdate:view": (v: string) => { events.views.push(v); },
37
43
  onImageDrop: (f: File) => { events.files.push(f); },
38
44
  }),
39
45
  });
@@ -48,27 +54,33 @@ function textareaOf(c: HTMLElement): HTMLTextAreaElement {
48
54
  return ta!;
49
55
  }
50
56
 
57
+ /** A formatting action — an item of the family's icon-button group,
58
+ * reachable by its accessible name. */
51
59
  function actionButton(c: HTMLElement, label: string): HTMLButtonElement {
52
- const btn = [...c.querySelectorAll<HTMLButtonElement>(".hk-md-editor-action")].find(
60
+ const btn = [...c.querySelectorAll<HTMLButtonElement>(".hk-md-editor-actions .hk-icon-group-item")].find(
53
61
  (b) => b.getAttribute("aria-label") === label,
54
62
  );
55
63
  expect(btn, `toolbar button "${label}"`).toBeTruthy();
56
64
  return btn!;
57
65
  }
58
66
 
59
- function modeButton(c: HTMLElement, label: string): HTMLButtonElement {
60
- const btn = [...c.querySelectorAll<HTMLButtonElement>(".hk-md-editor-mode")].find(
67
+ /** A view segment — a pill of the family's HkPillToggleGroup. */
68
+ function viewPill(c: HTMLElement, label: string): HTMLButtonElement {
69
+ const btn = [...c.querySelectorAll<HTMLButtonElement>(".hk-md-editor-views .hk-pill-group-pill")].find(
61
70
  (b) => b.textContent?.trim() === label,
62
71
  );
63
- expect(btn, `mode button "${label}"`).toBeTruthy();
72
+ expect(btn, `view pill "${label}"`).toBeTruthy();
64
73
  return btn!;
65
74
  }
66
75
 
67
- afterEach(() => {
76
+ afterEach(async () => {
68
77
  for (const { app, container } of mounts.splice(0)) {
69
78
  app.unmount();
70
79
  container.remove();
71
80
  }
81
+ // A locale test that fails mid-way must not leave the next suite's
82
+ // labels in the wrong language.
83
+ await setLocale("en");
72
84
  });
73
85
 
74
86
  const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
@@ -97,6 +109,124 @@ function dropEvent(type: string, files: File[], types?: string[]): Event {
97
109
  return ev;
98
110
  }
99
111
 
112
+ // ── Stylesheet contract ───────────────────────────────────────────────────
113
+ //
114
+ // The scroll bug this sheet guards against is a CSS one: a long rendering
115
+ // used to grow the editor past its host because one pane wrapper's
116
+ // automatic minimum was its content height. None of that is observable
117
+ // under happy-dom (no layout engine), so the rules are pinned as text.
118
+
119
+ /** Every declaration of the top-level rules whose selector is exactly
120
+ * `selector` in the compiled sheet, joined — sass hoists a nested
121
+ * `&::-webkit-scrollbar` rule out of its parent and splits the parent
122
+ * in two, so one selector may own more than one block. */
123
+ function ruleDeclarations(rawCss: string, selector: string): string {
124
+ // Line-start anchored; sass expands attribute selectors unquoted and
125
+ // breaks a selector list across lines, so both are matched loosely.
126
+ const css = `\n${rawCss}`;
127
+ const pattern = selector
128
+ .replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
129
+ .replace(/"/g, "")
130
+ .replace(/\s*,\s*/g, "\\s*,\\s*")
131
+ .replace(/\s+/g, "\\s+");
132
+ const opener = new RegExp(`\\n${pattern} \\{`, "g");
133
+ const blocks: string[] = [];
134
+ for (let m = opener.exec(css); m !== null; m = opener.exec(css)) {
135
+ const open = m.index + m[0].length - 1;
136
+ let depth = 0;
137
+ for (let i = open; i < css.length; i += 1) {
138
+ if (css[i] === "{") depth += 1;
139
+ if (css[i] === "}") {
140
+ depth -= 1;
141
+ if (depth === 0) {
142
+ blocks.push(css.slice(open + 1, i));
143
+ opener.lastIndex = i;
144
+ break;
145
+ }
146
+ }
147
+ }
148
+ }
149
+ expect(blocks.length, `rule "${selector}" exists`).toBeGreaterThan(0);
150
+ return blocks.join("\n");
151
+ }
152
+
153
+ function editorCss(): string {
154
+ const here = dirname(fileURLToPath(import.meta.url));
155
+ return compile(join(here, "HkMarkdownEditor.scss"), { style: "expanded" }).css;
156
+ }
157
+
158
+ describe("HkMarkdownEditor stylesheet contract", () => {
159
+ const css = editorCss();
160
+
161
+ it("closes the flex chain: every pane wrapper can shrink below its content", () => {
162
+ // The root clips; the body flexes under it; each pane wrapper gives up
163
+ // its content-based minimum so neither pane's CONTENT reaches the
164
+ // root's intrinsic height.
165
+ expect(ruleDeclarations(css, ".hk-md-editor")).toMatch(/overflow: hidden;/);
166
+ expect(ruleDeclarations(css, ".hk-md-editor-body")).toMatch(/flex: 1;/);
167
+ expect(ruleDeclarations(css, ".hk-md-editor-body")).toMatch(/min-height: 12rem;/);
168
+ expect(ruleDeclarations(css, ".hk-md-editor-input-pane")).toMatch(/min-height: 0;/);
169
+ expect(ruleDeclarations(css, ".hk-md-editor-input-pane")).toMatch(/min-width: 0;/);
170
+ const previewPane = ruleDeclarations(css, ".hk-md-editor-preview-pane");
171
+ expect(previewPane).toMatch(/min-height: 0;/);
172
+ expect(previewPane).toMatch(/min-width: 0;/);
173
+ // The rails' host must be the positioned box wrapping exactly the
174
+ // viewport (useOverlayScrollbar's mount contract).
175
+ expect(previewPane).toMatch(/position: relative;/);
176
+ });
177
+
178
+ it("both scroll viewports keep native mechanics with the native bar suppressed", () => {
179
+ // The house contract beside overflow: the suppression pair. A viewport
180
+ // with the overlay rail attached but the native bar left on would
181
+ // show two bars; one with neither would scroll with no bar at all.
182
+ for (const selector of [".hk-md-editor-input", ".hk-md-editor-preview"]) {
183
+ const decl = ruleDeclarations(css, selector);
184
+ expect(decl, `${selector} scrolls`).toMatch(/overflow-y: auto;/);
185
+ expect(decl, `${selector} hides the native bar (standard property)`).toMatch(/scrollbar-width: none;/);
186
+ }
187
+ // …and the webkit half of the pair, which compiles as a nested rule.
188
+ expect(css).toMatch(/\.hk-md-editor-input::-webkit-scrollbar\s*\{\s*display: none;/);
189
+ expect(css).toMatch(/\.hk-md-editor-preview::-webkit-scrollbar\s*\{\s*display: none;/);
190
+ });
191
+
192
+ it("a single-pane view takes the whole row and drops the divider", () => {
193
+ expect(ruleDeclarations(css, '.hk-md-editor-body[data-view="text"] .hk-md-editor-input-pane,\n.hk-md-editor-body[data-view="preview"] .hk-md-editor-preview-pane'))
194
+ .toMatch(/flex-basis: 100%;/);
195
+ expect(ruleDeclarations(css, '.hk-md-editor-body[data-view="preview"] .hk-md-editor-preview'))
196
+ .toMatch(/border-inline-start: none;/);
197
+ // The split carries the divider on the preview's inline-start edge.
198
+ expect(ruleDeclarations(css, ".hk-md-editor-preview")).toMatch(/border-inline-start: 1px solid/);
199
+ });
200
+
201
+ it("carries no hand-drawn control chrome: the toolbar is the family's", () => {
202
+ expect(css).not.toMatch(/\.hk-md-editor-mode\b/);
203
+ expect(css).not.toMatch(/\.hk-md-editor-modes\b/);
204
+ expect(css).not.toMatch(/\.hk-md-editor-action\s*\{/);
205
+ expect(css).not.toMatch(/\.hk-md-editor-action:hover/);
206
+ // What remains of the toolbar row is layout plus the two components'
207
+ // host hooks — no button styling of the editor's own.
208
+ const toolbar = ruleDeclarations(css, ".hk-md-editor-toolbar");
209
+ expect(toolbar).toMatch(/display: flex;/);
210
+ expect(ruleDeclarations(css, ".hk-md-editor-views")).toMatch(/margin-inline-start: auto;/);
211
+ // Compound with the group's class: the size class alone ties at
212
+ // (0,1,0), and source order between two sheets is not a contract.
213
+ expect(ruleDeclarations(css, ".hk-icon-group.hk-md-editor-actions")).toMatch(/--hk-icon-group-item-size: 1\.75rem;/);
214
+ });
215
+
216
+ it("the hidden source pane is really hidden, stacked hosts split the row", () => {
217
+ // `display: flex` on the pane outranks the UA `[hidden]` rule, so the
218
+ // attribute's display: none is restated on the pane itself.
219
+ expect(ruleDeclarations(css, ".hk-md-editor-input-pane[hidden]")).toMatch(/display: none;/);
220
+ // Narrow hosts stack the panes: the body turns column, each pane takes
221
+ // an equal share of a bounded row, and the divider follows the block axis.
222
+ const stacked = css.slice(css.indexOf("@media (max-width: 640px)"));
223
+ expect(stacked).toMatch(/\.hk-md-editor-body\s*\{\s*flex-direction: column;/);
224
+ expect(stacked).toMatch(/\.hk-md-editor-input-pane,\s*\.hk-md-editor-preview-pane\s*\{\s*flex: 1 1 0%;/);
225
+ expect(stacked).toMatch(/\.hk-md-editor-preview\s*\{\s*border-inline-start: none;\s*border-block-start: 1px solid/);
226
+ expect(stacked).toMatch(/\.hk-md-editor-body\[data-view=preview\] \.hk-md-editor-preview\s*\{\s*border-block-start: none;/);
227
+ });
228
+ });
229
+
100
230
  // ── Pure helpers ──────────────────────────────────────────────────────────
101
231
 
102
232
  describe("applyWrap", () => {
@@ -227,80 +357,224 @@ describe("HkMarkdownEditor", () => {
227
357
  expect(ta.selectionEnd).toBe(14);
228
358
  });
229
359
 
230
- it("mode toggle emits update:mode (and never echoes the active mode)", async () => {
231
- // The no-op guard reads the FED-BACK mode prop, so the harness has to
232
- // close the v-model:mode loop like a real host.
360
+ it("view toggle emits update:view (and never echoes the active view)", async () => {
361
+ // The no-op guard reads the FED-BACK view prop, so the harness has to
362
+ // close the v-model:view loop like a real host.
233
363
  const events: string[] = [];
234
364
  const container = document.createElement("div");
235
365
  document.body.appendChild(container);
236
366
  const app = createApp({
237
- data: () => ({ mode: "markdown" as string }),
367
+ data: () => ({ view: "both" as string }),
238
368
  render() {
239
369
  return h(HkMarkdownEditor, {
240
370
  modelValue: "",
241
- mode: this.mode,
242
- "onUpdate:mode": (m: string) => { events.push(m); this.mode = m; },
371
+ view: this.view,
372
+ "onUpdate:view": (v: string) => { events.push(v); this.view = v; },
243
373
  });
244
374
  },
245
375
  });
246
376
  app.mount(container);
247
377
  mounts.push({ app, container });
248
378
 
249
- modeButton(container, "Plain text").dispatchEvent(new MouseEvent("click", { bubbles: true }));
379
+ // Both is the default and reads active first.
380
+ expect(viewPill(container, "Both").hasAttribute("data-active")).toBe(true);
381
+ viewPill(container, "Preview only").dispatchEvent(new MouseEvent("click", { bubbles: true }));
382
+ await nextTick();
383
+ expect(events).toEqual(["preview"]);
384
+ // The active state followed the emitted view; re-clicking is a no-op.
385
+ const preview = viewPill(container, "Preview only");
386
+ expect(preview.hasAttribute("data-active")).toBe(true);
387
+ preview.dispatchEvent(new MouseEvent("click", { bubbles: true }));
250
388
  await nextTick();
251
- expect(events).toEqual(["plain"]);
252
- // The active state followed the emitted mode; re-clicking is a no-op.
253
- const plain = modeButton(container, "Plain text");
254
- expect(plain.hasAttribute("data-active")).toBe(true);
255
- plain.dispatchEvent(new MouseEvent("click", { bubbles: true }));
389
+ expect(events).toEqual(["preview"]);
390
+ viewPill(container, "Text only").dispatchEvent(new MouseEvent("click", { bubbles: true }));
391
+ await nextTick();
392
+ expect(events).toEqual(["preview", "text"]);
393
+ });
394
+
395
+ it("the view control and the formatting strip are the family's components, not hand-drawn", () => {
396
+ const { container } = mountEditor({ modelValue: "" });
397
+ // The segmented control IS an HkPillToggleGroup (role=group, its own
398
+ // pill class, the host's accessible name) — a bespoke button row
399
+ // would fail every one of these.
400
+ const group = container.querySelector<HTMLElement>(".hk-md-editor-views.hk-pill-group");
401
+ expect(group, "view control is an HkPillToggleGroup").not.toBeNull();
402
+ expect(group!.getAttribute("role")).toBe("group");
403
+ expect(group!.getAttribute("aria-label")).toBe("View");
404
+ expect(
405
+ [...group!.querySelectorAll(".hk-pill-group-pill")].map((p) => p.textContent?.trim()),
406
+ ).toEqual(["Text only", "Both", "Preview only"]);
407
+ // The formatting actions ARE an HkIconButtonGroup (buttons mode).
408
+ const strip = container.querySelector<HTMLElement>(".hk-md-editor-actions.hk-icon-group");
409
+ expect(strip, "actions are an HkIconButtonGroup").not.toBeNull();
410
+ expect(strip!.classList.contains("hk-icon-group-buttons")).toBe(true);
411
+ expect(container.querySelector(".hk-md-editor-mode, .hk-md-editor-modes")).toBeNull();
412
+ });
413
+
414
+ it("both panes mount the house scrollbar rail on their own wrapper", async () => {
415
+ const { container } = mountEditor({ modelValue: "# hi" });
416
+ // The rails attach in the post-flush of the mounting tick.
256
417
  await nextTick();
257
- expect(events).toEqual(["plain"]);
418
+ // Each track is a child of the box that wraps exactly its viewport:
419
+ // the textarea's pane and the preview's pane. One rail per pane — the
420
+ // native bars are suppressed in the SCSS, so a missing track would
421
+ // leave a scrolling pane with no scrollbar at all.
422
+ expect(container.querySelectorAll(".hk-md-editor-input-pane > .hk-scrollbar-track")).toHaveLength(1);
423
+ expect(container.querySelectorAll(".hk-md-editor-preview-pane > .hk-scrollbar-track")).toHaveLength(1);
424
+ // The preview viewport itself is the scroller (mechanics in CSS).
425
+ const preview = container.querySelector<HTMLElement>(".hk-md-editor-preview");
426
+ expect(preview!.parentElement?.classList.contains("hk-md-editor-preview-pane")).toBe(true);
258
427
  });
259
428
 
260
- it("split view renders the markdown preview for a heading", async () => {
429
+ it("both view (the default) renders the live preview for a heading", async () => {
261
430
  const { container } = mountEditor({ modelValue: "# hi" });
431
+ expect(container.querySelector(".hk-md-editor")!.getAttribute("data-view")).toBe("both");
262
432
  const preview = container.querySelector<HTMLElement>(".hk-md-editor-preview");
263
- expect(preview, "preview pane renders in split view").not.toBeNull();
433
+ expect(preview, "preview pane renders in both view").not.toBeNull();
264
434
  // The preview IS a mounted HkMarkdownRenderer fed the live source.
435
+ // MUT:mdview-renderer-starved (feeding the renderer a constant instead
436
+ // of the live modelValue → the settled "hi" assertion goes red).
265
437
  // Under happy-dom DOMPurify strips heading ELEMENTS (verified:
266
438
  // sanitize('<h1>hi</h1>') → 'hi'), so the assertion rides the
267
439
  // renderer's own output classes plus the settled text content —
268
440
  // the same textContent idiom HkMarkdownRenderer's suites use.
269
441
  // comment-gate-ok: verified environment fact (probe output quoted
270
442
  // above), not an unproven behaviour claim; the renderer wiring itself
271
- // is pinned by MUT:hikari-1486-R3-M6 (plain-flag mutation → this
272
- // suite's preview assertions red).
443
+ // is pinned by the mutation record of this suite (a renderer left
444
+ // out of the preview → these preview assertions go red).
273
445
  expect(preview!.querySelector(".hk-markdown .hk-markdown-body")).not.toBeNull();
274
446
  await settleFor(container, () =>
275
447
  (preview!.querySelector(".hk-markdown-body")?.textContent ?? "").includes("hi"),
276
448
  );
277
449
  expect(preview!.querySelector(".hk-markdown-body")?.textContent).toContain("hi");
278
- // data-plain is off in markdown mode (the plain-mode case pins the on state).
450
+ // The rendering is markdown rather than the raw-source fallback.
279
451
  expect(preview!.querySelector(".hk-markdown")?.hasAttribute("data-plain")).toBe(false);
280
452
  });
281
453
 
282
- it("edit view renders no preview pane", () => {
283
- const { container } = mountEditor({ modelValue: "# hi", view: "edit" });
454
+ it("text view renders the source alone — no preview pane, no preview rail", async () => {
455
+ const { container } = mountEditor({ modelValue: "# hi", view: "text" });
456
+ await nextTick();
457
+ expect(container.querySelector(".hk-md-editor")!.getAttribute("data-view")).toBe("text");
284
458
  expect(container.querySelector(".hk-md-editor-preview")).toBeNull();
459
+ expect(container.querySelector(".hk-md-editor-preview-pane")).toBeNull();
460
+ expect(container.querySelectorAll(".hk-scrollbar-track")).toHaveLength(1);
285
461
  expect(container.querySelector(".hk-md-editor-input")).not.toBeNull();
462
+ // The formatting strip stays: there is still text to format.
463
+ expect(container.querySelector(".hk-md-editor-actions")).not.toBeNull();
286
464
  });
287
465
 
288
- it("plain mode hides the markdown actions and previews pre-wrapped text", async () => {
289
- const { container } = mountEditor({ modelValue: "*raw* markup", mode: "plain" });
290
- expect(container.querySelector(".hk-md-editor-actions")).toBeNull();
291
- // The mode control stays reachable in plain mode (the way back).
292
- expect(container.querySelector(".hk-md-editor-modes")).not.toBeNull();
293
- const preview = container.querySelector<HTMLElement>(".hk-md-editor-preview");
294
- expect(preview).not.toBeNull();
295
- await settleFor(container, () => preview!.querySelector("pre.hk-md-plain") !== null);
296
- // Plain preview shows the RAW source, not rendered markdown.
297
- expect(preview!.querySelector("pre.hk-md-plain")?.textContent).toContain("*raw* markup");
466
+ it("preview view shows the rendering alone: the source pane hides, the strip goes inert", async () => {
467
+ const { container, events } = mountEditor({ modelValue: "# hi", view: "preview" });
468
+ await nextTick();
469
+ const body = container.querySelector(".hk-md-editor-body")!;
470
+ expect(body.getAttribute("data-view")).toBe("preview");
471
+ expect(container.querySelector(".hk-md-editor-preview")).not.toBeNull();
472
+ // The source pane is hidden, not unmounted (the textarea's undo
473
+ // history and caret survive the round trip — the round-trip suite
474
+ // below pins the same element) — and a hidden pane is out of the tab
475
+ // order and the accessibility tree.
476
+ // MUT:mdview-source-unmounted (rendering the source pane only when
477
+ // the view is not preview → the hidden assertion here and the
478
+ // same-textarea assertion in the round-trip suite go red).
479
+ const pane = container.querySelector<HTMLElement>(".hk-md-editor-input-pane")!;
480
+ expect(pane.hidden).toBe(true);
481
+ expect(container.querySelector(".hk-md-editor-preview-pane")).not.toBeNull();
482
+ // The formatting actions have no source to act on: every item inert.
483
+ for (const item of container.querySelectorAll<HTMLButtonElement>(".hk-md-editor-actions .hk-icon-group-item")) {
484
+ expect(item.disabled).toBe(true);
485
+ }
486
+ // A disabled item swallows the click: nothing reaches the model.
487
+ actionButton(container, "Bold").dispatchEvent(new MouseEvent("click", { bubbles: true }));
488
+ await nextTick();
489
+ expect(events.values).toEqual([]);
490
+ // The preview region and the source keep their accessible names.
491
+ expect(container.querySelector(".hk-md-editor-preview")!.getAttribute("role")).toBe("region");
492
+ expect(container.querySelector(".hk-md-editor-preview")!.getAttribute("aria-label")).toBe("Preview");
493
+ expect(textareaOf(container).getAttribute("aria-label")).toBe("Message body");
494
+ });
495
+
496
+ it("a view switch moves the rail to the pane that is on the page and keeps the source's state", async () => {
497
+ // The preview's rail follows the element actually mounted: it mounts
498
+ // while the rendering shows and leaves with it. The source pane's rail
499
+ // is attached once — a view switch leaves its textarea mounted.
500
+ // MUT:mdview-rail-detach-dropped (skipping either rail's detach on
501
+ // resync → the rails suite's live-handle registry goes red).
502
+ const container = document.createElement("div");
503
+ document.body.appendChild(container);
504
+ const app = createApp({
505
+ data: () => ({ view: "both" as string, body: "" as string }),
506
+ render() {
507
+ return h(HkMarkdownEditor, {
508
+ modelValue: this.body,
509
+ view: this.view,
510
+ "onUpdate:modelValue": (v: string) => { this.body = v; },
511
+ "onUpdate:view": (v: string) => { this.view = v; },
512
+ });
513
+ },
514
+ });
515
+ app.mount(container);
516
+ mounts.push({ app, container });
517
+ await nextTick();
518
+ expect(container.querySelectorAll(".hk-scrollbar-track")).toHaveLength(2);
519
+ const textarea = textareaOf(container);
520
+ textarea.focus();
521
+ textarea.setSelectionRange(1, 1);
522
+ viewPill(container, "Preview only").dispatchEvent(new MouseEvent("click", { bubbles: true }));
523
+ await nextTick();
524
+ expect(container.querySelector(".hk-md-editor-body")!.getAttribute("data-view")).toBe("preview");
525
+ expect(container.querySelector<HTMLElement>(".hk-md-editor-input-pane")!.hidden).toBe(true);
526
+ expect(container.querySelectorAll(".hk-md-editor-preview-pane > .hk-scrollbar-track")).toHaveLength(1);
527
+ viewPill(container, "Text only").dispatchEvent(new MouseEvent("click", { bubbles: true }));
528
+ await nextTick();
529
+ expect(container.querySelector(".hk-md-editor-preview")).toBeNull();
530
+ expect(container.querySelector(".hk-md-editor-preview-pane")).toBeNull();
531
+ expect(container.querySelectorAll(".hk-scrollbar-track")).toHaveLength(1);
532
+ expect(container.querySelector(".hk-md-editor-input-pane > .hk-scrollbar-track")).not.toBeNull();
533
+ expect(container.querySelector<HTMLElement>(".hk-md-editor-input-pane")!.hidden).toBe(false);
534
+ // The SAME textarea element came back, with its value and selection.
535
+ expect(textareaOf(container)).toBe(textarea);
536
+ viewPill(container, "Both").dispatchEvent(new MouseEvent("click", { bubbles: true }));
537
+ await nextTick();
538
+ expect(container.querySelector(".hk-md-editor-body")!.getAttribute("data-view")).toBe("both");
539
+ expect(container.querySelectorAll(".hk-scrollbar-track")).toHaveLength(2);
540
+ });
541
+
542
+ it("a locale switch relabels the pills and the formatting strip like the rest of the page", async () => {
543
+ const { container } = mountEditor({ modelValue: "" });
544
+ await nextTick();
545
+ expect(viewPill(container, "Both").hasAttribute("data-active")).toBe(true);
546
+ await setLocale("zh-Hans");
547
+ await nextTick();
548
+ expect(
549
+ [...container.querySelectorAll(".hk-md-editor-views .hk-pill-group-pill")].map((p) => p.textContent?.trim()),
550
+ ).toEqual(["仅文本", "全体显示", "仅预览"]);
551
+ expect(container.querySelector(".hk-md-editor-views")!.getAttribute("aria-label")).toBe("视图");
552
+ expect(container.querySelector(".hk-md-editor-actions .hk-icon-group-item[data-key='bold']")!.getAttribute("aria-label")).toBe("粗体");
553
+ await setLocale("en");
554
+ await nextTick();
555
+ expect(
556
+ [...container.querySelectorAll(".hk-md-editor-views .hk-pill-group-pill")].map((p) => p.textContent?.trim()),
557
+ ).toEqual(["Text only", "Both", "Preview only"]);
558
+ });
559
+
560
+ it("a stale view binding warns in dev instead of silently showing no active pill", () => {
561
+ // The retired `view="split"` binding (a host that has not migrated)
562
+ // trips the prop validator — Vue's own dev warning, nothing custom.
563
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
564
+ try {
565
+ const { container } = mountEditor({ modelValue: "", view: "split" });
566
+ const calls = warn.mock.calls.map((args) => args.map(String).join(" "));
567
+ expect(calls.some((text) => text.includes("Invalid prop") && text.includes('"view"'))).toBe(true);
568
+ expect(container.querySelectorAll(".hk-md-editor-views [data-active]")).toHaveLength(0);
569
+ } finally {
570
+ warn.mockRestore();
571
+ }
298
572
  });
299
573
 
300
- it("toolbar=false hides the actions but keeps the mode control", () => {
574
+ it("toolbar=false hides the actions but keeps the view control", () => {
301
575
  const { container } = mountEditor({ modelValue: "", toolbar: false });
302
576
  expect(container.querySelector(".hk-md-editor-actions")).toBeNull();
303
- expect(container.querySelector(".hk-md-editor-modes")).not.toBeNull();
577
+ expect(container.querySelector(".hk-md-editor-views.hk-pill-group")).not.toBeNull();
304
578
  });
305
579
 
306
580
  it("dropping an image file emits one imageDrop per file and prevents the default", async () => {
@@ -399,6 +673,6 @@ describe("HkMarkdownEditor", () => {
399
673
  expect(dropEv.defaultPrevented).toBe(false);
400
674
  expect(textareaOf(container).disabled).toBe(true);
401
675
  expect(actionButton(container, "Bold").disabled).toBe(true);
402
- expect(modeButton(container, "Plain text").disabled).toBe(true);
676
+ expect(viewPill(container, "Preview only").disabled).toBe(true);
403
677
  });
404
678
  });