anhedral 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -38
- package/assets/stack/ai-schema.ts.txt +5 -0
- package/assets/stack/ai.ts.txt +30 -0
- package/assets/stack/api-index.ts.txt +15 -0
- package/assets/stack/auth-features.ts.txt +4 -0
- package/assets/stack/auth-journal.json.txt +13 -0
- package/assets/stack/auth-migration.sql.txt +53 -0
- package/assets/stack/auth-routes.ts.txt +11 -0
- package/assets/stack/auth-schema.ts.txt +64 -0
- package/assets/stack/auth-snapshot.json.txt +346 -0
- package/assets/stack/auth.ts.txt +32 -0
- package/assets/stack/billing-mode.ts.txt +8 -0
- package/assets/stack/billing-schema.ts.txt +11 -0
- package/assets/stack/desktop.rs.txt +21 -0
- package/assets/stack/entitlement-guard.ts.txt +32 -0
- package/assets/stack/entitlements.ts.txt +8 -0
- package/assets/stack/events-schema.ts.txt +12 -0
- package/assets/stack/events.ts.txt +59 -0
- package/assets/stack/mobile-auth.ts.txt +25 -0
- package/assets/stack/mobile-billing.tsx.txt +63 -0
- package/assets/stack/mobile-session.tsx.txt +83 -0
- package/assets/stack/native-button.tsx.txt +108 -0
- package/assets/stack/native-global.css.txt +4 -0
- package/assets/stack/native-lib-utils.ts.txt +5 -0
- package/assets/stack/native-metro.config.js.txt +6 -0
- package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
- package/assets/stack/native-tailwind.config.js.txt +73 -0
- package/assets/stack/native-text.tsx.txt +89 -0
- package/assets/stack/purchases.ts.txt +65 -0
- package/assets/stack/revenuecat.ts.txt +88 -0
- package/assets/stack/rtc-schema.ts.txt +10 -0
- package/assets/stack/rtc.ts.txt +122 -0
- package/assets/stack/security.ts.txt +31 -0
- package/assets/stack/storage.ts.txt +36 -0
- package/assets/stack/stripe.ts.txt +126 -0
- package/assets/stack/web-sign-in.tsx.txt +51 -0
- package/assets/ui/LICENSE.react-native-reusables +21 -0
- package/assets/ui/UPSTREAM.json +7 -1
- package/assets/ui/catalog.json +891 -0
- package/assets/ui/extensions/registry.json +6 -0
- package/assets/ui/native/_controls.tsx +521 -0
- package/assets/ui/native/_core.tsx +118 -0
- package/assets/ui/native/_data.tsx +200 -0
- package/assets/ui/native/_display.tsx +453 -0
- package/assets/ui/native/_feedback.tsx +242 -0
- package/assets/ui/native/_legacy-dialog.tsx +38 -0
- package/assets/ui/native/_motion.tsx +520 -0
- package/assets/ui/native/_overlay.tsx +402 -0
- package/assets/ui/native/_selection.tsx +366 -0
- package/assets/ui/native/accordion.tsx +1 -0
- package/assets/ui/native/alert-dialog.tsx +11 -0
- package/assets/ui/native/alert.tsx +1 -0
- package/assets/ui/native/aspect-ratio.tsx +1 -0
- package/assets/ui/native/attachment.tsx +8 -0
- package/assets/ui/native/avatar.tsx +8 -0
- package/assets/ui/native/badge.tsx +1 -0
- package/assets/ui/native/breadcrumb.tsx +9 -0
- package/assets/ui/native/bubble.tsx +1 -0
- package/assets/ui/native/button-group.tsx +1 -0
- package/assets/ui/native/button.tsx +2 -1
- package/assets/ui/native/calendar.tsx +170 -0
- package/assets/ui/native/card.tsx +16 -5
- package/assets/ui/native/carousel.tsx +1 -0
- package/assets/ui/native/chart.tsx +193 -0
- package/assets/ui/native/checkbox.tsx +1 -0
- package/assets/ui/native/code-block.tsx +137 -0
- package/assets/ui/native/collapsible.tsx +1 -0
- package/assets/ui/native/combobox.tsx +1 -0
- package/assets/ui/native/command.tsx +11 -0
- package/assets/ui/native/context-menu.tsx +16 -0
- package/assets/ui/native/data-table.tsx +1 -0
- package/assets/ui/native/date-picker.tsx +43 -0
- package/assets/ui/native/dialog.tsx +14 -74
- package/assets/ui/native/direction.tsx +1 -0
- package/assets/ui/native/drawer.tsx +10 -0
- package/assets/ui/native/dropdown-menu.tsx +16 -0
- package/assets/ui/native/empty.tsx +8 -0
- package/assets/ui/native/field.tsx +13 -0
- package/assets/ui/native/hover-card.tsx +1 -0
- package/assets/ui/native/input-group.tsx +8 -0
- package/assets/ui/native/input-otp.tsx +1 -0
- package/assets/ui/native/input.tsx +2 -1
- package/assets/ui/native/item.tsx +12 -0
- package/assets/ui/native/kbd.tsx +1 -0
- package/assets/ui/native/marker.tsx +1 -0
- package/assets/ui/native/menubar.tsx +17 -0
- package/assets/ui/native/message-scroller.tsx +6 -0
- package/assets/ui/native/message.tsx +10 -0
- package/assets/ui/native/native-select.tsx +1 -0
- package/assets/ui/native/navigation-menu.tsx +10 -0
- package/assets/ui/native/pagination.tsx +9 -0
- package/assets/ui/native/popover.tsx +1 -0
- package/assets/ui/native/progress.tsx +1 -0
- package/assets/ui/native/questionnaire.tsx +130 -0
- package/assets/ui/native/radio-group.tsx +1 -0
- package/assets/ui/native/registry.json +1103 -0
- package/assets/ui/native/resizable.tsx +1 -0
- package/assets/ui/native/scroll-area.tsx +1 -0
- package/assets/ui/native/select.tsx +11 -0
- package/assets/ui/native/separator.tsx +1 -0
- package/assets/ui/native/sheet.tsx +10 -0
- package/assets/ui/native/sidebar.tsx +22 -0
- package/assets/ui/native/skeleton.tsx +1 -0
- package/assets/ui/native/slider.tsx +1 -0
- package/assets/ui/native/spinner.tsx +1 -0
- package/assets/ui/native/switch.tsx +1 -0
- package/assets/ui/native/table.tsx +10 -0
- package/assets/ui/native/tabs.tsx +1 -0
- package/assets/ui/native/textarea.tsx +1 -0
- package/assets/ui/native/toast.tsx +11 -0
- package/assets/ui/native/toggle-group.tsx +1 -0
- package/assets/ui/native/toggle.tsx +1 -0
- package/assets/ui/native/tooltip.tsx +1 -0
- package/assets/ui/native/trace.tsx +20 -0
- package/assets/ui/native/typography.tsx +15 -0
- package/dist/bin.js +7 -12
- package/dist/capabilities.d.ts +4 -33
- package/dist/capabilities.js +2 -66
- package/dist/capability-catalog.d.ts +83 -0
- package/dist/capability-catalog.js +121 -0
- package/dist/capability-command.d.ts +3 -0
- package/dist/capability-command.js +188 -0
- package/dist/capability-editor.d.ts +17 -0
- package/dist/capability-editor.js +97 -0
- package/dist/capability-recipes.d.ts +4 -0
- package/dist/capability-recipes.js +520 -0
- package/dist/capability-references.d.ts +4 -0
- package/dist/capability-references.js +7 -0
- package/dist/cli-commands.d.ts +1 -2
- package/dist/cli-commands.js +10 -104
- package/dist/cli-output.d.ts +1 -2
- package/dist/cli-output.js +6 -251
- package/dist/command-schema.js +39 -322
- package/dist/dependencies.d.ts +29 -6
- package/dist/dependencies.js +61 -14
- package/dist/index.d.ts +1 -42
- package/dist/index.js +1 -27
- package/dist/platforms/mobile.js +1 -20
- package/dist/platforms/web.d.ts +1 -1
- package/dist/platforms/web.js +27 -75
- package/dist/project-config.d.ts +2 -13
- package/dist/project-config.js +10 -82
- package/dist/registry/options.js +1 -5
- package/dist/registry/resolve.d.ts +1 -1
- package/dist/registry/resolve.js +2 -10
- package/dist/registry/usage.js +3 -9
- package/dist/scaffold/backend.js +0 -3
- package/dist/scaffold/database.js +2 -1
- package/dist/scaffold/documentation.js +82 -20
- package/dist/scaffold/expo-runtime.js +3 -4
- package/dist/scaffold/native-ui.js +12 -7
- package/dist/scaffold/stack-documentation.js +1 -1
- package/dist/scaffold/storage.d.ts +2 -0
- package/dist/scaffold/storage.js +21 -0
- package/dist/scaffold/workspace.js +26 -21
- package/dist/stack-registry.d.ts +2 -8
- package/dist/stack-registry.js +11 -87
- package/dist/standard.js +1 -11
- package/dist/ui-catalog.d.ts +26 -0
- package/dist/ui-catalog.js +31 -0
- package/dist/ui-command.d.ts +3 -0
- package/dist/ui-command.js +219 -0
- package/dist/ui-project.d.ts +22 -0
- package/dist/ui-project.js +110 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/anhedral-stack.md +4 -20
- package/docs/capabilities.md +110 -0
- package/docs/native-ui.md +102 -0
- package/docs/software-factory.md +16 -44
- package/docs/stack-standard.md +11 -60
- package/docs/ui.md +33 -0
- package/docs/verification.md +191 -0
- package/package.json +19 -18
- package/dist/access.d.ts +0 -10
- package/dist/access.js +0 -93
- package/dist/auth-schema-snapshot.d.ts +0 -346
- package/dist/auth-schema-snapshot.js +0 -347
- package/dist/auth-schema.d.ts +0 -1
- package/dist/auth-schema.js +0 -57
- package/dist/capability-contract.d.ts +0 -47
- package/dist/capability-contract.js +0 -129
- package/dist/catalog-model.d.ts +0 -24
- package/dist/catalog-model.js +0 -1
- package/dist/catalog-registration.d.ts +0 -16
- package/dist/catalog-registration.js +0 -22
- package/dist/catalog-snapshot.d.ts +0 -5
- package/dist/catalog-snapshot.js +0 -97
- package/dist/cli-delivery.d.ts +0 -3
- package/dist/cli-delivery.js +0 -112
- package/dist/cloudflare.d.ts +0 -25
- package/dist/cloudflare.js +0 -226
- package/dist/delivery-evidence.d.ts +0 -62
- package/dist/delivery-evidence.js +0 -157
- package/dist/delivery.d.ts +0 -82
- package/dist/delivery.js +0 -489
- package/dist/inspector-model.d.ts +0 -123
- package/dist/inspector-model.js +0 -1
- package/dist/integration-service-readers.d.ts +0 -12
- package/dist/integration-service-readers.js +0 -92
- package/dist/lifecycle-model.d.ts +0 -15
- package/dist/lifecycle-model.js +0 -20
- package/dist/lifecycle.d.ts +0 -11
- package/dist/lifecycle.js +0 -91
- package/dist/management.d.ts +0 -3
- package/dist/management.js +0 -47
- package/dist/mobile-delivery.d.ts +0 -77
- package/dist/mobile-delivery.js +0 -370
- package/dist/project-catalog.d.ts +0 -41
- package/dist/project-catalog.js +0 -288
- package/dist/project-inspector.d.ts +0 -4
- package/dist/project-inspector.js +0 -671
- package/dist/project-lifecycle.d.ts +0 -25
- package/dist/project-lifecycle.js +0 -57
- package/dist/project-state.d.ts +0 -47
- package/dist/project-state.js +0 -480
- package/dist/provider-auth.d.ts +0 -41
- package/dist/provider-auth.js +0 -180
- package/dist/provider-readiness.d.ts +0 -30
- package/dist/provider-readiness.js +0 -85
- package/dist/providers/adapters.d.ts +0 -17
- package/dist/providers/adapters.js +0 -103
- package/dist/providers/api.d.ts +0 -29
- package/dist/providers/api.js +0 -253
- package/dist/providers/config.d.ts +0 -15
- package/dist/providers/config.js +0 -136
- package/dist/providers/definitions.d.ts +0 -115
- package/dist/providers/definitions.js +0 -42
- package/dist/providers/provision.d.ts +0 -24
- package/dist/providers/provision.js +0 -76
- package/dist/providers/receipts.d.ts +0 -20
- package/dist/providers/receipts.js +0 -56
- package/dist/providers/recovery-verification.d.ts +0 -7
- package/dist/providers/recovery-verification.js +0 -52
- package/dist/providers/recovery.d.ts +0 -30
- package/dist/providers/recovery.js +0 -34
- package/dist/providers/runtime.d.ts +0 -10
- package/dist/providers/runtime.js +0 -234
- package/dist/providers/schema.d.ts +0 -28
- package/dist/providers/schema.js +0 -49
- package/dist/providers/state.d.ts +0 -55
- package/dist/providers/state.js +0 -283
- package/dist/provision.d.ts +0 -47
- package/dist/provision.js +0 -208
- package/dist/r2-service-data.d.ts +0 -2
- package/dist/r2-service-data.js +0 -136
- package/dist/readiness.d.ts +0 -23
- package/dist/readiness.js +0 -117
- package/dist/registry/add.d.ts +0 -24
- package/dist/registry/add.js +0 -210
- package/dist/registry/bootstrap.d.ts +0 -3
- package/dist/registry/bootstrap.js +0 -5
- package/dist/registry/commands.d.ts +0 -3
- package/dist/registry/commands.js +0 -83
- package/dist/registry/preview.d.ts +0 -11
- package/dist/registry/preview.js +0 -91
- package/dist/registry/receipt.d.ts +0 -3
- package/dist/registry/receipt.js +0 -68
- package/dist/repository.d.ts +0 -24
- package/dist/repository.js +0 -96
- package/dist/scaffold/auth.d.ts +0 -2
- package/dist/scaffold/auth.js +0 -76
- package/dist/scaffold/billing-config.d.ts +0 -1
- package/dist/scaffold/billing-config.js +0 -73
- package/dist/scaffold/billing-contracts.d.ts +0 -2
- package/dist/scaffold/billing-contracts.js +0 -48
- package/dist/scaffold/billing-providers.d.ts +0 -1
- package/dist/scaffold/billing-providers.js +0 -249
- package/dist/scaffold/billing-schema.d.ts +0 -1
- package/dist/scaffold/billing-schema.js +0 -34
- package/dist/scaffold/billing-security.d.ts +0 -1
- package/dist/scaffold/billing-security.js +0 -46
- package/dist/scaffold/billing-server.d.ts +0 -1
- package/dist/scaffold/billing-server.js +0 -139
- package/dist/scaffold/billing-store.d.ts +0 -1
- package/dist/scaffold/billing-store.js +0 -72
- package/dist/scaffold/billing.d.ts +0 -2
- package/dist/scaffold/billing.js +0 -208
- package/dist/scaffold/expo-auth.d.ts +0 -3
- package/dist/scaffold/expo-auth.js +0 -203
- package/dist/scaffold/expo-billing.d.ts +0 -3
- package/dist/scaffold/expo-billing.js +0 -257
- package/dist/scaffold/integrations.d.ts +0 -2
- package/dist/scaffold/integrations.js +0 -11
- package/dist/scaffold/managed-email.d.ts +0 -3
- package/dist/scaffold/managed-email.js +0 -47
- package/dist/scaffold/password-reset.d.ts +0 -1
- package/dist/scaffold/password-reset.js +0 -99
- package/dist/scaffold/private-files.d.ts +0 -2
- package/dist/scaffold/private-files.js +0 -78
- package/dist/scaffold/web-billing.d.ts +0 -2
- package/dist/scaffold/web-billing.js +0 -48
- package/dist/service-deletion.d.ts +0 -29
- package/dist/service-deletion.js +0 -195
- package/dist/service-descriptor.d.ts +0 -10
- package/dist/service-descriptor.js +0 -71
- package/dist/service-model.d.ts +0 -49
- package/dist/service-model.js +0 -8
- package/dist/service-operations.d.ts +0 -29
- package/dist/service-operations.js +0 -48
- package/dist/service-readers.d.ts +0 -8
- package/dist/service-readers.js +0 -216
- package/dist/services-command.d.ts +0 -39
- package/dist/services-command.js +0 -96
- package/dist/ship.d.ts +0 -35
- package/dist/ship.js +0 -107
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
cloneElement,
|
|
4
|
+
createContext,
|
|
5
|
+
isValidElement,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import { View, ScrollView, PanResponder, type ViewProps } from 'react-native';
|
|
13
|
+
import { Box, clamp, useControllable, useDirection } from './_core';
|
|
14
|
+
import { Button, type ButtonProps } from './button';
|
|
15
|
+
import { useTheme } from '../theme';
|
|
16
|
+
export function Slider({
|
|
17
|
+
value,
|
|
18
|
+
defaultValue = [0],
|
|
19
|
+
onValueChange,
|
|
20
|
+
onValueCommit,
|
|
21
|
+
min = 0,
|
|
22
|
+
max = 100,
|
|
23
|
+
step = 1,
|
|
24
|
+
disabled = false,
|
|
25
|
+
minStepsBetweenThumbs = 0,
|
|
26
|
+
accessibilityLabel = 'Value',
|
|
27
|
+
orientation = 'horizontal',
|
|
28
|
+
style,
|
|
29
|
+
onLayout,
|
|
30
|
+
...props
|
|
31
|
+
}: ViewProps & {
|
|
32
|
+
value?: number[];
|
|
33
|
+
defaultValue?: number[];
|
|
34
|
+
onValueChange?: (value: number[]) => void;
|
|
35
|
+
onValueCommit?: (value: number[]) => void;
|
|
36
|
+
min?: number;
|
|
37
|
+
max?: number;
|
|
38
|
+
step?: number;
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
minStepsBetweenThumbs?: number;
|
|
41
|
+
orientation?: 'horizontal' | 'vertical';
|
|
42
|
+
}) {
|
|
43
|
+
const lower = Number.isFinite(min) ? min : 0;
|
|
44
|
+
const upper = Number.isFinite(max) && max > lower ? max : lower + 100;
|
|
45
|
+
const increment = Number.isFinite(step) && step > 0 ? step : 1;
|
|
46
|
+
const [values, set] = useControllable(value, defaultValue, onValueChange);
|
|
47
|
+
const { colors } = useTheme();
|
|
48
|
+
const direction = useDirection();
|
|
49
|
+
const gap =
|
|
50
|
+
Math.max(0, Number.isFinite(minStepsBetweenThumbs) ? minStepsBetweenThumbs : 0) * increment;
|
|
51
|
+
const numbers = values.length
|
|
52
|
+
? values.map((item) => clamp(item, lower, upper)).sort((a, b) => a - b)
|
|
53
|
+
: [lower];
|
|
54
|
+
if (gap * (numbers.length - 1) > upper - lower)
|
|
55
|
+
throw new RangeError('Slider thumb spacing exceeds the available range.');
|
|
56
|
+
const current: number[] = [];
|
|
57
|
+
for (let index = 0; index < numbers.length; index++)
|
|
58
|
+
current.push(
|
|
59
|
+
clamp(
|
|
60
|
+
numbers[index]!,
|
|
61
|
+
index ? current[index - 1]! + gap : lower,
|
|
62
|
+
upper - (numbers.length - index - 1) * gap,
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
const latest = useRef(current);
|
|
66
|
+
latest.current = current;
|
|
67
|
+
const extent = useRef(1);
|
|
68
|
+
const active = useRef(0);
|
|
69
|
+
const initial = useRef(lower);
|
|
70
|
+
function update(index: number, next: number, commit = false) {
|
|
71
|
+
const start = index === 0 ? lower : latest.current[index - 1]! + gap;
|
|
72
|
+
const end = index === latest.current.length - 1 ? upper : latest.current[index + 1]! - gap;
|
|
73
|
+
const rounded = Math.round((next - lower) / increment) * increment + lower;
|
|
74
|
+
const result = latest.current.map((item, i) =>
|
|
75
|
+
i === index ? Number(clamp(rounded, start, end).toFixed(10)) : item,
|
|
76
|
+
);
|
|
77
|
+
latest.current = result;
|
|
78
|
+
set(result);
|
|
79
|
+
if (commit) onValueCommit?.(result);
|
|
80
|
+
}
|
|
81
|
+
const config = useRef({ disabled, orientation, direction, lower, upper, update, onValueCommit });
|
|
82
|
+
config.current = { disabled, orientation, direction, lower, upper, update, onValueCommit };
|
|
83
|
+
const pan = useRef<ReturnType<typeof PanResponder.create> | null>(null);
|
|
84
|
+
if (!pan.current)
|
|
85
|
+
pan.current = PanResponder.create({
|
|
86
|
+
onStartShouldSetPanResponder: () => !config.current.disabled,
|
|
87
|
+
onMoveShouldSetPanResponder: () => !config.current.disabled,
|
|
88
|
+
onPanResponderGrant: (event) => {
|
|
89
|
+
const current = config.current;
|
|
90
|
+
const ratio = clamp(
|
|
91
|
+
(current.orientation === 'vertical'
|
|
92
|
+
? event.nativeEvent.locationY
|
|
93
|
+
: event.nativeEvent.locationX) / extent.current,
|
|
94
|
+
0,
|
|
95
|
+
1,
|
|
96
|
+
);
|
|
97
|
+
const reversed = current.orientation === 'vertical' || current.direction === 'rtl';
|
|
98
|
+
const next =
|
|
99
|
+
current.lower + (reversed ? 1 - ratio : ratio) * (current.upper - current.lower);
|
|
100
|
+
active.current = latest.current.reduce(
|
|
101
|
+
(best, item, index) =>
|
|
102
|
+
Math.abs(item - next) < Math.abs(latest.current[best]! - next) ? index : best,
|
|
103
|
+
0,
|
|
104
|
+
);
|
|
105
|
+
current.update(active.current, next);
|
|
106
|
+
initial.current = latest.current[active.current]!;
|
|
107
|
+
},
|
|
108
|
+
onPanResponderMove: (_event, gesture) => {
|
|
109
|
+
const current = config.current;
|
|
110
|
+
const distance =
|
|
111
|
+
current.orientation === 'vertical'
|
|
112
|
+
? -gesture.dy
|
|
113
|
+
: gesture.dx * (current.direction === 'rtl' ? -1 : 1);
|
|
114
|
+
current.update(
|
|
115
|
+
active.current,
|
|
116
|
+
initial.current + (distance / extent.current) * (current.upper - current.lower),
|
|
117
|
+
);
|
|
118
|
+
},
|
|
119
|
+
onPanResponderRelease: () => config.current.onValueCommit?.(latest.current),
|
|
120
|
+
onPanResponderTerminate: () => config.current.onValueCommit?.(latest.current),
|
|
121
|
+
});
|
|
122
|
+
const vertical = orientation === 'vertical';
|
|
123
|
+
const position = (number: number) => ((number - lower) / (upper - lower)) * 100;
|
|
124
|
+
const beginning = current.length > 1 ? position(current[0]!) : 0;
|
|
125
|
+
const length = position(current[current.length - 1]!) - beginning;
|
|
126
|
+
return (
|
|
127
|
+
<View
|
|
128
|
+
{...props}
|
|
129
|
+
{...pan.current.panHandlers}
|
|
130
|
+
onLayout={(event) => {
|
|
131
|
+
extent.current = Math.max(1, event.nativeEvent.layout[vertical ? 'height' : 'width']);
|
|
132
|
+
onLayout?.(event);
|
|
133
|
+
}}
|
|
134
|
+
style={[
|
|
135
|
+
vertical
|
|
136
|
+
? { width: 44, height: 180, alignItems: 'center' }
|
|
137
|
+
: { height: 44, justifyContent: 'center' },
|
|
138
|
+
{ opacity: disabled ? 0.5 : 1 },
|
|
139
|
+
style,
|
|
140
|
+
]}
|
|
141
|
+
>
|
|
142
|
+
<View
|
|
143
|
+
style={[
|
|
144
|
+
vertical ? { width: 4, height: '100%' } : { height: 4, width: '100%' },
|
|
145
|
+
{ borderRadius: 2, backgroundColor: colors.secondary },
|
|
146
|
+
]}
|
|
147
|
+
>
|
|
148
|
+
<View
|
|
149
|
+
style={[
|
|
150
|
+
{ position: 'absolute', backgroundColor: colors.primary },
|
|
151
|
+
vertical
|
|
152
|
+
? { bottom: `${beginning}%`, height: `${length}%`, width: 4 }
|
|
153
|
+
: {
|
|
154
|
+
[direction === 'rtl' ? 'right' : 'left']: `${beginning}%`,
|
|
155
|
+
width: `${length}%`,
|
|
156
|
+
height: 4,
|
|
157
|
+
},
|
|
158
|
+
]}
|
|
159
|
+
/>
|
|
160
|
+
</View>
|
|
161
|
+
{current.map((item, index) => (
|
|
162
|
+
<View
|
|
163
|
+
key={index}
|
|
164
|
+
accessible
|
|
165
|
+
accessibilityRole="adjustable"
|
|
166
|
+
accessibilityLabel={
|
|
167
|
+
current.length === 1 ? accessibilityLabel : `${accessibilityLabel} ${index + 1}`
|
|
168
|
+
}
|
|
169
|
+
accessibilityState={{ disabled }}
|
|
170
|
+
accessibilityValue={{
|
|
171
|
+
min: index ? current[index - 1]! + gap : lower,
|
|
172
|
+
max: index < current.length - 1 ? current[index + 1]! - gap : upper,
|
|
173
|
+
now: item,
|
|
174
|
+
}}
|
|
175
|
+
accessibilityActions={disabled ? [] : [{ name: 'increment' }, { name: 'decrement' }]}
|
|
176
|
+
onAccessibilityAction={(event) => {
|
|
177
|
+
if (!disabled && ['increment', 'decrement'].includes(event.nativeEvent.actionName))
|
|
178
|
+
update(
|
|
179
|
+
index,
|
|
180
|
+
item + (event.nativeEvent.actionName === 'increment' ? increment : -increment),
|
|
181
|
+
true,
|
|
182
|
+
);
|
|
183
|
+
}}
|
|
184
|
+
style={[
|
|
185
|
+
{
|
|
186
|
+
position: 'absolute',
|
|
187
|
+
width: 22,
|
|
188
|
+
height: 22,
|
|
189
|
+
borderRadius: 11,
|
|
190
|
+
borderWidth: 2,
|
|
191
|
+
borderColor: colors.primary,
|
|
192
|
+
backgroundColor: colors.background,
|
|
193
|
+
},
|
|
194
|
+
vertical
|
|
195
|
+
? { bottom: `${position(item)}%`, marginBottom: -11 }
|
|
196
|
+
: {
|
|
197
|
+
[direction === 'rtl' ? 'right' : 'left']: `${position(item)}%`,
|
|
198
|
+
marginStart: -11,
|
|
199
|
+
},
|
|
200
|
+
]}
|
|
201
|
+
/>
|
|
202
|
+
))}
|
|
203
|
+
</View>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
type ResizeState = {
|
|
207
|
+
sizes: number[];
|
|
208
|
+
width: number;
|
|
209
|
+
direction: 'horizontal' | 'vertical';
|
|
210
|
+
resize: (index: number, delta: number) => void;
|
|
211
|
+
};
|
|
212
|
+
const ResizeContext = createContext<ResizeState | null>(null);
|
|
213
|
+
export function ResizablePanelGroup({
|
|
214
|
+
direction = 'horizontal',
|
|
215
|
+
onLayout: onSizes,
|
|
216
|
+
children,
|
|
217
|
+
style,
|
|
218
|
+
...props
|
|
219
|
+
}: Omit<ViewProps, 'onLayout'> & {
|
|
220
|
+
direction?: 'horizontal' | 'vertical';
|
|
221
|
+
onLayout?: (sizes: number[]) => void;
|
|
222
|
+
}) {
|
|
223
|
+
const panels = Children.toArray(children).filter(
|
|
224
|
+
(child) => isValidElement(child) && child.type === ResizablePanel,
|
|
225
|
+
) as React.ReactElement<{ defaultSize?: number; minSize?: number; maxSize?: number }>[];
|
|
226
|
+
const initial = panels.map(
|
|
227
|
+
(panel) => panel.props.defaultSize ?? 100 / Math.max(1, panels.length),
|
|
228
|
+
);
|
|
229
|
+
const total = initial.reduce((sum, item) => sum + item, 0) || 100;
|
|
230
|
+
const [sizes, set] = useState(initial.map((item) => (item / total) * 100));
|
|
231
|
+
const [width, setWidth] = useState(1);
|
|
232
|
+
const liveSizes = useRef(sizes);
|
|
233
|
+
liveSizes.current = sizes;
|
|
234
|
+
const resize = (index: number, delta: number) => {
|
|
235
|
+
if (!panels[index + 1]) return;
|
|
236
|
+
const before = liveSizes.current;
|
|
237
|
+
const available = before[index]! + before[index + 1]!;
|
|
238
|
+
const min = Math.max(
|
|
239
|
+
panels[index]!.props.minSize ?? 10,
|
|
240
|
+
available - (panels[index + 1]!.props.maxSize ?? 100),
|
|
241
|
+
);
|
|
242
|
+
const max = Math.min(
|
|
243
|
+
panels[index]!.props.maxSize ?? 100,
|
|
244
|
+
available - (panels[index + 1]!.props.minSize ?? 10),
|
|
245
|
+
);
|
|
246
|
+
if (min > max) return;
|
|
247
|
+
const next = [...before];
|
|
248
|
+
next[index] = clamp(before[index]! + delta, min, max);
|
|
249
|
+
next[index + 1] = available - next[index];
|
|
250
|
+
liveSizes.current = next;
|
|
251
|
+
set(next);
|
|
252
|
+
onSizes?.(next);
|
|
253
|
+
};
|
|
254
|
+
let index = -1;
|
|
255
|
+
return (
|
|
256
|
+
<ResizeContext.Provider value={{ sizes, width, direction, resize }}>
|
|
257
|
+
<View
|
|
258
|
+
{...props}
|
|
259
|
+
onLayout={(event) =>
|
|
260
|
+
setWidth(
|
|
261
|
+
Math.max(
|
|
262
|
+
1,
|
|
263
|
+
event.nativeEvent.layout[direction === 'horizontal' ? 'width' : 'height'] -
|
|
264
|
+
Math.max(0, panels.length - 1) * 24,
|
|
265
|
+
),
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
style={[
|
|
269
|
+
{ flexDirection: direction === 'horizontal' ? 'row' : 'column', minHeight: 120 },
|
|
270
|
+
style,
|
|
271
|
+
]}
|
|
272
|
+
>
|
|
273
|
+
{Children.map(children, (child) => {
|
|
274
|
+
if (!isValidElement<{ panelIndex?: number }>(child)) return child;
|
|
275
|
+
if (child.type !== ResizablePanel && child.type !== ResizableHandle) return child;
|
|
276
|
+
if (child.type === ResizablePanel) index++;
|
|
277
|
+
return cloneElement(child, { panelIndex: Math.max(0, index) });
|
|
278
|
+
})}
|
|
279
|
+
</View>
|
|
280
|
+
</ResizeContext.Provider>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
export function ResizablePanel({
|
|
284
|
+
defaultSize: _default,
|
|
285
|
+
minSize: _min,
|
|
286
|
+
maxSize: _max,
|
|
287
|
+
panelIndex = 0,
|
|
288
|
+
style,
|
|
289
|
+
...props
|
|
290
|
+
}: ViewProps & { defaultSize?: number; minSize?: number; maxSize?: number; panelIndex?: number }) {
|
|
291
|
+
const state = useContext(ResizeContext);
|
|
292
|
+
if (!state) throw Error('ResizablePanel requires ResizablePanelGroup.');
|
|
293
|
+
return (
|
|
294
|
+
<Box
|
|
295
|
+
{...props}
|
|
296
|
+
style={[
|
|
297
|
+
{ flex: state.sizes[panelIndex], minWidth: 0, minHeight: 0, overflow: 'hidden' },
|
|
298
|
+
style,
|
|
299
|
+
]}
|
|
300
|
+
/>
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
export function ResizableHandle({
|
|
304
|
+
withHandle = false,
|
|
305
|
+
panelIndex = 0,
|
|
306
|
+
accessibilityLabel = 'Resize panels',
|
|
307
|
+
}: {
|
|
308
|
+
panelIndex?: number;
|
|
309
|
+
accessibilityLabel?: string;
|
|
310
|
+
withHandle?: boolean;
|
|
311
|
+
}) {
|
|
312
|
+
const state = useContext(ResizeContext);
|
|
313
|
+
const previous = useRef(0);
|
|
314
|
+
const liveState = useRef(state);
|
|
315
|
+
liveState.current = state;
|
|
316
|
+
const pan = useRef<ReturnType<typeof PanResponder.create> | null>(null);
|
|
317
|
+
const { colors } = useTheme();
|
|
318
|
+
if (!state) throw Error('ResizableHandle requires ResizablePanelGroup.');
|
|
319
|
+
if (!pan.current)
|
|
320
|
+
pan.current = PanResponder.create({
|
|
321
|
+
onMoveShouldSetPanResponder: () => true,
|
|
322
|
+
onPanResponderGrant: () => {
|
|
323
|
+
previous.current = 0;
|
|
324
|
+
},
|
|
325
|
+
onPanResponderMove: (_event, gesture) => {
|
|
326
|
+
const current = liveState.current;
|
|
327
|
+
if (!current) return;
|
|
328
|
+
const distance = current.direction === 'horizontal' ? gesture.dx : gesture.dy;
|
|
329
|
+
current.resize(panelIndex, ((distance - previous.current) / current.width) * 100);
|
|
330
|
+
previous.current = distance;
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
return (
|
|
334
|
+
<View
|
|
335
|
+
{...pan.current.panHandlers}
|
|
336
|
+
accessible
|
|
337
|
+
accessibilityRole="adjustable"
|
|
338
|
+
accessibilityLabel={accessibilityLabel}
|
|
339
|
+
accessibilityValue={{ min: 0, max: 100, now: state.sizes[panelIndex] }}
|
|
340
|
+
accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }]}
|
|
341
|
+
onAccessibilityAction={(event) => {
|
|
342
|
+
if (['increment', 'decrement'].includes(event.nativeEvent.actionName))
|
|
343
|
+
state.resize(panelIndex, event.nativeEvent.actionName === 'increment' ? 5 : -5);
|
|
344
|
+
}}
|
|
345
|
+
style={
|
|
346
|
+
state.direction === 'horizontal'
|
|
347
|
+
? { width: 24, alignSelf: 'stretch', justifyContent: 'center', alignItems: 'center' }
|
|
348
|
+
: { height: 24, alignSelf: 'stretch', justifyContent: 'center', alignItems: 'center' }
|
|
349
|
+
}
|
|
350
|
+
>
|
|
351
|
+
{withHandle && (
|
|
352
|
+
<View
|
|
353
|
+
testID="resize-grip"
|
|
354
|
+
style={{
|
|
355
|
+
width: state.direction === 'horizontal' ? 4 : 28,
|
|
356
|
+
height: state.direction === 'horizontal' ? 28 : 4,
|
|
357
|
+
borderRadius: 2,
|
|
358
|
+
backgroundColor: colors.border,
|
|
359
|
+
}}
|
|
360
|
+
/>
|
|
361
|
+
)}
|
|
362
|
+
</View>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
type CarouselState = {
|
|
366
|
+
index: number;
|
|
367
|
+
count: number;
|
|
368
|
+
setCount: (count: number) => void;
|
|
369
|
+
size: number;
|
|
370
|
+
setSize: (size: number) => void;
|
|
371
|
+
move: (index: number) => void;
|
|
372
|
+
selected: (index: number) => void;
|
|
373
|
+
loop: boolean;
|
|
374
|
+
orientation: 'horizontal' | 'vertical';
|
|
375
|
+
scroll: React.RefObject<ScrollView | null>;
|
|
376
|
+
};
|
|
377
|
+
const CarouselContext = createContext<CarouselState | null>(null);
|
|
378
|
+
function useCarousel() {
|
|
379
|
+
const value = useContext(CarouselContext);
|
|
380
|
+
if (!value) throw Error('Carousel parts require Carousel.');
|
|
381
|
+
return value;
|
|
382
|
+
}
|
|
383
|
+
export function Carousel({
|
|
384
|
+
index,
|
|
385
|
+
defaultIndex = 0,
|
|
386
|
+
onIndexChange,
|
|
387
|
+
loop = false,
|
|
388
|
+
orientation = 'horizontal',
|
|
389
|
+
...props
|
|
390
|
+
}: ViewProps & {
|
|
391
|
+
index?: number;
|
|
392
|
+
defaultIndex?: number;
|
|
393
|
+
onIndexChange?: (index: number) => void;
|
|
394
|
+
loop?: boolean;
|
|
395
|
+
orientation?: 'horizontal' | 'vertical';
|
|
396
|
+
}) {
|
|
397
|
+
const [selected, set] = useControllable(index, defaultIndex, onIndexChange);
|
|
398
|
+
const [count, setCount] = useState(0);
|
|
399
|
+
const [size, setSize] = useState(1);
|
|
400
|
+
const scroll = useRef<ScrollView>(null);
|
|
401
|
+
const move = (next: number) => {
|
|
402
|
+
if (!count) return;
|
|
403
|
+
const target = loop ? (next + count) % count : clamp(next, 0, count - 1);
|
|
404
|
+
set(target);
|
|
405
|
+
scroll.current?.scrollTo({
|
|
406
|
+
[orientation === 'horizontal' ? 'x' : 'y']: target * size,
|
|
407
|
+
animated: false,
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
useEffect(() => {
|
|
411
|
+
if (size > 1)
|
|
412
|
+
scroll.current?.scrollTo({
|
|
413
|
+
[orientation === 'horizontal' ? 'x' : 'y']:
|
|
414
|
+
clamp(selected, 0, Math.max(0, count - 1)) * size,
|
|
415
|
+
animated: false,
|
|
416
|
+
});
|
|
417
|
+
}, [selected, size, count, orientation]);
|
|
418
|
+
return (
|
|
419
|
+
<CarouselContext.Provider
|
|
420
|
+
value={{
|
|
421
|
+
index: selected,
|
|
422
|
+
selected: set,
|
|
423
|
+
count,
|
|
424
|
+
setCount,
|
|
425
|
+
size,
|
|
426
|
+
setSize,
|
|
427
|
+
move,
|
|
428
|
+
loop,
|
|
429
|
+
orientation,
|
|
430
|
+
scroll,
|
|
431
|
+
}}
|
|
432
|
+
>
|
|
433
|
+
<Box accessibilityLabel="Carousel" {...props} />
|
|
434
|
+
</CarouselContext.Provider>
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
export function CarouselContent({
|
|
438
|
+
children,
|
|
439
|
+
style,
|
|
440
|
+
...props
|
|
441
|
+
}: React.ComponentProps<typeof ScrollView>) {
|
|
442
|
+
const carousel = useCarousel();
|
|
443
|
+
const count = Children.count(children);
|
|
444
|
+
useEffect(() => carousel.setCount(count), [count, carousel.setCount]);
|
|
445
|
+
return (
|
|
446
|
+
<ScrollView
|
|
447
|
+
{...props}
|
|
448
|
+
ref={carousel.scroll}
|
|
449
|
+
horizontal={carousel.orientation === 'horizontal'}
|
|
450
|
+
pagingEnabled
|
|
451
|
+
onLayout={(event) =>
|
|
452
|
+
carousel.setSize(
|
|
453
|
+
event.nativeEvent.layout[carousel.orientation === 'horizontal' ? 'width' : 'height'],
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
onMomentumScrollEnd={(event) =>
|
|
457
|
+
carousel.selected(
|
|
458
|
+
Math.round(
|
|
459
|
+
event.nativeEvent.contentOffset[carousel.orientation === 'horizontal' ? 'x' : 'y'] /
|
|
460
|
+
carousel.size,
|
|
461
|
+
),
|
|
462
|
+
)
|
|
463
|
+
}
|
|
464
|
+
showsHorizontalScrollIndicator={false}
|
|
465
|
+
style={[{ flexGrow: 0 }, style]}
|
|
466
|
+
>
|
|
467
|
+
{children}
|
|
468
|
+
</ScrollView>
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
export function CarouselItem({ style, ...props }: ViewProps) {
|
|
472
|
+
const carousel = useCarousel();
|
|
473
|
+
return (
|
|
474
|
+
<Box
|
|
475
|
+
{...props}
|
|
476
|
+
style={[
|
|
477
|
+
carousel.orientation === 'horizontal'
|
|
478
|
+
? { width: carousel.size }
|
|
479
|
+
: { height: carousel.size },
|
|
480
|
+
style,
|
|
481
|
+
]}
|
|
482
|
+
/>
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
export function CarouselPrevious({
|
|
486
|
+
children = 'Previous',
|
|
487
|
+
...props
|
|
488
|
+
}: Omit<ButtonProps, 'children'> & { children?: ReactNode }) {
|
|
489
|
+
const carousel = useCarousel();
|
|
490
|
+
return (
|
|
491
|
+
<Button
|
|
492
|
+
accessibilityLabel="Previous slide"
|
|
493
|
+
{...props}
|
|
494
|
+
disabled={!carousel.count || (!carousel.loop && carousel.index <= 0) || props.disabled}
|
|
495
|
+
onPress={() => carousel.move(carousel.index - 1)}
|
|
496
|
+
>
|
|
497
|
+
{children}
|
|
498
|
+
</Button>
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
export function CarouselNext({
|
|
502
|
+
children = 'Next',
|
|
503
|
+
...props
|
|
504
|
+
}: Omit<ButtonProps, 'children'> & { children?: ReactNode }) {
|
|
505
|
+
const carousel = useCarousel();
|
|
506
|
+
return (
|
|
507
|
+
<Button
|
|
508
|
+
accessibilityLabel="Next slide"
|
|
509
|
+
{...props}
|
|
510
|
+
disabled={
|
|
511
|
+
!carousel.count ||
|
|
512
|
+
(!carousel.loop && carousel.index >= carousel.count - 1) ||
|
|
513
|
+
props.disabled
|
|
514
|
+
}
|
|
515
|
+
onPress={() => carousel.move(carousel.index + 1)}
|
|
516
|
+
>
|
|
517
|
+
{children}
|
|
518
|
+
</Button>
|
|
519
|
+
);
|
|
520
|
+
}
|