@formancy/react 0.8.0 → 0.9.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/index.d.mts +10 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +31 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -109,6 +109,16 @@ export declare function useSubmit(): () => {
|
|
|
109
109
|
errors: Record<string, string[]>;
|
|
110
110
|
};
|
|
111
111
|
//#endregion
|
|
112
|
+
//#region src/go-to-field.d.ts
|
|
113
|
+
/**
|
|
114
|
+
* Take the person to a question: to its page first, on a paged form, and to its control once
|
|
115
|
+
* that page is drawn — into a group's first option, since a fieldset takes no focus, and past a
|
|
116
|
+
* tab a layout hides it behind (0213). What the error summary's links and the review's Change do,
|
|
117
|
+
* one function for both and for a host's own list of questions; the Angular binding's
|
|
118
|
+
* `injectGoToField` is the same. A path no field has throws, as the engine does for one.
|
|
119
|
+
*/
|
|
120
|
+
export declare function useGoToField(): (path: string) => void;
|
|
121
|
+
//#endregion
|
|
112
122
|
//#region src/fields/internals.d.ts
|
|
113
123
|
/**
|
|
114
124
|
* The pieces every control shares: the shell it renders inside, the prop shapes, and the few helpers more than one of them needs.
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/context.tsx","../src/use-field.ts","../src/use-repeater.ts","../src/use-wizard.ts","../src/use-submit.ts","../src/fields/internals.tsx","../src/form.tsx","../src/error-summary.tsx","../src/rich-text.tsx","../src/options-source.ts","../src/scanning.ts","../src/uploads.ts","../src/rich-text-editor.ts","../src/resume-notice.tsx"],"mappings":";;;;;wBAsBgB,mBACd,QACA,OACA;EAEA,QAAQ;;;;;;;EAOR,QAAQ;EACR,WAAW;oBACZ,IAAA;wBAsBe,iBAAiB;;;;;;;;;wBAkBjB,eAAe;;;UCvEd,qBAAqB;EACpC,SAAS;EACT;;EAEA,cAAc;;EAEd;IAAc;IAAY;;;EAE1B;IAAc;;;;;;;;;;;;;wBAaA,SAAS,eAAe,OAAO;;;UCrB9B;EACf;;EAEA;;EAEA;;EAEA;EACA;EACA,UAAU;;EAEV,QAAQ,cAAc;;;;;;;wBAQR,YAAY,eAAe,OAAO;;;UCrBjC;EACf;EACA;;;EAGA;EACA;;EAEA,QAAQ;EACR;;EAEA,KAAK;;;;;;;wBAQS,aAAa;;;;;;;;;;;wBCTb;EAAqB;EAAa,QAAQ
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/context.tsx","../src/use-field.ts","../src/use-repeater.ts","../src/use-wizard.ts","../src/use-submit.ts","../src/go-to-field.ts","../src/fields/internals.tsx","../src/form.tsx","../src/error-summary.tsx","../src/rich-text.tsx","../src/options-source.ts","../src/scanning.ts","../src/uploads.ts","../src/rich-text-editor.ts","../src/resume-notice.tsx"],"mappings":";;;;;wBAsBgB,mBACd,QACA,OACA;EAEA,QAAQ;;;;;;;EAOR,QAAQ;EACR,WAAW;oBACZ,IAAA;wBAsBe,iBAAiB;;;;;;;;;wBAkBjB,eAAe;;;UCvEd,qBAAqB;EACpC,SAAS;EACT;;EAEA,cAAc;;EAEd;IAAc;IAAY;;;EAE1B;IAAc;;;;;;;;;;;;;wBAaA,SAAS,eAAe,OAAO;;;UCrB9B;EACf;;EAEA;;EAEA;;EAEA;EACA;EACA,UAAU;;EAEV,QAAQ,cAAc;;;;;;;wBAQR,YAAY,eAAe,OAAO;;;UCrBjC;EACf;EACA;;;EAGA;EACA;;EAEA,QAAQ;EACR;;EAEA,KAAK;;;;;;;wBAQS,aAAa;;;;;;;;;;;wBCTb;EAAqB;EAAa,QAAQ;;;;;;;;;;;wBCD1C,iBAAiB;;;;;;;;;;;;;;;;UCYhB;EACf;EACA;;KAGU,iBAAiB,cAAc;UAE1B;EACf,SAAS,QAAQ,OAAO,WAAW;EACnC,SAAS,eAAe;;UAGT;EACf;EACA,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AAY;;WAEZ,SAAS,SAAS;;wBAGb,eAAe,WAAW,UAAU,oBAAoB"}
|
package/dist/index.mjs
CHANGED
|
@@ -143,6 +143,24 @@ function useSubmit() {
|
|
|
143
143
|
}, [engine]);
|
|
144
144
|
}
|
|
145
145
|
//#endregion
|
|
146
|
+
//#region src/go-to-field.ts
|
|
147
|
+
function useGoToField() {
|
|
148
|
+
const engine = useFormEngine();
|
|
149
|
+
const [focusing, setFocusing] = useState(void 0);
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (focusing === void 0) return;
|
|
152
|
+
focusControl(document.getElementById(focusing.id));
|
|
153
|
+
setFocusing(void 0);
|
|
154
|
+
}, [focusing]);
|
|
155
|
+
return useCallback((path) => {
|
|
156
|
+
const at = parsePath(path);
|
|
157
|
+
const wizard = engine.wizard();
|
|
158
|
+
const page = engine.pageOf(at);
|
|
159
|
+
if (wizard !== void 0 && wizard.page() !== page) wizard.goTo(page);
|
|
160
|
+
setFocusing({ id: engine.getFieldSnapshot(at).ids.control });
|
|
161
|
+
}, [engine]);
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
146
164
|
//#region src/layout.tsx
|
|
147
165
|
function LayoutTree({ schema, nodes, locale, renderField, at = [], shows }) {
|
|
148
166
|
return /* @__PURE__ */ jsx(Fragment$1, { children: nodes.map((node, index) => {
|
|
@@ -396,12 +414,7 @@ function useReview(goTo) {
|
|
|
396
414
|
const engine = useFormEngine();
|
|
397
415
|
const submit = useSubmit();
|
|
398
416
|
const [reviewing, setReviewing] = useState(false);
|
|
399
|
-
const
|
|
400
|
-
useEffect(() => {
|
|
401
|
-
if (focusing === void 0) return;
|
|
402
|
-
focusControl(document.getElementById(focusing));
|
|
403
|
-
setFocusing(void 0);
|
|
404
|
-
}, [focusing]);
|
|
417
|
+
const goToField = useGoToField();
|
|
405
418
|
return {
|
|
406
419
|
reviewing,
|
|
407
420
|
check() {
|
|
@@ -411,8 +424,7 @@ function useReview(goTo) {
|
|
|
411
424
|
},
|
|
412
425
|
change(answer) {
|
|
413
426
|
setReviewing(false);
|
|
414
|
-
|
|
415
|
-
setFocusing(answer.controlId);
|
|
427
|
+
goToField(answer.field);
|
|
416
428
|
}
|
|
417
429
|
};
|
|
418
430
|
}
|
|
@@ -1008,6 +1020,7 @@ function RadioGroupField({ path, label }) {
|
|
|
1008
1020
|
name: field.controlProps.name,
|
|
1009
1021
|
value: option.value,
|
|
1010
1022
|
checked: field.value === option.value,
|
|
1023
|
+
disabled: field.disabled,
|
|
1011
1024
|
onChange: () => field.setValue(option.value),
|
|
1012
1025
|
onBlur: () => field.touch()
|
|
1013
1026
|
}), /* @__PURE__ */ jsxs("label", {
|
|
@@ -1817,6 +1830,7 @@ function RatingField({ path, label }) {
|
|
|
1817
1830
|
name: controlProps.id,
|
|
1818
1831
|
value,
|
|
1819
1832
|
checked: value === chosen,
|
|
1833
|
+
disabled: field.disabled,
|
|
1820
1834
|
onChange: () => field.setValue(value),
|
|
1821
1835
|
onBlur: () => field.touch()
|
|
1822
1836
|
}), /* @__PURE__ */ jsx("span", {
|
|
@@ -1915,12 +1929,13 @@ function SignatureField({ path, label }) {
|
|
|
1915
1929
|
};
|
|
1916
1930
|
}, []);
|
|
1917
1931
|
const onPointerDown = (event) => {
|
|
1932
|
+
if (field.disabled) return;
|
|
1918
1933
|
before.current = drawn;
|
|
1919
1934
|
stroke.current = [pointFrom(event)];
|
|
1920
1935
|
surface.current?.setPointerCapture?.(event.pointerId);
|
|
1921
1936
|
};
|
|
1922
1937
|
const onPointerMove = (event) => {
|
|
1923
|
-
if (stroke.current === null) return;
|
|
1938
|
+
if (stroke.current === null || field.disabled) return;
|
|
1924
1939
|
stroke.current = [...stroke.current, pointFrom(event)];
|
|
1925
1940
|
commit([...before.current, stroke.current]);
|
|
1926
1941
|
};
|
|
@@ -1944,6 +1959,7 @@ function SignatureField({ path, label }) {
|
|
|
1944
1959
|
viewBox: `0 0 ${String(width)} ${String(height)}`,
|
|
1945
1960
|
role: "img",
|
|
1946
1961
|
"aria-label": label,
|
|
1962
|
+
"aria-disabled": field.disabled ? true : void 0,
|
|
1947
1963
|
onPointerDown,
|
|
1948
1964
|
onPointerMove,
|
|
1949
1965
|
onPointerUp,
|
|
@@ -1955,11 +1971,11 @@ function SignatureField({ path, label }) {
|
|
|
1955
1971
|
}, at))
|
|
1956
1972
|
}),
|
|
1957
1973
|
/* @__PURE__ */ jsx("input", {
|
|
1958
|
-
|
|
1974
|
+
...field.controlProps,
|
|
1959
1975
|
"data-formancy-part": "signature-typed",
|
|
1960
1976
|
type: "text",
|
|
1961
1977
|
value: answer.typed ?? "",
|
|
1962
|
-
"aria-label": text("signature.typed"),
|
|
1978
|
+
"aria-label": text("signature.typed", { label }),
|
|
1963
1979
|
onChange: (event) => {
|
|
1964
1980
|
const typed = event.target.value;
|
|
1965
1981
|
field.setValue(typed === "" ? null : { typed });
|
|
@@ -1969,6 +1985,7 @@ function SignatureField({ path, label }) {
|
|
|
1969
1985
|
/* @__PURE__ */ jsx("button", {
|
|
1970
1986
|
"data-formancy-part": "signature-clear",
|
|
1971
1987
|
type: "button",
|
|
1988
|
+
disabled: field.disabled,
|
|
1972
1989
|
onClick: () => {
|
|
1973
1990
|
stroke.current = null;
|
|
1974
1991
|
before.current = [];
|
|
@@ -2508,12 +2525,7 @@ function ErrorSummary({ labels }) {
|
|
|
2508
2525
|
const errors = useSyncExternalStore(subscribe, getErrors, getErrors);
|
|
2509
2526
|
const region = useRef(null);
|
|
2510
2527
|
const previousCount = useRef(0);
|
|
2511
|
-
const
|
|
2512
|
-
useEffect(() => {
|
|
2513
|
-
if (focusing === void 0) return;
|
|
2514
|
-
focusControl(document.getElementById(focusing));
|
|
2515
|
-
setFocusing(void 0);
|
|
2516
|
-
}, [focusing]);
|
|
2528
|
+
const goToField = useGoToField();
|
|
2517
2529
|
useEffect(() => {
|
|
2518
2530
|
if (errors.length > 0 && previousCount.current === 0) region.current?.focus();
|
|
2519
2531
|
previousCount.current = errors.length;
|
|
@@ -2534,10 +2546,7 @@ function ErrorSummary({ labels }) {
|
|
|
2534
2546
|
href: `#${controlId}`,
|
|
2535
2547
|
onClick: (event) => {
|
|
2536
2548
|
event.preventDefault();
|
|
2537
|
-
|
|
2538
|
-
const page = engine.pageOf(parsePath(path));
|
|
2539
|
-
if (wizard !== void 0 && wizard.page() !== page) wizard.goTo(page);
|
|
2540
|
-
setFocusing(controlId);
|
|
2549
|
+
goToField(path);
|
|
2541
2550
|
},
|
|
2542
2551
|
children: text("errors.entry", {
|
|
2543
2552
|
label: labelFor(path),
|
|
@@ -2581,6 +2590,6 @@ function ResumeNotice({ migration, labels }) {
|
|
|
2581
2590
|
});
|
|
2582
2591
|
}
|
|
2583
2592
|
//#endregion
|
|
2584
|
-
export { ErrorSummary, FormancyForm, FormancyProvider, OptionsSourcesProvider, ResumeNotice, RichText, RichTextEditorProvider, ScannerProvider, UploaderProvider, useField, useFormEngine, useFormText, useOptionsSources, useRepeater, useRichTextEditorFactory, useScanner, useSubmit, useUploader, useWizard };
|
|
2593
|
+
export { ErrorSummary, FormancyForm, FormancyProvider, OptionsSourcesProvider, ResumeNotice, RichText, RichTextEditorProvider, ScannerProvider, UploaderProvider, useField, useFormEngine, useFormText, useGoToField, useOptionsSources, useRepeater, useRichTextEditorFactory, useScanner, useSubmit, useUploader, useWizard };
|
|
2585
2594
|
|
|
2586
2595
|
//# sourceMappingURL=index.mjs.map
|