@rexezuge/web 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -6
- package/dist/Button.d.ts +18 -2
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +1 -1
- package/dist/Button.js.map +3 -3
- package/dist/FocusInput.js +1 -1
- package/dist/FocusInput.js.map +3 -3
- package/dist/LanguageSelector.d.ts +22 -1
- package/dist/LanguageSelector.d.ts.map +1 -1
- package/dist/LanguageSelector.js +1 -1
- package/dist/LanguageSelector.js.map +3 -3
- package/dist/Spinner.d.ts +1 -1
- package/dist/Spinner.d.ts.map +1 -1
- package/dist/Spinner.js +1 -1
- package/dist/Spinner.js.map +3 -3
- package/dist/api.d.ts +8 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1 -1
- package/dist/api.js.map +3 -3
- package/dist/bookmarks.d.ts +50 -0
- package/dist/bookmarks.d.ts.map +1 -0
- package/dist/bookmarks.js +1 -0
- package/dist/bookmarks.js.map +7 -0
- package/dist/contractClient.d.ts +55 -0
- package/dist/contractClient.d.ts.map +1 -0
- package/dist/contractClient.js +1 -0
- package/dist/contractClient.js.map +7 -0
- package/dist/i18n.d.ts +110 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +1 -0
- package/dist/i18n.js.map +7 -0
- package/dist/index.d.ts +13 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/language.d.ts +30 -0
- package/dist/language.d.ts.map +1 -0
- package/dist/language.js +1 -0
- package/dist/language.js.map +7 -0
- package/dist/legacyPalette.d.ts +24 -0
- package/dist/legacyPalette.d.ts.map +1 -0
- package/dist/legacyPalette.js +1 -0
- package/dist/legacyPalette.js.map +7 -0
- package/dist/styles.css +99 -0
- package/dist/theme.d.ts +38 -7
- package/dist/theme.d.ts.map +1 -1
- package/dist/theme.js +1 -1
- package/dist/theme.js.map +3 -3
- package/dist/useNotice.d.ts +6 -3
- package/dist/useNotice.d.ts.map +1 -1
- package/dist/useNotice.js.map +2 -2
- package/dist/useResource.d.ts +107 -0
- package/dist/useResource.d.ts.map +1 -0
- package/dist/useResource.js +1 -0
- package/dist/useResource.js.map +7 -0
- package/dist/useSpaLanguage.d.ts +71 -39
- package/dist/useSpaLanguage.d.ts.map +1 -1
- package/dist/useSpaLanguage.js +1 -1
- package/dist/useSpaLanguage.js.map +3 -3
- package/dist/utils.d.ts +15 -6
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +3 -3
- package/package.json +21 -6
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
React UI primitives, hooks, and API client for the family SPAs.
|
|
4
4
|
|
|
5
|
-
Depends on `@rexezuge/errors` (every rejection is a `ServiceError`) and `@rexezuge/
|
|
5
|
+
Depends on `@rexezuge/errors` (every rejection is a `ServiceError`), `@rexezuge/shared` and `@rexezuge/contracts` (for `createContractClient`). Peer-depends on `react` + `react-dom` 19 — the kit stays version-agnostic and the app owns the renderer — and on `lucide-react` `^1.49`, which three of the converged components use for their glyphs.
|
|
6
6
|
|
|
7
7
|
**Glyphs in, strings out.** No component in this package calls `useTranslation`: every label is a prop, because the app rendering a dialog knows what it says. Icons are the exception — vendoring a glyph's path data freezes it at whatever version was current when it was copied, so `lucide-react` is a peer and the icons come from the app's own copy. `Button` deliberately keeps using this package's own `Spinner` rather than lucide's `Loader2`; chrome is cheap to draw, iconography is not.
|
|
8
8
|
|
|
@@ -14,7 +14,17 @@ pnpm add @rexezuge/web
|
|
|
14
14
|
|
|
15
15
|
## 1. Components
|
|
16
16
|
|
|
17
|
-
Class-based primitives over the
|
|
17
|
+
Class-based primitives over the `--color-*` tokens (`--color-accent`, `--color-surface-*`, `--color-text-*`, `--color-{success,error,warning,info,neutral}-{bg,text}`). **Tailwind class helpers are the single styling API.** Import the token sheet once and override only what your palette changes:
|
|
18
|
+
|
|
19
|
+
```css
|
|
20
|
+
@import 'tailwindcss';
|
|
21
|
+
@import '@rexezuge/web/styles.css'; /* token defaults, the three kit animations, and the @source scan of this package */
|
|
22
|
+
@theme {
|
|
23
|
+
--color-accent: #7aa2f7;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`styles.css` declares the tokens as Tailwind theme **defaults**, so your own `@theme` or `:root` values win whatever the import order. It carries its own `@source` for this package's `dist`, which replaces the line every repo had to add (and that, when forgotten, rendered the kit's markup unstyled with a green build). Its defaults are the warm-dark palette seven of the ten `globals.css` copies shared.
|
|
18
28
|
|
|
19
29
|
| Export | Notes |
|
|
20
30
|
| ---------------------------------------------------------- | ----------------------------------------------------------------------- |
|
|
@@ -36,8 +46,8 @@ Class-based primitives over the CSS variables every Tailwind consumer already de
|
|
|
36
46
|
| `RefreshButton` | refresh control, `loading` blocks activation |
|
|
37
47
|
| `ReadOnlyField` | read-only value with an optional copy button |
|
|
38
48
|
| `EmptyState` / `LoadingSpinner` | the shared page states |
|
|
39
|
-
| `theme` (+ `buttonColors`, `inputStyle`, …) |
|
|
40
|
-
| `cn`
|
|
49
|
+
| `theme` (+ `buttonColors`, `inputStyle`, …) | **`@deprecated`, removed in 2.0**; use the class helpers |
|
|
50
|
+
| `cn`, `configureClassMerge` | conditional class join; register `twMerge` for full merging |
|
|
41
51
|
|
|
42
52
|
```tsx
|
|
43
53
|
import { Button, Card, CardHeader, CardTitle, useNotice } from '@rexezuge/web';
|
|
@@ -59,7 +69,9 @@ function Panel() {
|
|
|
59
69
|
|
|
60
70
|
- **`useNotice`** — one transient message, `{ notice, showNotice, dismissNotice }`. `notice` is `null` when there is nothing to say, which is what `NoticeBar` takes. A new notice replaces the old one's pending dismissal rather than stacking a second timer.
|
|
61
71
|
- **`useCopyToClipboard`** — `{ copied, copy }`, where `copied` becomes true **only** after a write that actually resolved. A denied permission or a plain-HTTP deployment leaves it `false`, which is the answer that matters: there is nothing to undo. Every value the family copies is a credential or an identifier, so a false success sends the operator away believing they have something they do not.
|
|
62
|
-
- **`useSpaLanguage`** — `localStorage`-persisted language with `Accept-Language` default (`DEFAULT_SUPPORTED_LANGUAGES`, `resolveLanguageTag`, `canonicalizeLanguageTag`). Hand the resolved tag to `LanguageSelector`.
|
|
72
|
+
- **`useSpaLanguage`** — `localStorage`-persisted language with `Accept-Language` default (`DEFAULT_SUPPORTED_LANGUAGES`, `resolveLanguageTag`, `canonicalizeLanguageTag`). Hand the resolved tag to `LanguageSelector`. With a `runtime` (the `createSpaI18n` result) and a `persist` (your `PUT /user/me`) it also loads bundles, reports `status` (`loading` / `ready` / `error`) and `pending`, and `changeLanguage(tag)` runs the load → save → commit flow every local copy hand-rolled, resolving `false` on failure so you show your own notice. `resolveLanguageTag` prefers the region, then the stated or implied script: `zh-HK` and `zh-Hant-TW` resolve to a supported `zh-TW` (they used to land on `zh-CN`).
|
|
73
|
+
- **`useResource(loader, deps, { enabled?, keepDataOnError? })`** — `{ data, error, status, isLoading, reload }`. The loader gets an `AbortSignal` that is aborted on a deps change, `reload` and unmount; only the latest run may set state; `error` is an `Error` (a `ServiceError` from the API client, with `status`); `data` and `error` are `null` when absent.
|
|
74
|
+
- **`useMutation(fn)`** — `{ mutate, mutateAsync, data, error, status, isPending, reset }` for writes. `mutate` never produces an unhandled rejection; `mutateAsync` rethrows. The latest call owns the state; unmount aborts and stops updates.
|
|
63
75
|
- **`useCurrentUser`** — fetches `CURRENT_USER_PATH` (`/user`), with loading/error states for shell gating.
|
|
64
76
|
|
|
65
77
|
## 3. API client
|
|
@@ -71,7 +83,70 @@ const api = createApiClient({ baseUrl: '', fetchFn: fetch });
|
|
|
71
83
|
const me = await api.get('/user'); // typed JSON; 204/empty bodies resolve to undefined
|
|
72
84
|
```
|
|
73
85
|
|
|
74
|
-
Every rejection is a `ServiceError` with `status` / `type` / `retryable`, decoded from the family `{ Exception: { Type, Message } }` envelope first, then the legacy `{ error, message }` shape; markup bodies are treated as absent and messages truncate at `MAX_ERROR_MESSAGE_LENGTH` (500). `buildQuery` encodes `QueryParams`. Deliberately excluded: the
|
|
86
|
+
Every rejection is a `ServiceError` with `status` / `type` / `retryable`, decoded from the family `{ Exception: { Type, Message } }` envelope first, then the legacy `{ error, message }` shape; markup bodies are treated as absent and messages truncate at `MAX_ERROR_MESSAGE_LENGTH` (500). `buildQuery` encodes `QueryParams`. Deliberately excluded: the authed-first public fallback, WebDAV `207` handling, and per-app `SUPPORTED_LANGUAGES` — each had exactly one consumer, so each stays with it.
|
|
87
|
+
|
|
88
|
+
**D1 session bookmarks** (`x-d1-bookmark`, converged from the CalDAV-Bridge / Mail-Meow / Mail-Otter `apiFetch` copies) are **on by default**, which is safe: the client only echoes a value the server sent, so against a Worker without D1 sessions nothing is ever sent. The store belongs to the client (no module state, no `resetD1Bookmark()` test seam), keeps the **newest** bookmark so a slow response cannot move the session backwards, and is read from error responses too. `bookmarks: false` turns it off; `createBookmarkStore()` passed to several clients shares one session.
|
|
89
|
+
|
|
90
|
+
### Contract client
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { createContractClient } from '@rexezuge/web';
|
|
94
|
+
import { itemsContract } from '@my-repo/contracts';
|
|
95
|
+
|
|
96
|
+
export const api = createContractClient(itemsContract, { validateResponses: import.meta.env.DEV });
|
|
97
|
+
const item = await api.getItem({ params: { id } }); // typed from the endpoint; a 204 endpoint resolves null
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
A typed layer over `createApiClient` (same errors, credentials, envelope decoding and bookmarks). Pass `fetchFn` and any `createApiClient` option, or an existing `apiClient` to share its transport (combining both throws). Each call takes `{ signal, headers }` as a second argument, so `useResource((signal) => api.listItems({}, { signal }), [])` aborts correctly. `validateResponses` (off by default) parses through the response schema and fails as `BadGatewayError` without quoting the body.
|
|
101
|
+
|
|
102
|
+
## 4. i18n bootstrap: `@rexezuge/web/i18n`
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
// apps/web/src/i18n.ts
|
|
106
|
+
import { bundlesByTag, createSpaI18n } from '@rexezuge/web/i18n';
|
|
107
|
+
import en from './locales/en/translation.json';
|
|
108
|
+
|
|
109
|
+
export const spaI18n = createSpaI18n({
|
|
110
|
+
supported: ['en', 'de', 'fr', 'ja', 'zh-CN', 'zh-TW'],
|
|
111
|
+
fallback: 'en',
|
|
112
|
+
resources: { en }, // or bundlesByTag(import.meta.glob(..., { eager: true }))
|
|
113
|
+
loaders: bundlesByTag(import.meta.glob('./locales/*/translation.json')),
|
|
114
|
+
storageKey: 'my-app-lng',
|
|
115
|
+
});
|
|
116
|
+
export const { t } = spaI18n;
|
|
117
|
+
|
|
118
|
+
// SpaApp.tsx
|
|
119
|
+
const { language, changeLanguage, status, pending } = useSpaLanguage({
|
|
120
|
+
supported: spaI18n.supported,
|
|
121
|
+
storageKey: spaI18n.storageKey,
|
|
122
|
+
preferred: user?.preferredLanguage,
|
|
123
|
+
runtime: spaI18n,
|
|
124
|
+
persist: (tag) => updatePreferredLanguage(tag),
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Replaces the ten `apps/web/src/i18n.ts` copies. `i18next` and `react-i18next` are **optional peers**, imported only by this subpath; the root barrel never touches them, and the components still take every label as a prop (glyph in, string out). Tag resolution is the kit's `resolveLanguageTag` over `@rexezuge/shared`'s canonicalizer. A supported language with no resource and no loader, or a fallback that is not eager, throws at creation.
|
|
129
|
+
|
|
130
|
+
## Extending
|
|
131
|
+
|
|
132
|
+
| You want | Door |
|
|
133
|
+
| -------------------------------------------- | ------------------------------------------------------------------ |
|
|
134
|
+
| Your palette | override `--color-*` in your `@theme` / `:root` after `styles.css` |
|
|
135
|
+
| Full tailwind-merge semantics in kit classes | `configureClassMerge(twMerge)` once at startup |
|
|
136
|
+
| Your busy glyph on `Button` | `loadingIcon={<Loader2 className="h-3.5 w-3.5 animate-spin" />}` |
|
|
137
|
+
| A link styled as a button | `className={buttonClass({ variant: 'primary', size: 'sm' })}` |
|
|
138
|
+
| The compact sidebar language picker | `<LanguageSelector compact icon={<Globe aria-hidden />} … />` |
|
|
139
|
+
| A URL-seeded notice | `useNotice({ initial: () => noticeFromUrl() })` (called once) |
|
|
140
|
+
| Bundles, the backend save | `useSpaLanguage({ runtime, persist })` |
|
|
141
|
+
| Your i18next instance / options | `createSpaI18n({ instance, initOptions, namespace })` |
|
|
142
|
+
| Share a D1 session across clients | `bookmarks: createBookmarkStore()`, or your own `BookmarkStore` |
|
|
143
|
+
| Typed calls for your API | `createContractClient(contract, options)` |
|
|
144
|
+
|
|
145
|
+
Closed: component behaviour and accessibility, the error decoding, `useCurrentUser`'s failure-is-`error` contract, tag resolution, the bookmark ordering, the abort and stale-response guards of the data hooks.
|
|
146
|
+
|
|
147
|
+
### Adoption gaps closed in this release
|
|
148
|
+
|
|
149
|
+
The local `Button` / `Card` / `LanguageSelector` / `useNotice` copies (CalDAV-Bridge, Edge-Git, Mail-Otter, Agent-Router, …) matched the kit on variants and sizes. What kept them was: their `cn` was `twMerge(clsx(…))`, so a colour in `className` replaced the variant's (`configureClassMerge`); their spinner was lucide's `Loader2` (`loadingIcon`); the language picker's `compact` + globe row and `className` (`compact`, `icon`, `className`); and a URL-seeded notice re-read on every render (lazy `initial`). `Card` was already drop-in. No copy had `asChild`, so none was added; `buttonClass()` covers a link. The `{ type, text }` → `{ kind, message }` notice rename is kept (Mail-Otter adopted it): it is what lets `useNotice` feed `NoticeBar` directly.
|
|
75
150
|
|
|
76
151
|
---
|
|
77
152
|
|
package/dist/Button.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ButtonHTMLAttributes, ReactElement } from 'react';
|
|
1
|
+
import type { ButtonHTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* The one button.
|
|
4
4
|
*
|
|
@@ -23,6 +23,16 @@ import type { ButtonHTMLAttributes, ReactElement } from 'react';
|
|
|
23
23
|
* - **`danger` hover.** Four repos use `hover:brightness-125`; Edge-Sonic uses
|
|
24
24
|
* `hover:opacity-90`. The majority wins.
|
|
25
25
|
*
|
|
26
|
+
* ## Adoption
|
|
27
|
+
*
|
|
28
|
+
* Variants, sizes, the `secondary` default and the base classes match the
|
|
29
|
+
* copies one-for-one (CalDAV-Bridge's `primary` default aside). What kept the
|
|
30
|
+
* copies alive was elsewhere: their `cn` was `twMerge(clsx(...))`, so a colour
|
|
31
|
+
* in `className` replaced the variant's (register yours with
|
|
32
|
+
* `configureClassMerge`), and their spinner was lucide's `Loader2`
|
|
33
|
+
* (`loadingIcon`). A link styled as a button takes `buttonClass()`; no copy
|
|
34
|
+
* had an `asChild`, so the kit does not add one.
|
|
35
|
+
*
|
|
26
36
|
* ## Loading
|
|
27
37
|
*
|
|
28
38
|
* Converged from **AWS-AccessBridge**'s `components/ui/LoadingButton.tsx`, the
|
|
@@ -58,8 +68,14 @@ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
58
68
|
* the call site.
|
|
59
69
|
*/
|
|
60
70
|
loading?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* The busy glyph, in place of the kit `Spinner`. Glyph in: the local copies
|
|
73
|
+
* rendered lucide's `<Loader2 className="h-3.5 w-3.5 animate-spin" />`, and
|
|
74
|
+
* passing it keeps their look on adoption.
|
|
75
|
+
*/
|
|
76
|
+
loadingIcon?: ReactNode;
|
|
61
77
|
}
|
|
62
|
-
declare function Button({ className, variant, size, loading, disabled, children, onClick, type, ...rest }: Readonly<ButtonProps>): ReactElement;
|
|
78
|
+
declare function Button({ className, variant, size, loading, loadingIcon, disabled, children, onClick, type, ...rest }: Readonly<ButtonProps>): ReactElement;
|
|
63
79
|
/**
|
|
64
80
|
* The class string for a button, for callers rendering the element themselves —
|
|
65
81
|
* a link styled as a button, or a toolbar control that is not a `<button>`.
|
package/dist/Button.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../src/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAc,YAAY,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../src/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAc,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,KAAK,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAClE,KAAK,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAErC;;;GAGG;AACH,QAAA,MAAM,eAAe,0PACoO,CAAC;AAE1P,QAAA,MAAM,kBAAkB,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAKrD,CAAC;AAEF,QAAA,MAAM,eAAe,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAI/C,CAAC;AAEF,UAAU,WAAY,SAAQ,oBAAoB,CAAC,iBAAiB,CAAC;IACnE;;MAEE;IACF,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB;;MAEE;IACF,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC;CACzB;AAED,iBAAS,MAAM,CAAC,EACd,SAAS,EACT,OAAqB,EACrB,IAAW,EACX,OAAe,EACf,WAAW,EACX,QAAgB,EAChB,QAAQ,EACR,OAAO,EACP,IAAe,EACf,GAAG,IAAI,EACR,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,YAAY,CAuBtC;AAED;;;GAGG;AACH,iBAAS,WAAW,CAClB,EAAE,OAAqB,EAAE,IAAW,EAAE,GAAE;IAAE,OAAO,CAAC,EAAE,aAAa,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAAO,EAC3F,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAER;AAED,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC;AACrF,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/Button.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var f=Object.defineProperty;var o=(r,t)=>f(r,"name",{value:t,configurable:!0});import{jsx as g,jsxs as y}from"react/jsx-runtime";import{cn as l}from"./utils.js";import{Spinner as h}from"./Spinner.js";const s="inline-flex items-center justify-center gap-2 rounded-lg text-sm font-medium transition-colors duration-150 disabled:opacity-50 disabled:pointer-events-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]",a={primary:"bg-[var(--color-accent)] text-[#0d1008] hover:bg-[var(--color-accent-dim)]",secondary:"bg-[var(--color-surface-3)] text-[var(--color-text-primary)] hover:bg-[var(--color-surface-4)]",ghost:"bg-transparent text-[var(--color-text-secondary)] hover:bg-[var(--color-surface-3)] hover:text-[var(--color-text-primary)]",danger:"bg-[var(--color-error-bg)] text-[var(--color-error-text)] hover:brightness-125"},c={sm:"px-3 py-1.5 text-xs",md:"px-4 py-2",lg:"px-5 py-2.5 text-base"};function C({className:r,variant:t="secondary",size:n="md",loading:e=!1,loadingIcon:u,disabled:i=!1,children:b,onClick:x,type:d="button",...p}){const v=o(m=>{i||e||x?.(m)},"handleClick");return y("button",{type:d,className:l(s,a[t],c[n],r),disabled:i||e,"aria-busy":e||void 0,onClick:v,...p,children:[e?u??g(h,{size:16,color:"currentColor",padding:"0"}):null,b]})}o(C,"Button");function j({variant:r="secondary",size:t="md"}={},n){return l(s,a[r],c[t],n)}o(j,"buttonClass");export{C as Button,s as buttonBaseClass,j as buttonClass,c as buttonSizeClass,a as buttonVariantClass};
|
package/dist/Button.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Button.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { ButtonHTMLAttributes, MouseEvent, ReactElement } from 'react';\nimport { cn } from './utils.ts';\nimport { Spinner } from './Spinner.tsx';\n\n/**\n * The one button.\n *\n * ## Provenance\n *\n * `components/ui/Button.tsx` in **CalDAV-Bridge**, **Durable-DAV**,\n * **Durable-DAV-Router**, **Edge-Git**, **Edge-Sonic** and **Mail-Otter** — six\n * copies written from one design, agreeing on the base classes, the four\n * variants (`primary`/`secondary`/`ghost`/`danger`) and the three sizes. The\n * differences that had to be settled:\n *\n * - **Default variant.** CalDAV-Bridge defaults to `primary`; the other five\n * default to `secondary`. The majority wins: a page of solid-coloured\n * buttons is noise, and `primary` should mark the one action that matters.\n * - **`type`.** Durable-DAV and Edge-Sonic default it to `button`; the others\n * leave the HTML default (`submit`) in place, so a `<Button>` inside a\n * `<form>` submits it. The explicit default is kept — it is the documented\n * fix, and a consumer that wants a submit button passes `type=\"submit\"`.\n * - **`ghost` hover.** Four repos hover to `--color-surface-3` with\n * `--color-text-secondary`; Edge-Sonic uses `surface-2`/`text-muted`. The\n * majority wins.\n * - **`danger` hover.** Four repos use `hover:brightness-125`; Edge-Sonic uses\n * `hover:opacity-90`. The majority wins.\n *\n * ## Loading\n *\n * Converged from **AWS-AccessBridge**'s `components/ui/LoadingButton.tsx`, the\n * one place the family tracked busy state itself. Its two behaviours fold\n * cleanly into this component's `loading` prop: the button is `disabled` while\n * loading (so neither a pointer, a keyboard, nor a screen reader can activate\n * it), *and* the click handler bails out, so a synthesized `click()` — which\n * jsdom and some test harnesses dispatch without honouring `disabled` — cannot\n * fire a second submission. The ring is this package's `Spinner`, which\n * inherits the button's text colour.\n */\n\ntype ButtonVariant = 'primary' | 'secondary' | 'danger' | 'ghost';\ntype ButtonSize = 'sm' | 'md' | 'lg';\n\n/**\n * Layout and focus affordance. The focus ring is on `focus-visible`, so a\n * pointer press does not paint it and a keyboard press always does.\n */\nconst buttonBaseClass =\n 'inline-flex items-center justify-center gap-2 rounded-lg text-sm font-medium transition-colors duration-150 disabled:opacity-50 disabled:pointer-events-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]';\n\nconst buttonVariantClass: Record<ButtonVariant, string> = {\n primary: 'bg-[var(--color-accent)] text-[#0d1008] hover:bg-[var(--color-accent-dim)]',\n secondary: 'bg-[var(--color-surface-3)] text-[var(--color-text-primary)] hover:bg-[var(--color-surface-4)]',\n ghost: 'bg-transparent text-[var(--color-text-secondary)] hover:bg-[var(--color-surface-3)] hover:text-[var(--color-text-primary)]',\n danger: 'bg-[var(--color-error-bg)] text-[var(--color-error-text)] hover:brightness-125',\n};\n\nconst buttonSizeClass: Record<ButtonSize, string> = {\n sm: 'px-3 py-1.5 text-xs',\n md: 'px-4 py-2',\n lg: 'px-5 py-2.5 text-base',\n};\n\ninterface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {\n /**\n Visual weight; defaults to `secondary`.\n */\n variant?: ButtonVariant;\n /**\n Control size; defaults to `md`.\n */\n size?: ButtonSize;\n /**\n * Shows the spinner and blocks activation until it clears. A busy button is\n * a disabled button: the prop alone is enough, no `disabled` bookkeeping at\n * the call site.\n */\n loading?: boolean;\n}\n\nfunction Button({\n className,\n variant = 'secondary',\n size = 'md',\n loading = false,\n disabled = false,\n children,\n onClick,\n type = 'button',\n ...rest\n}: Readonly<ButtonProps>): ReactElement {\n const handleClick = (event: MouseEvent<HTMLButtonElement>): void => {\n // Belt and braces: `disabled` already stops a real pointer or key press,\n // and this stops a synthesized event from re-entering an in-flight action.\n if (disabled || loading) {\n return;\n }\n onClick?.(event);\n };\n\n return (\n <button\n type={type}\n className={cn(buttonBaseClass, buttonVariantClass[variant], buttonSizeClass[size], className)}\n disabled={disabled || loading}\n aria-busy={loading || undefined}\n onClick={handleClick}\n {...rest}\n >\n {loading ? <Spinner size={16} color=\"currentColor\" padding=\"0\" /> : null}\n {children}\n </button>\n );\n}\n\n/**\n * The class string for a button, for callers rendering the element themselves —\n * a link styled as a button, or a toolbar control that is not a `<button>`.\n */\nfunction buttonClass(\n { variant = 'secondary', size = 'md' }: { variant?: ButtonVariant; size?: ButtonSize } = {},\n className?: string,\n): string {\n return cn(buttonBaseClass, buttonVariantClass[variant], buttonSizeClass[size], className);\n}\n\nexport { Button, buttonBaseClass, buttonClass, buttonSizeClass, buttonVariantClass };\nexport type { ButtonProps, ButtonSize, ButtonVariant };\n"],
|
|
5
|
-
"mappings": "iIACA,OAAS,MAAAA,MAAU,aACnB,OAAS,WAAAC,MAAe,
|
|
6
|
-
"names": ["cn", "Spinner", "buttonBaseClass", "buttonVariantClass", "buttonSizeClass", "Button", "className", "variant", "size", "loading", "disabled", "children", "onClick", "type", "rest", "handleClick", "__name", "event", "_jsxs", "_jsx", "buttonClass"]
|
|
4
|
+
"sourcesContent": ["import type { ButtonHTMLAttributes, MouseEvent, ReactElement, ReactNode } from 'react';\nimport { cn } from './utils.ts';\nimport { Spinner } from './Spinner.tsx';\n\n/**\n * The one button.\n *\n * ## Provenance\n *\n * `components/ui/Button.tsx` in **CalDAV-Bridge**, **Durable-DAV**,\n * **Durable-DAV-Router**, **Edge-Git**, **Edge-Sonic** and **Mail-Otter** — six\n * copies written from one design, agreeing on the base classes, the four\n * variants (`primary`/`secondary`/`ghost`/`danger`) and the three sizes. The\n * differences that had to be settled:\n *\n * - **Default variant.** CalDAV-Bridge defaults to `primary`; the other five\n * default to `secondary`. The majority wins: a page of solid-coloured\n * buttons is noise, and `primary` should mark the one action that matters.\n * - **`type`.** Durable-DAV and Edge-Sonic default it to `button`; the others\n * leave the HTML default (`submit`) in place, so a `<Button>` inside a\n * `<form>` submits it. The explicit default is kept — it is the documented\n * fix, and a consumer that wants a submit button passes `type=\"submit\"`.\n * - **`ghost` hover.** Four repos hover to `--color-surface-3` with\n * `--color-text-secondary`; Edge-Sonic uses `surface-2`/`text-muted`. The\n * majority wins.\n * - **`danger` hover.** Four repos use `hover:brightness-125`; Edge-Sonic uses\n * `hover:opacity-90`. The majority wins.\n *\n * ## Adoption\n *\n * Variants, sizes, the `secondary` default and the base classes match the\n * copies one-for-one (CalDAV-Bridge's `primary` default aside). What kept the\n * copies alive was elsewhere: their `cn` was `twMerge(clsx(...))`, so a colour\n * in `className` replaced the variant's (register yours with\n * `configureClassMerge`), and their spinner was lucide's `Loader2`\n * (`loadingIcon`). A link styled as a button takes `buttonClass()`; no copy\n * had an `asChild`, so the kit does not add one.\n *\n * ## Loading\n *\n * Converged from **AWS-AccessBridge**'s `components/ui/LoadingButton.tsx`, the\n * one place the family tracked busy state itself. Its two behaviours fold\n * cleanly into this component's `loading` prop: the button is `disabled` while\n * loading (so neither a pointer, a keyboard, nor a screen reader can activate\n * it), *and* the click handler bails out, so a synthesized `click()` — which\n * jsdom and some test harnesses dispatch without honouring `disabled` — cannot\n * fire a second submission. The ring is this package's `Spinner`, which\n * inherits the button's text colour.\n */\n\ntype ButtonVariant = 'primary' | 'secondary' | 'danger' | 'ghost';\ntype ButtonSize = 'sm' | 'md' | 'lg';\n\n/**\n * Layout and focus affordance. The focus ring is on `focus-visible`, so a\n * pointer press does not paint it and a keyboard press always does.\n */\nconst buttonBaseClass =\n 'inline-flex items-center justify-center gap-2 rounded-lg text-sm font-medium transition-colors duration-150 disabled:opacity-50 disabled:pointer-events-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]';\n\nconst buttonVariantClass: Record<ButtonVariant, string> = {\n primary: 'bg-[var(--color-accent)] text-[#0d1008] hover:bg-[var(--color-accent-dim)]',\n secondary: 'bg-[var(--color-surface-3)] text-[var(--color-text-primary)] hover:bg-[var(--color-surface-4)]',\n ghost: 'bg-transparent text-[var(--color-text-secondary)] hover:bg-[var(--color-surface-3)] hover:text-[var(--color-text-primary)]',\n danger: 'bg-[var(--color-error-bg)] text-[var(--color-error-text)] hover:brightness-125',\n};\n\nconst buttonSizeClass: Record<ButtonSize, string> = {\n sm: 'px-3 py-1.5 text-xs',\n md: 'px-4 py-2',\n lg: 'px-5 py-2.5 text-base',\n};\n\ninterface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {\n /**\n Visual weight; defaults to `secondary`.\n */\n variant?: ButtonVariant;\n /**\n Control size; defaults to `md`.\n */\n size?: ButtonSize;\n /**\n * Shows the spinner and blocks activation until it clears. A busy button is\n * a disabled button: the prop alone is enough, no `disabled` bookkeeping at\n * the call site.\n */\n loading?: boolean;\n /**\n * The busy glyph, in place of the kit `Spinner`. Glyph in: the local copies\n * rendered lucide's `<Loader2 className=\"h-3.5 w-3.5 animate-spin\" />`, and\n * passing it keeps their look on adoption.\n */\n loadingIcon?: ReactNode;\n}\n\nfunction Button({\n className,\n variant = 'secondary',\n size = 'md',\n loading = false,\n loadingIcon,\n disabled = false,\n children,\n onClick,\n type = 'button',\n ...rest\n}: Readonly<ButtonProps>): ReactElement {\n const handleClick = (event: MouseEvent<HTMLButtonElement>): void => {\n // Belt and braces: `disabled` already stops a real pointer or key press,\n // and this stops a synthesized event from re-entering an in-flight action.\n if (disabled || loading) {\n return;\n }\n onClick?.(event);\n };\n\n return (\n <button\n type={type}\n className={cn(buttonBaseClass, buttonVariantClass[variant], buttonSizeClass[size], className)}\n disabled={disabled || loading}\n aria-busy={loading || undefined}\n onClick={handleClick}\n {...rest}\n >\n {loading ? (loadingIcon ?? <Spinner size={16} color=\"currentColor\" padding=\"0\" />) : null}\n {children}\n </button>\n );\n}\n\n/**\n * The class string for a button, for callers rendering the element themselves —\n * a link styled as a button, or a toolbar control that is not a `<button>`.\n */\nfunction buttonClass(\n { variant = 'secondary', size = 'md' }: { variant?: ButtonVariant; size?: ButtonSize } = {},\n className?: string,\n): string {\n return cn(buttonBaseClass, buttonVariantClass[variant], buttonSizeClass[size], className);\n}\n\nexport { Button, buttonBaseClass, buttonClass, buttonSizeClass, buttonVariantClass };\nexport type { ButtonProps, ButtonSize, ButtonVariant };\n"],
|
|
5
|
+
"mappings": "iIACA,OAAS,MAAAA,MAAU,aACnB,OAAS,WAAAC,MAAe,eAuDxB,MAAMC,EACJ,wPAEIC,EAAoD,CACxD,QAAS,6EACT,UAAW,iGACX,MAAO,6HACP,OAAQ,kFAGJC,EAA8C,CAClD,GAAI,sBACJ,GAAI,YACJ,GAAI,yBA0BN,SAASC,EAAO,CACd,UAAAC,EACA,QAAAC,EAAU,YACV,KAAAC,EAAO,KACP,QAAAC,EAAU,GACV,YAAAC,EACA,SAAAC,EAAW,GACX,SAAAC,EACA,QAAAC,EACA,KAAAC,EAAO,SACP,GAAGC,CAAI,EACe,CACtB,MAAMC,EAAcC,EAACC,GAA8C,CAG7DP,GAAYF,GAGhBI,IAAUK,CAAK,CACjB,EAPoB,eASpB,OACEC,EAAA,SAAA,CACE,KAAML,EACN,UAAWd,EAAGE,EAAiBC,EAAmBI,CAAO,EAAGH,EAAgBI,CAAI,EAAGF,CAAS,EAC5F,SAAUK,GAAYF,EAAO,YAClBA,GAAW,OACtB,QAASO,EAAW,GAChBD,EAAI,SAAA,CAEPN,EAAWC,GAAeU,EAACnB,EAAO,CAAC,KAAM,GAAI,MAAM,eAAe,QAAQ,GAAG,CAAA,EAAO,KACpFW,CAAQ,CAAA,CAAA,CAGf,CAlCSK,EAAAZ,EAAA,UAwCT,SAASgB,EACP,CAAE,QAAAd,EAAU,YAAa,KAAAC,EAAO,IAAI,EAAqD,CAAA,EACzFF,EAAkB,CAElB,OAAON,EAAGE,EAAiBC,EAAmBI,CAAO,EAAGH,EAAgBI,CAAI,EAAGF,CAAS,CAC1F,CALSW,EAAAI,EAAA",
|
|
6
|
+
"names": ["cn", "Spinner", "buttonBaseClass", "buttonVariantClass", "buttonSizeClass", "Button", "className", "variant", "size", "loading", "loadingIcon", "disabled", "children", "onClick", "type", "rest", "handleClick", "__name", "event", "_jsxs", "_jsx", "buttonClass"]
|
|
7
7
|
}
|
package/dist/FocusInput.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var f=Object.defineProperty;var o=(e,r)=>f(e,"name",{value:r,configurable:!0});import{jsx as d}from"react/jsx-runtime";import{useState as m}from"react";import{Input as p}from"./Input.js";import{legacyPalette as u}from"./legacyPalette.js";function i({style:e,onFocus:r,onBlur:n,...c}){const[l,s]=m(!1),a={borderColor:l?u.focusBorder:u.border,...e};return d(p,{...c,style:a,onFocus:o(t=>{s(!0),r?.(t)},"handleFocus"),onBlur:o(t=>{s(!1),n?.(t)},"handleBlur")})}o(i,"FocusInput");export{i as FocusInput};
|
package/dist/FocusInput.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/FocusInput.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useState, type CSSProperties, type FocusEvent, type InputHTMLAttributes, type ReactElement } from 'react';\nimport { Input } from './Input.tsx';\nimport {
|
|
5
|
-
"mappings": "uHAAA,OAAS,YAAAA,MAAkG,QAC3G,OAAS,SAAAC,MAAa,aACtB,OAAS,
|
|
6
|
-
"names": ["useState", "Input", "
|
|
4
|
+
"sourcesContent": ["import { useState, type CSSProperties, type FocusEvent, type InputHTMLAttributes, type ReactElement } from 'react';\nimport { Input } from './Input.tsx';\nimport { legacyPalette } from './legacyPalette.ts';\n\n/**\n * A text field that paints its border while it holds focus.\n *\n * ## Provenance\n *\n * `components/ui/FocusInput.tsx` in **AWS-AccessBridge** — the only copy in the\n * family, and the only AWS primitive still in active use after the Tailwind\n * repos' `Input` absorbed the focus treatment into its class list\n * (`focus:border-[var(--color-accent)]`). It is kept because the two mechanisms\n * are not equivalent for a consumer without Tailwind: the class version needs\n * the stylesheet, the inline version needs nothing.\n *\n * Two normalizations from the original:\n *\n * - It **renders `Input`**, so the field's base styling (padding, radius,\n * disabled opacity, placeholder colour) comes from the kit instead of a\n * second, drifting copy.\n * - It no longer re-spells `inputStyle`. The original built its own style\n * object and merged the caller's over it; this one passes `style` straight\n * through, which is the same contract with one less place to change.\n *\n * Auto-focus is the standard `autoFocus` attribute — React applies it on mount,\n * and a component-level `focus()` call in an effect would race the caller's own\n * focus management for no gain.\n */\n\ntype FocusInputProps = InputHTMLAttributes<HTMLInputElement>;\n\nfunction FocusInput({ style, onFocus, onBlur, ...rest }: Readonly<FocusInputProps>): ReactElement {\n const [focused, setFocused] = useState(false);\n const focusStyle: CSSProperties = { borderColor: focused ? legacyPalette.focusBorder : legacyPalette.border, ...style };\n\n const handleFocus = (event: FocusEvent<HTMLInputElement>): void => {\n setFocused(true);\n onFocus?.(event);\n };\n\n const handleBlur = (event: FocusEvent<HTMLInputElement>): void => {\n setFocused(false);\n onBlur?.(event);\n };\n\n return <Input {...rest} style={focusStyle} onFocus={handleFocus} onBlur={handleBlur} />;\n}\n\nexport { FocusInput };\nexport type { FocusInputProps };\n"],
|
|
5
|
+
"mappings": "uHAAA,OAAS,YAAAA,MAAkG,QAC3G,OAAS,SAAAC,MAAa,aACtB,OAAS,iBAAAC,MAAqB,qBA8B9B,SAASC,EAAW,CAAE,MAAAC,EAAO,QAAAC,EAAS,OAAAC,EAAQ,GAAGC,CAAI,EAA6B,CAChF,KAAM,CAACC,EAASC,CAAU,EAAIT,EAAS,EAAK,EACtCU,EAA4B,CAAE,YAAaF,EAAUN,EAAc,YAAcA,EAAc,OAAQ,GAAGE,CAAK,EAYrH,OAAOO,EAACV,EAAK,CAAA,GAAKM,EAAM,MAAOG,EAAY,QAVvBE,EAACC,GAA6C,CAChEJ,EAAW,EAAI,EACfJ,IAAUQ,CAAK,CACjB,EAHoB,eAU6C,OAL9CD,EAACC,GAA6C,CAC/DJ,EAAW,EAAK,EAChBH,IAASO,CAAK,CAChB,EAHmB,aAKgE,CAAA,CACrF,CAfSD,EAAAT,EAAA",
|
|
6
|
+
"names": ["useState", "Input", "legacyPalette", "FocusInput", "style", "onFocus", "onBlur", "rest", "focused", "setFocused", "focusStyle", "_jsx", "__name", "event"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
1
2
|
/**
|
|
2
3
|
* The language picker.
|
|
3
4
|
*
|
|
@@ -28,6 +29,14 @@
|
|
|
28
29
|
* belongs to `useSpaLanguage`, which already does it; this component takes the
|
|
29
30
|
* resolved tag and normalizes defensively, so a caller passing a raw browser
|
|
30
31
|
* tag (`en-US`) still lands on a real option.
|
|
32
|
+
*
|
|
33
|
+
* ## The adoption gap this closes
|
|
34
|
+
*
|
|
35
|
+
* Every shell renders the selector twice: full-size in a settings page, and
|
|
36
|
+
* `compact` with a globe glyph in a narrow sidebar or header. The first kit
|
|
37
|
+
* version had neither the glyph nor a `className`, so the local copies stayed.
|
|
38
|
+
* `icon` (glyph in, so the app's own `lucide-react` `Globe`), `compact` and
|
|
39
|
+
* `className` make the swap drop-in.
|
|
31
40
|
*/
|
|
32
41
|
interface LanguageSelectorProps {
|
|
33
42
|
/**
|
|
@@ -54,8 +63,20 @@ interface LanguageSelectorProps {
|
|
|
54
63
|
*/
|
|
55
64
|
supported?: readonly string[];
|
|
56
65
|
disabled?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
A glyph rendered before the control (e.g. lucide's `<Globe aria-hidden />`).
|
|
68
|
+
*/
|
|
69
|
+
icon?: ReactNode;
|
|
70
|
+
/**
|
|
71
|
+
The dense variant for a sidebar or header: smaller text, full width.
|
|
72
|
+
*/
|
|
73
|
+
compact?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
Classes for the outer element: the `<label>` row with an `icon`, the `<select>` without.
|
|
76
|
+
*/
|
|
77
|
+
className?: string;
|
|
57
78
|
}
|
|
58
|
-
declare function LanguageSelector({ value, onChange, label, unknownLabel, supported, disabled, }: Readonly<LanguageSelectorProps>):
|
|
79
|
+
declare function LanguageSelector({ value, onChange, label, unknownLabel, supported, disabled, icon, compact, className, }: Readonly<LanguageSelectorProps>): ReactElement;
|
|
59
80
|
export { LanguageSelector };
|
|
60
81
|
export type { LanguageSelectorProps };
|
|
61
82
|
//# sourceMappingURL=LanguageSelector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LanguageSelector.d.ts","sourceRoot":"","sources":["../src/LanguageSelector.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LanguageSelector.d.ts","sourceRoot":"","sources":["../src/LanguageSelector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,UAAU,qBAAqB;IAC7B;;;;OAIG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC;;MAEE;IACF,KAAK,EAAE,MAAM,CAAC;IACd;;MAEE;IACF,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;MAEE;IACF,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;MAEE;IACF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;MAEE;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID,iBAAS,gBAAgB,CAAC,EACxB,KAAK,EACL,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,SAA6B,EAC7B,QAAQ,EACR,IAAI,EACJ,OAAe,EACf,SAAS,GACV,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,YAAY,CAkChD;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAC5B,YAAY,EAAE,qBAAqB,EAAE,CAAC"}
|
package/dist/LanguageSelector.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var h=Object.defineProperty;var n=(a,s)=>h(a,"name",{value:s,configurable:!0});import{jsx as l,jsxs as S}from"react/jsx-runtime";import{LocaleUtil as d,SUPPORTED_LOCALES as w}from"@rexezuge/shared";import{Select as u}from"./Input.js";import{cn as x}from"./utils.js";const L="px-2 py-1.5 text-xs";function v({value:a,onChange:s,label:i,unknownLabel:f,supported:p=w,disabled:C,icon:r,compact:t=!1,className:o}){const m=x(t&&L,r===void 0?o:t?"min-w-0":"w-auto"),c=a===null?l(u,{"aria-label":i,value:"",disabled:!0,className:m,onChange:n(()=>{},"onChange"),children:l("option",{value:"",children:f})}):l(u,{"aria-label":i,value:d.normalize(a),disabled:C,className:m,onChange:n(e=>s(e.target.value),"onChange"),children:p.map(e=>l("option",{value:e,children:d.displayName(e)},e))});return r===void 0?c:S("label",{className:x("flex items-center gap-2 text-sm text-[var(--color-text-muted)]",t&&"w-full min-w-0",o),children:[l("span",{className:"shrink-0",children:r}),c]})}n(v,"LanguageSelector");export{v as LanguageSelector};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/LanguageSelector.tsx"],
|
|
4
|
-
"sourcesContent": ["import { LocaleUtil, SUPPORTED_LOCALES } from '@rexezuge/shared';\nimport { Select } from './Input.tsx';\n\n/**\n * The language picker.\n *\n * ## Provenance\n *\n * `components/shared/LanguageSelector.tsx` in **AWS-AccessBridge**,\n * **CalDAV-Bridge**, **ChordDHT-Tracker**, **Durable-DAV**, **Durable-DAV-Router**,\n * **Edge-Git**, **Mail-Meow** and **Mail-Otter** — six real copies plus two\n * smaller ones, in two shapes.\n *\n * ## What converges away\n *\n * **The 12-locale table.** Every copy declared its own `LANGUAGE_LABELS` /\n * `NATIVE_NAMES` map — the same twelve entries, `en` through `ko`, re-typed in\n * each repo. `@rexezuge/shared`'s `LocaleUtil` already holds that table and its\n * `displayName`, converged from AWS-AccessBridge, Mail-Meow and Mail-Otter. So\n * this component now has no table of its own, and the two would have had to\n * agree by hand otherwise.\n *\n * **The `'unknown'` sentinel.** Mail-Otter spelled \"the browser asked for a\n * language this app does not have\" as the string `'unknown'`, which then had to\n * be compared against at every call site and could not be distinguished from a\n * locale literally spelled `unknown`. It is `null` here — absent, per the kit's\n * `AGENTS.md` — and the disabled branch renders from that.\n *\n * **The `i18n.resolvedLanguage ?? i18n.language` fallback.** The copies read\n * i18next's own state to decide what is selected. In the kit that resolution\n * belongs to `useSpaLanguage`, which already does it; this component takes the\n * resolved tag and normalizes defensively, so a caller passing a raw browser\n * tag (`en-US`) still lands on a real option.\n */\n\ninterface LanguageSelectorProps {\n /**\n * The current tag, or `null` when the app could not resolve one.\n *\n * `null` renders a disabled control reading {@link LanguageSelectorProps.unknownLabel}.\n */\n value: string | null;\n onChange: (languageTag: string) => void;\n /**\n The control's accessible name. Required — a bare `<select>` has none.\n */\n label: string;\n /**\n Shown instead of the language list when `value` is `null`.\n */\n unknownLabel: string;\n /**\n * The offered tags.\n *\n * Defaults to the family's twelve. A caller narrows this; it cannot widen it,\n * because an option with no display name in the shared table renders as its\n * raw tag.\n */\n supported?: readonly string[];\n disabled?: boolean;\n}\n\nfunction LanguageSelector({\n value,\n onChange,\n label,\n unknownLabel,\n supported = SUPPORTED_LOCALES,\n disabled,\n}: Readonly<LanguageSelectorProps>) {\n
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["LocaleUtil", "SUPPORTED_LOCALES", "Select", "LanguageSelector", "value", "onChange", "label", "unknownLabel", "supported", "disabled", "
|
|
4
|
+
"sourcesContent": ["import type { ReactElement, ReactNode } from 'react';\nimport { LocaleUtil, SUPPORTED_LOCALES } from '@rexezuge/shared';\nimport { Select } from './Input.tsx';\nimport { cn } from './utils.ts';\n\n/**\n * The language picker.\n *\n * ## Provenance\n *\n * `components/shared/LanguageSelector.tsx` in **AWS-AccessBridge**,\n * **CalDAV-Bridge**, **ChordDHT-Tracker**, **Durable-DAV**, **Durable-DAV-Router**,\n * **Edge-Git**, **Mail-Meow** and **Mail-Otter** — six real copies plus two\n * smaller ones, in two shapes.\n *\n * ## What converges away\n *\n * **The 12-locale table.** Every copy declared its own `LANGUAGE_LABELS` /\n * `NATIVE_NAMES` map — the same twelve entries, `en` through `ko`, re-typed in\n * each repo. `@rexezuge/shared`'s `LocaleUtil` already holds that table and its\n * `displayName`, converged from AWS-AccessBridge, Mail-Meow and Mail-Otter. So\n * this component now has no table of its own, and the two would have had to\n * agree by hand otherwise.\n *\n * **The `'unknown'` sentinel.** Mail-Otter spelled \"the browser asked for a\n * language this app does not have\" as the string `'unknown'`, which then had to\n * be compared against at every call site and could not be distinguished from a\n * locale literally spelled `unknown`. It is `null` here — absent, per the kit's\n * `AGENTS.md` — and the disabled branch renders from that.\n *\n * **The `i18n.resolvedLanguage ?? i18n.language` fallback.** The copies read\n * i18next's own state to decide what is selected. In the kit that resolution\n * belongs to `useSpaLanguage`, which already does it; this component takes the\n * resolved tag and normalizes defensively, so a caller passing a raw browser\n * tag (`en-US`) still lands on a real option.\n *\n * ## The adoption gap this closes\n *\n * Every shell renders the selector twice: full-size in a settings page, and\n * `compact` with a globe glyph in a narrow sidebar or header. The first kit\n * version had neither the glyph nor a `className`, so the local copies stayed.\n * `icon` (glyph in, so the app's own `lucide-react` `Globe`), `compact` and\n * `className` make the swap drop-in.\n */\n\ninterface LanguageSelectorProps {\n /**\n * The current tag, or `null` when the app could not resolve one.\n *\n * `null` renders a disabled control reading {@link LanguageSelectorProps.unknownLabel}.\n */\n value: string | null;\n onChange: (languageTag: string) => void;\n /**\n The control's accessible name. Required — a bare `<select>` has none.\n */\n label: string;\n /**\n Shown instead of the language list when `value` is `null`.\n */\n unknownLabel: string;\n /**\n * The offered tags.\n *\n * Defaults to the family's twelve. A caller narrows this; it cannot widen it,\n * because an option with no display name in the shared table renders as its\n * raw tag.\n */\n supported?: readonly string[];\n disabled?: boolean;\n /**\n A glyph rendered before the control (e.g. lucide's `<Globe aria-hidden />`).\n */\n icon?: ReactNode;\n /**\n The dense variant for a sidebar or header: smaller text, full width.\n */\n compact?: boolean;\n /**\n Classes for the outer element: the `<label>` row with an `icon`, the `<select>` without.\n */\n className?: string;\n}\n\nconst COMPACT_SELECT_CLASS = 'px-2 py-1.5 text-xs';\n\nfunction LanguageSelector({\n value,\n onChange,\n label,\n unknownLabel,\n supported = SUPPORTED_LOCALES,\n disabled,\n icon,\n compact = false,\n className,\n}: Readonly<LanguageSelectorProps>): ReactElement {\n // Inside the icon row the select shares the width; on its own it takes `className`.\n const inRowClass = compact ? 'min-w-0' : 'w-auto';\n const selectClass = cn(compact && COMPACT_SELECT_CLASS, icon === undefined ? className : inRowClass);\n const control =\n value === null ? (\n <Select aria-label={label} value=\"\" disabled className={selectClass} onChange={() => {}}>\n <option value=\"\">{unknownLabel}</option>\n </Select>\n ) : (\n <Select\n aria-label={label}\n value={LocaleUtil.normalize(value)}\n disabled={disabled}\n className={selectClass}\n onChange={(event) => onChange(event.target.value)}\n >\n {supported.map((tag) => (\n <option key={tag} value={tag}>\n {/* `displayName` normalizes first, so a supported-but-unspelled tag\n still resolves against the shared table rather than rendering raw. */}\n {LocaleUtil.displayName(tag)}\n </option>\n ))}\n </Select>\n );\n\n if (icon === undefined) return control;\n return (\n <label className={cn('flex items-center gap-2 text-sm text-[var(--color-text-muted)]', compact && 'w-full min-w-0', className)}>\n <span className=\"shrink-0\">{icon}</span>\n {control}\n </label>\n );\n}\n\nexport { LanguageSelector };\nexport type { LanguageSelectorProps };\n"],
|
|
5
|
+
"mappings": "iIACA,OAAS,cAAAA,EAAY,qBAAAC,MAAyB,mBAC9C,OAAS,UAAAC,MAAc,aACvB,OAAS,MAAAC,MAAU,aAiFnB,MAAMC,EAAuB,sBAE7B,SAASC,EAAiB,CACxB,MAAAC,EACA,SAAAC,EACA,MAAAC,EACA,aAAAC,EACA,UAAAC,EAAYT,EACZ,SAAAU,EACA,KAAAC,EACA,QAAAC,EAAU,GACV,UAAAC,CAAS,EACuB,CAGhC,MAAMC,EAAcZ,EAAGU,GAAWT,EAAsBQ,IAAS,OAAYE,EAD1DD,EAAU,UAAY,QAC0D,EAC7FG,EACJV,IAAU,KACRW,EAACf,EAAM,CAAA,aAAaM,EAAO,MAAM,GAAG,SAAQ,GAAC,UAAWO,EAAa,SAAUG,EAAA,IAAK,CAAE,EAAP,YAAQ,SACrFD,EAAA,SAAA,CAAQ,MAAM,GAAE,SAAER,CAAY,CAAA,CAAU,CAAA,EAG1CQ,EAACf,EAAM,CAAA,aACOM,EACZ,MAAOR,EAAW,UAAUM,CAAK,EACjC,SAAUK,EACV,UAAWI,EACX,SAAUG,EAACC,GAAUZ,EAASY,EAAM,OAAO,KAAK,EAAtC,YAAuC,SAEhDT,EAAU,IAAKU,GACdH,EAAA,SAAA,CAAkB,MAAOG,EAAG,SAGzBpB,EAAW,YAAYoB,CAAG,CAAC,EAHjBA,CAAG,CAKjB,CAAC,CAAA,EAIR,OAAIR,IAAS,OAAkBI,EAE7BK,EAAA,QAAA,CAAO,UAAWlB,EAAG,iEAAkEU,GAAW,iBAAkBC,CAAS,EAAC,SAAA,CAC5HG,EAAA,OAAA,CAAM,UAAU,WAAU,SAAEL,CAAI,CAAA,EAC/BI,CAAO,CAAA,CAAA,CAGd,CA5CSE,EAAAb,EAAA",
|
|
6
|
+
"names": ["LocaleUtil", "SUPPORTED_LOCALES", "Select", "cn", "COMPACT_SELECT_CLASS", "LanguageSelector", "value", "onChange", "label", "unknownLabel", "supported", "disabled", "icon", "compact", "className", "selectClass", "control", "_jsx", "__name", "event", "tag", "_jsxs"]
|
|
7
7
|
}
|
package/dist/Spinner.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ interface SpinnerProps {
|
|
|
35
35
|
*/
|
|
36
36
|
style?: CSSProperties;
|
|
37
37
|
}
|
|
38
|
-
declare function Spinner({ size, color, label, padding, style }: Readonly<SpinnerProps>): React.JSX.Element;
|
|
38
|
+
declare function Spinner({ size, color, label, padding, style, }: Readonly<SpinnerProps>): React.JSX.Element;
|
|
39
39
|
export { Spinner };
|
|
40
40
|
export type { SpinnerProps };
|
|
41
41
|
//# sourceMappingURL=Spinner.d.ts.map
|
package/dist/Spinner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Spinner.d.ts","sourceRoot":"","sources":["../src/Spinner.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAG3C;;;;;;;;;;;;;GAaG;AAEH,UAAU,YAAY;IACpB;;MAEE;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;MAEE;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;MAEE;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;MAEE;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;MAEE;IACF,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,iBAAS,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"Spinner.d.ts","sourceRoot":"","sources":["../src/Spinner.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAG3C;;;;;;;;;;;;;GAaG;AAEH,UAAU,YAAY;IACpB;;MAEE;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;MAEE;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;MAEE;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;MAEE;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;MAEE;IACF,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,iBAAS,OAAO,CAAC,EACf,IAAS,EACT,KAAiC,EACjC,KAAK,EACL,OAAkB,EAClB,KAAK,GACN,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAkB5C;AAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACnB,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/Spinner.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s=Object.defineProperty;var i=(r,e)=>s(r,"name",{value:e,configurable:!0});import{jsx as n,jsxs as p}from"react/jsx-runtime";import{legacyPalette as l}from"./legacyPalette.js";function d({size:r=24,color:e=l.spinnerBlue,label:t,padding:a="16px 0",style:o}){return p("div",{style:{textAlign:"center",padding:a,...o},children:[n("div",{className:"animate-spin","aria-hidden":"true",style:{width:`${r}px`,height:`${r}px`,borderRadius:"50%",border:`2px solid ${e}`,borderTopColor:"transparent",margin:"0 auto"}}),t?n("p",{style:{color:"#9ca3af",marginTop:"12px"},children:t}):null]})}i(d,"Spinner");export{d as Spinner};
|
package/dist/Spinner.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Spinner.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { CSSProperties } from 'react';\nimport {
|
|
5
|
-
"mappings": "iIACA,OAAS,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import type { CSSProperties } from 'react';\nimport { legacyPalette } from './legacyPalette.ts';\n\n/**\n * The loading ring.\n *\n * ## Provenance\n *\n * `components/ui/Spinner.tsx` in **AWS-AccessBridge** — the only named spinner\n * in the family. The other repos inline the same ring into their buttons as a\n * `Loader2` icon from `lucide-react`, which the kit does not depend on, so this\n * component *is* the kit's spinner vocabulary: `Button` and `LoadingButton`\n * render it while busy.\n *\n * The ring is a bordered circle with one transparent edge, animated by\n * Tailwind's `animate-spin` (present in every consuming app's stylesheet).\n */\n\ninterface SpinnerProps {\n /**\n Diameter in pixels.\n */\n size?: number;\n /**\n Border colour; `currentColor` inherits from the surrounding text.\n */\n color?: string;\n /**\n Optional caption under the ring.\n */\n label?: string;\n /**\n Padding around the whole block, as a CSS shorthand.\n */\n padding?: string;\n /**\n Extra styles for the outer wrapper.\n */\n style?: CSSProperties;\n}\n\nfunction Spinner({\n size = 24,\n color = legacyPalette.spinnerBlue,\n label,\n padding = '16px 0',\n style,\n}: Readonly<SpinnerProps>): React.JSX.Element {\n return (\n <div style={{ textAlign: 'center', padding, ...style }}>\n <div\n className=\"animate-spin\"\n aria-hidden=\"true\"\n style={{\n width: `${size}px`,\n height: `${size}px`,\n borderRadius: '50%',\n border: `2px solid ${color}`,\n borderTopColor: 'transparent',\n margin: '0 auto',\n }}\n />\n {label ? <p style={{ color: '#9ca3af', marginTop: '12px' }}>{label}</p> : null}\n </div>\n );\n}\n\nexport { Spinner };\nexport type { SpinnerProps };\n"],
|
|
5
|
+
"mappings": "iIACA,OAAS,iBAAAA,MAAqB,qBAwC9B,SAASC,EAAQ,CACf,KAAAC,EAAO,GACP,MAAAC,EAAQH,EAAc,YACtB,MAAAI,EACA,QAAAC,EAAU,SACV,MAAAC,CAAK,EACkB,CACvB,OACEC,EAAA,MAAA,CAAK,MAAO,CAAE,UAAW,SAAU,QAAAF,EAAS,GAAGC,CAAK,EAAE,SAAA,CACpDE,EAAA,MAAA,CACE,UAAU,eAAc,cACZ,OACZ,MAAO,CACL,MAAO,GAAGN,CAAI,KACd,OAAQ,GAAGA,CAAI,KACf,aAAc,MACd,OAAQ,aAAaC,CAAK,GAC1B,eAAgB,cAChB,OAAQ,SACT,CAAA,EAEFC,EAAQI,EAAA,IAAA,CAAG,MAAO,CAAE,MAAO,UAAW,UAAW,MAAM,EAAE,SAAGJ,CAAK,CAAA,EAAQ,IAAI,CAAA,CAAA,CAGpF,CAxBSK,EAAAR,EAAA",
|
|
6
|
+
"names": ["legacyPalette", "Spinner", "size", "color", "label", "padding", "style", "_jsxs", "_jsx", "__name"]
|
|
7
7
|
}
|
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ServiceError } from '@rexezuge/errors';
|
|
2
|
+
import type { BookmarkStore } from './bookmarks.ts';
|
|
2
3
|
/**
|
|
3
4
|
* The SPA's request path.
|
|
4
5
|
*
|
|
@@ -44,12 +45,10 @@ import { ServiceError } from '@rexezuge/errors';
|
|
|
44
45
|
* had actually succeeded (credential revoke). AWS-AccessBridge resolved the same
|
|
45
46
|
* case to `{}`; `undefined` is the honest answer for "there is no body".
|
|
46
47
|
*
|
|
48
|
+
* D1 session bookmarks are on by default (`bookmarks`); see `./bookmarks.ts`.
|
|
49
|
+
*
|
|
47
50
|
* ## What is deliberately not here
|
|
48
51
|
*
|
|
49
|
-
* - **The D1 session bookmark** (`x-d1-bookmark`, CalDAV-Bridge and
|
|
50
|
-
* Mail-Otter). It is module state threading a D1 replica pin through every
|
|
51
|
-
* `/user/*` request; the kit has no D1 client, so the header policy stays
|
|
52
|
-
* with the repos that own the binding.
|
|
53
52
|
* - **`apiAuthedFirst`** (Edge-Git) — a public-fallback policy with
|
|
54
53
|
* fail-closed 401/403/404 handling, specific to that app's two-surface API.
|
|
55
54
|
* - **WebDAV `readDav`** (Durable-DAV, Durable-DAV-Router) — it accepts `207
|
|
@@ -103,6 +102,11 @@ interface CreateApiClientOptions {
|
|
|
103
102
|
Truncation limit for a server-provided error message. Defaults to 500.
|
|
104
103
|
*/
|
|
105
104
|
maxErrorMessageLength?: number;
|
|
105
|
+
/**
|
|
106
|
+
* D1 session bookmarks: `true` (the default) keeps them in a store private to
|
|
107
|
+
* this client, a `BookmarkStore` shares one, `false` never sends or stores one.
|
|
108
|
+
*/
|
|
109
|
+
bookmarks?: boolean | BookmarkStore;
|
|
106
110
|
}
|
|
107
111
|
interface ApiClient {
|
|
108
112
|
/**
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,YAAY,EAIb,MAAM,kBAAkB,CAAC;AAE1B
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,YAAY,EAIb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH;;EAEE;AACF,KAAK,OAAO,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAExE;;EAEE;AACF,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAE/D,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,UAAU,EAAE,CAAC,CAAC;AAEtE,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;MAEE;IACF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B;;;;;;MAME;IACF,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,UAAU,sBAAsB;IAC9B;;MAEE;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;MAEE;IACF,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB;;MAEE;IACF,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;MAEE;IACF,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;CACrC;AAED,UAAU,SAAS;IACjB;;MAEE;IACF,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5D,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvD,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAClD,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjD,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACnD,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACrD;AAED;;EAEE;AACF,QAAA,MAAM,wBAAwB,MAAM,CAAC;AA2BrC;;;;;;;GAOG;AACH,cAAM,eAAgB,SAAQ,YAAY;gBAC5B,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;CAGjE;AA2GD;;;;;;GAMG;AACH,iBAAS,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAkB/C;AAED;;;;;;;;;;;;;GAaG;AACH,iBAAS,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,sBAA2B,GAAG,SAAS,CAiH1F;AAED,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,wBAAwB,EAAE,CAAC;AAClF,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,sBAAsB,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var H=Object.defineProperty;var s=(e,r)=>H(e,"name",{value:r,configurable:!0});import{BadGatewayError as P,BadRequestError as M,ConflictError as x,ForbiddenError as N,InternalServerError as U,MethodNotAllowedError as _,NotFoundError as B,NotImplementedError as j,PayloadTooLargeError as L,PreconditionFailedError as F,RateLimitedError as J,ServiceError as h,ServiceUnavailableError as q,UnauthorizedError as v,UnsupportedMediaTypeError as G}from"@rexezuge/errors";import{D1_BOOKMARK_HEADER as p,resolveBookmarkStore as D}from"./bookmarks.js";const A=500,O={400:M,401:v,403:N,404:B,405:_,409:x,412:F,413:L,415:G,429:J,500:U,501:j,502:P,503:q};class S extends h{static{s(this,"HttpStatusError")}constructor(r,c,t){super(r,t??`HttpStatus${r}`,c)}}function i(e){return typeof e=="string"&&e.trim()!==""?e:null}s(i,"readString");function b(e,r){return e.length>r?`${e.slice(0,r)}\u2026`:e}s(b,"truncate");const I=/[\u0000-\u001F\u007F]/;function K(e,r){return e.length===0||e.length>r||e.includes("<")?!1:!I.test(e)}s(K,"isProbablyProse");function Q(e,r,c){if(typeof e=="string"){const g=e.trim();return{message:g===""?null:b(g,c),type:null}}if(typeof e!="object"||e===null)return{message:null,type:null};const t=e,a=typeof t.error=="object"&&t.error!==null?t.error:null,u=i(t.Exception?.Type)??(typeof t.error=="string"?i(t.error):null)??i(a?.code)??i(t.code)??null,E=i(t.Exception?.Message)??i(t.message)??(typeof t.error=="string"?i(t.error):null)??i(a?.message)??null;return E!==null?{message:b(E,c),type:u}:u!==null?{message:`${u} (HTTP ${r})`,type:u}:{message:null,type:null}}s(Q,"decodeJsonError");function z(e,r,c){const t=e.trim();if(t==="")return{message:null,type:null};try{return Q(JSON.parse(t),r,c)}catch{return{message:K(t,c)?b(t,c):null,type:null}}}s(z,"decodeErrorBody");function X(e,r){const c=new Headers(e);if(r===void 0)return c;for(const[t,a]of new Headers(r))c.set(t,a);return c}s(X,"mergeHeaders");function V(e){return Array.isArray(e)}s(V,"isQueryList");function $(e){const r=new URLSearchParams;for(const[t,a]of Object.entries(e))if(!(a==null||a==="")){if(V(a)){for(const u of a)u!=null&&u!==""&&r.append(t,String(u));continue}r.set(t,String(a))}const c=r.toString();return c===""?"":`?${c}`}s($,"buildQuery");function W(e,r={}){const c=r.baseUrl??"",t=r.maxErrorMessageLength??A,a=D(r.bookmarks);async function u(o,n={}){const l=(n.method??"GET").toUpperCase(),f=`${c}${o}`,T=n.body!==void 0,d=X(r.headers,n.headers);d.has("Accept")||d.set("Accept","application/json"),T&&!d.has("Content-Type")&&d.set("Content-Type","application/json");const w=a?.get()??null;w!==null&&!d.has(p)&&d.set(p,w);const m={method:l,headers:d};r.credentials!==void 0&&(m.credentials=r.credentials),T&&(m.body=JSON.stringify(n.body)),n.signal!==void 0&&n.signal!==null&&(m.signal=n.signal),n.cache!==void 0&&(m.cache=n.cache);const k=`${l} ${f}`;let y;try{y=await e(f,m)}catch(C){throw h.from(C)}const R=y.headers.get(p);if(a!==null&&R!==null&&a.set(R),!y.ok)throw await E(y);return g(y,k)}s(u,"request");async function E(o){let n="";try{n=await o.text()}catch{}const l=z(n,o.status,t);if(Object.hasOwn(O,o.status)){const f=O[o.status];return new f(l.message??void 0)}return new S(o.status,l.message??`Request failed with status ${o.status}.`,l.type)}s(E,"toServiceError");async function g(o,n){if(o.status===204)return;let l;try{l=await o.text()}catch(f){throw h.from(f)}if(l.trim()!=="")try{return JSON.parse(l)}catch{throw new S(o.status,`Malformed response body: ${n}`,null)}}return s(g,"readJson"),{request:u,get:s(async(o,n)=>u(`${o}${n===void 0?"":$(n)}`),"get"),post:s(async(o,n)=>u(o,{method:"POST",body:n}),"post"),put:s(async(o,n)=>u(o,{method:"PUT",body:n}),"put"),patch:s(async(o,n)=>u(o,{method:"PATCH",body:n}),"patch"),delete:s(async(o,n)=>u(o,{method:"DELETE",body:n}),"delete")}}s(W,"createApiClient");export{S as HttpStatusError,A as MAX_ERROR_MESSAGE_LENGTH,$ as buildQuery,W as createApiClient};
|