@celestia-island/hikari 0.55.459 → 0.55.460
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/HkMarkdownEditor.d.ts +123 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/mermaid/wasmEngine.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/HkMarkdownEditor.barrel.test.ts +42 -0
- package/src/components/HkMarkdownEditor.scss +190 -0
- package/src/components/HkMarkdownEditor.test.tsx +404 -0
- package/src/components/HkMarkdownEditor.tsx +357 -0
- package/src/i18n/locales/ar/components.json +14 -1
- package/src/i18n/locales/de/components.json +14 -1
- package/src/i18n/locales/en/components.json +14 -1
- package/src/i18n/locales/es/components.json +14 -1
- package/src/i18n/locales/fr/components.json +14 -1
- package/src/i18n/locales/ja/components.json +14 -1
- package/src/i18n/locales/ko/components.json +14 -1
- package/src/i18n/locales/pt/components.json +14 -1
- package/src/i18n/locales/ru/components.json +14 -1
- package/src/i18n/locales/zh-Hans/components.json +14 -1
- package/src/i18n/locales/zh-Hant/components.json +14 -1
- package/src/index.ts +2 -0
- package/src/mermaid/wasmEngine.ts +1 -1
- package/src/scene3d/wasmFleetSpec.ts +1 -1
- package/src/utils/qr/qrEncoder.ts +6 -1
- package/src/wasm/highlight/hikari_wasm_highlight.d.ts +3 -2
- package/src/wasm/highlight/hikari_wasm_highlight.js +486 -160
- package/src/wasm/highlight/interfaces/celestia-hikari-highlight-types.d.ts +4 -0
- package/src/wasm/highlight/interfaces/wasi-cli-exit.d.ts +1 -0
- package/src/wasm/highlight/interfaces/wasi-clocks-monotonic-clock.d.ts +2 -0
- package/src/wasm/highlight/interfaces/wasi-clocks-wall-clock.d.ts +6 -0
- package/src/wasm/mermaid/hikari_wasm_mermaid.d.ts +3 -2
- package/src/wasm/mermaid/hikari_wasm_mermaid.js +487 -161
- package/src/wasm/mermaid/interfaces/celestia-hikari-mermaid-types.d.ts +4 -0
- package/src/wasm/mermaid/interfaces/wasi-cli-exit.d.ts +1 -0
- package/src/wasm/mermaid/interfaces/wasi-clocks-monotonic-clock.d.ts +2 -0
- package/src/wasm/mermaid/interfaces/wasi-clocks-wall-clock.d.ts +6 -0
- package/src/wasm/qr/hikari_wasm_qr.d.ts +4 -3
- package/src/wasm/qr/hikari_wasm_qr.js +475 -155
- package/src/wasm/qr/interfaces/{hikari-qr-types.d.ts → celestia-hikari-qr-types.d.ts} +1 -2
- package/src/wasm/qr/interfaces/wasi-cli-exit.d.ts +1 -0
- package/src/wasm/qr/interfaces/wasi-clocks-monotonic-clock.d.ts +2 -0
- package/src/wasm/qr/interfaces/wasi-clocks-wall-clock.d.ts +6 -0
- package/src/wasm/scene3d/hikari_wasm_scene3d.d.ts +4 -3
- package/src/wasm/scene3d/hikari_wasm_scene3d.js +482 -161
- package/src/wasm/scene3d/interfaces/{hikari-scene3d-types.d.ts → celestia-hikari-scene3d-types.d.ts} +1 -1
- package/src/wasm/scene3d/interfaces/wasi-cli-exit.d.ts +1 -0
- package/src/wasm/scene3d/interfaces/wasi-clocks-monotonic-clock.d.ts +2 -0
- package/src/wasm/scene3d/interfaces/wasi-clocks-wall-clock.d.ts +6 -0
- package/src/wasm/highlight/interfaces/hikari-highlight-types.d.ts +0 -4
- package/src/wasm/mermaid/interfaces/hikari-mermaid-types.d.ts +0 -4
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { createApp, h, nextTick } from "vue";
|
|
3
|
+
|
|
4
|
+
import HkMarkdownEditor, { applyLinePrefix, applyWrap } from "./HkMarkdownEditor";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HkMarkdownEditor contract: the v-model textarea, the pure toolbar
|
|
8
|
+
* 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).
|
|
12
|
+
* MUT:hikari-1486-R3-M18 (emit-only-files[0] mutation → "one imageDrop per
|
|
13
|
+
* file" assertion red) and MUT:hikari-1486-R3-M5 (preventDefault claim
|
|
14
|
+
* mutation → defaultPrevented assertion red) pin the emission contract.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
18
|
+
|
|
19
|
+
interface EditorEvents {
|
|
20
|
+
values: string[];
|
|
21
|
+
modes: string[];
|
|
22
|
+
files: File[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function mountEditor(
|
|
26
|
+
props: Record<string, unknown> = {},
|
|
27
|
+
): { container: HTMLElement; events: EditorEvents } {
|
|
28
|
+
const events: EditorEvents = { values: [], modes: [], files: [] };
|
|
29
|
+
const container = document.createElement("div");
|
|
30
|
+
document.body.appendChild(container);
|
|
31
|
+
const app = createApp({
|
|
32
|
+
render: () =>
|
|
33
|
+
h(HkMarkdownEditor, {
|
|
34
|
+
...props,
|
|
35
|
+
"onUpdate:modelValue": (v: string) => { events.values.push(v); },
|
|
36
|
+
"onUpdate:mode": (m: string) => { events.modes.push(m); },
|
|
37
|
+
onImageDrop: (f: File) => { events.files.push(f); },
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
app.mount(container);
|
|
41
|
+
mounts.push({ app, container });
|
|
42
|
+
return { container, events };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function textareaOf(c: HTMLElement): HTMLTextAreaElement {
|
|
46
|
+
const ta = c.querySelector<HTMLTextAreaElement>(".hk-md-editor-input");
|
|
47
|
+
expect(ta).not.toBeNull();
|
|
48
|
+
return ta!;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function actionButton(c: HTMLElement, label: string): HTMLButtonElement {
|
|
52
|
+
const btn = [...c.querySelectorAll<HTMLButtonElement>(".hk-md-editor-action")].find(
|
|
53
|
+
(b) => b.getAttribute("aria-label") === label,
|
|
54
|
+
);
|
|
55
|
+
expect(btn, `toolbar button "${label}"`).toBeTruthy();
|
|
56
|
+
return btn!;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function modeButton(c: HTMLElement, label: string): HTMLButtonElement {
|
|
60
|
+
const btn = [...c.querySelectorAll<HTMLButtonElement>(".hk-md-editor-mode")].find(
|
|
61
|
+
(b) => b.textContent?.trim() === label,
|
|
62
|
+
);
|
|
63
|
+
expect(btn, `mode button "${label}"`).toBeTruthy();
|
|
64
|
+
return btn!;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
afterEach(() => {
|
|
68
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
69
|
+
app.unmount();
|
|
70
|
+
container.remove();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
75
|
+
|
|
76
|
+
/** The renderer's parse pipeline is async (lazy marked/DOMPurify imports
|
|
77
|
+
* behind a coalesce window) — poll until the preview settles. */
|
|
78
|
+
async function settleFor(root: HTMLElement, predicate: () => boolean, tries = 240): Promise<void> {
|
|
79
|
+
for (let i = 0; i < tries; i += 1) {
|
|
80
|
+
if (predicate()) return;
|
|
81
|
+
await sleep(5);
|
|
82
|
+
await nextTick();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** happy-dom does not populate DragEvent/ClipboardEvent payloads; the
|
|
87
|
+
* editor only reads `.files`, so a plain stub object is the payload.
|
|
88
|
+
* comment-gate-ok: environment statement about the test runner, not a
|
|
89
|
+
* behaviour claim — the payload handling itself is pinned red-side by the
|
|
90
|
+
* drop/paste suites (MUT:hikari-1486-R3-M4/M19 gate-bypass mutations). */
|
|
91
|
+
function dropEvent(type: string, files: File[], types?: string[]): Event {
|
|
92
|
+
const ev = new Event(type, { bubbles: true, cancelable: true });
|
|
93
|
+
(ev as unknown as { dataTransfer: { files: File[]; types?: string[] } }).dataTransfer = {
|
|
94
|
+
files,
|
|
95
|
+
...(types !== undefined ? { types } : {}),
|
|
96
|
+
};
|
|
97
|
+
return ev;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ── Pure helpers ──────────────────────────────────────────────────────────
|
|
101
|
+
|
|
102
|
+
describe("applyWrap", () => {
|
|
103
|
+
it("wraps a middle selection and keeps it selected inside the markers", () => {
|
|
104
|
+
const edit = applyWrap("hello world", 6, 11, "**");
|
|
105
|
+
expect(edit.text).toBe("hello **world**");
|
|
106
|
+
// selection restored INSIDE the wrap, still around "world"
|
|
107
|
+
expect(edit.text.slice(edit.selectionStart, edit.selectionEnd)).toBe("world");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("parks the caret between the markers for an empty selection", () => {
|
|
111
|
+
const edit = applyWrap("hello", 5, 5, "`");
|
|
112
|
+
expect(edit.text).toBe("hello``");
|
|
113
|
+
expect(edit.selectionStart).toBe(6);
|
|
114
|
+
expect(edit.selectionEnd).toBe(6);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("supports asymmetric markers (link text)", () => {
|
|
118
|
+
const edit = applyWrap("say hi", 4, 6, "[", "]()");
|
|
119
|
+
expect(edit.text).toBe("say [hi]()");
|
|
120
|
+
expect(edit.text.slice(edit.selectionStart, edit.selectionEnd)).toBe("hi");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("clamps an out-of-range selection instead of corrupting the source", () => {
|
|
124
|
+
// Both indices clamp to the end: an empty-selection wrap there.
|
|
125
|
+
const edit = applyWrap("abc", 10, 99, "*");
|
|
126
|
+
expect(edit.text).toBe("abc**");
|
|
127
|
+
expect(edit.selectionStart).toBe(4);
|
|
128
|
+
expect(edit.selectionEnd).toBe(4);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe("applyLinePrefix", () => {
|
|
133
|
+
it("prefixes the line holding a mid-line caret", () => {
|
|
134
|
+
const edit = applyLinePrefix("one\ntwo\nthree", 5, 5, "## ");
|
|
135
|
+
expect(edit.text).toBe("one\n## two\nthree");
|
|
136
|
+
// selection covers the rewritten line
|
|
137
|
+
expect(edit.text.slice(edit.selectionStart, edit.selectionEnd)).toBe("## two");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("prefixes each selected line (multiline selection)", () => {
|
|
141
|
+
const edit = applyLinePrefix("a\nb\nc", 0, 3, "- ");
|
|
142
|
+
expect(edit.text).toBe("- a\n- b\nc");
|
|
143
|
+
expect(edit.text.slice(edit.selectionStart, edit.selectionEnd)).toBe("- a\n- b");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("numbers ordered-list lines per line index", () => {
|
|
147
|
+
const edit = applyLinePrefix("x\ny\nz", 0, 6, (i) => `${i + 1}. `);
|
|
148
|
+
expect(edit.text).toBe("1. x\n2. y\n3. z");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("operates through the last line without a trailing newline", () => {
|
|
152
|
+
const edit = applyLinePrefix("first\nlast", 7, 7, "> ");
|
|
153
|
+
expect(edit.text).toBe("first\n> last");
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// ── Component ─────────────────────────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
describe("HkMarkdownEditor", () => {
|
|
160
|
+
it("typing in the textarea emits update:modelValue", async () => {
|
|
161
|
+
const { container, events } = mountEditor({ modelValue: "" });
|
|
162
|
+
const ta = textareaOf(container);
|
|
163
|
+
ta.value = "hello";
|
|
164
|
+
ta.dispatchEvent(new Event("input", { bubbles: true }));
|
|
165
|
+
await nextTick();
|
|
166
|
+
expect(events.values).toEqual(["hello"]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("toolbar bold wraps the current textarea selection", async () => {
|
|
170
|
+
const { container, events } = mountEditor({ modelValue: "hello world" });
|
|
171
|
+
const ta = textareaOf(container);
|
|
172
|
+
ta.selectionStart = 6;
|
|
173
|
+
ta.selectionEnd = 11;
|
|
174
|
+
actionButton(container, "Bold").dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
175
|
+
await nextTick();
|
|
176
|
+
expect(events.values).toEqual(["hello **world**"]);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("toolbar ordered list prefixes each selected line", async () => {
|
|
180
|
+
const { container, events } = mountEditor({ modelValue: "a\nb" });
|
|
181
|
+
const ta = textareaOf(container);
|
|
182
|
+
ta.selectionStart = 0;
|
|
183
|
+
ta.selectionEnd = 3;
|
|
184
|
+
actionButton(container, "Ordered list").dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
185
|
+
await nextTick();
|
|
186
|
+
expect(events.values).toEqual(["1. a\n2. b"]);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("toolbar link puts the caret in the url slot — empty selection too (R2 S1 pin)", async () => {
|
|
190
|
+
// The caret assertion needs the v-model loop CLOSED (the restored
|
|
191
|
+
// selection lands on the fed-back value), so this harness is stateful.
|
|
192
|
+
const container = document.createElement("div");
|
|
193
|
+
document.body.appendChild(container);
|
|
194
|
+
const app = createApp({
|
|
195
|
+
data: () => ({ value: "hello world" }),
|
|
196
|
+
render() {
|
|
197
|
+
return h(HkMarkdownEditor, {
|
|
198
|
+
modelValue: this.value,
|
|
199
|
+
"onUpdate:modelValue": (v: string) => { this.value = v; },
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
app.mount(container);
|
|
204
|
+
mounts.push({ app, container });
|
|
205
|
+
|
|
206
|
+
// Empty selection at the end: `hello world[]()` … caret in the url slot.
|
|
207
|
+
const ta = textareaOf(container);
|
|
208
|
+
ta.focus();
|
|
209
|
+
ta.selectionStart = 11;
|
|
210
|
+
ta.selectionEnd = 11;
|
|
211
|
+
actionButton(container, "Link").dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
212
|
+
await nextTick();
|
|
213
|
+
await nextTick();
|
|
214
|
+
expect(ta.value).toBe("hello world[]()");
|
|
215
|
+
expect(ta.selectionStart).toBe(14);
|
|
216
|
+
expect(ta.selectionEnd).toBe(14);
|
|
217
|
+
|
|
218
|
+
// Non-empty selection: the selection becomes the link text, caret in
|
|
219
|
+
// the url slot — `hello [world]()[]()` … caret after the FIRST `(`.
|
|
220
|
+
ta.selectionStart = 6;
|
|
221
|
+
ta.selectionEnd = 11;
|
|
222
|
+
actionButton(container, "Link").dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
223
|
+
await nextTick();
|
|
224
|
+
await nextTick();
|
|
225
|
+
expect(ta.value).toBe("hello [world]()[]()");
|
|
226
|
+
expect(ta.selectionStart).toBe(14);
|
|
227
|
+
expect(ta.selectionEnd).toBe(14);
|
|
228
|
+
});
|
|
229
|
+
|
|
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.
|
|
233
|
+
const events: string[] = [];
|
|
234
|
+
const container = document.createElement("div");
|
|
235
|
+
document.body.appendChild(container);
|
|
236
|
+
const app = createApp({
|
|
237
|
+
data: () => ({ mode: "markdown" as string }),
|
|
238
|
+
render() {
|
|
239
|
+
return h(HkMarkdownEditor, {
|
|
240
|
+
modelValue: "",
|
|
241
|
+
mode: this.mode,
|
|
242
|
+
"onUpdate:mode": (m: string) => { events.push(m); this.mode = m; },
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
app.mount(container);
|
|
247
|
+
mounts.push({ app, container });
|
|
248
|
+
|
|
249
|
+
modeButton(container, "Plain text").dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
250
|
+
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 }));
|
|
256
|
+
await nextTick();
|
|
257
|
+
expect(events).toEqual(["plain"]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("split view renders the markdown preview for a heading", async () => {
|
|
261
|
+
const { container } = mountEditor({ modelValue: "# hi" });
|
|
262
|
+
const preview = container.querySelector<HTMLElement>(".hk-md-editor-preview");
|
|
263
|
+
expect(preview, "preview pane renders in split view").not.toBeNull();
|
|
264
|
+
// The preview IS a mounted HkMarkdownRenderer fed the live source.
|
|
265
|
+
// Under happy-dom DOMPurify strips heading ELEMENTS (verified:
|
|
266
|
+
// sanitize('<h1>hi</h1>') → 'hi'), so the assertion rides the
|
|
267
|
+
// renderer's own output classes plus the settled text content —
|
|
268
|
+
// the same textContent idiom HkMarkdownRenderer's suites use.
|
|
269
|
+
// comment-gate-ok: verified environment fact (probe output quoted
|
|
270
|
+
// 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).
|
|
273
|
+
expect(preview!.querySelector(".hk-markdown .hk-markdown-body")).not.toBeNull();
|
|
274
|
+
await settleFor(container, () =>
|
|
275
|
+
(preview!.querySelector(".hk-markdown-body")?.textContent ?? "").includes("hi"),
|
|
276
|
+
);
|
|
277
|
+
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).
|
|
279
|
+
expect(preview!.querySelector(".hk-markdown")?.hasAttribute("data-plain")).toBe(false);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("edit view renders no preview pane", () => {
|
|
283
|
+
const { container } = mountEditor({ modelValue: "# hi", view: "edit" });
|
|
284
|
+
expect(container.querySelector(".hk-md-editor-preview")).toBeNull();
|
|
285
|
+
expect(container.querySelector(".hk-md-editor-input")).not.toBeNull();
|
|
286
|
+
});
|
|
287
|
+
|
|
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");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("toolbar=false hides the actions but keeps the mode control", () => {
|
|
301
|
+
const { container } = mountEditor({ modelValue: "", toolbar: false });
|
|
302
|
+
expect(container.querySelector(".hk-md-editor-actions")).toBeNull();
|
|
303
|
+
expect(container.querySelector(".hk-md-editor-modes")).not.toBeNull();
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("dropping an image file emits one imageDrop per file and prevents the default", async () => {
|
|
307
|
+
const png = new File(["x"], "a.png", { type: "image/png" });
|
|
308
|
+
const jpg = new File(["y"], "b.jpg", { type: "image/jpeg" });
|
|
309
|
+
const txt = new File(["z"], "c.txt", { type: "text/plain" });
|
|
310
|
+
const { container, events } = mountEditor({ modelValue: "" });
|
|
311
|
+
const pane = container.querySelector<HTMLElement>(".hk-md-editor-input-pane")!;
|
|
312
|
+
const ev = dropEvent("drop", [png, jpg, txt]);
|
|
313
|
+
pane.dispatchEvent(ev);
|
|
314
|
+
await nextTick();
|
|
315
|
+
expect(events.files).toEqual([png, jpg]);
|
|
316
|
+
expect(ev.defaultPrevented, "an image drop is claimed, never navigated").toBe(true);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("dragover highlights the pane; dragleave and drop clear it", async () => {
|
|
320
|
+
const file = new File(["x"], "a.png", { type: "image/png" });
|
|
321
|
+
const { container } = mountEditor({ modelValue: "" });
|
|
322
|
+
const pane = container.querySelector<HTMLElement>(".hk-md-editor-input-pane")!;
|
|
323
|
+
|
|
324
|
+
// The highlight is a rendered attribute — it flushes on the next patch
|
|
325
|
+
// tick, not synchronously with the event.
|
|
326
|
+
pane.dispatchEvent(dropEvent("dragover", [file]));
|
|
327
|
+
await nextTick();
|
|
328
|
+
expect(pane.hasAttribute("data-dragging"), "dragover sets data-dragging").toBe(true);
|
|
329
|
+
|
|
330
|
+
pane.dispatchEvent(new Event("dragleave", { bubbles: true }));
|
|
331
|
+
await nextTick();
|
|
332
|
+
expect(pane.hasAttribute("data-dragging"), "dragleave clears data-dragging").toBe(false);
|
|
333
|
+
|
|
334
|
+
pane.dispatchEvent(dropEvent("dragover", [file]));
|
|
335
|
+
await nextTick();
|
|
336
|
+
pane.dispatchEvent(dropEvent("drop", [file]));
|
|
337
|
+
await nextTick();
|
|
338
|
+
expect(pane.hasAttribute("data-dragging"), "drop clears data-dragging").toBe(false);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it("an in-page drag (no Files payload type) never highlights", async () => {
|
|
342
|
+
const { container } = mountEditor({ modelValue: "" });
|
|
343
|
+
const pane = container.querySelector<HTMLElement>(".hk-md-editor-input-pane")!;
|
|
344
|
+
// A text/node drag over the pane advertises non-Files types — the
|
|
345
|
+
// highlight is reserved for file drags only.
|
|
346
|
+
pane.dispatchEvent(dropEvent("dragover", [], ["text/plain"]));
|
|
347
|
+
await nextTick();
|
|
348
|
+
expect(pane.hasAttribute("data-dragging")).toBe(false);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("pasting an image emits imageDrop and prevents the default", async () => {
|
|
352
|
+
const file = new File(["x"], "shot.png", { type: "image/png" });
|
|
353
|
+
const { container, events } = mountEditor({ modelValue: "" });
|
|
354
|
+
const ta = textareaOf(container);
|
|
355
|
+
const ev = new Event("paste", { bubbles: true, cancelable: true });
|
|
356
|
+
(ev as unknown as { clipboardData: { files: File[] } }).clipboardData = { files: [file] };
|
|
357
|
+
ta.dispatchEvent(ev);
|
|
358
|
+
await nextTick();
|
|
359
|
+
expect(events.files).toEqual([file]);
|
|
360
|
+
expect(ev.defaultPrevented).toBe(true);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("a non-image drop falls through to the browser default", async () => {
|
|
364
|
+
const txt = new File(["z"], "notes.txt", { type: "text/plain" });
|
|
365
|
+
const { container, events } = mountEditor({ modelValue: "" });
|
|
366
|
+
const pane = container.querySelector<HTMLElement>(".hk-md-editor-input-pane")!;
|
|
367
|
+
const ev = dropEvent("drop", [txt]);
|
|
368
|
+
pane.dispatchEvent(ev);
|
|
369
|
+
await nextTick();
|
|
370
|
+
expect(events.files).toEqual([]);
|
|
371
|
+
expect(ev.defaultPrevented).toBe(false);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("imageDrop=false disables the channel: no emit, default not prevented", async () => {
|
|
375
|
+
const file = new File(["x"], "a.png", { type: "image/png" });
|
|
376
|
+
const { container, events } = mountEditor({ modelValue: "", imageDrop: false });
|
|
377
|
+
const pane = container.querySelector<HTMLElement>(".hk-md-editor-input-pane")!;
|
|
378
|
+
const dropEv = dropEvent("drop", [file]);
|
|
379
|
+
pane.dispatchEvent(dropEv);
|
|
380
|
+
|
|
381
|
+
const ta = textareaOf(container);
|
|
382
|
+
const pasteEv = new Event("paste", { bubbles: true, cancelable: true });
|
|
383
|
+
(pasteEv as unknown as { clipboardData: { files: File[] } }).clipboardData = { files: [file] };
|
|
384
|
+
ta.dispatchEvent(pasteEv);
|
|
385
|
+
await nextTick();
|
|
386
|
+
expect(events.files).toEqual([]);
|
|
387
|
+
expect(dropEv.defaultPrevented).toBe(false);
|
|
388
|
+
expect(pasteEv.defaultPrevented).toBe(false);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("disabled blocks the channel too and disables the textarea and controls", async () => {
|
|
392
|
+
const file = new File(["x"], "a.png", { type: "image/png" });
|
|
393
|
+
const { container, events } = mountEditor({ modelValue: "", disabled: true });
|
|
394
|
+
const pane = container.querySelector<HTMLElement>(".hk-md-editor-input-pane")!;
|
|
395
|
+
const dropEv = dropEvent("drop", [file]);
|
|
396
|
+
pane.dispatchEvent(dropEv);
|
|
397
|
+
await nextTick();
|
|
398
|
+
expect(events.files).toEqual([]);
|
|
399
|
+
expect(dropEv.defaultPrevented).toBe(false);
|
|
400
|
+
expect(textareaOf(container).disabled).toBe(true);
|
|
401
|
+
expect(actionButton(container, "Bold").disabled).toBe(true);
|
|
402
|
+
expect(modeButton(container, "Plain text").disabled).toBe(true);
|
|
403
|
+
});
|
|
404
|
+
});
|