strata-react 1.3.25 → 1.3.27
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 +1 -0
- package/UPGRADING.md +4 -0
- package/dist/{api-types/cli.d.ts → api-types-cli.d.ts} +1 -0
- package/dist/api-types-cli.js +4 -3
- package/dist/api-types-cli.js.map +1 -1
- package/dist/{api-types/generate.d.ts → api-types.d.ts} +3 -3
- package/dist/api-types.js +3 -1
- package/dist/{button-KGJI6jQr.js → button-CYXjU-fs.js} +8 -5
- package/dist/button-CYXjU-fs.js.map +1 -0
- package/dist/{cursor-DDGBPiTJ.js → cursor-Cwyvgwsw.js} +9 -7
- package/dist/cursor-Cwyvgwsw.js.map +1 -0
- package/dist/{errors-BUvY1Z4d.js → errors-CmuwcWlb.js} +6 -6
- package/dist/{errors-BUvY1Z4d.js.map → errors-CmuwcWlb.js.map} +1 -1
- package/dist/{field-BjeE_FeB.js → field-DBCsFIng.js} +27 -23
- package/dist/field-DBCsFIng.js.map +1 -0
- package/dist/{follow-BTPs49FP.js → follow-CXQsL86O.js} +2 -2
- package/dist/follow-CXQsL86O.js.map +1 -0
- package/dist/{generate-CjTHKJ39.js → generate-BkWhh4k4.js} +8 -6
- package/dist/generate-BkWhh4k4.js.map +1 -0
- package/dist/{lib/geo.d.ts → geo-DfKa9JtK.d.ts} +35 -33
- package/dist/{hls/index.d.ts → hls.d.ts} +13 -12
- package/dist/hls.js +5 -4
- package/dist/hls.js.map +1 -1
- package/dist/index.d.ts +5401 -142
- package/dist/index.js +1072 -227
- package/dist/index.js.map +1 -1
- package/dist/map.d.ts +184 -0
- package/dist/map.js +21 -17
- package/dist/map.js.map +1 -1
- package/dist/media-player-BETa3P7K.d.ts +758 -0
- package/dist/{microphone-Bo3WaXgD.js → microphone-76skMt6i.js} +41 -30
- package/dist/microphone-76skMt6i.js.map +1 -0
- package/dist/microphone-DDOnQHxf.d.ts +237 -0
- package/dist/{migrate/cli.d.ts → migrate-cli.d.ts} +1 -0
- package/dist/migrate-cli.js +8 -6
- package/dist/migrate-cli.js.map +1 -1
- package/dist/panorama.d.ts +102 -0
- package/dist/panorama.js +18 -15
- package/dist/panorama.js.map +1 -1
- package/dist/{run-BT2WKzMz.js → run-D_Ic1jE7.js} +23 -16
- package/dist/run-D_Ic1jE7.js.map +1 -0
- package/dist/scene.d.ts +147 -0
- package/dist/scene.js +15 -13
- package/dist/scene.js.map +1 -1
- package/dist/testing.d.ts +468 -0
- package/dist/testing.js +11 -3
- package/dist/testing.js.map +1 -1
- package/dist/{theme-CxYZkUNk.js → theme-1oOSMj_D.js} +19 -17
- package/dist/theme-1oOSMj_D.js.map +1 -0
- package/dist/{tooltip-DhqrDtyu.js → tooltip-BosfsWYh.js} +9 -6
- package/dist/tooltip-BosfsWYh.js.map +1 -0
- package/dist/types-B3TsF0Ey.d.ts +241 -0
- package/dist/{value-controls-Dm_EYfZW.js → value-controls-5u7sD_wG.js} +22 -17
- package/dist/value-controls-5u7sD_wG.js.map +1 -0
- package/dist/{viewer-input-CHU0Hx4A.js → viewer-input-3Qa-o35k.js} +3 -2
- package/dist/{viewer-input-CHU0Hx4A.js.map → viewer-input-3Qa-o35k.js.map} +1 -1
- package/dist/{visual/cli.d.ts → visual-cli.d.ts} +2 -1
- package/dist/visual-cli.js +5 -4
- package/dist/visual-cli.js.map +1 -1
- package/dist/visual.d.ts +105 -0
- package/dist/visual.js +4 -3
- package/dist/visual.js.map +1 -1
- package/package.json +24 -19
- package/dist/api-types/index.d.ts +0 -1
- package/dist/button-KGJI6jQr.js.map +0 -1
- package/dist/components/active-list.d.ts +0 -46
- package/dist/components/alert.d.ts +0 -17
- package/dist/components/app-shell.d.ts +0 -32
- package/dist/components/async-button.d.ts +0 -48
- package/dist/components/auto-recorder.d.ts +0 -67
- package/dist/components/book-viewer.d.ts +0 -50
- package/dist/components/box-overlay.d.ts +0 -44
- package/dist/components/boxed-picture.d.ts +0 -34
- package/dist/components/button.d.ts +0 -45
- package/dist/components/byte-view.d.ts +0 -32
- package/dist/components/checkbox.d.ts +0 -39
- package/dist/components/choice-grid.d.ts +0 -42
- package/dist/components/commands.d.ts +0 -104
- package/dist/components/compare-audio.d.ts +0 -30
- package/dist/components/compare-grid.d.ts +0 -24
- package/dist/components/compare-parts.d.ts +0 -90
- package/dist/components/compare-regions.d.ts +0 -37
- package/dist/components/compare-text.d.ts +0 -32
- package/dist/components/compare-video-grid.d.ts +0 -52
- package/dist/components/compare-video.d.ts +0 -61
- package/dist/components/compare.d.ts +0 -90
- package/dist/components/composition.d.ts +0 -44
- package/dist/components/console.d.ts +0 -34
- package/dist/components/conversation.d.ts +0 -83
- package/dist/components/cursor.d.ts +0 -44
- package/dist/components/data-table.d.ts +0 -89
- package/dist/components/data-view.d.ts +0 -66
- package/dist/components/density.d.ts +0 -16
- package/dist/components/dialog.d.ts +0 -45
- package/dist/components/difference.d.ts +0 -19
- package/dist/components/disclosure.d.ts +0 -49
- package/dist/components/done.d.ts +0 -14
- package/dist/components/drag-source.d.ts +0 -29
- package/dist/components/field.d.ts +0 -79
- package/dist/components/file-intake.d.ts +0 -60
- package/dist/components/film-strip.d.ts +0 -35
- package/dist/components/folder-picker.d.ts +0 -59
- package/dist/components/fullscreen-frame.d.ts +0 -18
- package/dist/components/history.d.ts +0 -61
- package/dist/components/hotkeys.d.ts +0 -44
- package/dist/components/infinite-list.d.ts +0 -77
- package/dist/components/inspector.d.ts +0 -66
- package/dist/components/job-action.d.ts +0 -30
- package/dist/components/job-status.d.ts +0 -55
- package/dist/components/jobs-table.d.ts +0 -35
- package/dist/components/key-glyphs.d.ts +0 -5
- package/dist/components/key-owner.d.ts +0 -11
- package/dist/components/lightbox.d.ts +0 -61
- package/dist/components/line-chart.d.ts +0 -169
- package/dist/components/link-card.d.ts +0 -32
- package/dist/components/link.d.ts +0 -54
- package/dist/components/markable-text.d.ts +0 -60
- package/dist/components/media-contents.d.ts +0 -28
- package/dist/components/media-group.d.ts +0 -32
- package/dist/components/media-player.d.ts +0 -251
- package/dist/components/media-progress.d.ts +0 -17
- package/dist/components/media-skip.d.ts +0 -31
- package/dist/components/media-spans.d.ts +0 -93
- package/dist/components/media.d.ts +0 -133
- package/dist/components/meter.d.ts +0 -32
- package/dist/components/metric.d.ts +0 -17
- package/dist/components/outbox-status.d.ts +0 -10
- package/dist/components/page-header.d.ts +0 -14
- package/dist/components/pair-vote.d.ts +0 -70
- package/dist/components/pause-button.d.ts +0 -7
- package/dist/components/pixel-image.d.ts +0 -29
- package/dist/components/place-board.d.ts +0 -39
- package/dist/components/player-warning.d.ts +0 -24
- package/dist/components/popover.d.ts +0 -20
- package/dist/components/recorder.d.ts +0 -73
- package/dist/components/region-editor.d.ts +0 -67
- package/dist/components/save.d.ts +0 -46
- package/dist/components/say-again.d.ts +0 -13
- package/dist/components/schedule-table.d.ts +0 -24
- package/dist/components/secret-field.d.ts +0 -34
- package/dist/components/selectable-grid.d.ts +0 -57
- package/dist/components/selection.d.ts +0 -104
- package/dist/components/sequence-timeline.d.ts +0 -50
- package/dist/components/shortcut-editor.d.ts +0 -44
- package/dist/components/sortable-list.d.ts +0 -39
- package/dist/components/status.d.ts +0 -9
- package/dist/components/switch.d.ts +0 -15
- package/dist/components/system-panel.d.ts +0 -58
- package/dist/components/tabs.d.ts +0 -16
- package/dist/components/theme.d.ts +0 -106
- package/dist/components/thumbnail.d.ts +0 -50
- package/dist/components/tile-grid.d.ts +0 -67
- package/dist/components/timeline-player.d.ts +0 -18
- package/dist/components/timeline.d.ts +0 -115
- package/dist/components/toast.d.ts +0 -36
- package/dist/components/toggle.d.ts +0 -51
- package/dist/components/toolbar.d.ts +0 -15
- package/dist/components/tooltip.d.ts +0 -19
- package/dist/components/transcript-view.d.ts +0 -63
- package/dist/components/tree.d.ts +0 -74
- package/dist/components/undo.d.ts +0 -63
- package/dist/components/use-timeline.d.ts +0 -44
- package/dist/components/value-controls.d.ts +0 -91
- package/dist/components/video-clock.d.ts +0 -68
- package/dist/components/view-options.d.ts +0 -105
- package/dist/components/viewport.d.ts +0 -85
- package/dist/components/virtual-list.d.ts +0 -19
- package/dist/components/waveform.d.ts +0 -71
- package/dist/components/workflow-steps.d.ts +0 -71
- package/dist/components/workspace.d.ts +0 -83
- package/dist/cursor-DDGBPiTJ.js.map +0 -1
- package/dist/field-BjeE_FeB.js.map +0 -1
- package/dist/follow-BTPs49FP.js.map +0 -1
- package/dist/generate-CjTHKJ39.js.map +0 -1
- package/dist/lib/base.d.ts +0 -10
- package/dist/lib/book.d.ts +0 -25
- package/dist/lib/boxes.d.ts +0 -55
- package/dist/lib/breakpoint.d.ts +0 -4
- package/dist/lib/choice.d.ts +0 -29
- package/dist/lib/chords.d.ts +0 -20
- package/dist/lib/client-work.d.ts +0 -24
- package/dist/lib/control.d.ts +0 -4
- package/dist/lib/dev.d.ts +0 -2
- package/dist/lib/errors.d.ts +0 -43
- package/dist/lib/file-intake.d.ts +0 -60
- package/dist/lib/follow.d.ts +0 -18
- package/dist/lib/format.d.ts +0 -243
- package/dist/lib/grouped-grid-layout.d.ts +0 -44
- package/dist/lib/icon.d.ts +0 -6
- package/dist/lib/image-diff.d.ts +0 -30
- package/dist/lib/in-view.d.ts +0 -21
- package/dist/lib/loudness.d.ts +0 -18
- package/dist/lib/marks.d.ts +0 -6
- package/dist/lib/microphone.d.ts +0 -24
- package/dist/lib/number-input.d.ts +0 -4
- package/dist/lib/object-url.d.ts +0 -2
- package/dist/lib/overlay.d.ts +0 -1
- package/dist/lib/recording.d.ts +0 -16
- package/dist/lib/region.d.ts +0 -64
- package/dist/lib/rich-text.d.ts +0 -44
- package/dist/lib/search-param.d.ts +0 -16
- package/dist/lib/segmenter.d.ts +0 -40
- package/dist/lib/sequence.d.ts +0 -34
- package/dist/lib/speech.d.ts +0 -53
- package/dist/lib/text-diff.d.ts +0 -16
- package/dist/lib/timeline.d.ts +0 -14
- package/dist/lib/transcript.d.ts +0 -53
- package/dist/lib/utils.d.ts +0 -4
- package/dist/lib/viewer-input.d.ts +0 -29
- package/dist/lib/viewport.d.ts +0 -55
- package/dist/lib/waveform.d.ts +0 -46
- package/dist/map/fan.d.ts +0 -15
- package/dist/map/index.d.ts +0 -3
- package/dist/map/map-styles.d.ts +0 -2
- package/dist/map/markers.d.ts +0 -60
- package/dist/map/route-map.d.ts +0 -146
- package/dist/microphone-Bo3WaXgD.js.map +0 -1
- package/dist/migrate/stock-classes.d.ts +0 -11
- package/dist/panorama/gl.d.ts +0 -16
- package/dist/panorama/index.d.ts +0 -2
- package/dist/panorama/panorama-viewer.d.ts +0 -56
- package/dist/panorama/projection.d.ts +0 -45
- package/dist/query/api.d.ts +0 -23
- package/dist/query/clips.d.ts +0 -48
- package/dist/query/index.d.ts +0 -55
- package/dist/query/infinite.d.ts +0 -60
- package/dist/query/job.d.ts +0 -26
- package/dist/query/outbox.d.ts +0 -85
- package/dist/query/poll.d.ts +0 -24
- package/dist/query/reserve.d.ts +0 -33
- package/dist/query/typed-api.d.ts +0 -84
- package/dist/query/workflow.d.ts +0 -17
- package/dist/run-BT2WKzMz.js.map +0 -1
- package/dist/scene/camera.d.ts +0 -99
- package/dist/scene/index.d.ts +0 -2
- package/dist/scene/scene-viewport.d.ts +0 -48
- package/dist/testing/buttons.d.ts +0 -7
- package/dist/testing/index.d.ts +0 -161
- package/dist/testing/intersection-observer.d.ts +0 -34
- package/dist/testing/layout.d.ts +0 -13
- package/dist/testing/microphone.d.ts +0 -35
- package/dist/testing/setup.d.ts +0 -14
- package/dist/testing/speech.d.ts +0 -38
- package/dist/testing/storage.d.ts +0 -7
- package/dist/theme-CxYZkUNk.js.map +0 -1
- package/dist/tooltip-DhqrDtyu.js.map +0 -1
- package/dist/value-controls-Dm_EYfZW.js.map +0 -1
- package/dist/visual/capture.d.ts +0 -37
- package/dist/visual/compare.d.ts +0 -46
- package/dist/visual/drop.d.ts +0 -19
- package/dist/visual/fonts.d.ts +0 -18
- package/dist/visual/index.d.ts +0 -19
- package/dist/visual/run.d.ts +0 -22
- package/dist/visual/serve.d.ts +0 -13
- package/dist/visual/targets.d.ts +0 -17
- package/dist/visual/types.d.ts +0 -188
package/README.md
CHANGED
|
@@ -234,6 +234,7 @@ thousands of lines. Such an app imports the same stylesheet **without the reset*
|
|
|
234
234
|
| Value controls | `NumberField`, `Slider`, `ColorField`, `SecretField` | Set a number or colour precisely, inside `Field`. `NumberField` and `Slider` are React Aria's; the number field runs with `commitBehavior="validate"`, so a typed value outside `min`/`max` is kept on screen, explained in the `Field` ("Enter a value from 0% to 500%.") and never passed to `onChange`. A value that is not known is `null` and shows an en dash, never 0 or NaN. Digits and decimal mark follow `locale`. The unit sits inside the control, and in the slider's spoken value when `Intl` has it (%, °, ms, s, kB, MB, GB, kbps, Mbps). Arrows step, Home/End jump to the limits; `Slider editable` adds a number field. `ColorField`: platform picker, typed hex that is normalised, app suggestions, and a contrast note against `against`. No motion on value changes. `NumberField` options for a value set a little at a time or that costs work to change: `nudge={[0.1, 1, 10]}` (a toolbar of named step buttons that repeat when held and stop at the limits), `suggestion={{ value, label, reason }}` (a row with the reason in words and Use this value, never applied by itself) and `preview` (changes wait behind Apply and Revert; `onChange` is Apply's). `SecretField` is a credential the server keeps and never shows again: not set, set (no characters, no length, no input in the DOM), a masked entry with a Show toggle named for what it reveals, `onSave` through `AsyncButton`, Replace, a confirmed Remove that says what stops working, and a Test whose result is text beside it; a set, untouched field reports nothing |
|
|
235
235
|
| Notices and progress | `Alert`, `toast`, `StrataToastRegion`, `useClientWork`, `JobStatus` | Three weights. A `toast` confirms finished work and goes by itself (5 s plus 40 ms a character, 8 s minimum with an action, paused under the pointer or focus, always dismissable); it has no danger tone, because an error a person must act on is an inline `Alert` with its recovery as `action` (`announce` makes it `role="alert"` only when it answers something the person just did). `StrataToastRegion` goes once at the app root. `useClientWork` runs browser work with progress, cancel (aborts its `signal`, ends `cancelled`, never `failed`) and a double-start guard; `JobStatus` shows it exactly as it shows a server job, with `onCancel`, `cancelled` and `onDismiss` |
|
|
236
236
|
| Media player | `MediaPlayer`, `useMediaElement`, `SPEECH_RATES`, `useMediaSpans`, `SpanActions`, `PlayerNotice`, `SpanStrip`, `MediaContents` | Play a file or a sequence of chapters without the event glue: `marks` puts one file's own chapters (and `kind: "scene"` scenes, shorter) on the seek bar, each named in a tooltip and pressed to jump; the skip buttons beside Play step by scene (small) and chapter (large), or by 10 s and 1 min where a file has none (`skip`, `skipAction`); `fps` adds frame steps (`,` and `.`); `float` keeps a playing video in a corner box once the player has scrolled off the screen; and `MediaContents` lists them beside the player (the playing one marked, pressing one plays from its start, never scrolling the page); the element, its state, Strata's controls (or the browser's own on a touch device, `controls="auto"`), a load error with Try again, `navigator.mediaSession` metadata, the seek bar spanning the whole sequence. `useMediaElement(ref)` alone follows an element drawn with the browser's controls `spans` and `spanKinds` mark stretches (an intro, a recap, a sponsor read) on the seek bar as named ranges in a status role's tone and act on them as playback reaches them: `auto` skips (or mutes, for `action: "mute"`) with "Skipped intro" and Undo, `ask` offers a Skip button over the picture and on the `s` key, `off` only draws; each is acted on once, `onSpan` reports `skipped`, `muted`, `undone` or `played`, and `SeekBar` takes `spans` too. `mediaRef` hands out the player's state and requests (an object ref holds the latest, no render of its own), `overlay` draws the app's own thing over the picture only, `heading` (title, subtitle, avatar, each a link, with the app's router `state`) is drawn across the top of a video while paused or the pointer moves, and a video keeps a 16:9 (or `aspect`) box before its metadata loads. A video has a Full screen button and the `f` key by default (`fullscreen={false}` removes them); on the picture a click plays or pauses, a double click toggles full screen and the wheel sets the volume while the player has focus. A kind's `colour` names a custom property of the app's theme (`"--seg-sponsor"`) instead of a tone, each range carries `data-kind`, and under the browser's own controls a `SpanStrip` under the picture draws the ranges. `start` begins a first load at a time (an attacher's `startAt`, or a seek once the metadata is in) and says "Picked up at 2:05" with Start over (`resumeWords`); `onProgress` reports the position and the seconds actually played through, each once, a skipped span counted (`useMediaElement` takes it too, with `markWatched`). The HLS attacher starts a `growing` source at its beginning, honours `config.startPosition` and takes `words` for its failures. |
|
|
237
|
+
| Edit lists | `EditListPlayer`, `useEditList`; `editTimes`, `locateInEdit`, `editTimeOf`, `continues`, `nextBreak` | An edit (clips that are stretches `[start, end)` of files) played as one timeline before it is rendered: two stacked `<video>` elements, the one behind already loaded and sought to the next clip that does not carry straight on, so a cut shows no gap; clips of one file that follow on play through; the cut is timed from the browser's frame callbacks (a refresh early by the frame loop where there are none); a seek bar marked at every clip, Previous and Next clip (P and N), frame steps with `fps` (`,` and `.`), a new edit (another revision) stays in the clip being watched, and the empty state is a required prop |
|
|
237
238
|
| Media playback | `useTimeline`, `TimelinePlayer`, `Transport`, `SeekBar`, `TimeReadout`, `VolumeControl`, `RateChoice`, `MediaStage`, `StageGuides`, `transportShortcuts`, `format.timecode` | The controls around anything that plays, wired to a player the app owns (HTML media, Web Audio, a canvas, a data replay). Every control is a named icon button in one toolbar; the play button's name is "Play" or "Pause". `SeekBar` has the formatted time as its accessible value, arrows step 5 s and Page keys 30 s by default, and optional marks. `VolumeControl` shows its percent, and muting remembers the level. `transportShortcuts` is the one list for `useHotkeys` and `KeysLegend` (Space and K, J and L, the arrows by a frame, Home and End). `format.timecode` prints m:ss, m:ss.mmm or m:ss:ff. `MediaStage` fits a picture of any aspect ratio into the pane with a letterbox on the sunken surface role, and takes overlays such as `StageGuides` `useTimeline` is the same state for a clock the app owns (a recorded run, a replay, an animation): rAF at `rate`, loops or stops, play at the end restarts, a seek pauses, `step` by `frame`, `startAt`, joins a `MediaGroup` and the key-owner rule, so `Transport`, `SeekBar` and `transportShortcuts` plug in; `TimelinePlayer` puts a stage (a `SceneViewport` given `time`) over the same control bar, with the stage keeping the arrow keys. |
|
|
238
239
|
| Listening and reading | `Waveform`, `TranscriptView`, `PlayWindowButton`, `MediaGroup`, `FilmStrip`; `resamplePeaks`, `peaksFromAudio`, `peakGain`, `phraseAt`, `wordAt`, `pickEvenly`, `frameAt` | Timed media: a waveform from peaks or a decoded file (one slider, marks by line style, named spans, zoom, a keyboard-made range, a spectrogram underlay, `normalise` to draw quiet sound to fill the height and say by how much); `FilmStrip` is a row of frames from a stretch of video that fits its width (picked evenly), each with its time, pressing one seeks (`onSeek`, one tab stop with arrow keys), and the frame at `time` inside `span` is ringed; timed text that marks the heard word and plays from any word (modes, speakers, follow and Jump to now, virtualised), with doubtful words (dotted, named, counted, "Only doubtful"), a mark per phrase set from a row menu (`states`, `onPhraseState`), correction in place (Enter or F2, `onEdit`) and a hover and focus card (`renderCard`); `MediaPlayer window` plays one stretch of a file, `MediaGroup` lets one player play at a time, `PlayWindowButton` is a row's play control on a shared element; a review transcript needs no player (`time` and `onSeek` are optional), takes `marking` (words become `MarkableText` marks with ids `wordId(phraseId, index)`, selected across rows that are not mounted) and shows a corrected word (`word.correction`) dotted with the original on hover and `onCorrectionPress` to open it |
|
|
239
240
|
| Streams | `MediaPlayer attach`/`growing`, `useAttachedSource`, `attachHls` (`strata-react/hls`) | A source the element cannot play is attached by an engine; a source still being made says so, shows what exists as ready, and waits at its end without ending |
|
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-26 (built with Vite+)
|
|
15
|
+
|
|
16
|
+
- The package is now built by `vp pack` (tsdown). The type declarations are one bundled file per entry (`dist/testing.d.ts`, `dist/visual.d.ts`, ...) instead of a `dist/<entry>/index.d.ts` tree. Imports through the package's `exports` are unchanged; only an app that reached into `dist/` by path (do not) needs to change.
|
|
17
|
+
|
|
14
18
|
## 2026-11-26 (shared 3D input, #386)
|
|
15
19
|
- No action needed. `PanoramaViewer` and `SceneViewport` read pointers, the wheel and the status through shared hooks with the same behaviour; a pointer cancelled mid-press no longer calls `onPick`.
|
|
16
20
|
|
package/dist/api-types-cli.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { n as loadSchema, t as generateApiTypes } from "./generate-
|
|
1
|
+
import { n as loadSchema, t as generateApiTypes } from "./generate-BkWhh4k4.js";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
4
|
import { readFile, writeFile } from "node:fs/promises";
|
|
5
|
+
|
|
5
6
|
// src/api-types/cli.ts
|
|
6
|
-
|
|
7
|
+
const usage = `Usage: strata-api-types <schema> [options]
|
|
7
8
|
|
|
8
9
|
Writes TypeScript types for an app's API from its OpenAPI schema, so they follow the Python
|
|
9
10
|
server's instead of being written again by hand. <schema> is a URL (a running server, for example
|
|
@@ -62,6 +63,6 @@ async function main(argv, out = (t) => console.log(t), fetcher = fetch) {
|
|
|
62
63
|
return 1;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
|
-
export { main };
|
|
66
66
|
|
|
67
|
+
export { main };
|
|
67
68
|
//# sourceMappingURL=api-types-cli.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-types-cli.js","names":[],"sources":["../src/api-types/cli.ts"],"sourcesContent":["// The strata-api-types command: generate an app's TypeScript API types from its OpenAPI schema (see generate.ts).\nimport { existsSync } from \"node:fs\";\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { parseArgs } from \"node:util\";\nimport { generateApiTypes, loadSchema } from \"./generate\";\n\nconst usage = `Usage: strata-api-types <schema> [options]\n\nWrites TypeScript types for an app's API from its OpenAPI schema, so they follow the Python\nserver's instead of being written again by hand. <schema> is a URL (a running server, for example\nhttp://localhost:8360/api/openapi.json) or a JSON file the server's CLI wrote, so CI needs no server.\n\n -o, --output <file> the generated file (default src/api.generated.ts); commit it, never edit it\n --check write nothing; exit 1 if the file is missing or differs from the schema (for CI)\n --help show this\n`;\n\n/** Runs the command; the exit code. */\nexport async function main(argv: readonly string[]
|
|
1
|
+
{"version":3,"file":"api-types-cli.js","names":[],"sources":["../src/api-types/cli.ts"],"sourcesContent":["// The strata-api-types command: generate an app's TypeScript API types from its OpenAPI schema (see generate.ts).\nimport { existsSync } from \"node:fs\";\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { parseArgs } from \"node:util\";\nimport { generateApiTypes, loadSchema } from \"./generate\";\n\nconst usage = `Usage: strata-api-types <schema> [options]\n\nWrites TypeScript types for an app's API from its OpenAPI schema, so they follow the Python\nserver's instead of being written again by hand. <schema> is a URL (a running server, for example\nhttp://localhost:8360/api/openapi.json) or a JSON file the server's CLI wrote, so CI needs no server.\n\n -o, --output <file> the generated file (default src/api.generated.ts); commit it, never edit it\n --check write nothing; exit 1 if the file is missing or differs from the schema (for CI)\n --help show this\n`;\n\n/** Runs the command; the exit code. */\nexport async function main(\n argv: readonly string[],\n out: (text: string) => void = (t) => console.log(t),\n fetcher: typeof fetch = fetch,\n): Promise<number> {\n let parsed;\n try {\n parsed = parseArgs({\n args: [...argv],\n options: { output: { type: \"string\", short: \"o\" }, check: { type: \"boolean\" }, help: { type: \"boolean\" } },\n allowPositionals: true,\n });\n } catch (e) {\n out(`${(e as Error).message}\\n\\n${usage}`);\n return 2;\n }\n const { values, positionals } = parsed;\n if (values.help) {\n out(usage);\n return 0;\n }\n if (positionals.length !== 1) {\n out(`Give the schema to read: a URL or a JSON file.\\n\\n${usage}`);\n return 2;\n }\n const output = values.output ?? \"src/api.generated.ts\";\n try {\n const next = await generateApiTypes(await loadSchema(positionals[0]!, fetcher), positionals[0]!);\n if (values.check) {\n const current = existsSync(output) ? (await readFile(output, \"utf8\")).replace(/\\r\\n/g, \"\\n\") : null;\n if (current === next) {\n out(`${output} matches the schema.`);\n return 0;\n }\n out(\n `${output} ${current === null ? \"does not exist\" : \"no longer matches the schema\"}. Regenerate it: strata-api-types ${positionals[0]} -o ${output}`,\n );\n return 1;\n }\n await writeFile(output, next);\n out(`Wrote ${output}.`);\n return 0;\n } catch (e) {\n out((e as Error).message);\n return 1;\n }\n}\n"],"mappings":";;;;;;AAMA,MAAM,QAAQ;;;;;;;;;;;AAYd,eAAsB,KACpB,MACA,OAA+B,MAAM,QAAQ,IAAI,CAAC,GAClD,UAAwB,OACP;CACjB,IAAI;CACJ,IAAI;EACF,SAAS,UAAU;GACjB,MAAM,CAAC,GAAG,IAAI;GACd,SAAS;IAAE,QAAQ;KAAE,MAAM;KAAU,OAAO;IAAI;IAAG,OAAO,EAAE,MAAM,UAAU;IAAG,MAAM,EAAE,MAAM,UAAU;GAAE;GACzG,kBAAkB;EACpB,CAAC;CACH,SAAS,GAAG;EACV,IAAI,GAAI,EAAY,QAAQ,MAAM,OAAO;EACzC,OAAO;CACT;CACA,MAAM,EAAE,QAAQ,gBAAgB;CAChC,IAAI,OAAO,MAAM;EACf,IAAI,KAAK;EACT,OAAO;CACT;CACA,IAAI,YAAY,WAAW,GAAG;EAC5B,IAAI,qDAAqD,OAAO;EAChE,OAAO;CACT;CACA,MAAM,SAAS,OAAO,UAAU;CAChC,IAAI;EACF,MAAM,OAAO,MAAM,iBAAiB,MAAM,WAAW,YAAY,IAAK,OAAO,GAAG,YAAY,EAAG;EAC/F,IAAI,OAAO,OAAO;GAChB,MAAM,UAAU,WAAW,MAAM,KAAK,MAAM,SAAS,QAAQ,MAAM,EAAC,CAAE,QAAQ,SAAS,IAAI,IAAI;GAC/F,IAAI,YAAY,MAAM;IACpB,IAAI,GAAG,OAAO,qBAAqB;IACnC,OAAO;GACT;GACA,IACE,GAAG,OAAO,GAAG,YAAY,OAAO,mBAAmB,+BAA+B,oCAAoC,YAAY,GAAG,MAAM,QAC7I;GACA,OAAO;EACT;EACA,MAAM,UAAU,QAAQ,IAAI;EAC5B,IAAI,SAAS,OAAO,EAAE;EACtB,OAAO;CACT,SAAS,GAAG;EACV,IAAK,EAAY,OAAO;EACxB,OAAO;CACT;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** The OpenAPI document as the generator takes it: a parsed JSON object. */
|
|
2
|
-
|
|
2
|
+
type OpenApiDocument = Record<string, unknown>;
|
|
3
3
|
/** Reads an OpenAPI document from an `http(s)` URL (a running server) or a JSON file path. */
|
|
4
4
|
export declare function loadSchema(source: string, fetcher?: typeof fetch): Promise<OpenApiDocument>;
|
|
5
|
-
/** The message for a failed `import("openapi-typescript")`: absent, or present but unable to load (issue #293: a TypeScript 7 app was told to install what it had). */
|
|
6
|
-
export declare function explainImportFailure(cause: unknown, typescriptMajor?: number | undefined): string;
|
|
7
5
|
/**
|
|
8
6
|
* The TypeScript types for an OpenAPI document, as the text of the generated file. `source` is where the
|
|
9
7
|
* document was read from (a URL or file path): relative `$ref`s to other files resolve against it.
|
|
10
8
|
*/
|
|
11
9
|
export declare function generateApiTypes(schema: OpenApiDocument, source?: string): Promise<string>;
|
|
10
|
+
export type { OpenApiDocument };
|
|
11
|
+
//# sourceMappingURL=api-types.d.ts.map
|
package/dist/api-types.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { r as cn, t as Tooltip$1 } from "./tooltip-
|
|
1
|
+
import { r as cn, t as Tooltip$1 } from "./tooltip-BosfsWYh.js";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { Button } from "react-aria-components";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
|
|
6
7
|
// src/lib/in-view.ts
|
|
7
8
|
/**
|
|
8
9
|
* Whether an element is within `rootMargin` of its scroll region (the nearest
|
|
@@ -42,6 +43,7 @@ function useInView({ active = true, rootMargin = "0px", once = false, unsupporte
|
|
|
42
43
|
inView
|
|
43
44
|
};
|
|
44
45
|
}
|
|
46
|
+
|
|
45
47
|
// src/lib/dev.ts
|
|
46
48
|
/** Whether the app is running in development, decided by the app's bundler. */
|
|
47
49
|
function isDev() {
|
|
@@ -51,8 +53,9 @@ function isDev() {
|
|
|
51
53
|
return false;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
56
|
+
|
|
54
57
|
// src/components/button.tsx
|
|
55
|
-
|
|
58
|
+
const buttonVariants = cva("inline-flex max-w-full shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-control type-label transition-state press disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-(--control-icon) [&_svg]:shrink-0", {
|
|
56
59
|
variants: {
|
|
57
60
|
variant: {
|
|
58
61
|
default: "bg-primary text-primary-foreground hover:bg-primary-10",
|
|
@@ -117,7 +120,7 @@ function warnOnLoss(props, children) {
|
|
|
117
120
|
console.warn(`strata-react: a Button whose only content is "${glyph}" has no accessible name. Give it an aria-label, or use an IconButton with a label.`);
|
|
118
121
|
}
|
|
119
122
|
}
|
|
120
|
-
|
|
123
|
+
const warned = /* @__PURE__ */ new Set();
|
|
121
124
|
/** An icon-only button. `label` is required and becomes the accessible name and the tooltip (hover and keyboard focus); `hint` adds a muted aside to it, such as a shortcut. */
|
|
122
125
|
function IconButton({ icon: Icon, label, hint, variant = "ghost", size = "default", ...props }) {
|
|
123
126
|
return /* @__PURE__ */ jsx(Tooltip$1, {
|
|
@@ -143,6 +146,6 @@ function RowAction({ label, subject, icon: Icon, variant = "ghost", size = "sm",
|
|
|
143
146
|
children: [Icon && /* @__PURE__ */ jsx(Icon, { "aria-hidden": true }), label]
|
|
144
147
|
});
|
|
145
148
|
}
|
|
146
|
-
export { isDev as a, buttonVariants as i, IconButton as n, useInView as o, RowAction as r, Button$1 as t };
|
|
147
149
|
|
|
148
|
-
|
|
150
|
+
export { isDev as a, buttonVariants as i, IconButton as n, useInView as o, RowAction as r, Button$1 as t };
|
|
151
|
+
//# sourceMappingURL=button-CYXjU-fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button-CYXjU-fs.js","names":["Button","AriaButton","Tooltip"],"sources":["../src/lib/in-view.ts","../src/lib/dev.ts","../src/components/button.tsx"],"sourcesContent":["import * as React from \"react\";\n\n// One IntersectionObserver hook for everything that waits until it is near the screen: the\n// sentinel at the end of an InfiniteList and an image in a Thumbnail. Both watch from the nearest\n// `[data-strata-scroll]` region (a VirtualList's) or else the viewport, with a root\n// margin so the work starts before the element is reached. They differ in two ways, which are\n// options rather than two hooks:\n//\n// - `once`: an image, once asked for, stays asked for; scrolling it away again must not unload it.\n// A sentinel reports in and out of view every time.\n// - `unsupported`: where there is no IntersectionObserver (an old browser, a test without the\n// fake), an image loads at once, because a photo that never loads is worse than one loaded\n// early. A sentinel reports out of view, because InfiniteList's Show more button is the path\n// that always works.\n\n/** Options for {@link useInView}. */\nexport type InViewOptions = {\n /** Watch only while this is true. Default true. */\n active?: boolean;\n /** How far outside the scroll region still counts as in view (IntersectionObserver `rootMargin`). */\n rootMargin?: string;\n /** Stay in view after the first time, and stop watching. */\n once?: boolean;\n /** What to report where `IntersectionObserver` does not exist. Default false. */\n unsupported?: boolean;\n};\n\n/**\n * Whether an element is within `rootMargin` of its scroll region (the nearest\n * `[data-strata-scroll]` ancestor, else the viewport). Returns a callback ref, so it follows the\n * element as it mounts and unmounts.\n */\nexport function useInView({\n active = true,\n rootMargin = \"0px\",\n once = false,\n unsupported = false,\n}: InViewOptions = {}) {\n const [inView, setInView] = React.useState(false);\n const [el, setEl] = React.useState<Element | null>(null);\n const seen = once && inView;\n React.useEffect(() => {\n if (seen) return;\n if (!active || !el) {\n setInView(false);\n return;\n }\n if (typeof IntersectionObserver === \"undefined\") {\n setInView(unsupported);\n return;\n }\n const root = el.parentElement?.closest<HTMLElement>(\"[data-strata-scroll]\") ?? null;\n const observer = new IntersectionObserver((entries) => setInView(entries[entries.length - 1].isIntersecting), {\n root,\n rootMargin,\n });\n observer.observe(el);\n return () => observer.disconnect();\n }, [active, el, rootMargin, seen, unsupported]);\n return { ref: setEl, inView };\n}\n","// Development-only checks (a warning for a mistake a type cannot catch). `import.meta.env.DEV` is\n// replaced by the library build itself, so in the published package it is always false and the check\n// never runs in an app's development. `process.env.NODE_ENV` is left for the app's bundler to replace\n// (Vite, webpack and the rest do, in dependencies too), so the app decides. Where nothing replaces it\n// `process` does not exist, and the check is off.\n\n/** Whether the app is running in development, decided by the app's bundler. */\nexport function isDev(): boolean {\n try {\n return process.env.NODE_ENV !== \"production\";\n } catch {\n return false;\n }\n}\n","import * as React from \"react\";\nimport { Button as AriaButton, type PressEvent } from \"react-aria-components\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport type { IconComponent } from \"../lib/icon\";\nimport { cn } from \"../lib/utils\";\nimport type { ControlSize } from \"../lib/control\";\nimport { Tooltip } from \"./tooltip\";\nimport { isDev } from \"../lib/dev\";\n\n// Variant names are shadcn's, so copied code and agents' prior knowledge still work. Two things\n// differ on purpose:\n// 1. The default variant is `outline`, not the filled accent. A bare <Button> is the restrained\n// one; the accent (`variant=\"default\"`) has to be asked for, once per view. Generated app screens\n// put the accent on every button; 12 of 23 real product screens had no filled primary at all.\n// 2. Heights come from --control-h, shared with Input and NativeSelect, so density changes move\n// every control together.\n// 3. React Aria is the primitives layer (CLAUDE.md, \"The stack\"): behaviour and accessibility come\n// from it, the look from our tokens. `asChild`/`Slot` is gone; a button that navigates is a link.\n// 4. `press`: the button gives 2% under a click or a finger, over 100ms. Buttons are used tens of\n// times a day, so that is all the motion they get (character.md, the frequency budget).\n// 5. `title` is refused, not passed through (issue #231). React Aria's `Button` does not forward it,\n// so a tip moved over from a native button vanished with nothing said. Passing it through would\n// give a tip that has no keyboard focus, no touch and a long, unstyled delay; the answer is a\n// `Tooltip` (and `IconButton`'s `label` and `hint`). The type says so (`title?: never`) and, for\n// an untyped caller, so does a development warning. A button whose only child is one symbol\n// (`✕`, `−`, `+`) has no accessible name from its text and gets a development warning too.\nexport const buttonVariants = cva(\n \"inline-flex max-w-full shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-control type-label transition-state press disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-(--control-icon) [&_svg]:shrink-0\",\n {\n variants: {\n variant: {\n default: \"bg-primary text-primary-foreground hover:bg-primary-10\",\n outline: \"border border-input bg-background text-foreground hover:bg-muted\",\n secondary: \"bg-muted text-foreground hover:bg-neutral-4\",\n ghost: \"text-foreground hover:bg-muted\",\n destructive: \"bg-destructive text-destructive-foreground hover:bg-danger\",\n link: \"h-auto px-0 text-primary-11 underline underline-offset-4 hover:text-primary-12\",\n },\n size: {\n default: \"h-(--control-h) px-(--control-px)\",\n sm: \"h-(--control-h-sm) px-(--control-px-sm)\",\n icon: \"size-(--control-h)\",\n \"icon-sm\": \"size-(--control-h-sm)\",\n },\n },\n defaultVariants: { variant: \"outline\", size: \"default\" },\n },\n);\n\nexport type ButtonProps = Omit<React.ComponentProps<\"button\">, \"className\" | \"style\" | \"title\"> &\n VariantProps<typeof buttonVariants> & {\n className?: string;\n /** Not accepted: a `title` is a poor tooltip (no keyboard focus, no touch) and React Aria's button drops it. Wrap the button in a `Tooltip`, or use `IconButton`'s `label` and `hint`. */\n title?: never;\n /** React Aria's press event (mouse, touch, pen and keyboard alike). `onClick` also works. */\n onPress?: (event: PressEvent) => void;\n /** When a press begins and ends: for a control that acts while held (a nudge that repeats). */\n onPressStart?: (event: PressEvent) => void;\n onPressEnd?: (event: PressEvent) => void;\n };\n\n/**\n * A button with shadcn's variant names, built on React Aria's `Button` (press handling that behaves\n * the same for mouse, touch, pen and keyboard, focus-visible and hover state). The default variant is\n * `outline`; ask for the filled accent (`variant=\"default\"`) once per view. `type` defaults to `button`.\n * `onClick` and `disabled` are the DOM names and keep working; `onPress` is also accepted.\n */\nexport function Button({\n className,\n variant,\n size,\n type = \"button\",\n disabled,\n children,\n \"aria-busy\": ariaBusy,\n ...props\n}: ButtonProps) {\n // React Aria's button drops `aria-busy` (it forwards only the aria props it knows), so it is set\n // on the element here; a pending row action says it is busy to a screen reader (issue #248).\n const ref = React.useRef<HTMLButtonElement>(null);\n React.useEffect(() => {\n const el = ref.current;\n if (!el) return;\n if (ariaBusy) el.setAttribute(\"aria-busy\", String(ariaBusy));\n else el.removeAttribute(\"aria-busy\");\n }, [ariaBusy]);\n if (isDev()) warnOnLoss(props as Record<string, unknown>, children);\n // data-variant says which variant was drawn, so a test can check \"one filled button per view\"\n // without reading class names (strata-react issue #48, `filledButtons` in strata-react/testing).\n return (\n <AriaButton\n ref={ref}\n type={type}\n isDisabled={disabled}\n data-variant={variant ?? \"outline\"}\n className={cn(buttonVariants({ variant, size }), className)}\n {...(props as object)}\n >\n {/* A text label that cannot fit its column is cut with an ellipsis, not drawn past the button (issue #116). */}\n {typeof children === \"string\" ? <span className=\"min-w-0 truncate\">{children}</span> : children}\n </AriaButton>\n );\n}\n\n/** Development only: what a native button had that this one loses or cannot name (issue #231). */\nfunction warnOnLoss(props: Record<string, unknown>, children: React.ReactNode) {\n if (props.title !== undefined && !warned.has(\"title\")) {\n warned.add(\"title\");\n console.warn(\n \"strata-react: Button does not pass `title` through (React Aria's button drops it, and a title has no keyboard or touch). Wrap the button in a `Tooltip`, or use IconButton's `label` and `hint`.\",\n );\n }\n const glyph = typeof children === \"string\" ? children.trim() : \"\";\n if (\n glyph &&\n Array.from(glyph).length === 1 &&\n !/[\\p{L}\\p{N}]/u.test(glyph) &&\n !props[\"aria-label\"] &&\n !props[\"aria-labelledby\"] &&\n !warned.has(\"glyph\")\n ) {\n warned.add(\"glyph\");\n console.warn(\n `strata-react: a Button whose only content is \"${glyph}\" has no accessible name. Give it an aria-label, or use an IconButton with a label.`,\n );\n }\n}\nconst warned = new Set<string>();\n\n// An icon-only button cannot be written without a name: `label` is required by the type, becomes\n// the accessible name and is shown as a `Tooltip` on hover and keyboard focus, so the name and the\n// visible hint come from one string and cannot drift. This makes the most common generated\n// accessibility defect (an unlabelled icon button) a compile error instead of an audit finding.\nexport type IconButtonProps = Omit<ButtonProps, \"size\" | \"children\" | \"aria-label\"> & {\n /** `sm` is --control-h-sm, the height of a small `Toggle` or `Button`, for a toolbar or property row. Default --control-h. */\n size?: ControlSize;\n icon: IconComponent;\n label: string;\n /** Shown after the label in its tooltip, muted: \"Ctrl+Z\". */\n hint?: React.ReactNode;\n};\n\n/** An icon-only button. `label` is required and becomes the accessible name and the tooltip (hover and keyboard focus); `hint` adds a muted aside to it, such as a shortcut. */\nexport function IconButton({\n icon: Icon,\n label,\n hint,\n variant = \"ghost\",\n size = \"default\",\n ...props\n}: IconButtonProps) {\n return (\n <Tooltip label={label} hint={hint}>\n <Button size={size === \"sm\" ? \"icon-sm\" : \"icon\"} variant={variant} aria-label={label} {...props}>\n <Icon aria-hidden />\n </Button>\n </Tooltip>\n );\n}\n\n// A row action says what it does in the row (\"Withdraw\") and whom it does it to in its name\n// (\"Withdraw Tom Ellery\"): a table of eight \"Withdraw\" buttons is eight identical names in a\n// screen reader's list of controls. The name is an aria-label that starts with the visible verb,\n// so it meets WCAG 2.5.3 (label in name) and voice control still finds it by \"Withdraw\". Visually\n// hidden suffix text is not used: a hidden span joined to the verb did not form a name with its\n// space in dom-testing-library (strata-react issue #11). Ghost and small, one per row, shown only\n// on the rows where it applies; an icon-only row action is an `IconButton` whose `label` names the\n// row the same way. It keeps the row's pitch: rows with and without the action are the same height.\nexport type RowActionProps = Omit<ButtonProps, \"children\" | \"aria-label\"> & {\n /** The visible verb, sentence case: \"Withdraw\", \"Remove\". */\n label: string;\n /** What the row is, as a person would say it: \"Tom Ellery\", \"Moonbeam\". Completes the accessible name. */\n subject: string;\n icon?: IconComponent;\n};\n\n/** A small ghost action for one table row: shows `label`, and is named \"`label` `subject`\" so every row's action has its own name. */\nexport function RowAction({\n label,\n subject,\n icon: Icon,\n variant = \"ghost\",\n size = \"sm\",\n className,\n ...props\n}: RowActionProps) {\n // -my-1.5 lets the 32px button sit in the 20px line of a table row, inside the row's padding, so\n // rows with an action keep the same pitch as rows without one.\n return (\n <Button\n variant={variant}\n size={size}\n aria-label={`${label} ${subject}`}\n className={cn(\"-my-1.5\", className)}\n {...props}\n >\n {Icon && <Icon aria-hidden />}\n {label}\n </Button>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAgCA,SAAgB,UAAU,EACxB,SAAS,MACT,aAAa,OACb,OAAO,OACP,cAAc,UACG,CAAC,GAAG;CACrB,MAAM,CAAC,QAAQ,aAAa,MAAM,SAAS,KAAK;C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 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
|
|
3
4
|
// src/lib/geo.ts
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
const RAD = Math.PI / 180;
|
|
6
|
+
const EARTH_RADIUS_M = 6371e3;
|
|
6
7
|
/** Great-circle distance between two positions, in metres. */
|
|
7
8
|
function distance([lat1, lng1], [lat2, lng2]) {
|
|
8
9
|
const a = Math.sin((lat2 - lat1) * RAD / 2) ** 2 + Math.cos(lat1 * RAD) * Math.cos(lat2 * RAD) * Math.sin((lng2 - lng1) * RAD / 2) ** 2;
|
|
@@ -152,7 +153,7 @@ function snap(points, position, along = cumulative(points)) {
|
|
|
152
153
|
return best;
|
|
153
154
|
}
|
|
154
155
|
/** Route geometry helpers: `geo.distance`, `bearing`, `length`, `cumulative`, `bounds`, `pointAlong`, `snap` (its inverse), `slice`, `arrows`, `ends`, `nearest`. */
|
|
155
|
-
|
|
156
|
+
const geo = {
|
|
156
157
|
distance,
|
|
157
158
|
bearing,
|
|
158
159
|
cumulative,
|
|
@@ -165,8 +166,9 @@ var geo = {
|
|
|
165
166
|
ends,
|
|
166
167
|
nearest
|
|
167
168
|
};
|
|
169
|
+
|
|
168
170
|
// src/components/cursor.tsx
|
|
169
|
-
|
|
171
|
+
const EMPTY = {
|
|
170
172
|
at: null,
|
|
171
173
|
source: null,
|
|
172
174
|
owner: null
|
|
@@ -210,7 +212,7 @@ var CursorStore = class {
|
|
|
210
212
|
this.publish();
|
|
211
213
|
}
|
|
212
214
|
};
|
|
213
|
-
|
|
215
|
+
const Scope = React.createContext(null);
|
|
214
216
|
/** Holds one cursor position for the charts, map and seek bar inside it, with a throttled polite announcement of where a pointer or key has put it. */
|
|
215
217
|
function CursorScope({ children, format, announceEvery = 1e3 }) {
|
|
216
218
|
const store = React.useRef(null);
|
|
@@ -285,6 +287,6 @@ function useSharedCursor(source) {
|
|
|
285
287
|
setPlayback
|
|
286
288
|
]);
|
|
287
289
|
}
|
|
288
|
-
export { useSharedCursor as n, geo as r, CursorScope as t };
|
|
289
290
|
|
|
290
|
-
|
|
291
|
+
export { useSharedCursor as n, geo as r, CursorScope as t };
|
|
292
|
+
//# sourceMappingURL=cursor-Cwyvgwsw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursor-Cwyvgwsw.js","names":[],"sources":["../src/lib/geo.ts","../src/components/cursor.tsx"],"sourcesContent":["// Geometry for routes on a map (strata-react issue #80; the helpers jonathanburnhams.com wrote by\n// hand for its activity maps). Pure functions on `[latitude, longitude]` pairs in degrees, no map\n// library, so they live in the main entry and an app can use them for a text alternative or a\n// profile without installing the map's peer.\n//\n// Distances are great-circle (haversine) on a 6,371 km sphere, which is within half a percent of\n// the true figure at any route length a person runs, rides or drives. Bearings use a flat\n// approximation between neighbouring points (the longitude scaled by the cosine of the mean\n// latitude), fine for the short hops a chevron or a heading needs and wrong for a leg of hundreds\n// of kilometres: `bearing` is for neighbouring points, not for a flight.\n\n/** A position: `[latitude, longitude]` in degrees. */\nexport type LatLng = readonly [lat: number, lng: number];\n\nconst RAD = Math.PI / 180;\nconst EARTH_RADIUS_M = 6_371_000;\n\n/** Great-circle distance between two positions, in metres. */\nexport function distance([lat1, lng1]: LatLng, [lat2, lng2]: LatLng): number {\n const a =\n Math.sin(((lat2 - lat1) * RAD) / 2) ** 2 +\n Math.cos(lat1 * RAD) * Math.cos(lat2 * RAD) * Math.sin(((lng2 - lng1) * RAD) / 2) ** 2;\n return 2 * EARTH_RADIUS_M * Math.asin(Math.sqrt(a));\n}\n\n/** The direction from `a` to `b` in degrees clockwise from north (0 to 360), for neighbouring points. */\nexport function bearing([lat1, lng1]: LatLng, [lat2, lng2]: LatLng): number {\n const dx = (lng2 - lng1) * Math.cos((((lat1 + lat2) / 2) * Math.PI) / 180);\n const dy = lat2 - lat1;\n return ((Math.atan2(dx, dy) * 180) / Math.PI + 360) % 360;\n}\n\n/** The running distance along a route at each point, in metres, starting at 0. */\nexport function cumulative(points: readonly LatLng[]): number[] {\n const out = points.length ? [0] : [];\n for (let i = 1; i < points.length; i++) out.push(out[i - 1] + distance(points[i - 1], points[i]));\n return out;\n}\n\n/** The length of a route in metres. */\nexport function length(points: readonly LatLng[]): number {\n let total = 0;\n for (let i = 1; i < points.length; i++) total += distance(points[i - 1], points[i]);\n return total;\n}\n\n/** The south-west and north-east corners that hold every point, or null for none. */\nexport function bounds(points: readonly LatLng[]): [LatLng, LatLng] | null {\n if (!points.length) return null;\n let south = Infinity;\n let north = -Infinity;\n let west = Infinity;\n let east = -Infinity;\n for (const [lat, lng] of points) {\n if (lat < south) south = lat;\n if (lat > north) north = lat;\n if (lng < west) west = lng;\n if (lng > east) east = lng;\n }\n return [\n [south, west],\n [north, east],\n ];\n}\n\n/** The position `metres` along a route (clamped to its ends), by linear interpolation, or null for no points. */\nexport function pointAlong(\n points: readonly LatLng[],\n metres: number,\n along: readonly number[] = cumulative(points),\n): LatLng | null {\n if (!points.length) return null;\n const total = along[along.length - 1];\n const d = Math.min(Math.max(metres, 0), total);\n if (points.length === 1 || total === 0) return points[0];\n let lo = 1;\n let hi = points.length - 1;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (along[mid] < d) lo = mid + 1;\n else hi = mid;\n }\n const [p, q] = [points[lo - 1], points[lo]];\n const t = (d - along[lo - 1]) / (along[lo] - along[lo - 1] || 1);\n return [p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t];\n}\n\n/**\n * `count` positions evenly spaced by distance along a route (the ends skipped), each with the\n * direction of travel there. The direction is smoothed: the bearing from a point a fraction\n * (`window`) of the spacing before to one the same distance after, so GPS jitter and a tight bend\n * do not turn a chevron sideways.\n */\nexport function arrows(points: readonly LatLng[], count = 5, window = 0.4): { position: LatLng; bearing: number }[] {\n if (points.length < 2 || count < 1) return [];\n const along = cumulative(points);\n const total = along[along.length - 1];\n if (total === 0) return [];\n const spacing = total / (count + 1);\n const half = spacing * window;\n return Array.from({ length: count }, (_, i) => {\n const target = spacing * (i + 1);\n const before = pointAlong(points, target - half, along)!;\n const after = pointAlong(points, target + half, along)!;\n return { position: pointAlong(points, target, along)!, bearing: bearing(before, after) };\n });\n}\n\n/** The first and last positions, and whether they are within `loopWithin` metres of each other (a loop), or null for no route. */\nexport function ends(\n points: readonly LatLng[],\n loopWithin = 50,\n): { start: LatLng; finish: LatLng; loop: boolean } | null {\n if (!points.length) return null;\n const start = points[0];\n const finish = points[points.length - 1];\n return { start, finish, loop: distance(start, finish) <= loopWithin };\n}\n\n/** The index of the point nearest `position`, for \"where on the route is this?\". */\nexport function nearest(points: readonly LatLng[], position: LatLng): number {\n let best = -1;\n let bestD = Infinity;\n points.forEach((p, i) => {\n const d = distance(p, position);\n if (d < bestD) {\n bestD = d;\n best = i;\n }\n });\n return best;\n}\n\n/** The part of a route between two distances along it (metres, clamped, either order): the cut ends and every point between. Empty for no route. */\nexport function slice(\n points: readonly LatLng[],\n from: number,\n to: number,\n along: readonly number[] = cumulative(points),\n): LatLng[] {\n if (!points.length) return [];\n const [a, b] = from <= to ? [from, to] : [to, from];\n const start = pointAlong(points, a, along)!;\n const end = pointAlong(points, b, along)!;\n const lo = Math.max(a, 0);\n const hi = Math.min(b, along[along.length - 1]);\n const inside = points.filter((_, i) => along[i] > lo && along[i] < hi);\n return [start, ...inside, end];\n}\n\n/**\n * The nearest point on a route to `position`, not only its vertices: where it lies, how far along the\n * route that is, and how far `position` is from the route. The inverse of `pointAlong` (a cursor on a\n * map is a distance on a chart). Each leg is flattened around its own latitude, which is exact enough\n * for any leg a recording has; `index` is the leg's first point. Null for fewer than one point.\n */\nexport function snap(\n points: readonly LatLng[],\n position: LatLng,\n along: readonly number[] = cumulative(points),\n): { position: LatLng; metres: number; offset: number; index: number } | null {\n if (!points.length) return null;\n if (points.length === 1) return { position: points[0], metres: 0, offset: distance(points[0], position), index: 0 };\n let best: { position: LatLng; metres: number; offset: number; index: number } | null = null;\n for (let i = 1; i < points.length; i++) {\n const [p, q] = [points[i - 1], points[i]];\n const k = Math.cos((((p[0] + q[0]) / 2) * Math.PI) / 180);\n const [dx, dy] = [(q[1] - p[1]) * k, q[0] - p[0]];\n const len2 = dx * dx + dy * dy;\n const t =\n len2 === 0 ? 0 : Math.min(1, Math.max(0, ((position[1] - p[1]) * k * dx + (position[0] - p[0]) * dy) / len2));\n const at: LatLng = [p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t];\n const offset = distance(at, position);\n if (!best || offset < best.offset)\n best = { position: at, metres: along[i - 1] + (along[i] - along[i - 1]) * t, offset, index: i - 1 };\n }\n return best;\n}\n\n/** Route geometry helpers: `geo.distance`, `bearing`, `length`, `cumulative`, `bounds`, `pointAlong`, `snap` (its inverse), `slice`, `arrows`, `ends`, `nearest`. */\nexport const geo = { distance, bearing, cumulative, length, bounds, pointAlong, snap, slice, arrows, ends, nearest };\n","import * as React from \"react\";\n\n// A shared cursor: one position that a map, several charts and a seek bar all show at once (strata-react\n// issue #184, from strata-360, where the cursor on the elevation and pace charts is the marker on the\n// route). Each of those components already draws one position well; what an app lacked was the wiring.\n//\n// One position in a canonical unit the app chooses (metres along a route, or seconds), and every member\n// says how its own x maps to it (`CursorMapping`; the identity when they already agree). The rules:\n//\n// - **A writer never reacts to its own writes.** Every member has a `source` id, and a position whose\n// source is its own is not drawn back at it (a chart's own pointer already draws its own rule).\n// - **Two owners, and the pointer wins.** Playback sets the cursor (sixty times a second); a pointer or\n// key over any member sets it too, and holds it until it leaves, and then playback's position is\n// still there. Stored as two entries, not one value, so \"pointer left\" has something to fall back to.\n// - **It is not announced as it moves.** The scope has one polite live region, written at most once a\n// second and only for a pointer or key (never playback): sixty announcements a second are worse than\n// silence (§3.22).\n// - **A store, not state in the scope.** Members subscribe to it; the scope's children do not render\n// when the cursor moves, only the members that read it.\n//\n// Checked: React Aria has no shared-pointer part; `useSyncExternalStore` is React's own.\n\n/** Who set the cursor: a pointer or key over a member, or playback (a player's clock). */\nexport type CursorOwner = \"pointer\" | \"playback\";\n\n/** How a member's own x relates to the scope's unit. Both default to the identity. */\nexport type CursorMapping = {\n /** From this member's x to the scope's unit (a chart in seconds in a scope in metres: look it up in the series). */\n toCursor?: (x: number) => number;\n /** From the scope's unit to this member's x. */\n fromCursor?: (at: number) => number;\n};\n\ntype Entry = { at: number; source: string };\ntype Snapshot = {\n /** The position now: the pointer's while there is one, else playback's; null when neither is set. */\n at: number | null;\n /** Who wrote `at`; a member ignores a position it wrote. */\n source: string | null;\n owner: CursorOwner | null;\n};\n\nconst EMPTY: Snapshot = { at: null, source: null, owner: null };\n\nclass CursorStore {\n private pointer: Entry | null = null;\n private playback: Entry | null = null;\n private listeners = new Set<() => void>();\n snapshot: Snapshot = EMPTY;\n subscribe = (fn: () => void) => {\n this.listeners.add(fn);\n return () => void this.listeners.delete(fn);\n };\n private publish() {\n const e = this.pointer ?? this.playback;\n const owner: CursorOwner | null = this.pointer ? \"pointer\" : this.playback ? \"playback\" : null;\n if (e?.at === this.snapshot.at && e?.source === this.snapshot.source && owner === this.snapshot.owner) return;\n this.snapshot = e ? { at: e.at, source: e.source, owner } : EMPTY;\n for (const l of this.listeners) l();\n }\n /** A pointer or key over a member. `null` means it left: it clears only if the pointer was this member's, so a stale leave cannot remove another member's position. */\n setPointer(at: number | null, source: string) {\n if (at === null) {\n if (this.pointer?.source !== source) return;\n this.pointer = null;\n } else this.pointer = { at, source };\n this.publish();\n }\n setPlayback(at: number | null, source: string) {\n this.playback = at === null ? null : { at, source };\n this.publish();\n }\n}\n\nconst Scope = React.createContext<CursorStore | null>(null);\n\nexport type CursorScopeProps = {\n children: React.ReactNode;\n /** Words for the position in the scope's unit (\"12.4 km along\", \"1:23\"), for the polite announcement. Without it nothing is announced. */\n format?: (at: number) => string;\n /** Milliseconds between announcements. Default 1000. */\n announceEvery?: number;\n};\n\n/** Holds one cursor position for the charts, map and seek bar inside it, with a throttled polite announcement of where a pointer or key has put it. */\nexport function CursorScope({ children, format, announceEvery = 1000 }: CursorScopeProps) {\n const store = React.useRef<CursorStore | null>(null);\n store.current ??= new CursorStore();\n return (\n <Scope.Provider value={store.current}>\n {children}\n {format && <CursorAnnouncer store={store.current} format={format} every={announceEvery} />}\n </Scope.Provider>\n );\n}\n\n/** The live region: the latest pointer position, at most once per `every` ms (a throttle, so a pointer that never rests is still announced). */\nfunction CursorAnnouncer({\n store,\n format,\n every,\n}: {\n store: CursorStore;\n format: (at: number) => string;\n every: number;\n}) {\n const snap = React.useSyncExternalStore(\n store.subscribe,\n () => store.snapshot,\n () => EMPTY,\n );\n const [text, setText] = React.useState(\"\");\n const latest = React.useRef({ snap, format });\n latest.current = { snap, format };\n const last = React.useRef(0);\n const timer = React.useRef<number | undefined>(undefined);\n React.useEffect(() => {\n // Playback moves the cursor every frame and is never spoken; a pointer leaving says nothing.\n if (snap.owner !== \"pointer\" || snap.at === null) return;\n const speak = () => {\n timer.current = undefined;\n last.current = Date.now();\n const { snap: s, format: f } = latest.current;\n if (s.owner === \"pointer\" && s.at !== null) setText(f(s.at));\n };\n const wait = last.current + every - Date.now();\n if (wait <= 0) speak();\n else timer.current ??= window.setTimeout(speak, wait);\n }, [snap, every]);\n React.useEffect(() => () => window.clearTimeout(timer.current), []);\n return (\n <p role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n {text}\n </p>\n );\n}\n\n/** What a member reads and writes. */\nexport type SharedCursor = Snapshot & {\n /** This member's own id: positions it writes are not drawn back at it. */\n source: string;\n /** The position another member (or playback) put there, in the scope's unit; null when none or when this member wrote it. */\n other: number | null;\n /** The pointer or keyboard is at `at` over this member (the scope's unit). `null`: it left. */\n setPointer: (at: number | null) => void;\n /** Playback is at `at` (the scope's unit). Call it from the player's clock; `null` when it stops. */\n setPlayback: (at: number | null) => void;\n};\n\n/**\n * Join the nearest `CursorScope` as one member. Returns null outside a scope, so a component can take a\n * `cursor` prop and do nothing when the app has not set one up. `source` is this member's id; the\n * default is a unique one.\n */\nexport function useSharedCursor(source?: string): SharedCursor | null {\n const store = React.useContext(Scope);\n const own = React.useId();\n const id = source ?? own;\n const subscribe = React.useCallback((fn: () => void) => (store ? store.subscribe(fn) : () => {}), [store]);\n const snap = React.useSyncExternalStore(\n subscribe,\n () => store?.snapshot ?? EMPTY,\n () => EMPTY,\n );\n const setPointer = React.useCallback((at: number | null) => store?.setPointer(at, id), [store, id]);\n const setPlayback = React.useCallback((at: number | null) => store?.setPlayback(at, id), [store, id]);\n return React.useMemo(\n () =>\n store\n ? {\n ...snap,\n source: id,\n other: snap.at !== null && snap.source !== id ? snap.at : null,\n setPointer,\n setPlayback,\n }\n : null,\n [store, snap, id, setPointer, setPlayback],\n );\n}\n"],"mappings":";;;;AAcA,MAAM,MAAM,KAAK,KAAK;AACtB,MAAM,iBAAiB;;AAGvB,SAAgB,SAAS,CAAC,MAAM,OAAe,CAAC,MAAM,OAAuB;CAC3E,MAAM,IACJ,KAAK,KAAM,OAAO,QAAQ,MAAO,CAAC,KAAK,IACvC,KAAK,IAAI,OAAO,GAAG,IAAI,KAAK,IAAI,OAAO,GAAG,IAAI,KAAK,KAAM,OAAO,QAAQ,MAAO,CAAC,KAAK;CACvF,OAAO,IAAI,iBAAiB,KAAK,KAAK,KAAK,KAAK,CAAC,CAAC;AACpD;;AAGA,SAAgB,QAAQ,CAAC,MAAM,OAAe,CAAC,MAAM,OAAuB;CAC1E,MAAM,MAAM,OAAO,QAAQ,KAAK,KAAO,OAAO,QAAQ,IAAK,KAAK,KAAM,GAAG;CACzE,MAAM,KAAK,OAAO;CAClB,QAAS,KAAK,MAAM,IAAI,EAAE,IAAI,MAAO,KAAK,KAAK,OAAO;AACxD;;AAGA,SAAgB,WAAW,QAAqC;CAC9D,MAAM,MAAM,OAAO,SAAS,CAAC,CAAC,IAAI,CAAC;CACnC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,IAAI,KAAK,IAAI,IAAI,KAAK,SAAS,OAAO,IAAI,IAAI,OAAO,EAAE,CA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CAAC,GAAI,CAAC,KAAK,CAAC;CACzG,MAAM,OAAO,MAAM,qBACjB,iBACM,OAAO,YAAY,aACnB,KACR;CACA,MAAM,aAAa,MAAM,aAAa,OAAsB,OAAO,WAAW,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;CAClG,MAAM,cAAc,MAAM,aAAa,OAAsB,OAAO,YAAY,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;CACpG,OAAO,MAAM,cAET,QACI;EACE,GAAG;EACH,QAAQ;EACR,OAAO,KAAK,OAAO,QAAQ,KAAK,WAAW,KAAK,KAAK,KAAK;EAC1D;EACA;CACF,IACA,MACN;EAAC;EAAO;EAAM;EAAI;EAAY;CAAW,CAC3C;AACF"}
|
|
@@ -23,7 +23,7 @@ var HttpError = class extends Error {
|
|
|
23
23
|
this.payload = found.payload;
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
const text = (value) => typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
27
27
|
/** A field name from a FastAPI/pydantic `loc`: the path after where it came from (`["body", "address", "city"]` is `"address.city"`). */
|
|
28
28
|
function fieldName(loc) {
|
|
29
29
|
if (!Array.isArray(loc)) return void 0;
|
|
@@ -72,16 +72,16 @@ function readErrorBody(body) {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
/** A sentence ends once: "…absolute path" and "…absolute path." both end in one full stop. */
|
|
75
|
-
|
|
75
|
+
const sentence = (s) => /[.!?…]$/.test(s) ? s : `${s}.`;
|
|
76
76
|
function refused(error) {
|
|
77
77
|
if (error.reason) return `The request was refused: ${sentence(error.reason)}`;
|
|
78
78
|
if (Object.keys(error.fieldErrors).length) return "The request was refused: check the fields marked.";
|
|
79
79
|
return `The request was refused (${error.status}): ${error.statusText || "no reason given"}.`;
|
|
80
80
|
}
|
|
81
81
|
/** The default `DescribeError` for loads: the HTTP status in a sentence (with the server's reason for a 4xx), else the error's message, else a plain fallback. */
|
|
82
|
-
|
|
82
|
+
const describeHttpError = (error) => error instanceof HttpError ? error.status >= 500 ? `The server could not answer (${error.status}). Nothing was changed.` : refused(error) : error instanceof Error && error.message ? error.message : "The data could not be loaded. Nothing was changed.";
|
|
83
83
|
/** The default for `useAsyncAction`: the HTTP status in a sentence (with the server's reason for a 4xx), else the thrown Error's message, else undefined (the retry label alone). */
|
|
84
|
-
|
|
84
|
+
const describeActionError = (error) => error instanceof HttpError ? error.status >= 500 ? `The server could not answer (${error.status}).` : refused(error) : error instanceof Error && error.message ? error.message : void 0;
|
|
85
85
|
/** Messages for individual fields carried by what was thrown: an `HttpError`'s `fieldErrors`, else none. */
|
|
86
86
|
function fieldErrorsOf(error) {
|
|
87
87
|
return error instanceof HttpError ? error.fieldErrors : {};
|
|
@@ -90,6 +90,6 @@ function fieldErrorsOf(error) {
|
|
|
90
90
|
function errorPayload(error) {
|
|
91
91
|
return error instanceof HttpError ? error.payload : void 0;
|
|
92
92
|
}
|
|
93
|
-
export { fieldErrorsOf as a, errorPayload as i, describeActionError as n, readErrorBody as o, describeHttpError as r, HttpError as t };
|
|
94
93
|
|
|
95
|
-
|
|
94
|
+
export { fieldErrorsOf as a, errorPayload as i, describeActionError as n, readErrorBody as o, describeHttpError as r, HttpError as t };
|
|
95
|
+
//# sourceMappingURL=errors-CmuwcWlb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-
|
|
1
|
+
{"version":3,"file":"errors-CmuwcWlb.js","names":[],"sources":["../src/lib/errors.ts"],"sourcesContent":["// Errors, described for a person. Anything that fails in front of someone (a load in DataView, an\n// action in AsyncButton) says what happened in a sentence, in the product's words, not the\n// developer's: `HttpError`'s own message (\"409 Conflict from /api/bookings\") is for logs. Loads\n// and actions share HttpError's status sentences, so the same failure reads the same everywhere,\n// and differ only in what is true afterwards: a failed load changed nothing, while a failed action\n// may have reached the server, so its sentence does not promise that.\n//\n// A server's own reason beats the status text (strata-react issue #42, from python-app-template).\n// FastAPI and most JSON APIs say why a 4xx happened in the body (`{\"detail\": \"the data folder must\n// be an absolute path\"}`), and a client that drops it has to repeat every server rule to show the\n// person anything better than \"Bad Request\", which drifts and cannot cover rules only the server\n// can check. So `fetchJson` reads an error response's body, `HttpError` keeps it with the reason\n// and any per-field messages found in it, and the sentences below use the reason for a 4xx.\n// Per-field messages (FastAPI's 422 `detail: [{loc, msg}]`) are keyed by field name, so\n// `useAsyncAction`'s `fieldErrors` can put each under its `Field`, never in a toast. A 5xx body is\n// not shown: it is usually a stack trace or a proxy's HTML page, and is kept on `body` for logs.\n\n/** What `readErrorBody` finds in an error response: the server's sentence, and messages per field. */\nexport type ErrorBody = {\n /** Why the server refused, in its own words. */\n reason?: string;\n /** Messages for individual fields, keyed by field name (`\"name\"`, `\"address.city\"`). */\n fields?: Record<string, string>;\n /** The structured part of the body (`ErrorBody.payload` of the shared contract): what the app can act on, such as what is already running on a 409. Typed by the caller with `errorPayload`. */\n payload?: unknown;\n};\n\n/** Thrown by `fetchJson` on a non-2xx response; carries the status, the response body and the server's reason for `describeHttpError` and `describeActionError`. */\nexport class HttpError extends Error {\n /** The server's sentence for why it refused, from the body (`detail`, `message`, `error`), if it gave one. */\n readonly reason?: string;\n /** Messages for individual fields from the body (FastAPI's 422 `detail: [{loc, msg}]`), keyed by field name. Empty when there are none. */\n readonly fieldErrors: Readonly<Record<string, string>>;\n /** The body's `payload`, when it has one (`{ detail, payload }`): data for the app, not words for the person. Read it typed with `errorPayload`. */\n readonly payload?: unknown;\n\n constructor(\n readonly status: number,\n readonly statusText: string,\n readonly url: string,\n /** The response body: parsed JSON when it was JSON, else its text; undefined when empty. */\n readonly body?: unknown,\n found: ErrorBody = readErrorBody(body),\n ) {\n super(`${status} ${statusText} from ${url}`);\n this.name = \"HttpError\";\n this.reason = found.reason;\n this.fieldErrors = found.fields ?? {};\n this.payload = found.payload;\n }\n}\n\nconst text = (value: unknown) => (typeof value === \"string\" && value.trim() ? value.trim() : undefined);\n\n/** A field name from a FastAPI/pydantic `loc`: the path after where it came from (`[\"body\", \"address\", \"city\"]` is `\"address.city\"`). */\nfunction fieldName(loc: unknown) {\n if (!Array.isArray(loc)) return undefined;\n const path = loc.map(String);\n if ([\"body\", \"query\", \"path\", \"header\", \"cookie\", \"form\"].includes(path[0]) && path.length > 1) path.shift();\n return path.join(\".\") || undefined;\n}\n\n/**\n * The default reading of an error body, for the shapes most JSON APIs use: `{ detail: \"…\" }`\n * (FastAPI), `{ message: \"…\" }`, `{ error: \"…\" }` or `{ error: { message: \"…\" } }` for the reason,\n * and FastAPI's validation list `{ detail: [{ loc, msg }] }` for per-field messages. A short\n * plain-text body (not HTML) is taken as the reason too. Pass your own to `fetchJson` for other APIs.\n */\nexport function readErrorBody(body: unknown): ErrorBody {\n if (typeof body === \"string\") {\n const t = text(body);\n return t && t.length <= 300 && !t.startsWith(\"<\") ? { reason: t } : {};\n }\n if (!body || typeof body !== \"object\") return {};\n const b = body as Record<string, unknown>;\n const payload = b.payload !== undefined && b.payload !== null ? { payload: b.payload } : {};\n if (Array.isArray(b.detail)) {\n const fields: Record<string, string> = {};\n for (const item of b.detail as unknown[]) {\n const entry = item as { loc?: unknown; msg?: unknown } | null;\n const name = fieldName(entry?.loc);\n const msg = text(entry?.msg);\n if (name && msg && !fields[name]) fields[name] = msg;\n }\n return { fields, ...payload };\n }\n const nested =\n b.error && typeof b.error === \"object\" ? text((b.error as Record<string, unknown>).message) : undefined;\n return { reason: text(b.detail) ?? text(b.message) ?? text(b.error) ?? nested, ...payload };\n}\n\n/** Writes an error for a person: what happened, in a sentence. A product passes its own words. */\nexport type DescribeError = (error: unknown) => string;\n\n/** A sentence ends once: \"…absolute path\" and \"…absolute path.\" both end in one full stop. */\nconst sentence = (s: string) => (/[.!?…]$/.test(s) ? s : `${s}.`);\n\nfunction refused(error: HttpError) {\n if (error.reason) return `The request was refused: ${sentence(error.reason)}`;\n if (Object.keys(error.fieldErrors).length) return \"The request was refused: check the fields marked.\";\n return `The request was refused (${error.status}): ${error.statusText || \"no reason given\"}.`;\n}\n\n/** The default `DescribeError` for loads: the HTTP status in a sentence (with the server's reason for a 4xx), else the error's message, else a plain fallback. */\nexport const describeHttpError: DescribeError = (error) =>\n error instanceof HttpError\n ? error.status >= 500\n ? `The server could not answer (${error.status}). Nothing was changed.`\n : refused(error)\n : error instanceof Error && error.message\n ? error.message\n : \"The data could not be loaded. Nothing was changed.\";\n\n/** The default for `useAsyncAction`: the HTTP status in a sentence (with the server's reason for a 4xx), else the thrown Error's message, else undefined (the retry label alone). */\nexport const describeActionError = (error: unknown): string | undefined =>\n error instanceof HttpError\n ? error.status >= 500\n ? `The server could not answer (${error.status}).`\n : refused(error)\n : error instanceof Error && error.message\n ? error.message\n : undefined;\n\n/** Messages for individual fields carried by what was thrown: an `HttpError`'s `fieldErrors`, else none. */\nexport function fieldErrorsOf(error: unknown): Readonly<Record<string, string>> {\n return error instanceof HttpError ? error.fieldErrors : {};\n}\n\n/** The payload of an error from the server as the type the app expects (`errorPayload<{ running: string }>(error)`), or `undefined` when it is not an `HttpError` or carries none. The type is the caller's claim: check it against the API's schema. */\nexport function errorPayload<T>(error: unknown): T | undefined {\n return error instanceof HttpError ? (error.payload as T | undefined) : undefined;\n}\n"],"mappings":";;AA4BA,IAAa,YAAb,cAA+B,MAAM;CASxB;CACA;CACA;CAEA;;CAXX,AAAS;;CAET,AAAS;;CAET,AAAS;CAET,YACE,AAAS,QACT,AAAS,YACT,AAAS,KAET,AAAS,MACT,QAAmB,cAAc,IAAI,GACrC;EACA,MAAM,GAAG,OAAO,GAAG,WAAW,QAAQ,KAAK;EAPlC;EACA;EACA;EAEA;EAIT,KAAK,OAAO;EACZ,KAAK,SAAS,MAAM;EACpB,KAAK,cAAc,MAAM,UAAU,CAAC;EACpC,KAAK,UAAU,MAAM;CACvB;AACF;AAEA,MAAM,QAAQ,UAAoB,OAAO,UAAU,YAAY,MAAM,KAAK,IAAI,MAAM,KAAK,IAAI;;AAG7F,SAAS,UAAU,KAAc;CAC/B,IA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MAAM,QAAQ,OAAO,4BAA4B,SAAS,MAAM,MAAM;CAC1E,IAAI,OAAO,KAAK,MAAM,WAAW,CAAC,CAAC,QAAQ,OAAO;CAClD,OAAO,4BAA4B,MAAM,OAAO,KAAK,MAAM,cAAc,kBAAkB;AAC7F;;AAGA,MAAa,qBAAoC,UAC/C,iBAAiB,YACb,MAAM,UAAU,MACd,gCAAgC,MAAM,OAAO,2BAC7C,QAAQ,KAAK,IACf,iBAAiB,SAAS,MAAM,UAC9B,MAAM,UACN;;AAGR,MAAa,uBAAuB,UAClC,iBAAiB,YACb,MAAM,UAAU,MACd,gCAAgC,MAAM,OAAO,MAC7C,QAAQ,KAAK,IACf,iBAAiB,SAAS,MAAM,UAC9B,MAAM,UACN;;AAGR,SAAgB,cAAc,OAAkD;CAC9E,OAAO,iBAAiB,YAAY,MAAM,cAAc,CAAC;AAC3D;;AAGA,SAAgB,aAAgB,OAA+B;CAC7D,OAAO,iBAAiB,YAAa,MAAM,UAA4B;AACzE"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { r as cn } from "./tooltip-
|
|
1
|
+
import { r as cn } from "./tooltip-BosfsWYh.js";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { Label, Radio, RadioGroup } from "react-aria-components";
|
|
4
4
|
import { CircleAlert } from "lucide-react";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { useSearchParams } from "react-router";
|
|
7
|
+
|
|
7
8
|
// src/lib/format.ts
|
|
8
|
-
|
|
9
|
+
const NBSP = "\xA0";
|
|
9
10
|
/** The placeholder printed for a value that is not known: an en dash. */
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const MISSING = "–";
|
|
12
|
+
const BYTE_UNITS = [
|
|
12
13
|
"B",
|
|
13
14
|
"kB",
|
|
14
15
|
"MB",
|
|
@@ -16,8 +17,8 @@ var BYTE_UNITS = [
|
|
|
16
17
|
"TB",
|
|
17
18
|
"PB"
|
|
18
19
|
];
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const BYTE_SIZE = Object.fromEntries(BYTE_UNITS.map((u, i) => [u, 1e3 ** i]));
|
|
21
|
+
const BINARY_UNITS = [
|
|
21
22
|
"B",
|
|
22
23
|
"KiB",
|
|
23
24
|
"MiB",
|
|
@@ -25,8 +26,8 @@ var BINARY_UNITS = [
|
|
|
25
26
|
"TiB",
|
|
26
27
|
"PiB"
|
|
27
28
|
];
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
const BINARY_SIZE = Object.fromEntries(BINARY_UNITS.map((u, i) => [u, 1024 ** i]));
|
|
30
|
+
const SIZE = {
|
|
30
31
|
...BYTE_SIZE,
|
|
31
32
|
...BINARY_SIZE
|
|
32
33
|
};
|
|
@@ -56,8 +57,8 @@ function callable(nf, missing) {
|
|
|
56
57
|
resolvedOptions: () => nf.resolvedOptions()
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
const DAY = 864e5;
|
|
61
|
+
const AGO_STEPS = [
|
|
61
62
|
["year", 365 * DAY],
|
|
62
63
|
["month", 30 * DAY],
|
|
63
64
|
["week", 7 * DAY],
|
|
@@ -103,7 +104,7 @@ function createFormat(locale, options = {}) {
|
|
|
103
104
|
dateStyle: "medium",
|
|
104
105
|
timeStyle: "short"
|
|
105
106
|
});
|
|
106
|
-
const withUnit = (value, unit, fmt = integer) => `${fmt.format(value)}
|
|
107
|
+
const withUnit = (value, unit, fmt = integer) => `${fmt.format(value)}${"\xA0"}${unit}`;
|
|
107
108
|
return {
|
|
108
109
|
locale,
|
|
109
110
|
/** The zone times are shown in, or `undefined` for the viewer's own. */
|
|
@@ -211,9 +212,9 @@ function createFormat(locale, options = {}) {
|
|
|
211
212
|
Math.floor(s % 86400 / 3600),
|
|
212
213
|
Math.floor(s % 3600 / 60)
|
|
213
214
|
];
|
|
214
|
-
if (d > 0) return `${d}d
|
|
215
|
-
if (h > 0) return `${h}h
|
|
216
|
-
if (m > 0) return `${m}m
|
|
215
|
+
if (d > 0) return `${d}d${"\xA0"}${h}h${"\xA0"}${m}m`;
|
|
216
|
+
if (h > 0) return `${h}h${"\xA0"}${m}m`;
|
|
217
|
+
if (m > 0) return `${m}m${"\xA0"}${s % 60}s`;
|
|
217
218
|
return `${s}s`;
|
|
218
219
|
}
|
|
219
220
|
if (seconds < 60) return withUnit(Math.floor(seconds), "s");
|
|
@@ -237,7 +238,7 @@ function createFormat(locale, options = {}) {
|
|
|
237
238
|
const s = Math.abs(secondsAgo);
|
|
238
239
|
if (s < 1) return "now";
|
|
239
240
|
const [n, unit] = s < 60 ? [s, "s"] : s < 3600 ? [s / 60, "min"] : s < 86400 ? [s / 3600, "h"] : [s / 86400, "d"];
|
|
240
|
-
return `−${integer.format(n)}
|
|
241
|
+
return `−${integer.format(n)}${"\xA0"}${unit}`;
|
|
241
242
|
},
|
|
242
243
|
/**
|
|
243
244
|
* A distance in metres as a person says it: metres under a kilometre ("850 m"), then
|
|
@@ -258,11 +259,12 @@ function createFormat(locale, options = {}) {
|
|
|
258
259
|
* joined by a non-breaking space (`NBSP`), not a plain one: in a test, match with the same
|
|
259
260
|
* call or a `\s` regex, not a typed "6 pieces" string in a role's `name`.
|
|
260
261
|
*/
|
|
261
|
-
count: (value, one, many = `${one}s`, { compact: short = false } = {}) => value == null ? missing : `${(short ? compact : integer).format(value)}
|
|
262
|
+
count: (value, one, many = `${one}s`, { compact: short = false } = {}) => value == null ? missing : `${(short ? compact : integer).format(value)}${"\xA0"}${plurals.select(value) === "one" ? one : many}`
|
|
262
263
|
};
|
|
263
264
|
}
|
|
264
265
|
/** The en-GB formatters. */
|
|
265
|
-
|
|
266
|
+
const format = createFormat("en-GB");
|
|
267
|
+
|
|
266
268
|
// src/lib/search-param.ts
|
|
267
269
|
/**
|
|
268
270
|
* One value held in a URL search parameter (React Router): `const [mode, setMode] = useSearchParam("mode", { default: "all", parse: isMode })`.
|
|
@@ -290,14 +292,16 @@ function useSearchParam(key, { default: fallback, parse, replace = true }) {
|
|
|
290
292
|
]);
|
|
291
293
|
return [value, set];
|
|
292
294
|
}
|
|
295
|
+
|
|
293
296
|
// src/lib/control.ts
|
|
294
297
|
/** The height class of each control size. */
|
|
295
|
-
|
|
298
|
+
const controlHeight = {
|
|
296
299
|
default: "h-(--control-h)",
|
|
297
300
|
sm: "h-(--control-h-sm)"
|
|
298
301
|
};
|
|
302
|
+
|
|
299
303
|
// src/components/field.tsx
|
|
300
|
-
|
|
304
|
+
const FieldContext = React.createContext(null);
|
|
301
305
|
/** @internal The surrounding Field, and where a control reports its own message. */
|
|
302
306
|
function useFieldControl() {
|
|
303
307
|
const field = React.useContext(FieldContext);
|
|
@@ -314,7 +318,7 @@ function useField(id) {
|
|
|
314
318
|
"aria-invalid": field?.invalid || void 0
|
|
315
319
|
};
|
|
316
320
|
}
|
|
317
|
-
|
|
321
|
+
const noReport = () => {};
|
|
318
322
|
/** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */
|
|
319
323
|
function Field({ label, id: idProp, hint, error, action, children, className }) {
|
|
320
324
|
const generated = React.useId();
|
|
@@ -367,7 +371,7 @@ function Field({ label, id: idProp, hint, error, action, children, className })
|
|
|
367
371
|
})
|
|
368
372
|
});
|
|
369
373
|
}
|
|
370
|
-
|
|
374
|
+
const control = "w-full min-w-0 rounded-control border border-input bg-background px-3 type-body text-foreground transition-state placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-70 aria-invalid:border-danger";
|
|
371
375
|
/** A text input that picks up its id and descriptions from the surrounding `Field`. `size="sm"` is --control-h-sm; the native `size` (a width in characters) is not passed on. */
|
|
372
376
|
function Input$1({ className, id, size = "default", ...props }) {
|
|
373
377
|
return /* @__PURE__ */ jsx("input", {
|
|
@@ -487,6 +491,6 @@ function ChoiceGroupView({ legend, name, choices, value, onChange, error }) {
|
|
|
487
491
|
]
|
|
488
492
|
});
|
|
489
493
|
}
|
|
490
|
-
export { Textarea as a, useSearchParam as c, createFormat as d, format as f, NativeSelect as i, MISSING as l, Field as n, useFieldControl as o, toDate as p, Input$1 as r, controlHeight as s, ChoiceGroup as t, NBSP as u };
|
|
491
494
|
|
|
492
|
-
|
|
495
|
+
export { Textarea as a, useSearchParam as c, createFormat as d, format as f, NativeSelect as i, MISSING as l, Field as n, useFieldControl as o, toDate as p, Input$1 as r, controlHeight as s, ChoiceGroup as t, NBSP as u };
|
|
496
|
+
//# sourceMappingURL=field-DBCsFIng.js.map
|