@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
package/README.md
CHANGED
|
@@ -109,6 +109,45 @@ metric, and entries of one item share `save` and `item`:
|
|
|
109
109
|
For anything beyond a demo, implement `EntryStore` over your own storage, such as SQLite. Keep each entry's `save` and
|
|
110
110
|
`item` so groups can be read back.
|
|
111
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
|
+
|
|
112
151
|
## Bundled dashboards
|
|
113
152
|
|
|
114
153
|
`modelform dashboards [dir] [--watch]` writes an `index.ts` that imports every `.json` file in a folder, so
|