@veriforms/webapp-react 0.1.2 → 0.1.3
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 +11 -5
- package/dist/index.d.ts +20 -1
- package/dist/index.js +36 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
|
|
@@ -10,10 +10,10 @@ npm i @veriforms/webapp-sdk @veriforms/webapp-react react@18.3.1 react-dom@18.3.
|
|
|
10
10
|
npm i -D @veriforms/webapp-vite vite
|
|
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,12 @@ 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).
|
|
53
59
|
- `useAccess()`, `useTheme()`.
|
|
54
60
|
- `<PageLink to="admin">` — the way across pages (each page is its own access area).
|
|
55
61
|
- `<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 } 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,15 @@ 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>;
|
|
20
29
|
/** Who is signed in. */
|
|
21
30
|
export declare function useUser(): Loaded<UserInfo>;
|
|
22
31
|
/** What the visitor may do, as the server told the page (the server checks every call again). */
|
|
@@ -66,6 +75,16 @@ export declare function PageLink({ to, suffix, children, ...rest }: {
|
|
|
66
75
|
suffix?: `?${string}` | `#${string}`;
|
|
67
76
|
children?: ReactNode;
|
|
68
77
|
} & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>): import("react/jsx-runtime").JSX.Element;
|
|
78
|
+
/**
|
|
79
|
+
* A link to the platform's "Sign-in & security" page — the visitor's passkeys: rename, remove, add, remove all
|
|
80
|
+
* (since 0.1.3). Rendered only when the visitor can use passkeys here (`user().passkeysOffered`), so it never
|
|
81
|
+
* shows on an app without the e-mail code or to someone signed in with an account. The page belongs to the
|
|
82
|
+
* platform; no passkey dialog ever runs in page code. Its Back link returns to `returnTo` (default: this page).
|
|
83
|
+
*/
|
|
84
|
+
export declare function SignInSecurityLink({ returnTo, children, onClick, ...rest }: {
|
|
85
|
+
returnTo?: string;
|
|
86
|
+
children?: ReactNode;
|
|
87
|
+
} & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>): import("react/jsx-runtime").JSX.Element | null;
|
|
69
88
|
/** The platform's form for a submission or table-insert source, with its server rules mirrored. */
|
|
70
89
|
export declare function VfForm<K extends FormKey>({ source, options, className }: {
|
|
71
90
|
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,18 @@ 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
|
+
}
|
|
57
76
|
/** Who is signed in. */
|
|
58
77
|
export function useUser() {
|
|
59
78
|
return useRead(() => sdk.user(), 'user', undefined);
|
|
@@ -107,6 +126,19 @@ export function useSend(source) {
|
|
|
107
126
|
export function PageLink({ to, suffix, children, ...rest }) {
|
|
108
127
|
return _jsx("a", { ...rest, href: sdk.pageLink(to, suffix), children: children });
|
|
109
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* A link to the platform's "Sign-in & security" page — the visitor's passkeys: rename, remove, add, remove all
|
|
131
|
+
* (since 0.1.3). Rendered only when the visitor can use passkeys here (`user().passkeysOffered`), so it never
|
|
132
|
+
* shows on an app without the e-mail code or to someone signed in with an account. The page belongs to the
|
|
133
|
+
* platform; no passkey dialog ever runs in page code. Its Back link returns to `returnTo` (default: this page).
|
|
134
|
+
*/
|
|
135
|
+
export function SignInSecurityLink({ returnTo, children, onClick, ...rest }) {
|
|
136
|
+
const user = useUser();
|
|
137
|
+
if (!user.data?.passkeysOffered)
|
|
138
|
+
return null;
|
|
139
|
+
return (_jsx("a", { ...rest, href: "#", onClick: (e) => { onClick?.(e); if (e.defaultPrevented)
|
|
140
|
+
return; e.preventDefault(); sdk.signInSecurity(returnTo); }, children: children }));
|
|
141
|
+
}
|
|
110
142
|
/** The platform's form for a submission or table-insert source, with its server rules mirrored. */
|
|
111
143
|
export function VfForm({ source, options, className }) {
|
|
112
144
|
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.3",
|
|
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.3",
|
|
40
40
|
"react": "^18.3.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|