@marktiderman/genesis-ui-native 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-YJV5MMZX.js → chunk-7HWS2JGX.js} +7 -741
- package/dist/chunk-7HWS2JGX.js.map +1 -0
- package/dist/{chunk-IDHW2NOP.js → chunk-C6Q5ZAVT.js} +232 -6
- package/dist/chunk-C6Q5ZAVT.js.map +1 -0
- package/dist/{chunk-YI7XVY2D.js → chunk-ON7WP4T6.js} +13 -479
- package/dist/chunk-ON7WP4T6.js.map +1 -0
- package/dist/chunk-PO3MK6IY.js +1231 -0
- package/dist/chunk-PO3MK6IY.js.map +1 -0
- package/dist/chunk-SXCG2REG.js +479 -0
- package/dist/chunk-SXCG2REG.js.map +1 -0
- package/dist/components/index.d.ts +10 -3
- package/dist/components/index.js +3 -4
- package/dist/data/index.d.ts +482 -4
- package/dist/data/index.js +1480 -17
- package/dist/data/index.js.map +1 -1
- package/dist/inbox-page-DZUR-PJ1.d.ts +199 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -5
- package/dist/layouts/index.d.ts +4 -195
- package/dist/layouts/index.js +3 -3
- package/package.json +2 -2
- package/src/components/__tests__/button-a11y.test.tsx +17 -0
- package/src/components/button.tsx +8 -2
- package/src/components/image.tsx +5 -0
- package/src/data/NativeDetailPanel.tsx +8 -1
- package/src/data/index.ts +1 -0
- package/src/data/resource-view/NativeResourceFormSheet.tsx +305 -0
- package/src/data/resource-view/NativeResourceView.tsx +536 -0
- package/src/data/resource-view/NativeResourceWorkspace.tsx +657 -0
- package/src/data/resource-view/__tests__/native-resource-view.test.tsx +977 -0
- package/src/data/resource-view/__tests__/native-resource-workspace.test.tsx +356 -0
- package/src/data/resource-view/display.tsx +259 -0
- package/src/data/resource-view/index.ts +61 -0
- package/src/data/resource-view/mapping.ts +333 -0
- package/src/data/resource-view/messages.ts +121 -0
- package/src/data/resource-view/use-native-resource-view.ts +309 -0
- package/dist/chunk-EFXCJ5AN.js +0 -234
- package/dist/chunk-EFXCJ5AN.js.map +0 -1
- package/dist/chunk-FIITITXO.js +0 -492
- package/dist/chunk-FIITITXO.js.map +0 -1
- package/dist/chunk-IDHW2NOP.js.map +0 -1
- package/dist/chunk-YI7XVY2D.js.map +0 -1
- package/dist/chunk-YJV5MMZX.js.map +0 -1
package/dist/data/index.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
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-PO3MK6IY.js';
|
|
2
2
|
import '../chunk-7PCWEY6R.js';
|
|
3
|
-
import {
|
|
3
|
+
import { showInboxActions, NavBarSaveButton, composeHeaderOptions } from '../chunk-SXCG2REG.js';
|
|
4
|
+
import { NativeListItem, NativeBadge, NativeText, NativeButton, NativeInput, useGenesisModules, NativeLoadingState, NativeSectionListHeader, NativeEmptyState, NativeRefreshControl, NativeIcon } from '../chunk-C6Q5ZAVT.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, ActionSheetIOS } 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
|
-
import { titleCase, useResourceForm } from '@marktiderman/genesis-core';
|
|
12
|
-
import { Controller } from 'react-hook-form';
|
|
13
|
-
import { useResource } from '@marktiderman/genesis-core/hooks';
|
|
13
|
+
import { titleCase, useResourceForm, resourceKeys, useDataProvider, useViewer as useViewer$1, encodeRecordKey, useCapabilities as useCapabilities$1, DataWriteError } from '@marktiderman/genesis-core';
|
|
14
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
15
|
+
import { useResource, useViewer, 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';
|
|
19
|
+
import { useQueryClient, useQuery } from '@tanstack/react-query';
|
|
20
|
+
import { readinessChip } from '@marktiderman/genesis-core/resource';
|
|
14
21
|
|
|
15
|
-
function
|
|
22
|
+
function NativeEmptyState2({
|
|
16
23
|
message = "No items found",
|
|
17
24
|
action,
|
|
18
25
|
hasFilters = false,
|
|
@@ -125,7 +132,7 @@ function NativeDataPageShell({
|
|
|
125
132
|
if (emptyState) {
|
|
126
133
|
return /* @__PURE__ */ jsx(Fragment, { children: emptyState });
|
|
127
134
|
}
|
|
128
|
-
return /* @__PURE__ */ jsx(
|
|
135
|
+
return /* @__PURE__ */ jsx(NativeEmptyState2, { message: emptyMessage });
|
|
129
136
|
}
|
|
130
137
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
131
138
|
};
|
|
@@ -165,9 +172,11 @@ function NativeDetailPanel({
|
|
|
165
172
|
fields,
|
|
166
173
|
onEdit,
|
|
167
174
|
onDelete,
|
|
175
|
+
title: titleProp,
|
|
176
|
+
footer,
|
|
168
177
|
children
|
|
169
178
|
}) {
|
|
170
|
-
const title = titleField ? String(item[titleField] ?? "") : void 0;
|
|
179
|
+
const title = titleProp ?? (titleField ? String(item[titleField] ?? "") : void 0);
|
|
171
180
|
const hasActions = onEdit != null || onDelete != null;
|
|
172
181
|
if (children) {
|
|
173
182
|
return /* @__PURE__ */ jsx(SafeAreaView, { edges: ["bottom"], style: { flex: 1 }, children: /* @__PURE__ */ jsxs(
|
|
@@ -217,7 +226,8 @@ function NativeDetailPanel({
|
|
|
217
226
|
children: "Delete"
|
|
218
227
|
}
|
|
219
228
|
) : null
|
|
220
|
-
] }) : null
|
|
229
|
+
] }) : null,
|
|
230
|
+
footer
|
|
221
231
|
]
|
|
222
232
|
}
|
|
223
233
|
) });
|
|
@@ -358,12 +368,12 @@ function NativeResourceFormFieldRenderer({
|
|
|
358
368
|
placeholder: field.placeholder,
|
|
359
369
|
keyboardType: "numeric",
|
|
360
370
|
value: f.value != null ? String(f.value) : "",
|
|
361
|
-
onChangeText: (
|
|
362
|
-
if (
|
|
371
|
+
onChangeText: (text2) => {
|
|
372
|
+
if (text2 === "") {
|
|
363
373
|
f.onChange(void 0);
|
|
364
374
|
} else {
|
|
365
|
-
const num = Number(
|
|
366
|
-
f.onChange(Number.isNaN(num) ?
|
|
375
|
+
const num = Number(text2);
|
|
376
|
+
f.onChange(Number.isNaN(num) ? text2 : num);
|
|
367
377
|
}
|
|
368
378
|
},
|
|
369
379
|
editable: !isDisabled,
|
|
@@ -707,7 +717,7 @@ function NativeResourcePage({
|
|
|
707
717
|
// search brings back the saved rows.
|
|
708
718
|
/* @__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
719
|
) : /* @__PURE__ */ jsx(Fragment, { children: emptyState ?? /* @__PURE__ */ jsx(
|
|
710
|
-
|
|
720
|
+
NativeEmptyState2,
|
|
711
721
|
{
|
|
712
722
|
hasFilters: hasActiveFilters,
|
|
713
723
|
onClearFilters: hasActiveFilters ? handleClearFilters : void 0
|
|
@@ -790,6 +800,1459 @@ function NativeResourcePage({
|
|
|
790
800
|
] });
|
|
791
801
|
}
|
|
792
802
|
|
|
793
|
-
|
|
803
|
+
// src/data/resource-view/messages.ts
|
|
804
|
+
var defaultNativeResourceViewMessages = {
|
|
805
|
+
common: {
|
|
806
|
+
empty: "\u2014",
|
|
807
|
+
yes: "Yes",
|
|
808
|
+
no: "No",
|
|
809
|
+
cancel: "Cancel",
|
|
810
|
+
save: "Save",
|
|
811
|
+
edit: "Edit",
|
|
812
|
+
close: "Close",
|
|
813
|
+
create: "New {noun}",
|
|
814
|
+
editTitle: "Edit {noun}",
|
|
815
|
+
search: "Search {nounPlural}"
|
|
816
|
+
},
|
|
817
|
+
delete: {
|
|
818
|
+
action: "Delete",
|
|
819
|
+
confirmTitle: "Delete \u201C{name}\u201D?",
|
|
820
|
+
confirmBody: "This can't be undone."
|
|
821
|
+
},
|
|
822
|
+
bin: {
|
|
823
|
+
action: "Move to Bin",
|
|
824
|
+
confirmTitle: "Move \u201C{name}\u201D to the bin?",
|
|
825
|
+
confirmBody: "You can restore it from the bin."
|
|
826
|
+
},
|
|
827
|
+
list: {
|
|
828
|
+
emptyTitle: "No {nounPlural} yet",
|
|
829
|
+
emptyBody: "When there are some, they show up here.",
|
|
830
|
+
noResultsTitle: "No results",
|
|
831
|
+
noResultsBody: "Try a different search.",
|
|
832
|
+
loadingMore: "Loading more",
|
|
833
|
+
loadFailed: "These {nounPlural} couldn't be loaded.",
|
|
834
|
+
retry: "Try again",
|
|
835
|
+
noGroup: "No {label}"
|
|
836
|
+
},
|
|
837
|
+
form: {
|
|
838
|
+
required: "{label} is required.",
|
|
839
|
+
tooLong: "{label} can be at most {max} characters.",
|
|
840
|
+
saveFailed: "This {noun} couldn't be saved. Try again.",
|
|
841
|
+
pickDate: "Add a date",
|
|
842
|
+
pickDateTime: "Add a date and time",
|
|
843
|
+
clear: "Clear {label}",
|
|
844
|
+
loading: "Loading"
|
|
845
|
+
},
|
|
846
|
+
refusal: {
|
|
847
|
+
deleteFailed: "This {noun} couldn't be deleted. Try again.",
|
|
848
|
+
dismiss: "Dismiss"
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
function fill(template, values) {
|
|
852
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => key in values ? String(values[key]) : match);
|
|
853
|
+
}
|
|
854
|
+
var isEmptyValue = (value) => value === null || value === void 0 || value === "";
|
|
855
|
+
var NUMBER = new Intl.NumberFormat();
|
|
856
|
+
var DECIMAL = new Intl.NumberFormat(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
857
|
+
var PERCENT = new Intl.NumberFormat(void 0, { style: "percent", maximumFractionDigits: 1 });
|
|
858
|
+
var DAY = new Intl.DateTimeFormat(void 0, { dateStyle: "medium" });
|
|
859
|
+
function numeric(value, format) {
|
|
860
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
861
|
+
return Number.isFinite(n) ? format.format(n) : String(value);
|
|
862
|
+
}
|
|
863
|
+
var DAY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
864
|
+
function dayToDate(value) {
|
|
865
|
+
const day = typeof value === "string" ? DAY_PATTERN.exec(value) : null;
|
|
866
|
+
if (!day) return null;
|
|
867
|
+
return new Date(Number(day[1]), Number(day[2]) - 1, Number(day[3]));
|
|
868
|
+
}
|
|
869
|
+
function dateToDay(date) {
|
|
870
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
871
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
872
|
+
}
|
|
873
|
+
function formatDay(value) {
|
|
874
|
+
const date = dayToDate(value);
|
|
875
|
+
return date ? DAY.format(date) : String(value);
|
|
876
|
+
}
|
|
877
|
+
function resolveZone(zone, zones) {
|
|
878
|
+
if (!zone || zone === "viewer") return zones.viewer;
|
|
879
|
+
if (zone === "practice") return zones.practice;
|
|
880
|
+
return isTimeZone(zone) ? zone : zones.viewer;
|
|
881
|
+
}
|
|
882
|
+
var WALL = new Intl.DateTimeFormat(void 0, { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" });
|
|
883
|
+
function formatInstant(value, zone) {
|
|
884
|
+
const at = new Date(String(value));
|
|
885
|
+
if (Number.isNaN(at.getTime()) || !isTimeZone(zone)) return String(value);
|
|
886
|
+
const wall = wallClock(zone, at);
|
|
887
|
+
return WALL.format(new Date(Date.UTC(wall.year, wall.month - 1, wall.day, wall.hour, wall.minute, wall.second)));
|
|
888
|
+
}
|
|
889
|
+
function openableUrl(value) {
|
|
890
|
+
if (!isSafeUrl(value)) return null;
|
|
891
|
+
const url = value.trim();
|
|
892
|
+
return /^(https?:|mailto:|tel:)/i.test(url) ? url : null;
|
|
893
|
+
}
|
|
894
|
+
function displayText(hint, value, messages, timeZone = personTimeZone()) {
|
|
895
|
+
if (isEmptyValue(value)) return messages.common.empty;
|
|
896
|
+
switch (hint) {
|
|
897
|
+
case "number":
|
|
898
|
+
return numeric(value, NUMBER);
|
|
899
|
+
case "currency":
|
|
900
|
+
return numeric(value, DECIMAL);
|
|
901
|
+
case "percent":
|
|
902
|
+
return numeric(value, PERCENT);
|
|
903
|
+
case "boolean":
|
|
904
|
+
return value === true || value === "true" ? messages.common.yes : messages.common.no;
|
|
905
|
+
case "badge":
|
|
906
|
+
return titleCase(String(value));
|
|
907
|
+
case "date":
|
|
908
|
+
return formatDay(value);
|
|
909
|
+
case "datetime":
|
|
910
|
+
return formatInstant(value, timeZone);
|
|
911
|
+
case "url": {
|
|
912
|
+
const url = openableUrl(value);
|
|
913
|
+
return url ? url.replace(/^https?:\/\//i, "") : String(value);
|
|
914
|
+
}
|
|
915
|
+
case "json":
|
|
916
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
917
|
+
default:
|
|
918
|
+
return typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
var BADGE_VARIANT = {
|
|
922
|
+
success: "success",
|
|
923
|
+
warning: "warning",
|
|
924
|
+
danger: "destructive",
|
|
925
|
+
info: "info",
|
|
926
|
+
muted: "muted"
|
|
927
|
+
};
|
|
928
|
+
function badgeVariant(tone) {
|
|
929
|
+
return BADGE_VARIANT[tone ?? "muted"];
|
|
930
|
+
}
|
|
931
|
+
function LinkText({ url, label }) {
|
|
932
|
+
return /* @__PURE__ */ jsx(
|
|
933
|
+
Text,
|
|
934
|
+
{
|
|
935
|
+
accessibilityRole: "link",
|
|
936
|
+
className: "text-base text-primary underline",
|
|
937
|
+
onPress: () => void Linking.openURL(url),
|
|
938
|
+
children: label
|
|
939
|
+
}
|
|
940
|
+
);
|
|
941
|
+
}
|
|
942
|
+
var text = (hint) => (value, { messages, column, zones }) => /* @__PURE__ */ jsx(NativeText, { preset: "body", children: displayText(hint, value, messages, resolveZone(column.timeZone, zones)) });
|
|
943
|
+
var nativeDisplayRenderers = {
|
|
944
|
+
text: text("text"),
|
|
945
|
+
longText: (value) => /* @__PURE__ */ jsx(NativeText, { preset: "body", numberOfLines: 3, children: String(value) }),
|
|
946
|
+
number: text("number"),
|
|
947
|
+
currency: text("currency"),
|
|
948
|
+
percent: text("percent"),
|
|
949
|
+
boolean: text("boolean"),
|
|
950
|
+
badge: (value, { column }) => /* @__PURE__ */ jsx(NativeBadge, { variant: badgeVariant(column.tones?.[String(value)]), children: titleCase(String(value)) }),
|
|
951
|
+
date: text("date"),
|
|
952
|
+
datetime: text("datetime"),
|
|
953
|
+
// The linked row's id until relation labels arrive (batched per page, never per row).
|
|
954
|
+
relation: text("relation"),
|
|
955
|
+
url: (value, { messages }) => {
|
|
956
|
+
const url = openableUrl(value);
|
|
957
|
+
return url && /^https?:/i.test(url) ? /* @__PURE__ */ jsx(LinkText, { url, label: displayText("url", value, messages) }) : /* @__PURE__ */ jsx(NativeText, { preset: "body", children: String(value) });
|
|
958
|
+
},
|
|
959
|
+
email: (value) => {
|
|
960
|
+
const address = String(value).trim();
|
|
961
|
+
const url = /^[^\s@?&#/]+@[^\s@?&#/]+$/.test(address) ? openableUrl(`mailto:${address}`) : null;
|
|
962
|
+
return url ? /* @__PURE__ */ jsx(LinkText, { url, label: address }) : /* @__PURE__ */ jsx(NativeText, { preset: "body", children: address });
|
|
963
|
+
},
|
|
964
|
+
image: (value) => {
|
|
965
|
+
const url = openableUrl(value);
|
|
966
|
+
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) });
|
|
967
|
+
},
|
|
968
|
+
json: (value) => /* @__PURE__ */ jsx(NativeText, { preset: "caption", numberOfLines: 2, children: typeof value === "string" ? value : JSON.stringify(value) })
|
|
969
|
+
};
|
|
970
|
+
var DisplayRenderersContext = createContext(nativeDisplayRenderers);
|
|
971
|
+
var MessagesContext = createContext(defaultNativeResourceViewMessages);
|
|
972
|
+
var TimeZonesContext = createContext(null);
|
|
973
|
+
var DisplayTimeZonesProvider = TimeZonesContext.Provider;
|
|
974
|
+
function useDisplayTimeZones() {
|
|
975
|
+
const zones = useContext(TimeZonesContext);
|
|
976
|
+
return useMemo(() => zones ?? { viewer: personTimeZone(), practice: personTimeZone() }, [zones]);
|
|
977
|
+
}
|
|
978
|
+
function DisplayRenderersProvider({
|
|
979
|
+
renderers,
|
|
980
|
+
children
|
|
981
|
+
}) {
|
|
982
|
+
const parent = useContext(DisplayRenderersContext);
|
|
983
|
+
const value = useMemo(() => ({ ...parent, ...renderers }), [parent, renderers]);
|
|
984
|
+
return /* @__PURE__ */ jsx(DisplayRenderersContext.Provider, { value, children });
|
|
985
|
+
}
|
|
986
|
+
var NativeResourceViewMessagesProvider = MessagesContext.Provider;
|
|
987
|
+
function useNativeResourceViewMessages() {
|
|
988
|
+
return useContext(MessagesContext);
|
|
989
|
+
}
|
|
990
|
+
function useDisplayCell() {
|
|
991
|
+
const renderers = useContext(DisplayRenderersContext);
|
|
992
|
+
const messages = useNativeResourceViewMessages();
|
|
993
|
+
const zones = useDisplayTimeZones();
|
|
994
|
+
const viewer = useViewer();
|
|
995
|
+
return useMemo(
|
|
996
|
+
() => (column, row) => {
|
|
997
|
+
if (column.when && !column.when(row, viewer)) return /* @__PURE__ */ jsx(NativeText, { preset: "body", children: messages.common.empty });
|
|
998
|
+
const value = column.value(row);
|
|
999
|
+
if (isEmptyValue(value)) return /* @__PURE__ */ jsx(NativeText, { preset: "body", children: messages.common.empty });
|
|
1000
|
+
return renderers[column.display](value, { row, column, messages, zones });
|
|
1001
|
+
},
|
|
1002
|
+
[renderers, messages, zones, viewer]
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
function nativePicture(summary) {
|
|
1006
|
+
const picture = rowPicture(summary);
|
|
1007
|
+
if (picture?.kind === "image" && !/^https?:/i.test(picture.src)) {
|
|
1008
|
+
return picture.fallback ? { kind: "initials", text: picture.fallback } : null;
|
|
1009
|
+
}
|
|
1010
|
+
return picture;
|
|
1011
|
+
}
|
|
1012
|
+
function rowItem(view, row) {
|
|
1013
|
+
const summary = view.summary(row);
|
|
1014
|
+
return {
|
|
1015
|
+
id: String(row.id ?? summary.title),
|
|
1016
|
+
title: summary.title,
|
|
1017
|
+
...summary.subtitle ? { subtitle: summary.subtitle } : {},
|
|
1018
|
+
chips: summary.chips ?? [],
|
|
1019
|
+
picture: nativePicture(summary)
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
function sectionsFor(view, rows, messages) {
|
|
1023
|
+
const field = view.definition.groupBy;
|
|
1024
|
+
if (!field) return rows.length ? [{ key: "", title: "", data: [...rows] }] : [];
|
|
1025
|
+
const display = view.display(field);
|
|
1026
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1027
|
+
for (const row of rows) {
|
|
1028
|
+
const value = row[field];
|
|
1029
|
+
const key = isEmptyValue(value) ? "\0" : String(value);
|
|
1030
|
+
let group = groups.get(key);
|
|
1031
|
+
if (!group) {
|
|
1032
|
+
const title = isEmptyValue(value) ? fill(messages.list.noGroup, { label: view.label(field).toLowerCase() }) : displayText(display, value, messages);
|
|
1033
|
+
group = { key, title, data: [] };
|
|
1034
|
+
groups.set(key, group);
|
|
1035
|
+
}
|
|
1036
|
+
group.data.push(row);
|
|
1037
|
+
}
|
|
1038
|
+
return [...groups.values()];
|
|
1039
|
+
}
|
|
1040
|
+
function allowed(view, action, row, screen, viewer) {
|
|
1041
|
+
const own = screen?.(action, row);
|
|
1042
|
+
if (own === false) return false;
|
|
1043
|
+
if (typeof own === "string") return own;
|
|
1044
|
+
const guard = action === "create" ? view.can("create", viewer) : row ? view.can(action, row, viewer) : true;
|
|
1045
|
+
return guard;
|
|
1046
|
+
}
|
|
1047
|
+
function swipeActionsFor(view, row, options) {
|
|
1048
|
+
const { messages, softDelete, editable, screen, viewer, onEdit, onDelete, onRefused } = options;
|
|
1049
|
+
const actions = [];
|
|
1050
|
+
const add = (id, label, icon, right, run, destructive = false) => {
|
|
1051
|
+
if (right === false) return;
|
|
1052
|
+
const reason = right === true ? void 0 : right;
|
|
1053
|
+
actions.push({
|
|
1054
|
+
id,
|
|
1055
|
+
label,
|
|
1056
|
+
icon,
|
|
1057
|
+
...destructive ? { destructive } : {},
|
|
1058
|
+
...reason ? { reason } : {},
|
|
1059
|
+
onPress: reason ? () => onRefused(label, reason) : run
|
|
1060
|
+
});
|
|
1061
|
+
};
|
|
1062
|
+
if (editable) add("edit", messages.common.edit, "edit", allowed(view, "update", row, screen, viewer), () => onEdit(row));
|
|
1063
|
+
add(
|
|
1064
|
+
"delete",
|
|
1065
|
+
softDelete ? messages.bin.action : messages.delete.action,
|
|
1066
|
+
"trash",
|
|
1067
|
+
allowed(view, "delete", row, screen, viewer),
|
|
1068
|
+
() => onDelete(row),
|
|
1069
|
+
true
|
|
1070
|
+
);
|
|
1071
|
+
return actions;
|
|
1072
|
+
}
|
|
1073
|
+
var SEGMENTED_MAX = 4;
|
|
1074
|
+
function kindFor(display, options) {
|
|
1075
|
+
if (options) return options.length <= SEGMENTED_MAX ? "segmented" : "select";
|
|
1076
|
+
switch (display) {
|
|
1077
|
+
case "boolean":
|
|
1078
|
+
return "switch";
|
|
1079
|
+
case "date":
|
|
1080
|
+
return "date";
|
|
1081
|
+
case "datetime":
|
|
1082
|
+
return "datetime";
|
|
1083
|
+
case "number":
|
|
1084
|
+
case "currency":
|
|
1085
|
+
case "percent":
|
|
1086
|
+
return "number";
|
|
1087
|
+
case "longText":
|
|
1088
|
+
return "textarea";
|
|
1089
|
+
case "email":
|
|
1090
|
+
return "email";
|
|
1091
|
+
case "url":
|
|
1092
|
+
case "image":
|
|
1093
|
+
return "url";
|
|
1094
|
+
default:
|
|
1095
|
+
return "text";
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
function formFieldsFor(view, mode) {
|
|
1099
|
+
const writable = new Set(view.writable(mode));
|
|
1100
|
+
return view.form(mode).filter((f) => f.display !== "json" && !f.field.array).filter((f) => mode === "edit" || writable.has(f.field.name)).map((f) => {
|
|
1101
|
+
const options = f.field.enumValues?.map((value) => ({ value, label: displayText("badge", value, EMPTY_WORDS) }));
|
|
1102
|
+
const readOnly = !writable.has(f.field.name);
|
|
1103
|
+
return {
|
|
1104
|
+
key: f.field.name,
|
|
1105
|
+
label: f.label,
|
|
1106
|
+
kind: kindFor(f.display, options),
|
|
1107
|
+
display: f.display,
|
|
1108
|
+
required: !readOnly && f.required,
|
|
1109
|
+
readOnly,
|
|
1110
|
+
...f.max !== void 0 ? { max: f.max } : {},
|
|
1111
|
+
...options ? { options } : {},
|
|
1112
|
+
section: f.section,
|
|
1113
|
+
sectionTitle: f.sectionTitle,
|
|
1114
|
+
...f.visible ? { visible: f.visible } : {}
|
|
1115
|
+
};
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
var EMPTY_WORDS = { common: { empty: "", yes: "", no: "" } };
|
|
1119
|
+
function shownFields(fields, values) {
|
|
1120
|
+
return fields.filter((f) => !f.visible || f.visible(values));
|
|
1121
|
+
}
|
|
1122
|
+
function writableValues(view, mode, fields, values, dirty) {
|
|
1123
|
+
const writable = new Set(view.writable(mode));
|
|
1124
|
+
const out = {};
|
|
1125
|
+
for (const field of shownFields(fields, values)) {
|
|
1126
|
+
if (field.readOnly || !writable.has(field.key)) continue;
|
|
1127
|
+
if (dirty && !dirty.has(field.key)) continue;
|
|
1128
|
+
const value = values[field.key];
|
|
1129
|
+
out[field.key] = (value === "" || value === void 0) && !field.required ? null : value;
|
|
1130
|
+
}
|
|
1131
|
+
return out;
|
|
1132
|
+
}
|
|
1133
|
+
function validateValues(fields, values, messages) {
|
|
1134
|
+
const errors = {};
|
|
1135
|
+
for (const field of shownFields(fields, values)) {
|
|
1136
|
+
if (field.readOnly) continue;
|
|
1137
|
+
const value = values[field.key];
|
|
1138
|
+
if (field.required && field.kind !== "switch" && (isEmptyValue(value) || typeof value === "string" && !value.trim())) {
|
|
1139
|
+
errors[field.key] = fill(messages.form.required, { label: field.label });
|
|
1140
|
+
} else if (field.max !== void 0 && typeof value === "string" && value.length > field.max) {
|
|
1141
|
+
errors[field.key] = fill(messages.form.tooLong, { label: field.label, max: field.max });
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
return errors;
|
|
1145
|
+
}
|
|
1146
|
+
function refusalMessage(error, fallback) {
|
|
1147
|
+
if (error instanceof Error && error.name === "DataWriteError" && error.message) return error.message;
|
|
1148
|
+
return fallback;
|
|
1149
|
+
}
|
|
1150
|
+
function refusalFields(error) {
|
|
1151
|
+
if (error instanceof Error && error.name === "DataWriteError") {
|
|
1152
|
+
const fields = error.fields;
|
|
1153
|
+
if (fields) return { ...fields };
|
|
1154
|
+
}
|
|
1155
|
+
return {};
|
|
1156
|
+
}
|
|
1157
|
+
var FIELD_TYPE = {
|
|
1158
|
+
text: "text",
|
|
1159
|
+
email: "email",
|
|
1160
|
+
url: "url",
|
|
1161
|
+
number: "number",
|
|
1162
|
+
textarea: "textarea",
|
|
1163
|
+
switch: "switch",
|
|
1164
|
+
select: "select"
|
|
1165
|
+
};
|
|
1166
|
+
function sameValue(a, b) {
|
|
1167
|
+
const empty = (v) => v === "" || v === null || v === void 0;
|
|
1168
|
+
if (empty(a) && empty(b)) return true;
|
|
1169
|
+
return a === b || JSON.stringify(a) === JSON.stringify(b);
|
|
1170
|
+
}
|
|
1171
|
+
function startValues(fields, initial) {
|
|
1172
|
+
const values = {};
|
|
1173
|
+
for (const field of fields) {
|
|
1174
|
+
const value = initial?.[field.key];
|
|
1175
|
+
values[field.key] = value ?? (field.kind === "switch" ? false : "");
|
|
1176
|
+
}
|
|
1177
|
+
return values;
|
|
1178
|
+
}
|
|
1179
|
+
function NativeResourceFormSheet({
|
|
1180
|
+
open,
|
|
1181
|
+
mode,
|
|
1182
|
+
title,
|
|
1183
|
+
fields,
|
|
1184
|
+
initial,
|
|
1185
|
+
loading = false,
|
|
1186
|
+
recordKey: recordKey2,
|
|
1187
|
+
onCancel,
|
|
1188
|
+
onSave,
|
|
1189
|
+
testID = "native-resource-form"
|
|
1190
|
+
}) {
|
|
1191
|
+
const messages = useNativeResourceViewMessages();
|
|
1192
|
+
const defaults = useMemo(() => startValues(fields, initial), [fields, initial]);
|
|
1193
|
+
const form = useForm({ defaultValues: defaults });
|
|
1194
|
+
const [saving, setSaving] = useState(false);
|
|
1195
|
+
const [refusal, setRefusal] = useState(null);
|
|
1196
|
+
const latest = useRef(defaults);
|
|
1197
|
+
latest.current = defaults;
|
|
1198
|
+
const start = useRef(defaults);
|
|
1199
|
+
useEffect(() => {
|
|
1200
|
+
if (open && !loading) {
|
|
1201
|
+
start.current = latest.current;
|
|
1202
|
+
form.reset(start.current);
|
|
1203
|
+
setRefusal(null);
|
|
1204
|
+
}
|
|
1205
|
+
}, [open, loading, recordKey2, form]);
|
|
1206
|
+
const values = form.watch();
|
|
1207
|
+
const sections = useMemo(() => {
|
|
1208
|
+
const out = [];
|
|
1209
|
+
for (const field of shownFields(fields, values)) {
|
|
1210
|
+
const last = out[out.length - 1];
|
|
1211
|
+
if (last && last.key === (field.section ?? "")) last.fields.push(field);
|
|
1212
|
+
else out.push({ key: field.section ?? "", title: field.sectionTitle, fields: [field] });
|
|
1213
|
+
}
|
|
1214
|
+
return out;
|
|
1215
|
+
}, [fields, values]);
|
|
1216
|
+
const submit = async () => {
|
|
1217
|
+
setSaving(true);
|
|
1218
|
+
setRefusal(null);
|
|
1219
|
+
form.clearErrors();
|
|
1220
|
+
try {
|
|
1221
|
+
const now = form.getValues();
|
|
1222
|
+
const from = start.current;
|
|
1223
|
+
const dirty = new Set(fields.map((f) => f.key).filter((key) => !sameValue(now[key], from[key])));
|
|
1224
|
+
const result = await onSave(now, dirty);
|
|
1225
|
+
if (result.ok) return;
|
|
1226
|
+
for (const [key, message] of Object.entries(result.fields)) form.setError(key, { type: "server", message });
|
|
1227
|
+
if (result.message) setRefusal(result.message);
|
|
1228
|
+
} finally {
|
|
1229
|
+
setSaving(false);
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
return /* @__PURE__ */ jsxs(NativeSheet, { open, onOpenChange: (next) => next ? void 0 : onCancel(), testID, children: [
|
|
1233
|
+
/* @__PURE__ */ jsxs(
|
|
1234
|
+
View,
|
|
1235
|
+
{
|
|
1236
|
+
testID: `${testID}-bar`,
|
|
1237
|
+
style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", paddingHorizontal: 8, paddingVertical: 4 },
|
|
1238
|
+
children: [
|
|
1239
|
+
/* @__PURE__ */ jsx(
|
|
1240
|
+
Pressable,
|
|
1241
|
+
{
|
|
1242
|
+
testID: `${testID}-cancel`,
|
|
1243
|
+
accessibilityRole: "button",
|
|
1244
|
+
accessibilityLabel: messages.common.cancel,
|
|
1245
|
+
onPress: onCancel,
|
|
1246
|
+
hitSlop: 8,
|
|
1247
|
+
className: "min-h-[44px] justify-center px-3",
|
|
1248
|
+
children: /* @__PURE__ */ jsx(Text, { className: "text-base text-primary", children: messages.common.cancel })
|
|
1249
|
+
}
|
|
1250
|
+
),
|
|
1251
|
+
/* @__PURE__ */ jsx(NativeText, { preset: "body", accessibilityRole: "header", className: "font-semibold", numberOfLines: 1, children: title }),
|
|
1252
|
+
/* @__PURE__ */ jsx(
|
|
1253
|
+
NavBarSaveButton,
|
|
1254
|
+
{
|
|
1255
|
+
testID: `${testID}-save`,
|
|
1256
|
+
label: messages.common.save,
|
|
1257
|
+
loading: saving,
|
|
1258
|
+
disabled: loading,
|
|
1259
|
+
onPress: () => void submit()
|
|
1260
|
+
}
|
|
1261
|
+
)
|
|
1262
|
+
]
|
|
1263
|
+
}
|
|
1264
|
+
),
|
|
1265
|
+
/* @__PURE__ */ jsxs(NativeSheetScrollView, { contentContainerStyle: { padding: 16, gap: 20 }, keyboardShouldPersistTaps: "handled", children: [
|
|
1266
|
+
loading ? /* @__PURE__ */ jsx(NativeLoadingState, { fullScreen: false, label: messages.form.loading, testID: `${testID}-loading` }) : null,
|
|
1267
|
+
refusal ? /* @__PURE__ */ jsx(NativeInlineAlert, { testID: `${testID}-refusal`, variant: "destructive", description: refusal }) : null,
|
|
1268
|
+
loading ? null : sections.map((section, index) => /* @__PURE__ */ jsxs(View, { testID: `${testID}-section-${section.key || "main"}`, style: { gap: 12 }, children: [
|
|
1269
|
+
section.title ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", accessibilityRole: "header", className: "uppercase text-muted-foreground", children: section.title }) : null,
|
|
1270
|
+
section.fields.map((field) => /* @__PURE__ */ jsx(FormField, { field, form, mode, testID: `${testID}-field-${field.key}` }, field.key))
|
|
1271
|
+
] }, section.key || `__first_${index}`))
|
|
1272
|
+
] })
|
|
1273
|
+
] });
|
|
1274
|
+
}
|
|
1275
|
+
function FormField({
|
|
1276
|
+
field,
|
|
1277
|
+
form: f,
|
|
1278
|
+
mode: m,
|
|
1279
|
+
testID: id
|
|
1280
|
+
}) {
|
|
1281
|
+
const messages = useNativeResourceViewMessages();
|
|
1282
|
+
const zones = useDisplayTimeZones();
|
|
1283
|
+
const error = f.formState.errors[field.key]?.message;
|
|
1284
|
+
if (field.readOnly) {
|
|
1285
|
+
const shown = displayText(field.display, f.getValues(field.key), messages, resolveZone(void 0, zones));
|
|
1286
|
+
return /* @__PURE__ */ jsxs(View, { testID: id, style: { gap: 4 }, accessibilityLabel: `${field.label}, ${shown}`, children: [
|
|
1287
|
+
/* @__PURE__ */ jsx(NativeLabel, { children: field.label }),
|
|
1288
|
+
/* @__PURE__ */ jsx(NativeText, { testID: `${id}-value`, preset: "body", className: "text-muted-foreground", children: shown })
|
|
1289
|
+
] });
|
|
1290
|
+
}
|
|
1291
|
+
const type = FIELD_TYPE[field.kind];
|
|
1292
|
+
if (type) {
|
|
1293
|
+
const def = {
|
|
1294
|
+
key: field.key,
|
|
1295
|
+
label: field.label,
|
|
1296
|
+
type,
|
|
1297
|
+
required: field.required,
|
|
1298
|
+
...field.options ? { options: field.options } : {},
|
|
1299
|
+
...field.max !== void 0 ? { maxLength: field.max } : {}
|
|
1300
|
+
};
|
|
1301
|
+
return /* @__PURE__ */ jsx(View, { testID: id, children: /* @__PURE__ */ jsx(NativeResourceFormFieldRenderer, { field: def, control: f.control, action: m }) });
|
|
1302
|
+
}
|
|
1303
|
+
return /* @__PURE__ */ jsx(
|
|
1304
|
+
Controller,
|
|
1305
|
+
{
|
|
1306
|
+
name: field.key,
|
|
1307
|
+
control: f.control,
|
|
1308
|
+
render: ({ field: input }) => /* @__PURE__ */ jsxs(View, { testID: id, style: { gap: 6 }, children: [
|
|
1309
|
+
/* @__PURE__ */ jsx(NativeLabel, { children: field.label }),
|
|
1310
|
+
field.kind === "segmented" ? /* @__PURE__ */ jsx(
|
|
1311
|
+
NativeSegmentedControl,
|
|
1312
|
+
{
|
|
1313
|
+
testID: `${id}-segmented`,
|
|
1314
|
+
options: field.options ?? [],
|
|
1315
|
+
value: String(input.value ?? ""),
|
|
1316
|
+
onChange: input.onChange
|
|
1317
|
+
}
|
|
1318
|
+
) : /* @__PURE__ */ jsx(
|
|
1319
|
+
DateField,
|
|
1320
|
+
{
|
|
1321
|
+
kind: field.kind,
|
|
1322
|
+
value: input.value,
|
|
1323
|
+
onChange: input.onChange,
|
|
1324
|
+
clearable: !field.required,
|
|
1325
|
+
label: field.label,
|
|
1326
|
+
testID: id
|
|
1327
|
+
}
|
|
1328
|
+
),
|
|
1329
|
+
error ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-destructive", children: error }) : null
|
|
1330
|
+
] })
|
|
1331
|
+
}
|
|
1332
|
+
);
|
|
1333
|
+
}
|
|
1334
|
+
function DateField({
|
|
1335
|
+
kind,
|
|
1336
|
+
value,
|
|
1337
|
+
onChange,
|
|
1338
|
+
clearable,
|
|
1339
|
+
label,
|
|
1340
|
+
testID
|
|
1341
|
+
}) {
|
|
1342
|
+
const messages = useNativeResourceViewMessages();
|
|
1343
|
+
const date = kind === "date" ? dayToDate(value) : typeof value === "string" && value ? new Date(value) : null;
|
|
1344
|
+
if (!date || Number.isNaN(date.getTime())) {
|
|
1345
|
+
return /* @__PURE__ */ jsx(
|
|
1346
|
+
NativeButton,
|
|
1347
|
+
{
|
|
1348
|
+
variant: "outline",
|
|
1349
|
+
size: "sm",
|
|
1350
|
+
testID: `${testID}-set`,
|
|
1351
|
+
onPress: () => onChange(kind === "date" ? dateToDay(/* @__PURE__ */ new Date()) : (/* @__PURE__ */ new Date()).toISOString()),
|
|
1352
|
+
children: kind === "date" ? messages.form.pickDate : messages.form.pickDateTime
|
|
1353
|
+
}
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
const set = (next) => onChange(kind === "date" ? dateToDay(next) : next.toISOString());
|
|
1357
|
+
return /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "center", gap: 8 }, children: [
|
|
1358
|
+
/* @__PURE__ */ jsx(NativeDatePicker, { testID: `${testID}-date`, value: date, onChange: set }),
|
|
1359
|
+
kind === "datetime" ? /* @__PURE__ */ jsx(NativeTimePicker, { testID: `${testID}-time`, value: date, onChange: set }) : null,
|
|
1360
|
+
clearable ? /* @__PURE__ */ jsx(NativeButton, { variant: "ghost", size: "sm", testID: `${testID}-clear`, onPress: () => onChange(null), children: fill(messages.form.clear, { label: label.toLowerCase() }) }) : null
|
|
1361
|
+
] });
|
|
1362
|
+
}
|
|
1363
|
+
var SEARCH_DEBOUNCE_MS = 300;
|
|
1364
|
+
function filterParams(filter) {
|
|
1365
|
+
return Object.entries(filter ?? {}).map(
|
|
1366
|
+
([field, value]) => value === null ? { field, operator: "is_null" } : { field, operator: "eq", value }
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
function screenValues(...filters) {
|
|
1370
|
+
const out = {};
|
|
1371
|
+
for (const filter of filters) {
|
|
1372
|
+
for (const [field, value] of Object.entries(filter ?? {})) if (value !== null) out[field] = value;
|
|
1373
|
+
}
|
|
1374
|
+
return out;
|
|
1375
|
+
}
|
|
1376
|
+
var DEFAULT_MAX_PAGES = 10;
|
|
1377
|
+
function serverSort(view) {
|
|
1378
|
+
const groupBy = view.definition.groupBy;
|
|
1379
|
+
const orderBy = view.definition.orderBy;
|
|
1380
|
+
if (groupBy) return { field: groupBy, order: orderBy?.field === groupBy ? orderBy.direction ?? "asc" : "asc" };
|
|
1381
|
+
return orderBy ? { field: orderBy.field, order: orderBy.direction ?? "asc" } : void 0;
|
|
1382
|
+
}
|
|
1383
|
+
function useNativeResourceView(view, options = {}) {
|
|
1384
|
+
const { preset, filter, perPage, maxPages = DEFAULT_MAX_PAGES, searchFields: searchOption, can, live } = options;
|
|
1385
|
+
const messages = useNativeResourceViewMessages();
|
|
1386
|
+
const tab = preset ? view.definition.presets?.[preset] : void 0;
|
|
1387
|
+
if (preset && !tab) throw new Error(`NativeResourceView(${view.resource}): no preset "${preset}"`);
|
|
1388
|
+
const tabFilter = tab?.filter;
|
|
1389
|
+
const defaultFilters = useMemo(() => [...filterParams(tabFilter), ...filterParams(filter)], [tabFilter, filter]);
|
|
1390
|
+
const createKey = JSON.stringify(screenValues(tabFilter, filter));
|
|
1391
|
+
const createDefaults = useMemo(() => JSON.parse(createKey), [createKey]);
|
|
1392
|
+
const sort = useMemo(() => serverSort(view), [view]);
|
|
1393
|
+
const searchFields = useMemo(
|
|
1394
|
+
() => searchOption ?? (view.labelField ? [view.labelField] : void 0),
|
|
1395
|
+
[searchOption, view.labelField]
|
|
1396
|
+
);
|
|
1397
|
+
const pages = useInfiniteResource(view.resource, {
|
|
1398
|
+
defaultFilters,
|
|
1399
|
+
...sort ? { defaultSort: sort } : {},
|
|
1400
|
+
...perPage ? { perPage } : {},
|
|
1401
|
+
maxPages,
|
|
1402
|
+
...searchFields ? { searchFields } : {},
|
|
1403
|
+
keepPreviousData: true,
|
|
1404
|
+
...live ? { live } : {}
|
|
1405
|
+
});
|
|
1406
|
+
const [search, setSearchText] = useState("");
|
|
1407
|
+
const timer = useRef(null);
|
|
1408
|
+
const { setSearch: sendSearch } = pages;
|
|
1409
|
+
const setSearch = useCallback(
|
|
1410
|
+
(text2) => {
|
|
1411
|
+
setSearchText(text2);
|
|
1412
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1413
|
+
timer.current = setTimeout(() => sendSearch(text2), SEARCH_DEBOUNCE_MS);
|
|
1414
|
+
},
|
|
1415
|
+
[sendSearch]
|
|
1416
|
+
);
|
|
1417
|
+
useEffect(() => () => {
|
|
1418
|
+
if (timer.current) clearTimeout(timer.current);
|
|
1419
|
+
}, []);
|
|
1420
|
+
const [refusal, setRefusal] = useState(null);
|
|
1421
|
+
const deleteFailed = fill(messages.refusal.deleteFailed, { noun: view.noun });
|
|
1422
|
+
const optimistic = useResource(view.resource, {
|
|
1423
|
+
enabled: false,
|
|
1424
|
+
mutationMode: "optimistic",
|
|
1425
|
+
// The row is already back in the list (the cache is put back); say why, inline.
|
|
1426
|
+
onError: (error2) => setRefusal(refusalMessage(error2, deleteFailed))
|
|
1427
|
+
});
|
|
1428
|
+
const pessimistic = useResource(view.resource, { enabled: false, onError: () => {
|
|
1429
|
+
} });
|
|
1430
|
+
const capabilities = useCapabilities(view.resource);
|
|
1431
|
+
const softDelete = capabilities.data?.softDelete === true;
|
|
1432
|
+
const formFields = useCallback(
|
|
1433
|
+
(mode) => mode === "create" ? formFieldsFor(view, "create").filter((f) => !(f.key in createDefaults)) : formFieldsFor(view, "edit"),
|
|
1434
|
+
[view, createDefaults]
|
|
1435
|
+
);
|
|
1436
|
+
const editable = useMemo(() => formFieldsFor(view, "edit").some((f) => !f.readOnly), [view]);
|
|
1437
|
+
const viewer = useViewer();
|
|
1438
|
+
const canCreate = useMemo(
|
|
1439
|
+
() => formFieldsFor(view, "create").length ? allowed(view, "create", void 0, can, viewer) : false,
|
|
1440
|
+
[view, can, viewer]
|
|
1441
|
+
);
|
|
1442
|
+
const writers = useRef(pessimistic);
|
|
1443
|
+
writers.current = pessimistic;
|
|
1444
|
+
const save = useCallback(
|
|
1445
|
+
async (mode, values, row, dirty) => {
|
|
1446
|
+
const fields = formFields(mode);
|
|
1447
|
+
const errors = validateValues(fields, values, messages);
|
|
1448
|
+
if (Object.keys(errors).length) return { ok: false, fields: errors };
|
|
1449
|
+
const data = mode === "create" ? { ...writableValues(view, mode, fields, values), ...createDefaults } : writableValues(view, mode, fields, values, dirty);
|
|
1450
|
+
setRefusal(null);
|
|
1451
|
+
if (mode === "edit" && Object.keys(data).length === 0) return { ok: true };
|
|
1452
|
+
try {
|
|
1453
|
+
if (mode === "create") await writers.current.create(data);
|
|
1454
|
+
else await writers.current.update(row.id, data);
|
|
1455
|
+
return { ok: true };
|
|
1456
|
+
} catch (error2) {
|
|
1457
|
+
return {
|
|
1458
|
+
ok: false,
|
|
1459
|
+
message: refusalMessage(error2, fill(messages.form.saveFailed, { noun: view.noun })),
|
|
1460
|
+
fields: refusalFields(error2)
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
},
|
|
1464
|
+
[view, messages, createDefaults, formFields]
|
|
1465
|
+
);
|
|
1466
|
+
const removeRow = useRef(optimistic.remove);
|
|
1467
|
+
removeRow.current = optimistic.remove;
|
|
1468
|
+
const remove = useCallback((row) => {
|
|
1469
|
+
setRefusal(null);
|
|
1470
|
+
removeRow.current(row.id).catch(() => {
|
|
1471
|
+
});
|
|
1472
|
+
}, []);
|
|
1473
|
+
const item = useCallback((row) => rowItem(view, row), [view]);
|
|
1474
|
+
const actions = useCallback(
|
|
1475
|
+
(row, handlers) => swipeActionsFor(view, row, { messages, softDelete, editable, screen: can, viewer, ...handlers }),
|
|
1476
|
+
[view, messages, softDelete, editable, can, viewer]
|
|
1477
|
+
);
|
|
1478
|
+
const sections = useMemo(() => sectionsFor(view, pages.rows, messages), [view, pages.rows, messages]);
|
|
1479
|
+
const { query } = pages;
|
|
1480
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
1481
|
+
const refresh = useCallback(async () => {
|
|
1482
|
+
setRefreshing(true);
|
|
1483
|
+
try {
|
|
1484
|
+
await query.refetch();
|
|
1485
|
+
} finally {
|
|
1486
|
+
setRefreshing(false);
|
|
1487
|
+
}
|
|
1488
|
+
}, [query]);
|
|
1489
|
+
const error = query.isError ? query.error?.name === "DataReadError" && query.error.message ? query.error.message : fill(messages.list.loadFailed, { nounPlural: view.nounPlural }) : null;
|
|
1490
|
+
return {
|
|
1491
|
+
rows: pages.rows,
|
|
1492
|
+
sections,
|
|
1493
|
+
total: pages.total,
|
|
1494
|
+
loading: query.isLoading,
|
|
1495
|
+
error,
|
|
1496
|
+
refreshing,
|
|
1497
|
+
refresh,
|
|
1498
|
+
loadMore: pages.fetchNextPage,
|
|
1499
|
+
loadingMore: pages.isFetchingNextPage,
|
|
1500
|
+
hasMore: pages.hasNextPage,
|
|
1501
|
+
loadPrevious: pages.fetchPreviousPage,
|
|
1502
|
+
loadingPrevious: query.isFetchingPreviousPage,
|
|
1503
|
+
hasPrevious: pages.hasPreviousPage,
|
|
1504
|
+
search,
|
|
1505
|
+
setSearch,
|
|
1506
|
+
refusal,
|
|
1507
|
+
dismissRefusal: useCallback(() => setRefusal(null), []),
|
|
1508
|
+
item,
|
|
1509
|
+
actions,
|
|
1510
|
+
canCreate,
|
|
1511
|
+
formFields,
|
|
1512
|
+
save,
|
|
1513
|
+
remove,
|
|
1514
|
+
softDelete
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
var IOS_GROUP_MARGIN = 16;
|
|
1518
|
+
var GROUP_RADIUS = Number.parseFloat(String(Platform.Version)) >= 26 ? 26 : 10;
|
|
1519
|
+
var IOS = Platform.OS === "ios";
|
|
1520
|
+
var recordKey = (view, row) => {
|
|
1521
|
+
try {
|
|
1522
|
+
return String(encodeRecordKey(view.contract, row));
|
|
1523
|
+
} catch {
|
|
1524
|
+
return String(row.id);
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
function NativeResourceView(props) {
|
|
1528
|
+
const scope = useOptionalViewerScope();
|
|
1529
|
+
const viewer = scope?.timeZone;
|
|
1530
|
+
const { practiceTimeZone } = props;
|
|
1531
|
+
const zones = useMemo(() => {
|
|
1532
|
+
const own = personTimeZone({ timeZone: viewer });
|
|
1533
|
+
return { viewer: own, practice: practiceTimeZone && isTimeZone(practiceTimeZone) ? practiceTimeZone : own };
|
|
1534
|
+
}, [viewer, practiceTimeZone]);
|
|
1535
|
+
return /* @__PURE__ */ jsx(DisplayTimeZonesProvider, { value: zones, children: /* @__PURE__ */ jsx(Screen, { ...props }) });
|
|
1536
|
+
}
|
|
1537
|
+
var PICTURE_SIZE = 40;
|
|
1538
|
+
function RowLeading({ picture, testID }) {
|
|
1539
|
+
const [failed, setFailed] = useState(null);
|
|
1540
|
+
if (picture.kind === "image" && failed !== picture.src) {
|
|
1541
|
+
return /* @__PURE__ */ jsx(
|
|
1542
|
+
NativeImage,
|
|
1543
|
+
{
|
|
1544
|
+
testID: `${testID}-image`,
|
|
1545
|
+
src: picture.src,
|
|
1546
|
+
...picture.alt ? { alt: picture.alt } : {},
|
|
1547
|
+
width: PICTURE_SIZE,
|
|
1548
|
+
height: PICTURE_SIZE,
|
|
1549
|
+
className: "rounded-full",
|
|
1550
|
+
onError: () => setFailed(picture.src)
|
|
1551
|
+
}
|
|
1552
|
+
);
|
|
1553
|
+
}
|
|
1554
|
+
const initials = picture.kind === "image" ? picture.fallback : picture.text;
|
|
1555
|
+
if (!initials) return null;
|
|
1556
|
+
return (
|
|
1557
|
+
// The row's label already names it; the letters would only be read twice.
|
|
1558
|
+
/* @__PURE__ */ jsx(View, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", children: /* @__PURE__ */ jsx(NativeAvatar, { testID: `${testID}-initials`, fallback: initials, size: PICTURE_SIZE }) })
|
|
1559
|
+
);
|
|
1560
|
+
}
|
|
1561
|
+
var ResourceRow = memo(function ResourceRow2({
|
|
1562
|
+
row,
|
|
1563
|
+
first,
|
|
1564
|
+
last,
|
|
1565
|
+
item: itemFor,
|
|
1566
|
+
actions: actionsFor,
|
|
1567
|
+
handlers,
|
|
1568
|
+
onPress,
|
|
1569
|
+
chevron,
|
|
1570
|
+
Swipeable,
|
|
1571
|
+
cancelLabel,
|
|
1572
|
+
surface,
|
|
1573
|
+
separator,
|
|
1574
|
+
testID
|
|
1575
|
+
}) {
|
|
1576
|
+
const item = itemFor(row);
|
|
1577
|
+
const actions = actionsFor(row, handlers);
|
|
1578
|
+
const chip = item.chips[0];
|
|
1579
|
+
const picture = item.picture;
|
|
1580
|
+
const rowTestID = `${testID}-row-${item.id}`;
|
|
1581
|
+
const content = /* @__PURE__ */ jsxs(
|
|
1582
|
+
View,
|
|
1583
|
+
{
|
|
1584
|
+
testID: `${rowTestID}-cell`,
|
|
1585
|
+
style: [
|
|
1586
|
+
{ backgroundColor: surface },
|
|
1587
|
+
IOS ? {
|
|
1588
|
+
marginHorizontal: IOS_GROUP_MARGIN,
|
|
1589
|
+
borderTopLeftRadius: first ? GROUP_RADIUS : 0,
|
|
1590
|
+
borderTopRightRadius: first ? GROUP_RADIUS : 0,
|
|
1591
|
+
borderBottomLeftRadius: last ? GROUP_RADIUS : 0,
|
|
1592
|
+
borderBottomRightRadius: last ? GROUP_RADIUS : 0,
|
|
1593
|
+
overflow: "hidden"
|
|
1594
|
+
} : null
|
|
1595
|
+
],
|
|
1596
|
+
children: [
|
|
1597
|
+
/* @__PURE__ */ jsx(
|
|
1598
|
+
Pressable,
|
|
1599
|
+
{
|
|
1600
|
+
testID: rowTestID,
|
|
1601
|
+
accessibilityRole: "button",
|
|
1602
|
+
accessibilityLabel: [picture?.kind === "image" ? picture.alt : null, item.title, item.subtitle, chip?.label].filter(Boolean).join(", "),
|
|
1603
|
+
accessibilityActions: actions.map((a) => ({ name: a.id, label: a.reason ? `${a.label}: ${a.reason}` : a.label })),
|
|
1604
|
+
onAccessibilityAction: (event) => actions.find((a) => a.id === event.nativeEvent.actionName)?.onPress(),
|
|
1605
|
+
onPress: () => onPress(row),
|
|
1606
|
+
onLongPress: actions.length ? () => showInboxActions(item.title, actions, cancelLabel) : void 0,
|
|
1607
|
+
children: /* @__PURE__ */ jsx(
|
|
1608
|
+
NativeListItem,
|
|
1609
|
+
{
|
|
1610
|
+
testID: `${rowTestID}-item`,
|
|
1611
|
+
title: item.title,
|
|
1612
|
+
subtitle: item.subtitle,
|
|
1613
|
+
leading: picture ? /* @__PURE__ */ jsx(RowLeading, { picture, testID: rowTestID }) : void 0,
|
|
1614
|
+
className: "bg-transparent",
|
|
1615
|
+
trailing: chip ? /* @__PURE__ */ jsx(NativeBadge, { testID: `${rowTestID}-chip`, variant: badgeVariant(chip.tone), children: chip.label }) : void 0,
|
|
1616
|
+
showChevron: chevron
|
|
1617
|
+
}
|
|
1618
|
+
)
|
|
1619
|
+
}
|
|
1620
|
+
),
|
|
1621
|
+
!last ? /* @__PURE__ */ jsx(View, { style: { height: 0.5, marginLeft: 16, backgroundColor: separator } }) : null
|
|
1622
|
+
]
|
|
1623
|
+
}
|
|
1624
|
+
);
|
|
1625
|
+
return actions.length && Swipeable ? /* @__PURE__ */ jsx(Swipeable, { actions, testID: `${rowTestID}-swipe`, children: content }) : content;
|
|
1626
|
+
});
|
|
1627
|
+
function Screen(props) {
|
|
1628
|
+
const {
|
|
1629
|
+
view,
|
|
1630
|
+
title,
|
|
1631
|
+
subtitle,
|
|
1632
|
+
onRowPress,
|
|
1633
|
+
swipeable: Swipeable,
|
|
1634
|
+
header,
|
|
1635
|
+
emptyState,
|
|
1636
|
+
searchable,
|
|
1637
|
+
practiceTimeZone: _zone,
|
|
1638
|
+
testID = "native-resource-view",
|
|
1639
|
+
...options
|
|
1640
|
+
} = props;
|
|
1641
|
+
const state = useNativeResourceView(view, options);
|
|
1642
|
+
const keyExtractor = useCallback((row) => recordKey(view, row), [view]);
|
|
1643
|
+
const messages = useNativeResourceViewMessages();
|
|
1644
|
+
const colors = useThemeRoles();
|
|
1645
|
+
const cell = useDisplayCell();
|
|
1646
|
+
const [peekId, setPeekId] = useState(null);
|
|
1647
|
+
const [sheet, setSheet] = useState(null);
|
|
1648
|
+
const refused = useCallback((label, reason) => Alert.alert(label, reason), []);
|
|
1649
|
+
const { remove, softDelete, item: itemFor, actions: actionsFor } = state;
|
|
1650
|
+
const confirmDelete = useCallback(
|
|
1651
|
+
(row) => {
|
|
1652
|
+
const name = itemFor(row).title;
|
|
1653
|
+
const words = softDelete ? messages.bin : messages.delete;
|
|
1654
|
+
Alert.alert(fill(words.confirmTitle, { name }), words.confirmBody, [
|
|
1655
|
+
{ text: messages.common.cancel, style: "cancel" },
|
|
1656
|
+
{
|
|
1657
|
+
text: words.action,
|
|
1658
|
+
style: "destructive",
|
|
1659
|
+
onPress: () => {
|
|
1660
|
+
setPeekId(null);
|
|
1661
|
+
remove(row);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
]);
|
|
1665
|
+
},
|
|
1666
|
+
[itemFor, softDelete, messages, remove]
|
|
1667
|
+
);
|
|
1668
|
+
const edit = useCallback((row) => {
|
|
1669
|
+
setPeekId(null);
|
|
1670
|
+
setSheet({ mode: "edit", row });
|
|
1671
|
+
}, []);
|
|
1672
|
+
const handlers = useMemo(() => ({ onEdit: edit, onDelete: confirmDelete, onRefused: refused }), [edit, confirmDelete, refused]);
|
|
1673
|
+
const rowPress = useRef(onRowPress);
|
|
1674
|
+
rowPress.current = onRowPress;
|
|
1675
|
+
const press = useCallback((row) => rowPress.current ? rowPress.current(row) : setPeekId({ row }), []);
|
|
1676
|
+
const chevron = !!onRowPress;
|
|
1677
|
+
const renderItem = useCallback(
|
|
1678
|
+
({ item: row, index, section }) => /* @__PURE__ */ jsx(
|
|
1679
|
+
ResourceRow,
|
|
1680
|
+
{
|
|
1681
|
+
row,
|
|
1682
|
+
first: index === 0,
|
|
1683
|
+
last: index === section.data.length - 1,
|
|
1684
|
+
item: itemFor,
|
|
1685
|
+
actions: actionsFor,
|
|
1686
|
+
handlers,
|
|
1687
|
+
onPress: press,
|
|
1688
|
+
chevron,
|
|
1689
|
+
Swipeable,
|
|
1690
|
+
cancelLabel: messages.common.cancel,
|
|
1691
|
+
surface: colors.surface,
|
|
1692
|
+
separator: colors.separator,
|
|
1693
|
+
testID
|
|
1694
|
+
}
|
|
1695
|
+
),
|
|
1696
|
+
[itemFor, actionsFor, handlers, press, chevron, Swipeable, messages, colors.surface, colors.separator, testID]
|
|
1697
|
+
);
|
|
1698
|
+
const renderSectionHeader = useCallback(
|
|
1699
|
+
({ section }) => section.title ? /* @__PURE__ */ jsx(
|
|
1700
|
+
NativeSectionListHeader,
|
|
1701
|
+
{
|
|
1702
|
+
testID: `${testID}-section-${section.key || "none"}`,
|
|
1703
|
+
title: section.title,
|
|
1704
|
+
className: "border-b-0 bg-transparent pt-4"
|
|
1705
|
+
}
|
|
1706
|
+
) : null,
|
|
1707
|
+
[testID]
|
|
1708
|
+
);
|
|
1709
|
+
const create = () => {
|
|
1710
|
+
if (state.canCreate === true) setSheet({ mode: "create" });
|
|
1711
|
+
else if (typeof state.canCreate === "string") refused(fill(messages.common.create, { noun: view.noun }), state.canCreate);
|
|
1712
|
+
};
|
|
1713
|
+
const showSearch = searchable ?? !!(options.searchFields?.length || view.labelField);
|
|
1714
|
+
const heading = title === false ? null : title ?? view.title;
|
|
1715
|
+
const hasRows = state.rows.length > 0;
|
|
1716
|
+
const listHeader = /* @__PURE__ */ jsxs(View, { style: { paddingHorizontal: 16, paddingTop: 8, paddingBottom: 8, gap: 12 }, children: [
|
|
1717
|
+
heading || state.canCreate !== false ? /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" }, children: [
|
|
1718
|
+
/* @__PURE__ */ jsxs(View, { style: { flex: 1 }, children: [
|
|
1719
|
+
heading ? /* @__PURE__ */ jsx(NativeText, { preset: "h2", accessibilityRole: "header", children: heading }) : null,
|
|
1720
|
+
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
|
|
1721
|
+
] }),
|
|
1722
|
+
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
|
|
1723
|
+
] }) : null,
|
|
1724
|
+
showSearch ? /* @__PURE__ */ jsx(
|
|
1725
|
+
NativeSearchBar,
|
|
1726
|
+
{
|
|
1727
|
+
testID: `${testID}-search`,
|
|
1728
|
+
value: state.search,
|
|
1729
|
+
onChange: state.setSearch,
|
|
1730
|
+
placeholder: fill(messages.common.search, { nounPlural: view.nounPlural })
|
|
1731
|
+
}
|
|
1732
|
+
) : null,
|
|
1733
|
+
state.error && hasRows ? (
|
|
1734
|
+
// A refetch or the next page failed: keep the rows, say so above them.
|
|
1735
|
+
/* @__PURE__ */ jsxs(View, { testID: `${testID}-read-error`, style: { gap: 8 }, children: [
|
|
1736
|
+
/* @__PURE__ */ jsx(NativeInlineAlert, { variant: "destructive", description: state.error }),
|
|
1737
|
+
/* @__PURE__ */ jsx(NativeButton, { variant: "outline", size: "sm", onPress: () => void state.refresh(), children: messages.list.retry })
|
|
1738
|
+
] })
|
|
1739
|
+
) : null,
|
|
1740
|
+
state.refusal ? /* @__PURE__ */ jsx(
|
|
1741
|
+
NativeInlineAlert,
|
|
1742
|
+
{
|
|
1743
|
+
testID: `${testID}-refusal`,
|
|
1744
|
+
variant: "destructive",
|
|
1745
|
+
description: state.refusal,
|
|
1746
|
+
onDismiss: state.dismissRefusal
|
|
1747
|
+
}
|
|
1748
|
+
) : null,
|
|
1749
|
+
header,
|
|
1750
|
+
state.loadingPrevious ? /* @__PURE__ */ jsx(NativeLoadingState, { fullScreen: false, size: "small", label: messages.list.loadingMore, testID: `${testID}-previous` }) : null
|
|
1751
|
+
] });
|
|
1752
|
+
const empty = state.loading ? /* @__PURE__ */ jsx(NativeLoadingState, { fullScreen: false, testID: `${testID}-loading` }) : state.error ? /* @__PURE__ */ jsx(
|
|
1753
|
+
NativeEmptyState,
|
|
1754
|
+
{
|
|
1755
|
+
testID: `${testID}-error`,
|
|
1756
|
+
variant: "error",
|
|
1757
|
+
title: state.error,
|
|
1758
|
+
primaryAction: /* @__PURE__ */ jsx(NativeButton, { variant: "outline", size: "sm", onPress: () => void state.refresh(), children: messages.list.retry })
|
|
1759
|
+
}
|
|
1760
|
+
) : emptyState ?? (state.search ? /* @__PURE__ */ jsx(NativeEmptyState, { testID: `${testID}-empty`, variant: "no-results", title: messages.list.noResultsTitle, body: messages.list.noResultsBody }) : /* @__PURE__ */ jsx(
|
|
1761
|
+
NativeEmptyState,
|
|
1762
|
+
{
|
|
1763
|
+
testID: `${testID}-empty`,
|
|
1764
|
+
title: view.definition.copy?.empty?.title ?? fill(messages.list.emptyTitle, { nounPlural: view.nounPlural }),
|
|
1765
|
+
body: view.definition.copy?.empty?.body ?? messages.list.emptyBody
|
|
1766
|
+
}
|
|
1767
|
+
));
|
|
1768
|
+
const peekRow = useOne(view.resource, peekId ? peekId.row.id : null);
|
|
1769
|
+
const editRow = useOne(view.resource, sheet?.mode === "edit" ? sheet.row.id : null);
|
|
1770
|
+
const peek = peekId ? peekRow.data ?? peekId.row : null;
|
|
1771
|
+
const peekFields = useMemo(
|
|
1772
|
+
() => view.columns().map((column) => ({
|
|
1773
|
+
key: column.key,
|
|
1774
|
+
label: column.label,
|
|
1775
|
+
render: (_value, row) => cell(column, row)
|
|
1776
|
+
})),
|
|
1777
|
+
[view, cell]
|
|
1778
|
+
);
|
|
1779
|
+
const { formFields } = state;
|
|
1780
|
+
const createFields = useMemo(() => formFields("create"), [formFields]);
|
|
1781
|
+
const editFields = useMemo(() => formFields("edit"), [formFields]);
|
|
1782
|
+
const peekActions = peek ? actionsFor(peek, handlers) : [];
|
|
1783
|
+
const editLoading = sheet?.mode === "edit" && editRow.data === void 0 && !editRow.isError;
|
|
1784
|
+
return /* @__PURE__ */ jsxs(SafeAreaView, { testID, edges: ["left", "right", "bottom"], style: { flex: 1, backgroundColor: colors.groupedBackground }, children: [
|
|
1785
|
+
/* @__PURE__ */ jsx(
|
|
1786
|
+
SectionList,
|
|
1787
|
+
{
|
|
1788
|
+
testID: `${testID}-list`,
|
|
1789
|
+
sections: state.sections,
|
|
1790
|
+
keyExtractor,
|
|
1791
|
+
renderItem,
|
|
1792
|
+
renderSectionHeader,
|
|
1793
|
+
extraData: actionsFor,
|
|
1794
|
+
stickySectionHeadersEnabled: false,
|
|
1795
|
+
contentInsetAdjustmentBehavior: "automatic",
|
|
1796
|
+
keyboardShouldPersistTaps: "handled",
|
|
1797
|
+
ListHeaderComponent: listHeader,
|
|
1798
|
+
ListEmptyComponent: empty,
|
|
1799
|
+
ListFooterComponent: state.loadingMore ? /* @__PURE__ */ jsx(NativeLoadingState, { fullScreen: false, size: "small", label: messages.list.loadingMore, testID: `${testID}-more` }) : null,
|
|
1800
|
+
contentContainerStyle: { flexGrow: 1, paddingBottom: 32 },
|
|
1801
|
+
onEndReached: state.hasMore ? state.loadMore : void 0,
|
|
1802
|
+
onEndReachedThreshold: 0.5,
|
|
1803
|
+
onStartReached: state.hasPrevious ? state.loadPrevious : void 0,
|
|
1804
|
+
onStartReachedThreshold: 0.5,
|
|
1805
|
+
maintainVisibleContentPosition: { minIndexForVisible: 0 },
|
|
1806
|
+
refreshControl: /* @__PURE__ */ jsx(NativeRefreshControl, { testID: `${testID}-refresh`, refreshing: state.refreshing, onRefresh: () => void state.refresh() })
|
|
1807
|
+
}
|
|
1808
|
+
),
|
|
1809
|
+
/* @__PURE__ */ jsx(NativeSheet, { open: peek !== null, onOpenChange: (open) => open ? void 0 : setPeekId(null), testID: `${testID}-peek`, children: peek ? /* @__PURE__ */ jsx(
|
|
1810
|
+
NativeDetailPanel,
|
|
1811
|
+
{
|
|
1812
|
+
item: peek,
|
|
1813
|
+
title: itemFor(peek).title,
|
|
1814
|
+
fields: peekFields,
|
|
1815
|
+
footer: peekActions.length ? /* @__PURE__ */ jsx(View, { testID: `${testID}-peek-actions`, style: { gap: 12 }, children: peekActions.map((action) => /* @__PURE__ */ jsxs(View, { style: { gap: 4 }, children: [
|
|
1816
|
+
/* @__PURE__ */ jsx(
|
|
1817
|
+
NativeButton,
|
|
1818
|
+
{
|
|
1819
|
+
testID: `${testID}-peek-${action.id}`,
|
|
1820
|
+
variant: action.destructive ? "destructive" : "outline",
|
|
1821
|
+
className: action.reason ? "opacity-50" : void 0,
|
|
1822
|
+
onPress: action.onPress,
|
|
1823
|
+
children: action.label
|
|
1824
|
+
}
|
|
1825
|
+
),
|
|
1826
|
+
action.reason ? /* @__PURE__ */ jsx(NativeText, { testID: `${testID}-peek-${action.id}-reason`, preset: "caption", className: "text-muted-foreground", children: action.reason }) : null
|
|
1827
|
+
] }, action.id)) }) : null
|
|
1828
|
+
}
|
|
1829
|
+
) : null }),
|
|
1830
|
+
/* @__PURE__ */ jsx(
|
|
1831
|
+
NativeResourceFormSheet,
|
|
1832
|
+
{
|
|
1833
|
+
open: sheet !== null,
|
|
1834
|
+
mode: sheet?.mode ?? "create",
|
|
1835
|
+
title: fill(sheet?.mode === "edit" ? messages.common.editTitle : messages.common.create, { noun: view.noun }),
|
|
1836
|
+
fields: sheet?.mode === "edit" ? editFields : createFields,
|
|
1837
|
+
initial: sheet?.mode === "edit" ? editRow.data ?? (editRow.isError ? sheet.row : void 0) : void 0,
|
|
1838
|
+
loading: editLoading,
|
|
1839
|
+
recordKey: sheet?.row ? recordKey(view, sheet.row) : "new",
|
|
1840
|
+
onCancel: () => setSheet(null),
|
|
1841
|
+
onSave: async (values, dirty) => {
|
|
1842
|
+
const result = await state.save(sheet?.mode ?? "create", values, sheet?.row, dirty);
|
|
1843
|
+
if (result.ok) setSheet(null);
|
|
1844
|
+
return result;
|
|
1845
|
+
},
|
|
1846
|
+
testID: `${testID}-form`
|
|
1847
|
+
}
|
|
1848
|
+
)
|
|
1849
|
+
] });
|
|
1850
|
+
}
|
|
1851
|
+
var defaultNativeResourceWorkspaceMessages = {
|
|
1852
|
+
actions: "Actions",
|
|
1853
|
+
cancel: "Cancel",
|
|
1854
|
+
save: "Save",
|
|
1855
|
+
notChanged: "This {noun} was not changed.",
|
|
1856
|
+
failed: "That didn't work. Try again.",
|
|
1857
|
+
noRunner: "{name} isn't available here.",
|
|
1858
|
+
checks: "Checks",
|
|
1859
|
+
checkDone: "Done",
|
|
1860
|
+
checkTodo: "To do",
|
|
1861
|
+
allSections: "All sections",
|
|
1862
|
+
notANumber: "Enter a number.",
|
|
1863
|
+
ready: void 0,
|
|
1864
|
+
empty: void 0,
|
|
1865
|
+
pending: void 0,
|
|
1866
|
+
problems: void 0,
|
|
1867
|
+
warnings: void 0
|
|
1868
|
+
};
|
|
1869
|
+
var SEGMENTED_SECTIONS_MAX = 4;
|
|
1870
|
+
function useHeaderActions({ workspace, row, onAction, can, messages }) {
|
|
1871
|
+
const words = { ...defaultNativeResourceWorkspaceMessages, ...messages };
|
|
1872
|
+
const provider = useDataProvider();
|
|
1873
|
+
const queryClient = useQueryClient();
|
|
1874
|
+
const view = workspace.view;
|
|
1875
|
+
const capabilities = useCapabilities$1(view.resource, { enabled: !onAction && !!provider.capabilities });
|
|
1876
|
+
const described = useQuery({
|
|
1877
|
+
queryKey: ["__describe", view.resource],
|
|
1878
|
+
queryFn: () => provider.describe(view.resource),
|
|
1879
|
+
enabled: !onAction && !!provider.describe,
|
|
1880
|
+
staleTime: Infinity
|
|
1881
|
+
});
|
|
1882
|
+
const viewer = useViewer$1();
|
|
1883
|
+
const actions = workspace.headerFor(row, {
|
|
1884
|
+
viewer,
|
|
1885
|
+
runnable: Boolean(onAction) || Boolean(provider.runAction) && capabilities.data?.actions !== false,
|
|
1886
|
+
...!onAction && described.data?.actions ? { served: described.data.actions.map((a) => a.name) } : {},
|
|
1887
|
+
...can ? { can: (name) => can(name, row) } : {}
|
|
1888
|
+
}).actions;
|
|
1889
|
+
const running = useRef(false);
|
|
1890
|
+
const [pending, setPending] = useState(false);
|
|
1891
|
+
const run = async (a) => {
|
|
1892
|
+
if (running.current) return;
|
|
1893
|
+
running.current = true;
|
|
1894
|
+
setPending(true);
|
|
1895
|
+
try {
|
|
1896
|
+
if (onAction) await onAction(a.name, row);
|
|
1897
|
+
else if (provider.runAction) await provider.runAction(view.resource, { id: workspace.recordId(row), action: a.name });
|
|
1898
|
+
else throw new DataWriteError("error", fill(words.noRunner, { name: a.label }));
|
|
1899
|
+
await queryClient.invalidateQueries({ queryKey: [...resourceKeys(view.resource).all] });
|
|
1900
|
+
} catch (error) {
|
|
1901
|
+
Alert.alert(a.label, refusalMessage(error, words.failed));
|
|
1902
|
+
} finally {
|
|
1903
|
+
running.current = false;
|
|
1904
|
+
setPending(false);
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
const press = (a) => {
|
|
1908
|
+
if (running.current) return;
|
|
1909
|
+
if (a.allowed !== true) return Alert.alert(a.label, a.allowed);
|
|
1910
|
+
if (!a.confirm) return void run(a);
|
|
1911
|
+
Alert.alert(a.confirm, a.description, [
|
|
1912
|
+
{ text: words.cancel, style: "cancel" },
|
|
1913
|
+
{ text: a.label, style: a.destructive ? "destructive" : "default", onPress: () => void run(a) }
|
|
1914
|
+
]);
|
|
1915
|
+
};
|
|
1916
|
+
return { actions, press, pending, words };
|
|
1917
|
+
}
|
|
1918
|
+
var A11Y_PREFIX = "action:";
|
|
1919
|
+
function NativeResourceWorkspaceMenu(props) {
|
|
1920
|
+
const { testID = "native-resource-workspace-menu" } = props;
|
|
1921
|
+
const { actions, press, pending, words } = useHeaderActions(props);
|
|
1922
|
+
const [open, setOpen] = useState(false);
|
|
1923
|
+
if (actions.length === 0) return null;
|
|
1924
|
+
const labelOf = (a) => a.allowed === true ? a.label : `${a.label} (${a.allowed})`;
|
|
1925
|
+
const show = () => {
|
|
1926
|
+
if (Platform.OS === "ios") {
|
|
1927
|
+
const destructive = actions.flatMap((a, i) => a.destructive ? [i] : []);
|
|
1928
|
+
ActionSheetIOS.showActionSheetWithOptions(
|
|
1929
|
+
{
|
|
1930
|
+
title: props.workspace.headerFor(props.row).title,
|
|
1931
|
+
options: [...actions.map(labelOf), words.cancel],
|
|
1932
|
+
cancelButtonIndex: actions.length,
|
|
1933
|
+
...destructive.length ? { destructiveButtonIndex: destructive } : {}
|
|
1934
|
+
},
|
|
1935
|
+
(index) => {
|
|
1936
|
+
const a = actions[index];
|
|
1937
|
+
if (a) press(a);
|
|
1938
|
+
}
|
|
1939
|
+
);
|
|
1940
|
+
} else {
|
|
1941
|
+
setOpen(true);
|
|
1942
|
+
}
|
|
1943
|
+
};
|
|
1944
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1945
|
+
/* @__PURE__ */ jsx(
|
|
1946
|
+
Pressable,
|
|
1947
|
+
{
|
|
1948
|
+
testID,
|
|
1949
|
+
accessibilityRole: "button",
|
|
1950
|
+
accessibilityLabel: words.actions,
|
|
1951
|
+
accessibilityState: { disabled: pending, busy: pending },
|
|
1952
|
+
disabled: pending,
|
|
1953
|
+
accessibilityActions: actions.map((a) => ({ name: `${A11Y_PREFIX}${a.name}`, label: a.allowed === true ? a.label : `${a.label}: ${a.allowed}` })),
|
|
1954
|
+
onAccessibilityAction: (event) => {
|
|
1955
|
+
const name = event.nativeEvent.actionName;
|
|
1956
|
+
const a = name.startsWith(A11Y_PREFIX) ? actions.find((x) => `${A11Y_PREFIX}${x.name}` === name) : void 0;
|
|
1957
|
+
if (a) press(a);
|
|
1958
|
+
},
|
|
1959
|
+
onPress: show,
|
|
1960
|
+
hitSlop: 8,
|
|
1961
|
+
className: "min-h-[44px] min-w-[44px] items-center justify-center",
|
|
1962
|
+
children: /* @__PURE__ */ jsx(NativeIcon, { name: "more", label: words.actions })
|
|
1963
|
+
}
|
|
1964
|
+
),
|
|
1965
|
+
/* @__PURE__ */ jsx(NativeSheet, { open, onOpenChange: setOpen, testID: `${testID}-sheet`, children: /* @__PURE__ */ jsxs(View, { style: { paddingVertical: 8 }, children: [
|
|
1966
|
+
actions.map((a) => /* @__PURE__ */ jsxs(
|
|
1967
|
+
Pressable,
|
|
1968
|
+
{
|
|
1969
|
+
testID: `${testID}-${a.name}`,
|
|
1970
|
+
accessibilityRole: "button",
|
|
1971
|
+
accessibilityLabel: a.allowed === true ? a.label : `${a.label}: ${a.allowed}`,
|
|
1972
|
+
onPress: () => {
|
|
1973
|
+
setOpen(false);
|
|
1974
|
+
press(a);
|
|
1975
|
+
},
|
|
1976
|
+
className: "min-h-[48px] justify-center px-4",
|
|
1977
|
+
children: [
|
|
1978
|
+
/* @__PURE__ */ jsx(NativeText, { preset: "body", className: a.destructive ? "text-destructive" : void 0, children: a.label }),
|
|
1979
|
+
a.allowed !== true ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-muted-foreground", children: a.allowed }) : null
|
|
1980
|
+
]
|
|
1981
|
+
},
|
|
1982
|
+
a.name
|
|
1983
|
+
)),
|
|
1984
|
+
/* @__PURE__ */ jsx(Pressable, { testID: `${testID}-cancel`, accessibilityRole: "button", onPress: () => setOpen(false), className: "min-h-[48px] justify-center px-4", children: /* @__PURE__ */ jsx(NativeText, { preset: "body", className: "text-muted-foreground", children: words.cancel }) })
|
|
1985
|
+
] }) })
|
|
1986
|
+
] });
|
|
1987
|
+
}
|
|
1988
|
+
function getNativeResourceWorkspaceStackOptions(props) {
|
|
1989
|
+
const { workspace, row, onAction, can, messages, ...header } = props;
|
|
1990
|
+
const menu = { workspace, row, ...onAction ? { onAction } : {}, ...can ? { can } : {}, ...messages ? { messages } : {} };
|
|
1991
|
+
return composeHeaderOptions({
|
|
1992
|
+
...header,
|
|
1993
|
+
headerTitle: workspace.headerFor(row).title,
|
|
1994
|
+
headerRight: header.headerRight ?? (workspace.headerActions.length ? () => /* @__PURE__ */ jsx(NativeResourceWorkspaceMenu, { ...menu }) : void 0)
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
function NativeResourceWorkspace(props) {
|
|
1998
|
+
const { workspace, row, section, onSectionChange, onOpenSection, onSaved, switcher, slots, lists, messages, testID = "native-resource-workspace" } = props;
|
|
1999
|
+
const words = { ...defaultNativeResourceWorkspaceMessages, ...messages };
|
|
2000
|
+
const colors = useThemeRoles();
|
|
2001
|
+
const queryClient = useQueryClient();
|
|
2002
|
+
const record = row;
|
|
2003
|
+
const sections = workspace.sections;
|
|
2004
|
+
const many = sections.length > SEGMENTED_SECTIONS_MAX;
|
|
2005
|
+
const [local, setLocal] = useState(void 0);
|
|
2006
|
+
const activeId = section ?? local ?? (many ? void 0 : sections[0]?.id);
|
|
2007
|
+
const active = activeId ? workspace.section(activeId) : void 0;
|
|
2008
|
+
const readiness = workspace.readinessFor(record);
|
|
2009
|
+
const summary = workspace.readinessSummary(record);
|
|
2010
|
+
const chip = summary ? readinessChip(summary, words) : null;
|
|
2011
|
+
const choose = (id) => {
|
|
2012
|
+
if (many && onOpenSection) return onOpenSection(id);
|
|
2013
|
+
setLocal(id);
|
|
2014
|
+
onSectionChange?.(id);
|
|
2015
|
+
};
|
|
2016
|
+
const top = /* @__PURE__ */ jsxs(View, { style: { paddingHorizontal: 16, paddingTop: 8, gap: 12 }, children: [
|
|
2017
|
+
switcher,
|
|
2018
|
+
chip ? /* @__PURE__ */ jsx(View, { style: { flexDirection: "row" }, children: /* @__PURE__ */ jsx(NativeBadge, { testID: `${testID}-readiness`, variant: badgeVariant(chip.tone), children: chip.label }) }) : null,
|
|
2019
|
+
readiness.some((r) => !r.ok) ? /* @__PURE__ */ jsx(Group, { testID: `${testID}-checks`, title: words.checks, children: readiness.map((r, i) => /* @__PURE__ */ jsx(Cell, { last: i === readiness.length - 1, children: /* @__PURE__ */ jsx(
|
|
2020
|
+
NativeListItem,
|
|
2021
|
+
{
|
|
2022
|
+
testID: `${testID}-check-${i}`,
|
|
2023
|
+
title: r.title,
|
|
2024
|
+
subtitle: r.ok ? void 0 : r.reason,
|
|
2025
|
+
className: "bg-transparent",
|
|
2026
|
+
trailing: /* @__PURE__ */ jsx(NativeBadge, { testID: `${testID}-check-${i}-chip`, variant: badgeVariant(r.tone), children: r.ok ? words.checkDone : words.checkTodo })
|
|
2027
|
+
}
|
|
2028
|
+
) }, r.key)) }) : null,
|
|
2029
|
+
!many ? /* @__PURE__ */ jsx(
|
|
2030
|
+
NativeSegmentedControl,
|
|
2031
|
+
{
|
|
2032
|
+
testID: `${testID}-sections`,
|
|
2033
|
+
options: sections.map((s) => ({ value: s.id, label: s.label })),
|
|
2034
|
+
value: activeId ?? "",
|
|
2035
|
+
onChange: choose
|
|
2036
|
+
}
|
|
2037
|
+
) : null
|
|
2038
|
+
] });
|
|
2039
|
+
let body = null;
|
|
2040
|
+
if (many && !active) {
|
|
2041
|
+
body = /* @__PURE__ */ jsx(ScrollView, { contentContainerStyle: { padding: 16 }, children: /* @__PURE__ */ jsx(Group, { testID: `${testID}-sections`, children: sections.map((s, i) => /* @__PURE__ */ jsx(Cell, { last: i === sections.length - 1, children: /* @__PURE__ */ jsx(NativeListItem, { testID: `${testID}-section-${s.id}`, title: s.label, showChevron: true, onPress: () => choose(s.id), className: "bg-transparent" }) }, s.id)) }) });
|
|
2042
|
+
}
|
|
2043
|
+
const back = many && local !== void 0 && section === void 0 ? /* @__PURE__ */ jsx(View, { style: { paddingHorizontal: 16, paddingTop: 8 }, children: /* @__PURE__ */ jsx(Group, { testID: `${testID}-back`, children: /* @__PURE__ */ jsx(Cell, { last: true, children: /* @__PURE__ */ jsx(
|
|
2044
|
+
NativeListItem,
|
|
2045
|
+
{
|
|
2046
|
+
testID: `${testID}-all-sections`,
|
|
2047
|
+
title: words.allSections,
|
|
2048
|
+
leading: /* @__PURE__ */ jsx(NativeIcon, { name: "chevron-left" }),
|
|
2049
|
+
onPress: () => setLocal(void 0),
|
|
2050
|
+
className: "bg-transparent"
|
|
2051
|
+
}
|
|
2052
|
+
) }) }) }) : null;
|
|
2053
|
+
if (active?.kind === "list") {
|
|
2054
|
+
body = /* @__PURE__ */ jsx(
|
|
2055
|
+
NativeResourceView,
|
|
2056
|
+
{
|
|
2057
|
+
view: active.view,
|
|
2058
|
+
testID: `${testID}-list`,
|
|
2059
|
+
...lists?.[active.id],
|
|
2060
|
+
title: false,
|
|
2061
|
+
filter: workspace.listFilter(active.id, record)
|
|
2062
|
+
},
|
|
2063
|
+
active.id
|
|
2064
|
+
);
|
|
2065
|
+
} else if (active?.kind === "settings") {
|
|
2066
|
+
body = /* @__PURE__ */ jsx(ScrollView, { contentContainerStyle: { padding: 16 }, keyboardShouldPersistTaps: "handled", children: /* @__PURE__ */ jsx(
|
|
2067
|
+
SettingsGroup,
|
|
2068
|
+
{
|
|
2069
|
+
workspace,
|
|
2070
|
+
sectionId: active.id,
|
|
2071
|
+
row: record,
|
|
2072
|
+
words,
|
|
2073
|
+
onSaved: (saved) => {
|
|
2074
|
+
void queryClient.invalidateQueries({ queryKey: [...resourceKeys(workspace.view.resource).all] });
|
|
2075
|
+
onSaved?.(saved);
|
|
2076
|
+
},
|
|
2077
|
+
testID: `${testID}-settings`
|
|
2078
|
+
},
|
|
2079
|
+
`${String(workspace.recordId(record))}:${active.id}`
|
|
2080
|
+
) });
|
|
2081
|
+
} else if (active) {
|
|
2082
|
+
body = slots?.[active.id] ?? null;
|
|
2083
|
+
}
|
|
2084
|
+
return /* @__PURE__ */ jsxs(View, { testID, style: { flex: 1, backgroundColor: colors.groupedBackground }, children: [
|
|
2085
|
+
top,
|
|
2086
|
+
back,
|
|
2087
|
+
/* @__PURE__ */ jsx(View, { style: { flex: 1 }, children: body })
|
|
2088
|
+
] });
|
|
2089
|
+
}
|
|
2090
|
+
function SettingsGroup({
|
|
2091
|
+
workspace,
|
|
2092
|
+
sectionId,
|
|
2093
|
+
row,
|
|
2094
|
+
words,
|
|
2095
|
+
onSaved,
|
|
2096
|
+
testID
|
|
2097
|
+
}) {
|
|
2098
|
+
const provider = useDataProvider();
|
|
2099
|
+
const view = workspace.view;
|
|
2100
|
+
const fields = useMemo(() => {
|
|
2101
|
+
const byKey = new Map(formFieldsFor(view, "edit").map((f) => [f.key, f]));
|
|
2102
|
+
return workspace.settingsFields(sectionId).map((f) => byKey.get(f.field.name)).filter((f) => !!f && !f.readOnly);
|
|
2103
|
+
}, [workspace, view, sectionId]);
|
|
2104
|
+
const viewer = useViewer$1();
|
|
2105
|
+
const locked = workspace.settingsLocked(row, viewer);
|
|
2106
|
+
const [draft, setDraft] = useState(() => Object.fromEntries(fields.map((f) => [f.key, row[f.key]])));
|
|
2107
|
+
const [invalid, setInvalid] = useState({});
|
|
2108
|
+
const [saving, setSaving] = useState(false);
|
|
2109
|
+
const [refusal, setRefusal] = useState(null);
|
|
2110
|
+
const shown = fields.filter((f) => !f.visible || f.visible(draft));
|
|
2111
|
+
const changed = {};
|
|
2112
|
+
for (const f of shown) if (draft[f.key] !== row[f.key]) changed[f.key] = draft[f.key];
|
|
2113
|
+
const dirty = Object.keys(changed).length > 0 && !shown.some((f) => invalid[f.key]);
|
|
2114
|
+
const set = (key, value, error) => {
|
|
2115
|
+
setRefusal(null);
|
|
2116
|
+
setInvalid(({ [key]: _old, ...rest }) => error ? { ...rest, [key]: error } : rest);
|
|
2117
|
+
setDraft((d) => ({ ...d, [key]: value }));
|
|
2118
|
+
};
|
|
2119
|
+
const save = async () => {
|
|
2120
|
+
setSaving(true);
|
|
2121
|
+
setRefusal(null);
|
|
2122
|
+
try {
|
|
2123
|
+
const result = await provider.update(view.resource, { id: workspace.recordId(row), data: workspace.settingsPatch(sectionId, changed) });
|
|
2124
|
+
if (!result || result.data === null || result.data === void 0) setRefusal(fill(words.notChanged, { noun: view.noun }));
|
|
2125
|
+
else onSaved(result.data);
|
|
2126
|
+
} catch (error) {
|
|
2127
|
+
setRefusal(refusalMessage(error, words.failed));
|
|
2128
|
+
} finally {
|
|
2129
|
+
setSaving(false);
|
|
2130
|
+
}
|
|
2131
|
+
};
|
|
2132
|
+
return /* @__PURE__ */ jsxs(View, { style: { gap: 12 }, children: [
|
|
2133
|
+
refusal ? /* @__PURE__ */ jsx(NativeInlineAlert, { testID: `${testID}-refusal`, variant: "destructive", description: refusal }) : null,
|
|
2134
|
+
locked !== null ? /* @__PURE__ */ jsx(NativeInlineAlert, { testID: `${testID}-locked`, variant: "info", description: locked }) : null,
|
|
2135
|
+
/* @__PURE__ */ jsx(Group, { testID: `${testID}-group`, title: workspace.section(sectionId)?.label, children: shown.map((f, i) => /* @__PURE__ */ jsx(Cell, { last: i === shown.length - 1, children: /* @__PURE__ */ jsx(
|
|
2136
|
+
SettingRow,
|
|
2137
|
+
{
|
|
2138
|
+
field: f,
|
|
2139
|
+
nullable: Boolean(view.field(f.key)?.nullable),
|
|
2140
|
+
value: draft[f.key],
|
|
2141
|
+
error: invalid[f.key],
|
|
2142
|
+
disabled: locked !== null,
|
|
2143
|
+
words,
|
|
2144
|
+
onChange: (v, error) => set(f.key, v, error),
|
|
2145
|
+
testID: `${testID}-${f.key}`
|
|
2146
|
+
}
|
|
2147
|
+
) }, f.key)) }),
|
|
2148
|
+
locked === null ? /* @__PURE__ */ jsx(NativeButton, { testID: `${testID}-save`, disabled: !dirty || saving, loading: saving, onPress: () => void save(), children: words.save }) : null
|
|
2149
|
+
] });
|
|
2150
|
+
}
|
|
2151
|
+
function parseSettingNumber(text2) {
|
|
2152
|
+
const t = text2.trim();
|
|
2153
|
+
const normalised = /^-?\d+,\d+$/.test(t) ? t.replace(",", ".") : t;
|
|
2154
|
+
const n = normalised === "" ? Number.NaN : Number(normalised);
|
|
2155
|
+
return Number.isFinite(n) ? n : null;
|
|
2156
|
+
}
|
|
2157
|
+
function SettingRow({
|
|
2158
|
+
field: f,
|
|
2159
|
+
nullable,
|
|
2160
|
+
value,
|
|
2161
|
+
error,
|
|
2162
|
+
disabled,
|
|
2163
|
+
words,
|
|
2164
|
+
onChange,
|
|
2165
|
+
testID
|
|
2166
|
+
}) {
|
|
2167
|
+
const empty = nullable ? null : "";
|
|
2168
|
+
const [typed, setTyped] = useState(() => value == null ? "" : String(value));
|
|
2169
|
+
if (f.kind === "switch") {
|
|
2170
|
+
return /* @__PURE__ */ jsx(
|
|
2171
|
+
NativeListItem,
|
|
2172
|
+
{
|
|
2173
|
+
testID,
|
|
2174
|
+
title: f.label,
|
|
2175
|
+
className: "bg-transparent",
|
|
2176
|
+
disabled,
|
|
2177
|
+
trailing: /* @__PURE__ */ jsx(NativeSwitch, { testID: `${testID}-input`, "aria-label": f.label, checked: value === true, disabled, onCheckedChange: (v) => onChange(v) })
|
|
2178
|
+
}
|
|
2179
|
+
);
|
|
2180
|
+
}
|
|
2181
|
+
const text2 = value == null ? "" : String(value);
|
|
2182
|
+
let control;
|
|
2183
|
+
if (f.kind === "segmented") {
|
|
2184
|
+
control = /* @__PURE__ */ jsx(NativeSegmentedControl, { testID: `${testID}-input`, options: f.options ?? [], value: text2, disabled, onChange: (v) => onChange(v) });
|
|
2185
|
+
} else if (f.kind === "select") {
|
|
2186
|
+
control = /* @__PURE__ */ jsxs(NativeSelect, { value: text2, onValueChange: (v) => onChange(v), children: [
|
|
2187
|
+
/* @__PURE__ */ jsx(NativeSelectTrigger, { testID: `${testID}-input`, placeholder: f.label, disabled }),
|
|
2188
|
+
/* @__PURE__ */ jsx(NativeSelectContent, { children: (f.options ?? []).map((o) => /* @__PURE__ */ jsx(NativeSelectItem, { value: o.value, children: o.label }, o.value)) })
|
|
2189
|
+
] });
|
|
2190
|
+
} else if (f.kind === "textarea") {
|
|
2191
|
+
control = /* @__PURE__ */ jsx(
|
|
2192
|
+
NativeTextarea,
|
|
2193
|
+
{
|
|
2194
|
+
testID: `${testID}-input`,
|
|
2195
|
+
accessibilityLabel: f.label,
|
|
2196
|
+
editable: !disabled,
|
|
2197
|
+
value: text2,
|
|
2198
|
+
maxLength: f.max,
|
|
2199
|
+
onChangeText: (t) => onChange(t === "" ? empty : t)
|
|
2200
|
+
}
|
|
2201
|
+
);
|
|
2202
|
+
} else if (f.kind === "number") {
|
|
2203
|
+
control = /* @__PURE__ */ jsx(
|
|
2204
|
+
NativeInput,
|
|
2205
|
+
{
|
|
2206
|
+
testID: `${testID}-input`,
|
|
2207
|
+
accessibilityLabel: f.label,
|
|
2208
|
+
editable: !disabled,
|
|
2209
|
+
value: typed,
|
|
2210
|
+
keyboardType: "decimal-pad",
|
|
2211
|
+
error,
|
|
2212
|
+
onChangeText: (t) => {
|
|
2213
|
+
setTyped(t);
|
|
2214
|
+
if (t.trim() === "") return onChange(empty);
|
|
2215
|
+
const n = parseSettingNumber(t);
|
|
2216
|
+
return n === null ? onChange(t, words.notANumber) : onChange(n);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
);
|
|
2220
|
+
} else {
|
|
2221
|
+
control = /* @__PURE__ */ jsx(
|
|
2222
|
+
NativeInput,
|
|
2223
|
+
{
|
|
2224
|
+
testID: `${testID}-input`,
|
|
2225
|
+
accessibilityLabel: f.label,
|
|
2226
|
+
editable: !disabled,
|
|
2227
|
+
value: text2,
|
|
2228
|
+
maxLength: f.max,
|
|
2229
|
+
autoCapitalize: f.kind === "text" ? "sentences" : "none",
|
|
2230
|
+
keyboardType: f.kind === "email" ? "email-address" : f.kind === "url" ? "url" : "default",
|
|
2231
|
+
onChangeText: (t) => onChange(t === "" ? empty : t)
|
|
2232
|
+
}
|
|
2233
|
+
);
|
|
2234
|
+
}
|
|
2235
|
+
return /* @__PURE__ */ jsxs(View, { testID, style: { paddingHorizontal: 16, paddingVertical: 10, gap: 6, opacity: disabled ? 0.6 : 1 }, children: [
|
|
2236
|
+
/* @__PURE__ */ jsx(NativeText, { preset: "body-sm", className: "font-medium", children: f.label }),
|
|
2237
|
+
control
|
|
2238
|
+
] });
|
|
2239
|
+
}
|
|
2240
|
+
function Group({ title, children, testID }) {
|
|
2241
|
+
const colors = useThemeRoles();
|
|
2242
|
+
const ios = Platform.OS === "ios";
|
|
2243
|
+
return /* @__PURE__ */ jsxs(View, { testID, style: { gap: 6 }, children: [
|
|
2244
|
+
title ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", accessibilityRole: "header", className: ios ? "uppercase text-muted-foreground px-4" : "text-primary px-4", children: title }) : null,
|
|
2245
|
+
/* @__PURE__ */ jsx(View, { style: { backgroundColor: colors.surface, borderRadius: ios ? 10 : 0, overflow: "hidden" }, children })
|
|
2246
|
+
] });
|
|
2247
|
+
}
|
|
2248
|
+
function Cell({ last, children }) {
|
|
2249
|
+
const colors = useThemeRoles();
|
|
2250
|
+
return /* @__PURE__ */ jsxs(View, { children: [
|
|
2251
|
+
children,
|
|
2252
|
+
!last ? /* @__PURE__ */ jsx(View, { style: { height: 0.5, marginLeft: 16, backgroundColor: colors.separator } }) : null
|
|
2253
|
+
] });
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
export { DEFAULT_MAX_PAGES, DisplayRenderersProvider, DisplayTimeZonesProvider, NativeDataFilters, NativeDataPageShell, NativeDetailPanel, NativeEmptyState2 as NativeEmptyState, NativeResourceForm, NativeResourceFormFieldRenderer, NativeResourceFormSheet, NativeResourcePage, NativeResourceView, NativeResourceViewMessagesProvider, NativeResourceWorkspace, NativeResourceWorkspaceMenu, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
|
|
794
2257
|
//# sourceMappingURL=index.js.map
|
|
795
2258
|
//# sourceMappingURL=index.js.map
|