@grafctory/clay 0.0.0-stage → 0.5.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/dist/board.js ADDED
@@ -0,0 +1,222 @@
1
+ /*
2
+ * Copyright © 2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Shared status board.
18
+ *
19
+ * Offers the components of an interface one board to tell what the system is doing and has done, wherever they sit
20
+ * in the page: a component running an operation or catching an issue puts it up as a post without knowing who shows
21
+ * it, and a component showing posts renders them, as a transient toast, a note in the page or a diagnostic panel,
22
+ * without knowing who put them up, so concurrent sources never paint over one another.
23
+ *
24
+ * Posts stand until they are cleared, and each keeps an identity of its own, so a source updates the post it put up
25
+ * as its operation moves on, and a reader tells a new post from one it has already shown.
26
+ *
27
+ * Issues nothing in the interface caught are taken up as well: a broken script and an unhandled rejection are raised
28
+ * on the outermost board as they reach the page, so an exchange whose rejection went unattended is shown rather than
29
+ * logged, and once only however many boards are nested, since no component inside any of them can claim it.
30
+ *
31
+ * Posting and reading are offered apart, so a component only posting never renders because posts change.
32
+ *
33
+ * @module
34
+ */
35
+ import { assert } from "@grafctory/core";
36
+ import { some } from "@grafctory/core/arrays";
37
+ import { clip } from "@grafctory/core/strings";
38
+ import { equals, immutable } from "@grafctory/core/values";
39
+ import { isProblem, toProblem } from "@grafctory/http/success";
40
+ import { createContext, createElement } from "preact";
41
+ import { useContext, useEffect, useState } from "preact/hooks";
42
+ /**
43
+ * The longest excerpt of machine-readable details quoted in a message.
44
+ */
45
+ const ExcerptLength = 100;
46
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47
+ /**
48
+ * The board seen outside any {@link Board}, posting nowhere, logging raised issues to the console and clearing nothing.
49
+ */
50
+ const nowhere = immutable({
51
+ post: toPost,
52
+ raise: issue => {
53
+ console.error("unhandled issue outside Board context", issue);
54
+ return toFailure(issue);
55
+ },
56
+ clear: () => { }
57
+ });
58
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59
+ /**
60
+ * The board provided by the enclosing {@link Board}, as returned by {@link useBoard}; outside any, {@link nowhere}.
61
+ */
62
+ const BoardContext = createContext(nowhere);
63
+ /**
64
+ * The posts standing on the enclosing {@link Board}, oldest first, as returned by {@link usePosts}; outside any, none.
65
+ *
66
+ * Kept apart from {@link BoardContext}, so a component only posting never renders because posts change.
67
+ */
68
+ const PostsContext = createContext(immutable([]));
69
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
70
+ /**
71
+ * Offers a shared status board to nested components.
72
+ *
73
+ * The outermost context takes up the issues the page raises on its own account, that is broken scripts and unhandled
74
+ * rejections, and states them among the others: a rejected exchange nobody attended reaches a reader with the status
75
+ * and the explanation its source gave it, rather than as a console entry only developers ever read.
76
+ *
77
+ * Nested contexts behave as error boundaries do: each holds the posts and the issues of the components it encloses.
78
+ * The issues of the page belong to no component, so they are stated once, however many contexts are nested.
79
+ *
80
+ * Posts stand for as long as the context lives and are cleared by whoever put them up or showed them, so a post is
81
+ * never dropped by a later one; the oldest is dropped on its own where posts stand beyond `limit`.
82
+ *
83
+ * @param options The number of posts standing at a time, and the components they are offered to
84
+ *
85
+ * @returns The nested components, with the posts put up on the interface offered to them
86
+ *
87
+ * @throws {@link !TypeError TypeError} If `limit` is not an integer
88
+ */
89
+ export function Board({ limit = 0, children }) {
90
+ const $limit = assert(limit, limit => Number.isInteger(limit), `illegal limit <${limit}>`);
91
+ const outermost = useContext(BoardContext) === nowhere;
92
+ const [posts, setPosts] = useState(() => immutable([]));
93
+ const [board] = useState(() => {
94
+ const put = (post) => {
95
+ setPosts(posts => posted(posts, post, $limit));
96
+ return post;
97
+ };
98
+ return immutable({
99
+ post: post => put(toPost(post)),
100
+ raise: issue => put(toFailure(issue)),
101
+ clear: posts => setPosts(standing => cleared(standing, posts))
102
+ });
103
+ });
104
+ // window issues outlive the render, so they are taken up for as long as the context lives; page issues are owned
105
+ // by no component, so the outermost context alone takes them up, as nested ones would state each of them again
106
+ useEffect(() => outermost ? listen(board) : undefined, [outermost, board]);
107
+ return createElement(BoardContext.Provider, { value: board }, createElement(PostsContext.Provider, { value: posts, children }));
108
+ }
109
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110
+ /**
111
+ * Retrieves the status board.
112
+ *
113
+ * The board stands for as long as the {@link Board} context offering it lives, so a component posting renders again
114
+ * only as its own state requires, and a handler may keep it across exchanges.
115
+ *
116
+ * @returns The board of the innermost enclosing {@link Board} context; outside any, one posting nowhere, logging raised
117
+ * issues to the console and clearing nothing
118
+ */
119
+ export function useBoard() {
120
+ return useContext(BoardContext);
121
+ }
122
+ /**
123
+ * Retrieves the posts put up on the interface.
124
+ *
125
+ * Renders the component again whenever a post is put up, raised or cleared, so a reader shows what stands at any
126
+ * time.
127
+ *
128
+ * @returns The posts of the innermost enclosing {@link Board} context, oldest first; outside any, none
129
+ */
130
+ export function usePosts() {
131
+ return useContext(PostsContext);
132
+ }
133
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
134
+ /**
135
+ * Completes a post as a source puts it up.
136
+ *
137
+ * @param post The post as given to {@link Board.post}
138
+ *
139
+ * @returns `post` with a fresh `urn:uuid:` identity if it carries none, `normal` status if it states none, and its
140
+ * problem worded by {@link toMessage} as its message if it carries no message of its own
141
+ */
142
+ function toPost({ instance = `urn:uuid:${crypto.randomUUID()}`, status = "normal", message, ...rest }) {
143
+ // the signature rules out a post stating neither, but a caller unchecked by it still gets a wording
144
+ return immutable({ ...rest, instance, status, message: message ?? toMessage(rest.problem ?? {}) });
145
+ }
146
+ /**
147
+ * Converts a caught issue into a post telling of it.
148
+ *
149
+ * @param issue The issue as given to {@link Board.raise}
150
+ *
151
+ * @returns A post with a fresh identity, carrying `issue` as problem details worded as its message: a `failure` if
152
+ * `issue` already was problem details, and a `defect` if it was anything else the interface threw
153
+ */
154
+ function toFailure(issue) {
155
+ return toPost({
156
+ status: isProblem(issue) ? "failure" : "defect",
157
+ problem: toProblem(issue)
158
+ });
159
+ }
160
+ /**
161
+ * Words a problem as the message of a post telling of it.
162
+ *
163
+ * @param problem The problem to word
164
+ *
165
+ * @returns The explanation of `problem`, or failing that its summary, blank values counting as missing; failing both,
166
+ * a standing English wording naming its HTTP status or, where no server assigned one, quoting an excerpt of the
167
+ * machine-readable details it carries, so the reader gets a hint of what went wrong even then
168
+ */
169
+ function toMessage({ status, title, detail, report }) {
170
+ const explanation = [detail, title].find(text => text?.trim());
171
+ return explanation ? explanation
172
+ : status ? `Request failed with HTTP status ${status}`
173
+ : report !== undefined ? `Unexpected error: ${clip(JSON.stringify(report), ExcerptLength)}`
174
+ : "Unexpected error";
175
+ }
176
+ /**
177
+ * Raises the issues the page raises on its own account.
178
+ *
179
+ * @param board The board broken scripts and unhandled rejections are raised on
180
+ *
181
+ * @returns A function that stops raising them
182
+ */
183
+ function listen(board) {
184
+ const failed = (event) => board.raise(event.error ?? event.message);
185
+ const rejected = (event) => board.raise(event.reason);
186
+ window.addEventListener("error", failed);
187
+ window.addEventListener("unhandledrejection", rejected);
188
+ return () => {
189
+ window.removeEventListener("error", failed);
190
+ window.removeEventListener("unhandledrejection", rejected);
191
+ };
192
+ }
193
+ /**
194
+ * Puts a post up on the board.
195
+ *
196
+ * @param posts The posts standing on the board
197
+ * @param post The post to put up
198
+ * @param limit The number of posts held at a time; unlimited if not positive
199
+ *
200
+ * @returns `posts` with `post` replacing the one sharing its identity where it stands, or put up last less the oldest
201
+ * beyond `limit`; `posts` itself if `post` already stands as given, so the context renders nothing
202
+ */
203
+ function posted(posts, post, limit) {
204
+ const standing = posts.find(({ instance }) => instance === post.instance);
205
+ return standing === undefined ? immutable([...posts, post].slice(limit > 0 ? -limit : 0))
206
+ : equals(standing, post) ? posts
207
+ : immutable(posts.map(current => current === standing ? post : current));
208
+ }
209
+ /**
210
+ * Takes posts down from the board.
211
+ *
212
+ * @param posts The posts standing on the board
213
+ * @param targets The posts to take down, matched by identity; every post if omitted
214
+ *
215
+ * @returns `posts` less `targets`; `posts` itself if none of them stands, so the context renders nothing
216
+ */
217
+ function cleared(posts, targets) {
218
+ const instances = new Set(some(targets).map(({ instance }) => instance));
219
+ const kept = targets === undefined ? [] : posts.filter(({ instance }) => !instances.has(instance));
220
+ return kept.length === posts.length ? posts : immutable(kept);
221
+ }
222
+ //# sourceMappingURL=board.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"board.js","sourceRoot":"","sources":["../src/board.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAa,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAgB,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAA0B,aAAa,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG/D;;GAEG;AACH,MAAM,aAAa,GAAG,GAAG,CAAC;AAG1B,wHAAwH;AAExH;;GAEG;AACH,MAAM,OAAO,GAAU,SAAS,CAAC;IAEhC,IAAI,EAAE,MAAM;IAEZ,KAAK,EAAE,KAAK,CAAC,EAAE;QAE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AC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAE/D,CAAC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Shared fetch client.
3
+ *
4
+ * Offers the components of an interface one client to read resources through and write them back with, configured
5
+ * once where the interface is assembled rather than at every call site, and states whether that client is busy, so
6
+ * that waiting is shown wherever the interface sees fit.
7
+ *
8
+ * The client and its status are offered apart, so a component making exchanges never renders as the client gets busy.
9
+ *
10
+ * > [!NOTE]
11
+ * >
12
+ * > The client is a plain [`fetch`](https://developer.mozilla.org/docs/Web/API/Window/fetch) function, so anything
13
+ * > expecting one accepts it and anything producing one may replace it:
14
+ * > [@grafctory/http](https://grafctory.github.io/http/) provides composable fetch middlewares covering recurring HTTP
15
+ * > concerns, such as authentication, caching or uniform failure reporting.
16
+ *
17
+ * @module
18
+ */
19
+ import { type Fetch } from "@grafctory/http";
20
+ import { type ComponentChildren } from "preact";
21
+ /**
22
+ * Offers a shared fetch client to nested components.
23
+ *
24
+ * Extends the client with the services every interface relies on: JSON is asked for unless an exchange states the
25
+ * content it expects on its own terms, and every exchange in flight counts towards the busy status, so that waiting is
26
+ * stated without any call site taking part.
27
+ *
28
+ * Whatever a deployment settles for itself stays with the consumer: a client assembled with
29
+ * {@link @grafctory/http!createFetch createFetch} and handed over keeps the services above, with its own middlewares
30
+ * running closer to the network.
31
+ *
32
+ * The client is assembled as the context first renders and kept for as long as it lives, so that exchanges are not
33
+ * disturbed by the interface around them: a client handed over later never replaces the one in use.
34
+ *
35
+ * @param options The client the context is to offer, and the components it is offered to
36
+ *
37
+ * @returns The nested components, with the extended client and its status offered to them
38
+ */
39
+ export declare function Fetch({ fetch, children }: {
40
+ /**
41
+ * The fetch function every exchange is ultimately performed by; defaults to the global one.
42
+ */
43
+ fetch?: Fetch;
44
+ /**
45
+ * The components the client and its status are offered to.
46
+ */
47
+ children: ComponentChildren;
48
+ }): import("preact").VNode<{
49
+ value: typeof globalThis.fetch;
50
+ children?: ComponentChildren;
51
+ }>;
52
+ /**
53
+ * Retrieves the shared fetch client.
54
+ *
55
+ * The client lasts as long as its {@link Fetch} context, so a handler may keep it and reading it triggers no render.
56
+ *
57
+ * @returns The client of the innermost enclosing {@link Fetch} context; outside any, the global fetch function
58
+ */
59
+ export declare function useFetch(): Fetch;
60
+ /**
61
+ * States whether the shared fetch client is busy.
62
+ *
63
+ * Renders the component again whenever the client takes up work or falls idle, so that a progress indicator states
64
+ * what the interface is waiting for without following exchanges of its own. Concurrent exchanges stand as a single
65
+ * stretch of waiting, rather than as one stretch each.
66
+ *
67
+ * @returns true if the client of the innermost enclosing {@link Fetch} context has exchanges in flight; false otherwise
68
+ */
69
+ export declare function useFetching(): boolean;
70
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAI1D,OAAO,EAAE,KAAK,iBAAiB,EAAgC,MAAM,QAAQ,CAAC;AAmB9E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,KAAK,CAAC,EAErB,KAAwB,EAExB,QAAQ,EAER,EAAE;IAEF;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAA;IAEb;;OAEG;IACH,QAAQ,EAAE,iBAAiB,CAAA;CAE3B;;;GAcA;AAKD;;;;;;GAMG;AACH,wBAAgB,QAAQ,IAAI,KAAK,CAEhC;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,IAAI,OAAO,CAErC"}
package/dist/fetch.js ADDED
@@ -0,0 +1,97 @@
1
+ /*
2
+ * Copyright © 2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Shared fetch client.
18
+ *
19
+ * Offers the components of an interface one client to read resources through and write them back with, configured
20
+ * once where the interface is assembled rather than at every call site, and states whether that client is busy, so
21
+ * that waiting is shown wherever the interface sees fit.
22
+ *
23
+ * The client and its status are offered apart, so a component making exchanges never renders as the client gets busy.
24
+ *
25
+ * > [!NOTE]
26
+ * >
27
+ * > The client is a plain [`fetch`](https://developer.mozilla.org/docs/Web/API/Window/fetch) function, so anything
28
+ * > expecting one accepts it and anything producing one may replace it:
29
+ * > [@grafctory/http](https://grafctory.github.io/http/) provides composable fetch middlewares covering recurring HTTP
30
+ * > concerns, such as authentication, caching or uniform failure reporting.
31
+ *
32
+ * @module
33
+ */
34
+ import { createFetch } from "@grafctory/http";
35
+ import { headers } from "@grafctory/http/headers";
36
+ import { monitor } from "@grafctory/http/monitor";
37
+ import { transport } from "@grafctory/http/transport";
38
+ import { createContext, createElement } from "preact";
39
+ import { useContext, useState } from "preact/hooks";
40
+ /**
41
+ * The client offered by the innermost enclosing {@link Fetch} context; the global fetch function outside any.
42
+ */
43
+ const ClientContext = createContext(globalThis.fetch);
44
+ /**
45
+ * Whether the client of the innermost enclosing {@link Fetch} context is busy; false outside any.
46
+ *
47
+ * Kept apart from the client, so that components reading only the client never render as its status changes.
48
+ */
49
+ const StatusContext = createContext(false);
50
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51
+ /**
52
+ * Offers a shared fetch client to nested components.
53
+ *
54
+ * Extends the client with the services every interface relies on: JSON is asked for unless an exchange states the
55
+ * content it expects on its own terms, and every exchange in flight counts towards the busy status, so that waiting is
56
+ * stated without any call site taking part.
57
+ *
58
+ * Whatever a deployment settles for itself stays with the consumer: a client assembled with
59
+ * {@link @grafctory/http!createFetch createFetch} and handed over keeps the services above, with its own middlewares
60
+ * running closer to the network.
61
+ *
62
+ * The client is assembled as the context first renders and kept for as long as it lives, so that exchanges are not
63
+ * disturbed by the interface around them: a client handed over later never replaces the one in use.
64
+ *
65
+ * @param options The client the context is to offer, and the components it is offered to
66
+ *
67
+ * @returns The nested components, with the extended client and its status offered to them
68
+ */
69
+ export function Fetch({ fetch = globalThis.fetch, children }) {
70
+ const [status, setStatus] = useState(false);
71
+ const [client] = useState(() => createFetch(monitor({ busy: setStatus }), headers({ "Accept": "application/json" }), transport(fetch)));
72
+ return createElement(ClientContext.Provider, { value: client }, createElement(StatusContext.Provider, { value: status, children }));
73
+ }
74
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75
+ /**
76
+ * Retrieves the shared fetch client.
77
+ *
78
+ * The client lasts as long as its {@link Fetch} context, so a handler may keep it and reading it triggers no render.
79
+ *
80
+ * @returns The client of the innermost enclosing {@link Fetch} context; outside any, the global fetch function
81
+ */
82
+ export function useFetch() {
83
+ return useContext(ClientContext);
84
+ }
85
+ /**
86
+ * States whether the shared fetch client is busy.
87
+ *
88
+ * Renders the component again whenever the client takes up work or falls idle, so that a progress indicator states
89
+ * what the interface is waiting for without following exchanges of its own. Concurrent exchanges stand as a single
90
+ * stretch of waiting, rather than as one stretch each.
91
+ *
92
+ * @returns true if the client of the innermost enclosing {@link Fetch} context has exchanges in flight; false otherwise
93
+ */
94
+ export function useFetching() {
95
+ return useContext(StatusContext);
96
+ }
97
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,WAAW,EAAc,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,OAAO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+ /**
2
+ * Focus bindings of a group of controls, as returned by {@link useFocus}.
3
+ *
4
+ * The group gives each item the tab index retrieved by `tabIndex`, binds `onFocus` to the focus event of each item and
5
+ * attaches `onKeyDown` to the element holding its items. The whole group then takes a single stop in the `Tab`
6
+ * sequence, the arrow keys move the focus among its items, and the stop follows the focus however it moves.
7
+ */
8
+ export type Focus = {
9
+ /**
10
+ * Retrieves the tab index of an item: `0` for the item holding the stop, `-1` for the others.
11
+ */
12
+ readonly tabIndex: (item: string) => 0 | -1;
13
+ /**
14
+ * Handles the keys moving the focus, claiming them from the browser. The group attaches the handler to the element
15
+ * holding its items, so it receives the keys pressed on any of them. Keys {@link isReserved | reserved} for a
16
+ * field inside an item, such as a text input, are left to the field to move its caret or change its value.
17
+ */
18
+ readonly onKeyDown: (event: KeyboardEvent) => void;
19
+ /**
20
+ * Moves the stop to an item focused without the arrow keys, such as by a pointer or by a script calling `focus()`.
21
+ * The group calls it from the focus event of each item, so `Tab` brings the reader back to the item they left.
22
+ * Focusing the item that already holds the stop notifies nothing. A group of buttons also calls it from their
23
+ * click event, since Safari leaves a clicked button unfocused and so fires no focus event for it.
24
+ */
25
+ readonly onFocus: (item: string) => void;
26
+ };
27
+ /**
28
+ * Makes a group of controls a single stop for `Tab`, moving the focus among its items with the arrow keys.
29
+ *
30
+ * The group renders each item with the tab index and the focus handler the hook returns, and attaches the keyboard
31
+ * handler to the element holding the items. The group stores the item `onMove` notifies and passes it back as
32
+ * `active` on the next render, so the stop stays on the item the reader left, however they reached it.
33
+ *
34
+ * @param options The group configuration
35
+ *
36
+ * @returns The tab index and the focus handler of each item and the keyboard handler of the group
37
+ */
38
+ export declare function useFocus({ wrap, orientation, items, active, identify, onMove }: {
39
+ /**
40
+ * Whether a step past either end comes round from the other, rather than stopping at the end.
41
+ */
42
+ wrap?: boolean;
43
+ /**
44
+ * The axis the arrow keys move along: `horizontal` takes the left and right arrows, `vertical` the up and down
45
+ * ones, and the arrows of the other axis are left to the browser. If omitted, as for a group with no fixed axis,
46
+ * all four arrows move the focus, the right and down arrows stepping forwards, the left and up ones backwards.
47
+ */
48
+ orientation?: "horizontal" | "vertical";
49
+ /**
50
+ * The keys of the items the focus moves among, in display order; an item left out of them is passed over by the
51
+ * arrow keys, which is how a group keeps a disabled control out of their reach while leaving it on show.
52
+ */
53
+ items: readonly string[];
54
+ /**
55
+ * The key of the item the focus last stood on, which holds the stop of the group. If `active` is omitted, or if
56
+ * the item it names is no longer among the `items` of the group, the first item holds the stop instead.
57
+ */
58
+ active?: string;
59
+ /**
60
+ * Retrieves the DOM id of the element standing for an item, which takes the focus once moved to.
61
+ */
62
+ identify: (item: string) => string;
63
+ /**
64
+ * Notified with the key of the item the focus moves to. The group stores the key and passes it back as `active`
65
+ * on the next render, keeping the stop where the reader left it. A key move notifies before the focus moves and
66
+ * may notify again with the same key once the focus lands, so the handler stores the key rather than toggling.
67
+ */
68
+ onMove: (item: string) => void;
69
+ }): Focus;
70
+ //# sourceMappingURL=focus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus.d.ts","sourceRoot":"","sources":["../src/focus.ts"],"names":[],"mappings":"AA+DA;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG;IAEnB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IAE3C;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAElD;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAExC,CAAA;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,EAExB,IAAY,EACZ,WAAW,EAEX,KAAK,EACL,MAAM,EACN,QAAQ,EAER,MAAM,EAEN,EAAE;IAEF;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAEd;;;;OAIG;IACH,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAA;IAGvC;;;OAGG;IACH,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IAGlC;;;;OAIG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAE9B,GAAG,KAAK,CA2DR"}
package/dist/focus.js ADDED
@@ -0,0 +1,65 @@
1
+ /*
2
+ * Copyright © 2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { immutable } from "@grafctory/core/values";
17
+ import { isReserved } from "./index.js";
18
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19
+ /**
20
+ * Makes a group of controls a single stop for `Tab`, moving the focus among its items with the arrow keys.
21
+ *
22
+ * The group renders each item with the tab index and the focus handler the hook returns, and attaches the keyboard
23
+ * handler to the element holding the items. The group stores the item `onMove` notifies and passes it back as
24
+ * `active` on the next render, so the stop stays on the item the reader left, however they reached it.
25
+ *
26
+ * @param options The group configuration
27
+ *
28
+ * @returns The tab index and the focus handler of each item and the keyboard handler of the group
29
+ */
30
+ export function useFocus({ wrap = false, orientation, items, active, identify, onMove }) {
31
+ const holder = active !== undefined && items.includes(active) ? active : items[0];
32
+ return immutable({
33
+ tabIndex: item => item === holder ? 0 : -1,
34
+ onKeyDown: event => {
35
+ const offset = stride(event.key);
36
+ const target = offset === undefined || isReserved(event) || event.altKey || event.ctrlKey || event.metaKey
37
+ ? undefined
38
+ : step(offset);
39
+ if (target !== undefined) {
40
+ event.preventDefault();
41
+ onMove(target);
42
+ document.getElementById(identify(target))?.focus();
43
+ }
44
+ },
45
+ onFocus: item => item === holder ? undefined : onMove(item)
46
+ });
47
+ function stride(key) {
48
+ const horizontal = orientation !== "vertical";
49
+ const vertical = orientation !== "horizontal";
50
+ return key === "Home" ? -Infinity
51
+ : key === "End" ? +Infinity
52
+ : horizontal && key === "ArrowRight" || vertical && key === "ArrowDown" ? +1
53
+ : horizontal && key === "ArrowLeft" || vertical && key === "ArrowUp" ? -1
54
+ : undefined;
55
+ }
56
+ function step(offset) {
57
+ const target = items.indexOf(holder ?? "") + offset;
58
+ // an infinite offset has no remainder, so it reaches the end by clamping whether wrapping or not
59
+ const index = wrap && Number.isFinite(offset)
60
+ ? ((target % items.length) + items.length) % items.length
61
+ : Math.min(Math.max(target, 0), items.length - 1);
62
+ return items[index];
63
+ }
64
+ }
65
+ //# sourceMappingURL=focus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus.js","sourceRoot":"","sources":["../src/focus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA6CH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAmCxC,wHAAwH;AAExH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ,CAAC,EAExB,IAAI,GAAG,KAAK,EACZ,WAAW,EAEX,KAAK,EACL,MAAM,EACN,QAAQ,EAER,MAAM,EA0CN;IAEA,MAAM,MAAM,GAAG,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAElF,OAAO,SAAS,CAAC;QAEhB,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AAW,IAAI,QAAQ,IAAI,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;wBACxE,CAAC,CAAC,SAAS,CAAC;IAEjB,CAAC;IAED,SAAS,IAAI,CAAC,MAAc;QAE3B,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,GAAC,MAAM,CAAC;QAElD,iGAAiG;QAEjG,MAAM,KAAK,GAAG,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;YAC5C,CAAC,CAAC,CAAC,CAAC,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,GAAC,KAAK,CAAC,MAAM,CAAC,GAAC,KAAK,CAAC,MAAM;YACnD,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAC,CAAC,CAAC,CAAC;QAEjD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;IAErB,CAAC;AAEF,CAAC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Preact contexts and hooks.
3
+ *
4
+ * Provides what the app states about itself, so a component carries the app identity wherever it is assembled without
5
+ * being handed it. Also provides the element the app renders into, already fitted to the page, so a screen that fills
6
+ * the window needs no root of its own. Tells which keys and presses belong to a field, so a widget handling them over
7
+ * its surface leaves the fields it holds working as usual. The package contexts and hooks come from their own modules,
8
+ * so a component imports only the ones it is wired to, and an app pulls in no service it never provides.
9
+ *
10
+ * Importing this module needs no DOM. The app identity is read from the document on first access, so a test or a
11
+ * server render reading it has to supply a DOM first, already carrying the title and tags the app states itself by.
12
+ *
13
+ * @module index
14
+ */
15
+ import { type Optional } from "@grafctory/core";
16
+ /**
17
+ * What the app says about itself, as its document states it.
18
+ *
19
+ * Read on first access and immutable thereafter, so a later edit to the document is never picked up.
20
+ */
21
+ export declare const app: {
22
+ /**
23
+ * The absolute root URL of the site, with a trailing slash.
24
+ */
25
+ readonly root: string;
26
+ /**
27
+ * The absolute base URL the app is published at, with a trailing slash, as `<base>` states it, or the site root.
28
+ */
29
+ readonly base: string;
30
+ /**
31
+ * The app name, as the `<title>` tag states it, or `undefined` if the tag is missing or empty.
32
+ */
33
+ readonly name: Optional<string>;
34
+ /**
35
+ * The URL of the app icon, as the `<link rel="icon">` tag states it, or `undefined` if the tag is missing.
36
+ */
37
+ readonly icon: Optional<string>;
38
+ /**
39
+ * The app description, as the `<meta name="description">` tag states it, or `undefined` if missing or empty.
40
+ */
41
+ readonly info: Optional<string>;
42
+ /**
43
+ * The app copyright, as the `<meta name="copyright">` tag states it, or `undefined` if missing or empty.
44
+ */
45
+ readonly copy: Optional<string>;
46
+ };
47
+ /**
48
+ * Checks whether an event is reserved for the field it lands in.
49
+ *
50
+ * A widget handling keys or presses on its own, for example moving the focus with arrow keys or dragging an item by
51
+ * its surface, leaves reserved events alone. A field inside the widget then keeps the keys and presses that move its
52
+ * caret or change its value, and works there as it does anywhere else on the page.
53
+ *
54
+ * Fields are enabled text and value controls, native or carrying a matching ARIA role, and editable regions. Buttons,
55
+ * checkboxes, radio buttons and the other controls acting on a single press are not fields.
56
+ *
57
+ * @param event The key or pointer event to check
58
+ *
59
+ * @returns true if `event` targets a field or an element inside one; false otherwise
60
+ */
61
+ export declare function isReserved(event: Event): boolean;
62
+ /**
63
+ * Settles the custom element a page is rendered into.
64
+ *
65
+ * Hands out a stable root for a rendering call: the same element answers every call naming it, so that repeated
66
+ * calls, as issued on hot reload, replace the page rather than adding another copy of it.
67
+ *
68
+ * An element created here takes the height of whatever holds it and stretches the frame rendered into it across its
69
+ * whole box, so the frame fills the page rather than standing as tall as its content: an app states once, in its own
70
+ * document, that the body is as tall as the window, and gets a root already fitted to it. An element the document
71
+ * already carries is handed back as it stands, leaving its layout to the app that placed it.
72
+ *
73
+ * @param name The name of the hosting custom element, hyphenated as the DOM requires
74
+ *
75
+ * @returns The element named `name`, appended to the body and fitted to it unless the document already carries one
76
+ */
77
+ export declare function host(name: string): Element;
78
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAuDhD;;;;GAIG;AACH,eAAO,MAAM,GAAG;IAEf;;OAEG;mBACS,MAAM;IAIlB;;OAEG;mBACS,MAAM;IAKlB;;OAEG;mBACS,QAAQ,CAAC,MAAM,CAAC;IAI5B;;OAEG;mBACS,QAAQ,CAAC,MAAM,CAAC;IAK5B;;OAEG;mBACS,QAAQ,CAAC,MAAM,CAAC;IAK5B;;OAEG;mBACS,QAAQ,CAAC,MAAM,CAAC;CAK3B,CAAC;AAKH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAIhD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAe1C"}