zkit-ui 1.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.
- package/README.md +267 -0
- package/dist/ComponentLibProvider.d.ts +15 -0
- package/dist/ComponentLibProvider.d.ts.map +1 -0
- package/dist/ComponentLibProvider.js +18 -0
- package/dist/assets/animations/spinner.json +1 -0
- package/dist/assets/icons/check.svg +4 -0
- package/dist/assets/icons/toast/error.webp +0 -0
- package/dist/assets/icons/toast/success.webp +0 -0
- package/dist/assets/icons/toast/warning.webp +0 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +42 -0
- package/dist/i18n/I18nProvider.d.ts +11 -0
- package/dist/i18n/I18nProvider.d.ts.map +1 -0
- package/dist/i18n/I18nProvider.js +84 -0
- package/dist/i18n/locale.d.ts +7 -0
- package/dist/i18n/locale.d.ts.map +1 -0
- package/dist/i18n/locale.js +87 -0
- package/dist/i18n/locales/de.d.ts +51 -0
- package/dist/i18n/locales/de.d.ts.map +1 -0
- package/dist/i18n/locales/de.js +62 -0
- package/dist/i18n/locales/en-US.d.ts +51 -0
- package/dist/i18n/locales/en-US.d.ts.map +1 -0
- package/dist/i18n/locales/en-US.js +62 -0
- package/dist/i18n/locales/index.d.ts +9 -0
- package/dist/i18n/locales/index.d.ts.map +1 -0
- package/dist/i18n/locales/index.js +23 -0
- package/dist/i18n/locales/ja.d.ts +51 -0
- package/dist/i18n/locales/ja.d.ts.map +1 -0
- package/dist/i18n/locales/ja.js +62 -0
- package/dist/i18n/locales/zh-CN.d.ts +51 -0
- package/dist/i18n/locales/zh-CN.d.ts.map +1 -0
- package/dist/i18n/locales/zh-CN.js +62 -0
- package/dist/i18n/locales/zh-TW.d.ts +51 -0
- package/dist/i18n/locales/zh-TW.d.ts.map +1 -0
- package/dist/i18n/locales/zh-TW.js +62 -0
- package/dist/i18n/types.d.ts +11 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +2 -0
- package/dist/i18n/useI18n.d.ts +2 -0
- package/dist/i18n/useI18n.d.ts.map +1 -0
- package/dist/i18n/useI18n.js +41 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/services/ActionDialogService/ActionDialog.d.ts +4 -0
- package/dist/services/ActionDialogService/ActionDialog.d.ts.map +1 -0
- package/dist/services/ActionDialogService/ActionDialog.js +531 -0
- package/dist/services/ActionDialogService/index.d.ts +4 -0
- package/dist/services/ActionDialogService/index.d.ts.map +1 -0
- package/dist/services/ActionDialogService/index.js +8 -0
- package/dist/services/ActionDialogService/service.d.ts +7 -0
- package/dist/services/ActionDialogService/service.d.ts.map +1 -0
- package/dist/services/ActionDialogService/service.js +309 -0
- package/dist/services/ActionDialogService/shared.d.ts +17 -0
- package/dist/services/ActionDialogService/shared.d.ts.map +1 -0
- package/dist/services/ActionDialogService/shared.js +167 -0
- package/dist/services/ActionDialogService/types.d.ts +160 -0
- package/dist/services/ActionDialogService/types.d.ts.map +1 -0
- package/dist/services/ActionDialogService/types.js +2 -0
- package/dist/services/CardToastService/index.d.ts +115 -0
- package/dist/services/CardToastService/index.d.ts.map +1 -0
- package/dist/services/CardToastService/index.js +899 -0
- package/dist/services/ImagePreviewService/index.d.ts +179 -0
- package/dist/services/ImagePreviewService/index.d.ts.map +1 -0
- package/dist/services/ImagePreviewService/index.js +1383 -0
- package/dist/services/LoadingService/index.d.ts +146 -0
- package/dist/services/LoadingService/index.d.ts.map +1 -0
- package/dist/services/LoadingService/index.js +827 -0
- package/dist/services/PermissionPurposeDialogService/index.d.ts +99 -0
- package/dist/services/PermissionPurposeDialogService/index.d.ts.map +1 -0
- package/dist/services/PermissionPurposeDialogService/index.js +360 -0
- package/dist/services/PickerService/index.d.ts +128 -0
- package/dist/services/PickerService/index.d.ts.map +1 -0
- package/dist/services/PickerService/index.js +250 -0
- package/dist/theme/ThemeProvider.d.ts +15 -0
- package/dist/theme/ThemeProvider.d.ts.map +1 -0
- package/dist/theme/ThemeProvider.js +61 -0
- package/dist/theme/defaultTheme.d.ts +3 -0
- package/dist/theme/defaultTheme.d.ts.map +1 -0
- package/dist/theme/defaultTheme.js +28 -0
- package/dist/theme/mergeTheme.d.ts +3 -0
- package/dist/theme/mergeTheme.d.ts.map +1 -0
- package/dist/theme/mergeTheme.js +19 -0
- package/dist/theme/types.d.ts +17 -0
- package/dist/theme/types.d.ts.map +1 -0
- package/dist/theme/types.js +2 -0
- package/dist/theme/useTheme.d.ts +2 -0
- package/dist/theme/useTheme.d.ts.map +1 -0
- package/dist/theme/useTheme.js +46 -0
- package/dist/ui/Accordion/index.d.ts +99 -0
- package/dist/ui/Accordion/index.d.ts.map +1 -0
- package/dist/ui/Accordion/index.js +777 -0
- package/dist/ui/AddressCascader/index.d.ts +58 -0
- package/dist/ui/AddressCascader/index.d.ts.map +1 -0
- package/dist/ui/AddressCascader/index.js +710 -0
- package/dist/ui/BetweenTime/index.d.ts +82 -0
- package/dist/ui/BetweenTime/index.d.ts.map +1 -0
- package/dist/ui/BetweenTime/index.js +702 -0
- package/dist/ui/Button/index.d.ts +93 -0
- package/dist/ui/Button/index.d.ts.map +1 -0
- package/dist/ui/Button/index.js +832 -0
- package/dist/ui/Checkbox/index.d.ts +103 -0
- package/dist/ui/Checkbox/index.d.ts.map +1 -0
- package/dist/ui/Checkbox/index.js +694 -0
- package/dist/ui/DatePicker/index.d.ts +5 -0
- package/dist/ui/DatePicker/index.d.ts.map +1 -0
- package/dist/ui/DatePicker/index.js +157 -0
- package/dist/ui/DatePicker/types.d.ts +99 -0
- package/dist/ui/DatePicker/types.d.ts.map +1 -0
- package/dist/ui/DatePicker/types.js +2 -0
- package/dist/ui/DatePicker/utils.d.ts +32 -0
- package/dist/ui/DatePicker/utils.d.ts.map +1 -0
- package/dist/ui/DatePicker/utils.js +316 -0
- package/dist/ui/LinkedScroll/index.d.ts +78 -0
- package/dist/ui/LinkedScroll/index.d.ts.map +1 -0
- package/dist/ui/LinkedScroll/index.js +470 -0
- package/dist/ui/LoadingSpinner/index.d.ts +8 -0
- package/dist/ui/LoadingSpinner/index.d.ts.map +1 -0
- package/dist/ui/LoadingSpinner/index.js +122 -0
- package/dist/ui/Picker/actionBar.d.ts +14 -0
- package/dist/ui/Picker/actionBar.d.ts.map +1 -0
- package/dist/ui/Picker/actionBar.js +28 -0
- package/dist/ui/Picker/index.d.ts +5 -0
- package/dist/ui/Picker/index.d.ts.map +1 -0
- package/dist/ui/Picker/index.js +412 -0
- package/dist/ui/Picker/types.d.ts +80 -0
- package/dist/ui/Picker/types.d.ts.map +1 -0
- package/dist/ui/Picker/types.js +2 -0
- package/dist/ui/Picker/utils.d.ts +27 -0
- package/dist/ui/Picker/utils.d.ts.map +1 -0
- package/dist/ui/Picker/utils.js +182 -0
- package/dist/ui/Radio/index.d.ts +95 -0
- package/dist/ui/Radio/index.d.ts.map +1 -0
- package/dist/ui/Radio/index.js +633 -0
- package/dist/ui/Sheet/index.d.ts +12 -0
- package/dist/ui/Sheet/index.d.ts.map +1 -0
- package/dist/ui/Sheet/index.js +832 -0
- package/dist/ui/Sheet/nativeBottom.d.ts +52 -0
- package/dist/ui/Sheet/nativeBottom.d.ts.map +1 -0
- package/dist/ui/Sheet/nativeBottom.js +442 -0
- package/dist/ui/Sheet/nativeBottom.web.d.ts +18 -0
- package/dist/ui/Sheet/nativeBottom.web.d.ts.map +1 -0
- package/dist/ui/Sheet/nativeBottom.web.js +46 -0
- package/dist/ui/Sheet/slots.d.ts +5 -0
- package/dist/ui/Sheet/slots.d.ts.map +1 -0
- package/dist/ui/Sheet/slots.js +40 -0
- package/dist/ui/Sheet/types.d.ts +131 -0
- package/dist/ui/Sheet/types.d.ts.map +1 -0
- package/dist/ui/Sheet/types.js +2 -0
- package/dist/ui/SliderCaptcha/index.d.ts +57 -0
- package/dist/ui/SliderCaptcha/index.d.ts.map +1 -0
- package/dist/ui/SliderCaptcha/index.js +586 -0
- package/dist/ui/Switch/index.d.ts +72 -0
- package/dist/ui/Switch/index.d.ts.map +1 -0
- package/dist/ui/Switch/index.js +671 -0
- package/dist/ui/Text/index.d.ts +41 -0
- package/dist/ui/Text/index.d.ts.map +1 -0
- package/dist/ui/Text/index.js +325 -0
- package/dist/ui/TextInput/TextInputPrimitive.d.ts +8 -0
- package/dist/ui/TextInput/TextInputPrimitive.d.ts.map +1 -0
- package/dist/ui/TextInput/TextInputPrimitive.js +54 -0
- package/dist/ui/TextInput/index.d.ts +89 -0
- package/dist/ui/TextInput/index.d.ts.map +1 -0
- package/dist/ui/TextInput/index.js +545 -0
- package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.d.ts +39 -0
- package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.d.ts.map +1 -0
- package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.js +60 -0
- package/dist/ui/WheelColumn/constants.d.ts +2 -0
- package/dist/ui/WheelColumn/constants.d.ts.map +1 -0
- package/dist/ui/WheelColumn/constants.js +4 -0
- package/dist/ui/WheelColumn/index.d.ts +59 -0
- package/dist/ui/WheelColumn/index.d.ts.map +1 -0
- package/dist/ui/WheelColumn/index.js +547 -0
- package/ios/ZKitWheelPicker.h +18 -0
- package/ios/ZKitWheelPicker.mm +230 -0
- package/ios/ZKitWheelPickerLabel.h +10 -0
- package/ios/ZKitWheelPickerLabel.mm +31 -0
- package/ios/ZKitWheelPickerManager.h +5 -0
- package/ios/ZKitWheelPickerManager.mm +53 -0
- package/package.json +75 -0
- package/react-native.config.js +10 -0
- package/src/ComponentLibProvider.tsx +56 -0
- package/src/assets/animations/spinner.json +1 -0
- package/src/assets/icons/check.svg +4 -0
- package/src/assets/icons/toast/error.webp +0 -0
- package/src/assets/icons/toast/success.webp +0 -0
- package/src/assets/icons/toast/warning.webp +0 -0
- package/src/config.ts +65 -0
- package/src/i18n/I18nProvider.tsx +69 -0
- package/src/i18n/locale.ts +108 -0
- package/src/i18n/locales/de.ts +67 -0
- package/src/i18n/locales/en-US.ts +67 -0
- package/src/i18n/locales/index.ts +19 -0
- package/src/i18n/locales/ja.ts +67 -0
- package/src/i18n/locales/zh-CN.ts +67 -0
- package/src/i18n/locales/zh-TW.ts +67 -0
- package/src/i18n/types.ts +21 -0
- package/src/i18n/useI18n.ts +7 -0
- package/src/index.ts +395 -0
- package/src/services/ActionDialogService/ActionDialog.tsx +756 -0
- package/src/services/ActionDialogService/README.md +146 -0
- package/src/services/ActionDialogService/index.tsx +39 -0
- package/src/services/ActionDialogService/service.tsx +355 -0
- package/src/services/ActionDialogService/shared.ts +204 -0
- package/src/services/ActionDialogService/types.ts +197 -0
- package/src/services/CardToastService/README.md +128 -0
- package/src/services/CardToastService/index.tsx +1284 -0
- package/src/services/ImagePreviewService/README.md +67 -0
- package/src/services/ImagePreviewService/index.tsx +2148 -0
- package/src/services/LoadingService/README.md +128 -0
- package/src/services/LoadingService/index.tsx +1113 -0
- package/src/services/PermissionPurposeDialogService/README.md +80 -0
- package/src/services/PermissionPurposeDialogService/index.tsx +449 -0
- package/src/services/PickerService/README.md +154 -0
- package/src/services/PickerService/index.tsx +410 -0
- package/src/theme/ThemeProvider.tsx +40 -0
- package/src/theme/defaultTheme.ts +30 -0
- package/src/theme/mergeTheme.ts +16 -0
- package/src/theme/types.ts +36 -0
- package/src/theme/useTheme.ts +10 -0
- package/src/types/svg.d.ts +9 -0
- package/src/types/vant-area-data.d.ts +19 -0
- package/src/ui/Accordion/README.md +67 -0
- package/src/ui/Accordion/index.tsx +1221 -0
- package/src/ui/AddressCascader/README.md +144 -0
- package/src/ui/AddressCascader/index.tsx +1084 -0
- package/src/ui/BetweenTime/README.md +490 -0
- package/src/ui/BetweenTime/index.tsx +1001 -0
- package/src/ui/Button/README.md +186 -0
- package/src/ui/Button/index.tsx +1356 -0
- package/src/ui/Checkbox/README.md +211 -0
- package/src/ui/Checkbox/index.tsx +1231 -0
- package/src/ui/DatePicker/README.md +117 -0
- package/src/ui/DatePicker/index.tsx +295 -0
- package/src/ui/DatePicker/types.ts +115 -0
- package/src/ui/DatePicker/utils.ts +405 -0
- package/src/ui/LinkedScroll/README.md +55 -0
- package/src/ui/LinkedScroll/index.tsx +809 -0
- package/src/ui/LoadingSpinner/index.tsx +104 -0
- package/src/ui/Picker/README.md +190 -0
- package/src/ui/Picker/actionBar.tsx +70 -0
- package/src/ui/Picker/index.tsx +694 -0
- package/src/ui/Picker/types.ts +94 -0
- package/src/ui/Picker/utils.ts +239 -0
- package/src/ui/Radio/README.md +207 -0
- package/src/ui/Radio/index.tsx +1117 -0
- package/src/ui/Sheet/README.md +82 -0
- package/src/ui/Sheet/index.tsx +1163 -0
- package/src/ui/Sheet/nativeBottom.tsx +683 -0
- package/src/ui/Sheet/nativeBottom.web.tsx +40 -0
- package/src/ui/Sheet/slots.tsx +75 -0
- package/src/ui/Sheet/types.ts +195 -0
- package/src/ui/SliderCaptcha/README.md +61 -0
- package/src/ui/SliderCaptcha/index.tsx +816 -0
- package/src/ui/Switch/README.md +143 -0
- package/src/ui/Switch/index.tsx +1092 -0
- package/src/ui/Text/README.md +157 -0
- package/src/ui/Text/index.tsx +450 -0
- package/src/ui/TextInput/README.md +197 -0
- package/src/ui/TextInput/TextInputPrimitive.tsx +44 -0
- package/src/ui/TextInput/index.tsx +942 -0
- package/src/ui/WheelColumn/README.md +104 -0
- package/src/ui/WheelColumn/ZKitWheelPickerNativeComponent.tsx +68 -0
- package/src/ui/WheelColumn/constants.ts +1 -0
- package/src/ui/WheelColumn/index.tsx +826 -0
- package/zkit-ui.podspec +19 -0
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.BetweenTime = void 0;
|
|
40
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
41
|
+
const React = __importStar(require("react"));
|
|
42
|
+
const react_native_1 = require("react-native");
|
|
43
|
+
const expo_linear_gradient_1 = require("expo-linear-gradient");
|
|
44
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
45
|
+
const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat"));
|
|
46
|
+
const react_native_safe_area_context_1 = require("react-native-safe-area-context");
|
|
47
|
+
const zkit_tools_1 = require("zkit-tools");
|
|
48
|
+
const useI18n_1 = require("../../i18n/useI18n");
|
|
49
|
+
const useTheme_1 = require("../../theme/useTheme");
|
|
50
|
+
const Sheet_1 = require("../Sheet");
|
|
51
|
+
const Button_1 = require("../Button");
|
|
52
|
+
const actionBar_1 = require("../Picker/actionBar");
|
|
53
|
+
const Text_1 = require("../Text");
|
|
54
|
+
const WheelColumn_1 = require("../WheelColumn");
|
|
55
|
+
dayjs_1.default.extend(customParseFormat_1.default);
|
|
56
|
+
const ITEM_HEIGHT = WheelColumn_1.WHEEL_ITEM_HEIGHT;
|
|
57
|
+
const VISIBLE_ITEMS = WheelColumn_1.WHEEL_VISIBLE_ITEMS;
|
|
58
|
+
const STANDARD_INPUT_FORMATS = [
|
|
59
|
+
'YYYY',
|
|
60
|
+
'YYYY-M',
|
|
61
|
+
'YYYY-MM',
|
|
62
|
+
'YYYY-M-D',
|
|
63
|
+
'YYYY-MM-DD',
|
|
64
|
+
'YYYY-MM-DDHH',
|
|
65
|
+
'YYYY-MM-DD HH',
|
|
66
|
+
'YYYY-MM-DDHH:mm',
|
|
67
|
+
'YYYY-MM-DD HH:mm',
|
|
68
|
+
'YYYY-MM-DDHH:mm:ss',
|
|
69
|
+
'YYYY-MM-DD HH:mm:ss',
|
|
70
|
+
];
|
|
71
|
+
function clampNumber(n, min, max) {
|
|
72
|
+
return Math.max(min, Math.min(max, n));
|
|
73
|
+
}
|
|
74
|
+
function toIntOrNull(v) {
|
|
75
|
+
const n = Number.parseInt(v, 10);
|
|
76
|
+
return Number.isFinite(n) ? n : null;
|
|
77
|
+
}
|
|
78
|
+
function parseStandardDateStrict(input) {
|
|
79
|
+
if (!input)
|
|
80
|
+
return undefined;
|
|
81
|
+
const d = (0, dayjs_1.default)(input, STANDARD_INPUT_FORMATS, true);
|
|
82
|
+
if (!d.isValid()) {
|
|
83
|
+
throw new Error(`[zkit-ui][BetweenTime] Invalid date string: "${input}"`);
|
|
84
|
+
}
|
|
85
|
+
return d;
|
|
86
|
+
}
|
|
87
|
+
function formatByType(d, type) {
|
|
88
|
+
switch (type) {
|
|
89
|
+
case 'year':
|
|
90
|
+
return d.format('YYYY');
|
|
91
|
+
case 'month':
|
|
92
|
+
return d.format('YYYY-MM');
|
|
93
|
+
case 'day':
|
|
94
|
+
return d.format('YYYY-MM-DD');
|
|
95
|
+
case 'hour':
|
|
96
|
+
return d.format('YYYY-MM-DDHH');
|
|
97
|
+
case 'minute':
|
|
98
|
+
return d.format('YYYY-MM-DDHH:mm');
|
|
99
|
+
case 'second':
|
|
100
|
+
return d.format('YYYY-MM-DDHH:mm:ss');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function normalizeDraftByType(d, type) {
|
|
104
|
+
if (type === 'year')
|
|
105
|
+
return d.month(0).date(1).hour(0).minute(0).second(0);
|
|
106
|
+
if (type === 'month')
|
|
107
|
+
return d.date(1).hour(0).minute(0).second(0);
|
|
108
|
+
if (type === 'day')
|
|
109
|
+
return d.hour(0).minute(0).second(0);
|
|
110
|
+
if (type === 'hour')
|
|
111
|
+
return d.minute(0).second(0);
|
|
112
|
+
if (type === 'minute')
|
|
113
|
+
return d.second(0);
|
|
114
|
+
return d;
|
|
115
|
+
}
|
|
116
|
+
function clampToBounds(d, bounds) {
|
|
117
|
+
if (bounds.min && d.isBefore(bounds.min))
|
|
118
|
+
return bounds.min;
|
|
119
|
+
if (bounds.max && d.isAfter(bounds.max))
|
|
120
|
+
return bounds.max;
|
|
121
|
+
return d;
|
|
122
|
+
}
|
|
123
|
+
function resolveInitialPair(modelValue, bounds, type) {
|
|
124
|
+
const rawStart = Array.isArray(modelValue) ? modelValue[0] : undefined;
|
|
125
|
+
const rawEnd = Array.isArray(modelValue) ? modelValue[1] : undefined;
|
|
126
|
+
const min = bounds.min;
|
|
127
|
+
const max = bounds.max;
|
|
128
|
+
const now = (0, dayjs_1.default)();
|
|
129
|
+
let s = rawStart ? parseStandardDateStrict(rawStart) : undefined;
|
|
130
|
+
let e = rawEnd ? parseStandardDateStrict(rawEnd) : undefined;
|
|
131
|
+
if (!s || !e) {
|
|
132
|
+
const seed = clampToBounds(now, bounds);
|
|
133
|
+
s = s !== null && s !== void 0 ? s : seed;
|
|
134
|
+
e = e !== null && e !== void 0 ? e : seed;
|
|
135
|
+
}
|
|
136
|
+
s = normalizeDraftByType(clampToBounds(s, bounds), type);
|
|
137
|
+
e = normalizeDraftByType(clampToBounds(e, bounds), type);
|
|
138
|
+
if (s.isAfter(e)) {
|
|
139
|
+
const tmp = s;
|
|
140
|
+
s = e;
|
|
141
|
+
e = tmp;
|
|
142
|
+
}
|
|
143
|
+
if (min && max && min.isAfter(max)) {
|
|
144
|
+
throw new Error('[zkit-ui][BetweenTime] Invalid bounds: start is after end.');
|
|
145
|
+
}
|
|
146
|
+
return { start: s, end: e };
|
|
147
|
+
}
|
|
148
|
+
function ensureFormatSyncValueIsStandard(value) {
|
|
149
|
+
const d = (0, dayjs_1.default)(value, STANDARD_INPUT_FORMATS, true);
|
|
150
|
+
if (!d.isValid()) {
|
|
151
|
+
throw new Error(`[zkit-ui][BetweenTime] formatSyncValue requires standard output, got "${value}".`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function getQuarterStart(d) {
|
|
155
|
+
const m = d.month(); // 0-11
|
|
156
|
+
const qStartMonth = Math.floor(m / 3) * 3;
|
|
157
|
+
return d.month(qStartMonth).date(1).hour(0).minute(0).second(0);
|
|
158
|
+
}
|
|
159
|
+
function getQuickRange(key, now) {
|
|
160
|
+
if (key === 'd') {
|
|
161
|
+
const t = now.startOf('day');
|
|
162
|
+
return { start: t, end: t.endOf('day') };
|
|
163
|
+
}
|
|
164
|
+
if (key === 'w') {
|
|
165
|
+
const s = now.startOf('week').startOf('day');
|
|
166
|
+
const e = now.endOf('week').endOf('day');
|
|
167
|
+
return { start: s, end: e };
|
|
168
|
+
}
|
|
169
|
+
if (key === 'm') {
|
|
170
|
+
const s = now.startOf('month').startOf('day');
|
|
171
|
+
const e = now.endOf('month').endOf('day');
|
|
172
|
+
return { start: s, end: e };
|
|
173
|
+
}
|
|
174
|
+
if (key === 'y') {
|
|
175
|
+
const s = now.startOf('year').startOf('day');
|
|
176
|
+
const e = now.endOf('year').endOf('day');
|
|
177
|
+
return { start: s, end: e };
|
|
178
|
+
}
|
|
179
|
+
if (key === 'q') {
|
|
180
|
+
const s = getQuarterStart(now).startOf('day');
|
|
181
|
+
const e = s.add(3, 'month').subtract(1, 'second').endOf('day');
|
|
182
|
+
return { start: s, end: e };
|
|
183
|
+
}
|
|
184
|
+
const n = toIntOrNull(key);
|
|
185
|
+
if (n != null && n > 0) {
|
|
186
|
+
const e = now.endOf('day');
|
|
187
|
+
const s = now.subtract(n - 1, 'day').startOf('day');
|
|
188
|
+
return { start: s, end: e };
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
function getColumnsCount(type) {
|
|
193
|
+
if (type === 'year')
|
|
194
|
+
return 1;
|
|
195
|
+
if (type === 'month')
|
|
196
|
+
return 2;
|
|
197
|
+
if (type === 'day')
|
|
198
|
+
return 3;
|
|
199
|
+
if (type === 'hour')
|
|
200
|
+
return 4;
|
|
201
|
+
if (type === 'minute')
|
|
202
|
+
return 5;
|
|
203
|
+
return 6;
|
|
204
|
+
}
|
|
205
|
+
function ensureBoundsValid(bounds) {
|
|
206
|
+
if (bounds.min && bounds.max && bounds.min.isAfter(bounds.max)) {
|
|
207
|
+
throw new Error('[zkit-ui][BetweenTime] Invalid bounds: start is after end.');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// 缓存常用的选项数组,避免重复创建
|
|
211
|
+
const wheelOptionsCache = new Map();
|
|
212
|
+
function buildWheelOptions(min, max, pad2 = false) {
|
|
213
|
+
const cacheKey = `${min}-${max}-${pad2}`;
|
|
214
|
+
const cached = wheelOptionsCache.get(cacheKey);
|
|
215
|
+
if (cached)
|
|
216
|
+
return cached;
|
|
217
|
+
const out = [];
|
|
218
|
+
for (let v = min; v <= max; v += 1) {
|
|
219
|
+
out.push({ value: v, label: pad2 ? String(v).padStart(2, '0') : String(v) });
|
|
220
|
+
}
|
|
221
|
+
wheelOptionsCache.set(cacheKey, out);
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
function resolveWheelData(d, bounds, type) {
|
|
225
|
+
var _a, _b;
|
|
226
|
+
const count = getColumnsCount(type);
|
|
227
|
+
const min = bounds.min;
|
|
228
|
+
const max = bounds.max;
|
|
229
|
+
const minYear = (_a = min === null || min === void 0 ? void 0 : min.year()) !== null && _a !== void 0 ? _a : 1970;
|
|
230
|
+
const maxYear = (_b = max === null || max === void 0 ? void 0 : max.year()) !== null && _b !== void 0 ? _b : 2099;
|
|
231
|
+
const years = buildWheelOptions(minYear, maxYear);
|
|
232
|
+
const y = clampNumber(d.year(), minYear, maxYear);
|
|
233
|
+
const mMin = y === (min === null || min === void 0 ? void 0 : min.year()) ? (min.month() + 1) : 1;
|
|
234
|
+
const mMax = y === (max === null || max === void 0 ? void 0 : max.year()) ? (max.month() + 1) : 12;
|
|
235
|
+
const months = buildWheelOptions(mMin, mMax, true);
|
|
236
|
+
const month = clampNumber(d.month() + 1, mMin, mMax);
|
|
237
|
+
const base = (0, dayjs_1.default)(`${y}-${String(month).padStart(2, '0')}-01`);
|
|
238
|
+
const dim = base.daysInMonth();
|
|
239
|
+
const isMinYM = y === (min === null || min === void 0 ? void 0 : min.year()) && month === (min.month() + 1);
|
|
240
|
+
const isMaxYM = y === (max === null || max === void 0 ? void 0 : max.year()) && month === (max.month() + 1);
|
|
241
|
+
const dMin = isMinYM ? min.date() : 1;
|
|
242
|
+
const dMax = isMaxYM ? max.date() : dim;
|
|
243
|
+
const days = buildWheelOptions(dMin, dMax, true);
|
|
244
|
+
const day = clampNumber(d.date(), dMin, dMax);
|
|
245
|
+
const sameMinYMD = min != null && y === min.year() && month === (min.month() + 1) && day === min.date();
|
|
246
|
+
const sameMaxYMD = max != null && y === max.year() && month === (max.month() + 1) && day === max.date();
|
|
247
|
+
const hMin = sameMinYMD ? min.hour() : 0;
|
|
248
|
+
const hMax = sameMaxYMD ? max.hour() : 23;
|
|
249
|
+
const hours = buildWheelOptions(hMin, hMax, true);
|
|
250
|
+
const hour = clampNumber(d.hour(), hMin, hMax);
|
|
251
|
+
const sameMinYMDH = sameMinYMD && hour === (min === null || min === void 0 ? void 0 : min.hour());
|
|
252
|
+
const sameMaxYMDH = sameMaxYMD && hour === (max === null || max === void 0 ? void 0 : max.hour());
|
|
253
|
+
const minMin = sameMinYMDH ? min.minute() : 0;
|
|
254
|
+
const minMax = sameMaxYMDH ? max.minute() : 59;
|
|
255
|
+
const minutes = buildWheelOptions(minMin, minMax, true);
|
|
256
|
+
const minute = clampNumber(d.minute(), minMin, minMax);
|
|
257
|
+
const sameMinYMDHM = sameMinYMDH && minute === (min === null || min === void 0 ? void 0 : min.minute());
|
|
258
|
+
const sameMaxYMDHM = sameMaxYMDH && minute === (max === null || max === void 0 ? void 0 : max.minute());
|
|
259
|
+
const sMin = sameMinYMDHM ? min.second() : 0;
|
|
260
|
+
const sMax = sameMaxYMDHM ? max.second() : 59;
|
|
261
|
+
const seconds = buildWheelOptions(sMin, sMax, true);
|
|
262
|
+
const all = [years, months, days, hours, minutes, seconds].slice(0, count);
|
|
263
|
+
const indices = [
|
|
264
|
+
years.findIndex((it) => it.value === y),
|
|
265
|
+
months.findIndex((it) => it.value === month),
|
|
266
|
+
days.findIndex((it) => it.value === day),
|
|
267
|
+
hours.findIndex((it) => it.value === hour),
|
|
268
|
+
minutes.findIndex((it) => it.value === minute),
|
|
269
|
+
seconds.findIndex((it) => it.value === clampNumber(d.second(), sMin, sMax)),
|
|
270
|
+
].slice(0, count);
|
|
271
|
+
return { columns: all, indices };
|
|
272
|
+
}
|
|
273
|
+
function applyColumnValue(d, columnIndex, value) {
|
|
274
|
+
if (columnIndex === 0)
|
|
275
|
+
return d.year(value);
|
|
276
|
+
if (columnIndex === 1)
|
|
277
|
+
return d.month(value - 1);
|
|
278
|
+
if (columnIndex === 2)
|
|
279
|
+
return d.date(value);
|
|
280
|
+
if (columnIndex === 3)
|
|
281
|
+
return d.hour(value);
|
|
282
|
+
if (columnIndex === 4)
|
|
283
|
+
return d.minute(value);
|
|
284
|
+
return d.second(value);
|
|
285
|
+
}
|
|
286
|
+
function composeTrigger(children, onPress, disabled) {
|
|
287
|
+
var _a, _b, _c;
|
|
288
|
+
if (React.isValidElement(children)) {
|
|
289
|
+
const anyChild = children;
|
|
290
|
+
const prevOnPress = (_a = anyChild === null || anyChild === void 0 ? void 0 : anyChild.props) === null || _a === void 0 ? void 0 : _a.onPress;
|
|
291
|
+
if (typeof prevOnPress === 'function') {
|
|
292
|
+
return React.cloneElement(children, {
|
|
293
|
+
onPress: (...args) => {
|
|
294
|
+
prevOnPress(...args);
|
|
295
|
+
onPress();
|
|
296
|
+
},
|
|
297
|
+
disabled: disabled || ((_b = anyChild === null || anyChild === void 0 ? void 0 : anyChild.props) === null || _b === void 0 ? void 0 : _b.disabled),
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
return React.cloneElement(children, {
|
|
301
|
+
onPress,
|
|
302
|
+
disabled: disabled || ((_c = anyChild === null || anyChild === void 0 ? void 0 : anyChild.props) === null || _c === void 0 ? void 0 : _c.disabled),
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: onPress, disabled: disabled, children: children }));
|
|
306
|
+
}
|
|
307
|
+
exports.BetweenTime = React.forwardRef(function BetweenTime({ title, start, end, type = 'day', format = 'YYYY-MM-DD', formatSyncValue = false, cellUnits, quickDate, lazyContent = true, drawerSize, disabled = false, value: valueProp, defaultValue, onValueChange, open: openProp, defaultOpen = false, onOpenChange, onDismissComplete, onCancel, onConfirm, children, }, ref) {
|
|
308
|
+
const { t } = (0, useI18n_1.useI18n)();
|
|
309
|
+
const theme = (0, useTheme_1.useTheme)();
|
|
310
|
+
const { height: screenH, width: screenW } = (0, react_native_1.useWindowDimensions)();
|
|
311
|
+
const insets = (0, react_native_safe_area_context_1.useSafeAreaInsets)();
|
|
312
|
+
const safeBottom = (0, actionBar_1.getPickerActionBarBottomInset)(insets.bottom);
|
|
313
|
+
const bounds = React.useMemo(() => {
|
|
314
|
+
const min = parseStandardDateStrict(start);
|
|
315
|
+
const max = parseStandardDateStrict(end);
|
|
316
|
+
const b = { min, max };
|
|
317
|
+
ensureBoundsValid(b);
|
|
318
|
+
return b;
|
|
319
|
+
}, [start, end]);
|
|
320
|
+
const [innerValue, setInnerValue] = React.useState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : []);
|
|
321
|
+
const isValueControlled = valueProp !== undefined;
|
|
322
|
+
const value = isValueControlled ? valueProp : innerValue;
|
|
323
|
+
const [innerOpen, setInnerOpen] = React.useState(defaultOpen);
|
|
324
|
+
const isOpenControlled = openProp !== undefined;
|
|
325
|
+
const visible = isOpenControlled ? !!openProp : innerOpen;
|
|
326
|
+
const [contentMounted, setContentMounted] = React.useState(!lazyContent);
|
|
327
|
+
const detents = React.useMemo(() => {
|
|
328
|
+
if (drawerSize == null)
|
|
329
|
+
return ['auto'];
|
|
330
|
+
const n = typeof drawerSize === 'number' ? drawerSize : Number.parseFloat(drawerSize);
|
|
331
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
332
|
+
return ['auto'];
|
|
333
|
+
const fraction = clampNumber(n / screenH, 0.1, 0.92);
|
|
334
|
+
return [fraction];
|
|
335
|
+
}, [drawerSize, screenH]);
|
|
336
|
+
const [activeSide, setActiveSide] = React.useState('start');
|
|
337
|
+
const [{ draftStart, draftEnd }, setDraft] = React.useState(() => {
|
|
338
|
+
const pair = resolveInitialPair(value, bounds, type);
|
|
339
|
+
return { draftStart: pair.start, draftEnd: pair.end };
|
|
340
|
+
});
|
|
341
|
+
React.useEffect(() => {
|
|
342
|
+
const pair = resolveInitialPair(value, bounds, type);
|
|
343
|
+
setDraft({ draftStart: pair.start, draftEnd: pair.end });
|
|
344
|
+
}, [bounds, type, value === null || value === void 0 ? void 0 : value[0], value === null || value === void 0 ? void 0 : value[1]]);
|
|
345
|
+
React.useEffect(() => {
|
|
346
|
+
if (visible) {
|
|
347
|
+
const pair = resolveInitialPair(value, bounds, type);
|
|
348
|
+
setDraft({ draftStart: pair.start, draftEnd: pair.end });
|
|
349
|
+
if (lazyContent && !contentMounted)
|
|
350
|
+
setContentMounted(true);
|
|
351
|
+
}
|
|
352
|
+
// 只希望在进入打开态时重置草稿,不跟随其他依赖重复触发。
|
|
353
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
354
|
+
}, [visible]);
|
|
355
|
+
const defaultCellUnits = React.useMemo(() => [
|
|
356
|
+
t('betweenTime.unit.year'),
|
|
357
|
+
t('betweenTime.unit.month'),
|
|
358
|
+
t('betweenTime.unit.day'),
|
|
359
|
+
t('betweenTime.unit.hour'),
|
|
360
|
+
t('betweenTime.unit.minute'),
|
|
361
|
+
t('betweenTime.unit.second'),
|
|
362
|
+
], [t]);
|
|
363
|
+
const getQuickLabel = React.useCallback((key) => {
|
|
364
|
+
if (key === 'd')
|
|
365
|
+
return t('betweenTime.quick.today');
|
|
366
|
+
if (key === 'w')
|
|
367
|
+
return t('betweenTime.quick.thisWeek');
|
|
368
|
+
if (key === 'm')
|
|
369
|
+
return t('betweenTime.quick.thisMonth');
|
|
370
|
+
if (key === 'y')
|
|
371
|
+
return t('betweenTime.quick.thisYear');
|
|
372
|
+
if (key === 'q')
|
|
373
|
+
return t('betweenTime.quick.thisQuarter');
|
|
374
|
+
const n = toIntOrNull(key);
|
|
375
|
+
if (n != null && n > 0)
|
|
376
|
+
return t('betweenTime.quick.recentDays', { n });
|
|
377
|
+
return key;
|
|
378
|
+
}, [t]);
|
|
379
|
+
const setPickerOpen = React.useCallback((nextOpen) => {
|
|
380
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(nextOpen);
|
|
381
|
+
if (!isOpenControlled)
|
|
382
|
+
setInnerOpen(nextOpen);
|
|
383
|
+
}, [isOpenControlled, onOpenChange]);
|
|
384
|
+
const close = React.useCallback(() => {
|
|
385
|
+
setPickerOpen(false);
|
|
386
|
+
}, [setPickerOpen]);
|
|
387
|
+
const openPicker = React.useCallback(() => {
|
|
388
|
+
if (disabled)
|
|
389
|
+
return;
|
|
390
|
+
if (!visible) {
|
|
391
|
+
setPickerOpen(true);
|
|
392
|
+
}
|
|
393
|
+
const pair = resolveInitialPair(value, bounds, type);
|
|
394
|
+
setDraft({ draftStart: pair.start, draftEnd: pair.end });
|
|
395
|
+
if (lazyContent && !contentMounted) {
|
|
396
|
+
setContentMounted(true);
|
|
397
|
+
}
|
|
398
|
+
}, [bounds, contentMounted, disabled, lazyContent, setPickerOpen, type, value, visible]);
|
|
399
|
+
React.useImperativeHandle(ref, () => ({
|
|
400
|
+
open: openPicker,
|
|
401
|
+
close,
|
|
402
|
+
}), [openPicker, close]);
|
|
403
|
+
const columnsCount = React.useMemo(() => getColumnsCount(type), [type]);
|
|
404
|
+
const wheelsRef = React.useRef([]);
|
|
405
|
+
React.useEffect(() => {
|
|
406
|
+
wheelsRef.current.length = columnsCount;
|
|
407
|
+
}, [columnsCount]);
|
|
408
|
+
const resolvedCellUnits = cellUnits !== null && cellUnits !== void 0 ? cellUnits : defaultCellUnits;
|
|
409
|
+
const unitLabels = React.useMemo(() => resolvedCellUnits.slice(0, columnsCount), [resolvedCellUnits, columnsCount]);
|
|
410
|
+
const activeDraft = activeSide === 'start' ? draftStart : draftEnd;
|
|
411
|
+
const { columns, indices } = React.useMemo(() => resolveWheelData(activeDraft, bounds, type), [activeDraft, bounds, type]);
|
|
412
|
+
const columnsLayoutRef = React.useRef({ width: screenW - (0, zkit_tools_1.wp)(32) });
|
|
413
|
+
const onColumnsLayout = React.useCallback((e) => {
|
|
414
|
+
columnsLayoutRef.current = { width: e.nativeEvent.layout.width };
|
|
415
|
+
}, []);
|
|
416
|
+
const columnWidth = React.useMemo(() => {
|
|
417
|
+
const w = columnsLayoutRef.current.width;
|
|
418
|
+
return w / Math.max(1, columnsCount);
|
|
419
|
+
}, [columnsCount, screenW]);
|
|
420
|
+
const setValue = React.useCallback((next) => {
|
|
421
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(next);
|
|
422
|
+
if (!isValueControlled)
|
|
423
|
+
setInnerValue(next);
|
|
424
|
+
}, [isValueControlled, onValueChange]);
|
|
425
|
+
const applyPairAndEmit = React.useCallback((nextStart, nextEnd) => {
|
|
426
|
+
const s = normalizeDraftByType(clampToBounds(nextStart, bounds), type);
|
|
427
|
+
const e = normalizeDraftByType(clampToBounds(nextEnd, bounds), type);
|
|
428
|
+
let a = s;
|
|
429
|
+
let b = e;
|
|
430
|
+
let nextActive = activeSide;
|
|
431
|
+
if (a.isAfter(b)) {
|
|
432
|
+
const tmp = a;
|
|
433
|
+
a = b;
|
|
434
|
+
b = tmp;
|
|
435
|
+
nextActive = activeSide === 'start' ? 'end' : 'start';
|
|
436
|
+
}
|
|
437
|
+
setDraft({ draftStart: a, draftEnd: b });
|
|
438
|
+
if (nextActive !== activeSide)
|
|
439
|
+
setActiveSide(nextActive);
|
|
440
|
+
const rawStart = formatByType(a, type);
|
|
441
|
+
const rawEnd = formatByType(b, type);
|
|
442
|
+
let outStart = rawStart;
|
|
443
|
+
let outEnd = rawEnd;
|
|
444
|
+
if (formatSyncValue) {
|
|
445
|
+
outStart = a.format(format);
|
|
446
|
+
outEnd = b.format(format);
|
|
447
|
+
ensureFormatSyncValueIsStandard(outStart);
|
|
448
|
+
ensureFormatSyncValueIsStandard(outEnd);
|
|
449
|
+
}
|
|
450
|
+
const nextValue = outStart && outEnd ? [outStart, outEnd] : [];
|
|
451
|
+
setValue(nextValue);
|
|
452
|
+
}, [activeSide, bounds, format, formatSyncValue, setValue, type]);
|
|
453
|
+
// iOS 原生 wheel 在减速尚未结束时,业务层未必已经拿到最新列值。
|
|
454
|
+
// 确认按钮这里会主动向每一列请求一次“以当前中心项为准”的即时结算,
|
|
455
|
+
// 然后再统一重建 start / end,避免出现“明明已经滚到新值,但确认后还是旧值”的错位。
|
|
456
|
+
const syncDraftFromWheels = React.useCallback(async () => {
|
|
457
|
+
var _a, _b;
|
|
458
|
+
let nextDraft = activeDraft;
|
|
459
|
+
for (let columnIndex = 0; columnIndex < columnsCount; columnIndex += 1) {
|
|
460
|
+
const opts = (_a = columns[columnIndex]) !== null && _a !== void 0 ? _a : [];
|
|
461
|
+
if (!opts.length)
|
|
462
|
+
break;
|
|
463
|
+
const wheel = wheelsRef.current[columnIndex];
|
|
464
|
+
const settledIndex = react_native_1.Platform.OS === 'ios'
|
|
465
|
+
? await (wheel === null || wheel === void 0 ? void 0 : wheel.syncCurrentSelection())
|
|
466
|
+
: wheel === null || wheel === void 0 ? void 0 : wheel.settleToNearest(false);
|
|
467
|
+
const safeIndex = clampNumber((_b = settledIndex !== null && settledIndex !== void 0 ? settledIndex : indices[columnIndex]) !== null && _b !== void 0 ? _b : 0, 0, opts.length - 1);
|
|
468
|
+
const picked = opts[safeIndex];
|
|
469
|
+
if (!picked)
|
|
470
|
+
continue;
|
|
471
|
+
nextDraft = applyColumnValue(nextDraft, columnIndex, picked.value);
|
|
472
|
+
}
|
|
473
|
+
nextDraft = normalizeDraftByType(clampToBounds(nextDraft, bounds), type);
|
|
474
|
+
const startCandidate = activeSide === 'start' ? nextDraft : draftStart;
|
|
475
|
+
const endCandidate = activeSide === 'start' ? draftEnd : nextDraft;
|
|
476
|
+
const nextStart = normalizeDraftByType(clampToBounds(startCandidate, bounds), type);
|
|
477
|
+
const nextEnd = normalizeDraftByType(clampToBounds(endCandidate, bounds), type);
|
|
478
|
+
const nextPair = nextStart.isAfter(nextEnd)
|
|
479
|
+
? { start: nextEnd, end: nextStart }
|
|
480
|
+
: { start: nextStart, end: nextEnd };
|
|
481
|
+
applyPairAndEmit(nextPair.start, nextPair.end);
|
|
482
|
+
return nextPair;
|
|
483
|
+
}, [activeDraft, activeSide, applyPairAndEmit, bounds, columns, columnsCount, draftEnd, draftStart, indices, type]);
|
|
484
|
+
const handleWheelIndexChange = React.useCallback((columnIndex, nextIndex) => {
|
|
485
|
+
const opts = columns[columnIndex];
|
|
486
|
+
const picked = opts === null || opts === void 0 ? void 0 : opts[nextIndex];
|
|
487
|
+
if (!picked)
|
|
488
|
+
return;
|
|
489
|
+
const valueNum = picked.value;
|
|
490
|
+
let nextDraft = applyColumnValue(activeDraft, columnIndex, valueNum);
|
|
491
|
+
nextDraft = clampToBounds(nextDraft, bounds);
|
|
492
|
+
nextDraft = normalizeDraftByType(nextDraft, type);
|
|
493
|
+
if (activeSide === 'start')
|
|
494
|
+
applyPairAndEmit(nextDraft, draftEnd);
|
|
495
|
+
else
|
|
496
|
+
applyPairAndEmit(draftStart, nextDraft);
|
|
497
|
+
}, [activeDraft, activeSide, applyPairAndEmit, bounds, columns, draftEnd, draftStart, type]);
|
|
498
|
+
const handleClear = React.useCallback(() => {
|
|
499
|
+
setValue([]);
|
|
500
|
+
}, [setValue]);
|
|
501
|
+
const handleCancel = React.useCallback(() => {
|
|
502
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
503
|
+
const pair = resolveInitialPair(value, bounds, type);
|
|
504
|
+
setDraft({ draftStart: pair.start, draftEnd: pair.end });
|
|
505
|
+
close();
|
|
506
|
+
}, [bounds, close, onCancel, type, value]);
|
|
507
|
+
const handleConfirm = React.useCallback(async () => {
|
|
508
|
+
const synced = await syncDraftFromWheels();
|
|
509
|
+
const next = [synced.start, synced.end];
|
|
510
|
+
const rawStart = formatByType(next[0], type);
|
|
511
|
+
const rawEnd = formatByType(next[1], type);
|
|
512
|
+
let outStart = rawStart;
|
|
513
|
+
let outEnd = rawEnd;
|
|
514
|
+
if (formatSyncValue) {
|
|
515
|
+
outStart = next[0].format(format);
|
|
516
|
+
outEnd = next[1].format(format);
|
|
517
|
+
ensureFormatSyncValueIsStandard(outStart);
|
|
518
|
+
ensureFormatSyncValueIsStandard(outEnd);
|
|
519
|
+
}
|
|
520
|
+
const nextValue = outStart && outEnd ? [outStart, outEnd] : [];
|
|
521
|
+
setValue(nextValue);
|
|
522
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm({ value: nextValue });
|
|
523
|
+
close();
|
|
524
|
+
}, [close, format, formatSyncValue, onConfirm, setValue, syncDraftFromWheels, type]);
|
|
525
|
+
const handleQuickPick = React.useCallback((key) => {
|
|
526
|
+
const range = getQuickRange(key, (0, dayjs_1.default)());
|
|
527
|
+
if (!range)
|
|
528
|
+
return;
|
|
529
|
+
applyPairAndEmit(range.start, range.end);
|
|
530
|
+
}, [applyPairAndEmit]);
|
|
531
|
+
const triggerNode = React.useMemo(() => children != null ? composeTrigger(children, openPicker, disabled) : null, [children, disabled, openPicker]);
|
|
532
|
+
const handleSheetOpenChange = React.useCallback((nextOpen, meta) => {
|
|
533
|
+
if (!nextOpen && visible && meta.reason !== 'api') {
|
|
534
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
535
|
+
const pair = resolveInitialPair(value, bounds, type);
|
|
536
|
+
setDraft({ draftStart: pair.start, draftEnd: pair.end });
|
|
537
|
+
}
|
|
538
|
+
setPickerOpen(nextOpen);
|
|
539
|
+
}, [bounds, onCancel, setPickerOpen, type, value, visible]);
|
|
540
|
+
const handleSheetDismissComplete = React.useCallback(() => {
|
|
541
|
+
if (lazyContent)
|
|
542
|
+
setContentMounted(false);
|
|
543
|
+
onDismissComplete === null || onDismissComplete === void 0 ? void 0 : onDismissComplete();
|
|
544
|
+
}, [lazyContent, onDismissComplete]);
|
|
545
|
+
const sheetNode = ((0, jsx_runtime_1.jsx)(Sheet_1.Sheet, { placement: "bottom", open: visible, onOpenChange: handleSheetOpenChange, onCloseComplete: handleSheetDismissComplete, detents: detents, backgroundColor: theme.colors.surface, handle: false, draggable: false, dismissible: !disabled, nativeProps: { insetAdjustment: 'never' }, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [
|
|
546
|
+
styles.sheetInner,
|
|
547
|
+
{
|
|
548
|
+
backgroundColor: theme.colors.surface,
|
|
549
|
+
paddingBottom: safeBottom,
|
|
550
|
+
},
|
|
551
|
+
], pointerEvents: disabled ? 'none' : 'auto', children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.header, children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { style: [styles.headerTitle, { color: theme.colors.onSurface }], numberOfLines: 1, children: title !== null && title !== void 0 ? title : t('betweenTime.title') }), (0, jsx_runtime_1.jsx)(Button_1.Button, { variant: "ghost", onPress: handleClear, disabled: disabled, colors: { text: theme.colors.muted }, layout: { minHeight: (0, zkit_tools_1.wp)(32), paddingHorizontal: (0, zkit_tools_1.wp)(8), textSize: (0, zkit_tools_1.sp)(14) }, children: t('betweenTime.clear') })] }), Array.isArray(quickDate) && quickDate.length > 0 ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.quickRow, children: quickDate.map((k) => ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: () => handleQuickPick(k), style: ({ pressed }) => [
|
|
552
|
+
styles.quickPill,
|
|
553
|
+
{
|
|
554
|
+
borderColor: `${theme.colors.primary}22`,
|
|
555
|
+
backgroundColor: `${theme.colors.primary}14`,
|
|
556
|
+
},
|
|
557
|
+
pressed && { opacity: 0.8 },
|
|
558
|
+
], disabled: disabled, children: (0, jsx_runtime_1.jsx)(Text_1.Text, { style: [styles.quickText, { color: theme.colors.primary }], children: getQuickLabel(k) }) }, k))) })) : null, (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.rangeRow, children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: () => setActiveSide('start'), style: ({ pressed }) => [
|
|
559
|
+
styles.rangePill,
|
|
560
|
+
activeSide === 'start'
|
|
561
|
+
? { borderColor: theme.colors.primary, backgroundColor: '#FFFFFF' }
|
|
562
|
+
: { borderColor: theme.colors.border, backgroundColor: '#FFFFFF' },
|
|
563
|
+
pressed && { opacity: 0.85 },
|
|
564
|
+
], children: (0, jsx_runtime_1.jsx)(Text_1.Text, { style: [
|
|
565
|
+
styles.rangeText,
|
|
566
|
+
{ color: activeSide === 'start' ? theme.colors.primary : theme.colors.muted },
|
|
567
|
+
], numberOfLines: 1, children: draftStart ? draftStart.format(format) : t('betweenTime.startTime') }) }), (0, jsx_runtime_1.jsx)(Text_1.Text, { style: [styles.toText, { color: theme.colors.muted }], children: t('betweenTime.to') }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: () => setActiveSide('end'), style: ({ pressed }) => [
|
|
568
|
+
styles.rangePill,
|
|
569
|
+
activeSide === 'end'
|
|
570
|
+
? { borderColor: theme.colors.primary, backgroundColor: '#FFFFFF' }
|
|
571
|
+
: { borderColor: theme.colors.border, backgroundColor: '#FFFFFF' },
|
|
572
|
+
pressed && { opacity: 0.85 },
|
|
573
|
+
], children: (0, jsx_runtime_1.jsx)(Text_1.Text, { style: [
|
|
574
|
+
styles.rangeText,
|
|
575
|
+
{ color: activeSide === 'end' ? theme.colors.primary : theme.colors.muted },
|
|
576
|
+
], numberOfLines: 1, children: draftEnd ? draftEnd.format(format) : t('betweenTime.endTime') }) })] }), contentMounted ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.pickerArea, children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.unitRow, children: unitLabels.map((u, idx) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.unitCell, { width: columnWidth }], children: (0, jsx_runtime_1.jsx)(Text_1.Text, { style: [styles.unitText, { color: theme.colors.muted }], children: u }) }, `${u}-${idx}`))) }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.pickerWrapper, onLayout: onColumnsLayout, children: [react_native_1.Platform.OS !== 'ios' && ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.highlightBar, pointerEvents: "none" })), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.columnsRow, children: columns.map((col, colIdx) => {
|
|
577
|
+
var _a, _b, _c;
|
|
578
|
+
return ((0, jsx_runtime_1.jsx)(WheelColumn_1.WheelColumn, { ref: (instance) => {
|
|
579
|
+
wheelsRef.current[colIdx] = instance;
|
|
580
|
+
}, options: col, value: (_c = (_b = col[Math.max(0, (_a = indices[colIdx]) !== null && _a !== void 0 ? _a : 0)]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : null, onChange: (payload) => handleWheelIndexChange(colIdx, payload.index), width: columnWidth, disabled: disabled }, `col-${colIdx}-${columnsCount}`));
|
|
581
|
+
}) }), react_native_1.Platform.OS !== 'ios' && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.topMask, pointerEvents: "none", children: (0, jsx_runtime_1.jsx)(expo_linear_gradient_1.LinearGradient, { colors: ['#FFFFFF', 'rgba(255,255,255,0)'], style: react_native_1.StyleSheet.absoluteFill }) }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.bottomMask, pointerEvents: "none", children: (0, jsx_runtime_1.jsx)(expo_linear_gradient_1.LinearGradient, { colors: ['rgba(255,255,255,0)', '#FFFFFF'], style: react_native_1.StyleSheet.absoluteFill }) })] }))] })] })) : ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.pickerArea, { height: WheelColumn_1.WHEEL_AREA_HEIGHT + (0, zkit_tools_1.wp)(26) }] })), (0, jsx_runtime_1.jsx)(actionBar_1.PickerActionBar, { cancelText: t('betweenTime.cancel'), confirmText: t('betweenTime.confirm'), onCancel: handleCancel, onConfirm: handleConfirm, disabled: disabled, style: styles.footer })] }) }));
|
|
582
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [triggerNode, sheetNode] }));
|
|
583
|
+
});
|
|
584
|
+
const styles = react_native_1.StyleSheet.create({
|
|
585
|
+
sheetInner: {
|
|
586
|
+
width: '100%',
|
|
587
|
+
paddingHorizontal: (0, zkit_tools_1.wp)(16),
|
|
588
|
+
paddingTop: (0, zkit_tools_1.wp)(14),
|
|
589
|
+
},
|
|
590
|
+
header: {
|
|
591
|
+
height: (0, zkit_tools_1.wp)(44),
|
|
592
|
+
flexDirection: 'row',
|
|
593
|
+
alignItems: 'center',
|
|
594
|
+
justifyContent: 'space-between',
|
|
595
|
+
},
|
|
596
|
+
headerTitle: {
|
|
597
|
+
fontSize: (0, zkit_tools_1.sp)(16),
|
|
598
|
+
fontWeight: '600',
|
|
599
|
+
},
|
|
600
|
+
quickRow: {
|
|
601
|
+
flexDirection: 'row',
|
|
602
|
+
flexWrap: 'wrap',
|
|
603
|
+
gap: (0, zkit_tools_1.wp)(10),
|
|
604
|
+
paddingTop: (0, zkit_tools_1.wp)(8),
|
|
605
|
+
paddingBottom: (0, zkit_tools_1.wp)(12),
|
|
606
|
+
},
|
|
607
|
+
quickPill: {
|
|
608
|
+
height: (0, zkit_tools_1.wp)(28),
|
|
609
|
+
paddingHorizontal: (0, zkit_tools_1.wp)(12),
|
|
610
|
+
borderRadius: (0, zkit_tools_1.wp)(14),
|
|
611
|
+
borderWidth: react_native_1.StyleSheet.hairlineWidth,
|
|
612
|
+
alignItems: 'center',
|
|
613
|
+
justifyContent: 'center',
|
|
614
|
+
},
|
|
615
|
+
quickText: {
|
|
616
|
+
fontSize: (0, zkit_tools_1.sp)(12),
|
|
617
|
+
fontWeight: '600',
|
|
618
|
+
},
|
|
619
|
+
rangeRow: {
|
|
620
|
+
flexDirection: 'row',
|
|
621
|
+
alignItems: 'center',
|
|
622
|
+
justifyContent: 'space-between',
|
|
623
|
+
paddingTop: (0, zkit_tools_1.wp)(4),
|
|
624
|
+
paddingBottom: (0, zkit_tools_1.wp)(10),
|
|
625
|
+
},
|
|
626
|
+
rangePill: {
|
|
627
|
+
flex: 1,
|
|
628
|
+
height: (0, zkit_tools_1.wp)(40),
|
|
629
|
+
borderRadius: (0, zkit_tools_1.wp)(20),
|
|
630
|
+
borderWidth: (0, zkit_tools_1.wp)(1.5),
|
|
631
|
+
alignItems: 'center',
|
|
632
|
+
justifyContent: 'center',
|
|
633
|
+
paddingHorizontal: (0, zkit_tools_1.wp)(12),
|
|
634
|
+
},
|
|
635
|
+
rangeText: {
|
|
636
|
+
fontSize: (0, zkit_tools_1.sp)(14),
|
|
637
|
+
fontWeight: '600',
|
|
638
|
+
},
|
|
639
|
+
toText: {
|
|
640
|
+
width: (0, zkit_tools_1.wp)(28),
|
|
641
|
+
textAlign: 'center',
|
|
642
|
+
fontSize: (0, zkit_tools_1.sp)(13),
|
|
643
|
+
fontWeight: '600',
|
|
644
|
+
},
|
|
645
|
+
pickerArea: {
|
|
646
|
+
paddingTop: (0, zkit_tools_1.wp)(4),
|
|
647
|
+
paddingBottom: WheelColumn_1.WHEEL_AREA_VERTICAL_INSET * 2,
|
|
648
|
+
},
|
|
649
|
+
unitRow: {
|
|
650
|
+
flexDirection: 'row',
|
|
651
|
+
justifyContent: 'space-between',
|
|
652
|
+
paddingBottom: (0, zkit_tools_1.wp)(6),
|
|
653
|
+
},
|
|
654
|
+
unitCell: {
|
|
655
|
+
alignItems: 'center',
|
|
656
|
+
justifyContent: 'center',
|
|
657
|
+
},
|
|
658
|
+
unitText: {
|
|
659
|
+
fontSize: (0, zkit_tools_1.sp)(12),
|
|
660
|
+
fontWeight: '600',
|
|
661
|
+
},
|
|
662
|
+
pickerWrapper: {
|
|
663
|
+
height: ITEM_HEIGHT * VISIBLE_ITEMS,
|
|
664
|
+
position: 'relative',
|
|
665
|
+
width: '100%',
|
|
666
|
+
overflow: 'visible',
|
|
667
|
+
},
|
|
668
|
+
highlightBar: {
|
|
669
|
+
position: 'absolute',
|
|
670
|
+
top: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
|
|
671
|
+
left: -(0, zkit_tools_1.wp)(16),
|
|
672
|
+
right: -(0, zkit_tools_1.wp)(16),
|
|
673
|
+
height: ITEM_HEIGHT,
|
|
674
|
+
backgroundColor: WheelColumn_1.WHEEL_SELECTION_BACKGROUND_COLOR,
|
|
675
|
+
zIndex: 0,
|
|
676
|
+
},
|
|
677
|
+
topMask: {
|
|
678
|
+
position: 'absolute',
|
|
679
|
+
top: 0,
|
|
680
|
+
left: 0,
|
|
681
|
+
right: 0,
|
|
682
|
+
height: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
|
|
683
|
+
zIndex: 2,
|
|
684
|
+
},
|
|
685
|
+
bottomMask: {
|
|
686
|
+
position: 'absolute',
|
|
687
|
+
bottom: 0,
|
|
688
|
+
left: 0,
|
|
689
|
+
right: 0,
|
|
690
|
+
height: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
|
|
691
|
+
zIndex: 2,
|
|
692
|
+
},
|
|
693
|
+
columnsRow: {
|
|
694
|
+
flexDirection: 'row',
|
|
695
|
+
alignItems: 'stretch',
|
|
696
|
+
justifyContent: 'space-between',
|
|
697
|
+
zIndex: 1,
|
|
698
|
+
},
|
|
699
|
+
footer: {
|
|
700
|
+
paddingTop: (0, zkit_tools_1.wp)(12),
|
|
701
|
+
},
|
|
702
|
+
});
|