strata-react 1.3.8 → 1.3.9
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 +2 -1
- package/UPGRADING.md +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +185 -9
- package/dist/index.js.map +1 -1
- package/dist/query/api.d.ts +1 -1
- package/dist/query/clips.d.ts +48 -0
- package/dist/query/reserve.d.ts +33 -0
- package/dist/query/typed-api.d.ts +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -163,9 +163,10 @@ thousands of lines. Such an app imports the same stylesheet **without the reset*
|
|
|
163
163
|
| Density | `Density`, `DensityName`, `ThemeProvider`'s `density`, `ControlSize` (`size="sm"` on `Input`, `NativeSelect`, `NumberField`, `IconButton`) | Control height is two variables, `--control-h` and `--control-h-sm`. `<ThemeProvider density="compact">` or `<Density page value="compact">` sets them app-wide, including dialogs and menus, which portal out of the app's root; `<Density value="compact">` is one region (a toolbar, a dense panel) and does not reach its overlays. A coarse pointer (touch) always gets 44px targets, whatever the density A second look for a region is roles alone: set `--control-h`, `--control-h-sm`, `--control-px`, `--control-px-sm`, `--control-icon` and each type step's `--type-<step>-size`, `-leading` and `-weight` (`caption`, `label`, `body-sm`, `body`, `heading`, `title`, `figure`) on a class; the defaults are today's values. |
|
|
164
164
|
| Workspace | `Workspace`, `Split`, `Pane`, `useWorkspaceState`, `WorkspaceState` | One screen of panes for a tool: splits of panes with a growing stage, a header on every pane (name, actions, fold button), separators that resize by pointer and by keyboard (arrows, Shift, Home, End, Enter to restore) within each pane's `min` and `max`, panes that fold to a rail or header bar with a visible way back (and `state.toggle(id)` from a menu), sizes and folds remembered with `useWorkspaceState("name")`, and stacking below 720px. Each pane is a labelled region |
|
|
165
165
|
| Writes kept while offline | `createOutbox`, `useOutbox`, `useOutboxStarted`, `OutboxStatus`, `isRefusal` | Writes that must not be lost when the connection is (answers in a game played on a tablet whose wifi drops): kept in localStorage (`strata:outbox:<name>`), sent one at a time oldest first, a dependent write (`after`) refused with what it follows; a 4xx is refused and listed with the server's reason until dismissed, anything else (no answer, 5xx, 401/403 from a login, 408, 429) waits and is tried again after 2 s doubling to a minute, at once on `online` or when the page is shown. `add` answers how the first try went (`sent`, `waiting`, `refused`) so a screen goes on without the server. Every write must be idempotent on the server (a client-made id). `OutboxStatus noun="answer"` is the sign: nothing while all is sent, "3 answers kept on this device. The server could not be reached. Trying again at 10:42." with Send now, and the refused list |
|
|
166
|
+
| Items kept for offline | `createReserve`, `useReserve` | The read side of the outbox: items the server made ahead (rounds of play), kept per key in localStorage (`strata:reserve:<name>:<key>`), `size` each. `take(key)` removes and returns the oldest (an item is used once); `refresh(key, fresh)` after a fresh item arrives drops kept items `sameMake(kept, fresh)` calls out of date and tops up in one request when fewer than half remain (one in flight per key; a failure is tried again at the next refresh); `useReserve(reserve, key)` is the count for "6 rounds kept for offline"; `seed` and `clear` for tests and stories. Without storage nothing is kept and `persisted` says so |
|
|
166
167
|
| History and save state | `useHistory`, `useHistoryState`, `History`, `useAutoSave`, `SaveStatus`, `SaveState`, `useLeaveGuard` | Undo and redo for a document edited over a session: a step is a name and an `undo`/`redo` pair, `begin(label)` groups a drag into one step, a `key` merges a slider's pushes, a `limit` drops the oldest. `history.commands` are Undo and Redo as `Command`s ("Undo move clip", Mod+Z, Mod+Shift+Z or Mod+Y) for `useCommands` and `Menu`. `useAutoSave` debounces and never overlaps saves; `SaveStatus` is the fixed-width sign ("Saved 10:42", "Saving…", "Unsaved changes", "Not saved" with the reason and "Try again"), quiet except for a failure and its recovery. For one removal that commits after a few seconds, use `useUndoable` |
|
|
167
168
|
| Links and URL choices | `ButtonLink`, `TextLink`, `useSearchParam`, `NativeSelect param=`, `ChoiceGroup param=`, `ToggleGroup param=` | `ButtonLink` is a link (`to` for a route, `href` for a download) drawn as a `Button` with its variants; it sets `data-variant`, so `variant="default"` is the view's one filled button for `expectOneFilledButton()`. `TextLink` is the house in-app link. Both are React Aria links with React Router navigation. A filter or choice a person would link to is `useSearchParam("mode", { default, parse })` (the default is never written, an invalid value reads as the default, other params are kept, history is replaced), or `param=` on the three controls, as `Tabs` does |
|
|
168
|
-
| Speech | `speak`, `useSpeech`, `SayAgain`, `canSay`, `textOf`, `installFakeSpeech` (`strata-react/testing`) | The browser's `speechSynthesis` with the voice picked by language once voices have loaded, what is being said cancelled by the next prompt, a slightly slow default rate, and nothing where there is no speech or the person muted it. Recorded prompts (`speak(parts)`, `SayAgain parts=`): each part's clip plays in order, and the browser's voice says the words when a part has no clip or one fails (one voice per prompt). `SayAgain`'s name is the sentence it says. `installFakeSpeech()` records what was said and which clips played in a test (`clips()`, `finish()`, `failClip()`) |
|
|
169
|
+
| Speech | `speak`, `useSpeech`, `SayAgain`, `ClipsProvider`, `useClips`, `useSayOnShow`, `canSay`, `textOf`, `installFakeSpeech` (`strata-react/testing`) | The browser's `speechSynthesis` with the voice picked by language once voices have loaded, what is being said cancelled by the next prompt, a slightly slow default rate, and nothing where there is no speech or the person muted it. Recorded prompts (`speak(parts)`, `SayAgain parts=`): each part's clip plays in order, and the browser's voice says the words when a part has no clip or one fails (one voice per prompt). `SayAgain`'s name is the sentence it says. `installFakeSpeech()` records what was said and which clips played in a test (`clips()`, `finish()`, `failClip()`) . `ClipsProvider load=` reads the app's clip list once (a record of line text to URL, read again only when `clipsQueryKey` is invalidated); `useClips()` gives `ready`, `parts(text)`, `say(text)` and `words(text)` (`split` cuts a prompt into lines, `describe` words a line that has no clip), `useSayOnShow(text)` says a prompt once the list has arrived or failed, and `SayAgain` inside the provider needs no `parts` or `lang`; outside it, the browser's voice alone |
|
|
169
170
|
| Recording | `useRecorder`, `InputLevel`, `TakeLevel`, `MicrophoneContext`, `encodeWav`, `fakeMicrophone` (`strata-react/testing`) | One take of speech from the microphone as a lossless 16-bit PCM WAV (an AudioWorklet, not MediaRecorder, which only writes compressed audio), with the browser's echo cancellation, noise suppression and gain off. `start()` resolves with the take when it stops, by `stop()` or at `maxSeconds`. `InputLevel` is the live peak in dBFS with a "Too loud" notch at -3; `TakeLevel` judges the finished take for speech in words. The device comes from `MicrophoneContext`, so tests pass `renderWithStrata(ui, { microphone: fakeMicrophone() })`. The microphone needs a secure page (https or localhost); the refusals read as sentences |
|
|
170
171
|
| Toolbar and toggles | `Toolbar`, `ToolbarSeparator`, `Toggle`, `ToggleGroup`, `Switch` | A toolbar is one tab stop with arrows, Home and End inside; needs a `label`. `Toggle` (`aria-pressed`) and `ToggleGroup` (one of 2 to 7, always one chosen) show chosen as an ink border on a tint, never the filled primary, so they do not break the one-filled-button rule; an icon-only toggle still needs its `label` (shown as a tooltip). `Switch` is only for a setting that applies at once, label and control one target |
|
|
171
172
|
| Commands | `Command`, `useCommands`, `Menu`, `ContextMenu`, `CommandMenu`, `CommandLegend`, `formatChord`, `matchesChord` | A command is declared once (label or label function, chords, `disabled` with a reason, `destructive`, `checked`) and drives the key handler, dropdown and menu-bar menus, the context menu, the searchable command menu (Mod+K) and the legend, so they cannot disagree. Chords are written once ("Mod+Shift+Z") and shown per platform (⇧⌘Z, Ctrl+Shift+Z); they never fire while typing or during IME composition, and a chord the browser keeps (Ctrl+S) needs `claim: true`. `useHotkeys` is unchanged for single keys |
|
package/UPGRADING.md
CHANGED
|
@@ -11,6 +11,10 @@ time. While the version is 0.x, any release may break.
|
|
|
11
11
|
|
|
12
12
|
Every PR that changes what an app sees adds a line here (see `CLAUDE.md`, "Changelog").
|
|
13
13
|
|
|
14
|
+
## 2026-11-24
|
|
15
|
+
- `createApi`'s `post`/`put`/`patch` send a `Blob`, bytes, `FormData`, `URLSearchParams` or a stream as it is (a Blob with its own type as Content-Type); before, any body was `JSON.stringify`ed, so such a body arrived as `{}`. `createTypedApi` takes `body` (not `json`) on an operation whose request body has only a non-JSON media type, so a workaround that went round the typed client through `fetchJson` can be deleted.
|
|
16
|
+
- `SayAgain` inside a `ClipsProvider` takes the recordings of `text` and the provider's `lang` itself; one given `parts` or `lang` is unchanged, and outside a provider nothing changes.
|
|
17
|
+
|
|
14
18
|
## 2026-11-23
|
|
15
19
|
- Speech (#310): `installFakeSpeech()` now also replaces `window.Audio` until `uninstall()`, and each `Spoken` entry has `clip` (null for the browser's voice), so a test that compares a whole entry with `toEqual` adds `clip: null`. `useSpeech().say` takes a sentence or recorded parts; `stopSpeaking()` and unmounting `useSpeech` stop a playing clip too.
|
|
16
20
|
- `ChoiceGrid`'s `marks` type is `ChoiceMarks` (a quiz's three words, or `{ picked }` alone); `createTypedApi`'s POST/PUT/PATCH on an operation with `requestBody?: never` no longer ask for `json`, so a `json: undefined` workaround can be deleted. The request argument is now required when the operation has a required path or query value (a call that left it out compiled and threw at run time); pass `{ path: … }`.
|
package/dist/index.d.ts
CHANGED
|
@@ -80,6 +80,8 @@ export { ThemeProvider, useColorScheme, useSystemColorScheme, ColorSchemeChoice,
|
|
|
80
80
|
export { StrataQueryProvider, createQueryClient, toLoad, staleOf, useLoad, useInfiniteLoad, useJob, isTaskRunning, useWorkflowRun, isWorkflowRunning, type WorkflowRunLike, type WorkflowRunOptions, apiPage, fetchJson, HttpError, describeHttpError, errorPayload, readErrorBody, type DescribeError, type ErrorBody, type FetchJsonOptions, type FetchJsonInit, createApi, createTypedApi, type TypedApi, type Api, type ApiOptions, type ApiPage, type InfiniteLoad, type InfiniteLoadOptions, type Job, type JobOptions, type More, } from './query';
|
|
81
81
|
export { createOutbox, useOutbox, useOutboxStarted, isRefusal, type Outbox, type OutboxOptions, type OutboxRequest, type OutboxItem, type OutboxRefusal, type OutboxSnapshot, type Delivery, } from './query/outbox';
|
|
82
82
|
export { OutboxStatus, type OutboxStatusProps } from './components/outbox-status';
|
|
83
|
+
export { createReserve, useReserve, type Reserve, type ReserveOptions } from './query/reserve';
|
|
84
|
+
export { ClipsProvider, useClips, useSayOnShow, clipsQueryKey, type Clips, type ClipsContext, type ClipsProviderProps, type SayOnShowOptions } from './query/clips';
|
|
83
85
|
export { describeActionError, fieldErrorsOf } from './lib/errors';
|
|
84
86
|
export { appBase, withBase } from './lib/base';
|
|
85
87
|
export { useSearchParam, type SearchParam, type SearchParamOptions } from './lib/search-param';
|
package/dist/index.js
CHANGED
|
@@ -11277,16 +11277,17 @@ function withBase(path, base = appBase()) {
|
|
|
11277
11277
|
return path.startsWith("/") && !path.startsWith("//") ? base + path : path;
|
|
11278
11278
|
}
|
|
11279
11279
|
// src/query/api.ts
|
|
11280
|
+
var isRaw = (body) => typeof Blob !== "undefined" && body instanceof Blob || body instanceof ArrayBuffer || ArrayBuffer.isView(body) || typeof FormData !== "undefined" && body instanceof FormData || body instanceof URLSearchParams || typeof ReadableStream !== "undefined" && body instanceof ReadableStream;
|
|
11280
11281
|
/**
|
|
11281
11282
|
* A small client over `fetchJson` for the app's own server: root-relative paths get the app's base (so it works behind a reverse proxy),
|
|
11282
|
-
* and `post`, `put` and `patch` send their body as JSON. `api.post<Learner>("/api/learners", { nickname })`.
|
|
11283
|
+
* and `post`, `put` and `patch` send their body as JSON (a `Blob`, bytes, `FormData` or a stream is sent as it is, with the Blob's own type). `api.post<Learner>("/api/learners", { nickname })`.
|
|
11283
11284
|
*/
|
|
11284
11285
|
function createApi({ base, ...options } = {}) {
|
|
11285
11286
|
const url = (path) => withBase(path, base ?? appBase());
|
|
11286
11287
|
const send = (method, path, body, init) => fetchJson(url(path), {
|
|
11287
11288
|
...init,
|
|
11288
11289
|
method,
|
|
11289
|
-
...body === void 0 ? {} : { json: body }
|
|
11290
|
+
...body === void 0 ? {} : isRaw(body) ? { body } : { json: body }
|
|
11290
11291
|
}, options);
|
|
11291
11292
|
return {
|
|
11292
11293
|
url,
|
|
@@ -11316,10 +11317,10 @@ function fill(path, values, query) {
|
|
|
11316
11317
|
function createTypedApi(options = {}) {
|
|
11317
11318
|
const api = createApi(options);
|
|
11318
11319
|
const call = (method) => (path, request) => {
|
|
11319
|
-
const { path: values, query, json, ...init } = request ?? {};
|
|
11320
|
+
const { path: values, query, json, body, ...init } = request ?? {};
|
|
11320
11321
|
const target = fill(path, values, query);
|
|
11321
11322
|
const rest = init;
|
|
11322
|
-
return method === "get" ? api.get(target, rest) : method === "delete" ? api.delete(target, rest) : api[method](target, json, rest);
|
|
11323
|
+
return method === "get" ? api.get(target, rest) : method === "delete" ? api.delete(target, rest) : api[method](target, body ?? json, rest);
|
|
11323
11324
|
};
|
|
11324
11325
|
return {
|
|
11325
11326
|
url: api.url,
|
|
@@ -11528,7 +11529,7 @@ function problemOf(error) {
|
|
|
11528
11529
|
}
|
|
11529
11530
|
return "The server could not be reached.";
|
|
11530
11531
|
}
|
|
11531
|
-
function defaultStorage() {
|
|
11532
|
+
function defaultStorage$1() {
|
|
11532
11533
|
try {
|
|
11533
11534
|
const s = window.localStorage;
|
|
11534
11535
|
const probe = "strata:outbox:probe";
|
|
@@ -11545,7 +11546,7 @@ function randomId() {
|
|
|
11545
11546
|
/** A queue of writes kept on the device (localStorage) and sent in order when the server can take them; see `useOutbox` and `OutboxStatus`. */
|
|
11546
11547
|
function createOutbox({ name, send, storage, retryMs = 2e3, maxRetryMs = 6e4 }) {
|
|
11547
11548
|
const key = `strata:outbox:${name}`;
|
|
11548
|
-
const store = storage === void 0 ? defaultStorage() : storage;
|
|
11549
|
+
const store = storage === void 0 ? defaultStorage$1() : storage;
|
|
11549
11550
|
const post = send ?? ((item) => fetchJson(withBase(item.path, appBase()), {
|
|
11550
11551
|
method: item.method,
|
|
11551
11552
|
json: item.json
|
|
@@ -11812,6 +11813,104 @@ function OutboxStatus({ outbox, noun, className }) {
|
|
|
11812
11813
|
})]
|
|
11813
11814
|
});
|
|
11814
11815
|
}
|
|
11816
|
+
// src/query/reserve.ts
|
|
11817
|
+
function defaultStorage() {
|
|
11818
|
+
try {
|
|
11819
|
+
const s = window.localStorage;
|
|
11820
|
+
const probe = "strata:reserve:probe";
|
|
11821
|
+
s.setItem(probe, "1");
|
|
11822
|
+
s.removeItem(probe);
|
|
11823
|
+
return s;
|
|
11824
|
+
} catch {
|
|
11825
|
+
return null;
|
|
11826
|
+
}
|
|
11827
|
+
}
|
|
11828
|
+
/** Items the server made ahead, kept on the device (localStorage) and used once each; see `useReserve`. */
|
|
11829
|
+
function createReserve({ name, size, fetch, sameMake = () => true, storage }) {
|
|
11830
|
+
const prefix = `strata:reserve:${name}:`;
|
|
11831
|
+
const store = storage === void 0 ? defaultStorage() : storage;
|
|
11832
|
+
let persisted = store !== null;
|
|
11833
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
11834
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
11835
|
+
const latest = /* @__PURE__ */ new Map();
|
|
11836
|
+
const changed = () => {
|
|
11837
|
+
for (const l of listeners) l();
|
|
11838
|
+
};
|
|
11839
|
+
const read = (key) => {
|
|
11840
|
+
if (!persisted || !store) return [];
|
|
11841
|
+
try {
|
|
11842
|
+
const raw = JSON.parse(store.getItem(prefix + key) ?? "null");
|
|
11843
|
+
return Array.isArray(raw) ? raw : [];
|
|
11844
|
+
} catch {
|
|
11845
|
+
return [];
|
|
11846
|
+
}
|
|
11847
|
+
};
|
|
11848
|
+
const write = (key, items) => {
|
|
11849
|
+
if (persisted && store) try {
|
|
11850
|
+
if (items.length) store.setItem(prefix + key, JSON.stringify(items.slice(0, size)));
|
|
11851
|
+
else store.removeItem(prefix + key);
|
|
11852
|
+
} catch {
|
|
11853
|
+
persisted = false;
|
|
11854
|
+
}
|
|
11855
|
+
changed();
|
|
11856
|
+
};
|
|
11857
|
+
return {
|
|
11858
|
+
take(key) {
|
|
11859
|
+
const items = read(key);
|
|
11860
|
+
const [next, ...rest] = items;
|
|
11861
|
+
if (items.length === 0) return void 0;
|
|
11862
|
+
write(key, rest);
|
|
11863
|
+
return next;
|
|
11864
|
+
},
|
|
11865
|
+
async refresh(key, fresh) {
|
|
11866
|
+
latest.set(key, fresh);
|
|
11867
|
+
const current = read(key);
|
|
11868
|
+
const kept = current.filter((item) => sameMake(item, fresh));
|
|
11869
|
+
if (kept.length !== current.length) write(key, kept);
|
|
11870
|
+
if (kept.length * 2 >= size || inFlight.has(key)) return;
|
|
11871
|
+
inFlight.add(key);
|
|
11872
|
+
try {
|
|
11873
|
+
const more = await fetch(key, size - kept.length);
|
|
11874
|
+
const now = read(key);
|
|
11875
|
+
write(key, [...now, ...more.filter((item) => sameMake(item, latest.get(key)))].slice(0, size));
|
|
11876
|
+
} catch {} finally {
|
|
11877
|
+
inFlight.delete(key);
|
|
11878
|
+
}
|
|
11879
|
+
},
|
|
11880
|
+
kept: (key) => read(key).length,
|
|
11881
|
+
get persisted() {
|
|
11882
|
+
return persisted;
|
|
11883
|
+
},
|
|
11884
|
+
seed(key, items) {
|
|
11885
|
+
write(key, items);
|
|
11886
|
+
},
|
|
11887
|
+
clear(key) {
|
|
11888
|
+
if (key !== void 0) return write(key, []);
|
|
11889
|
+
if (persisted && store) try {
|
|
11890
|
+
for (const k of Object.keys(store).filter((k) => k.startsWith(prefix))) store.removeItem(k);
|
|
11891
|
+
} catch {
|
|
11892
|
+
persisted = false;
|
|
11893
|
+
}
|
|
11894
|
+
changed();
|
|
11895
|
+
},
|
|
11896
|
+
subscribe(listener) {
|
|
11897
|
+
listeners.add(listener);
|
|
11898
|
+
return () => listeners.delete(listener);
|
|
11899
|
+
}
|
|
11900
|
+
};
|
|
11901
|
+
}
|
|
11902
|
+
/** How many items `reserve` keeps for `key`, re-rendering as they are taken, topped up or changed by another tab: "6 rounds kept for offline". */
|
|
11903
|
+
function useReserve(reserve, key) {
|
|
11904
|
+
const subscribe = React.useCallback((listener) => {
|
|
11905
|
+
const stop = reserve.subscribe(listener);
|
|
11906
|
+
window.addEventListener("storage", listener);
|
|
11907
|
+
return () => {
|
|
11908
|
+
stop();
|
|
11909
|
+
window.removeEventListener("storage", listener);
|
|
11910
|
+
};
|
|
11911
|
+
}, [reserve]);
|
|
11912
|
+
return React.useSyncExternalStore(subscribe, () => reserve.kept(key), () => 0);
|
|
11913
|
+
}
|
|
11815
11914
|
// src/lib/speech.ts
|
|
11816
11915
|
var partsOf = (saying) => (typeof saying === "string" ? [{ text: saying }] : [...saying]).filter((p) => p.text.trim() || p.clip);
|
|
11817
11916
|
/** The words of what is said, as one sentence: what the browser's voice says when a recording is missing, and the button's name. */
|
|
@@ -11954,11 +12053,88 @@ function useSpeech({ lang, rate, muted = false } = {}) {
|
|
|
11954
12053
|
}, [])
|
|
11955
12054
|
};
|
|
11956
12055
|
}
|
|
12056
|
+
// src/query/clips.tsx
|
|
12057
|
+
/** The query key of the clip list: invalidate it after a recording is kept, `queryClient.invalidateQueries({ queryKey: clipsQueryKey })`. */
|
|
12058
|
+
var clipsQueryKey = ["strata", "clips"];
|
|
12059
|
+
var Context$1 = React.createContext({
|
|
12060
|
+
ready: true,
|
|
12061
|
+
parts: (text) => [{
|
|
12062
|
+
text,
|
|
12063
|
+
clip: null
|
|
12064
|
+
}],
|
|
12065
|
+
say: (text) => speak(text),
|
|
12066
|
+
words: (text) => text
|
|
12067
|
+
});
|
|
12068
|
+
/** Reads the app's clip list once and gives `useClips`, `SayAgain` and `useSayOnShow` each line's recording. Put it in the shell, inside the query provider. */
|
|
12069
|
+
function ClipsProvider({ load, lang, split, describe, queryKey = clipsQueryKey, children }) {
|
|
12070
|
+
const list = useLoad({
|
|
12071
|
+
queryKey,
|
|
12072
|
+
queryFn: load,
|
|
12073
|
+
staleTime: Infinity,
|
|
12074
|
+
networkMode: "always"
|
|
12075
|
+
});
|
|
12076
|
+
const clips = list.status === "ready" ? list.data : void 0;
|
|
12077
|
+
const value = React.useMemo(() => {
|
|
12078
|
+
const parts = (text) => (split ? split(text) : [text]).map((line) => line.trim()).filter(Boolean).map((line) => {
|
|
12079
|
+
const url = clips?.[line];
|
|
12080
|
+
return url ? {
|
|
12081
|
+
text: line,
|
|
12082
|
+
clip: withBase(url, appBase())
|
|
12083
|
+
} : {
|
|
12084
|
+
text: describe?.(line) ?? line,
|
|
12085
|
+
clip: null
|
|
12086
|
+
};
|
|
12087
|
+
});
|
|
12088
|
+
return {
|
|
12089
|
+
ready: list.status !== "loading",
|
|
12090
|
+
lang,
|
|
12091
|
+
parts,
|
|
12092
|
+
say: (text) => speak(parts(text), { lang }),
|
|
12093
|
+
words: (text) => textOf(parts(text))
|
|
12094
|
+
};
|
|
12095
|
+
}, [
|
|
12096
|
+
clips,
|
|
12097
|
+
list.status,
|
|
12098
|
+
lang,
|
|
12099
|
+
split,
|
|
12100
|
+
describe
|
|
12101
|
+
]);
|
|
12102
|
+
return /* @__PURE__ */ jsx(Context$1.Provider, {
|
|
12103
|
+
value,
|
|
12104
|
+
children
|
|
12105
|
+
});
|
|
12106
|
+
}
|
|
12107
|
+
/** The app's clips: `const { say, parts, words, ready } = useClips()`. The browser's voice alone outside a `ClipsProvider`. */
|
|
12108
|
+
function useClips() {
|
|
12109
|
+
return React.useContext(Context$1);
|
|
12110
|
+
}
|
|
12111
|
+
/**
|
|
12112
|
+
* Says `text` once when it appears and the clips are `ready`, and again when `text` changes; stops it on unmount so a prompt does not talk
|
|
12113
|
+
* after its screen is gone. `useSayOnShow(question.text)`.
|
|
12114
|
+
*/
|
|
12115
|
+
function useSayOnShow(text, { muted = false } = {}) {
|
|
12116
|
+
const { ready, say } = useClips();
|
|
12117
|
+
const latest = React.useRef(say);
|
|
12118
|
+
latest.current = say;
|
|
12119
|
+
React.useEffect(() => {
|
|
12120
|
+
if (muted || !ready || !text) return;
|
|
12121
|
+
latest.current(text);
|
|
12122
|
+
return () => stopSpeaking();
|
|
12123
|
+
}, [
|
|
12124
|
+
muted,
|
|
12125
|
+
ready,
|
|
12126
|
+
text
|
|
12127
|
+
]);
|
|
12128
|
+
}
|
|
11957
12129
|
// src/components/say-again.tsx
|
|
11958
12130
|
/** An icon button that says one sentence aloud, from its recordings when given, else with the browser's voice; hidden where neither can be heard or it is muted. */
|
|
11959
12131
|
function SayAgain({ text, parts, verb = "Say", className, ...options }) {
|
|
11960
|
-
const
|
|
11961
|
-
const
|
|
12132
|
+
const clips = useClips();
|
|
12133
|
+
const { say, speaking } = useSpeech({
|
|
12134
|
+
...options,
|
|
12135
|
+
lang: options.lang ?? clips.lang
|
|
12136
|
+
});
|
|
12137
|
+
const saying = parts?.length ? parts : clips.parts(text);
|
|
11962
12138
|
if (options.muted || !canSay(saying)) return null;
|
|
11963
12139
|
return /* @__PURE__ */ jsx(IconButton, {
|
|
11964
12140
|
icon: Volume2,
|
|
@@ -17838,6 +18014,6 @@ function FolderPicker({ label, useFolders: useListing, value, onChange, onChoose
|
|
|
17838
18014
|
]
|
|
17839
18015
|
});
|
|
17840
18016
|
}
|
|
17841
|
-
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, Breadcrumb, BulkBar, Button, ButtonLink, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, ContextMenu, Conversation, CursorScope, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, KeysLegend, LEVEL_FLOOR_DB, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, NBSP, NativeSelect, NumberField, OutboxStatus, PageHeader, PairJudge, PairVote, Pane, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, SideNav, Skeleton, Slider, SortableList, SpanActions, SpanStrip, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, Workspace, actualPixelsScale, ancestorsOf, apiPage, appBase, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, clampToRoom, clampViewport, cn, colorSchemeScript, commandShortcut, countMarks, createApi, createFormat, createOutbox, createQueryClient, createTypedApi, crossedThreshold, describeActionError, describeHttpError, describeRegion, detectPlatform, diffWords, differences, drawRect, ease, encodeWav, errorPayload, explainMicrophoneError, fetchJson, fieldErrorsOf, findPage, fitRect, format, formatChord, gainToVolume, geo, gridPoints, gutterOf, inputLevelThresholds, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, labelOf, lerpRect, logScale, loudnessOf, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, noOverlap, normaliseAngle, pageName, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickVoice, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, resample, resamplePeaks, resizeRect, safeHref, sayPosition, serialiseSort, settleCut, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepOnGrid, stopSpeaking, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMicrophone, useOutbox, useOutboxStarted, usePlayerWarnings, useRecorder, useSearchParam, useSelection, useSharedCursor, useSpeech, useSystemColorScheme, useTimelineZoom, useUndoable, useViewOptions, useViewport, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
|
|
18017
|
+
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, Breadcrumb, BulkBar, Button, ButtonLink, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, ContextMenu, Conversation, CursorScope, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, KeysLegend, LEVEL_FLOOR_DB, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, NBSP, NativeSelect, NumberField, OutboxStatus, PageHeader, PairJudge, PairVote, Pane, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, SideNav, Skeleton, Slider, SortableList, SpanActions, SpanStrip, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, Workspace, actualPixelsScale, ancestorsOf, apiPage, appBase, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, clampToRoom, clampViewport, clipsQueryKey, cn, colorSchemeScript, commandShortcut, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createTypedApi, crossedThreshold, describeActionError, describeHttpError, describeRegion, detectPlatform, diffWords, differences, drawRect, ease, encodeWav, errorPayload, explainMicrophoneError, fetchJson, fieldErrorsOf, findPage, fitRect, format, formatChord, gainToVolume, geo, gridPoints, gutterOf, inputLevelThresholds, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, labelOf, lerpRect, logScale, loudnessOf, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, noOverlap, normaliseAngle, pageName, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickVoice, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, resample, resamplePeaks, resizeRect, safeHref, sayPosition, serialiseSort, settleCut, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepOnGrid, stopSpeaking, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useClips, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMicrophone, useOutbox, useOutboxStarted, usePlayerWarnings, useRecorder, useReserve, useSayOnShow, useSearchParam, useSelection, useSharedCursor, useSpeech, useSystemColorScheme, useTimelineZoom, useUndoable, useViewOptions, useViewport, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
|
|
17842
18018
|
|
|
17843
18019
|
//# sourceMappingURL=index.js.map
|