@remit/web-client 0.0.138 → 0.0.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/components/compose/AddressField.tsx +20 -188
- package/src/components/compose/ComposeForm.tsx +51 -87
- package/src/components/compose/ComposeSmtpMissingBanner.tsx +10 -35
- package/src/components/compose/MobileComposeSheet.tsx +1 -1
- package/src/components/mail/DailyBrief.tsx +91 -31
- package/src/components/mail/MailListHeader.tsx +5 -1
- package/src/components/mail/MessageList.tsx +1 -1
- package/src/components/mail/ThreadListInteraction.tsx +6 -2
- package/src/components/settings/label-delete-confirm.stories.tsx +1 -1
- package/src/lib/brief-chip-query.test.ts +85 -0
- package/src/lib/organize/search-to-rule.test.ts +15 -1
- package/src/lib/search-tokens.ts +20 -86
- package/src/routes/settings/labels.tsx +1 -1
- package/src/components/compose/ComposeBody.stories.tsx +0 -463
- package/src/components/compose/ComposeBody.tsx +0 -210
- package/src/components/compose/SubjectField.tsx +0 -19
- package/src/components/compose/compose-mode.test.ts +0 -76
- package/src/components/compose/compose-mode.ts +0 -50
- package/src/components/ui/ConfirmDialog.stories.tsx +0 -54
- package/src/components/ui/ConfirmDialog.tsx +0 -140
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
import type { RichTextValue } from "@remit/ui/rich-text";
|
|
2
|
-
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
import { expect, fn, userEvent, waitFor, within } from "storybook/test";
|
|
5
|
-
import { ComposeBody, type ConversionFailure } from "./ComposeBody";
|
|
6
|
-
|
|
7
|
-
const RICH_DOCUMENT = [
|
|
8
|
-
"<h2>Quarterly numbers</h2>",
|
|
9
|
-
"<p>Revenue is <strong>up</strong> on the quarter.</p>",
|
|
10
|
-
"<table><thead><tr><th>Region</th><th>Total</th></tr></thead>",
|
|
11
|
-
"<tbody><tr><td>EMEA</td><td>412</td></tr></tbody></table>",
|
|
12
|
-
].join("");
|
|
13
|
-
|
|
14
|
-
const PLAIN_PARAGRAPHS =
|
|
15
|
-
"<p>Thanks — that works.</p><p></p><p>See you then.</p>";
|
|
16
|
-
|
|
17
|
-
const UNDERLINED = "<p>Please <u>read this</u> before Friday.</p>";
|
|
18
|
-
|
|
19
|
-
const PLAIN_MARKDOWN = [
|
|
20
|
-
"## Quarterly numbers",
|
|
21
|
-
"",
|
|
22
|
-
"| Region | Total |",
|
|
23
|
-
"| --- | --- |",
|
|
24
|
-
"| EMEA | 412 |",
|
|
25
|
-
].join("\n");
|
|
26
|
-
|
|
27
|
-
const DUTCH_DOCUMENT =
|
|
28
|
-
"<p>Beste Anna, de vergadering van donderdag gaat niet door. Ik stuur je morgen een nieuw voorstel voor de planning.</p>";
|
|
29
|
-
|
|
30
|
-
const DUTCH_PROSE =
|
|
31
|
-
"Beste Anna, de vergadering van donderdag gaat niet door. Ik stuur je morgen een nieuw voorstel.";
|
|
32
|
-
|
|
33
|
-
/** The languages a Dutch-writing account has configured, most-used first. */
|
|
34
|
-
const LANGUAGES = ["nl", "en", "de"];
|
|
35
|
-
|
|
36
|
-
const noop = () => undefined;
|
|
37
|
-
|
|
38
|
-
const Harness = ({
|
|
39
|
-
initialHtml = "",
|
|
40
|
-
initialText = "",
|
|
41
|
-
startIn = "rich",
|
|
42
|
-
onConversionError = () => undefined,
|
|
43
|
-
conversions,
|
|
44
|
-
languages = LANGUAGES,
|
|
45
|
-
quoted,
|
|
46
|
-
}: {
|
|
47
|
-
initialHtml?: string;
|
|
48
|
-
initialText?: string;
|
|
49
|
-
startIn?: "rich" | "plain";
|
|
50
|
-
onConversionError?: (failure: ConversionFailure) => void;
|
|
51
|
-
conversions?: {
|
|
52
|
-
toPlain: (value: RichTextValue) => string;
|
|
53
|
-
toRich: (text: string) => string;
|
|
54
|
-
};
|
|
55
|
-
languages?: string[];
|
|
56
|
-
quoted?: string;
|
|
57
|
-
}) => {
|
|
58
|
-
const [mode, setMode] = useState<"rich" | "plain">(startIn);
|
|
59
|
-
return (
|
|
60
|
-
<div className="flex h-[460px] w-[680px] flex-col overflow-auto rounded-md border border-line bg-canvas">
|
|
61
|
-
<ComposeBody
|
|
62
|
-
mode={mode}
|
|
63
|
-
onModeChange={setMode}
|
|
64
|
-
initialHtml={initialHtml}
|
|
65
|
-
initialText={initialText}
|
|
66
|
-
onChange={() => undefined}
|
|
67
|
-
onConversionError={onConversionError}
|
|
68
|
-
conversions={conversions}
|
|
69
|
-
languages={languages}
|
|
70
|
-
onLanguageChange={noop}
|
|
71
|
-
/>
|
|
72
|
-
{quoted && (
|
|
73
|
-
<blockquote
|
|
74
|
-
data-testid="compose-quoted"
|
|
75
|
-
lang="fr"
|
|
76
|
-
className="border-l-2 border-line px-3 py-2 text-sm text-fg-muted"
|
|
77
|
-
>
|
|
78
|
-
{quoted}
|
|
79
|
-
</blockquote>
|
|
80
|
-
)}
|
|
81
|
-
</div>
|
|
82
|
-
);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const chipOf = (canvasElement: HTMLElement): HTMLElement => {
|
|
86
|
-
const chip = canvasElement.querySelector<HTMLElement>(
|
|
87
|
-
"[data-testid=compose-language-chip]",
|
|
88
|
-
);
|
|
89
|
-
if (!chip) throw new Error("the language chip is not mounted");
|
|
90
|
-
return chip;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* The mode switch as the compose window runs it: the toolbar control, the one
|
|
95
|
-
* warning it raises, and the two surfaces it swaps between. The live
|
|
96
|
-
* `ComposeForm` adds the recipients, the autosave and the send around this.
|
|
97
|
-
*/
|
|
98
|
-
const meta: Meta<typeof Harness> = {
|
|
99
|
-
title: "Screens/WebClient/ComposeModes",
|
|
100
|
-
component: Harness,
|
|
101
|
-
parameters: { layout: "centered" },
|
|
102
|
-
};
|
|
103
|
-
export default meta;
|
|
104
|
-
|
|
105
|
-
type Story = StoryObj<typeof Harness>;
|
|
106
|
-
|
|
107
|
-
const toggleOf = (canvasElement: HTMLElement): HTMLElement => {
|
|
108
|
-
const toggle = canvasElement.querySelector<HTMLElement>(
|
|
109
|
-
"[data-testid=compose-mode-toggle]",
|
|
110
|
-
);
|
|
111
|
-
if (!toggle) throw new Error("the mode toggle is not mounted");
|
|
112
|
-
return toggle;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const plainSurface = (canvasElement: HTMLElement): HTMLTextAreaElement | null =>
|
|
116
|
-
canvasElement.querySelector<HTMLTextAreaElement>(
|
|
117
|
-
"[data-testid=compose-body-plain]",
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
export const RichDocument: Story = {
|
|
121
|
-
name: "Rich, with formatting",
|
|
122
|
-
args: { initialHtml: RICH_DOCUMENT },
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export const PlainDraft: Story = {
|
|
126
|
-
name: "Plain, reopened from Markdown",
|
|
127
|
-
args: { startIn: "plain", initialText: PLAIN_MARKDOWN },
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Cancel changes nothing: the mode stays rich, the document is untouched, and
|
|
132
|
-
* focus comes back to the control that was pressed. `aria-pressed` never flips
|
|
133
|
-
* optimistically.
|
|
134
|
-
*/
|
|
135
|
-
export const WarningCancelled: Story = {
|
|
136
|
-
name: "The warning, cancelled",
|
|
137
|
-
args: { initialHtml: RICH_DOCUMENT },
|
|
138
|
-
play: async ({ canvasElement }) => {
|
|
139
|
-
const toggle = toggleOf(canvasElement);
|
|
140
|
-
await userEvent.click(toggle);
|
|
141
|
-
|
|
142
|
-
const dialog = within(document.body).getByRole("dialog");
|
|
143
|
-
await expect(dialog).toHaveTextContent("Switch to plain text?");
|
|
144
|
-
await expect(dialog).toHaveTextContent(
|
|
145
|
-
"Formatting becomes Markdown. Bold keeps its asterisks, a table becomes rows of pipes, and that text is what the recipient gets. No formatted version is sent alongside it.",
|
|
146
|
-
);
|
|
147
|
-
await expect(toggle).toHaveAttribute("aria-pressed", "false");
|
|
148
|
-
|
|
149
|
-
await userEvent.click(
|
|
150
|
-
within(dialog).getByRole("button", { name: "Cancel" }),
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
await expect(plainSurface(canvasElement)).toBeNull();
|
|
154
|
-
await expect(
|
|
155
|
-
canvasElement.querySelector("[data-testid=compose-body] table"),
|
|
156
|
-
).not.toBeNull();
|
|
157
|
-
await expect(toggleOf(canvasElement)).toHaveFocus();
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export const WarningConfirmed: Story = {
|
|
162
|
-
name: "The warning, confirmed",
|
|
163
|
-
args: { initialHtml: RICH_DOCUMENT },
|
|
164
|
-
play: async ({ canvasElement }) => {
|
|
165
|
-
await userEvent.click(toggleOf(canvasElement));
|
|
166
|
-
await userEvent.click(
|
|
167
|
-
within(within(document.body).getByRole("dialog")).getByRole("button", {
|
|
168
|
-
name: "Switch to plain text",
|
|
169
|
-
}),
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
const textarea = plainSurface(canvasElement);
|
|
173
|
-
if (!textarea) throw new Error("the plain surface did not arrive");
|
|
174
|
-
await expect(textarea.value).toContain("## Quarterly numbers");
|
|
175
|
-
await expect(textarea.value).toContain("**up**");
|
|
176
|
-
await expect(textarea.value).toContain("| EMEA | 412 |");
|
|
177
|
-
|
|
178
|
-
// The formatting buttons leave with the rich surface.
|
|
179
|
-
await expect(
|
|
180
|
-
canvasElement.querySelector("[aria-label='Bold (Ctrl+B)']"),
|
|
181
|
-
).toBeNull();
|
|
182
|
-
await expect(toggleOf(canvasElement)).toHaveAttribute(
|
|
183
|
-
"aria-pressed",
|
|
184
|
-
"true",
|
|
185
|
-
);
|
|
186
|
-
await expect(textarea).toHaveFocus();
|
|
187
|
-
await expect(textarea.selectionStart).toBe(textarea.value.length);
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
/** Nothing but paragraphs and a blank line: switching changes nothing, so nothing is asked. */
|
|
192
|
-
export const PlainProseSwitchesSilently: Story = {
|
|
193
|
-
name: "Plain paragraphs switch without asking",
|
|
194
|
-
args: { initialHtml: PLAIN_PARAGRAPHS },
|
|
195
|
-
play: async ({ canvasElement }) => {
|
|
196
|
-
await userEvent.click(toggleOf(canvasElement));
|
|
197
|
-
|
|
198
|
-
await expect(within(document.body).queryByRole("dialog")).toBeNull();
|
|
199
|
-
const textarea = plainSurface(canvasElement);
|
|
200
|
-
if (!textarea) throw new Error("the plain surface did not arrive");
|
|
201
|
-
await expect(textarea.value).toContain("Thanks");
|
|
202
|
-
await expect(textarea.value).toContain("See you then.");
|
|
203
|
-
},
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* An underlined word exports identical to its own characters, so a comparison
|
|
208
|
-
* of the two strings would switch in silence and destroy it. The rule reads the
|
|
209
|
-
* document instead.
|
|
210
|
-
*/
|
|
211
|
-
export const UnderlineStillWarns: Story = {
|
|
212
|
-
name: "An underline alone still warns",
|
|
213
|
-
args: { initialHtml: UNDERLINED },
|
|
214
|
-
play: async ({ canvasElement }) => {
|
|
215
|
-
await userEvent.click(toggleOf(canvasElement));
|
|
216
|
-
|
|
217
|
-
await expect(within(document.body).getByRole("dialog")).toHaveTextContent(
|
|
218
|
-
"Switch to plain text?",
|
|
219
|
-
);
|
|
220
|
-
},
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
export const PlainToRich: Story = {
|
|
224
|
-
name: "Markdown back to rich, without asking",
|
|
225
|
-
args: { startIn: "plain", initialText: PLAIN_MARKDOWN },
|
|
226
|
-
play: async ({ canvasElement }) => {
|
|
227
|
-
await userEvent.click(toggleOf(canvasElement));
|
|
228
|
-
|
|
229
|
-
await expect(within(document.body).queryByRole("dialog")).toBeNull();
|
|
230
|
-
const editable = canvasElement.querySelector("[data-testid=compose-body]");
|
|
231
|
-
if (!editable) throw new Error("the rich surface did not arrive");
|
|
232
|
-
await expect(editable.querySelector("h2")).not.toBeNull();
|
|
233
|
-
await expect(editable.querySelector("table td")).not.toBeNull();
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
/** Switching an ordinary note to rich must not reflow it. */
|
|
238
|
-
export const PlainProseToRich: Story = {
|
|
239
|
-
name: "Prose with no Markdown in it",
|
|
240
|
-
args: {
|
|
241
|
-
startIn: "plain",
|
|
242
|
-
initialText: "Thanks — that works.\n\nI'll send the deck tomorrow.",
|
|
243
|
-
},
|
|
244
|
-
play: async ({ canvasElement }) => {
|
|
245
|
-
await userEvent.click(toggleOf(canvasElement));
|
|
246
|
-
|
|
247
|
-
const editable = canvasElement.querySelector("[data-testid=compose-body]");
|
|
248
|
-
if (!editable) throw new Error("the rich surface did not arrive");
|
|
249
|
-
await expect(editable.querySelectorAll("p").length).toBe(2);
|
|
250
|
-
await expect(editable.textContent).toContain("Thanks — that works.");
|
|
251
|
-
await expect(editable.textContent).toContain(
|
|
252
|
-
"I'll send the deck tomorrow.",
|
|
253
|
-
);
|
|
254
|
-
},
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* A conversion that would blank a written message does not happen: autosave
|
|
259
|
-
* would persist the empty body a moment later and the draft would be gone with
|
|
260
|
-
* nothing said.
|
|
261
|
-
*/
|
|
262
|
-
export const ConversionCameBackEmpty: Story = {
|
|
263
|
-
name: "A conversion that came back empty",
|
|
264
|
-
args: {
|
|
265
|
-
startIn: "plain",
|
|
266
|
-
initialText: "Everything I wrote this morning.",
|
|
267
|
-
onConversionError: fn(),
|
|
268
|
-
conversions: {
|
|
269
|
-
toPlain: (value) => value.text,
|
|
270
|
-
toRich: () => "",
|
|
271
|
-
},
|
|
272
|
-
},
|
|
273
|
-
play: async ({ args, canvasElement }) => {
|
|
274
|
-
await userEvent.click(toggleOf(canvasElement));
|
|
275
|
-
|
|
276
|
-
await expect(args.onConversionError).toHaveBeenCalledWith({
|
|
277
|
-
outcome: "blocked",
|
|
278
|
-
title: "Couldn't switch to rich text",
|
|
279
|
-
detail: "The conversion came back empty, so your message is unchanged.",
|
|
280
|
-
});
|
|
281
|
-
const textarea = plainSurface(canvasElement);
|
|
282
|
-
if (!textarea) throw new Error("the plain surface left");
|
|
283
|
-
await expect(textarea.value).toBe("Everything I wrote this morning.");
|
|
284
|
-
await expect(toggleOf(canvasElement)).toHaveAttribute(
|
|
285
|
-
"aria-pressed",
|
|
286
|
-
"true",
|
|
287
|
-
);
|
|
288
|
-
},
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
/** One Shift+Tab out of the body reaches the toggle, and Enter acts. */
|
|
292
|
-
export const ReachableFromTheBody: Story = {
|
|
293
|
-
name: "Shift+Tab from the body reaches it",
|
|
294
|
-
args: { initialHtml: PLAIN_PARAGRAPHS },
|
|
295
|
-
play: async ({ canvasElement }) => {
|
|
296
|
-
const editable = canvasElement.querySelector<HTMLElement>(
|
|
297
|
-
"[data-testid=compose-body]",
|
|
298
|
-
);
|
|
299
|
-
if (!editable) throw new Error("the rich surface is not mounted");
|
|
300
|
-
|
|
301
|
-
await userEvent.click(editable);
|
|
302
|
-
await userEvent.tab({ shift: true });
|
|
303
|
-
await expect(toggleOf(canvasElement)).toHaveFocus();
|
|
304
|
-
|
|
305
|
-
await userEvent.keyboard("{Enter}");
|
|
306
|
-
await expect(plainSurface(canvasElement)).not.toBeNull();
|
|
307
|
-
},
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Detection runs over the body against the account's own languages and writes
|
|
312
|
-
* the result onto the writing surface. Firefox picks a dictionary from that tag
|
|
313
|
-
* among the ones the user installed; Chrome and Safari ignore it, and nothing
|
|
314
|
-
* here says otherwise.
|
|
315
|
-
*/
|
|
316
|
-
export const DutchIsDetected: Story = {
|
|
317
|
-
name: "Dutch prose sets the chip",
|
|
318
|
-
args: { initialHtml: DUTCH_DOCUMENT },
|
|
319
|
-
play: async ({ canvasElement }) => {
|
|
320
|
-
await waitFor(
|
|
321
|
-
async () => {
|
|
322
|
-
await expect(chipOf(canvasElement)).toHaveTextContent("NL");
|
|
323
|
-
},
|
|
324
|
-
{ timeout: 5000 },
|
|
325
|
-
);
|
|
326
|
-
await expect(
|
|
327
|
-
canvasElement.querySelector("[data-testid=compose-body]"),
|
|
328
|
-
).toHaveAttribute("lang", "nl");
|
|
329
|
-
},
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
/** Under twenty characters detection is a coin toss, so the account default stands. */
|
|
333
|
-
export const TooShortHoldsTheDefault: Story = {
|
|
334
|
-
name: "Nine characters hold the default",
|
|
335
|
-
args: { startIn: "plain" },
|
|
336
|
-
play: async ({ canvasElement }) => {
|
|
337
|
-
const textarea = plainSurface(canvasElement);
|
|
338
|
-
if (!textarea) throw new Error("the plain surface is not mounted");
|
|
339
|
-
|
|
340
|
-
await userEvent.click(textarea);
|
|
341
|
-
await userEvent.keyboard("Hi Sophie");
|
|
342
|
-
|
|
343
|
-
await new Promise((resolve) => setTimeout(resolve, 800));
|
|
344
|
-
await expect(chipOf(canvasElement)).toHaveTextContent("NL");
|
|
345
|
-
},
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* The first manual pick freezes the language for the rest of the message.
|
|
350
|
-
* Detection does not argue with a choice the user made — a tag that moved back
|
|
351
|
-
* under the caret would be a control that undoes itself.
|
|
352
|
-
*/
|
|
353
|
-
export const ManualPickSticks: Story = {
|
|
354
|
-
name: "A picked language survives more typing",
|
|
355
|
-
args: { startIn: "plain" },
|
|
356
|
-
play: async ({ canvasElement }) => {
|
|
357
|
-
const textarea = plainSurface(canvasElement);
|
|
358
|
-
if (!textarea) throw new Error("the plain surface is not mounted");
|
|
359
|
-
|
|
360
|
-
await userEvent.click(textarea);
|
|
361
|
-
await userEvent.keyboard(DUTCH_PROSE);
|
|
362
|
-
await waitFor(
|
|
363
|
-
async () => {
|
|
364
|
-
await expect(chipOf(canvasElement)).toHaveTextContent("NL");
|
|
365
|
-
},
|
|
366
|
-
{ timeout: 5000 },
|
|
367
|
-
);
|
|
368
|
-
|
|
369
|
-
await userEvent.click(chipOf(canvasElement));
|
|
370
|
-
await userEvent.click(
|
|
371
|
-
within(canvasElement).getByRole("menuitemradio", { name: /English/ }),
|
|
372
|
-
);
|
|
373
|
-
await expect(chipOf(canvasElement)).toHaveTextContent("EN");
|
|
374
|
-
|
|
375
|
-
await userEvent.click(textarea);
|
|
376
|
-
await userEvent.keyboard(" Groetjes, Matthijs.");
|
|
377
|
-
await new Promise((resolve) => setTimeout(resolve, 800));
|
|
378
|
-
await expect(chipOf(canvasElement)).toHaveTextContent("EN");
|
|
379
|
-
await expect(textarea).toHaveAttribute("lang", "en");
|
|
380
|
-
},
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Two Shift+Tabs out of the body reach the chip — one still reaches the mode
|
|
385
|
-
* toggle, where #673 put it. The menu takes focus as it opens and hands it back
|
|
386
|
-
* to the chip on a pick, so the keyboard never lands somewhere it cannot leave.
|
|
387
|
-
*/
|
|
388
|
-
export const ChipFromTheKeyboard: Story = {
|
|
389
|
-
name: "Shift+Tab twice reaches the chip",
|
|
390
|
-
// Short enough that detection declines, so the chip is on the account
|
|
391
|
-
// default and the arrow key below has a known row to move off.
|
|
392
|
-
args: { initialHtml: "<p>Hoi.</p>" },
|
|
393
|
-
play: async ({ canvasElement }) => {
|
|
394
|
-
const editable = canvasElement.querySelector<HTMLElement>(
|
|
395
|
-
"[data-testid=compose-body]",
|
|
396
|
-
);
|
|
397
|
-
if (!editable) throw new Error("the rich surface is not mounted");
|
|
398
|
-
|
|
399
|
-
await userEvent.click(editable);
|
|
400
|
-
await userEvent.tab({ shift: true });
|
|
401
|
-
await expect(toggleOf(canvasElement)).toHaveFocus();
|
|
402
|
-
await userEvent.tab({ shift: true });
|
|
403
|
-
await expect(chipOf(canvasElement)).toHaveFocus();
|
|
404
|
-
|
|
405
|
-
await userEvent.keyboard("{Enter}");
|
|
406
|
-
await waitFor(async () => {
|
|
407
|
-
await expect(
|
|
408
|
-
canvasElement.querySelector("[data-testid=compose-language-menu]"),
|
|
409
|
-
).not.toBeNull();
|
|
410
|
-
});
|
|
411
|
-
await userEvent.keyboard("{ArrowDown}{Enter}");
|
|
412
|
-
|
|
413
|
-
await expect(chipOf(canvasElement)).toHaveTextContent("EN");
|
|
414
|
-
await expect(chipOf(canvasElement)).toHaveFocus();
|
|
415
|
-
await expect(editable).toHaveAttribute("lang", "en");
|
|
416
|
-
},
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
/** The tag follows the message across the mode switch, onto whichever surface is up. */
|
|
420
|
-
export const PlainSurfaceCarriesTheLanguage: Story = {
|
|
421
|
-
name: "Plain text keeps the same language",
|
|
422
|
-
args: { initialHtml: DUTCH_DOCUMENT },
|
|
423
|
-
play: async ({ canvasElement }) => {
|
|
424
|
-
await waitFor(
|
|
425
|
-
async () => {
|
|
426
|
-
await expect(chipOf(canvasElement)).toHaveTextContent("NL");
|
|
427
|
-
},
|
|
428
|
-
{ timeout: 5000 },
|
|
429
|
-
);
|
|
430
|
-
|
|
431
|
-
await userEvent.click(toggleOf(canvasElement));
|
|
432
|
-
const textarea = plainSurface(canvasElement);
|
|
433
|
-
if (!textarea) throw new Error("the plain surface did not arrive");
|
|
434
|
-
|
|
435
|
-
await expect(textarea).toHaveAttribute("lang", "nl");
|
|
436
|
-
await expect(chipOf(canvasElement)).toHaveTextContent("NL");
|
|
437
|
-
},
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* The quoted block a reply is written above is somebody else's text. It lives
|
|
442
|
-
* outside the editor, so detection never sees it and a French thread answered
|
|
443
|
-
* in Dutch is tagged Dutch.
|
|
444
|
-
*/
|
|
445
|
-
export const QuotedTextIsNotRead: Story = {
|
|
446
|
-
name: "A French quote under a Dutch reply",
|
|
447
|
-
args: {
|
|
448
|
-
initialHtml: DUTCH_DOCUMENT,
|
|
449
|
-
quoted:
|
|
450
|
-
"Bonjour, je vous confirme que la réunion de jeudi est annulée. Je vous propose de la reporter à la semaine prochaine.",
|
|
451
|
-
},
|
|
452
|
-
play: async ({ canvasElement }) => {
|
|
453
|
-
await waitFor(
|
|
454
|
-
async () => {
|
|
455
|
-
await expect(chipOf(canvasElement)).toHaveTextContent("NL");
|
|
456
|
-
},
|
|
457
|
-
{ timeout: 5000 },
|
|
458
|
-
);
|
|
459
|
-
await expect(
|
|
460
|
-
canvasElement.querySelector("[data-testid=compose-body]"),
|
|
461
|
-
).toHaveAttribute("lang", "nl");
|
|
462
|
-
},
|
|
463
|
-
};
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ComposeBodyMode,
|
|
3
|
-
ComposeLanguageChip,
|
|
4
|
-
ComposeModeToggle,
|
|
5
|
-
markdownToHtml,
|
|
6
|
-
PlainTextEditor,
|
|
7
|
-
RichTextEditor,
|
|
8
|
-
type RichTextValue,
|
|
9
|
-
useComposeLanguage,
|
|
10
|
-
} from "@remit/ui/rich-text";
|
|
11
|
-
import { useEffect, useRef, useState } from "react";
|
|
12
|
-
import { ConfirmDialog } from "../ui/ConfirmDialog";
|
|
13
|
-
import { conversionOutcome, switchNeedsWarning } from "./compose-mode";
|
|
14
|
-
|
|
15
|
-
export interface ConversionFailure {
|
|
16
|
-
title: string;
|
|
17
|
-
detail: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The two directions of the mode switch, injectable so a story can drive the
|
|
22
|
-
* conversion that comes back empty — the branch that keeps autosave from
|
|
23
|
-
* persisting a blanked draft, and the one case no real document produces on
|
|
24
|
-
* demand.
|
|
25
|
-
*/
|
|
26
|
-
export interface ComposeConversions {
|
|
27
|
-
toPlain: (value: RichTextValue) => string;
|
|
28
|
-
toRich: (text: string) => string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const DEFAULT_COMPOSE_CONVERSIONS: ComposeConversions = {
|
|
32
|
-
toPlain: (value) => value.text,
|
|
33
|
-
toRich: (text) => markdownToHtml(text),
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const textOf = (html: string): string =>
|
|
37
|
-
new DOMParser().parseFromString(html, "text/html").body.textContent ?? "";
|
|
38
|
-
|
|
39
|
-
const plainValue = (text: string): RichTextValue => ({
|
|
40
|
-
html: "",
|
|
41
|
-
text,
|
|
42
|
-
formatting: [],
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
interface ComposeBodyProps {
|
|
46
|
-
mode: ComposeBodyMode;
|
|
47
|
-
onModeChange: (mode: ComposeBodyMode) => void;
|
|
48
|
-
initialHtml: string;
|
|
49
|
-
initialText: string;
|
|
50
|
-
onChange: (value: RichTextValue) => void;
|
|
51
|
-
onSubmit?: () => void;
|
|
52
|
-
autoFocus?: boolean;
|
|
53
|
-
onConversionError: (failure: ConversionFailure) => void;
|
|
54
|
-
conversions?: ComposeConversions;
|
|
55
|
-
/** The account's writing languages, most-used first. */
|
|
56
|
-
languages: readonly string[];
|
|
57
|
-
/** The tag a reopened draft was stored under. */
|
|
58
|
-
initialLanguage?: string;
|
|
59
|
-
/** Reports the language the message is being written in, so the form can tag it. */
|
|
60
|
-
onLanguageChange: (language: string) => void;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The compose writing surface and the control that swaps it. Rich text is the
|
|
65
|
-
* WYSIWYG document; plain text is a textarea whose content is the Markdown that
|
|
66
|
-
* will be sent verbatim. The conversion runs over an in-memory document, so the
|
|
67
|
-
* surface swaps in the same frame the choice is made.
|
|
68
|
-
*/
|
|
69
|
-
export const ComposeBody = ({
|
|
70
|
-
mode,
|
|
71
|
-
onModeChange,
|
|
72
|
-
initialHtml,
|
|
73
|
-
initialText,
|
|
74
|
-
onChange,
|
|
75
|
-
onSubmit,
|
|
76
|
-
autoFocus = false,
|
|
77
|
-
onConversionError,
|
|
78
|
-
conversions = DEFAULT_COMPOSE_CONVERSIONS,
|
|
79
|
-
languages,
|
|
80
|
-
initialLanguage,
|
|
81
|
-
onLanguageChange,
|
|
82
|
-
}: ComposeBodyProps) => {
|
|
83
|
-
const [richHtml, setRichHtml] = useState(initialHtml);
|
|
84
|
-
const [richGeneration, setRichGeneration] = useState(0);
|
|
85
|
-
const [plainText, setPlainText] = useState(initialText);
|
|
86
|
-
const [bodyText, setBodyText] = useState(initialText);
|
|
87
|
-
const [confirming, setConfirming] = useState(false);
|
|
88
|
-
// The caret does not survive a conversion: a rich selection is a node path
|
|
89
|
-
// and Markdown is a character offset. The surface that arrives takes focus
|
|
90
|
-
// with the caret at the end; the toggle keeps it when the mode did not change.
|
|
91
|
-
const [focusSwitchedSurface, setFocusSwitchedSurface] = useState(false);
|
|
92
|
-
const richValue = useRef<RichTextValue>({
|
|
93
|
-
html: initialHtml,
|
|
94
|
-
text: initialText,
|
|
95
|
-
formatting: [],
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// Detection reads the body the user typed. The quoted reply block is not part
|
|
99
|
-
// of it — that lives outside the editor, in the form's own `quoted` slot.
|
|
100
|
-
const { language, choose } = useComposeLanguage({
|
|
101
|
-
languages,
|
|
102
|
-
text: bodyText,
|
|
103
|
-
initialLanguage,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
onLanguageChange(language);
|
|
108
|
-
}, [language, onLanguageChange]);
|
|
109
|
-
|
|
110
|
-
const handleRichChange = (value: RichTextValue) => {
|
|
111
|
-
richValue.current = value;
|
|
112
|
-
setBodyText(value.text);
|
|
113
|
-
onChange(value);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const handlePlainChange = (text: string) => {
|
|
117
|
-
setPlainText(text);
|
|
118
|
-
setBodyText(text);
|
|
119
|
-
onChange(plainValue(text));
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const switchToPlain = () => {
|
|
123
|
-
const value = richValue.current;
|
|
124
|
-
const converted = conversions.toPlain(value);
|
|
125
|
-
const decision = conversionOutcome("plain", textOf(value.html), converted);
|
|
126
|
-
if (decision.outcome === "blocked") {
|
|
127
|
-
onConversionError(decision);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
setPlainText(converted);
|
|
131
|
-
setBodyText(converted);
|
|
132
|
-
setFocusSwitchedSurface(true);
|
|
133
|
-
onChange(plainValue(converted));
|
|
134
|
-
onModeChange("plain");
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const switchToRich = () => {
|
|
138
|
-
const converted = conversions.toRich(plainText);
|
|
139
|
-
const decision = conversionOutcome("rich", plainText, textOf(converted));
|
|
140
|
-
if (decision.outcome === "blocked") {
|
|
141
|
-
onConversionError(decision);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
setRichHtml(converted);
|
|
145
|
-
setRichGeneration((generation) => generation + 1);
|
|
146
|
-
setFocusSwitchedSurface(true);
|
|
147
|
-
onModeChange("rich");
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const handleToggle = () => {
|
|
151
|
-
if (mode === "plain") {
|
|
152
|
-
switchToRich();
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (switchNeedsWarning("plain", richValue.current.formatting)) {
|
|
156
|
-
setConfirming(true);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
switchToPlain();
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// The chip comes first so the mode toggle stays one Shift+Tab out of the
|
|
163
|
-
// body, where #673 put it, and the chip is the second.
|
|
164
|
-
const trailing = (
|
|
165
|
-
<>
|
|
166
|
-
<ComposeLanguageChip
|
|
167
|
-
language={language}
|
|
168
|
-
languages={languages}
|
|
169
|
-
onSelect={choose}
|
|
170
|
-
/>
|
|
171
|
-
<ComposeModeToggle mode={mode} onToggle={handleToggle} />
|
|
172
|
-
</>
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
return (
|
|
176
|
-
<>
|
|
177
|
-
{mode === "plain" ? (
|
|
178
|
-
<PlainTextEditor
|
|
179
|
-
value={plainText}
|
|
180
|
-
onChange={handlePlainChange}
|
|
181
|
-
onSubmit={onSubmit}
|
|
182
|
-
autoFocus={focusSwitchedSurface}
|
|
183
|
-
lang={language}
|
|
184
|
-
trailing={trailing}
|
|
185
|
-
/>
|
|
186
|
-
) : (
|
|
187
|
-
<RichTextEditor
|
|
188
|
-
key={richGeneration}
|
|
189
|
-
initialHtml={richHtml}
|
|
190
|
-
onChange={handleRichChange}
|
|
191
|
-
onSubmit={onSubmit}
|
|
192
|
-
autoFocus={autoFocus || focusSwitchedSurface}
|
|
193
|
-
lang={language}
|
|
194
|
-
trailing={trailing}
|
|
195
|
-
/>
|
|
196
|
-
)}
|
|
197
|
-
<ConfirmDialog
|
|
198
|
-
isOpen={confirming}
|
|
199
|
-
title="Switch to plain text?"
|
|
200
|
-
description="Formatting becomes Markdown. Bold keeps its asterisks, a table becomes rows of pipes, and that text is what the recipient gets. No formatted version is sent alongside it."
|
|
201
|
-
confirmLabel="Switch to plain text"
|
|
202
|
-
onConfirm={() => {
|
|
203
|
-
setConfirming(false);
|
|
204
|
-
switchToPlain();
|
|
205
|
-
}}
|
|
206
|
-
onCancel={() => setConfirming(false)}
|
|
207
|
-
/>
|
|
208
|
-
</>
|
|
209
|
-
);
|
|
210
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
interface SubjectFieldProps {
|
|
2
|
-
value: string;
|
|
3
|
-
onChange: (value: string) => void;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export const SubjectField = ({ value, onChange }: SubjectFieldProps) => (
|
|
7
|
-
<div className="flex items-start gap-2">
|
|
8
|
-
{/* biome-ignore lint/a11y/noLabelWithoutControl: label is visually adjacent to the sibling input; static id risks duplicates */}
|
|
9
|
-
<label className="text-sm text-fg-muted shrink-0 w-12 pt-1.5">Subj:</label>
|
|
10
|
-
<input
|
|
11
|
-
type="text"
|
|
12
|
-
value={value}
|
|
13
|
-
onChange={(e) => onChange(e.target.value)}
|
|
14
|
-
className="flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm"
|
|
15
|
-
placeholder="Subject"
|
|
16
|
-
data-subject-field
|
|
17
|
-
/>
|
|
18
|
-
</div>
|
|
19
|
-
);
|