@colixsystems/widget-sdk 0.304.0 → 0.306.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 CHANGED
@@ -90,7 +90,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
90
90
 
91
91
  ## Status
92
92
 
93
- `v0.304.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**.
93
+ `v0.306.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.306.0 (contract 1.250.0)
96
+
97
+ **New linter rule `read-error-not-branched` (severity `warning`).** A read that the viewer may not make never succeeds on a retry. A signed-out visitor reading a table only members may read gets a `DatastoreError` with `code: "NOT_FOUND"`; a signed-in user the table's grants leave out gets `FORBIDDEN` or no rows. Both carry `retryable: false`. A widget that shows "could not be loaded" with a Retry for every read error loops that visitor forever. The read hooks' `error` (`useDatastoreQuery`, `usePagedDatastoreQuery`, `useDatastoreRecord`, `useDatastoreAggregate`, `useDatastoreFigure`) has always carried `{ code, message, retryable }`, and the contract now says so. Offer Retry only when `error.retryable` (a dropped connection, a timeout, a rate limit, a 5xx). Otherwise show a calm signed-out state to a visitor with no `useUser().id` ("Sign in to see the recipes"), and `error.message` to a signed-in user, with no Retry. The rule fires when a read hook's `refetch` or `retry` is bound to an `onPress` in the statement that handles its `error`, and that error's `retryable` and `code ===` are never read and the signed-in user's id is never checked. A bare `useUser()` call does not satisfy it.
98
+
99
+ ### What's new in 0.305.0 (contract 1.249.0)
100
+
101
+ **A `<Button>` follows its parent's alignment.** A button forced `alignSelf: "flex-start"` on itself, so it sat at the left of a column with `alignItems: "center"` (an empty state's call to action) and at the top of a row with `alignItems: "center"` (an Edit button beside a name and a price). It now hugs its label inside a box its parent places: centred in a centring column, vertically centred in a centring row, at the end of a `flex-end` column, and at the start of a plain column, content-width as before. A `style` with `alignSelf`, `flex`, `flexGrow`, `flexBasis` or a percentage `width`, `minWidth`, `height` or `minHeight` makes it an ordinary flex item the parent places like any other, so a `flex: 1` button in a row takes the row's cross-axis alignment. The button's margins, `maxWidth`, `maxHeight`, `flexShrink`, `position` and offsets go on that box. `<IconButton>` drops its own `alignSelf` too: a fixed square never stretches. Visible change: a button that sat at the start of a centring parent moves to where that parent puts its children.
94
102
 
95
103
  ### What's new in 0.304.0 (contract 1.248.0)
96
104
 
@@ -3830,7 +3838,7 @@ export default function ContactList({ tableId, pageSize }) {
3830
3838
  <TextInput value={draft} onChangeText={setDraft} placeholder="Search" />
3831
3839
  <Pressable onPress={() => setStatus(status === "Won" ? "" : "Won")}><Text>Won</Text></Pressable>
3832
3840
  {loading ? <Text>Loading…</Text> : data.map((row) => <Text key={row.id}>{row.name}</Text>)}
3833
- {error ? <Button variant="ghost" title="Retry" onPress={retry} /> : null}
3841
+ {error ? (error.retryable ? <Button variant="ghost" title="Retry" onPress={retry} /> : <Text>{error.message}</Text>) : null}
3834
3842
  <Text>{total ?? 0} contacts</Text>
3835
3843
  {hasMore ? <Button variant="ghost" title="Load more" busy={loadingMore} onPress={loadMore} /> : null}
3836
3844
  </View>
@@ -130,6 +130,43 @@ function triggerProps(props) {
130
130
  };
131
131
  }
132
132
 
133
+ // Where a hugging button sits among its siblings: its box takes these.
134
+ const BOX_STYLE_KEYS = new Set([
135
+ "margin", "marginTop", "marginRight", "marginBottom", "marginLeft",
136
+ "marginHorizontal", "marginVertical", "marginStart", "marginEnd",
137
+ "marginBlock", "marginBlockStart", "marginBlockEnd",
138
+ "marginInline", "marginInlineStart", "marginInlineEnd",
139
+ "flexShrink", "maxWidth", "maxHeight",
140
+ "position", "top", "right", "bottom", "left", "start", "end", "zIndex", "display",
141
+ ]);
142
+ const SELF_PLACING_KEYS = ["alignSelf", "flex", "flexGrow", "flexBasis"];
143
+ const SIZE_KEYS = ["width", "minWidth", "height", "minHeight"];
144
+
145
+ /**
146
+ * How a button's `style` splits between the box its parent places and the
147
+ * button that hugs its label inside it, or null when the style places the
148
+ * button itself (an `alignSelf`, a flex grow or basis, a percentage size).
149
+ *
150
+ * Flexbox has no "do not stretch" that leaves the parent's other alignments
151
+ * alone: `alignSelf: "flex-start"` overrode a centring parent, and Yoga
152
+ * stretches a `width: "fit-content"` child. So the box follows the parent and
153
+ * the button hugs at its start, which differs only where the parent stretches.
154
+ *
155
+ * @param {object|Array|null|undefined|false} style
156
+ * @returns {{ box: object, button: object } | null}
157
+ */
158
+ function hugStyle(style) {
159
+ const flat = flattenStyle(style);
160
+ const selfPlaced =
161
+ SELF_PLACING_KEYS.some((key) => flat[key] !== undefined) ||
162
+ SIZE_KEYS.some((key) => flat[key] !== undefined && typeof flat[key] !== "number");
163
+ if (selfPlaced) return null;
164
+ const box = {};
165
+ const button = {};
166
+ for (const [key, value] of Object.entries(flat)) (BOX_STYLE_KEYS.has(key) ? box : button)[key] = value;
167
+ return { box, button };
168
+ }
169
+
133
170
  function pressable(props) {
134
171
  return typeof props.onPress === "function" || typeof props.onLongPress === "function";
135
172
  }
@@ -230,6 +267,7 @@ export function makeButton(rn) {
230
267
  const fontSize =
231
268
  typeof f.fontSize === "number" && Number.isFinite(f.fontSize) ? f.fontSize : sized.fontSize;
232
269
  const glyph = iconNode(icon, Math.round(fontSize), ink);
270
+ const hug = hugStyle(style);
233
271
 
234
272
  const container = [
235
273
  {
@@ -237,14 +275,14 @@ export function makeButton(rn) {
237
275
  borderRadius: radii.sm,
238
276
  alignItems: "center",
239
277
  justifyContent: "center",
240
- alignSelf: "flex-start",
241
278
  },
279
+ hug ? { alignSelf: "flex-start" } : null,
242
280
  ...layers,
243
281
  glyph ? { flexDirection: "row", gap: spacing.xs } : null,
244
282
  // The gradient IS the fill, so it drops every flat background.
245
283
  gradient ? { backgroundColor: "transparent" } : null,
246
284
  disabled ? { opacity: 0.5 } : null,
247
- style,
285
+ hug ? hug.button : style,
248
286
  ];
249
287
  const label = React.createElement(
250
288
  Text,
@@ -275,23 +313,23 @@ export function makeButton(rn) {
275
313
  busy ? busyMark(look, layers, fontSize) : null,
276
314
  ];
277
315
 
278
- if (!pressable(props)) {
279
- return React.createElement(View, { ref, style: container, testID, accessibilityLabel }, children);
280
- }
281
- return React.createElement(
282
- Pressable,
283
- {
284
- ref,
285
- onPress,
286
- ...trigger.pass,
287
- ...pressableState({ disabled, busy, selected, expanded: trigger.expanded }, web),
288
- accessibilityRole: "button",
289
- accessibilityLabel: accessibilityLabel || (typeof title === "string" ? title : undefined),
290
- testID,
291
- style: pressedStyle(container, disabled || busy),
292
- },
293
- children,
294
- );
316
+ const button = pressable(props)
317
+ ? React.createElement(
318
+ Pressable,
319
+ {
320
+ ref,
321
+ onPress,
322
+ ...trigger.pass,
323
+ ...pressableState({ disabled, busy, selected, expanded: trigger.expanded }, web),
324
+ accessibilityRole: "button",
325
+ accessibilityLabel: accessibilityLabel || (typeof title === "string" ? title : undefined),
326
+ testID,
327
+ style: pressedStyle(container, disabled || busy),
328
+ },
329
+ children,
330
+ )
331
+ : React.createElement(View, { ref, style: container, testID, accessibilityLabel }, children);
332
+ return hug ? React.createElement(View, { style: hug.box }, button) : button;
295
333
  });
296
334
  Button.displayName = "Button";
297
335
 
@@ -335,7 +373,7 @@ export function makeButton(rn) {
335
373
  const { box, glyph } = iconButtonFrame(size);
336
374
 
337
375
  const container = [
338
- { borderRadius: theme.radii.sm, alignItems: "center", justifyContent: "center", alignSelf: "flex-start" },
376
+ { borderRadius: theme.radii.sm, alignItems: "center", justifyContent: "center" },
339
377
  ...layers,
340
378
  // A real square: the web ignores hitSlop, so the box is the target.
341
379
  { width: box, height: box, minWidth: box, minHeight: box, paddingHorizontal: 0, paddingVertical: 0 },
package/dist/contract.cjs CHANGED
@@ -1407,7 +1407,7 @@ const HOOKS = [
1407
1407
  data: "Record | null",
1408
1408
  loading: "boolean",
1409
1409
  fetching: "boolean",
1410
- error: "DatastoreError | null",
1410
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
1411
1411
  refetch: "() => Promise<void>",
1412
1412
  },
1413
1413
  requiredContextSlice: ["datastore.records"],
@@ -2000,7 +2000,7 @@ const HOOKS = [
2000
2000
  total: "number | null",
2001
2001
  loading: "boolean",
2002
2002
  fetching: "boolean",
2003
- error: "DatastoreError | null",
2003
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2004
2004
  refetch: "() => Promise<void>",
2005
2005
  },
2006
2006
  requiredContextSlice: ["datastore.records"],
@@ -2034,7 +2034,7 @@ const HOOKS = [
2034
2034
  loading: "boolean",
2035
2035
  fetching: "boolean",
2036
2036
  loadingMore: "boolean",
2037
- error: "DatastoreError | null",
2037
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2038
2038
  loadMore: "() => void",
2039
2039
  retry: "() => void",
2040
2040
  refetch: "() => Promise<void>",
@@ -2068,7 +2068,7 @@ const HOOKS = [
2068
2068
  truncated: "boolean",
2069
2069
  loading: "boolean",
2070
2070
  fetching: "boolean",
2071
- error: "DatastoreError | null",
2071
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2072
2072
  refetch: "() => Promise<void>",
2073
2073
  },
2074
2074
  requiredContextSlice: ["datastore.records"],
@@ -2108,7 +2108,7 @@ const HOOKS = [
2108
2108
  "Array<{ group, count, sum }> // by a column; a USER column's group is the user id",
2109
2109
  loading: "boolean",
2110
2110
  fetching: "boolean",
2111
- error: "DatastoreError | null",
2111
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2112
2112
  refetch: "() => Promise<void>",
2113
2113
  },
2114
2114
  requiredContextSlice: ["datastore.records"],
@@ -3872,7 +3872,7 @@ const PRIMITIVES = [
3872
3872
  {
3873
3873
  name: "Button",
3874
3874
  description:
3875
- 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style, e.g. `alignSelf`) and `labelStyle`. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3875
+ 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style) and `labelStyle`. It hugs its label and follows its parent\'s alignment: centred in a column with `alignItems: "center"`, vertically centred in such a row, at the start of a plain column. A `style` with `alignSelf`, `flex` or a percentage width makes it an ordinary flex item the parent may stretch. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3876
3876
  rnComponent: null,
3877
3877
  docsUrl: null,
3878
3878
  },
@@ -6917,7 +6917,11 @@ const CONTRACT = deepFreeze({
6917
6917
  // the palette. `deriveStatusColors` stays exported, unused by the hosts.
6918
6918
  // 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
6919
6919
  // the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
6920
- version: "1.248.0",
6920
+ // 1.249.0: a `<Button>` follows its parent's cross-axis alignment instead
6921
+ // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6922
+ // 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
6923
+ // `{ code, message, retryable }` it has always carried; Retry only when retryable.
6924
+ version: "1.250.0",
6921
6925
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6922
6926
  hooks: HOOKS,
6923
6927
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -1402,7 +1402,7 @@ const HOOKS = [
1402
1402
  data: "Record | null",
1403
1403
  loading: "boolean",
1404
1404
  fetching: "boolean",
1405
- error: "DatastoreError | null",
1405
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
1406
1406
  refetch: "() => Promise<void>",
1407
1407
  },
1408
1408
  requiredContextSlice: ["datastore.records"],
@@ -1995,7 +1995,7 @@ const HOOKS = [
1995
1995
  total: "number | null",
1996
1996
  loading: "boolean",
1997
1997
  fetching: "boolean",
1998
- error: "DatastoreError | null",
1998
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
1999
1999
  refetch: "() => Promise<void>",
2000
2000
  },
2001
2001
  requiredContextSlice: ["datastore.records"],
@@ -2029,7 +2029,7 @@ const HOOKS = [
2029
2029
  loading: "boolean",
2030
2030
  fetching: "boolean",
2031
2031
  loadingMore: "boolean",
2032
- error: "DatastoreError | null",
2032
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2033
2033
  loadMore: "() => void",
2034
2034
  retry: "() => void",
2035
2035
  refetch: "() => Promise<void>",
@@ -2063,7 +2063,7 @@ const HOOKS = [
2063
2063
  truncated: "boolean",
2064
2064
  loading: "boolean",
2065
2065
  fetching: "boolean",
2066
- error: "DatastoreError | null",
2066
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2067
2067
  refetch: "() => Promise<void>",
2068
2068
  },
2069
2069
  requiredContextSlice: ["datastore.records"],
@@ -2103,7 +2103,7 @@ const HOOKS = [
2103
2103
  "Array<{ group, count, sum }> // by a column; a USER column's group is the user id",
2104
2104
  loading: "boolean",
2105
2105
  fetching: "boolean",
2106
- error: "DatastoreError | null",
2106
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2107
2107
  refetch: "() => Promise<void>",
2108
2108
  },
2109
2109
  requiredContextSlice: ["datastore.records"],
@@ -3867,7 +3867,7 @@ const PRIMITIVES = [
3867
3867
  {
3868
3868
  name: "Button",
3869
3869
  description:
3870
- 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style, e.g. `alignSelf`) and `labelStyle`. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3870
+ 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style) and `labelStyle`. It hugs its label and follows its parent\'s alignment: centred in a column with `alignItems: "center"`, vertically centred in such a row, at the start of a plain column. A `style` with `alignSelf`, `flex` or a percentage width makes it an ordinary flex item the parent may stretch. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3871
3871
  rnComponent: null,
3872
3872
  docsUrl: null,
3873
3873
  },
@@ -6912,7 +6912,11 @@ const CONTRACT = deepFreeze({
6912
6912
  // the palette. `deriveStatusColors` stays exported, unused by the hosts.
6913
6913
  // 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
6914
6914
  // the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
6915
- version: "1.248.0",
6915
+ // 1.249.0: a `<Button>` follows its parent's cross-axis alignment instead
6916
+ // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6917
+ // 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
6918
+ // `{ code, message, retryable }` it has always carried; Retry only when retryable.
6919
+ version: "1.250.0",
6916
6920
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6917
6921
  hooks: HOOKS,
6918
6922
  primitives: PRIMITIVES,
package/dist/linter.cjs CHANGED
@@ -1668,6 +1668,74 @@ function _datastoreErrorHandlingRules(source) {
1668
1668
  ];
1669
1669
  }
1670
1670
 
1671
+ // sc-16511 — soft warning, the read twin of `datastore-error-not-branched`.
1672
+ // A read refused because the viewer may not see the table (a signed-out
1673
+ // visitor gets NOT_FOUND, a signed-in one FORBIDDEN) never clears on a retry,
1674
+ // so a Retry bound to every read error loops the visitor forever. Reading the
1675
+ // read error's `retryable`, branching on its `code ===`, or guarding on the
1676
+ // signed-in user's id satisfies it. A bare `useUser()` call does not: widgets
1677
+ // call it for a greeting, and that is exactly the widget this rule exists for.
1678
+ const READ_HOOK = String.raw`use(?:PagedDatastoreQuery|Datastore(?:Query|Record|Aggregate|Figure)\w*)`;
1679
+ const READ_HOOK_CALL_RE = new RegExp(String.raw`\b${READ_HOOK}\s*\(`);
1680
+ const READ_HOOK_DESTRUCTURE_RE = new RegExp(String.raw`\{([^{}]*)\}\s*=\s*${READ_HOOK}\s*\(`, "g");
1681
+ const RETRY_CONTROL_RE = /\bonPress\s*(?:=\s*\{|:)\s*(?:\(\s*\)\s*=>\s*\{?\s*)?(?:refetch|retry)\b/g;
1682
+ // How far before a retry control, within one statement, its error check may sit.
1683
+ const RETRY_ERROR_WINDOW = 400;
1684
+
1685
+ function _statementBefore(code, index) {
1686
+ const window = code.slice(Math.max(0, index - RETRY_ERROR_WINDOW), index);
1687
+ return window.slice(window.lastIndexOf(";") + 1);
1688
+ }
1689
+
1690
+ /** The names the read hooks' `error` is bound to; `error` when none is destructured. */
1691
+ function _readErrorNames(code) {
1692
+ const names = new Set();
1693
+ for (const m of code.matchAll(READ_HOOK_DESTRUCTURE_RE)) {
1694
+ const bound = /(?:^|,)\s*error\s*(?::\s*([A-Za-z_$][\w$]*))?\s*(?:=[^,]*)?(?:,|$)/.exec(m[1]);
1695
+ if (bound) names.add(bound[1] || "error");
1696
+ }
1697
+ return names.size > 0 ? [...names] : ["error"];
1698
+ }
1699
+
1700
+ function _signedInGuardRes(code) {
1701
+ const res = [/\buseUser\s*\(\s*\)\s*\??\.id\b/];
1702
+ const guardOn = (name) => {
1703
+ const n = name.replace(/\$/g, "\\$");
1704
+ return [new RegExp(`!\\s*${n}\\b(?!\\s*\\.)`), new RegExp(`(?<![\\w$.])${n}\\s*(?:\\?[^.?]|&&|\\|\\|)`)];
1705
+ };
1706
+ const named = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*useUser\s*\(\s*\)/.exec(code);
1707
+ if (named) res.push(...guardOn(`${named[1]}\\??\\.id`));
1708
+ const destructured = /\b(?:const|let|var)\s*\{([^}]*)\}\s*=\s*useUser\s*\(\s*\)/.exec(code);
1709
+ const idName = destructured && /(?:^|,)\s*id\s*(?::\s*([A-Za-z_$][\w$]*))?\s*(?:,|$)/.exec(destructured[1]);
1710
+ if (idName) res.push(...guardOn(idName[1] || "id"));
1711
+ return res;
1712
+ }
1713
+
1714
+ function _readErrorHandlingRules(source) {
1715
+ const code = _stripNonCode(source);
1716
+ if (!READ_HOOK_CALL_RE.test(code)) return [];
1717
+ const errorNames = _readErrorNames(code).map((n) => n.replace(/\$/g, "\\$"));
1718
+ const nearError = new RegExp(String.raw`(?<![\w$.])(?:${errorNames.join("|")})(?![\w$])`);
1719
+ const retry = [...code.matchAll(RETRY_CONTROL_RE)].find((m) => nearError.test(_statementBefore(code, m.index)));
1720
+ if (!retry) return [];
1721
+ const branched = new RegExp(String.raw`(?<![\w$.])(?:${errorNames.join("|")})\??\.(?:retryable\b|code\s*===)`);
1722
+ if (branched.test(code)) return [];
1723
+ if (_signedInGuardRes(code).some((re) => re.test(code))) return [];
1724
+ const line = code.slice(0, retry.index).split(/\r?\n/).length;
1725
+ return [
1726
+ {
1727
+ rule: "read-error-not-branched",
1728
+ severity: "warning",
1729
+ label:
1730
+ `offers Retry on every read error - a viewer who may not read the ` +
1731
+ `table (signed out: NOT_FOUND) can never succeed. Show Retry only when ` +
1732
+ `error.retryable; otherwise a signed-out state or error.message.`,
1733
+ line,
1734
+ snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
1735
+ },
1736
+ ];
1737
+ }
1738
+
1671
1739
  // sc-5206 — soft warning: a `useDatastoreQuery` argument built from a raw
1672
1740
  // `const q = useMemo(() => ({...}), [...])` re-fetches in a loop the moment
1673
1741
  // the deps array is wrong (sc-1579's volatile-query gate exists because of
@@ -3208,6 +3276,7 @@ function lintSource(source, options) {
3208
3276
  findings.push(..._hardcodedCurrencyLabelRules(source));
3209
3277
  findings.push(..._paymentErrorHandlingRules(source));
3210
3278
  findings.push(..._datastoreErrorHandlingRules(source));
3279
+ findings.push(..._readErrorHandlingRules(source));
3211
3280
  // sc-5206 — soft warnings steering a widget toward the two new hooks.
3212
3281
  findings.push(..._rawUseMemoIntoDatastoreQueryRules(source));
3213
3282
  findings.push(..._handRolledWriteGateRules(source));
package/dist/linter.js CHANGED
@@ -1663,6 +1663,74 @@ function _datastoreErrorHandlingRules(source) {
1663
1663
  ];
1664
1664
  }
1665
1665
 
1666
+ // sc-16511 — soft warning, the read twin of `datastore-error-not-branched`.
1667
+ // A read refused because the viewer may not see the table (a signed-out
1668
+ // visitor gets NOT_FOUND, a signed-in one FORBIDDEN) never clears on a retry,
1669
+ // so a Retry bound to every read error loops the visitor forever. Reading the
1670
+ // read error's `retryable`, branching on its `code ===`, or guarding on the
1671
+ // signed-in user's id satisfies it. A bare `useUser()` call does not: widgets
1672
+ // call it for a greeting, and that is exactly the widget this rule exists for.
1673
+ const READ_HOOK = String.raw`use(?:PagedDatastoreQuery|Datastore(?:Query|Record|Aggregate|Figure)\w*)`;
1674
+ const READ_HOOK_CALL_RE = new RegExp(String.raw`\b${READ_HOOK}\s*\(`);
1675
+ const READ_HOOK_DESTRUCTURE_RE = new RegExp(String.raw`\{([^{}]*)\}\s*=\s*${READ_HOOK}\s*\(`, "g");
1676
+ const RETRY_CONTROL_RE = /\bonPress\s*(?:=\s*\{|:)\s*(?:\(\s*\)\s*=>\s*\{?\s*)?(?:refetch|retry)\b/g;
1677
+ // How far before a retry control, within one statement, its error check may sit.
1678
+ const RETRY_ERROR_WINDOW = 400;
1679
+
1680
+ function _statementBefore(code, index) {
1681
+ const window = code.slice(Math.max(0, index - RETRY_ERROR_WINDOW), index);
1682
+ return window.slice(window.lastIndexOf(";") + 1);
1683
+ }
1684
+
1685
+ /** The names the read hooks' `error` is bound to; `error` when none is destructured. */
1686
+ function _readErrorNames(code) {
1687
+ const names = new Set();
1688
+ for (const m of code.matchAll(READ_HOOK_DESTRUCTURE_RE)) {
1689
+ const bound = /(?:^|,)\s*error\s*(?::\s*([A-Za-z_$][\w$]*))?\s*(?:=[^,]*)?(?:,|$)/.exec(m[1]);
1690
+ if (bound) names.add(bound[1] || "error");
1691
+ }
1692
+ return names.size > 0 ? [...names] : ["error"];
1693
+ }
1694
+
1695
+ function _signedInGuardRes(code) {
1696
+ const res = [/\buseUser\s*\(\s*\)\s*\??\.id\b/];
1697
+ const guardOn = (name) => {
1698
+ const n = name.replace(/\$/g, "\\$");
1699
+ return [new RegExp(`!\\s*${n}\\b(?!\\s*\\.)`), new RegExp(`(?<![\\w$.])${n}\\s*(?:\\?[^.?]|&&|\\|\\|)`)];
1700
+ };
1701
+ const named = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*useUser\s*\(\s*\)/.exec(code);
1702
+ if (named) res.push(...guardOn(`${named[1]}\\??\\.id`));
1703
+ const destructured = /\b(?:const|let|var)\s*\{([^}]*)\}\s*=\s*useUser\s*\(\s*\)/.exec(code);
1704
+ const idName = destructured && /(?:^|,)\s*id\s*(?::\s*([A-Za-z_$][\w$]*))?\s*(?:,|$)/.exec(destructured[1]);
1705
+ if (idName) res.push(...guardOn(idName[1] || "id"));
1706
+ return res;
1707
+ }
1708
+
1709
+ function _readErrorHandlingRules(source) {
1710
+ const code = _stripNonCode(source);
1711
+ if (!READ_HOOK_CALL_RE.test(code)) return [];
1712
+ const errorNames = _readErrorNames(code).map((n) => n.replace(/\$/g, "\\$"));
1713
+ const nearError = new RegExp(String.raw`(?<![\w$.])(?:${errorNames.join("|")})(?![\w$])`);
1714
+ const retry = [...code.matchAll(RETRY_CONTROL_RE)].find((m) => nearError.test(_statementBefore(code, m.index)));
1715
+ if (!retry) return [];
1716
+ const branched = new RegExp(String.raw`(?<![\w$.])(?:${errorNames.join("|")})\??\.(?:retryable\b|code\s*===)`);
1717
+ if (branched.test(code)) return [];
1718
+ if (_signedInGuardRes(code).some((re) => re.test(code))) return [];
1719
+ const line = code.slice(0, retry.index).split(/\r?\n/).length;
1720
+ return [
1721
+ {
1722
+ rule: "read-error-not-branched",
1723
+ severity: "warning",
1724
+ label:
1725
+ `offers Retry on every read error - a viewer who may not read the ` +
1726
+ `table (signed out: NOT_FOUND) can never succeed. Show Retry only when ` +
1727
+ `error.retryable; otherwise a signed-out state or error.message.`,
1728
+ line,
1729
+ snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
1730
+ },
1731
+ ];
1732
+ }
1733
+
1666
1734
  // sc-5206 — soft warning: a `useDatastoreQuery` argument built from a raw
1667
1735
  // `const q = useMemo(() => ({...}), [...])` re-fetches in a loop the moment
1668
1736
  // the deps array is wrong (sc-1579's volatile-query gate exists because of
@@ -3203,6 +3271,7 @@ export function lintSource(source, options) {
3203
3271
  findings.push(..._hardcodedCurrencyLabelRules(source));
3204
3272
  findings.push(..._paymentErrorHandlingRules(source));
3205
3273
  findings.push(..._datastoreErrorHandlingRules(source));
3274
+ findings.push(..._readErrorHandlingRules(source));
3206
3275
  // sc-5206 — soft warnings steering a widget toward the two new hooks.
3207
3276
  findings.push(..._rawUseMemoIntoDatastoreQueryRules(source));
3208
3277
  findings.push(..._handRolledWriteGateRules(source));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.304.0",
3
+ "version": "0.306.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",
package/src/contract.js CHANGED
@@ -1402,7 +1402,7 @@ const HOOKS = [
1402
1402
  data: "Record | null",
1403
1403
  loading: "boolean",
1404
1404
  fetching: "boolean",
1405
- error: "DatastoreError | null",
1405
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
1406
1406
  refetch: "() => Promise<void>",
1407
1407
  },
1408
1408
  requiredContextSlice: ["datastore.records"],
@@ -1995,7 +1995,7 @@ const HOOKS = [
1995
1995
  total: "number | null",
1996
1996
  loading: "boolean",
1997
1997
  fetching: "boolean",
1998
- error: "DatastoreError | null",
1998
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
1999
1999
  refetch: "() => Promise<void>",
2000
2000
  },
2001
2001
  requiredContextSlice: ["datastore.records"],
@@ -2029,7 +2029,7 @@ const HOOKS = [
2029
2029
  loading: "boolean",
2030
2030
  fetching: "boolean",
2031
2031
  loadingMore: "boolean",
2032
- error: "DatastoreError | null",
2032
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2033
2033
  loadMore: "() => void",
2034
2034
  retry: "() => void",
2035
2035
  refetch: "() => Promise<void>",
@@ -2063,7 +2063,7 @@ const HOOKS = [
2063
2063
  truncated: "boolean",
2064
2064
  loading: "boolean",
2065
2065
  fetching: "boolean",
2066
- error: "DatastoreError | null",
2066
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2067
2067
  refetch: "() => Promise<void>",
2068
2068
  },
2069
2069
  requiredContextSlice: ["datastore.records"],
@@ -2103,7 +2103,7 @@ const HOOKS = [
2103
2103
  "Array<{ group, count, sum }> // by a column; a USER column's group is the user id",
2104
2104
  loading: "boolean",
2105
2105
  fetching: "boolean",
2106
- error: "DatastoreError | null",
2106
+ error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
2107
2107
  refetch: "() => Promise<void>",
2108
2108
  },
2109
2109
  requiredContextSlice: ["datastore.records"],
@@ -3867,7 +3867,7 @@ const PRIMITIVES = [
3867
3867
  {
3868
3868
  name: "Button",
3869
3869
  description:
3870
- 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style, e.g. `alignSelf`) and `labelStyle`. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3870
+ 'Themed button. `<Button title="Save" onPress={save} />` — use it by default for a button: its fill, label colour, border, corner radius, padding, weight, shadow and gradient come from the app\'s button look (Design > Components > Buttons, and Danger buttons / Button outline for the danger variant and emphasis border), so it matches the built-in Button widget. Props: `title`, `onPress` (omit it for a purely visual button inside something else that is pressable), `variant` ("primary" default | "secondary" | "outlined" | "danger" | "ghost", no fill or border with the accent as its label, for a quiet action such as "Load more" or "Cancel" | "link", underlined accent text with no side padding, for an inline action), `size` ("sm", 36px high | "md", 44px, the default | "lg", 52px), `busy` (an action in flight: a `<Spinner>` over the label, which stays the button\'s accessible name and keeps its width, and the button cannot be pressed; use it for a save or an upload instead of swapping the label), `selected` (a toggle\'s on state, drawn in the accent\'s quiet tint; omit it for a plain button), `icon` (a lucide name) with `iconPosition` ("leading" | "trailing"), `disabled`, `accessibilityLabel`, `testID`, `style` (extra container style) and `labelStyle`. It hugs its label and follows its parent\'s alignment: centred in a column with `alignItems: "center"`, vertically centred in such a row, at the start of a plain column. A `style` with `alignSelf`, `flex` or a percentage width makes it an ordinary flex item the parent may stretch. Pass `fields` — `{ background, textColor, borderColor, borderWidth, paddingX, paddingY, radius, fontWeight, fontSize, shadow, gradient }` — to override one button, e.g. from style fields your widget declares. A ghost or link button takes the look\'s shape and type but not its fill, border, shadow or label colour, unless you pass them in `fields`. On a section that paints its own fill (`theme.colors.backdrop` there), a variant colour that the section makes unreadable takes that section\'s text colour, as its text does: an outlined label and border, a secondary whose fill disappears becomes outlined, and a primary or danger fill turns inverse (that text colour as its fill, its own colour as its label). A white or lightly tinted panel changes nothing, and a button inside a `<Card>` is measured against that card. A colour you pass in `fields`, `style` or `labelStyle`, or that the app\'s button look sets, is never changed. A button with only an icon is `<IconButton>`. For any other button, when the request needs one it cannot draw (a round floating action button, a tile with an image and two lines of text, a split button with a menu half), build your own from `Pressable` with `pressableLift` in the app\'s look (theme colours, radii and spacing), at least 44px high (a compact icon control in a dense row may go down to 36px, never below) and with an `accessibilityLabel`.',
3871
3871
  rnComponent: null,
3872
3872
  docsUrl: null,
3873
3873
  },
@@ -6912,7 +6912,11 @@ const CONTRACT = deepFreeze({
6912
6912
  // the palette. `deriveStatusColors` stays exported, unused by the hosts.
6913
6913
  // 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
6914
6914
  // the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
6915
- version: "1.248.0",
6915
+ // 1.249.0: a `<Button>` follows its parent's cross-axis alignment instead
6916
+ // of forcing `alignSelf: "flex-start"`; it still hugs its label.
6917
+ // 1.250.0: documentation (sc-16511) — the read hooks' `error` names the
6918
+ // `{ code, message, retryable }` it has always carried; Retry only when retryable.
6919
+ version: "1.250.0",
6916
6920
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6917
6921
  hooks: HOOKS,
6918
6922
  primitives: PRIMITIVES,