@joinskips/brand 5.0.0-develop.116 → 5.0.0-develop.118

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/README.md CHANGED
@@ -13,4 +13,11 @@ import tokens from '@joinskips/brand/tokens/skips-design-tokens.json' with { typ
13
13
  @import '@joinskips/brand/fonts/onest/onest.css';
14
14
  ```
15
15
 
16
+ A Tailwind 4 app imports the tokens as its theme. The colours sit under `@variant light` and `@variant dark`, the way
17
+ Uniwind reads them.
18
+
19
+ ```css
20
+ @import '@joinskips/brand/tokens/skips-tailwind-theme.css';
21
+ ```
22
+
16
23
  `manifest.json` lists every file with its hash and size. Onest's licence is `fonts/onest/OFL.txt`.
@@ -0,0 +1,9 @@
1
+ export declare const ATTACHMENT_TYPES: string[];
2
+ export declare const MAX_ATTACHMENT_BYTES: number;
3
+ /** A picked file's type: the picker's own, else the one its name says, else none. */
4
+ export declare function attachmentType(name: string, given?: string | null): string;
5
+ /** Why a picked file cannot be sent, or null when it can. */
6
+ export declare function attachmentProblem(file: {
7
+ type: string;
8
+ size: number;
9
+ }): 'type' | 'size' | null;
@@ -0,0 +1,34 @@
1
+ export const ATTACHMENT_TYPES = [
2
+ 'image/jpeg',
3
+ 'image/png',
4
+ 'image/gif',
5
+ 'image/webp',
6
+ 'image/heic',
7
+ 'image/heif',
8
+ 'application/pdf',
9
+ ];
10
+ export const MAX_ATTACHMENT_BYTES = 40 * 1024 * 1024;
11
+ // Pickers can leave the type out, so it comes from the name.
12
+ const TYPE_BY_EXTENSION = new Map([
13
+ ['jpg', 'image/jpeg'],
14
+ ['jpeg', 'image/jpeg'],
15
+ ['png', 'image/png'],
16
+ ['gif', 'image/gif'],
17
+ ['webp', 'image/webp'],
18
+ ['heic', 'image/heic'],
19
+ ['heif', 'image/heif'],
20
+ ['pdf', 'application/pdf'],
21
+ ]);
22
+ /** A picked file's type: the picker's own, else the one its name says, else none. */
23
+ export function attachmentType(name, given) {
24
+ if (given)
25
+ return given;
26
+ const dot = name.lastIndexOf('.');
27
+ return dot === -1 ? '' : (TYPE_BY_EXTENSION.get(name.slice(dot + 1).toLowerCase()) ?? '');
28
+ }
29
+ /** Why a picked file cannot be sent, or null when it can. */
30
+ export function attachmentProblem(file) {
31
+ if (!ATTACHMENT_TYPES.includes(file.type))
32
+ return 'type';
33
+ return file.size > MAX_ATTACHMENT_BYTES ? 'size' : null;
34
+ }
@@ -0,0 +1,4 @@
1
+ export declare function Bubble({ mine, text }: {
2
+ mine?: boolean;
3
+ text: string;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Text, View } from 'react-native';
3
+ import { Markdown } from "./Markdown.js";
4
+ // The member's line in the accent and exactly as typed, Skips' on a card with its Markdown drawn, each with its
5
+ // tail corner tighter.
6
+ export function Bubble({ mine = false, text }) {
7
+ if (mine) {
8
+ return (_jsx(Text, { className: "rounded-[20px] rounded-br-[7px] bg-accent px-4 py-2.5 font-ui text-md text-accent-ink", children: text }));
9
+ }
10
+ return (_jsx(View, { className: "shrink rounded-[20px] rounded-bl-[7px] border border-line-subtle bg-surface px-4 py-2.5", children: _jsx(Markdown, { text: text }) }));
11
+ }
@@ -0,0 +1,28 @@
1
+ import { type ImageSourcePropType } from 'react-native';
2
+ import type { PickedFile } from '../message.ts';
3
+ import { type Thread } from '../thread.ts';
4
+ import { type ChatIcon, type ChatWords } from './parts.ts';
5
+ export type LoadState = 'loading' | 'ready' | 'failed';
6
+ export interface ConversationProps {
7
+ thread: Thread;
8
+ load: LoadState;
9
+ feedDown: boolean;
10
+ typists: string[];
11
+ skipUserId: number | null;
12
+ onSend: (text: string, file: PickedFile | null) => void;
13
+ onRetry: (id: number) => void;
14
+ onTyped: (text: string) => void;
15
+ onLoadOlder: () => void;
16
+ onReload: () => void;
17
+ pickFile?: () => Promise<PickedFile | null>;
18
+ initialText?: string;
19
+ keyboardOffset?: number;
20
+ bottomInset?: number;
21
+ words: ChatWords;
22
+ Icon: ChatIcon;
23
+ skipMark: ImageSourcePropType;
24
+ }
25
+ export declare const PHOTO_RETRIES = 5;
26
+ export declare const PHOTO_RETRY_MS = 1500;
27
+ /** One conversation: its messages oldest at the top, the care team's typing, and the box to write in. */
28
+ export declare function Conversation(props: ConversationProps): import("react").JSX.Element;
@@ -0,0 +1,117 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { ActivityIndicator, FlatList, Image, KeyboardAvoidingView, Linking, Platform, Pressable, Text, TextInput, View, } from 'react-native';
4
+ import { attachmentProblem } from "../attachments.js";
5
+ import { groupThread } from "../thread.js";
6
+ import { Bubble } from "./Bubble.js";
7
+ import { useColor } from "./parts.js";
8
+ // An image from require needs its size in style: the web draws it at its own size otherwise.
9
+ const AVATAR_SIZE = 32;
10
+ export const PHOTO_RETRIES = 5;
11
+ export const PHOTO_RETRY_MS = 1_500;
12
+ const MIN_BOTTOM_SPACE = 12;
13
+ // React Native text inherits no font from the screen, so each line carries it.
14
+ function Line({ className, ...props }) {
15
+ return _jsx(Text, { className: `font-ui ${className}`, ...props });
16
+ }
17
+ const isPhoto = (file) => file.type.startsWith('image/');
18
+ /** One conversation: its messages oldest at the top, the care team's typing, and the box to write in. */
19
+ export function Conversation(props) {
20
+ const { thread, load, feedDown, typists, words, onReload, onLoadOlder } = props;
21
+ const secondary = useColor('ink-secondary');
22
+ // The list is inverted so it rests at the newest message and stays put while the member reads older ones.
23
+ const items = groupThread(thread.messages, props.skipUserId).reverse();
24
+ return (_jsxs(KeyboardAvoidingView, { behavior: "padding", keyboardVerticalOffset: props.keyboardOffset ?? 0, className: "flex-1", children: [feedDown ? (_jsx(Line, { role: "status", className: "bg-muted px-gutter-phone py-2 text-center text-sm text-ink-secondary", children: words.feedDown })) : null, load === 'loading' ? (_jsx(ActivityIndicator, { accessibilityLabel: words.loading, className: "flex-1", color: secondary })) : load === 'failed' ? (_jsxs(View, { role: "alert", className: "flex-1 items-center justify-center gap-3 px-gutter-phone", children: [_jsx(Line, { className: "text-center text-base text-ink-secondary", children: words.loadFailed }), _jsx(Pressable, { role: "button", onPress: onReload, className: "h-control items-center justify-center rounded-pill border border-line-control px-6 active:opacity-80", children: _jsx(Line, { className: "text-md font-semibold text-ink", children: words.retry }) })] })) : (_jsx(FlatList, { inverted: true, data: items, keyExtractor: itemKey, onEndReached: onLoadOlder, contentContainerClassName: "gap-4 px-gutter-phone py-4 md:mx-auto md:w-full md:max-w-reading", ListHeaderComponent: typists.length ? _jsx(Line, { className: "text-sm text-ink-secondary", children: words.typingLine(typists) }) : undefined, renderItem: ({ item }) => _jsx(ThreadRow, { item: item, ...props }) })), _jsx(Composer, { ...props })] }));
25
+ }
26
+ function itemKey(item) {
27
+ if (item.kind === 'run')
28
+ return `r${String(item.messages[0]?.id)}`;
29
+ return `${item.kind === 'notice' ? 'n' : 'u'}${String(item.message.id)}`;
30
+ }
31
+ function Composer({ onSend, onTyped, pickFile, initialText, bottomInset, words, Icon }) {
32
+ const secondary = useColor('ink-secondary');
33
+ const placeholder = useColor('ink-placeholder');
34
+ const actionInk = useColor('action-ink');
35
+ const [text, setText] = useState(initialText ?? '');
36
+ const [picked, setPicked] = useState(null);
37
+ const [refused, setRefused] = useState(null);
38
+ const canSend = Boolean(text.trim() || picked);
39
+ const attach = async (pick) => {
40
+ const file = await pick();
41
+ if (!file)
42
+ return;
43
+ const problem = attachmentProblem(file);
44
+ setRefused(problem ? words.attachmentRefused[problem] : null);
45
+ if (!problem)
46
+ setPicked(file);
47
+ };
48
+ const submit = () => {
49
+ onSend(text, picked);
50
+ setText('');
51
+ setPicked(null);
52
+ setRefused(null);
53
+ };
54
+ return (_jsxs(View, { style: { paddingBottom: Math.max(bottomInset ?? 0, MIN_BOTTOM_SPACE) }, className: "gap-2 px-gutter-phone pt-2 md:mx-auto md:w-full md:max-w-reading", children: [refused ? (_jsx(Line, { role: "alert", className: "text-sm text-error-ink", children: refused })) : null, picked ? (_jsxs(View, { className: "flex-row items-center gap-3 self-start rounded-control border border-line-subtle bg-surface p-2 pr-3", children: [isPhoto(picked) ? (_jsx(Image, { source: { uri: picked.uri }, resizeMode: "cover", className: "h-10 w-10 rounded-control bg-muted" })) : (_jsx(View, { className: "h-10 w-10 items-center justify-center", children: _jsx(Icon, { name: "file", color: secondary, size: 20 }) })), _jsxs(View, { className: "max-w-56", children: [_jsx(Line, { className: "text-sm text-ink", numberOfLines: 1, children: picked.name }), _jsx(Line, { className: "text-xs text-ink-secondary", children: `${isPhoto(picked) ? words.photo : words.pdf} · ${words.fileSize(picked.size)}` })] }), _jsx(Pressable, { role: "button", accessibilityLabel: `${words.remove} ${picked.name}`, hitSlop: 8, onPress: () => {
55
+ setPicked(null);
56
+ }, children: _jsx(Icon, { name: "close", color: secondary, size: 18 }) })] })) : null, _jsxs(View, { className: "flex-row items-end gap-1 rounded-[24px] border border-line-subtle bg-surface p-1.5 shadow-card", children: [pickFile ? (_jsx(Pressable, { role: "button", accessibilityLabel: words.attach, onPress: () => void attach(pickFile), className: "h-[42px] w-[42px] items-center justify-center rounded-pill active:bg-muted", children: _jsx(Icon, { name: "attach", color: secondary, size: 18 }) })) : null, _jsx(TextInput, { value: text, onChangeText: (value) => {
57
+ setText(value);
58
+ onTyped(value);
59
+ }, placeholder: words.composerPlaceholder, placeholderTextColor: placeholder, accessibilityLabel: words.composerPlaceholder, multiline: true, ...Platform.select({ web: { rows: 1 }, default: {} }), className: "max-h-40 flex-1 self-center px-1 py-2 font-ui text-md leading-6 text-ink" }), _jsx(Pressable, { role: "button", accessibilityLabel: words.send, disabled: !canSend, onPress: submit, className: `h-[42px] w-[42px] items-center justify-center rounded-pill bg-action active:bg-action-pressed ${canSend ? '' : 'opacity-40'}`, children: _jsx(View, { style: { transform: [{ rotate: '-90deg' }] }, children: _jsx(Icon, { name: "arrow-right", color: actionInk, size: 18 }) }) })] }), _jsx(Line, { className: "text-center text-xs text-ink-secondary", children: words.emergencyNote })] }));
60
+ }
61
+ function ThreadRow({ item, words, onRetry, ...props }) {
62
+ if (item.kind === 'notice') {
63
+ return (_jsx(Line, { className: "self-center rounded-control border border-line-subtle px-3 py-2 text-sm text-ink-secondary", children: item.message.text }));
64
+ }
65
+ if (item.kind === 'unsent')
66
+ return _jsx(Unsent, { message: item.message, words: words, onRetry: onRetry, Icon: props.Icon });
67
+ const { sender, messages } = item;
68
+ const mine = sender === 'mine';
69
+ const name = mine ? words.you : sender === 'skip' ? words.skip : sender.name;
70
+ // The run is in time order, so its time is its last line's.
71
+ const sentAt = Math.max(...messages.map((m) => m.sentAt));
72
+ return (_jsxs(View, { className: `max-w-[82%] gap-1 ${mine ? 'items-end self-end' : 'items-start self-start'}`, children: [messages.map((message, index) => (_jsxs(View, { className: "flex-row items-end gap-2", children: [mine ? null : index === messages.length - 1 ? (_jsx(SenderAvatar, { sender: sender, name: name, skipMark: props.skipMark })) : (_jsx(View, { className: "w-8" })), _jsxs(View, { className: `shrink gap-2 ${mine ? 'items-end' : 'items-start'}`, children: [message.attachments.map((attachment) => (_jsx(Attachment, { attachment: attachment, words: words, Icon: props.Icon }, attachment.url))), message.text ? _jsx(Bubble, { mine: mine, text: message.text }) : null] })] }, message.id))), _jsx(Line, { className: `px-1 text-xs text-ink-secondary ${mine ? '' : 'ml-10'}`, children: `${name} · ${words.messageTime(sentAt)}` })] }));
73
+ }
74
+ function Unsent({ message, words, onRetry, Icon, }) {
75
+ const failed = message.delivery === 'failed';
76
+ return (_jsxs(Pressable, { ...(failed ? { role: 'button' } : {}), disabled: !failed, onPress: () => {
77
+ onRetry(message.id);
78
+ }, className: `max-w-[82%] items-end gap-1 self-end ${failed ? '' : 'opacity-70'}`, children: [message.file ? _jsx(PickedPreview, { picked: message.file, words: words, Icon: Icon }) : null, message.text ? _jsx(Bubble, { mine: true, text: message.text }) : null, _jsx(Line, { ...(failed ? { role: 'alert' } : {}), className: `px-1 text-xs ${failed ? 'text-error-ink' : 'text-ink-secondary'}`, children: `${words.you} · ${failed ? words.notSent : words.sending}` })] }));
79
+ }
80
+ // Skip's mark, or a care team member's photo, or their initial when they have none or it does not load.
81
+ function SenderAvatar({ sender, name, skipMark, }) {
82
+ const [failed, setFailed] = useState(false);
83
+ if (sender === 'skip') {
84
+ return (_jsx(Image, { source: skipMark, accessibilityElementsHidden: true, style: { width: AVATAR_SIZE, height: AVATAR_SIZE }, className: "rounded-control" }));
85
+ }
86
+ return (_jsx(View, { accessibilityElementsHidden: true, className: "h-8 w-8 items-center justify-center overflow-hidden rounded-pill bg-muted", children: sender.avatarUrl && !failed ? (_jsx(Image, { source: { uri: sender.avatarUrl }, onError: () => {
87
+ setFailed(true);
88
+ }, style: { width: AVATAR_SIZE, height: AVATAR_SIZE } })) : (_jsx(Line, { className: "text-sm font-semibold text-ink", children: name.trim().charAt(0).toUpperCase() })) }));
89
+ }
90
+ // Brand's attachment card, with what kind of file it is under the name.
91
+ function FileCard({ name, detail, Icon }) {
92
+ const secondary = useColor('ink-secondary');
93
+ return (_jsxs(View, { className: "w-80 max-w-full flex-row items-center gap-3 rounded-control border border-line-subtle bg-surface p-3", children: [_jsx(Icon, { name: "file", color: secondary, size: 20 }), _jsxs(View, { className: "flex-1", children: [_jsx(Line, { className: "text-sm text-ink", numberOfLines: 1, children: name }), _jsx(Line, { className: "text-xs text-ink-secondary", children: detail })] })] }));
94
+ }
95
+ // A picked file on its way: the photo itself, or a PDF's card with its size.
96
+ function PickedPreview({ picked, words, Icon }) {
97
+ if (isPhoto(picked)) {
98
+ return (_jsx(Image, { source: { uri: picked.uri }, accessibilityLabel: `${words.photo} ${picked.name}`, resizeMode: "cover", className: "h-48 w-48 rounded-control bg-muted" }));
99
+ }
100
+ return _jsx(FileCard, { name: picked.name, detail: `${words.pdf} · ${words.fileSize(picked.size)}`, Icon: Icon });
101
+ }
102
+ // A photo shows in the conversation and a PDF as its card. Either opens in full.
103
+ function Attachment({ attachment, words, Icon, }) {
104
+ // The Skips App stores a photo a moment after its upload answers, so a fresh one loads again until it is there.
105
+ const [attempt, setAttempt] = useState(0);
106
+ const open = () => void Linking.openURL(attachment.url);
107
+ if (attachment.kind === 'file') {
108
+ return (_jsx(Pressable, { role: "link", onPress: open, className: "active:opacity-80", children: _jsx(FileCard, { name: attachment.name, detail: words.fileKind(attachment.name), Icon: Icon }) }));
109
+ }
110
+ return (_jsx(Pressable, { role: "link", accessibilityLabel: `${words.photo} ${attachment.name}`, onPress: open, className: "active:opacity-80", children: _jsx(Image, { source: { uri: attachment.thumbUrl ?? attachment.url },
111
+ // Past the last attempt the key stays the same, so the photo is not asked for again.
112
+ onError: () => {
113
+ setTimeout(() => {
114
+ setAttempt((last) => Math.min(last + 1, PHOTO_RETRIES));
115
+ }, PHOTO_RETRY_MS);
116
+ }, resizeMode: "cover", className: "h-48 w-48 rounded-control bg-muted" }, attempt) }));
117
+ }
@@ -0,0 +1,3 @@
1
+ export declare function Markdown({ text }: {
2
+ text: string;
3
+ }): import("react").JSX.Element;
@@ -0,0 +1,47 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Linking, Text, View } from 'react-native';
3
+ import { readMarkdown } from "../markdown.js";
4
+ // A line from Skips as the care team wrote it: its Markdown drawn as text, with no HTML taken from it.
5
+ function Inlines({ nodes }) {
6
+ return nodes.map((node, i) => _jsx(InlineNode, { node: node }, `${String(i)}-${node.type}`));
7
+ }
8
+ function InlineNode({ node }) {
9
+ switch (node.type) {
10
+ case 'text':
11
+ return node.text;
12
+ case 'break':
13
+ return '\n';
14
+ case 'code':
15
+ return _jsx(Text, { className: "bg-muted font-mono text-sm", children: node.text });
16
+ case 'strong':
17
+ return (_jsx(Text, { className: "font-semibold", children: _jsx(Inlines, { nodes: node.children }) }));
18
+ case 'em':
19
+ return (_jsx(Text, { className: "italic", children: _jsx(Inlines, { nodes: node.children }) }));
20
+ case 'del':
21
+ return (_jsx(Text, { className: "line-through", children: _jsx(Inlines, { nodes: node.children }) }));
22
+ case 'link':
23
+ return (_jsx(Text, { role: "link", className: "underline", onPress: () => {
24
+ void Linking.openURL(node.href);
25
+ }, children: _jsx(Inlines, { nodes: node.children }) }));
26
+ }
27
+ }
28
+ function Blocks({ blocks }) {
29
+ return blocks.map((block, i) => _jsx(BlockNode, { block: block }, `${String(i)}-${block.type}`));
30
+ }
31
+ function BlockNode({ block }) {
32
+ switch (block.type) {
33
+ case 'paragraph':
34
+ return (_jsx(Text, { className: "font-ui text-md text-ink", children: _jsx(Inlines, { nodes: block.children }) }));
35
+ case 'list':
36
+ return (_jsx(View, { role: "list", className: "gap-1", children: block.items.map((item, i) => (_jsxs(View, { role: "listitem", className: "flex-row gap-2", children: [_jsx(Text, { className: "font-ui text-md text-ink", children: block.ordered ? `${String(block.start + i)}.` : '•' }), _jsx(View, { className: "shrink gap-1", children: _jsx(Blocks, { blocks: item }) })] }, String(i)))) }));
37
+ case 'quote':
38
+ return (_jsx(View, { className: "gap-1 border-l-2 border-line-control pl-3", children: _jsx(Blocks, { blocks: block.children }) }));
39
+ case 'code':
40
+ return _jsx(Text, { className: "bg-muted p-2 font-mono text-sm text-ink", children: block.text });
41
+ case 'rule':
42
+ return _jsx(View, { className: "h-px bg-line-control" });
43
+ }
44
+ }
45
+ export function Markdown({ text }) {
46
+ return (_jsx(View, { className: "gap-2", children: _jsx(Blocks, { blocks: readMarkdown(text) }) }));
47
+ }
@@ -0,0 +1,69 @@
1
+ import { type ImageSourcePropType } from 'react-native';
2
+ import type { ChoiceItem } from '../message.ts';
3
+ /** Every word the website's welcome shows, which the website passes in. */
4
+ export interface WelcomeWords {
5
+ logIn: string;
6
+ continueHere: string;
7
+ choiceNotSent: string;
8
+ emailLabel: string;
9
+ emailSubmit: string;
10
+ emailError: string;
11
+ changeEmail: string;
12
+ nameLabel: string;
13
+ nameSubmit: string;
14
+ nameError: string;
15
+ codeLabel: string;
16
+ codeSubmit: string;
17
+ resend: string;
18
+ resendWait: string;
19
+ codeNoMatch: string;
20
+ codeRanOut: string;
21
+ typing: string;
22
+ }
23
+ /** The choice under Skip's welcome: log in as a member, or go on here as someone new. */
24
+ export declare function WelcomeChoice({ words, onLogIn, onContinueHere, }: {
25
+ words: WelcomeWords;
26
+ onLogIn: () => void;
27
+ onContinueHere: () => void;
28
+ }): import("react").JSX.Element;
29
+ /** The answers to Skip's question, all drawn alike. One answer only: while one is on its way, none can be pressed. */
30
+ export declare function Choices({ items, question, sending, holding, failed, words, onChoose, }: {
31
+ items: ChoiceItem[];
32
+ question: string;
33
+ sending: string | null;
34
+ holding?: boolean;
35
+ failed: boolean;
36
+ words: WelcomeWords;
37
+ onChoose: (answer: ChoiceItem) => void;
38
+ }): import("react").JSX.Element;
39
+ /** The email asked for after Continue here, and again for a visitor changing it. */
40
+ export declare function EmailStep({ words, onSubmit, initial, }: {
41
+ words: WelcomeWords;
42
+ onSubmit: (email: string) => void;
43
+ initial?: string;
44
+ }): import("react").JSX.Element;
45
+ /** The name asked of a visitor the Skips App does not know, with the way back to change a mistyped email. */
46
+ export declare function NameStep({ words, onSubmit, onChangeEmail, }: {
47
+ words: WelcomeWords;
48
+ onSubmit: (name: string) => void;
49
+ onChangeEmail: () => void;
50
+ }): import("react").JSX.Element;
51
+ /**
52
+ * The code emailed to the visitor, one digit to a box over one real field, so typing, deleting, a paste and the
53
+ * phone's own code suggestion work as in any field. The chat mounts it afresh for each code that goes out.
54
+ */
55
+ export declare function CodeStep({ words, length, noMatch, ranOut, resendAfterMs, onSubmit, onResend, onChangeEmail, }: {
56
+ words: WelcomeWords;
57
+ length: number;
58
+ noMatch: boolean;
59
+ ranOut: boolean;
60
+ resendAfterMs?: number;
61
+ onSubmit: (code: string) => void;
62
+ onResend: () => void;
63
+ onChangeEmail: () => void;
64
+ }): import("react").JSX.Element;
65
+ /** Skip writing a reply: three dots rising in turn in Skip's bubble beside Skip's mark, announced as a status. */
66
+ export declare function SkipTyping({ label, skipMark }: {
67
+ label: string;
68
+ skipMark: ImageSourcePropType;
69
+ }): import("react").JSX.Element;
@@ -0,0 +1,105 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { ActivityIndicator, Animated, Image, Pressable, Text, TextInput, View } from 'react-native';
4
+ import { DOT_CYCLE_MS } from "../skipTyping.js";
5
+ import { codeDigits, completesCode, EMAIL_MAX_LENGTH, givenEmail, givenName, NAME_MAX_LENGTH, RESEND_AFTER_MS, resendClock, } from "../welcome.js";
6
+ import { useColor } from "./parts.js";
7
+ const PILL_LOOK = {
8
+ solid: { box: 'bg-action active:bg-action-pressed', text: 'text-action-ink' },
9
+ stroked: { box: 'border border-line-control active:bg-muted', text: 'text-ink' },
10
+ flat: { box: 'active:bg-muted', text: 'text-ink' },
11
+ };
12
+ function Pill({ label, look = 'solid', disabled = false, loading = false, onPress, }) {
13
+ const ink = useColor(look === 'solid' ? 'action-ink' : 'ink');
14
+ return (_jsxs(Pressable, { role: "button", accessibilityLabel: label, disabled: disabled || loading, "aria-busy": loading, onPress: onPress, className: `h-control-compact flex-row items-center justify-center gap-2 rounded-pill px-5 ${PILL_LOOK[look].box} ${disabled ? 'opacity-40' : ''}`, children: [loading ? _jsx(ActivityIndicator, { "aria-hidden": true, size: "small", color: ink }) : null, _jsx(Text, { className: `font-ui text-sm font-semibold ${PILL_LOOK[look].text}`, children: label })] }));
15
+ }
16
+ /** The choice under Skip's welcome: log in as a member, or go on here as someone new. */
17
+ export function WelcomeChoice({ words, onLogIn, onContinueHere, }) {
18
+ return (_jsxs(View, { className: "flex-row flex-wrap items-center justify-center gap-2 self-stretch py-1", children: [_jsx(Pill, { label: words.logIn, look: "stroked", onPress: onLogIn }), _jsx(Pill, { label: words.continueHere, onPress: onContinueHere })] }));
19
+ }
20
+ /** The answers to Skip's question, all drawn alike. One answer only: while one is on its way, none can be pressed. */
21
+ export function Choices({ items, question, sending, holding = false, failed, words, onChoose, }) {
22
+ return (_jsxs(View, { className: "items-center gap-1 self-stretch py-1", children: [_jsx(View, { role: "group", accessibilityLabel: question, className: "flex-row flex-wrap items-center justify-center gap-2", children: items.map((item) => (_jsx(Pill, { label: item.title, look: "stroked", disabled: holding || sending !== null, loading: sending === item.value, onPress: () => {
23
+ onChoose(item);
24
+ } }, item.value))) }), failed ? (_jsx(Text, { role: "alert", className: "font-ui text-sm text-error-ink", children: words.choiceNotSent })) : null] }));
25
+ }
26
+ // One thing asked of a new visitor: a field in focus and its button. What is typed is checked here and handed on.
27
+ function StepField({ label, error, submitLabel, input, usable, onSubmit, initial = '', aside }) {
28
+ const [typed, setTyped] = useState(initial);
29
+ const [refused, setRefused] = useState(false);
30
+ const placeholder = useColor('ink-placeholder');
31
+ const submit = () => {
32
+ const value = usable(typed);
33
+ setRefused(value === null);
34
+ if (value !== null)
35
+ onSubmit(value);
36
+ };
37
+ return (_jsxs(View, { className: "w-full max-w-[360px] gap-2 self-center", children: [aside ? (_jsx(View, { className: "self-center", children: _jsx(Pill, { label: aside.label, look: "flat", onPress: aside.onPress }) })) : null, _jsx(Text, { className: "font-ui text-sm font-medium text-ink", children: label }), _jsx(TextInput, { autoFocus: true, value: typed, onChangeText: setTyped, onSubmitEditing: submit, accessibilityLabel: label, "aria-invalid": refused, placeholderTextColor: placeholder, className: `h-control rounded-control border bg-surface px-3 font-ui text-md text-ink ${refused ? 'border-error-ink' : 'border-line-control'}`, ...input }), refused ? (_jsx(Text, { role: "alert", className: "font-ui text-sm text-error-ink", children: error })) : null, _jsx(View, { className: "self-center", children: _jsx(Pill, { label: submitLabel, onPress: submit }) })] }));
38
+ }
39
+ /** The email asked for after Continue here, and again for a visitor changing it. */
40
+ export function EmailStep({ words, onSubmit, initial, }) {
41
+ return (_jsx(StepField, { label: words.emailLabel, error: words.emailError, submitLabel: words.emailSubmit, input: { autoComplete: 'email', inputMode: 'email', maxLength: EMAIL_MAX_LENGTH, autoCapitalize: 'none' }, usable: givenEmail, onSubmit: onSubmit, ...(initial === undefined ? {} : { initial }) }));
42
+ }
43
+ /** The name asked of a visitor the Skips App does not know, with the way back to change a mistyped email. */
44
+ export function NameStep({ words, onSubmit, onChangeEmail, }) {
45
+ return (_jsx(StepField, { label: words.nameLabel, error: words.nameError, submitLabel: words.nameSubmit, input: { autoComplete: 'name', maxLength: NAME_MAX_LENGTH, autoCapitalize: 'words' }, usable: givenName, onSubmit: onSubmit, aside: { label: words.changeEmail, onPress: onChangeEmail } }));
46
+ }
47
+ const TICK_MS = 250;
48
+ // Send new code, held back until the wait is over, and the wait beside it.
49
+ function NewCode({ waitMs, words, onResend }) {
50
+ const [secondsLeft, setSecondsLeft] = useState(Math.ceil(waitMs / 1000));
51
+ useEffect(() => {
52
+ const end = Date.now() + waitMs;
53
+ const timer = setInterval(() => {
54
+ const left = Math.max(0, Math.ceil((end - Date.now()) / 1000));
55
+ setSecondsLeft(left);
56
+ if (left === 0)
57
+ clearInterval(timer);
58
+ }, TICK_MS);
59
+ return () => {
60
+ clearInterval(timer);
61
+ };
62
+ }, [waitMs]);
63
+ return (_jsxs(_Fragment, { children: [_jsx(Pill, { label: words.resend, look: "flat", disabled: secondsLeft > 0, onPress: onResend }), secondsLeft > 0 ? (_jsx(Text, { role: "timer", accessibilityLabel: words.resendWait, className: "font-ui text-sm text-ink-secondary", children: resendClock(secondsLeft) })) : null] }));
64
+ }
65
+ /**
66
+ * The code emailed to the visitor, one digit to a box over one real field, so typing, deleting, a paste and the
67
+ * phone's own code suggestion work as in any field. The chat mounts it afresh for each code that goes out.
68
+ */
69
+ export function CodeStep({ words, length, noMatch, ranOut, resendAfterMs = RESEND_AFTER_MS, onSubmit, onResend, onChangeEmail, }) {
70
+ const [code, setCode] = useState('');
71
+ const error = ranOut ? words.codeRanOut : noMatch ? words.codeNoMatch : null;
72
+ return (_jsxs(View, { className: "w-full max-w-[360px] items-center gap-3 self-center", children: [_jsx(Text, { className: "font-ui text-sm font-medium text-ink", children: words.codeLabel }), _jsxs(View, { className: "relative", children: [_jsx(View, { "aria-hidden": true, className: "flex-row gap-2", children: Array.from({ length }, (_, box) => (_jsx(View, { className: `h-control w-11 items-center justify-center rounded-control border ${error ? 'border-error-ink' : 'border-line-control'}`, children: _jsx(Text, { className: "font-ui text-xl font-medium text-ink", children: code[box] ?? '' }) }, box))) }), _jsx(TextInput, { autoFocus: true, value: code, onChangeText: (typed) => {
73
+ const digits = codeDigits(typed, length);
74
+ setCode(digits);
75
+ if (completesCode(digits, code, length))
76
+ onSubmit(digits);
77
+ }, accessibilityLabel: words.codeLabel, "aria-invalid": error !== null, inputMode: "numeric", autoComplete: "one-time-code", textContentType: "oneTimeCode", caretHidden: true, className: "absolute inset-0 rounded-control text-transparent" })] }), error ? (_jsx(Text, { role: "alert", className: "text-center font-ui text-sm text-error-ink", children: error })) : null, _jsxs(View, { className: "flex-row flex-wrap items-center justify-center gap-2", children: [_jsx(Pill, { label: words.changeEmail, look: "flat", onPress: onChangeEmail }), _jsx(NewCode, { waitMs: resendAfterMs, words: words, onResend: onResend }), _jsx(Pill, { label: words.codeSubmit, onPress: () => {
78
+ onSubmit(code);
79
+ } })] })] }));
80
+ }
81
+ const DOTS = [0, 1, 2];
82
+ const DOT_SIZE = 6;
83
+ /** Skip writing a reply: three dots rising in turn in Skip's bubble beside Skip's mark, announced as a status. */
84
+ export function SkipTyping({ label, skipMark }) {
85
+ const dotColor = useColor('ink-secondary');
86
+ const rise = useRef(DOTS.map(() => new Animated.Value(0))).current;
87
+ useEffect(() => {
88
+ const step = DOT_CYCLE_MS / (2 * DOTS.length);
89
+ const loop = Animated.loop(Animated.stagger(step, rise.map((value) => Animated.sequence([
90
+ Animated.timing(value, { toValue: 1, duration: step, useNativeDriver: true }),
91
+ Animated.timing(value, { toValue: 0, duration: step, useNativeDriver: true }),
92
+ ]))));
93
+ loop.start();
94
+ return () => {
95
+ loop.stop();
96
+ };
97
+ }, [rise]);
98
+ return (_jsxs(View, { className: "mt-3 flex-row items-end gap-2", children: [_jsx(Image, { source: skipMark, "aria-hidden": true, style: { width: 32, height: 32 }, className: "rounded-control" }), _jsx(View, { role: "status", accessibilityLabel: label, className: "flex-row items-center gap-1 rounded-[20px] rounded-bl-[7px] border border-line-subtle bg-surface px-4 py-4", children: rise.map((value, dot) => (_jsx(Animated.View, { style: {
99
+ width: DOT_SIZE,
100
+ height: DOT_SIZE,
101
+ borderRadius: DOT_SIZE / 2,
102
+ backgroundColor: dotColor,
103
+ transform: [{ translateY: value.interpolate({ inputRange: [0, 1], outputRange: [0, -DOT_SIZE] }) }],
104
+ } }, DOTS[dot]))) })] }));
105
+ }
@@ -0,0 +1,35 @@
1
+ import type { ComponentType } from 'react';
2
+ /** The icons the chat draws, from the brand's interface icons, which each app already draws. */
3
+ export type ChatIconName = 'attach' | 'arrow-right' | 'file' | 'close';
4
+ export type ChatIcon = ComponentType<{
5
+ name: ChatIconName;
6
+ color: string;
7
+ size: number;
8
+ }>;
9
+ /** Every word the chat shows, which each app passes in. */
10
+ export interface ChatWords {
11
+ composerPlaceholder: string;
12
+ send: string;
13
+ attach: string;
14
+ remove: string;
15
+ photo: string;
16
+ pdf: string;
17
+ sending: string;
18
+ notSent: string;
19
+ retry: string;
20
+ you: string;
21
+ skip: string;
22
+ emergencyNote: string;
23
+ feedDown: string;
24
+ loading: string;
25
+ loadFailed: string;
26
+ attachmentRefused: {
27
+ type: string;
28
+ size: string;
29
+ };
30
+ fileKind: (name: string) => string;
31
+ fileSize: (bytes: number) => string;
32
+ messageTime: (ms: number) => string;
33
+ typingLine: (names: string[]) => string;
34
+ }
35
+ export declare function useColor(token: string): string;
@@ -0,0 +1,6 @@
1
+ import { useCSSVariable } from 'uniwind';
2
+ // A colour token for props a class cannot reach, such as an icon's colour.
3
+ export function useColor(token) {
4
+ const value = useCSSVariable(`--color-${token}`);
5
+ return value === undefined ? '' : String(value);
6
+ }
@@ -0,0 +1,10 @@
1
+ export { Conversation, type ConversationProps, type LoadState } from './components/Conversation.tsx';
2
+ export type { ChatIcon, ChatIconName, ChatWords } from './components/parts.ts';
3
+ export { ATTACHMENT_TYPES, MAX_ATTACHMENT_BYTES, attachmentProblem, attachmentType } from './attachments.ts';
4
+ export { isSkip, type ChatAttachment, type ChatAuthor, type ChatMessage, type ChoiceItem, type MessageChoice, type PickedFile, } from './message.ts';
5
+ export { CLUSTER_GAP_MS, EMPTY_THREAD, groupThread, pendingId, withFailed, withoutMessage, withPending, withReceived, withReceivedAll, withSent, type Delivery, type RunSender, type Thread, type ThreadItem, type ThreadMessage, } from './thread.ts';
6
+ export { TYPING_CLEAR_MS, TYPING_IDLE_MS, createTypingSignal, createTypingWatch } from './typing.ts';
7
+ export { TYPING_IDLE, TYPING_TIMES, heldFrom, typingReducer, type TypingEvent, type TypingSignal, type TypingStarted, type TypingState, type TypingTimes, } from './skipTyping.ts';
8
+ export { fitVisibleArea, type Fit, type VisualViewportBox } from './visibleArea.ts';
9
+ export { EMAIL_MAX_LENGTH, NAME_MAX_LENGTH, RESEND_AFTER_MS, WELCOME_TYPING_TIMES, givenEmail, givenName, isEmail, isName, typesBefore, typingMs, type WelcomeStep, type WelcomeTypingTimes, } from './welcome.ts';
10
+ export { Choices, CodeStep, EmailStep, NameStep, SkipTyping, WelcomeChoice, type WelcomeWords, } from './components/Welcome.tsx';
package/chat/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { Conversation } from "./components/Conversation.js";
2
+ export { ATTACHMENT_TYPES, MAX_ATTACHMENT_BYTES, attachmentProblem, attachmentType } from "./attachments.js";
3
+ export { isSkip, } from "./message.js";
4
+ export { CLUSTER_GAP_MS, EMPTY_THREAD, groupThread, pendingId, withFailed, withoutMessage, withPending, withReceived, withReceivedAll, withSent, } from "./thread.js";
5
+ export { TYPING_CLEAR_MS, TYPING_IDLE_MS, createTypingSignal, createTypingWatch } from "./typing.js";
6
+ export { TYPING_IDLE, TYPING_TIMES, heldFrom, typingReducer, } from "./skipTyping.js";
7
+ export { fitVisibleArea } from "./visibleArea.js";
8
+ export { EMAIL_MAX_LENGTH, NAME_MAX_LENGTH, RESEND_AFTER_MS, WELCOME_TYPING_TIMES, givenEmail, givenName, isEmail, isName, typesBefore, typingMs, } from "./welcome.js";
9
+ export { Choices, CodeStep, EmailStep, NameStep, SkipTyping, WelcomeChoice, } from "./components/Welcome.js";
@@ -0,0 +1,47 @@
1
+ import type { Token } from 'markdown-it';
2
+ export interface TextInline {
3
+ type: 'text';
4
+ text: string;
5
+ }
6
+ export interface BreakInline {
7
+ type: 'break';
8
+ }
9
+ export interface CodeInline {
10
+ type: 'code';
11
+ text: string;
12
+ }
13
+ export interface MarkInline {
14
+ type: 'strong' | 'em' | 'del';
15
+ children: Inline[];
16
+ }
17
+ export interface LinkInline {
18
+ type: 'link';
19
+ href: string;
20
+ children: Inline[];
21
+ }
22
+ export type Inline = TextInline | BreakInline | CodeInline | MarkInline | LinkInline;
23
+ export interface ParagraphBlock {
24
+ type: 'paragraph';
25
+ children: Inline[];
26
+ }
27
+ export interface ListBlock {
28
+ type: 'list';
29
+ ordered: boolean;
30
+ start: number;
31
+ items: Block[][];
32
+ }
33
+ export interface QuoteBlock {
34
+ type: 'quote';
35
+ children: Block[];
36
+ }
37
+ export interface CodeBlock {
38
+ type: 'code';
39
+ text: string;
40
+ }
41
+ export interface RuleBlock {
42
+ type: 'rule';
43
+ }
44
+ export type Block = ParagraphBlock | ListBlock | QuoteBlock | CodeBlock | RuleBlock;
45
+ export declare const LINK_PROTOCOLS: readonly string[];
46
+ export declare function inlinesOf(token: Token): Inline[];
47
+ export declare function readMarkdown(source: string): Block[];