@marktiderman/genesis-ui-native 2.5.0 → 2.7.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/dist/{chunk-YJV5MMZX.js → chunk-7HWS2JGX.js} +7 -741
- package/dist/chunk-7HWS2JGX.js.map +1 -0
- package/dist/{chunk-IDHW2NOP.js → chunk-C6Q5ZAVT.js} +232 -6
- package/dist/chunk-C6Q5ZAVT.js.map +1 -0
- package/dist/{chunk-YI7XVY2D.js → chunk-ON7WP4T6.js} +13 -479
- package/dist/chunk-ON7WP4T6.js.map +1 -0
- package/dist/chunk-PO3MK6IY.js +1231 -0
- package/dist/chunk-PO3MK6IY.js.map +1 -0
- package/dist/chunk-SXCG2REG.js +479 -0
- package/dist/chunk-SXCG2REG.js.map +1 -0
- package/dist/components/index.d.ts +10 -3
- package/dist/components/index.js +3 -4
- package/dist/data/index.d.ts +482 -4
- package/dist/data/index.js +1480 -17
- package/dist/data/index.js.map +1 -1
- package/dist/inbox-page-DZUR-PJ1.d.ts +199 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -5
- package/dist/layouts/index.d.ts +4 -195
- package/dist/layouts/index.js +3 -3
- package/package.json +2 -2
- package/src/components/__tests__/button-a11y.test.tsx +17 -0
- package/src/components/button.tsx +8 -2
- package/src/components/image.tsx +5 -0
- package/src/data/NativeDetailPanel.tsx +8 -1
- package/src/data/index.ts +1 -0
- package/src/data/resource-view/NativeResourceFormSheet.tsx +305 -0
- package/src/data/resource-view/NativeResourceView.tsx +536 -0
- package/src/data/resource-view/NativeResourceWorkspace.tsx +657 -0
- package/src/data/resource-view/__tests__/native-resource-view.test.tsx +977 -0
- package/src/data/resource-view/__tests__/native-resource-workspace.test.tsx +356 -0
- package/src/data/resource-view/display.tsx +259 -0
- package/src/data/resource-view/index.ts +61 -0
- package/src/data/resource-view/mapping.ts +333 -0
- package/src/data/resource-view/messages.ts +121 -0
- package/src/data/resource-view/use-native-resource-view.ts +309 -0
- package/dist/chunk-EFXCJ5AN.js +0 -234
- package/dist/chunk-EFXCJ5AN.js.map +0 -1
- package/dist/chunk-FIITITXO.js +0 -492
- package/dist/chunk-FIITITXO.js.map +0 -1
- package/dist/chunk-IDHW2NOP.js.map +0 -1
- package/dist/chunk-YI7XVY2D.js.map +0 -1
- package/dist/chunk-YJV5MMZX.js.map +0 -1
package/dist/components/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export { Box, FULL_SCREEN_DARK, Grid, Inline, NativeAccordion, NativeAccordionContent, NativeAccordionItem, NativeAccordionTrigger,
|
|
2
|
-
export { NativeAlert, NativeAlertDescription, NativeAlertTitle, NativeCard, NativeCardContent, NativeCardDescription, NativeCardFooter, NativeCardHeader, NativeCardTitle, NativeCheckbox, NativeLabel, NativeSelect, NativeSelectContent, NativeSelectItem, NativeSelectTrigger, NativeSeparator, NativeSkeleton, NativeSwitch, NativeTextarea, alertVariants } from '../chunk-
|
|
1
|
+
export { Box, FULL_SCREEN_DARK, Grid, Inline, NativeAccordion, NativeAccordionContent, NativeAccordionItem, NativeAccordionTrigger, NativeChip, NativeChipGroup, NativeCombobox, NativeDialog, NativeDialogContent, NativeDialogDescription, NativeDialogFooter, NativeDialogHeader, NativeDialogTitle, NativeDrawer, NativeDropdownMenu, NativeDropdownMenuContent, NativeDropdownMenuItem, NativeDropdownMenuTrigger, NativeFullScreenModal, NativeGlassSurface, NativeHeaderCard, NativeNumberInput, NativePagination, NativePopover, NativePopoverContent, NativePopoverTrigger, NativeProgress, NativeRadioGroup, NativeRadioGroupItem, NativeRangeSlider, NativeSlider, NativeStepper, NativeTabs, NativeTabsContent, NativeTabsList, NativeTabsTrigger, NativeToastProvider, NativeToggle, NativeTooltip, NativeTooltipContent, NativeTooltipTrigger, Stack, spaceScale, spacingClass, toggleVariants, useLiquidGlass, useReduceTransparency, useToast } from '../chunk-7HWS2JGX.js';
|
|
2
|
+
export { NativeAlert, NativeAlertDescription, NativeAlertTitle, NativeAvatar, NativeBanner, NativeCard, NativeCardContent, NativeCardDescription, NativeCardFooter, NativeCardHeader, NativeCardTitle, NativeCheckbox, NativeDatePicker, NativeImage, NativeInlineAlert, NativeLabel, NativeSearchBar, NativeSegmentedControl, NativeSelect, NativeSelectContent, NativeSelectItem, NativeSelectTrigger, NativeSeparator, NativeSheet, NativeSheetProvider, NativeSheetScrollView, NativeSkeleton, NativeSwitch, NativeTextarea, NativeTimePicker, alertVariants } from '../chunk-PO3MK6IY.js';
|
|
3
3
|
import '../chunk-7PCWEY6R.js';
|
|
4
|
-
export { NATIVE_ICON_NAMES, NativeEmptyState, NativeIcon, NativeListItem, NativeListItemDivider, NativeLoadingState, NativeRefreshControl, NativeSectionListHeader, SF_SYMBOLS } from '../chunk-
|
|
5
|
-
export { GenesisModulesProvider, NativeBadge, NativeButton, NativeInput, NativeText, badgeTextVariants, badgeVariants, buttonTextVariants, buttonVariants, textVariants, useGenesisModules } from '../chunk-EFXCJ5AN.js';
|
|
4
|
+
export { GenesisModulesProvider, NATIVE_ICON_NAMES, NativeBadge, NativeButton, NativeEmptyState, NativeIcon, NativeInput, NativeListItem, NativeListItemDivider, NativeLoadingState, NativeRefreshControl, NativeSectionListHeader, NativeText, SF_SYMBOLS, badgeTextVariants, badgeVariants, buttonTextVariants, buttonVariants, textVariants, useGenesisModules } from '../chunk-C6Q5ZAVT.js';
|
|
6
5
|
import '../chunk-Z3AQYVUA.js';
|
|
7
6
|
import '../chunk-OHZD7KRO.js';
|
|
8
7
|
import '../chunk-DGUM43GV.js';
|
package/dist/data/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
import { ResourceFormFieldDef, BaseRecord } from '@marktiderman/genesis-core';
|
|
2
|
+
import { ReactNode, ComponentType } from 'react';
|
|
3
|
+
import { ResourceFormFieldDef, BaseRecord, DataRow, ResourceContract } from '@marktiderman/genesis-core';
|
|
4
4
|
import { Control, UseFormReturn } from 'react-hook-form';
|
|
5
5
|
import { UseResourceOptions } from '@marktiderman/genesis-core/hooks';
|
|
6
|
+
import { d as InboxSwipeAction, c as InboxPageSlotMap, g as ScreenHeaderProps } from '../inbox-page-DZUR-PJ1.js';
|
|
7
|
+
import { ResourceView, DisplayHint, RowSummary, RowPicture, Allowed, Viewer, ResolvedColumn, ResourceWorkspace } from '@marktiderman/genesis-core/resource-view';
|
|
8
|
+
import { ReadinessLabels } from '@marktiderman/genesis-core/resource';
|
|
9
|
+
import '@marktiderman/genesis-core/slots';
|
|
10
|
+
import 'react-native';
|
|
6
11
|
|
|
7
12
|
interface NativeEmptyStateProps {
|
|
8
13
|
message?: string;
|
|
@@ -58,9 +63,13 @@ interface NativeDetailPanelProps<T = Record<string, unknown>> {
|
|
|
58
63
|
fields?: NativeDetailField<T>[];
|
|
59
64
|
onEdit?: (item: T) => void;
|
|
60
65
|
onDelete?: (item: T) => void;
|
|
66
|
+
/** The heading. Wins over `titleField` (e.g. a view's `summary(row).title`). */
|
|
67
|
+
title?: string;
|
|
68
|
+
/** Below the fields and actions (e.g. actions with their own wording, or the reason one is refused). */
|
|
69
|
+
footer?: ReactNode;
|
|
61
70
|
children?: ReactNode;
|
|
62
71
|
}
|
|
63
|
-
declare function NativeDetailPanel<T extends Record<string, unknown>>({ item, titleField, fields, onEdit, onDelete, children, }: NativeDetailPanelProps<T>): react.JSX.Element;
|
|
72
|
+
declare function NativeDetailPanel<T extends Record<string, unknown>>({ item, titleField, fields, onEdit, onDelete, title: titleProp, footer, children, }: NativeDetailPanelProps<T>): react.JSX.Element;
|
|
64
73
|
|
|
65
74
|
interface NativeResourceFormFieldRendererProps {
|
|
66
75
|
field: ResourceFormFieldDef;
|
|
@@ -119,4 +128,473 @@ interface NativeResourcePageProps<T extends BaseRecord = BaseRecord> {
|
|
|
119
128
|
}
|
|
120
129
|
declare function NativeResourcePage<T extends BaseRecord = BaseRecord>({ resource, resourceOptions, title, subtitle, cardFields, renderItem, searchFields, searchPlaceholder, statusFilter, onItemPress, titleField, onCreatePress, createLabel, headerRight, emptyState, offlineState, }: NativeResourcePageProps<T>): react.JSX.Element;
|
|
121
130
|
|
|
122
|
-
|
|
131
|
+
interface NativeResourceViewMessages {
|
|
132
|
+
common: {
|
|
133
|
+
/** Shown for an empty value. */
|
|
134
|
+
empty: string;
|
|
135
|
+
yes: string;
|
|
136
|
+
no: string;
|
|
137
|
+
cancel: string;
|
|
138
|
+
save: string;
|
|
139
|
+
edit: string;
|
|
140
|
+
close: string;
|
|
141
|
+
/** "New {noun}". */
|
|
142
|
+
create: string;
|
|
143
|
+
/** "Edit {noun}". */
|
|
144
|
+
editTitle: string;
|
|
145
|
+
/** "Search {nounPlural}". */
|
|
146
|
+
search: string;
|
|
147
|
+
};
|
|
148
|
+
delete: {
|
|
149
|
+
/** The action when a delete removes the row for good. */
|
|
150
|
+
action: string;
|
|
151
|
+
/** `{name}`: the row's title. */
|
|
152
|
+
confirmTitle: string;
|
|
153
|
+
confirmBody: string;
|
|
154
|
+
};
|
|
155
|
+
bin: {
|
|
156
|
+
/** The action when the provider moves deleted rows to a recycle bin (`softDelete`). */
|
|
157
|
+
action: string;
|
|
158
|
+
confirmTitle: string;
|
|
159
|
+
confirmBody: string;
|
|
160
|
+
};
|
|
161
|
+
list: {
|
|
162
|
+
/** `{nounPlural}`. */
|
|
163
|
+
emptyTitle: string;
|
|
164
|
+
emptyBody: string;
|
|
165
|
+
noResultsTitle: string;
|
|
166
|
+
noResultsBody: string;
|
|
167
|
+
loadingMore: string;
|
|
168
|
+
/** `{nounPlural}`. */
|
|
169
|
+
loadFailed: string;
|
|
170
|
+
retry: string;
|
|
171
|
+
/** A section for rows with no value in the group field. `{label}`: the field. */
|
|
172
|
+
noGroup: string;
|
|
173
|
+
};
|
|
174
|
+
form: {
|
|
175
|
+
/** `{label}`. */
|
|
176
|
+
required: string;
|
|
177
|
+
/** `{label}`, `{max}`. */
|
|
178
|
+
tooLong: string;
|
|
179
|
+
/** `{noun}`. A save failed with no message of its own. */
|
|
180
|
+
saveFailed: string;
|
|
181
|
+
/** An empty day field's button. */
|
|
182
|
+
pickDate: string;
|
|
183
|
+
/** An empty date-and-time field's button. */
|
|
184
|
+
pickDateTime: string;
|
|
185
|
+
/** Empties an optional date. `{label}`. */
|
|
186
|
+
clear: string;
|
|
187
|
+
loading: string;
|
|
188
|
+
};
|
|
189
|
+
refusal: {
|
|
190
|
+
/** `{noun}`. A delete failed with no message of its own. */
|
|
191
|
+
deleteFailed: string;
|
|
192
|
+
dismiss: string;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
declare const defaultNativeResourceViewMessages: NativeResourceViewMessages;
|
|
196
|
+
|
|
197
|
+
type Row$3 = Record<string, unknown>;
|
|
198
|
+
type AnyResourceView<T extends Row$3 = Row$3> = ResourceView<any, T & DataRow>;
|
|
199
|
+
/** What one row shows in a NativeListItem. */
|
|
200
|
+
interface NativeResourceRowItem {
|
|
201
|
+
id: string;
|
|
202
|
+
title: string;
|
|
203
|
+
/** `summary(row).subtitle`, the only subtitle: never a raw column. */
|
|
204
|
+
subtitle?: string;
|
|
205
|
+
chips: NonNullable<RowSummary["chips"]>;
|
|
206
|
+
/**
|
|
207
|
+
* `rowPicture(summary)`: an image (passed `isSafeUrl`, with initials to fall back to), initials,
|
|
208
|
+
* or null. On a phone only an http(s) image can load, so any other safe src (a root-relative
|
|
209
|
+
* path) draws its initials instead.
|
|
210
|
+
*/
|
|
211
|
+
picture: RowPicture | null;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* A row as NativeListItem draws it: `view.summary(row)`'s title, subtitle and chips, and nothing
|
|
215
|
+
* else. A view that wants a second line says so in its summary.
|
|
216
|
+
*/
|
|
217
|
+
declare function rowItem<T extends Row$3>(view: AnyResourceView<T>, row: T): NativeResourceRowItem;
|
|
218
|
+
interface NativeResourceSection<T> {
|
|
219
|
+
key: string;
|
|
220
|
+
/** Empty for the one section of an ungrouped view (no header is drawn). */
|
|
221
|
+
title: string;
|
|
222
|
+
data: T[];
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Rows in sections by `definition.groupBy`, in the order each group first appears (the server's
|
|
226
|
+
* sort, so paging never reorders what's on screen). Without `groupBy`, one untitled section.
|
|
227
|
+
*/
|
|
228
|
+
declare function sectionsFor<T extends Row$3>(view: AnyResourceView<T>, rows: readonly T[], messages: NativeResourceViewMessages): NativeResourceSection<T>[];
|
|
229
|
+
/** A row action: InboxPage's swipe action plus an icon name and, when a guard refuses it, why. */
|
|
230
|
+
interface NativeResourceSwipeAction extends InboxSwipeAction {
|
|
231
|
+
/** An icon name from Genesis's set (`edit`, `trash`), mapped per platform. */
|
|
232
|
+
icon?: string;
|
|
233
|
+
/** Set when a guard refuses the action: pressing it explains instead of acting. */
|
|
234
|
+
reason?: string;
|
|
235
|
+
}
|
|
236
|
+
/** A screen's own rule. It only narrows: `false` hides the action, a sentence shows it refused. */
|
|
237
|
+
type NativeResourceScreenCan<T> = (action: "create" | "update" | "delete", row?: T) => Allowed | boolean;
|
|
238
|
+
/**
|
|
239
|
+
* The effective right: the screen's rule AND the view's guard (never OR). The guard gets the
|
|
240
|
+
* viewer (`useViewer()`); without one it gets no one, so a guard that needs it refuses.
|
|
241
|
+
*/
|
|
242
|
+
declare function allowed<T extends Row$3>(view: AnyResourceView<T>, action: "create" | "update" | "delete", row: T | undefined, screen?: NativeResourceScreenCan<T>, viewer?: Viewer): Allowed | false;
|
|
243
|
+
interface SwipeActionOptions<T> {
|
|
244
|
+
messages: NativeResourceViewMessages;
|
|
245
|
+
/** The provider moves deleted rows to a recycle bin (`capabilities(resource).softDelete`). */
|
|
246
|
+
softDelete: boolean;
|
|
247
|
+
/** The view has fields a writer may change when editing. */
|
|
248
|
+
editable: boolean;
|
|
249
|
+
screen?: NativeResourceScreenCan<T>;
|
|
250
|
+
/** Who is looking (`useViewer()`), for the view's guards. */
|
|
251
|
+
viewer?: Viewer;
|
|
252
|
+
onEdit: (row: T) => void;
|
|
253
|
+
onDelete: (row: T) => void;
|
|
254
|
+
/** A refused action was pressed: say why. */
|
|
255
|
+
onRefused: (label: string, reason: string) => void;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* A row's swipe actions, from the view's guards. A refused action stays in the list with its
|
|
259
|
+
* reason, so the person learns why; one the screen turns off (`false`) is left out.
|
|
260
|
+
*/
|
|
261
|
+
declare function swipeActionsFor<T extends Row$3>(view: AnyResourceView<T>, row: T, options: SwipeActionOptions<T>): NativeResourceSwipeAction[];
|
|
262
|
+
/** How a form field is drawn. */
|
|
263
|
+
type NativeFormFieldKind = "text" | "email" | "url" | "number" | "textarea" | "switch" | "segmented" | "select" | "date" | "datetime";
|
|
264
|
+
interface NativeFormField {
|
|
265
|
+
key: string;
|
|
266
|
+
label: string;
|
|
267
|
+
kind: NativeFormFieldKind;
|
|
268
|
+
display: DisplayHint;
|
|
269
|
+
required: boolean;
|
|
270
|
+
/** Shown as text, never as an input, and never sent. */
|
|
271
|
+
readOnly: boolean;
|
|
272
|
+
max?: number;
|
|
273
|
+
options?: {
|
|
274
|
+
value: string;
|
|
275
|
+
label: string;
|
|
276
|
+
}[];
|
|
277
|
+
/** The heading it sits under; null for the form's first, untitled group. */
|
|
278
|
+
section: string | null;
|
|
279
|
+
sectionTitle: string | null;
|
|
280
|
+
visible?: (values: Readonly<Record<string, unknown>>) => boolean;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* The form sheet's fields: `view.form(mode)` (which already leaves out JSON, lists, links, scope,
|
|
284
|
+
* sensitive and unreadable fields and server-filled keys), each marked read-only unless
|
|
285
|
+
* `view.writable(mode)` lists it. Copied, never mutated: core caches and freezes `form()`. A create leaves read-only fields out (there is nothing to show yet); an edit shows
|
|
286
|
+
* them as text.
|
|
287
|
+
*/
|
|
288
|
+
declare function formFieldsFor<T extends Row$3>(view: AnyResourceView<T>, mode: "create" | "edit"): NativeFormField[];
|
|
289
|
+
/**
|
|
290
|
+
* What a save sends: only the keys `view.writable(mode)` lists and the form shows. Read-only,
|
|
291
|
+
* generated, key and scope fields, and anything else the values carry (joined columns), never go.
|
|
292
|
+
* An edit passes `dirty`, the fields the person changed, so a save never rewrites the rest. A
|
|
293
|
+
* cleared optional value (an empty text, a cleared number or date) is sent as null.
|
|
294
|
+
*/
|
|
295
|
+
declare function writableValues<T extends Row$3>(view: AnyResourceView<T>, mode: "create" | "edit", fields: readonly NativeFormField[], values: Readonly<Record<string, unknown>>, dirty?: ReadonlySet<string>): Record<string, unknown>;
|
|
296
|
+
/** Field errors for a save: required fields with no value, and text over `max`. */
|
|
297
|
+
declare function validateValues(fields: readonly NativeFormField[], values: Readonly<Record<string, unknown>>, messages: NativeResourceViewMessages): Record<string, string>;
|
|
298
|
+
|
|
299
|
+
type Row$2 = Record<string, unknown>;
|
|
300
|
+
type Filter = Readonly<Record<string, string | number | boolean | null>>;
|
|
301
|
+
/** How long typing waits before the search goes to the server. */
|
|
302
|
+
declare const SEARCH_DEBOUNCE_MS = 300;
|
|
303
|
+
interface NativeResourceViewOptions<T extends Row$2 = Row$2> {
|
|
304
|
+
/** A tab the view defines: its server filter. */
|
|
305
|
+
preset?: string;
|
|
306
|
+
/**
|
|
307
|
+
* Equality filters sent to the server (`{ client_id: id }`); `null` means "is empty". A create
|
|
308
|
+
* also saves every non-null value here (a tab's filter too), even for read-only fields such as
|
|
309
|
+
* a required link: they come from the screen, never from an input. An edit never sends them.
|
|
310
|
+
*/
|
|
311
|
+
filter?: Filter;
|
|
312
|
+
/** Rows per page. Default 25. */
|
|
313
|
+
perPage?: number;
|
|
314
|
+
/**
|
|
315
|
+
* Pages kept loaded when the provider pages by cursor (and serves `prevCursor`): scrolling far
|
|
316
|
+
* drops pages from the front, and scrolling back to the top loads them again (`loadPrevious` on
|
|
317
|
+
* the list's `onStartReached`, with `maintainVisibleContentPosition` so the rows on screen stay
|
|
318
|
+
* put). Offset paging never drops pages. Default 10.
|
|
319
|
+
*/
|
|
320
|
+
maxPages?: number;
|
|
321
|
+
/** Fields the search box searches. Default: the view's `labelField`. */
|
|
322
|
+
searchFields?: string[];
|
|
323
|
+
/** The screen's own rule. It only narrows the view's guards. */
|
|
324
|
+
can?: NativeResourceScreenCan<T>;
|
|
325
|
+
/** Refetch loaded pages when the provider reports a change. */
|
|
326
|
+
live?: boolean;
|
|
327
|
+
}
|
|
328
|
+
type SaveResult = {
|
|
329
|
+
ok: true;
|
|
330
|
+
} | {
|
|
331
|
+
ok: false;
|
|
332
|
+
message?: string;
|
|
333
|
+
fields: Record<string, string>;
|
|
334
|
+
};
|
|
335
|
+
interface UseNativeResourceViewReturn<T extends Row$2 = Row$2> {
|
|
336
|
+
rows: T[];
|
|
337
|
+
/** Rows in `groupBy` sections (one untitled section when the view doesn't group). */
|
|
338
|
+
sections: NativeResourceSection<T>[];
|
|
339
|
+
/** Rows matching the filters and search, when the provider counts them. */
|
|
340
|
+
total: number | undefined;
|
|
341
|
+
/** The first page is loading. */
|
|
342
|
+
loading: boolean;
|
|
343
|
+
/** The read failed: its message, in plain words. */
|
|
344
|
+
error: string | null;
|
|
345
|
+
refreshing: boolean;
|
|
346
|
+
refresh: () => Promise<void>;
|
|
347
|
+
/** Pass to the list's `onEndReached`: loads the next page by cursor. */
|
|
348
|
+
loadMore: () => void;
|
|
349
|
+
loadingMore: boolean;
|
|
350
|
+
hasMore: boolean;
|
|
351
|
+
/** Pass to the list's `onStartReached`: loads back a page `maxPages` dropped from the front. */
|
|
352
|
+
loadPrevious: () => void;
|
|
353
|
+
loadingPrevious: boolean;
|
|
354
|
+
hasPrevious: boolean;
|
|
355
|
+
/** What the search box shows (the server sees it 300 ms after the last keystroke). */
|
|
356
|
+
search: string;
|
|
357
|
+
setSearch: (text: string) => void;
|
|
358
|
+
/** The last refused write, in plain words, shown inline until dismissed or the next write. */
|
|
359
|
+
refusal: string | null;
|
|
360
|
+
dismissRefusal: () => void;
|
|
361
|
+
item: (row: T) => NativeResourceRowItem;
|
|
362
|
+
/** The row's swipe actions. Edit and delete call `onEdit` / `onDelete` you pass here. */
|
|
363
|
+
actions: (row: T, handlers: {
|
|
364
|
+
onEdit: (row: T) => void;
|
|
365
|
+
onDelete: (row: T) => void;
|
|
366
|
+
onRefused: (label: string, reason: string) => void;
|
|
367
|
+
}) => NativeResourceSwipeAction[];
|
|
368
|
+
/** Whether a new row may be created: true, or the guard's reason. False when the screen turns it off or there's no form. */
|
|
369
|
+
canCreate: Allowed | false;
|
|
370
|
+
/** The form sheet's fields. */
|
|
371
|
+
formFields: (mode: "create" | "edit") => NativeFormField[];
|
|
372
|
+
/**
|
|
373
|
+
* Check and save the form's values. Sends only writable keys, and for an edit only the `dirty`
|
|
374
|
+
* ones (all writable keys when `dirty` is left out). Stays pessimistic so the sheet can show
|
|
375
|
+
* refusals.
|
|
376
|
+
*/
|
|
377
|
+
save: (mode: "create" | "edit", values: Readonly<Record<string, unknown>>, row?: T, dirty?: ReadonlySet<string>) => Promise<SaveResult>;
|
|
378
|
+
/** Delete a row optimistically: it leaves the list at once and comes back if the server refuses. */
|
|
379
|
+
remove: (row: T) => void;
|
|
380
|
+
/** The provider bins deleted rows (they can be restored). */
|
|
381
|
+
softDelete: boolean;
|
|
382
|
+
}
|
|
383
|
+
/** The values a create takes from the screen: every non-null equality filter, the screen's over the tab's. */
|
|
384
|
+
declare function screenValues(...filters: (Filter | undefined)[]): Record<string, string | number | boolean>;
|
|
385
|
+
/** Pages kept loaded by default (cursor paging). */
|
|
386
|
+
declare const DEFAULT_MAX_PAGES = 10;
|
|
387
|
+
/**
|
|
388
|
+
* The server sort: the `groupBy` field first, so every page arrives in section order and a later
|
|
389
|
+
* page never lands in the middle of an earlier section; else the view's `orderBy`. (A second sort
|
|
390
|
+
* key within a group needs `useInfiniteResource` to take several sorts.)
|
|
391
|
+
*/
|
|
392
|
+
declare function serverSort<T extends Row$2>(view: AnyResourceView<T>): {
|
|
393
|
+
field: string;
|
|
394
|
+
order: "asc" | "desc";
|
|
395
|
+
} | undefined;
|
|
396
|
+
declare function useNativeResourceView<T extends Row$2 = Row$2>(view: AnyResourceView<T>, options?: NativeResourceViewOptions<T>): UseNativeResourceViewReturn<T>;
|
|
397
|
+
|
|
398
|
+
type Row$1 = Record<string, unknown>;
|
|
399
|
+
/** The gesture wrapper around a row, the same props as InboxPage's `swipeable` slot. */
|
|
400
|
+
type NativeResourceSwipeableProps = Omit<InboxPageSlotMap["swipeable"], "actions"> & {
|
|
401
|
+
actions: NativeResourceSwipeAction[];
|
|
402
|
+
};
|
|
403
|
+
interface NativeResourceViewProps<T extends Row$1 = Row$1> extends NativeResourceViewOptions<T> {
|
|
404
|
+
view: AnyResourceView<T>;
|
|
405
|
+
/** The heading above the list. Default the view's title; `false` when the navigation bar shows it. */
|
|
406
|
+
title?: string | false;
|
|
407
|
+
subtitle?: string;
|
|
408
|
+
/**
|
|
409
|
+
* A row was pressed: push its detail route (`router.push(\`/brands/${row.id}\`)`), so deep links
|
|
410
|
+
* and notification taps land on the same screen. Without it, a press opens a peek sheet.
|
|
411
|
+
*/
|
|
412
|
+
onRowPress?: (row: T) => void;
|
|
413
|
+
/** Wraps each row that has actions in a swipe gesture (e.g. gesture-handler's ReanimatedSwipeable). */
|
|
414
|
+
swipeable?: ComponentType<NativeResourceSwipeableProps>;
|
|
415
|
+
/** Above the list, under the search (a filter, a call to action). */
|
|
416
|
+
header?: ReactNode;
|
|
417
|
+
/** Replaces the empty state. */
|
|
418
|
+
emptyState?: ReactNode;
|
|
419
|
+
/** Hide the search box. Shown by default when the view has something to search. */
|
|
420
|
+
searchable?: boolean;
|
|
421
|
+
/**
|
|
422
|
+
* The practice's IANA zone, for columns with `timeZone: "practice"`. Timestamps otherwise read
|
|
423
|
+
* on the viewer's clock (ViewerScope's zone, else the device's).
|
|
424
|
+
*/
|
|
425
|
+
practiceTimeZone?: string;
|
|
426
|
+
testID?: string;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* A native list screen from a view:
|
|
430
|
+
*
|
|
431
|
+
* ```tsx
|
|
432
|
+
* <NativeResourceView view={brandsView} onRowPress={(b) => router.push(`/brands/${b.id}`)} />
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
declare function NativeResourceView<T extends Row$1 = Row$1>(props: NativeResourceViewProps<T>): react.JSX.Element;
|
|
436
|
+
|
|
437
|
+
type Values = Record<string, unknown>;
|
|
438
|
+
interface NativeResourceFormSheetProps {
|
|
439
|
+
open: boolean;
|
|
440
|
+
mode: "create" | "edit";
|
|
441
|
+
title: string;
|
|
442
|
+
fields: readonly NativeFormField[];
|
|
443
|
+
/** The row being edited (fetched by id), or a create's starting values. */
|
|
444
|
+
initial?: Values;
|
|
445
|
+
/** The record is still loading: a spinner instead of fields, and Save is off. */
|
|
446
|
+
loading?: boolean;
|
|
447
|
+
/** Which record the sheet holds; the form starts over when it (or `open`) changes. */
|
|
448
|
+
recordKey?: string;
|
|
449
|
+
onCancel: () => void;
|
|
450
|
+
/** Saves with the fields the person changed; the sheet closes on `{ ok: true }` and shows the refusal otherwise. */
|
|
451
|
+
onSave: (values: Values, dirty: ReadonlySet<string>) => Promise<SaveResult>;
|
|
452
|
+
testID?: string;
|
|
453
|
+
}
|
|
454
|
+
declare function NativeResourceFormSheet({ open, mode, title, fields, initial, loading, recordKey, onCancel, onSave, testID, }: NativeResourceFormSheetProps): react.JSX.Element;
|
|
455
|
+
|
|
456
|
+
/** The clocks a timestamp can be read on: the viewer's and the practice's (IANA names). */
|
|
457
|
+
interface DisplayTimeZones {
|
|
458
|
+
viewer: string;
|
|
459
|
+
practice: string;
|
|
460
|
+
}
|
|
461
|
+
/** What a renderer gets besides the value (as on the web, with native's messages and clocks). */
|
|
462
|
+
interface DisplayContext {
|
|
463
|
+
row: Record<string, unknown>;
|
|
464
|
+
column: ResolvedColumn<Record<string, unknown>>;
|
|
465
|
+
messages: NativeResourceViewMessages;
|
|
466
|
+
zones: DisplayTimeZones;
|
|
467
|
+
}
|
|
468
|
+
type DisplayRenderer = (value: unknown, context: DisplayContext) => ReactNode;
|
|
469
|
+
type DisplayRenderers = Readonly<Record<DisplayHint, DisplayRenderer>>;
|
|
470
|
+
/** A `YYYY-MM-DD` day as a local Date at midnight, from its parts (the picker's value). Null when it isn't a day. */
|
|
471
|
+
declare function dayToDate(value: unknown): Date | null;
|
|
472
|
+
/** A picked Date back to the `YYYY-MM-DD` day it shows, from its local parts (never `toISOString`). */
|
|
473
|
+
declare function dateToDay(date: Date): string;
|
|
474
|
+
/** A calendar day, the same day on every clock. */
|
|
475
|
+
declare function formatDay(value: unknown): string;
|
|
476
|
+
/** A column's clock: "viewer" (the default) and "practice" from `zones`, else a valid IANA name. */
|
|
477
|
+
declare function resolveZone(zone: string | undefined, zones: DisplayTimeZones): string;
|
|
478
|
+
/** A timestamp as the clock on the wall in `zone` shows it (core's `wallClock`), not the device's. */
|
|
479
|
+
declare function formatInstant(value: unknown, zone: string): string;
|
|
480
|
+
/** A link a row may open: http(s), mailto or tel that passes `isSafeUrl`. Root-relative paths mean nothing on a phone. */
|
|
481
|
+
declare function openableUrl(value: unknown): string | null;
|
|
482
|
+
/**
|
|
483
|
+
* One value as plain text, for the places that take a string (a row's subtitle, a section title,
|
|
484
|
+
* a read-only form row). Renderers use the same words.
|
|
485
|
+
*/
|
|
486
|
+
declare function displayText(hint: DisplayHint, value: unknown, messages: NativeResourceViewMessages,
|
|
487
|
+
/** The resolved IANA zone a timestamp is read on (`resolveZone`). Default: the device's. */
|
|
488
|
+
timeZone?: string): string;
|
|
489
|
+
/** Genesis's native renderers. Every one shows text it can't draw, never a broken row. */
|
|
490
|
+
declare const nativeDisplayRenderers: DisplayRenderers;
|
|
491
|
+
/** The clocks timestamps are read on below. NativeResourceView sets it from ViewerScope. */
|
|
492
|
+
declare const DisplayTimeZonesProvider: react.Provider<DisplayTimeZones | null>;
|
|
493
|
+
/** The clocks for timestamps: the nearest provider's, else the device's for both. */
|
|
494
|
+
declare function useDisplayTimeZones(): DisplayTimeZones;
|
|
495
|
+
/** Replace some of the renderers for everything below (nested providers build on each other). */
|
|
496
|
+
declare function DisplayRenderersProvider({ renderers, children, }: {
|
|
497
|
+
renderers: Partial<Record<DisplayHint, DisplayRenderer>>;
|
|
498
|
+
children: ReactNode;
|
|
499
|
+
}): react.JSX.Element;
|
|
500
|
+
/** The words NativeResourceView shows, for everything below. Pass a stable object. */
|
|
501
|
+
declare const NativeResourceViewMessagesProvider: react.Provider<NativeResourceViewMessages>;
|
|
502
|
+
declare function useNativeResourceViewMessages(): NativeResourceViewMessages;
|
|
503
|
+
/** Draw one value: the empty mark for no value or a value the row (or viewer) hides (`when`), else its hint's renderer. */
|
|
504
|
+
declare function useDisplayCell(): (column: ResolvedColumn<Record<string, unknown>>, row: Record<string, unknown>) => ReactNode;
|
|
505
|
+
|
|
506
|
+
type Row = Record<string, unknown>;
|
|
507
|
+
type AnyWorkspace<T extends Row> = ResourceWorkspace<ResourceContract<any>, T & DataRow>;
|
|
508
|
+
/**
|
|
509
|
+
* The words NativeResourceWorkspace shows. Override any of them with `messages`. The readiness
|
|
510
|
+
* chip's keys (`ready`, `empty`, `pending`, `problems`, `warnings`) are genesis-core/resource's
|
|
511
|
+
* `readinessChip` labels: unset, they use its defaults.
|
|
512
|
+
*/
|
|
513
|
+
interface NativeResourceWorkspaceMessages extends ReadinessLabels {
|
|
514
|
+
actions: string;
|
|
515
|
+
cancel: string;
|
|
516
|
+
save: string;
|
|
517
|
+
/** `{noun}`: the record's noun. When a save changed no rows. */
|
|
518
|
+
notChanged: string;
|
|
519
|
+
failed: string;
|
|
520
|
+
/** `{name}`: the action. When the provider can't run actions and the screen gave no `onAction`. */
|
|
521
|
+
noRunner: string;
|
|
522
|
+
checks: string;
|
|
523
|
+
checkDone: string;
|
|
524
|
+
checkTodo: string;
|
|
525
|
+
/** The back row of a section opened from the list of sections. */
|
|
526
|
+
allSections: string;
|
|
527
|
+
notANumber: string;
|
|
528
|
+
}
|
|
529
|
+
declare const defaultNativeResourceWorkspaceMessages: NativeResourceWorkspaceMessages;
|
|
530
|
+
/** Up to this many sections show as a segmented control; more are pushed rows. */
|
|
531
|
+
declare const SEGMENTED_SECTIONS_MAX = 4;
|
|
532
|
+
interface NativeResourceWorkspaceHeaderProps<T extends Row = Row> {
|
|
533
|
+
workspace: AnyWorkspace<T>;
|
|
534
|
+
row: T;
|
|
535
|
+
/** Runs an allowed (and confirmed) action. Default: the provider's `runAction`. */
|
|
536
|
+
onAction?: (name: string, row: T) => unknown;
|
|
537
|
+
/** The screen's own rule: `false` hides an action, a sentence refuses it. Only narrows. */
|
|
538
|
+
can?: (action: string, row: T) => Allowed | boolean;
|
|
539
|
+
messages?: Partial<NativeResourceWorkspaceMessages>;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* The header menu: a button that lists the workspace's actions. On iOS an action sheet
|
|
543
|
+
* (ActionSheetIOS, destructive ones in red); elsewhere a sheet of rows, since Android's alert
|
|
544
|
+
* shows at most three buttons. A refused action stays listed and explains why when pressed.
|
|
545
|
+
*/
|
|
546
|
+
declare function NativeResourceWorkspaceMenu<T extends Row = Row>(props: NativeResourceWorkspaceHeaderProps<T> & {
|
|
547
|
+
testID?: string;
|
|
548
|
+
}): react.JSX.Element | null;
|
|
549
|
+
/**
|
|
550
|
+
* `<Stack.Screen options>` for a workspace: the record's title in the navigation bar and the
|
|
551
|
+
* actions in the header menu.
|
|
552
|
+
*
|
|
553
|
+
* ```tsx
|
|
554
|
+
* <Stack.Screen options={getNativeResourceWorkspaceStackOptions({ workspace: brandWorkspace, row: brand })} />
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
declare function getNativeResourceWorkspaceStackOptions<T extends Row>(props: NativeResourceWorkspaceHeaderProps<T> & Omit<ScreenHeaderProps, "headerTitle">): Record<string, unknown>;
|
|
558
|
+
interface NativeResourceWorkspaceProps<T extends Row = Row> {
|
|
559
|
+
workspace: AnyWorkspace<T>;
|
|
560
|
+
/** The record, as the screen loaded it. A save refreshes it through the cache. */
|
|
561
|
+
row: T;
|
|
562
|
+
/**
|
|
563
|
+
* The section to show. With up to four sections, the segmented control's value (default the
|
|
564
|
+
* first). With more, the pushed section; without it, the list of sections.
|
|
565
|
+
*/
|
|
566
|
+
section?: string;
|
|
567
|
+
/** The segmented control changed section. */
|
|
568
|
+
onSectionChange?: (id: string) => void;
|
|
569
|
+
/**
|
|
570
|
+
* With more than four sections: push that section's route (the pushed screen passes `section`).
|
|
571
|
+
* Without it, the section opens in place with an "All sections" row to go back.
|
|
572
|
+
*/
|
|
573
|
+
onOpenSection?: (id: string) => void;
|
|
574
|
+
/** After a settings section saved, with the stored row. */
|
|
575
|
+
onSaved?: (row: T) => void;
|
|
576
|
+
/** Above the sections: a switcher between records. */
|
|
577
|
+
switcher?: ReactNode;
|
|
578
|
+
/** The screen's own sections, by id. */
|
|
579
|
+
slots?: Partial<Record<string, ReactNode>>;
|
|
580
|
+
/** More props for a list section's NativeResourceView, by section id. */
|
|
581
|
+
lists?: Partial<Record<string, Partial<Omit<NativeResourceViewProps, "view" | "filter">>>>;
|
|
582
|
+
messages?: Partial<NativeResourceWorkspaceMessages>;
|
|
583
|
+
testID?: string;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* One record's screen from a workspace:
|
|
587
|
+
*
|
|
588
|
+
* ```tsx
|
|
589
|
+
* <Stack.Screen options={getNativeResourceWorkspaceStackOptions({ workspace: brandWorkspace, row: brand })} />
|
|
590
|
+
* <NativeResourceWorkspace workspace={brandWorkspace} row={brand} />
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
593
|
+
declare function NativeResourceWorkspace<T extends Row = Row>(props: NativeResourceWorkspaceProps<T>): react.JSX.Element;
|
|
594
|
+
/**
|
|
595
|
+
* A number as typed: "1.5" or, with a comma as the decimal mark, "1,5". Anything else (an empty
|
|
596
|
+
* string aside) is an error, never NaN.
|
|
597
|
+
*/
|
|
598
|
+
declare function parseSettingNumber(text: string): number | null;
|
|
599
|
+
|
|
600
|
+
export { type AnyResourceView, DEFAULT_MAX_PAGES, type DisplayContext, type DisplayRenderer, type DisplayRenderers, DisplayRenderersProvider, type DisplayTimeZones, DisplayTimeZonesProvider, type NativeCardFieldDef, NativeDataFilters, type NativeDataFiltersProps, NativeDataPageShell, type NativeDataPageShellProps, type NativeDetailField, NativeDetailPanel, type NativeDetailPanelProps, NativeEmptyState, type NativeEmptyStateProps, type NativeFormField, type NativeFormFieldKind, NativeResourceForm, NativeResourceFormFieldRenderer, type NativeResourceFormFieldRendererProps, type NativeResourceFormProps, NativeResourceFormSheet, type NativeResourceFormSheetProps, NativeResourcePage, type NativeResourcePageProps, type NativeResourceRowItem, type NativeResourceScreenCan, type NativeResourceSection, type NativeResourceSwipeAction, type NativeResourceSwipeableProps, NativeResourceView, type NativeResourceViewMessages, NativeResourceViewMessagesProvider, type NativeResourceViewOptions, type NativeResourceViewProps, NativeResourceWorkspace, type NativeResourceWorkspaceHeaderProps, NativeResourceWorkspaceMenu, type NativeResourceWorkspaceMessages, type NativeResourceWorkspaceProps, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, type SaveResult, type UseNativeResourceViewReturn, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
|