@marktiderman/genesis-ui-native 3.5.1 → 3.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/README.md +115 -7
- package/dist/{chunk-ONH2PCGH.js → chunk-3KFUS7O6.js} +9 -15
- package/dist/chunk-3KFUS7O6.js.map +1 -0
- package/dist/{chunk-LBVD7XXL.js → chunk-7NDKIIOT.js} +627 -20
- package/dist/chunk-7NDKIIOT.js.map +1 -0
- package/dist/chunk-CAI7LGN6.js +39 -0
- package/dist/chunk-CAI7LGN6.js.map +1 -0
- package/dist/{chunk-ABVSSJNT.js → chunk-GBNIBHSU.js} +198 -168
- package/dist/chunk-GBNIBHSU.js.map +1 -0
- package/dist/chunk-IXC3LO2K.js +410 -0
- package/dist/chunk-IXC3LO2K.js.map +1 -0
- package/dist/{chunk-GHYUNNNU.js → chunk-KH2RVAI5.js} +174 -93
- package/dist/chunk-KH2RVAI5.js.map +1 -0
- package/dist/{chunk-6KWEAGRD.js → chunk-O4BMDV7I.js} +110 -17
- package/dist/chunk-O4BMDV7I.js.map +1 -0
- package/dist/chunk-RTYO24SC.js +105 -0
- package/dist/chunk-RTYO24SC.js.map +1 -0
- package/dist/{chunk-D5RKSPMH.js → chunk-YWDDDYDI.js} +4 -3
- package/dist/chunk-YWDDDYDI.js.map +1 -0
- package/dist/components/index.d.ts +382 -10
- package/dist/components/index.js +6 -5
- package/dist/data/index.d.ts +68 -4
- package/dist/data/index.js +231 -30
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.d.ts +90 -2
- package/dist/hooks/index.js +3 -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 +9 -8
- package/dist/layouts/index.d.ts +40 -51
- package/dist/layouts/index.js +6 -4
- package/dist/{native-modules-PwnGltOU.d.ts → native-modules-DEJJQhDx.d.ts} +55 -1
- package/package.json +101 -4
- package/src/__tests__/doctor-rules.test.ts +87 -0
- package/src/__tests__/native-modules-lists.test.tsx +1 -0
- package/src/components/__tests__/button-haptic.test.tsx +52 -0
- package/src/components/__tests__/composer-bar.test.tsx +79 -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 +219 -0
- package/src/components/button.tsx +18 -1
- package/src/components/composer-bar.tsx +276 -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 +457 -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/NativeRecordView.tsx +85 -8
- package/src/data/resource-view/NativeResourceView.tsx +79 -32
- 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/hooks/__tests__/use-haptics.test.tsx +146 -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 +5 -0
- package/src/hooks/use-haptics.ts +64 -0
- package/src/hooks/use-motion.ts +128 -0
- package/src/hooks/use-press-feedback.ts +87 -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 +20 -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
package/dist/data/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { NativeImage, NativeAvatar, NativeCard, NativeCardContent, NativeSeparator, NativeLabel, NativeSwitch, NativeCheckbox, NativeSelect, NativeSelectTrigger, NativeSelectContent, NativeSelectItem, NativeTextarea,
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { useThemeRoles } from '../chunk-Z3AQYVUA.js';
|
|
1
|
+
import { NativeImage, NativeAvatar, NativeCard, NativeCardContent, NativeSeparator, NativeLabel, NativeSwitch, NativeCheckbox, NativeSelect, NativeSelectTrigger, NativeSelectContent, NativeSelectItem, NativeTextarea, NativeSheet, NativeSheetScrollView, NativeAlert, NativeAlertTitle, NativeAlertDescription, NativeInlineAlert, NativeSegmentedControl, NativeDatePicker, NativeTimePicker, NativeSearchBar, NativeGalleryGrid, NativeCardHeader, NativeCardTitle } from '../chunk-KH2RVAI5.js';
|
|
2
|
+
import { showInboxActions, NavBarSaveButton, composeHeaderOptions } from '../chunk-3KFUS7O6.js';
|
|
3
|
+
import { NativeListItem, NativeBadge, NativeText, NativeButton, NativeInput, NativeLoadingState, NativeSectionListHeader, NativeEmptyState, NativeRefreshControl, NativeIcon, NativeSkeleton } from '../chunk-O4BMDV7I.js';
|
|
4
|
+
import { useGenesisModules, useThemeRoles } from '../chunk-RTYO24SC.js';
|
|
6
5
|
import '../chunk-OHZD7KRO.js';
|
|
7
6
|
import '../chunk-DGUM43GV.js';
|
|
8
|
-
import { Platform, View, Pressable, Text, Linking, ScrollView, Alert, SectionList, ActionSheetIOS, FlatList } from 'react-native';
|
|
7
|
+
import { Platform, View, Pressable, Text, Linking, ScrollView, AccessibilityInfo, Alert, SectionList, ActionSheetIOS, FlatList } from 'react-native';
|
|
9
8
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
10
9
|
import * as React from 'react';
|
|
11
|
-
import { createContext, memo, useState, useCallback,
|
|
10
|
+
import { createContext, memo, useState, useCallback, useEffect, useMemo, useContext, useRef, useLayoutEffect } from 'react';
|
|
12
11
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
13
|
-
import { encodeRecordKey, titleCase, useResourceForm, resourceKeys, useDataProvider, useViewer as useViewer$1,
|
|
12
|
+
import { encodeRecordKey, titleCase, useResourceForm, resourceKeys, useDataProvider, useCapabilities as useCapabilities$1, useViewer as useViewer$1, useResource as useResource$1, writeConflict, isDataWriteError, DataWriteError } from '@marktiderman/genesis-core';
|
|
14
13
|
import { Controller, useForm } from 'react-hook-form';
|
|
15
14
|
import { useRelationLabel, useResource, useViewer, useInfiniteResource, useCapabilities, useOptionalViewerScope, scopeClock, useOne, useLinkOptions } from '@marktiderman/genesis-core/hooks';
|
|
16
15
|
import { personTimeZone, isTimeZone, wallClock } from '@marktiderman/genesis-core/dates';
|
|
@@ -410,6 +409,98 @@ function NativeResourceFormFieldRenderer({
|
|
|
410
409
|
}
|
|
411
410
|
);
|
|
412
411
|
}
|
|
412
|
+
var english = {
|
|
413
|
+
title: "Someone else changed this {noun}",
|
|
414
|
+
description: "They saved a change after you opened it. Theirs is next to yours below: keep yours to save it over theirs, or take theirs and drop your changes.",
|
|
415
|
+
same: "Their change already matches yours, so there's nothing to choose.",
|
|
416
|
+
theirs: "Theirs",
|
|
417
|
+
mine: "Yours",
|
|
418
|
+
empty: "Empty",
|
|
419
|
+
unknown: "Not shown",
|
|
420
|
+
keepMine: "Keep my version",
|
|
421
|
+
takeTheirs: "Take their version",
|
|
422
|
+
failed: "Your version wasn't saved.",
|
|
423
|
+
yes: "Yes",
|
|
424
|
+
no: "No",
|
|
425
|
+
record: "record"
|
|
426
|
+
};
|
|
427
|
+
function plain(value, w) {
|
|
428
|
+
if (value === null || value === void 0 || value === "") return w.empty;
|
|
429
|
+
if (typeof value === "boolean") return value ? w.yes : w.no;
|
|
430
|
+
if (typeof value === "object") {
|
|
431
|
+
try {
|
|
432
|
+
return JSON.stringify(value);
|
|
433
|
+
} catch {
|
|
434
|
+
return String(value);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return String(value);
|
|
438
|
+
}
|
|
439
|
+
function NativeConflictSheet({
|
|
440
|
+
conflict,
|
|
441
|
+
noun,
|
|
442
|
+
label = titleCase,
|
|
443
|
+
format,
|
|
444
|
+
onKeepMine,
|
|
445
|
+
onTakeTheirs,
|
|
446
|
+
onDismiss,
|
|
447
|
+
messages,
|
|
448
|
+
testID = "native-conflict-sheet"
|
|
449
|
+
}) {
|
|
450
|
+
const w = { ...english, ...messages };
|
|
451
|
+
const [keeping, setKeeping] = useState(false);
|
|
452
|
+
const [failed, setFailed] = useState(null);
|
|
453
|
+
const fields = conflict?.fields ?? [];
|
|
454
|
+
const title = w.title.replace("{noun}", noun ?? w.record);
|
|
455
|
+
const canKeep = fields.length > 0 && conflict?.currentVersion != null;
|
|
456
|
+
useEffect(() => {
|
|
457
|
+
setFailed(null);
|
|
458
|
+
if (conflict) AccessibilityInfo.announceForAccessibility?.(title);
|
|
459
|
+
}, [conflict, title]);
|
|
460
|
+
const has = (field) => !!conflict && field in conflict.theirs;
|
|
461
|
+
const text2 = (field, value, known = true) => known ? plain(value, w) : w.unknown;
|
|
462
|
+
const show = (field, value, known = true) => format && known ? format(field, value) : /* @__PURE__ */ jsx(NativeText, { preset: "body-sm", children: text2(field, value, known) });
|
|
463
|
+
const keep = async () => {
|
|
464
|
+
setKeeping(true);
|
|
465
|
+
setFailed(null);
|
|
466
|
+
try {
|
|
467
|
+
await onKeepMine();
|
|
468
|
+
} catch (error) {
|
|
469
|
+
setFailed(error instanceof Error && error.message ? error.message : w.failed);
|
|
470
|
+
} finally {
|
|
471
|
+
setKeeping(false);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
return /* @__PURE__ */ jsx(
|
|
475
|
+
NativeSheet,
|
|
476
|
+
{
|
|
477
|
+
open: conflict !== null,
|
|
478
|
+
onOpenChange: (open) => !open && !keeping && onDismiss(),
|
|
479
|
+
fitContent: true,
|
|
480
|
+
testID,
|
|
481
|
+
children: /* @__PURE__ */ jsx(NativeSheetScrollView, { children: /* @__PURE__ */ jsxs(View, { style: { gap: 12, paddingHorizontal: 16, paddingVertical: 12 }, children: [
|
|
482
|
+
/* @__PURE__ */ jsx(NativeText, { preset: "h4", accessibilityRole: "header", children: title }),
|
|
483
|
+
/* @__PURE__ */ jsx(NativeText, { preset: "body-sm", className: "text-muted-foreground", children: fields.length > 0 ? w.description : w.same }),
|
|
484
|
+
conflict ? fields.map((field) => /* @__PURE__ */ jsxs(View, { style: { gap: 4 }, testID: `${testID}-field-${field}`, children: [
|
|
485
|
+
/* @__PURE__ */ jsx(NativeText, { preset: "label", children: label(field) }),
|
|
486
|
+
/* @__PURE__ */ jsxs(View, { accessible: true, ...format ? {} : { accessibilityLabel: `${w.theirs}: ${text2(field, conflict.theirs[field], has(field))}` }, children: [
|
|
487
|
+
/* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-muted-foreground", children: w.theirs }),
|
|
488
|
+
show(field, conflict.theirs[field], has(field))
|
|
489
|
+
] }),
|
|
490
|
+
/* @__PURE__ */ jsxs(View, { accessible: true, ...format ? {} : { accessibilityLabel: `${w.mine}: ${text2(field, conflict.mine[field])}` }, children: [
|
|
491
|
+
/* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-muted-foreground", children: w.mine }),
|
|
492
|
+
show(field, conflict.mine[field])
|
|
493
|
+
] })
|
|
494
|
+
] }, field)) : null,
|
|
495
|
+
failed ? /* @__PURE__ */ jsx(NativeText, { preset: "body-sm", className: "text-destructive", accessibilityRole: "alert", testID: `${testID}-failed`, children: failed }) : null,
|
|
496
|
+
/* @__PURE__ */ jsxs(View, { style: { gap: 8, paddingTop: 4 }, children: [
|
|
497
|
+
canKeep ? /* @__PURE__ */ jsx(NativeButton, { size: "lg", onPress: () => void keep(), loading: keeping, disabled: keeping, testID: `${testID}-keep-mine`, children: w.keepMine }) : null,
|
|
498
|
+
/* @__PURE__ */ jsx(NativeButton, { size: "lg", variant: "outline", onPress: onTakeTheirs, disabled: keeping, testID: `${testID}-take-theirs`, children: w.takeTheirs })
|
|
499
|
+
] })
|
|
500
|
+
] }) })
|
|
501
|
+
}
|
|
502
|
+
);
|
|
503
|
+
}
|
|
413
504
|
function NativeResourceForm({
|
|
414
505
|
resource,
|
|
415
506
|
action,
|
|
@@ -433,7 +524,18 @@ function NativeResourceForm({
|
|
|
433
524
|
prefillFromUrl: false,
|
|
434
525
|
validationMode: "onSubmit"
|
|
435
526
|
};
|
|
436
|
-
const { form, resolvedFields, onSubmit, isSaving } = useResourceForm(options);
|
|
527
|
+
const { form, resolvedFields, onSubmit, isSaving, conflict, keepMine, takeTheirs, dismissConflict } = useResourceForm(options);
|
|
528
|
+
const conflictSheet = /* @__PURE__ */ jsx(
|
|
529
|
+
NativeConflictSheet,
|
|
530
|
+
{
|
|
531
|
+
conflict,
|
|
532
|
+
label: (field) => resolvedFields.find((f) => f.key === field)?.label ?? titleCase(field),
|
|
533
|
+
onKeepMine: keepMine,
|
|
534
|
+
onTakeTheirs: takeTheirs,
|
|
535
|
+
onDismiss: dismissConflict,
|
|
536
|
+
testID: "native-resource-form-conflict"
|
|
537
|
+
}
|
|
538
|
+
);
|
|
437
539
|
const resolvedTitle = title ?? (action === "create" ? `Create ${titleCase(resource)}` : `Edit ${titleCase(resource)}`);
|
|
438
540
|
const submitLabel = action === "create" ? "Create" : "Save";
|
|
439
541
|
const values = form.watch();
|
|
@@ -481,20 +583,24 @@ function NativeResourceForm({
|
|
|
481
583
|
if (layout === "inline") {
|
|
482
584
|
return /* @__PURE__ */ jsxs(View, { style: { gap: 16 }, children: [
|
|
483
585
|
/* @__PURE__ */ jsx(NativeText, { preset: "h3", children: resolvedTitle }),
|
|
484
|
-
formContent
|
|
586
|
+
formContent,
|
|
587
|
+
conflictSheet
|
|
485
588
|
] });
|
|
486
589
|
}
|
|
487
|
-
return /* @__PURE__ */
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
590
|
+
return /* @__PURE__ */ jsxs(SafeAreaView, { edges: ["bottom"], style: { flex: 1 }, children: [
|
|
591
|
+
/* @__PURE__ */ jsxs(
|
|
592
|
+
ScrollView,
|
|
593
|
+
{
|
|
594
|
+
contentContainerStyle: { padding: 16, gap: 16 },
|
|
595
|
+
showsVerticalScrollIndicator: false,
|
|
596
|
+
children: [
|
|
597
|
+
/* @__PURE__ */ jsx(NativeText, { preset: "h3", children: resolvedTitle }),
|
|
598
|
+
formContent
|
|
599
|
+
]
|
|
600
|
+
}
|
|
601
|
+
),
|
|
602
|
+
conflictSheet
|
|
603
|
+
] });
|
|
498
604
|
}
|
|
499
605
|
function resolveField(f, index) {
|
|
500
606
|
if (typeof f === "string") {
|
|
@@ -1968,6 +2074,7 @@ function Screen(props) {
|
|
|
1968
2074
|
searchable,
|
|
1969
2075
|
mode = "list",
|
|
1970
2076
|
numColumns: columnsProp,
|
|
2077
|
+
gallery: screenGallery,
|
|
1971
2078
|
renderCard,
|
|
1972
2079
|
scopeTimeZone: _zone,
|
|
1973
2080
|
testID = "native-resource-view",
|
|
@@ -2148,10 +2255,43 @@ function Screen(props) {
|
|
|
2148
2255
|
const { formFields } = state;
|
|
2149
2256
|
const createFields = useMemo(() => formFields("create"), [formFields]);
|
|
2150
2257
|
const editFields = useMemo(() => formFields("edit"), [formFields]);
|
|
2258
|
+
const galleryKey = JSON.stringify(screenGallery ?? null);
|
|
2259
|
+
const photos = useMemo(() => {
|
|
2260
|
+
if (!grid || !(view.definition.gallery || screenGallery?.image)) return null;
|
|
2261
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2262
|
+
const items = [];
|
|
2263
|
+
for (const section of state.sections) {
|
|
2264
|
+
for (const row of section.data) {
|
|
2265
|
+
const photo = view.galleryItem(row, screenGallery);
|
|
2266
|
+
if (!photo) continue;
|
|
2267
|
+
byId.set(photo.id, row);
|
|
2268
|
+
items.push(photo);
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
return { items, byId };
|
|
2272
|
+
}, [grid, view, galleryKey, state.sections]);
|
|
2273
|
+
const galleryRowHeight = screenGallery?.rowHeight ?? view.definition.gallery?.rowHeight;
|
|
2151
2274
|
const peekActions = peek ? actionsFor(peek, handlers) : [];
|
|
2152
2275
|
const editLoading = sheet?.mode === "edit" && editRow.data === void 0 && !editRow.isError;
|
|
2153
2276
|
return /* @__PURE__ */ jsxs(SafeAreaView, { testID, edges: ["left", "right", "bottom"], style: { flex: 1, backgroundColor: colors.groupedBackground }, children: [
|
|
2154
|
-
/* @__PURE__ */ jsx(
|
|
2277
|
+
photos ? /* @__PURE__ */ jsx(
|
|
2278
|
+
NativeGalleryGrid,
|
|
2279
|
+
{
|
|
2280
|
+
testID: `${testID}-gallery`,
|
|
2281
|
+
items: photos.items,
|
|
2282
|
+
...galleryRowHeight !== void 0 ? { rowHeight: galleryRowHeight } : {},
|
|
2283
|
+
onItemPress: (photo) => {
|
|
2284
|
+
const row = photos.byId.get(photo.id);
|
|
2285
|
+
if (row) press(row);
|
|
2286
|
+
},
|
|
2287
|
+
header: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2288
|
+
listHeader,
|
|
2289
|
+
photos.items.length === 0 ? empty : null
|
|
2290
|
+
] }),
|
|
2291
|
+
footer: state.loadingMore ? /* @__PURE__ */ jsx(NativeLoadingState, { fullScreen: false, size: "small", label: messages.list.loadingMore, testID: `${testID}-more` }) : null,
|
|
2292
|
+
...state.hasMore ? { loadMore: state.loadMore } : {}
|
|
2293
|
+
}
|
|
2294
|
+
) : /* @__PURE__ */ jsx(
|
|
2155
2295
|
SectionList,
|
|
2156
2296
|
{
|
|
2157
2297
|
testID: `${testID}-list`,
|
|
@@ -2285,6 +2425,8 @@ function useHeaderActions({ view: recordView, row, onAction, can, messages }) {
|
|
|
2285
2425
|
return { actions, press, pending, words };
|
|
2286
2426
|
}
|
|
2287
2427
|
var A11Y_PREFIX = "action:";
|
|
2428
|
+
var alreadyShown = () => {
|
|
2429
|
+
};
|
|
2288
2430
|
function NativeRecordViewMenu(props) {
|
|
2289
2431
|
const { testID = "native-resource-workspace-menu" } = props;
|
|
2290
2432
|
const { actions, press, pending, words } = useHeaderActions(props);
|
|
@@ -2484,13 +2626,17 @@ function NativeRecordView(props) {
|
|
|
2484
2626
|
function SettingsGroup({
|
|
2485
2627
|
recordView,
|
|
2486
2628
|
sectionId,
|
|
2487
|
-
row,
|
|
2629
|
+
row: rowProp,
|
|
2488
2630
|
words,
|
|
2489
2631
|
onSaved,
|
|
2490
2632
|
testID
|
|
2491
2633
|
}) {
|
|
2492
2634
|
const provider = useDataProvider();
|
|
2635
|
+
const [theirsRow, setTheirsRow] = useState(null);
|
|
2636
|
+
useEffect(() => setTheirsRow(null), [rowProp]);
|
|
2637
|
+
const row = theirsRow ?? rowProp;
|
|
2493
2638
|
const view = recordView.view;
|
|
2639
|
+
const versionField = useCapabilities$1(view.resource, { enabled: !!provider.capabilities }).data?.version?.field;
|
|
2494
2640
|
const fields = useMemo(() => {
|
|
2495
2641
|
const byKey = new Map(formFieldsFor(view, "edit").map((f) => [f.key, f]));
|
|
2496
2642
|
return recordView.settingsFields(sectionId).map((f) => byKey.get(f.field.name)).filter((f) => !!f && !f.readOnly);
|
|
@@ -2498,6 +2644,10 @@ function SettingsGroup({
|
|
|
2498
2644
|
const viewer = useViewer$1();
|
|
2499
2645
|
const locked = recordView.settingsLocked(row, viewer);
|
|
2500
2646
|
const [edits, setEdits] = useState({});
|
|
2647
|
+
const editBase = useRef(void 0);
|
|
2648
|
+
useEffect(() => {
|
|
2649
|
+
if (Object.keys(edits).length === 0) editBase.current = void 0;
|
|
2650
|
+
}, [edits]);
|
|
2501
2651
|
const draft = useMemo(() => ({ ...Object.fromEntries(fields.map((f) => [f.key, row[f.key]])), ...edits }), [fields, row, edits]);
|
|
2502
2652
|
useEffect(() => {
|
|
2503
2653
|
setEdits((current) => {
|
|
@@ -2513,23 +2663,61 @@ function SettingsGroup({
|
|
|
2513
2663
|
for (const f of shown) if (f.key in edits && !sameFormValue(draft[f.key], row[f.key])) changed[f.key] = draft[f.key];
|
|
2514
2664
|
const dirty = Object.keys(changed).length > 0 && !shown.some((f) => invalid[f.key]);
|
|
2515
2665
|
const set = (key, value, error) => {
|
|
2666
|
+
if (Object.keys(edits).length === 0 && editBase.current === void 0) editBase.current = row;
|
|
2516
2667
|
setRefusal(null);
|
|
2517
2668
|
setInvalid(({ [key]: _old, ...rest }) => error ? { ...rest, [key]: error } : rest);
|
|
2518
2669
|
setEdits((d) => ({ ...d, [key]: value }));
|
|
2519
2670
|
};
|
|
2520
|
-
const
|
|
2671
|
+
const queryClient = useQueryClient();
|
|
2672
|
+
const { update } = useResource$1(view.resource, { enabled: false, onError: alreadyShown });
|
|
2673
|
+
const [conflict, setConflict] = useState(null);
|
|
2674
|
+
const lastFailure = useRef(null);
|
|
2675
|
+
const save = async (values = changed, expectedVersion) => {
|
|
2521
2676
|
setSaving(true);
|
|
2522
2677
|
setRefusal(null);
|
|
2678
|
+
const data = recordView.settingsPatch(sectionId, values);
|
|
2523
2679
|
try {
|
|
2524
|
-
const
|
|
2525
|
-
|
|
2526
|
-
|
|
2680
|
+
const version = expectedVersion ?? (versionField ? (editBase.current ?? row)[versionField] : void 0);
|
|
2681
|
+
const saved = await update(recordView.recordId(row), data, version != null ? { expectedVersion: String(version) } : void 0);
|
|
2682
|
+
if (saved === null || saved === void 0) {
|
|
2683
|
+
lastFailure.current = fill(words.notChanged, { noun: view.noun });
|
|
2684
|
+
setRefusal(lastFailure.current);
|
|
2685
|
+
return "failed";
|
|
2686
|
+
}
|
|
2687
|
+
if (versionField && saved[versionField] != null) editBase.current = { ...editBase.current ?? row, [versionField]: saved[versionField] };
|
|
2688
|
+
setConflict(null);
|
|
2689
|
+
onSaved(saved);
|
|
2690
|
+
return "saved";
|
|
2527
2691
|
} catch (error) {
|
|
2528
|
-
|
|
2692
|
+
const found = writeConflict(error, data);
|
|
2693
|
+
if (found && isDataWriteError(error) && error.current) {
|
|
2694
|
+
setConflict({ conflict: found, values, row: error.current, message: error.message });
|
|
2695
|
+
return "conflict";
|
|
2696
|
+
}
|
|
2697
|
+
lastFailure.current = refusalMessage(error, words.failed);
|
|
2698
|
+
setRefusal(lastFailure.current);
|
|
2699
|
+
return "failed";
|
|
2529
2700
|
} finally {
|
|
2530
2701
|
setSaving(false);
|
|
2531
2702
|
}
|
|
2532
2703
|
};
|
|
2704
|
+
const keepMine = async () => {
|
|
2705
|
+
if (!conflict) return;
|
|
2706
|
+
const { values, conflict: c } = conflict;
|
|
2707
|
+
if (await save(values, c.currentVersion ?? void 0) === "failed") throw new Error(lastFailure.current ?? words.failed);
|
|
2708
|
+
};
|
|
2709
|
+
const takeTheirs = () => {
|
|
2710
|
+
if (!conflict) return;
|
|
2711
|
+
const { row: theirs } = conflict;
|
|
2712
|
+
setConflict(null);
|
|
2713
|
+
setEdits({});
|
|
2714
|
+
setTheirsRow({ ...rowProp, ...theirs });
|
|
2715
|
+
void queryClient.invalidateQueries({ queryKey: [...resourceKeys(view.resource).all] });
|
|
2716
|
+
};
|
|
2717
|
+
const dismissConflict = () => {
|
|
2718
|
+
if (conflict) setRefusal(conflict.message);
|
|
2719
|
+
setConflict(null);
|
|
2720
|
+
};
|
|
2533
2721
|
return /* @__PURE__ */ jsxs(View, { style: { gap: 12 }, children: [
|
|
2534
2722
|
refusal ? /* @__PURE__ */ jsx(NativeInlineAlert, { testID: `${testID}-refusal`, variant: "destructive", description: refusal }) : null,
|
|
2535
2723
|
locked !== null ? /* @__PURE__ */ jsx(NativeInlineAlert, { testID: `${testID}-locked`, variant: "info", description: locked }) : null,
|
|
@@ -2546,7 +2734,20 @@ function SettingsGroup({
|
|
|
2546
2734
|
testID: `${testID}-${f.key}`
|
|
2547
2735
|
}
|
|
2548
2736
|
) }, f.key)) }),
|
|
2549
|
-
locked === null ? /* @__PURE__ */ jsx(NativeButton, { testID: `${testID}-save`, disabled: !dirty || saving, loading: saving, onPress: () => void save(), children: words.save }) : null
|
|
2737
|
+
locked === null ? /* @__PURE__ */ jsx(NativeButton, { testID: `${testID}-save`, disabled: !dirty || saving, loading: saving, onPress: () => void save(), children: words.save }) : null,
|
|
2738
|
+
/* @__PURE__ */ jsx(
|
|
2739
|
+
NativeConflictSheet,
|
|
2740
|
+
{
|
|
2741
|
+
conflict: conflict?.conflict ?? null,
|
|
2742
|
+
noun: view.noun,
|
|
2743
|
+
label: (key) => fields.find((f) => f.key === key)?.label ?? key,
|
|
2744
|
+
onKeepMine: keepMine,
|
|
2745
|
+
onTakeTheirs: takeTheirs,
|
|
2746
|
+
onDismiss: dismissConflict,
|
|
2747
|
+
...words.conflict ? { messages: words.conflict } : {},
|
|
2748
|
+
testID: `${testID}-conflict`
|
|
2749
|
+
}
|
|
2750
|
+
)
|
|
2550
2751
|
] });
|
|
2551
2752
|
}
|
|
2552
2753
|
function NativeResourceWorkspace({ workspace, ...props }) {
|
|
@@ -2667,6 +2868,6 @@ function Cell({ last, children }) {
|
|
|
2667
2868
|
] });
|
|
2668
2869
|
}
|
|
2669
2870
|
|
|
2670
|
-
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 };
|
|
2871
|
+
export { DEFAULT_MAX_PAGES, DisplayRenderersProvider, DisplayTimeZonesProvider, NativeConflictSheet, 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 };
|
|
2671
2872
|
//# sourceMappingURL=index.js.map
|
|
2672
2873
|
//# sourceMappingURL=index.js.map
|