@colixsystems/widget-sdk 0.127.0 → 0.129.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 +34 -2
- package/dist/contract.cjs +57 -5
- package/dist/contract.js +57 -5
- package/dist/hooks.js +157 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.js +2 -0
- package/dist/index.native.js +2 -0
- package/dist/linter.cjs +34 -0
- package/dist/linter.js +58 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -70,7 +70,37 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
70
70
|
|
|
71
71
|
## Status
|
|
72
72
|
|
|
73
|
-
`v0.
|
|
73
|
+
`v0.129.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**.
|
|
74
|
+
|
|
75
|
+
### What's new in 0.129.0 (contract 1.100.0)
|
|
76
|
+
|
|
77
|
+
**Widgets can READ a barcode now — `useBarcodeScanner()` (sc-7228).** A widget could already *generate* a QR code (`react-native-qrcode-svg`) but never read one, so the whole class of apps that starts by pointing a phone at a label — inventory counts, asset check-in/out, warehouse picking, ticket scanning, scan-on-delivery — had no way in.
|
|
78
|
+
|
|
79
|
+
```jsx
|
|
80
|
+
import { useBarcodeScanner, BarcodeError } from "@colixsystems/widget-sdk";
|
|
81
|
+
|
|
82
|
+
const { result, scanning, supported, scan, reset } = useBarcodeScanner();
|
|
83
|
+
const hit = await scan(); // { value, format } | null
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`scan()` is **imperative** — call it from a tap, because both hosts gate the camera permission prompt on a gesture. It resolves the first code decoded, resolves `null` when the user dismisses (a dismissal is NOT an error), and rejects a `BarcodeError` with `.code` of `PERMISSION_DENIED | UNSUPPORTED | INTERNAL`. `format` is a lowercase symbology name (`qr_code`, `code_128`, `ean_13`, …) and is a **hint**: the two hosts detect different sets, so never branch on it for correctness.
|
|
87
|
+
|
|
88
|
+
It is deliberately **one-shot** rather than a start/stop subscription — to read several codes, call `scan()` again. There is no loop to leave running and no camera to forget to release.
|
|
89
|
+
|
|
90
|
+
**Gate the button on `supported`, and always keep a manual-entry path.** `BarcodeDetector` is Chromium-only today, so the web Player reports `supported: false` in Safari and Firefox. That is a genuine browser gap, not a missing feature, so a scanner must never be the only way to enter a code:
|
|
91
|
+
|
|
92
|
+
```jsx
|
|
93
|
+
<TextInput value={code} onChangeText={setCode} />
|
|
94
|
+
{supported ? <Pressable onPress={scan}><Text>Scan</Text></Pressable> : null}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Host-brokered, not a vetted import.** Like the camera and speech-to-text, your widget never imports the native module: `expo-camera` is pinned by the Expo export only, so a widget that does not scan gains no native dependency and nothing new enters widget bundles.
|
|
98
|
+
|
|
99
|
+
### What's new in 0.128.0 (contract 1.99.0 — unchanged)
|
|
100
|
+
|
|
101
|
+
**New linter rule `flex-basis-percent` — a percentage `flexBasis` sizes the HEIGHT in a column (sc-7274).** A generated form carried one shared field helper, `style={{ flexGrow: 1, flexBasis: wide ? "100%" : 220 }}`, used both as a row cell (where the number is exactly right) and as a full-width field stacked in a column (where the percentage is a trap). `flex-basis` sizes the **main** axis, and a column's main axis is the **height**: each wide field was asking for its parent's entire height. It rendered correctly in the builder canvas — an auto-height ancestor leaves the percentage indefinite, so it degrades to `content` — and broke the moment the page shipped, because a Grid cell stretches its child on the web Player and made that height definite. Measured on the published page: the group was 633px tall and every wide field inside it was **also** 633px, so with `View`'s default `flex-shrink: 0` they could not shrink back and overflowed 633px and 1266px down, painting a blank band mid-form and three fields on top of the section below and the submit row.
|
|
102
|
+
|
|
103
|
+
- **`flex-basis-percent` (severity `warning`, non-blocking).** A literal percentage `flexBasis` — `"100%"`, `"50%"`, and the responsive ternary `flexBasis: stacked ? "100%" : CARD_WIDE` — is flagged. Author fix: **`width: "100%"`**, which is the direction-agnostic way to say "full width": it fills the row in a column parent AND takes its own line in a wrap row, so nothing is lost by switching. Keep a **number** (`flexBasis: 220`) where you mean a wrap threshold. It is a **warning**, not an error, because in a ROW parent the percentage IS correct and an AST-free scan cannot see the parent's `flexDirection` — the offending style usually lives in a shared cell helper far from its parent. Scope is the literal inline form; a basis threaded through a variable is beyond the scan, and the designer skill's form guidance remains the first guard. Comments are not scanned, so documenting the anti-pattern is safe.
|
|
74
104
|
|
|
75
105
|
### What's new in 0.127.0 (contract 1.99.0)
|
|
76
106
|
|
|
@@ -1336,7 +1366,7 @@ A widget that works but looks unfinished is only half done. `useTheme()` is the
|
|
|
1336
1366
|
- **Spend one gradient.** `<Gradient colors={[theme.colors.primary, theme.colors.primaryStrong]} angle={160} style={…}>` is a `View` that paints a gradient behind its children, so it replaces the `View` you'd otherwise give a flat `backgroundColor`. `angle` is CSS degrees (0 = to top, 90 = to right, default 180); text on it uses `colors.onPrimary`. Exactly **one** per widget — on the focal element — and never behind body text. Both hosts render it identically (web paints CSS, native uses `expo-linear-gradient`), so there is no per-platform branching to write; don't import `expo-linear-gradient` yourself and don't write a `backgroundImage` string.
|
|
1337
1367
|
- **Answer the touch.** Every tappable card, row and list entry lifts while the pointer is over it (web) or it is pressed (touch). One declaration does both: give the Pressable a style FUNCTION and spread `pressableLift` — `<Pressable onPress={open} style={(state) => [styles.card, ...pressableLift(state)]}>`. The lift is a -2px nudge plus one elevation step from `theme.interaction`, with the web transition built in. Never hand-write hover logic or your own pressed shadows, and never fake feedback with `opacity` — a dimmed surface reads as disabling itself.
|
|
1338
1368
|
- **Size to your container — measure it, don't stretch into it.** The same widget sits in a full-width desktop section (~1400px), a half-width grid cell (~700px) and a phone (~360px), so layout built only from `flex: 1` stretches to fill whatever it is handed — a month calendar ends up with 200px day cells and swallows the page. Measure your own width with `onLayout={(e) => setWidth(e.nativeEvent.layout.width)}` on the root `View` (a React Native primitive, so it behaves identically on both hosts), render nothing size-dependent while `width === 0`, and compute every threshold from the measured value: a widget gets no declared breakpoint prop, but it can always measure. **Cap a repeating cell** rather than giving a grid `flex: 1` — `const cell = Math.max(32, Math.min(Math.floor((usable - gap * (columns - 1)) / columns), 64));`, with a calendar day cell topping out at 56–72px on `aspectRatio: 1`, and the grid given its exact computed width plus `alignSelf: 'center'` when the cap leaves slack. **Split two co-equal surfaces above ~720px measured width** (`flexDirection: width >= 720 ? 'row' : 'column'`, each half `{ flex: 1, minWidth: 0 }`) — a picker beside the form it feeds on a wide canvas, stacked in reading order below it. Never hardcode a width, never put `flex: 1` / `height: '100%'` on a content widget's root, and don't read the screen with `Dimensions` — the screen is not the widget.
|
|
1339
|
-
- **Compose forms — pair fields into rows, don't stack one per row.** Put short, related fields side by side (first + last name, city + postal code, expiry + CVC): a row of `{ flexDirection: 'row', flexWrap: 'wrap', gap: theme.spacing.md }` with each field cell `{ flexGrow: 1, flexBasis: 160 }` splits the width on a wide card and wraps to stacked on a narrow phone — the right recipe for field pairs because it needs no measurement (a fixed-width column overflows a phone; when a layout needs a real column count instead of wrapping, measure your width as above). Keep wide fields (email, address, notes) full-width
|
|
1369
|
+
- **Compose forms — pair fields into rows, don't stack one per row.** Put short, related fields side by side (first + last name, city + postal code, expiry + CVC): a row of `{ flexDirection: 'row', flexWrap: 'wrap', gap: theme.spacing.md }` with each field cell `{ flexGrow: 1, flexBasis: 160 }` splits the width on a wide card and wraps to stacked on a narrow phone — the right recipe for field pairs because it needs no measurement (a fixed-width column overflows a phone; when a layout needs a real column count instead of wrapping, measure your width as above). Keep wide fields (email, address, notes) full-width with `width: '100%'` — NEVER `flexBasis: '100%'`, which sizes the main axis and therefore claims the parent's whole HEIGHT in a column (sc-7274) — cap it at two–three per row, group a long form into labelled sections, and label every input above it (not placeholder-only). Give a `multiline` field BOTH a floor and a ceiling (`{ minHeight: 150, maxHeight: 260 }`) so a long value scrolls inside the box instead of growing past its card, and keep the Save / Cancel row in normal flow below the fields, never positioned over them.
|
|
1340
1370
|
- **Respond to touch.** Give every `Pressable` the lift via the function-style `style={(state) => [base, ...pressableLift(state)]}` — see "Answer the touch" above. Never dim with `opacity`, which reads as the surface disabling itself.
|
|
1341
1371
|
- **Drag and drop — show what is being dragged.** A drag where the item stays put reads as broken. Three things change the moment a drag starts: the **drag proxy** (the item lifts and follows the finger — `...theme.elevation.lg`, `{ scale: 1.03 }`, `opacity: 0.9`; for a tall or full-width item drag a compact `primarySoft` pill with its icon + one line of label instead), the **source placeholder** (the vacated slot keeps its height as a quiet `colors.surfaceMuted` block so the list doesn't collapse), and the **drop target** (one slot at a time highlighted with `primarySoft` or a 2px `colors.primary` border). Always animate the release — settle into the new slot, or `Animated.spring(pan, { toValue: { x: 0, y: 0 }, useNativeDriver: false })` back to the origin on cancel. Build it with `Animated` + `PanResponder` from `react-native` (the only mechanism that behaves identically on both hosts) — never HTML5 drag events (`draggable` / `onDragStart` / `dataTransfer` are web-only, and `document` / `window` are banned) — and start the drag from a `GripVertical` grip handle whenever the row is also tappable or sits in a `ScrollView`.
|
|
1342
1372
|
- **Use icons for clarity.** Pair a `lucide-react-native` icon with its label at a consistent size, coloured from the theme. The label never repeats the icon as a character — with a `Plus` icon the button says "Add item", never "+ Add item" (that renders a doubled plus).
|
|
@@ -1598,6 +1628,8 @@ Two rules keep a widget's look reachable from the Studio (sc-6455). `no-hardcode
|
|
|
1598
1628
|
|
|
1599
1629
|
Pass `--manifest` to enable `style-field-unread` — it needs the manifest, and it needs every source at once so a split-impl widget's per-host field reads are seen together.
|
|
1600
1630
|
|
|
1631
|
+
`flex-basis-percent` flags a literal percentage `flexBasis` (sc-7274) — `"100%"`, `"50%"`, or the ternary a responsive cell writes. `flex-basis` sizes the MAIN axis, so in a column parent it asks for the parent's HEIGHT: under an ancestor that makes that height definite (a Grid cell stretches its child on the web Player) the child fills the container and, since a `View` never shrinks, overflows over everything below it. Say full-width with `width: "100%"` — correct in a column AND in a wrap row — and keep a NUMBER for a wrap threshold. A warning, because the percentage is right in a row and a text scan cannot see the parent.
|
|
1632
|
+
|
|
1601
1633
|
`no-html-in-content` flags an HTML tag inside a **string** (sc-6970) — `"<strong>"`, `"<br>"`, `"<p>…</p>"`. There is no HTML renderer on either host, so the tag reaches the reader as literal text; author formatted text with `<MarkdownInput>` and render it with `<RichText>` instead. Only string and template content is scanned, so your own `<View>` / `<Text>` JSX can never trip it. A warning for a human author, blocking for the AI widget agent.
|
|
1602
1634
|
|
|
1603
1635
|
## Local dev loop (`appstudio-widget dev`)
|
package/dist/contract.cjs
CHANGED
|
@@ -1670,6 +1670,38 @@ const HOOKS = [
|
|
|
1670
1670
|
requiredContextSlice: [],
|
|
1671
1671
|
scopes: null,
|
|
1672
1672
|
},
|
|
1673
|
+
// sc-7228 — host-brokered barcode / QR scanning. Optional slice; the hook
|
|
1674
|
+
// reports supported:false rather than throwing at render.
|
|
1675
|
+
{
|
|
1676
|
+
name: "useBarcodeScanner",
|
|
1677
|
+
signature: "useBarcodeScanner(options?)",
|
|
1678
|
+
description:
|
|
1679
|
+
"Read a barcode or QR code with the device camera. Returns { result, scanning, error, supported, scan, reset }. " +
|
|
1680
|
+
"Scanning is IMPERATIVE — call scan() from a user gesture (a tap); the browser and the mobile OS gate the camera " +
|
|
1681
|
+
"permission prompt on a gesture, so it NEVER opens on mount. It resolves { value, format } for the FIRST code " +
|
|
1682
|
+
"decoded, or NULL when the user dismisses the scanner — dismissal is the common case and is deliberately NOT an " +
|
|
1683
|
+
"error, so no try/catch is needed on the happy path. It rejects with a BarcodeError whose .code is one of " +
|
|
1684
|
+
"PERMISSION_DENIED | UNSUPPORTED | INTERNAL. `value` is the decoded text; `format` is a lowercase symbology name " +
|
|
1685
|
+
"(qr_code, code_128, ean_13, …) — treat it as a hint, not a promise, because the two hosts detect different sets. " +
|
|
1686
|
+
"It is deliberately ONE-SHOT rather than a start/stop subscription: to scan several codes, call scan() again. " +
|
|
1687
|
+
"reset() clears the last result and error. ALWAYS check `supported` before rendering a scan button and give the " +
|
|
1688
|
+
"widget a manual-entry path — the web Player reports false wherever the browser has no BarcodeDetector (Safari and " +
|
|
1689
|
+
"Firefox today), which is a real browser gap, not a missing feature. options: { formats } is a HINT narrowing the " +
|
|
1690
|
+
"symbologies to look for. The Expo export scans via expo-camera; the web Player via BarcodeDetector over the same " +
|
|
1691
|
+
"getUserMedia preview useCamera() uses. The camera is released on every exit path, including a dismissal.",
|
|
1692
|
+
returnShape: {
|
|
1693
|
+
result: "{ value, format } | null",
|
|
1694
|
+
scanning: "boolean",
|
|
1695
|
+
error: "BarcodeError | null",
|
|
1696
|
+
supported:
|
|
1697
|
+
"boolean // GATE THE BUTTON ON THIS: false where the browser has no BarcodeDetector",
|
|
1698
|
+
scan:
|
|
1699
|
+
"() => Promise<{ value, format } | null> // null if dismissed; rejects with BarcodeError",
|
|
1700
|
+
reset: "() => void // clear the last result + error",
|
|
1701
|
+
},
|
|
1702
|
+
requiredContextSlice: [],
|
|
1703
|
+
scopes: null,
|
|
1704
|
+
},
|
|
1673
1705
|
// sc-7193 — host-brokered image editing. Optional slice; the hook reports
|
|
1674
1706
|
// supported:false rather than throwing at render.
|
|
1675
1707
|
{
|
|
@@ -2343,10 +2375,11 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
2343
2375
|
"subscribeBackgroundWatchState(cb) -> unsubscribe }, " +
|
|
2344
2376
|
"speech: { isSupported() -> boolean, start(options, { onResult, onError, onEnd }) -> Promise<{ stop(), abort() }> }, " +
|
|
2345
2377
|
"camera: { isSupported() -> boolean, capture(options?) -> Promise<asset | null>, pick(options?) -> Promise<asset | null> }, " +
|
|
2346
|
-
"imageEditor: { isSupported() -> boolean, edit(uri, actions, options?) -> Promise<asset> }
|
|
2347
|
-
"
|
|
2348
|
-
"
|
|
2349
|
-
"
|
|
2378
|
+
"imageEditor: { isSupported() -> boolean, edit(uri, actions, options?) -> Promise<asset> }, " +
|
|
2379
|
+
"barcode: { isSupported() -> boolean, scan(options?) -> Promise<{ value, format } | null> } }. " +
|
|
2380
|
+
"Backs useGeolocation(), useSpeechToText(), useCamera(), useImageEditor() and useBarcodeScanner(). The web Player brokers them via " +
|
|
2381
|
+
"navigator.geolocation, window.SpeechRecognition, a getUserMedia camera preview, a host-side canvas and BarcodeDetector; the Expo export via " +
|
|
2382
|
+
"expo-location, expo-speech-recognition, expo-image-picker, expo-image-manipulator and expo-camera. " +
|
|
2350
2383
|
"imageEditor.edit applies resize / crop / rotate / flip in order and rejects with an ImageEditorError " +
|
|
2351
2384
|
"(.code UNSUPPORTED | INVALID_ACTION | DECODE_FAILED | ENCODE_FAILED | INTERNAL). " +
|
|
2352
2385
|
"getCurrentPosition rejects with a GeolocationError (.code PERMISSION_DENIED | UNAVAILABLE | TIMEOUT | UNSUPPORTED | INTERNAL). " +
|
|
@@ -2354,6 +2387,11 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
2354
2387
|
"its onError carries the Web Speech error vocabulary (not-allowed | no-speech | language-not-supported | network | aborted). " +
|
|
2355
2388
|
"camera.capture/pick resolve a normalised { uri, name, mimeType, width, height, size, file, release? } or NULL when the " +
|
|
2356
2389
|
"user dismisses the picker, and reject with a CameraError (.code PERMISSION_DENIED | UNSUPPORTED | INTERNAL). " +
|
|
2390
|
+
"barcode.scan resolves { value, format } for the first code decoded or NULL when the user dismisses, and rejects with a " +
|
|
2391
|
+
"BarcodeError (.code PERMISSION_DENIED | UNSUPPORTED | INTERNAL). Its formats hint and its format output BOTH speak " +
|
|
2392
|
+
"BarcodeDetector names (qr_code, code_128, ean_13, ...) on both hosts; the Expo export maps them to expo-camera own " +
|
|
2393
|
+
"vocabulary internally and DROPS a name it cannot map. isSupported() is false wherever the browser ships no " +
|
|
2394
|
+
"BarcodeDetector (Safari, Firefox), so a widget must always offer manual entry beside a scan button. " +
|
|
2357
2395
|
"sc-6450 — the geolocation background-watch members are NATIVE-ONLY and opt-in per app: the web Player and an export that " +
|
|
2358
2396
|
"did not opt in both report isBackgroundSupported() false, and the Expo export backs it with expo-location + " +
|
|
2359
2397
|
"expo-task-manager. subscribeBackgroundPositions and subscribeBackgroundWatchState are plain subscriptions — they start no " +
|
|
@@ -2367,6 +2405,7 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
2367
2405
|
speech: "object",
|
|
2368
2406
|
camera: "object",
|
|
2369
2407
|
imageEditor: "object",
|
|
2408
|
+
barcode: "object",
|
|
2370
2409
|
},
|
|
2371
2410
|
},
|
|
2372
2411
|
};
|
|
@@ -3768,7 +3807,20 @@ const CONTRACT = deepFreeze({
|
|
|
3768
3807
|
// reason date-fns is: an AI-agent widget is transpiled, never bundled, so
|
|
3769
3808
|
// its bare import must resolve at runtime on both hosts. No existing entry
|
|
3770
3809
|
// changed shape — minor bump on the pre-1.0 channel.
|
|
3771
|
-
|
|
3810
|
+
// 1.100.0: additive (sc-7228) — new `useBarcodeScanner()` hook + a `barcode`
|
|
3811
|
+
// member on the optional `device` host slice. Widgets could GENERATE a QR
|
|
3812
|
+
// code (react-native-qrcode-svg) but never READ one, so inventory counts,
|
|
3813
|
+
// asset check-in/out, ticket scanning and scan-on-delivery were
|
|
3814
|
+
// unbuildable. Host-brokered rather than a vetted import, the same call as
|
|
3815
|
+
// `camera` and `speech`: widgets never import the native module, so
|
|
3816
|
+
// `expo-camera` stays out of widget bundles and is pinned in the export
|
|
3817
|
+
// only. One-shot scan() modelled on useCamera().capture() rather than a
|
|
3818
|
+
// start/stop subscription — no second streaming lifecycle to keep in step.
|
|
3819
|
+
// NOT native-only: the web half is BarcodeDetector over the getUserMedia
|
|
3820
|
+
// preview useCamera already owns, so this is full parity wherever the
|
|
3821
|
+
// browser ships the API and a declared `supported:false` where it does not
|
|
3822
|
+
// (Safari, Firefox) — a genuine browser gap per CLAUDE.md §8.
|
|
3823
|
+
version: "1.100.0",
|
|
3772
3824
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
3773
3825
|
hooks: HOOKS,
|
|
3774
3826
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -1670,6 +1670,38 @@ const HOOKS = [
|
|
|
1670
1670
|
requiredContextSlice: [],
|
|
1671
1671
|
scopes: null,
|
|
1672
1672
|
},
|
|
1673
|
+
// sc-7228 — host-brokered barcode / QR scanning. Optional slice; the hook
|
|
1674
|
+
// reports supported:false rather than throwing at render.
|
|
1675
|
+
{
|
|
1676
|
+
name: "useBarcodeScanner",
|
|
1677
|
+
signature: "useBarcodeScanner(options?)",
|
|
1678
|
+
description:
|
|
1679
|
+
"Read a barcode or QR code with the device camera. Returns { result, scanning, error, supported, scan, reset }. " +
|
|
1680
|
+
"Scanning is IMPERATIVE — call scan() from a user gesture (a tap); the browser and the mobile OS gate the camera " +
|
|
1681
|
+
"permission prompt on a gesture, so it NEVER opens on mount. It resolves { value, format } for the FIRST code " +
|
|
1682
|
+
"decoded, or NULL when the user dismisses the scanner — dismissal is the common case and is deliberately NOT an " +
|
|
1683
|
+
"error, so no try/catch is needed on the happy path. It rejects with a BarcodeError whose .code is one of " +
|
|
1684
|
+
"PERMISSION_DENIED | UNSUPPORTED | INTERNAL. `value` is the decoded text; `format` is a lowercase symbology name " +
|
|
1685
|
+
"(qr_code, code_128, ean_13, …) — treat it as a hint, not a promise, because the two hosts detect different sets. " +
|
|
1686
|
+
"It is deliberately ONE-SHOT rather than a start/stop subscription: to scan several codes, call scan() again. " +
|
|
1687
|
+
"reset() clears the last result and error. ALWAYS check `supported` before rendering a scan button and give the " +
|
|
1688
|
+
"widget a manual-entry path — the web Player reports false wherever the browser has no BarcodeDetector (Safari and " +
|
|
1689
|
+
"Firefox today), which is a real browser gap, not a missing feature. options: { formats } is a HINT narrowing the " +
|
|
1690
|
+
"symbologies to look for. The Expo export scans via expo-camera; the web Player via BarcodeDetector over the same " +
|
|
1691
|
+
"getUserMedia preview useCamera() uses. The camera is released on every exit path, including a dismissal.",
|
|
1692
|
+
returnShape: {
|
|
1693
|
+
result: "{ value, format } | null",
|
|
1694
|
+
scanning: "boolean",
|
|
1695
|
+
error: "BarcodeError | null",
|
|
1696
|
+
supported:
|
|
1697
|
+
"boolean // GATE THE BUTTON ON THIS: false where the browser has no BarcodeDetector",
|
|
1698
|
+
scan:
|
|
1699
|
+
"() => Promise<{ value, format } | null> // null if dismissed; rejects with BarcodeError",
|
|
1700
|
+
reset: "() => void // clear the last result + error",
|
|
1701
|
+
},
|
|
1702
|
+
requiredContextSlice: [],
|
|
1703
|
+
scopes: null,
|
|
1704
|
+
},
|
|
1673
1705
|
// sc-7193 — host-brokered image editing. Optional slice; the hook reports
|
|
1674
1706
|
// supported:false rather than throwing at render.
|
|
1675
1707
|
{
|
|
@@ -2343,10 +2375,11 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
2343
2375
|
"subscribeBackgroundWatchState(cb) -> unsubscribe }, " +
|
|
2344
2376
|
"speech: { isSupported() -> boolean, start(options, { onResult, onError, onEnd }) -> Promise<{ stop(), abort() }> }, " +
|
|
2345
2377
|
"camera: { isSupported() -> boolean, capture(options?) -> Promise<asset | null>, pick(options?) -> Promise<asset | null> }, " +
|
|
2346
|
-
"imageEditor: { isSupported() -> boolean, edit(uri, actions, options?) -> Promise<asset> }
|
|
2347
|
-
"
|
|
2348
|
-
"
|
|
2349
|
-
"
|
|
2378
|
+
"imageEditor: { isSupported() -> boolean, edit(uri, actions, options?) -> Promise<asset> }, " +
|
|
2379
|
+
"barcode: { isSupported() -> boolean, scan(options?) -> Promise<{ value, format } | null> } }. " +
|
|
2380
|
+
"Backs useGeolocation(), useSpeechToText(), useCamera(), useImageEditor() and useBarcodeScanner(). The web Player brokers them via " +
|
|
2381
|
+
"navigator.geolocation, window.SpeechRecognition, a getUserMedia camera preview, a host-side canvas and BarcodeDetector; the Expo export via " +
|
|
2382
|
+
"expo-location, expo-speech-recognition, expo-image-picker, expo-image-manipulator and expo-camera. " +
|
|
2350
2383
|
"imageEditor.edit applies resize / crop / rotate / flip in order and rejects with an ImageEditorError " +
|
|
2351
2384
|
"(.code UNSUPPORTED | INVALID_ACTION | DECODE_FAILED | ENCODE_FAILED | INTERNAL). " +
|
|
2352
2385
|
"getCurrentPosition rejects with a GeolocationError (.code PERMISSION_DENIED | UNAVAILABLE | TIMEOUT | UNSUPPORTED | INTERNAL). " +
|
|
@@ -2354,6 +2387,11 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
2354
2387
|
"its onError carries the Web Speech error vocabulary (not-allowed | no-speech | language-not-supported | network | aborted). " +
|
|
2355
2388
|
"camera.capture/pick resolve a normalised { uri, name, mimeType, width, height, size, file, release? } or NULL when the " +
|
|
2356
2389
|
"user dismisses the picker, and reject with a CameraError (.code PERMISSION_DENIED | UNSUPPORTED | INTERNAL). " +
|
|
2390
|
+
"barcode.scan resolves { value, format } for the first code decoded or NULL when the user dismisses, and rejects with a " +
|
|
2391
|
+
"BarcodeError (.code PERMISSION_DENIED | UNSUPPORTED | INTERNAL). Its formats hint and its format output BOTH speak " +
|
|
2392
|
+
"BarcodeDetector names (qr_code, code_128, ean_13, ...) on both hosts; the Expo export maps them to expo-camera own " +
|
|
2393
|
+
"vocabulary internally and DROPS a name it cannot map. isSupported() is false wherever the browser ships no " +
|
|
2394
|
+
"BarcodeDetector (Safari, Firefox), so a widget must always offer manual entry beside a scan button. " +
|
|
2357
2395
|
"sc-6450 — the geolocation background-watch members are NATIVE-ONLY and opt-in per app: the web Player and an export that " +
|
|
2358
2396
|
"did not opt in both report isBackgroundSupported() false, and the Expo export backs it with expo-location + " +
|
|
2359
2397
|
"expo-task-manager. subscribeBackgroundPositions and subscribeBackgroundWatchState are plain subscriptions — they start no " +
|
|
@@ -2367,6 +2405,7 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
2367
2405
|
speech: "object",
|
|
2368
2406
|
camera: "object",
|
|
2369
2407
|
imageEditor: "object",
|
|
2408
|
+
barcode: "object",
|
|
2370
2409
|
},
|
|
2371
2410
|
},
|
|
2372
2411
|
};
|
|
@@ -3768,7 +3807,20 @@ const CONTRACT = deepFreeze({
|
|
|
3768
3807
|
// reason date-fns is: an AI-agent widget is transpiled, never bundled, so
|
|
3769
3808
|
// its bare import must resolve at runtime on both hosts. No existing entry
|
|
3770
3809
|
// changed shape — minor bump on the pre-1.0 channel.
|
|
3771
|
-
|
|
3810
|
+
// 1.100.0: additive (sc-7228) — new `useBarcodeScanner()` hook + a `barcode`
|
|
3811
|
+
// member on the optional `device` host slice. Widgets could GENERATE a QR
|
|
3812
|
+
// code (react-native-qrcode-svg) but never READ one, so inventory counts,
|
|
3813
|
+
// asset check-in/out, ticket scanning and scan-on-delivery were
|
|
3814
|
+
// unbuildable. Host-brokered rather than a vetted import, the same call as
|
|
3815
|
+
// `camera` and `speech`: widgets never import the native module, so
|
|
3816
|
+
// `expo-camera` stays out of widget bundles and is pinned in the export
|
|
3817
|
+
// only. One-shot scan() modelled on useCamera().capture() rather than a
|
|
3818
|
+
// start/stop subscription — no second streaming lifecycle to keep in step.
|
|
3819
|
+
// NOT native-only: the web half is BarcodeDetector over the getUserMedia
|
|
3820
|
+
// preview useCamera already owns, so this is full parity wherever the
|
|
3821
|
+
// browser ships the API and a declared `supported:false` where it does not
|
|
3822
|
+
// (Safari, Firefox) — a genuine browser gap per CLAUDE.md §8.
|
|
3823
|
+
version: "1.100.0",
|
|
3772
3824
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
3773
3825
|
hooks: HOOKS,
|
|
3774
3826
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -1589,6 +1589,163 @@ export function useCamera(options) {
|
|
|
1589
1589
|
return { asset, loading, error, supported, capture, pick, reset };
|
|
1590
1590
|
}
|
|
1591
1591
|
|
|
1592
|
+
/**
|
|
1593
|
+
* The symbology names the SDK speaks on BOTH hosts — BarcodeDetector's
|
|
1594
|
+
* vocabulary. Normalising here is what stops the hosts diverging on bad
|
|
1595
|
+
* input: the web detector THROWS on a name outside its enum while the native
|
|
1596
|
+
* scanner silently ignores one, so an unknown name would reject on web and
|
|
1597
|
+
* quietly scan everything on native.
|
|
1598
|
+
*/
|
|
1599
|
+
const BARCODE_FORMATS = Object.freeze([
|
|
1600
|
+
"aztec",
|
|
1601
|
+
"codabar",
|
|
1602
|
+
"code_128",
|
|
1603
|
+
"code_39",
|
|
1604
|
+
"code_93",
|
|
1605
|
+
"data_matrix",
|
|
1606
|
+
"ean_13",
|
|
1607
|
+
"ean_8",
|
|
1608
|
+
"itf",
|
|
1609
|
+
"pdf417",
|
|
1610
|
+
"qr_code",
|
|
1611
|
+
"upc_a",
|
|
1612
|
+
"upc_e",
|
|
1613
|
+
]);
|
|
1614
|
+
|
|
1615
|
+
/** Drop anything the hosts cannot both honour, so neither has to guess. */
|
|
1616
|
+
function normaliseBarcodeOptions(options) {
|
|
1617
|
+
const opts = options || {};
|
|
1618
|
+
if (!Array.isArray(opts.formats)) return opts;
|
|
1619
|
+
const formats = opts.formats
|
|
1620
|
+
.map((name) => String(name).toLowerCase())
|
|
1621
|
+
.filter((name) => BARCODE_FORMATS.includes(name));
|
|
1622
|
+
return { ...opts, formats };
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
/**
|
|
1626
|
+
* Structured error thrown by `useBarcodeScanner` callbacks.
|
|
1627
|
+
*
|
|
1628
|
+
* `code` is one of:
|
|
1629
|
+
* - "PERMISSION_DENIED" — the user (or OS) refused camera access.
|
|
1630
|
+
* - "UNSUPPORTED" — this host brokers no scanner (no BarcodeDetector).
|
|
1631
|
+
* - "INTERNAL" — anything else.
|
|
1632
|
+
*
|
|
1633
|
+
* A user dismissing the scanner is NOT an error — the promise resolves `null`.
|
|
1634
|
+
*/
|
|
1635
|
+
export class BarcodeError extends Error {
|
|
1636
|
+
constructor(code, message, opts) {
|
|
1637
|
+
super(message);
|
|
1638
|
+
this.name = "BarcodeError";
|
|
1639
|
+
this.code = code;
|
|
1640
|
+
if (opts && opts.cause) this.cause = opts.cause;
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
/** Coerce a thrown value into a BarcodeError with a stable code. */
|
|
1645
|
+
function toBarcodeError(err) {
|
|
1646
|
+
if (err instanceof BarcodeError) return err;
|
|
1647
|
+
const raw = err && err.code !== undefined ? err.code : null;
|
|
1648
|
+
let code = "INTERNAL";
|
|
1649
|
+
if (raw === "PERMISSION_DENIED") code = "PERMISSION_DENIED";
|
|
1650
|
+
else if (raw === "UNSUPPORTED") code = "UNSUPPORTED";
|
|
1651
|
+
const message =
|
|
1652
|
+
(err && typeof err.message === "string" && err.message) ||
|
|
1653
|
+
"Barcode scan failed";
|
|
1654
|
+
return new BarcodeError(code, message, { cause: err });
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
/**
|
|
1658
|
+
* Read a barcode or QR code with the device camera. Returns
|
|
1659
|
+
* `{ result, scanning, error, supported, scan, reset }`.
|
|
1660
|
+
*
|
|
1661
|
+
* Scanning is IMPERATIVE — call `scan()` from a user gesture. The OS and the
|
|
1662
|
+
* browser gate the camera permission prompt on a gesture, so the hook never
|
|
1663
|
+
* opens the camera on mount.
|
|
1664
|
+
*
|
|
1665
|
+
* `scan()` resolves `{ value, format }` for the first code decoded, or `null`
|
|
1666
|
+
* when the user dismisses the scanner — dismissal is the most common outcome
|
|
1667
|
+
* and is deliberately not an error, so widgets need no try/catch on the happy
|
|
1668
|
+
* path. It rejects with a `BarcodeError` for a genuine failure.
|
|
1669
|
+
*
|
|
1670
|
+
* One-shot by design: to read several codes, call `scan()` again. There is no
|
|
1671
|
+
* start/stop subscription to leave running.
|
|
1672
|
+
*
|
|
1673
|
+
* ALWAYS check `supported` before rendering a scan button, and give the widget
|
|
1674
|
+
* a manual-entry path: the web Player reports false wherever the browser ships
|
|
1675
|
+
* no `BarcodeDetector` (Safari and Firefox today). That is a real browser gap,
|
|
1676
|
+
* so a scanner must never be the only way to enter a code.
|
|
1677
|
+
*/
|
|
1678
|
+
export function useBarcodeScanner(options) {
|
|
1679
|
+
const ctx = useWidgetContextOrThrow("useBarcodeScanner");
|
|
1680
|
+
const [result, setResult] = useState(null);
|
|
1681
|
+
const [scanning, setScanning] = useState(false);
|
|
1682
|
+
const [error, setError] = useState(null);
|
|
1683
|
+
// `ctx` is a fresh identity every host render — hold the live client and
|
|
1684
|
+
// options in refs so the returned callbacks stay stable.
|
|
1685
|
+
const clientRef = useRef(ctx.device && ctx.device.barcode);
|
|
1686
|
+
clientRef.current = ctx.device && ctx.device.barcode;
|
|
1687
|
+
const optionsRef = useRef(options);
|
|
1688
|
+
optionsRef.current = options;
|
|
1689
|
+
const runRef = useRef(0);
|
|
1690
|
+
|
|
1691
|
+
const supported = Boolean(
|
|
1692
|
+
clientRef.current &&
|
|
1693
|
+
typeof clientRef.current.scan === "function" &&
|
|
1694
|
+
(typeof clientRef.current.isSupported !== "function" ||
|
|
1695
|
+
clientRef.current.isSupported()),
|
|
1696
|
+
);
|
|
1697
|
+
|
|
1698
|
+
// A scan open at unmount still resolves; bumping the run id discards it
|
|
1699
|
+
// instead of setting state on a widget that is gone.
|
|
1700
|
+
useEffect(
|
|
1701
|
+
() => () => {
|
|
1702
|
+
runRef.current += 1;
|
|
1703
|
+
},
|
|
1704
|
+
[],
|
|
1705
|
+
);
|
|
1706
|
+
|
|
1707
|
+
const reset = useCallback(() => {
|
|
1708
|
+
runRef.current += 1;
|
|
1709
|
+
setResult(null);
|
|
1710
|
+
setError(null);
|
|
1711
|
+
}, []);
|
|
1712
|
+
|
|
1713
|
+
const scan = useCallback(async () => {
|
|
1714
|
+
const client = clientRef.current;
|
|
1715
|
+
if (
|
|
1716
|
+
!client ||
|
|
1717
|
+
typeof client.scan !== "function" ||
|
|
1718
|
+
(typeof client.isSupported === "function" && !client.isSupported())
|
|
1719
|
+
) {
|
|
1720
|
+
const e = new BarcodeError(
|
|
1721
|
+
"UNSUPPORTED",
|
|
1722
|
+
"This host does not provide barcode scanning.",
|
|
1723
|
+
);
|
|
1724
|
+
setError(e);
|
|
1725
|
+
throw e;
|
|
1726
|
+
}
|
|
1727
|
+
const run = (runRef.current += 1);
|
|
1728
|
+
setScanning(true);
|
|
1729
|
+
setError(null);
|
|
1730
|
+
try {
|
|
1731
|
+
const next = await client.scan(normaliseBarcodeOptions(optionsRef.current));
|
|
1732
|
+
// A reset(), a newer scan, or an unmount landed while this one was open.
|
|
1733
|
+
if (run !== runRef.current) return null;
|
|
1734
|
+
if (!next) return null;
|
|
1735
|
+
setResult(next);
|
|
1736
|
+
return next;
|
|
1737
|
+
} catch (err) {
|
|
1738
|
+
const be = toBarcodeError(err);
|
|
1739
|
+
if (run === runRef.current) setError(be);
|
|
1740
|
+
throw be;
|
|
1741
|
+
} finally {
|
|
1742
|
+
if (run === runRef.current) setScanning(false);
|
|
1743
|
+
}
|
|
1744
|
+
}, []);
|
|
1745
|
+
|
|
1746
|
+
return { result, scanning, error, supported, scan, reset };
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1592
1749
|
/**
|
|
1593
1750
|
* Structured error thrown by `useImageEditor` callbacks.
|
|
1594
1751
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1746,6 +1746,68 @@ export class ImageEditorError extends Error {
|
|
|
1746
1746
|
);
|
|
1747
1747
|
}
|
|
1748
1748
|
|
|
1749
|
+
/** A code decoded by `useBarcodeScanner().scan()`. */
|
|
1750
|
+
export interface BarcodeScan {
|
|
1751
|
+
/** The decoded text. */
|
|
1752
|
+
value: string;
|
|
1753
|
+
/**
|
|
1754
|
+
* Lowercase symbology name (`qr_code`, `code_128`, `ean_13`, …). A HINT, not
|
|
1755
|
+
* a promise: the two hosts detect different sets, so never branch on it for
|
|
1756
|
+
* correctness.
|
|
1757
|
+
*/
|
|
1758
|
+
format: string;
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
/** Options for `useBarcodeScanner(...)`. */
|
|
1762
|
+
export interface BarcodeScannerOptions {
|
|
1763
|
+
/** Narrow which symbologies to look for. A hint the host honours where it can. */
|
|
1764
|
+
formats?: string[];
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
export interface BarcodeScannerResult {
|
|
1768
|
+
/** The most recent scan, or null before the first call / after reset. */
|
|
1769
|
+
result: BarcodeScan | null;
|
|
1770
|
+
scanning: boolean;
|
|
1771
|
+
error: BarcodeError | null;
|
|
1772
|
+
/**
|
|
1773
|
+
* False where the host brokers no scanner — notably any browser without
|
|
1774
|
+
* `BarcodeDetector` (Safari, Firefox). GATE THE SCAN BUTTON ON THIS.
|
|
1775
|
+
*/
|
|
1776
|
+
supported: boolean;
|
|
1777
|
+
/** Resolves the first code decoded, or null if the user dismisses. */
|
|
1778
|
+
scan(): Promise<BarcodeScan | null>;
|
|
1779
|
+
/** Clear `result` and `error`. */
|
|
1780
|
+
reset(): void;
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
/**
|
|
1784
|
+
* Read a barcode or QR code with the device camera. Imperative — call `scan()`
|
|
1785
|
+
* from a user gesture; the OS and the browser gate the camera prompt on one, so
|
|
1786
|
+
* it never opens on mount. One-shot by design: to read several codes, call
|
|
1787
|
+
* `scan()` again rather than leaving a subscription running.
|
|
1788
|
+
*
|
|
1789
|
+
* The Expo export scans via `expo-camera`; the web Player via `BarcodeDetector`
|
|
1790
|
+
* over the same `getUserMedia` preview `useCamera()` uses. Where the browser
|
|
1791
|
+
* ships no `BarcodeDetector` this is a genuine platform gap (CLAUDE.md §8), so
|
|
1792
|
+
* `supported` is false and the widget must offer manual entry instead.
|
|
1793
|
+
*/
|
|
1794
|
+
export function useBarcodeScanner(
|
|
1795
|
+
options?: BarcodeScannerOptions,
|
|
1796
|
+
): BarcodeScannerResult;
|
|
1797
|
+
|
|
1798
|
+
/**
|
|
1799
|
+
* Error surfaced by `useBarcodeScanner()` — thrown by `scan()` and stored in
|
|
1800
|
+
* the hook's `error` slot. A dismissal is not an error; `scan()` resolves null.
|
|
1801
|
+
*/
|
|
1802
|
+
export class BarcodeError extends Error {
|
|
1803
|
+
code: "PERMISSION_DENIED" | "UNSUPPORTED" | "INTERNAL";
|
|
1804
|
+
constructor(
|
|
1805
|
+
code: BarcodeError["code"],
|
|
1806
|
+
message: string,
|
|
1807
|
+
opts?: { cause?: unknown },
|
|
1808
|
+
);
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1749
1811
|
/**
|
|
1750
1812
|
* Error class thrown by useDatastoreMutation callbacks (and surfaced by
|
|
1751
1813
|
* useDatastoreQuery in its `error` slot). The `code` is a stable
|
package/dist/index.js
CHANGED
package/dist/index.native.js
CHANGED
package/dist/linter.cjs
CHANGED
|
@@ -1201,6 +1201,37 @@ function _imagePercentHeightRules(source) {
|
|
|
1201
1201
|
return findings;
|
|
1202
1202
|
}
|
|
1203
1203
|
|
|
1204
|
+
// sc-7274 — a percentage `flexBasis` sizes the MAIN axis, which in a column is
|
|
1205
|
+
// the HEIGHT: under a definite-height parent (a Grid cell stretches its child
|
|
1206
|
+
// on the web Player) the child fills the container and, with `flex-shrink: 0`,
|
|
1207
|
+
// overflows over the content below. `width: "100%"` is the direction-agnostic
|
|
1208
|
+
// replacement. Mirror of linter.js (see there for the full rationale).
|
|
1209
|
+
const _FLEX_BASIS_PERCENT_RE =
|
|
1210
|
+
/\bflexBasis\s*:[^,}\n]*?(["'])\s*(\d+(?:\.\d+)?)\s*%\s*\1/g;
|
|
1211
|
+
|
|
1212
|
+
function _flexBasisPercentRules(source) {
|
|
1213
|
+
const findings = [];
|
|
1214
|
+
const code = _stripNonCode(source, { keepStrings: true });
|
|
1215
|
+
const sourceLines = source.split(/\r?\n/);
|
|
1216
|
+
_FLEX_BASIS_PERCENT_RE.lastIndex = 0;
|
|
1217
|
+
let hit;
|
|
1218
|
+
while ((hit = _FLEX_BASIS_PERCENT_RE.exec(code))) {
|
|
1219
|
+
const line = code.slice(0, hit.index).split(/\r?\n/).length;
|
|
1220
|
+
findings.push({
|
|
1221
|
+
rule: "flex-basis-percent",
|
|
1222
|
+
severity: "warning",
|
|
1223
|
+
label:
|
|
1224
|
+
`flexBasis "${hit[2]}%" sizes the MAIN axis — in a column that is the ` +
|
|
1225
|
+
`HEIGHT, so under a definite-height parent it fills the container and ` +
|
|
1226
|
+
`overflows below. Use width: "100%"; a NUMBER (flexBasis: 220) is a ` +
|
|
1227
|
+
`wrap threshold.`,
|
|
1228
|
+
line,
|
|
1229
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
return findings;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1204
1235
|
// sc-4913 — a measured frame INCLUDES the element's own padding, so cells sized
|
|
1205
1236
|
// from it overflow the content box and the last one wraps into an empty column.
|
|
1206
1237
|
// Mirror of linter.js (see there for the full rationale).
|
|
@@ -1491,6 +1522,9 @@ function lintSource(source, options) {
|
|
|
1491
1522
|
findings.push(..._lucideIconRules(source));
|
|
1492
1523
|
findings.push(..._selfContainedReferenceRules(source));
|
|
1493
1524
|
findings.push(..._imagePercentHeightRules(source));
|
|
1525
|
+
// sc-7274 — soft warning: a percentage flexBasis sizes the main axis, so in a
|
|
1526
|
+
// column it claims the parent's whole height and overflows.
|
|
1527
|
+
findings.push(..._flexBasisPercentRules(source));
|
|
1494
1528
|
// sc-4913 — soft warning: a measured width that includes the widget's own
|
|
1495
1529
|
// padding wraps the last grid column into an empty one.
|
|
1496
1530
|
findings.push(..._measuredPaddingRules(source));
|
package/dist/linter.js
CHANGED
|
@@ -1226,6 +1226,61 @@ function _imagePercentHeightRules(source) {
|
|
|
1226
1226
|
return findings;
|
|
1227
1227
|
}
|
|
1228
1228
|
|
|
1229
|
+
// sc-7274 — a percentage `flexBasis` sizes the MAIN axis, and in a column that
|
|
1230
|
+
// is the HEIGHT.
|
|
1231
|
+
//
|
|
1232
|
+
// `flexBasis: "100%"` written to mean "full width" is only that in a ROW. In a
|
|
1233
|
+
// column parent it asks for the parent's whole HEIGHT, and the moment an
|
|
1234
|
+
// ancestor makes that height definite — a Grid cell stretches its child on the
|
|
1235
|
+
// web Player — every such sibling becomes as tall as the container. `View`
|
|
1236
|
+
// defaults to `flex-shrink: 0`, so they cannot shrink back: they overflow
|
|
1237
|
+
// hundreds of pixels down over whatever follows. That shipped a customer form
|
|
1238
|
+
// with a blank band mid-layout and three fields painted across the submit row,
|
|
1239
|
+
// visible only once published (the builder canvas leaves the height auto,
|
|
1240
|
+
// where the percentage degrades to `content` and the form looks right).
|
|
1241
|
+
//
|
|
1242
|
+
// `width: "100%"` is the direction-agnostic replacement — it fills the row in a
|
|
1243
|
+
// column parent AND takes its own line in a wrap row — so a percentage basis is
|
|
1244
|
+
// never the only way to say it.
|
|
1245
|
+
//
|
|
1246
|
+
// `severity: "warning"`, like `image-percent-height`: in a row parent the value
|
|
1247
|
+
// IS correct, and an AST-free scan cannot see the parent's `flexDirection`
|
|
1248
|
+
// (the style usually lives in a shared field/cell helper). A warning still
|
|
1249
|
+
// drives an AI-agent repair turn, which is the point of the rule.
|
|
1250
|
+
//
|
|
1251
|
+
// Scope is the literal inline form, including the ternary a responsive cell
|
|
1252
|
+
// writes (`flexBasis: stacked ? "100%" : CARD`). A basis threaded through a
|
|
1253
|
+
// variable stays beyond the scan; the designer skill remains the first guard.
|
|
1254
|
+
const _FLEX_BASIS_PERCENT_RE =
|
|
1255
|
+
/\bflexBasis\s*:[^,}\n]*?(["'])\s*(\d+(?:\.\d+)?)\s*%\s*\1/g;
|
|
1256
|
+
|
|
1257
|
+
function _flexBasisPercentRules(source) {
|
|
1258
|
+
const findings = [];
|
|
1259
|
+
// Comments blanked, strings kept: the value under test IS a string literal,
|
|
1260
|
+
// so this rule's own documentation must not flag itself.
|
|
1261
|
+
const code = _stripNonCode(source, { keepStrings: true });
|
|
1262
|
+
const sourceLines = source.split(/\r?\n/);
|
|
1263
|
+
_FLEX_BASIS_PERCENT_RE.lastIndex = 0;
|
|
1264
|
+
let hit;
|
|
1265
|
+
while ((hit = _FLEX_BASIS_PERCENT_RE.exec(code))) {
|
|
1266
|
+
const line = code.slice(0, hit.index).split(/\r?\n/).length;
|
|
1267
|
+
findings.push({
|
|
1268
|
+
rule: "flex-basis-percent",
|
|
1269
|
+
severity: "warning",
|
|
1270
|
+
// Kept under FINDING_LABEL_BUDGET: the repair turn truncates the whole
|
|
1271
|
+
// message at 300 chars, which would otherwise eat the fix and the line.
|
|
1272
|
+
label:
|
|
1273
|
+
`flexBasis "${hit[2]}%" sizes the MAIN axis — in a column that is the ` +
|
|
1274
|
+
`HEIGHT, so under a definite-height parent it fills the container and ` +
|
|
1275
|
+
`overflows below. Use width: "100%"; a NUMBER (flexBasis: 220) is a ` +
|
|
1276
|
+
`wrap threshold.`,
|
|
1277
|
+
line,
|
|
1278
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
return findings;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1229
1284
|
// sc-4913 — a measured frame INCLUDES the element's own padding.
|
|
1230
1285
|
//
|
|
1231
1286
|
// `onLayout` reports the frame width, and padding sits inside that frame. A
|
|
@@ -1543,6 +1598,9 @@ export function lintSource(source, options) {
|
|
|
1543
1598
|
findings.push(..._selfContainedReferenceRules(source));
|
|
1544
1599
|
// sc-3493 — soft warning: percentage height on an <Image> collapses to 0.
|
|
1545
1600
|
findings.push(..._imagePercentHeightRules(source));
|
|
1601
|
+
// sc-7274 — soft warning: a percentage flexBasis sizes the main axis, so in a
|
|
1602
|
+
// column it claims the parent's whole height and overflows.
|
|
1603
|
+
findings.push(..._flexBasisPercentRules(source));
|
|
1546
1604
|
// sc-4913 — soft warning: a measured width that includes the widget's own
|
|
1547
1605
|
// padding wraps the last grid column into an empty one.
|
|
1548
1606
|
findings.push(..._measuredPaddingRules(source));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.129.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",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
],
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "node scripts/build.js",
|
|
52
|
-
"test": "node --test src/__tests__/contract.test.js src/__tests__/vetted-imports-audit.test.js src/__tests__/hooks-users.test.js src/__tests__/hooks-groups.test.js src/__tests__/hooks-invites.test.js src/__tests__/hooks-schema.test.js src/__tests__/hooks-assets-by-tag.test.js src/__tests__/hooks-filestore-upload.test.js src/__tests__/hooks-filestore-file.test.js src/__tests__/hooks-mutation.test.js src/__tests__/hooks-payments.test.js src/__tests__/hooks-record-permissions.test.js src/__tests__/hooks-geolocation.test.js src/__tests__/hooks-section-empty.test.js src/__tests__/hooks-widget-event.test.js src/__tests__/hooks-widget-input.test.js src/__tests__/hooks-identification.test.js src/__tests__/hooks-subscription.test.js src/__tests__/hooks-volatile-query-key.test.js src/__tests__/linter-users-scope.test.js src/__tests__/linter-comments.test.js src/__tests__/linter-translation-api.test.js src/__tests__/linter-page-url.test.js src/__tests__/linter-image-height.test.js src/__tests__/linter-hardcoded-design.test.js src/__tests__/linter-measured-padding.test.js src/__tests__/linter-payment-error.test.js src/__tests__/linter-platform.test.js src/__tests__/linter-react-import.test.js src/__tests__/lucide-icon-names.test.js src/__tests__/lucideIconName.test.js src/__tests__/manifest-actions.test.js src/__tests__/widget-translations.test.js src/__tests__/hooks-translate.test.js src/__tests__/devserver.test.js src/__tests__/flatten-entry.test.js src/__tests__/host-externals.test.js src/__tests__/datetimepicker.test.js src/__tests__/property-schema-resolve.test.js src/__tests__/corner-radius.test.js src/__tests__/theme-components-parity.test.js src/__tests__/navigation-parity.test.js src/__tests__/theme-depth-tokens.test.js src/__tests__/interaction-lift.test.js src/__tests__/toast-host.test.js src/__tests__/overlay-tokens.test.js src/__tests__/hooks-domain-error-mapping.test.js src/__tests__/linter-datastore-error.test.js src/__tests__/linter-write-gating.test.js src/__tests__/hooks-speech-to-text.test.js src/__tests__/hooks-camera.test.js src/__tests__/hooks-image-editor.test.js src/__tests__/hooks-bound-columns.test.js src/__tests__/hooks-stable-query.test.js src/__tests__/hooks-can-write.test.js src/__tests__/widget-route.test.js src/__tests__/linter-html-in-content.test.js src/__tests__/markdown.test.js src/__tests__/markdown-edit.test.js src/__tests__/richtext-tokens.test.js"
|
|
52
|
+
"test": "node --test src/__tests__/contract.test.js src/__tests__/vetted-imports-audit.test.js src/__tests__/hooks-users.test.js src/__tests__/hooks-groups.test.js src/__tests__/hooks-invites.test.js src/__tests__/hooks-schema.test.js src/__tests__/hooks-assets-by-tag.test.js src/__tests__/hooks-filestore-upload.test.js src/__tests__/hooks-filestore-file.test.js src/__tests__/hooks-mutation.test.js src/__tests__/hooks-payments.test.js src/__tests__/hooks-record-permissions.test.js src/__tests__/hooks-geolocation.test.js src/__tests__/hooks-section-empty.test.js src/__tests__/hooks-widget-event.test.js src/__tests__/hooks-widget-input.test.js src/__tests__/hooks-identification.test.js src/__tests__/hooks-subscription.test.js src/__tests__/hooks-volatile-query-key.test.js src/__tests__/linter-users-scope.test.js src/__tests__/linter-comments.test.js src/__tests__/linter-translation-api.test.js src/__tests__/linter-page-url.test.js src/__tests__/linter-image-height.test.js src/__tests__/linter-flex-basis-percent.test.js src/__tests__/linter-hardcoded-design.test.js src/__tests__/linter-measured-padding.test.js src/__tests__/linter-payment-error.test.js src/__tests__/linter-platform.test.js src/__tests__/linter-react-import.test.js src/__tests__/lucide-icon-names.test.js src/__tests__/lucideIconName.test.js src/__tests__/manifest-actions.test.js src/__tests__/widget-translations.test.js src/__tests__/hooks-translate.test.js src/__tests__/devserver.test.js src/__tests__/flatten-entry.test.js src/__tests__/host-externals.test.js src/__tests__/datetimepicker.test.js src/__tests__/property-schema-resolve.test.js src/__tests__/corner-radius.test.js src/__tests__/theme-components-parity.test.js src/__tests__/navigation-parity.test.js src/__tests__/theme-depth-tokens.test.js src/__tests__/interaction-lift.test.js src/__tests__/toast-host.test.js src/__tests__/overlay-tokens.test.js src/__tests__/hooks-domain-error-mapping.test.js src/__tests__/linter-datastore-error.test.js src/__tests__/linter-write-gating.test.js src/__tests__/hooks-speech-to-text.test.js src/__tests__/hooks-camera.test.js src/__tests__/hooks-barcode.test.js src/__tests__/hooks-image-editor.test.js src/__tests__/hooks-bound-columns.test.js src/__tests__/hooks-stable-query.test.js src/__tests__/hooks-can-write.test.js src/__tests__/widget-route.test.js src/__tests__/linter-html-in-content.test.js src/__tests__/markdown.test.js src/__tests__/markdown-edit.test.js src/__tests__/richtext-tokens.test.js"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">=18"
|