@remit/ui 0.0.212 → 0.0.214

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/ui",
3
- "version": "0.0.212",
3
+ "version": "0.0.214",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -148,6 +148,7 @@ describe("CalendarInviteCard", () => {
148
148
  return upTo.slice(upTo.lastIndexOf("<button"));
149
149
  };
150
150
  assert.match(before("Add to calendar"), /disabled=""/);
151
+ assert.match(before("Maybe"), /disabled=""/);
151
152
  assert.doesNotMatch(before("Decline"), /disabled=""/);
152
153
  assert.doesNotMatch(before("Stop offering"), /disabled=""/);
153
154
  });
@@ -75,6 +75,11 @@ export const AlreadyOnTheCalendar: Story = {
75
75
  args: { ...base, rsvp: "accepted", clashes: [] },
76
76
  };
77
77
 
78
+ /** Answered maybe. On the calendar as tentative, and the organiser was not told. */
79
+ export const AnsweredMaybe: Story = {
80
+ args: { ...base, rsvp: "tentative", clashes: [] },
81
+ };
82
+
78
83
  /** Declined, with the way back to offering other times still open. */
79
84
  export const Declined: Story = {
80
85
  args: { ...base, rsvp: "declined", clashes: [] },
@@ -78,7 +78,7 @@ export interface CalendarInviteCardProps {
78
78
  reportHref?: string;
79
79
  /**
80
80
  * Why nothing can be written to a calendar yet, and the way to fix it. Set,
81
- * it holds Add and Remove; the answers that write nothing stay live.
81
+ * it holds Add, Maybe and Remove; the answers that write nothing stay live.
82
82
  */
83
83
  addBlocked?: ReactNode;
84
84
  touch?: boolean;
@@ -271,7 +271,7 @@ export function CalendarInviteCard({
271
271
  variant="secondary"
272
272
  size={touch ? "md" : "sm"}
273
273
  onClick={onTentative}
274
- disabled={busy}
274
+ disabled={busy || addBlocked !== undefined}
275
275
  className={cn(touch && "min-h-11 flex-1")}
276
276
  >
277
277
  Maybe
@@ -10,7 +10,11 @@ import { PlainTextEditor } from "./plain-text-editor.js";
10
10
  import { markdownToHtml } from "./rich-text-document.js";
11
11
  import { RichTextEditor } from "./rich-text-editor.js";
12
12
  import type { SpellcheckOptions } from "./rich-text-spellcheck.js";
13
- import type { ComposeCaret, RichTextValue } from "./rich-text-value.js";
13
+ import type {
14
+ ComposeCaret,
15
+ ComposeInsertion,
16
+ RichTextValue,
17
+ } from "./rich-text-value.js";
14
18
  import { useComposeLanguage } from "./use-compose-language.js";
15
19
 
16
20
  export interface ConversionFailure {
@@ -69,6 +73,8 @@ export interface ComposeBodyProps {
69
73
  * the browser's.
70
74
  */
71
75
  spellcheck?: SpellcheckOptions;
76
+ insertion?: ComposeInsertion;
77
+ onInserted?: (version: number) => void;
72
78
  }
73
79
 
74
80
  /**
@@ -91,6 +97,8 @@ export const ComposeBody = ({
91
97
  initialLanguage,
92
98
  onLanguageChange,
93
99
  spellcheck,
100
+ insertion,
101
+ onInserted,
94
102
  }: ComposeBodyProps) => {
95
103
  const [richHtml, setRichHtml] = useState(initialHtml);
96
104
  const [richGeneration, setRichGeneration] = useState(0);
@@ -195,6 +203,8 @@ export const ComposeBody = ({
195
203
  initialCaret={focusSwitchedSurface ? "end" : initialCaret}
196
204
  lang={language}
197
205
  trailing={trailing}
206
+ insertion={insertion}
207
+ onInserted={onInserted}
198
208
  />
199
209
  ) : (
200
210
  <RichTextEditor
@@ -206,6 +216,8 @@ export const ComposeBody = ({
206
216
  lang={language}
207
217
  trailing={trailing}
208
218
  spellcheck={spellcheck}
219
+ insertion={insertion}
220
+ onInserted={onInserted}
209
221
  />
210
222
  )}
211
223
  <ConfirmDialog
@@ -1,4 +1,4 @@
1
- import { CalendarDays, Copy } from "lucide-react";
1
+ import { CalendarDays, Reply } from "lucide-react";
2
2
  import { type ReactNode, useState } from "react";
3
3
  import { cn } from "../lib/cn.js";
4
4
  import { Button } from "./button.js";
@@ -82,10 +82,6 @@ export interface CalendarProseIntel {
82
82
  slots: CalendarSlotPick[];
83
83
  /** Start clocks already ticked into the reply. */
84
84
  picked: readonly string[];
85
- /** What became of the last copy of the picked times. */
86
- copy?: "idle" | "copied" | "failed";
87
- /** The picked times as text, offered to select by hand when copying failed. */
88
- copyText?: string;
89
85
  }
90
86
 
91
87
  export interface IntelligenceCalendarData {
@@ -123,7 +119,7 @@ export interface IntelligenceCalendarActions {
123
119
  onRemoveInvite?: () => void;
124
120
  onOpenNewerInvite?: () => void;
125
121
  onToggleSlot: (slot: CalendarSlotPick) => void;
126
- onCopySlots?: () => void;
122
+ onReplyWithSlots?: () => void;
127
123
  onAddSuggestion: (suggestionId: string, timeZone: string) => void;
128
124
  onReviewSuggestion?: (suggestionId: string, timeZone: string) => void;
129
125
  onDismissSuggestion: (suggestionId: string) => void;
@@ -277,41 +273,20 @@ export function IntelligenceCalendar({
277
273
  touch={touch}
278
274
  scroll
279
275
  />
280
- {actions.onCopySlots ? (
276
+ {actions.onReplyWithSlots ? (
281
277
  <div className="mt-2 flex flex-col gap-1.5">
282
278
  <Button
283
279
  variant="secondary"
284
280
  size={touch ? "md" : "sm"}
285
- icon={<Copy className="size-3.5" />}
286
- onClick={actions.onCopySlots}
281
+ icon={<Reply className="size-3.5" />}
282
+ onClick={actions.onReplyWithSlots}
287
283
  disabled={picked.size === 0}
288
284
  className={cn("self-start", touch && "min-h-11")}
289
285
  >
290
- Copy picked times
286
+ Reply with these times
291
287
  </Button>
292
- {prose.copy === "copied" && (
293
- <p role="status" className="text-2xs text-positive">
294
- Copied. Paste them into your reply.
295
- </p>
296
- )}
297
- {prose.copy === "failed" && (
298
- <div role="alert" className="flex flex-col gap-1">
299
- <p className="text-2xs text-danger">
300
- This page can't copy for you. Select the times below and
301
- copy them yourself.
302
- </p>
303
- <textarea
304
- readOnly
305
- aria-label="Picked times"
306
- value={prose.copyText ?? ""}
307
- onFocus={(event) => event.currentTarget.select()}
308
- rows={2}
309
- className="w-full resize-none rounded-md border border-line bg-surface p-1.5 text-xs text-fg"
310
- />
311
- </div>
312
- )}
313
288
  <p className="text-2xs text-fg-subtle">
314
- Picked slots are copied as plain text. Nothing is booked.
289
+ Picked slots go into the reply as plain text. Nothing is booked.
315
290
  </p>
316
291
  </div>
317
292
  ) : (
@@ -54,7 +54,6 @@ function PanelDemo({
54
54
  hideCloseButton,
55
55
  touch,
56
56
  className,
57
- copyFails = false,
58
57
  }: {
59
58
  sender: IntelligenceData;
60
59
  calendar: IntelligenceCalendarData;
@@ -62,8 +61,6 @@ function PanelDemo({
62
61
  hideCloseButton?: boolean;
63
62
  touch?: boolean;
64
63
  className?: string;
65
- /** The page cannot reach the clipboard, as on plain http. */
66
- copyFails?: boolean;
67
64
  }) {
68
65
  const [tab, setTab] = useState<IntelligenceTabId>(initialTab);
69
66
  const [rsvp, setRsvp] = useState<RsvpState>(
@@ -72,9 +69,6 @@ function PanelDemo({
72
69
  const [removed, setRemoved] = useState(false);
73
70
  const [offering, setOffering] = useState(calendar.prose !== undefined);
74
71
  const [picked, setPicked] = useState<string[]>([]);
75
- const [copy, setCopy] = useState<"idle" | "copied" | "failed">(
76
- calendar.prose?.copy ?? "idle",
77
- );
78
72
  const [dropped, setDropped] = useState<string[]>([]);
79
73
  const [selectedEventId, setSelectedEventId] = useState("");
80
74
  const [lastAction, setLastAction] = useState("");
@@ -83,8 +77,6 @@ function PanelDemo({
83
77
  ? {
84
78
  ...(calendar.prose ?? thursdayProse),
85
79
  picked,
86
- copy,
87
- copyText: `${(calendar.prose ?? thursdayProse).dayLabel}: ${picked.join(", ")}`,
88
80
  }
89
81
  : undefined;
90
82
 
@@ -110,6 +102,10 @@ function PanelDemo({
110
102
  selectedEventId,
111
103
  actions: {
112
104
  onAddInvite: () => setRsvp("accepted"),
105
+ onTentativeInvite:
106
+ calendar.invite?.invite.state === "cancelled"
107
+ ? undefined
108
+ : () => setRsvp("tentative"),
113
109
  onDeclineInvite: () => setRsvp("declined"),
114
110
  onReopenInvite:
115
111
  calendar.invite?.invite.state === "cancelled"
@@ -119,14 +115,16 @@ function PanelDemo({
119
115
  onOfferOtherTimes: () => setOffering(true),
120
116
  onRemoveInvite: () => setRemoved(true),
121
117
  onToggleSlot: (slot) => {
122
- setCopy("idle");
123
118
  setPicked((prev) =>
124
119
  prev.includes(slot.startTime)
125
120
  ? prev.filter((start) => start !== slot.startTime)
126
121
  : [...prev, slot.startTime],
127
122
  );
128
123
  },
129
- onCopySlots: () => setCopy(copyFails ? "failed" : "copied"),
124
+ onReplyWithSlots: () =>
125
+ setLastAction(
126
+ `opened a reply holding ${(calendar.prose ?? thursdayProse).dayLabel}: ${picked.join(", ")}`,
127
+ ),
130
128
  onAddSuggestion: (id, timeZone) => {
131
129
  setDropped((prev) => [...prev, id]);
132
130
  setLastAction(
@@ -231,7 +229,6 @@ function rail(
231
229
  sender: IntelligenceData,
232
230
  calendar: IntelligenceCalendarData,
233
231
  initialTab: IntelligenceTabId = "calendar",
234
- copyFails = false,
235
232
  ): Story {
236
233
  return {
237
234
  render: () => (
@@ -240,7 +237,6 @@ function rail(
240
237
  sender={sender}
241
238
  calendar={calendar}
242
239
  initialTab={initialTab}
243
- copyFails={copyFails}
244
240
  className="h-full"
245
241
  />
246
242
  </RailHost>
@@ -319,7 +315,19 @@ export const Declined = rail(KICKOFF, organiserSender, {
319
315
  });
320
316
 
321
317
  /**
322
- * No calendar to write to yet. Adding waits for one, with the way to make it;
318
+ * Answered maybe. The event is on the calendar as tentative, and the organiser
319
+ * was not told.
320
+ */
321
+ export const AnsweredMaybe = rail(KICKOFF, organiserSender, {
322
+ ...inviteWithClash,
323
+ invite: inviteWithClash.invite && {
324
+ ...inviteWithClash.invite,
325
+ rsvp: "tentative",
326
+ },
327
+ });
328
+
329
+ /**
330
+ * No calendar to write to yet. Adding and maybe wait for one, with the way to make it;
323
331
  * declining and muting write nothing to a calendar and stay live.
324
332
  */
325
333
  export const NoCalendarYet = rail(KICKOFF, organiserSender, {
@@ -351,18 +359,6 @@ export const ReadFailure = rail(PLAIN, organiserSender, {
351
359
  reportHref: REPORT,
352
360
  });
353
361
 
354
- /**
355
- * Picked times on a page that cannot reach the clipboard, as on plain http.
356
- * The failure is stated and the times are there to select by hand.
357
- */
358
- export const CopyFailed = rail(
359
- THURSDAY,
360
- organiserSender,
361
- proseTimeThread,
362
- "calendar",
363
- true,
364
- );
365
-
366
362
  /**
367
363
  * The same invitation an hour later. Nothing is booked over it, and the panel
368
364
  * says that too — silence there would read as "not checked", which is the same
@@ -10,7 +10,7 @@ import {
10
10
  import { Banner } from "./banner.js";
11
11
  import { isWritingElsewhere } from "./editor-focus.js";
12
12
  import { htmlToMarkdown } from "./rich-text-document.js";
13
- import type { ComposeCaret } from "./rich-text-value.js";
13
+ import type { ComposeCaret, ComposeInsertion } from "./rich-text-value.js";
14
14
 
15
15
  export interface PlainTextEditorProps {
16
16
  value: string;
@@ -21,6 +21,8 @@ export interface PlainTextEditorProps {
21
21
  * does not take focus.
22
22
  */
23
23
  initialCaret?: ComposeCaret;
24
+ insertion?: ComposeInsertion;
25
+ onInserted?: (version: number) => void;
24
26
  placeholder?: string;
25
27
  ariaLabel?: string;
26
28
  /** Pinned to the right of the toolbar strip. The mode toggle rides here. */
@@ -70,11 +72,27 @@ export const PlainTextEditor = ({
70
72
  ariaLabel = "Message body",
71
73
  trailing,
72
74
  lang,
75
+ insertion,
76
+ onInserted,
73
77
  }: PlainTextEditorProps) => {
74
78
  const textareaRef = useRef<HTMLTextAreaElement>(null);
75
79
  const pendingCaret = useRef<number | null>(null);
76
80
  const plainRequested = useRef(false);
77
81
  const [emptyPaste, setEmptyPaste] = useState(false);
82
+ const appliedInsertion = useRef<number | undefined>(undefined);
83
+
84
+ useEffect(() => {
85
+ if (!insertion || insertion.version === appliedInsertion.current) return;
86
+ appliedInsertion.current = insertion.version;
87
+ const textarea = textareaRef.current;
88
+ if (!textarea) return;
89
+ textarea.focus();
90
+ const spliced = insertAtCaret(textarea, insertion.text);
91
+ onInserted?.(insertion.version);
92
+ if (!spliced) return;
93
+ pendingCaret.current = spliced.caret;
94
+ onChange(spliced.value);
95
+ }, [insertion, onChange, onInserted]);
78
96
 
79
97
  // Grows to its content rather than scrolling inside itself: one scroller in
80
98
  // the compose body keeps the caret in view for free, which a nested one is
@@ -47,7 +47,11 @@ import {
47
47
  SUGGESTION_LIMIT,
48
48
  } from "./rich-text-spellcheck-words.js";
49
49
  import { RichTextToolbar } from "./rich-text-toolbar.js";
50
- import type { ComposeCaret, RichTextValue } from "./rich-text-value.js";
50
+ import type {
51
+ ComposeCaret,
52
+ ComposeInsertion,
53
+ RichTextValue,
54
+ } from "./rich-text-value.js";
51
55
 
52
56
  export interface RichTextEditorProps {
53
57
  /**
@@ -81,6 +85,8 @@ export interface RichTextEditorProps {
81
85
  * `lang`, which is also when the browser keeps checking.
82
86
  */
83
87
  spellcheck?: SpellcheckOptions;
88
+ insertion?: ComposeInsertion;
89
+ onInserted?: (version: number) => void;
84
90
  }
85
91
 
86
92
  /**
@@ -906,6 +912,32 @@ const AutoFocus = ({ caret }: { caret?: ComposeCaret }) => {
906
912
  return null;
907
913
  };
908
914
 
915
+ const InsertionPlugin = ({
916
+ insertion,
917
+ onInserted,
918
+ }: {
919
+ insertion: ComposeInsertion | undefined;
920
+ onInserted: ((version: number) => void) | undefined;
921
+ }) => {
922
+ const [editor] = useLexicalComposerContext();
923
+ const applied = useRef<number | undefined>(undefined);
924
+
925
+ useEffect(() => {
926
+ if (!insertion || insertion.version === applied.current) return;
927
+ applied.current = insertion.version;
928
+ editor.update(() => {
929
+ const selection = $getSelection();
930
+ const target = $isRangeSelection(selection)
931
+ ? selection
932
+ : $getRoot().selectEnd();
933
+ target.insertRawText(insertion.text);
934
+ });
935
+ onInserted?.(insertion.version);
936
+ }, [editor, insertion, onInserted]);
937
+
938
+ return null;
939
+ };
940
+
909
941
  const seedDocument =
910
942
  (html: string) =>
911
943
  (editor: LexicalEditor): void => {
@@ -925,6 +957,8 @@ export const RichTextEditor = ({
925
957
  trailing,
926
958
  lang,
927
959
  spellcheck,
960
+ insertion,
961
+ onInserted,
928
962
  }: RichTextEditorProps) => {
929
963
  const [checkedHere, setCheckedHere] = useState(false);
930
964
  const bodyRef = useRef<HTMLDivElement>(null);
@@ -997,6 +1031,7 @@ export const RichTextEditor = ({
997
1031
  <TablePlugin />
998
1032
  <PastePlugin />
999
1033
  <AutoFocus caret={initialCaret} />
1034
+ <InsertionPlugin insertion={insertion} onInserted={onInserted} />
1000
1035
  {onChange && <ChangePlugin onChange={onChange} />}
1001
1036
  </LexicalComposer>
1002
1037
  );
@@ -23,6 +23,11 @@ export interface RichTextValue {
23
23
  */
24
24
  export type ComposeCaret = "start" | "end";
25
25
 
26
+ export interface ComposeInsertion {
27
+ version: number;
28
+ text: string;
29
+ }
30
+
26
31
  export const EMPTY_RICH_TEXT: RichTextValue = {
27
32
  html: "",
28
33
  text: "",
package/src/rich-text.ts CHANGED
@@ -59,6 +59,7 @@ export {
59
59
  normaliseWord,
60
60
  SUGGESTION_LIMIT,
61
61
  } from "./components/rich-text-spellcheck-words.js";
62
+ export type { ComposeInsertion } from "./components/rich-text-value.js";
62
63
  export {
63
64
  type ComposeCaret,
64
65
  EMPTY_RICH_TEXT,