@celestia-island/hikari 0.55.518 → 0.55.520

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.
@@ -1,8 +1,11 @@
1
1
  import "./HkMarkdownEditor.scss";
2
- /** Editing dialect of the editor body. `markdown` runs the toolbar and the
3
- * rendered live preview; `plain` reduces the surface to a textarea (the
4
- * split preview degrades to pre-wrapped plain text). */
5
- export type HkMarkdownEditorMode = "markdown" | "plain";
2
+ /** Which panes the editor shows. The source textarea is the document;
3
+ * the preview is its live rendering (markdown is the convenient way to
4
+ * write it, not a mode the writer has to pick). `text` = the source
5
+ * alone, `both` = the split (source | preview), `preview` = the
6
+ * rendering alone. */
7
+ export type HkMarkdownEditorView = "text" | "both" | "preview";
8
+ declare function isView(value: unknown): value is HkMarkdownEditorView;
6
9
  /** The result of one pure text transform: the rewritten source plus the
7
10
  * selection the editor should restore afterwards. Selections are plain
8
11
  * string indices into `text` — the same coordinates a textarea's
@@ -30,27 +33,33 @@ export declare function applyWrap(source: string, selectionStart: number, select
30
33
  */
31
34
  export declare function applyLinePrefix(source: string, selectionStart: number, selectionEnd: number, prefix: string | ((lineIndex: number) => string)): MarkdownTextEdit;
32
35
  /**
33
- * HkMarkdownEditor — the family's standard two-pane markdown/plain-text
34
- * editor. Left: the textarea (every toolbar action a pure string transform
35
- * over the current selection, refocused with a restored selection after
36
- * each action). Right: the live preview through HkMarkdownRenderer,
37
- * shown in split view — markdown mode renders, plain mode degrades to
38
- * pre-wrapped plain text. Image drops/pastes are REPORTED (one
39
- * `imageDrop` event per file) and never embedded or uploaded: the host
40
- * owns the upload and inserts its own markdown marker.
36
+ * HkMarkdownEditor — the family's standard two-pane rich-text editor.
37
+ * Left: the textarea (every toolbar action a pure string transform over
38
+ * the current selection, refocused with a restored selection after each
39
+ * action). Right: the live rendering of that source through
40
+ * HkMarkdownRenderer. The right-hand segmented control (the family's
41
+ * HkPillToggleGroup, single-choice) picks which panes show — the source
42
+ * alone, both, or the rendering alone. Image drops/pastes are REPORTED
43
+ * (one `imageDrop` event per file) and never embedded or uploaded: the
44
+ * host owns the upload and inserts its own marker.
45
+ *
46
+ * Geometry: the root is `overflow: hidden` and every pane wrapper is a
47
+ * `min-height: 0` flex item, so a host that bounds the root (a
48
+ * `flex: 1` + `min-height: 0` chain, or an explicit height) gets two
49
+ * panes that scroll INSIDE themselves under the house overlay rail — a
50
+ * long rendering never grows the editor past its host. A host that
51
+ * leaves it content-sized gets a 12rem floor and may grow with the
52
+ * rendering.
41
53
  */
42
54
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
43
55
  modelValue: {
44
56
  type: StringConstructor;
45
57
  default: string;
46
58
  };
47
- mode: {
48
- type: () => HkMarkdownEditorMode;
49
- default: string;
50
- };
51
59
  view: {
52
- type: () => "split" | "edit";
60
+ type: () => HkMarkdownEditorView;
53
61
  default: string;
62
+ validator: typeof isView;
54
63
  };
55
64
  placeholder: {
56
65
  type: StringConstructor;
@@ -60,8 +69,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
60
69
  type: BooleanConstructor;
61
70
  default: boolean;
62
71
  };
63
- /** Toolbar actions row (markdown mode only — plain mode has no
64
- * markdown to insert). The mode segmented control always renders. */
72
+ /** Toolbar actions row. The view segmented control always renders. */
65
73
  toolbar: {
66
74
  type: BooleanConstructor;
67
75
  default: boolean;
@@ -73,20 +81,17 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
73
81
  };
74
82
  }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
75
83
  "update:modelValue": (_value: string) => true;
76
- "update:mode": (_mode: HkMarkdownEditorMode) => true;
84
+ "update:view": (_view: HkMarkdownEditorView) => true;
77
85
  imageDrop: (_file: File) => true;
78
86
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
79
87
  modelValue: {
80
88
  type: StringConstructor;
81
89
  default: string;
82
90
  };
83
- mode: {
84
- type: () => HkMarkdownEditorMode;
85
- default: string;
86
- };
87
91
  view: {
88
- type: () => "split" | "edit";
92
+ type: () => HkMarkdownEditorView;
89
93
  default: string;
94
+ validator: typeof isView;
90
95
  };
91
96
  placeholder: {
92
97
  type: StringConstructor;
@@ -96,8 +101,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
96
101
  type: BooleanConstructor;
97
102
  default: boolean;
98
103
  };
99
- /** Toolbar actions row (markdown mode only — plain mode has no
100
- * markdown to insert). The mode segmented control always renders. */
104
+ /** Toolbar actions row. The view segmented control always renders. */
101
105
  toolbar: {
102
106
  type: BooleanConstructor;
103
107
  default: boolean;
@@ -110,10 +114,9 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
110
114
  }>> & Readonly<{
111
115
  "onUpdate:modelValue"?: ((_value: string) => any) | undefined;
112
116
  onImageDrop?: ((_file: File) => any) | undefined;
113
- "onUpdate:mode"?: ((_mode: HkMarkdownEditorMode) => any) | undefined;
117
+ "onUpdate:view"?: ((_view: HkMarkdownEditorView) => any) | undefined;
114
118
  }>, {
115
- view: "split" | "edit";
116
- mode: HkMarkdownEditorMode;
119
+ view: HkMarkdownEditorView;
117
120
  toolbar: boolean;
118
121
  disabled: boolean;
119
122
  modelValue: string;
@@ -67,6 +67,12 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
67
67
  type: StringConstructor;
68
68
  default: undefined;
69
69
  };
70
+ /** Disables every pill (the all-pill included): a disabled editor's
71
+ * view strip must not offer a switch its host would refuse. */
72
+ disabled: {
73
+ type: BooleanConstructor;
74
+ default: boolean;
75
+ };
70
76
  /** Pill-suffix renderer (2026-11-19, the filter-chip sort arrows): one
71
77
  * call per rendered pill — a null value scopes the ALL-pill, a value
72
78
  * scopes that option — rendered UNWRAPPED after the label so the
@@ -102,6 +108,12 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
102
108
  type: StringConstructor;
103
109
  default: undefined;
104
110
  };
111
+ /** Disables every pill (the all-pill included): a disabled editor's
112
+ * view strip must not offer a switch its host would refuse. */
113
+ disabled: {
114
+ type: BooleanConstructor;
115
+ default: boolean;
116
+ };
105
117
  /** Pill-suffix renderer (2026-11-19, the filter-chip sort arrows): one
106
118
  * call per rendered pill — a null value scopes the ALL-pill, a value
107
119
  * scopes that option — rendered UNWRAPPED after the label so the
@@ -118,6 +130,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
118
130
  onAll?: (() => any) | undefined;
119
131
  }>, {
120
132
  options: HkPillToggleGroupOption[];
133
+ disabled: boolean;
121
134
  selected: Set<string>;
122
135
  allLabel: string;
123
136
  renderTrailing: (value: string | null) => VNode | undefined;
@@ -353,7 +353,7 @@ export { default as HkListTransition } from "./components/HkListTransition";
353
353
  export { default as HkLoadMore } from "./components/HkLoadMore";
354
354
  export { default as HkMarkdownRenderer } from "./components/HkMarkdownRenderer";
355
355
  export { default as HkMarkdownEditor, applyLinePrefix, applyWrap } from "./components/HkMarkdownEditor";
356
- export type { HkMarkdownEditorMode, MarkdownTextEdit } from "./components/HkMarkdownEditor";
356
+ export type { HkMarkdownEditorView, MarkdownTextEdit } from "./components/HkMarkdownEditor";
357
357
  export { default as HkMermaidDiagram } from "./components/HkMermaidDiagram";
358
358
  export { default as HkTerminal } from "./components/HkTerminal";
359
359
  export { default as HkModal } from "./components/HkModal";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.518",
3
+ "version": "0.55.520",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
@@ -4,7 +4,7 @@ import {
4
4
  HkMarkdownEditor,
5
5
  applyLinePrefix,
6
6
  applyWrap,
7
- type HkMarkdownEditorMode,
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 mode: HkMarkdownEditorMode = "plain";
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(mode).toBe("plain");
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
+ });
@@ -1,4 +1,4 @@
1
- // HkMarkdownEditor chrome — the two-pane markdown/plain editor.
1
+ // HkMarkdownEditor chrome — the two-pane source/rendering editor.
2
2
  //
3
3
  // All colors ride hikari's token triplets (`rgb(var(--color-*))`,
4
4
  // `color-mix`), spacing/radius/motion ride the `--space-*` / `--radius-*`
@@ -18,10 +18,14 @@
18
18
  }
19
19
 
20
20
  // ── Toolbar row ──────────────────────────────────────────────────────────
21
- // The markdown actions (left) and the mode segmented control (right). The
22
- // mode control is part of the v-model:mode contract, not a toolbar action
23
- // — it stays when `toolbar` is off and when the plain mode retires the
24
- // markdown actions.
21
+ // Two family components, nothing hand-drawn: the formatting actions are
22
+ // HkIconButtonGroup in "buttons" mode (the toolbar grammar — a tight
23
+ // action strip with the hover reveal built in), retuned to the editor's
24
+ // compact 28px chrome step through the group's own documented size
25
+ // variable; the view segmented control is HkPillToggleGroup (a
26
+ // single-choice host keeps one value in the set). The view control is
27
+ // part of the v-model:view contract, not a toolbar action — it stays
28
+ // when `toolbar` is off.
25
29
 
26
30
  .hk-md-editor-toolbar {
27
31
  display: flex;
@@ -32,90 +36,26 @@
32
36
  background: color-mix(in srgb, rgb(var(--color-background)) 35%, transparent);
33
37
  }
34
38
 
35
- .hk-md-editor-actions {
36
- display: flex;
37
- align-items: center;
38
- gap: var(--space-2);
39
+ // Compound on purpose: the group's own size class ties this selector at
40
+ // (0,1,0), and source order between two sheets is not a contract.
41
+ .hk-icon-group.hk-md-editor-actions {
42
+ --hk-icon-group-item-size: 1.75rem;
39
43
  }
40
44
 
41
- // Ghost icon button: the toolbar's smallest chrome step. Borderless and
42
- // transparent until hovered — the label lives in `title`/`aria-label`.
43
- .hk-md-editor-action {
44
- display: inline-flex;
45
- align-items: center;
46
- justify-content: center;
47
- width: 1.75rem;
48
- height: 1.75rem;
49
- padding: 0;
50
- border: none;
51
- border-radius: var(--radius-sm);
52
- background: transparent;
53
- color: rgb(var(--color-muted));
54
- cursor: pointer;
55
- transition-property: background-color, color;
56
- transition-duration: var(--duration-short);
57
- transition-timing-function: var(--ease-standard);
58
-
59
- &:hover:not(:disabled) {
60
- background: color-mix(in srgb, rgb(var(--color-text)) 10%, transparent);
61
- color: rgb(var(--color-text));
62
- }
63
-
64
- &:focus-visible {
65
- outline: none;
66
- box-shadow: var(--shadow-focus);
67
- }
68
-
69
- &:disabled {
70
- opacity: 0.5;
71
- cursor: not-allowed;
72
- }
73
- }
74
-
75
- // Compact segmented control (right side of the row).
76
- .hk-md-editor-modes {
77
- display: inline-flex;
78
- align-items: center;
79
- gap: var(--space-2);
45
+ .hk-md-editor-views {
80
46
  margin-inline-start: auto;
81
- padding: var(--space-2);
82
- border: 1px solid var(--border-faint);
83
- border-radius: var(--radius-full);
84
- }
85
-
86
- .hk-md-editor-mode {
87
- border: none;
88
- padding: var(--space-2) var(--space-8);
89
- border-radius: var(--radius-full);
90
- background: transparent;
91
- color: rgb(var(--color-muted));
92
- font-size: var(--text-xs);
93
- line-height: 1.4;
94
- cursor: pointer;
95
- transition-property: background-color, color;
96
- transition-duration: var(--duration-short);
97
- transition-timing-function: var(--ease-standard);
98
-
99
- &:hover:not(:disabled) {
100
- color: rgb(var(--color-text));
101
- }
102
-
103
- // The active tint rides data-active (the segmented grammar shared with
104
- // HkPillToggleGroup) — a wash of the primary channel under the ink.
105
- &[data-active] {
106
- background: rgb(var(--color-primary) / 16%);
107
- color: rgb(var(--color-text));
108
- }
109
-
110
- &:disabled {
111
- opacity: 0.5;
112
- cursor: not-allowed;
113
- }
114
47
  }
115
48
 
116
49
  // ── Two-pane body ────────────────────────────────────────────────────────
117
- // ~50/50: each pane is flex-basis 50% with min-width 0 so long lines and
118
- // wide tables scroll inside their own pane instead of pushing the split.
50
+ // The body is `flex: 1` under the root, and each pane wrapper is a
51
+ // flex item with `min-height: 0`: under a host-bounded root (a
52
+ // `flex: 1` + `min-height: 0` chain or an explicit height — the root's
53
+ // `overflow: hidden` makes it shrinkable) neither pane's CONTENT can
54
+ // push the editor past its host. A long rendering scrolls inside its
55
+ // pane instead of growing the page, and the textarea (whose intrinsic
56
+ // height is its `rows`, never its text) fills the same row. A
57
+ // content-sized host gets the 12rem floor below, and the rendering may
58
+ // grow it — bound the editor when the page must not scroll.
119
59
 
120
60
  .hk-md-editor-body {
121
61
  display: flex;
@@ -129,18 +69,33 @@
129
69
  display: flex;
130
70
  flex: 1 1 50%;
131
71
  min-width: 0;
72
+ min-height: 0;
132
73
 
133
74
  // Drag-over highlight: an inset ring on the pane (the attribute comes
134
75
  // from the component's dragging state; the look lives here).
135
76
  &[data-dragging] {
136
77
  box-shadow: inset 0 0 0 2px rgb(var(--color-focused-border));
137
78
  }
79
+
80
+ // `display: flex` above outranks the UA `[hidden]` rule, so the
81
+ // attribute's own display: none is restated here.
82
+ &[hidden] {
83
+ display: none;
84
+ }
138
85
  }
139
86
 
140
87
  .hk-md-editor-input {
141
88
  box-sizing: border-box;
142
89
  flex: 1;
143
90
  width: 100%;
91
+ // Native scroll mechanics, no native bar (the house contract: the
92
+ // scrollbar-width/::-webkit-scrollbar suppression pair beside
93
+ // overflow) — the shared overlay rail attaches to the textarea.
94
+ overflow-y: auto;
95
+ scrollbar-width: none;
96
+ &::-webkit-scrollbar {
97
+ display: none;
98
+ }
144
99
  border: none;
145
100
  outline: none;
146
101
  resize: none;
@@ -160,14 +115,23 @@
160
115
  }
161
116
  }
162
117
 
163
- // The preview pane carries the divider (border on the pane, not a gap) —
164
- // in plain mode the renderer degrades to pre-wrapped plain text itself.
165
- // Native scroll mechanics, no native bar (the house contract: the
166
- // scrollbar-width/::-webkit-scrollbar suppression pair beside overflow).
167
- .hk-md-editor-preview {
118
+ // The preview pane's wrapper is the rails' host: the box that wraps
119
+ // EXACTLY the scroll viewport (positioned, sized by the flex row), the
120
+ // mount every other overlay-scrollbar consumer uses.
121
+ .hk-md-editor-preview-pane {
122
+ position: relative;
123
+ display: flex;
168
124
  flex: 1 1 50%;
169
125
  min-width: 0;
170
- overflow: auto;
126
+ min-height: 0;
127
+ }
128
+
129
+ // The preview viewport carries the divider (border on the pane, not a
130
+ // gap). Native scroll mechanics, no native bar — the shared overlay rail
131
+ // attaches to it (the same house contract as the textarea).
132
+ .hk-md-editor-preview {
133
+ flex: 1;
134
+ overflow-y: auto;
171
135
  scrollbar-width: none;
172
136
  &::-webkit-scrollbar {
173
137
  display: none;
@@ -177,14 +141,33 @@
177
141
  background: color-mix(in srgb, rgb(var(--color-background)) 35%, transparent);
178
142
  }
179
143
 
144
+ // A single-pane view takes the whole row — no divider without a sibling.
145
+ .hk-md-editor-body[data-view="text"] .hk-md-editor-input-pane,
146
+ .hk-md-editor-body[data-view="preview"] .hk-md-editor-preview-pane {
147
+ flex-basis: 100%;
148
+ }
149
+
150
+ .hk-md-editor-body[data-view="preview"] .hk-md-editor-preview {
151
+ border-inline-start: none;
152
+ }
153
+
180
154
  // Narrow hosts stack the panes — the divider follows the block axis.
181
155
  @media (max-width: 640px) {
182
156
  .hk-md-editor-body {
183
157
  flex-direction: column;
184
158
  }
185
159
 
160
+ .hk-md-editor-input-pane,
161
+ .hk-md-editor-preview-pane {
162
+ flex: 1 1 0%;
163
+ }
164
+
186
165
  .hk-md-editor-preview {
187
166
  border-inline-start: none;
188
167
  border-block-start: 1px solid var(--border-faint);
189
168
  }
169
+
170
+ .hk-md-editor-body[data-view="preview"] .hk-md-editor-preview {
171
+ border-block-start: none;
172
+ }
190
173
  }