@marktiderman/genesis-ui-native 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/chunk-BAU4YQZV.js +760 -0
  2. package/dist/chunk-BAU4YQZV.js.map +1 -0
  3. package/dist/chunk-DGUM43GV.js +10 -0
  4. package/dist/chunk-DGUM43GV.js.map +1 -0
  5. package/dist/chunk-HNIEFTEL.js +43 -0
  6. package/dist/chunk-HNIEFTEL.js.map +1 -0
  7. package/dist/chunk-N4WHTQIO.js +20 -0
  8. package/dist/chunk-N4WHTQIO.js.map +1 -0
  9. package/dist/chunk-OHZD7KRO.js +11 -0
  10. package/dist/chunk-OHZD7KRO.js.map +1 -0
  11. package/dist/chunk-PTJ2KCLM.js +160 -0
  12. package/dist/chunk-PTJ2KCLM.js.map +1 -0
  13. package/dist/chunk-TXJT55JC.js +2213 -0
  14. package/dist/chunk-TXJT55JC.js.map +1 -0
  15. package/dist/chunk-ULS7I6ZS.js +183 -0
  16. package/dist/chunk-ULS7I6ZS.js.map +1 -0
  17. package/dist/chunk-ZVF6PONU.js +522 -0
  18. package/dist/chunk-ZVF6PONU.js.map +1 -0
  19. package/dist/components/index.d.ts +908 -0
  20. package/dist/components/index.js +8 -0
  21. package/dist/components/index.js.map +1 -0
  22. package/dist/data/index.d.ts +117 -0
  23. package/dist/data/index.js +770 -0
  24. package/dist/data/index.js.map +1 -0
  25. package/dist/hooks/index.d.ts +31 -0
  26. package/dist/hooks/index.js +5 -0
  27. package/dist/hooks/index.js.map +1 -0
  28. package/dist/index.d.ts +11 -0
  29. package/dist/index.js +11 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/layouts/index.d.ts +364 -0
  32. package/dist/layouts/index.js +8 -0
  33. package/dist/layouts/index.js.map +1 -0
  34. package/dist/utils.d.ts +5 -0
  35. package/dist/utils.js +4 -0
  36. package/dist/utils.js.map +1 -0
  37. package/package.json +127 -0
  38. package/src/components/__tests__/accordion.test.tsx +122 -0
  39. package/src/components/__tests__/chip-group.test.tsx +45 -0
  40. package/src/components/__tests__/combobox.test.tsx +97 -0
  41. package/src/components/__tests__/drawer.test.tsx +98 -0
  42. package/src/components/__tests__/empty-state.test.tsx +66 -0
  43. package/src/components/__tests__/header-card.test.tsx +31 -0
  44. package/src/components/__tests__/layout.test.tsx +109 -0
  45. package/src/components/__tests__/list-item.test.tsx +31 -0
  46. package/src/components/__tests__/number-input.test.tsx +46 -0
  47. package/src/components/__tests__/pagination.test.tsx +43 -0
  48. package/src/components/__tests__/search-bar.test.tsx +41 -0
  49. package/src/components/__tests__/segmented-empty-alert.test.tsx +79 -0
  50. package/src/components/__tests__/slider.test.tsx +134 -0
  51. package/src/components/__tests__/stepper.test.tsx +25 -0
  52. package/src/components/__tests__/toast.test.tsx +63 -0
  53. package/src/components/accordion.tsx +223 -0
  54. package/src/components/alert.tsx +131 -0
  55. package/src/components/avatar.tsx +68 -0
  56. package/src/components/badge.tsx +80 -0
  57. package/src/components/button.tsx +118 -0
  58. package/src/components/card.tsx +120 -0
  59. package/src/components/checkbox.tsx +60 -0
  60. package/src/components/chip-group.tsx +127 -0
  61. package/src/components/combobox.tsx +137 -0
  62. package/src/components/date-time-picker.tsx +127 -0
  63. package/src/components/dialog.tsx +131 -0
  64. package/src/components/drawer.tsx +131 -0
  65. package/src/components/dropdown-menu.tsx +133 -0
  66. package/src/components/empty-state.tsx +161 -0
  67. package/src/components/header-card.tsx +116 -0
  68. package/src/components/index.ts +259 -0
  69. package/src/components/inline-alert.tsx +150 -0
  70. package/src/components/input.tsx +51 -0
  71. package/src/components/label.tsx +35 -0
  72. package/src/components/layout/box.tsx +115 -0
  73. package/src/components/layout/flex.ts +24 -0
  74. package/src/components/layout/grid.tsx +73 -0
  75. package/src/components/layout/index.ts +27 -0
  76. package/src/components/layout/inline.tsx +63 -0
  77. package/src/components/layout/spacing.ts +116 -0
  78. package/src/components/layout/stack.tsx +58 -0
  79. package/src/components/list-item.tsx +108 -0
  80. package/src/components/number-input.tsx +119 -0
  81. package/src/components/pagination.tsx +132 -0
  82. package/src/components/popover.tsx +198 -0
  83. package/src/components/progress.tsx +50 -0
  84. package/src/components/radio-group.tsx +92 -0
  85. package/src/components/refresh-control.tsx +73 -0
  86. package/src/components/search-bar.tsx +128 -0
  87. package/src/components/section-list.tsx +54 -0
  88. package/src/components/segmented-control.tsx +79 -0
  89. package/src/components/select.tsx +178 -0
  90. package/src/components/separator.tsx +31 -0
  91. package/src/components/sheet.tsx +192 -0
  92. package/src/components/skeleton.tsx +104 -0
  93. package/src/components/slider.tsx +223 -0
  94. package/src/components/stepper.tsx +96 -0
  95. package/src/components/switch.tsx +35 -0
  96. package/src/components/tabs.tsx +147 -0
  97. package/src/components/text.tsx +62 -0
  98. package/src/components/textarea.tsx +52 -0
  99. package/src/components/toast.tsx +228 -0
  100. package/src/components/toggle.tsx +85 -0
  101. package/src/components/tooltip.tsx +104 -0
  102. package/src/data/NativeDataFilters.tsx +100 -0
  103. package/src/data/NativeDataPageShell.tsx +111 -0
  104. package/src/data/NativeDetailPanel.tsx +130 -0
  105. package/src/data/NativeEmptyState.tsx +46 -0
  106. package/src/data/NativeResourceForm.tsx +157 -0
  107. package/src/data/NativeResourceFormField.tsx +280 -0
  108. package/src/data/NativeResourcePage.tsx +505 -0
  109. package/src/data/index.ts +9 -0
  110. package/src/hooks/index.ts +16 -0
  111. package/src/hooks/use-genesis-extension.ts +81 -0
  112. package/src/hooks/use-reduced-motion.ts +32 -0
  113. package/src/hooks/use-theme-mode.ts +31 -0
  114. package/src/index.ts +5 -0
  115. package/src/layouts/__tests__/auth.test.tsx +150 -0
  116. package/src/layouts/__tests__/nav-bar.test.tsx +86 -0
  117. package/src/layouts/__tests__/notifications-page.test.tsx +94 -0
  118. package/src/layouts/__tests__/screen-container.test.tsx +79 -0
  119. package/src/layouts/__tests__/settings-page.test.tsx +107 -0
  120. package/src/layouts/__tests__/settings-sub-page.test.tsx +53 -0
  121. package/src/layouts/auth.tsx +352 -0
  122. package/src/layouts/index.ts +61 -0
  123. package/src/layouts/nav-bar.tsx +200 -0
  124. package/src/layouts/notifications-page.tsx +274 -0
  125. package/src/layouts/screen-container.tsx +213 -0
  126. package/src/layouts/settings-page.tsx +195 -0
  127. package/src/layouts/settings-sub-page.tsx +183 -0
  128. package/src/nativewind.d.ts +40 -0
  129. package/src/utils.ts +6 -0
@@ -0,0 +1,770 @@
1
+ import { NativeBadge, NativeCard, NativeCardContent, NativeSeparator, NativeLabel, NativeSwitch, NativeCheckbox, NativeSelect, NativeSelectTrigger, NativeSelectContent, NativeSelectItem, NativeTextarea, NativeAlert, NativeAlertTitle, NativeAlertDescription, NativeSkeleton, NativeCardHeader, NativeCardTitle } from '../chunk-ZVF6PONU.js';
2
+ import { NativeText, NativeButton, NativeInput } from '../chunk-PTJ2KCLM.js';
3
+ import '../chunk-OHZD7KRO.js';
4
+ import '../chunk-DGUM43GV.js';
5
+ import { View, ScrollView, Pressable, FlatList } from 'react-native';
6
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
7
+ import * as React from 'react';
8
+ import { useCallback, useState, useMemo, useEffect } from 'react';
9
+ import { SafeAreaView } from 'react-native-safe-area-context';
10
+ import { titleCase, useResourceForm } from '@marktiderman/genesis-core';
11
+ import { Controller } from 'react-hook-form';
12
+ import { useResource } from '@marktiderman/genesis-core/hooks';
13
+
14
+ function NativeEmptyState({
15
+ message = "No items found",
16
+ action,
17
+ hasFilters = false,
18
+ onClearFilters
19
+ }) {
20
+ if (hasFilters) {
21
+ return /* @__PURE__ */ jsxs(View, { className: "flex-1 items-center justify-center px-4 py-12", children: [
22
+ /* @__PURE__ */ jsx(NativeText, { preset: "body", className: "text-muted-foreground text-center", children: "No results match your filters" }),
23
+ onClearFilters ? /* @__PURE__ */ jsx(View, { className: "mt-4", children: /* @__PURE__ */ jsx(NativeButton, { variant: "outline", size: "sm", onPress: onClearFilters, children: "Clear Filters" }) }) : null
24
+ ] });
25
+ }
26
+ return /* @__PURE__ */ jsxs(View, { className: "flex-1 items-center justify-center px-4 py-12", children: [
27
+ /* @__PURE__ */ jsx(NativeText, { preset: "body", className: "text-muted-foreground text-center", children: message }),
28
+ action ? /* @__PURE__ */ jsx(View, { className: "mt-4", children: action }) : null
29
+ ] });
30
+ }
31
+ function NativeDataFilters({
32
+ search,
33
+ onSearchChange,
34
+ searchPlaceholder = "Search...",
35
+ statusChips,
36
+ sort
37
+ }) {
38
+ const handleStatusToggle = useCallback(
39
+ (option) => {
40
+ if (!statusChips) return;
41
+ const isSelected = statusChips.selected.includes(option);
42
+ const next = isSelected ? statusChips.selected.filter((s) => s !== option) : [...statusChips.selected, option];
43
+ statusChips.onChange(next);
44
+ },
45
+ [statusChips]
46
+ );
47
+ const handleSortToggle = useCallback(
48
+ (value) => {
49
+ sort?.onChange(value);
50
+ },
51
+ [sort]
52
+ );
53
+ return /* @__PURE__ */ jsxs(View, { style: { gap: 12 }, children: [
54
+ /* @__PURE__ */ jsx(
55
+ NativeInput,
56
+ {
57
+ placeholder: searchPlaceholder,
58
+ value: search,
59
+ onChangeText: onSearchChange
60
+ }
61
+ ),
62
+ statusChips && statusChips.options.length > 0 && /* @__PURE__ */ jsx(
63
+ ScrollView,
64
+ {
65
+ horizontal: true,
66
+ showsHorizontalScrollIndicator: false,
67
+ contentContainerStyle: { gap: 8 },
68
+ children: statusChips.options.map((option) => {
69
+ const isSelected = statusChips.selected.includes(option);
70
+ return /* @__PURE__ */ jsx(Pressable, { onPress: () => handleStatusToggle(option), children: /* @__PURE__ */ jsx(NativeBadge, { variant: isSelected ? "default" : "outline", children: option }) }, option);
71
+ })
72
+ }
73
+ ),
74
+ sort && sort.options.length > 0 && /* @__PURE__ */ jsx(
75
+ ScrollView,
76
+ {
77
+ horizontal: true,
78
+ showsHorizontalScrollIndicator: false,
79
+ contentContainerStyle: { gap: 8 },
80
+ children: sort.options.map((option) => {
81
+ const isSelected = sort.value === option.value;
82
+ return /* @__PURE__ */ jsx(
83
+ Pressable,
84
+ {
85
+ onPress: () => handleSortToggle(option.value),
86
+ children: /* @__PURE__ */ jsx(NativeBadge, { variant: isSelected ? "secondary" : "outline", children: option.label })
87
+ },
88
+ option.value
89
+ );
90
+ })
91
+ }
92
+ )
93
+ ] });
94
+ }
95
+ function NativeDataPageShell({
96
+ title,
97
+ subtitle,
98
+ headerRight,
99
+ isLoading,
100
+ isEmpty,
101
+ hasError,
102
+ errorMessage = "Something went wrong.",
103
+ onRetry,
104
+ emptyMessage,
105
+ emptyState,
106
+ children
107
+ }) {
108
+ const renderContent = () => {
109
+ if (isLoading) {
110
+ return /* @__PURE__ */ jsxs(View, { className: "px-4 pt-4 gap-3", children: [
111
+ /* @__PURE__ */ jsx(NativeSkeleton, { className: "w-full h-10 rounded-lg" }),
112
+ /* @__PURE__ */ jsx(NativeSkeleton, { className: "w-full h-20 rounded-lg" }),
113
+ /* @__PURE__ */ jsx(NativeSkeleton, { className: "w-full h-20 rounded-lg" }),
114
+ /* @__PURE__ */ jsx(NativeSkeleton, { className: "w-full h-20 rounded-lg" })
115
+ ] });
116
+ }
117
+ if (hasError) {
118
+ return /* @__PURE__ */ jsxs(View, { className: "flex-1 items-center justify-center px-4 py-12 gap-4", children: [
119
+ /* @__PURE__ */ jsx(NativeText, { preset: "body", className: "text-destructive text-center", children: errorMessage }),
120
+ onRetry ? /* @__PURE__ */ jsx(NativeButton, { variant: "outline", size: "sm", onPress: onRetry, children: "Try Again" }) : null
121
+ ] });
122
+ }
123
+ if (isEmpty) {
124
+ if (emptyState) {
125
+ return /* @__PURE__ */ jsx(Fragment, { children: emptyState });
126
+ }
127
+ return /* @__PURE__ */ jsx(NativeEmptyState, { message: emptyMessage });
128
+ }
129
+ return /* @__PURE__ */ jsx(Fragment, { children });
130
+ };
131
+ return /* @__PURE__ */ jsxs(SafeAreaView, { edges: ["left", "right"], className: "flex-1 bg-background", children: [
132
+ /* @__PURE__ */ jsx(View, { className: "px-4 pt-4 pb-2", children: /* @__PURE__ */ jsxs(
133
+ View,
134
+ {
135
+ style: {
136
+ flexDirection: "row",
137
+ alignItems: "center",
138
+ justifyContent: "space-between"
139
+ },
140
+ children: [
141
+ /* @__PURE__ */ jsxs(View, { className: "flex-1", children: [
142
+ /* @__PURE__ */ jsx(NativeText, { preset: "h2", children: title }),
143
+ subtitle ? /* @__PURE__ */ jsx(NativeText, { preset: "body-sm", className: "text-muted-foreground mt-0.5", children: subtitle }) : null
144
+ ] }),
145
+ headerRight ? /* @__PURE__ */ jsx(View, { className: "ml-3", children: headerRight }) : null
146
+ ]
147
+ }
148
+ ) }),
149
+ /* @__PURE__ */ jsx(
150
+ ScrollView,
151
+ {
152
+ className: "flex-1",
153
+ contentContainerStyle: { flexGrow: 1 },
154
+ keyboardShouldPersistTaps: "handled",
155
+ children: renderContent()
156
+ }
157
+ )
158
+ ] });
159
+ }
160
+ var SKIP_KEYS = /* @__PURE__ */ new Set(["id", "created_at", "updated_at"]);
161
+ function NativeDetailPanel({
162
+ item,
163
+ titleField,
164
+ fields,
165
+ onEdit,
166
+ onDelete,
167
+ children
168
+ }) {
169
+ const title = titleField ? String(item[titleField] ?? "") : void 0;
170
+ const hasActions = onEdit != null || onDelete != null;
171
+ if (children) {
172
+ return /* @__PURE__ */ jsx(SafeAreaView, { edges: ["bottom"], style: { flex: 1 }, children: /* @__PURE__ */ jsxs(
173
+ ScrollView,
174
+ {
175
+ contentContainerStyle: { padding: 16, gap: 16 },
176
+ showsVerticalScrollIndicator: false,
177
+ children: [
178
+ title ? /* @__PURE__ */ jsx(NativeText, { preset: "h3", children: title }) : null,
179
+ children
180
+ ]
181
+ }
182
+ ) });
183
+ }
184
+ const resolvedFields = fields ?? Object.keys(item).filter((k) => !SKIP_KEYS.has(k)).map((k) => ({ key: k, label: titleCase(k) }));
185
+ return /* @__PURE__ */ jsx(SafeAreaView, { edges: ["bottom"], style: { flex: 1 }, children: /* @__PURE__ */ jsxs(
186
+ ScrollView,
187
+ {
188
+ contentContainerStyle: { padding: 16, gap: 16 },
189
+ showsVerticalScrollIndicator: false,
190
+ children: [
191
+ title ? /* @__PURE__ */ jsx(NativeText, { preset: "h3", children: title }) : null,
192
+ /* @__PURE__ */ jsx(NativeCard, { children: /* @__PURE__ */ jsx(NativeCardContent, { className: "pt-6 gap-4", children: resolvedFields.map((field, index) => {
193
+ const raw = item[field.key];
194
+ const rendered = field.render ? field.render(raw, item) : raw == null ? null : String(raw);
195
+ return /* @__PURE__ */ jsxs(View, { children: [
196
+ index > 0 ? /* @__PURE__ */ jsx(NativeSeparator, { style: { marginBottom: 16 } }) : null,
197
+ /* @__PURE__ */ jsx(
198
+ NativeText,
199
+ {
200
+ preset: "caption",
201
+ className: "text-muted-foreground uppercase tracking-wider mb-1",
202
+ children: field.label
203
+ }
204
+ ),
205
+ typeof rendered === "string" || rendered == null ? /* @__PURE__ */ jsx(NativeText, { preset: "body", children: rendered ?? "\u2014" }) : rendered
206
+ ] }, field.key);
207
+ }) }) }),
208
+ hasActions ? /* @__PURE__ */ jsxs(View, { style: { gap: 12 }, children: [
209
+ /* @__PURE__ */ jsx(NativeSeparator, {}),
210
+ onEdit ? /* @__PURE__ */ jsx(NativeButton, { variant: "outline", onPress: () => onEdit(item), children: "Edit" }) : null,
211
+ onDelete ? /* @__PURE__ */ jsx(
212
+ NativeButton,
213
+ {
214
+ variant: "destructive",
215
+ onPress: () => onDelete(item),
216
+ children: "Delete"
217
+ }
218
+ ) : null
219
+ ] }) : null
220
+ ]
221
+ }
222
+ ) });
223
+ }
224
+ var KEYBOARD_TYPE_MAP = {
225
+ email: "email-address",
226
+ url: "url",
227
+ text: "default",
228
+ date: "default"
229
+ };
230
+ var AUTO_CAPITALIZE_MAP = {
231
+ email: "none",
232
+ url: "none",
233
+ text: "sentences",
234
+ date: "none"
235
+ };
236
+ function NativeResourceFormFieldRenderer({
237
+ field,
238
+ control,
239
+ action,
240
+ autoFocus,
241
+ watchedValues
242
+ }) {
243
+ const label = field.label ?? titleCase(field.key);
244
+ const fieldType = field.type ?? "text";
245
+ const isReadOnly = action === "edit" && !!field.readOnlyOnEdit;
246
+ const isDisabled = isReadOnly || (watchedValues ? field.disabled?.(watchedValues) === true : false);
247
+ if (field.hidden || fieldType === "hidden") {
248
+ return null;
249
+ }
250
+ return /* @__PURE__ */ jsx(
251
+ Controller,
252
+ {
253
+ name: field.key,
254
+ control,
255
+ render: ({ field: f, fieldState }) => {
256
+ const errorMessage = fieldState.error?.message;
257
+ if (fieldType === "switch") {
258
+ return /* @__PURE__ */ jsxs(View, { className: "gap-1.5", children: [
259
+ /* @__PURE__ */ jsxs(
260
+ Pressable,
261
+ {
262
+ className: "flex-row items-center justify-between rounded-lg border border-border p-4",
263
+ onPress: () => !isDisabled && f.onChange(!f.value),
264
+ accessibilityRole: "switch",
265
+ accessibilityState: { checked: !!f.value, disabled: isDisabled },
266
+ children: [
267
+ /* @__PURE__ */ jsx(NativeLabel, { disabled: isDisabled, children: label }),
268
+ /* @__PURE__ */ jsx(
269
+ NativeSwitch,
270
+ {
271
+ checked: !!f.value,
272
+ onCheckedChange: f.onChange,
273
+ disabled: isDisabled
274
+ }
275
+ )
276
+ ]
277
+ }
278
+ ),
279
+ field.description ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-muted-foreground", children: field.description }) : null,
280
+ errorMessage ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-destructive", children: errorMessage }) : null
281
+ ] });
282
+ }
283
+ if (fieldType === "checkbox") {
284
+ return /* @__PURE__ */ jsxs(View, { className: "gap-1.5", children: [
285
+ /* @__PURE__ */ jsxs(
286
+ Pressable,
287
+ {
288
+ className: "flex-row items-center gap-3",
289
+ onPress: () => !isDisabled && f.onChange(!f.value),
290
+ accessibilityRole: "checkbox",
291
+ accessibilityState: { checked: !!f.value, disabled: isDisabled },
292
+ children: [
293
+ /* @__PURE__ */ jsx(
294
+ NativeCheckbox,
295
+ {
296
+ checked: !!f.value,
297
+ onCheckedChange: f.onChange,
298
+ disabled: isDisabled
299
+ }
300
+ ),
301
+ /* @__PURE__ */ jsx(NativeLabel, { disabled: isDisabled, children: label })
302
+ ]
303
+ }
304
+ ),
305
+ field.description ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-muted-foreground", children: field.description }) : null,
306
+ errorMessage ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-destructive", children: errorMessage }) : null
307
+ ] });
308
+ }
309
+ if (fieldType === "select" && field.options) {
310
+ return /* @__PURE__ */ jsxs(View, { className: "gap-1.5", children: [
311
+ /* @__PURE__ */ jsx(NativeLabel, { disabled: isDisabled, children: label }),
312
+ /* @__PURE__ */ jsxs(
313
+ NativeSelect,
314
+ {
315
+ value: f.value != null ? String(f.value) : "",
316
+ onValueChange: f.onChange,
317
+ defaultValue: "",
318
+ children: [
319
+ /* @__PURE__ */ jsx(
320
+ NativeSelectTrigger,
321
+ {
322
+ placeholder: field.placeholder ?? `Select ${label.toLowerCase()}...`,
323
+ disabled: isDisabled
324
+ }
325
+ ),
326
+ /* @__PURE__ */ jsx(NativeSelectContent, { children: field.options.map((opt) => /* @__PURE__ */ jsx(NativeSelectItem, { value: opt.value, children: opt.label }, opt.value)) })
327
+ ]
328
+ }
329
+ ),
330
+ field.description ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-muted-foreground", children: field.description }) : null,
331
+ errorMessage ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-destructive", children: errorMessage }) : null
332
+ ] });
333
+ }
334
+ if (fieldType === "textarea") {
335
+ return /* @__PURE__ */ jsxs(View, { className: "gap-1.5", children: [
336
+ /* @__PURE__ */ jsx(
337
+ NativeTextarea,
338
+ {
339
+ label,
340
+ placeholder: field.placeholder,
341
+ rows: field.rows ?? 3,
342
+ value: f.value != null ? String(f.value) : "",
343
+ onChangeText: f.onChange,
344
+ editable: !isDisabled
345
+ }
346
+ ),
347
+ field.description ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-muted-foreground", children: field.description }) : null,
348
+ errorMessage ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-destructive", children: errorMessage }) : null
349
+ ] });
350
+ }
351
+ if (fieldType === "number") {
352
+ return /* @__PURE__ */ jsxs(View, { className: "gap-1.5", children: [
353
+ /* @__PURE__ */ jsx(
354
+ NativeInput,
355
+ {
356
+ label,
357
+ placeholder: field.placeholder,
358
+ keyboardType: "numeric",
359
+ value: f.value != null ? String(f.value) : "",
360
+ onChangeText: (text) => {
361
+ if (text === "") {
362
+ f.onChange(void 0);
363
+ } else {
364
+ const num = Number(text);
365
+ f.onChange(Number.isNaN(num) ? text : num);
366
+ }
367
+ },
368
+ editable: !isDisabled,
369
+ autoFocus
370
+ }
371
+ ),
372
+ field.description ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-muted-foreground", children: field.description }) : null,
373
+ errorMessage ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-destructive", children: errorMessage }) : null
374
+ ] });
375
+ }
376
+ return /* @__PURE__ */ jsxs(View, { className: "gap-1.5", children: [
377
+ /* @__PURE__ */ jsx(
378
+ NativeInput,
379
+ {
380
+ label,
381
+ placeholder: field.placeholder,
382
+ keyboardType: KEYBOARD_TYPE_MAP[fieldType] ?? "default",
383
+ autoCapitalize: AUTO_CAPITALIZE_MAP[fieldType] ?? "sentences",
384
+ value: f.value != null ? String(f.value) : "",
385
+ onChangeText: f.onChange,
386
+ editable: !isDisabled,
387
+ autoFocus
388
+ }
389
+ ),
390
+ field.description ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-muted-foreground", children: field.description }) : null,
391
+ errorMessage ? /* @__PURE__ */ jsx(NativeText, { preset: "caption", className: "text-destructive", children: errorMessage }) : null
392
+ ] });
393
+ }
394
+ }
395
+ );
396
+ }
397
+ function NativeResourceForm({
398
+ resource,
399
+ action,
400
+ fields,
401
+ item,
402
+ listData,
403
+ title,
404
+ layout = "screen",
405
+ onSuccess,
406
+ onError,
407
+ renderForm
408
+ }) {
409
+ const options = {
410
+ resource,
411
+ action,
412
+ initialData: item,
413
+ fields,
414
+ listData,
415
+ onSuccess,
416
+ onError,
417
+ prefillFromUrl: false,
418
+ validationMode: "onSubmit"
419
+ };
420
+ const { form, resolvedFields, onSubmit, isSaving } = useResourceForm(options);
421
+ const resolvedTitle = title ?? (action === "create" ? `Create ${titleCase(resource)}` : `Edit ${titleCase(resource)}`);
422
+ const submitLabel = action === "create" ? "Create" : "Save";
423
+ const values = form.watch();
424
+ const rootError = form.formState.errors.root?.message;
425
+ const { groups, firstFieldKey } = React.useMemo(() => {
426
+ const visible = resolvedFields.filter(
427
+ (field) => field.visible == null || field.visible(values) !== false
428
+ );
429
+ const result = [];
430
+ for (const field of visible) {
431
+ const lastGroup = result[result.length - 1];
432
+ if (lastGroup && lastGroup.group === field.group) {
433
+ lastGroup.fields.push(field);
434
+ } else {
435
+ result.push({ group: field.group, fields: [field] });
436
+ }
437
+ }
438
+ const first = visible.find((f) => !f.hidden && f.type !== "hidden");
439
+ return { groups: result, firstFieldKey: first?.key ?? null };
440
+ }, [resolvedFields, values]);
441
+ const formContent = renderForm ? renderForm(form, resolvedFields) : /* @__PURE__ */ jsxs(View, { style: { gap: 16 }, children: [
442
+ rootError ? /* @__PURE__ */ jsxs(NativeAlert, { variant: "destructive", children: [
443
+ /* @__PURE__ */ jsx(NativeAlertTitle, { variant: "destructive", children: "Error" }),
444
+ /* @__PURE__ */ jsx(NativeAlertDescription, { variant: "destructive", children: rootError })
445
+ ] }) : null,
446
+ groups.map((group, groupIndex) => /* @__PURE__ */ jsxs(View, { style: { gap: 12 }, children: [
447
+ group.group ? /* @__PURE__ */ jsxs(View, { style: { gap: 8 }, children: [
448
+ groupIndex > 0 ? /* @__PURE__ */ jsx(NativeSeparator, {}) : null,
449
+ /* @__PURE__ */ jsx(NativeText, { preset: "body-sm", className: "text-muted-foreground", children: group.group })
450
+ ] }) : groupIndex > 0 ? /* @__PURE__ */ jsx(NativeSeparator, {}) : null,
451
+ group.fields.map((field) => /* @__PURE__ */ jsx(
452
+ NativeResourceFormFieldRenderer,
453
+ {
454
+ field,
455
+ control: form.control,
456
+ action,
457
+ autoFocus: field.key === firstFieldKey,
458
+ watchedValues: values
459
+ },
460
+ field.key
461
+ ))
462
+ ] }, group.group ?? `__ungrouped_${groupIndex}`)),
463
+ /* @__PURE__ */ jsx(NativeButton, { onPress: onSubmit, disabled: isSaving, loading: isSaving, children: isSaving ? "Saving..." : submitLabel })
464
+ ] });
465
+ if (layout === "inline") {
466
+ return /* @__PURE__ */ jsxs(View, { style: { gap: 16 }, children: [
467
+ /* @__PURE__ */ jsx(NativeText, { preset: "h3", children: resolvedTitle }),
468
+ formContent
469
+ ] });
470
+ }
471
+ return /* @__PURE__ */ jsx(SafeAreaView, { edges: ["bottom"], style: { flex: 1 }, children: /* @__PURE__ */ jsxs(
472
+ ScrollView,
473
+ {
474
+ contentContainerStyle: { padding: 16, gap: 16 },
475
+ showsVerticalScrollIndicator: false,
476
+ children: [
477
+ /* @__PURE__ */ jsx(NativeText, { preset: "h3", children: resolvedTitle }),
478
+ formContent
479
+ ]
480
+ }
481
+ ) });
482
+ }
483
+ function resolveField(f, index) {
484
+ if (typeof f === "string") {
485
+ return {
486
+ key: f,
487
+ position: index === 0 ? "title" : "meta"
488
+ };
489
+ }
490
+ return f;
491
+ }
492
+ function autoDetectFields(item) {
493
+ const keys = Object.keys(item).filter((k) => k !== "id");
494
+ return keys.map((key, i) => ({
495
+ key,
496
+ position: i === 0 ? "title" : "meta"
497
+ }));
498
+ }
499
+ function DefaultCardRenderer({
500
+ item,
501
+ fields,
502
+ onPress
503
+ }) {
504
+ const titleField = fields.find((f) => f.position === "title");
505
+ const badgeField = fields.find((f) => f.position === "badge");
506
+ const subtitleField = fields.find((f) => f.position === "subtitle");
507
+ const metaFields = fields.filter((f) => f.position === "meta");
508
+ const renderValue = (field) => {
509
+ const value = item[field.key];
510
+ if (field.render) {
511
+ return field.render(value, item);
512
+ }
513
+ if (value === null || value === void 0) return null;
514
+ return String(value);
515
+ };
516
+ const titleContent = titleField ? renderValue(titleField) : null;
517
+ const badgeContent = badgeField ? renderValue(badgeField) : null;
518
+ const subtitleContent = subtitleField ? renderValue(subtitleField) : null;
519
+ return /* @__PURE__ */ jsx(
520
+ Pressable,
521
+ {
522
+ onPress: onPress ? () => onPress(item) : void 0,
523
+ style: ({ pressed }) => ({ opacity: pressed ? 0.7 : 1 }),
524
+ children: /* @__PURE__ */ jsxs(NativeCard, { className: "mx-4 mb-3", children: [
525
+ /* @__PURE__ */ jsxs(NativeCardHeader, { className: "pb-2", children: [
526
+ /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" }, children: [
527
+ titleContent !== null ? /* @__PURE__ */ jsx(NativeCardTitle, { className: "flex-1 text-base", children: titleContent }) : null,
528
+ badgeContent !== null ? /* @__PURE__ */ jsx(NativeText, { preset: "body-sm", className: "text-muted-foreground ml-2", children: badgeContent }) : null
529
+ ] }),
530
+ subtitleContent !== null ? /* @__PURE__ */ jsx(NativeText, { preset: "body-sm", className: "text-muted-foreground mt-0.5", children: subtitleContent }) : null
531
+ ] }),
532
+ metaFields.length > 0 ? /* @__PURE__ */ jsx(NativeCardContent, { className: "pt-0", children: /* @__PURE__ */ jsx(View, { style: { flexDirection: "row", flexWrap: "wrap", gap: 8 }, children: metaFields.map((field) => {
533
+ const val = renderValue(field);
534
+ if (val === null) return null;
535
+ return /* @__PURE__ */ jsxs(NativeText, { preset: "caption", className: "text-muted-foreground", children: [
536
+ field.label ? `${field.label}: ` : "",
537
+ val
538
+ ] }, field.key);
539
+ }) }) }) : null
540
+ ] })
541
+ }
542
+ );
543
+ }
544
+ function NativeResourcePage({
545
+ resource,
546
+ resourceOptions,
547
+ title,
548
+ subtitle,
549
+ cardFields,
550
+ renderItem,
551
+ searchFields,
552
+ searchPlaceholder,
553
+ statusFilter,
554
+ onItemPress,
555
+ titleField,
556
+ onCreatePress,
557
+ createLabel = "New",
558
+ headerRight,
559
+ emptyState
560
+ }) {
561
+ const [search, setSearchLocal] = useState("");
562
+ const [selectedStatuses, setSelectedStatuses] = useState([]);
563
+ const statusFilterConfig = useMemo(() => {
564
+ if (!statusFilter) return null;
565
+ if (typeof statusFilter === "string") {
566
+ return { field: statusFilter, options: void 0 };
567
+ }
568
+ return { field: statusFilter.field, options: statusFilter.options };
569
+ }, [statusFilter]);
570
+ const mergedOptions = useMemo(
571
+ () => ({
572
+ ...resourceOptions,
573
+ searchFields: searchFields ?? resourceOptions?.searchFields
574
+ }),
575
+ // eslint-disable-next-line react-hooks/exhaustive-deps
576
+ [resourceOptions, searchFields]
577
+ );
578
+ const { list, setSearch, setFilters } = useResource(resource, mergedOptions);
579
+ useEffect(() => {
580
+ setSearch(search);
581
+ }, [search, setSearch]);
582
+ useEffect(() => {
583
+ if (!statusFilterConfig) return;
584
+ if (selectedStatuses.length === 0) {
585
+ setFilters([]);
586
+ } else if (selectedStatuses.length === 1) {
587
+ setFilters([
588
+ {
589
+ field: statusFilterConfig.field,
590
+ operator: "eq",
591
+ value: selectedStatuses[0]
592
+ }
593
+ ]);
594
+ } else {
595
+ setFilters([
596
+ {
597
+ field: statusFilterConfig.field,
598
+ operator: "in",
599
+ value: selectedStatuses
600
+ }
601
+ ]);
602
+ }
603
+ }, [selectedStatuses, statusFilterConfig, setFilters]);
604
+ const items = list.data?.data ?? [];
605
+ const isLoading = list.isLoading;
606
+ const hasError = list.isError;
607
+ const resolvedFields = useMemo(() => {
608
+ if (titleField && cardFields) {
609
+ const resolved = cardFields.map((f, i) => resolveField(f, i));
610
+ return resolved.map(
611
+ (f) => f.key === titleField ? { ...f, position: "title" } : f
612
+ );
613
+ }
614
+ if (cardFields && cardFields.length > 0) {
615
+ return cardFields.map((f, i) => resolveField(f, i));
616
+ }
617
+ if (items.length > 0) {
618
+ const detected = autoDetectFields(items[0]);
619
+ if (titleField) {
620
+ return detected.map(
621
+ (f) => f.key === titleField ? { ...f, position: "title" } : f
622
+ );
623
+ }
624
+ return detected;
625
+ }
626
+ return [];
627
+ }, [cardFields, titleField, items]);
628
+ const statusOptions = useMemo(() => {
629
+ if (!statusFilterConfig) return [];
630
+ if (statusFilterConfig.options) return statusFilterConfig.options;
631
+ const values = /* @__PURE__ */ new Set();
632
+ for (const item of items) {
633
+ const v = item[statusFilterConfig.field];
634
+ if (typeof v === "string") values.add(v);
635
+ }
636
+ return Array.from(values).sort();
637
+ }, [statusFilterConfig, items]);
638
+ const effectiveHeaderRight = useMemo(() => {
639
+ if (onCreatePress) {
640
+ return /* @__PURE__ */ jsxs(View, { style: { flexDirection: "row", alignItems: "center", gap: 8 }, children: [
641
+ headerRight,
642
+ /* @__PURE__ */ jsx(NativeButton, { size: "sm", onPress: onCreatePress, children: createLabel })
643
+ ] });
644
+ }
645
+ return headerRight ?? null;
646
+ }, [onCreatePress, createLabel, headerRight]);
647
+ const [refreshing, setRefreshing] = useState(false);
648
+ const refetch = list.refetch;
649
+ const handleRefresh = useCallback(async () => {
650
+ setRefreshing(true);
651
+ try {
652
+ await refetch();
653
+ } catch (err) {
654
+ console.error(`[NativeResourcePage] Pull-to-refresh failed:`, err);
655
+ } finally {
656
+ setRefreshing(false);
657
+ }
658
+ }, [refetch]);
659
+ const hasActiveFilters = search.length > 0 || selectedStatuses.length > 0;
660
+ const handleClearFilters = useCallback(() => {
661
+ setSearchLocal("");
662
+ setSelectedStatuses([]);
663
+ }, []);
664
+ const keyExtractor = useCallback(
665
+ (item) => String(item.id),
666
+ []
667
+ );
668
+ const renderFlatListItem = useCallback(
669
+ ({ item }) => {
670
+ if (renderItem) {
671
+ return /* @__PURE__ */ jsx(Fragment, { children: renderItem(item) });
672
+ }
673
+ return /* @__PURE__ */ jsx(
674
+ DefaultCardRenderer,
675
+ {
676
+ item,
677
+ fields: resolvedFields,
678
+ onPress: onItemPress
679
+ }
680
+ );
681
+ },
682
+ [renderItem, resolvedFields, onItemPress]
683
+ );
684
+ const ListHeaderComponent = useMemo(
685
+ () => /* @__PURE__ */ jsx(View, { className: "px-4 pb-3", children: /* @__PURE__ */ jsx(
686
+ NativeDataFilters,
687
+ {
688
+ search,
689
+ onSearchChange: setSearchLocal,
690
+ searchPlaceholder,
691
+ statusChips: statusOptions.length > 0 ? {
692
+ options: statusOptions,
693
+ selected: selectedStatuses,
694
+ onChange: setSelectedStatuses
695
+ } : void 0
696
+ }
697
+ ) }),
698
+ [search, searchPlaceholder, statusOptions, selectedStatuses]
699
+ );
700
+ const ListEmptyComponent = useMemo(
701
+ () => isLoading ? null : /* @__PURE__ */ jsx(Fragment, { children: emptyState ?? /* @__PURE__ */ jsx(
702
+ NativeEmptyState,
703
+ {
704
+ hasFilters: hasActiveFilters,
705
+ onClearFilters: hasActiveFilters ? handleClearFilters : void 0
706
+ }
707
+ ) }),
708
+ [isLoading, emptyState, hasActiveFilters, handleClearFilters]
709
+ );
710
+ const renderPageContent = () => {
711
+ if (isLoading) {
712
+ return /* @__PURE__ */ jsxs(View, { className: "px-4 pt-4 gap-3", children: [
713
+ /* @__PURE__ */ jsx(NativeSkeleton, { className: "w-full h-10 rounded-lg" }),
714
+ /* @__PURE__ */ jsx(NativeSkeleton, { className: "w-full h-20 rounded-lg" }),
715
+ /* @__PURE__ */ jsx(NativeSkeleton, { className: "w-full h-20 rounded-lg" }),
716
+ /* @__PURE__ */ jsx(NativeSkeleton, { className: "w-full h-20 rounded-lg" })
717
+ ] });
718
+ }
719
+ if (hasError) {
720
+ return /* @__PURE__ */ jsxs(View, { className: "flex-1 items-center justify-center px-4 py-12 gap-4", children: [
721
+ /* @__PURE__ */ jsx(NativeText, { preset: "body", className: "text-destructive text-center", children: list.error?.message ?? "Something went wrong." }),
722
+ /* @__PURE__ */ jsx(NativeButton, { variant: "outline", size: "sm", onPress: () => list.refetch(), children: "Try Again" })
723
+ ] });
724
+ }
725
+ return /* @__PURE__ */ jsx(
726
+ FlatList,
727
+ {
728
+ data: items,
729
+ keyExtractor,
730
+ renderItem: renderFlatListItem,
731
+ ListHeaderComponent,
732
+ ListEmptyComponent,
733
+ contentContainerStyle: { flexGrow: 1, paddingBottom: 24 },
734
+ refreshing,
735
+ onRefresh: handleRefresh
736
+ }
737
+ );
738
+ };
739
+ return /* @__PURE__ */ jsxs(SafeAreaView, { edges: ["left", "right"], className: "flex-1 bg-background", children: [
740
+ /* @__PURE__ */ jsx(View, { className: "px-4 pt-4 pb-2", children: /* @__PURE__ */ jsxs(
741
+ View,
742
+ {
743
+ style: {
744
+ flexDirection: "row",
745
+ alignItems: "center",
746
+ justifyContent: "space-between"
747
+ },
748
+ children: [
749
+ /* @__PURE__ */ jsxs(View, { className: "flex-1", children: [
750
+ /* @__PURE__ */ jsx(NativeText, { preset: "h2", children: title }),
751
+ subtitle ? /* @__PURE__ */ jsx(
752
+ NativeText,
753
+ {
754
+ preset: "body-sm",
755
+ className: "text-muted-foreground mt-0.5",
756
+ children: subtitle
757
+ }
758
+ ) : null
759
+ ] }),
760
+ effectiveHeaderRight ? /* @__PURE__ */ jsx(View, { className: "ml-3", children: effectiveHeaderRight }) : null
761
+ ]
762
+ }
763
+ ) }),
764
+ /* @__PURE__ */ jsx(View, { className: "flex-1", children: renderPageContent() })
765
+ ] });
766
+ }
767
+
768
+ export { NativeDataFilters, NativeDataPageShell, NativeDetailPanel, NativeEmptyState, NativeResourceForm, NativeResourceFormFieldRenderer, NativeResourcePage };
769
+ //# sourceMappingURL=index.js.map
770
+ //# sourceMappingURL=index.js.map