@octane-xplat/date-picker 0.19.0 → 0.20.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 +2 -181
- package/package.json +8 -8
- package/src/AppKitDatePicker.macos.tsrx +39 -36
- package/src/AppKitDatePicker.tsrx +2 -0
- package/src/MaterialDatePicker.android.tsrx +43 -42
- package/src/MaterialDatePicker.tsrx +2 -0
- package/src/SwiftUIDatePicker.ios.tsrx +47 -45
- package/src/SwiftUIDatePicker.tsrx +2 -0
- package/src/android/index.ts +4 -4
- package/src/android/types.ts +111 -111
- package/src/date-picker-owner.macos.ts +240 -210
- package/src/ios/index.ts +3 -3
- package/src/ios/types.ts +26 -26
- package/src/macos/index.ts +3 -3
- package/src/macos/types.ts +24 -24
- package/src/style-merge.ts +40 -37
|
@@ -1,234 +1,264 @@
|
|
|
1
1
|
import type { AppKitDatePickerProps } from './macos/types'
|
|
2
2
|
|
|
3
3
|
export interface DatePickerOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
mode: NonNullable<AppKitDatePickerProps['components']>
|
|
5
|
+
style: NonNullable<AppKitDatePickerProps['pickerStyle']>
|
|
6
|
+
selectionMillis: number
|
|
7
|
+
minimumMillis?: number
|
|
8
|
+
maximumMillis?: number
|
|
9
|
+
enabled: boolean
|
|
10
|
+
accessibilityLabel?: string
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface DatePickerHandle {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
update(options: DatePickerOptions): void
|
|
15
|
+
detach(): void
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export type DatePickerAttach = (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
view: object,
|
|
20
|
+
options: DatePickerOptions,
|
|
21
|
+
onChange: (millis: number) => void,
|
|
22
22
|
) => DatePickerHandle | null
|
|
23
23
|
|
|
24
24
|
export type DatePickerStatus = 'ready' | 'invalid' | 'unavailable'
|
|
25
25
|
|
|
26
26
|
function milliseconds(date: Date | undefined): number | undefined {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
try {
|
|
28
|
+
return date === undefined ? undefined : date.getTime()
|
|
29
|
+
} catch {
|
|
30
|
+
return NaN
|
|
31
|
+
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const valid = (value: number) =>
|
|
35
|
-
|
|
35
|
+
Number.isFinite(value) && Number.isFinite(new Date(value).getTime())
|
|
36
36
|
|
|
37
37
|
/** Own one mounted attachment. Default selection seeds once; mode/view changes
|
|
38
38
|
* retain the accepted selection. This model does not prove native editing. */
|
|
39
39
|
export function createDatePickerOwner(deps: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
props(): AppKitDatePickerProps
|
|
41
|
+
attach(): DatePickerAttach | undefined
|
|
42
|
+
status?(status: DatePickerStatus): void
|
|
43
|
+
now?(): number
|
|
44
44
|
}): {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
update: () => void
|
|
46
|
+
bind(next: object | null): void
|
|
47
|
+
dispose(): void
|
|
48
|
+
getStatus: () => DatePickerStatus
|
|
49
49
|
} {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
50
|
+
let view: object | null = null,
|
|
51
|
+
disposed = false,
|
|
52
|
+
retained: number | undefined
|
|
53
|
+
|
|
54
|
+
let status: DatePickerStatus = 'unavailable'
|
|
55
|
+
type Session = {
|
|
56
|
+
view: object
|
|
57
|
+
mode: string
|
|
58
|
+
style: string
|
|
59
|
+
writing: number
|
|
60
|
+
handle: DatePickerHandle | null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let session: Session | null = null
|
|
64
|
+
const report = (next: DatePickerStatus) => {
|
|
65
|
+
if (!disposed && next !== status) {
|
|
66
|
+
status = next
|
|
67
|
+
deps.status?.(next)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const detach = () => {
|
|
72
|
+
const old = session
|
|
73
|
+
|
|
74
|
+
session = null
|
|
75
|
+
try {
|
|
76
|
+
old?.handle?.detach()
|
|
77
|
+
} catch {}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const plan = (): DatePickerOptions | null => {
|
|
81
|
+
const props = deps.props(),
|
|
82
|
+
min = milliseconds(props.minimumDate),
|
|
83
|
+
max = milliseconds(props.maximumDate)
|
|
84
|
+
|
|
85
|
+
if (
|
|
86
|
+
(min !== undefined && !valid(min)) ||
|
|
87
|
+
(max !== undefined && !valid(max)) ||
|
|
88
|
+
(min !== undefined && max !== undefined && min > max)
|
|
89
|
+
) {
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const controlled = props.selection !== undefined
|
|
94
|
+
let selected = controlled
|
|
95
|
+
? milliseconds(props.selection)!
|
|
96
|
+
: (retained ?? milliseconds(props.defaultSelection) ?? (deps.now ?? Date.now)())
|
|
97
|
+
|
|
98
|
+
if (!valid(selected)) {
|
|
99
|
+
return null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (
|
|
103
|
+
controlled &&
|
|
104
|
+
((min !== undefined && selected < min) || (max !== undefined && selected > max))
|
|
105
|
+
) {
|
|
106
|
+
return null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!controlled) {
|
|
110
|
+
selected = Math.min(max ?? Infinity, Math.max(min ?? -Infinity, selected))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const mode = props.components ?? 'date'
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
mode,
|
|
117
|
+
style: mode === 'date' ? (props.pickerStyle ?? 'textField') : 'textField',
|
|
118
|
+
selectionMillis: selected,
|
|
119
|
+
minimumMillis: min,
|
|
120
|
+
maximumMillis: max,
|
|
121
|
+
enabled: !props.disabled,
|
|
122
|
+
accessibilityLabel: props.accessibilityLabel,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const update = () => {
|
|
127
|
+
if (disposed || !view) {
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const options = plan()
|
|
132
|
+
|
|
133
|
+
if (!options) {
|
|
134
|
+
detach()
|
|
135
|
+
report('invalid')
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
retained = options.selectionMillis
|
|
140
|
+
if (
|
|
141
|
+
session &&
|
|
142
|
+
(session.view !== view || session.mode !== options.mode || session.style !== options.style)
|
|
143
|
+
) {
|
|
144
|
+
detach()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (session?.handle) {
|
|
148
|
+
const owner = session
|
|
149
|
+
|
|
150
|
+
owner.writing++
|
|
151
|
+
try {
|
|
152
|
+
owner.handle!.update(options)
|
|
153
|
+
if (session === owner) {
|
|
154
|
+
report('ready')
|
|
155
|
+
}
|
|
156
|
+
} catch {
|
|
157
|
+
if (session === owner) {
|
|
158
|
+
detach()
|
|
159
|
+
report('unavailable')
|
|
160
|
+
}
|
|
161
|
+
} finally {
|
|
162
|
+
owner.writing--
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const attach = deps.attach()
|
|
169
|
+
|
|
170
|
+
if (!attach) {
|
|
171
|
+
report('unavailable')
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const owner: Session = {
|
|
176
|
+
view,
|
|
177
|
+
mode: options.mode,
|
|
178
|
+
style: options.style,
|
|
179
|
+
writing: 1,
|
|
180
|
+
handle: null,
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
session = owner
|
|
184
|
+
try {
|
|
185
|
+
const handle = attach(view, options, (millis) => {
|
|
186
|
+
if (disposed || session !== owner || owner.writing || !owner.handle) {
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const current = plan()
|
|
191
|
+
|
|
192
|
+
if (!current || !current.enabled || !valid(millis)) {
|
|
193
|
+
update()
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const picked = new Date(millis).getTime()
|
|
198
|
+
|
|
199
|
+
if (
|
|
200
|
+
(current.minimumMillis !== undefined && picked < current.minimumMillis) ||
|
|
201
|
+
(current.maximumMillis !== undefined && picked > current.maximumMillis)
|
|
202
|
+
) {
|
|
203
|
+
update()
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (picked === current.selectionMillis) {
|
|
208
|
+
return
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (deps.props().selection === undefined) {
|
|
212
|
+
retained = picked
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
deps.props().onSelectionChange?.(new Date(picked))
|
|
217
|
+
} finally {
|
|
218
|
+
update()
|
|
219
|
+
} // Restore a rejected controlled value; suppress programmatic echoes.
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
if (disposed || session !== owner) {
|
|
223
|
+
handle?.detach()
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
owner.handle = handle
|
|
228
|
+
if (!handle) {
|
|
229
|
+
session = null
|
|
230
|
+
report('unavailable')
|
|
231
|
+
} else {
|
|
232
|
+
report('ready')
|
|
233
|
+
}
|
|
234
|
+
} catch {
|
|
235
|
+
if (session === owner) {
|
|
236
|
+
detach()
|
|
237
|
+
report('unavailable')
|
|
238
|
+
}
|
|
239
|
+
} finally {
|
|
240
|
+
owner.writing--
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
update,
|
|
246
|
+
bind(next: object | null) {
|
|
247
|
+
if (!disposed && next !== view) {
|
|
248
|
+
detach()
|
|
249
|
+
view = next
|
|
250
|
+
if (view) {
|
|
251
|
+
update()
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
dispose() {
|
|
256
|
+
if (!disposed) {
|
|
257
|
+
disposed = true
|
|
258
|
+
detach()
|
|
259
|
+
view = null
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
getStatus: () => status,
|
|
263
|
+
}
|
|
234
264
|
}
|
package/src/ios/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { SwiftUIDatePicker } from '../SwiftUIDatePicker.ios.tsrx'
|
|
2
2
|
export type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
SwiftUIDatePickerComponent,
|
|
4
|
+
SwiftUIDatePickerProps,
|
|
5
|
+
SwiftUIDatePickerStyle,
|
|
6
6
|
} from './types'
|
package/src/ios/types.ts
CHANGED
|
@@ -6,30 +6,30 @@ export type SwiftUIDatePickerComponent = 'date' | 'hourAndMinute'
|
|
|
6
6
|
|
|
7
7
|
/** iOS date-picker props (SwiftUI DatePicker). */
|
|
8
8
|
export interface SwiftUIDatePickerProps {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
9
|
+
/** Element id passed through to the host element. */
|
|
10
|
+
id?: string
|
|
11
|
+
/** Class list applied to the picker element. */
|
|
12
|
+
className?: any
|
|
13
|
+
/** Inline style (string CSS or object). */
|
|
14
|
+
style?: any
|
|
15
|
+
/** Label shown next to the picker. When omitted, the label is hidden. */
|
|
16
|
+
title?: string
|
|
17
|
+
/** Controlled selection. Pair with `onSelectionChange`. */
|
|
18
|
+
selection?: Date
|
|
19
|
+
/** Initial selection when `selection` is not provided. */
|
|
20
|
+
defaultSelection?: Date
|
|
21
|
+
/** Earliest selectable date. */
|
|
22
|
+
minimumDate?: Date
|
|
23
|
+
/** Latest selectable date. */
|
|
24
|
+
maximumDate?: Date
|
|
25
|
+
/** Which components the picker displays. @default ['date'] */
|
|
26
|
+
displayedComponents?: readonly SwiftUIDatePickerComponent[]
|
|
27
|
+
/** SwiftUI presentation style. `graphical` renders an inline calendar. @default 'automatic' */
|
|
28
|
+
pickerStyle?: SwiftUIDatePickerStyle
|
|
29
|
+
/** Disables interaction with the picker. */
|
|
30
|
+
disabled?: boolean
|
|
31
|
+
/** Spoken name for assistive tech. */
|
|
32
|
+
accessibilityLabel?: string
|
|
33
|
+
/** Called when the user picks a new date; programmatic `selection` updates do not emit. */
|
|
34
|
+
onSelectionChange?: (date: Date) => void
|
|
35
35
|
}
|
package/src/macos/index.ts
CHANGED
package/src/macos/types.ts
CHANGED
|
@@ -6,28 +6,28 @@ export type AppKitDatePickerStyle = 'textField' | 'graphical'
|
|
|
6
6
|
|
|
7
7
|
/** macOS date-picker props (NSDatePicker). */
|
|
8
8
|
export interface AppKitDatePickerProps {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
9
|
+
/** Element id passed through to the host element. */
|
|
10
|
+
id?: string
|
|
11
|
+
/** Class list applied to the picker element. */
|
|
12
|
+
className?: any
|
|
13
|
+
/** Inline style (string CSS or object). */
|
|
14
|
+
style?: any
|
|
15
|
+
/** Which element groups the NSDatePicker shows. @default 'date' */
|
|
16
|
+
components?: AppKitDatePickerComponents
|
|
17
|
+
/** 'graphical' embeds the inline calendar (date mode only). @default 'textField' */
|
|
18
|
+
pickerStyle?: AppKitDatePickerStyle
|
|
19
|
+
/** Controlled selection. Pair with `onSelectionChange`. */
|
|
20
|
+
selection?: Date
|
|
21
|
+
/** Initial uncontrolled seed. Later defaults do not reset the mounted picker. */
|
|
22
|
+
defaultSelection?: Date
|
|
23
|
+
/** Earliest selectable date. */
|
|
24
|
+
minimumDate?: Date
|
|
25
|
+
/** Latest selectable date. */
|
|
26
|
+
maximumDate?: Date
|
|
27
|
+
/** Disables interaction with the picker. */
|
|
28
|
+
disabled?: boolean
|
|
29
|
+
/** Spoken name for assistive tech. */
|
|
30
|
+
accessibilityLabel?: string
|
|
31
|
+
/** User selection changes; programmatic updates and retired controls do not emit. */
|
|
32
|
+
onSelectionChange?: (date: Date) => void
|
|
33
33
|
}
|