@marktiderman/genesis-ui-native 3.3.0 → 3.5.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.
Files changed (31) hide show
  1. package/README.md +24 -0
  2. package/dist/{chunk-VZ3PQLZ4.js → chunk-ABVSSJNT.js} +3 -3
  3. package/dist/{chunk-VZ3PQLZ4.js.map → chunk-ABVSSJNT.js.map} +1 -1
  4. package/dist/{chunk-ZHVQTMNV.js → chunk-ONH2PCGH.js} +7 -4
  5. package/dist/chunk-ONH2PCGH.js.map +1 -0
  6. package/dist/data/index.d.ts +104 -7
  7. package/dist/data/index.js +407 -79
  8. package/dist/data/index.js.map +1 -1
  9. package/dist/{inbox-page-DZUR-PJ1.d.ts → inbox-page-BEarNEIP.d.ts} +11 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.js +2 -2
  12. package/dist/layouts/index.d.ts +2 -2
  13. package/dist/layouts/index.js +2 -2
  14. package/package.json +3 -3
  15. package/src/data/NativeResourceFormField.tsx +12 -3
  16. package/src/data/resource-view/NativeLinkPicker.tsx +191 -0
  17. package/src/data/resource-view/NativeRecordView.tsx +15 -5
  18. package/src/data/resource-view/NativeResourceFormSheet.tsx +25 -1
  19. package/src/data/resource-view/NativeResourceView.tsx +296 -50
  20. package/src/data/resource-view/__tests__/native-link-picker.test.tsx +201 -0
  21. package/src/data/resource-view/__tests__/native-record-view.test.tsx +11 -0
  22. package/src/data/resource-view/__tests__/native-resource-view-delete.test.tsx +171 -0
  23. package/src/data/resource-view/__tests__/native-resource-view.test.tsx +226 -2
  24. package/src/data/resource-view/__tests__/native-tel-field.test.tsx +79 -0
  25. package/src/data/resource-view/index.ts +8 -1
  26. package/src/data/resource-view/mapping.ts +60 -7
  27. package/src/data/resource-view/messages.ts +25 -0
  28. package/src/data/resource-view/use-native-resource-view.ts +62 -13
  29. package/src/layouts/__tests__/screen-container.test.tsx +51 -2
  30. package/src/layouts/screen-container.tsx +20 -1
  31. package/dist/chunk-ZHVQTMNV.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { NativeImage, NativeAvatar, NativeCard, NativeCardContent, NativeSeparator, NativeLabel, NativeSwitch, NativeCheckbox, NativeSelect, NativeSelectTrigger, NativeSelectContent, NativeSelectItem, NativeTextarea, NativeAlert, NativeAlertTitle, NativeAlertDescription, NativeSheet, NativeSheetScrollView, NativeInlineAlert, NativeSegmentedControl, NativeDatePicker, NativeTimePicker, NativeSearchBar, NativeSkeleton, NativeCardHeader, NativeCardTitle } from '../chunk-GHYUNNNU.js';
2
2
  import '../chunk-7PCWEY6R.js';
3
- import { showInboxActions, NavBarSaveButton, composeHeaderOptions } from '../chunk-ZHVQTMNV.js';
3
+ import { showInboxActions, NavBarSaveButton, composeHeaderOptions } from '../chunk-ONH2PCGH.js';
4
4
  import { NativeListItem, NativeBadge, NativeText, NativeButton, NativeInput, useGenesisModules, NativeLoadingState, NativeSectionListHeader, NativeEmptyState, NativeRefreshControl, NativeIcon } from '../chunk-6KWEAGRD.js';
5
5
  import { useThemeRoles } from '../chunk-Z3AQYVUA.js';
6
6
  import '../chunk-OHZD7KRO.js';
@@ -8,14 +8,14 @@ import '../chunk-DGUM43GV.js';
8
8
  import { Platform, View, Pressable, Text, Linking, ScrollView, Alert, SectionList, ActionSheetIOS, FlatList } from 'react-native';
9
9
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
10
10
  import * as React from 'react';
11
- import { createContext, memo, useState, useCallback, useMemo, useEffect, useContext, useRef } from 'react';
11
+ import { createContext, memo, useState, useCallback, useMemo, useEffect, useContext, useRef, useLayoutEffect } from 'react';
12
12
  import { SafeAreaView } from 'react-native-safe-area-context';
13
- import { titleCase, useResourceForm, resourceKeys, useDataProvider, useViewer as useViewer$1, encodeRecordKey, useCapabilities as useCapabilities$1, DataWriteError } from '@marktiderman/genesis-core';
13
+ import { encodeRecordKey, titleCase, useResourceForm, resourceKeys, useDataProvider, useViewer as useViewer$1, useCapabilities as useCapabilities$1, DataWriteError } from '@marktiderman/genesis-core';
14
14
  import { Controller, useForm } from 'react-hook-form';
15
- import { useRelationLabel, useResource, useViewer, useInfiniteResource, useCapabilities, useOptionalViewerScope, scopeClock, useOne } from '@marktiderman/genesis-core/hooks';
15
+ import { useRelationLabel, useResource, useViewer, useInfiniteResource, useCapabilities, useOptionalViewerScope, scopeClock, useOne, useLinkOptions } from '@marktiderman/genesis-core/hooks';
16
16
  import { personTimeZone, isTimeZone, wallClock } from '@marktiderman/genesis-core/dates';
17
17
  import { isSafeUrl } from '@marktiderman/genesis-core/urls';
18
- import { valueText, rowPicture } from '@marktiderman/genesis-core/resource-view';
18
+ import { valueText, sameFormValue, rowPicture, filterParams as filterParams$1 } from '@marktiderman/genesis-core/resource-view';
19
19
  import { useQueryClient, useQuery } from '@tanstack/react-query';
20
20
  import { readinessChip } from '@marktiderman/genesis-core/resource';
21
21
 
@@ -235,12 +235,14 @@ function NativeDetailPanel({
235
235
  var KEYBOARD_TYPE_MAP = {
236
236
  email: "email-address",
237
237
  url: "url",
238
+ tel: "phone-pad",
238
239
  text: "default",
239
240
  date: "default"
240
241
  };
241
242
  var AUTO_CAPITALIZE_MAP = {
242
243
  email: "none",
243
244
  url: "none",
245
+ tel: "none",
244
246
  text: "sentences",
245
247
  date: "none"
246
248
  };
@@ -392,6 +394,9 @@ function NativeResourceFormFieldRenderer({
392
394
  placeholder: field.placeholder,
393
395
  keyboardType: KEYBOARD_TYPE_MAP[fieldType] ?? "default",
394
396
  autoCapitalize: AUTO_CAPITALIZE_MAP[fieldType] ?? "sentences",
397
+ ...field.autoComplete ? { autoComplete: field.autoComplete } : {},
398
+ ...field.inputMode ? { inputMode: field.inputMode } : {},
399
+ ...field.enterKeyHint ? { enterKeyHint: field.enterKeyHint } : {},
395
400
  value: f.value != null ? String(f.value) : "",
396
401
  onChangeText: f.onChange,
397
402
  editable: !isDisabled,
@@ -844,6 +849,15 @@ var defaultNativeResourceViewMessages = {
844
849
  clear: "Clear {label}",
845
850
  loading: "Loading"
846
851
  },
852
+ link: {
853
+ placeholder: "Choose\u2026",
854
+ search: "Search",
855
+ none: "None",
856
+ noResults: "No matches",
857
+ loadMore: "Show more",
858
+ loadFailed: "Couldn't load the choices.",
859
+ untitled: "Untitled"
860
+ },
847
861
  refusal: {
848
862
  deleteFailed: "This {noun} couldn't be deleted. Try again.",
849
863
  dismiss: "Dismiss"
@@ -1087,8 +1101,9 @@ function swipeActionsFor(view, row, options) {
1087
1101
  return actions;
1088
1102
  }
1089
1103
  var SEGMENTED_MAX = 4;
1090
- function kindFor(display, options) {
1104
+ function kindFor(display, options, widget) {
1091
1105
  if (options) return options.length <= SEGMENTED_MAX ? "segmented" : "select";
1106
+ if (widget === "tel" && display === "text") return "tel";
1092
1107
  switch (display) {
1093
1108
  case "boolean":
1094
1109
  return "switch";
@@ -1111,23 +1126,43 @@ function kindFor(display, options) {
1111
1126
  return "text";
1112
1127
  }
1113
1128
  }
1114
- function formFieldsFor(view, mode) {
1115
- const writable = new Set(view.writable(mode));
1129
+ function heldTo(link, keys) {
1130
+ if (!keys) return link;
1131
+ const held = { field: link.field, operator: "in", value: [...keys] };
1132
+ return Object.freeze({
1133
+ resource: link.resource,
1134
+ field: link.field,
1135
+ get labelField() {
1136
+ return link.labelField;
1137
+ },
1138
+ ...link.searchFields ? { searchFields: link.searchFields } : {},
1139
+ filters: (scope, values) => [...link.filters(scope, values), held]
1140
+ });
1141
+ }
1142
+ function formFieldsFor(view, mode, options = {}) {
1143
+ const pinned = new Set(options.pinned ?? []);
1144
+ const within = options.within ?? {};
1145
+ const writable = new Set([...view.writable(mode)].filter((name) => !(pinned.has(name) && view.field(name)?.references)));
1116
1146
  return view.form(mode).filter((f) => f.display !== "json" && !f.field.array).filter((f) => mode === "edit" || writable.has(f.field.name)).map((f) => {
1117
- const options = f.options?.map((o) => ({ value: o.value, label: o.label }));
1147
+ const options2 = f.options?.map((o) => ({ value: o.value, label: o.label }));
1118
1148
  const readOnly = !writable.has(f.field.name);
1149
+ const link = !readOnly && !options2 && f.link ? heldTo(f.link, Object.hasOwn(within, f.field.name) ? within[f.field.name] : void 0) : void 0;
1119
1150
  return {
1120
1151
  key: f.field.name,
1121
1152
  label: f.label,
1122
- kind: kindFor(f.display, options),
1153
+ kind: link ? "link" : kindFor(f.display, options2, f.field.widget),
1123
1154
  display: f.display,
1124
1155
  required: !readOnly && f.required,
1125
1156
  readOnly,
1126
1157
  ...typeof f.field.nullable === "boolean" ? { nullable: f.field.nullable } : {},
1127
1158
  ...f.field.hasDefault || f.field.generated ? { hasDefault: true } : {},
1128
1159
  ...f.max !== void 0 ? { max: f.max } : {},
1129
- ...options ? { options } : {},
1160
+ ...f.autoComplete ? { autoComplete: f.autoComplete } : {},
1161
+ ...f.inputMode ? { inputMode: f.inputMode } : {},
1162
+ ...f.enterKeyHint ? { enterKeyHint: f.enterKeyHint } : {},
1163
+ ...options2 ? { options: options2 } : {},
1130
1164
  ...f.field.references ? { references: f.field.references } : {},
1165
+ ...link ? { link } : {},
1131
1166
  ...f.labelField ? { labelField: f.labelField } : {},
1132
1167
  ...f.missingLabel ? { missingLabel: f.missingLabel } : {},
1133
1168
  section: f.section,
@@ -1181,9 +1216,131 @@ function refusalFields(error) {
1181
1216
  }
1182
1217
  return {};
1183
1218
  }
1219
+ var SEARCH_DEBOUNCE_MS = 300;
1220
+ function NativeLinkPicker({ field, value, onChange, values, error, testID }) {
1221
+ const messages = useNativeResourceViewMessages();
1222
+ const words = { ...defaultNativeResourceViewMessages.link, ...messages.link };
1223
+ const link = field.link;
1224
+ const viewer = useViewer();
1225
+ const [open, setOpen] = useState(false);
1226
+ const [query, setQuery] = useState("");
1227
+ const [search, setSearch] = useState("");
1228
+ useEffect(() => {
1229
+ const timer = setTimeout(() => setSearch(query), SEARCH_DEBOUNCE_MS);
1230
+ return () => clearTimeout(timer);
1231
+ }, [query]);
1232
+ const filtersKey = JSON.stringify(link.filters(viewer.scope, values));
1233
+ const filters = useMemo(() => JSON.parse(filtersKey), [filtersKey]);
1234
+ const labelField = field.labelField ?? link.labelField;
1235
+ const list = useLinkOptions(
1236
+ { resource: link.resource, field: link.field, labelField, searchFields: link.searchFields },
1237
+ { filters, search, enabled: open, untitled: words.untitled }
1238
+ );
1239
+ const loaded = isEmptyValue(value) ? void 0 : list.options.find((o) => String(o.value) === String(value));
1240
+ const looked = useRelationLabel({ resource: link.resource, field: link.field }, value, {
1241
+ ...list.labelField ?? labelField ? { labelField: list.labelField ?? labelField } : {},
1242
+ enabled: !isEmptyValue(value) && !loaded
1243
+ });
1244
+ const chosen = isEmptyValue(value) ? null : loaded?.label ?? (looked === void 0 ? void 0 : looked ?? field.missingLabel ?? messages.common.hiddenLink ?? defaultNativeResourceViewMessages.common.hiddenLink);
1245
+ const shown = chosen === void 0 ? messages.common.empty : chosen ?? words.placeholder;
1246
+ const pick = (next) => {
1247
+ onChange(next);
1248
+ setOpen(false);
1249
+ setQuery("");
1250
+ };
1251
+ return /* @__PURE__ */ jsxs(View, { testID, style: { gap: 6 }, children: [
1252
+ /* @__PURE__ */ jsx(NativeLabel, { children: field.label }),
1253
+ /* @__PURE__ */ jsxs(
1254
+ Pressable,
1255
+ {
1256
+ testID: `${testID}-trigger`,
1257
+ accessibilityRole: "button",
1258
+ accessibilityLabel: error ? `${field.label}, ${shown}, ${error}` : `${field.label}, ${shown}`,
1259
+ accessibilityState: { expanded: open },
1260
+ onPress: () => setOpen((was) => !was),
1261
+ className: "min-h-[44px] flex-row items-center justify-between rounded-md border border-input bg-background px-3",
1262
+ children: [
1263
+ /* @__PURE__ */ jsx(Text, { className: chosen ? "text-base text-foreground" : "text-base text-muted-foreground", numberOfLines: 1, children: shown }),
1264
+ /* @__PURE__ */ jsx(Text, { className: "text-muted-foreground", accessible: false, children: open ? "\u25B4" : "\u25BE" })
1265
+ ]
1266
+ }
1267
+ ),
1268
+ open ? /* @__PURE__ */ jsxs(View, { testID: `${testID}-list`, style: { gap: 4 }, accessibilityRole: "radiogroup", accessibilityLabel: field.label, children: [
1269
+ list.searchable ? /* @__PURE__ */ jsx(
1270
+ NativeSearchBar,
1271
+ {
1272
+ testID: `${testID}-search`,
1273
+ value: query,
1274
+ onChange: setQuery,
1275
+ placeholder: words.search,
1276
+ showCancel: false
1277
+ }
1278
+ ) : null,
1279
+ !field.required && query === "" ? /* @__PURE__ */ jsx(
1280
+ Option,
1281
+ {
1282
+ testID: `${testID}-none`,
1283
+ label: words.none,
1284
+ muted: true,
1285
+ selected: isEmptyValue(value),
1286
+ onPress: () => pick(null)
1287
+ }
1288
+ ) : null,
1289
+ list.isLoading ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "px-3 py-2 text-muted-foreground", testID: `${testID}-loading`, children: messages.form.loading }) : list.isError ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "px-3 py-2 text-destructive", accessibilityRole: "alert", children: words.loadFailed }) : list.options.length === 0 ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "px-3 py-2 text-muted-foreground", testID: `${testID}-empty`, children: words.noResults }) : list.options.map((option) => /* @__PURE__ */ jsx(
1290
+ Option,
1291
+ {
1292
+ testID: `${testID}-option-${String(option.value)}`,
1293
+ label: option.label,
1294
+ selected: !isEmptyValue(value) && String(value) === String(option.value),
1295
+ onPress: () => pick(option.value)
1296
+ },
1297
+ String(option.value)
1298
+ )),
1299
+ list.hasMore ? /* @__PURE__ */ jsx(
1300
+ NativeButton,
1301
+ {
1302
+ variant: "ghost",
1303
+ size: "sm",
1304
+ testID: `${testID}-more`,
1305
+ disabled: list.isLoadingMore,
1306
+ onPress: list.loadMore,
1307
+ children: list.isLoadingMore ? messages.list.loadingMore : words.loadMore
1308
+ }
1309
+ ) : null
1310
+ ] }) : null,
1311
+ error ? (
1312
+ // A live region on Android; the alert role on iOS and the web.
1313
+ /* @__PURE__ */ jsx(View, { accessibilityLiveRegion: "polite", children: /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-destructive", testID: `${testID}-error`, accessibilityRole: "alert", children: error }) })
1314
+ ) : null
1315
+ ] });
1316
+ }
1317
+ function Option({
1318
+ label,
1319
+ selected,
1320
+ muted = false,
1321
+ onPress,
1322
+ testID
1323
+ }) {
1324
+ return /* @__PURE__ */ jsxs(
1325
+ Pressable,
1326
+ {
1327
+ testID,
1328
+ accessibilityRole: "radio",
1329
+ accessibilityLabel: label,
1330
+ accessibilityState: { checked: selected },
1331
+ onPress,
1332
+ className: "min-h-[44px] flex-row items-center justify-between px-3",
1333
+ children: [
1334
+ /* @__PURE__ */ jsx(Text, { className: muted ? "text-base text-muted-foreground" : "text-base text-foreground", children: label }),
1335
+ selected ? /* @__PURE__ */ jsx(Text, { className: "text-base text-primary", accessible: false, children: "\u2713" }) : null
1336
+ ]
1337
+ }
1338
+ );
1339
+ }
1184
1340
  var FIELD_TYPE = {
1185
1341
  text: "text",
1186
1342
  email: "email",
1343
+ tel: "tel",
1187
1344
  url: "url",
1188
1345
  number: "number",
1189
1346
  textarea: "textarea",
@@ -1322,6 +1479,26 @@ function FormField({
1322
1479
  /* @__PURE__ */ jsx(NativeText, { testID: `${id}-value`, preset: "body", className: "text-muted-foreground", children: shown })
1323
1480
  ] });
1324
1481
  }
1482
+ if (field.kind === "link" && field.link) {
1483
+ return /* @__PURE__ */ jsx(
1484
+ Controller,
1485
+ {
1486
+ name: field.key,
1487
+ control: f.control,
1488
+ render: ({ field: input }) => /* @__PURE__ */ jsx(
1489
+ NativeLinkPicker,
1490
+ {
1491
+ field,
1492
+ value: input.value,
1493
+ onChange: input.onChange,
1494
+ values: f.getValues(),
1495
+ error,
1496
+ testID: id
1497
+ }
1498
+ )
1499
+ }
1500
+ );
1501
+ }
1325
1502
  const type = FIELD_TYPE[field.kind];
1326
1503
  if (type) {
1327
1504
  const def = {
@@ -1330,7 +1507,10 @@ function FormField({
1330
1507
  type,
1331
1508
  required: field.required,
1332
1509
  ...field.options ? { options: field.options } : {},
1333
- ...field.max !== void 0 ? { maxLength: field.max } : {}
1510
+ ...field.max !== void 0 ? { maxLength: field.max } : {},
1511
+ ...field.autoComplete ? { autoComplete: field.autoComplete } : {},
1512
+ ...field.inputMode ? { inputMode: field.inputMode } : {},
1513
+ ...field.enterKeyHint ? { enterKeyHint: field.enterKeyHint } : {}
1334
1514
  };
1335
1515
  return /* @__PURE__ */ jsx(View, { testID: id, children: /* @__PURE__ */ jsx(NativeResourceFormFieldRenderer, { field: def, control: f.control, action: m }) });
1336
1516
  }
@@ -1394,11 +1574,16 @@ function DateField({
1394
1574
  clearable ? /* @__PURE__ */ jsx(NativeButton, { variant: "ghost", size: "sm", testID: `${testID}-clear`, onPress: () => onChange(null), children: fill(messages.form.clear, { label: label.toLowerCase() }) }) : null
1395
1575
  ] });
1396
1576
  }
1397
- var SEARCH_DEBOUNCE_MS = 300;
1577
+ var recordKey = (view, row) => {
1578
+ try {
1579
+ return String(encodeRecordKey(view.contract, row));
1580
+ } catch {
1581
+ return String(row.id);
1582
+ }
1583
+ };
1584
+ var SEARCH_DEBOUNCE_MS2 = 300;
1398
1585
  function filterParams(filter) {
1399
- return Object.entries(filter ?? {}).map(
1400
- ([field, value]) => value === null ? { field, operator: "is_null" } : Array.isArray(value) ? { field, operator: "in", value: [...value] } : { field, operator: "eq", value }
1401
- );
1586
+ return filterParams$1(filter);
1402
1587
  }
1403
1588
  function screenValues(...filters) {
1404
1589
  const out = {};
@@ -1409,6 +1594,16 @@ function screenValues(...filters) {
1409
1594
  }
1410
1595
  return out;
1411
1596
  }
1597
+ function screenLists(...filters) {
1598
+ const out = {};
1599
+ for (const filter of filters) {
1600
+ for (const [field, value] of Object.entries(filter ?? {})) {
1601
+ if (Array.isArray(value)) out[field] = [...value];
1602
+ else delete out[field];
1603
+ }
1604
+ }
1605
+ return out;
1606
+ }
1412
1607
  var DEFAULT_MAX_PAGES = 10;
1413
1608
  function serverSorts(view) {
1414
1609
  const groupBy = view.definition.groupBy;
@@ -1434,6 +1629,8 @@ function useNativeResourceView(view, options = {}) {
1434
1629
  );
1435
1630
  const createKey = JSON.stringify(screenValues(tabFilter, filter));
1436
1631
  const createDefaults = useMemo(() => JSON.parse(createKey), [createKey]);
1632
+ const listKey = JSON.stringify(screenLists(tabFilter, filter));
1633
+ const within = useMemo(() => JSON.parse(listKey), [listKey]);
1437
1634
  const sorts = useMemo(() => serverSorts(view), [view]);
1438
1635
  const searchFields = useMemo(
1439
1636
  () => searchOption ?? (view.labelField ? [view.labelField] : void 0),
@@ -1455,7 +1652,7 @@ function useNativeResourceView(view, options = {}) {
1455
1652
  (text2) => {
1456
1653
  setSearchText(text2);
1457
1654
  if (timer.current) clearTimeout(timer.current);
1458
- timer.current = setTimeout(() => sendSearch(text2), SEARCH_DEBOUNCE_MS);
1655
+ timer.current = setTimeout(() => sendSearch(text2), SEARCH_DEBOUNCE_MS2);
1459
1656
  },
1460
1657
  [sendSearch]
1461
1658
  );
@@ -1475,8 +1672,8 @@ function useNativeResourceView(view, options = {}) {
1475
1672
  const capabilities = useCapabilities(view.resource);
1476
1673
  const softDelete = capabilities.data?.softDelete === true;
1477
1674
  const formFields = useCallback(
1478
- (mode) => mode === "create" ? formFieldsFor(view, "create").filter((f) => !(f.key in createDefaults)) : formFieldsFor(view, "edit"),
1479
- [view, createDefaults]
1675
+ (mode) => mode === "create" ? formFieldsFor(view, "create", { within }).filter((f) => !(f.key in createDefaults)) : formFieldsFor(view, "edit", { pinned: Object.keys(createDefaults), within }),
1676
+ [view, createDefaults, within]
1480
1677
  );
1481
1678
  const editable = useMemo(() => formFieldsFor(view, "edit").some((f) => !f.readOnly), [view]);
1482
1679
  const viewer = useViewer();
@@ -1521,6 +1718,23 @@ function useNativeResourceView(view, options = {}) {
1521
1718
  [view, messages, softDelete, editable, can, viewer]
1522
1719
  );
1523
1720
  const sections = useMemo(() => sectionsFor(view, pages.rows, messages), [view, pages.rows, messages]);
1721
+ const loaded = useRef({ keys: [], offset: 0 });
1722
+ const hasPrevious = pages.hasPreviousPage;
1723
+ const snapshot = useMemo(() => {
1724
+ const keys = pages.rows.map((row) => recordKey(view, row));
1725
+ const last = loaded.current;
1726
+ let offset = 0;
1727
+ if (hasPrevious && keys.length > 0 && last.keys.length > 0) {
1728
+ const back = keys.indexOf(last.keys[0]);
1729
+ const dropped = last.keys.indexOf(keys[0]);
1730
+ offset = back >= 0 ? last.offset - back : dropped >= 0 ? last.offset + dropped : last.offset;
1731
+ }
1732
+ return { keys, offset: Math.max(0, offset) };
1733
+ }, [view, pages.rows, hasPrevious]);
1734
+ useLayoutEffect(() => {
1735
+ loaded.current = snapshot;
1736
+ }, [snapshot]);
1737
+ const rowOffset = snapshot.offset;
1524
1738
  const { query } = pages;
1525
1739
  const [refreshing, setRefreshing] = useState(false);
1526
1740
  const refresh = useCallback(async () => {
@@ -1545,7 +1759,8 @@ function useNativeResourceView(view, options = {}) {
1545
1759
  hasMore: pages.hasNextPage,
1546
1760
  loadPrevious: pages.fetchPreviousPage,
1547
1761
  loadingPrevious: query.isFetchingPreviousPage,
1548
- hasPrevious: pages.hasPreviousPage,
1762
+ hasPrevious,
1763
+ rowOffset,
1549
1764
  search,
1550
1765
  setSearch,
1551
1766
  refusal,
@@ -1562,13 +1777,6 @@ function useNativeResourceView(view, options = {}) {
1562
1777
  var IOS_GROUP_MARGIN = 16;
1563
1778
  var GROUP_RADIUS = Number.parseFloat(String(Platform.Version)) >= 26 ? 26 : 10;
1564
1779
  var IOS = Platform.OS === "ios";
1565
- var recordKey = (view, row) => {
1566
- try {
1567
- return String(encodeRecordKey(view.contract, row));
1568
- } catch {
1569
- return String(row.id);
1570
- }
1571
- };
1572
1780
  function NativeResourceView(props) {
1573
1781
  const scope = useOptionalViewerScope();
1574
1782
  const viewer = scope?.timeZone;
@@ -1603,6 +1811,34 @@ function RowLeading({ picture, testID }) {
1603
1811
  /* @__PURE__ */ jsx(View, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", children: /* @__PURE__ */ jsx(NativeAvatar, { testID: `${testID}-initials`, fallback: initials, size: PICTURE_SIZE }) })
1604
1812
  );
1605
1813
  }
1814
+ function cardFor(row, { item: itemFor, actions: actionsFor, handlers, onPress, cancelLabel, testID, first, last }) {
1815
+ const item = itemFor(row);
1816
+ const actions = actionsFor(row, handlers);
1817
+ const chip = item.chips[0];
1818
+ const picture = item.picture;
1819
+ const open = () => onPress(row);
1820
+ const showActions = () => showInboxActions(item.title, actions, cancelLabel);
1821
+ return {
1822
+ item,
1823
+ actions,
1824
+ open,
1825
+ showActions,
1826
+ first,
1827
+ last,
1828
+ pressableProps: {
1829
+ testID: `${testID}-row-${item.id}`,
1830
+ accessibilityRole: "button",
1831
+ accessibilityLabel: [picture?.kind === "image" ? picture.alt : null, item.title, item.subtitle, chip?.label].filter(Boolean).join(", "),
1832
+ accessibilityActions: actions.map((a) => ({ name: a.id, label: a.reason ? `${a.label}: ${a.reason}` : a.label })),
1833
+ onAccessibilityAction: (event) => actions.find((a) => a.id === event.nativeEvent.actionName)?.onPress(),
1834
+ onPress: open,
1835
+ onLongPress: actions.length ? showActions : void 0
1836
+ }
1837
+ };
1838
+ }
1839
+ function withSwipe(content, card, Swipeable) {
1840
+ return card.actions.length && Swipeable ? /* @__PURE__ */ jsx(Swipeable, { actions: card.actions, testID: `${card.pressableProps.testID}-swipe`, children: content }) : content;
1841
+ }
1606
1842
  var ResourceRow = memo(function ResourceRow2({
1607
1843
  row,
1608
1844
  first,
@@ -1618,11 +1854,11 @@ var ResourceRow = memo(function ResourceRow2({
1618
1854
  separator,
1619
1855
  testID
1620
1856
  }) {
1621
- const item = itemFor(row);
1622
- const actions = actionsFor(row, handlers);
1857
+ const card = cardFor(row, { item: itemFor, actions: actionsFor, handlers, onPress, cancelLabel, testID, first, last });
1858
+ const { item, pressableProps } = card;
1623
1859
  const chip = item.chips[0];
1624
1860
  const picture = item.picture;
1625
- const rowTestID = `${testID}-row-${item.id}`;
1861
+ const rowTestID = pressableProps.testID;
1626
1862
  const content = /* @__PURE__ */ jsxs(
1627
1863
  View,
1628
1864
  {
@@ -1639,36 +1875,84 @@ var ResourceRow = memo(function ResourceRow2({
1639
1875
  } : null
1640
1876
  ],
1641
1877
  children: [
1642
- /* @__PURE__ */ jsx(
1643
- Pressable,
1878
+ /* @__PURE__ */ jsx(Pressable, { ...pressableProps, children: /* @__PURE__ */ jsx(
1879
+ NativeListItem,
1644
1880
  {
1645
- testID: rowTestID,
1646
- accessibilityRole: "button",
1647
- accessibilityLabel: [picture?.kind === "image" ? picture.alt : null, item.title, item.subtitle, chip?.label].filter(Boolean).join(", "),
1648
- accessibilityActions: actions.map((a) => ({ name: a.id, label: a.reason ? `${a.label}: ${a.reason}` : a.label })),
1649
- onAccessibilityAction: (event) => actions.find((a) => a.id === event.nativeEvent.actionName)?.onPress(),
1650
- onPress: () => onPress(row),
1651
- onLongPress: actions.length ? () => showInboxActions(item.title, actions, cancelLabel) : void 0,
1652
- children: /* @__PURE__ */ jsx(
1653
- NativeListItem,
1654
- {
1655
- testID: `${rowTestID}-item`,
1656
- title: item.title,
1657
- subtitle: item.subtitle,
1658
- leading: picture ? /* @__PURE__ */ jsx(RowLeading, { picture, testID: rowTestID }) : void 0,
1659
- className: "bg-transparent",
1660
- trailing: chip ? /* @__PURE__ */ jsx(NativeBadge, { testID: `${rowTestID}-chip`, variant: badgeVariant(chip.tone), children: chip.label }) : void 0,
1661
- showChevron: chevron
1662
- }
1663
- )
1881
+ testID: `${rowTestID}-item`,
1882
+ title: item.title,
1883
+ subtitle: item.subtitle,
1884
+ leading: picture ? /* @__PURE__ */ jsx(RowLeading, { picture, testID: rowTestID }) : void 0,
1885
+ className: "bg-transparent",
1886
+ trailing: chip ? /* @__PURE__ */ jsx(NativeBadge, { testID: `${rowTestID}-chip`, variant: badgeVariant(chip.tone), children: chip.label }) : void 0,
1887
+ showChevron: chevron
1664
1888
  }
1665
- ),
1889
+ ) }),
1666
1890
  !last ? /* @__PURE__ */ jsx(View, { style: { height: 0.5, marginLeft: 16, backgroundColor: separator } }) : null
1667
1891
  ]
1668
1892
  }
1669
1893
  );
1670
- return actions.length && Swipeable ? /* @__PURE__ */ jsx(Swipeable, { actions, testID: `${rowTestID}-swipe`, children: content }) : content;
1894
+ return withSwipe(content, card, Swipeable);
1895
+ });
1896
+ var CustomRow = memo(function CustomRow2(props) {
1897
+ const card = cardFor(props.row, props);
1898
+ return withSwipe(props.renderCard(props.row, props.index, card), card, props.Swipeable);
1899
+ });
1900
+ var GRID_GAP = 12;
1901
+ function GridCard(props) {
1902
+ const card = cardFor(props.row, props);
1903
+ const { item, pressableProps } = card;
1904
+ const chip = item.chips[0];
1905
+ const content = /* @__PURE__ */ jsxs(
1906
+ Pressable,
1907
+ {
1908
+ ...pressableProps,
1909
+ style: { backgroundColor: props.surface, borderRadius: GROUP_RADIUS, padding: 12, gap: 8, minHeight: 44, flexGrow: 1 },
1910
+ children: [
1911
+ item.picture ? /* @__PURE__ */ jsx(RowLeading, { picture: item.picture, testID: pressableProps.testID }) : null,
1912
+ /* @__PURE__ */ jsx(NativeText, { preset: "label", numberOfLines: 2, children: item.title }),
1913
+ item.subtitle ? /* @__PURE__ */ jsx(NativeText, { preset: "body-sm", className: "text-muted-foreground", numberOfLines: 2, children: item.subtitle }) : null,
1914
+ chip ? /* @__PURE__ */ jsx(View, { style: { flexDirection: "row" }, children: /* @__PURE__ */ jsx(NativeBadge, { testID: `${pressableProps.testID}-chip`, variant: badgeVariant(chip.tone), children: chip.label }) }) : null
1915
+ ]
1916
+ }
1917
+ );
1918
+ return withSwipe(content, card, props.Swipeable);
1919
+ }
1920
+ var GridRow = memo(function GridRow2({ line, numColumns, renderCard, ...shared }) {
1921
+ const cells = [];
1922
+ for (let i = 0; i < line.lead; i += 1) cells.push(/* @__PURE__ */ jsx(View, { style: { flex: 1 } }, `lead-${i}`));
1923
+ line.rows.forEach((row, offset) => {
1924
+ const index = line.index + offset;
1925
+ const props = { ...shared, row, first: index === 0, last: index === line.lastIndex };
1926
+ cells.push(
1927
+ /* @__PURE__ */ jsx(View, { style: { flex: 1 }, children: renderCard ? /* @__PURE__ */ jsx(CustomRow, { ...props, index, renderCard }) : /* @__PURE__ */ jsx(GridCard, { ...props }) }, recordKey(shared.view, row))
1928
+ );
1929
+ });
1930
+ for (let i = line.lead + line.rows.length; i < numColumns; i += 1) cells.push(/* @__PURE__ */ jsx(View, { style: { flex: 1 } }, `spacer-${i}`));
1931
+ return /* @__PURE__ */ jsx(View, { testID: `${shared.testID}-grid-line-${line.key}`, style: { flexDirection: "row", gap: GRID_GAP, paddingHorizontal: 16, paddingBottom: GRID_GAP }, children: cells });
1671
1932
  });
1933
+ function gridLines(sectionKey, rows, above, numColumns, previous = /* @__PURE__ */ new Map()) {
1934
+ const lines = [];
1935
+ const lastIndex = above + rows.length - 1;
1936
+ let j = 0;
1937
+ while (j < rows.length) {
1938
+ const index = above + j;
1939
+ const n = Math.floor(index / numColumns);
1940
+ const lead = index - n * numColumns;
1941
+ const take = numColumns - lead;
1942
+ const next = {
1943
+ key: `${sectionKey || "none"}-${n}`,
1944
+ index,
1945
+ lead,
1946
+ rows: rows.slice(j, j + take),
1947
+ lastIndex: index + take > lastIndex ? lastIndex : -1
1948
+ };
1949
+ const old = previous.get(next.key);
1950
+ const same = old !== void 0 && old.index === next.index && old.lastIndex === next.lastIndex && old.rows.length === next.rows.length && old.rows.every((row, i) => row === next.rows[i]);
1951
+ lines.push(same ? old : next);
1952
+ j += take;
1953
+ }
1954
+ return lines;
1955
+ }
1672
1956
  function Screen(props) {
1673
1957
  const {
1674
1958
  view,
@@ -1679,6 +1963,9 @@ function Screen(props) {
1679
1963
  header,
1680
1964
  emptyState,
1681
1965
  searchable,
1966
+ mode = "list",
1967
+ numColumns: columnsProp,
1968
+ renderCard,
1682
1969
  scopeTimeZone: _zone,
1683
1970
  testID = "native-resource-view",
1684
1971
  ...options
@@ -1719,26 +2006,60 @@ function Screen(props) {
1719
2006
  rowPress.current = onRowPress;
1720
2007
  const press = useCallback((row) => rowPress.current ? rowPress.current(row) : setPeekId({ row }), []);
1721
2008
  const chevron = !!onRowPress;
2009
+ const shared = useMemo(
2010
+ () => ({
2011
+ view,
2012
+ item: itemFor,
2013
+ actions: actionsFor,
2014
+ handlers,
2015
+ onPress: press,
2016
+ chevron,
2017
+ Swipeable,
2018
+ cancelLabel: messages.common.cancel,
2019
+ surface: colors.surface,
2020
+ separator: colors.separator,
2021
+ testID
2022
+ }),
2023
+ [view, itemFor, actionsFor, handlers, press, chevron, Swipeable, messages, colors.surface, colors.separator, testID]
2024
+ );
1722
2025
  const renderItem = useCallback(
1723
- ({ item: row, index, section }) => /* @__PURE__ */ jsx(
1724
- ResourceRow,
1725
- {
1726
- row,
1727
- first: index === 0,
1728
- last: index === section.data.length - 1,
1729
- item: itemFor,
1730
- actions: actionsFor,
1731
- handlers,
1732
- onPress: press,
1733
- chevron,
1734
- Swipeable,
1735
- cancelLabel: messages.common.cancel,
1736
- surface: colors.surface,
1737
- separator: colors.separator,
1738
- testID
1739
- }
1740
- ),
1741
- [itemFor, actionsFor, handlers, press, chevron, Swipeable, messages, colors.surface, colors.separator, testID]
2026
+ ({ item: row, index, section }) => {
2027
+ const props2 = { ...shared, row, first: index === 0, last: index === section.data.length - 1 };
2028
+ return renderCard ? /* @__PURE__ */ jsx(CustomRow, { ...props2, index, renderCard }) : /* @__PURE__ */ jsx(ResourceRow, { ...props2 });
2029
+ },
2030
+ [shared, renderCard]
2031
+ );
2032
+ const numColumns = Math.max(1, Math.floor(columnsProp ?? 2));
2033
+ const grid = mode === "grid";
2034
+ const sectionStarts = useRef(/* @__PURE__ */ new Map());
2035
+ const lastLines = useRef(/* @__PURE__ */ new Map());
2036
+ const { rowOffset, hasPrevious } = state;
2037
+ const gridState = useMemo(() => {
2038
+ const starts = /* @__PURE__ */ new Map();
2039
+ const lines = /* @__PURE__ */ new Map();
2040
+ let at = rowOffset;
2041
+ if (!grid) return { sections: [], starts, lines };
2042
+ const out = state.sections.map((section, i) => {
2043
+ const seen = sectionStarts.current.get(section.key);
2044
+ const start = i === 0 && hasPrevious && seen !== void 0 ? Math.min(seen, at) : at;
2045
+ starts.set(section.key, start);
2046
+ const data = gridLines(section.key, section.data, at - start, numColumns, lastLines.current);
2047
+ for (const line of data) lines.set(line.key, line);
2048
+ at += section.data.length;
2049
+ return { key: section.key, title: section.title, data };
2050
+ });
2051
+ return { sections: out, starts, lines };
2052
+ }, [grid, state.sections, numColumns, rowOffset, hasPrevious]);
2053
+ useLayoutEffect(() => {
2054
+ if (!grid) return;
2055
+ sectionStarts.current = gridState.starts;
2056
+ lastLines.current = gridState.lines;
2057
+ }, [grid, gridState]);
2058
+ const gridSections = gridState.sections;
2059
+ const gridKey = useCallback((line) => line.key, []);
2060
+ const renderGridLine = useCallback(
2061
+ ({ item: line }) => /* @__PURE__ */ jsx(GridRow, { ...shared, line, numColumns, renderCard }),
2062
+ [shared, numColumns, renderCard]
1742
2063
  );
1743
2064
  const renderSectionHeader = useCallback(
1744
2065
  ({ section }) => section.title ? /* @__PURE__ */ jsx(
@@ -1831,9 +2152,9 @@ function Screen(props) {
1831
2152
  SectionList,
1832
2153
  {
1833
2154
  testID: `${testID}-list`,
1834
- sections: state.sections,
1835
- keyExtractor,
1836
- renderItem,
2155
+ sections: grid ? gridSections : state.sections,
2156
+ keyExtractor: grid ? gridKey : keyExtractor,
2157
+ renderItem: grid ? renderGridLine : renderItem,
1837
2158
  renderSectionHeader,
1838
2159
  extraData: actionsFor,
1839
2160
  stickySectionHeadersEnabled: false,
@@ -2173,18 +2494,25 @@ function SettingsGroup({
2173
2494
  }, [recordView, view, sectionId]);
2174
2495
  const viewer = useViewer$1();
2175
2496
  const locked = recordView.settingsLocked(row, viewer);
2176
- const [draft, setDraft] = useState(() => Object.fromEntries(fields.map((f) => [f.key, row[f.key]])));
2497
+ const [edits, setEdits] = useState({});
2498
+ const draft = useMemo(() => ({ ...Object.fromEntries(fields.map((f) => [f.key, row[f.key]])), ...edits }), [fields, row, edits]);
2499
+ useEffect(() => {
2500
+ setEdits((current) => {
2501
+ const left = Object.fromEntries(Object.entries(current).filter(([k, v]) => !sameFormValue(v, row[k])));
2502
+ return Object.keys(left).length === Object.keys(current).length ? current : left;
2503
+ });
2504
+ }, [row]);
2177
2505
  const [invalid, setInvalid] = useState({});
2178
2506
  const [saving, setSaving] = useState(false);
2179
2507
  const [refusal, setRefusal] = useState(null);
2180
2508
  const shown = fields.filter((f) => !f.visible || f.visible(draft));
2181
2509
  const changed = {};
2182
- for (const f of shown) if (draft[f.key] !== row[f.key]) changed[f.key] = draft[f.key];
2510
+ for (const f of shown) if (f.key in edits && !sameFormValue(draft[f.key], row[f.key])) changed[f.key] = draft[f.key];
2183
2511
  const dirty = Object.keys(changed).length > 0 && !shown.some((f) => invalid[f.key]);
2184
2512
  const set = (key, value, error) => {
2185
2513
  setRefusal(null);
2186
2514
  setInvalid(({ [key]: _old, ...rest }) => error ? { ...rest, [key]: error } : rest);
2187
- setDraft((d) => ({ ...d, [key]: value }));
2515
+ setEdits((d) => ({ ...d, [key]: value }));
2188
2516
  };
2189
2517
  const save = async () => {
2190
2518
  setSaving(true);
@@ -2336,6 +2664,6 @@ function Cell({ last, children }) {
2336
2664
  ] });
2337
2665
  }
2338
2666
 
2339
- export { DEFAULT_MAX_PAGES, DisplayRenderersProvider, DisplayTimeZonesProvider, NativeDataFilters, NativeDataPageShell, NativeDetailPanel, NativeEmptyState2 as NativeEmptyState, NativeRecordView, NativeRecordViewMenu, NativeResourceForm, NativeResourceFormFieldRenderer, NativeResourceFormSheet, NativeResourcePage, NativeResourceView, NativeResourceViewMessagesProvider, NativeResourceWorkspace, NativeResourceWorkspaceMenu, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, allowed, dateToDay, dayToDate, defaultNativeRecordViewMessages, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeRecordViewStackOptions, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, serverSorts, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
2667
+ export { DEFAULT_MAX_PAGES, DisplayRenderersProvider, DisplayTimeZonesProvider, NativeDataFilters, NativeDataPageShell, NativeDetailPanel, NativeEmptyState2 as NativeEmptyState, NativeRecordView, NativeRecordViewMenu, NativeResourceForm, NativeResourceFormFieldRenderer, NativeResourceFormSheet, NativeResourcePage, NativeResourceView, NativeResourceViewMessagesProvider, NativeResourceWorkspace, NativeResourceWorkspaceMenu, SEARCH_DEBOUNCE_MS2 as SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, allowed, dateToDay, dayToDate, defaultNativeRecordViewMessages, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeRecordViewStackOptions, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, serverSorts, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
2340
2668
  //# sourceMappingURL=index.js.map
2341
2669
  //# sourceMappingURL=index.js.map