@colixsystems/widget-sdk 0.222.0 → 0.223.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 +18 -3
- package/dist/contract.cjs +5 -1
- package/dist/contract.js +5 -1
- package/dist/hooks.js +4 -3
- package/dist/index.d.ts +6 -3
- package/package.json +1 -1
- package/src/contract.js +5 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
24
24
|
| **CORE** | `useUser()` | `{ id, email, displayName, photoUrl, roles, groupIds }` | `ctx.user` (host-built context, **camelCase** — not a wire payload; `id` null when anonymous) — no scope. `photoUrl` is the user's own profile photo as an absolute URL, or `null`. |
|
|
25
25
|
| **CORE** | `useUserPhoto()` | `{ url, canEdit, upload, remove, uploading, error }` | `ctx.user` + the optional `ctx.account` — no scope. Changes the signed-in user's OWN profile photo. `canEdit` is false when nobody is signed in or the host cannot change it; `upload` / `remove` then reject. |
|
|
26
26
|
| **CORE** | `useAnonymousAccount()` | `{ supported, canCreate, creating, error, create }` | The optional `ctx.account.anonymous` — no scope. Offers an account with a generated login code and password and no email. `create()` opens the app's own dialog, which confirms, creates the account, shows the pair once and signs the visitor in; the widget never receives the pair and `create()` resolves `{ created: true }`. `supported` is false where the workspace has not turned anonymous accounts on, on the Builder canvas, in a preview and for a badge counter; `canCreate` is false while someone is signed in. |
|
|
27
|
-
| **CORE** | `useNavigation()` | `{ goTo, goBack, push, replace, back, currentRoute, openLink }` | `ctx.navigation` — no scope. `goTo(pageIdOrSlug, params?)` accepts a page UUID (a `pageRef` prop) **or its slug** (a row's page-key field) — both hosts resolve either (`openLink` for a link of unknown shape; a known external URL can also use the `Linking` primitive) |
|
|
27
|
+
| **CORE** | `useNavigation()` | `{ goTo, goToStartPage, goBack, push, replace, back, currentRoute, openLink }` | `ctx.navigation` — no scope. `goTo(pageIdOrSlug, params?)` accepts a page UUID (a `pageRef` prop) **or its slug** (a row's page-key field) — both hosts resolve either; `goToStartPage()` opens the signed-in user's own start page (`openLink` for a link of unknown shape; a known external URL can also use the `Linking` primitive) |
|
|
28
28
|
| **CORE** | `useFilePreview(file)` | `{ uri }` | No scope. A temporary address an `<Image>` can show for a file the person picked but has not uploaded yet (a photo in a composer). Native picks use their own uri; on the web the SDK creates and releases an object URL, which widgets may not do themselves. `uri` is null for no file. |
|
|
29
29
|
| **CORE** | `usePageBadge(count)` | `{ supported }` | `ctx.navigation.setBadge` — no scope. Puts `count` on the menu entry or tab of the page the widget is on (a chat's unread messages). The host sums the page's widgets and keeps the last count after the widget leaves the screen, until it reports again; `0` clears this widget's share. `supported` is false where the host draws no page badges (the Builder canvas). |
|
|
30
30
|
| **CORE** | `useRouteParams()` | `{ [paramKey]: value }` | `ctx.navigation.currentRoute.params` — no scope. The nav params the previous page passed via `goTo(pageId, params)`; the flat accessor for master→detail (read `recordId` on a detail page). Empty object when none. |
|
|
@@ -84,7 +84,22 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
84
84
|
|
|
85
85
|
## Status
|
|
86
86
|
|
|
87
|
-
`v0.
|
|
87
|
+
`v0.223.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**.
|
|
88
|
+
|
|
89
|
+
### What's new in 0.223.0 (contract 1.179.0)
|
|
90
|
+
|
|
91
|
+
**A widget can send the user back to their start page — `useNavigation().goToStartPage()`.** An app opens on a start page that can differ per user, because page access is restricted per group. A "Back to start" or "Home" button should take each user to their own start page rather than to one hard-coded page they may not be allowed to open.
|
|
92
|
+
|
|
93
|
+
```jsx
|
|
94
|
+
import { useNavigation, Button } from "@colixsystems/widget-sdk";
|
|
95
|
+
|
|
96
|
+
export default function BackToStart() {
|
|
97
|
+
const { goToStartPage } = useNavigation();
|
|
98
|
+
return <Button title="Back to the start page" onPress={() => goToStartPage()} />;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The web Player and the exported app both go to the page the app opens on for the signed-in user. It takes no arguments and carries no params. It is a no-op where there is no live router (the Studio canvas, a badge counter). Additive.
|
|
88
103
|
|
|
89
104
|
### What's new in 0.222.0 (contract 1.178.0)
|
|
90
105
|
|
|
@@ -2752,7 +2767,7 @@ import { defineWidget, validateManifest, useDatastoreQuery, Text, View } from "@
|
|
|
2752
2767
|
|
|
2753
2768
|
- `defineWidget({ manifest, component })` — validates the manifest and produces a widget module the host can register.
|
|
2754
2769
|
- `validateManifest(m)` / `validatePropertySchema(s)` / `validateProps(schema, props)` — shape validation; no third-party deps.
|
|
2755
|
-
- `useDatastoreQuery`, `useDatastoreRecord`, `useDatastoreSchema`, `useDatastoreMutation`, `useDirectory`, `useUsers`, `useGroups`, `useRecordPermissions`, `useAsset`, `useWidgetEvent`, `useWidgetInput`, `usePayments`, `useSendNotification`, `useTheme`, `useI18n`, `useUser`, `useNavigation`, `useRouteParams`, `usePageContext`, `useWidgetRoute`, `useChildRenderer`, `useClipboard`, `useToast` — hooks that read from the host-provided `WidgetContext` (or, for `useClipboard`, the platform clipboard API directly). `useDirectory(query?)` returns `{ users, loading, error, refetch }` (each user `{ id, name, role }`) and requires the `directory.read:users` scope. `useUsers(query?)` returns `{ users, loading, error, refetch, invite, deactivate, reactivate, remove }` and requires `users.read:*` (mutations also need `users.write:*`); rejections are a `DirectoryError`. `useGroups(query?)` returns `{ groups, loading, error, refetch, create, remove, addMember, removeMember }` and requires `groups.read:*` (mutations also need `groups.write:*`). `usePayments()` returns `{ requestPayment, getPayment }` and requires the `payments.charge:appUser` scope; `requestPayment(...)` rejects with a `PaymentError` carrying `code`, the server's user-safe `message`, and `retryable` (`false` = this charge cannot succeed until the workspace, manifest, or amount changes — show the message, not a retry). `useSendNotification()` returns `{ send, sending, error }` and requires the `notifications.send:appUser` scope; `send({ recipient_user_id, title, body, link?, payload? })` notifies one app user in the same workspace (cross-workspace `recipient_user_id` is rejected), must be called from an event handler rather than render, and rejects with a `NotificationError`. `useUser()` returns the active end-user identity `{ id, email, displayName, roles, groupIds }` (camelCase — the host-built context object, not a wire payload; `id` is `null` for anonymous / preview). `useNavigation()` returns `{ goTo, goBack, push, replace, back, currentRoute, openLink }` for internal page navigation; `openLink(link)` follows an author- or data-supplied link of unknown shape through the host's shared resolver (in-app page → internal route, off-app http(s) → opened outside, unsafe → refused) and is the safe choice for any value your code did not construct, while `Linking.openURL(url)` is for an external URL you built yourself. `useRouteParams()` returns the current route's params object (`currentRoute.params`) — the flat master→detail accessor; read a param off it (e.g. `recordId`), never call it. `useDatastoreRecord(tableId, recordId)` returns `{ data, loading, error, refetch }` for a single record (data is one row or null). `useDatastoreSchema(tableId)` returns `{ schema, loading, error, refetch }` where `schema` is `{ id, name, columns: [{ id, name, data_type, required, relation_type, target_table_id, is_identification }] }` (structure only, no row data; snake_case verbatim) — use it to resolve a stored `columnId` to its column type at runtime; requires the `datastore.read:<table>` scope. `useAsset(fileId)` returns `{ url, file, loading, error, refetch }` — the `url` is an absolute URL composed against the host's API base. `useChildRenderer()` returns `{ renderNode(node) }` — container widgets call it to render arbitrary child page-tree nodes (prefer the `WidgetTree` component for the common case). `useWidgetInput(inputName)` returns the latest payload a sibling widget published on the event the page author wired to this widget's declared `inputs` entry (`undefined` when unwired or not yet published).
|
|
2770
|
+
- `useDatastoreQuery`, `useDatastoreRecord`, `useDatastoreSchema`, `useDatastoreMutation`, `useDirectory`, `useUsers`, `useGroups`, `useRecordPermissions`, `useAsset`, `useWidgetEvent`, `useWidgetInput`, `usePayments`, `useSendNotification`, `useTheme`, `useI18n`, `useUser`, `useNavigation`, `useRouteParams`, `usePageContext`, `useWidgetRoute`, `useChildRenderer`, `useClipboard`, `useToast` — hooks that read from the host-provided `WidgetContext` (or, for `useClipboard`, the platform clipboard API directly). `useDirectory(query?)` returns `{ users, loading, error, refetch }` (each user `{ id, name, role }`) and requires the `directory.read:users` scope. `useUsers(query?)` returns `{ users, loading, error, refetch, invite, deactivate, reactivate, remove }` and requires `users.read:*` (mutations also need `users.write:*`); rejections are a `DirectoryError`. `useGroups(query?)` returns `{ groups, loading, error, refetch, create, remove, addMember, removeMember }` and requires `groups.read:*` (mutations also need `groups.write:*`). `usePayments()` returns `{ requestPayment, getPayment }` and requires the `payments.charge:appUser` scope; `requestPayment(...)` rejects with a `PaymentError` carrying `code`, the server's user-safe `message`, and `retryable` (`false` = this charge cannot succeed until the workspace, manifest, or amount changes — show the message, not a retry). `useSendNotification()` returns `{ send, sending, error }` and requires the `notifications.send:appUser` scope; `send({ recipient_user_id, title, body, link?, payload? })` notifies one app user in the same workspace (cross-workspace `recipient_user_id` is rejected), must be called from an event handler rather than render, and rejects with a `NotificationError`. `useUser()` returns the active end-user identity `{ id, email, displayName, roles, groupIds }` (camelCase — the host-built context object, not a wire payload; `id` is `null` for anonymous / preview). `useNavigation()` returns `{ goTo, goToStartPage, goBack, push, replace, back, currentRoute, openLink }` for internal page navigation; `goToStartPage()` opens the signed-in user's own start page (the page the app opens on for them); `openLink(link)` follows an author- or data-supplied link of unknown shape through the host's shared resolver (in-app page → internal route, off-app http(s) → opened outside, unsafe → refused) and is the safe choice for any value your code did not construct, while `Linking.openURL(url)` is for an external URL you built yourself. `useRouteParams()` returns the current route's params object (`currentRoute.params`) — the flat master→detail accessor; read a param off it (e.g. `recordId`), never call it. `useDatastoreRecord(tableId, recordId)` returns `{ data, loading, error, refetch }` for a single record (data is one row or null). `useDatastoreSchema(tableId)` returns `{ schema, loading, error, refetch }` where `schema` is `{ id, name, columns: [{ id, name, data_type, required, relation_type, target_table_id, is_identification }] }` (structure only, no row data; snake_case verbatim) — use it to resolve a stored `columnId` to its column type at runtime; requires the `datastore.read:<table>` scope. `useAsset(fileId)` returns `{ url, file, loading, error, refetch }` — the `url` is an absolute URL composed against the host's API base. `useChildRenderer()` returns `{ renderNode(node) }` — container widgets call it to render arbitrary child page-tree nodes (prefer the `WidgetTree` component for the common case). `useWidgetInput(inputName)` returns the latest payload a sibling widget published on the event the page author wired to this widget's declared `inputs` entry (`undefined` when unwired or not yet published).
|
|
2756
2771
|
- `WidgetTree({ node })` — component that renders an author-authored child node through the host's renderer; used by Tabs / Card / custom containers to host arbitrary child widgets.
|
|
2757
2772
|
- `Text`, `View`, `Pressable`, `Image`, `ScrollView`, `TextInput`, `FlatList`, `SectionList`, `ActivityIndicator`, `Switch`, `StyleSheet`, `Linking`, `Icon`, `DateTimePicker` — re-exported from `react-native` (the RN primitives) or implemented in the SDK (`Icon` wraps `lucide-react-native`; `DateTimePicker` wraps `@react-native-community/datetimepicker` on native and renders `<input type="date|time|datetime-local">` directly on web because the RN library has no react-native-web mapping). The web build aliases `react-native` to `react-native-web` so the RN-re-exported primitives render in the browser without any per-platform code; the exported Expo app's Metro bundler resolves the real `react-native` library. `Linking` is a static API (`Linking.openURL(url)`) — use it for external URLs, and use `useNavigation().goTo(pageId)` for internal page navigation. See https://reactnative.dev/docs/ for per-component props.
|
|
2758
2773
|
- `Overlay` — the screen-level overlay (sc-6607). `<Overlay visible={!!preview} onRequestClose={() => setPreview(null)} size="full">…</Overlay>` renders its children OUTSIDE the widget's layout box on both hosts (web portals it to the document root, native uses the OS modal), so no clipping card, `ScrollView` or neighbouring widget can cut off a document/media preview, lightbox or confirm dialog — which absolute positioning inside the widget cannot achieve on either platform. Children stay in your own React tree, so state and hooks work normally. `onRequestClose` carries the backdrop press, Escape on web, and the Android back button; `size` is `sm` | `md` (default) | `lg` | `full`; the scrim, surface, radius, padding and elevation come from the workspace theme. An anchored dropdown still belongs inside your own root.
|
package/dist/contract.cjs
CHANGED
|
@@ -1128,6 +1128,8 @@ const HOOKS = [
|
|
|
1128
1128
|
goTo:
|
|
1129
1129
|
"(pageIdOrSlug: string, params?: object) => void — a page's UUID (a pageRef prop) OR its SLUG (e.g. a row's page-key field); both hosts resolve either. There is NO page-name lookup: a slug is the only data-carried navigation key.",
|
|
1130
1130
|
openLink: "(link: string) => boolean",
|
|
1131
|
+
goToStartPage:
|
|
1132
|
+
"() => void — opens the signed-in user's own start page, the page the app opens on for them (it can differ per user, since page access is restricted per group). Use it for a 'back to start' or 'home' button instead of hard-coding a page. A no-op where there is no live router (the Studio canvas, a badge counter).",
|
|
1131
1133
|
goBack: "() => void",
|
|
1132
1134
|
push: "(pageIdOrSlug: string, params?: object) => void",
|
|
1133
1135
|
replace: "(pageIdOrSlug: string, params?: object) => void",
|
|
@@ -5878,7 +5880,9 @@ const CONTRACT = deepFreeze({
|
|
|
5878
5880
|
// edge behind the card's content, with a `scrim` on the text's edge and
|
|
5879
5881
|
// an `imagePosition` for the crop. Children may be a function taking
|
|
5880
5882
|
// `{ colors, onImage }`: the theme colours as they read over the picture.
|
|
5881
|
-
|
|
5883
|
+
// 1.179.0: additive (sc-11253) — `useNavigation().goToStartPage()` opens
|
|
5884
|
+
// the signed-in user's own start page on both hosts.
|
|
5885
|
+
version: "1.179.0",
|
|
5882
5886
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
5883
5887
|
hooks: HOOKS,
|
|
5884
5888
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -1128,6 +1128,8 @@ const HOOKS = [
|
|
|
1128
1128
|
goTo:
|
|
1129
1129
|
"(pageIdOrSlug: string, params?: object) => void — a page's UUID (a pageRef prop) OR its SLUG (e.g. a row's page-key field); both hosts resolve either. There is NO page-name lookup: a slug is the only data-carried navigation key.",
|
|
1130
1130
|
openLink: "(link: string) => boolean",
|
|
1131
|
+
goToStartPage:
|
|
1132
|
+
"() => void — opens the signed-in user's own start page, the page the app opens on for them (it can differ per user, since page access is restricted per group). Use it for a 'back to start' or 'home' button instead of hard-coding a page. A no-op where there is no live router (the Studio canvas, a badge counter).",
|
|
1131
1133
|
goBack: "() => void",
|
|
1132
1134
|
push: "(pageIdOrSlug: string, params?: object) => void",
|
|
1133
1135
|
replace: "(pageIdOrSlug: string, params?: object) => void",
|
|
@@ -5874,7 +5876,9 @@ const CONTRACT = deepFreeze({
|
|
|
5874
5876
|
// edge behind the card's content, with a `scrim` on the text's edge and
|
|
5875
5877
|
// an `imagePosition` for the crop. Children may be a function taking
|
|
5876
5878
|
// `{ colors, onImage }`: the theme colours as they read over the picture.
|
|
5877
|
-
|
|
5879
|
+
// 1.179.0: additive (sc-11253) — `useNavigation().goToStartPage()` opens
|
|
5880
|
+
// the signed-in user's own start page on both hosts.
|
|
5881
|
+
version: "1.179.0",
|
|
5878
5882
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
5879
5883
|
hooks: HOOKS,
|
|
5880
5884
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -682,10 +682,11 @@ export function useContainerWidth() {
|
|
|
682
682
|
|
|
683
683
|
/**
|
|
684
684
|
* Returns the host-provided navigation surface:
|
|
685
|
-
* `{ goTo, goBack, push, replace, back, currentRoute }`.
|
|
685
|
+
* `{ goTo, goToStartPage, goBack, push, replace, back, currentRoute }`.
|
|
686
686
|
*
|
|
687
|
-
* `goTo(pageId, params?)` navigates to an internal app page. `
|
|
688
|
-
*
|
|
687
|
+
* `goTo(pageId, params?)` navigates to an internal app page. `goToStartPage()`
|
|
688
|
+
* opens the signed-in user's own start page, which can differ per user.
|
|
689
|
+
* `goBack()` pops the stack. `push` / `replace` / `back` are aliases that map to
|
|
689
690
|
* the platform's native navigator (react-router on web, react-navigation
|
|
690
691
|
* on native). Missing methods degrade to no-ops on the Studio canvas
|
|
691
692
|
* preview, where there is no live router.
|
package/dist/index.d.ts
CHANGED
|
@@ -765,6 +765,7 @@ export interface WidgetContext<TProps = unknown> {
|
|
|
765
765
|
};
|
|
766
766
|
navigation: {
|
|
767
767
|
goTo(pageId: string, params?: Record<string, string>): void;
|
|
768
|
+
goToStartPage(): void;
|
|
768
769
|
goBack(): void;
|
|
769
770
|
push(pageId: string, params?: Record<string, unknown>): void;
|
|
770
771
|
replace(pageId: string, params?: Record<string, unknown>): void;
|
|
@@ -2019,12 +2020,14 @@ export function useFill(): boolean;
|
|
|
2019
2020
|
|
|
2020
2021
|
/**
|
|
2021
2022
|
* The host-provided navigation surface. `goTo(pageId, params?)` navigates
|
|
2022
|
-
* to an internal app page; `goBack()` pops the stack.
|
|
2023
|
-
*
|
|
2024
|
-
*
|
|
2023
|
+
* to an internal app page; `goBack()` pops the stack. `goToStartPage()`
|
|
2024
|
+
* opens the signed-in user's own start page, which can differ per user.
|
|
2025
|
+
* Missing methods degrade to no-ops on the Studio canvas preview where no
|
|
2026
|
+
* live router is mounted. For external URLs use the `Linking` primitive.
|
|
2025
2027
|
*/
|
|
2026
2028
|
export function useNavigation(): {
|
|
2027
2029
|
goTo(pageId: string, params?: Record<string, unknown>): void;
|
|
2030
|
+
goToStartPage(): void;
|
|
2028
2031
|
goBack(): void;
|
|
2029
2032
|
push(pageId: string, params?: Record<string, unknown>): void;
|
|
2030
2033
|
replace(pageId: string, params?: Record<string, unknown>): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.223.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
|
@@ -1128,6 +1128,8 @@ const HOOKS = [
|
|
|
1128
1128
|
goTo:
|
|
1129
1129
|
"(pageIdOrSlug: string, params?: object) => void — a page's UUID (a pageRef prop) OR its SLUG (e.g. a row's page-key field); both hosts resolve either. There is NO page-name lookup: a slug is the only data-carried navigation key.",
|
|
1130
1130
|
openLink: "(link: string) => boolean",
|
|
1131
|
+
goToStartPage:
|
|
1132
|
+
"() => void — opens the signed-in user's own start page, the page the app opens on for them (it can differ per user, since page access is restricted per group). Use it for a 'back to start' or 'home' button instead of hard-coding a page. A no-op where there is no live router (the Studio canvas, a badge counter).",
|
|
1131
1133
|
goBack: "() => void",
|
|
1132
1134
|
push: "(pageIdOrSlug: string, params?: object) => void",
|
|
1133
1135
|
replace: "(pageIdOrSlug: string, params?: object) => void",
|
|
@@ -5874,7 +5876,9 @@ const CONTRACT = deepFreeze({
|
|
|
5874
5876
|
// edge behind the card's content, with a `scrim` on the text's edge and
|
|
5875
5877
|
// an `imagePosition` for the crop. Children may be a function taking
|
|
5876
5878
|
// `{ colors, onImage }`: the theme colours as they read over the picture.
|
|
5877
|
-
|
|
5879
|
+
// 1.179.0: additive (sc-11253) — `useNavigation().goToStartPage()` opens
|
|
5880
|
+
// the signed-in user's own start page on both hosts.
|
|
5881
|
+
version: "1.179.0",
|
|
5878
5882
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
5879
5883
|
hooks: HOOKS,
|
|
5880
5884
|
primitives: PRIMITIVES,
|