@ostack.tech/ui-kform 0.16.3 → 0.16.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ostack-ui-kform.js +228 -123
- package/dist/ostack-ui-kform.js.map +1 -1
- package/package.json +2 -2
- package/types/components/PathLink/PathLink.d.ts +22 -1
- package/types/components/ResetOnChange/ResetOnChange.d.ts +40 -0
- package/types/components/ResetOnChange/ResetOnChangeContext.d.ts +7 -0
- package/types/components/ResetOnChange/index.d.ts +3 -0
- package/types/components/ResetOnChange/useResetOnChange.d.ts +96 -0
- package/types/components/TableControl/TableControlColumnFns.d.ts +5 -28
- package/types/components/TableControl/TableControlRemoveRowTrigger.d.ts +10 -20
- package/types/index.d.ts +1 -1
- package/types/utils/extractConfirmDialogOptions.d.ts +13 -0
- package/types/utils/useResetOnChange.d.ts +0 -98
package/dist/ostack-ui-kform.js
CHANGED
|
@@ -9,7 +9,7 @@ import { AtPathError, CurrentPath, FormContext, FormattedValue, InvalidPathError
|
|
|
9
9
|
import { Children, Fragment as Fragment$1, Suspense, createContext, isValidElement, startTransition, useCallback, useContext, useDeferredValue, useEffect, useEffectEvent, useId, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
10
10
|
import { createStore, useStore } from "zustand";
|
|
11
11
|
import { useShallow } from "zustand/react/shallow";
|
|
12
|
-
import { AbsolutePath, AbsolutePathFragment, Path, PathMultimap, PromiseCancellationException, ValidationFailure, arrayToTable, compareSchemaPaths, isComputedSchema, isKtList, isTable, nullableSchemaInnerSchema, sliceTableRows, tableIdsToArray, tableRowsToArray, tableSize } from "@ostack.tech/kform";
|
|
12
|
+
import { AbsolutePath, AbsolutePathFragment, Path, PathMultimap, PromiseCancellationException, ValidationFailure, ValueEvent, arrayToTable, compareSchemaPaths, isComputedSchema, isKtList, isTable, nullableSchemaInnerSchema, sliceTableRows, tableIdsToArray, tableRowsToArray, tableSize } from "@ostack.tech/kform";
|
|
13
13
|
import { subscribeWithSelector } from "zustand/middleware";
|
|
14
14
|
import { shallow } from "zustand/shallow";
|
|
15
15
|
import { fileOpen, fileSave, supported } from "browser-fs-access";
|
|
@@ -2486,6 +2486,186 @@ function DebugInfoControlAddonTrigger({ label, ...otherProps }) {
|
|
|
2486
2486
|
});
|
|
2487
2487
|
}
|
|
2488
2488
|
//#endregion
|
|
2489
|
+
//#region src/components/ResetOnChange/ResetOnChangeContext.ts
|
|
2490
|
+
/** Reset on change context. */
|
|
2491
|
+
var ResetOnChangeContext = createContext(void 0);
|
|
2492
|
+
/** Function providing access to the reset on change context value. */
|
|
2493
|
+
function useResetOnChangeContext() {
|
|
2494
|
+
return useContext(ResetOnChangeContext);
|
|
2495
|
+
}
|
|
2496
|
+
//#endregion
|
|
2497
|
+
//#region src/utils/extractConfirmDialogOptions.ts
|
|
2498
|
+
/** Function used to extract confirm dialog options with a given prefix. */
|
|
2499
|
+
function extractConfirmDialogOptions(options, prefix = "confirmDialog", newPrefix = "") {
|
|
2500
|
+
const confirmDialogOptions = {};
|
|
2501
|
+
const otherOptions = {};
|
|
2502
|
+
for (const k in options) {
|
|
2503
|
+
const v = options[k];
|
|
2504
|
+
if (k.startsWith(prefix)) {
|
|
2505
|
+
const unprefixed = k.slice(prefix.length);
|
|
2506
|
+
const opt = newPrefix ? newPrefix + unprefixed : unprefixed.charAt(0).toLowerCase() + unprefixed.slice(1);
|
|
2507
|
+
confirmDialogOptions[opt] = v;
|
|
2508
|
+
} else otherOptions[k] = v;
|
|
2509
|
+
}
|
|
2510
|
+
return [confirmDialogOptions, otherOptions];
|
|
2511
|
+
}
|
|
2512
|
+
//#endregion
|
|
2513
|
+
//#region src/components/ResetOnChange/useResetOnChange.tsx
|
|
2514
|
+
var ALWAYS_RESET = () => true;
|
|
2515
|
+
/**
|
|
2516
|
+
* Hook which returns an `onValueChange` event handler which resets the fields
|
|
2517
|
+
* at the provided `reset` path(s) to their initial value when a value changes
|
|
2518
|
+
* (according to the `when` function).
|
|
2519
|
+
*
|
|
2520
|
+
* Optionally requests user-confirmation via alert dialog if `showConfirmation`
|
|
2521
|
+
* is provided.
|
|
2522
|
+
*
|
|
2523
|
+
* When using wildcards in `reset`, certain fields may be excluded via
|
|
2524
|
+
* `exclude`.
|
|
2525
|
+
*
|
|
2526
|
+
* Example usage:
|
|
2527
|
+
*
|
|
2528
|
+
* ```tsx
|
|
2529
|
+
* import {
|
|
2530
|
+
* CheckboxControl,
|
|
2531
|
+
* useResetOnChange,
|
|
2532
|
+
* } from "@ostack.tech/ui-kform";
|
|
2533
|
+
*
|
|
2534
|
+
* function NoTransactionsControl() {
|
|
2535
|
+
* const handleOnChange = useResetOnChange("/transactions", {
|
|
2536
|
+
* when: ({ value }) => Boolean(value),
|
|
2537
|
+
* confirmDialogTitle: "Confirm no transactions",
|
|
2538
|
+
* confirmDialogMessage: (
|
|
2539
|
+
* <>
|
|
2540
|
+
* By checking this box, the “Itemised transactions” table will be
|
|
2541
|
+
* cleared. Are you sure you want to continue?
|
|
2542
|
+
* </>
|
|
2543
|
+
* ),
|
|
2544
|
+
* confirmDialogOkText: "Confirm",
|
|
2545
|
+
* });
|
|
2546
|
+
*
|
|
2547
|
+
* return (
|
|
2548
|
+
* <CheckboxControl
|
|
2549
|
+
* path="/noTransactions"
|
|
2550
|
+
* onValueChange={handleOnChange}
|
|
2551
|
+
* >
|
|
2552
|
+
* I declare that no taxable transactions were performed during this
|
|
2553
|
+
* filing period.
|
|
2554
|
+
* </CheckboxControl>
|
|
2555
|
+
* );
|
|
2556
|
+
* }
|
|
2557
|
+
* ```
|
|
2558
|
+
*
|
|
2559
|
+
* @param reset Path(s) to reset when the value changes (relative to the current
|
|
2560
|
+
* path). Wildcards in paths (`*` or `**`) are supported.
|
|
2561
|
+
* @param options Hook options. See {@link UseResetOnChangeOptions}.
|
|
2562
|
+
*/
|
|
2563
|
+
function useResetOnChange(reset, { when = ALWAYS_RESET, exclude, confirmDialogMessage, showConfirmation = Boolean(confirmDialogMessage), setUntouched = true, setPristine = true, undo = undoValueChange, ...confirmDialogOptions } = {}) {
|
|
2564
|
+
const [unprefixedConfirmDialogOptions] = extractConfirmDialogOptions(confirmDialogOptions);
|
|
2565
|
+
const { confirm } = useAlertDialog();
|
|
2566
|
+
const formManager = useFormManager();
|
|
2567
|
+
const currentPath = useCurrentPath();
|
|
2568
|
+
const undoing = useRef(false);
|
|
2569
|
+
const toReset = useMemo(() => {
|
|
2570
|
+
let resolvedReset = (Array.isArray(reset) ? reset : [reset]).map((path) => currentPath.resolve(path));
|
|
2571
|
+
if (exclude) {
|
|
2572
|
+
const resolvedExclude = (Array.isArray(exclude) ? exclude : [exclude]).map((path) => currentPath.resolve(path));
|
|
2573
|
+
resolvedReset = excludePaths(formManager, resolvedReset, resolvedExclude);
|
|
2574
|
+
}
|
|
2575
|
+
return resolvedReset;
|
|
2576
|
+
}, [
|
|
2577
|
+
currentPath,
|
|
2578
|
+
exclude,
|
|
2579
|
+
formManager,
|
|
2580
|
+
reset
|
|
2581
|
+
]);
|
|
2582
|
+
const handleValueChange = async (event) => {
|
|
2583
|
+
if (!undoing.current && when(event)) {
|
|
2584
|
+
if (showConfirmation) {
|
|
2585
|
+
if (await someIsDirty(formManager, toReset) && !await confirm(confirmDialogMessage, {
|
|
2586
|
+
color: "warning",
|
|
2587
|
+
...unprefixedConfirmDialogOptions
|
|
2588
|
+
})) {
|
|
2589
|
+
undoing.current = true;
|
|
2590
|
+
Promise.resolve(undo(formManager, event)).finally(() => undoing.current = false);
|
|
2591
|
+
return;
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
await resetAll(formManager, toReset, setUntouched, setPristine);
|
|
2595
|
+
}
|
|
2596
|
+
};
|
|
2597
|
+
return (event) => void handleValueChange(event);
|
|
2598
|
+
}
|
|
2599
|
+
/** `undoChange` implementation which sets the old value onto the storage. */
|
|
2600
|
+
function undoValueChange(formManager, event) {
|
|
2601
|
+
if (!(event instanceof ValueEvent.Change)) throw new Error("Unable to undo change. Please provide a custom `undo` function.");
|
|
2602
|
+
return formManager.set(event.path, event.oldValue);
|
|
2603
|
+
}
|
|
2604
|
+
/**
|
|
2605
|
+
* Returns an "expanded" (without wildcards) list of all paths in `path` that
|
|
2606
|
+
* **do not** match those in `toExclude`.
|
|
2607
|
+
*/
|
|
2608
|
+
function excludePaths(formManager, paths, exclude) {
|
|
2609
|
+
return paths.flatMap((path) => Array.from(formManager.schemaInfo(path)).map((info) => info.path)).filter((path) => !exclude.some((toIgnore) => path.matches(toIgnore)));
|
|
2610
|
+
}
|
|
2611
|
+
/**
|
|
2612
|
+
* Returns a promise that resolves with whether at least one of the provided
|
|
2613
|
+
* paths is dirty.
|
|
2614
|
+
*/
|
|
2615
|
+
async function someIsDirty(formManager, paths) {
|
|
2616
|
+
return (await Promise.all(paths.map((path) => formManager.isDirty(path)))).some((isDirty) => isDirty);
|
|
2617
|
+
}
|
|
2618
|
+
/**
|
|
2619
|
+
* Resets all the provided paths by calling `reset`, `setPristine` and
|
|
2620
|
+
* `setUntouched` on them.
|
|
2621
|
+
*/
|
|
2622
|
+
async function resetAll(formManager, toReset, setPristine, setUntouched) {
|
|
2623
|
+
await Promise.all(toReset.flatMap((path) => [
|
|
2624
|
+
formManager.reset(path),
|
|
2625
|
+
setPristine && formManager.setPristine(path),
|
|
2626
|
+
setUntouched && formManager.setUntouched(path)
|
|
2627
|
+
]));
|
|
2628
|
+
}
|
|
2629
|
+
//#endregion
|
|
2630
|
+
//#region src/components/ResetOnChange/ResetOnChange.tsx
|
|
2631
|
+
/**
|
|
2632
|
+
* Component used to reset path(s) to their initial value when the value of
|
|
2633
|
+
* controls within it change (according to the `when` function). Built on top of
|
|
2634
|
+
* the `useResetOnChange` hook.
|
|
2635
|
+
*
|
|
2636
|
+
* Optionally requests user-confirmation via alert dialog if `showConfirmation`
|
|
2637
|
+
* is provided.
|
|
2638
|
+
*
|
|
2639
|
+
* When using wildcards in `reset`, certain fields may be excluded via
|
|
2640
|
+
* `exclude`.
|
|
2641
|
+
*
|
|
2642
|
+
* Example usage:
|
|
2643
|
+
*
|
|
2644
|
+
* ```tsx
|
|
2645
|
+
* import { CheckboxControl, ResetOnChange } from "@ostack.tech/ui-kform";
|
|
2646
|
+
*
|
|
2647
|
+
* function SameAddressControl() {
|
|
2648
|
+
* return (
|
|
2649
|
+
* <ResetOnChange
|
|
2650
|
+
* reset="/mailingAddress"
|
|
2651
|
+
* when={({ value }) => Boolean(value)}
|
|
2652
|
+
* >
|
|
2653
|
+
* <CheckboxControl path="/sameAddress">
|
|
2654
|
+
* Same as residential address
|
|
2655
|
+
* </CheckboxControl>
|
|
2656
|
+
* </ResetOnChange>
|
|
2657
|
+
* );
|
|
2658
|
+
* }
|
|
2659
|
+
* ```
|
|
2660
|
+
*/
|
|
2661
|
+
function ResetOnChange({ reset, children, ...otherProps }) {
|
|
2662
|
+
const resetOnChange = useResetOnChange(reset, otherProps);
|
|
2663
|
+
return /* @__PURE__ */ jsx(ResetOnChangeContext, {
|
|
2664
|
+
value: resetOnChange,
|
|
2665
|
+
children
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
//#endregion
|
|
2489
2669
|
//#region src/components/CheckboxControl/CheckboxControl.tsx
|
|
2490
2670
|
/**
|
|
2491
2671
|
* The checkbox control component is a KForm form control for values with
|
|
@@ -2525,7 +2705,7 @@ function CheckboxControl({ path, issueMessages, issuesPanelLabel, displayIssues
|
|
|
2525
2705
|
formManager,
|
|
2526
2706
|
onInitialized,
|
|
2527
2707
|
onFormManagerEvent,
|
|
2528
|
-
onValueChange,
|
|
2708
|
+
onValueChange: combineEventHandlers(onValueChange, useResetOnChangeContext()),
|
|
2529
2709
|
onValidationStatusChange,
|
|
2530
2710
|
onDisplayStatusChange,
|
|
2531
2711
|
onDirtyStatusChange,
|
|
@@ -2757,7 +2937,7 @@ function CheckboxGroupControl({ path, options, issueMessages, issuesPanelLabel,
|
|
|
2757
2937
|
formManager,
|
|
2758
2938
|
onInitialized,
|
|
2759
2939
|
onFormManagerEvent,
|
|
2760
|
-
onValueChange,
|
|
2940
|
+
onValueChange: combineEventHandlers(onValueChange, useResetOnChangeContext()),
|
|
2761
2941
|
onValidationStatusChange,
|
|
2762
2942
|
onDisplayStatusChange,
|
|
2763
2943
|
onDirtyStatusChange,
|
|
@@ -2912,7 +3092,7 @@ function DateControl({ path, issueMessages, issuesPanelLabel, displayIssues = tr
|
|
|
2912
3092
|
formManager,
|
|
2913
3093
|
onInitialized,
|
|
2914
3094
|
onFormManagerEvent,
|
|
2915
|
-
onValueChange,
|
|
3095
|
+
onValueChange: combineEventHandlers(onValueChange, useResetOnChangeContext()),
|
|
2916
3096
|
onValidationStatusChange,
|
|
2917
3097
|
onDisplayStatusChange,
|
|
2918
3098
|
onDirtyStatusChange,
|
|
@@ -3011,6 +3191,7 @@ function DateRangeControl({ startPath, endPath, startIssueMessages, endIssueMess
|
|
|
3011
3191
|
const parseToString = useCallback((formattedValue, state) => parse(formattedValue, state.schema), [parse]);
|
|
3012
3192
|
const formatFromString = useCallback((stringValue, state) => format(stringValue, state.schema), [format]);
|
|
3013
3193
|
const formIsLoading = useFormIsLoading();
|
|
3194
|
+
const resetOnChange = useResetOnChangeContext();
|
|
3014
3195
|
const startController = useTemporalInput(startPath, {
|
|
3015
3196
|
enabled: !formIsLoading,
|
|
3016
3197
|
parseToString,
|
|
@@ -3021,7 +3202,7 @@ function DateRangeControl({ startPath, endPath, startIssueMessages, endIssueMess
|
|
|
3021
3202
|
})), []),
|
|
3022
3203
|
onInitialized: onStartInitialized,
|
|
3023
3204
|
onFormManagerEvent: onStartFormManagerEvent,
|
|
3024
|
-
onValueChange: onStartValueChange,
|
|
3205
|
+
onValueChange: combineEventHandlers(onStartValueChange, resetOnChange),
|
|
3025
3206
|
onValidationStatusChange: onStartValidationStatusChange,
|
|
3026
3207
|
onDisplayStatusChange: onStartDisplayStatusChange,
|
|
3027
3208
|
onDirtyStatusChange: onStartDirtyStatusChange,
|
|
@@ -3037,7 +3218,7 @@ function DateRangeControl({ startPath, endPath, startIssueMessages, endIssueMess
|
|
|
3037
3218
|
})), []),
|
|
3038
3219
|
onInitialized: onEndInitialized,
|
|
3039
3220
|
onFormManagerEvent: onEndFormManagerEvent,
|
|
3040
|
-
onValueChange: onEndValueChange,
|
|
3221
|
+
onValueChange: combineEventHandlers(onEndValueChange, resetOnChange),
|
|
3041
3222
|
onValidationStatusChange: onEndValidationStatusChange,
|
|
3042
3223
|
onDisplayStatusChange: onEndDisplayStatusChange,
|
|
3043
3224
|
onDirtyStatusChange: onEndDirtyStatusChange,
|
|
@@ -3245,7 +3426,7 @@ function FileControl({ path, issueMessages, issuesPanelLabel, displayIssues = tr
|
|
|
3245
3426
|
}, []),
|
|
3246
3427
|
onInitialized,
|
|
3247
3428
|
onFormManagerEvent,
|
|
3248
|
-
onValueChange,
|
|
3429
|
+
onValueChange: combineEventHandlers(onValueChange, useResetOnChangeContext()),
|
|
3249
3430
|
onValidationStatusChange,
|
|
3250
3431
|
onDisplayStatusChange,
|
|
3251
3432
|
onDirtyStatusChange,
|
|
@@ -4955,7 +5136,7 @@ function NumericControl({ path, issueMessages, issuesPanelLabel, displayIssues =
|
|
|
4955
5136
|
formManager,
|
|
4956
5137
|
onInitialized,
|
|
4957
5138
|
onFormManagerEvent,
|
|
4958
|
-
onValueChange,
|
|
5139
|
+
onValueChange: combineEventHandlers(onValueChange, useResetOnChangeContext()),
|
|
4959
5140
|
onValidationStatusChange,
|
|
4960
5141
|
onDisplayStatusChange,
|
|
4961
5142
|
onDirtyStatusChange,
|
|
@@ -5023,7 +5204,28 @@ function NumericControl({ path, issueMessages, issuesPanelLabel, displayIssues =
|
|
|
5023
5204
|
}
|
|
5024
5205
|
//#endregion
|
|
5025
5206
|
//#region src/components/PathLink/PathLink.tsx
|
|
5026
|
-
/**
|
|
5207
|
+
/**
|
|
5208
|
+
* The path link component creates a link (although typically rendered as a
|
|
5209
|
+
* `<button>`) to a part of the form identified by the provided path. It is
|
|
5210
|
+
* built on top of the [`Link`
|
|
5211
|
+
* component](/docs/ostack-ui-typography-link--docs).
|
|
5212
|
+
*
|
|
5213
|
+
* Example usage:
|
|
5214
|
+
*
|
|
5215
|
+
* ```tsx
|
|
5216
|
+
* import { Alert } from "@ostack.tech/ui";
|
|
5217
|
+
* import { PathLink } from "@ostack.tech/ui-kform";
|
|
5218
|
+
*
|
|
5219
|
+
* function ProfileNotice() {
|
|
5220
|
+
* return (
|
|
5221
|
+
* <Alert>
|
|
5222
|
+
* Your profile URL will be generated using your handle. To change it,
|
|
5223
|
+
* update your <PathLink to="/username">username</PathLink>.
|
|
5224
|
+
* </Alert>
|
|
5225
|
+
* );
|
|
5226
|
+
* }
|
|
5227
|
+
* ```
|
|
5228
|
+
*/
|
|
5027
5229
|
function PathLink({ as = "button", to, onClick, ...otherProps }) {
|
|
5028
5230
|
const focus = useFocus();
|
|
5029
5231
|
const path = useResolvedPath(to);
|
|
@@ -5185,7 +5387,7 @@ function RadioGroupControl({ path, options, issueMessages, issuesPanelLabel, dis
|
|
|
5185
5387
|
formManager,
|
|
5186
5388
|
onInitialized,
|
|
5187
5389
|
onFormManagerEvent,
|
|
5188
|
-
onValueChange,
|
|
5390
|
+
onValueChange: combineEventHandlers(onValueChange, useResetOnChangeContext()),
|
|
5189
5391
|
onValidationStatusChange,
|
|
5190
5392
|
onDisplayStatusChange,
|
|
5191
5393
|
onDirtyStatusChange,
|
|
@@ -5549,7 +5751,7 @@ function SelectControl({ path, options: groupedOptions, issueMessages, issuesPan
|
|
|
5549
5751
|
formManager,
|
|
5550
5752
|
onInitialized,
|
|
5551
5753
|
onFormManagerEvent,
|
|
5552
|
-
onValueChange,
|
|
5754
|
+
onValueChange: combineEventHandlers(onValueChange, useResetOnChangeContext()),
|
|
5553
5755
|
onValidationStatusChange,
|
|
5554
5756
|
onDisplayStatusChange,
|
|
5555
5757
|
onDirtyStatusChange,
|
|
@@ -5740,7 +5942,7 @@ function SelectMultipleControl({ path, options: groupedOptions, issueMessages, i
|
|
|
5740
5942
|
formManager,
|
|
5741
5943
|
onInitialized,
|
|
5742
5944
|
onFormManagerEvent,
|
|
5743
|
-
onValueChange,
|
|
5945
|
+
onValueChange: combineEventHandlers(onValueChange, useResetOnChangeContext()),
|
|
5744
5946
|
onValidationStatusChange,
|
|
5745
5947
|
onDisplayStatusChange,
|
|
5746
5948
|
onDirtyStatusChange,
|
|
@@ -6208,7 +6410,7 @@ function TableControl({ path, issueMessages, issuesPanelLabel, displayIssues = t
|
|
|
6208
6410
|
setFormattedValue: setIds,
|
|
6209
6411
|
onInitialized,
|
|
6210
6412
|
onFormManagerEvent,
|
|
6211
|
-
onValueChange,
|
|
6413
|
+
onValueChange: combineEventHandlers(onValueChange, useResetOnChangeContext()),
|
|
6212
6414
|
onValidationStatusChange,
|
|
6213
6415
|
onDisplayStatusChange,
|
|
6214
6416
|
onDirtyStatusChange,
|
|
@@ -6401,9 +6603,10 @@ function TableControlIndexColumnLabel() {
|
|
|
6401
6603
|
* By default, it renders an icon button with label `defaultButtonLabel`,
|
|
6402
6604
|
* however, this can be overriden by providing `children`.
|
|
6403
6605
|
*/
|
|
6404
|
-
function TableControlRemoveRowTrigger({
|
|
6606
|
+
function TableControlRemoveRowTrigger({ onConfirmRowRemoval, onRowRemoved, confirmDialogMessage, confirmDialogTitle, confirmDialogOkText, confirmDialogCancelText, showConfirmation = Boolean(confirmDialogMessage), showWhenReadOnly, disabled, onClick, children, ...otherProps }) {
|
|
6405
6607
|
const [locale] = useLocale();
|
|
6406
|
-
const
|
|
6608
|
+
const [confirmDialogOptions, nonConfirmDialogProps] = extractConfirmDialogOptions(otherProps);
|
|
6609
|
+
const { defaultButtonLabel, label = defaultButtonLabel ?? locale.TableControlRemoveRowTrigger.label, ...iconButtonProps } = nonConfirmDialogProps;
|
|
6407
6610
|
confirmDialogTitle ??= locale.TableControlRemoveRowTrigger.confirmDialogTitle ?? label;
|
|
6408
6611
|
confirmDialogMessage ??= locale.TableControlRemoveRowTrigger.confirmDialogMessage;
|
|
6409
6612
|
confirmDialogOkText ??= locale.TableControlRemoveRowTrigger.confirmDialogOkText;
|
|
@@ -6420,11 +6623,12 @@ function TableControlRemoveRowTrigger({ showConfirmation, onConfirmRowRemoval, o
|
|
|
6420
6623
|
const handleClick = async () => {
|
|
6421
6624
|
setLatestInteraction(controller.getState().path);
|
|
6422
6625
|
const { path, dirty } = getState();
|
|
6423
|
-
if (removing || showConfirmation && dirty && !await confirm(confirmDialogMessage(index), {
|
|
6626
|
+
if (removing || showConfirmation && dirty && !await confirm(typeof confirmDialogMessage === "function" ? confirmDialogMessage(index) : confirmDialogMessage, {
|
|
6424
6627
|
title: confirmDialogTitle,
|
|
6425
6628
|
color: "danger",
|
|
6426
6629
|
okText: confirmDialogOkText,
|
|
6427
|
-
cancelText: confirmDialogCancelText
|
|
6630
|
+
cancelText: confirmDialogCancelText,
|
|
6631
|
+
...confirmDialogOptions
|
|
6428
6632
|
})) return;
|
|
6429
6633
|
setRemoving(true);
|
|
6430
6634
|
try {
|
|
@@ -6450,7 +6654,7 @@ function TableControlRemoveRowTrigger({ showConfirmation, onConfirmRowRemoval, o
|
|
|
6450
6654
|
...commonProps
|
|
6451
6655
|
});
|
|
6452
6656
|
return /* @__PURE__ */ jsx(Slot, {
|
|
6453
|
-
...
|
|
6657
|
+
...nonConfirmDialogProps,
|
|
6454
6658
|
...commonProps,
|
|
6455
6659
|
children
|
|
6456
6660
|
});
|
|
@@ -6499,7 +6703,8 @@ function tableControlIndexColumn({ render, ...otherProps } = {}) {
|
|
|
6499
6703
|
* @param overrides Column properties used to display the actions of each row.
|
|
6500
6704
|
* @returns Table control column used to display the actions of each row.
|
|
6501
6705
|
*/
|
|
6502
|
-
function tableControlActionsColumn({ removeRowLabel, showRowRemovalConfirmation, onConfirmRowRemoval, onRowRemoved,
|
|
6706
|
+
function tableControlActionsColumn({ removeRowLabel, showRowRemovalConfirmation, onConfirmRowRemoval, onRowRemoved, confirmRowRemovalDialogMessage, removeRowProps, render, ...otherProps } = {}) {
|
|
6707
|
+
const [confirmRowRemovalDialogProps, columnProps] = extractConfirmDialogOptions(otherProps, "confirmRowRemovalDialog", "confirmDialog");
|
|
6503
6708
|
return {
|
|
6504
6709
|
label: /* @__PURE__ */ jsx(TableControlActionsColumnLabel, {}),
|
|
6505
6710
|
sticky: "right",
|
|
@@ -6513,13 +6718,11 @@ function tableControlActionsColumn({ removeRowLabel, showRowRemovalConfirmation,
|
|
|
6513
6718
|
showConfirmation: showRowRemovalConfirmation,
|
|
6514
6719
|
onConfirmRowRemoval,
|
|
6515
6720
|
onRowRemoved,
|
|
6516
|
-
confirmDialogTitle: confirmRowRemovalDialogTitle,
|
|
6517
6721
|
confirmDialogMessage: confirmRowRemovalDialogMessage,
|
|
6518
|
-
|
|
6519
|
-
confirmDialogCancelText: confirmRowRemovalDialogCancelText,
|
|
6722
|
+
...confirmRowRemovalDialogProps,
|
|
6520
6723
|
...removeRowProps
|
|
6521
6724
|
}),
|
|
6522
|
-
...
|
|
6725
|
+
...columnProps
|
|
6523
6726
|
};
|
|
6524
6727
|
}
|
|
6525
6728
|
//#endregion
|
|
@@ -6685,7 +6888,7 @@ function TextControl({ path, issueMessages, issuesPanelLabel, displayIssues = tr
|
|
|
6685
6888
|
formManager,
|
|
6686
6889
|
onInitialized,
|
|
6687
6890
|
onFormManagerEvent,
|
|
6688
|
-
onValueChange,
|
|
6891
|
+
onValueChange: combineEventHandlers(onValueChange, useResetOnChangeContext()),
|
|
6689
6892
|
onValidationStatusChange,
|
|
6690
6893
|
onDisplayStatusChange,
|
|
6691
6894
|
onDirtyStatusChange,
|
|
@@ -6798,104 +7001,6 @@ function ValidateAction({ label, keybinds, showWhenReadOnly, loading, disabled,
|
|
|
6798
7001
|
});
|
|
6799
7002
|
}
|
|
6800
7003
|
//#endregion
|
|
6801
|
-
|
|
6802
|
-
var ALWAYS_RESET = () => true;
|
|
6803
|
-
/**
|
|
6804
|
-
* Hook which returns an `onValueChange` event handler which resets the fields
|
|
6805
|
-
* at the provided `toReset` paths to their initial value when the value changes
|
|
6806
|
-
* (according to the `when` function).
|
|
6807
|
-
*
|
|
6808
|
-
* Optionally requests user-confirmation via dialog if `confirmation` is
|
|
6809
|
-
* provided.
|
|
6810
|
-
*
|
|
6811
|
-
* When using wildcards in `toReset`, certain fields may be excluded via
|
|
6812
|
-
* `exclude`.
|
|
6813
|
-
*
|
|
6814
|
-
* Example usage:
|
|
6815
|
-
*
|
|
6816
|
-
* ```tsx
|
|
6817
|
-
* function NoTransactionsControl() {
|
|
6818
|
-
* const handleOnChange = useResetOnChange("/transactions/*", {
|
|
6819
|
-
* when: ({ value }) => value,
|
|
6820
|
-
* confirmation: {
|
|
6821
|
-
* title: "Confirm no transactions",
|
|
6822
|
-
* message: (
|
|
6823
|
-
* <>
|
|
6824
|
-
* By checking this box, all fields in section “Transactions” will
|
|
6825
|
-
* be cleared. Are you sure you want to continue?
|
|
6826
|
-
* </>
|
|
6827
|
-
* ),
|
|
6828
|
-
* okText: "Confirm",
|
|
6829
|
-
* },
|
|
6830
|
-
* });
|
|
6831
|
-
*
|
|
6832
|
-
* return (
|
|
6833
|
-
* <CheckboxControl
|
|
6834
|
-
* path="noTransactions"
|
|
6835
|
-
* onValueChange={handleOnChange}
|
|
6836
|
-
* />
|
|
6837
|
-
* );
|
|
6838
|
-
* }
|
|
6839
|
-
* ```
|
|
6840
|
-
*
|
|
6841
|
-
* @param toReset Paths to reset up when the value changes (relative to the
|
|
6842
|
-
* current path). Wildcards in paths (`*` or `**`) are supported.
|
|
6843
|
-
* @param options Hook options. See {@link UseResetOnChangeOptions}.
|
|
6844
|
-
*/
|
|
6845
|
-
function useResetOnChange(toReset, { when = ALWAYS_RESET, exclude, confirmation, setUntouched = true, setPristine = true } = {}) {
|
|
6846
|
-
const { confirm } = useAlertDialog();
|
|
6847
|
-
const formManager = useFormManager();
|
|
6848
|
-
const currentPath = useCurrentPath();
|
|
6849
|
-
const resettingValue = useRef(false);
|
|
6850
|
-
const handleValueChange = async (event) => {
|
|
6851
|
-
if (!resettingValue.current && when(event)) {
|
|
6852
|
-
let resolvedToReset = (Array.isArray(toReset) ? toReset : [toReset]).map((path) => currentPath.resolve(path));
|
|
6853
|
-
if (exclude) {
|
|
6854
|
-
const resolvedExclude = (Array.isArray(exclude) ? exclude : [exclude]).map((path) => currentPath.resolve(path));
|
|
6855
|
-
resolvedToReset = excludePaths(formManager, resolvedToReset, resolvedExclude);
|
|
6856
|
-
}
|
|
6857
|
-
if (confirmation) {
|
|
6858
|
-
const { message, ...confirmOptions } = confirmation;
|
|
6859
|
-
if (await someIsDirty(formManager, resolvedToReset) && !await confirm(message, {
|
|
6860
|
-
color: "warning",
|
|
6861
|
-
...confirmOptions
|
|
6862
|
-
})) {
|
|
6863
|
-
resettingValue.current = true;
|
|
6864
|
-
formManager.set(event.path, event.oldValue).finally(() => resettingValue.current = false);
|
|
6865
|
-
return;
|
|
6866
|
-
}
|
|
6867
|
-
}
|
|
6868
|
-
await resetAll(formManager, resolvedToReset, setUntouched, setPristine);
|
|
6869
|
-
}
|
|
6870
|
-
};
|
|
6871
|
-
return (event) => void handleValueChange(event);
|
|
6872
|
-
}
|
|
6873
|
-
/**
|
|
6874
|
-
* Returns an "expanded" (without wildcards) list of all paths in `path` that
|
|
6875
|
-
* **do not** match those in `toExclude`.
|
|
6876
|
-
*/
|
|
6877
|
-
function excludePaths(formManager, paths, exclude) {
|
|
6878
|
-
return paths.flatMap((path) => Array.from(formManager.schemaInfo(path)).map((info) => info.path)).filter((path) => !exclude.some((toIgnore) => path.matches(toIgnore)));
|
|
6879
|
-
}
|
|
6880
|
-
/**
|
|
6881
|
-
* Returns a promise that resolves with whether at least one of the provided
|
|
6882
|
-
* paths is dirty.
|
|
6883
|
-
*/
|
|
6884
|
-
async function someIsDirty(formManager, paths) {
|
|
6885
|
-
return (await Promise.all(paths.map((path) => formManager.isDirty(path)))).some((isDirty) => isDirty);
|
|
6886
|
-
}
|
|
6887
|
-
/**
|
|
6888
|
-
* Resets all the provided paths by calling `reset`, `setPristine` and
|
|
6889
|
-
* `setUntouched` on them.
|
|
6890
|
-
*/
|
|
6891
|
-
async function resetAll(formManager, toReset, setPristine, setUntouched) {
|
|
6892
|
-
await Promise.all(toReset.flatMap((path) => [
|
|
6893
|
-
formManager.reset(path),
|
|
6894
|
-
setPristine && formManager.setPristine(path),
|
|
6895
|
-
setUntouched && formManager.setUntouched(path)
|
|
6896
|
-
]));
|
|
6897
|
-
}
|
|
6898
|
-
//#endregion
|
|
6899
|
-
export { ActivePathContext, ActivePathProvider, Annex, AnnexRegistrar, Annexes, AnnexesManager, CheckboxControl, CheckboxGroupControl, CheckboxGroupControlItem, ControlField, DEFAULT_FIRST_ISSUE_KEYBINDS, DEFAULT_FOCUS_KEYBINDS, DEFAULT_LAST_ISSUE_KEYBINDS, DEFAULT_LOAD_KEYBINDS, DEFAULT_NEXT_ISSUE_KEYBINDS, DEFAULT_PREVIOUS_ISSUE_KEYBINDS, DEFAULT_PRINT_KEYBINDS, DEFAULT_SAVE_AS_KEYBINDS, DEFAULT_SAVE_KEYBINDS, DEFAULT_SUBMIT_KEYBINDS, DEFAULT_VALIDATE_KEYBINDS, DateControl, DateRangeControl, DebugInfo, DebugInfoControlAddonTrigger, FileControl, FormApp, FormAppIssueMessages, FormAppStatus, FormPage, FormPageRegistrar, FormPages, FormPagesNavigation, FormStep, FormStepContent, FormStepList, FormStepRegistrar, FormStepper, FormStepperFinishTrigger, FormStepperNextTrigger, FormStepperPreviousTrigger, IssueMessages, IssuesAlert, IssuesPanel, IssuesPopover, LoadAction, LocalizationContext, LocalizationProvider, NumericControl, PathLink, PrefixSuffixContext, PrefixSuffixProvider, PrintAction, RadioGroupControl, RadioGroupControlItem, RepetitiveAnnexRegistrar, SaveAction, SelectControl, SelectControlItem, SelectControlItemGroup, SelectMultipleControl, SelectMultipleControlItem, SelectMultipleControlItemGroup, SubmitAction, TableControl, TableControlActionsColumn, TableControlAddRowTrigger, TableControlCellRenderer, TableControlColumn, TableControlColumnGroup, TableControlColumns, TableControlContent, TableControlIndexColumn, TableControlPagination, TableControlRemoveRowTrigger, TableControlRowsPerPage, TextControl, TopBar, TopBarActions, ValidateAction, displayStatusToColor, displayStatusToControlStatus, locale as enGB, locale$1 as enUS, locale$2 as fr, locale$2 as frFR, locale$3 as pt, locale$3 as ptPT, setDefaultPrefixSuffix, tableControlActionsColumn, tableControlIndexColumn, useActiveIssuesPanelBreadcrumb, useActivePathContext, useControlIssues, useDisplayIssueCodesInIssueMessages, useFocus, useFormAppElement, useFormInDebugMode, useFormIsDisabled, useFormIsLoading, useFormIsReadOnly, useFormIsSaving, useFormIsValidating, useFormLoader, useFormSaver, useFormTitle, useFormValidator, useIsInControlField, useIsRegistered, useIssuesDisplayMode, useLocale, useOnPathFocus, usePrefix, useRegisterControl, useRegisterController, useRegisterControllerWithinControlField, useRegisterIssueMessages, useRegisterLabel, useRegisteredIssueMessage, useResetFocus, useResetOnChange, useSetBottomPanelHeight, useSetLeftSidebarWidth, useSetTopBarHeight, useStartIssuesNavigation, useTableControlApiRef, useTopBarElement };
|
|
7004
|
+
export { ActivePathContext, ActivePathProvider, Annex, AnnexRegistrar, Annexes, AnnexesManager, CheckboxControl, CheckboxGroupControl, CheckboxGroupControlItem, ControlField, DEFAULT_FIRST_ISSUE_KEYBINDS, DEFAULT_FOCUS_KEYBINDS, DEFAULT_LAST_ISSUE_KEYBINDS, DEFAULT_LOAD_KEYBINDS, DEFAULT_NEXT_ISSUE_KEYBINDS, DEFAULT_PREVIOUS_ISSUE_KEYBINDS, DEFAULT_PRINT_KEYBINDS, DEFAULT_SAVE_AS_KEYBINDS, DEFAULT_SAVE_KEYBINDS, DEFAULT_SUBMIT_KEYBINDS, DEFAULT_VALIDATE_KEYBINDS, DateControl, DateRangeControl, DebugInfo, DebugInfoControlAddonTrigger, FileControl, FormApp, FormAppIssueMessages, FormAppStatus, FormPage, FormPageRegistrar, FormPages, FormPagesNavigation, FormStep, FormStepContent, FormStepList, FormStepRegistrar, FormStepper, FormStepperFinishTrigger, FormStepperNextTrigger, FormStepperPreviousTrigger, IssueMessages, IssuesAlert, IssuesPanel, IssuesPopover, LoadAction, LocalizationContext, LocalizationProvider, NumericControl, PathLink, PrefixSuffixContext, PrefixSuffixProvider, PrintAction, RadioGroupControl, RadioGroupControlItem, RepetitiveAnnexRegistrar, ResetOnChange, SaveAction, SelectControl, SelectControlItem, SelectControlItemGroup, SelectMultipleControl, SelectMultipleControlItem, SelectMultipleControlItemGroup, SubmitAction, TableControl, TableControlActionsColumn, TableControlAddRowTrigger, TableControlCellRenderer, TableControlColumn, TableControlColumnGroup, TableControlColumns, TableControlContent, TableControlIndexColumn, TableControlPagination, TableControlRemoveRowTrigger, TableControlRowsPerPage, TextControl, TopBar, TopBarActions, ValidateAction, displayStatusToColor, displayStatusToControlStatus, locale as enGB, locale$1 as enUS, locale$2 as fr, locale$2 as frFR, locale$3 as pt, locale$3 as ptPT, setDefaultPrefixSuffix, tableControlActionsColumn, tableControlIndexColumn, useActiveIssuesPanelBreadcrumb, useActivePathContext, useControlIssues, useDisplayIssueCodesInIssueMessages, useFocus, useFormAppElement, useFormInDebugMode, useFormIsDisabled, useFormIsLoading, useFormIsReadOnly, useFormIsSaving, useFormIsValidating, useFormLoader, useFormSaver, useFormTitle, useFormValidator, useIsInControlField, useIsRegistered, useIssuesDisplayMode, useLocale, useOnPathFocus, usePrefix, useRegisterControl, useRegisterController, useRegisterControllerWithinControlField, useRegisterIssueMessages, useRegisterLabel, useRegisteredIssueMessage, useResetFocus, useResetOnChange, useResetOnChangeContext, useSetBottomPanelHeight, useSetLeftSidebarWidth, useSetTopBarHeight, useStartIssuesNavigation, useTableControlApiRef, useTopBarElement };
|
|
6900
7005
|
|
|
6901
7006
|
//# sourceMappingURL=ostack-ui-kform.js.map
|