@modelform/react-native 0.13.0 → 0.15.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/dist/index.mjs CHANGED
@@ -53,6 +53,7 @@ import {
53
53
  bundleRoot,
54
54
  calculateInterval,
55
55
  checkFiles,
56
+ choicesOf,
56
57
  cleanDashboard,
57
58
  cleanPanelOptions,
58
59
  collapseRow,
@@ -80,6 +81,10 @@ import {
80
81
  fetchJsonWithToken,
81
82
  fieldDisplayName,
82
83
  fieldMatches,
84
+ fillForm,
85
+ fillHints,
86
+ fillPrompt,
87
+ fillSchema,
83
88
  fixDocumentPrompt,
84
89
  fixTemplatePrompt,
85
90
  formatClock,
@@ -131,6 +136,7 @@ import {
131
136
  mappingRows,
132
137
  matchChoices,
133
138
  metricChanges,
139
+ modelFiller,
134
140
  movePanel,
135
141
  newDocument,
136
142
  newPanel,
@@ -152,6 +158,7 @@ import {
152
158
  parseClockDigits,
153
159
  parseDashboardLink,
154
160
  parseDuration,
161
+ parseFillAnswer,
155
162
  parseGazetteer,
156
163
  parseJsonText,
157
164
  parseLocalDateTime,
@@ -172,6 +179,7 @@ import {
172
179
  queryParam,
173
180
  readConfigFiles,
174
181
  readDocumentAnswer,
182
+ readFill,
175
183
  readTemplateAnswer,
176
184
  readingOrder,
177
185
  reduce,
@@ -194,6 +202,8 @@ import {
194
202
  resolveVariables,
195
203
  revalidateBundle,
196
204
  rowsToMappings,
205
+ ruleFill,
206
+ ruleFiller,
197
207
  sameSave,
198
208
  sampleEntries,
199
209
  screenDocuments,
@@ -242,7 +252,7 @@ import {
242
252
  variableWithType,
243
253
  visibleVariables,
244
254
  zoomRange
245
- } from "./chunk-OFXIKI2L.mjs";
255
+ } from "./chunk-GWGDDKJE.mjs";
246
256
 
247
257
  // src/ui/theme.tsx
248
258
  import { createContext, useContext } from "react";
@@ -1422,6 +1432,15 @@ import { Pressable as Pressable5, StyleSheet as StyleSheet6, Text as Text6 } fro
1422
1432
  import Svg4, { Path as Path4 } from "react-native-svg";
1423
1433
  import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
1424
1434
  var listening = null;
1435
+ function stopListening() {
1436
+ listening?.abort();
1437
+ listening = null;
1438
+ }
1439
+ function claimListening(session, done = false) {
1440
+ if (done) {
1441
+ if (listening === session) listening = null;
1442
+ } else listening = session;
1443
+ }
1425
1444
  var HINT_MS = 4e3;
1426
1445
  function useDictation(panel, value, onChange, choices) {
1427
1446
  const form = useInputForm();
@@ -1450,14 +1469,14 @@ function useDictation(panel, value, onChange, choices) {
1450
1469
  session.current.stop();
1451
1470
  return;
1452
1471
  }
1453
- listening?.abort();
1472
+ stopListening();
1454
1473
  setHint(null);
1455
1474
  let mine = null;
1456
1475
  let ended = false;
1457
1476
  const end = () => {
1458
1477
  ended = true;
1459
1478
  if (session.current === mine) session.current = null;
1460
- if (listening === mine) listening = null;
1479
+ claimListening(mine, true);
1461
1480
  setOn(false);
1462
1481
  };
1463
1482
  try {
@@ -1481,13 +1500,13 @@ function useDictation(panel, value, onChange, choices) {
1481
1500
  }
1482
1501
  if (!ended) {
1483
1502
  session.current = mine;
1484
- listening = mine;
1503
+ claimListening(mine);
1485
1504
  setOn(true);
1486
1505
  }
1487
1506
  };
1488
1507
  return { available: !!speech && takesDictation(panel), listening: on, hint, toggle };
1489
1508
  }
1490
- function MicButton({ dictation, title, size = 32 }) {
1509
+ function MicButton({ dictation, title, label, size = 32 }) {
1491
1510
  const theme = useDashTheme();
1492
1511
  if (!dictation.available) return null;
1493
1512
  const on = dictation.listening;
@@ -1496,7 +1515,7 @@ function MicButton({ dictation, title, size = 32 }) {
1496
1515
  {
1497
1516
  onPress: dictation.toggle,
1498
1517
  accessibilityRole: "button",
1499
- accessibilityLabel: on ? "Stop dictating" : title ? `Dictate ${title}` : "Dictate",
1518
+ accessibilityLabel: on ? "Stop dictating" : label ?? (title ? `Dictate ${title}` : "Dictate"),
1500
1519
  accessibilityState: { selected: on },
1501
1520
  hitSlop: 6,
1502
1521
  style: ({ pressed }) => [
@@ -4165,11 +4184,13 @@ function PanelCardContent({ panel, width, height, deferred }) {
4165
4184
  const form = useContext4(InputFormContext);
4166
4185
  const problem = group ? form?.group?.(panel)?.problem : isInputPanel(panel) ? form?.problem?.(panel.options.metric) : void 0;
4167
4186
  const hasLinks = !!panel.links?.length;
4168
- const hasTitle = !!panel.title || hasLinks || !!problem;
4187
+ const filled = !group && isInputPanel(panel) && !!form?.filled?.(panel.options.metric);
4188
+ const hasTitle = !!panel.title || hasLinks || !!problem || filled;
4169
4189
  const title = panel.title ? interpolate(panel.title, { values: variables, info: variableInfo2, scoped: panel.scopedVars, timezone: dashboard.timezone }) : "";
4170
- return /* @__PURE__ */ jsxs15(View13, { style: [styles15.card, { width, height, backgroundColor: theme.surface, borderColor: theme.border }], children: [
4190
+ return /* @__PURE__ */ jsxs15(View13, { style: [styles15.card, { width, height, backgroundColor: theme.surface, borderColor: filled ? theme.accent : theme.border }, filled && { borderWidth: 2 }], children: [
4171
4191
  hasTitle && /* @__PURE__ */ jsxs15(View13, { style: styles15.titleRow, children: [
4172
4192
  /* @__PURE__ */ jsx17(Text14, { style: [styles15.title, { color: theme.text }], numberOfLines: 1, children: title }),
4193
+ filled && !problem && /* @__PURE__ */ jsx17(Text14, { style: [styles15.problem, { color: theme.accent }], numberOfLines: 1, children: "From voice" }),
4173
4194
  !!problem && /* @__PURE__ */ jsx17(Text14, { style: [styles15.problem, { color: theme.danger }], numberOfLines: 1, accessibilityRole: "alert", children: problem }),
4174
4195
  hasLinks && /* @__PURE__ */ jsx17(
4175
4196
  Pressable13,
@@ -4221,7 +4242,7 @@ var styles15 = StyleSheet15.create({
4221
4242
  });
4222
4243
 
4223
4244
  // src/ui/inputs/InputForm.tsx
4224
- import { useCallback as useCallback4, useEffect as useEffect5, useMemo as useMemo10, useState as useState13 } from "react";
4245
+ import { useCallback as useCallback4, useEffect as useEffect6, useMemo as useMemo10, useState as useState14 } from "react";
4225
4246
  import { Platform as Platform2, Pressable as Pressable14, StyleSheet as StyleSheet16, Text as Text15, View as View14 } from "react-native";
4226
4247
 
4227
4248
  // src/ui/speech.ts
@@ -4242,7 +4263,7 @@ function webSpeechRecognizer() {
4242
4263
  const r = new Recognition();
4243
4264
  if (o.lang) r.lang = o.lang;
4244
4265
  r.interimResults = true;
4245
- r.continuous = false;
4266
+ r.continuous = !!o.continuous;
4246
4267
  r.maxAlternatives = 1;
4247
4268
  let delivered = false;
4248
4269
  let aborted = false;
@@ -4255,6 +4276,7 @@ function webSpeechRecognizer() {
4255
4276
  if (!e.results[i].isFinal) final = false;
4256
4277
  }
4257
4278
  lastText = text.trim();
4279
+ if (o.continuous) final = false;
4258
4280
  if (final) delivered = true;
4259
4281
  o.onText(lastText, final);
4260
4282
  };
@@ -4285,6 +4307,83 @@ function webSpeechRecognizer() {
4285
4307
  };
4286
4308
  }
4287
4309
 
4310
+ // src/ui/inputs/VoiceFill.tsx
4311
+ import { useEffect as useEffect5, useRef as useRef7, useState as useState13 } from "react";
4312
+ function useVoiceFill({ speech, lang, filler, form, onFilled, onError }) {
4313
+ const [on, setOn] = useState13(false);
4314
+ const [filling, setFilling] = useState13(false);
4315
+ const [heard, setHeard] = useState13(null);
4316
+ const session = useRef7(null);
4317
+ const alive = useRef7(true);
4318
+ const latest = useRef7({ form, filler, onFilled, onError });
4319
+ useEffect5(() => {
4320
+ latest.current = { form, filler, onFilled, onError };
4321
+ });
4322
+ useEffect5(() => {
4323
+ alive.current = true;
4324
+ return () => {
4325
+ alive.current = false;
4326
+ session.current?.abort();
4327
+ };
4328
+ }, []);
4329
+ const fill = async (said) => {
4330
+ const { form: f, filler: run } = latest.current;
4331
+ if (!run) return;
4332
+ setFilling(true);
4333
+ let result;
4334
+ try {
4335
+ result = await run(f, said);
4336
+ } catch {
4337
+ result = { values: {}, problems: [{ key: "", problem: "Couldn\u2019t fill the form" }] };
4338
+ }
4339
+ if (!alive.current) return;
4340
+ setFilling(false);
4341
+ latest.current.onFilled(result, said);
4342
+ };
4343
+ const toggle = () => {
4344
+ if (!speech || !filler) return;
4345
+ if (session.current) {
4346
+ session.current.stop();
4347
+ return;
4348
+ }
4349
+ stopListening();
4350
+ setHeard(null);
4351
+ let mine = null;
4352
+ let ended = false;
4353
+ const end = () => {
4354
+ ended = true;
4355
+ if (session.current === mine) session.current = null;
4356
+ claimListening(mine, true);
4357
+ if (alive.current) {
4358
+ setOn(false);
4359
+ setHeard(null);
4360
+ }
4361
+ };
4362
+ try {
4363
+ mine = speech.start({
4364
+ lang,
4365
+ hints: fillHints(form),
4366
+ continuous: true,
4367
+ onText(text, final) {
4368
+ if (!final) return setHeard(text || null);
4369
+ if (text.trim()) fill(text.trim());
4370
+ },
4371
+ onError: (message) => alive.current && latest.current.onError(message),
4372
+ onEnd: end
4373
+ });
4374
+ } catch {
4375
+ onError("Dictation couldn\u2019t start");
4376
+ return;
4377
+ }
4378
+ if (!ended) {
4379
+ session.current = mine;
4380
+ claimListening(mine);
4381
+ setOn(true);
4382
+ }
4383
+ };
4384
+ return { available: !!speech && !!filler && form.fields.length > 0, listening: on, filling, heard, toggle };
4385
+ }
4386
+
4288
4387
  // src/ui/inputs/InputForm.tsx
4289
4388
  import { jsx as jsx18, jsxs as jsxs16 } from "react/jsx-runtime";
4290
4389
  var NO_CHOICES = {};
@@ -4320,20 +4419,23 @@ function baseItems(group, editing, last) {
4320
4419
  return values.map((v, i) => ({ key: `b${i}`, values: v, edited: [] }));
4321
4420
  }
4322
4421
  var nextItemKey = 1;
4323
- function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, timestamp, defaults: given = NO_DEFAULTS, beforeSave, editing, speech: givenSpeech, speechLang }) {
4422
+ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, timestamp, defaults: given = NO_DEFAULTS, beforeSave, editing, speech: givenSpeech, speechLang, filler = ruleFiller }) {
4324
4423
  const speech = givenSpeech === void 0 ? defaultSpeech() : givenSpeech;
4325
4424
  const theme = useDashTheme();
4326
4425
  const panels = useMemo10(() => plainInputPanels(dashboard), [dashboard]);
4327
4426
  const groups = useMemo10(() => inputGroups(dashboard), [dashboard]);
4328
4427
  const saved = useMemo10(() => editing ? savedValues(panels, editing) : NO_DEFAULTS, [panels, editing]);
4329
- const [defaults, setDefaults] = useState13({});
4330
- const [edits, setEdits] = useState13({});
4331
- const [last, setLast] = useState13({});
4332
- const [groupEdits, setGroupEdits] = useState13({});
4333
- const [offsetMs, setOffsetMs] = useState13(0);
4334
- const [status, setStatus] = useState13(null);
4335
- const [checked, setChecked] = useState13(false);
4336
- useEffect5(() => {
4428
+ const [defaults, setDefaults] = useState14({});
4429
+ const [edits, setEdits] = useState14({});
4430
+ const [last, setLast] = useState14({});
4431
+ const [groupEdits, setGroupEdits] = useState14({});
4432
+ const [offsetMs, setOffsetMs] = useState14(0);
4433
+ const [status, setStatus] = useState14(null);
4434
+ const [checked, setChecked] = useState14(false);
4435
+ const [filled, setFilled] = useState14({});
4436
+ const [beforeFill, setBeforeFill] = useState14(null);
4437
+ const fillable = useMemo10(() => fillForm(dashboard, choices), [dashboard, choices]);
4438
+ useEffect6(() => {
4337
4439
  let run = 0;
4338
4440
  const load = async () => {
4339
4441
  const mine = ++run;
@@ -4369,8 +4471,15 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
4369
4471
  setValue: (m, v) => {
4370
4472
  setStatus(null);
4371
4473
  setEdits((e) => ({ ...e, [m]: v }));
4474
+ setFilled((f) => {
4475
+ if (!(m in f)) return f;
4476
+ const { [m]: _, ...rest } = f;
4477
+ return rest;
4478
+ });
4479
+ setBeforeFill(null);
4372
4480
  },
4373
4481
  isDirty: (m) => m in edits,
4482
+ filled: (m) => m in filled,
4374
4483
  store,
4375
4484
  choices,
4376
4485
  speech,
@@ -4384,7 +4493,30 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
4384
4493
  setGroupEdits((all) => ({ ...all, [groupKey(g)]: update(all[groupKey(g)] ?? base[groupKey(g)] ?? []) }));
4385
4494
  })
4386
4495
  };
4387
- }, [edits, saved, defaults, given, store, choices, speech, speechLang, panels, checked, itemsOf, last, groupEdits, base]);
4496
+ }, [edits, saved, defaults, given, store, choices, speech, speechLang, panels, checked, itemsOf, last, groupEdits, base, filled]);
4497
+ const clearFill = () => {
4498
+ setFilled({});
4499
+ setBeforeFill(null);
4500
+ };
4501
+ const onFilled = useCallback4(
4502
+ (result, said) => {
4503
+ const keys = Object.keys(result.values);
4504
+ const label = (key) => fillable.fields.find((f) => f.key === key)?.label ?? key;
4505
+ const problem = result.problems[0];
4506
+ const problemText = problem ? problem.key ? `${label(problem.key)}: ${problem.problem.charAt(0).toLowerCase()}${problem.problem.slice(1)}` : problem.problem : "";
4507
+ if (!keys.length) {
4508
+ setStatus(problem ? `Couldn\u2019t fill. ${problemText}` : `Didn\u2019t catch any fields in \u201C${said}\u201D`);
4509
+ return;
4510
+ }
4511
+ setBeforeFill(edits);
4512
+ setEdits({ ...edits, ...result.values });
4513
+ setFilled(Object.fromEntries(keys.map((k) => [k, true])));
4514
+ const more = result.problems.length > 1 ? ` (+${result.problems.length - 1} more)` : "";
4515
+ setStatus(`Filled ${keys.length} ${keys.length === 1 ? "field" : "fields"}. Check, then Save${problem ? `. ${problemText}${more}` : ""}`);
4516
+ },
4517
+ [fillable, edits]
4518
+ );
4519
+ const voice = useVoiceFill({ speech, lang: speechLang, filler, form: fillable, onFilled, onError: setStatus });
4388
4520
  const dirty = Object.keys(edits).length + groups.reduce((n, g) => n + groupChanges(base[groupKey(g)] ?? [], groupEdits[groupKey(g)]), 0);
4389
4521
  const recordedGroups = useCallback4(
4390
4522
  () => groups.filter((g) => editing || groupKey(g) in groupEdits || groupFields(g).some((f) => f.options.record === "always")),
@@ -4414,6 +4546,7 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
4414
4546
  setEdits({});
4415
4547
  setGroupEdits({});
4416
4548
  setChecked(false);
4549
+ clearFill();
4417
4550
  setOffsetMs(0);
4418
4551
  setStatus(`Saved ${added.length} ${added.length === 1 ? "value" : "values"}`);
4419
4552
  onSaved?.(added.length, added);
@@ -4423,14 +4556,36 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
4423
4556
  {
4424
4557
  header: header !== void 0 ? header : /* @__PURE__ */ jsx18(TimestampPicker, { offsetMs, onChange: setOffsetMs }),
4425
4558
  footer: /* @__PURE__ */ jsxs16(View14, { style: [styles16.footer, { backgroundColor: theme.surface, borderTopColor: theme.border }], children: [
4426
- /* @__PURE__ */ jsx18(Text15, { style: [styles16.status, { color: status?.startsWith("Can\u2019t") ? theme.danger : theme.textSecondary }], children: status ?? (dirty ? `${dirty} unsaved ${dirty === 1 ? "change" : "changes"}` : "Nothing to save") }),
4427
- dirty > 0 && /* @__PURE__ */ jsx18(
4559
+ voice.available && /* @__PURE__ */ jsx18(MicButton, { dictation: voice, label: "Fill the form by voice", size: 36 }),
4560
+ /* @__PURE__ */ jsx18(
4561
+ Text15,
4562
+ {
4563
+ style: [styles16.status, { color: status?.startsWith("Can\u2019t") || status?.startsWith("Couldn\u2019t") ? theme.danger : theme.textSecondary }],
4564
+ accessibilityLiveRegion: "polite",
4565
+ children: voice.listening ? voice.heard ? `\u201C${voice.heard}\u201D` : "Listening\u2026 say each field\u2019s name and its value, then tap to stop" : voice.filling ? "Filling\u2026" : status ?? (dirty ? `${dirty} unsaved ${dirty === 1 ? "change" : "changes"}` : "Nothing to save")
4566
+ }
4567
+ ),
4568
+ beforeFill && /* @__PURE__ */ jsx18(
4569
+ Pressable14,
4570
+ {
4571
+ onPress: () => {
4572
+ setEdits(beforeFill);
4573
+ clearFill();
4574
+ setStatus(null);
4575
+ },
4576
+ style: styles16.secondary,
4577
+ accessibilityRole: "button",
4578
+ children: /* @__PURE__ */ jsx18(Text15, { style: { color: theme.textSecondary, fontWeight: "500" }, children: "Undo" })
4579
+ }
4580
+ ),
4581
+ dirty > 0 && !beforeFill && /* @__PURE__ */ jsx18(
4428
4582
  Pressable14,
4429
4583
  {
4430
4584
  onPress: () => {
4431
4585
  setEdits({});
4432
4586
  setGroupEdits({});
4433
4587
  setChecked(false);
4588
+ clearFill();
4434
4589
  setStatus(null);
4435
4590
  },
4436
4591
  style: styles16.secondary,
@@ -4504,8 +4659,8 @@ async function replace(store, ids, entries) {
4504
4659
  var HOUR = 36e5;
4505
4660
  function TimestampPicker({ offsetMs, onChange }) {
4506
4661
  const theme = useDashTheme();
4507
- const [now, setNow] = useState13(() => Date.now());
4508
- useEffect5(() => {
4662
+ const [now, setNow] = useState14(() => Date.now());
4663
+ useEffect6(() => {
4509
4664
  const id = setInterval(() => setNow(Date.now()), 3e4);
4510
4665
  return () => clearInterval(id);
4511
4666
  }, []);
@@ -4602,6 +4757,7 @@ export {
4602
4757
  bundleRoot,
4603
4758
  calculateInterval,
4604
4759
  checkFiles,
4760
+ choicesOf,
4605
4761
  cleanDashboard,
4606
4762
  cleanPanelOptions,
4607
4763
  collapseRow,
@@ -4630,6 +4786,10 @@ export {
4630
4786
  fetchJsonWithToken,
4631
4787
  fieldDisplayName,
4632
4788
  fieldMatches,
4789
+ fillForm,
4790
+ fillHints,
4791
+ fillPrompt,
4792
+ fillSchema,
4633
4793
  fixDocumentPrompt,
4634
4794
  fixTemplatePrompt,
4635
4795
  formatClock,
@@ -4683,6 +4843,7 @@ export {
4683
4843
  mappingRows,
4684
4844
  matchChoices,
4685
4845
  metricChanges,
4846
+ modelFiller,
4686
4847
  movePanel,
4687
4848
  newDocument,
4688
4849
  newPanel,
@@ -4704,6 +4865,7 @@ export {
4704
4865
  parseClockDigits,
4705
4866
  parseDashboardLink,
4706
4867
  parseDuration,
4868
+ parseFillAnswer,
4707
4869
  parseGazetteer,
4708
4870
  parseJsonText,
4709
4871
  parseLocalDateTime,
@@ -4724,6 +4886,7 @@ export {
4724
4886
  queryParam,
4725
4887
  readConfigFiles,
4726
4888
  readDocumentAnswer,
4889
+ readFill,
4727
4890
  readTemplateAnswer,
4728
4891
  readingOrder,
4729
4892
  reduce,
@@ -4747,6 +4910,8 @@ export {
4747
4910
  resolveVariables,
4748
4911
  revalidateBundle,
4749
4912
  rowsToMappings,
4913
+ ruleFill,
4914
+ ruleFiller,
4750
4915
  sameSave,
4751
4916
  sampleEntries,
4752
4917
  screenDocuments,
@@ -1,4 +1,9 @@
1
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;
2
7
  export interface Dictation {
3
8
  /** Whether this input can be dictated into here: it takes dictation and the form has a recognizer. */
4
9
  available: boolean;
@@ -13,9 +18,10 @@ export interface Dictation {
13
18
  */
14
19
  export declare function useDictation(panel: InputPanel, value: InputValue, onChange: (v: InputValue) => void, choices?: InputChoice[]): Dictation;
15
20
  /** The microphone button beside an input. Filled while listening; tap again to stop. */
16
- export declare function MicButton({ dictation, title, size }: {
17
- dictation: Dictation;
21
+ export declare function MicButton({ dictation, title, label, size }: {
22
+ dictation: Pick<Dictation, 'available' | 'listening' | 'toggle'>;
18
23
  title?: string;
24
+ label?: string;
19
25
  size?: number;
20
26
  }): import("react").JSX.Element | null;
21
27
  /** What's being heard, or why it couldn't be used, under the input. Nothing when there's nothing to say. */
@@ -1,5 +1,6 @@
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';
5
6
  import { type SpeechRecognizer } from '../speech';
@@ -36,10 +37,16 @@ export interface InputFormProps {
36
37
  speech?: SpeechRecognizer | null;
37
38
  /** Language to dictate in (BCP-47); the recognizer's default when missing. */
38
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;
39
46
  }
40
47
  /**
41
48
  * A data entry form laid out from dashboard JSON with input-* panels. Edited values are
42
49
  * staged until Save, then recorded together at the chosen timestamp, along with any
43
50
  * `record: "always"` inputs. Counters record immediately on tap.
44
51
  */
45
- export declare function InputForm({ dashboard, store, onSaved, choices, header, timestamp, defaults: given, beforeSave, editing, speech: givenSpeech, speechLang }: 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 {};
@@ -5,6 +5,8 @@ export interface InputFormState {
5
5
  value(metric: string): InputValue;
6
6
  setValue(metric: string, v: InputValue): void;
7
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;
8
10
  store: EntryStore;
9
11
  /** Runtime choice lists for input-select panels with `choicesFrom`. */
10
12
  choices: Record<string, InputChoice[]>;
@@ -8,6 +8,11 @@ export interface DictationOptions {
8
8
  lang?: string;
9
9
  /** Words likely to be said, such as choice labels, for recognizers that take hints. */
10
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;
11
16
  /** What's been heard so far. Called with `final` once, when the phrase is done. */
12
17
  onText(text: string, final: boolean): void;
13
18
  /** Something went wrong, in words to show the user. Not called when stopped or aborted. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelform/react-native",
3
- "version": "0.13.0",
3
+ "version": "0.15.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",