@modelform/react-native 0.12.0 → 0.14.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.
@@ -0,0 +1,30 @@
1
+ import type { InputChoice, InputPanel, InputValue } from '../../core/inputs';
2
+ import type { DictationSession } from '../speech';
3
+ /** Stops whatever is listening, before starting something new. */
4
+ export declare function stopListening(): void;
5
+ /** Marks `session` as the one listening, or, with `done`, as no longer listening. */
6
+ export declare function claimListening(session: DictationSession | null, done?: boolean): void;
7
+ export interface Dictation {
8
+ /** Whether this input can be dictated into here: it takes dictation and the form has a recognizer. */
9
+ available: boolean;
10
+ listening: boolean;
11
+ /** What's being heard, or why it couldn't be used. */
12
+ hint: string | null;
13
+ toggle(): void;
14
+ }
15
+ /**
16
+ * Dictation into one input: listens for a phrase, turns it into the input's value with
17
+ * spokenValue, and hands that to `onChange`. Only the final phrase changes the value.
18
+ */
19
+ export declare function useDictation(panel: InputPanel, value: InputValue, onChange: (v: InputValue) => void, choices?: InputChoice[]): Dictation;
20
+ /** The microphone button beside an input. Filled while listening; tap again to stop. */
21
+ export declare function MicButton({ dictation, title, label, size }: {
22
+ dictation: Pick<Dictation, 'available' | 'listening' | 'toggle'>;
23
+ title?: string;
24
+ label?: string;
25
+ size?: number;
26
+ }): import("react").JSX.Element | null;
27
+ /** What's being heard, or why it couldn't be used, under the input. Nothing when there's nothing to say. */
28
+ export declare function DictationHint({ dictation }: {
29
+ dictation: Dictation;
30
+ }): import("react").JSX.Element | null;
@@ -1,7 +1,9 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import { type Entry, type InputChoice, type InputValue, type NewEntry } from '../../core/inputs';
3
+ import { type FormFiller } from '../../core/formFill';
3
4
  import type { EntryStore } from '../../core/local';
4
5
  import type { Dashboard } from '../../core/schema';
6
+ import { type SpeechRecognizer } from '../speech';
5
7
  export interface InputFormProps {
6
8
  dashboard: Dashboard;
7
9
  store: EntryStore;
@@ -27,10 +29,24 @@ export interface InputFormProps {
27
29
  * their timestamp in place of them.
28
30
  */
29
31
  editing?: Entry[];
32
+ /**
33
+ * Dictation for text, number, duration and choice inputs. On the web the browser's speech
34
+ * recognition is used by default where there is one; elsewhere pass a recognizer (an adapter
35
+ * over expo-speech-recognition, say). null turns dictation off.
36
+ */
37
+ speech?: SpeechRecognizer | null;
38
+ /** Language to dictate in (BCP-47); the recognizer's default when missing. */
39
+ speechLang?: string;
40
+ /**
41
+ * Fills the whole form from one thing said, with a microphone beside Save. What it fills is
42
+ * highlighted for review; nothing is recorded until Save. Default ruleFiller (no model); null
43
+ * turns it off. Needs `speech` too.
44
+ */
45
+ filler?: FormFiller | null;
30
46
  }
31
47
  /**
32
48
  * A data entry form laid out from dashboard JSON with input-* panels. Edited values are
33
49
  * staged until Save, then recorded together at the chosen timestamp, along with any
34
50
  * `record: "always"` inputs. Counters record immediately on tap.
35
51
  */
36
- export declare function InputForm({ dashboard, store, onSaved, choices, header, timestamp, defaults: given, beforeSave, editing }: InputFormProps): import("react").JSX.Element;
52
+ export declare function InputForm({ dashboard, store, onSaved, choices, header, timestamp, defaults: given, beforeSave, editing, speech: givenSpeech, speechLang, filler }: InputFormProps): import("react").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { type FillForm, type FillResult, type FormFiller } from '../../core/formFill';
2
+ import type { SpeechRecognizer } from '../speech';
3
+ export interface VoiceFill {
4
+ /** Whether the form can be filled by voice: a recognizer, a filler, and fields to fill. */
5
+ available: boolean;
6
+ listening: boolean;
7
+ /** The filler is working on what was said. */
8
+ filling: boolean;
9
+ /** What's being heard while listening. */
10
+ heard: string | null;
11
+ toggle(): void;
12
+ }
13
+ interface Options {
14
+ speech: SpeechRecognizer | null | undefined;
15
+ lang?: string;
16
+ filler: FormFiller | null | undefined;
17
+ form: FillForm;
18
+ /** What was said, and what the filler made of it. */
19
+ onFilled(result: FillResult, said: string): void;
20
+ /** Something went wrong (no microphone, say), in words to show the user. */
21
+ onError(message: string): void;
22
+ }
23
+ /**
24
+ * Filling the whole form from one thing said: listens until stopped (pauses and all), hands the
25
+ * transcript to the filler, and passes its result on for the form to show for review.
26
+ */
27
+ export declare function useVoiceFill({ speech, lang, filler, form, onFilled, onError }: Options): VoiceFill;
28
+ export {};
@@ -1,14 +1,21 @@
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;
6
7
  isDirty(metric: string): boolean;
8
+ /** Whether the input was just filled by voice and not yet edited, saved or discarded: shown highlighted for review. */
9
+ filled?(metric: string): boolean;
7
10
  store: EntryStore;
8
11
  /** Runtime choice lists for input-select panels with `choicesFrom`. */
9
12
  choices: Record<string, InputChoice[]>;
10
13
  /** Why the input's value can't be saved, once that's worth showing. */
11
14
  problem?(metric: string): string | undefined;
15
+ /** Dictation for the inputs that take it; none means no microphone buttons. */
16
+ speech?: SpeechRecognizer | null;
17
+ /** Language to dictate in (BCP-47); the recognizer's default when missing. */
18
+ speechLang?: string;
12
19
  /** An input-group's items and what can be done to them. Missing outside an InputForm that supports groups. */
13
20
  group?(panel: InputGroupPanel): FormGroup;
14
21
  }
@@ -0,0 +1,34 @@
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
+ /**
12
+ * Keep listening through pauses until stopped, for a long phrase (filling a whole form).
13
+ * `onText` is still called with `final` only once, when listening stops.
14
+ */
15
+ continuous?: boolean;
16
+ /** What's been heard so far. Called with `final` once, when the phrase is done. */
17
+ onText(text: string, final: boolean): void;
18
+ /** Something went wrong, in words to show the user. Not called when stopped or aborted. */
19
+ onError(message: string): void;
20
+ /** Listening has stopped, for any reason. Always called last. */
21
+ onEnd(): void;
22
+ }
23
+ export interface DictationSession {
24
+ /** Stop listening and deliver what was heard. */
25
+ stop(): void;
26
+ /** Stop listening and drop what was heard. */
27
+ abort(): void;
28
+ }
29
+ export interface SpeechRecognizer {
30
+ /** Listen for one phrase. Asks for microphone and speech permission first where needed. */
31
+ start(options: DictationOptions): DictationSession;
32
+ }
33
+ /** The browser's speech recognition, or null where there's none (Firefox, and outside browsers). */
34
+ export declare function webSpeechRecognizer(): SpeechRecognizer | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelform/react-native",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Render Grafana-compatible dashboard JSON, and input forms in the same format, as native React Native panels.",
5
5
  "keywords": [
6
6
  "react-native",