@use-voltra/core 2.3.1 → 2.4.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/build/cjs/index.js +2 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/locale.js +117 -0
- package/build/cjs/locale.js.map +1 -0
- package/build/cjs/payload/short-names.js +2 -0
- package/build/cjs/payload/short-names.js.map +1 -1
- package/build/cjs/renderer/native-modifiers.js +28 -0
- package/build/cjs/renderer/native-modifiers.js.map +1 -0
- package/build/cjs/renderer/renderer.js +9 -0
- package/build/cjs/renderer/renderer.js.map +1 -1
- package/build/cjs/useUpdateOnHMR.js +23 -0
- package/build/cjs/useUpdateOnHMR.js.map +1 -0
- package/build/cjs/widget-environment.js.map +1 -1
- package/build/esm/index.js +2 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/locale.js +110 -0
- package/build/esm/locale.js.map +1 -0
- package/build/esm/payload/short-names.js +2 -0
- package/build/esm/payload/short-names.js.map +1 -1
- package/build/esm/renderer/native-modifiers.js +25 -0
- package/build/esm/renderer/native-modifiers.js.map +1 -0
- package/build/esm/renderer/renderer.js +9 -0
- package/build/esm/renderer/renderer.js.map +1 -1
- package/build/esm/useUpdateOnHMR.js +19 -0
- package/build/esm/useUpdateOnHMR.js.map +1 -0
- package/build/esm/widget-environment.js.map +1 -1
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/locale.d.ts +48 -0
- package/build/types/locale.d.ts.map +1 -0
- package/build/types/payload/short-names.d.ts.map +1 -1
- package/build/types/renderer/index.d.ts +1 -0
- package/build/types/renderer/index.d.ts.map +1 -1
- package/build/types/renderer/native-modifiers.d.ts +13 -0
- package/build/types/renderer/native-modifiers.d.ts.map +1 -0
- package/build/types/renderer/renderer.d.ts.map +1 -1
- package/build/types/types.d.ts +81 -0
- package/build/types/types.d.ts.map +1 -1
- package/build/types/useUpdateOnHMR.d.ts +7 -0
- package/build/types/useUpdateOnHMR.d.ts.map +1 -0
- package/build/types/widget-environment.d.ts +28 -2
- package/build/types/widget-environment.d.ts.map +1 -1
- package/package.json +7 -1
- package/src/index.ts +2 -0
- package/src/locale.ts +139 -0
- package/src/payload/short-names.ts +2 -0
- package/src/renderer/index.ts +1 -0
- package/src/renderer/native-modifiers.ts +36 -0
- package/src/renderer/renderer.ts +8 -0
- package/src/types.ts +96 -0
- package/src/useUpdateOnHMR.ts +24 -0
- package/src/widget-environment.ts +42 -2
package/src/types.ts
CHANGED
|
@@ -12,3 +12,99 @@ export type VoltraElementRef = {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export type VoltraNodeJson = VoltraElementJson | VoltraElementJson[] | VoltraElementRef | string
|
|
15
|
+
|
|
16
|
+
export type EventSubscription = {
|
|
17
|
+
remove: () => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type PreloadImageBaseOptions = {
|
|
21
|
+
key: string
|
|
22
|
+
width?: number
|
|
23
|
+
height?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type PreloadImageUrlOptions = PreloadImageBaseOptions & {
|
|
27
|
+
url: string
|
|
28
|
+
method?: 'GET' | 'POST' | 'PUT'
|
|
29
|
+
headers?: Record<string, string>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type PreloadImageSvgOptions = PreloadImageBaseOptions & {
|
|
33
|
+
svg: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type PreloadImageOptions = PreloadImageUrlOptions | PreloadImageSvgOptions
|
|
37
|
+
|
|
38
|
+
export type PreloadImageFailure = {
|
|
39
|
+
key: string
|
|
40
|
+
error: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type PreloadImagesResult = {
|
|
44
|
+
succeeded: string[]
|
|
45
|
+
failed: PreloadImageFailure[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use `setWidgetServerUpdate` with an `Authorization` header instead. These are
|
|
50
|
+
* stored in the same place and keep the same replace-the-whole-set semantics.
|
|
51
|
+
*/
|
|
52
|
+
export type WidgetServerCredentials = {
|
|
53
|
+
token: string
|
|
54
|
+
headers?: Record<string, string>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Runtime overrides for a widget's `serverUpdate` settings — the twin of the `serverUpdate` key
|
|
59
|
+
* in app.json, which supplies the defaults.
|
|
60
|
+
*
|
|
61
|
+
* Every field is optional and replaces the app.json value when set. `headers` and `query` merge
|
|
62
|
+
* per key across layers; everything else takes the value from the most specific layer that sets
|
|
63
|
+
* it. Passing settings without a `widgetId` sets them for every server-driven widget.
|
|
64
|
+
*/
|
|
65
|
+
export type WidgetServerUpdateSettings = {
|
|
66
|
+
/** Endpoint to fetch from. Must be https, or http to a local dev host in a debug build. */
|
|
67
|
+
url?: string
|
|
68
|
+
/** How often to fetch, in minutes. Clamped to at least 15 and at most 24 hours. */
|
|
69
|
+
intervalMinutes?: number
|
|
70
|
+
/** Set false to stop fetching and drive the widget from the app instead. Defaults to true. */
|
|
71
|
+
enabled?: boolean
|
|
72
|
+
/** HTTP method. Defaults to GET. A body is dropped on GET and HEAD, with a warning. */
|
|
73
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
|
|
74
|
+
/** Extra query parameters. Voltra's own keys are reserved and rejected. */
|
|
75
|
+
query?: Record<string, string>
|
|
76
|
+
/** Extra request headers, for example `Authorization`. */
|
|
77
|
+
headers?: Record<string, string>
|
|
78
|
+
/** Request body, sent as `application/json`. */
|
|
79
|
+
body?: WidgetServerUpdateBody
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A JSON value, as accepted for a server-update request body. */
|
|
83
|
+
export type WidgetServerUpdateBody =
|
|
84
|
+
| string
|
|
85
|
+
| number
|
|
86
|
+
| boolean
|
|
87
|
+
| null
|
|
88
|
+
| WidgetServerUpdateBody[]
|
|
89
|
+
| { [key: string]: WidgetServerUpdateBody }
|
|
90
|
+
|
|
91
|
+
/** Options selecting which widget a settings call applies to. */
|
|
92
|
+
export type WidgetServerUpdateOptions = {
|
|
93
|
+
/** Widget id to scope the settings to. Omit to set them for every server-driven widget. */
|
|
94
|
+
widgetId?: string
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Fully resolved settings for one widget: every layer flattened and app.json's defaults applied,
|
|
99
|
+
* exactly what it would fetch with right now.
|
|
100
|
+
*/
|
|
101
|
+
export type WidgetServerUpdateSnapshot = {
|
|
102
|
+
/** Absent when the widget is server-driven but has no URL yet. */
|
|
103
|
+
url?: string
|
|
104
|
+
intervalMinutes: number
|
|
105
|
+
enabled: boolean
|
|
106
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
|
|
107
|
+
query: Record<string, string>
|
|
108
|
+
headers: Record<string, string>
|
|
109
|
+
body?: WidgetServerUpdateBody
|
|
110
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { getFastRefreshHub } from './fastRefreshHub.js'
|
|
4
|
+
|
|
5
|
+
declare const __DEV__: boolean | undefined
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Force the calling component to re-render whenever Metro applies a Fast Refresh
|
|
9
|
+
* patch, so freshly patched Voltra payloads are re-rendered. Shared by the iOS and
|
|
10
|
+
* Android client packages; relies on the process-wide {@link FastRefreshHub}.
|
|
11
|
+
*/
|
|
12
|
+
export const useUpdateOnHMR = () => {
|
|
13
|
+
const [, forceUpdate] = useState(0)
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!__DEV__) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return getFastRefreshHub().onPatch(() => {
|
|
21
|
+
forceUpdate((prev) => prev + 1)
|
|
22
|
+
})
|
|
23
|
+
}, [])
|
|
24
|
+
}
|
|
@@ -33,8 +33,48 @@ export type WidgetEnvironment<TConfig extends Record<string, unknown> | undefine
|
|
|
33
33
|
* doesn't expose it (rare). */
|
|
34
34
|
colorScheme?: 'light' | 'dark'
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// Locale and formatting preferences (ADR 0009)
|
|
38
|
+
// Always pass these explicitly to `Intl` / `toLocale*` calls: the JS runtime's own default
|
|
39
|
+
// locale and time zone are the process's, which may not match what the widget is drawn for.
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
/** BCP-47 locale tag the widget is being drawn in, including Unicode extensions for user
|
|
43
|
+
* overrides — for example `"pl-PL"` or `"en-US-u-hc-h23"`. On iOS this is the locale the
|
|
44
|
+
* widget extension resolved from the languages the app declares; see `preferredLanguages`
|
|
45
|
+
* for the user's full list. */
|
|
46
|
+
locale: string
|
|
47
|
+
|
|
48
|
+
/** The user's ordered language list as BCP-47 tags, independent of what the app or the
|
|
49
|
+
* widget extension supports. Use it (or `resolveLocale`) to pick a translation. */
|
|
50
|
+
preferredLanguages: string[]
|
|
51
|
+
|
|
52
|
+
/** Language the app asked Voltra to render widgets in with `setDynamicWidgetLocale`.
|
|
53
|
+
* `undefined` unless the app set one. `resolveLocale` gives it precedence. */
|
|
54
|
+
appLocale?: string
|
|
55
|
+
|
|
56
|
+
/** Writing direction of `locale`. */
|
|
57
|
+
layoutDirection: 'ltr' | 'rtl'
|
|
58
|
+
|
|
59
|
+
/** Effective clock preference, already reconciled with the user's 12/24-hour setting. Pass it
|
|
60
|
+
* as `hourCycle` to `Intl.DateTimeFormat`. */
|
|
61
|
+
hourCycle: 'h12' | 'h23'
|
|
62
|
+
|
|
63
|
+
/** IANA time zone of the device, for example `"Europe/Warsaw"`. Pass it as `timeZone` to
|
|
64
|
+
* `Intl.DateTimeFormat` when formatting `date`. */
|
|
65
|
+
timeZone: string
|
|
66
|
+
|
|
67
|
+
/** Measurement system of the user's region. Absent when the platform cannot tell
|
|
68
|
+
* (Android below API 28). */
|
|
69
|
+
measurementSystem?: 'metric' | 'us' | 'uk'
|
|
70
|
+
|
|
71
|
+
/** Unicode calendar identifier as `Intl` spells it, for example `"gregory"` or
|
|
72
|
+
* `"japanese"`. */
|
|
73
|
+
calendar?: string
|
|
74
|
+
|
|
75
|
+
/** First day of the week in the user's region: `1` is Sunday, `2` is Monday … `7` is
|
|
76
|
+
* Saturday (the `Calendar.firstWeekday` / `java.util.Calendar` numbering). */
|
|
77
|
+
firstDayOfWeek?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
|
38
78
|
|
|
39
79
|
// ---------------------------------------------------------------------------
|
|
40
80
|
// iOS-only runtime values
|