@colixsystems/widget-sdk 0.308.0 → 0.313.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 +36 -5
- package/dist/contract.cjs +109 -18
- package/dist/contract.js +109 -18
- package/dist/devserver.js +4 -30
- package/dist/flatten-entry.js +30 -0
- package/dist/hooks.js +3 -2
- package/dist/host.d.ts +10 -0
- package/dist/host.js +4 -0
- package/dist/index.d.ts +5 -2
- package/dist/linter.cjs +149 -26
- package/dist/linter.js +149 -26
- package/dist/webbundle.js +1 -1
- package/package.json +13 -7
- package/src/contract.js +109 -18
- package/src/webbundle.js +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
19
19
|
| Group | Hook (signature) | Returns | Reads / scope |
|
|
20
20
|
| ----- | ---------------- | ------- | ------------- |
|
|
21
21
|
| **CORE** | `useTheme()` | `{ colors, elevation, interaction, spacing, spacingScale, radii, typography, components, widgetStyles }` | `ctx.workspace.theme` — no scope. `elevation` is the shared depth scale (`none / sm / md / lg / xl`) you spread into a style; `colors` includes the accent's quiet tiers (`primarySoft` / `onPrimarySoft` / `primaryStrong`) and `loader`, the spinner colour for your own loading state. `components` is HOST-OWNED (the theme's per-component style tokens); the host has already folded it into your `props.style`, so read `useWidgetStyle()` and ignore this slice. |
|
|
22
|
-
| **CORE** | `useWorkspaceCurrency()` | `{ currency, formatMoney }` | `ctx.workspace.currency` — no scope. The currency this workspace charges its app users in, resolved at RENDER time. Render every price as `formatMoney(minorUnits)` and never write a currency symbol or code into a widget: the owner can change it after the widget ships, and a baked label then contradicts the charge. |
|
|
22
|
+
| **CORE** | `useWorkspaceCurrency()` | `{ currency, formatMoney }` | `ctx.workspace.currency` — no scope. The currency this workspace charges its app users in, resolved at RENDER time. Render every price as `formatMoney(minorUnits)` (a whole amount shows no decimals; `{ decimals: "always" }` keeps them) and never write a currency symbol or code into a widget: the owner can change it after the widget ships, and a baked label then contradicts the charge. |
|
|
23
23
|
| **CORE** | `useWidgetStyle()` | `{ [styleField]: value }` | `ctx.props.style` — no scope. The author-set per-widget style values declared in `manifest.styleSchema`; apply each onto whatever element you choose. |
|
|
24
24
|
| **CORE** | `useUser()` | `{ id, email, displayName, photoUrl, roles, groupIds }` | `ctx.user` (host-built context, **camelCase** — not a wire payload; `id` null when anonymous) — no scope. `photoUrl` is the user's own profile photo as an absolute URL, or `null`. |
|
|
25
25
|
| **CORE** | `useUserPhoto()` | `{ url, canEdit, upload, remove, uploading, error }` | `ctx.user` + the optional `ctx.account` — no scope. Changes the signed-in user's OWN profile photo. `canEdit` is false when nobody is signed in or the host cannot change it; `upload` / `remove` then reject. |
|
|
@@ -90,7 +90,31 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
90
90
|
|
|
91
91
|
## Status
|
|
92
92
|
|
|
93
|
-
`v0.
|
|
93
|
+
`v0.313.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
94
|
+
|
|
95
|
+
### What's new in 0.313.0 (contract 1.254.0)
|
|
96
|
+
|
|
97
|
+
**`esbuild` and `sucrase` are no longer installed with the SDK.** They are optional peer dependencies now: build tooling peers, installed by first-party tooling, so installing the SDK brings no third-party code into your project or an app built from it. Linting, building and uploading a widget need neither. A project that depends on `esbuild` directly at a version outside `^0.28.0` gets `ERESOLVE` on install; move it to `^0.28.0`, or install with `--legacy-peer-deps`. The widget contract is unchanged.
|
|
98
|
+
|
|
99
|
+
### What's new in 0.312.0 (contract 1.254.0)
|
|
100
|
+
|
|
101
|
+
**`formatMoney` writes a whole price without decimals.** `useWorkspaceCurrency().formatMoney(79500)` now renders `"795 kr"` instead of `"795,00 kr"`, the way shops, salons and menus write prices; an amount with a fractional part keeps the currency's decimals (`formatMoney(9950)` → `"99,50 kr"`). For a receipt or invoice total that should always read to the cent, pass `formatMoney(minorUnits, { decimals: "always" })` → `"795,00 kr"`. Zero-decimal currencies such as JPY are unchanged. Hosts get the same formatter as `formatMoneyIn(currency, minorUnits, options?)` from `@colixsystems/widget-sdk/host`; the paid-app sign-up price on both hosts now uses it, so it reads `"99 kr / month"` in the web Player and the exported app alike.
|
|
102
|
+
|
|
103
|
+
### What's new in 0.311.0 (contract 1.253.0)
|
|
104
|
+
|
|
105
|
+
**New linter rule `empty-state-action-outside` (severity `warning`, non-blocking).** A `<Button>` or `<Pressable>` rendered straight after an `<EmptyState>`, or as the first child of the `View` that follows one, sits outside the empty-state panel. Pass it as the EmptyState's children instead: `<EmptyState title={…}><Button … /></EmptyState>` draws it inside the panel, under the message. An EmptyState and a button that are alternatives (`empty ? <EmptyState /> : <Button />`) or sit in separate expressions are not flagged.
|
|
106
|
+
|
|
107
|
+
**New linter rule `field-label-styles-mixed` (severity `warning`, non-blocking).** A widget that gives one form field the SDK `label` (`<TextField>`, `<Select>`, `<RadioGroup>`, `<PeoplePicker>`, `<FileUpload>`, `<FormField>`) and labels another with its own `<Text>` shows labels in two styles. A `<Text>` counts as a field's label only when it is the element just before a control with no `label` (one of those fields, a `<ChipGroup>`, a `<DateTimePicker>` or a `<TextInput>`), so a heading above a form does not count. Label every field one way: the `label` prop, or `<FormField label>` round a control that has none.
|
|
108
|
+
|
|
109
|
+
### What's new in 0.310.0 (contract 1.253.0)
|
|
110
|
+
|
|
111
|
+
**A look can carry its own light surface colours.** A theme may state `surfaceMutedColor`, `surfaceBorderColor` and `mutedTextColor`. On a light page they become `useTheme().colors.surfaceMuted`, `border` and `onSurfaceMuted`, in the web Player and the exported app alike, so a warm page gets warm panels and muted text instead of the default slate. They are worked out only for a tinted page; a white, grey or slate-blue page keeps the slate defaults, which already match it. A dark page ignores them and keeps the colours derived from it. A theme without them renders exactly as before. Hosts read them through the new `themeSurfaceTokens(themeConfig)` in `@colixsystems/widget-sdk/host`; `deriveLightSurfaceColors(backgroundColor, inkColor)` works the three out from a light page, holding the muted text at 4.5:1 on the surface, the muted panel and the page. Nothing changes for a widget: it keeps reading `useTheme().colors`.
|
|
112
|
+
|
|
113
|
+
### What's new in 0.309.0 (contract 1.253.0)
|
|
114
|
+
|
|
115
|
+
**Sibling files upload.** A package whose entry imports its own files (`import { step } from "./engine.js"`) now uploads, by npm or as a `.tgz`, instead of failing with `Could not resolve "./engine.js"`. Each entry has its siblings folded into it, so the web Player and the exported app both run one self-contained module. A sibling uses named exports only and is imported by name; a default export, `import * as`, a cycle or a `../` path is refused at upload with its file and line.
|
|
116
|
+
|
|
117
|
+
**`useSafeAreaInsets()` works on the web.** `react-native-safe-area-context` is now resolved by the host, like `react-native`, instead of being bundled into each widget. The web Player and the Studio canvas provide zero insets and the window as the frame, so `useSafeAreaInsets()` and `useSafeAreaFrame()` return values on the web as documented rather than throwing "No safe area value available". The exported app keeps the device's real insets. A widget bundled before this release carries its own copy and still throws on the web until it is published again.
|
|
94
118
|
|
|
95
119
|
### What's new in 0.308.0 (contract 1.252.0)
|
|
96
120
|
|
|
@@ -3871,7 +3895,9 @@ here. Derives `supportedPlatforms: ["web", "native"]`.
|
|
|
3871
3895
|
**2. Split implementation — `widget.web.jsx` + `widget.native.jsx`.** Pick this
|
|
3872
3896
|
when the widget needs a package that only runs on ONE platform. Each file
|
|
3873
3897
|
targets its platform and imports the package that works there; shared logic
|
|
3874
|
-
lives in a sibling `./helper.js` both files import
|
|
3898
|
+
lives in a sibling `./helper.js` both files import (any entry may import
|
|
3899
|
+
sibling files; give them named exports only and import them by name, since the
|
|
3900
|
+
upload folds each into the entry that imports it). This is the **canonical
|
|
3875
3901
|
pattern** for graphics, media, and any platform-divergent library:
|
|
3876
3902
|
|
|
3877
3903
|
| Capability | `widget.native.jsx` | `widget.web.jsx` |
|
|
@@ -3991,6 +4017,10 @@ Pass `--manifest` to enable `style-field-unread` and the three editability rules
|
|
|
3991
4017
|
|
|
3992
4018
|
`text-symbol-icon` flags a JSX text child that is nothing but symbols or emoji (`<Text>✓</Text>`, `<Text>{open ? "▲" : "▼"}</Text>`, or `✓ {label}`), naming the lucide `<Icon>` to draw instead where one is obvious (✓ check, ★ star, → arrow-right, ☰ menu, ⌕ search). A symbol inside running text ("Steg 1 → 2", "© 2026"), bullets and dashes (• · – —), ×, currency signs and flag emoji pass. A warning for a human author, blocking for the AI widget agent and `/mcp/build`.
|
|
3993
4019
|
|
|
4020
|
+
`empty-state-action-outside` flags a `<Button>` or `<Pressable>` placed beside an `<EmptyState>` (next to it, or first in the `View` after it), outside the panel. Pass it as the EmptyState's children. A warning.
|
|
4021
|
+
|
|
4022
|
+
`field-label-styles-mixed` flags a widget that labels some fields with the SDK `label` and others with a `<Text>` just before the control, so the labels render in two styles. Label every field one way. A warning.
|
|
4023
|
+
|
|
3994
4024
|
`comment-as-jsx-text` refuses a `//` or `/* */` comment written between JSX tags, where it is text the web Player shows and the native app refuses. Write it as `{/* … */}`. An error.
|
|
3995
4025
|
|
|
3996
4026
|
`row-action-not-gated` flags a widget that calls `update` or `delete` from `useDatastoreMutation` without a per-row permission check: no `_capabilities` read and no `useCanWrite(tableId, { recordId })`. The table-level `useCanWrite(tableId)` only answers "may create", so a list gated on it shows Edit / Delete on rows the server will refuse. A warning.
|
|
@@ -4027,8 +4057,9 @@ published bundle hits) and hot-reloads onto the canvas on every save.
|
|
|
4027
4057
|
`widget.native.jsx` with shared `./relative.jsx` helpers) need a real build
|
|
4028
4058
|
step; the dev server reports relative imports rather than serving a module
|
|
4029
4059
|
the browser can't resolve.
|
|
4030
|
-
- `dev` lazily requires the optional `sucrase`
|
|
4031
|
-
|
|
4060
|
+
- `dev` lazily requires the optional peers `sucrase` and `esbuild`. In this
|
|
4061
|
+
monorepo they are already present; in a standalone widget project run
|
|
4062
|
+
`npm i -D sucrase esbuild`.
|
|
4032
4063
|
- Lint findings print to the terminal on each change but never block serving.
|
|
4033
4064
|
|
|
4034
4065
|
## Why no TypeScript dependency?
|
package/dist/contract.cjs
CHANGED
|
@@ -2514,7 +2514,7 @@ const HOOKS = [
|
|
|
2514
2514
|
currency:
|
|
2515
2515
|
"string // the ISO code this workspace charges its app users in, e.g. \"SEK\"",
|
|
2516
2516
|
formatMoney:
|
|
2517
|
-
"(minorUnits) => string //
|
|
2517
|
+
"(minorUnits, { decimals: \"always\" }?) => string // 79500 -> \"795 kr\", 9950 -> \"99,50 kr\": a whole amount shows no decimals; pass { decimals: \"always\" } for a receipt or invoice total (\"795,00 kr\"). Renders identically on web and native. NEVER write a currency symbol or code yourself",
|
|
2518
2518
|
},
|
|
2519
2519
|
requiredContextSlice: ["workspace.currency"],
|
|
2520
2520
|
scopes: null,
|
|
@@ -4978,8 +4978,8 @@ const VETTED_IMPORTS = [
|
|
|
4978
4978
|
description:
|
|
4979
4979
|
"RevenueCat in-app purchase (StoreKit / Play Billing). PREFER usePurchases() from the SDK, which already runs on the " +
|
|
4980
4980
|
"app's configured, signed-in customer. Import this directly only for what the hook does not cover, and NEVER call " +
|
|
4981
|
-
"Purchases.configure, logIn or logOut — the app owns them
|
|
4982
|
-
"connected RevenueCat. Native-only because no browser offers store billing: author it in widget.native.jsx and give " +
|
|
4981
|
+
"Purchases.configure, logIn or logOut — the app owns them. The package is in the app only when the workspace " +
|
|
4982
|
+
"connected RevenueCat: a store build of a workspace that has not is refused while a widget imports it. Native-only because no browser offers store billing: author it in widget.native.jsx and give " +
|
|
4983
4983
|
"widget.web.jsx a visible 'available in the app' state.",
|
|
4984
4984
|
},
|
|
4985
4985
|
{
|
|
@@ -5168,6 +5168,8 @@ const ALLOWED_BARE_IMPORTS = [
|
|
|
5168
5168
|
// * react-native, lucide-react-native, react-native-svg,
|
|
5169
5169
|
// react-native-qrcode-svg: share the host's react-native-web instance
|
|
5170
5170
|
// (sc-1265, sc-6105).
|
|
5171
|
+
// * react-native-safe-area-context: its hooks read the host's provider,
|
|
5172
|
+
// which an inlined copy cannot see (sc-16577).
|
|
5171
5173
|
// * date-fns and the maths set: an agent widget is transpiled, not
|
|
5172
5174
|
// bundled, so the host must resolve its bare imports (sc-7191).
|
|
5173
5175
|
const HOST_EXTERNAL_SPECIFIERS = [
|
|
@@ -5182,6 +5184,7 @@ const HOST_EXTERNAL_SPECIFIERS = [
|
|
|
5182
5184
|
"date-fns",
|
|
5183
5185
|
"react-native-qrcode-svg",
|
|
5184
5186
|
"react-native",
|
|
5187
|
+
"react-native-safe-area-context",
|
|
5185
5188
|
"decimal.js",
|
|
5186
5189
|
"d3-scale",
|
|
5187
5190
|
"d3-shape",
|
|
@@ -5338,18 +5341,6 @@ function normaliseCurrencyCode(value) {
|
|
|
5338
5341
|
return code || CHARGE_CURRENCY;
|
|
5339
5342
|
}
|
|
5340
5343
|
|
|
5341
|
-
/**
|
|
5342
|
-
* `formatMoneyIn("SEK", 45000)` → `"450,00 kr"`.
|
|
5343
|
-
*
|
|
5344
|
-
* Takes MINOR units — the same unit `requestPayment` charges in — so there is no
|
|
5345
|
-
* conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
|
|
5346
|
-
* rather than `Intl.NumberFormat`, which does not produce identical output in
|
|
5347
|
-
* the exported Expo app and react-native-web; this string sits beside the amount
|
|
5348
|
-
* the buyer is actually charged, so the two hosts must agree exactly.
|
|
5349
|
-
*
|
|
5350
|
-
* A non-finite amount renders as zero rather than "NaN": a price whose data has
|
|
5351
|
-
* not loaded should read as an amount, never as a broken string in a checkout.
|
|
5352
|
-
*/
|
|
5353
5344
|
/**
|
|
5354
5345
|
* sc-5717 — value equality for a stored widget-route value: is this key still
|
|
5355
5346
|
* at the default its widget declared?
|
|
@@ -5365,7 +5356,22 @@ function sameWidgetRouteValue(a, b) {
|
|
|
5365
5356
|
}
|
|
5366
5357
|
return Object.is(a, b);
|
|
5367
5358
|
}
|
|
5368
|
-
|
|
5359
|
+
/**
|
|
5360
|
+
* `formatMoneyIn("SEK", 79500)` → `"795 kr"`; `formatMoneyIn("SEK", 9950)` → `"99,50 kr"`.
|
|
5361
|
+
*
|
|
5362
|
+
* Takes MINOR units — the same unit `requestPayment` charges in — so there is no
|
|
5363
|
+
* conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
|
|
5364
|
+
* rather than `Intl.NumberFormat`, which does not produce identical output in
|
|
5365
|
+
* the exported Expo app and react-native-web; this string sits beside the amount
|
|
5366
|
+
* the buyer is actually charged, so the two hosts must agree exactly.
|
|
5367
|
+
*
|
|
5368
|
+
* A whole amount drops its decimals, as shops and menus write prices.
|
|
5369
|
+
* `{ decimals: "always" }` keeps them, for a receipt or invoice total.
|
|
5370
|
+
*
|
|
5371
|
+
* A non-finite amount renders as zero rather than "NaN": a price whose data has
|
|
5372
|
+
* not loaded should read as an amount, never as a broken string in a checkout.
|
|
5373
|
+
*/
|
|
5374
|
+
function formatMoneyIn(currency, minorUnits, options) {
|
|
5369
5375
|
const code = normaliseCurrencyCode(currency);
|
|
5370
5376
|
const fmt = CURRENCY_FORMATS[code] || {
|
|
5371
5377
|
...CURRENCY_FORMAT_FALLBACK,
|
|
@@ -5378,7 +5384,9 @@ function formatMoneyIn(currency, minorUnits) {
|
|
|
5378
5384
|
const whole = fmt.decimals > 0 ? digits.slice(0, -fmt.decimals) : digits;
|
|
5379
5385
|
const cents = fmt.decimals > 0 ? digits.slice(-fmt.decimals) : "";
|
|
5380
5386
|
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, fmt.groupSeparator);
|
|
5381
|
-
const
|
|
5387
|
+
const alwaysDecimals = Boolean(options && options.decimals === "always");
|
|
5388
|
+
const showCents = cents !== "" && (alwaysDecimals || /[1-9]/.test(cents));
|
|
5389
|
+
const body = showCents ? `${grouped}${fmt.decimalSeparator}${cents}` : grouped;
|
|
5382
5390
|
const gap = fmt.space ? " " : "";
|
|
5383
5391
|
const withSymbol =
|
|
5384
5392
|
fmt.position === "before"
|
|
@@ -6945,7 +6953,11 @@ const CONTRACT = deepFreeze({
|
|
|
6945
6953
|
// `filterList` condition and a query's array-form `filter` take
|
|
6946
6954
|
// `{ operator: "in", value: [a, b] }`; on a list column it matches a row
|
|
6947
6955
|
// holding any of the values. At most 100; no `valueMode` applies.
|
|
6948
|
-
|
|
6956
|
+
// 1.253.0: fix (sc-16577) — `react-native-safe-area-context` is host-resolved,
|
|
6957
|
+
// so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
|
|
6958
|
+
// 1.254.0: `formatMoney` shows a whole amount without decimals ("795 kr");
|
|
6959
|
+
// `formatMoney(minor, { decimals: "always" })` keeps them ("795,00 kr").
|
|
6960
|
+
version: "1.254.0",
|
|
6949
6961
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6950
6962
|
hooks: HOOKS,
|
|
6951
6963
|
primitives: PRIMITIVES,
|
|
@@ -7297,6 +7309,82 @@ function deriveSurfaceTokens(backgroundColor) {
|
|
|
7297
7309
|
};
|
|
7298
7310
|
}
|
|
7299
7311
|
|
|
7312
|
+
// The theme_config keys that state a light page's own surface set, by token.
|
|
7313
|
+
const THEME_SURFACE_COLOR_KEYS = Object.freeze({
|
|
7314
|
+
surfaceMuted: "surfaceMutedColor",
|
|
7315
|
+
border: "surfaceBorderColor",
|
|
7316
|
+
onSurfaceMuted: "mutedTextColor",
|
|
7317
|
+
});
|
|
7318
|
+
// How far a look's muted panel and border step from its page toward its ink.
|
|
7319
|
+
const LIGHT_SURFACE_MIX = Object.freeze({ surfaceMuted: 0.04, border: 0.12 });
|
|
7320
|
+
// Slate's own saturation, so a tinted set is as quiet as the default one.
|
|
7321
|
+
const LIGHT_SURFACE_MAX_SATURATION = 0.2;
|
|
7322
|
+
const LIGHT_SURFACE_TEXT_STEP = 0.01;
|
|
7323
|
+
|
|
7324
|
+
function isLightBackground(backgroundColor) {
|
|
7325
|
+
return readableTextColor(backgroundColor, "dark", "light") === "dark";
|
|
7326
|
+
}
|
|
7327
|
+
|
|
7328
|
+
/**
|
|
7329
|
+
* The page's surface set for a stored theme: `deriveSurfaceTokens` of its
|
|
7330
|
+
* background, with the theme's own `THEME_SURFACE_COLOR_KEYS` over it while
|
|
7331
|
+
* that background is light. A dark page keeps the derivation, so a light set
|
|
7332
|
+
* left on the theme never paints it. `null` when the background is unusable.
|
|
7333
|
+
*/
|
|
7334
|
+
function themeSurfaceTokens(themeConfig) {
|
|
7335
|
+
const cfg = themeConfig && typeof themeConfig === "object" ? themeConfig : {};
|
|
7336
|
+
const derived = deriveSurfaceTokens(cfg.backgroundColor);
|
|
7337
|
+
if (!derived || !isLightBackground(cfg.backgroundColor)) return derived;
|
|
7338
|
+
const out = { ...derived };
|
|
7339
|
+
for (const [token, key] of Object.entries(THEME_SURFACE_COLOR_KEYS)) {
|
|
7340
|
+
if (isHexColor(cfg[key])) out[token] = cfg[key];
|
|
7341
|
+
}
|
|
7342
|
+
return out;
|
|
7343
|
+
}
|
|
7344
|
+
|
|
7345
|
+
/**
|
|
7346
|
+
* The surface set a look's LIGHT background wants, as theme_config keys: the
|
|
7347
|
+
* muted panel and border step toward the ink in the background's own hue, and
|
|
7348
|
+
* the muted text keeps the default's weight in that hue, darkened until it
|
|
7349
|
+
* reads at WCAG AA on the surface, the muted panel and the page. `null` for a
|
|
7350
|
+
* dark or unusable background, which `deriveSurfaceTokens` already covers.
|
|
7351
|
+
*/
|
|
7352
|
+
/** The hues of the contract's own slate: a page tinted within them already matches it. */
|
|
7353
|
+
const SLATE_HUES = Object.freeze({ from: 195, to: 225 });
|
|
7354
|
+
|
|
7355
|
+
/** Whether a page has a hue of its own; white, grey and slate-blue keep the contract's colours. */
|
|
7356
|
+
function hasOwnTint(backgroundColor) {
|
|
7357
|
+
const channels = hexChannels(backgroundColor);
|
|
7358
|
+
if (Math.max(...channels) - Math.min(...channels) <= 2) return false;
|
|
7359
|
+
const [hue] = hexToHsl(backgroundColor);
|
|
7360
|
+
return hue < SLATE_HUES.from || hue > SLATE_HUES.to;
|
|
7361
|
+
}
|
|
7362
|
+
|
|
7363
|
+
function deriveLightSurfaceColors(backgroundColor, inkColor) {
|
|
7364
|
+
if (!isHexColor(backgroundColor) || !isLightBackground(backgroundColor) || !hasOwnTint(backgroundColor)) return null;
|
|
7365
|
+
const base = DEFAULT_THEME_TOKENS.colors;
|
|
7366
|
+
const [hue, saturation] = hexToHsl(backgroundColor);
|
|
7367
|
+
const tint = Math.min(saturation, LIGHT_SURFACE_MAX_SATURATION);
|
|
7368
|
+
const ink = isHexColor(inkColor) ? inkColor : base.onSurface;
|
|
7369
|
+
const tone = hslToHex(hue, tint, hexToHsl(ink)[2]);
|
|
7370
|
+
const surfaceMuted = mixHex(backgroundColor, tone, LIGHT_SURFACE_MIX.surfaceMuted);
|
|
7371
|
+
const backdrops = [base.surface, surfaceMuted, backgroundColor];
|
|
7372
|
+
let lightness = hexToHsl(base.onSurfaceMuted)[2];
|
|
7373
|
+
let text = hslToHex(hue, tint, lightness);
|
|
7374
|
+
while (
|
|
7375
|
+
lightness > 0 &&
|
|
7376
|
+
backdrops.some((backdrop) => contrastRatio(text, backdrop) < ACCENT_TEXT_MIN_CONTRAST)
|
|
7377
|
+
) {
|
|
7378
|
+
lightness = Math.max(0, lightness - LIGHT_SURFACE_TEXT_STEP);
|
|
7379
|
+
text = hslToHex(hue, tint, lightness);
|
|
7380
|
+
}
|
|
7381
|
+
return {
|
|
7382
|
+
[THEME_SURFACE_COLOR_KEYS.surfaceMuted]: surfaceMuted,
|
|
7383
|
+
[THEME_SURFACE_COLOR_KEYS.border]: mixHex(backgroundColor, tone, LIGHT_SURFACE_MIX.border),
|
|
7384
|
+
[THEME_SURFACE_COLOR_KEYS.onSurfaceMuted]: text,
|
|
7385
|
+
};
|
|
7386
|
+
}
|
|
7387
|
+
|
|
7300
7388
|
// sc-8370: WCAG 1.4.3 for text, 1.4.11 for a control's boundary.
|
|
7301
7389
|
const INK_CONTRAST = Object.freeze({ text: 4.5, boundary: 3 });
|
|
7302
7390
|
|
|
@@ -7450,6 +7538,9 @@ module.exports = {
|
|
|
7450
7538
|
deriveAccentTints,
|
|
7451
7539
|
deriveStatusColors,
|
|
7452
7540
|
deriveSurfaceTokens,
|
|
7541
|
+
themeSurfaceTokens,
|
|
7542
|
+
deriveLightSurfaceColors,
|
|
7543
|
+
THEME_SURFACE_COLOR_KEYS,
|
|
7453
7544
|
inkForBackdrop,
|
|
7454
7545
|
INK_CONTRAST,
|
|
7455
7546
|
gradientAngleToVector,
|
package/dist/contract.js
CHANGED
|
@@ -2509,7 +2509,7 @@ const HOOKS = [
|
|
|
2509
2509
|
currency:
|
|
2510
2510
|
"string // the ISO code this workspace charges its app users in, e.g. \"SEK\"",
|
|
2511
2511
|
formatMoney:
|
|
2512
|
-
"(minorUnits) => string //
|
|
2512
|
+
"(minorUnits, { decimals: \"always\" }?) => string // 79500 -> \"795 kr\", 9950 -> \"99,50 kr\": a whole amount shows no decimals; pass { decimals: \"always\" } for a receipt or invoice total (\"795,00 kr\"). Renders identically on web and native. NEVER write a currency symbol or code yourself",
|
|
2513
2513
|
},
|
|
2514
2514
|
requiredContextSlice: ["workspace.currency"],
|
|
2515
2515
|
scopes: null,
|
|
@@ -4973,8 +4973,8 @@ const VETTED_IMPORTS = [
|
|
|
4973
4973
|
description:
|
|
4974
4974
|
"RevenueCat in-app purchase (StoreKit / Play Billing). PREFER usePurchases() from the SDK, which already runs on the " +
|
|
4975
4975
|
"app's configured, signed-in customer. Import this directly only for what the hook does not cover, and NEVER call " +
|
|
4976
|
-
"Purchases.configure, logIn or logOut — the app owns them
|
|
4977
|
-
"connected RevenueCat. Native-only because no browser offers store billing: author it in widget.native.jsx and give " +
|
|
4976
|
+
"Purchases.configure, logIn or logOut — the app owns them. The package is in the app only when the workspace " +
|
|
4977
|
+
"connected RevenueCat: a store build of a workspace that has not is refused while a widget imports it. Native-only because no browser offers store billing: author it in widget.native.jsx and give " +
|
|
4978
4978
|
"widget.web.jsx a visible 'available in the app' state.",
|
|
4979
4979
|
},
|
|
4980
4980
|
{
|
|
@@ -5163,6 +5163,8 @@ const ALLOWED_BARE_IMPORTS = [
|
|
|
5163
5163
|
// * react-native, lucide-react-native, react-native-svg,
|
|
5164
5164
|
// react-native-qrcode-svg: share the host's react-native-web instance
|
|
5165
5165
|
// (sc-1265, sc-6105).
|
|
5166
|
+
// * react-native-safe-area-context: its hooks read the host's provider,
|
|
5167
|
+
// which an inlined copy cannot see (sc-16577).
|
|
5166
5168
|
// * date-fns and the maths set: an agent widget is transpiled, not
|
|
5167
5169
|
// bundled, so the host must resolve its bare imports (sc-7191).
|
|
5168
5170
|
const HOST_EXTERNAL_SPECIFIERS = [
|
|
@@ -5177,6 +5179,7 @@ const HOST_EXTERNAL_SPECIFIERS = [
|
|
|
5177
5179
|
"date-fns",
|
|
5178
5180
|
"react-native-qrcode-svg",
|
|
5179
5181
|
"react-native",
|
|
5182
|
+
"react-native-safe-area-context",
|
|
5180
5183
|
"decimal.js",
|
|
5181
5184
|
"d3-scale",
|
|
5182
5185
|
"d3-shape",
|
|
@@ -5333,18 +5336,6 @@ function normaliseCurrencyCode(value) {
|
|
|
5333
5336
|
return code || CHARGE_CURRENCY;
|
|
5334
5337
|
}
|
|
5335
5338
|
|
|
5336
|
-
/**
|
|
5337
|
-
* `formatMoneyIn("SEK", 45000)` → `"450,00 kr"`.
|
|
5338
|
-
*
|
|
5339
|
-
* Takes MINOR units — the same unit `requestPayment` charges in — so there is no
|
|
5340
|
-
* conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
|
|
5341
|
-
* rather than `Intl.NumberFormat`, which does not produce identical output in
|
|
5342
|
-
* the exported Expo app and react-native-web; this string sits beside the amount
|
|
5343
|
-
* the buyer is actually charged, so the two hosts must agree exactly.
|
|
5344
|
-
*
|
|
5345
|
-
* A non-finite amount renders as zero rather than "NaN": a price whose data has
|
|
5346
|
-
* not loaded should read as an amount, never as a broken string in a checkout.
|
|
5347
|
-
*/
|
|
5348
5339
|
/**
|
|
5349
5340
|
* sc-5717 — value equality for a stored widget-route value: is this key still
|
|
5350
5341
|
* at the default its widget declared?
|
|
@@ -5360,7 +5351,22 @@ function sameWidgetRouteValue(a, b) {
|
|
|
5360
5351
|
}
|
|
5361
5352
|
return Object.is(a, b);
|
|
5362
5353
|
}
|
|
5363
|
-
|
|
5354
|
+
/**
|
|
5355
|
+
* `formatMoneyIn("SEK", 79500)` → `"795 kr"`; `formatMoneyIn("SEK", 9950)` → `"99,50 kr"`.
|
|
5356
|
+
*
|
|
5357
|
+
* Takes MINOR units — the same unit `requestPayment` charges in — so there is no
|
|
5358
|
+
* conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
|
|
5359
|
+
* rather than `Intl.NumberFormat`, which does not produce identical output in
|
|
5360
|
+
* the exported Expo app and react-native-web; this string sits beside the amount
|
|
5361
|
+
* the buyer is actually charged, so the two hosts must agree exactly.
|
|
5362
|
+
*
|
|
5363
|
+
* A whole amount drops its decimals, as shops and menus write prices.
|
|
5364
|
+
* `{ decimals: "always" }` keeps them, for a receipt or invoice total.
|
|
5365
|
+
*
|
|
5366
|
+
* A non-finite amount renders as zero rather than "NaN": a price whose data has
|
|
5367
|
+
* not loaded should read as an amount, never as a broken string in a checkout.
|
|
5368
|
+
*/
|
|
5369
|
+
function formatMoneyIn(currency, minorUnits, options) {
|
|
5364
5370
|
const code = normaliseCurrencyCode(currency);
|
|
5365
5371
|
const fmt = CURRENCY_FORMATS[code] || {
|
|
5366
5372
|
...CURRENCY_FORMAT_FALLBACK,
|
|
@@ -5373,7 +5379,9 @@ function formatMoneyIn(currency, minorUnits) {
|
|
|
5373
5379
|
const whole = fmt.decimals > 0 ? digits.slice(0, -fmt.decimals) : digits;
|
|
5374
5380
|
const cents = fmt.decimals > 0 ? digits.slice(-fmt.decimals) : "";
|
|
5375
5381
|
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, fmt.groupSeparator);
|
|
5376
|
-
const
|
|
5382
|
+
const alwaysDecimals = Boolean(options && options.decimals === "always");
|
|
5383
|
+
const showCents = cents !== "" && (alwaysDecimals || /[1-9]/.test(cents));
|
|
5384
|
+
const body = showCents ? `${grouped}${fmt.decimalSeparator}${cents}` : grouped;
|
|
5377
5385
|
const gap = fmt.space ? " " : "";
|
|
5378
5386
|
const withSymbol =
|
|
5379
5387
|
fmt.position === "before"
|
|
@@ -6940,7 +6948,11 @@ const CONTRACT = deepFreeze({
|
|
|
6940
6948
|
// `filterList` condition and a query's array-form `filter` take
|
|
6941
6949
|
// `{ operator: "in", value: [a, b] }`; on a list column it matches a row
|
|
6942
6950
|
// holding any of the values. At most 100; no `valueMode` applies.
|
|
6943
|
-
|
|
6951
|
+
// 1.253.0: fix (sc-16577) — `react-native-safe-area-context` is host-resolved,
|
|
6952
|
+
// so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
|
|
6953
|
+
// 1.254.0: `formatMoney` shows a whole amount without decimals ("795 kr");
|
|
6954
|
+
// `formatMoney(minor, { decimals: "always" })` keeps them ("795,00 kr").
|
|
6955
|
+
version: "1.254.0",
|
|
6944
6956
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6945
6957
|
hooks: HOOKS,
|
|
6946
6958
|
primitives: PRIMITIVES,
|
|
@@ -7292,6 +7304,82 @@ function deriveSurfaceTokens(backgroundColor) {
|
|
|
7292
7304
|
};
|
|
7293
7305
|
}
|
|
7294
7306
|
|
|
7307
|
+
// The theme_config keys that state a light page's own surface set, by token.
|
|
7308
|
+
const THEME_SURFACE_COLOR_KEYS = Object.freeze({
|
|
7309
|
+
surfaceMuted: "surfaceMutedColor",
|
|
7310
|
+
border: "surfaceBorderColor",
|
|
7311
|
+
onSurfaceMuted: "mutedTextColor",
|
|
7312
|
+
});
|
|
7313
|
+
// How far a look's muted panel and border step from its page toward its ink.
|
|
7314
|
+
const LIGHT_SURFACE_MIX = Object.freeze({ surfaceMuted: 0.04, border: 0.12 });
|
|
7315
|
+
// Slate's own saturation, so a tinted set is as quiet as the default one.
|
|
7316
|
+
const LIGHT_SURFACE_MAX_SATURATION = 0.2;
|
|
7317
|
+
const LIGHT_SURFACE_TEXT_STEP = 0.01;
|
|
7318
|
+
|
|
7319
|
+
function isLightBackground(backgroundColor) {
|
|
7320
|
+
return readableTextColor(backgroundColor, "dark", "light") === "dark";
|
|
7321
|
+
}
|
|
7322
|
+
|
|
7323
|
+
/**
|
|
7324
|
+
* The page's surface set for a stored theme: `deriveSurfaceTokens` of its
|
|
7325
|
+
* background, with the theme's own `THEME_SURFACE_COLOR_KEYS` over it while
|
|
7326
|
+
* that background is light. A dark page keeps the derivation, so a light set
|
|
7327
|
+
* left on the theme never paints it. `null` when the background is unusable.
|
|
7328
|
+
*/
|
|
7329
|
+
function themeSurfaceTokens(themeConfig) {
|
|
7330
|
+
const cfg = themeConfig && typeof themeConfig === "object" ? themeConfig : {};
|
|
7331
|
+
const derived = deriveSurfaceTokens(cfg.backgroundColor);
|
|
7332
|
+
if (!derived || !isLightBackground(cfg.backgroundColor)) return derived;
|
|
7333
|
+
const out = { ...derived };
|
|
7334
|
+
for (const [token, key] of Object.entries(THEME_SURFACE_COLOR_KEYS)) {
|
|
7335
|
+
if (isHexColor(cfg[key])) out[token] = cfg[key];
|
|
7336
|
+
}
|
|
7337
|
+
return out;
|
|
7338
|
+
}
|
|
7339
|
+
|
|
7340
|
+
/**
|
|
7341
|
+
* The surface set a look's LIGHT background wants, as theme_config keys: the
|
|
7342
|
+
* muted panel and border step toward the ink in the background's own hue, and
|
|
7343
|
+
* the muted text keeps the default's weight in that hue, darkened until it
|
|
7344
|
+
* reads at WCAG AA on the surface, the muted panel and the page. `null` for a
|
|
7345
|
+
* dark or unusable background, which `deriveSurfaceTokens` already covers.
|
|
7346
|
+
*/
|
|
7347
|
+
/** The hues of the contract's own slate: a page tinted within them already matches it. */
|
|
7348
|
+
const SLATE_HUES = Object.freeze({ from: 195, to: 225 });
|
|
7349
|
+
|
|
7350
|
+
/** Whether a page has a hue of its own; white, grey and slate-blue keep the contract's colours. */
|
|
7351
|
+
function hasOwnTint(backgroundColor) {
|
|
7352
|
+
const channels = hexChannels(backgroundColor);
|
|
7353
|
+
if (Math.max(...channels) - Math.min(...channels) <= 2) return false;
|
|
7354
|
+
const [hue] = hexToHsl(backgroundColor);
|
|
7355
|
+
return hue < SLATE_HUES.from || hue > SLATE_HUES.to;
|
|
7356
|
+
}
|
|
7357
|
+
|
|
7358
|
+
function deriveLightSurfaceColors(backgroundColor, inkColor) {
|
|
7359
|
+
if (!isHexColor(backgroundColor) || !isLightBackground(backgroundColor) || !hasOwnTint(backgroundColor)) return null;
|
|
7360
|
+
const base = DEFAULT_THEME_TOKENS.colors;
|
|
7361
|
+
const [hue, saturation] = hexToHsl(backgroundColor);
|
|
7362
|
+
const tint = Math.min(saturation, LIGHT_SURFACE_MAX_SATURATION);
|
|
7363
|
+
const ink = isHexColor(inkColor) ? inkColor : base.onSurface;
|
|
7364
|
+
const tone = hslToHex(hue, tint, hexToHsl(ink)[2]);
|
|
7365
|
+
const surfaceMuted = mixHex(backgroundColor, tone, LIGHT_SURFACE_MIX.surfaceMuted);
|
|
7366
|
+
const backdrops = [base.surface, surfaceMuted, backgroundColor];
|
|
7367
|
+
let lightness = hexToHsl(base.onSurfaceMuted)[2];
|
|
7368
|
+
let text = hslToHex(hue, tint, lightness);
|
|
7369
|
+
while (
|
|
7370
|
+
lightness > 0 &&
|
|
7371
|
+
backdrops.some((backdrop) => contrastRatio(text, backdrop) < ACCENT_TEXT_MIN_CONTRAST)
|
|
7372
|
+
) {
|
|
7373
|
+
lightness = Math.max(0, lightness - LIGHT_SURFACE_TEXT_STEP);
|
|
7374
|
+
text = hslToHex(hue, tint, lightness);
|
|
7375
|
+
}
|
|
7376
|
+
return {
|
|
7377
|
+
[THEME_SURFACE_COLOR_KEYS.surfaceMuted]: surfaceMuted,
|
|
7378
|
+
[THEME_SURFACE_COLOR_KEYS.border]: mixHex(backgroundColor, tone, LIGHT_SURFACE_MIX.border),
|
|
7379
|
+
[THEME_SURFACE_COLOR_KEYS.onSurfaceMuted]: text,
|
|
7380
|
+
};
|
|
7381
|
+
}
|
|
7382
|
+
|
|
7295
7383
|
// sc-8370: WCAG 1.4.3 for text, 1.4.11 for a control's boundary.
|
|
7296
7384
|
const INK_CONTRAST = Object.freeze({ text: 4.5, boundary: 3 });
|
|
7297
7385
|
|
|
@@ -7445,6 +7533,9 @@ export {
|
|
|
7445
7533
|
deriveAccentTints,
|
|
7446
7534
|
deriveStatusColors,
|
|
7447
7535
|
deriveSurfaceTokens,
|
|
7536
|
+
themeSurfaceTokens,
|
|
7537
|
+
deriveLightSurfaceColors,
|
|
7538
|
+
THEME_SURFACE_COLOR_KEYS,
|
|
7448
7539
|
inkForBackdrop,
|
|
7449
7540
|
INK_CONTRAST,
|
|
7450
7541
|
gradientAngleToVector,
|
package/dist/devserver.js
CHANGED
|
@@ -82,8 +82,11 @@ import { bundleWebEntry } from "./webbundle.js";
|
|
|
82
82
|
import {
|
|
83
83
|
findImportStatements,
|
|
84
84
|
findRelativeImportStatements,
|
|
85
|
+
resolveRelativeImport,
|
|
85
86
|
} from "./flatten-entry.js";
|
|
86
87
|
|
|
88
|
+
export { resolveRelativeImport };
|
|
89
|
+
|
|
87
90
|
// Bare-import / relative-import detection. The loader rewrites bare specifiers
|
|
88
91
|
// in the ENTRY to client-side blob shims, so they resolve fine. Relative
|
|
89
92
|
// imports in a SINGLE-FILE entry have nowhere to resolve — single-file mode
|
|
@@ -126,7 +129,7 @@ export async function loadTransform() {
|
|
|
126
129
|
return mod.transform;
|
|
127
130
|
} catch {
|
|
128
131
|
throw new Error(
|
|
129
|
-
"`appstudio-widget dev` needs
|
|
132
|
+
"`appstudio-widget dev` needs `sucrase`, an optional peer of the SDK.\n" +
|
|
130
133
|
"Install it in your widget project:\n" +
|
|
131
134
|
" npm install --save-dev sucrase",
|
|
132
135
|
);
|
|
@@ -172,35 +175,6 @@ export function findRelativeImports(source) {
|
|
|
172
175
|
);
|
|
173
176
|
}
|
|
174
177
|
|
|
175
|
-
/**
|
|
176
|
-
* Resolve a relative specifier (`./foo` / `../bar/baz`) into an absolute
|
|
177
|
-
* `/file/<rel>` path under the widget directory. The result is what the dev
|
|
178
|
-
* server serves and what the browser fetches. Returns null when the resolved
|
|
179
|
-
* path escapes the widget directory — the caller refuses to bundle it.
|
|
180
|
-
*
|
|
181
|
-
* Specifiers without a `.jsx`/`.js`/`.json` extension get a `.jsx` default so
|
|
182
|
-
* `import Helper from "./helper"` works without forcing the author to type
|
|
183
|
-
* the extension (matches Vite / Metro behaviour).
|
|
184
|
-
*
|
|
185
|
-
* @param {string} fromRel the rel-path of the importing file (POSIX-style,
|
|
186
|
-
* relative to the widget dir, e.g. "MapWidget.web.jsx" or "lib/util.jsx").
|
|
187
|
-
* @param {string} specifier the relative specifier as written in source.
|
|
188
|
-
* @returns {string | null} POSIX-style rel-path under the widget dir, or null
|
|
189
|
-
* if the resolution escapes it.
|
|
190
|
-
*/
|
|
191
|
-
export function resolveRelativeImport(fromRel, specifier) {
|
|
192
|
-
if (!specifier.startsWith("./") && !specifier.startsWith("../")) return null;
|
|
193
|
-
const fromDir = posix.dirname(fromRel.replace(/\\/g, "/"));
|
|
194
|
-
const joined = posix.normalize(posix.join(fromDir, specifier));
|
|
195
|
-
if (joined.startsWith("..") || joined.startsWith("/")) return null;
|
|
196
|
-
// Default the extension when omitted. A specifier with a non-JS extension
|
|
197
|
-
// (asset imports like `./icon.svg`) is rejected — the dev server only
|
|
198
|
-
// serves JS modules; static asset bundling needs a real build step.
|
|
199
|
-
if (/\.(jsx?|json)$/.test(joined)) return joined;
|
|
200
|
-
if (/\.[A-Za-z0-9]+$/.test(joined)) return null;
|
|
201
|
-
return `${joined}.jsx`;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
178
|
/**
|
|
205
179
|
* Rewrite imports inside a served file so the browser can resolve every
|
|
206
180
|
* specifier without help from the host loader:
|
package/dist/flatten-entry.js
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
// a declaration capturing another module's free reference is not detectable
|
|
32
32
|
// without scope analysis this deliberately does not do.
|
|
33
33
|
|
|
34
|
+
import { posix } from "node:path";
|
|
34
35
|
import { stripNonCode } from "./source-mask.js";
|
|
35
36
|
|
|
36
37
|
// ---------------------------------------------------------------------------
|
|
@@ -815,3 +816,32 @@ export function flattenEntry({ entryRel, readModule, resolve, parse }) {
|
|
|
815
816
|
// which parses cleanly and does the wrong thing.
|
|
816
817
|
return { source: parts.join("\n;\n"), modules: [entryRel, ...siblings] };
|
|
817
818
|
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Resolve a relative specifier (`./foo` / `../bar/baz`) into a POSIX rel-path
|
|
822
|
+
* under the widget directory: what the dev server serves and what the
|
|
823
|
+
* packer and the hosted upload inline (sc-16577). Returns null when the resolved
|
|
824
|
+
* path escapes the widget directory — the caller refuses to bundle it.
|
|
825
|
+
*
|
|
826
|
+
* Specifiers without a `.jsx`/`.js`/`.json` extension get a `.jsx` default so
|
|
827
|
+
* `import Helper from "./helper"` works without forcing the author to type
|
|
828
|
+
* the extension (matches Vite / Metro behaviour).
|
|
829
|
+
*
|
|
830
|
+
* @param {string} fromRel the rel-path of the importing file (POSIX-style,
|
|
831
|
+
* relative to the widget dir, e.g. "MapWidget.web.jsx" or "lib/util.jsx").
|
|
832
|
+
* @param {string} specifier the relative specifier as written in source.
|
|
833
|
+
* @returns {string | null} POSIX-style rel-path under the widget dir, or null
|
|
834
|
+
* if the resolution escapes it.
|
|
835
|
+
*/
|
|
836
|
+
export function resolveRelativeImport(fromRel, specifier) {
|
|
837
|
+
if (!specifier.startsWith("./") && !specifier.startsWith("../")) return null;
|
|
838
|
+
const fromDir = posix.dirname(fromRel.replace(/\\/g, "/"));
|
|
839
|
+
const joined = posix.normalize(posix.join(fromDir, specifier));
|
|
840
|
+
if (joined.startsWith("..") || joined.startsWith("/")) return null;
|
|
841
|
+
// Default the extension when omitted. A specifier with a non-JS extension
|
|
842
|
+
// (asset imports like `./icon.svg`) is rejected — the dev server only
|
|
843
|
+
// serves JS modules; static asset bundling needs a real build step.
|
|
844
|
+
if (/\.(jsx?|json)$/.test(joined)) return joined;
|
|
845
|
+
if (/\.[A-Za-z0-9]+$/.test(joined)) return null;
|
|
846
|
+
return `${joined}.jsx`;
|
|
847
|
+
}
|
package/dist/hooks.js
CHANGED
|
@@ -198,8 +198,9 @@ function readInput(inputs, inputName) {
|
|
|
198
198
|
* resolve the other two pieces of workspace configuration at render time.
|
|
199
199
|
*
|
|
200
200
|
* `formatMoney` takes MINOR units, the same unit `requestPayment` charges in.
|
|
201
|
+
* A whole amount shows no decimals; `{ decimals: "always" }` keeps them.
|
|
201
202
|
*
|
|
202
|
-
* @returns {{ currency: string, formatMoney: (minorUnits: number) => string }}
|
|
203
|
+
* @returns {{ currency: string, formatMoney: (minorUnits: number, options?: { decimals?: "always" }) => string }}
|
|
203
204
|
*/
|
|
204
205
|
export function useWorkspaceCurrency() {
|
|
205
206
|
const ctx = useWidgetContextOrThrow("useWorkspaceCurrency");
|
|
@@ -208,7 +209,7 @@ export function useWorkspaceCurrency() {
|
|
|
208
209
|
return React.useMemo(
|
|
209
210
|
() => ({
|
|
210
211
|
currency: normaliseCurrencyCode(currency),
|
|
211
|
-
formatMoney: (minorUnits) => formatMoneyIn(currency, minorUnits),
|
|
212
|
+
formatMoney: (minorUnits, options) => formatMoneyIn(currency, minorUnits, options),
|
|
212
213
|
}),
|
|
213
214
|
[currency],
|
|
214
215
|
);
|
package/dist/host.d.ts
CHANGED
|
@@ -73,6 +73,16 @@ export function surfaceAwareTheme<T>(theme: T, backgroundColor: unknown): T;
|
|
|
73
73
|
/** Minimum contrast: `text` for labels (WCAG 1.4.3), `boundary` for edges (1.4.11). */
|
|
74
74
|
export const INK_CONTRAST: Readonly<{ text: number; boundary: number }>;
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Minor units in a currency to its display string, as `useWorkspaceCurrency().formatMoney`
|
|
78
|
+
* writes it: `formatMoneyIn("SEK", 79500)` -> "795 kr", 9950 -> "99,50 kr".
|
|
79
|
+
*/
|
|
80
|
+
export function formatMoneyIn(
|
|
81
|
+
currency: string | null | undefined,
|
|
82
|
+
minorUnits: number,
|
|
83
|
+
options?: { decimals?: "always" },
|
|
84
|
+
): string;
|
|
85
|
+
|
|
76
86
|
/**
|
|
77
87
|
* The measured re-ink rule a painted section applies to its text and buttons:
|
|
78
88
|
* `current` while it reaches `minimum` against `backdrop`, else `candidate`
|
package/dist/host.js
CHANGED
|
@@ -42,6 +42,10 @@ export {
|
|
|
42
42
|
// Host plumbing, deliberately off the author entry point: a widget reads the
|
|
43
43
|
// already-correct `useTheme().colors`, it never derives them itself.
|
|
44
44
|
export { deriveSurfaceTokens, inkForBackdrop, INK_CONTRAST } from "./contract.js";
|
|
45
|
+
// A stored theme's page surface set, honouring its own light-surface colours.
|
|
46
|
+
export { themeSurfaceTokens } from "./contract.js";
|
|
47
|
+
// The host's own price labels, written exactly as a widget's `formatMoney`.
|
|
48
|
+
export { formatMoneyIn } from "./contract.js";
|
|
45
49
|
export { surfaceAwareTheme } from "./surface-theme.js";
|
|
46
50
|
|
|
47
51
|
// REQ-WSDK-PLATFORM §6: the host half of `useToast()` — the queue, the
|
package/dist/index.d.ts
CHANGED
|
@@ -1843,8 +1843,11 @@ export function useRecordMutes(
|
|
|
1843
1843
|
export interface WorkspaceCurrency {
|
|
1844
1844
|
/** The ISO code this workspace charges its app users in. */
|
|
1845
1845
|
currency: string;
|
|
1846
|
-
/**
|
|
1847
|
-
|
|
1846
|
+
/**
|
|
1847
|
+
* MINOR units in, a display string out: 79500 -> "795 kr", 9950 -> "99,50 kr".
|
|
1848
|
+
* `{ decimals: "always" }` keeps the decimals of a whole amount: "795,00 kr".
|
|
1849
|
+
*/
|
|
1850
|
+
formatMoney: (minorUnits: number, options?: { decimals?: "always" }) => string;
|
|
1848
1851
|
}
|
|
1849
1852
|
/**
|
|
1850
1853
|
* sc-4686 — the workspace charge currency + the only sanctioned way to render
|