@modelform/react-native 0.13.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.
- package/README.md +24 -0
- package/dist/{chunk-OFXIKI2L.mjs → chunk-72OFPTDE.mjs} +244 -0
- package/dist/{chunk-CU4TMSZE.js → chunk-XWSPLZNC.js} +346 -102
- package/dist/core/formFill.d.ts +89 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +20 -2
- package/dist/core/index.mjs +19 -1
- package/dist/index.js +338 -175
- package/dist/index.mjs +187 -24
- package/dist/ui/inputs/Dictation.d.ts +8 -2
- package/dist/ui/inputs/InputForm.d.ts +8 -1
- package/dist/ui/inputs/VoiceFill.d.ts +28 -0
- package/dist/ui/inputs/formContext.d.ts +2 -0
- package/dist/ui/speech.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -80,6 +80,10 @@ import {
|
|
|
80
80
|
fetchJsonWithToken,
|
|
81
81
|
fieldDisplayName,
|
|
82
82
|
fieldMatches,
|
|
83
|
+
fillForm,
|
|
84
|
+
fillHints,
|
|
85
|
+
fillPrompt,
|
|
86
|
+
fillSchema,
|
|
83
87
|
fixDocumentPrompt,
|
|
84
88
|
fixTemplatePrompt,
|
|
85
89
|
formatClock,
|
|
@@ -131,6 +135,7 @@ import {
|
|
|
131
135
|
mappingRows,
|
|
132
136
|
matchChoices,
|
|
133
137
|
metricChanges,
|
|
138
|
+
modelFiller,
|
|
134
139
|
movePanel,
|
|
135
140
|
newDocument,
|
|
136
141
|
newPanel,
|
|
@@ -152,6 +157,7 @@ import {
|
|
|
152
157
|
parseClockDigits,
|
|
153
158
|
parseDashboardLink,
|
|
154
159
|
parseDuration,
|
|
160
|
+
parseFillAnswer,
|
|
155
161
|
parseGazetteer,
|
|
156
162
|
parseJsonText,
|
|
157
163
|
parseLocalDateTime,
|
|
@@ -172,6 +178,7 @@ import {
|
|
|
172
178
|
queryParam,
|
|
173
179
|
readConfigFiles,
|
|
174
180
|
readDocumentAnswer,
|
|
181
|
+
readFill,
|
|
175
182
|
readTemplateAnswer,
|
|
176
183
|
readingOrder,
|
|
177
184
|
reduce,
|
|
@@ -194,6 +201,8 @@ import {
|
|
|
194
201
|
resolveVariables,
|
|
195
202
|
revalidateBundle,
|
|
196
203
|
rowsToMappings,
|
|
204
|
+
ruleFill,
|
|
205
|
+
ruleFiller,
|
|
197
206
|
sameSave,
|
|
198
207
|
sampleEntries,
|
|
199
208
|
screenDocuments,
|
|
@@ -242,7 +251,7 @@ import {
|
|
|
242
251
|
variableWithType,
|
|
243
252
|
visibleVariables,
|
|
244
253
|
zoomRange
|
|
245
|
-
} from "./chunk-
|
|
254
|
+
} from "./chunk-72OFPTDE.mjs";
|
|
246
255
|
|
|
247
256
|
// src/ui/theme.tsx
|
|
248
257
|
import { createContext, useContext } from "react";
|
|
@@ -1422,6 +1431,15 @@ import { Pressable as Pressable5, StyleSheet as StyleSheet6, Text as Text6 } fro
|
|
|
1422
1431
|
import Svg4, { Path as Path4 } from "react-native-svg";
|
|
1423
1432
|
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1424
1433
|
var listening = null;
|
|
1434
|
+
function stopListening() {
|
|
1435
|
+
listening?.abort();
|
|
1436
|
+
listening = null;
|
|
1437
|
+
}
|
|
1438
|
+
function claimListening(session, done = false) {
|
|
1439
|
+
if (done) {
|
|
1440
|
+
if (listening === session) listening = null;
|
|
1441
|
+
} else listening = session;
|
|
1442
|
+
}
|
|
1425
1443
|
var HINT_MS = 4e3;
|
|
1426
1444
|
function useDictation(panel, value, onChange, choices) {
|
|
1427
1445
|
const form = useInputForm();
|
|
@@ -1450,14 +1468,14 @@ function useDictation(panel, value, onChange, choices) {
|
|
|
1450
1468
|
session.current.stop();
|
|
1451
1469
|
return;
|
|
1452
1470
|
}
|
|
1453
|
-
|
|
1471
|
+
stopListening();
|
|
1454
1472
|
setHint(null);
|
|
1455
1473
|
let mine = null;
|
|
1456
1474
|
let ended = false;
|
|
1457
1475
|
const end = () => {
|
|
1458
1476
|
ended = true;
|
|
1459
1477
|
if (session.current === mine) session.current = null;
|
|
1460
|
-
|
|
1478
|
+
claimListening(mine, true);
|
|
1461
1479
|
setOn(false);
|
|
1462
1480
|
};
|
|
1463
1481
|
try {
|
|
@@ -1481,13 +1499,13 @@ function useDictation(panel, value, onChange, choices) {
|
|
|
1481
1499
|
}
|
|
1482
1500
|
if (!ended) {
|
|
1483
1501
|
session.current = mine;
|
|
1484
|
-
|
|
1502
|
+
claimListening(mine);
|
|
1485
1503
|
setOn(true);
|
|
1486
1504
|
}
|
|
1487
1505
|
};
|
|
1488
1506
|
return { available: !!speech && takesDictation(panel), listening: on, hint, toggle };
|
|
1489
1507
|
}
|
|
1490
|
-
function MicButton({ dictation, title, size = 32 }) {
|
|
1508
|
+
function MicButton({ dictation, title, label, size = 32 }) {
|
|
1491
1509
|
const theme = useDashTheme();
|
|
1492
1510
|
if (!dictation.available) return null;
|
|
1493
1511
|
const on = dictation.listening;
|
|
@@ -1496,7 +1514,7 @@ function MicButton({ dictation, title, size = 32 }) {
|
|
|
1496
1514
|
{
|
|
1497
1515
|
onPress: dictation.toggle,
|
|
1498
1516
|
accessibilityRole: "button",
|
|
1499
|
-
accessibilityLabel: on ? "Stop dictating" : title ? `Dictate ${title}` : "Dictate",
|
|
1517
|
+
accessibilityLabel: on ? "Stop dictating" : label ?? (title ? `Dictate ${title}` : "Dictate"),
|
|
1500
1518
|
accessibilityState: { selected: on },
|
|
1501
1519
|
hitSlop: 6,
|
|
1502
1520
|
style: ({ pressed }) => [
|
|
@@ -4165,11 +4183,13 @@ function PanelCardContent({ panel, width, height, deferred }) {
|
|
|
4165
4183
|
const form = useContext4(InputFormContext);
|
|
4166
4184
|
const problem = group ? form?.group?.(panel)?.problem : isInputPanel(panel) ? form?.problem?.(panel.options.metric) : void 0;
|
|
4167
4185
|
const hasLinks = !!panel.links?.length;
|
|
4168
|
-
const
|
|
4186
|
+
const filled = !group && isInputPanel(panel) && !!form?.filled?.(panel.options.metric);
|
|
4187
|
+
const hasTitle = !!panel.title || hasLinks || !!problem || filled;
|
|
4169
4188
|
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: [
|
|
4189
|
+
return /* @__PURE__ */ jsxs15(View13, { style: [styles15.card, { width, height, backgroundColor: theme.surface, borderColor: filled ? theme.accent : theme.border }, filled && { borderWidth: 2 }], children: [
|
|
4171
4190
|
hasTitle && /* @__PURE__ */ jsxs15(View13, { style: styles15.titleRow, children: [
|
|
4172
4191
|
/* @__PURE__ */ jsx17(Text14, { style: [styles15.title, { color: theme.text }], numberOfLines: 1, children: title }),
|
|
4192
|
+
filled && !problem && /* @__PURE__ */ jsx17(Text14, { style: [styles15.problem, { color: theme.accent }], numberOfLines: 1, children: "From voice" }),
|
|
4173
4193
|
!!problem && /* @__PURE__ */ jsx17(Text14, { style: [styles15.problem, { color: theme.danger }], numberOfLines: 1, accessibilityRole: "alert", children: problem }),
|
|
4174
4194
|
hasLinks && /* @__PURE__ */ jsx17(
|
|
4175
4195
|
Pressable13,
|
|
@@ -4221,7 +4241,7 @@ var styles15 = StyleSheet15.create({
|
|
|
4221
4241
|
});
|
|
4222
4242
|
|
|
4223
4243
|
// src/ui/inputs/InputForm.tsx
|
|
4224
|
-
import { useCallback as useCallback4, useEffect as
|
|
4244
|
+
import { useCallback as useCallback4, useEffect as useEffect6, useMemo as useMemo10, useState as useState14 } from "react";
|
|
4225
4245
|
import { Platform as Platform2, Pressable as Pressable14, StyleSheet as StyleSheet16, Text as Text15, View as View14 } from "react-native";
|
|
4226
4246
|
|
|
4227
4247
|
// src/ui/speech.ts
|
|
@@ -4242,7 +4262,7 @@ function webSpeechRecognizer() {
|
|
|
4242
4262
|
const r = new Recognition();
|
|
4243
4263
|
if (o.lang) r.lang = o.lang;
|
|
4244
4264
|
r.interimResults = true;
|
|
4245
|
-
r.continuous =
|
|
4265
|
+
r.continuous = !!o.continuous;
|
|
4246
4266
|
r.maxAlternatives = 1;
|
|
4247
4267
|
let delivered = false;
|
|
4248
4268
|
let aborted = false;
|
|
@@ -4255,6 +4275,7 @@ function webSpeechRecognizer() {
|
|
|
4255
4275
|
if (!e.results[i].isFinal) final = false;
|
|
4256
4276
|
}
|
|
4257
4277
|
lastText = text.trim();
|
|
4278
|
+
if (o.continuous) final = false;
|
|
4258
4279
|
if (final) delivered = true;
|
|
4259
4280
|
o.onText(lastText, final);
|
|
4260
4281
|
};
|
|
@@ -4285,6 +4306,83 @@ function webSpeechRecognizer() {
|
|
|
4285
4306
|
};
|
|
4286
4307
|
}
|
|
4287
4308
|
|
|
4309
|
+
// src/ui/inputs/VoiceFill.tsx
|
|
4310
|
+
import { useEffect as useEffect5, useRef as useRef7, useState as useState13 } from "react";
|
|
4311
|
+
function useVoiceFill({ speech, lang, filler, form, onFilled, onError }) {
|
|
4312
|
+
const [on, setOn] = useState13(false);
|
|
4313
|
+
const [filling, setFilling] = useState13(false);
|
|
4314
|
+
const [heard, setHeard] = useState13(null);
|
|
4315
|
+
const session = useRef7(null);
|
|
4316
|
+
const alive = useRef7(true);
|
|
4317
|
+
const latest = useRef7({ form, filler, onFilled, onError });
|
|
4318
|
+
useEffect5(() => {
|
|
4319
|
+
latest.current = { form, filler, onFilled, onError };
|
|
4320
|
+
});
|
|
4321
|
+
useEffect5(() => {
|
|
4322
|
+
alive.current = true;
|
|
4323
|
+
return () => {
|
|
4324
|
+
alive.current = false;
|
|
4325
|
+
session.current?.abort();
|
|
4326
|
+
};
|
|
4327
|
+
}, []);
|
|
4328
|
+
const fill = async (said) => {
|
|
4329
|
+
const { form: f, filler: run } = latest.current;
|
|
4330
|
+
if (!run) return;
|
|
4331
|
+
setFilling(true);
|
|
4332
|
+
let result;
|
|
4333
|
+
try {
|
|
4334
|
+
result = await run(f, said);
|
|
4335
|
+
} catch {
|
|
4336
|
+
result = { values: {}, problems: [{ key: "", problem: "Couldn\u2019t fill the form" }] };
|
|
4337
|
+
}
|
|
4338
|
+
if (!alive.current) return;
|
|
4339
|
+
setFilling(false);
|
|
4340
|
+
latest.current.onFilled(result, said);
|
|
4341
|
+
};
|
|
4342
|
+
const toggle = () => {
|
|
4343
|
+
if (!speech || !filler) return;
|
|
4344
|
+
if (session.current) {
|
|
4345
|
+
session.current.stop();
|
|
4346
|
+
return;
|
|
4347
|
+
}
|
|
4348
|
+
stopListening();
|
|
4349
|
+
setHeard(null);
|
|
4350
|
+
let mine = null;
|
|
4351
|
+
let ended = false;
|
|
4352
|
+
const end = () => {
|
|
4353
|
+
ended = true;
|
|
4354
|
+
if (session.current === mine) session.current = null;
|
|
4355
|
+
claimListening(mine, true);
|
|
4356
|
+
if (alive.current) {
|
|
4357
|
+
setOn(false);
|
|
4358
|
+
setHeard(null);
|
|
4359
|
+
}
|
|
4360
|
+
};
|
|
4361
|
+
try {
|
|
4362
|
+
mine = speech.start({
|
|
4363
|
+
lang,
|
|
4364
|
+
hints: fillHints(form),
|
|
4365
|
+
continuous: true,
|
|
4366
|
+
onText(text, final) {
|
|
4367
|
+
if (!final) return setHeard(text || null);
|
|
4368
|
+
if (text.trim()) fill(text.trim());
|
|
4369
|
+
},
|
|
4370
|
+
onError: (message) => alive.current && latest.current.onError(message),
|
|
4371
|
+
onEnd: end
|
|
4372
|
+
});
|
|
4373
|
+
} catch {
|
|
4374
|
+
onError("Dictation couldn\u2019t start");
|
|
4375
|
+
return;
|
|
4376
|
+
}
|
|
4377
|
+
if (!ended) {
|
|
4378
|
+
session.current = mine;
|
|
4379
|
+
claimListening(mine);
|
|
4380
|
+
setOn(true);
|
|
4381
|
+
}
|
|
4382
|
+
};
|
|
4383
|
+
return { available: !!speech && !!filler && form.fields.length > 0, listening: on, filling, heard, toggle };
|
|
4384
|
+
}
|
|
4385
|
+
|
|
4288
4386
|
// src/ui/inputs/InputForm.tsx
|
|
4289
4387
|
import { jsx as jsx18, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
4290
4388
|
var NO_CHOICES = {};
|
|
@@ -4320,20 +4418,23 @@ function baseItems(group, editing, last) {
|
|
|
4320
4418
|
return values.map((v, i) => ({ key: `b${i}`, values: v, edited: [] }));
|
|
4321
4419
|
}
|
|
4322
4420
|
var nextItemKey = 1;
|
|
4323
|
-
function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, timestamp, defaults: given = NO_DEFAULTS, beforeSave, editing, speech: givenSpeech, speechLang }) {
|
|
4421
|
+
function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, timestamp, defaults: given = NO_DEFAULTS, beforeSave, editing, speech: givenSpeech, speechLang, filler = ruleFiller }) {
|
|
4324
4422
|
const speech = givenSpeech === void 0 ? defaultSpeech() : givenSpeech;
|
|
4325
4423
|
const theme = useDashTheme();
|
|
4326
4424
|
const panels = useMemo10(() => plainInputPanels(dashboard), [dashboard]);
|
|
4327
4425
|
const groups = useMemo10(() => inputGroups(dashboard), [dashboard]);
|
|
4328
4426
|
const saved = useMemo10(() => editing ? savedValues(panels, editing) : NO_DEFAULTS, [panels, editing]);
|
|
4329
|
-
const [defaults, setDefaults] =
|
|
4330
|
-
const [edits, setEdits] =
|
|
4331
|
-
const [last, setLast] =
|
|
4332
|
-
const [groupEdits, setGroupEdits] =
|
|
4333
|
-
const [offsetMs, setOffsetMs] =
|
|
4334
|
-
const [status, setStatus] =
|
|
4335
|
-
const [checked, setChecked] =
|
|
4336
|
-
|
|
4427
|
+
const [defaults, setDefaults] = useState14({});
|
|
4428
|
+
const [edits, setEdits] = useState14({});
|
|
4429
|
+
const [last, setLast] = useState14({});
|
|
4430
|
+
const [groupEdits, setGroupEdits] = useState14({});
|
|
4431
|
+
const [offsetMs, setOffsetMs] = useState14(0);
|
|
4432
|
+
const [status, setStatus] = useState14(null);
|
|
4433
|
+
const [checked, setChecked] = useState14(false);
|
|
4434
|
+
const [filled, setFilled] = useState14({});
|
|
4435
|
+
const [beforeFill, setBeforeFill] = useState14(null);
|
|
4436
|
+
const fillable = useMemo10(() => fillForm(dashboard, choices), [dashboard, choices]);
|
|
4437
|
+
useEffect6(() => {
|
|
4337
4438
|
let run = 0;
|
|
4338
4439
|
const load = async () => {
|
|
4339
4440
|
const mine = ++run;
|
|
@@ -4369,8 +4470,15 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
|
|
|
4369
4470
|
setValue: (m, v) => {
|
|
4370
4471
|
setStatus(null);
|
|
4371
4472
|
setEdits((e) => ({ ...e, [m]: v }));
|
|
4473
|
+
setFilled((f) => {
|
|
4474
|
+
if (!(m in f)) return f;
|
|
4475
|
+
const { [m]: _, ...rest } = f;
|
|
4476
|
+
return rest;
|
|
4477
|
+
});
|
|
4478
|
+
setBeforeFill(null);
|
|
4372
4479
|
},
|
|
4373
4480
|
isDirty: (m) => m in edits,
|
|
4481
|
+
filled: (m) => m in filled,
|
|
4374
4482
|
store,
|
|
4375
4483
|
choices,
|
|
4376
4484
|
speech,
|
|
@@ -4384,7 +4492,30 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
|
|
|
4384
4492
|
setGroupEdits((all) => ({ ...all, [groupKey(g)]: update(all[groupKey(g)] ?? base[groupKey(g)] ?? []) }));
|
|
4385
4493
|
})
|
|
4386
4494
|
};
|
|
4387
|
-
}, [edits, saved, defaults, given, store, choices, speech, speechLang, panels, checked, itemsOf, last, groupEdits, base]);
|
|
4495
|
+
}, [edits, saved, defaults, given, store, choices, speech, speechLang, panels, checked, itemsOf, last, groupEdits, base, filled]);
|
|
4496
|
+
const clearFill = () => {
|
|
4497
|
+
setFilled({});
|
|
4498
|
+
setBeforeFill(null);
|
|
4499
|
+
};
|
|
4500
|
+
const onFilled = useCallback4(
|
|
4501
|
+
(result, said) => {
|
|
4502
|
+
const keys = Object.keys(result.values);
|
|
4503
|
+
const label = (key) => fillable.fields.find((f) => f.key === key)?.label ?? key;
|
|
4504
|
+
const problem = result.problems[0];
|
|
4505
|
+
const problemText = problem ? problem.key ? `${label(problem.key)}: ${problem.problem.charAt(0).toLowerCase()}${problem.problem.slice(1)}` : problem.problem : "";
|
|
4506
|
+
if (!keys.length) {
|
|
4507
|
+
setStatus(problem ? `Couldn\u2019t fill. ${problemText}` : `Didn\u2019t catch any fields in \u201C${said}\u201D`);
|
|
4508
|
+
return;
|
|
4509
|
+
}
|
|
4510
|
+
setBeforeFill(edits);
|
|
4511
|
+
setEdits({ ...edits, ...result.values });
|
|
4512
|
+
setFilled(Object.fromEntries(keys.map((k) => [k, true])));
|
|
4513
|
+
const more = result.problems.length > 1 ? ` (+${result.problems.length - 1} more)` : "";
|
|
4514
|
+
setStatus(`Filled ${keys.length} ${keys.length === 1 ? "field" : "fields"}. Check, then Save${problem ? `. ${problemText}${more}` : ""}`);
|
|
4515
|
+
},
|
|
4516
|
+
[fillable, edits]
|
|
4517
|
+
);
|
|
4518
|
+
const voice = useVoiceFill({ speech, lang: speechLang, filler, form: fillable, onFilled, onError: setStatus });
|
|
4388
4519
|
const dirty = Object.keys(edits).length + groups.reduce((n, g) => n + groupChanges(base[groupKey(g)] ?? [], groupEdits[groupKey(g)]), 0);
|
|
4389
4520
|
const recordedGroups = useCallback4(
|
|
4390
4521
|
() => groups.filter((g) => editing || groupKey(g) in groupEdits || groupFields(g).some((f) => f.options.record === "always")),
|
|
@@ -4414,6 +4545,7 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
|
|
|
4414
4545
|
setEdits({});
|
|
4415
4546
|
setGroupEdits({});
|
|
4416
4547
|
setChecked(false);
|
|
4548
|
+
clearFill();
|
|
4417
4549
|
setOffsetMs(0);
|
|
4418
4550
|
setStatus(`Saved ${added.length} ${added.length === 1 ? "value" : "values"}`);
|
|
4419
4551
|
onSaved?.(added.length, added);
|
|
@@ -4423,14 +4555,36 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
|
|
|
4423
4555
|
{
|
|
4424
4556
|
header: header !== void 0 ? header : /* @__PURE__ */ jsx18(TimestampPicker, { offsetMs, onChange: setOffsetMs }),
|
|
4425
4557
|
footer: /* @__PURE__ */ jsxs16(View14, { style: [styles16.footer, { backgroundColor: theme.surface, borderTopColor: theme.border }], children: [
|
|
4426
|
-
/* @__PURE__ */ jsx18(
|
|
4427
|
-
|
|
4558
|
+
voice.available && /* @__PURE__ */ jsx18(MicButton, { dictation: voice, label: "Fill the form by voice", size: 36 }),
|
|
4559
|
+
/* @__PURE__ */ jsx18(
|
|
4560
|
+
Text15,
|
|
4561
|
+
{
|
|
4562
|
+
style: [styles16.status, { color: status?.startsWith("Can\u2019t") || status?.startsWith("Couldn\u2019t") ? theme.danger : theme.textSecondary }],
|
|
4563
|
+
accessibilityLiveRegion: "polite",
|
|
4564
|
+
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")
|
|
4565
|
+
}
|
|
4566
|
+
),
|
|
4567
|
+
beforeFill && /* @__PURE__ */ jsx18(
|
|
4568
|
+
Pressable14,
|
|
4569
|
+
{
|
|
4570
|
+
onPress: () => {
|
|
4571
|
+
setEdits(beforeFill);
|
|
4572
|
+
clearFill();
|
|
4573
|
+
setStatus(null);
|
|
4574
|
+
},
|
|
4575
|
+
style: styles16.secondary,
|
|
4576
|
+
accessibilityRole: "button",
|
|
4577
|
+
children: /* @__PURE__ */ jsx18(Text15, { style: { color: theme.textSecondary, fontWeight: "500" }, children: "Undo" })
|
|
4578
|
+
}
|
|
4579
|
+
),
|
|
4580
|
+
dirty > 0 && !beforeFill && /* @__PURE__ */ jsx18(
|
|
4428
4581
|
Pressable14,
|
|
4429
4582
|
{
|
|
4430
4583
|
onPress: () => {
|
|
4431
4584
|
setEdits({});
|
|
4432
4585
|
setGroupEdits({});
|
|
4433
4586
|
setChecked(false);
|
|
4587
|
+
clearFill();
|
|
4434
4588
|
setStatus(null);
|
|
4435
4589
|
},
|
|
4436
4590
|
style: styles16.secondary,
|
|
@@ -4504,8 +4658,8 @@ async function replace(store, ids, entries) {
|
|
|
4504
4658
|
var HOUR = 36e5;
|
|
4505
4659
|
function TimestampPicker({ offsetMs, onChange }) {
|
|
4506
4660
|
const theme = useDashTheme();
|
|
4507
|
-
const [now, setNow] =
|
|
4508
|
-
|
|
4661
|
+
const [now, setNow] = useState14(() => Date.now());
|
|
4662
|
+
useEffect6(() => {
|
|
4509
4663
|
const id = setInterval(() => setNow(Date.now()), 3e4);
|
|
4510
4664
|
return () => clearInterval(id);
|
|
4511
4665
|
}, []);
|
|
@@ -4630,6 +4784,10 @@ export {
|
|
|
4630
4784
|
fetchJsonWithToken,
|
|
4631
4785
|
fieldDisplayName,
|
|
4632
4786
|
fieldMatches,
|
|
4787
|
+
fillForm,
|
|
4788
|
+
fillHints,
|
|
4789
|
+
fillPrompt,
|
|
4790
|
+
fillSchema,
|
|
4633
4791
|
fixDocumentPrompt,
|
|
4634
4792
|
fixTemplatePrompt,
|
|
4635
4793
|
formatClock,
|
|
@@ -4683,6 +4841,7 @@ export {
|
|
|
4683
4841
|
mappingRows,
|
|
4684
4842
|
matchChoices,
|
|
4685
4843
|
metricChanges,
|
|
4844
|
+
modelFiller,
|
|
4686
4845
|
movePanel,
|
|
4687
4846
|
newDocument,
|
|
4688
4847
|
newPanel,
|
|
@@ -4704,6 +4863,7 @@ export {
|
|
|
4704
4863
|
parseClockDigits,
|
|
4705
4864
|
parseDashboardLink,
|
|
4706
4865
|
parseDuration,
|
|
4866
|
+
parseFillAnswer,
|
|
4707
4867
|
parseGazetteer,
|
|
4708
4868
|
parseJsonText,
|
|
4709
4869
|
parseLocalDateTime,
|
|
@@ -4724,6 +4884,7 @@ export {
|
|
|
4724
4884
|
queryParam,
|
|
4725
4885
|
readConfigFiles,
|
|
4726
4886
|
readDocumentAnswer,
|
|
4887
|
+
readFill,
|
|
4727
4888
|
readTemplateAnswer,
|
|
4728
4889
|
readingOrder,
|
|
4729
4890
|
reduce,
|
|
@@ -4747,6 +4908,8 @@ export {
|
|
|
4747
4908
|
resolveVariables,
|
|
4748
4909
|
revalidateBundle,
|
|
4749
4910
|
rowsToMappings,
|
|
4911
|
+
ruleFill,
|
|
4912
|
+
ruleFiller,
|
|
4750
4913
|
sameSave,
|
|
4751
4914
|
sampleEntries,
|
|
4752
4915
|
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[]>;
|
package/dist/ui/speech.d.ts
CHANGED
|
@@ -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