@marktiderman/genesis-ui-native 3.5.0 → 3.6.0
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 +71 -7
- package/dist/{chunk-LBVD7XXL.js → chunk-2Z72MYHB.js} +627 -20
- package/dist/chunk-2Z72MYHB.js.map +1 -0
- package/dist/chunk-4OQOJ2OC.js +80 -0
- package/dist/chunk-4OQOJ2OC.js.map +1 -0
- package/dist/{chunk-6KWEAGRD.js → chunk-6PGLX6ET.js} +101 -6
- package/dist/chunk-6PGLX6ET.js.map +1 -0
- package/dist/{chunk-ONH2PCGH.js → chunk-AGTBABAH.js} +9 -15
- package/dist/chunk-AGTBABAH.js.map +1 -0
- package/dist/{chunk-ABVSSJNT.js → chunk-FUMSL7VZ.js} +198 -168
- package/dist/chunk-FUMSL7VZ.js.map +1 -0
- package/dist/{chunk-GHYUNNNU.js → chunk-NDXNSSM6.js} +175 -93
- package/dist/chunk-NDXNSSM6.js.map +1 -0
- package/dist/chunk-SEJ6RBP7.js +361 -0
- package/dist/chunk-SEJ6RBP7.js.map +1 -0
- package/dist/{chunk-D5RKSPMH.js → chunk-ZRQAFFTN.js} +4 -3
- package/dist/chunk-ZRQAFFTN.js.map +1 -0
- package/dist/components/index.d.ts +331 -4
- package/dist/components/index.js +5 -5
- package/dist/data/index.d.ts +68 -4
- package/dist/data/index.js +235 -31
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.d.ts +60 -1
- package/dist/hooks/index.js +2 -3
- package/dist/icons/lucide.d.ts +1 -1
- package/dist/icons/lucide.js +7 -1
- package/dist/icons/lucide.js.map +1 -1
- package/dist/{inbox-page-BEarNEIP.d.ts → inbox-page-B7_Oi2fS.d.ts} +2 -44
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -8
- package/dist/layouts/index.d.ts +40 -51
- package/dist/layouts/index.js +5 -4
- package/dist/{native-modules-PwnGltOU.d.ts → native-modules-Cl3zw3kh.d.ts} +27 -1
- package/package.json +78 -4
- package/src/__tests__/doctor-rules.test.ts +60 -0
- package/src/__tests__/native-modules-lists.test.tsx +1 -0
- package/src/components/__tests__/composer-bar.test.tsx +55 -0
- package/src/components/__tests__/gallery-card.test.tsx +59 -0
- package/src/components/__tests__/gallery-grid.test.tsx +160 -0
- package/src/components/__tests__/lightbox-resnap.test.tsx +50 -0
- package/src/components/__tests__/lightbox-zoom.test.ts +33 -0
- package/src/components/__tests__/lightbox.test.tsx +141 -0
- package/src/components/__tests__/live-indicator.test.tsx +72 -0
- package/src/components/__tests__/rating.test.tsx +82 -0
- package/src/components/__tests__/thread-list.test.tsx +156 -0
- package/src/components/composer-bar.tsx +198 -0
- package/src/components/drawer.tsx +15 -9
- package/src/components/gallery-card.tsx +109 -0
- package/src/components/gallery-grid.tsx +285 -0
- package/src/components/gallery-layout.ts +2 -0
- package/src/components/gallery-types.ts +2 -0
- package/src/components/index.ts +44 -0
- package/src/components/lightbox-zoom.tsx +282 -0
- package/src/components/lightbox.tsx +342 -0
- package/src/components/live-indicator.tsx +139 -0
- package/src/components/rating.tsx +128 -0
- package/src/components/skeleton.tsx +9 -4
- package/src/components/thread-list.tsx +427 -0
- package/src/components/toast.tsx +7 -4
- package/src/data/NativeConflictSheet.tsx +181 -0
- package/src/data/NativeResourceForm.tsx +15 -1
- package/src/data/index.ts +2 -0
- package/src/data/resource-view/NativeLinkPicker.tsx +1 -1
- package/src/data/resource-view/NativeRecordView.tsx +85 -8
- package/src/data/resource-view/NativeResourceView.tsx +79 -32
- package/src/data/resource-view/__tests__/native-link-picker.test.tsx +16 -0
- package/src/data/resource-view/__tests__/native-record-view.test.tsx +95 -1
- package/src/data/resource-view/__tests__/native-resource-gallery.test.tsx +125 -0
- package/src/data/resource-view/mapping.ts +3 -0
- package/src/hooks/__tests__/use-motion.test.tsx +106 -0
- package/src/hooks/__tests__/use-thread-jump.test.tsx +88 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/use-motion.ts +128 -0
- package/src/hooks/use-thread-jump.ts +110 -0
- package/src/icon-names.ts +6 -0
- package/src/icons/lucide.ts +12 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +6 -0
- package/src/layouts/__tests__/thread-page.test.tsx +114 -14
- package/src/layouts/inbox-page.tsx +6 -55
- package/src/layouts/index.ts +2 -0
- package/src/layouts/thread-page.tsx +326 -262
- package/src/native-modules.tsx +16 -2
- package/dist/chunk-6KWEAGRD.js.map +0 -1
- package/dist/chunk-7PCWEY6R.js +0 -27
- package/dist/chunk-7PCWEY6R.js.map +0 -1
- package/dist/chunk-ABVSSJNT.js.map +0 -1
- package/dist/chunk-D5RKSPMH.js.map +0 -1
- package/dist/chunk-GHYUNNNU.js.map +0 -1
- package/dist/chunk-LBVD7XXL.js.map +0 -1
- package/dist/chunk-ONH2PCGH.js.map +0 -1
- package/dist/chunk-Z3AQYVUA.js +0 -36
- package/dist/chunk-Z3AQYVUA.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @feat:inbox-thread
|
|
2
|
-
import {
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
3
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
4
|
import { describe, expect, it, vi } from "vitest";
|
|
5
5
|
import { ThreadPage, getThreadPageStackOptions, readReceiptFor, type ThreadMessage } from "../thread-page";
|
|
6
|
-
import {
|
|
6
|
+
import { GenesisModulesProvider } from "../../native-modules";
|
|
7
7
|
|
|
8
8
|
const messages: ThreadMessage[] = [
|
|
9
9
|
{ id: "1", body: "The save button does nothing", mine: true, timestamp: "2026-10-24T09:00:00Z" },
|
|
@@ -99,27 +99,127 @@ describe("ThreadPage", () => {
|
|
|
99
99
|
expect(screen.getByTestId("t-empty").textContent).toContain("Say hello");
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
-
it("
|
|
102
|
+
it("sits in React Native's KeyboardAvoidingView without the keyboard module", () => {
|
|
103
103
|
render(<ThreadPage testID="t" messages={messages} composer={composer()} />);
|
|
104
|
-
|
|
105
|
-
expect(
|
|
104
|
+
const keyboard = screen.getByTestId("t-keyboard");
|
|
105
|
+
expect(keyboard.querySelector('[data-testid="t-composer-input"]')).toBeTruthy();
|
|
106
|
+
expect(keyboard.querySelector('[data-testid="t-messages"]')).toBeTruthy();
|
|
106
107
|
});
|
|
107
108
|
|
|
108
|
-
it("
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
109
|
+
it("follows the keyboard frame by frame with the app's keyboard-controller KeyboardAvoidingView", () => {
|
|
110
|
+
const seen: Record<string, unknown>[] = [];
|
|
111
|
+
const Kav = ({ children, testID, ...rest }: Record<string, unknown> & { children?: ReactNode; testID?: string }) => {
|
|
112
|
+
seen.push(rest);
|
|
112
113
|
return <div data-testid={testID}>{children}</div>;
|
|
113
|
-
}
|
|
114
|
+
};
|
|
115
|
+
render(
|
|
116
|
+
<GenesisModulesProvider modules={{ keyboardAvoidingView: Kav }}>
|
|
117
|
+
<ThreadPage testID="t" messages={messages} composer={composer()} keyboardVerticalOffset={64} />
|
|
118
|
+
</GenesisModulesProvider>,
|
|
119
|
+
);
|
|
120
|
+
expect(seen.at(-1)).toMatchObject({ behavior: "translate-with-padding", automaticOffset: true, keyboardVerticalOffset: 64 });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("shows events as centred lines, and keeps them out of the read receipt", () => {
|
|
124
|
+
const withEvent: ThreadMessage[] = [...messages, { id: "e", kind: "event", body: "Sam was assigned", mine: true, timestamp: "2026-10-24T09:20:00Z" }];
|
|
125
|
+
render(<ThreadPage testID="t" messages={withEvent} composer={composer()} readAt="2026-10-24T10:00:00Z" />);
|
|
126
|
+
expect(screen.getByTestId("t-event-e").textContent).toBe("Sam was assigned");
|
|
127
|
+
expect(screen.queryByTestId("t-message-e")).toBeNull();
|
|
128
|
+
expect(readReceiptFor(withEvent, "2026-10-24T10:00:00Z")).toBe("3");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("marks the first unread with a divider", () => {
|
|
132
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} firstUnreadId="2" labels={{ newMessages: "Unread" }} />);
|
|
133
|
+
expect(screen.getByTestId("t-unread").textContent).toBe("Unread");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("says each send state, and discards on request", () => {
|
|
137
|
+
const onDiscard = vi.fn();
|
|
138
|
+
const rows: ThreadMessage[] = [
|
|
139
|
+
{ id: "p", body: "a", mine: true, timestamp: "2026-10-24T09:00:00Z", status: "pending" },
|
|
140
|
+
{ id: "z", body: "b", mine: true, timestamp: "2026-10-24T09:00:00Z", status: "paused" },
|
|
141
|
+
{ id: "c", body: "c", mine: true, timestamp: "2026-10-24T09:00:00Z", status: "conflict", onRetry: vi.fn(), onDiscard },
|
|
142
|
+
];
|
|
143
|
+
render(<ThreadPage testID="t" messages={rows} composer={composer()} />);
|
|
144
|
+
expect(screen.getByTestId("t-message-p-time").textContent).toBe("Waiting to send");
|
|
145
|
+
expect(screen.getByTestId("t-message-z-time").textContent).toBe("Sign in to send");
|
|
146
|
+
expect(screen.getByTestId("t-message-c-time").textContent).toMatch(/changed elsewhere/);
|
|
147
|
+
fireEvent.click(screen.getByTestId("t-message-c-discard"));
|
|
148
|
+
expect(onDiscard).toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("says it's updating while fresher rows load", () => {
|
|
152
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} updating />);
|
|
153
|
+
expect(screen.getByTestId("t-updating").textContent).toBe("Updating…");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("tints an internal note, and the composer in its internal mode", () => {
|
|
157
|
+
const rows: ThreadMessage[] = [{ id: "n", body: "Check the logs", mine: true, tone: "internal", timestamp: "2026-10-24T09:00:00Z" }];
|
|
158
|
+
const onModeChange = vi.fn();
|
|
159
|
+
render(
|
|
160
|
+
<ThreadPage
|
|
161
|
+
testID="t"
|
|
162
|
+
messages={rows}
|
|
163
|
+
composer={composer({ modes: [{ id: "reply", label: "Reply" }, { id: "note", label: "Internal note", tone: "internal" }], mode: "note", onModeChange })}
|
|
164
|
+
/>,
|
|
165
|
+
);
|
|
166
|
+
expect(screen.getByTestId("t-composer-mode-note").getAttribute("aria-selected")).toBe("true");
|
|
167
|
+
expect(screen.getByTestId("t-composer-input").getAttribute("placeholder")).toBe("Internal note");
|
|
168
|
+
fireEvent.click(screen.getByTestId("t-composer-mode-reply"));
|
|
169
|
+
expect(onModeChange).toHaveBeenCalledWith("reply");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("says an internal note is one, to VoiceOver", () => {
|
|
173
|
+
const rows: ThreadMessage[] = [{ id: "n", body: "Check the logs", mine: true, tone: "internal", timestamp: "2026-10-24T09:00:00Z" }];
|
|
174
|
+
render(<ThreadPage testID="t" messages={rows} composer={composer()} />);
|
|
175
|
+
expect(screen.getByTestId("t-message-n").getAttribute("aria-label")).toMatch(/^You, Internal note, Check the logs/);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("offers Discard only on a message that hasn't gone", () => {
|
|
179
|
+
const onDiscard = vi.fn();
|
|
180
|
+
const rows: ThreadMessage[] = [{ id: "s", body: "sent", mine: true, timestamp: "2026-10-24T09:00:00Z", onDiscard }];
|
|
181
|
+
render(<ThreadPage testID="t" messages={rows} composer={composer()} />);
|
|
182
|
+
expect(screen.queryByTestId("t-message-s-discard")).toBeNull();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("doesn't offer Discard while a message is sending (it may already be on the server)", () => {
|
|
186
|
+
const onDiscard = vi.fn();
|
|
187
|
+
const rows: ThreadMessage[] = [
|
|
188
|
+
{ id: "a", body: "a", mine: true, timestamp: "2026-10-24T09:00:00Z", status: "sending", onDiscard },
|
|
189
|
+
{ id: "b", body: "b", mine: true, timestamp: "2026-10-24T09:01:00Z", status: "pending", onDiscard },
|
|
190
|
+
];
|
|
191
|
+
render(<ThreadPage testID="t" messages={rows} composer={composer()} />);
|
|
192
|
+
expect(screen.queryByTestId("t-message-a-discard")).toBeNull();
|
|
193
|
+
expect(screen.getByTestId("t-message-b-discard")).toBeTruthy();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("warns in development when keyboard-controller is set up but not passed as keyboardAvoidingView", async () => {
|
|
197
|
+
const { KeyboardScrollProvider } = await import("../keyboard");
|
|
198
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
199
|
+
const Scroll = ({ children }: { children?: ReactNode }) => <div>{children}</div>;
|
|
114
200
|
render(
|
|
115
201
|
<KeyboardScrollProvider component={Scroll}>
|
|
116
202
|
<ThreadPage testID="t" messages={messages} composer={composer()} />
|
|
117
203
|
</KeyboardScrollProvider>,
|
|
118
204
|
);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
205
|
+
expect(warn.mock.calls.some(([m]) => String(m).includes("keyboardAvoidingView"))).toBe(true);
|
|
206
|
+
warn.mockRestore();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("shows a skeleton, not the empty state, while the first page loads", () => {
|
|
210
|
+
render(<ThreadPage testID="t" messages={[]} composer={composer()} loading />);
|
|
211
|
+
expect(screen.getByTestId("t-messages-loading")).toBeTruthy();
|
|
212
|
+
expect(screen.queryByTestId("t-empty")).toBeNull();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("pins the header region above the list", () => {
|
|
216
|
+
const Props = ({ testID }: { testID: string }) => <div data-testid={testID}>Open · Sam</div>;
|
|
217
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} slots={{ headerRegion: Props }} />);
|
|
218
|
+
const region = screen.getByTestId("t-header-region");
|
|
219
|
+
expect(region.textContent).toBe("Open · Sam");
|
|
220
|
+
expect(screen.getByTestId("t-messages").contains(region)).toBe(false);
|
|
221
|
+
// Outside the keyboard-avoiding view, so it doesn't move with the keyboard.
|
|
222
|
+
expect(screen.getByTestId("t-keyboard").contains(region)).toBe(false);
|
|
123
223
|
});
|
|
124
224
|
|
|
125
225
|
it("composes a standard header by default", () => {
|
|
@@ -41,49 +41,11 @@ import { NativeBadge } from "../components/badge";
|
|
|
41
41
|
import { NativeRefreshControl } from "../components/refresh-control";
|
|
42
42
|
import { NativeLoadingState } from "../components/loading-state";
|
|
43
43
|
import { composeHeaderOptions, type ScreenHeaderProps } from "./screen-container";
|
|
44
|
+
import { formatInboxTime, type InboxItem, type InboxSwipeAction } from "@marktiderman/genesis-core/conversation";
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
label: string;
|
|
49
|
-
onPress: () => void;
|
|
50
|
-
/** Destructive tone (delete, leave). */
|
|
51
|
-
destructive?: boolean;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface InboxItem {
|
|
55
|
-
/** Stable id for keying. */
|
|
56
|
-
id: string;
|
|
57
|
-
title: string;
|
|
58
|
-
/** The latest message or a summary, at most two lines. */
|
|
59
|
-
preview?: string;
|
|
60
|
-
/** When it last changed. Shown as a short time or date. */
|
|
61
|
-
timestamp?: string | Date;
|
|
62
|
-
/** Something new the person hasn't read: a dot, and the title in bold. */
|
|
63
|
-
unread?: boolean;
|
|
64
|
-
/** How many unread messages; shown as a count instead of the dot when above 0. */
|
|
65
|
-
unreadCount?: number;
|
|
66
|
-
/** A short status shown under the preview ("In progress", "12 votes"). */
|
|
67
|
-
meta?: string;
|
|
68
|
-
/** Replaces the unread dot (an icon). For a picture of who it is, use `avatar`, which keeps the dot. */
|
|
69
|
-
leading?: ReactNode;
|
|
70
|
-
/**
|
|
71
|
-
* A picture of who or what it is (a `NativeAvatar`, about 40pt), between the
|
|
72
|
-
* unread dot and the text. The separator then starts at the text. It is hidden
|
|
73
|
-
* from screen readers; when it shows someone `title` doesn't name, say who in
|
|
74
|
-
* `avatarLabel`.
|
|
75
|
-
*/
|
|
76
|
-
avatar?: ReactNode;
|
|
77
|
-
/** Who the avatar shows, read before the title, when `title` doesn't name them. */
|
|
78
|
-
avatarLabel?: string;
|
|
79
|
-
/** Shown at the end of the row (a vote button, a badge). Replaces the chevron. */
|
|
80
|
-
trailing?: ReactNode;
|
|
81
|
-
/** Opens the conversation. Rows with `onPress` show a chevron unless `trailing` is set. */
|
|
82
|
-
onPress?: () => void;
|
|
83
|
-
swipeActions?: InboxSwipeAction[];
|
|
84
|
-
/** testID override. Default `<page testID>-row-<id>`. */
|
|
85
|
-
testID?: string;
|
|
86
|
-
}
|
|
46
|
+
// The conversation contract is genesis-core's, shared with genesis-ui's InboxPage.
|
|
47
|
+
export type { InboxItem, InboxSwipeAction } from "@marktiderman/genesis-core/conversation";
|
|
48
|
+
export { formatInboxTime } from "@marktiderman/genesis-core/conversation";
|
|
87
49
|
|
|
88
50
|
/** The parts `slots` and `slotProps` reach, with the props each receives. */
|
|
89
51
|
export type InboxPageSlotMap = {
|
|
@@ -140,18 +102,6 @@ export function getInboxPageStackOptions(props: ScreenHeaderProps & { headerTitl
|
|
|
140
102
|
});
|
|
141
103
|
}
|
|
142
104
|
|
|
143
|
-
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
144
|
-
|
|
145
|
-
/** The default row time: `9:41`, `Yesterday`, `Monday`, then a short date. */
|
|
146
|
-
export function formatInboxTime(date: Date, now: Date): string {
|
|
147
|
-
const start = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
148
|
-
const days = Math.round((start(now) - start(date)) / DAY_MS);
|
|
149
|
-
if (days <= 0) return date.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
|
|
150
|
-
if (days === 1) return "Yesterday";
|
|
151
|
-
if (days < 7) return date.toLocaleDateString(undefined, { weekday: "long" });
|
|
152
|
-
return date.toLocaleDateString(undefined, { day: "numeric", month: "short", year: date.getFullYear() === now.getFullYear() ? undefined : "numeric" });
|
|
153
|
-
}
|
|
154
|
-
|
|
155
105
|
/** The row's leading padding, the unread dot's column, an avatar's default size and its gap to the text. */
|
|
156
106
|
const ROW_PADDING = 16;
|
|
157
107
|
const LEADING_WIDTH = 18;
|
|
@@ -349,13 +299,14 @@ function DefaultRow(row: InboxPageSlotMap["row"]) {
|
|
|
349
299
|
testID={row.testID}
|
|
350
300
|
accessibilityRole={row.onPress ? "button" : undefined}
|
|
351
301
|
accessibilityLabel={label}
|
|
302
|
+
accessibilityState={row.selected ? { selected: true } : undefined}
|
|
352
303
|
accessibilityActions={actions.map((a) => ({ name: a.id, label: a.label }))}
|
|
353
304
|
onAccessibilityAction={(event) => actions.find((a) => a.id === event.nativeEvent.actionName)?.onPress()}
|
|
354
305
|
onPress={row.onPress}
|
|
355
306
|
onLongPress={actions.length ? () => showInboxActions(row.title, actions) : undefined}
|
|
356
307
|
onPressIn={() => setPressed(true)}
|
|
357
308
|
onPressOut={() => setPressed(false)}
|
|
358
|
-
style={{ flexDirection: "row", alignItems: "center", paddingHorizontal: ROW_PADDING, paddingVertical: 11, minHeight: 60, backgroundColor: pressed && row.onPress ? colors.fill : undefined }}
|
|
309
|
+
style={{ flexDirection: "row", alignItems: "center", paddingHorizontal: ROW_PADDING, paddingVertical: 11, minHeight: 60, backgroundColor: (pressed && row.onPress) || row.selected ? colors.fill : undefined }}
|
|
359
310
|
>
|
|
360
311
|
<View style={{ width: LEADING_WIDTH, alignItems: "flex-start" }}>
|
|
361
312
|
{row.leading ?? (row.unreadCount && row.unreadCount > 0 ? null : <UnreadDot unread={!!row.unread} testID={`${row.testID}-unread`} color={colors.tint} />)}
|