@veriforms/webapp-react 0.1.2 → 0.1.4
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 +16 -6
- package/dist/index.d.ts +27 -1
- package/dist/index.js +45 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# @veriforms/webapp-react
|
|
2
2
|
|
|
3
|
-
React hooks and components for VeriForms web apps built in code
|
|
3
|
+
React hooks and components for VeriForms web apps built in code,
|
|
4
4
|
over `@veriforms/webapp-sdk`.
|
|
5
5
|
|
|
6
6
|
## Install
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
9
|
npm i @veriforms/webapp-sdk @veriforms/webapp-react react@18.3.1 react-dom@18.3.1
|
|
10
|
-
npm i -D @veriforms/webapp-vite vite
|
|
10
|
+
npm i -D @veriforms/webapp-vite vite@6 # or let `vf app init <appId>` write the whole project
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
The packages are public on npm (owner decision 2026-12-03). Web apps built in code are open to
|
|
14
|
+
the Enterprise and Enterprise Plus plans and to other accounts VeriForms enabled (owner decision
|
|
15
|
+
2026-12-04).
|
|
16
|
+
The three packages are released together at one version
|
|
17
17
|
(`webapp-react` names the SDK exactly). Install React at the version the platform serves (18.3.1) —
|
|
18
18
|
the upload compares your `package-lock.json`.
|
|
19
19
|
|
|
@@ -50,6 +50,16 @@ function Book() {
|
|
|
50
50
|
same error; use it where the code goes on after the write, inside `try`/`catch`
|
|
51
51
|
(`try { await book.send(body); close(); } catch { /* book.error is set */ }`). Calling `send`
|
|
52
52
|
without a `catch` turns a refusal into an unhandled rejection.
|
|
53
|
+
- `useKnowledgeSearch(source, question)` (0.1.3) — a `knowledge` source: `data` is
|
|
54
|
+
`{ status: 'ok', passages, sourceLine }` or `{ status: 'no_match' | 'empty', message }`; a refusal
|
|
55
|
+
(an internal base on an app open to people outside the space, a missing base) is `error`, a
|
|
56
|
+
`KnowledgeSearchError` — never an empty answer. Show `sourceLine` under anything built from the
|
|
57
|
+
passages. No question, no search: pass the question the visitor submitted, not every keystroke
|
|
58
|
+
(each search is metered).
|
|
59
|
+
- `useValues(keys?)` (0.1.4) — Definitions values the app's `config.json` declares in `"values"`:
|
|
60
|
+
`data` maps each key to its text, formatted in the app's language as `{{value:<key>}}` writes it.
|
|
61
|
+
A key that is not declared, or a value the space does not serve, is `error`, a `ValuesError` with
|
|
62
|
+
its `code` and `keys` — never an empty text. The draft (`vf app dev`) serves the real values too.
|
|
53
63
|
- `useAccess()`, `useTheme()`.
|
|
54
64
|
- `<PageLink to="admin">` — the way across pages (each page is its own access area).
|
|
55
65
|
- `<VfForm source="booking" />` — the platform's form with its server rules mirrored.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AnchorHTMLAttributes, type ReactNode } from 'react';
|
|
2
|
-
import type { FormKey, PageName, ParamsOf, ReadKey, ResultOf, RowOf, SendKey, SendResultOf, BodyOf, SubmissionsReadKey, FieldsOf, TableKey, TablePage, SubmissionsPage, UserInfo, WriteOptions, RoleName, SourceKey } from '@veriforms/webapp-sdk';
|
|
2
|
+
import type { FormKey, PageName, ParamsOf, ReadKey, ResultOf, RowOf, SendKey, SendResultOf, BodyOf, SubmissionsReadKey, FieldsOf, TableKey, TablePage, SubmissionsPage, UserInfo, WriteOptions, RoleName, SourceKey, KnowledgeKey, KnowledgeAnswer, ValueKey } from '@veriforms/webapp-sdk';
|
|
3
3
|
/** What a read hook holds: the data once loaded, the error as raised, and a way to read again. */
|
|
4
4
|
export interface Loaded<T> {
|
|
5
5
|
data: T | undefined;
|
|
@@ -17,6 +17,22 @@ export declare function useTable<K extends TableKey>(source: K, params?: Partial
|
|
|
17
17
|
}): Loaded<TablePage<RowOf<K>>>;
|
|
18
18
|
/** This web app's own submissions, read back through a veriforms-data source. */
|
|
19
19
|
export declare function useSubmissions<K extends SubmissionsReadKey>(source: K, params?: Partial<ParamsOf<K>>): Loaded<SubmissionsPage<FieldsOf<K>>>;
|
|
20
|
+
/**
|
|
21
|
+
* Asks a knowledge source one question (since 0.1.3). `data` is the answer: `status: 'ok'` with the
|
|
22
|
+
* passages and the server-built `sourceLine` (show it under what you build from them), or `no_match` /
|
|
23
|
+
* `empty` with a `message` to show. A refusal is `error` — a `KnowledgeSearchError`
|
|
24
|
+
* (`sdk.isKnowledgeRefusal(error)` for the base's rule or a missing base) — never an empty answer.
|
|
25
|
+
* No question (null, '' or blanks): nothing is searched and nothing is loading. Each search is metered,
|
|
26
|
+
* so pass the question the visitor submitted, not every keystroke.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useKnowledgeSearch<K extends KnowledgeKey>(source: K, question: string | null | undefined): Loaded<KnowledgeAnswer>;
|
|
29
|
+
/**
|
|
30
|
+
* Definitions values the app's config.json declares in "values" (since 0.1.4): `data` maps each key to
|
|
31
|
+
* its text as `{{value:<key>}}` writes it (formatted — parse a number yourself). Without `keys`, every
|
|
32
|
+
* declared value. A refusal (an undeclared key, a value the space does not serve) is `error`, a
|
|
33
|
+
* `ValuesError` naming the code and the keys — never an empty text.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useValues<K extends ValueKey>(keys?: readonly K[]): Loaded<Record<K, string>>;
|
|
20
36
|
/** Who is signed in. */
|
|
21
37
|
export declare function useUser(): Loaded<UserInfo>;
|
|
22
38
|
/** What the visitor may do, as the server told the page (the server checks every call again). */
|
|
@@ -66,6 +82,16 @@ export declare function PageLink({ to, suffix, children, ...rest }: {
|
|
|
66
82
|
suffix?: `?${string}` | `#${string}`;
|
|
67
83
|
children?: ReactNode;
|
|
68
84
|
} & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>): import("react/jsx-runtime").JSX.Element;
|
|
85
|
+
/**
|
|
86
|
+
* A link to the platform's "Sign-in & security" page — the visitor's passkeys: rename, remove, add, remove all
|
|
87
|
+
* (since 0.1.3). Rendered only when the visitor can use passkeys here (`user().passkeysOffered`), so it never
|
|
88
|
+
* shows on an app without the e-mail code or to someone signed in with an account. The page belongs to the
|
|
89
|
+
* platform; no passkey dialog ever runs in page code. Its Back link returns to `returnTo` (default: this page).
|
|
90
|
+
*/
|
|
91
|
+
export declare function SignInSecurityLink({ returnTo, children, onClick, ...rest }: {
|
|
92
|
+
returnTo?: string;
|
|
93
|
+
children?: ReactNode;
|
|
94
|
+
} & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>): import("react/jsx-runtime").JSX.Element | null;
|
|
69
95
|
/** The platform's form for a submission or table-insert source, with its server rules mirrored. */
|
|
70
96
|
export declare function VfForm<K extends FormKey>({ source, options, className }: {
|
|
71
97
|
source: K;
|
package/dist/index.js
CHANGED
|
@@ -8,15 +8,22 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
8
8
|
// platform says a source's rows changed on this page (vf:data-changed).
|
|
9
9
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
10
|
import * as sdk from '@veriforms/webapp-sdk';
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* One read, re-run when its key changes or reload() is called; a stale answer never overwrites a newer one.
|
|
13
|
+
* `enabled === false` reads nothing (and is not loading): a search without a question.
|
|
14
|
+
*/
|
|
15
|
+
function useRead(read, key, sourceKey, enabled = true) {
|
|
16
|
+
const [state, setState] = useState({ loading: enabled });
|
|
14
17
|
const [tick, setTick] = useState(0);
|
|
15
18
|
const run = useRef(0);
|
|
16
19
|
const readRef = useRef(read);
|
|
17
20
|
readRef.current = read;
|
|
18
21
|
useEffect(() => {
|
|
19
22
|
const mine = ++run.current;
|
|
23
|
+
if (!enabled) {
|
|
24
|
+
setState({ loading: false });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
20
27
|
setState((s) => ({ data: s.data, error: undefined, loading: true }));
|
|
21
28
|
let promise;
|
|
22
29
|
try {
|
|
@@ -30,7 +37,7 @@ function useRead(read, key, sourceKey) {
|
|
|
30
37
|
promise.then((data) => { if (run.current === mine)
|
|
31
38
|
setState({ data, loading: false }); }, (error) => { if (run.current === mine)
|
|
32
39
|
setState({ error, loading: false }); });
|
|
33
|
-
}, [key, tick]);
|
|
40
|
+
}, [key, tick, enabled]);
|
|
34
41
|
// The platform tells the page when a source's rows changed here (a confirmed proposal, an action).
|
|
35
42
|
useEffect(() => {
|
|
36
43
|
if (!sourceKey)
|
|
@@ -54,6 +61,27 @@ export function useTable(source, params) {
|
|
|
54
61
|
export function useSubmissions(source, params) {
|
|
55
62
|
return useRead(() => sdk.data.list(source, params), keyOf('submissions', source, params), source);
|
|
56
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Asks a knowledge source one question (since 0.1.3). `data` is the answer: `status: 'ok'` with the
|
|
66
|
+
* passages and the server-built `sourceLine` (show it under what you build from them), or `no_match` /
|
|
67
|
+
* `empty` with a `message` to show. A refusal is `error` — a `KnowledgeSearchError`
|
|
68
|
+
* (`sdk.isKnowledgeRefusal(error)` for the base's rule or a missing base) — never an empty answer.
|
|
69
|
+
* No question (null, '' or blanks): nothing is searched and nothing is loading. Each search is metered,
|
|
70
|
+
* so pass the question the visitor submitted, not every keystroke.
|
|
71
|
+
*/
|
|
72
|
+
export function useKnowledgeSearch(source, question) {
|
|
73
|
+
const q = (question ?? '').trim();
|
|
74
|
+
return useRead(() => sdk.knowledge.search(source, q), keyOf('knowledge', source, q), undefined, q.length > 0);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Definitions values the app's config.json declares in "values" (since 0.1.4): `data` maps each key to
|
|
78
|
+
* its text as `{{value:<key>}}` writes it (formatted — parse a number yourself). Without `keys`, every
|
|
79
|
+
* declared value. A refusal (an undeclared key, a value the space does not serve) is `error`, a
|
|
80
|
+
* `ValuesError` naming the code and the keys — never an empty text.
|
|
81
|
+
*/
|
|
82
|
+
export function useValues(keys) {
|
|
83
|
+
return useRead(() => sdk.values.get(keys), keyOf('values', keys ?? null), undefined);
|
|
84
|
+
}
|
|
57
85
|
/** Who is signed in. */
|
|
58
86
|
export function useUser() {
|
|
59
87
|
return useRead(() => sdk.user(), 'user', undefined);
|
|
@@ -107,6 +135,19 @@ export function useSend(source) {
|
|
|
107
135
|
export function PageLink({ to, suffix, children, ...rest }) {
|
|
108
136
|
return _jsx("a", { ...rest, href: sdk.pageLink(to, suffix), children: children });
|
|
109
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* A link to the platform's "Sign-in & security" page — the visitor's passkeys: rename, remove, add, remove all
|
|
140
|
+
* (since 0.1.3). Rendered only when the visitor can use passkeys here (`user().passkeysOffered`), so it never
|
|
141
|
+
* shows on an app without the e-mail code or to someone signed in with an account. The page belongs to the
|
|
142
|
+
* platform; no passkey dialog ever runs in page code. Its Back link returns to `returnTo` (default: this page).
|
|
143
|
+
*/
|
|
144
|
+
export function SignInSecurityLink({ returnTo, children, onClick, ...rest }) {
|
|
145
|
+
const user = useUser();
|
|
146
|
+
if (!user.data?.passkeysOffered)
|
|
147
|
+
return null;
|
|
148
|
+
return (_jsx("a", { ...rest, href: "#", onClick: (e) => { onClick?.(e); if (e.defaultPrevented)
|
|
149
|
+
return; e.preventDefault(); sdk.signInSecurity(returnTo); }, children: children }));
|
|
150
|
+
}
|
|
110
151
|
/** The platform's form for a submission or table-insert source, with its server rules mirrored. */
|
|
111
152
|
export function VfForm({ source, options, className }) {
|
|
112
153
|
const ref = useRef(null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veriforms/webapp-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "React hooks and components for VeriForms web apps built in code: data sources, tables, submissions, the visitor, access, page links and the platform's form — over @veriforms/webapp-sdk.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"veriforms",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"prepublishOnly": "npm run build"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@veriforms/webapp-sdk": "0.1.
|
|
39
|
+
"@veriforms/webapp-sdk": "0.1.4",
|
|
40
40
|
"react": "^18.3.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|