@colixsystems/widget-sdk 0.79.0 → 0.80.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 +4 -0
- package/dist/container-width.js +28 -0
- package/dist/contract.cjs +48 -1
- package/dist/contract.js +48 -1
- package/dist/hooks.js +32 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +2 -0
- package/dist/index.native.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,8 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
26
26
|
| **CORE** | `useWidgetEvent(name)` | `(payload?) => void` | `ctx.events.emit` — no scope |
|
|
27
27
|
| **CORE** | `useChildRenderer()` | `{ renderNode(node) }` | `ctx.renderer` — no scope (prefer the `WidgetTree` component) |
|
|
28
28
|
| **CORE** | `useFill()` | `boolean` | `ctx.fill` — no scope. `true` when the host sized this widget to fill its page-grid tile's reserved height (containers + media fill by default; the author can override per tile). Media-style widgets switch to a `flex: 1` / `height: "100%"` layout; others ignore it. Defaults `false`. |
|
|
29
|
+
| **CORE** | `useContainerWidth()` | `[width, onLayout]` | No context slice, no scope. Measures the width the widget's OWN box has, so it can lay itself out for the space it is in rather than for the screen. Spread the handler onto your outermost primitive. Use it for any widget with a wide form and a narrow one (a table, a toolbar, a row of tiles) — never switch on the device or window width, because a widget in a one-of-three grid cell on desktop has phone-width room and a widget filling a phone page does not. Width is 0 until the first layout: render the WIDE form then. One implementation covers web (react-native-web) and the native export. |
|
|
30
|
+
| **CORE** | `isNarrowWidth(width)` | `boolean` | No context slice, no scope. True when a MEASURED width is below `NARROW_WIDTH_PX` (480) — the one threshold every widget switches at, so a page reflows together rather than raggedly. An unmeasured width (0) is NOT narrow, so nothing flashes through the narrow form on first paint. |
|
|
29
31
|
| **CORE** | `useSectionEmpty(isEmpty)` | `void` | `ctx.section.reportEmpty` — no scope. Declares that the widget has NO content to show, so the host drops its layout slot instead of reserving space (and its parent's `gap`) for it. Returning `null` is not enough: the host wraps every widget in an entrance element, so a widget rendering nothing still leaves an empty box the parent stack gaps around. For a CONDITIONALLY ABSENT section (a per-record child collection with no rows for this record), never to suppress a genuine empty state. Stays mounted while collapsed, so passing `false` brings it back. Authoring surfaces never collapse. No-op on a host that doesn't implement it. |
|
|
30
32
|
| **CORE** | `useRefresh(handler)` | `void` | `ctx.refresh.subscribe` — no scope. Subscribes the handler to the page-level refresh tick (pull-to-refresh on mobile). Handler may return a Promise — the host waits for `allSettled` before clearing the spinner. The three datastore hooks auto-subscribe their own `refetch`; widgets only call this directly to re-run non-datastore work. No-op on a host that doesn't implement refresh. |
|
|
31
33
|
| **CORE** | `useClipboard()` | `{ copy, paste, hasContent }` | platform clipboard (web `navigator.clipboard` / native `expo-clipboard`); rejects with `ClipboardError` — no scope |
|
|
@@ -302,6 +304,8 @@ useEffect(() => {
|
|
|
302
304
|
|
|
303
305
|
### What's new in 0.41.0
|
|
304
306
|
|
|
307
|
+
**New `useContainerWidth()` hook + `isNarrowWidth(width)` / `NARROW_WIDTH_PX` (sc-4399).** A widget can now measure the width of its OWN box and lay itself out for the space it is in. This is the capability that was missing for every widget except Gallery, which had hand-rolled the same `onLayout` measurement for its carousel — that copy is now gone and Gallery reads the hook. It matters because the screen is the wrong question: a widget in a one-of-three grid cell on a desktop page has phone-width room, and a widget filling a phone page does not, so a table-shaped widget that switches on the device is wrong in both directions. `isNarrowWidth` gives every widget one threshold (480) to switch at, so a page of them reflows together instead of raggedly, and an unmeasured width (0) is deliberately not narrow so nothing flashes through its narrow form on first paint. `onLayout` is a react-native primitive callback, so ONE implementation serves the web Player and the exported app. Additive — `CONTRACT.version` bumped to the next minor for two new hooks.
|
|
308
|
+
|
|
305
309
|
**New `useSectionEmpty(isEmpty)` hook + optional `ctx.section` slice (sc-4416).** A widget can now tell the host it has no content to show, and the host removes its layout slot rather than reserving space for it. This closes a gap that `null` alone could not: the host wraps every widget node in an entrance element, so a widget that rendered nothing still left an empty box its parent stack put `gap` around — a dead band of whitespace exactly where the content would have been. It matters most for a per-record child collection (a policy detail page whose quiz section only exists for policies that have questions): the widget owns the rows, so only the widget can say, and `visibleWhen` cannot reach it because "has related rows" is not a field the record carries. The widget stays MOUNTED while collapsed, so when rows arrive it reports `false` and the section returns on its own — no measurement, no second pass. The slot (`ctx.section.reportEmpty`) is optional and deliberately omitted on authoring surfaces: on the Studio canvas and in the Agent Mode edit preview an empty widget must stay visible and selectable, or an absent section could never be edited. Additive — `CONTRACT.version` bumped to the next minor for a new hook plus a new optional context slice.
|
|
306
310
|
|
|
307
311
|
**New `useRefresh(handler)` hook + page-level refresh signal (sc-1179).** Pull-to-refresh on the mobile web Player + the native Expo export's `RefreshControl` now fans a page-level refresh tick out to every widget on the page. The three datastore hooks — `useDatastoreQuery`, `useDatastoreRecord`, `useAsset` — auto-subscribe their own `refetch`, so a widget built on those hooks gets refreshed for free. Widgets that need to re-run other work (a third-party `fetch`, a derived calculation) call `useRefresh(async () => { … })` directly. The handler may return a Promise — the host waits on `Promise.allSettled` of every subscriber before clearing the spinner. The slot (`ctx.refresh.subscribe`) is optional on the WidgetContext: a host that does not implement refresh (the Studio canvas preview) simply omits it and the hook collapses to a no-op. Additive — `CONTRACT.version` bumped to the next minor since the contract grew a new hook + a new (optional) context slice.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// sc-4399 — the narrow-form threshold, in its own dependency-free module.
|
|
2
|
+
//
|
|
3
|
+
// Deliberately NOT in hooks.js: that file's test harnesses load it through a
|
|
4
|
+
// hand-rolled transform that only understands `export function`, so an
|
|
5
|
+
// `export const` there breaks every hooks test at once. Keeping the constant
|
|
6
|
+
// here also means a consumer that just wants the number pays no React import.
|
|
7
|
+
//
|
|
8
|
+
// `useContainerWidth` itself stays in hooks.js, where React is already
|
|
9
|
+
// imported — it is the hook that measures; these two only classify.
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The width below which a widget should adopt its narrow form — a table
|
|
13
|
+
* becomes stacked label/value blocks, a toolbar wraps. ONE number so a page of
|
|
14
|
+
* widgets reflows together instead of raggedly.
|
|
15
|
+
*/
|
|
16
|
+
export const NARROW_WIDTH_PX = 480;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* True when a MEASURED width is below the threshold.
|
|
20
|
+
*
|
|
21
|
+
* An unmeasured width (0, before the first `onLayout`) is deliberately NOT
|
|
22
|
+
* narrow: the wide rendering is the historical one, so a widget that never
|
|
23
|
+
* lays out is unchanged, and no widget flashes through its narrow form on
|
|
24
|
+
* first paint.
|
|
25
|
+
*/
|
|
26
|
+
export function isNarrowWidth(width) {
|
|
27
|
+
return typeof width === "number" && width > 0 && width < NARROW_WIDTH_PX;
|
|
28
|
+
}
|
package/dist/contract.cjs
CHANGED
|
@@ -358,6 +358,45 @@ const HOOKS = [
|
|
|
358
358
|
requiredContextSlice: ["refresh.subscribe"],
|
|
359
359
|
scopes: null,
|
|
360
360
|
},
|
|
361
|
+
{
|
|
362
|
+
name: "useContainerWidth",
|
|
363
|
+
signature: "useContainerWidth()",
|
|
364
|
+
description:
|
|
365
|
+
"Measure the width the widget's OWN box has, so it can lay itself out " +
|
|
366
|
+
"for the space it is in rather than for the screen. Returns " +
|
|
367
|
+
"`[width, onLayout]`; spread the handler onto the widget's outermost " +
|
|
368
|
+
"primitive. A widget in a 1-of-3 grid cell on a desktop page has " +
|
|
369
|
+
"phone-width room while a widget filling a phone page does not, and the " +
|
|
370
|
+
"window width answers neither question — this is why a table-shaped " +
|
|
371
|
+
"widget must not switch on the device. `onLayout` is the react-native " +
|
|
372
|
+
"callback, so ONE implementation serves the web Player (through " +
|
|
373
|
+
"react-native-web) and the native export. Before the first layout the " +
|
|
374
|
+
"width is 0: treat that as \"not yet measured\" and render the wide " +
|
|
375
|
+
"form. Pair it with `isNarrowWidth(width)` so every widget switches at " +
|
|
376
|
+
"the same threshold. Takes no host context, so it is safe everywhere " +
|
|
377
|
+
"including the Studio canvas.",
|
|
378
|
+
returnShape: {
|
|
379
|
+
"(returns)": "[number, function]",
|
|
380
|
+
},
|
|
381
|
+
requiredContextSlice: [],
|
|
382
|
+
scopes: null,
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
name: "isNarrowWidth",
|
|
386
|
+
signature: "isNarrowWidth(width)",
|
|
387
|
+
description:
|
|
388
|
+
"True when a MEASURED width is below `NARROW_WIDTH_PX` (480), the one " +
|
|
389
|
+
"threshold at which a widget adopts its narrow form — a table becomes " +
|
|
390
|
+
"stacked cards, a toolbar wraps. One number so a page of widgets " +
|
|
391
|
+
"reflows together instead of raggedly. An unmeasured width (0) is " +
|
|
392
|
+
"deliberately NOT narrow, so a widget that never lays out keeps its " +
|
|
393
|
+
"historical wide rendering.",
|
|
394
|
+
returnShape: {
|
|
395
|
+
"(returns)": "boolean",
|
|
396
|
+
},
|
|
397
|
+
requiredContextSlice: [],
|
|
398
|
+
scopes: null,
|
|
399
|
+
},
|
|
361
400
|
{
|
|
362
401
|
name: "useSectionEmpty",
|
|
363
402
|
signature: "useSectionEmpty(isEmpty)",
|
|
@@ -2406,7 +2445,15 @@ const CONTRACT = deepFreeze({
|
|
|
2406
2445
|
// public endpoint instead, which skips the cache, the metering and the
|
|
2407
2446
|
// workspace's provider. Publishing the host list here keeps the linter,
|
|
2408
2447
|
// the Developer guide and the agent prompt reading one source.
|
|
2409
|
-
|
|
2448
|
+
// 1.54.0: additive (sc-4399, epic 4395) — `useContainerWidth()` +
|
|
2449
|
+
// `isNarrowWidth(width)` / `NARROW_WIDTH_PX`. Built-in widgets laid
|
|
2450
|
+
// themselves out at a fixed size — UserManagement's rows alone carried
|
|
2451
|
+
// ~800px of minWidth — so a page that reflowed around them still
|
|
2452
|
+
// overflowed, because the widget inside demanded desktop width. Gallery
|
|
2453
|
+
// already measured its own box with onLayout; this promotes that one
|
|
2454
|
+
// pattern to the SDK so custom and marketplace widgets get it too,
|
|
2455
|
+
// instead of each rolling its own.
|
|
2456
|
+
version: "1.54.0",
|
|
2410
2457
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
2411
2458
|
hooks: HOOKS,
|
|
2412
2459
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -358,6 +358,45 @@ const HOOKS = [
|
|
|
358
358
|
requiredContextSlice: ["refresh.subscribe"],
|
|
359
359
|
scopes: null,
|
|
360
360
|
},
|
|
361
|
+
{
|
|
362
|
+
name: "useContainerWidth",
|
|
363
|
+
signature: "useContainerWidth()",
|
|
364
|
+
description:
|
|
365
|
+
"Measure the width the widget's OWN box has, so it can lay itself out " +
|
|
366
|
+
"for the space it is in rather than for the screen. Returns " +
|
|
367
|
+
"`[width, onLayout]`; spread the handler onto the widget's outermost " +
|
|
368
|
+
"primitive. A widget in a 1-of-3 grid cell on a desktop page has " +
|
|
369
|
+
"phone-width room while a widget filling a phone page does not, and the " +
|
|
370
|
+
"window width answers neither question — this is why a table-shaped " +
|
|
371
|
+
"widget must not switch on the device. `onLayout` is the react-native " +
|
|
372
|
+
"callback, so ONE implementation serves the web Player (through " +
|
|
373
|
+
"react-native-web) and the native export. Before the first layout the " +
|
|
374
|
+
"width is 0: treat that as \"not yet measured\" and render the wide " +
|
|
375
|
+
"form. Pair it with `isNarrowWidth(width)` so every widget switches at " +
|
|
376
|
+
"the same threshold. Takes no host context, so it is safe everywhere " +
|
|
377
|
+
"including the Studio canvas.",
|
|
378
|
+
returnShape: {
|
|
379
|
+
"(returns)": "[number, function]",
|
|
380
|
+
},
|
|
381
|
+
requiredContextSlice: [],
|
|
382
|
+
scopes: null,
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
name: "isNarrowWidth",
|
|
386
|
+
signature: "isNarrowWidth(width)",
|
|
387
|
+
description:
|
|
388
|
+
"True when a MEASURED width is below `NARROW_WIDTH_PX` (480), the one " +
|
|
389
|
+
"threshold at which a widget adopts its narrow form — a table becomes " +
|
|
390
|
+
"stacked cards, a toolbar wraps. One number so a page of widgets " +
|
|
391
|
+
"reflows together instead of raggedly. An unmeasured width (0) is " +
|
|
392
|
+
"deliberately NOT narrow, so a widget that never lays out keeps its " +
|
|
393
|
+
"historical wide rendering.",
|
|
394
|
+
returnShape: {
|
|
395
|
+
"(returns)": "boolean",
|
|
396
|
+
},
|
|
397
|
+
requiredContextSlice: [],
|
|
398
|
+
scopes: null,
|
|
399
|
+
},
|
|
361
400
|
{
|
|
362
401
|
name: "useSectionEmpty",
|
|
363
402
|
signature: "useSectionEmpty(isEmpty)",
|
|
@@ -2406,7 +2445,15 @@ const CONTRACT = deepFreeze({
|
|
|
2406
2445
|
// public endpoint instead, which skips the cache, the metering and the
|
|
2407
2446
|
// workspace's provider. Publishing the host list here keeps the linter,
|
|
2408
2447
|
// the Developer guide and the agent prompt reading one source.
|
|
2409
|
-
|
|
2448
|
+
// 1.54.0: additive (sc-4399, epic 4395) — `useContainerWidth()` +
|
|
2449
|
+
// `isNarrowWidth(width)` / `NARROW_WIDTH_PX`. Built-in widgets laid
|
|
2450
|
+
// themselves out at a fixed size — UserManagement's rows alone carried
|
|
2451
|
+
// ~800px of minWidth — so a page that reflowed around them still
|
|
2452
|
+
// overflowed, because the widget inside demanded desktop width. Gallery
|
|
2453
|
+
// already measured its own box with onLayout; this promotes that one
|
|
2454
|
+
// pattern to the SDK so custom and marketplace widgets get it too,
|
|
2455
|
+
// instead of each rolling its own.
|
|
2456
|
+
version: "1.54.0",
|
|
2410
2457
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
2411
2458
|
hooks: HOOKS,
|
|
2412
2459
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -289,6 +289,38 @@ export function useSectionEmpty(isEmpty) {
|
|
|
289
289
|
}, [empty]);
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
+
/**
|
|
293
|
+
* sc-4399 — measure the width the widget's own box actually has, so it can lay
|
|
294
|
+
* itself out for the space it is in rather than for the screen. A widget in a
|
|
295
|
+
* 1-of-3 grid cell on a desktop page has phone-width room; a widget filling a
|
|
296
|
+
* phone page does not. The window width answers neither question.
|
|
297
|
+
*
|
|
298
|
+
* Spread the returned handler onto the widget's outermost primitive:
|
|
299
|
+
*
|
|
300
|
+
* const [width, onLayout] = useContainerWidth();
|
|
301
|
+
* return <View onLayout={onLayout}>{isNarrowWidth(width) ? <Cards/> : <Table/>}</View>;
|
|
302
|
+
*
|
|
303
|
+
* `onLayout` is the react-native primitive callback, so ONE implementation
|
|
304
|
+
* serves the web Player (through react-native-web) and the native export.
|
|
305
|
+
* Before the first layout the width is 0 — treat that as "not yet measured"
|
|
306
|
+
* and render the wide form, which is what `isNarrowWidth`
|
|
307
|
+
* (./container-width.js) does.
|
|
308
|
+
*
|
|
309
|
+
* Takes no context, so it is safe on every host including the Studio canvas.
|
|
310
|
+
*/
|
|
311
|
+
export function useContainerWidth() {
|
|
312
|
+
const [width, setWidth] = useState(0);
|
|
313
|
+
const onLayout = useCallback((event) => {
|
|
314
|
+
const next =
|
|
315
|
+
event && event.nativeEvent && event.nativeEvent.layout
|
|
316
|
+
? event.nativeEvent.layout.width
|
|
317
|
+
: undefined;
|
|
318
|
+
if (typeof next !== "number" || !(next > 0)) return;
|
|
319
|
+
setWidth((prev) => (prev === next ? prev : next));
|
|
320
|
+
}, []);
|
|
321
|
+
return [width, onLayout];
|
|
322
|
+
}
|
|
323
|
+
|
|
292
324
|
/**
|
|
293
325
|
* Returns the host-provided navigation surface:
|
|
294
326
|
* `{ goTo, goBack, push, replace, back, currentRoute }`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1110,6 +1110,34 @@ export function useRefresh(
|
|
|
1110
1110
|
*/
|
|
1111
1111
|
export function useSectionEmpty(isEmpty: boolean): void;
|
|
1112
1112
|
|
|
1113
|
+
/** The layout event a react-native primitive passes to `onLayout`. */
|
|
1114
|
+
export interface WidgetLayoutEvent {
|
|
1115
|
+
nativeEvent: { layout: { width: number; height: number; x: number; y: number } };
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* sc-4399 — measure the width the widget's OWN box has, so it can lay itself
|
|
1120
|
+
* out for the space it is in rather than for the screen. Spread the returned
|
|
1121
|
+
* handler onto the widget's outermost primitive; ONE implementation serves the
|
|
1122
|
+
* web Player (via react-native-web) and the native export. The width is 0
|
|
1123
|
+
* before the first layout — treat that as "not yet measured" and render the
|
|
1124
|
+
* wide form, which is what `isNarrowWidth` does.
|
|
1125
|
+
*/
|
|
1126
|
+
export function useContainerWidth(): [
|
|
1127
|
+
number,
|
|
1128
|
+
(event: WidgetLayoutEvent) => void,
|
|
1129
|
+
];
|
|
1130
|
+
|
|
1131
|
+
/** The width below which a widget should adopt its narrow form (480). */
|
|
1132
|
+
export const NARROW_WIDTH_PX: number;
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
* True when a MEASURED width is below `NARROW_WIDTH_PX`. An unmeasured width
|
|
1136
|
+
* (0) is deliberately NOT narrow, so a widget that never lays out keeps its
|
|
1137
|
+
* historical wide rendering.
|
|
1138
|
+
*/
|
|
1139
|
+
export function isNarrowWidth(width: number): boolean;
|
|
1140
|
+
|
|
1113
1141
|
/** Pass-through options for `useGeolocation().getCurrentPosition(...)`. */
|
|
1114
1142
|
export interface GeolocationOptions {
|
|
1115
1143
|
enableHighAccuracy?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -51,10 +51,12 @@ export {
|
|
|
51
51
|
useChildRenderer,
|
|
52
52
|
useRefresh,
|
|
53
53
|
useSectionEmpty,
|
|
54
|
+
useContainerWidth,
|
|
54
55
|
useGeolocation,
|
|
55
56
|
GeolocationError,
|
|
56
57
|
WidgetTree,
|
|
57
58
|
} from "./hooks.js";
|
|
59
|
+
export { isNarrowWidth, NARROW_WIDTH_PX } from "./container-width.js";
|
|
58
60
|
// REQ-WSDK-PLATFORM §6 — Tier A hooks. Each ships in a per-platform file
|
|
59
61
|
// (./clipboard.js / .native.js, ./toast.js / .native.js); index.js picks
|
|
60
62
|
// the web variant and index.native.js picks the native variant.
|
package/dist/index.native.js
CHANGED
|
@@ -51,10 +51,12 @@ export {
|
|
|
51
51
|
useChildRenderer,
|
|
52
52
|
useRefresh,
|
|
53
53
|
useSectionEmpty,
|
|
54
|
+
useContainerWidth,
|
|
54
55
|
useGeolocation,
|
|
55
56
|
GeolocationError,
|
|
56
57
|
WidgetTree,
|
|
57
58
|
} from "./hooks.js";
|
|
59
|
+
export { isNarrowWidth, NARROW_WIDTH_PX } from "./container-width.js";
|
|
58
60
|
// REQ-WSDK-PLATFORM §6 — Tier A hooks (native variants).
|
|
59
61
|
export { useClipboard, ClipboardError } from "./clipboard.native.js";
|
|
60
62
|
export { useToast } from "./toast.native.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.80.0",
|
|
4
4
|
"description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|