@octane-xplat/date-picker 0.18.0 → 0.19.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 CHANGED
@@ -2,10 +2,17 @@
2
2
 
3
3
  Platform-specific date and time pickers for Octane xplat apps: a SwiftUI
4
4
  `DatePicker` on iOS, Material 3 `DatePicker`/`TimePicker` built with Jetpack
5
- Compose on Android, and a real `NSDatePicker` on macOS. For portable form
6
- controls that work on every target, use `Calendar`, `DateInput`,
5
+ Compose on Android, and an experimental `NSDatePicker` source implementation
6
+ on native macOS. Native macOS editing, layout and VoiceOver qualification is
7
+ pending. For a shared form API, use `Calendar`, `DateInput`,
7
8
  `TimeInput`, `DateTimeInput`, and `DateRangeInput` from `@octane-xplat/ui`.
8
9
 
10
+ From an existing Xplat app, install the package before using the example:
11
+
12
+ ```sh
13
+ bun add @octane-xplat/date-picker
14
+ ```
15
+
9
16
  ```tsx
10
17
  import { useState } from 'octane'
11
18
  import { DateInput } from '@octane-xplat/ui'
@@ -25,8 +32,16 @@ These native entries have platform-specific contracts.
25
32
  The old `@octane-xplat/date-picker/web` `DateInput` subpath was removed because
26
33
  its browser-only string contract conflicted with the shared `DateInput` API.
27
34
 
35
+ In an existing app, install the package with Bun. The macOS entry needs a
36
+ [native AppKit app](../../docs/platform/macos-native.md); the renderer supplies
37
+ its native attachment automatically.
38
+
39
+ ```sh
40
+ bun add @octane-xplat/date-picker
41
+ ```
42
+
28
43
  ```tsx
29
- /** @jsxImportSource @nativescript-community/octane */
44
+ /** @jsxImportSource @octane-xplat/jsx */
30
45
  // SwiftUIDatePickerExample.ios.tsx
31
46
  import { SwiftUIDatePicker } from '@octane-xplat/date-picker/ios'
32
47
 
@@ -43,7 +58,7 @@ export function Picker() {
43
58
  ```
44
59
 
45
60
  ```tsx
46
- /** @jsxImportSource @nativescript-community/octane */
61
+ /** @jsxImportSource @octane-xplat/jsx */
47
62
  // MaterialDatePickerExample.android.tsx
48
63
  import { MaterialDatePicker } from '@octane-xplat/date-picker/android'
49
64
 
@@ -63,16 +78,23 @@ export function Picker() {
63
78
 
64
79
  ```tsx
65
80
  // AppKitDatePickerExample.macos.tsx
81
+ import { useState } from 'octane'
66
82
  import { AppKitDatePicker } from '@octane-xplat/date-picker/macos'
83
+ import { Text } from '@octane-xplat/ui'
67
84
 
68
85
  export function Picker() {
86
+ const [selection, setSelection] = useState(new Date(2026, 9, 29))
69
87
  return (
70
- <AppKitDatePicker
71
- components="date"
72
- pickerStyle="graphical"
73
- defaultSelection={new Date(2026, 9, 2)}
74
- onSelectionChange={console.log}
75
- />
88
+ <>
89
+ <AppKitDatePicker
90
+ components="date"
91
+ pickerStyle="graphical"
92
+ selection={selection}
93
+ onSelectionChange={setSelection}
94
+ accessibilityLabel="Departure date"
95
+ />
96
+ <Text>{selection.toLocaleString()}</Text>
97
+ </>
76
98
  )
77
99
  }
78
100
  ```
@@ -83,7 +105,7 @@ and `pickerStyle`; the Android entry follows the uncontrolled
83
105
  `initialDate`/`onDateSelected` model of the Material 3 pickers with
84
106
  `selectableDates` range bounds; the macOS entry takes
85
107
  `components`/`pickerStyle` (`'graphical'` embeds the
86
- inline calendar) with a controlled `selection` `Date`.
108
+ inline date calendar) with a controlled `selection` `Date`.
87
109
 
88
110
  ```tsx
89
111
  // Departure.macos.tsx
@@ -103,15 +125,35 @@ export function Departure() {
103
125
  }
104
126
  ```
105
127
 
128
+ On native macOS, `defaultSelection` seeds an uncontrolled picker once. Its
129
+ accepted date survives component/style changes and replacement of the backing
130
+ view; later defaults do not reset it. Bounds are inclusive. Invalid dates,
131
+ reversed bounds or an out-of-bounds controlled selection show a generic message
132
+ until the props are repaired. Uncontrolled selection clamps to new bounds without
133
+ emitting a change. Disabled, retired and programmatic changes do not call
134
+ `onSelectionChange`; the current callback receives user changes. See the
135
+ [native macOS workflow and remaining limits](../../docs/platform/date-picker.md#native-macos-selection-lifecycle).
136
+
137
+ ```tsx
138
+ // BoundedDate.macos.tsx — defaultSelection is only the initial seed.
139
+ import { AppKitDatePicker } from '@octane-xplat/date-picker/macos'
140
+ const initial = new Date(2026, 9, 29)
141
+ const minimum = new Date(2026, 0, 1)
142
+ export function BoundedDate() {
143
+ return <AppKitDatePicker defaultSelection={initial} minimumDate={minimum}
144
+ accessibilityLabel="Departure date" onSelectionChange={(date) => console.log(date)} />
145
+ }
146
+ ```
147
+
106
148
  Android notes: give `MaterialDatePicker` a bounded height (the M3 calendar's
107
149
  lazy grid collapses under unbounded height), and keep `initialDate` and
108
150
  `selectableDates` identity-stable — the provider keys its state `remember`
109
151
  on them, so a per-render `new Date()` resets the selection.
110
152
  See the framework guide for details and maintained examples:
111
- [`docs/platform/date-picker.md`](../../docs/platform/date-picker.md).
153
+ [`docs/platform/date-picker.md`](https://octane-xplat.goddardai.org/date-picker).
112
154
 
113
155
  ```tsx
114
- /** @jsxImportSource @nativescript-community/octane */
156
+ /** @jsxImportSource @octane-xplat/jsx */
115
157
  // Departure.android.tsx — reuse these objects while the picker is mounted.
116
158
  import { MaterialDatePicker } from '@octane-xplat/date-picker/android'
117
159
 
package/package.json CHANGED
@@ -1,82 +1,88 @@
1
1
  {
2
- "name": "@octane-xplat/date-picker",
3
- "version": "0.18.0",
4
- "description": "Platform-specific date and time selection controls for Octane xplat",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/octane-xplat/octane-xplat",
8
- "directory": "packages/date-picker"
9
- },
10
- "files": [
11
- "types",
12
- "src",
13
- "platforms",
14
- "!src/**/*.test.*",
15
- "!src/**/*.spec.*"
16
- ],
17
- "type": "module",
18
- "exports": {
19
- ".": {
20
- "types": "./types/index.d.ts",
21
- "web": "./src/index.ts",
22
- "native": "./src/index.ts",
23
- "default": "./src/index.ts"
24
- },
25
- "./ios": {
26
- "types": "./types/ios/index.d.ts",
27
- "native": "./src/ios/index.ts"
28
- },
29
- "./android": {
30
- "types": "./types/android/index.d.ts",
31
- "native": "./src/android/index.ts"
32
- },
33
- "./macos": {
34
- "types": "./types/macos/index.d.ts",
35
- "macos": "./src/macos/index.ts"
36
- }
37
- },
38
- "publishConfig": {
39
- "access": "public"
40
- },
41
- "dependencies": {
42
- "@nativescript/jetpack-compose": "1.0.0-beta.0",
43
- "@nativescript/swift-ui": "4.0.2"
44
- },
45
- "devDependencies": {
46
- "@nativescript-community/octane": "0.2.5",
47
- "@nativescript/core": "9.1.3",
48
- "@octane-xplat/macos-renderer": "0.18.0",
49
- "@octanejs/vite-plugin": "0.1.61",
50
- "octane": "0.14.0",
51
- "tsrx-typegen": "0.4.0",
52
- "typescript": "5.9.3",
53
- "vite": "8.3.0"
54
- },
55
- "peerDependencies": {
56
- "@nativescript-community/octane": ">=0.2.1 <1",
57
- "@nativescript/core": ">=9.1.0 <10",
58
- "octane": ">=0.1.51 <1"
59
- },
60
- "peerDependenciesMeta": {
61
- "@nativescript-community/octane": {
62
- "optional": true
63
- },
64
- "@nativescript/core": {
65
- "optional": true
66
- },
67
- "octane": {
68
- "optional": true
69
- }
70
- },
71
- "nativescript": {
72
- "platforms": {
73
- "android": "9.1.0",
74
- "ios": "9.1.0"
75
- }
76
- },
77
- "scripts": {
78
- "test:packed": "node tests/packed-consumer.mjs",
79
- "pack:check": "tsrx-typegen --pack-check",
80
- "typegen": "tsc -p tsconfig.types.json"
81
- }
82
- }
2
+ "name": "@octane-xplat/date-picker",
3
+ "version": "0.19.0",
4
+ "description": "Platform-specific date and time selection controls for Octane xplat",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/octane-xplat/octane-xplat",
8
+ "directory": "packages/date-picker"
9
+ },
10
+ "files": [
11
+ "types/generated",
12
+ "src",
13
+ "platforms",
14
+ "!src/**/*.test.*",
15
+ "!src/**/*.spec.*"
16
+ ],
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./types/generated/index.d.ts",
21
+ "web": "./src/index.ts",
22
+ "native": "./src/index.ts",
23
+ "default": "./src/index.ts"
24
+ },
25
+ "./ios": {
26
+ "types": "./types/generated/ios/index.d.ts",
27
+ "native": "./src/ios/index.ts"
28
+ },
29
+ "./android": {
30
+ "types": "./types/generated/android/index.d.ts",
31
+ "native": "./src/android/index.ts"
32
+ },
33
+ "./macos": {
34
+ "types": "./types/generated/macos/index.d.ts",
35
+ "macos": "./src/macos/index.ts"
36
+ }
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "scripts": {
42
+ "prepack": "bun run typegen && tsrx-typegen --pack-check",
43
+ "test": "node --test tests/date-picker-owner.macos.test.mjs",
44
+ "test:packed": "node tests/packed-consumer.mjs",
45
+ "pack:check": "tsrx-typegen --pack-check",
46
+ "typegen": "tsrx-typegen --target date-picker",
47
+ "typecheck": "tsrx-tsc --noEmit -p tsconfig.types.json"
48
+ },
49
+ "dependencies": {
50
+ "@nativescript/jetpack-compose": "1.0.0-beta.0",
51
+ "@nativescript/swift-ui": "4.0.2",
52
+ "@octane-xplat/jsx": "0.19.0"
53
+ },
54
+ "devDependencies": {
55
+ "@nativescript-community/octane": "0.2.5",
56
+ "@nativescript/core": "9.1.3",
57
+ "@octane-xplat/macos-renderer": "0.19.0",
58
+ "@octanejs/vite-plugin": "0.5.0",
59
+ "octane": "0.16.3",
60
+ "tsrx-typegen": "0.5.0",
61
+ "typescript": "5.9.3",
62
+ "vite": "8.3.0",
63
+ "@tsrx/typescript-plugin": "0.4.11"
64
+ },
65
+ "peerDependencies": {
66
+ "@nativescript-community/octane": ">=0.2.1 <1",
67
+ "@nativescript/core": ">=9.1.0 <10",
68
+ "octane": ">=0.1.51 <1"
69
+ },
70
+ "peerDependenciesMeta": {
71
+ "@nativescript-community/octane": {
72
+ "optional": true
73
+ },
74
+ "@nativescript/core": {
75
+ "optional": true
76
+ },
77
+ "octane": {
78
+ "optional": true
79
+ }
80
+ },
81
+ "nativescript": {
82
+ "platforms": {
83
+ "android": "9.1.0",
84
+ "ios": "9.1.0"
85
+ }
86
+ },
87
+ "types": "./types/generated/index.d.ts"
88
+ }
@@ -0,0 +1 @@
1
+ .xplat-appkit-date-picker { display: flex; min-width: 240; }
@@ -1,6 +1,10 @@
1
- /** @jsxImportSource @octane-xplat/macos-renderer */
2
- import { useEffect, useRef } from 'octane'
1
+ /** @jsxImportSource @octane-xplat/jsx */
2
+ import './AppKitDatePicker.macos.css'
3
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'octane'
3
4
  import type { AppKitDatePickerProps } from './macos/types'
5
+ import { createDatePickerOwner } from './date-picker-owner.macos'
6
+ import { mergeStyle } from './style-merge'
7
+ import type { DatePickerAttach } from './date-picker-owner.macos'
4
8
 
5
9
  const host = (): any => (globalThis as any).__xplatAppKit ?? {}
6
10
 
@@ -10,48 +14,43 @@ const host = (): any => (globalThis as any).__xplatAppKit ?? {}
10
14
  * clock-and-calendar field; 'dateAndTime' shows both element groups.
11
15
  * The host element carries an explicit size — the picker is pinned to
12
16
  * its edges. */
13
- export function AppKitDatePicker(props: AppKitDatePickerProps) @{
14
- const anchor = useRef<any>(null)
15
- const handle = useRef<any>(null)
17
+ export function AppKitDatePicker(props: AppKitDatePickerProps): unknown @{
18
+ const live = useRef(props)
19
+ live.current = props
20
+ const [, rerender] = useState(0)
21
+ const owner = useMemo(
22
+ () =>
23
+ createDatePickerOwner({
24
+ props: () => live.current,
25
+ attach: () =>
26
+ typeof host().attachDatePicker === 'function'
27
+ ? (host().attachDatePicker as DatePickerAttach)
28
+ : undefined,
29
+ status: () => rerender((n) => n + 1),
30
+ }),
31
+ [],
32
+ )
16
33
 
17
- const options = () => ({
18
- mode: props.components,
19
- style: props.pickerStyle,
20
- selectionMillis: props.selection?.getTime?.(),
21
- minimumMillis: props.minimumDate?.getTime?.(),
22
- maximumMillis: props.maximumDate?.getTime?.(),
23
- enabled: !props.disabled,
24
- })
34
+ useLayoutEffect(() => owner.update(), null)
35
+ useEffect(() => () => owner.dispose(), [])
36
+ const graphical =
37
+ props.components === 'time' ||
38
+ ((props.components ?? 'date') === 'date' && props.pickerStyle === 'graphical')
25
39
 
26
- useEffect(() => {
27
- const view = anchor.current
28
- const attach = host().attachDatePicker
29
- if (!view || typeof attach !== 'function') return
30
- // defaultSelection seeds the initial date; after that the user's
31
- // pick owns the value — only the controlled `selection` is pushed.
32
- handle.current = attach(
33
- view,
34
- { ...options(), selectionMillis: (props.selection ?? props.defaultSelection)?.getTime?.() },
35
- (millis: number) => {
36
- props.onSelectionChange?.(new Date(millis))
37
- },
38
- )
39
-
40
- return () => {
41
- handle.current?.detach()
42
- handle.current = null
40
+ <masonview
41
+ ref={owner.bind}
42
+ id={props.id}
43
+ className={['xplat-appkit-date-picker', props.className]}
44
+ style={mergeStyle({ minHeight: graphical ? 300 : 26 }, props.style)}
45
+ >
46
+ @if (owner.getStatus() === 'invalid') {
47
+ <label text="Choose a valid date and date range." accessibilityLiveRegion="polite" />
43
48
  }
44
- }, [props.components, props.pickerStyle])
45
-
46
- // Push controlled selection/range updates into the mounted picker; the
47
- // bridge update is echo-suppressed by comparing against dateValue.
48
- useEffect(() => {
49
- handle.current?.update(options())
50
- })
51
-
52
- <masonview ref={(v: any) => { anchor.current = v }} id={props.id} className={props.className} style={{display: "flex", ...({
53
- minWidth: 240,
54
- minHeight: props.pickerStyle === 'graphical' ? 300 : 26,
55
- ...props.style,
56
- })}}/>;
49
+ @if (owner.getStatus() === 'unavailable') {
50
+ <label
51
+ text="Date selection is unavailable in this app."
52
+ accessibilityLiveRegion="polite"
53
+ />
54
+ }
55
+ </masonview>
57
56
  }
@@ -1,24 +1,38 @@
1
- /** @jsxImportSource @nativescript-community/octane */
1
+ /** @jsxImportSource @octane-xplat/jsx */
2
2
  import { registerElement } from '@nativescript-community/octane'
3
- import type { Attributes } from '@nativescript-community/octane/intrinsics'
4
- import { ComposeDataDriver, JetpackCompose, registerJetpackCompose } from '@nativescript/jetpack-compose'
3
+ import type { Attributes } from '@octane-xplat/jsx/intrinsics'
4
+ import {
5
+ ComposeDataDriver,
6
+ JetpackCompose,
7
+ registerJetpackCompose,
8
+ } from '@nativescript/jetpack-compose'
9
+
5
10
  import type { MaterialDatePickerProps } from './android/types'
6
11
 
7
12
  declare const com: any
8
13
 
9
- declare module '@nativescript-community/octane/intrinsics' {
10
- interface NativeScriptElements {
11
- xplatandroiddatepicker: Attributes<typeof JetpackCompose>
14
+ declare module '@octane-xplat/jsx/intrinsics' {
15
+ interface NativeElements<TElement> {
16
+ xplatandroiddatepicker: Attributes<
17
+ TElement,
18
+ {
19
+ composeId?: string
20
+ data?: Record<string, unknown>
21
+ onComposeEvent?: (event: { data?: unknown }) => void
22
+ }
23
+ >
12
24
  }
13
25
  }
14
26
 
15
27
  registerElement('xplatandroiddatepicker', JetpackCompose)
16
- registerJetpackCompose('xplat-material-datepicker', (owner: any) =>
17
- new ComposeDataDriver(new com.octanexplat.datepicker.XplatDatePickerProvider(), owner),
28
+ registerJetpackCompose(
29
+ 'xplat-material-datepicker',
30
+ (owner: any) =>
31
+ new ComposeDataDriver(new com.octanexplat.datepicker.XplatDatePickerProvider(), owner),
18
32
  )
19
33
 
20
34
  /** Renders a Material 3 DatePicker/TimePicker through the NativeScript Jetpack Compose bridge. */
21
- export function MaterialDatePicker(props: MaterialDatePickerProps) @{
35
+ export function MaterialDatePicker(props: MaterialDatePickerProps): unknown @{
22
36
  const data = {
23
37
  initialDate: props.initialDate?.getTime() ?? null,
24
38
  variant: props.variant ?? 'picker',
@@ -45,5 +59,5 @@ export function MaterialDatePicker(props: MaterialDatePickerProps) @{
45
59
  const millis = event.data?.date
46
60
  props.onDateSelected?.(typeof millis === 'number' ? new Date(millis) : null)
47
61
  }}
48
- />;
62
+ />
49
63
  }
@@ -1,27 +1,38 @@
1
- /** @jsxImportSource @nativescript-community/octane */
1
+ /** @jsxImportSource @octane-xplat/jsx */
2
2
  import { registerElement } from '@nativescript-community/octane'
3
- import type { Attributes } from '@nativescript-community/octane/intrinsics'
3
+ import type { Attributes } from '@octane-xplat/jsx/intrinsics'
4
4
  import { SwiftUI, UIDataDriver, registerSwiftUI } from '@nativescript/swift-ui'
5
5
  import { useState } from 'octane'
6
6
  import type { SwiftUIDatePickerProps } from './ios/types'
7
7
 
8
8
  declare const XplatDatePickerProvider: any
9
9
 
10
- declare module '@nativescript-community/octane/intrinsics' {
11
- interface NativeScriptElements {
12
- xplatiosdatepicker: Attributes<typeof SwiftUI>
10
+ declare module '@octane-xplat/jsx/intrinsics' {
11
+ interface NativeElements<TElement> {
12
+ xplatiosdatepicker: Attributes<
13
+ TElement,
14
+ {
15
+ swiftId?: string
16
+ data?: Record<string, unknown>
17
+ onSwiftUIEvent?: (event: { data?: unknown }) => void
18
+ }
19
+ >
13
20
  }
14
21
  }
15
22
 
16
23
  registerElement('xplatiosdatepicker', SwiftUI)
17
- registerSwiftUI('xplat-swiftui-datepicker', (owner: any) =>
18
- new UIDataDriver(new XplatDatePickerProvider(), owner),
24
+ registerSwiftUI(
25
+ 'xplat-swiftui-datepicker',
26
+ (owner: any) => new UIDataDriver(new XplatDatePickerProvider(), owner),
19
27
  )
20
28
 
21
29
  /** Renders a SwiftUI DatePicker through NativeScript's SwiftUI bridge. */
22
- export function SwiftUIDatePicker(props: SwiftUIDatePickerProps) @{
30
+ export function SwiftUIDatePicker(props: SwiftUIDatePickerProps): unknown @{
23
31
  const controlled = props.selection !== undefined
24
- const [internalSelection, setInternalSelection] = useState<Date | undefined>(props.defaultSelection)
32
+ const [internalSelection, setInternalSelection] = useState<Date | undefined>(
33
+ props.defaultSelection,
34
+ )
35
+
25
36
  const selection = controlled ? props.selection! : internalSelection
26
37
 
27
38
  <xplatiosdatepicker
@@ -42,10 +53,16 @@ export function SwiftUIDatePicker(props: SwiftUIDatePickerProps) @{
42
53
  }}
43
54
  onSwiftUIEvent={(event: any) => {
44
55
  const millis = event.data?.date
45
- if (typeof millis !== 'number') return
56
+ if (typeof millis !== 'number') {
57
+ return
58
+ }
59
+
46
60
  const next = new Date(millis)
47
- if (!controlled) setInternalSelection(next)
61
+ if (!controlled) {
62
+ setInternalSelection(next)
63
+ }
64
+
48
65
  props.onSelectionChange?.(next)
49
66
  }}
50
- />;
67
+ />
51
68
  }