@modelform/react-native 0.11.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 CHANGED
@@ -13,7 +13,8 @@ same format. One JSON model describes both what an app records and how it charts
13
13
  - **Datasources:** a local one over recorded entries, and a Grafana one that runs panel queries through a Grafana
14
14
  instance's HTTP API. You can also implement your own.
15
15
  - **Configs:** a manifest format for whole apps (tabs, forms and dashboards), with JSON Schemas, validation that
16
- reports issues instead of throwing, and a loader with caching and last-good fallback.
16
+ reports issues instead of throwing, and a loader with caching and last-good fallback. A manifest's `version` is the
17
+ oldest format that can show it; an app older than that gets `needsUpdate` and keeps its last good config.
17
18
  - **AI assistants:** `templatePrompt()` writes a prompt for making a template with any assistant (Claude, ChatGPT…),
18
19
  and `readTemplateAnswer()` reads the template back out of its reply. `documentPrompt()` and `readDocumentAnswer()` do
19
20
  the same for changing one form or dashboard, and `documentChanges()` lists what a change does. Nothing calls a model.
@@ -108,6 +109,45 @@ metric, and entries of one item share `save` and `item`:
108
109
  For anything beyond a demo, implement `EntryStore` over your own storage, such as SQLite. Keep each entry's `save` and
109
110
  `item` so groups can be read back.
110
111
 
112
+ ### Dictation
113
+
114
+ Number, duration, text and choice inputs show a microphone button when the form has a speech recognizer. What's said
115
+ becomes the value ("seventy two point five" → 72.5, "went for a swim" picks Swim), and dictated text is added after a
116
+ multi-line field's text. On the web, the browser's speech recognition is used where there is one (Chrome, Edge,
117
+ Safari; not Firefox). On phones, pass a `SpeechRecognizer`, for example over
118
+ [expo-speech-recognition](https://github.com/jamsch/expo-speech-recognition):
119
+
120
+ ```tsx
121
+ import { ExpoSpeechRecognitionModule } from 'expo-speech-recognition';
122
+ import type { SpeechRecognizer } from '@modelform/react-native';
123
+
124
+ const speech: SpeechRecognizer = {
125
+ start(o) {
126
+ const subs: { remove(): void }[] = [];
127
+ const end = () => {
128
+ subs.forEach((s) => s.remove());
129
+ o.onEnd();
130
+ };
131
+ ExpoSpeechRecognitionModule.requestPermissionsAsync().then(({ granted }) => {
132
+ if (!granted) return o.onError('Microphone access is off'), end();
133
+ subs.push(
134
+ ExpoSpeechRecognitionModule.addListener('result', (e) => o.onText(e.results[0]?.transcript ?? '', e.isFinal)),
135
+ ExpoSpeechRecognitionModule.addListener('error', (e) => e.error !== 'aborted' && o.onError(e.message)),
136
+ ExpoSpeechRecognitionModule.addListener('end', end),
137
+ );
138
+ ExpoSpeechRecognitionModule.start({ lang: o.lang ?? 'en-US', interimResults: true, contextualStrings: o.hints });
139
+ });
140
+ return { stop: () => ExpoSpeechRecognitionModule.stop(), abort: () => ExpoSpeechRecognitionModule.abort() };
141
+ },
142
+ };
143
+
144
+ <InputForm dashboard={form} store={store} speech={speech} />;
145
+ ```
146
+
147
+ `speech={null}` turns dictation off. `spokenValue(panel, text)` and the parsers behind it are exported for filling
148
+ forms by other means. The native recognizer is shared, so a real adapter should also wait for the previous session's
149
+ `end` before starting the next one; otherwise that late event ends the new session too.
150
+
111
151
  ## Bundled dashboards
112
152
 
113
153
  `modelform dashboards [dir] [--watch]` writes an `index.ts` that imports every `.json` file in a folder, so