@azx-pbc/axiom-web 0.0.0-stage → 0.0.6
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/LICENSE +21 -0
- package/README.md +161 -2
- package/dist/address.d.ts +32 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +146 -0
- package/dist/address.js.map +1 -0
- package/dist/capture/MediaCapture.d.ts +45 -0
- package/dist/capture/MediaCapture.d.ts.map +1 -0
- package/dist/capture/MediaCapture.js +669 -0
- package/dist/capture/MediaCapture.js.map +1 -0
- package/dist/capture/SignatureCapture.d.ts +31 -0
- package/dist/capture/SignatureCapture.d.ts.map +1 -0
- package/dist/capture/SignatureCapture.js +329 -0
- package/dist/capture/SignatureCapture.js.map +1 -0
- package/dist/capture/copy.d.ts +101 -0
- package/dist/capture/copy.d.ts.map +1 -0
- package/dist/capture/copy.js +1369 -0
- package/dist/capture/copy.js.map +1 -0
- package/dist/capture/index.d.ts +19 -0
- package/dist/capture/index.d.ts.map +1 -0
- package/dist/capture/index.js +14 -0
- package/dist/capture/index.js.map +1 -0
- package/dist/capture/media-kind.d.ts +16 -0
- package/dist/capture/media-kind.d.ts.map +1 -0
- package/dist/capture/media-kind.js +64 -0
- package/dist/capture/media-kind.js.map +1 -0
- package/dist/capture/permissions.d.ts +109 -0
- package/dist/capture/permissions.d.ts.map +1 -0
- package/dist/capture/permissions.js +172 -0
- package/dist/capture/permissions.js.map +1 -0
- package/dist/capture/refusal.d.ts +13 -0
- package/dist/capture/refusal.d.ts.map +1 -0
- package/dist/capture/refusal.js +16 -0
- package/dist/capture/refusal.js.map +1 -0
- package/dist/controls.d.ts +64 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +2524 -0
- package/dist/controls.js.map +1 -0
- package/dist/coordinate.d.ts +38 -0
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +220 -0
- package/dist/coordinate.js.map +1 -0
- package/dist/copy.d.ts +313 -0
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +2602 -0
- package/dist/copy.js.map +1 -0
- package/dist/countries.d.ts +14 -0
- package/dist/countries.d.ts.map +1 -0
- package/dist/countries.js +264 -0
- package/dist/countries.js.map +1 -0
- package/dist/format/calendar-locale.d.ts +19 -0
- package/dist/format/calendar-locale.d.ts.map +1 -0
- package/dist/format/calendar-locale.js +38 -0
- package/dist/format/calendar-locale.js.map +1 -0
- package/dist/format/country-names.d.ts +21 -0
- package/dist/format/country-names.d.ts.map +1 -0
- package/dist/format/country-names.js +2277 -0
- package/dist/format/country-names.js.map +1 -0
- package/dist/format/date.d.ts +58 -0
- package/dist/format/date.d.ts.map +1 -0
- package/dist/format/date.js +155 -0
- package/dist/format/date.js.map +1 -0
- package/dist/format/digits.d.ts +23 -0
- package/dist/format/digits.d.ts.map +1 -0
- package/dist/format/digits.js +46 -0
- package/dist/format/digits.js.map +1 -0
- package/dist/format/index.d.ts +28 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +24 -0
- package/dist/format/index.js.map +1 -0
- package/dist/format/locale.d.ts +33 -0
- package/dist/format/locale.d.ts.map +1 -0
- package/dist/format/locale.js +39 -0
- package/dist/format/locale.js.map +1 -0
- package/dist/format/media-type.d.ts +8 -0
- package/dist/format/media-type.d.ts.map +1 -0
- package/dist/format/media-type.js +302 -0
- package/dist/format/media-type.js.map +1 -0
- package/dist/format/money.d.ts +52 -0
- package/dist/format/money.d.ts.map +1 -0
- package/dist/format/money.js +36 -0
- package/dist/format/money.js.map +1 -0
- package/dist/format/number.d.ts +28 -0
- package/dist/format/number.d.ts.map +1 -0
- package/dist/format/number.js +91 -0
- package/dist/format/number.js.map +1 -0
- package/dist/host.d.ts +122 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +20 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/media.d.ts +42 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +151 -0
- package/dist/media.js.map +1 -0
- package/dist/pickers/DatePicker.d.ts +35 -0
- package/dist/pickers/DatePicker.d.ts.map +1 -0
- package/dist/pickers/DatePicker.js +212 -0
- package/dist/pickers/DatePicker.js.map +1 -0
- package/dist/pickers/TimeSegments.d.ts +27 -0
- package/dist/pickers/TimeSegments.d.ts.map +1 -0
- package/dist/pickers/TimeSegments.js +82 -0
- package/dist/pickers/TimeSegments.js.map +1 -0
- package/dist/pickers/day-picker-locale.d.ts +15 -0
- package/dist/pickers/day-picker-locale.d.ts.map +1 -0
- package/dist/pickers/day-picker-locale.js +46 -0
- package/dist/pickers/day-picker-locale.js.map +1 -0
- package/dist/render/dom.d.ts +100 -0
- package/dist/render/dom.d.ts.map +1 -0
- package/dist/render/dom.js +882 -0
- package/dist/render/dom.js.map +1 -0
- package/dist/render/layout.d.ts +45 -0
- package/dist/render/layout.d.ts.map +1 -0
- package/dist/render/layout.js +8 -0
- package/dist/render/layout.js.map +1 -0
- package/dist/schedule/SchedulePicker.d.ts +46 -0
- package/dist/schedule/SchedulePicker.d.ts.map +1 -0
- package/dist/schedule/SchedulePicker.js +160 -0
- package/dist/schedule/SchedulePicker.js.map +1 -0
- package/dist/schedule/timeslot.d.ts +52 -0
- package/dist/schedule/timeslot.d.ts.map +1 -0
- package/dist/schedule/timeslot.js +265 -0
- package/dist/schedule/timeslot.js.map +1 -0
- package/dist/styles.css +2151 -0
- package/dist/theme/index.d.ts +12 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +11 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/presets.d.ts +93 -0
- package/dist/theme/presets.d.ts.map +1 -0
- package/dist/theme/presets.js +200 -0
- package/dist/theme/presets.js.map +1 -0
- package/dist/tokens.css +234 -0
- package/dist/wizard-checkpoints.d.ts +18 -0
- package/dist/wizard-checkpoints.d.ts.map +1 -0
- package/dist/wizard-checkpoints.js +56 -0
- package/dist/wizard-checkpoints.js.map +1 -0
- package/package.json +76 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AZX, PBC. Open Source
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,162 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @azx-pbc/axiom-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Axiom's reference web renderer for React 19. One `<RenderedForm>` paints a compiled artifact's
|
|
4
|
+
layout tree and every control in `CONTROLS`, with the copy, host-action and theme contracts a host
|
|
5
|
+
fills in. It depends on `@azx-pbc/axiom-react` and `@azx-pbc/axiom-runtime`, and peers on React.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @azx-pbc/axiom-web @azx-pbc/axiom-react @azx-pbc/axiom-runtime react@^19 react-dom@^19
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
From a checkout, `pnpm install` links the workspace packages. The published package is ESM-only and
|
|
14
|
+
peers on React and `react-dom`.
|
|
15
|
+
|
|
16
|
+
The manifest states Node `>=24`; the renderer mounts wherever React 19 and a DOM run.
|
|
17
|
+
|
|
18
|
+
## Use
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import type { ReactElement } from 'react';
|
|
22
|
+
import { FormProvider } from '@azx-pbc/axiom-react';
|
|
23
|
+
import type { AccessEntry, CompiledSchema, WireRecord } from '@azx-pbc/axiom-runtime';
|
|
24
|
+
import { FormCopyContext, HostActionsContext, RenderedForm, formCopy } from '@azx-pbc/axiom-web';
|
|
25
|
+
import type { HostActions } from '@azx-pbc/axiom-web';
|
|
26
|
+
|
|
27
|
+
declare const hostActions: HostActions;
|
|
28
|
+
declare const translate: (key: string) => string;
|
|
29
|
+
|
|
30
|
+
export function Page(props: {
|
|
31
|
+
readonly compiled: CompiledSchema;
|
|
32
|
+
readonly record: WireRecord;
|
|
33
|
+
readonly access: readonly AccessEntry[];
|
|
34
|
+
}): ReactElement {
|
|
35
|
+
const copy = formCopy('en');
|
|
36
|
+
return (
|
|
37
|
+
<HostActionsContext.Provider value={hostActions}>
|
|
38
|
+
<FormCopyContext.Provider value={copy}>
|
|
39
|
+
<FormProvider
|
|
40
|
+
compiled={props.compiled}
|
|
41
|
+
initialValues={props.record}
|
|
42
|
+
access={props.access}
|
|
43
|
+
valueDisplay={copy.display}
|
|
44
|
+
>
|
|
45
|
+
<RenderedForm fields={props.compiled.fields} translate={translate} />
|
|
46
|
+
</FormProvider>
|
|
47
|
+
</FormCopyContext.Provider>
|
|
48
|
+
</HostActionsContext.Provider>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`RenderedForm` paints the body; it has no submit button and no `onSubmit`. The host's bar calls
|
|
54
|
+
`useForm().handleSubmit(save)`, which performs the submit and returns the `Promise<void>` that
|
|
55
|
+
settles when it finishes, and the API that authorises the write is the host's. The deprecated
|
|
56
|
+
`submitHandler(save)` returns the same call as a thunk for a handler that is bound directly.
|
|
57
|
+
The two stylesheets are asset doors, imported where a bundler resolves CSS:
|
|
58
|
+
`@azx-pbc/axiom-web/tokens.css` and `@azx-pbc/axiom-web/styles.css`.
|
|
59
|
+
|
|
60
|
+
## The seams
|
|
61
|
+
|
|
62
|
+
- `ControlComponents` replaces one control, keyed by the closed `Control` union plus the two
|
|
63
|
+
capture hints (`signature`, `media`). The adapter keeps the label, hint, error and wrapper.
|
|
64
|
+
- `LayoutComponents` replaces one container kind (`section`, `group`, `wizard`, `step`, `records`,
|
|
65
|
+
`record`, `summary_card`, `heading`, `callout`, `divider`, `sop_block`, `error_summary`). The
|
|
66
|
+
slot receives the adapter's own rendering as `children`, so it can wrap it or replace it.
|
|
67
|
+
- `FormCopy` (also exported as the earlier `HostCopy`) is the host's words for failures the
|
|
68
|
+
artifact states no message key for, plus `display` for values whose wire spelling is not prose.
|
|
69
|
+
- `HostActions` supplies the capabilities the device cannot perform: a signature service, a media
|
|
70
|
+
picker and a position reading.
|
|
71
|
+
|
|
72
|
+
`react-dom` is a peer because the form mounts in a browser tree; the renderer itself imports only
|
|
73
|
+
`react`, and never `react-dom`.
|
|
74
|
+
|
|
75
|
+
## Copy and locale
|
|
76
|
+
|
|
77
|
+
`FormCopyContext` **defaults to packaged English**: the context is created with
|
|
78
|
+
`formCopy(undefined)`, which returns the `en` catalogue. A tree under no provider therefore paints
|
|
79
|
+
English, not empty strings. `formCopy(locale)` carries all nine shipped languages (`en`, `es`,
|
|
80
|
+
`pt`, `fr`, `ar`, `de`, `it`, `ru` and `zh`); an unshipped locale falls back to English. Override
|
|
81
|
+
the provider with `formCopy(locale)` for those nine, or with your own full `FormCopy` object for
|
|
82
|
+
any other language. Arabic is a shipped right-to-left catalogue, so a host that declares `ar`
|
|
83
|
+
inherits its text and direction. `useFormCopy()` reads the value in force.
|
|
84
|
+
`FormCopy.display` is the port the provider passes as `valueDisplay`, because a boolean and a list
|
|
85
|
+
have no locale-neutral spelling. It also owns where a currency mark sits relative to the amount.
|
|
86
|
+
|
|
87
|
+
The `@azx-pbc/axiom-web/format` door carries the vendored locale mechanics for a host that
|
|
88
|
+
formats outside a control: `resolveLocale`, `formatDecimal`, `formatMoney`, `formatCivilDate`,
|
|
89
|
+
the digit policies and the bare `date-fns` calendar table the readout uses. The pickers read a
|
|
90
|
+
picker-only table that spreads those same objects and adds DayPicker's labels, so the two share
|
|
91
|
+
one `localize` source without making a readout-only host pay for the labels.
|
|
92
|
+
`formatMoney` returns the grouped amount and the currency code, never a symbol or a placement:
|
|
93
|
+
the copy layer's `FormCopy.display` writes the mark and its side, so an amount and its sentence
|
|
94
|
+
cannot disagree. No function on either door consults `Intl` or a host locale database.
|
|
95
|
+
|
|
96
|
+
The package's own modules are also clean of host formatters, but `react-day-picker` contains
|
|
97
|
+
`Intl` paths of its own: its month/year formatter uses `Intl.DateTimeFormat` for the year-first
|
|
98
|
+
locales, Chinese included. The picker overrides that caption and grid label with the vendored
|
|
99
|
+
month table, and `picker-locale.test.tsx` renders the Chinese calendar with
|
|
100
|
+
`Intl.DateTimeFormat` and `Intl.NumberFormat` stubbed to throw, so a dependency reintroducing the
|
|
101
|
+
call fails the suite rather than only escaping the dist scan.
|
|
102
|
+
|
|
103
|
+
## Server rendering
|
|
104
|
+
|
|
105
|
+
The renderer reads no DOM API during render, so `renderToString` works; `applyTheme` probes for
|
|
106
|
+
`document` and returns without touching a global when there is none. Element ids come from React's
|
|
107
|
+
`useId()` through `FormProvider`, so the server string and the browser's first render agree
|
|
108
|
+
(`src/__tests__/theme-ssr.test.ts` covers the theme call). Host option loaders start after mount, so
|
|
109
|
+
a server string is in the idle state and the first client paint may be `loading`; that is an update,
|
|
110
|
+
not a mismatch. Hydrate with the same artifact, record, access answer and locale that produced the
|
|
111
|
+
string.
|
|
112
|
+
|
|
113
|
+
## Testing
|
|
114
|
+
|
|
115
|
+
There are **no host-facing test utilities**: this package publishes no `./testing` door, no render
|
|
116
|
+
helper and no fixture. Test your own components with your own runner. `@azx-pbc/axiom-runtime/testing`
|
|
117
|
+
and `@azx-pbc/axiom-compiler/testing` exist for this repository's own suites and carry no host
|
|
118
|
+
compatibility guarantee.
|
|
119
|
+
|
|
120
|
+
## What the host implements
|
|
121
|
+
|
|
122
|
+
The package renders and formats; it does not store or transport. **The host implements** the
|
|
123
|
+
artifact and record stores, the draft store, the submit queue and retries, offline durability,
|
|
124
|
+
authentication and authorisation, file upload and media storage, and the signature service. The
|
|
125
|
+
`HostActions` you supply are the seams for the last two: the library never opens a file, uploads
|
|
126
|
+
bytes, keeps a copy, or calls `navigator.geolocation`.
|
|
127
|
+
|
|
128
|
+
## Unavailable options
|
|
129
|
+
|
|
130
|
+
An artifact can state that an option may not be chosen, and why: a declared `availableWhen`
|
|
131
|
+
condition, or a host page item marked `available: false`. The runtime decides that answer per code
|
|
132
|
+
and the renderer paints it once, so a `select`, a `radio` group, a `combobox` and a `multiselect`
|
|
133
|
+
(painted as a checkbox group by default) render the same choice list. `rank` and `timeslot` keep their own
|
|
134
|
+
affordance: a ranking is an order rather than a selection, and a timeslot page holds slot records
|
|
135
|
+
the runtime states no option code for. While any offered code may not be chosen, the field is
|
|
136
|
+
painted as the choice list of focusable `option` elements. An entry the record
|
|
137
|
+
refuses carries `aria-disabled="true"` and the sentence explaining why, named by its
|
|
138
|
+
`aria-describedby`, and never the HTML `disabled` attribute: it stays in the tab order, so its reason
|
|
139
|
+
can be read, and a press still calls the binding's `setValue`. An entry whose availability is not
|
|
140
|
+
decided yet stays operable and states its cause.
|
|
141
|
+
|
|
142
|
+
That write is the host's to judge. Pass `FormProvider`'s `onWriteProposed` to stage a refused choice
|
|
143
|
+
as a proposal instead of committing it, and answer with `applyProposal` or `discardProposal`. A
|
|
144
|
+
field-level refusal keeps its own answer: a read-only field paints the value and no affordance, and
|
|
145
|
+
a disabled one paints the list while no press reaches the session.
|
|
146
|
+
|
|
147
|
+
The list is `role="listbox"`, with `aria-multiselectable` for a multiple selection, and it keeps the
|
|
148
|
+
field's legend, description, failure and requirement. Focus moves with the arrow keys, `Home` and
|
|
149
|
+
`End`; `Enter` and `Space` press the focused entry. The class hooks are `.ax-choice-list` for the
|
|
150
|
+
group and `.ax-option` for an entry, with `data-option-state="unavailable"` or `"undetermined"` and
|
|
151
|
+
`aria-selected` stating the rest.
|
|
152
|
+
|
|
153
|
+
A host domain may arrive in pages. While the last resolved page states a `nextCursor`, the renderer
|
|
154
|
+
paints `FormCopy.loadMoreOptions()` under the control (`data-options-more`); the press asks the page
|
|
155
|
+
machine for one more page and the field re-reads the merged domain, so a code a later page refuses is
|
|
156
|
+
painted as unavailable exactly like one the first page refused. One page is in flight at a time, and
|
|
157
|
+
a page that rejects stops the action and states the failure rather than retrying it.
|
|
158
|
+
|
|
159
|
+
## Styles
|
|
160
|
+
|
|
161
|
+
`./tokens.css` is the token contract and `./styles.css` is the component sheet. A host with its own
|
|
162
|
+
design system keeps the `.ax-*` class hooks and state attributes and imports neither.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { WireValue } from '@azx-pbc/axiom-runtime';
|
|
3
|
+
/**
|
|
4
|
+
* One `address` value, edited as the closed shape the wire declares.
|
|
5
|
+
*
|
|
6
|
+
* The form of the record, not the shape of a country, is the contract: `line1`, `city`,
|
|
7
|
+
* `postalCode` and `country` are required members and `line2` and `region` are optional, and
|
|
8
|
+
* `country` is an upper-case ISO alpha-2 code. The editor writes a record only when those four
|
|
9
|
+
* are non-empty and the code is well formed. An incomplete value is a local draft the reader may
|
|
10
|
+
* leave on the page; it never reaches the binding, so a half-typed address cannot overwrite a
|
|
11
|
+
* stored one. Validation is structural only — no postal format and no geocoding — because
|
|
12
|
+
* `MODEL-2.1.25` deliberately leaves those to the host.
|
|
13
|
+
*
|
|
14
|
+
* The group is a `fieldset` with the field's own label as its legend, and every member has its
|
|
15
|
+
* own label whose accessible name names the address it belongs to as well. The picker's labels
|
|
16
|
+
* are localised through the copy catalogue, so a code is a value and never the visible name.
|
|
17
|
+
*/
|
|
18
|
+
export interface AddressEditorProps {
|
|
19
|
+
readonly controlId: string;
|
|
20
|
+
/** The field's label and required marker, already translated for this page. */
|
|
21
|
+
readonly legend: ReactNode;
|
|
22
|
+
readonly label: string;
|
|
23
|
+
readonly value: WireValue | undefined;
|
|
24
|
+
readonly setValue: (value: WireValue) => void;
|
|
25
|
+
readonly describedBy: string | undefined;
|
|
26
|
+
readonly required: boolean;
|
|
27
|
+
readonly invalid: boolean;
|
|
28
|
+
readonly disabled: boolean;
|
|
29
|
+
readonly onBlur: () => void;
|
|
30
|
+
}
|
|
31
|
+
export declare function AddressEditor({ controlId, legend, label, value, setValue, describedBy, required, invalid, disabled, onBlur, }: AddressEditorProps): ReactElement;
|
|
32
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAKpE;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;CAC7B;AA2ED,wBAAgB,aAAa,CAAC,EAC5B,SAAS,EACT,MAAM,EACN,KAAK,EACL,KAAK,EACL,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,MAAM,GACP,EAAE,kBAAkB,GAAG,YAAY,CAwJnC"}
|
package/dist/address.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { COUNTRY_CODE_PATTERN, isRecord, sameWireValue } from '@azx-pbc/axiom-runtime';
|
|
4
|
+
import { ALPHA2_COUNTRY_CODES } from './countries.js';
|
|
5
|
+
import { useHostCopy } from './copy.js';
|
|
6
|
+
const BLANK = Object.freeze({
|
|
7
|
+
line1: '',
|
|
8
|
+
line2: '',
|
|
9
|
+
city: '',
|
|
10
|
+
region: '',
|
|
11
|
+
postalCode: '',
|
|
12
|
+
country: '',
|
|
13
|
+
});
|
|
14
|
+
/** The members a stored value shows, with anything that is not text read as empty. */
|
|
15
|
+
function draftOf(value) {
|
|
16
|
+
if (!isRecord(value))
|
|
17
|
+
return BLANK;
|
|
18
|
+
const member = (key) => {
|
|
19
|
+
const raw = value[key];
|
|
20
|
+
return typeof raw === 'string' ? raw : '';
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
line1: member('line1'),
|
|
24
|
+
line2: member('line2'),
|
|
25
|
+
city: member('city'),
|
|
26
|
+
region: member('region'),
|
|
27
|
+
postalCode: member('postalCode'),
|
|
28
|
+
country: member('country'),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The wire record a draft states, or `undefined` while it is incomplete.
|
|
33
|
+
*
|
|
34
|
+
* Empty optional members are omitted rather than written as empty strings: the wire refuses a
|
|
35
|
+
* present empty member, so `{ line2: '' }` would be a record the engine rejects. The required
|
|
36
|
+
* members are trimmed for the same reason: whitespace is a draft, not an address line.
|
|
37
|
+
*/
|
|
38
|
+
function recordOf(draft) {
|
|
39
|
+
const line1 = draft.line1.trim();
|
|
40
|
+
const line2 = draft.line2.trim();
|
|
41
|
+
const city = draft.city.trim();
|
|
42
|
+
const region = draft.region.trim();
|
|
43
|
+
const postalCode = draft.postalCode.trim();
|
|
44
|
+
const country = draft.country;
|
|
45
|
+
if (line1 === '' || city === '' || postalCode === '' || !COUNTRY_CODE_PATTERN.test(country)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
line1,
|
|
50
|
+
city,
|
|
51
|
+
postalCode,
|
|
52
|
+
country,
|
|
53
|
+
...(line2 === '' ? {} : { line2 }),
|
|
54
|
+
...(region === '' ? {} : { region }),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function AddressEditor({ controlId, legend, label, value, setValue, describedBy, required, invalid, disabled, onBlur, }) {
|
|
58
|
+
const copy = useHostCopy();
|
|
59
|
+
const published = draftOf(value);
|
|
60
|
+
// The draft is what the reader has typed; with none, the control shows the stored address.
|
|
61
|
+
// Keeping a partial draft is the point: it is the reader's work in progress, not a value the
|
|
62
|
+
// wire accepted, and blurring must not discard it.
|
|
63
|
+
const [draft, setDraft] = useState(undefined);
|
|
64
|
+
const shown = draft ?? published;
|
|
65
|
+
const relations = {
|
|
66
|
+
'aria-invalid': invalid,
|
|
67
|
+
...(describedBy === undefined || describedBy === '' ? {} : { 'aria-describedby': describedBy }),
|
|
68
|
+
};
|
|
69
|
+
const change = (member, text) => {
|
|
70
|
+
const next = { ...shown, [member]: text };
|
|
71
|
+
setDraft(next);
|
|
72
|
+
const record = recordOf(next);
|
|
73
|
+
if (record !== undefined) {
|
|
74
|
+
if (!sameWireValue(record, value))
|
|
75
|
+
setValue(record);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// The stored value was a complete address and this edit is not one: keeping the old record
|
|
79
|
+
// would export an address the control no longer shows, and blurring would not correct it
|
|
80
|
+
// because an incomplete draft stays while the reader is still typing. A clear is the write
|
|
81
|
+
// that makes the record and the screen agree. A draft over a record that was never complete
|
|
82
|
+
// stays local — there is nothing to clear.
|
|
83
|
+
if (recordOf(published) !== undefined)
|
|
84
|
+
setValue(null);
|
|
85
|
+
};
|
|
86
|
+
const blur = () => {
|
|
87
|
+
// A complete draft is the record now; dropping it lets a reset or a re-baseline reach the
|
|
88
|
+
// control again. An incomplete draft stays, because the reader may still be typing.
|
|
89
|
+
if (recordOf(shown) !== undefined)
|
|
90
|
+
setDraft(undefined);
|
|
91
|
+
onBlur();
|
|
92
|
+
};
|
|
93
|
+
const members = [
|
|
94
|
+
{
|
|
95
|
+
member: 'line1',
|
|
96
|
+
label: copy.addressLine1(),
|
|
97
|
+
autoComplete: 'address-line1',
|
|
98
|
+
wide: true,
|
|
99
|
+
required: true,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
member: 'line2',
|
|
103
|
+
label: copy.addressLine2(),
|
|
104
|
+
autoComplete: 'address-line2',
|
|
105
|
+
wide: true,
|
|
106
|
+
required: false,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
member: 'city',
|
|
110
|
+
label: copy.addressCity(),
|
|
111
|
+
autoComplete: 'address-level2',
|
|
112
|
+
wide: false,
|
|
113
|
+
required: true,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
member: 'region',
|
|
117
|
+
label: copy.addressRegion(),
|
|
118
|
+
autoComplete: 'address-level1',
|
|
119
|
+
wide: false,
|
|
120
|
+
required: false,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
member: 'postalCode',
|
|
124
|
+
label: copy.addressPostalCode(),
|
|
125
|
+
autoComplete: 'postal-code',
|
|
126
|
+
wide: false,
|
|
127
|
+
required: true,
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
// A stored code the current list does not know is still shown, rather than silently changing
|
|
131
|
+
// the reader's country to the first option. The wire accepts any upper-case alpha-2 code.
|
|
132
|
+
const codes = shown.country === '' || ALPHA2_COUNTRY_CODES.includes(shown.country)
|
|
133
|
+
? ALPHA2_COUNTRY_CODES
|
|
134
|
+
: [shown.country, ...ALPHA2_COUNTRY_CODES];
|
|
135
|
+
const countryId = `${controlId}-country`;
|
|
136
|
+
return (_jsxs("fieldset", { className: "ax-address",
|
|
137
|
+
// The group is the element a summary link lands on; `-1` makes it focusable by script
|
|
138
|
+
// without adding a tab stop. Its members follow as their own stops.
|
|
139
|
+
id: controlId, tabIndex: -1, "aria-invalid": invalid, ...(describedBy === undefined || describedBy === ''
|
|
140
|
+
? {}
|
|
141
|
+
: { 'aria-describedby': describedBy }), children: [_jsx("legend", { className: "ax-label", children: legend }), members.map((spec) => {
|
|
142
|
+
const memberId = `${controlId}-${spec.member}`;
|
|
143
|
+
return (_jsxs("div", { className: spec.wide ? 'ax-address-member ax-address-member--wide' : 'ax-address-member', children: [_jsxs("label", { className: "ax-label", htmlFor: memberId, children: [spec.label, ' ', _jsx("span", { className: "ax-visually-hidden axiom-visually-hidden", children: copy.memberScope(label) })] }), _jsx("input", { id: memberId, className: "ax-control ax-control--address", type: "text", autoComplete: spec.autoComplete, value: shown[spec.member], ...relations, "aria-required": required && spec.required, disabled: disabled, onChange: (event) => change(spec.member, event.target.value), onBlur: blur })] }, spec.member));
|
|
144
|
+
}), _jsxs("div", { className: "ax-address-member ax-address-member--country", children: [_jsxs("label", { className: "ax-label", htmlFor: countryId, children: [copy.addressCountry(), ' ', _jsx("span", { className: "ax-visually-hidden axiom-visually-hidden", children: copy.memberScope(label) })] }), _jsxs("select", { id: countryId, className: "ax-control ax-control--address", autoComplete: "country", value: shown.country, ...relations, "aria-required": required, disabled: disabled, onChange: (event) => change('country', event.target.value), onBlur: blur, children: [_jsx("option", { value: "", children: copy.addressCountryPlaceholder() }), codes.map((code) => (_jsx("option", { value: code, children: copy.countryName(code) }, code)))] })] })] }));
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src/address.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AA0CxC,MAAM,KAAK,GAAiB,MAAM,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,EAAE;IACV,UAAU,EAAE,EAAE;IACd,OAAO,EAAE,EAAE;CACZ,CAAC,CAAC;AAEH,sFAAsF;AACtF,SAAS,OAAO,CAAC,KAA4B;IAC3C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACnC,MAAM,MAAM,GAAG,CAAC,GAAkB,EAAU,EAAE;QAC5C,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5C,CAAC,CAAC;IACF,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC;QACtB,KAAK,EAAE,MAAM,CAAC,OAAO,C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AC,0CAA0C,YACvD,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GACnB,IACD,EACR,kBACE,EAAE,EAAE,SAAS,EACb,SAAS,EAAC,gCAAgC,EAC1C,YAAY,EAAC,SAAS,EACtB,KAAK,EAAE,KAAK,CAAC,OAAO,KAChB,SAAS,mBACE,QAAQ,EACvB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,CAAC,KAAqC,EAAE,EAAE,CAClD,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAEvC,MAAM,EAAE,IAAI,aAEZ,iBAAQ,KAAK,EAAC,EAAE,YAAE,IAAI,CAAC,yBAAyB,EAAE,GAAU,EAC3D,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACnB,iBAAmB,KAAK,EAAE,IAAI,YAC3B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IADZ,IAAI,CAER,CACV,CAAC,IACK,IACL,IACG,CACZ,CAAC;AACJ,CAAC","sourcesContent":["import { useState } from 'react';\nimport type { ChangeEvent, ReactElement, ReactNode } from 'react';\nimport type { WireRecord, WireValue } from '@azx-pbc/axiom-runtime';\nimport { COUNTRY_CODE_PATTERN, isRecord, sameWireValue } from '@azx-pbc/axiom-runtime';\nimport { ALPHA2_COUNTRY_CODES } from './countries.js';\nimport { useHostCopy } from './copy.js';\n\n/**\n * One `address` value, edited as the closed shape the wire declares.\n *\n * The form of the record, not the shape of a country, is the contract: `line1`, `city`,\n * `postalCode` and `country` are required members and `line2` and `region` are optional, and\n * `country` is an upper-case ISO alpha-2 code. The editor writes a record only when those four\n * are non-empty and the code is well formed. An incomplete value is a local draft the reader may\n * leave on the page; it never reaches the binding, so a half-typed address cannot overwrite a\n * stored one. Validation is structural only — no postal format and no geocoding — because\n * `MODEL-2.1.25` deliberately leaves those to the host.\n *\n * The group is a `fieldset` with the field's own label as its legend, and every member has its\n * own label whose accessible name names the address it belongs to as well. The picker's labels\n * are localised through the copy catalogue, so a code is a value and never the visible name.\n */\nexport interface AddressEditorProps {\n readonly controlId: string;\n /** The field's label and required marker, already translated for this page. */\n readonly legend: ReactNode;\n readonly label: string;\n readonly value: WireValue | undefined;\n readonly setValue: (value: WireValue) => void;\n readonly describedBy: string | undefined;\n readonly required: boolean;\n readonly invalid: boolean;\n readonly disabled: boolean;\n readonly onBlur: () => void;\n}\n\ntype AddressMember = 'line1' | 'line2' | 'city' | 'region' | 'postalCode' | 'country';\n\ninterface AddressDraft {\n readonly line1: string;\n readonly line2: string;\n readonly city: string;\n readonly region: string;\n readonly postalCode: string;\n readonly country: string;\n}\n\nconst BLANK: AddressDraft = Object.freeze({\n line1: '',\n line2: '',\n city: '',\n region: '',\n postalCode: '',\n country: '',\n});\n\n/** The members a stored value shows, with anything that is not text read as empty. */\nfunction draftOf(value: WireValue | undefined): AddressDraft {\n if (!isRecord(value)) return BLANK;\n const member = (key: AddressMember): string => {\n const raw = value[key];\n return typeof raw === 'string' ? raw : '';\n };\n return {\n line1: member('line1'),\n line2: member('line2'),\n city: member('city'),\n region: member('region'),\n postalCode: member('postalCode'),\n country: member('country'),\n };\n}\n\n/**\n * The wire record a draft states, or `undefined` while it is incomplete.\n *\n * Empty optional members are omitted rather than written as empty strings: the wire refuses a\n * present empty member, so `{ line2: '' }` would be a record the engine rejects. The required\n * members are trimmed for the same reason: whitespace is a draft, not an address line.\n */\nfunction recordOf(draft: AddressDraft): WireRecord | undefined {\n const line1 = draft.line1.trim();\n const line2 = draft.line2.trim();\n const city = draft.city.trim();\n const region = draft.region.trim();\n const postalCode = draft.postalCode.trim();\n const country = draft.country;\n if (line1 === '' || city === '' || postalCode === '' || !COUNTRY_CODE_PATTERN.test(country)) {\n return undefined;\n }\n return {\n line1,\n city,\n postalCode,\n country,\n ...(line2 === '' ? {} : { line2 }),\n ...(region === '' ? {} : { region }),\n };\n}\n\ninterface MemberSpec {\n readonly member: Exclude<AddressMember, 'country'>;\n readonly label: string;\n readonly autoComplete: string;\n readonly wide: boolean;\n /** The wire requires this member; `aria-required` states the member, not just the field. */\n readonly required: boolean;\n}\n\nexport function AddressEditor({\n controlId,\n legend,\n label,\n value,\n setValue,\n describedBy,\n required,\n invalid,\n disabled,\n onBlur,\n}: AddressEditorProps): ReactElement {\n const copy = useHostCopy();\n const published = draftOf(value);\n // The draft is what the reader has typed; with none, the control shows the stored address.\n // Keeping a partial draft is the point: it is the reader's work in progress, not a value the\n // wire accepted, and blurring must not discard it.\n const [draft, setDraft] = useState<AddressDraft | undefined>(undefined);\n const shown = draft ?? published;\n const relations = {\n 'aria-invalid': invalid,\n ...(describedBy === undefined || describedBy === '' ? {} : { 'aria-describedby': describedBy }),\n };\n const change = (member: AddressMember, text: string): void => {\n const next = { ...shown, [member]: text };\n setDraft(next);\n const record = recordOf(next);\n if (record !== undefined) {\n if (!sameWireValue(record, value)) setValue(record);\n return;\n }\n // The stored value was a complete address and this edit is not one: keeping the old record\n // would export an address the control no longer shows, and blurring would not correct it\n // because an incomplete draft stays while the reader is still typing. A clear is the write\n // that makes the record and the screen agree. A draft over a record that was never complete\n // stays local — there is nothing to clear.\n if (recordOf(published) !== undefined) setValue(null);\n };\n const blur = (): void => {\n // A complete draft is the record now; dropping it lets a reset or a re-baseline reach the\n // control again. An incomplete draft stays, because the reader may still be typing.\n if (recordOf(shown) !== undefined) setDraft(undefined);\n onBlur();\n };\n const members: readonly MemberSpec[] = [\n {\n member: 'line1',\n label: copy.addressLine1(),\n autoComplete: 'address-line1',\n wide: true,\n required: true,\n },\n {\n member: 'line2',\n label: copy.addressLine2(),\n autoComplete: 'address-line2',\n wide: true,\n required: false,\n },\n {\n member: 'city',\n label: copy.addressCity(),\n autoComplete: 'address-level2',\n wide: false,\n required: true,\n },\n {\n member: 'region',\n label: copy.addressRegion(),\n autoComplete: 'address-level1',\n wide: false,\n required: false,\n },\n {\n member: 'postalCode',\n label: copy.addressPostalCode(),\n autoComplete: 'postal-code',\n wide: false,\n required: true,\n },\n ];\n // A stored code the current list does not know is still shown, rather than silently changing\n // the reader's country to the first option. The wire accepts any upper-case alpha-2 code.\n const codes =\n shown.country === '' || ALPHA2_COUNTRY_CODES.includes(shown.country)\n ? ALPHA2_COUNTRY_CODES\n : [shown.country, ...ALPHA2_COUNTRY_CODES];\n const countryId = `${controlId}-country`;\n return (\n <fieldset\n className=\"ax-address\"\n // The group is the element a summary link lands on; `-1` makes it focusable by script\n // without adding a tab stop. Its members follow as their own stops.\n id={controlId}\n tabIndex={-1}\n aria-invalid={invalid}\n {...(describedBy === undefined || describedBy === ''\n ? {}\n : { 'aria-describedby': describedBy })}\n >\n <legend className=\"ax-label\">{legend}</legend>\n {members.map((spec) => {\n const memberId = `${controlId}-${spec.member}`;\n return (\n <div\n key={spec.member}\n className={\n spec.wide ? 'ax-address-member ax-address-member--wide' : 'ax-address-member'\n }\n >\n <label className=\"ax-label\" htmlFor={memberId}>\n {spec.label}{' '}\n <span className=\"ax-visually-hidden axiom-visually-hidden\">\n {copy.memberScope(label)}\n </span>\n </label>\n <input\n id={memberId}\n className=\"ax-control ax-control--address\"\n type=\"text\"\n autoComplete={spec.autoComplete}\n value={shown[spec.member]}\n {...relations}\n aria-required={required && spec.required}\n disabled={disabled}\n onChange={(event: ChangeEvent<HTMLInputElement>) =>\n change(spec.member, event.target.value)\n }\n onBlur={blur}\n />\n </div>\n );\n })}\n <div className=\"ax-address-member ax-address-member--country\">\n <label className=\"ax-label\" htmlFor={countryId}>\n {copy.addressCountry()}{' '}\n <span className=\"ax-visually-hidden axiom-visually-hidden\">\n {copy.memberScope(label)}\n </span>\n </label>\n <select\n id={countryId}\n className=\"ax-control ax-control--address\"\n autoComplete=\"country\"\n value={shown.country}\n {...relations}\n aria-required={required}\n disabled={disabled}\n onChange={(event: ChangeEvent<HTMLSelectElement>) =>\n change('country', event.target.value)\n }\n onBlur={blur}\n >\n <option value=\"\">{copy.addressCountryPlaceholder()}</option>\n {codes.map((code) => (\n <option key={code} value={code}>\n {copy.countryName(code)}\n </option>\n ))}\n </select>\n </div>\n </fieldset>\n );\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { WireRecord } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
import type { CaptureMessages } from './copy.js';
|
|
4
|
+
import type { CapturePlatform } from './permissions.js';
|
|
5
|
+
/** The bytes one capture produced, before the host stores them. */
|
|
6
|
+
export interface CapturedMedia {
|
|
7
|
+
readonly blob: Blob;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly mime: string;
|
|
10
|
+
readonly source: 'camera' | 'files' | 'recorder';
|
|
11
|
+
readonly durationMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/** The props a media capture panel paints from. */
|
|
14
|
+
export interface MediaCaptureProps {
|
|
15
|
+
/** The field's label: the panel's group name and the noun its sentences use. */
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly description?: string;
|
|
18
|
+
/** The declaration's accepted media types and extensions, passed through to the file input. */
|
|
19
|
+
readonly accept?: readonly string[];
|
|
20
|
+
readonly minBytes?: number;
|
|
21
|
+
readonly maxBytes?: number;
|
|
22
|
+
readonly required?: boolean;
|
|
23
|
+
/** A host or declaration refusal to paint beside the panel. */
|
|
24
|
+
readonly error?: string;
|
|
25
|
+
readonly disabled?: boolean;
|
|
26
|
+
/** The browser facilities; a test or a story may supply a fake at this boundary. */
|
|
27
|
+
readonly platform?: CapturePlatform;
|
|
28
|
+
readonly messages?: Partial<CaptureMessages>;
|
|
29
|
+
/** Writes the bytes and answers the closed `media_ref`; storage is never the panel's. */
|
|
30
|
+
readonly store: (media: CapturedMedia) => Promise<WireRecord | undefined>;
|
|
31
|
+
/** Called after the host stored the bytes, with the reference it wrote. */
|
|
32
|
+
readonly onCaptured?: (reference: WireRecord) => void;
|
|
33
|
+
readonly onCancel?: () => void;
|
|
34
|
+
}
|
|
35
|
+
/** A duration as `m:ss`, the reading a recorder states. */
|
|
36
|
+
export declare function elapsedText(milliseconds: number): string;
|
|
37
|
+
/**
|
|
38
|
+
* One capture panel.
|
|
39
|
+
*
|
|
40
|
+
* The state machine is the visible surface: choosing, requesting, refused, live, recording,
|
|
41
|
+
* review, saving, captured and error. Only `requesting` calls `getUserMedia`, and only an event
|
|
42
|
+
* handler can enter it; there is no effect that opens a device on mount.
|
|
43
|
+
*/
|
|
44
|
+
export declare function MediaCapture(props: MediaCaptureProps): ReactElement;
|
|
45
|
+
//# sourceMappingURL=MediaCapture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MediaCapture.d.ts","sourceRoot":"","sources":["../../src/capture/MediaCapture.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,OAAO,CAAC;AAIvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAcjD,OAAO,KAAK,EAIV,eAAe,EAEhB,MAAM,kBAAkB,CAAC;AAE1B,mEAAmE;AACnE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;IACjD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,mDAAmD;AACnD,MAAM,WAAW,iBAAiB;IAChC,gFAAgF;IAChF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,+FAA+F;IAC/F,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC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