@marktiderman/genesis-ui-native 2.4.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/{chunk-BPD5DCFP.js → chunk-3S5XVER4.js} +271 -6
- package/dist/chunk-3S5XVER4.js.map +1 -0
- package/dist/chunk-56QLEHHV.js +1231 -0
- package/dist/chunk-56QLEHHV.js.map +1 -0
- package/dist/chunk-6JBNSW4D.js +479 -0
- package/dist/chunk-6JBNSW4D.js.map +1 -0
- package/dist/{chunk-RARJGZA3.js → chunk-KZEIF4YI.js} +7 -741
- package/dist/chunk-KZEIF4YI.js.map +1 -0
- package/dist/{chunk-6TLBCRS6.js → chunk-VMSIKSU2.js} +13 -477
- package/dist/chunk-VMSIKSU2.js.map +1 -0
- package/dist/components/index.d.ts +29 -3
- package/dist/components/index.js +3 -4
- package/dist/data/index.d.ts +382 -4
- package/dist/data/index.js +1067 -19
- package/dist/data/index.js.map +1 -1
- package/dist/inbox-page-DZUR-PJ1.d.ts +199 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -5
- package/dist/layouts/index.d.ts +4 -186
- package/dist/layouts/index.js +3 -3
- package/package.json +2 -2
- package/src/components/__tests__/loading-state.test.tsx +41 -0
- package/src/components/image.tsx +5 -0
- package/src/components/index.ts +3 -0
- package/src/components/loading-state.tsx +92 -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 +528 -0
- package/src/data/resource-view/__tests__/native-resource-view.test.tsx +870 -0
- package/src/data/resource-view/display.tsx +256 -0
- package/src/data/resource-view/index.ts +50 -0
- package/src/data/resource-view/mapping.ts +326 -0
- package/src/data/resource-view/messages.ts +121 -0
- package/src/data/resource-view/use-native-resource-view.ts +307 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +2 -1
- package/src/layouts/__tests__/screen-container.test.tsx +27 -0
- package/src/layouts/inbox-page.tsx +4 -7
- package/src/layouts/screen-container.tsx +18 -1
- package/dist/chunk-6TLBCRS6.js.map +0 -1
- package/dist/chunk-BPD5DCFP.js.map +0 -1
- 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-RARJGZA3.js.map +0 -1
package/dist/data/index.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import { NativeCard, NativeCardContent, NativeSeparator, NativeLabel, NativeSwitch, NativeCheckbox, NativeSelect, NativeSelectTrigger, NativeSelectContent, NativeSelectItem, NativeTextarea, NativeAlert, NativeAlertTitle, NativeAlertDescription, NativeSkeleton, NativeCardHeader, NativeCardTitle } from '../chunk-
|
|
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-56QLEHHV.js';
|
|
2
2
|
import '../chunk-7PCWEY6R.js';
|
|
3
|
-
import {
|
|
3
|
+
import { showInboxActions, NavBarSaveButton } from '../chunk-6JBNSW4D.js';
|
|
4
|
+
import { NativeListItem, NativeBadge, NativeText, NativeButton, NativeInput, useGenesisModules, NativeLoadingState, NativeSectionListHeader, NativeEmptyState, NativeRefreshControl } from '../chunk-3S5XVER4.js';
|
|
5
|
+
import { useThemeRoles } from '../chunk-Z3AQYVUA.js';
|
|
4
6
|
import '../chunk-OHZD7KRO.js';
|
|
5
7
|
import '../chunk-DGUM43GV.js';
|
|
6
|
-
import { View, ScrollView,
|
|
8
|
+
import { Platform, View, Pressable, Text, Linking, ScrollView, Alert, SectionList, FlatList } from 'react-native';
|
|
7
9
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
8
10
|
import * as React from 'react';
|
|
9
|
-
import {
|
|
11
|
+
import { createContext, memo, useState, useCallback, useMemo, useEffect, useContext, useRef } from 'react';
|
|
10
12
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
11
13
|
import { titleCase, useResourceForm } from '@marktiderman/genesis-core';
|
|
12
|
-
import { Controller } from 'react-hook-form';
|
|
13
|
-
import { useResource } from '@marktiderman/genesis-core/hooks';
|
|
14
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
15
|
+
import { useResource, useInfiniteResource, useCapabilities, useOptionalViewerScope, useOne } from '@marktiderman/genesis-core/hooks';
|
|
16
|
+
import { personTimeZone, isTimeZone, wallClock } from '@marktiderman/genesis-core/dates';
|
|
17
|
+
import { isSafeUrl } from '@marktiderman/genesis-core/urls';
|
|
18
|
+
import { rowPicture } from '@marktiderman/genesis-core/resource-view';
|
|
14
19
|
|
|
15
|
-
function
|
|
20
|
+
function NativeEmptyState2({
|
|
16
21
|
message = "No items found",
|
|
17
22
|
action,
|
|
18
23
|
hasFilters = false,
|
|
@@ -125,7 +130,7 @@ function NativeDataPageShell({
|
|
|
125
130
|
if (emptyState) {
|
|
126
131
|
return /* @__PURE__ */ jsx(Fragment, { children: emptyState });
|
|
127
132
|
}
|
|
128
|
-
return /* @__PURE__ */ jsx(
|
|
133
|
+
return /* @__PURE__ */ jsx(NativeEmptyState2, { message: emptyMessage });
|
|
129
134
|
}
|
|
130
135
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
131
136
|
};
|
|
@@ -165,9 +170,11 @@ function NativeDetailPanel({
|
|
|
165
170
|
fields,
|
|
166
171
|
onEdit,
|
|
167
172
|
onDelete,
|
|
173
|
+
title: titleProp,
|
|
174
|
+
footer,
|
|
168
175
|
children
|
|
169
176
|
}) {
|
|
170
|
-
const title = titleField ? String(item[titleField] ?? "") : void 0;
|
|
177
|
+
const title = titleProp ?? (titleField ? String(item[titleField] ?? "") : void 0);
|
|
171
178
|
const hasActions = onEdit != null || onDelete != null;
|
|
172
179
|
if (children) {
|
|
173
180
|
return /* @__PURE__ */ jsx(SafeAreaView, { edges: ["bottom"], style: { flex: 1 }, children: /* @__PURE__ */ jsxs(
|
|
@@ -217,7 +224,8 @@ function NativeDetailPanel({
|
|
|
217
224
|
children: "Delete"
|
|
218
225
|
}
|
|
219
226
|
) : null
|
|
220
|
-
] }) : null
|
|
227
|
+
] }) : null,
|
|
228
|
+
footer
|
|
221
229
|
]
|
|
222
230
|
}
|
|
223
231
|
) });
|
|
@@ -358,12 +366,12 @@ function NativeResourceFormFieldRenderer({
|
|
|
358
366
|
placeholder: field.placeholder,
|
|
359
367
|
keyboardType: "numeric",
|
|
360
368
|
value: f.value != null ? String(f.value) : "",
|
|
361
|
-
onChangeText: (
|
|
362
|
-
if (
|
|
369
|
+
onChangeText: (text2) => {
|
|
370
|
+
if (text2 === "") {
|
|
363
371
|
f.onChange(void 0);
|
|
364
372
|
} else {
|
|
365
|
-
const num = Number(
|
|
366
|
-
f.onChange(Number.isNaN(num) ?
|
|
373
|
+
const num = Number(text2);
|
|
374
|
+
f.onChange(Number.isNaN(num) ? text2 : num);
|
|
367
375
|
}
|
|
368
376
|
},
|
|
369
377
|
editable: !isDisabled,
|
|
@@ -665,7 +673,7 @@ function NativeResourcePage({
|
|
|
665
673
|
setSearchLocal("");
|
|
666
674
|
setSelectedStatuses([]);
|
|
667
675
|
}, []);
|
|
668
|
-
const
|
|
676
|
+
const keyExtractor2 = useCallback(
|
|
669
677
|
(item) => String(item.id),
|
|
670
678
|
[]
|
|
671
679
|
);
|
|
@@ -707,7 +715,7 @@ function NativeResourcePage({
|
|
|
707
715
|
// search brings back the saved rows.
|
|
708
716
|
/* @__PURE__ */ jsx(View, { testID: "native-resource-offline", className: "flex-1 items-center justify-center px-4 py-12 gap-4", children: offlineState ?? /* @__PURE__ */ jsx(NativeText, { preset: "body", className: "text-muted-foreground text-center", children: "You're offline. This list loads when you're back online." }) })
|
|
709
717
|
) : /* @__PURE__ */ jsx(Fragment, { children: emptyState ?? /* @__PURE__ */ jsx(
|
|
710
|
-
|
|
718
|
+
NativeEmptyState2,
|
|
711
719
|
{
|
|
712
720
|
hasFilters: hasActiveFilters,
|
|
713
721
|
onClearFilters: hasActiveFilters ? handleClearFilters : void 0
|
|
@@ -736,7 +744,7 @@ function NativeResourcePage({
|
|
|
736
744
|
{
|
|
737
745
|
testID: "native-resource-page-list",
|
|
738
746
|
data: items,
|
|
739
|
-
keyExtractor,
|
|
747
|
+
keyExtractor: keyExtractor2,
|
|
740
748
|
renderItem: renderFlatListItem,
|
|
741
749
|
ListHeaderComponent,
|
|
742
750
|
ListEmptyComponent,
|
|
@@ -751,7 +759,7 @@ function NativeResourcePage({
|
|
|
751
759
|
{
|
|
752
760
|
testID: "native-resource-page-list",
|
|
753
761
|
data: items,
|
|
754
|
-
keyExtractor,
|
|
762
|
+
keyExtractor: keyExtractor2,
|
|
755
763
|
renderItem: renderFlatListItem,
|
|
756
764
|
ListHeaderComponent,
|
|
757
765
|
ListEmptyComponent,
|
|
@@ -790,6 +798,1046 @@ function NativeResourcePage({
|
|
|
790
798
|
] });
|
|
791
799
|
}
|
|
792
800
|
|
|
793
|
-
|
|
801
|
+
// src/data/resource-view/messages.ts
|
|
802
|
+
var defaultNativeResourceViewMessages = {
|
|
803
|
+
common: {
|
|
804
|
+
empty: "\u2014",
|
|
805
|
+
yes: "Yes",
|
|
806
|
+
no: "No",
|
|
807
|
+
cancel: "Cancel",
|
|
808
|
+
save: "Save",
|
|
809
|
+
edit: "Edit",
|
|
810
|
+
close: "Close",
|
|
811
|
+
create: "New {noun}",
|
|
812
|
+
editTitle: "Edit {noun}",
|
|
813
|
+
search: "Search {nounPlural}"
|
|
814
|
+
},
|
|
815
|
+
delete: {
|
|
816
|
+
action: "Delete",
|
|
817
|
+
confirmTitle: "Delete \u201C{name}\u201D?",
|
|
818
|
+
confirmBody: "This can't be undone."
|
|
819
|
+
},
|
|
820
|
+
bin: {
|
|
821
|
+
action: "Move to Bin",
|
|
822
|
+
confirmTitle: "Move \u201C{name}\u201D to the bin?",
|
|
823
|
+
confirmBody: "You can restore it from the bin."
|
|
824
|
+
},
|
|
825
|
+
list: {
|
|
826
|
+
emptyTitle: "No {nounPlural} yet",
|
|
827
|
+
emptyBody: "When there are some, they show up here.",
|
|
828
|
+
noResultsTitle: "No results",
|
|
829
|
+
noResultsBody: "Try a different search.",
|
|
830
|
+
loadingMore: "Loading more",
|
|
831
|
+
loadFailed: "These {nounPlural} couldn't be loaded.",
|
|
832
|
+
retry: "Try again",
|
|
833
|
+
noGroup: "No {label}"
|
|
834
|
+
},
|
|
835
|
+
form: {
|
|
836
|
+
required: "{label} is required.",
|
|
837
|
+
tooLong: "{label} can be at most {max} characters.",
|
|
838
|
+
saveFailed: "This {noun} couldn't be saved. Try again.",
|
|
839
|
+
pickDate: "Add a date",
|
|
840
|
+
pickDateTime: "Add a date and time",
|
|
841
|
+
clear: "Clear {label}",
|
|
842
|
+
loading: "Loading"
|
|
843
|
+
},
|
|
844
|
+
refusal: {
|
|
845
|
+
deleteFailed: "This {noun} couldn't be deleted. Try again.",
|
|
846
|
+
dismiss: "Dismiss"
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
function fill(template, values) {
|
|
850
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => key in values ? String(values[key]) : match);
|
|
851
|
+
}
|
|
852
|
+
var isEmptyValue = (value) => value === null || value === void 0 || value === "";
|
|
853
|
+
var NUMBER = new Intl.NumberFormat();
|
|
854
|
+
var DECIMAL = new Intl.NumberFormat(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
855
|
+
var PERCENT = new Intl.NumberFormat(void 0, { style: "percent", maximumFractionDigits: 1 });
|
|
856
|
+
var DAY = new Intl.DateTimeFormat(void 0, { dateStyle: "medium" });
|
|
857
|
+
function numeric(value, format) {
|
|
858
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
859
|
+
return Number.isFinite(n) ? format.format(n) : String(value);
|
|
860
|
+
}
|
|
861
|
+
var DAY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
862
|
+
function dayToDate(value) {
|
|
863
|
+
const day = typeof value === "string" ? DAY_PATTERN.exec(value) : null;
|
|
864
|
+
if (!day) return null;
|
|
865
|
+
return new Date(Number(day[1]), Number(day[2]) - 1, Number(day[3]));
|
|
866
|
+
}
|
|
867
|
+
function dateToDay(date) {
|
|
868
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
869
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
870
|
+
}
|
|
871
|
+
function formatDay(value) {
|
|
872
|
+
const date = dayToDate(value);
|
|
873
|
+
return date ? DAY.format(date) : String(value);
|
|
874
|
+
}
|
|
875
|
+
function resolveZone(zone, zones) {
|
|
876
|
+
if (!zone || zone === "viewer") return zones.viewer;
|
|
877
|
+
if (zone === "practice") return zones.practice;
|
|
878
|
+
return isTimeZone(zone) ? zone : zones.viewer;
|
|
879
|
+
}
|
|
880
|
+
var WALL = new Intl.DateTimeFormat(void 0, { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" });
|
|
881
|
+
function formatInstant(value, zone) {
|
|
882
|
+
const at = new Date(String(value));
|
|
883
|
+
if (Number.isNaN(at.getTime()) || !isTimeZone(zone)) return String(value);
|
|
884
|
+
const wall = wallClock(zone, at);
|
|
885
|
+
return WALL.format(new Date(Date.UTC(wall.year, wall.month - 1, wall.day, wall.hour, wall.minute, wall.second)));
|
|
886
|
+
}
|
|
887
|
+
function openableUrl(value) {
|
|
888
|
+
if (!isSafeUrl(value)) return null;
|
|
889
|
+
const url = value.trim();
|
|
890
|
+
return /^(https?:|mailto:|tel:)/i.test(url) ? url : null;
|
|
891
|
+
}
|
|
892
|
+
function displayText(hint, value, messages, timeZone = personTimeZone()) {
|
|
893
|
+
if (isEmptyValue(value)) return messages.common.empty;
|
|
894
|
+
switch (hint) {
|
|
895
|
+
case "number":
|
|
896
|
+
return numeric(value, NUMBER);
|
|
897
|
+
case "currency":
|
|
898
|
+
return numeric(value, DECIMAL);
|
|
899
|
+
case "percent":
|
|
900
|
+
return numeric(value, PERCENT);
|
|
901
|
+
case "boolean":
|
|
902
|
+
return value === true || value === "true" ? messages.common.yes : messages.common.no;
|
|
903
|
+
case "badge":
|
|
904
|
+
return titleCase(String(value));
|
|
905
|
+
case "date":
|
|
906
|
+
return formatDay(value);
|
|
907
|
+
case "datetime":
|
|
908
|
+
return formatInstant(value, timeZone);
|
|
909
|
+
case "url": {
|
|
910
|
+
const url = openableUrl(value);
|
|
911
|
+
return url ? url.replace(/^https?:\/\//i, "") : String(value);
|
|
912
|
+
}
|
|
913
|
+
case "json":
|
|
914
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
915
|
+
default:
|
|
916
|
+
return typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
var BADGE_VARIANT = {
|
|
920
|
+
success: "success",
|
|
921
|
+
warning: "warning",
|
|
922
|
+
danger: "destructive",
|
|
923
|
+
info: "info",
|
|
924
|
+
muted: "muted"
|
|
925
|
+
};
|
|
926
|
+
function badgeVariant(tone) {
|
|
927
|
+
return BADGE_VARIANT[tone ?? "muted"];
|
|
928
|
+
}
|
|
929
|
+
function LinkText({ url, label }) {
|
|
930
|
+
return /* @__PURE__ */ jsx(
|
|
931
|
+
Text,
|
|
932
|
+
{
|
|
933
|
+
accessibilityRole: "link",
|
|
934
|
+
className: "text-base text-primary underline",
|
|
935
|
+
onPress: () => void Linking.openURL(url),
|
|
936
|
+
children: label
|
|
937
|
+
}
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
var text = (hint) => (value, { messages, column, zones }) => /* @__PURE__ */ jsx(NativeText, { preset: "body", children: displayText(hint, value, messages, resolveZone(column.timeZone, zones)) });
|
|
941
|
+
var nativeDisplayRenderers = {
|
|
942
|
+
text: text("text"),
|
|
943
|
+
longText: (value) => /* @__PURE__ */ jsx(NativeText, { preset: "body", numberOfLines: 3, children: String(value) }),
|
|
944
|
+
number: text("number"),
|
|
945
|
+
currency: text("currency"),
|
|
946
|
+
percent: text("percent"),
|
|
947
|
+
boolean: text("boolean"),
|
|
948
|
+
badge: (value, { column }) => /* @__PURE__ */ jsx(NativeBadge, { variant: badgeVariant(column.tones?.[String(value)]), children: titleCase(String(value)) }),
|
|
949
|
+
date: text("date"),
|
|
950
|
+
datetime: text("datetime"),
|
|
951
|
+
// The linked row's id until relation labels arrive (batched per page, never per row).
|
|
952
|
+
relation: text("relation"),
|
|
953
|
+
url: (value, { messages }) => {
|
|
954
|
+
const url = openableUrl(value);
|
|
955
|
+
return url && /^https?:/i.test(url) ? /* @__PURE__ */ jsx(LinkText, { url, label: displayText("url", value, messages) }) : /* @__PURE__ */ jsx(NativeText, { preset: "body", children: String(value) });
|
|
956
|
+
},
|
|
957
|
+
email: (value) => {
|
|
958
|
+
const address = String(value).trim();
|
|
959
|
+
const url = /^[^\s@?&#/]+@[^\s@?&#/]+$/.test(address) ? openableUrl(`mailto:${address}`) : null;
|
|
960
|
+
return url ? /* @__PURE__ */ jsx(LinkText, { url, label: address }) : /* @__PURE__ */ jsx(NativeText, { preset: "body", children: address });
|
|
961
|
+
},
|
|
962
|
+
image: (value) => {
|
|
963
|
+
const url = openableUrl(value);
|
|
964
|
+
return url && /^https?:/i.test(url) ? /* @__PURE__ */ jsx(NativeImage, { src: url, width: 64, height: 64, className: "rounded-md" }) : /* @__PURE__ */ jsx(NativeText, { preset: "body", children: String(value) });
|
|
965
|
+
},
|
|
966
|
+
json: (value) => /* @__PURE__ */ jsx(NativeText, { preset: "caption", numberOfLines: 2, children: typeof value === "string" ? value : JSON.stringify(value) })
|
|
967
|
+
};
|
|
968
|
+
var DisplayRenderersContext = createContext(nativeDisplayRenderers);
|
|
969
|
+
var MessagesContext = createContext(defaultNativeResourceViewMessages);
|
|
970
|
+
var TimeZonesContext = createContext(null);
|
|
971
|
+
var DisplayTimeZonesProvider = TimeZonesContext.Provider;
|
|
972
|
+
function useDisplayTimeZones() {
|
|
973
|
+
const zones = useContext(TimeZonesContext);
|
|
974
|
+
return useMemo(() => zones ?? { viewer: personTimeZone(), practice: personTimeZone() }, [zones]);
|
|
975
|
+
}
|
|
976
|
+
function DisplayRenderersProvider({
|
|
977
|
+
renderers,
|
|
978
|
+
children
|
|
979
|
+
}) {
|
|
980
|
+
const parent = useContext(DisplayRenderersContext);
|
|
981
|
+
const value = useMemo(() => ({ ...parent, ...renderers }), [parent, renderers]);
|
|
982
|
+
return /* @__PURE__ */ jsx(DisplayRenderersContext.Provider, { value, children });
|
|
983
|
+
}
|
|
984
|
+
var NativeResourceViewMessagesProvider = MessagesContext.Provider;
|
|
985
|
+
function useNativeResourceViewMessages() {
|
|
986
|
+
return useContext(MessagesContext);
|
|
987
|
+
}
|
|
988
|
+
function useDisplayCell() {
|
|
989
|
+
const renderers = useContext(DisplayRenderersContext);
|
|
990
|
+
const messages = useNativeResourceViewMessages();
|
|
991
|
+
const zones = useDisplayTimeZones();
|
|
992
|
+
return useMemo(
|
|
993
|
+
() => (column, row) => {
|
|
994
|
+
if (column.when && !column.when(row)) return /* @__PURE__ */ jsx(NativeText, { preset: "body", children: messages.common.empty });
|
|
995
|
+
const value = column.value(row);
|
|
996
|
+
if (isEmptyValue(value)) return /* @__PURE__ */ jsx(NativeText, { preset: "body", children: messages.common.empty });
|
|
997
|
+
return renderers[column.display](value, { row, column, messages, zones });
|
|
998
|
+
},
|
|
999
|
+
[renderers, messages, zones]
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
1002
|
+
function nativePicture(summary) {
|
|
1003
|
+
const picture = rowPicture(summary);
|
|
1004
|
+
if (picture?.kind === "image" && !/^https?:/i.test(picture.src)) {
|
|
1005
|
+
return picture.fallback ? { kind: "initials", text: picture.fallback } : null;
|
|
1006
|
+
}
|
|
1007
|
+
return picture;
|
|
1008
|
+
}
|
|
1009
|
+
function rowItem(view, row) {
|
|
1010
|
+
const summary = view.summary(row);
|
|
1011
|
+
return {
|
|
1012
|
+
id: String(row.id ?? summary.title),
|
|
1013
|
+
title: summary.title,
|
|
1014
|
+
...summary.subtitle ? { subtitle: summary.subtitle } : {},
|
|
1015
|
+
chips: summary.chips ?? [],
|
|
1016
|
+
picture: nativePicture(summary)
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
function sectionsFor(view, rows, messages) {
|
|
1020
|
+
const field = view.definition.groupBy;
|
|
1021
|
+
if (!field) return rows.length ? [{ key: "", title: "", data: [...rows] }] : [];
|
|
1022
|
+
const display = view.display(field);
|
|
1023
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1024
|
+
for (const row of rows) {
|
|
1025
|
+
const value = row[field];
|
|
1026
|
+
const key = isEmptyValue(value) ? "\0" : String(value);
|
|
1027
|
+
let group = groups.get(key);
|
|
1028
|
+
if (!group) {
|
|
1029
|
+
const title = isEmptyValue(value) ? fill(messages.list.noGroup, { label: view.label(field).toLowerCase() }) : displayText(display, value, messages);
|
|
1030
|
+
group = { key, title, data: [] };
|
|
1031
|
+
groups.set(key, group);
|
|
1032
|
+
}
|
|
1033
|
+
group.data.push(row);
|
|
1034
|
+
}
|
|
1035
|
+
return [...groups.values()];
|
|
1036
|
+
}
|
|
1037
|
+
function allowed(view, action, row, screen) {
|
|
1038
|
+
const own = screen?.(action, row);
|
|
1039
|
+
if (own === false) return false;
|
|
1040
|
+
if (typeof own === "string") return own;
|
|
1041
|
+
const guard = action === "create" ? view.can("create") : row ? view.can(action, row) : true;
|
|
1042
|
+
return guard;
|
|
1043
|
+
}
|
|
1044
|
+
function swipeActionsFor(view, row, options) {
|
|
1045
|
+
const { messages, softDelete, editable, screen, onEdit, onDelete, onRefused } = options;
|
|
1046
|
+
const actions = [];
|
|
1047
|
+
const add = (id, label, icon, right, run, destructive = false) => {
|
|
1048
|
+
if (right === false) return;
|
|
1049
|
+
const reason = right === true ? void 0 : right;
|
|
1050
|
+
actions.push({
|
|
1051
|
+
id,
|
|
1052
|
+
label,
|
|
1053
|
+
icon,
|
|
1054
|
+
...destructive ? { destructive } : {},
|
|
1055
|
+
...reason ? { reason } : {},
|
|
1056
|
+
onPress: reason ? () => onRefused(label, reason) : run
|
|
1057
|
+
});
|
|
1058
|
+
};
|
|
1059
|
+
if (editable) add("edit", messages.common.edit, "edit", allowed(view, "update", row, screen), () => onEdit(row));
|
|
1060
|
+
add(
|
|
1061
|
+
"delete",
|
|
1062
|
+
softDelete ? messages.bin.action : messages.delete.action,
|
|
1063
|
+
"trash",
|
|
1064
|
+
allowed(view, "delete", row, screen),
|
|
1065
|
+
() => onDelete(row),
|
|
1066
|
+
true
|
|
1067
|
+
);
|
|
1068
|
+
return actions;
|
|
1069
|
+
}
|
|
1070
|
+
var SEGMENTED_MAX = 4;
|
|
1071
|
+
function kindFor(display, options) {
|
|
1072
|
+
if (options) return options.length <= SEGMENTED_MAX ? "segmented" : "select";
|
|
1073
|
+
switch (display) {
|
|
1074
|
+
case "boolean":
|
|
1075
|
+
return "switch";
|
|
1076
|
+
case "date":
|
|
1077
|
+
return "date";
|
|
1078
|
+
case "datetime":
|
|
1079
|
+
return "datetime";
|
|
1080
|
+
case "number":
|
|
1081
|
+
case "currency":
|
|
1082
|
+
case "percent":
|
|
1083
|
+
return "number";
|
|
1084
|
+
case "longText":
|
|
1085
|
+
return "textarea";
|
|
1086
|
+
case "email":
|
|
1087
|
+
return "email";
|
|
1088
|
+
case "url":
|
|
1089
|
+
case "image":
|
|
1090
|
+
return "url";
|
|
1091
|
+
default:
|
|
1092
|
+
return "text";
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
function formFieldsFor(view, mode) {
|
|
1096
|
+
const writable = new Set(view.writable(mode));
|
|
1097
|
+
return view.form(mode).filter((f) => f.display !== "json" && !f.field.array).filter((f) => mode === "edit" || writable.has(f.field.name)).map((f) => {
|
|
1098
|
+
const options = f.field.enumValues?.map((value) => ({ value, label: displayText("badge", value, EMPTY_WORDS) }));
|
|
1099
|
+
const readOnly = !writable.has(f.field.name);
|
|
1100
|
+
return {
|
|
1101
|
+
key: f.field.name,
|
|
1102
|
+
label: f.label,
|
|
1103
|
+
kind: kindFor(f.display, options),
|
|
1104
|
+
display: f.display,
|
|
1105
|
+
required: !readOnly && f.required,
|
|
1106
|
+
readOnly,
|
|
1107
|
+
...f.max !== void 0 ? { max: f.max } : {},
|
|
1108
|
+
...options ? { options } : {},
|
|
1109
|
+
section: f.section,
|
|
1110
|
+
sectionTitle: f.sectionTitle,
|
|
1111
|
+
...f.visible ? { visible: f.visible } : {}
|
|
1112
|
+
};
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
var EMPTY_WORDS = { common: { empty: "", yes: "", no: "" } };
|
|
1116
|
+
function shownFields(fields, values) {
|
|
1117
|
+
return fields.filter((f) => !f.visible || f.visible(values));
|
|
1118
|
+
}
|
|
1119
|
+
function writableValues(view, mode, fields, values, dirty) {
|
|
1120
|
+
const writable = new Set(view.writable(mode));
|
|
1121
|
+
const out = {};
|
|
1122
|
+
for (const field of shownFields(fields, values)) {
|
|
1123
|
+
if (field.readOnly || !writable.has(field.key)) continue;
|
|
1124
|
+
if (dirty && !dirty.has(field.key)) continue;
|
|
1125
|
+
const value = values[field.key];
|
|
1126
|
+
out[field.key] = (value === "" || value === void 0) && !field.required ? null : value;
|
|
1127
|
+
}
|
|
1128
|
+
return out;
|
|
1129
|
+
}
|
|
1130
|
+
function validateValues(fields, values, messages) {
|
|
1131
|
+
const errors = {};
|
|
1132
|
+
for (const field of shownFields(fields, values)) {
|
|
1133
|
+
if (field.readOnly) continue;
|
|
1134
|
+
const value = values[field.key];
|
|
1135
|
+
if (field.required && field.kind !== "switch" && (isEmptyValue(value) || typeof value === "string" && !value.trim())) {
|
|
1136
|
+
errors[field.key] = fill(messages.form.required, { label: field.label });
|
|
1137
|
+
} else if (field.max !== void 0 && typeof value === "string" && value.length > field.max) {
|
|
1138
|
+
errors[field.key] = fill(messages.form.tooLong, { label: field.label, max: field.max });
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
return errors;
|
|
1142
|
+
}
|
|
1143
|
+
function refusalMessage(error, fallback) {
|
|
1144
|
+
if (error instanceof Error && error.name === "DataWriteError" && error.message) return error.message;
|
|
1145
|
+
return fallback;
|
|
1146
|
+
}
|
|
1147
|
+
function refusalFields(error) {
|
|
1148
|
+
if (error instanceof Error && error.name === "DataWriteError") {
|
|
1149
|
+
const fields = error.fields;
|
|
1150
|
+
if (fields) return { ...fields };
|
|
1151
|
+
}
|
|
1152
|
+
return {};
|
|
1153
|
+
}
|
|
1154
|
+
var FIELD_TYPE = {
|
|
1155
|
+
text: "text",
|
|
1156
|
+
email: "email",
|
|
1157
|
+
url: "url",
|
|
1158
|
+
number: "number",
|
|
1159
|
+
textarea: "textarea",
|
|
1160
|
+
switch: "switch",
|
|
1161
|
+
select: "select"
|
|
1162
|
+
};
|
|
1163
|
+
function sameValue(a, b) {
|
|
1164
|
+
const empty = (v) => v === "" || v === null || v === void 0;
|
|
1165
|
+
if (empty(a) && empty(b)) return true;
|
|
1166
|
+
return a === b || JSON.stringify(a) === JSON.stringify(b);
|
|
1167
|
+
}
|
|
1168
|
+
function startValues(fields, initial) {
|
|
1169
|
+
const values = {};
|
|
1170
|
+
for (const field of fields) {
|
|
1171
|
+
const value = initial?.[field.key];
|
|
1172
|
+
values[field.key] = value ?? (field.kind === "switch" ? false : "");
|
|
1173
|
+
}
|
|
1174
|
+
return values;
|
|
1175
|
+
}
|
|
1176
|
+
function NativeResourceFormSheet({
|
|
1177
|
+
open,
|
|
1178
|
+
mode,
|
|
1179
|
+
title,
|
|
1180
|
+
fields,
|
|
1181
|
+
initial,
|
|
1182
|
+
loading = false,
|
|
1183
|
+
recordKey,
|
|
1184
|
+
onCancel,
|
|
1185
|
+
onSave,
|
|
1186
|
+
testID = "native-resource-form"
|
|
1187
|
+
}) {
|
|
1188
|
+
const messages = useNativeResourceViewMessages();
|
|
1189
|
+
const defaults = useMemo(() => startValues(fields, initial), [fields, initial]);
|
|
1190
|
+
const form = useForm({ defaultValues: defaults });
|
|
1191
|
+
const [saving, setSaving] = useState(false);
|
|
1192
|
+
const [refusal, setRefusal] = useState(null);
|
|
1193
|
+
const latest = useRef(defaults);
|
|
1194
|
+
latest.current = defaults;
|
|
1195
|
+
const start = useRef(defaults);
|
|
1196
|
+
useEffect(() => {
|
|
1197
|
+
if (open && !loading) {
|
|
1198
|
+
start.current = latest.current;
|
|
1199
|
+
form.reset(start.current);
|
|
1200
|
+
setRefusal(null);
|
|
1201
|
+
}
|
|
1202
|
+
}, [open, loading, recordKey, form]);
|
|
1203
|
+
const values = form.watch();
|
|
1204
|
+
const sections = useMemo(() => {
|
|
1205
|
+
const out = [];
|
|
1206
|
+
for (const field of shownFields(fields, values)) {
|
|
1207
|
+
const last = out[out.length - 1];
|
|
1208
|
+
if (last && last.key === (field.section ?? "")) last.fields.push(field);
|
|
1209
|
+
else out.push({ key: field.section ?? "", title: field.sectionTitle, fields: [field] });
|
|
1210
|
+
}
|
|
1211
|
+
return out;
|
|
1212
|
+
}, [fields, values]);
|
|
1213
|
+
const submit = async () => {
|
|
1214
|
+
setSaving(true);
|
|
1215
|
+
setRefusal(null);
|
|
1216
|
+
form.clearErrors();
|
|
1217
|
+
try {
|
|
1218
|
+
const now = form.getValues();
|
|
1219
|
+
const from = start.current;
|
|
1220
|
+
const dirty = new Set(fields.map((f) => f.key).filter((key) => !sameValue(now[key], from[key])));
|
|
1221
|
+
const result = await onSave(now, dirty);
|
|
1222
|
+
if (result.ok) return;
|
|
1223
|
+
for (const [key, message] of Object.entries(result.fields)) form.setError(key, { type: "server", message });
|
|
1224
|
+
if (result.message) setRefusal(result.message);
|
|
1225
|
+
} finally {
|
|
1226
|
+
setSaving(false);
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
return /* @__PURE__ */ jsxs(NativeSheet, { open, onOpenChange: (next) => next ? void 0 : onCancel(), testID, children: [
|
|
1230
|
+
/* @__PURE__ */ jsxs(
|
|
1231
|
+
View,
|
|
1232
|
+
{
|
|
1233
|
+
testID: `${testID}-bar`,
|
|
1234
|
+
style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", paddingHorizontal: 8, paddingVertical: 4 },
|
|
1235
|
+
children: [
|
|
1236
|
+
/* @__PURE__ */ jsx(
|
|
1237
|
+
Pressable,
|
|
1238
|
+
{
|
|
1239
|
+
testID: `${testID}-cancel`,
|
|
1240
|
+
accessibilityRole: "button",
|
|
1241
|
+
accessibilityLabel: messages.common.cancel,
|
|
1242
|
+
onPress: onCancel,
|
|
1243
|
+
hitSlop: 8,
|
|
1244
|
+
className: "min-h-[44px] justify-center px-3",
|
|
1245
|
+
children: /* @__PURE__ */ jsx(Text, { className: "text-base text-primary", children: messages.common.cancel })
|
|
1246
|
+
}
|
|
1247
|
+
),
|
|
1248
|
+
/* @__PURE__ */ jsx(NativeText, { preset: "body", accessibilityRole: "header", className: "font-semibold", numberOfLines: 1, children: title }),
|
|
1249
|
+
/* @__PURE__ */ jsx(
|
|
1250
|
+
NavBarSaveButton,
|
|
1251
|
+
{
|
|
1252
|
+
testID: `${testID}-save`,
|
|
1253
|
+
label: messages.common.save,
|
|
1254
|
+
loading: saving,
|
|
1255
|
+
disabled: loading,
|
|
1256
|
+
onPress: () => void submit()
|
|
1257
|
+
}
|
|
1258
|
+
)
|
|
1259
|
+
]
|
|
1260
|
+
}
|
|
1261
|
+
),
|
|
1262
|
+
/* @__PURE__ */ jsxs(NativeSheetScrollView, { contentContainerStyle: { padding: 16, gap: 20 }, keyboardShouldPersistTaps: "handled", children: [
|
|
1263
|
+
loading ? /* @__PURE__ */ jsx(NativeLoadingState, { fullScreen: false, label: messages.form.loading, testID: `${testID}-loading` }) : null,
|
|
1264
|
+
refusal ? /* @__PURE__ */ jsx(NativeInlineAlert, { testID: `${testID}-refusal`, variant: "destructive", description: refusal }) : null,
|
|
1265
|
+
loading ? null : sections.map((section, index) => /* @__PURE__ */ jsxs(View, { testID: `${testID}-section-${section.key || "main"}`, style: { gap: 12 }, children: [
|
|
1266
|
+
section.title ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", accessibilityRole: "header", className: "uppercase text-muted-foreground", children: section.title }) : null,
|
|
1267
|
+
section.fields.map((field) => /* @__PURE__ */ jsx(FormField, { field, form, mode, testID: `${testID}-field-${field.key}` }, field.key))
|
|
1268
|
+
] }, section.key || `__first_${index}`))
|
|
1269
|
+
] })
|
|
1270
|
+
] });
|
|
1271
|
+
}
|
|
1272
|
+
function FormField({
|
|
1273
|
+
field,
|
|
1274
|
+
form: f,
|
|
1275
|
+
mode: m,
|
|
1276
|
+
testID: id
|
|
1277
|
+
}) {
|
|
1278
|
+
const messages = useNativeResourceViewMessages();
|
|
1279
|
+
const zones = useDisplayTimeZones();
|
|
1280
|
+
const error = f.formState.errors[field.key]?.message;
|
|
1281
|
+
if (field.readOnly) {
|
|
1282
|
+
const shown = displayText(field.display, f.getValues(field.key), messages, resolveZone(void 0, zones));
|
|
1283
|
+
return /* @__PURE__ */ jsxs(View, { testID: id, style: { gap: 4 }, accessibilityLabel: `${field.label}, ${shown}`, children: [
|
|
1284
|
+
/* @__PURE__ */ jsx(NativeLabel, { children: field.label }),
|
|
1285
|
+
/* @__PURE__ */ jsx(NativeText, { testID: `${id}-value`, preset: "body", className: "text-muted-foreground", children: shown })
|
|
1286
|
+
] });
|
|
1287
|
+
}
|
|
1288
|
+
const type = FIELD_TYPE[field.kind];
|
|
1289
|
+
if (type) {
|
|
1290
|
+
const def = {
|
|
1291
|
+
key: field.key,
|
|
1292
|
+
label: field.label,
|
|
1293
|
+
type,
|
|
1294
|
+
required: field.required,
|
|
1295
|
+
...field.options ? { options: field.options } : {},
|
|
1296
|
+
...field.max !== void 0 ? { maxLength: field.max } : {}
|
|
1297
|
+
};
|
|
1298
|
+
return /* @__PURE__ */ jsx(View, { testID: id, children: /* @__PURE__ */ jsx(NativeResourceFormFieldRenderer, { field: def, control: f.control, action: m }) });
|
|
1299
|
+
}
|
|
1300
|
+
return /* @__PURE__ */ jsx(
|
|
1301
|
+
Controller,
|
|
1302
|
+
{
|
|
1303
|
+
name: field.key,
|
|
1304
|
+
control: f.control,
|
|
1305
|
+
render: ({ field: input }) => /* @__PURE__ */ jsxs(View, { testID: id, style: { gap: 6 }, children: [
|
|
1306
|
+
/* @__PURE__ */ jsx(NativeLabel, { children: field.label }),
|
|
1307
|
+
field.kind === "segmented" ? /* @__PURE__ */ jsx(
|
|
1308
|
+
NativeSegmentedControl,
|
|
1309
|
+
{
|
|
1310
|
+
testID: `${id}-segmented`,
|
|
1311
|
+
options: field.options ?? [],
|
|
1312
|
+
value: String(input.value ?? ""),
|
|
1313
|
+
onChange: input.onChange
|
|
1314
|
+
}
|
|
1315
|
+
) : /* @__PURE__ */ jsx(
|
|
1316
|
+
DateField,
|
|
1317
|
+
{
|
|
1318
|
+
kind: field.kind,
|
|
1319
|
+
value: input.value,
|
|
1320
|
+
onChange: input.onChange,
|
|
1321
|
+
clearable: !field.required,
|
|
1322
|
+
label: field.label,
|
|
1323
|
+
testID: id
|
|
1324
|
+
}
|
|
1325
|
+
),
|
|
1326
|
+
error ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-destructive", children: error }) : null
|
|
1327
|
+
] })
|
|
1328
|
+
}
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
function DateField({
|
|
1332
|
+
kind,
|
|
1333
|
+
value,
|
|
1334
|
+
onChange,
|
|
1335
|
+
clearable,
|
|
1336
|
+
label,
|
|
1337
|
+
testID
|
|
1338
|
+
}) {
|
|
1339
|
+
const messages = useNativeResourceViewMessages();
|
|
1340
|
+
const date = kind === "date" ? dayToDate(value) : typeof value === "string" && value ? new Date(value) : null;
|
|
1341
|
+
if (!date || Number.isNaN(date.getTime())) {
|
|
1342
|
+
return /* @__PURE__ */ jsx(
|
|
1343
|
+
NativeButton,
|
|
1344
|
+
{
|
|
1345
|
+
variant: "outline",
|
|
1346
|
+
size: "sm",
|
|
1347
|
+
testID: `${testID}-set`,
|
|
1348
|
+
onPress: () => onChange(kind === "date" ? dateToDay(/* @__PURE__ */ new Date()) : (/* @__PURE__ */ new Date()).toISOString()),
|
|
1349
|
+
children: kind === "date" ? messages.form.pickDate : messages.form.pickDateTime
|
|
1350
|
+
}
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
const set = (next) => onChange(kind === "date" ? dateToDay(next) : next.toISOString());
|
|
1354
|
+
return /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "center", gap: 8 }, children: [
|
|
1355
|
+
/* @__PURE__ */ jsx(NativeDatePicker, { testID: `${testID}-date`, value: date, onChange: set }),
|
|
1356
|
+
kind === "datetime" ? /* @__PURE__ */ jsx(NativeTimePicker, { testID: `${testID}-time`, value: date, onChange: set }) : null,
|
|
1357
|
+
clearable ? /* @__PURE__ */ jsx(NativeButton, { variant: "ghost", size: "sm", testID: `${testID}-clear`, onPress: () => onChange(null), children: fill(messages.form.clear, { label: label.toLowerCase() }) }) : null
|
|
1358
|
+
] });
|
|
1359
|
+
}
|
|
1360
|
+
var SEARCH_DEBOUNCE_MS = 300;
|
|
1361
|
+
function filterParams(filter) {
|
|
1362
|
+
return Object.entries(filter ?? {}).map(
|
|
1363
|
+
([field, value]) => value === null ? { field, operator: "is_null" } : { field, operator: "eq", value }
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
function screenValues(...filters) {
|
|
1367
|
+
const out = {};
|
|
1368
|
+
for (const filter of filters) {
|
|
1369
|
+
for (const [field, value] of Object.entries(filter ?? {})) if (value !== null) out[field] = value;
|
|
1370
|
+
}
|
|
1371
|
+
return out;
|
|
1372
|
+
}
|
|
1373
|
+
var DEFAULT_MAX_PAGES = 10;
|
|
1374
|
+
function serverSort(view) {
|
|
1375
|
+
const groupBy = view.definition.groupBy;
|
|
1376
|
+
const orderBy = view.definition.orderBy;
|
|
1377
|
+
if (groupBy) return { field: groupBy, order: orderBy?.field === groupBy ? orderBy.direction ?? "asc" : "asc" };
|
|
1378
|
+
return orderBy ? { field: orderBy.field, order: orderBy.direction ?? "asc" } : void 0;
|
|
1379
|
+
}
|
|
1380
|
+
function useNativeResourceView(view, options = {}) {
|
|
1381
|
+
const { preset, filter, perPage, maxPages = DEFAULT_MAX_PAGES, searchFields: searchOption, can, live } = options;
|
|
1382
|
+
const messages = useNativeResourceViewMessages();
|
|
1383
|
+
const tab = preset ? view.definition.presets?.[preset] : void 0;
|
|
1384
|
+
if (preset && !tab) throw new Error(`NativeResourceView(${view.resource}): no preset "${preset}"`);
|
|
1385
|
+
const tabFilter = tab?.filter;
|
|
1386
|
+
const defaultFilters = useMemo(() => [...filterParams(tabFilter), ...filterParams(filter)], [tabFilter, filter]);
|
|
1387
|
+
const createKey = JSON.stringify(screenValues(tabFilter, filter));
|
|
1388
|
+
const createDefaults = useMemo(() => JSON.parse(createKey), [createKey]);
|
|
1389
|
+
const sort = useMemo(() => serverSort(view), [view]);
|
|
1390
|
+
const searchFields = useMemo(
|
|
1391
|
+
() => searchOption ?? (view.labelField ? [view.labelField] : void 0),
|
|
1392
|
+
[searchOption, view.labelField]
|
|
1393
|
+
);
|
|
1394
|
+
const pages = useInfiniteResource(view.resource, {
|
|
1395
|
+
defaultFilters,
|
|
1396
|
+
...sort ? { defaultSort: sort } : {},
|
|
1397
|
+
...perPage ? { perPage } : {},
|
|
1398
|
+
maxPages,
|
|
1399
|
+
...searchFields ? { searchFields } : {},
|
|
1400
|
+
keepPreviousData: true,
|
|
1401
|
+
...live ? { live } : {}
|
|
1402
|
+
});
|
|
1403
|
+
const [search, setSearchText] = useState("");
|
|
1404
|
+
const timer = useRef(null);
|
|
1405
|
+
const { setSearch: sendSearch } = pages;
|
|
1406
|
+
const setSearch = useCallback(
|
|
1407
|
+
(text2) => {
|
|
1408
|
+
setSearchText(text2);
|
|
1409
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1410
|
+
timer.current = setTimeout(() => sendSearch(text2), SEARCH_DEBOUNCE_MS);
|
|
1411
|
+
},
|
|
1412
|
+
[sendSearch]
|
|
1413
|
+
);
|
|
1414
|
+
useEffect(() => () => {
|
|
1415
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1416
|
+
}, []);
|
|
1417
|
+
const [refusal, setRefusal] = useState(null);
|
|
1418
|
+
const deleteFailed = fill(messages.refusal.deleteFailed, { noun: view.noun });
|
|
1419
|
+
const optimistic = useResource(view.resource, {
|
|
1420
|
+
enabled: false,
|
|
1421
|
+
mutationMode: "optimistic",
|
|
1422
|
+
// The row is already back in the list (the cache is put back); say why, inline.
|
|
1423
|
+
onError: (error2) => setRefusal(refusalMessage(error2, deleteFailed))
|
|
1424
|
+
});
|
|
1425
|
+
const pessimistic = useResource(view.resource, { enabled: false, onError: () => {
|
|
1426
|
+
} });
|
|
1427
|
+
const capabilities = useCapabilities(view.resource);
|
|
1428
|
+
const softDelete = capabilities.data?.softDelete === true;
|
|
1429
|
+
const formFields = useCallback(
|
|
1430
|
+
(mode) => mode === "create" ? formFieldsFor(view, "create").filter((f) => !(f.key in createDefaults)) : formFieldsFor(view, "edit"),
|
|
1431
|
+
[view, createDefaults]
|
|
1432
|
+
);
|
|
1433
|
+
const editable = useMemo(() => formFieldsFor(view, "edit").some((f) => !f.readOnly), [view]);
|
|
1434
|
+
const canCreate = useMemo(
|
|
1435
|
+
() => formFieldsFor(view, "create").length ? allowed(view, "create", void 0, can) : false,
|
|
1436
|
+
[view, can]
|
|
1437
|
+
);
|
|
1438
|
+
const writers = useRef(pessimistic);
|
|
1439
|
+
writers.current = pessimistic;
|
|
1440
|
+
const save = useCallback(
|
|
1441
|
+
async (mode, values, row, dirty) => {
|
|
1442
|
+
const fields = formFields(mode);
|
|
1443
|
+
const errors = validateValues(fields, values, messages);
|
|
1444
|
+
if (Object.keys(errors).length) return { ok: false, fields: errors };
|
|
1445
|
+
const data = mode === "create" ? { ...writableValues(view, mode, fields, values), ...createDefaults } : writableValues(view, mode, fields, values, dirty);
|
|
1446
|
+
setRefusal(null);
|
|
1447
|
+
if (mode === "edit" && Object.keys(data).length === 0) return { ok: true };
|
|
1448
|
+
try {
|
|
1449
|
+
if (mode === "create") await writers.current.create(data);
|
|
1450
|
+
else await writers.current.update(row.id, data);
|
|
1451
|
+
return { ok: true };
|
|
1452
|
+
} catch (error2) {
|
|
1453
|
+
return {
|
|
1454
|
+
ok: false,
|
|
1455
|
+
message: refusalMessage(error2, fill(messages.form.saveFailed, { noun: view.noun })),
|
|
1456
|
+
fields: refusalFields(error2)
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
},
|
|
1460
|
+
[view, messages, createDefaults, formFields]
|
|
1461
|
+
);
|
|
1462
|
+
const removeRow = useRef(optimistic.remove);
|
|
1463
|
+
removeRow.current = optimistic.remove;
|
|
1464
|
+
const remove = useCallback((row) => {
|
|
1465
|
+
setRefusal(null);
|
|
1466
|
+
removeRow.current(row.id).catch(() => {
|
|
1467
|
+
});
|
|
1468
|
+
}, []);
|
|
1469
|
+
const item = useCallback((row) => rowItem(view, row), [view]);
|
|
1470
|
+
const actions = useCallback(
|
|
1471
|
+
(row, handlers) => swipeActionsFor(view, row, { messages, softDelete, editable, screen: can, ...handlers }),
|
|
1472
|
+
[view, messages, softDelete, editable, can]
|
|
1473
|
+
);
|
|
1474
|
+
const sections = useMemo(() => sectionsFor(view, pages.rows, messages), [view, pages.rows, messages]);
|
|
1475
|
+
const { query } = pages;
|
|
1476
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
1477
|
+
const refresh = useCallback(async () => {
|
|
1478
|
+
setRefreshing(true);
|
|
1479
|
+
try {
|
|
1480
|
+
await query.refetch();
|
|
1481
|
+
} finally {
|
|
1482
|
+
setRefreshing(false);
|
|
1483
|
+
}
|
|
1484
|
+
}, [query]);
|
|
1485
|
+
const error = query.isError ? query.error?.name === "DataReadError" && query.error.message ? query.error.message : fill(messages.list.loadFailed, { nounPlural: view.nounPlural }) : null;
|
|
1486
|
+
return {
|
|
1487
|
+
rows: pages.rows,
|
|
1488
|
+
sections,
|
|
1489
|
+
total: pages.total,
|
|
1490
|
+
loading: query.isLoading,
|
|
1491
|
+
error,
|
|
1492
|
+
refreshing,
|
|
1493
|
+
refresh,
|
|
1494
|
+
loadMore: pages.fetchNextPage,
|
|
1495
|
+
loadingMore: pages.isFetchingNextPage,
|
|
1496
|
+
hasMore: pages.hasNextPage,
|
|
1497
|
+
loadPrevious: pages.fetchPreviousPage,
|
|
1498
|
+
loadingPrevious: query.isFetchingPreviousPage,
|
|
1499
|
+
hasPrevious: pages.hasPreviousPage,
|
|
1500
|
+
search,
|
|
1501
|
+
setSearch,
|
|
1502
|
+
refusal,
|
|
1503
|
+
dismissRefusal: useCallback(() => setRefusal(null), []),
|
|
1504
|
+
item,
|
|
1505
|
+
actions,
|
|
1506
|
+
canCreate,
|
|
1507
|
+
formFields,
|
|
1508
|
+
save,
|
|
1509
|
+
remove,
|
|
1510
|
+
softDelete
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
var IOS_GROUP_MARGIN = 16;
|
|
1514
|
+
var GROUP_RADIUS = Number.parseFloat(String(Platform.Version)) >= 26 ? 26 : 10;
|
|
1515
|
+
var IOS = Platform.OS === "ios";
|
|
1516
|
+
var keyExtractor = (row) => String(row.id);
|
|
1517
|
+
function NativeResourceView(props) {
|
|
1518
|
+
const scope = useOptionalViewerScope();
|
|
1519
|
+
const viewer = scope?.timeZone;
|
|
1520
|
+
const { practiceTimeZone } = props;
|
|
1521
|
+
const zones = useMemo(() => {
|
|
1522
|
+
const own = personTimeZone({ timeZone: viewer });
|
|
1523
|
+
return { viewer: own, practice: practiceTimeZone && isTimeZone(practiceTimeZone) ? practiceTimeZone : own };
|
|
1524
|
+
}, [viewer, practiceTimeZone]);
|
|
1525
|
+
return /* @__PURE__ */ jsx(DisplayTimeZonesProvider, { value: zones, children: /* @__PURE__ */ jsx(Screen, { ...props }) });
|
|
1526
|
+
}
|
|
1527
|
+
var PICTURE_SIZE = 40;
|
|
1528
|
+
function RowLeading({ picture, testID }) {
|
|
1529
|
+
const [failed, setFailed] = useState(null);
|
|
1530
|
+
if (picture.kind === "image" && failed !== picture.src) {
|
|
1531
|
+
return /* @__PURE__ */ jsx(
|
|
1532
|
+
NativeImage,
|
|
1533
|
+
{
|
|
1534
|
+
testID: `${testID}-image`,
|
|
1535
|
+
src: picture.src,
|
|
1536
|
+
...picture.alt ? { alt: picture.alt } : {},
|
|
1537
|
+
width: PICTURE_SIZE,
|
|
1538
|
+
height: PICTURE_SIZE,
|
|
1539
|
+
className: "rounded-full",
|
|
1540
|
+
onError: () => setFailed(picture.src)
|
|
1541
|
+
}
|
|
1542
|
+
);
|
|
1543
|
+
}
|
|
1544
|
+
const initials = picture.kind === "image" ? picture.fallback : picture.text;
|
|
1545
|
+
if (!initials) return null;
|
|
1546
|
+
return (
|
|
1547
|
+
// The row's label already names it; the letters would only be read twice.
|
|
1548
|
+
/* @__PURE__ */ jsx(View, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", children: /* @__PURE__ */ jsx(NativeAvatar, { testID: `${testID}-initials`, fallback: initials, size: PICTURE_SIZE }) })
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
var ResourceRow = memo(function ResourceRow2({
|
|
1552
|
+
row,
|
|
1553
|
+
first,
|
|
1554
|
+
last,
|
|
1555
|
+
item: itemFor,
|
|
1556
|
+
actions: actionsFor,
|
|
1557
|
+
handlers,
|
|
1558
|
+
onPress,
|
|
1559
|
+
chevron,
|
|
1560
|
+
Swipeable,
|
|
1561
|
+
cancelLabel,
|
|
1562
|
+
surface,
|
|
1563
|
+
separator,
|
|
1564
|
+
testID
|
|
1565
|
+
}) {
|
|
1566
|
+
const item = itemFor(row);
|
|
1567
|
+
const actions = actionsFor(row, handlers);
|
|
1568
|
+
const chip = item.chips[0];
|
|
1569
|
+
const picture = item.picture;
|
|
1570
|
+
const rowTestID = `${testID}-row-${item.id}`;
|
|
1571
|
+
const content = /* @__PURE__ */ jsxs(
|
|
1572
|
+
View,
|
|
1573
|
+
{
|
|
1574
|
+
testID: `${rowTestID}-cell`,
|
|
1575
|
+
style: [
|
|
1576
|
+
{ backgroundColor: surface },
|
|
1577
|
+
IOS ? {
|
|
1578
|
+
marginHorizontal: IOS_GROUP_MARGIN,
|
|
1579
|
+
borderTopLeftRadius: first ? GROUP_RADIUS : 0,
|
|
1580
|
+
borderTopRightRadius: first ? GROUP_RADIUS : 0,
|
|
1581
|
+
borderBottomLeftRadius: last ? GROUP_RADIUS : 0,
|
|
1582
|
+
borderBottomRightRadius: last ? GROUP_RADIUS : 0,
|
|
1583
|
+
overflow: "hidden"
|
|
1584
|
+
} : null
|
|
1585
|
+
],
|
|
1586
|
+
children: [
|
|
1587
|
+
/* @__PURE__ */ jsx(
|
|
1588
|
+
Pressable,
|
|
1589
|
+
{
|
|
1590
|
+
testID: rowTestID,
|
|
1591
|
+
accessibilityRole: "button",
|
|
1592
|
+
accessibilityLabel: [picture?.kind === "image" ? picture.alt : null, item.title, item.subtitle, chip?.label].filter(Boolean).join(", "),
|
|
1593
|
+
accessibilityActions: actions.map((a) => ({ name: a.id, label: a.reason ? `${a.label}: ${a.reason}` : a.label })),
|
|
1594
|
+
onAccessibilityAction: (event) => actions.find((a) => a.id === event.nativeEvent.actionName)?.onPress(),
|
|
1595
|
+
onPress: () => onPress(row),
|
|
1596
|
+
onLongPress: actions.length ? () => showInboxActions(item.title, actions, cancelLabel) : void 0,
|
|
1597
|
+
children: /* @__PURE__ */ jsx(
|
|
1598
|
+
NativeListItem,
|
|
1599
|
+
{
|
|
1600
|
+
testID: `${rowTestID}-item`,
|
|
1601
|
+
title: item.title,
|
|
1602
|
+
subtitle: item.subtitle,
|
|
1603
|
+
leading: picture ? /* @__PURE__ */ jsx(RowLeading, { picture, testID: rowTestID }) : void 0,
|
|
1604
|
+
className: "bg-transparent",
|
|
1605
|
+
trailing: chip ? /* @__PURE__ */ jsx(NativeBadge, { testID: `${rowTestID}-chip`, variant: badgeVariant(chip.tone), children: chip.label }) : void 0,
|
|
1606
|
+
showChevron: chevron
|
|
1607
|
+
}
|
|
1608
|
+
)
|
|
1609
|
+
}
|
|
1610
|
+
),
|
|
1611
|
+
!last ? /* @__PURE__ */ jsx(View, { style: { height: 0.5, marginLeft: 16, backgroundColor: separator } }) : null
|
|
1612
|
+
]
|
|
1613
|
+
}
|
|
1614
|
+
);
|
|
1615
|
+
return actions.length && Swipeable ? /* @__PURE__ */ jsx(Swipeable, { actions, testID: `${rowTestID}-swipe`, children: content }) : content;
|
|
1616
|
+
});
|
|
1617
|
+
function Screen(props) {
|
|
1618
|
+
const {
|
|
1619
|
+
view,
|
|
1620
|
+
title,
|
|
1621
|
+
subtitle,
|
|
1622
|
+
onRowPress,
|
|
1623
|
+
swipeable: Swipeable,
|
|
1624
|
+
header,
|
|
1625
|
+
emptyState,
|
|
1626
|
+
searchable,
|
|
1627
|
+
practiceTimeZone: _zone,
|
|
1628
|
+
testID = "native-resource-view",
|
|
1629
|
+
...options
|
|
1630
|
+
} = props;
|
|
1631
|
+
const state = useNativeResourceView(view, options);
|
|
1632
|
+
const messages = useNativeResourceViewMessages();
|
|
1633
|
+
const colors = useThemeRoles();
|
|
1634
|
+
const cell = useDisplayCell();
|
|
1635
|
+
const [peekId, setPeekId] = useState(null);
|
|
1636
|
+
const [sheet, setSheet] = useState(null);
|
|
1637
|
+
const refused = useCallback((label, reason) => Alert.alert(label, reason), []);
|
|
1638
|
+
const { remove, softDelete, item: itemFor, actions: actionsFor } = state;
|
|
1639
|
+
const confirmDelete = useCallback(
|
|
1640
|
+
(row) => {
|
|
1641
|
+
const name = itemFor(row).title;
|
|
1642
|
+
const words = softDelete ? messages.bin : messages.delete;
|
|
1643
|
+
Alert.alert(fill(words.confirmTitle, { name }), words.confirmBody, [
|
|
1644
|
+
{ text: messages.common.cancel, style: "cancel" },
|
|
1645
|
+
{
|
|
1646
|
+
text: words.action,
|
|
1647
|
+
style: "destructive",
|
|
1648
|
+
onPress: () => {
|
|
1649
|
+
setPeekId(null);
|
|
1650
|
+
remove(row);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
]);
|
|
1654
|
+
},
|
|
1655
|
+
[itemFor, softDelete, messages, remove]
|
|
1656
|
+
);
|
|
1657
|
+
const edit = useCallback((row) => {
|
|
1658
|
+
setPeekId(null);
|
|
1659
|
+
setSheet({ mode: "edit", row });
|
|
1660
|
+
}, []);
|
|
1661
|
+
const handlers = useMemo(() => ({ onEdit: edit, onDelete: confirmDelete, onRefused: refused }), [edit, confirmDelete, refused]);
|
|
1662
|
+
const rowPress = useRef(onRowPress);
|
|
1663
|
+
rowPress.current = onRowPress;
|
|
1664
|
+
const press = useCallback((row) => rowPress.current ? rowPress.current(row) : setPeekId({ row }), []);
|
|
1665
|
+
const chevron = !!onRowPress;
|
|
1666
|
+
const renderItem = useCallback(
|
|
1667
|
+
({ item: row, index, section }) => /* @__PURE__ */ jsx(
|
|
1668
|
+
ResourceRow,
|
|
1669
|
+
{
|
|
1670
|
+
row,
|
|
1671
|
+
first: index === 0,
|
|
1672
|
+
last: index === section.data.length - 1,
|
|
1673
|
+
item: itemFor,
|
|
1674
|
+
actions: actionsFor,
|
|
1675
|
+
handlers,
|
|
1676
|
+
onPress: press,
|
|
1677
|
+
chevron,
|
|
1678
|
+
Swipeable,
|
|
1679
|
+
cancelLabel: messages.common.cancel,
|
|
1680
|
+
surface: colors.surface,
|
|
1681
|
+
separator: colors.separator,
|
|
1682
|
+
testID
|
|
1683
|
+
}
|
|
1684
|
+
),
|
|
1685
|
+
[itemFor, actionsFor, handlers, press, chevron, Swipeable, messages, colors.surface, colors.separator, testID]
|
|
1686
|
+
);
|
|
1687
|
+
const renderSectionHeader = useCallback(
|
|
1688
|
+
({ section }) => section.title ? /* @__PURE__ */ jsx(
|
|
1689
|
+
NativeSectionListHeader,
|
|
1690
|
+
{
|
|
1691
|
+
testID: `${testID}-section-${section.key || "none"}`,
|
|
1692
|
+
title: section.title,
|
|
1693
|
+
className: "border-b-0 bg-transparent pt-4"
|
|
1694
|
+
}
|
|
1695
|
+
) : null,
|
|
1696
|
+
[testID]
|
|
1697
|
+
);
|
|
1698
|
+
const create = () => {
|
|
1699
|
+
if (state.canCreate === true) setSheet({ mode: "create" });
|
|
1700
|
+
else if (typeof state.canCreate === "string") refused(fill(messages.common.create, { noun: view.noun }), state.canCreate);
|
|
1701
|
+
};
|
|
1702
|
+
const showSearch = searchable ?? !!(options.searchFields?.length || view.labelField);
|
|
1703
|
+
const heading = title === false ? null : title ?? view.title;
|
|
1704
|
+
const hasRows = state.rows.length > 0;
|
|
1705
|
+
const listHeader = /* @__PURE__ */ jsxs(View, { style: { paddingHorizontal: 16, paddingTop: 8, paddingBottom: 8, gap: 12 }, children: [
|
|
1706
|
+
heading || state.canCreate !== false ? /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" }, children: [
|
|
1707
|
+
/* @__PURE__ */ jsxs(View, { style: { flex: 1 }, children: [
|
|
1708
|
+
heading ? /* @__PURE__ */ jsx(NativeText, { preset: "h2", accessibilityRole: "header", children: heading }) : null,
|
|
1709
|
+
subtitle ?? view.definition.copy?.subtitle ? /* @__PURE__ */ jsx(NativeText, { preset: "body-sm", className: "text-muted-foreground mt-0.5", children: subtitle ?? view.definition.copy?.subtitle }) : null
|
|
1710
|
+
] }),
|
|
1711
|
+
state.canCreate !== false ? /* @__PURE__ */ jsx(NativeButton, { size: "sm", testID: `${testID}-create`, onPress: create, children: view.definition.copy?.create ?? fill(messages.common.create, { noun: view.noun }) }) : null
|
|
1712
|
+
] }) : null,
|
|
1713
|
+
showSearch ? /* @__PURE__ */ jsx(
|
|
1714
|
+
NativeSearchBar,
|
|
1715
|
+
{
|
|
1716
|
+
testID: `${testID}-search`,
|
|
1717
|
+
value: state.search,
|
|
1718
|
+
onChange: state.setSearch,
|
|
1719
|
+
placeholder: fill(messages.common.search, { nounPlural: view.nounPlural })
|
|
1720
|
+
}
|
|
1721
|
+
) : null,
|
|
1722
|
+
state.error && hasRows ? (
|
|
1723
|
+
// A refetch or the next page failed: keep the rows, say so above them.
|
|
1724
|
+
/* @__PURE__ */ jsxs(View, { testID: `${testID}-read-error`, style: { gap: 8 }, children: [
|
|
1725
|
+
/* @__PURE__ */ jsx(NativeInlineAlert, { variant: "destructive", description: state.error }),
|
|
1726
|
+
/* @__PURE__ */ jsx(NativeButton, { variant: "outline", size: "sm", onPress: () => void state.refresh(), children: messages.list.retry })
|
|
1727
|
+
] })
|
|
1728
|
+
) : null,
|
|
1729
|
+
state.refusal ? /* @__PURE__ */ jsx(
|
|
1730
|
+
NativeInlineAlert,
|
|
1731
|
+
{
|
|
1732
|
+
testID: `${testID}-refusal`,
|
|
1733
|
+
variant: "destructive",
|
|
1734
|
+
description: state.refusal,
|
|
1735
|
+
onDismiss: state.dismissRefusal
|
|
1736
|
+
}
|
|
1737
|
+
) : null,
|
|
1738
|
+
header,
|
|
1739
|
+
state.loadingPrevious ? /* @__PURE__ */ jsx(NativeLoadingState, { fullScreen: false, size: "small", label: messages.list.loadingMore, testID: `${testID}-previous` }) : null
|
|
1740
|
+
] });
|
|
1741
|
+
const empty = state.loading ? /* @__PURE__ */ jsx(NativeLoadingState, { fullScreen: false, testID: `${testID}-loading` }) : state.error ? /* @__PURE__ */ jsx(
|
|
1742
|
+
NativeEmptyState,
|
|
1743
|
+
{
|
|
1744
|
+
testID: `${testID}-error`,
|
|
1745
|
+
variant: "error",
|
|
1746
|
+
title: state.error,
|
|
1747
|
+
primaryAction: /* @__PURE__ */ jsx(NativeButton, { variant: "outline", size: "sm", onPress: () => void state.refresh(), children: messages.list.retry })
|
|
1748
|
+
}
|
|
1749
|
+
) : emptyState ?? (state.search ? /* @__PURE__ */ jsx(NativeEmptyState, { testID: `${testID}-empty`, variant: "no-results", title: messages.list.noResultsTitle, body: messages.list.noResultsBody }) : /* @__PURE__ */ jsx(
|
|
1750
|
+
NativeEmptyState,
|
|
1751
|
+
{
|
|
1752
|
+
testID: `${testID}-empty`,
|
|
1753
|
+
title: view.definition.copy?.empty?.title ?? fill(messages.list.emptyTitle, { nounPlural: view.nounPlural }),
|
|
1754
|
+
body: view.definition.copy?.empty?.body ?? messages.list.emptyBody
|
|
1755
|
+
}
|
|
1756
|
+
));
|
|
1757
|
+
const peekRow = useOne(view.resource, peekId ? peekId.row.id : null);
|
|
1758
|
+
const editRow = useOne(view.resource, sheet?.mode === "edit" ? sheet.row.id : null);
|
|
1759
|
+
const peek = peekId ? peekRow.data ?? peekId.row : null;
|
|
1760
|
+
const peekFields = useMemo(
|
|
1761
|
+
() => view.columns().map((column) => ({
|
|
1762
|
+
key: column.key,
|
|
1763
|
+
label: column.label,
|
|
1764
|
+
render: (_value, row) => cell(column, row)
|
|
1765
|
+
})),
|
|
1766
|
+
[view, cell]
|
|
1767
|
+
);
|
|
1768
|
+
const { formFields } = state;
|
|
1769
|
+
const createFields = useMemo(() => formFields("create"), [formFields]);
|
|
1770
|
+
const editFields = useMemo(() => formFields("edit"), [formFields]);
|
|
1771
|
+
const peekActions = peek ? actionsFor(peek, handlers) : [];
|
|
1772
|
+
const editLoading = sheet?.mode === "edit" && editRow.data === void 0 && !editRow.isError;
|
|
1773
|
+
return /* @__PURE__ */ jsxs(SafeAreaView, { testID, edges: ["left", "right", "bottom"], style: { flex: 1, backgroundColor: colors.groupedBackground }, children: [
|
|
1774
|
+
/* @__PURE__ */ jsx(
|
|
1775
|
+
SectionList,
|
|
1776
|
+
{
|
|
1777
|
+
testID: `${testID}-list`,
|
|
1778
|
+
sections: state.sections,
|
|
1779
|
+
keyExtractor,
|
|
1780
|
+
renderItem,
|
|
1781
|
+
renderSectionHeader,
|
|
1782
|
+
extraData: actionsFor,
|
|
1783
|
+
stickySectionHeadersEnabled: false,
|
|
1784
|
+
contentInsetAdjustmentBehavior: "automatic",
|
|
1785
|
+
keyboardShouldPersistTaps: "handled",
|
|
1786
|
+
ListHeaderComponent: listHeader,
|
|
1787
|
+
ListEmptyComponent: empty,
|
|
1788
|
+
ListFooterComponent: state.loadingMore ? /* @__PURE__ */ jsx(NativeLoadingState, { fullScreen: false, size: "small", label: messages.list.loadingMore, testID: `${testID}-more` }) : null,
|
|
1789
|
+
contentContainerStyle: { flexGrow: 1, paddingBottom: 32 },
|
|
1790
|
+
onEndReached: state.hasMore ? state.loadMore : void 0,
|
|
1791
|
+
onEndReachedThreshold: 0.5,
|
|
1792
|
+
onStartReached: state.hasPrevious ? state.loadPrevious : void 0,
|
|
1793
|
+
onStartReachedThreshold: 0.5,
|
|
1794
|
+
maintainVisibleContentPosition: { minIndexForVisible: 0 },
|
|
1795
|
+
refreshControl: /* @__PURE__ */ jsx(NativeRefreshControl, { testID: `${testID}-refresh`, refreshing: state.refreshing, onRefresh: () => void state.refresh() })
|
|
1796
|
+
}
|
|
1797
|
+
),
|
|
1798
|
+
/* @__PURE__ */ jsx(NativeSheet, { open: peek !== null, onOpenChange: (open) => open ? void 0 : setPeekId(null), testID: `${testID}-peek`, children: peek ? /* @__PURE__ */ jsx(
|
|
1799
|
+
NativeDetailPanel,
|
|
1800
|
+
{
|
|
1801
|
+
item: peek,
|
|
1802
|
+
title: itemFor(peek).title,
|
|
1803
|
+
fields: peekFields,
|
|
1804
|
+
footer: peekActions.length ? /* @__PURE__ */ jsx(View, { testID: `${testID}-peek-actions`, style: { gap: 12 }, children: peekActions.map((action) => /* @__PURE__ */ jsxs(View, { style: { gap: 4 }, children: [
|
|
1805
|
+
/* @__PURE__ */ jsx(
|
|
1806
|
+
NativeButton,
|
|
1807
|
+
{
|
|
1808
|
+
testID: `${testID}-peek-${action.id}`,
|
|
1809
|
+
variant: action.destructive ? "destructive" : "outline",
|
|
1810
|
+
className: action.reason ? "opacity-50" : void 0,
|
|
1811
|
+
onPress: action.onPress,
|
|
1812
|
+
children: action.label
|
|
1813
|
+
}
|
|
1814
|
+
),
|
|
1815
|
+
action.reason ? /* @__PURE__ */ jsx(NativeText, { testID: `${testID}-peek-${action.id}-reason`, preset: "caption", className: "text-muted-foreground", children: action.reason }) : null
|
|
1816
|
+
] }, action.id)) }) : null
|
|
1817
|
+
}
|
|
1818
|
+
) : null }),
|
|
1819
|
+
/* @__PURE__ */ jsx(
|
|
1820
|
+
NativeResourceFormSheet,
|
|
1821
|
+
{
|
|
1822
|
+
open: sheet !== null,
|
|
1823
|
+
mode: sheet?.mode ?? "create",
|
|
1824
|
+
title: fill(sheet?.mode === "edit" ? messages.common.editTitle : messages.common.create, { noun: view.noun }),
|
|
1825
|
+
fields: sheet?.mode === "edit" ? editFields : createFields,
|
|
1826
|
+
initial: sheet?.mode === "edit" ? editRow.data ?? (editRow.isError ? sheet.row : void 0) : void 0,
|
|
1827
|
+
loading: editLoading,
|
|
1828
|
+
recordKey: sheet?.row ? String(sheet.row.id) : "new",
|
|
1829
|
+
onCancel: () => setSheet(null),
|
|
1830
|
+
onSave: async (values, dirty) => {
|
|
1831
|
+
const result = await state.save(sheet?.mode ?? "create", values, sheet?.row, dirty);
|
|
1832
|
+
if (result.ok) setSheet(null);
|
|
1833
|
+
return result;
|
|
1834
|
+
},
|
|
1835
|
+
testID: `${testID}-form`
|
|
1836
|
+
}
|
|
1837
|
+
)
|
|
1838
|
+
] });
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
export { DEFAULT_MAX_PAGES, DisplayRenderersProvider, DisplayTimeZonesProvider, NativeDataFilters, NativeDataPageShell, NativeDetailPanel, NativeEmptyState2 as NativeEmptyState, NativeResourceForm, NativeResourceFormFieldRenderer, NativeResourceFormSheet, NativeResourcePage, NativeResourceView, NativeResourceViewMessagesProvider, SEARCH_DEBOUNCE_MS, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, displayText, formFieldsFor, formatDay, formatInstant, nativeDisplayRenderers, openableUrl, resolveZone, rowItem, screenValues, sectionsFor, serverSort, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
|
|
794
1842
|
//# sourceMappingURL=index.js.map
|
|
795
1843
|
//# sourceMappingURL=index.js.map
|