@colixsystems/widget-sdk 0.309.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 +27 -4
- package/dist/contract.cjs +104 -18
- package/dist/contract.js +104 -18
- package/dist/devserver.js +1 -1
- 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 +104 -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,25 @@ 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`.
|
|
94
112
|
|
|
95
113
|
### What's new in 0.309.0 (contract 1.253.0)
|
|
96
114
|
|
|
@@ -3999,6 +4017,10 @@ Pass `--manifest` to enable `style-field-unread` and the three editability rules
|
|
|
3999
4017
|
|
|
4000
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`.
|
|
4001
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
|
+
|
|
4002
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.
|
|
4003
4025
|
|
|
4004
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.
|
|
@@ -4035,8 +4057,9 @@ published bundle hits) and hot-reloads onto the canvas on every save.
|
|
|
4035
4057
|
`widget.native.jsx` with shared `./relative.jsx` helpers) need a real build
|
|
4036
4058
|
step; the dev server reports relative imports rather than serving a module
|
|
4037
4059
|
the browser can't resolve.
|
|
4038
|
-
- `dev` lazily requires the optional `sucrase`
|
|
4039
|
-
|
|
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`.
|
|
4040
4063
|
- Lint findings print to the terminal on each change but never block serving.
|
|
4041
4064
|
|
|
4042
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
|
{
|
|
@@ -5341,18 +5341,6 @@ function normaliseCurrencyCode(value) {
|
|
|
5341
5341
|
return code || CHARGE_CURRENCY;
|
|
5342
5342
|
}
|
|
5343
5343
|
|
|
5344
|
-
/**
|
|
5345
|
-
* `formatMoneyIn("SEK", 45000)` → `"450,00 kr"`.
|
|
5346
|
-
*
|
|
5347
|
-
* Takes MINOR units — the same unit `requestPayment` charges in — so there is no
|
|
5348
|
-
* conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
|
|
5349
|
-
* rather than `Intl.NumberFormat`, which does not produce identical output in
|
|
5350
|
-
* the exported Expo app and react-native-web; this string sits beside the amount
|
|
5351
|
-
* the buyer is actually charged, so the two hosts must agree exactly.
|
|
5352
|
-
*
|
|
5353
|
-
* A non-finite amount renders as zero rather than "NaN": a price whose data has
|
|
5354
|
-
* not loaded should read as an amount, never as a broken string in a checkout.
|
|
5355
|
-
*/
|
|
5356
5344
|
/**
|
|
5357
5345
|
* sc-5717 — value equality for a stored widget-route value: is this key still
|
|
5358
5346
|
* at the default its widget declared?
|
|
@@ -5368,7 +5356,22 @@ function sameWidgetRouteValue(a, b) {
|
|
|
5368
5356
|
}
|
|
5369
5357
|
return Object.is(a, b);
|
|
5370
5358
|
}
|
|
5371
|
-
|
|
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) {
|
|
5372
5375
|
const code = normaliseCurrencyCode(currency);
|
|
5373
5376
|
const fmt = CURRENCY_FORMATS[code] || {
|
|
5374
5377
|
...CURRENCY_FORMAT_FALLBACK,
|
|
@@ -5381,7 +5384,9 @@ function formatMoneyIn(currency, minorUnits) {
|
|
|
5381
5384
|
const whole = fmt.decimals > 0 ? digits.slice(0, -fmt.decimals) : digits;
|
|
5382
5385
|
const cents = fmt.decimals > 0 ? digits.slice(-fmt.decimals) : "";
|
|
5383
5386
|
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, fmt.groupSeparator);
|
|
5384
|
-
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;
|
|
5385
5390
|
const gap = fmt.space ? " " : "";
|
|
5386
5391
|
const withSymbol =
|
|
5387
5392
|
fmt.position === "before"
|
|
@@ -6950,7 +6955,9 @@ const CONTRACT = deepFreeze({
|
|
|
6950
6955
|
// holding any of the values. At most 100; no `valueMode` applies.
|
|
6951
6956
|
// 1.253.0: fix (sc-16577) — `react-native-safe-area-context` is host-resolved,
|
|
6952
6957
|
// so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
|
|
6953
|
-
|
|
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",
|
|
6954
6961
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6955
6962
|
hooks: HOOKS,
|
|
6956
6963
|
primitives: PRIMITIVES,
|
|
@@ -7302,6 +7309,82 @@ function deriveSurfaceTokens(backgroundColor) {
|
|
|
7302
7309
|
};
|
|
7303
7310
|
}
|
|
7304
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
|
+
|
|
7305
7388
|
// sc-8370: WCAG 1.4.3 for text, 1.4.11 for a control's boundary.
|
|
7306
7389
|
const INK_CONTRAST = Object.freeze({ text: 4.5, boundary: 3 });
|
|
7307
7390
|
|
|
@@ -7455,6 +7538,9 @@ module.exports = {
|
|
|
7455
7538
|
deriveAccentTints,
|
|
7456
7539
|
deriveStatusColors,
|
|
7457
7540
|
deriveSurfaceTokens,
|
|
7541
|
+
themeSurfaceTokens,
|
|
7542
|
+
deriveLightSurfaceColors,
|
|
7543
|
+
THEME_SURFACE_COLOR_KEYS,
|
|
7458
7544
|
inkForBackdrop,
|
|
7459
7545
|
INK_CONTRAST,
|
|
7460
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
|
{
|
|
@@ -5336,18 +5336,6 @@ function normaliseCurrencyCode(value) {
|
|
|
5336
5336
|
return code || CHARGE_CURRENCY;
|
|
5337
5337
|
}
|
|
5338
5338
|
|
|
5339
|
-
/**
|
|
5340
|
-
* `formatMoneyIn("SEK", 45000)` → `"450,00 kr"`.
|
|
5341
|
-
*
|
|
5342
|
-
* Takes MINOR units — the same unit `requestPayment` charges in — so there is no
|
|
5343
|
-
* conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
|
|
5344
|
-
* rather than `Intl.NumberFormat`, which does not produce identical output in
|
|
5345
|
-
* the exported Expo app and react-native-web; this string sits beside the amount
|
|
5346
|
-
* the buyer is actually charged, so the two hosts must agree exactly.
|
|
5347
|
-
*
|
|
5348
|
-
* A non-finite amount renders as zero rather than "NaN": a price whose data has
|
|
5349
|
-
* not loaded should read as an amount, never as a broken string in a checkout.
|
|
5350
|
-
*/
|
|
5351
5339
|
/**
|
|
5352
5340
|
* sc-5717 — value equality for a stored widget-route value: is this key still
|
|
5353
5341
|
* at the default its widget declared?
|
|
@@ -5363,7 +5351,22 @@ function sameWidgetRouteValue(a, b) {
|
|
|
5363
5351
|
}
|
|
5364
5352
|
return Object.is(a, b);
|
|
5365
5353
|
}
|
|
5366
|
-
|
|
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) {
|
|
5367
5370
|
const code = normaliseCurrencyCode(currency);
|
|
5368
5371
|
const fmt = CURRENCY_FORMATS[code] || {
|
|
5369
5372
|
...CURRENCY_FORMAT_FALLBACK,
|
|
@@ -5376,7 +5379,9 @@ function formatMoneyIn(currency, minorUnits) {
|
|
|
5376
5379
|
const whole = fmt.decimals > 0 ? digits.slice(0, -fmt.decimals) : digits;
|
|
5377
5380
|
const cents = fmt.decimals > 0 ? digits.slice(-fmt.decimals) : "";
|
|
5378
5381
|
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, fmt.groupSeparator);
|
|
5379
|
-
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;
|
|
5380
5385
|
const gap = fmt.space ? " " : "";
|
|
5381
5386
|
const withSymbol =
|
|
5382
5387
|
fmt.position === "before"
|
|
@@ -6945,7 +6950,9 @@ const CONTRACT = deepFreeze({
|
|
|
6945
6950
|
// holding any of the values. At most 100; no `valueMode` applies.
|
|
6946
6951
|
// 1.253.0: fix (sc-16577) — `react-native-safe-area-context` is host-resolved,
|
|
6947
6952
|
// so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
|
|
6948
|
-
|
|
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",
|
|
6949
6956
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6950
6957
|
hooks: HOOKS,
|
|
6951
6958
|
primitives: PRIMITIVES,
|
|
@@ -7297,6 +7304,82 @@ function deriveSurfaceTokens(backgroundColor) {
|
|
|
7297
7304
|
};
|
|
7298
7305
|
}
|
|
7299
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
|
+
|
|
7300
7383
|
// sc-8370: WCAG 1.4.3 for text, 1.4.11 for a control's boundary.
|
|
7301
7384
|
const INK_CONTRAST = Object.freeze({ text: 4.5, boundary: 3 });
|
|
7302
7385
|
|
|
@@ -7450,6 +7533,9 @@ export {
|
|
|
7450
7533
|
deriveAccentTints,
|
|
7451
7534
|
deriveStatusColors,
|
|
7452
7535
|
deriveSurfaceTokens,
|
|
7536
|
+
themeSurfaceTokens,
|
|
7537
|
+
deriveLightSurfaceColors,
|
|
7538
|
+
THEME_SURFACE_COLOR_KEYS,
|
|
7453
7539
|
inkForBackdrop,
|
|
7454
7540
|
INK_CONTRAST,
|
|
7455
7541
|
gradientAngleToVector,
|
package/dist/devserver.js
CHANGED
|
@@ -129,7 +129,7 @@ export async function loadTransform() {
|
|
|
129
129
|
return mod.transform;
|
|
130
130
|
} catch {
|
|
131
131
|
throw new Error(
|
|
132
|
-
"`appstudio-widget dev` needs
|
|
132
|
+
"`appstudio-widget dev` needs `sucrase`, an optional peer of the SDK.\n" +
|
|
133
133
|
"Install it in your widget project:\n" +
|
|
134
134
|
" npm install --save-dev sucrase",
|
|
135
135
|
);
|
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
|
package/dist/linter.cjs
CHANGED
|
@@ -2276,6 +2276,30 @@ function _openTagStack() {
|
|
|
2276
2276
|
};
|
|
2277
2277
|
}
|
|
2278
2278
|
|
|
2279
|
+
/**
|
|
2280
|
+
* The next opening tag in `structure` from `_JSX_TOKEN_RE`'s position, keeping
|
|
2281
|
+
* `open` in step with the fragments and closing tags passed on the way.
|
|
2282
|
+
*/
|
|
2283
|
+
function _nextOpeningTag(structure, open, fragmentFrame) {
|
|
2284
|
+
let token;
|
|
2285
|
+
while ((token = _JSX_TOKEN_RE.exec(structure))) {
|
|
2286
|
+
const [, closing, name] = token;
|
|
2287
|
+
if (!name) {
|
|
2288
|
+
// A fragment, `<>` or `</>`; any other `<` is a comparison.
|
|
2289
|
+
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2290
|
+
if (closing) open.pop();
|
|
2291
|
+
else open.push(fragmentFrame(token));
|
|
2292
|
+
continue;
|
|
2293
|
+
}
|
|
2294
|
+
if (closing) {
|
|
2295
|
+
open.close(name);
|
|
2296
|
+
continue;
|
|
2297
|
+
}
|
|
2298
|
+
return token;
|
|
2299
|
+
}
|
|
2300
|
+
return null;
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2279
2303
|
function _fieldInBorderedRowRules(source) {
|
|
2280
2304
|
const findings = [];
|
|
2281
2305
|
const scan = {
|
|
@@ -2310,19 +2334,8 @@ function _fieldInBorderedRowRules(source) {
|
|
|
2310
2334
|
const open = _openTagStack();
|
|
2311
2335
|
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2312
2336
|
let token;
|
|
2313
|
-
while ((token =
|
|
2314
|
-
const
|
|
2315
|
-
if (!name) {
|
|
2316
|
-
// A fragment, `<>` or `</>`; any other `<` is a comparison.
|
|
2317
|
-
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2318
|
-
if (closing) open.pop();
|
|
2319
|
-
else open.push(null);
|
|
2320
|
-
continue;
|
|
2321
|
-
}
|
|
2322
|
-
if (closing) {
|
|
2323
|
-
open.close(name);
|
|
2324
|
-
continue;
|
|
2325
|
-
}
|
|
2337
|
+
while ((token = _nextOpeningTag(structure, open, () => null))) {
|
|
2338
|
+
const name = token[2];
|
|
2326
2339
|
const end = scan.index.tagEnd(token.index);
|
|
2327
2340
|
if (end === -1) break;
|
|
2328
2341
|
const tag = { name, attrs: [token.index + token[0].length, end], borderedRow: undefined };
|
|
@@ -2386,20 +2399,14 @@ function _gridCellWidthRules(source) {
|
|
|
2386
2399
|
const open = _openTagStack();
|
|
2387
2400
|
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2388
2401
|
let token;
|
|
2389
|
-
|
|
2390
|
-
|
|
2402
|
+
// A fragment is transparent: its children are its parent's children.
|
|
2403
|
+
const fragment = () => {
|
|
2404
|
+
const parent = open.top();
|
|
2405
|
+
return { name: "", narrow: parent && parent.narrow, cell: parent && parent.cell };
|
|
2406
|
+
};
|
|
2407
|
+
while ((token = _nextOpeningTag(structure, open, fragment))) {
|
|
2408
|
+
const name = token[2];
|
|
2391
2409
|
const parent = open.top();
|
|
2392
|
-
if (!name) {
|
|
2393
|
-
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2394
|
-
// A fragment is transparent: its children are its parent's children.
|
|
2395
|
-
if (closing) open.pop();
|
|
2396
|
-
else open.push({ name: "", narrow: parent && parent.narrow, cell: parent && parent.cell });
|
|
2397
|
-
continue;
|
|
2398
|
-
}
|
|
2399
|
-
if (closing) {
|
|
2400
|
-
open.close(name);
|
|
2401
|
-
continue;
|
|
2402
|
-
}
|
|
2403
2410
|
const end = index.tagEnd(token.index);
|
|
2404
2411
|
if (end === -1) break;
|
|
2405
2412
|
const tag = { name, narrow: undefined, cell: parent && parent.cell };
|
|
@@ -2429,6 +2436,120 @@ function _gridCellWidthRules(source) {
|
|
|
2429
2436
|
return findings;
|
|
2430
2437
|
}
|
|
2431
2438
|
|
|
2439
|
+
// sc-16682 — two sibling patterns a production build's widgets shipped.
|
|
2440
|
+
//
|
|
2441
|
+
// An action beside an <EmptyState> sits outside its panel; EmptyState takes
|
|
2442
|
+
// its action as `children`. Flagged when a Button or Pressable is the next
|
|
2443
|
+
// element after an EmptyState, or the first child of the View that is.
|
|
2444
|
+
//
|
|
2445
|
+
// Field labels in two styles: one field given the SDK `label`, another
|
|
2446
|
+
// labelled by a <Text> drawn just before it, so the two labels render in
|
|
2447
|
+
// different type. Only a Text that is the control's previous sibling counts
|
|
2448
|
+
// as its label, which keeps a heading above a whole form out of it.
|
|
2449
|
+
const _EMPTY_STATE_ACTION_TAGS = new Set(["Button", "Pressable"]);
|
|
2450
|
+
const _SELF_LABELLED_FIELD_TAGS = new Set([
|
|
2451
|
+
"TextField",
|
|
2452
|
+
"Select",
|
|
2453
|
+
"RadioGroup",
|
|
2454
|
+
"PeoplePicker",
|
|
2455
|
+
"FileUpload",
|
|
2456
|
+
"FormField",
|
|
2457
|
+
]);
|
|
2458
|
+
const _LABELLABLE_CONTROL_TAGS = new Set([
|
|
2459
|
+
..._SELF_LABELLED_FIELD_TAGS,
|
|
2460
|
+
"TextInput",
|
|
2461
|
+
"ChipGroup",
|
|
2462
|
+
"DateTimePicker",
|
|
2463
|
+
]);
|
|
2464
|
+
const _LABEL_ATTR_RE = /(?:^|\s)label\s*=/;
|
|
2465
|
+
|
|
2466
|
+
function _siblingRules(source) {
|
|
2467
|
+
if (!source.includes("<EmptyState") && !source.includes("label")) return [];
|
|
2468
|
+
const structure = _stripNonCode(source);
|
|
2469
|
+
const index = _jsxScanIndex(structure);
|
|
2470
|
+
const lineAt = _lineCounter(structure);
|
|
2471
|
+
const sourceLines = source.split(/\r?\n/);
|
|
2472
|
+
const findings = [];
|
|
2473
|
+
const report = (rule, at, label) => {
|
|
2474
|
+
const line = lineAt(at);
|
|
2475
|
+
findings.push({
|
|
2476
|
+
rule,
|
|
2477
|
+
severity: "warning",
|
|
2478
|
+
label,
|
|
2479
|
+
line,
|
|
2480
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
2481
|
+
});
|
|
2482
|
+
};
|
|
2483
|
+
// Not when the two are alternatives (`empty ? <EmptyState /> : <Button />`)
|
|
2484
|
+
// or sit in separate expressions (`{a && <EmptyState />}{b && <Button />}`).
|
|
2485
|
+
const renderedTogether = (emptyState, at) => {
|
|
2486
|
+
let depth = 0;
|
|
2487
|
+
for (let i = emptyState.at; i < at; i++) {
|
|
2488
|
+
const ch = structure[i];
|
|
2489
|
+
if (ch === "{") depth++;
|
|
2490
|
+
else if (ch === "}" && --depth < 0) return false;
|
|
2491
|
+
else if (ch === ":" && depth === 0) return false;
|
|
2492
|
+
}
|
|
2493
|
+
return true;
|
|
2494
|
+
};
|
|
2495
|
+
const afterEmptyState = (tag) =>
|
|
2496
|
+
tag && tag.name === "EmptyState" ? tag : null;
|
|
2497
|
+
let sdkLabelled = null;
|
|
2498
|
+
let ownLabelled = null;
|
|
2499
|
+
const open = _openTagStack();
|
|
2500
|
+
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2501
|
+
let token;
|
|
2502
|
+
const fragment = (at) => ({ name: "", at: at.index, before: null, last: null });
|
|
2503
|
+
while ((token = _nextOpeningTag(structure, open, fragment))) {
|
|
2504
|
+
const name = token[2];
|
|
2505
|
+
// `useState<Item>` and `a<B` are not tags.
|
|
2506
|
+
if (/[\w$)\]]/.test(structure[token.index - 1] || "")) continue;
|
|
2507
|
+
const end = index.tagEnd(token.index);
|
|
2508
|
+
if (end === -1) break;
|
|
2509
|
+
const parent = open.top();
|
|
2510
|
+
const before = parent ? parent.last : null;
|
|
2511
|
+
const tag = { name, at: token.index, before, last: null };
|
|
2512
|
+
if (parent) parent.last = tag;
|
|
2513
|
+
if (_EMPTY_STATE_ACTION_TAGS.has(name) && parent) {
|
|
2514
|
+
const emptyState =
|
|
2515
|
+
afterEmptyState(before) ||
|
|
2516
|
+
(parent.name === "View" && !before ? afterEmptyState(parent.before) : null);
|
|
2517
|
+
if (emptyState && renderedTogether(emptyState, token.index)) {
|
|
2518
|
+
report(
|
|
2519
|
+
"empty-state-action-outside",
|
|
2520
|
+
token.index,
|
|
2521
|
+
`This <${name}> sits beside the <EmptyState>, outside its panel. ` +
|
|
2522
|
+
`EmptyState takes its action as children: ` +
|
|
2523
|
+
`<EmptyState title={…}><Button title={…} onPress={…} /></EmptyState> ` +
|
|
2524
|
+
`draws it inside the panel, under the message.`,
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
if (_LABELLABLE_CONTROL_TAGS.has(name)) {
|
|
2529
|
+
const labelled = _LABEL_ATTR_RE.test(structure.slice(token.index + token[0].length, end));
|
|
2530
|
+
if (labelled && _SELF_LABELLED_FIELD_TAGS.has(name)) {
|
|
2531
|
+
if (!sdkLabelled) sdkLabelled = tag;
|
|
2532
|
+
} else if (!labelled && before && before.name === "Text") {
|
|
2533
|
+
if (!ownLabelled) ownLabelled = { tag, label: before };
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
if (!_selfClosing(structure, end)) open.push(tag);
|
|
2537
|
+
_JSX_TOKEN_RE.lastIndex = end + 1;
|
|
2538
|
+
}
|
|
2539
|
+
if (sdkLabelled && ownLabelled) {
|
|
2540
|
+
report(
|
|
2541
|
+
"field-label-styles-mixed",
|
|
2542
|
+
ownLabelled.label.at,
|
|
2543
|
+
`This <Text> labels the <${ownLabelled.tag.name}> after it, while ` +
|
|
2544
|
+
`line ${lineAt(sdkLabelled.at)} gives <${sdkLabelled.name}> the ` +
|
|
2545
|
+
`SDK label, so the form shows labels in two styles. Label every ` +
|
|
2546
|
+
`field one way: the label prop, or <FormField label> round a ` +
|
|
2547
|
+
`control that has none.`,
|
|
2548
|
+
);
|
|
2549
|
+
}
|
|
2550
|
+
return findings;
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2432
2553
|
// sc-4913 — a measured frame INCLUDES the element's own padding.
|
|
2433
2554
|
//
|
|
2434
2555
|
// `onLayout` reports the frame width, and padding sits inside that frame. A
|
|
@@ -3264,6 +3385,8 @@ function lintSource(source, options) {
|
|
|
3264
3385
|
findings.push(..._fieldInBorderedRowRules(source));
|
|
3265
3386
|
// sc-15754 — a Grid cell under 200px holding more than one Text is refused.
|
|
3266
3387
|
findings.push(..._gridCellWidthRules(source));
|
|
3388
|
+
// sc-16682 — soft warnings: an action beside an EmptyState, mixed field labels.
|
|
3389
|
+
findings.push(..._siblingRules(source));
|
|
3267
3390
|
// sc-4913 — soft warning: a measured width that includes the widget's own
|
|
3268
3391
|
// padding wraps the last grid column into an empty one.
|
|
3269
3392
|
findings.push(..._measuredPaddingRules(source));
|
package/dist/linter.js
CHANGED
|
@@ -2271,6 +2271,30 @@ function _openTagStack() {
|
|
|
2271
2271
|
};
|
|
2272
2272
|
}
|
|
2273
2273
|
|
|
2274
|
+
/**
|
|
2275
|
+
* The next opening tag in `structure` from `_JSX_TOKEN_RE`'s position, keeping
|
|
2276
|
+
* `open` in step with the fragments and closing tags passed on the way.
|
|
2277
|
+
*/
|
|
2278
|
+
function _nextOpeningTag(structure, open, fragmentFrame) {
|
|
2279
|
+
let token;
|
|
2280
|
+
while ((token = _JSX_TOKEN_RE.exec(structure))) {
|
|
2281
|
+
const [, closing, name] = token;
|
|
2282
|
+
if (!name) {
|
|
2283
|
+
// A fragment, `<>` or `</>`; any other `<` is a comparison.
|
|
2284
|
+
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2285
|
+
if (closing) open.pop();
|
|
2286
|
+
else open.push(fragmentFrame(token));
|
|
2287
|
+
continue;
|
|
2288
|
+
}
|
|
2289
|
+
if (closing) {
|
|
2290
|
+
open.close(name);
|
|
2291
|
+
continue;
|
|
2292
|
+
}
|
|
2293
|
+
return token;
|
|
2294
|
+
}
|
|
2295
|
+
return null;
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2274
2298
|
function _fieldInBorderedRowRules(source) {
|
|
2275
2299
|
const findings = [];
|
|
2276
2300
|
const scan = {
|
|
@@ -2305,19 +2329,8 @@ function _fieldInBorderedRowRules(source) {
|
|
|
2305
2329
|
const open = _openTagStack();
|
|
2306
2330
|
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2307
2331
|
let token;
|
|
2308
|
-
while ((token =
|
|
2309
|
-
const
|
|
2310
|
-
if (!name) {
|
|
2311
|
-
// A fragment, `<>` or `</>`; any other `<` is a comparison.
|
|
2312
|
-
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2313
|
-
if (closing) open.pop();
|
|
2314
|
-
else open.push(null);
|
|
2315
|
-
continue;
|
|
2316
|
-
}
|
|
2317
|
-
if (closing) {
|
|
2318
|
-
open.close(name);
|
|
2319
|
-
continue;
|
|
2320
|
-
}
|
|
2332
|
+
while ((token = _nextOpeningTag(structure, open, () => null))) {
|
|
2333
|
+
const name = token[2];
|
|
2321
2334
|
const end = scan.index.tagEnd(token.index);
|
|
2322
2335
|
if (end === -1) break;
|
|
2323
2336
|
const tag = { name, attrs: [token.index + token[0].length, end], borderedRow: undefined };
|
|
@@ -2381,20 +2394,14 @@ function _gridCellWidthRules(source) {
|
|
|
2381
2394
|
const open = _openTagStack();
|
|
2382
2395
|
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2383
2396
|
let token;
|
|
2384
|
-
|
|
2385
|
-
|
|
2397
|
+
// A fragment is transparent: its children are its parent's children.
|
|
2398
|
+
const fragment = () => {
|
|
2399
|
+
const parent = open.top();
|
|
2400
|
+
return { name: "", narrow: parent && parent.narrow, cell: parent && parent.cell };
|
|
2401
|
+
};
|
|
2402
|
+
while ((token = _nextOpeningTag(structure, open, fragment))) {
|
|
2403
|
+
const name = token[2];
|
|
2386
2404
|
const parent = open.top();
|
|
2387
|
-
if (!name) {
|
|
2388
|
-
if (structure[token.index + 1 + closing.length] !== ">") continue;
|
|
2389
|
-
// A fragment is transparent: its children are its parent's children.
|
|
2390
|
-
if (closing) open.pop();
|
|
2391
|
-
else open.push({ name: "", narrow: parent && parent.narrow, cell: parent && parent.cell });
|
|
2392
|
-
continue;
|
|
2393
|
-
}
|
|
2394
|
-
if (closing) {
|
|
2395
|
-
open.close(name);
|
|
2396
|
-
continue;
|
|
2397
|
-
}
|
|
2398
2405
|
const end = index.tagEnd(token.index);
|
|
2399
2406
|
if (end === -1) break;
|
|
2400
2407
|
const tag = { name, narrow: undefined, cell: parent && parent.cell };
|
|
@@ -2424,6 +2431,120 @@ function _gridCellWidthRules(source) {
|
|
|
2424
2431
|
return findings;
|
|
2425
2432
|
}
|
|
2426
2433
|
|
|
2434
|
+
// sc-16682 — two sibling patterns a production build's widgets shipped.
|
|
2435
|
+
//
|
|
2436
|
+
// An action beside an <EmptyState> sits outside its panel; EmptyState takes
|
|
2437
|
+
// its action as `children`. Flagged when a Button or Pressable is the next
|
|
2438
|
+
// element after an EmptyState, or the first child of the View that is.
|
|
2439
|
+
//
|
|
2440
|
+
// Field labels in two styles: one field given the SDK `label`, another
|
|
2441
|
+
// labelled by a <Text> drawn just before it, so the two labels render in
|
|
2442
|
+
// different type. Only a Text that is the control's previous sibling counts
|
|
2443
|
+
// as its label, which keeps a heading above a whole form out of it.
|
|
2444
|
+
const _EMPTY_STATE_ACTION_TAGS = new Set(["Button", "Pressable"]);
|
|
2445
|
+
const _SELF_LABELLED_FIELD_TAGS = new Set([
|
|
2446
|
+
"TextField",
|
|
2447
|
+
"Select",
|
|
2448
|
+
"RadioGroup",
|
|
2449
|
+
"PeoplePicker",
|
|
2450
|
+
"FileUpload",
|
|
2451
|
+
"FormField",
|
|
2452
|
+
]);
|
|
2453
|
+
const _LABELLABLE_CONTROL_TAGS = new Set([
|
|
2454
|
+
..._SELF_LABELLED_FIELD_TAGS,
|
|
2455
|
+
"TextInput",
|
|
2456
|
+
"ChipGroup",
|
|
2457
|
+
"DateTimePicker",
|
|
2458
|
+
]);
|
|
2459
|
+
const _LABEL_ATTR_RE = /(?:^|\s)label\s*=/;
|
|
2460
|
+
|
|
2461
|
+
function _siblingRules(source) {
|
|
2462
|
+
if (!source.includes("<EmptyState") && !source.includes("label")) return [];
|
|
2463
|
+
const structure = _stripNonCode(source);
|
|
2464
|
+
const index = _jsxScanIndex(structure);
|
|
2465
|
+
const lineAt = _lineCounter(structure);
|
|
2466
|
+
const sourceLines = source.split(/\r?\n/);
|
|
2467
|
+
const findings = [];
|
|
2468
|
+
const report = (rule, at, label) => {
|
|
2469
|
+
const line = lineAt(at);
|
|
2470
|
+
findings.push({
|
|
2471
|
+
rule,
|
|
2472
|
+
severity: "warning",
|
|
2473
|
+
label,
|
|
2474
|
+
line,
|
|
2475
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
2476
|
+
});
|
|
2477
|
+
};
|
|
2478
|
+
// Not when the two are alternatives (`empty ? <EmptyState /> : <Button />`)
|
|
2479
|
+
// or sit in separate expressions (`{a && <EmptyState />}{b && <Button />}`).
|
|
2480
|
+
const renderedTogether = (emptyState, at) => {
|
|
2481
|
+
let depth = 0;
|
|
2482
|
+
for (let i = emptyState.at; i < at; i++) {
|
|
2483
|
+
const ch = structure[i];
|
|
2484
|
+
if (ch === "{") depth++;
|
|
2485
|
+
else if (ch === "}" && --depth < 0) return false;
|
|
2486
|
+
else if (ch === ":" && depth === 0) return false;
|
|
2487
|
+
}
|
|
2488
|
+
return true;
|
|
2489
|
+
};
|
|
2490
|
+
const afterEmptyState = (tag) =>
|
|
2491
|
+
tag && tag.name === "EmptyState" ? tag : null;
|
|
2492
|
+
let sdkLabelled = null;
|
|
2493
|
+
let ownLabelled = null;
|
|
2494
|
+
const open = _openTagStack();
|
|
2495
|
+
_JSX_TOKEN_RE.lastIndex = 0;
|
|
2496
|
+
let token;
|
|
2497
|
+
const fragment = (at) => ({ name: "", at: at.index, before: null, last: null });
|
|
2498
|
+
while ((token = _nextOpeningTag(structure, open, fragment))) {
|
|
2499
|
+
const name = token[2];
|
|
2500
|
+
// `useState<Item>` and `a<B` are not tags.
|
|
2501
|
+
if (/[\w$)\]]/.test(structure[token.index - 1] || "")) continue;
|
|
2502
|
+
const end = index.tagEnd(token.index);
|
|
2503
|
+
if (end === -1) break;
|
|
2504
|
+
const parent = open.top();
|
|
2505
|
+
const before = parent ? parent.last : null;
|
|
2506
|
+
const tag = { name, at: token.index, before, last: null };
|
|
2507
|
+
if (parent) parent.last = tag;
|
|
2508
|
+
if (_EMPTY_STATE_ACTION_TAGS.has(name) && parent) {
|
|
2509
|
+
const emptyState =
|
|
2510
|
+
afterEmptyState(before) ||
|
|
2511
|
+
(parent.name === "View" && !before ? afterEmptyState(parent.before) : null);
|
|
2512
|
+
if (emptyState && renderedTogether(emptyState, token.index)) {
|
|
2513
|
+
report(
|
|
2514
|
+
"empty-state-action-outside",
|
|
2515
|
+
token.index,
|
|
2516
|
+
`This <${name}> sits beside the <EmptyState>, outside its panel. ` +
|
|
2517
|
+
`EmptyState takes its action as children: ` +
|
|
2518
|
+
`<EmptyState title={…}><Button title={…} onPress={…} /></EmptyState> ` +
|
|
2519
|
+
`draws it inside the panel, under the message.`,
|
|
2520
|
+
);
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
if (_LABELLABLE_CONTROL_TAGS.has(name)) {
|
|
2524
|
+
const labelled = _LABEL_ATTR_RE.test(structure.slice(token.index + token[0].length, end));
|
|
2525
|
+
if (labelled && _SELF_LABELLED_FIELD_TAGS.has(name)) {
|
|
2526
|
+
if (!sdkLabelled) sdkLabelled = tag;
|
|
2527
|
+
} else if (!labelled && before && before.name === "Text") {
|
|
2528
|
+
if (!ownLabelled) ownLabelled = { tag, label: before };
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
if (!_selfClosing(structure, end)) open.push(tag);
|
|
2532
|
+
_JSX_TOKEN_RE.lastIndex = end + 1;
|
|
2533
|
+
}
|
|
2534
|
+
if (sdkLabelled && ownLabelled) {
|
|
2535
|
+
report(
|
|
2536
|
+
"field-label-styles-mixed",
|
|
2537
|
+
ownLabelled.label.at,
|
|
2538
|
+
`This <Text> labels the <${ownLabelled.tag.name}> after it, while ` +
|
|
2539
|
+
`line ${lineAt(sdkLabelled.at)} gives <${sdkLabelled.name}> the ` +
|
|
2540
|
+
`SDK label, so the form shows labels in two styles. Label every ` +
|
|
2541
|
+
`field one way: the label prop, or <FormField label> round a ` +
|
|
2542
|
+
`control that has none.`,
|
|
2543
|
+
);
|
|
2544
|
+
}
|
|
2545
|
+
return findings;
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2427
2548
|
// sc-4913 — a measured frame INCLUDES the element's own padding.
|
|
2428
2549
|
//
|
|
2429
2550
|
// `onLayout` reports the frame width, and padding sits inside that frame. A
|
|
@@ -3259,6 +3380,8 @@ export function lintSource(source, options) {
|
|
|
3259
3380
|
findings.push(..._fieldInBorderedRowRules(source));
|
|
3260
3381
|
// sc-15754 — a Grid cell under 200px holding more than one Text is refused.
|
|
3261
3382
|
findings.push(..._gridCellWidthRules(source));
|
|
3383
|
+
// sc-16682 — soft warnings: an action beside an EmptyState, mixed field labels.
|
|
3384
|
+
findings.push(..._siblingRules(source));
|
|
3262
3385
|
// sc-4913 — soft warning: a measured width that includes the widget's own
|
|
3263
3386
|
// padding wraps the last grid column into an empty one.
|
|
3264
3387
|
findings.push(..._measuredPaddingRules(source));
|
package/dist/webbundle.js
CHANGED
|
@@ -40,7 +40,7 @@ export async function loadEsbuild() {
|
|
|
40
40
|
return await import("esbuild");
|
|
41
41
|
} catch {
|
|
42
42
|
throw new Error(
|
|
43
|
-
"Bundling a widget's web entry needs
|
|
43
|
+
"Bundling a widget's web entry needs `esbuild`, an optional peer of the SDK.\n" +
|
|
44
44
|
"Install it in your widget project:\n" +
|
|
45
45
|
" npm install --save-dev esbuild",
|
|
46
46
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.313.0",
|
|
4
4
|
"description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
|
|
5
5
|
"homepage": "https://github.com/Colix-AB/AppStudio",
|
|
6
6
|
"type": "module",
|
|
@@ -77,7 +77,9 @@
|
|
|
77
77
|
"react-native": "*",
|
|
78
78
|
"react-dom": ">=18.0.0",
|
|
79
79
|
"react-native-web": ">=0.19.0",
|
|
80
|
-
"react-native-webview": ">=13.7.0"
|
|
80
|
+
"react-native-webview": ">=13.7.0",
|
|
81
|
+
"esbuild": "^0.28.0",
|
|
82
|
+
"sucrase": "^3.35.0"
|
|
81
83
|
},
|
|
82
84
|
"peerDependenciesMeta": {
|
|
83
85
|
"react": {
|
|
@@ -94,12 +96,14 @@
|
|
|
94
96
|
},
|
|
95
97
|
"react-native-webview": {
|
|
96
98
|
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"esbuild": {
|
|
101
|
+
"optional": true
|
|
102
|
+
},
|
|
103
|
+
"sucrase": {
|
|
104
|
+
"optional": true
|
|
97
105
|
}
|
|
98
106
|
},
|
|
99
|
-
"optionalDependencies": {
|
|
100
|
-
"esbuild": "^0.28.0",
|
|
101
|
-
"sucrase": "^3.35.0"
|
|
102
|
-
},
|
|
103
107
|
"keywords": [
|
|
104
108
|
"appstudio",
|
|
105
109
|
"widget",
|
|
@@ -108,6 +112,8 @@
|
|
|
108
112
|
],
|
|
109
113
|
"license": "MIT",
|
|
110
114
|
"devDependencies": {
|
|
111
|
-
"@babel/parser": "^7.29.7"
|
|
115
|
+
"@babel/parser": "^7.29.7",
|
|
116
|
+
"esbuild": "^0.28.0",
|
|
117
|
+
"sucrase": "^3.35.0"
|
|
112
118
|
}
|
|
113
119
|
}
|
package/src/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
|
{
|
|
@@ -5336,18 +5336,6 @@ function normaliseCurrencyCode(value) {
|
|
|
5336
5336
|
return code || CHARGE_CURRENCY;
|
|
5337
5337
|
}
|
|
5338
5338
|
|
|
5339
|
-
/**
|
|
5340
|
-
* `formatMoneyIn("SEK", 45000)` → `"450,00 kr"`.
|
|
5341
|
-
*
|
|
5342
|
-
* Takes MINOR units — the same unit `requestPayment` charges in — so there is no
|
|
5343
|
-
* conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
|
|
5344
|
-
* rather than `Intl.NumberFormat`, which does not produce identical output in
|
|
5345
|
-
* the exported Expo app and react-native-web; this string sits beside the amount
|
|
5346
|
-
* the buyer is actually charged, so the two hosts must agree exactly.
|
|
5347
|
-
*
|
|
5348
|
-
* A non-finite amount renders as zero rather than "NaN": a price whose data has
|
|
5349
|
-
* not loaded should read as an amount, never as a broken string in a checkout.
|
|
5350
|
-
*/
|
|
5351
5339
|
/**
|
|
5352
5340
|
* sc-5717 — value equality for a stored widget-route value: is this key still
|
|
5353
5341
|
* at the default its widget declared?
|
|
@@ -5363,7 +5351,22 @@ function sameWidgetRouteValue(a, b) {
|
|
|
5363
5351
|
}
|
|
5364
5352
|
return Object.is(a, b);
|
|
5365
5353
|
}
|
|
5366
|
-
|
|
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) {
|
|
5367
5370
|
const code = normaliseCurrencyCode(currency);
|
|
5368
5371
|
const fmt = CURRENCY_FORMATS[code] || {
|
|
5369
5372
|
...CURRENCY_FORMAT_FALLBACK,
|
|
@@ -5376,7 +5379,9 @@ function formatMoneyIn(currency, minorUnits) {
|
|
|
5376
5379
|
const whole = fmt.decimals > 0 ? digits.slice(0, -fmt.decimals) : digits;
|
|
5377
5380
|
const cents = fmt.decimals > 0 ? digits.slice(-fmt.decimals) : "";
|
|
5378
5381
|
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, fmt.groupSeparator);
|
|
5379
|
-
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;
|
|
5380
5385
|
const gap = fmt.space ? " " : "";
|
|
5381
5386
|
const withSymbol =
|
|
5382
5387
|
fmt.position === "before"
|
|
@@ -6945,7 +6950,9 @@ const CONTRACT = deepFreeze({
|
|
|
6945
6950
|
// holding any of the values. At most 100; no `valueMode` applies.
|
|
6946
6951
|
// 1.253.0: fix (sc-16577) — `react-native-safe-area-context` is host-resolved,
|
|
6947
6952
|
// so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
|
|
6948
|
-
|
|
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",
|
|
6949
6956
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6950
6957
|
hooks: HOOKS,
|
|
6951
6958
|
primitives: PRIMITIVES,
|
|
@@ -7297,6 +7304,82 @@ function deriveSurfaceTokens(backgroundColor) {
|
|
|
7297
7304
|
};
|
|
7298
7305
|
}
|
|
7299
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
|
+
|
|
7300
7383
|
// sc-8370: WCAG 1.4.3 for text, 1.4.11 for a control's boundary.
|
|
7301
7384
|
const INK_CONTRAST = Object.freeze({ text: 4.5, boundary: 3 });
|
|
7302
7385
|
|
|
@@ -7450,6 +7533,9 @@ export {
|
|
|
7450
7533
|
deriveAccentTints,
|
|
7451
7534
|
deriveStatusColors,
|
|
7452
7535
|
deriveSurfaceTokens,
|
|
7536
|
+
themeSurfaceTokens,
|
|
7537
|
+
deriveLightSurfaceColors,
|
|
7538
|
+
THEME_SURFACE_COLOR_KEYS,
|
|
7453
7539
|
inkForBackdrop,
|
|
7454
7540
|
INK_CONTRAST,
|
|
7455
7541
|
gradientAngleToVector,
|
package/src/webbundle.js
CHANGED
|
@@ -40,7 +40,7 @@ export async function loadEsbuild() {
|
|
|
40
40
|
return await import("esbuild");
|
|
41
41
|
} catch {
|
|
42
42
|
throw new Error(
|
|
43
|
-
"Bundling a widget's web entry needs
|
|
43
|
+
"Bundling a widget's web entry needs `esbuild`, an optional peer of the SDK.\n" +
|
|
44
44
|
"Install it in your widget project:\n" +
|
|
45
45
|
" npm install --save-dev esbuild",
|
|
46
46
|
);
|