@modelform/react-native 0.12.0 → 0.13.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 +39 -0
- package/dist/{chunk-G67L7TFK.js → chunk-CU4TMSZE.js} +338 -90
- package/dist/{chunk-YUSXYDXG.mjs → chunk-OFXIKI2L.mjs} +248 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +18 -2
- package/dist/core/index.mjs +17 -1
- package/dist/core/speech.d.ts +36 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +696 -465
- package/dist/index.mjs +685 -454
- package/dist/ui/inputs/Dictation.d.ts +24 -0
- package/dist/ui/inputs/InputForm.d.ts +10 -1
- package/dist/ui/inputs/formContext.d.ts +5 -0
- package/dist/ui/speech.d.ts +29 -0
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { InputChoice, InputPanel, InputValue } from '../../core/inputs';
|
|
2
|
+
export interface Dictation {
|
|
3
|
+
/** Whether this input can be dictated into here: it takes dictation and the form has a recognizer. */
|
|
4
|
+
available: boolean;
|
|
5
|
+
listening: boolean;
|
|
6
|
+
/** What's being heard, or why it couldn't be used. */
|
|
7
|
+
hint: string | null;
|
|
8
|
+
toggle(): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Dictation into one input: listens for a phrase, turns it into the input's value with
|
|
12
|
+
* spokenValue, and hands that to `onChange`. Only the final phrase changes the value.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useDictation(panel: InputPanel, value: InputValue, onChange: (v: InputValue) => void, choices?: InputChoice[]): Dictation;
|
|
15
|
+
/** The microphone button beside an input. Filled while listening; tap again to stop. */
|
|
16
|
+
export declare function MicButton({ dictation, title, size }: {
|
|
17
|
+
dictation: Dictation;
|
|
18
|
+
title?: string;
|
|
19
|
+
size?: number;
|
|
20
|
+
}): import("react").JSX.Element | null;
|
|
21
|
+
/** What's being heard, or why it couldn't be used, under the input. Nothing when there's nothing to say. */
|
|
22
|
+
export declare function DictationHint({ dictation }: {
|
|
23
|
+
dictation: Dictation;
|
|
24
|
+
}): import("react").JSX.Element | null;
|
|
@@ -2,6 +2,7 @@ import { type ReactNode } from 'react';
|
|
|
2
2
|
import { type Entry, type InputChoice, type InputValue, type NewEntry } from '../../core/inputs';
|
|
3
3
|
import type { EntryStore } from '../../core/local';
|
|
4
4
|
import type { Dashboard } from '../../core/schema';
|
|
5
|
+
import { type SpeechRecognizer } from '../speech';
|
|
5
6
|
export interface InputFormProps {
|
|
6
7
|
dashboard: Dashboard;
|
|
7
8
|
store: EntryStore;
|
|
@@ -27,10 +28,18 @@ export interface InputFormProps {
|
|
|
27
28
|
* their timestamp in place of them.
|
|
28
29
|
*/
|
|
29
30
|
editing?: Entry[];
|
|
31
|
+
/**
|
|
32
|
+
* Dictation for text, number, duration and choice inputs. On the web the browser's speech
|
|
33
|
+
* recognition is used by default where there is one; elsewhere pass a recognizer (an adapter
|
|
34
|
+
* over expo-speech-recognition, say). null turns dictation off.
|
|
35
|
+
*/
|
|
36
|
+
speech?: SpeechRecognizer | null;
|
|
37
|
+
/** Language to dictate in (BCP-47); the recognizer's default when missing. */
|
|
38
|
+
speechLang?: string;
|
|
30
39
|
}
|
|
31
40
|
/**
|
|
32
41
|
* A data entry form laid out from dashboard JSON with input-* panels. Edited values are
|
|
33
42
|
* staged until Save, then recorded together at the chosen timestamp, along with any
|
|
34
43
|
* `record: "always"` inputs. Counters record immediately on tap.
|
|
35
44
|
*/
|
|
36
|
-
export declare function InputForm({ dashboard, store, onSaved, choices, header, timestamp, defaults: given, beforeSave, editing }: InputFormProps): import("react").JSX.Element;
|
|
45
|
+
export declare function InputForm({ dashboard, store, onSaved, choices, header, timestamp, defaults: given, beforeSave, editing, speech: givenSpeech, speechLang }: InputFormProps): import("react").JSX.Element;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type GroupItem, type InputChoice, type InputGroupPanel, type InputValue } from '../../core/inputs';
|
|
2
2
|
import type { EntryStore } from '../../core/local';
|
|
3
|
+
import type { SpeechRecognizer } from '../speech';
|
|
3
4
|
export interface InputFormState {
|
|
4
5
|
value(metric: string): InputValue;
|
|
5
6
|
setValue(metric: string, v: InputValue): void;
|
|
@@ -9,6 +10,10 @@ export interface InputFormState {
|
|
|
9
10
|
choices: Record<string, InputChoice[]>;
|
|
10
11
|
/** Why the input's value can't be saved, once that's worth showing. */
|
|
11
12
|
problem?(metric: string): string | undefined;
|
|
13
|
+
/** Dictation for the inputs that take it; none means no microphone buttons. */
|
|
14
|
+
speech?: SpeechRecognizer | null;
|
|
15
|
+
/** Language to dictate in (BCP-47); the recognizer's default when missing. */
|
|
16
|
+
speechLang?: string;
|
|
12
17
|
/** An input-group's items and what can be done to them. Missing outside an InputForm that supports groups. */
|
|
13
18
|
group?(panel: InputGroupPanel): FormGroup;
|
|
14
19
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Speech recognition as the forms use it. modelform doesn't depend on a native speech module:
|
|
3
|
+
* the app passes a SpeechRecognizer to InputForm (an adapter over expo-speech-recognition, say),
|
|
4
|
+
* and on the web the browser's Web Speech API is used when there is one.
|
|
5
|
+
*/
|
|
6
|
+
export interface DictationOptions {
|
|
7
|
+
/** BCP-47 language tag; the recognizer's default (usually the device's) when missing. */
|
|
8
|
+
lang?: string;
|
|
9
|
+
/** Words likely to be said, such as choice labels, for recognizers that take hints. */
|
|
10
|
+
hints?: string[];
|
|
11
|
+
/** What's been heard so far. Called with `final` once, when the phrase is done. */
|
|
12
|
+
onText(text: string, final: boolean): void;
|
|
13
|
+
/** Something went wrong, in words to show the user. Not called when stopped or aborted. */
|
|
14
|
+
onError(message: string): void;
|
|
15
|
+
/** Listening has stopped, for any reason. Always called last. */
|
|
16
|
+
onEnd(): void;
|
|
17
|
+
}
|
|
18
|
+
export interface DictationSession {
|
|
19
|
+
/** Stop listening and deliver what was heard. */
|
|
20
|
+
stop(): void;
|
|
21
|
+
/** Stop listening and drop what was heard. */
|
|
22
|
+
abort(): void;
|
|
23
|
+
}
|
|
24
|
+
export interface SpeechRecognizer {
|
|
25
|
+
/** Listen for one phrase. Asks for microphone and speech permission first where needed. */
|
|
26
|
+
start(options: DictationOptions): DictationSession;
|
|
27
|
+
}
|
|
28
|
+
/** The browser's speech recognition, or null where there's none (Firefox, and outside browsers). */
|
|
29
|
+
export declare function webSpeechRecognizer(): SpeechRecognizer | null;
|
package/package.json
CHANGED