@mpfrontend/ui 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,62 @@
1
- # Temporary Holding Version
1
+ # @mpfrontend/ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Local development package. Runtime: client. Public API is exported from src/index.ts and compiled
4
+ into dist. Nx owns build, typecheck, lint and test targets. Consumer applications install packed artifacts.
5
+ See ../../docs/IMPLEMENTATION-STATUS.md for observed evidence and remaining work.
6
+
7
+ Import `@mpfrontend/ui/tailwind.css` from the consumer's Tailwind v4 entry so its compiler scans the
8
+ published JavaScript for structural utility classes. Import `@mpfrontend/ui/styles.css` for semantic
9
+ token-driven state and color rules. Product values, icons, typography and DLS composition remain in the
10
+ consumer adapter/theme. The application frame (skip link, header, navigation, page frame) is the separate
11
+ package `@mpfrontend/app-layout`.
12
+
13
+ ## Dialog and one-time code
14
+
15
+ `Dialog` is a modal dialog on the native `dialog` element: `aria-modal`, labelled by its `title` and described
16
+ by its `description`, Escape and the browser's cancel call `onClose`, a focus guard keeps Tab and Shift+Tab
17
+ inside it, and focus returns to the element that opened it. Every text is a prop (`closeLabel` names the
18
+ close button), and it uses logical properties only.
19
+
20
+ `OneTimeCodeField` accepts digits only, up to a configured `length` (4 to 10, 6 by default), with
21
+ `autocomplete="one-time-code"` and a numeric keyboard; a pasted code keeps its digits and drops spaces,
22
+ dashes and other characters, and a decimal digit of any script becomes its ASCII digit (`codeDigits`). It
23
+ has an error state and never logs or stores the value.
24
+
25
+ `ConfirmWithCode` confirms a sensitive action in a `Dialog`: `onConfirm(code, signal)` sends the code to
26
+ the server through the BFF (a same-origin request with the CSRF token and an idempotency key), the browser
27
+ never checks the code, and the code is cleared on close and on failure and never written to browser
28
+ storage, a URL or a log. DOM behaviour (keyboard, focus, names, clearing) is tested with happy-dom 20.14.5,
29
+ a test-only dependency chosen because the tests need focus and keyboard events without a browser.
30
+
31
+ ## Tree
32
+
33
+ `Tree` is a controlled tree view on the WAI-ARIA tree pattern; with `columns` it is a tree table
34
+ (`treegrid`). The consumer owns `expanded` (`onExpandedChange`) and the per-node `states`, a set it defines,
35
+ with `stateLabels` for their visible text. Arrows move, open and close (the horizontal arrows swap in a
36
+ right-to-left context), Home and End jump, and Enter and Space call `onActivate`, where the consumer's own
37
+ rule decides what changes; `descendantIds(node)` helps a rule over the current children. The component has
38
+ no access decision and no inheritance between states, and never changes the nodes it receives. Rows are
39
+ virtualized at a fixed `rowHeight` inside a `height` viewport: ten thousand nodes render only the rows in
40
+ view, and the focused row stays rendered. Each item carries `aria-level`, `aria-setsize`, `aria-posinset`
41
+ and `aria-expanded`, and its accessible name includes its state label.
42
+
43
+
44
+ ## Field access in tables and forms
45
+
46
+ `ResourceTable` and `ResourceForm` take `access`, a reader of `@mpfrontend/access-core` (from `useAccess()` of
47
+ `@mpfrontend/access-react`). A column whose field may not be viewed is removed with its header. A form field that
48
+ may not be viewed is not rendered, with its label, `helpers` text and `errors` text, and leaves validation and the
49
+ submitted values; a field that may not be edited is disabled; a save passes `onSubmit` only the changed fields that
50
+ may be edited, compared with `original` (`dirtyPatch`), and a changed field that may not be edited throws
51
+ `FORBIDDEN_FIELD` instead of being sent. Without `access` both components behave as before. A hidden field is a
52
+ presentation; the server still refuses a field the person may not write.
53
+
54
+ ## Paging, sorting and filtering
55
+
56
+ `ResourceTable` takes `control`, a declared `mode` with controlled `page`, `size`, `sort` and `filters` and their
57
+ change events, with the visible text of its controls from the consumer's catalog. In `server` mode it shows the rows
58
+ the server returned and never sorts, filters or pages them itself; in `client` mode it filters, sorts and pages the
59
+ rows it is given. The mode is never switched by the data. Sortable headers carry `aria-sort`; filters submit
60
+ together; the pagination is a labelled navigation. A sort or a filter on a column the person may not view is
61
+ ignored. `useTableUrlState` of `@mpfrontend/data-react` binds the controlled values to the URL. Without `control`,
62
+ the table renders exactly as before.
@@ -0,0 +1,19 @@
1
+ import { type ReactNode } from 'react';
2
+ /** The next element of a Tab or Shift+Tab press inside a trap: the ends wrap around. */
3
+ export declare function nextFocus<T>(elements: readonly T[], current: T | null, backwards: boolean): T | undefined;
4
+ export type DialogProps = {
5
+ open: boolean;
6
+ title: ReactNode;
7
+ /** Called on Escape, on the close button and on the browser's own cancel; the parent closes the dialog. */
8
+ onClose: () => void;
9
+ /** The accessible name of the close button; every visible text is the consumer's. */
10
+ closeLabel: string;
11
+ children: ReactNode;
12
+ description?: ReactNode;
13
+ };
14
+ /**
15
+ * A modal dialog on the native dialog element: aria-modal, labelled by its title (and described by its
16
+ * description), Escape closes it, a focus guard keeps Tab inside it, and focus returns to the element that
17
+ * opened it. It uses logical properties only, so it reads the same in both directions.
18
+ */
19
+ export declare function Dialog({ open, title, onClose, closeLabel, children, description }: DialogProps): import("react").JSX.Element;
package/dist/dialog.js ADDED
@@ -0,0 +1,66 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useRef } from 'react';
4
+ const focusable = 'a[href],button:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
5
+ /** The next element of a Tab or Shift+Tab press inside a trap: the ends wrap around. */
6
+ export function nextFocus(elements, current, backwards) {
7
+ if (!elements.length)
8
+ return undefined;
9
+ const index = current === null ? -1 : elements.indexOf(current);
10
+ if (backwards)
11
+ return index <= 0 ? elements[elements.length - 1] : elements[index - 1];
12
+ return index < 0 || index === elements.length - 1 ? elements[0] : elements[index + 1];
13
+ }
14
+ /**
15
+ * A modal dialog on the native dialog element: aria-modal, labelled by its title (and described by its
16
+ * description), Escape closes it, a focus guard keeps Tab inside it, and focus returns to the element that
17
+ * opened it. It uses logical properties only, so it reads the same in both directions.
18
+ */
19
+ export function Dialog({ open, title, onClose, closeLabel, children, description }) {
20
+ const ref = useRef(null), opener = useRef(null);
21
+ const titleId = useId(), descriptionId = useId();
22
+ useEffect(() => {
23
+ const dialog = ref.current;
24
+ if (!dialog)
25
+ return;
26
+ if (open) {
27
+ opener.current = document.activeElement;
28
+ if (!dialog.open) {
29
+ if (typeof dialog.showModal === 'function')
30
+ dialog.showModal();
31
+ else
32
+ dialog.setAttribute('open', '');
33
+ }
34
+ const first = dialog.querySelector('[data-autofocus]') ?? dialog.querySelector(focusable);
35
+ (first ?? dialog).focus();
36
+ return;
37
+ }
38
+ if (dialog.open) {
39
+ if (typeof dialog.close === 'function')
40
+ dialog.close();
41
+ else
42
+ dialog.removeAttribute('open');
43
+ }
44
+ const previous = opener.current;
45
+ opener.current = null;
46
+ if (previous && typeof previous.focus === 'function' && previous.isConnected)
47
+ previous.focus();
48
+ }, [open]);
49
+ function keyDown(event) {
50
+ if (event.key === 'Escape') {
51
+ event.preventDefault();
52
+ onClose();
53
+ return;
54
+ }
55
+ if (event.key !== 'Tab')
56
+ return;
57
+ const elements = [...event.currentTarget.querySelectorAll(focusable)];
58
+ const target = nextFocus(elements, document.activeElement, event.shiftKey);
59
+ if (target) {
60
+ event.preventDefault();
61
+ target.focus();
62
+ }
63
+ }
64
+ return _jsx("dialog", { ref: ref, "aria-modal": "true", "aria-labelledby": titleId, "aria-describedby": description === undefined ? undefined : descriptionId, onKeyDown: keyDown, onCancel: event => { event.preventDefault(); onClose(); }, className: "mp-dialog m-auto w-[min(100%-2rem,32rem)] rounded-[var(--mp-radius-surface)] border p-6", children: open && _jsxs("div", { className: "grid gap-4", children: [_jsxs("div", { className: "flex items-start justify-between gap-4", children: [_jsx("h2", { id: titleId, className: "m-0 text-start text-xl font-semibold", children: title }), _jsx("button", { type: "button", className: "mp-dialog-close rounded-[var(--mp-radius-control)] px-2", "aria-label": closeLabel, onClick: onClose, children: "\u00D7" })] }), description !== undefined && _jsx("p", { id: descriptionId, className: "m-0", children: description }), children] }) });
65
+ }
66
+ //# sourceMappingURL=dialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialog.js","sourceRoot":"","sources":["../src/dialog.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAC,SAAS,EAAC,KAAK,EAAC,MAAM,EAAmC,MAAM,OAAO,CAAC;AAE/E,MAAM,SAAS,GAAC,2JAA2J,CAAC;AAE5K,wFAAwF;AACxF,MAAM,UAAU,SAAS,CAAI,QAAqB,EAAC,OAAc,EAAC,SAAiB;IACjF,IAAG,CAAC,QAAQ,CAAC,MAAM;QAAC,OAAO,SAAS,CAAC;IACrC,MAAM,KAAK,GAAC,OAAO,KAAG,IAAI,CAAA,CAAC,CAAA,CAAC,CAAC,CAAA,CAAC,CAAA,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACxD,IAAG,SAAS;QAAC,OAAO,KAAK,IAAE,CAAC,CAAA,CAAC,CAAA,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAC,CAAC,CAAC,CAAA,CAAC,CAAA,QAAQ,CAAC,KAAK,GAAC,CAAC,CAAC,CAAC;IAC3E,OAAO,KAAK,GAAC,CAAC,IAAE,KAAK,KAAG,QAAQ,CAAC,MAAM,GAAC,CAAC,CAAA,CAAC,CAAA,QAAQ,CAAC,CAAC,CAAC,CAAA,CAAC,CAAA,QAAQ,CAAC,KAAK,GAAC,CAAC,CAAC,CAAC;AAC1E,CAAC;AAaD;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,EAAC,IAAI,EAAC,KAAK,EAAC,OAAO,EAAC,UAAU,EAAC,QAAQ,EAAC,WAAW,EAAa;IACrF,MAAM,GAAG,GAAC,MAAM,CAAoB,IAAI,CAAC,EAAC,MAAM,GAAC,MAAM,CAAe,IAAI,CAAC,CAAC;IAC5E,MAAM,OAAO,GAAC,KAAK,EAAE,EAAC,aAAa,GAAC,KAAK,EAAE,C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;QAClE,IAAG,KAAK,CAAC,GAAG,KAAG,KAAK;YAAC,OAAO;QAC5B,MAAM,QAAQ,GAAC,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,gBAAgB,CAAc,SAAS,CAAC,CAAC,CAAC;QACjF,MAAM,MAAM,GAAC,SAAS,CAAC,QAAQ,EAAC,QAAQ,CAAC,aAAiC,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC3F,IAAG,MAAM,EAAC,CAAC;YAAA,KAAK,CAAC,cAAc,EAAE,CAAC;YAAA,MAAM,CAAC,KAAK,EAAE,CAAC;QAAA,CAAC;IACpD,CAAC;IACD,OAAO,iBAAQ,GAAG,EAAE,GAAG,gBAAa,MAAM,qBAAkB,OAAO,sBAAoB,WAAW,KAAG,SAAS,CAAA,CAAC,CAAA,SAAS,CAAA,CAAC,CAAA,aAAa,EACpI,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAA,EAAE,GAAC,KAAK,CAAC,cAAc,EAAE,CAAC,CAAA,OAAO,EAAE,CAAC,CAAA,CAAC,EACxE,SAAS,EAAC,yFAAyF,YAClG,IAAI,IAAE,eAAK,SAAS,EAAC,YAAY,aAChC,eAAK,SAAS,EAAC,wCAAwC,aACrD,aAAI,EAAE,EAAE,OAAO,EAAE,SAAS,EAAC,sCAAsC,YAAE,KAAK,GAAM,EAC9E,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,yDAAyD,gBAAa,UAAU,EAAE,OAAO,EAAE,OAAO,uBAAY,IAC1I,EACL,WAAW,KAAG,SAAS,IAAE,YAAG,EAAE,EAAE,aAAa,EAAE,SAAS,EAAC,KAAK,YAAE,WAAW,GAAK,EAChF,QAAQ,IACL,GACC,CAAC;AACZ,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { type ButtonHTMLAttributes, type InputHTMLAttributes, type SelectHTMLAttributes, type ReactNode, type Key } from 'react';
2
+ import type { AccessReader } from '@mpfrontend/access-core';
3
+ export type DisplayField = Readonly<{
4
+ key: string;
5
+ type: string;
6
+ required: boolean;
7
+ editable: boolean;
8
+ nullable: boolean;
9
+ }>;
10
+ export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
11
+ tone?: 'primary' | 'secondary' | 'ghost' | 'danger';
12
+ loading?: boolean;
13
+ loadingLabel?: ReactNode;
14
+ restricted?: boolean;
15
+ leadingIcon?: ReactNode;
16
+ trailingIcon?: ReactNode;
17
+ };
18
+ export type FieldProps = InputHTMLAttributes<HTMLInputElement> & {
19
+ label: string;
20
+ helper?: string;
21
+ error?: string;
22
+ };
23
+ export type SelectProps = SelectHTMLAttributes<HTMLSelectElement> & {
24
+ label: string;
25
+ icon?: ReactNode;
26
+ };
27
+ export declare function Button({ tone, loading, loadingLabel, restricted, leadingIcon, trailingIcon, children, disabled, ...props }: ButtonProps): import("react").JSX.Element;
28
+ export declare function Field({ label, helper, error, ...props }: FieldProps): import("react").JSX.Element;
29
+ export declare function Select({ label, children, icon, ...props }: SelectProps): import("react").JSX.Element;
30
+ export declare function Card({ children }: {
31
+ children: ReactNode;
32
+ }): import("react").JSX.Element;
33
+ export type TableSort = Readonly<{
34
+ field: string;
35
+ direction: 'asc' | 'desc';
36
+ }>;
37
+ /** The visible text of the table's controls, from the consumer's catalog. */
38
+ export type TableText = Readonly<{
39
+ pagination: string;
40
+ previous: string;
41
+ next: string;
42
+ /** The current page and the page count, when the count is known. */
43
+ page: (page: number, count: number | undefined) => string;
44
+ size?: string;
45
+ apply?: string;
46
+ filters?: string;
47
+ }>;
48
+ /**
49
+ * The controlled state of a table and its change events. The mode is declared, never inferred: in `client` mode the
50
+ * table filters, sorts and pages the rows it is given; in `server` mode it shows them as the server returned them and
51
+ * never sorts, filters or pages them itself.
52
+ */
53
+ export type TableControl = Readonly<{
54
+ mode: 'client' | 'server';
55
+ page: number;
56
+ size: number;
57
+ sort?: TableSort | undefined;
58
+ filters?: Readonly<Record<string, string>>;
59
+ /** The total number of rows the server reports (server mode). */
60
+ total?: number | undefined;
61
+ /** Whether a next page exists, when the server reports no total (server mode). */
62
+ hasMore?: boolean;
63
+ sortable?: readonly string[];
64
+ filterable?: readonly string[];
65
+ sizes?: readonly number[];
66
+ onPageChange: (page: number) => void;
67
+ onSizeChange?: (size: number) => void;
68
+ onSortChange?: (sort: TableSort | undefined) => void;
69
+ onFiltersChange?: (filters: Readonly<Record<string, string>>) => void;
70
+ text: TableText;
71
+ }>;
72
+ /**
73
+ * With `access`, a column whose field may not be viewed is removed with its header. Without it, every field shows.
74
+ * With `control`, the table has sortable headers, filters and paging bound to the controlled values; a sort or a
75
+ * filter on a column the person may not view is ignored. Without it, the table renders the rows as before.
76
+ */
77
+ export declare function ResourceTable({ fields, rows, caption, format, labels, detail, rowKey, access, control }: {
78
+ fields: readonly DisplayField[];
79
+ rows: readonly Record<string, unknown>[];
80
+ caption: string;
81
+ format: (value: unknown) => string;
82
+ labels?: Readonly<Record<string, string>>;
83
+ detail?: (row: Record<string, unknown>) => ReactNode;
84
+ rowKey?: (row: Record<string, unknown>, index: number) => Key;
85
+ access?: AccessReader;
86
+ control?: TableControl;
87
+ }): import("react").JSX.Element;
88
+ /**
89
+ * With `access`, a field that may not be viewed is not rendered (its label, helper and error with it) and leaves
90
+ * validation and the submitted values; a field that may not be edited is disabled; a save passes `onSubmit` only the
91
+ * changed fields that may be edited, compared with `original` (dirtyPatch). Without `access`, every editable field
92
+ * shows and `onSubmit` receives nothing, as before.
93
+ */
94
+ export declare function ResourceForm({ fields, values, onChange, onSubmit, labels, saveLabel, disabled, access, original, helpers, errors }: {
95
+ fields: readonly DisplayField[];
96
+ values: Readonly<Record<string, unknown>>;
97
+ onChange: (key: string, value: unknown) => void;
98
+ onSubmit: (patch?: Record<string, unknown>) => void;
99
+ labels?: Readonly<Record<string, string>>;
100
+ saveLabel: string;
101
+ disabled?: boolean;
102
+ access?: AccessReader;
103
+ original?: Readonly<Record<string, unknown>>;
104
+ helpers?: Readonly<Record<string, string>>;
105
+ errors?: Readonly<Record<string, string>>;
106
+ }): import("react").JSX.Element;
107
+ export { Dialog, nextFocus, type DialogProps } from './dialog.js';
108
+ export { OneTimeCodeField, ConfirmWithCode, codeDigits, type OneTimeCodeFieldProps, type ConfirmWithCodeProps } from './one-time-code.js';
109
+ export { Tree, visibleRows, descendantIds, treeKey, type TreeNode, type TreeRow, type TreeColumn, type TreeMove, type TreeProps } from './tree.js';
package/dist/index.js ADDED
@@ -0,0 +1,99 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId } from 'react';
4
+ import { buttonState, fieldState, isControlUnavailable } from '@mpfrontend/primitives';
5
+ export function Button({ tone = 'primary', loading = false, loadingLabel, restricted = false, leadingIcon, trailingIcon, children, disabled, ...props }) {
6
+ const state = buttonState({ disabled: disabled ?? false, loading, restricted });
7
+ return _jsxs("button", { ...props, disabled: isControlUnavailable(state), "aria-busy": state === 'loading' || undefined, "aria-disabled": state === 'restricted' || undefined, "data-state": state, "data-tone": tone, className: ['mp-button', 'inline-flex h-[var(--mp-control-height)] items-center justify-center gap-2 whitespace-nowrap rounded-[var(--mp-radius-control)] border-0 px-[var(--mp-control-padding)]', props.className].filter(Boolean).join(' '), children: [loading ? _jsx("span", { className: "mp-button-spinner", "aria-hidden": "true" }) : leadingIcon, _jsx("span", { children: loading ? (loadingLabel ?? children) : children }), !loading && trailingIcon] });
8
+ }
9
+ export function Field({ label, helper, error, ...props }) {
10
+ const generated = useId(), id = props.id ?? generated, description = id + '-description';
11
+ const state = fieldState({ disabled: props.disabled ?? false, readOnly: props.readOnly ?? false, invalid: !!error });
12
+ return _jsxs("label", { className: "mp-field flex max-w-full flex-col gap-[var(--mp-field-gap)]", "data-state": state, htmlFor: id, children: [_jsx("span", { className: "mp-field-label text-sm font-medium", children: label }), _jsx("input", { ...props, id: id, className: ['mp-input', 'h-[var(--mp-control-height)] w-full rounded-[var(--mp-radius-control)] border px-3', props.className].filter(Boolean).join(' '), "aria-invalid": !!error, "aria-describedby": error || helper ? description : props['aria-describedby'] }), (helper || error) && _jsx("span", { id: description, className: error ? 'mp-field-helper mp-field-error text-xs' : 'mp-field-helper text-xs', children: error ?? helper })] });
13
+ }
14
+ export function Select({ label, children, icon, ...props }) {
15
+ const generated = useId(), id = props.id ?? generated;
16
+ const state = fieldState({ disabled: props.disabled ?? false });
17
+ return _jsxs("label", { className: "mp-field flex max-w-full flex-col gap-[var(--mp-field-gap)]", "data-state": state, htmlFor: id, children: [_jsx("span", { className: "mp-field-label text-sm font-medium", children: label }), _jsxs("span", { className: "mp-select-wrap relative w-full", "data-custom-icon": icon ? 'true' : undefined, children: [_jsx("select", { ...props, id: id, className: ['mp-select', 'h-[var(--mp-control-height)] w-full rounded-[var(--mp-radius-control)] border px-3', props.className].filter(Boolean).join(' '), children: children }), icon && _jsx("span", { className: "mp-select-icon pointer-events-none absolute end-3 top-1/2 -translate-y-1/2", "aria-hidden": "true", children: icon })] })] });
18
+ }
19
+ export function Card({ children }) { return _jsx("section", { className: "mp-card rounded-[var(--mp-radius-surface)] border p-6", children: children }); }
20
+ function compareValues(a, b) {
21
+ if (a === b)
22
+ return 0;
23
+ if (a === null || a === undefined)
24
+ return 1;
25
+ if (b === null || b === undefined)
26
+ return -1;
27
+ if (typeof a === 'number' && typeof b === 'number')
28
+ return a - b;
29
+ if (typeof a === 'boolean' && typeof b === 'boolean')
30
+ return a === b ? 0 : a ? 1 : -1;
31
+ return String(a).localeCompare(String(b));
32
+ }
33
+ const nextSort = (sort, field) => sort?.field !== field ? { field, direction: 'asc' } : sort.direction === 'asc' ? { field, direction: 'desc' } : undefined;
34
+ /**
35
+ * With `access`, a column whose field may not be viewed is removed with its header. Without it, every field shows.
36
+ * With `control`, the table has sortable headers, filters and paging bound to the controlled values; a sort or a
37
+ * filter on a column the person may not view is ignored. Without it, the table renders the rows as before.
38
+ */
39
+ export function ResourceTable({ fields, rows, caption, format, labels = {}, detail, rowKey, access, control }) {
40
+ const columns = access ? fields.filter(field => access.field(field.key).view) : fields;
41
+ const visible = new Set(columns.map(field => field.key)), hiddenField = (key) => fields.some(field => field.key === key) && !visible.has(key);
42
+ let shown = rows, total;
43
+ if (control?.mode === 'client') {
44
+ const filters = Object.entries(control.filters ?? {}).filter(([key, value]) => value !== '' && visible.has(key));
45
+ let selected = rows.filter(row => filters.every(([key, value]) => format(row[key]).toLocaleLowerCase().includes(value.toLocaleLowerCase())));
46
+ const sort = control.sort && visible.has(control.sort.field) ? control.sort : undefined;
47
+ if (sort)
48
+ selected = [...selected].sort((a, b) => compareValues(a[sort.field], b[sort.field]) * (sort.direction === 'asc' ? 1 : -1));
49
+ total = selected.length;
50
+ shown = selected.slice((control.page - 1) * control.size, control.page * control.size);
51
+ }
52
+ else if (control)
53
+ total = control.total;
54
+ const count = control && total !== undefined ? Math.max(1, Math.ceil(total / control.size)) : undefined;
55
+ const header = (field) => {
56
+ const label = labels[field.key] ?? field.key;
57
+ if (!control?.onSortChange || !control.sortable?.includes(field.key))
58
+ return _jsx("th", { className: "border-b p-3 text-start", scope: "col", children: label }, field.key);
59
+ const direction = control.sort?.field === field.key ? control.sort.direction : undefined;
60
+ const onSortChange = control.onSortChange;
61
+ return _jsx("th", { className: "border-b p-3 text-start", scope: "col", "aria-sort": direction === 'asc' ? 'ascending' : direction === 'desc' ? 'descending' : 'none', children: _jsx("button", { type: "button", className: "mp-table-sort inline-flex items-center gap-1", onClick: () => onSortChange(nextSort(control.sort, field.key)), children: label }) }, field.key);
62
+ };
63
+ const filterable = control?.onFiltersChange ? (control.filterable ?? []).filter(name => !hiddenField(name)) : [];
64
+ const table = _jsx("div", { className: "mp-table-wrap overflow-auto", children: _jsxs("table", { className: "w-full border-collapse", children: [_jsx("caption", { children: caption }), _jsx("thead", { children: _jsxs("tr", { children: [columns.map(header), detail && _jsx("th", { className: "border-b p-3 text-start", scope: "col", children: labels.detail ?? 'Details' })] }) }), _jsx("tbody", { children: shown.map((row, index) => _jsxs("tr", { children: [columns.map(field => _jsx("td", { className: "border-b p-3 text-start", children: format(row[field.key]) }, field.key)), detail && _jsx("td", { className: "border-b p-3 text-start", children: detail(row) })] }, rowKey ? rowKey(row, index) : index)) })] }) });
65
+ if (!control)
66
+ return table;
67
+ const { page, size, sizes, onSizeChange, onFiltersChange, text } = control;
68
+ return _jsxs("div", { className: "mp-table grid gap-4", children: [filterable.length > 0 && onFiltersChange && _jsxs("form", { role: "search", "aria-label": text.filters, className: "flex flex-wrap items-end gap-4", onSubmit: event => { event.preventDefault(); const data = new FormData(event.currentTarget); onFiltersChange(Object.fromEntries(filterable.map(name => [name, String(data.get(name) ?? '')]))); }, children: [filterable.map(name => _jsx(Field, { name: name, label: labels[name] ?? name, defaultValue: control.filters?.[name] ?? '' }, name)), _jsx(Button, { type: "submit", tone: "secondary", children: text.apply })] }, JSON.stringify(control.filters ?? {})), table, _jsxs("nav", { "aria-label": text.pagination, className: "flex flex-wrap items-center gap-4", children: [_jsx(Button, { type: "button", tone: "ghost", disabled: page <= 1, onClick: () => control.onPageChange(page - 1), children: text.previous }), _jsx("span", { children: text.page(page, count) }), _jsx(Button, { type: "button", tone: "ghost", disabled: count !== undefined ? page >= count : control.hasMore !== true, onClick: () => control.onPageChange(page + 1), children: text.next }), sizes && onSizeChange && _jsx(Select, { label: text.size ?? '', value: String(size), onChange: event => onSizeChange(Number(event.target.value)), children: sizes.map(option => _jsx("option", { value: option, children: option }, option)) })] })] });
69
+ }
70
+ /**
71
+ * With `access`, a field that may not be viewed is not rendered (its label, helper and error with it) and leaves
72
+ * validation and the submitted values; a field that may not be edited is disabled; a save passes `onSubmit` only the
73
+ * changed fields that may be edited, compared with `original` (dirtyPatch). Without `access`, every editable field
74
+ * shows and `onSubmit` receives nothing, as before.
75
+ */
76
+ export function ResourceForm({ fields, values, onChange, onSubmit, labels = {}, saveLabel, disabled = false, access, original = {}, helpers = {}, errors = {} }) {
77
+ const editable = fields.filter(field => field.editable);
78
+ if (editable.some(field => !['string', 'boolean', 'number', 'integer'].includes(field.type)))
79
+ throw new Error('UNSUPPORTED_FORM_FIELD');
80
+ const shown = access ? editable.filter(field => access.field(field.key).view) : editable;
81
+ const locked = (field) => disabled || (access ? !access.field(field.key).edit : false);
82
+ const unavailable = disabled || shown.length === 0 || shown.every(locked);
83
+ const submit = () => {
84
+ if (unavailable)
85
+ return;
86
+ if (!access) {
87
+ onSubmit();
88
+ return;
89
+ }
90
+ // Only the fields shown are compared, so a hidden field never leaves; a changed field that may not be edited
91
+ // throws FORBIDDEN_FIELD instead of being sent.
92
+ onSubmit(access.patch(original, Object.fromEntries(shown.filter(field => Object.hasOwn(values, field.key)).map(field => [field.key, values[field.key]]))));
93
+ };
94
+ return _jsxs("form", { className: "mp-form grid gap-4", onSubmit: event => { event.preventDefault(); submit(); }, children: [shown.map(field => _jsx(Field, { label: labels[field.key] ?? field.key, name: field.key, required: field.required && field.type !== 'boolean', disabled: locked(field), ...(helpers[field.key] !== undefined ? { helper: helpers[field.key] } : {}), ...(errors[field.key] !== undefined ? { error: errors[field.key] } : {}), type: field.type === 'boolean' ? 'checkbox' : field.type === 'number' || field.type === 'integer' ? 'number' : 'text', step: field.type === 'number' ? 'any' : field.type === 'integer' ? 1 : undefined, checked: field.type === 'boolean' ? values[field.key] === true : undefined, value: field.type === 'boolean' ? undefined : String(values[field.key] ?? ''), onChange: event => onChange(field.key, field.type === 'boolean' ? event.target.checked : field.type === 'number' || field.type === 'integer' ? event.target.valueAsNumber : event.target.value) }, field.key)), _jsx(Button, { disabled: unavailable, type: "submit", tone: "secondary", children: saveLabel })] });
95
+ }
96
+ export { Dialog, nextFocus } from './dialog.js';
97
+ export { OneTimeCodeField, ConfirmWithCode, codeDigits } from './one-time-code.js';
98
+ export { Tree, visibleRows, descendantIds, treeKey } from './tree.js';
99
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,KA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AAK,CAAC,IAAI,KAAG,SAAS,CAAA,CAAC,CAAA,KAAK,CAAC,MAAM,CAAC,OAAO,CAAA,CAAC,CAAA,KAAK,CAAC,IAAI,KAAG,QAAQ,IAAE,KAAK,CAAC,IAAI,KAAG,SAAS,CAAA,CAAC,CAAA,KAAK,CAAC,MAAM,CAAC,aAAa,CAAA,CAAC,CAAA,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAA3vB,KAAK,CAAC,GAAG,CAAsvB,CAAC,EAAC,KAAC,MAAM,IAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,WAAW,YAAE,SAAS,GAAU,IAAO,CAAC;AAC59B,CAAC;AACD,OAAO,EAAC,MAAM,EAAC,SAAS,EAAkB,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAC,gBAAgB,EAAC,eAAe,EAAC,UAAU,EAAsD,MAAM,oBAAoB,CAAC;AACpI,OAAO,EAAC,IAAI,EAAC,WAAW,EAAC,aAAa,EAAC,OAAO,EAAyE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { type ReactNode } from 'react';
2
+ /**
3
+ * The digits of typed or pasted input, at most `length` of them: every Unicode decimal digit, of any script,
4
+ * becomes its ASCII digit, and every other character (spaces, dashes, letters, other numerals) is dropped.
5
+ * The value is never checked here.
6
+ */
7
+ export declare function codeDigits(input: string, length: number): string;
8
+ export type OneTimeCodeFieldProps = {
9
+ label: string;
10
+ value: string;
11
+ onChange: (value: string) => void;
12
+ /** Digits in a code; 4 to 10, 6 by default. */
13
+ length?: number;
14
+ helper?: string;
15
+ error?: string;
16
+ disabled?: boolean;
17
+ name?: string;
18
+ };
19
+ /**
20
+ * A one-time-code field: one input that accepts digits only, of a configured length, with
21
+ * autocomplete="one-time-code" so that the platform can offer a received code, paste of a formatted code,
22
+ * and an error state. It never logs or stores the value.
23
+ */
24
+ export declare function OneTimeCodeField({ label, value, onChange, length, helper, error, disabled, name }: OneTimeCodeFieldProps): import("react").JSX.Element;
25
+ export type ConfirmWithCodeProps = {
26
+ open: boolean;
27
+ title: ReactNode;
28
+ description?: ReactNode;
29
+ length?: number;
30
+ labels: Readonly<{
31
+ code: string;
32
+ confirm: string;
33
+ cancel: string;
34
+ close: string;
35
+ failed: string;
36
+ sending?: string;
37
+ }>;
38
+ /**
39
+ * Sends the code to the server through the BFF (a same-origin request with the CSRF token and an
40
+ * idempotency key) and resolves when the server accepted it. The browser never checks the code.
41
+ */
42
+ onConfirm: (code: string, signal: AbortSignal) => Promise<void>;
43
+ onClose: () => void;
44
+ };
45
+ /**
46
+ * Confirms a sensitive action with a code sent to the person. The code lives in component state only: it
47
+ * is cleared on close and on failure, and never written to browser storage, a URL or a log.
48
+ */
49
+ export declare function ConfirmWithCode({ open, title, description, length, labels, onConfirm, onClose }: ConfirmWithCodeProps): import("react").JSX.Element;
@@ -0,0 +1,86 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useRef, useState } from 'react';
4
+ import { Button } from './index.js';
5
+ import { Dialog } from './dialog.js';
6
+ const decimalDigit = /^\p{Nd}$/u;
7
+ /**
8
+ * The value of a Unicode decimal digit (general category Nd), or `undefined` for any other character.
9
+ * Unicode encodes decimal digits in contiguous runs of ten, zero first, so a digit's value is its distance
10
+ * from the start of its run of digits, modulo ten.
11
+ */
12
+ function digitValue(point) {
13
+ if (!decimalDigit.test(String.fromCodePoint(point)))
14
+ return undefined;
15
+ let start = point;
16
+ while (start > 0 && decimalDigit.test(String.fromCodePoint(start - 1)))
17
+ start--;
18
+ return (point - start) % 10;
19
+ }
20
+ /**
21
+ * The digits of typed or pasted input, at most `length` of them: every Unicode decimal digit, of any script,
22
+ * becomes its ASCII digit, and every other character (spaces, dashes, letters, other numerals) is dropped.
23
+ * The value is never checked here.
24
+ */
25
+ export function codeDigits(input, length) {
26
+ let digits = '';
27
+ for (const character of input) {
28
+ const value = digitValue(character.codePointAt(0));
29
+ if (value !== undefined)
30
+ digits += String(value);
31
+ if (digits.length === length)
32
+ break;
33
+ }
34
+ return digits;
35
+ }
36
+ /**
37
+ * A one-time-code field: one input that accepts digits only, of a configured length, with
38
+ * autocomplete="one-time-code" so that the platform can offer a received code, paste of a formatted code,
39
+ * and an error state. It never logs or stores the value.
40
+ */
41
+ export function OneTimeCodeField({ label, value, onChange, length = 6, helper, error, disabled = false, name }) {
42
+ if (!Number.isSafeInteger(length) || length < 4 || length > 10)
43
+ throw new Error('INVALID_CODE_LENGTH');
44
+ const id = useId(), description = id + '-description';
45
+ return _jsxs("label", { className: "mp-field flex max-w-full flex-col gap-[var(--mp-field-gap)]", "data-state": disabled ? 'disabled' : error ? 'error' : 'default', htmlFor: id, children: [_jsx("span", { className: "mp-field-label text-sm font-medium", children: label }), _jsx("input", { id: id, name: name, className: "mp-input mp-code-input h-[var(--mp-control-height)] w-full rounded-[var(--mp-radius-control)] border px-3 tracking-[0.3em]", type: "text", inputMode: "numeric", autoComplete: "one-time-code", pattern: '[0-9]{' + length + '}', maxLength: length * 3, dir: "ltr", spellCheck: false, disabled: disabled, required: true, value: value, "aria-invalid": error !== undefined, "aria-describedby": error || helper ? description : undefined, onChange: event => onChange(codeDigits(event.target.value, length)) }), (helper || error) && _jsx("span", { id: description, className: error ? 'mp-field-helper mp-field-error text-xs' : 'mp-field-helper text-xs', children: error ?? helper })] });
46
+ }
47
+ /**
48
+ * Confirms a sensitive action with a code sent to the person. The code lives in component state only: it
49
+ * is cleared on close and on failure, and never written to browser storage, a URL or a log.
50
+ */
51
+ export function ConfirmWithCode({ open, title, description, length = 6, labels, onConfirm, onClose }) {
52
+ const [code, setCode] = useState(''), [status, setStatus] = useState('idle');
53
+ const active = useRef(null);
54
+ useEffect(() => { if (!open) {
55
+ active.current?.abort();
56
+ active.current = null;
57
+ setCode('');
58
+ setStatus('idle');
59
+ } }, [open]);
60
+ useEffect(() => () => active.current?.abort(), []);
61
+ async function submit(event) {
62
+ event.preventDefault();
63
+ if (code.length !== length || status === 'sending')
64
+ return;
65
+ const controller = new AbortController();
66
+ active.current = controller;
67
+ setStatus('sending');
68
+ try {
69
+ await onConfirm(code, controller.signal);
70
+ if (!controller.signal.aborted) {
71
+ setCode('');
72
+ setStatus('idle');
73
+ }
74
+ }
75
+ catch {
76
+ if (!controller.signal.aborted) {
77
+ setCode('');
78
+ setStatus('failed');
79
+ }
80
+ }
81
+ }
82
+ function close() { active.current?.abort(); setCode(''); setStatus('idle'); onClose(); }
83
+ return _jsx(Dialog, { open: open, title: title, description: description, onClose: close, closeLabel: labels.close, children: _jsxs("form", { className: "grid gap-4", onSubmit: submit, children: [_jsx(OneTimeCodeField, { label: labels.code, value: code, onChange: value => { setCode(value); if (status === 'failed')
84
+ setStatus('idle'); }, length: length, disabled: status === 'sending', ...(status === 'failed' ? { error: labels.failed } : {}) }), _jsxs("div", { className: "flex flex-wrap justify-end gap-2", children: [_jsx(Button, { type: "button", tone: "ghost", onClick: close, children: labels.cancel }), _jsx(Button, { type: "submit", disabled: code.length !== length, loading: status === 'sending', ...(labels.sending ? { loadingLabel: labels.sending } : {}), children: labels.confirm })] })] }) });
85
+ }
86
+ //# sourceMappingURL=one-time-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"one-time-code.js","sourceRoot":"","sources":["../src/one-time-code.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAC,SAAS,EAAC,KAAK,EAAC,MAAM,EAAC,QAAQ,EAA+B,MAAM,OAAO,CAAC;AACpF,OAAO,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAClC,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAEnC,MAAM,YAAY,GAAC,WAAW,CAAC;AAC/B;;;;GAIG;AACH,SAAS,UAAU,CAAC,KAAY;IAC9B,IAAG,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAAC,OAAO,SAAS,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never changes it. */
3
+ export type TreeNode<T = unknown> = Readonly<{
4
+ id: string;
5
+ label: string;
6
+ children?: readonly TreeNode<T>[];
7
+ data?: T;
8
+ }>;
9
+ /** A visible row: the node with its position in the WAI-ARIA tree structure. */
10
+ export type TreeRow<T = unknown> = Readonly<{
11
+ node: TreeNode<T>;
12
+ level: number;
13
+ setSize: number;
14
+ position: number;
15
+ parentId?: string;
16
+ expandable: boolean;
17
+ expanded: boolean;
18
+ }>;
19
+ export type TreeColumn<T = unknown> = Readonly<{
20
+ key: string;
21
+ header: ReactNode;
22
+ cell: (node: TreeNode<T>) => ReactNode;
23
+ }>;
24
+ /** The rows a person can see: depth first, children only under expanded nodes. */
25
+ export declare function visibleRows<T>(nodes: readonly TreeNode<T>[], expanded: ReadonlySet<string>): TreeRow<T>[];
26
+ /** Every descendant id of a node, for a consumer's bulk rule over the current children; read only. */
27
+ export declare function descendantIds<T>(node: TreeNode<T>): string[];
28
+ export type TreeMove = Readonly<{
29
+ focus?: string;
30
+ expand?: string;
31
+ collapse?: string;
32
+ activate?: string;
33
+ }>;
34
+ /**
35
+ * The WAI-ARIA tree keyboard model for one key press. In a right-to-left context the horizontal arrows swap,
36
+ * so that the arrow toward the start of the line always closes and moves to the parent.
37
+ */
38
+ export declare function treeKey<T>(rows: readonly TreeRow<T>[], current: string | undefined, key: string, direction: 'ltr' | 'rtl'): TreeMove | undefined;
39
+ export type TreeProps<T, S extends string> = {
40
+ /** The accessible name of the tree. */
41
+ label: string;
42
+ nodes: readonly TreeNode<T>[];
43
+ /** Controlled: the ids of expanded nodes. */
44
+ expanded: ReadonlySet<string>;
45
+ onExpandedChange: (next: ReadonlySet<string>) => void;
46
+ /** Controlled: the consumer-defined state of each node, and the visible text of each state. */
47
+ states?: Readonly<Record<string, S | undefined>>;
48
+ stateLabels?: Readonly<Record<S, string>>;
49
+ /** Enter or Space on a node; the consumer's rule decides what changes, the component decides nothing. */
50
+ onActivate?: (node: TreeNode<T>) => void;
51
+ /** Columns make it a tree table (role treegrid); the first column is the node label. */
52
+ columns?: readonly TreeColumn<T>[];
53
+ labelHeader?: ReactNode;
54
+ /** Rows are virtualized: a fixed row height and the viewport height in pixels. */
55
+ rowHeight?: number;
56
+ height?: number;
57
+ direction?: 'ltr' | 'rtl';
58
+ };
59
+ /**
60
+ * A controlled tree view, or a tree table with columns, on the WAI-ARIA tree pattern: arrows move, open and
61
+ * close, Home and End jump, Enter and Space activate, with roving focus. Only the rows in view are rendered,
62
+ * so that thousands of nodes stay responsive. It holds no access rule and no inheritance between states.
63
+ */
64
+ export declare function Tree<T, S extends string = string>({ label, nodes, expanded, onExpandedChange, states, stateLabels, onActivate, columns, labelHeader, rowHeight, height, direction }: TreeProps<T, S>): import("react").JSX.Element;
package/dist/tree.js ADDED
@@ -0,0 +1,127 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId, useMemo, useRef, useState } from 'react';
4
+ /** The rows a person can see: depth first, children only under expanded nodes. */
5
+ export function visibleRows(nodes, expanded) {
6
+ const rows = [];
7
+ const visit = (list, level, parentId) => {
8
+ list.forEach((node, index) => {
9
+ const expandable = (node.children?.length ?? 0) > 0, open = expandable && expanded.has(node.id);
10
+ rows.push({ node, level, setSize: list.length, position: index + 1, ...(parentId === undefined ? {} : { parentId }), expandable, expanded: open });
11
+ if (open)
12
+ visit(node.children, level + 1, node.id);
13
+ });
14
+ };
15
+ visit(nodes, 1);
16
+ return rows;
17
+ }
18
+ /** Every descendant id of a node, for a consumer's bulk rule over the current children; read only. */
19
+ export function descendantIds(node) {
20
+ const ids = [];
21
+ const visit = (list) => { for (const child of list ?? []) {
22
+ ids.push(child.id);
23
+ visit(child.children);
24
+ } };
25
+ visit(node.children);
26
+ return ids;
27
+ }
28
+ /**
29
+ * The WAI-ARIA tree keyboard model for one key press. In a right-to-left context the horizontal arrows swap,
30
+ * so that the arrow toward the start of the line always closes and moves to the parent.
31
+ */
32
+ export function treeKey(rows, current, key, direction) {
33
+ const index = Math.max(0, rows.findIndex(row => row.node.id === current)), row = rows[index];
34
+ if (!row)
35
+ return undefined;
36
+ const inward = direction === 'rtl' ? 'ArrowLeft' : 'ArrowRight', outward = direction === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
37
+ switch (key) {
38
+ case 'ArrowDown': return { focus: rows[Math.min(rows.length - 1, index + 1)].node.id };
39
+ case 'ArrowUp': return { focus: rows[Math.max(0, index - 1)].node.id };
40
+ case 'Home': return { focus: rows[0].node.id };
41
+ case 'End': return { focus: rows[rows.length - 1].node.id };
42
+ case 'Enter':
43
+ case ' ': return { activate: row.node.id };
44
+ case inward:
45
+ if (row.expandable && !row.expanded)
46
+ return { expand: row.node.id };
47
+ if (row.expanded)
48
+ return { focus: rows[index + 1].node.id };
49
+ return {};
50
+ case outward:
51
+ if (row.expanded)
52
+ return { collapse: row.node.id };
53
+ return row.parentId === undefined ? {} : { focus: row.parentId };
54
+ default: return undefined;
55
+ }
56
+ }
57
+ /**
58
+ * A controlled tree view, or a tree table with columns, on the WAI-ARIA tree pattern: arrows move, open and
59
+ * close, Home and End jump, Enter and Space activate, with roving focus. Only the rows in view are rendered,
60
+ * so that thousands of nodes stay responsive. It holds no access rule and no inheritance between states.
61
+ */
62
+ export function Tree({ label, nodes, expanded, onExpandedChange, states, stateLabels, onActivate, columns, labelHeader, rowHeight = 40, height = 480, direction }) {
63
+ const rows = useMemo(() => visibleRows(nodes, expanded), [nodes, expanded]);
64
+ const [active, setActive] = useState(undefined), [scroll, setScroll] = useState(0);
65
+ const viewport = useRef(null), base = useId();
66
+ const current = rows.some(row => row.node.id === active) ? active : rows[0]?.node.id;
67
+ const overscan = 4, first = Math.max(0, Math.floor(scroll / rowHeight) - overscan);
68
+ const last = Math.min(rows.length, Math.ceil((scroll + height) / rowHeight) + overscan);
69
+ const currentIndex = rows.findIndex(row => row.node.id === current);
70
+ // The focused row stays rendered when it is scrolled out of view, so that focus is never lost.
71
+ const indexes = [...Array.from({ length: Math.max(0, last - first) }, (_, i) => first + i)];
72
+ if (currentIndex >= 0 && (currentIndex < first || currentIndex >= last))
73
+ indexes.push(currentIndex);
74
+ const grid = columns !== undefined && columns.length > 0;
75
+ const id = (nodeId) => base + '-' + encodeURIComponent(nodeId);
76
+ function move(target) {
77
+ if (target === undefined)
78
+ return;
79
+ setActive(target);
80
+ const index = rows.findIndex(row => row.node.id === target), element = viewport.current;
81
+ if (element && index >= 0) {
82
+ if (index * rowHeight < element.scrollTop)
83
+ element.scrollTop = index * rowHeight;
84
+ else if ((index + 1) * rowHeight > element.scrollTop + height)
85
+ element.scrollTop = (index + 1) * rowHeight - height;
86
+ setScroll(element.scrollTop);
87
+ }
88
+ queueMicrotask(() => document.getElementById(id(target))?.focus());
89
+ }
90
+ function keyDown(event) {
91
+ const resolved = direction ?? ((event.currentTarget.closest('[dir]')?.getAttribute('dir') === 'rtl') ? 'rtl' : 'ltr');
92
+ const result = treeKey(rows, current, event.key, resolved);
93
+ if (!result)
94
+ return;
95
+ event.preventDefault();
96
+ if (result.expand)
97
+ onExpandedChange(new Set([...expanded, result.expand]));
98
+ if (result.collapse) {
99
+ const next = new Set(expanded);
100
+ next.delete(result.collapse);
101
+ onExpandedChange(next);
102
+ }
103
+ if (result.activate) {
104
+ const row = rows.find(entry => entry.node.id === result.activate);
105
+ if (row)
106
+ onActivate?.(row.node);
107
+ }
108
+ move(result.focus);
109
+ }
110
+ const label_ = (row) => {
111
+ const state = states?.[row.node.id], stateLabel = state === undefined ? undefined : stateLabels?.[state];
112
+ return _jsxs("span", { className: "flex min-w-0 items-center gap-2 ps-[calc(var(--mp-tree-level)*1.25rem)]", children: [_jsx("span", { "aria-hidden": "true", className: 'mp-tree-toggle inline-block w-4 text-center' + (row.expanded ? '' : ' rtl:-scale-x-100'), children: row.expandable ? (row.expanded ? '▾' : '▸') : '' }), _jsx("span", { id: id(row.node.id) + '-name', className: "truncate", children: row.node.label }), stateLabel !== undefined && _jsx("span", { id: id(row.node.id) + '-state', className: "mp-tree-state ms-auto text-xs", "data-state": state, children: stateLabel })] });
113
+ };
114
+ return _jsxs("div", { ref: viewport, role: grid ? 'treegrid' : 'tree', "aria-label": label, "aria-rowcount": grid ? rows.length + 1 : undefined, className: "mp-tree relative overflow-auto rounded-[var(--mp-radius-control)] border h-[var(--mp-tree-height)]", style: { '--mp-tree-height': height + 'px' }, onKeyDown: keyDown, onScroll: (event) => setScroll(event.currentTarget.scrollTop), children: [grid && _jsxs("div", { role: "row", "aria-rowindex": 1, className: "mp-tree-header sticky top-0 z-10 flex border-b", children: [_jsx("span", { role: "columnheader", className: "flex-1 p-2 text-start", children: labelHeader }), columns.map(column => _jsx("span", { role: "columnheader", className: "w-40 p-2 text-start", children: column.header }, column.key))] }), _jsx("div", { className: "relative h-[var(--mp-tree-total)]", style: { '--mp-tree-total': rows.length * rowHeight + 'px' }, role: grid ? 'rowgroup' : 'none', children: indexes.map(index => {
115
+ const row = rows[index], focused = row.node.id === current, state = states?.[row.node.id];
116
+ const shared = { id: id(row.node.id), tabIndex: focused ? 0 : -1, 'aria-level': row.level, 'aria-setsize': row.setSize, 'aria-posinset': row.position,
117
+ ...(row.expandable ? { 'aria-expanded': row.expanded } : {}),
118
+ 'aria-labelledby': id(row.node.id) + '-name' + (state !== undefined && stateLabels?.[state] !== undefined ? ' ' + id(row.node.id) + '-state' : ''),
119
+ 'data-focused': focused || undefined, onFocus: () => setActive(row.node.id), onClick: () => { setActive(row.node.id); onActivate?.(row.node); },
120
+ className: 'mp-tree-item absolute inset-x-0 flex h-[var(--mp-tree-row)] translate-y-[var(--mp-tree-offset)] cursor-pointer items-center',
121
+ style: { '--mp-tree-row': rowHeight + 'px', '--mp-tree-offset': index * rowHeight + 'px', '--mp-tree-level': row.level - 1 } };
122
+ return grid
123
+ ? _jsxs("div", { role: "row", "aria-rowindex": index + 2, ...shared, children: [_jsx("span", { role: "gridcell", className: "flex-1 p-2 text-start", children: label_(row) }), columns.map(column => _jsx("span", { role: "gridcell", className: "w-40 p-2 text-start", children: column.cell(row.node) }, column.key))] }, row.node.id)
124
+ : _jsx("div", { role: "treeitem", ...shared, children: _jsx("span", { className: "flex-1 px-2", children: label_(row) }) }, row.node.id);
125
+ }) })] });
126
+ }
127
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.js","sourceRoot":"","sources":["../src/tree.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAC,KAAK,EAAC,OAAO,EAAC,MAAM,EAAC,QAAQ,EAAgD,MAAM,OAAO,CAAC;AAQnG,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAAI,KAA4B,EAAC,QAA4B;IACtF,MAAM,IAAI,GAAc,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAC,CAAC,IAA2B,EAAC,KAAY,EAAC,QAAgB,EAAC,EAAE;QACvE,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAC,KAAK,EAAC,EAAE;YACzB,MAAM,UAAU,GAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,IAAE,CAAC,CAAC,GAAC,CAAC,EAAC,IAAI,GAAC,UAAU,IAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACrF,IAAI,CAAC,IAAI,CAAC,EAAC,IAAI,EAAC,KAAK,EAAC,OAAO,EAAC,IAAI,CAAC,MAAM,EAAC,QAAQ,EAAC,KAAK,GAAC,CAAC,EAAC,GAAG,CAAC,QAAQ,KAAG,SAAS,CAAA,CAAC,CAAA,EAAE,CAAA,CAAC,CAAA,EAAC,QAAQ,EAAC,CAAC,EAAC,UAAU,EAAC,QAAQ,EAAC,IAAI,EAAC,CAAC,CAAC;YAC9H,IAAG,IAAI;gBAAC,KAAK,CAAC,IAAI,CAAC,QAAS,EAAC,KAAK,GAAC,CAAC,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,KAAK,CAA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F,CAAC,KAFnH,GAAG,CAAC,IAAI,CAAC,EAAE,CAGhB;wBACN,CAAC,CAAA,cAAuB,IAAI,EAAC,UAAU,KAAK,MAAM,YAAE,eAAM,SAAS,EAAC,aAAa,YAAE,MAAM,CAAC,GAAG,CAAC,GAAQ,IAA3F,GAAG,CAAC,IAAI,CAAC,EAAE,CAAsF,CAAC;gBACjH,CAAC,CAAC,GACE,IACF,CAAC;AACT,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@mpfrontend/ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/panahister/mpfrontend.git",
8
+ "directory": "packages/ui"
9
+ },
10
+ "type": "module",
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ },
18
+ "./styles.css": "./src/styles.css",
19
+ "./tailwind.css": "./src/tailwind.css"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "src/styles.css",
25
+ "src/tailwind.css"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "provenance": true
30
+ },
31
+ "dependencies": {
32
+ "@mpfrontend/access-core": "0.1.0",
33
+ "@mpfrontend/primitives": "0.1.0"
34
+ },
35
+ "devDependencies": {
36
+ "@happy-dom/global-registrator": "20.14.5",
37
+ "happy-dom": "20.14.5"
38
+ },
39
+ "peerDependencies": {
40
+ "react": "^19.3.0",
41
+ "react-dom": "^19.3.0",
42
+ "tailwindcss": ">=4 <5"
43
+ }
6
44
  }
package/src/styles.css ADDED
@@ -0,0 +1,36 @@
1
+ .mp-button { font:inherit; background:var(--mp-action-primary); color:var(--mp-on-primary); cursor:pointer; }
2
+ .mp-button:not(:disabled):hover { background:var(--mp-action-primaryhover); }
3
+ .mp-button:not(:disabled):active { background:var(--mp-action-primarypressed); }
4
+ .mp-button:focus-visible { outline:2px solid var(--mp-focus-ring); outline-offset:2px; }
5
+ .mp-button[data-tone="secondary"] { background:var(--mp-action-secondary); color:var(--mp-foreground-primary); border:1px solid var(--mp-border-subtle); }
6
+ .mp-button[data-tone="secondary"]:not(:disabled):hover { background:var(--mp-action-secondaryhover); }
7
+ .mp-button[data-tone="ghost"] { background:transparent; color:var(--mp-foreground-primary); }
8
+ .mp-button[data-tone="ghost"]:not(:disabled):hover { background:var(--mp-surface-subtle); }
9
+ .mp-button[data-tone="danger"] { background:var(--mp-action-danger); color:var(--mp-foreground-inverse,var(--mp-on-primary)); }
10
+ .mp-button[data-tone="danger"]:not(:disabled):hover { filter:brightness(0.92); }
11
+ .mp-button:disabled { color:var(--mp-foreground-disabled); background:var(--mp-surface-subtle); cursor:not-allowed; }
12
+ .mp-button-spinner { width:1rem; height:1rem; border:1.5px solid currentColor; border-inline-end-color:transparent; border-radius:50%; animation:mp-spin .8s linear infinite; }
13
+ @keyframes mp-spin { to { transform:rotate(360deg); } }
14
+ @media (prefers-reduced-motion:reduce) { .mp-button-spinner { animation-duration:1.8s; } }
15
+ .mp-field { font-family:var(--mp-font-family); }
16
+ .mp-field-label { color:var(--mp-foreground-primary); }
17
+ .mp-input,.mp-select { box-sizing:border-box; border-color:var(--mp-border-default); background:var(--mp-surface-panel); color:var(--mp-foreground-primary); font:inherit; }
18
+ .mp-input::placeholder { color:var(--mp-foreground-muted); }
19
+ .mp-input:disabled,.mp-select:disabled { color:var(--mp-foreground-disabled); background:var(--mp-surface-subtle); }
20
+ .mp-input[aria-invalid="true"] { border-color:var(--mp-status-error); }
21
+ .mp-field-helper { color:var(--mp-foreground-secondary); }
22
+ .mp-field-error { color:var(--mp-status-error); }
23
+ .mp-select-wrap[data-custom-icon="true"]>.mp-select { appearance:none; padding-inline-end:2.75rem; }
24
+ .mp-card { background:var(--mp-surface-panel); border-color:var(--mp-border-default); }
25
+ .mp-table-wrap th,.mp-table-wrap td { border-color:var(--mp-border-default); }
26
+ .mp-table-wrap th { color:var(--mp-foreground-secondary); }
27
+ .mp-table-wrap caption { text-align:start; padding-block:1rem; }
28
+ .mp-dialog { background:var(--mp-surface-panel); color:var(--mp-foreground-primary); border-color:var(--mp-border-default); }
29
+ .mp-dialog::backdrop { background:color-mix(in srgb, var(--mp-surface-canvas) 70%, transparent); }
30
+ .mp-dialog-close { background:transparent; color:var(--mp-foreground-secondary); border:0; cursor:pointer; font:inherit; }
31
+ .mp-dialog-close:focus-visible { outline:2px solid var(--mp-focus-ring); outline-offset:2px; }
32
+ .mp-tree { border-color:var(--mp-border-default); background:var(--mp-surface-panel); }
33
+ .mp-tree-header { background:var(--mp-surface-panel); border-color:var(--mp-border-default); color:var(--mp-foreground-secondary); }
34
+ .mp-tree-item:hover { background:var(--mp-surface-subtle); }
35
+ .mp-tree-item:focus-visible { outline:2px solid var(--mp-focus-ring); outline-offset:-2px; }
36
+ .mp-tree-state { color:var(--mp-foreground-secondary); }
@@ -0,0 +1,2 @@
1
+ /* Registers the compiled package output as a Tailwind v4 source in consuming applications. */
2
+ @source "../dist/**/*.js";