@cratis/components 4.52.0 → 4.54.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/compat-manifest.json +13 -13
- package/dist/esm/CommandDialog/CommandDialog.d.ts +9 -1
- package/dist/esm/CommandDialog/CommandDialog.d.ts.map +1 -1
- package/dist/esm/CommandDialog/CommandDialog.js +10 -4
- package/dist/esm/CommandDialog/CommandDialog.js.map +1 -1
- package/dist/esm/CommandDialog/index.d.ts +1 -0
- package/dist/esm/CommandDialog/index.d.ts.map +1 -1
- package/dist/esm/CommandDialog/validationFeedback.d.ts +28 -0
- package/dist/esm/CommandDialog/validationFeedback.d.ts.map +1 -0
- package/dist/esm/CommandDialog/validationFeedback.js +20 -0
- package/dist/esm/CommandDialog/validationFeedback.js.map +1 -0
- package/dist/esm/Dialogs/Dialog.d.ts +7 -0
- package/dist/esm/Dialogs/Dialog.d.ts.map +1 -1
- package/dist/esm/Dialogs/Dialog.js.map +1 -1
- package/dist/esm/Dialogs/DialogImplementation.d.ts.map +1 -1
- package/dist/esm/Dialogs/DialogImplementation.js +1 -0
- package/dist/esm/Dialogs/DialogImplementation.js.map +1 -1
- package/dist/esm/Dialogs/DialogRefusalFeedback.d.ts +11 -0
- package/dist/esm/Dialogs/DialogRefusalFeedback.d.ts.map +1 -0
- package/dist/esm/Dialogs/DialogRefusalFeedback.js +4 -0
- package/dist/esm/Dialogs/DialogRefusalFeedback.js.map +1 -0
- package/dist/esm/Dialogs/DialogSlotHost.d.ts.map +1 -1
- package/dist/esm/Dialogs/DialogSlotHost.js +1 -0
- package/dist/esm/Dialogs/DialogSlotHost.js.map +1 -1
- package/dist/esm/Dialogs/index.d.ts +1 -0
- package/dist/esm/Dialogs/index.d.ts.map +1 -1
- package/dist/esm/Dialogs/useDialogFocus.d.ts +5 -2
- package/dist/esm/Dialogs/useDialogFocus.d.ts.map +1 -1
- package/dist/esm/Dialogs/useDialogFocus.js +14 -7
- package/dist/esm/Dialogs/useDialogFocus.js.map +1 -1
- package/package.json +1 -1
package/compat-manifest.json
CHANGED
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
{
|
|
71
71
|
"name": "@cratis/components",
|
|
72
72
|
"role": "core",
|
|
73
|
-
"version": "4.
|
|
73
|
+
"version": "4.54.0",
|
|
74
74
|
"releaseMajorRange": ">=4 <5",
|
|
75
75
|
"independentRelease": false,
|
|
76
76
|
"private": false,
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
{
|
|
95
95
|
"name": "@cratis/eslint-plugin-components",
|
|
96
96
|
"role": "eslint",
|
|
97
|
-
"version": "4.
|
|
97
|
+
"version": "4.54.0",
|
|
98
98
|
"releaseMajorRange": ">=4 <5",
|
|
99
99
|
"independentRelease": false,
|
|
100
100
|
"private": false,
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
{
|
|
108
108
|
"name": "@cratis/components.migrator",
|
|
109
109
|
"role": "migrator",
|
|
110
|
-
"version": "4.
|
|
110
|
+
"version": "4.54.0",
|
|
111
111
|
"releaseMajorRange": ">=4 <5",
|
|
112
112
|
"independentRelease": false,
|
|
113
113
|
"private": false,
|
|
@@ -118,13 +118,13 @@
|
|
|
118
118
|
{
|
|
119
119
|
"name": "@cratis/components.conformance",
|
|
120
120
|
"role": "conformance",
|
|
121
|
-
"version": "4.
|
|
121
|
+
"version": "4.54.0",
|
|
122
122
|
"releaseMajorRange": ">=4 <5",
|
|
123
123
|
"independentRelease": false,
|
|
124
124
|
"private": false,
|
|
125
125
|
"packageAccess": "public",
|
|
126
126
|
"peerDependencies": {
|
|
127
|
-
"@cratis/components": "4.
|
|
127
|
+
"@cratis/components": "4.54.0",
|
|
128
128
|
"react": "^19.0.0",
|
|
129
129
|
"react-dom": "^19.0.0"
|
|
130
130
|
},
|
|
@@ -134,13 +134,13 @@
|
|
|
134
134
|
{
|
|
135
135
|
"name": "@cratis/components.mui",
|
|
136
136
|
"role": "renderer-adapter",
|
|
137
|
-
"version": "4.
|
|
137
|
+
"version": "4.54.0",
|
|
138
138
|
"releaseMajorRange": ">=4 <5",
|
|
139
139
|
"independentRelease": false,
|
|
140
140
|
"private": false,
|
|
141
141
|
"packageAccess": "public",
|
|
142
142
|
"peerDependencies": {
|
|
143
|
-
"@cratis/components": "4.
|
|
143
|
+
"@cratis/components": "4.54.0",
|
|
144
144
|
"@emotion/react": ">=11.5 <12",
|
|
145
145
|
"@emotion/styled": ">=11.11 <12",
|
|
146
146
|
"@mui/material": ">=9 <10",
|
|
@@ -190,13 +190,13 @@
|
|
|
190
190
|
{
|
|
191
191
|
"name": "@cratis/components.primereact",
|
|
192
192
|
"role": "renderer-adapter",
|
|
193
|
-
"version": "4.
|
|
193
|
+
"version": "4.54.0",
|
|
194
194
|
"releaseMajorRange": ">=4 <5",
|
|
195
195
|
"independentRelease": false,
|
|
196
196
|
"private": false,
|
|
197
197
|
"packageAccess": "public",
|
|
198
198
|
"peerDependencies": {
|
|
199
|
-
"@cratis/components": "4.
|
|
199
|
+
"@cratis/components": "4.54.0",
|
|
200
200
|
"@primereact/core": ">=11 <12",
|
|
201
201
|
"@primereact/ui": ">=11 <12",
|
|
202
202
|
"@primeuix/themes": ">=3 <4",
|
|
@@ -258,13 +258,13 @@
|
|
|
258
258
|
{
|
|
259
259
|
"name": "@cratis/components.primereact10",
|
|
260
260
|
"role": "renderer-adapter",
|
|
261
|
-
"version": "4.
|
|
261
|
+
"version": "4.54.0",
|
|
262
262
|
"releaseMajorRange": ">=4 <5",
|
|
263
263
|
"independentRelease": false,
|
|
264
264
|
"private": false,
|
|
265
265
|
"packageAccess": "public",
|
|
266
266
|
"peerDependencies": {
|
|
267
|
-
"@cratis/components": "4.
|
|
267
|
+
"@cratis/components": "4.54.0",
|
|
268
268
|
"primereact": ">=10.9.9 <11",
|
|
269
269
|
"react": "^19.0.0",
|
|
270
270
|
"react-dom": "^19.0.0"
|
|
@@ -306,13 +306,13 @@
|
|
|
306
306
|
{
|
|
307
307
|
"name": "@cratis/components.designsystemet",
|
|
308
308
|
"role": "renderer-adapter",
|
|
309
|
-
"version": "4.
|
|
309
|
+
"version": "4.54.0",
|
|
310
310
|
"releaseMajorRange": ">=4 <5",
|
|
311
311
|
"independentRelease": false,
|
|
312
312
|
"private": false,
|
|
313
313
|
"packageAccess": "public",
|
|
314
314
|
"peerDependencies": {
|
|
315
|
-
"@cratis/components": "4.
|
|
315
|
+
"@cratis/components": "4.54.0",
|
|
316
316
|
"@digdir/designsystemet-css": ">=1.24 <2",
|
|
317
317
|
"@digdir/designsystemet-react": ">=1.24 <2",
|
|
318
318
|
"react": "^19.0.0",
|
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { type CommandFormProps } from '@cratis/arc.react/commands';
|
|
4
4
|
import type { BeforeExecuteCallback } from './applyBeforeExecute.js';
|
|
5
5
|
import type { ConfirmBeforeExecute } from './confirmBeforeExecute.js';
|
|
6
|
+
import { type ValidationAnnouncement } from './validationFeedback.js';
|
|
6
7
|
/**
|
|
7
8
|
* Props for {@link CommandDialog}. Combines the props of a `CommandForm`
|
|
8
9
|
* (`command`, `initialValues`, `onSuccess`, `onValidationFailure`, `onFailed`,
|
|
@@ -13,7 +14,7 @@ import type { ConfirmBeforeExecute } from './confirmBeforeExecute.js';
|
|
|
13
14
|
* @typeParam TCommand - The command record type (must extend `object`).
|
|
14
15
|
* @typeParam TResponse - The response payload type returned by a successful command. Defaults to `object`.
|
|
15
16
|
*/
|
|
16
|
-
export interface CommandDialogProps<TCommand extends object, TResponse = object> extends Omit<CommandFormProps<TCommand, TResponse>, 'children' | 'onBeforeExecute'>, Omit<DialogProps, 'children' | 'isBusy' | 'isCommandDialog'> {
|
|
17
|
+
export interface CommandDialogProps<TCommand extends object, TResponse = object> extends Omit<CommandFormProps<TCommand, TResponse>, 'children' | 'onBeforeExecute'>, Omit<DialogProps, 'children' | 'isBusy' | 'isCommandDialog' | 'refusalFeedback'> {
|
|
17
18
|
/**
|
|
18
19
|
* A transformer invoked with the current command values immediately before
|
|
19
20
|
* the command executes on confirm. It **must return** the values to run with
|
|
@@ -37,6 +38,13 @@ export interface CommandDialogProps<TCommand extends object, TResponse = object>
|
|
|
37
38
|
* Unlike `onConfirm`, this runs before execution, not after success.
|
|
38
39
|
*/
|
|
39
40
|
confirmBeforeExecute?: ConfirmBeforeExecute<TCommand>;
|
|
41
|
+
/**
|
|
42
|
+
* Builds the text announced in the dialog's live region when submit is blocked by
|
|
43
|
+
* validation results. Receives every validation result; use it to localize the
|
|
44
|
+
* announcement. Defaults to an English summary with the number of problems and the
|
|
45
|
+
* first message. Focus moves to the first invalid field either way.
|
|
46
|
+
*/
|
|
47
|
+
validationAnnouncement?: ValidationAnnouncement;
|
|
40
48
|
/**
|
|
41
49
|
* Form fields and arbitrary content for the dialog body. Children that are
|
|
42
50
|
* `CommandFormField` instances are automatically wrapped so they bind to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandDialog.d.ts","sourceRoot":"","sources":["../../../CommandDialog/CommandDialog.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,sBAAmB,CAAC;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAKH,KAAK,gBAAgB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"CommandDialog.d.ts","sourceRoot":"","sources":["../../../CommandDialog/CommandDialog.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,sBAAmB,CAAC;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAKH,KAAK,gBAAgB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAsB,CAAC;AACl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
|
7
7
|
import { markAsCommandFormColumn, isCommandFormField } from '../CommandForm/commandFormMarkers.js';
|
|
8
8
|
import { CommandOverlayContext } from '../CommandForm/commandOverlayContext.js';
|
|
9
|
+
import { validationRefusalFeedback } from './validationFeedback.js';
|
|
9
10
|
|
|
10
|
-
const CommandDialogWrapper = ({ isValid, onClose, onConfirm, onSuccess, onValidationFailure, onFailed, onException, onUnauthorized, onBeforeExecute, confirmBeforeExecute, children, ...dialogProps }) => {
|
|
11
|
+
const CommandDialogWrapper = ({ isValid, onClose, onConfirm, onSuccess, onValidationFailure, onFailed, onException, onUnauthorized, onBeforeExecute, confirmBeforeExecute, validationAnnouncement, children, ...dialogProps }) => {
|
|
11
12
|
const { setCommandValues, setCommandResult, isValid: isCommandFormValid, } = useCommandFormContext();
|
|
12
13
|
const commandInstance = useCommandInstance();
|
|
13
14
|
const submission = useCommandExecution(commandInstance, setCommandValues, onBeforeExecute, confirmBeforeExecute, onException);
|
|
15
|
+
const bodyRef = React.useRef(null);
|
|
16
|
+
const refusedValidation = React.useRef([]);
|
|
17
|
+
const refusalFeedback = () => validationRefusalFeedback(refusedValidation.current, bodyRef.current, validationAnnouncement);
|
|
14
18
|
const handleConfirm = async () => {
|
|
19
|
+
refusedValidation.current = [];
|
|
15
20
|
const result = await submission.run();
|
|
16
21
|
if (!result)
|
|
17
22
|
return false;
|
|
@@ -24,6 +29,7 @@ const CommandDialogWrapper = ({ isValid, onClose, onConfirm, onSuccess, onValida
|
|
|
24
29
|
await onUnauthorized?.();
|
|
25
30
|
if (!result.isValid) {
|
|
26
31
|
await onValidationFailure?.(result.validationResults);
|
|
32
|
+
refusedValidation.current = result.validationResults ?? [];
|
|
27
33
|
}
|
|
28
34
|
if (submission.isMounted())
|
|
29
35
|
setCommandResult(result);
|
|
@@ -59,10 +65,10 @@ const CommandDialogWrapper = ({ isValid, onClose, onConfirm, onSuccess, onValida
|
|
|
59
65
|
};
|
|
60
66
|
const processedChildren = processChildren(children);
|
|
61
67
|
const isDialogValid = isValid !== false && isCommandFormValid;
|
|
62
|
-
return (jsx(Dialog, { ...dialogProps, onClose: onClose, onConfirm: handleConfirm, isValid: isDialogValid, isBusy: submission.isSubmitting, isCommandDialog: true, children: jsx("div", { style: { display: 'flex', flexDirection: 'column', width: '100%' }, children: processedChildren }) }));
|
|
68
|
+
return (jsx(Dialog, { ...dialogProps, onClose: onClose, onConfirm: handleConfirm, isValid: isDialogValid, isBusy: submission.isSubmitting, isCommandDialog: true, refusalFeedback: refusalFeedback, children: jsx("div", { ref: bodyRef, style: { display: 'flex', flexDirection: 'column', width: '100%' }, children: processedChildren }) }));
|
|
63
69
|
};
|
|
64
70
|
const CommandDialogComponent = (props) => {
|
|
65
|
-
const { title, subtitle, placement, closeIcon, headerActions, hideGlobalHeaderActions, sliceLocation, visible, width, style, contentStyle, resizable, buttons = DialogButtons.OkCancel, initialFocus, okLabel, cancelLabel, yesLabel, noLabel, dismissable, dismissOnOutsideClick, closeOnEscape, showCloseButton, closeAriaLabel, isValid, onClose, onConfirm, onCancel, onBeforeExecute, confirmBeforeExecute, className, pt, ptOptions, unstyled, children, ...commandFormProps } = props;
|
|
71
|
+
const { title, subtitle, placement, closeIcon, headerActions, hideGlobalHeaderActions, sliceLocation, visible, width, style, contentStyle, resizable, buttons = DialogButtons.OkCancel, initialFocus, okLabel, cancelLabel, yesLabel, noLabel, dismissable, dismissOnOutsideClick, closeOnEscape, showCloseButton, closeAriaLabel, isValid, onClose, onConfirm, onCancel, onBeforeExecute, confirmBeforeExecute, validationAnnouncement, className, pt, ptOptions, unstyled, children, ...commandFormProps } = props;
|
|
66
72
|
const dialogProps = {
|
|
67
73
|
title,
|
|
68
74
|
subtitle,
|
|
@@ -96,7 +102,7 @@ const CommandDialogComponent = (props) => {
|
|
|
96
102
|
ptOptions,
|
|
97
103
|
unstyled,
|
|
98
104
|
};
|
|
99
|
-
return (jsx(CommandForm, { ...commandFormProps, children: jsx(CommandOverlayContext.Provider, { value: commandFormProps.currentValues, children: jsx(CommandDialogWrapper, { ...dialogProps, onSuccess: props.onSuccess, onValidationFailure: props.onValidationFailure, onFailed: props.onFailed, onException: props.onException, onUnauthorized: props.onUnauthorized, onBeforeExecute: onBeforeExecute, confirmBeforeExecute: confirmBeforeExecute, children: children }) }) }));
|
|
105
|
+
return (jsx(CommandForm, { ...commandFormProps, children: jsx(CommandOverlayContext.Provider, { value: commandFormProps.currentValues, children: jsx(CommandDialogWrapper, { ...dialogProps, onSuccess: props.onSuccess, onValidationFailure: props.onValidationFailure, onFailed: props.onFailed, onException: props.onException, onUnauthorized: props.onUnauthorized, onBeforeExecute: onBeforeExecute, confirmBeforeExecute: confirmBeforeExecute, validationAnnouncement: validationAnnouncement, children: children }) }) }));
|
|
100
106
|
};
|
|
101
107
|
const CommandDialogColumnWrapper = ({ children }) => (jsx(CommandForm.Column, { children: children }));
|
|
102
108
|
markAsCommandFormColumn(CommandDialogColumnWrapper);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandDialog.js","sources":["../../../CommandDialog/CommandDialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogButtons, DialogResult } from '@cratis/arc.react/dialogs';\nimport { Dialog, type DialogProps } from '../Dialogs/Dialog';\nimport React from 'react';\nimport {\n CommandForm,\n CommandFormFieldWrapper,\n useCommandFormContext,\n useCommandInstance,\n type CommandFormProps,\n} from '@cratis/arc.react/commands';\nimport type { BeforeExecuteCallback } from './applyBeforeExecute';\nimport type { ConfirmBeforeExecute } from './confirmBeforeExecute';\nimport { useCommandExecution } from './useCommandExecution';\nimport {\n isCommandFormField,\n markAsCommandFormColumn,\n} from '../CommandForm/commandFormMarkers';\nimport { CommandOverlayContext } from '../CommandForm/commandOverlayContext';\n\n/**\n * Props for {@link CommandDialog}. Combines the props of a `CommandForm`\n * (`command`, `initialValues`, `onSuccess`, `onValidationFailure`, `onFailed`,\n * `onBeforeExecute`, etc.) with the props of a {@link Dialog} (`title`,\n * `buttons`, `width`, `pt`, `unstyled`, …). Dialog presentation props\n * such as `subtitle`, `placement`, and `closeIcon` are forwarded to the dialog.\n *\n * @typeParam TCommand - The command record type (must extend `object`).\n * @typeParam TResponse - The response payload type returned by a successful command. Defaults to `object`.\n */\nexport interface CommandDialogProps<TCommand extends object, TResponse = object>\n extends\n Omit<CommandFormProps<TCommand, TResponse>, 'children' | 'onBeforeExecute'>,\n Omit<DialogProps, 'children' | 'isBusy' | 'isCommandDialog'> {\n /**\n * A transformer invoked with the current command values immediately before\n * the command executes on confirm. It **must return** the values to run with\n * (mutated or not) — a callback that returns nothing does not execute the\n * command with `undefined`; the current values are kept and a warning is\n * logged. May be async.\n *\n * ⚠️ It runs **only on submit**, after the form has already been validated,\n * so a value produced here can never satisfy required-field validation — the\n * submit button stays disabled if a required value is only seeded here. Seed\n * required values through `initialValues`; reserve `onBeforeExecute` for\n * transforms that do not affect validity (for example a generated id).\n */\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n\n /**\n * Ask whether to run the command after validation and `onBeforeExecute`.\n * Receives the transformed values. Only `true` executes; all other outcomes\n * keep the dialog open. May return a promise (for example from a confirmation dialog).\n * If command values change while confirmation is pending, execution is skipped\n * and the dialog stays open; confirm the new values again.\n * Unlike `onConfirm`, this runs before execution, not after success.\n */\n confirmBeforeExecute?: ConfirmBeforeExecute<TCommand>;\n\n /**\n * Form fields and arbitrary content for the dialog body. Children that are\n * `CommandFormField` instances are automatically wrapped so they bind to\n * the command instance.\n */\n children?: React.ReactNode;\n}\n\n// Requiring each key here makes a newly added Dialog prop fail compilation until it is routed.\ntype ForwardedDialogProps = Omit<DialogProps, 'children' | 'isBusy' | 'isCommandDialog'> &\n Record<keyof Omit<DialogProps, 'children' | 'isBusy' | 'isCommandDialog'>, unknown>;\n\nconst CommandDialogWrapper = <TCommand extends object, TResponse = object>({\n isValid,\n onClose,\n onConfirm,\n onSuccess,\n onValidationFailure,\n onFailed,\n onException,\n onUnauthorized,\n onBeforeExecute,\n confirmBeforeExecute,\n children,\n ...dialogProps\n}: Omit<DialogProps, 'isBusy'> & {\n onSuccess?: CommandFormProps<TCommand, TResponse>['onSuccess'];\n onValidationFailure?: CommandFormProps<TCommand, TResponse>['onValidationFailure'];\n onFailed?: CommandFormProps<TCommand, TResponse>['onFailed'];\n onException?: CommandFormProps<TCommand, TResponse>['onException'];\n onUnauthorized?: CommandFormProps<TCommand, TResponse>['onUnauthorized'];\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n confirmBeforeExecute?: ConfirmBeforeExecute<TCommand>;\n}) => {\n const {\n setCommandValues,\n setCommandResult,\n isValid: isCommandFormValid,\n } = useCommandFormContext<TCommand>();\n const commandInstance = useCommandInstance<TCommand>();\n const submission = useCommandExecution<TCommand, TResponse>(\n commandInstance, setCommandValues, onBeforeExecute, confirmBeforeExecute, onException,\n );\n\n const handleConfirm = async () => {\n const result = await submission.run();\n if (!result) return false;\n\n if (!result.isSuccess) {\n await onFailed?.(result);\n if (result.hasExceptions) {\n await onException?.(result.exceptionMessages, result.exceptionStackTrace);\n }\n if (!result.isAuthorized) await onUnauthorized?.();\n if (!result.isValid) {\n await onValidationFailure?.(result.validationResults);\n }\n if (submission.isMounted()) setCommandResult(result);\n return false;\n }\n\n await onSuccess?.(result.response as TResponse);\n if (onConfirm) {\n const closeResult = await onConfirm();\n return closeResult === true;\n }\n if (onClose) {\n const closeResult = await onClose(DialogResult.Ok);\n return closeResult !== false;\n }\n return true;\n };\n\n const processChildren = (nodes: React.ReactNode): React.ReactNode => {\n return React.Children.map(nodes, (child) => {\n if (!React.isValidElement(child)) return child;\n\n const component = child.type as React.ComponentType<unknown>;\n if (isCommandFormField(component)) {\n type FieldElement = Parameters<\n typeof CommandFormFieldWrapper\n >[0]['field'];\n // SAFETY: isCommandFormField guards that child.type is a command form field component.\n return (\n <CommandFormFieldWrapper field={child as unknown as FieldElement} />\n );\n }\n\n const childProps = child.props as Record<string, unknown>;\n // A function child is a render prop, not a node: mapping it would replace the\n // function with its mapped result and break the component that calls it.\n if (childProps.children != null && typeof childProps.children !== 'function') {\n return React.cloneElement(\n child as React.ReactElement<Record<string, unknown>>,\n {\n children: processChildren(childProps.children as React.ReactNode),\n },\n );\n }\n\n return child;\n });\n };\n\n const processedChildren = processChildren(children);\n const isDialogValid = isValid !== false && isCommandFormValid;\n\n return (\n <Dialog\n {...dialogProps}\n onClose={onClose}\n onConfirm={handleConfirm}\n isValid={isDialogValid}\n isBusy={submission.isSubmitting}\n isCommandDialog\n >\n <div style={{ display: 'flex', flexDirection: 'column', width: '100%' }}>\n {processedChildren}\n </div>\n </Dialog>\n );\n};\n\n/**\n * A {@link Dialog} that hosts a Cratis Arc `CommandForm`, runs the bound\n * command on confirm, and only closes when the command succeeds. This is\n * the standard pattern for \"user fills in a form, clicks OK, command runs\n * server-side, dialog dismisses\" — `CommandDialog` collapses about thirty\n * lines of orchestration into the props on a single component.\n *\n * ## Where `TCommand` comes from\n *\n * `TCommand` is an auto-generated TypeScript class produced by the Arc proxy\n * generator from a C# `[Command]` record. `dotnet build` writes a `.ts` file\n * per command with the right property types and a typed `execute()` method;\n * importing the class is all the connection-to-the-backend you need. The\n * class also exposes a `.use()` hook for direct (non-dialog) usage and a\n * `useWithChangeTracking()` variant.\n *\n * ## What happens on confirm\n *\n * 1. If `onBeforeExecute` is supplied, it transforms the command values.\n * Used for generated IDs (`Guid.create()`) that the user did not type in.\n * 2. The command's `execute()` runs through Arc's command pipeline. The\n * backend handler returns either a typed response (mapped to `TResponse`)\n * or a `ValidationResult[]`.\n * 3. On `IsSuccess: true`, `onSuccess(response)` fires and the dialog closes\n * through the dialog host context.\n * 4. On a validation failure, `onValidationFailure(errors)` fires and the\n * form's per-field error display is updated. The dialog stays open.\n * 5. On a domain or transport failure, `onFailed(result)` fires. The dialog\n * stays open and the `CommandResult` is set on the form context so the\n * UI can surface the error to the user.\n *\n * Throughout, the dialog is in the `isBusy` state — the confirm button keeps\n * focus but is `aria-disabled` and ignores activation, the other action\n * buttons are disabled, and the confirm button shows a spinner.\n *\n * ## Destructive commands and initial focus\n *\n * The confirm button is focused when the dialog opens, and a focused native\n * button fires `click` from the `keydown` of `Enter`. A command whose form\n * has required fields is protected from a held or double-tapped `Enter` for\n * free, because `isCommandFormValid` keeps confirm disabled until something\n * is filled in. A command that takes **no** input — the typical \"delete\n * this, permanently\" command — has no such gate, so its confirm button is\n * armed the instant the dialog appears.\n *\n * Pass `initialFocus` (forwarded straight to {@link Dialog}) for those:\n *\n * ```tsx\n * <CommandDialog<DeletePerson>\n * command={DeletePerson}\n * title=\"Delete personal data?\"\n * okLabel=\"Delete\"\n * initialFocus={DialogInitialFocus.Cancel}\n * onSuccess={() => closeDialog(DialogResult.Ok)}>\n * This cannot be undone.\n * </CommandDialog>\n * ```\n *\n * Everything else — the footer, the close (X), `Escape`, and the confirm\n * wiring that runs the command — is untouched.\n *\n * ## Field binding\n *\n * Children that are `CommandFormField` instances (`InputTextField`,\n * `NumberField`, `DropdownField`, every `@cratis/components/CommandForm/fields`\n * widget) bind to a property on the command via the `value` accessor:\n *\n * ```tsx\n * <InputTextField value={c => c.name} title=\"Name\" />\n * ```\n *\n * The accessor's argument is the command instance — TypeScript infers\n * `c.name` is a string and the field type-checks against that. Arbitrary\n * non-field children (custom layout, additional text, decorative elements)\n * are rendered as plain content.\n *\n * ## Typed dialog host usage\n *\n * Combine with `useDialog<CommandResult<TResponse>>()` from\n * `@cratis/arc.react/dialogs` to get a fully-typed result at the call site:\n *\n * ```tsx\n * import { useDialog, DialogResult } from '@cratis/arc.react/dialogs';\n * import { CommandDialog } from '@cratis/components/CommandDialog';\n * import { RegisterAuthor } from './RegisterAuthor'; // proxy from C#\n *\n * type RegisterAuthorResponse = { authorId: string };\n *\n * const RegisterAuthorDialog = () => {\n * const { closeDialog } = useDialogContext<CommandResult<RegisterAuthorResponse>>();\n * return (\n * <CommandDialog<RegisterAuthor, RegisterAuthorResponse>\n * command={RegisterAuthor}\n * title=\"Register author\"\n * okLabel=\"Register\"\n * onSuccess={(response) => closeDialog(DialogResult.Ok)}\n * onCancel={() => closeDialog(DialogResult.Cancelled)}>\n * <InputTextField value={c => c.name} title=\"Name\" />\n * <InputTextField value={c => c.email} title=\"Email\" />\n * </CommandDialog>\n * );\n * };\n * ```\n *\n * ## What's special vs. raw Dialog + CommandForm\n *\n * - Confirm wiring (`onConfirm` → `commandInstance.execute()`) is handled\n * internally; you only supply `onSuccess` / `onValidationFailure` / `onFailed`.\n * - The dialog's `isBusy` state tracks the in-flight command without manual\n * `useState`.\n * - Field error propagation from `CommandResult.validationResults` to the\n * form context is automatic.\n *\n * @typeParam TCommand - The command class (proxy generated from C# `[Command]`).\n * @typeParam TResponse - The success payload type returned by the command's `Handle()` method on the backend.\n * @param props - {@link CommandDialogProps}.\n */\nconst CommandDialogComponent = <TCommand extends object = object, TResponse = object>(\n props: CommandDialogProps<TCommand, TResponse>,\n) => {\n const {\n title,\n subtitle,\n placement,\n closeIcon,\n headerActions,\n hideGlobalHeaderActions,\n sliceLocation,\n visible,\n width,\n style,\n contentStyle,\n resizable,\n buttons = DialogButtons.OkCancel,\n initialFocus,\n okLabel,\n cancelLabel,\n yesLabel,\n noLabel,\n dismissable,\n dismissOnOutsideClick,\n closeOnEscape,\n showCloseButton,\n closeAriaLabel,\n isValid,\n onClose,\n onConfirm,\n onCancel,\n onBeforeExecute,\n confirmBeforeExecute,\n className,\n pt,\n ptOptions,\n unstyled,\n children,\n ...commandFormProps\n } = props;\n\n const dialogProps = {\n title,\n subtitle,\n placement,\n closeIcon,\n headerActions,\n hideGlobalHeaderActions,\n sliceLocation,\n visible,\n width,\n style,\n contentStyle,\n resizable,\n buttons,\n initialFocus,\n okLabel,\n cancelLabel,\n yesLabel,\n noLabel,\n dismissable,\n dismissOnOutsideClick,\n closeOnEscape,\n showCloseButton,\n closeAriaLabel,\n isValid,\n onClose,\n onConfirm,\n onCancel,\n className,\n pt,\n ptOptions,\n unstyled,\n } satisfies ForwardedDialogProps;\n\n return (\n <CommandForm<TCommand, TResponse> {...commandFormProps}>\n <CommandOverlayContext.Provider value={commandFormProps.currentValues}>\n <CommandDialogWrapper<TCommand, TResponse>\n {...dialogProps}\n onSuccess={props.onSuccess}\n onValidationFailure={props.onValidationFailure}\n onFailed={props.onFailed}\n onException={props.onException}\n onUnauthorized={props.onUnauthorized}\n onBeforeExecute={onBeforeExecute}\n confirmBeforeExecute={confirmBeforeExecute}\n >\n {children}\n </CommandDialogWrapper>\n </CommandOverlayContext.Provider>\n </CommandForm>\n );\n};\n\nconst CommandDialogColumnWrapper = ({ children }: { children: React.ReactNode }) => (\n <CommandForm.Column>{children}</CommandForm.Column>\n);\nmarkAsCommandFormColumn(CommandDialogColumnWrapper);\n\nCommandDialogComponent.Column = CommandDialogColumnWrapper;\n\n/**\n * A {@link Dialog} that hosts a Cratis Arc `CommandForm`, runs the bound\n * command on confirm, and only closes when the command succeeds. This is\n * the standard pattern for \"user fills in a form, clicks OK, command runs\n * server-side, dialog dismisses\" — `CommandDialog` collapses about thirty\n * lines of orchestration into the props on a single component.\n *\n * See {@link CommandDialogComponent} for full documentation.\n *\n * @typeParam TCommand - The command class (proxy generated from C# `[Command]`).\n * @typeParam TResponse - The success payload type returned by the command's `Handle()` method on the backend.\n */\nexport const CommandDialog = CommandDialogComponent;\n"],"names":["_jsx"],"mappings":";;;;;;;;;AAyEA,MAAM,oBAAoB,GAAG,CAA8C,EACvE,OAAO,EACP,OAAO,EACP,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,WAAW,EACX,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,QAAQ,EACR,GAAG,WAAW,EASjB,KAAI;AACD,IAAA,MAAM,EACF,gBAAgB,EAChB,gBAAgB,EAChB,OAAO,EAAE,kBAAkB,GAC9B,GAAG,qBAAqB,EAAY;AACrC,IAAA,MAAM,eAAe,GAAG,kBAAkB,EAAY;AACtD,IAAA,MAAM,UAAU,GAAG,mBA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ACvB;AAEtB,CAAC;AAED,MAAM,0BAA0B,GAAG,CAAC,EAAE,QAAQ,EAAiC,MAC3EA,GAAA,CAAC,WAAW,CAAC,MAAM,cAAE,QAAQ,EAAA,CAAsB,CACtD;AACD,uBAAuB,CAAC,0BAA0B,CAAC;AAEnD,sBAAsB,CAAC,MAAM,GAAG,0BAA0B;AAcnD,MAAM,aAAa,GAAG;;"}
|
|
1
|
+
{"version":3,"file":"CommandDialog.js","sources":["../../../CommandDialog/CommandDialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogButtons, DialogResult } from '@cratis/arc.react/dialogs';\nimport { Dialog, type DialogProps } from '../Dialogs/Dialog';\nimport React from 'react';\nimport {\n CommandForm,\n CommandFormFieldWrapper,\n useCommandFormContext,\n useCommandInstance,\n type CommandFormProps,\n} from '@cratis/arc.react/commands';\nimport type { BeforeExecuteCallback } from './applyBeforeExecute';\nimport type { ConfirmBeforeExecute } from './confirmBeforeExecute';\nimport { useCommandExecution } from './useCommandExecution';\nimport {\n isCommandFormField,\n markAsCommandFormColumn,\n} from '../CommandForm/commandFormMarkers';\nimport { CommandOverlayContext } from '../CommandForm/commandOverlayContext';\nimport {\n validationRefusalFeedback,\n type CommandValidationResults,\n type ValidationAnnouncement,\n} from './validationFeedback';\n\n/**\n * Props for {@link CommandDialog}. Combines the props of a `CommandForm`\n * (`command`, `initialValues`, `onSuccess`, `onValidationFailure`, `onFailed`,\n * `onBeforeExecute`, etc.) with the props of a {@link Dialog} (`title`,\n * `buttons`, `width`, `pt`, `unstyled`, …). Dialog presentation props\n * such as `subtitle`, `placement`, and `closeIcon` are forwarded to the dialog.\n *\n * @typeParam TCommand - The command record type (must extend `object`).\n * @typeParam TResponse - The response payload type returned by a successful command. Defaults to `object`.\n */\nexport interface CommandDialogProps<TCommand extends object, TResponse = object>\n extends\n Omit<CommandFormProps<TCommand, TResponse>, 'children' | 'onBeforeExecute'>,\n Omit<DialogProps, 'children' | 'isBusy' | 'isCommandDialog' | 'refusalFeedback'> {\n /**\n * A transformer invoked with the current command values immediately before\n * the command executes on confirm. It **must return** the values to run with\n * (mutated or not) — a callback that returns nothing does not execute the\n * command with `undefined`; the current values are kept and a warning is\n * logged. May be async.\n *\n * ⚠️ It runs **only on submit**, after the form has already been validated,\n * so a value produced here can never satisfy required-field validation — the\n * submit button stays disabled if a required value is only seeded here. Seed\n * required values through `initialValues`; reserve `onBeforeExecute` for\n * transforms that do not affect validity (for example a generated id).\n */\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n\n /**\n * Ask whether to run the command after validation and `onBeforeExecute`.\n * Receives the transformed values. Only `true` executes; all other outcomes\n * keep the dialog open. May return a promise (for example from a confirmation dialog).\n * If command values change while confirmation is pending, execution is skipped\n * and the dialog stays open; confirm the new values again.\n * Unlike `onConfirm`, this runs before execution, not after success.\n */\n confirmBeforeExecute?: ConfirmBeforeExecute<TCommand>;\n\n /**\n * Builds the text announced in the dialog's live region when submit is blocked by\n * validation results. Receives every validation result; use it to localize the\n * announcement. Defaults to an English summary with the number of problems and the\n * first message. Focus moves to the first invalid field either way.\n */\n validationAnnouncement?: ValidationAnnouncement;\n\n /**\n * Form fields and arbitrary content for the dialog body. Children that are\n * `CommandFormField` instances are automatically wrapped so they bind to\n * the command instance.\n */\n children?: React.ReactNode;\n}\n\n// Requiring each key here makes a newly added Dialog prop fail compilation until it is routed.\ntype CommandDialogOwnedProps = 'children' | 'isBusy' | 'isCommandDialog' | 'refusalFeedback';\ntype ForwardedDialogProps = Omit<DialogProps, CommandDialogOwnedProps> &\n Record<keyof Omit<DialogProps, CommandDialogOwnedProps>, unknown>;\n\nconst CommandDialogWrapper = <TCommand extends object, TResponse = object>({\n isValid,\n onClose,\n onConfirm,\n onSuccess,\n onValidationFailure,\n onFailed,\n onException,\n onUnauthorized,\n onBeforeExecute,\n confirmBeforeExecute,\n validationAnnouncement,\n children,\n ...dialogProps\n}: Omit<DialogProps, 'isBusy' | 'refusalFeedback'> & {\n onSuccess?: CommandFormProps<TCommand, TResponse>['onSuccess'];\n onValidationFailure?: CommandFormProps<TCommand, TResponse>['onValidationFailure'];\n onFailed?: CommandFormProps<TCommand, TResponse>['onFailed'];\n onException?: CommandFormProps<TCommand, TResponse>['onException'];\n onUnauthorized?: CommandFormProps<TCommand, TResponse>['onUnauthorized'];\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n confirmBeforeExecute?: ConfirmBeforeExecute<TCommand>;\n validationAnnouncement?: ValidationAnnouncement;\n}) => {\n const {\n setCommandValues,\n setCommandResult,\n isValid: isCommandFormValid,\n } = useCommandFormContext<TCommand>();\n const commandInstance = useCommandInstance<TCommand>();\n const submission = useCommandExecution<TCommand, TResponse>(\n commandInstance, setCommandValues, onBeforeExecute, confirmBeforeExecute, onException,\n );\n\n const bodyRef = React.useRef<HTMLDivElement>(null);\n const refusedValidation = React.useRef<CommandValidationResults>([]);\n const refusalFeedback = () =>\n validationRefusalFeedback(refusedValidation.current, bodyRef.current, validationAnnouncement);\n\n const handleConfirm = async () => {\n refusedValidation.current = [];\n const result = await submission.run();\n if (!result) return false;\n\n if (!result.isSuccess) {\n await onFailed?.(result);\n if (result.hasExceptions) {\n await onException?.(result.exceptionMessages, result.exceptionStackTrace);\n }\n if (!result.isAuthorized) await onUnauthorized?.();\n if (!result.isValid) {\n await onValidationFailure?.(result.validationResults);\n refusedValidation.current = result.validationResults ?? [];\n }\n if (submission.isMounted()) setCommandResult(result);\n return false;\n }\n\n await onSuccess?.(result.response as TResponse);\n if (onConfirm) {\n const closeResult = await onConfirm();\n return closeResult === true;\n }\n if (onClose) {\n const closeResult = await onClose(DialogResult.Ok);\n return closeResult !== false;\n }\n return true;\n };\n\n const processChildren = (nodes: React.ReactNode): React.ReactNode => {\n return React.Children.map(nodes, (child) => {\n if (!React.isValidElement(child)) return child;\n\n const component = child.type as React.ComponentType<unknown>;\n if (isCommandFormField(component)) {\n type FieldElement = Parameters<\n typeof CommandFormFieldWrapper\n >[0]['field'];\n // SAFETY: isCommandFormField guards that child.type is a command form field component.\n return (\n <CommandFormFieldWrapper field={child as unknown as FieldElement} />\n );\n }\n\n const childProps = child.props as Record<string, unknown>;\n // A function child is a render prop, not a node: mapping it would replace the\n // function with its mapped result and break the component that calls it.\n if (childProps.children != null && typeof childProps.children !== 'function') {\n return React.cloneElement(\n child as React.ReactElement<Record<string, unknown>>,\n {\n children: processChildren(childProps.children as React.ReactNode),\n },\n );\n }\n\n return child;\n });\n };\n\n const processedChildren = processChildren(children);\n const isDialogValid = isValid !== false && isCommandFormValid;\n\n return (\n <Dialog\n {...dialogProps}\n onClose={onClose}\n onConfirm={handleConfirm}\n isValid={isDialogValid}\n isBusy={submission.isSubmitting}\n isCommandDialog\n refusalFeedback={refusalFeedback}\n >\n <div ref={bodyRef} style={{ display: 'flex', flexDirection: 'column', width: '100%' }}>\n {processedChildren}\n </div>\n </Dialog>\n );\n};\n\n/**\n * A {@link Dialog} that hosts a Cratis Arc `CommandForm`, runs the bound\n * command on confirm, and only closes when the command succeeds. This is\n * the standard pattern for \"user fills in a form, clicks OK, command runs\n * server-side, dialog dismisses\" — `CommandDialog` collapses about thirty\n * lines of orchestration into the props on a single component.\n *\n * ## Where `TCommand` comes from\n *\n * `TCommand` is an auto-generated TypeScript class produced by the Arc proxy\n * generator from a C# `[Command]` record. `dotnet build` writes a `.ts` file\n * per command with the right property types and a typed `execute()` method;\n * importing the class is all the connection-to-the-backend you need. The\n * class also exposes a `.use()` hook for direct (non-dialog) usage and a\n * `useWithChangeTracking()` variant.\n *\n * ## What happens on confirm\n *\n * 1. If `onBeforeExecute` is supplied, it transforms the command values.\n * Used for generated IDs (`Guid.create()`) that the user did not type in.\n * 2. The command's `execute()` runs through Arc's command pipeline. The\n * backend handler returns either a typed response (mapped to `TResponse`)\n * or a `ValidationResult[]`.\n * 3. On `IsSuccess: true`, `onSuccess(response)` fires and the dialog closes\n * through the dialog host context.\n * 4. On a validation failure, `onValidationFailure(errors)` fires and the\n * form's per-field error display is updated. The dialog stays open.\n * 5. On a domain or transport failure, `onFailed(result)` fires. The dialog\n * stays open and the `CommandResult` is set on the form context so the\n * UI can surface the error to the user.\n *\n * Throughout, the dialog is in the `isBusy` state — the confirm button keeps\n * focus but is `aria-disabled` and ignores activation, the other action\n * buttons are disabled, and the confirm button shows a spinner.\n *\n * ## Destructive commands and initial focus\n *\n * The confirm button is focused when the dialog opens, and a focused native\n * button fires `click` from the `keydown` of `Enter`. A command whose form\n * has required fields is protected from a held or double-tapped `Enter` for\n * free, because `isCommandFormValid` keeps confirm disabled until something\n * is filled in. A command that takes **no** input — the typical \"delete\n * this, permanently\" command — has no such gate, so its confirm button is\n * armed the instant the dialog appears.\n *\n * Pass `initialFocus` (forwarded straight to {@link Dialog}) for those:\n *\n * ```tsx\n * <CommandDialog<DeletePerson>\n * command={DeletePerson}\n * title=\"Delete personal data?\"\n * okLabel=\"Delete\"\n * initialFocus={DialogInitialFocus.Cancel}\n * onSuccess={() => closeDialog(DialogResult.Ok)}>\n * This cannot be undone.\n * </CommandDialog>\n * ```\n *\n * Everything else — the footer, the close (X), `Escape`, and the confirm\n * wiring that runs the command — is untouched.\n *\n * ## Field binding\n *\n * Children that are `CommandFormField` instances (`InputTextField`,\n * `NumberField`, `DropdownField`, every `@cratis/components/CommandForm/fields`\n * widget) bind to a property on the command via the `value` accessor:\n *\n * ```tsx\n * <InputTextField value={c => c.name} title=\"Name\" />\n * ```\n *\n * The accessor's argument is the command instance — TypeScript infers\n * `c.name` is a string and the field type-checks against that. Arbitrary\n * non-field children (custom layout, additional text, decorative elements)\n * are rendered as plain content.\n *\n * ## Typed dialog host usage\n *\n * Combine with `useDialog<CommandResult<TResponse>>()` from\n * `@cratis/arc.react/dialogs` to get a fully-typed result at the call site:\n *\n * ```tsx\n * import { useDialog, DialogResult } from '@cratis/arc.react/dialogs';\n * import { CommandDialog } from '@cratis/components/CommandDialog';\n * import { RegisterAuthor } from './RegisterAuthor'; // proxy from C#\n *\n * type RegisterAuthorResponse = { authorId: string };\n *\n * const RegisterAuthorDialog = () => {\n * const { closeDialog } = useDialogContext<CommandResult<RegisterAuthorResponse>>();\n * return (\n * <CommandDialog<RegisterAuthor, RegisterAuthorResponse>\n * command={RegisterAuthor}\n * title=\"Register author\"\n * okLabel=\"Register\"\n * onSuccess={(response) => closeDialog(DialogResult.Ok)}\n * onCancel={() => closeDialog(DialogResult.Cancelled)}>\n * <InputTextField value={c => c.name} title=\"Name\" />\n * <InputTextField value={c => c.email} title=\"Email\" />\n * </CommandDialog>\n * );\n * };\n * ```\n *\n * ## What's special vs. raw Dialog + CommandForm\n *\n * - Confirm wiring (`onConfirm` → `commandInstance.execute()`) is handled\n * internally; you only supply `onSuccess` / `onValidationFailure` / `onFailed`.\n * - The dialog's `isBusy` state tracks the in-flight command without manual\n * `useState`.\n * - Field error propagation from `CommandResult.validationResults` to the\n * form context is automatic.\n *\n * @typeParam TCommand - The command class (proxy generated from C# `[Command]`).\n * @typeParam TResponse - The success payload type returned by the command's `Handle()` method on the backend.\n * @param props - {@link CommandDialogProps}.\n */\nconst CommandDialogComponent = <TCommand extends object = object, TResponse = object>(\n props: CommandDialogProps<TCommand, TResponse>,\n) => {\n const {\n title,\n subtitle,\n placement,\n closeIcon,\n headerActions,\n hideGlobalHeaderActions,\n sliceLocation,\n visible,\n width,\n style,\n contentStyle,\n resizable,\n buttons = DialogButtons.OkCancel,\n initialFocus,\n okLabel,\n cancelLabel,\n yesLabel,\n noLabel,\n dismissable,\n dismissOnOutsideClick,\n closeOnEscape,\n showCloseButton,\n closeAriaLabel,\n isValid,\n onClose,\n onConfirm,\n onCancel,\n onBeforeExecute,\n confirmBeforeExecute,\n validationAnnouncement,\n className,\n pt,\n ptOptions,\n unstyled,\n children,\n ...commandFormProps\n } = props;\n\n const dialogProps = {\n title,\n subtitle,\n placement,\n closeIcon,\n headerActions,\n hideGlobalHeaderActions,\n sliceLocation,\n visible,\n width,\n style,\n contentStyle,\n resizable,\n buttons,\n initialFocus,\n okLabel,\n cancelLabel,\n yesLabel,\n noLabel,\n dismissable,\n dismissOnOutsideClick,\n closeOnEscape,\n showCloseButton,\n closeAriaLabel,\n isValid,\n onClose,\n onConfirm,\n onCancel,\n className,\n pt,\n ptOptions,\n unstyled,\n } satisfies ForwardedDialogProps;\n\n return (\n <CommandForm<TCommand, TResponse> {...commandFormProps}>\n <CommandOverlayContext.Provider value={commandFormProps.currentValues}>\n <CommandDialogWrapper<TCommand, TResponse>\n {...dialogProps}\n onSuccess={props.onSuccess}\n onValidationFailure={props.onValidationFailure}\n onFailed={props.onFailed}\n onException={props.onException}\n onUnauthorized={props.onUnauthorized}\n onBeforeExecute={onBeforeExecute}\n confirmBeforeExecute={confirmBeforeExecute}\n validationAnnouncement={validationAnnouncement}\n >\n {children}\n </CommandDialogWrapper>\n </CommandOverlayContext.Provider>\n </CommandForm>\n );\n};\n\nconst CommandDialogColumnWrapper = ({ children }: { children: React.ReactNode }) => (\n <CommandForm.Column>{children}</CommandForm.Column>\n);\nmarkAsCommandFormColumn(CommandDialogColumnWrapper);\n\nCommandDialogComponent.Column = CommandDialogColumnWrapper;\n\n/**\n * A {@link Dialog} that hosts a Cratis Arc `CommandForm`, runs the bound\n * command on confirm, and only closes when the command succeeds. This is\n * the standard pattern for \"user fills in a form, clicks OK, command runs\n * server-side, dialog dismisses\" — `CommandDialog` collapses about thirty\n * lines of orchestration into the props on a single component.\n *\n * See {@link CommandDialogComponent} for full documentation.\n *\n * @typeParam TCommand - The command class (proxy generated from C# `[Command]`).\n * @typeParam TResponse - The success payload type returned by the command's `Handle()` method on the backend.\n */\nexport const CommandDialog = CommandDialogComponent;\n"],"names":["_jsx"],"mappings":";;;;;;;;;;AAuFA,MAAM,oBAAoB,GAAG,CAA8C,EACvE,OAAO,EACP,OAAO,EACP,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,WAAW,EACX,cAAc,EACd,eAAe,EACf,oBAAoB,EACp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Q;QACR,OAAO;QACP,WAAW;QACX,qBAAqB;QACrB,aAAa;QACb,eAAe;QACf,cAAc;QACd,OAAO;QACP,OAAO;QACP,SAAS;QACT,QAAQ;QACR,SAAS;QACT,EAAE;QACF,SAAS;QACT,QAAQ;KACoB;AAEhC,IAAA,QACIA,GAAA,CAAC,WAAW,EAAA,EAAA,GAA0B,gBAAgB,EAAA,QAAA,EAClDA,GAAA,CAAC,qBAAqB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,gBAAgB,CAAC,aAAa,EAAA,QAAA,EACjEA,GAAA,CAAC,oBAAoB,EAAA,EAAA,GACb,WAAW,EACf,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,mBAAmB,EAAE,KAAK,CAAC,mBAAmB,EAC9C,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,WAAW,EAAE,KAAK,CAAC,WAAW,EAC9B,cAAc,EAAE,KAAK,CAAC,cAAc,EACpC,eAAe,EAAE,eAAe,EAChC,oBAAoB,EAAE,oBAAoB,EAC1C,sBAAsB,EAAE,sBAAsB,YAE7C,QAAQ,EAAA,CACU,EAAA,CACM,EAAA,CACvB;AAEtB,CAAC;AAED,MAAM,0BAA0B,GAAG,CAAC,EAAE,QAAQ,EAAiC,MAC3EA,GAAA,CAAC,WAAW,CAAC,MAAM,cAAE,QAAQ,EAAA,CAAsB,CACtD;AACD,uBAAuB,CAAC,0BAA0B,CAAC;AAEnD,sBAAsB,CAAC,MAAM,GAAG,0BAA0B;AAcnD,MAAM,aAAa,GAAG;;"}
|
|
@@ -4,4 +4,5 @@ export * from './CommandDialog.js';
|
|
|
4
4
|
export * from './CommandStepper.js';
|
|
5
5
|
export * from './StepperCommandDialog.js';
|
|
6
6
|
export * from './StepperPanel.js';
|
|
7
|
+
export type { CommandValidationResults, ValidationAnnouncement } from './validationFeedback.js';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../CommandDialog/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAsB,CAAC;AACrC,YAAY,EAAE,oBAAoB,EAAE,MAAM,2BAAwB,CAAC;AACnE,cAAc,oBAAiB,CAAC;AAChC,cAAc,qBAAkB,CAAC;AACjC,cAAc,2BAAwB,CAAC;AACvC,cAAc,mBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../CommandDialog/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAsB,CAAC;AACrC,YAAY,EAAE,oBAAoB,EAAE,MAAM,2BAAwB,CAAC;AACnE,cAAc,oBAAiB,CAAC;AAChC,cAAc,qBAAkB,CAAC;AACjC,cAAc,2BAAwB,CAAC;AACvC,cAAc,mBAAgB,CAAC;AAC/B,YAAY,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,yBAAsB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CommandFormProps } from '@cratis/arc.react/commands';
|
|
2
|
+
import type { DialogRefusalFeedback } from '../Dialogs/DialogRefusalFeedback.js';
|
|
3
|
+
/** The validation results a refused command reports. */
|
|
4
|
+
export type CommandValidationResults = Parameters<NonNullable<CommandFormProps<object, object>['onValidationFailure']>>[0];
|
|
5
|
+
/** Builds the live-region text announced when submit is blocked by validation. */
|
|
6
|
+
export type ValidationAnnouncement = (results: CommandValidationResults) => string;
|
|
7
|
+
/**
|
|
8
|
+
* The built-in English announcement: how many problems there are and the first one.
|
|
9
|
+
* @param results The validation results, at least one.
|
|
10
|
+
* @returns The text to announce.
|
|
11
|
+
*/
|
|
12
|
+
export declare const defaultValidationAnnouncement: ValidationAnnouncement;
|
|
13
|
+
/**
|
|
14
|
+
* Finds the first invalid field in a container: the first element marked `aria-invalid="true"`,
|
|
15
|
+
* or its first focusable descendant when the marked element is a wrapper.
|
|
16
|
+
* @param container The element holding the fields.
|
|
17
|
+
* @returns The element to focus, or `undefined` when there is none.
|
|
18
|
+
*/
|
|
19
|
+
export declare const firstInvalidField: (container: HTMLElement | null) => HTMLElement | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Describes a refusal caused by validation: the announcement and the field to focus.
|
|
22
|
+
* @param results The validation results of the refused command; empty when it was not refused by validation.
|
|
23
|
+
* @param container The element holding the fields.
|
|
24
|
+
* @param announce Builds the announcement text.
|
|
25
|
+
* @returns The feedback, or `undefined` to keep the dialog's generic refusal behavior.
|
|
26
|
+
*/
|
|
27
|
+
export declare const validationRefusalFeedback: (results: CommandValidationResults, container: HTMLElement | null, announce?: ValidationAnnouncement) => DialogRefusalFeedback | undefined;
|
|
28
|
+
//# sourceMappingURL=validationFeedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationFeedback.d.ts","sourceRoot":"","sources":["../../../CommandDialog/validationFeedback.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qCAAkC,CAAC;AAE9E,wDAAwD;AACxD,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAC7C,WAAW,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,qBAAqB,CAAC,CAAC,CACvE,CAAC,CAAC,CAAC,CAAC;AAEL,kFAAkF;AAClF,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,wBAAwB,KAAK,MAAM,CAAC;AAEnF;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,EAAE,sBAGkC,CAAC;AAK/E;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,cAAe,WAAW,GAAG,IAAI,KAAG,WAAW,GAAG,SAK/E,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,YACzB,wBAAwB,aACtB,WAAW,GAAG,IAAI,aACnB,sBAAsB,KACjC,qBAAqB,GAAG,SAG1B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const defaultValidationAnnouncement = (results) => results.length === 1
|
|
2
|
+
? `There is 1 problem. ${results[0].message}`
|
|
3
|
+
: `There are ${results.length} problems. First: ${results[0].message}`;
|
|
4
|
+
const focusableSelector = 'input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
5
|
+
const firstInvalidField = (container) => {
|
|
6
|
+
const invalid = container?.querySelector('[aria-invalid="true"]');
|
|
7
|
+
if (!invalid)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (invalid.matches(focusableSelector))
|
|
10
|
+
return invalid;
|
|
11
|
+
return invalid.querySelector(focusableSelector) ?? undefined;
|
|
12
|
+
};
|
|
13
|
+
const validationRefusalFeedback = (results, container, announce = defaultValidationAnnouncement) => {
|
|
14
|
+
if (results.length === 0)
|
|
15
|
+
return undefined;
|
|
16
|
+
return { message: announce(results), focus: firstInvalidField(container) };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { defaultValidationAnnouncement, firstInvalidField, validationRefusalFeedback };
|
|
20
|
+
//# sourceMappingURL=validationFeedback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationFeedback.js","sources":["../../../CommandDialog/validationFeedback.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { CommandFormProps } from '@cratis/arc.react/commands';\nimport type { DialogRefusalFeedback } from '../Dialogs/DialogRefusalFeedback';\n\n/** The validation results a refused command reports. */\nexport type CommandValidationResults = Parameters<\n NonNullable<CommandFormProps<object, object>['onValidationFailure']>\n>[0];\n\n/** Builds the live-region text announced when submit is blocked by validation. */\nexport type ValidationAnnouncement = (results: CommandValidationResults) => string;\n\n/**\n * The built-in English announcement: how many problems there are and the first one.\n * @param results The validation results, at least one.\n * @returns The text to announce.\n */\nexport const defaultValidationAnnouncement: ValidationAnnouncement = (results) =>\n results.length === 1\n ? `There is 1 problem. ${results[0].message}`\n : `There are ${results.length} problems. First: ${results[0].message}`;\n\nconst focusableSelector =\n 'input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Finds the first invalid field in a container: the first element marked `aria-invalid=\"true\"`,\n * or its first focusable descendant when the marked element is a wrapper.\n * @param container The element holding the fields.\n * @returns The element to focus, or `undefined` when there is none.\n */\nexport const firstInvalidField = (container: HTMLElement | null): HTMLElement | undefined => {\n const invalid = container?.querySelector<HTMLElement>('[aria-invalid=\"true\"]');\n if (!invalid) return undefined;\n if (invalid.matches(focusableSelector)) return invalid;\n return invalid.querySelector<HTMLElement>(focusableSelector) ?? undefined;\n};\n\n/**\n * Describes a refusal caused by validation: the announcement and the field to focus.\n * @param results The validation results of the refused command; empty when it was not refused by validation.\n * @param container The element holding the fields.\n * @param announce Builds the announcement text.\n * @returns The feedback, or `undefined` to keep the dialog's generic refusal behavior.\n */\nexport const validationRefusalFeedback = (\n results: CommandValidationResults,\n container: HTMLElement | null,\n announce: ValidationAnnouncement = defaultValidationAnnouncement,\n): DialogRefusalFeedback | undefined => {\n if (results.length === 0) return undefined;\n return { message: announce(results), focus: firstInvalidField(container) };\n};\n"],"names":[],"mappings":"AAmBO,MAAM,6BAA6B,GAA2B,CAAC,OAAO,KACzE,OAAO,CAAC,MAAM,KAAK;MACb,uBAAuB,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;AAC3C,MAAE,CAAA,UAAA,EAAa,OAAO,CAAC,MAAM,CAAA,kBAAA,EAAqB,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO;AAE5E,MAAM,iBAAiB,GACnB,kIAAkI;AAQ/H,MAAM,iBAAiB,GAAG,CAAC,SAA6B,KAA6B;IACxF,MAAM,OAAO,GAAG,SAAS,EAAE,aAAa,CAAc,uBAAuB,CAAC;AAC9E,IAAA,IAAI,CAAC,OAAO;AAAE,QAAA,OAAO,SAAS;AAC9B,IAAA,IAAI,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;AAAE,QAAA,OAAO,OAAO;IACtD,OAAO,OAAO,CAAC,aAAa,CAAc,iBAAiB,CAAC,IAAI,SAAS;AAC7E;AASO,MAAM,yBAAyB,GAAG,CACrC,OAAiC,EACjC,SAA6B,EAC7B,QAAA,GAAmC,6BAA6B,KAC7B;AACnC,IAAA,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,SAAS;AAC1C,IAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,SAAS,CAAC,EAAE;AAC9E;;"}
|
|
@@ -2,6 +2,7 @@ import type { DialogResult, DialogButtons } from '@cratis/arc.react/dialogs';
|
|
|
2
2
|
import type { ButtonHTMLAttributes, CSSProperties, HTMLAttributes, ReactNode } from 'react';
|
|
3
3
|
import type { DialogSliceLocation } from '../configuration/DialogSliceLocation.js';
|
|
4
4
|
import type { DialogInitialFocus } from './DialogInitialFocus.js';
|
|
5
|
+
import type { DialogRefusalFeedback } from './DialogRefusalFeedback.js';
|
|
5
6
|
/** Callback handling a typed dialog result; return `false` to keep the dialog open. */
|
|
6
7
|
export type CloseDialog = (result: DialogResult) => boolean | void | Promise<boolean> | Promise<void>;
|
|
7
8
|
/** Confirmation callback; return `true` to permit host closure. */
|
|
@@ -74,6 +75,12 @@ export interface DialogProps {
|
|
|
74
75
|
* dialog from a plain one. Defaults to `false`.
|
|
75
76
|
*/
|
|
76
77
|
isCommandDialog?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Read when a confirm is refused, to replace the generic announcement and focus target with
|
|
80
|
+
* feedback about this refusal. Used by `CommandDialog` to announce validation failures and focus
|
|
81
|
+
* the first invalid field. Returning `undefined` keeps the default behavior.
|
|
82
|
+
*/
|
|
83
|
+
refusalFeedback?: () => DialogRefusalFeedback | undefined;
|
|
77
84
|
/**
|
|
78
85
|
* Glyph for the header close button. Names this one dialog and wins over the provider's
|
|
79
86
|
* `icons.close`; defaults to a multiplication sign when neither is set.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../../Dialogs/Dialog.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EACR,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,SAAS,EACZ,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAsC,CAAC;AAChF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../../Dialogs/Dialog.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EACR,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,SAAS,EACZ,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAsC,CAAC;AAChF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAAyB,CAAC;AAIrE,uFAAuF;AACvF,MAAM,MAAM,WAAW,GAAG,CACtB,MAAM,EAAE,YAAY,KACnB,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvD,mEAAmE;AACnE,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACtF,mEAAmE;AACnE,MAAM,MAAM,cA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;IAClB,wEAAwE;IACxE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8FAA8F;IAC9F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0GAA0G;IAC1G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iGAAiG;IACjG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8FAA8F;IAC9F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yHAAyH;IACzH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kGAAkG;IAClG,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,4FAA4F;IAC5F,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iGAAiG;IACjG,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,EAAE,CAAC,EAAE,WAAW,CAAC;IACjB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAUD;;;GAGG;AACH,eAAO,MAAM,MAAM,UAAW,WAAW,+FAKxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.js","sources":["../../../Dialogs/Dialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { DialogResult, DialogButtons } from '@cratis/arc.react/dialogs';\nimport type {\n ButtonHTMLAttributes,\n CSSProperties,\n HTMLAttributes,\n ReactNode,\n} from 'react';\nimport { unstable_useSlot } from '../renderer/RendererContext';\nimport { renderSlot } from '../renderer/renderSlot';\nimport type { unstable_SlotDeclaration } from '../renderer/slots';\nimport type { DialogSliceLocation } from '../configuration/DialogSliceLocation';\nimport type { DialogInitialFocus } from './DialogInitialFocus';\nimport { DialogImplementation } from './DialogImplementation';\nimport { DialogSlotHost } from './DialogSlotHost';\n\n/** Callback handling a typed dialog result; return `false` to keep the dialog open. */\nexport type CloseDialog = (\n result: DialogResult,\n) => boolean | void | Promise<boolean> | Promise<void>;\n\n/** Confirmation callback; return `true` to permit host closure. */\nexport type ConfirmCallback = () => boolean | void | Promise<boolean> | Promise<void>;\n/** Cancellation callback; return `true` to permit host closure. */\nexport type CancelCallback = () => boolean | void | Promise<boolean> | Promise<void>;\n\ntype DialogPartAttributes<TElement> = HTMLAttributes<TElement> & {\n [attribute: `data-${string}`]: string | number | boolean | undefined;\n};\n\ntype DialogButtonAttributes = Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n 'onClick' | 'value'\n>;\n\n/**\n * Where a {@link Dialog} sits in the viewport. `center` is the classic modal; `start` and `end`\n * make it a full-height side sheet against the inline-start or inline-end edge.\n */\nexport type DialogPlacement = 'center' | 'start' | 'end';\n\n/** Stable Cratis-owned parts for styling a {@link Dialog}. */\nexport interface DialogParts {\n /** Viewport backdrop and dismissal surface. */\n backdrop?: DialogPartAttributes<HTMLDivElement>;\n /** Viewport positioning wrapper. */\n positioner?: DialogPartAttributes<HTMLDivElement>;\n /** Modal root. */\n root?: DialogPartAttributes<HTMLDivElement>;\n /** Header containing title and optional close action. */\n header?: DialogPartAttributes<HTMLElement>;\n /** Dialog heading. */\n title?: DialogPartAttributes<HTMLHeadingElement>;\n /** Secondary line under the heading, rendered only when `subtitle` is set. */\n subtitle?: DialogPartAttributes<HTMLParagraphElement>;\n /** Region before the close button holding per-dialog and app-wide header actions. */\n headerActions?: DialogPartAttributes<HTMLDivElement>;\n /** Header close button. */\n close?: DialogButtonAttributes;\n /** Dialog content region. */\n content?: DialogPartAttributes<HTMLDivElement>;\n /** Footer action region. */\n footer?: DialogPartAttributes<HTMLElement>;\n /** Primary confirmation button. */\n confirm?: DialogButtonAttributes;\n /** Secondary dismissal button(s). */\n cancel?: DialogButtonAttributes;\n}\n\n/** Props for {@link Dialog}. */\nexport interface DialogProps {\n /** Dialog heading. */\n title: string;\n /**\n * Secondary line under the heading — a reference, a status, a short summary. Announced as the\n * dialog's description.\n */\n subtitle?: ReactNode;\n /**\n * Viewport placement. `center` (default) is a modal; `start` and `end` render a full-height\n * side sheet against that inline edge, sliding in from it. Dismissal, focus and busy behavior\n * are identical across placements.\n */\n placement?: DialogPlacement;\n /**\n * Actions rendered in the header before the close button, in a `header-actions` part. Use it\n * for a help, feedback or copy-link action that belongs to this dialog. Rendered next to the\n * app-wide actions registered on `CratisComponentsProvider`.\n */\n headerActions?: ReactNode;\n /** Suppresses the app-wide header actions registered on `CratisComponentsProvider` for this dialog. */\n hideGlobalHeaderActions?: boolean;\n /** Where this dialog's opener sits in the application. Passed to app-wide header actions as `sliceLocation`. */\n sliceLocation?: DialogSliceLocation;\n /**\n * Set by `CommandDialog` and `StepperCommandDialog` so app-wide header actions can tell a command\n * dialog from a plain one. Defaults to `false`.\n */\n isCommandDialog?: boolean;\n /**\n * Glyph for the header close button. Names this one dialog and wins over the provider's\n * `icons.close`; defaults to a multiplication sign when neither is set.\n */\n closeIcon?: ReactNode;\n /** Controlled open state. Defaults to `true`. */\n visible?: boolean;\n /** Combined result callback used when a dedicated confirm/cancel callback is absent. */\n onClose?: CloseDialog;\n /** Invoked by primary confirmation actions. */\n onConfirm?: ConfirmCallback;\n /** Invoked by cancellation actions. */\n onCancel?: CancelCallback;\n /** Predefined Arc buttons, custom footer content, or `null` for no footer. */\n buttons?: DialogButtons | ReactNode;\n /** Initial focus target. Defaults to the confirmation action. */\n initialFocus?: DialogInitialFocus;\n /** Dialog body content. */\n children: ReactNode;\n /** CSS width. Defaults to `450px`. */\n width?: string;\n /** Modal-root inline style. */\n style?: CSSProperties;\n /** Content-region inline style. */\n contentStyle?: CSSProperties;\n /**\n * @deprecated The Cratis dialog is viewport-bounded rather than resizable. Remove this prop.\n */\n resizable?: boolean;\n /** Whether the primary action is enabled. Defaults to `true`. */\n isValid?: boolean;\n /** Disables every action and dismissal path while work is in flight. */\n isBusy?: boolean;\n /** Label for the Ok action. Falls back to the provider's `dialog.ok` message, then `'Ok'`. */\n okLabel?: string;\n /** Label for the Cancel action. Falls back to the provider's `dialog.cancel` message, then `'Cancel'`. */\n cancelLabel?: string;\n /** Label for the Yes action. Falls back to the provider's `dialog.yes` message, then `'Yes'`. */\n yesLabel?: string;\n /** Label for the No action. Falls back to the provider's `dialog.no` message, then `'No'`. */\n noLabel?: string;\n /** Accessible label for the header close button. Falls back to the provider's `dialog.close` message, then `'Close'`. */\n closeAriaLabel?: string;\n /**\n * Combined default for header, Escape, and backdrop dismissal. Defaults to true\n * for predefined buttons and false for custom/no footer. Independent props override it.\n */\n dismissable?: boolean;\n /** Whether outside clicks dismiss the dialog. Falls back to `dismissable`; blocked while busy. */\n dismissOnOutsideClick?: boolean;\n /** Whether Escape dismisses the dialog. Falls back to `dismissable`; blocked while busy. */\n closeOnEscape?: boolean;\n /** Whether to show the header close button. Falls back to `dismissable`; disabled while busy. */\n showCloseButton?: boolean;\n /** Extra class name for the modal root. */\n className?: string;\n /** Cratis-owned per-part attributes. */\n pt?: DialogParts;\n /**\n * @deprecated Cratis parts always merge. Remove this renderer-era option.\n */\n ptOptions?: object;\n /**\n * @deprecated Components always uses consumer-owned CSS. Customize through `pt` and CSS instead.\n */\n unstyled?: boolean;\n}\n\nconst coreDialogDeclaration = Object.freeze({\n mode: 'atomic',\n fidelity: 'native',\n render: DialogImplementation,\n}) satisfies unstable_SlotDeclaration<'dialogs.dialog'>;\n\nconst slotHostDeclaration = Object.freeze({ render: DialogSlotHost });\n\n/**\n * A modal dialog with Arc host integration, typed footer actions, busy/validity\n * state, controlled dismissal, and stable Cratis-owned styling parts.\n */\nexport const Dialog = (props: DialogProps) => {\n const declaration = unstable_useSlot('dialogs.dialog', coreDialogDeclaration);\n if (declaration.render === DialogImplementation) return renderSlot(coreDialogDeclaration, props);\n // An adapter dialog receives the public props plus its Components-owned host.\n return renderSlot(slotHostDeclaration, { render: declaration.render, props });\n};\n"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"Dialog.js","sources":["../../../Dialogs/Dialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { DialogResult, DialogButtons } from '@cratis/arc.react/dialogs';\nimport type {\n ButtonHTMLAttributes,\n CSSProperties,\n HTMLAttributes,\n ReactNode,\n} from 'react';\nimport { unstable_useSlot } from '../renderer/RendererContext';\nimport { renderSlot } from '../renderer/renderSlot';\nimport type { unstable_SlotDeclaration } from '../renderer/slots';\nimport type { DialogSliceLocation } from '../configuration/DialogSliceLocation';\nimport type { DialogInitialFocus } from './DialogInitialFocus';\nimport type { DialogRefusalFeedback } from './DialogRefusalFeedback';\nimport { DialogImplementation } from './DialogImplementation';\nimport { DialogSlotHost } from './DialogSlotHost';\n\n/** Callback handling a typed dialog result; return `false` to keep the dialog open. */\nexport type CloseDialog = (\n result: DialogResult,\n) => boolean | void | Promise<boolean> | Promise<void>;\n\n/** Confirmation callback; return `true` to permit host closure. */\nexport type ConfirmCallback = () => boolean | void | Promise<boolean> | Promise<void>;\n/** Cancellation callback; return `true` to permit host closure. */\nexport type CancelCallback = () => boolean | void | Promise<boolean> | Promise<void>;\n\ntype DialogPartAttributes<TElement> = HTMLAttributes<TElement> & {\n [attribute: `data-${string}`]: string | number | boolean | undefined;\n};\n\ntype DialogButtonAttributes = Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n 'onClick' | 'value'\n>;\n\n/**\n * Where a {@link Dialog} sits in the viewport. `center` is the classic modal; `start` and `end`\n * make it a full-height side sheet against the inline-start or inline-end edge.\n */\nexport type DialogPlacement = 'center' | 'start' | 'end';\n\n/** Stable Cratis-owned parts for styling a {@link Dialog}. */\nexport interface DialogParts {\n /** Viewport backdrop and dismissal surface. */\n backdrop?: DialogPartAttributes<HTMLDivElement>;\n /** Viewport positioning wrapper. */\n positioner?: DialogPartAttributes<HTMLDivElement>;\n /** Modal root. */\n root?: DialogPartAttributes<HTMLDivElement>;\n /** Header containing title and optional close action. */\n header?: DialogPartAttributes<HTMLElement>;\n /** Dialog heading. */\n title?: DialogPartAttributes<HTMLHeadingElement>;\n /** Secondary line under the heading, rendered only when `subtitle` is set. */\n subtitle?: DialogPartAttributes<HTMLParagraphElement>;\n /** Region before the close button holding per-dialog and app-wide header actions. */\n headerActions?: DialogPartAttributes<HTMLDivElement>;\n /** Header close button. */\n close?: DialogButtonAttributes;\n /** Dialog content region. */\n content?: DialogPartAttributes<HTMLDivElement>;\n /** Footer action region. */\n footer?: DialogPartAttributes<HTMLElement>;\n /** Primary confirmation button. */\n confirm?: DialogButtonAttributes;\n /** Secondary dismissal button(s). */\n cancel?: DialogButtonAttributes;\n}\n\n/** Props for {@link Dialog}. */\nexport interface DialogProps {\n /** Dialog heading. */\n title: string;\n /**\n * Secondary line under the heading — a reference, a status, a short summary. Announced as the\n * dialog's description.\n */\n subtitle?: ReactNode;\n /**\n * Viewport placement. `center` (default) is a modal; `start` and `end` render a full-height\n * side sheet against that inline edge, sliding in from it. Dismissal, focus and busy behavior\n * are identical across placements.\n */\n placement?: DialogPlacement;\n /**\n * Actions rendered in the header before the close button, in a `header-actions` part. Use it\n * for a help, feedback or copy-link action that belongs to this dialog. Rendered next to the\n * app-wide actions registered on `CratisComponentsProvider`.\n */\n headerActions?: ReactNode;\n /** Suppresses the app-wide header actions registered on `CratisComponentsProvider` for this dialog. */\n hideGlobalHeaderActions?: boolean;\n /** Where this dialog's opener sits in the application. Passed to app-wide header actions as `sliceLocation`. */\n sliceLocation?: DialogSliceLocation;\n /**\n * Set by `CommandDialog` and `StepperCommandDialog` so app-wide header actions can tell a command\n * dialog from a plain one. Defaults to `false`.\n */\n isCommandDialog?: boolean;\n /**\n * Read when a confirm is refused, to replace the generic announcement and focus target with\n * feedback about this refusal. Used by `CommandDialog` to announce validation failures and focus\n * the first invalid field. Returning `undefined` keeps the default behavior.\n */\n refusalFeedback?: () => DialogRefusalFeedback | undefined;\n /**\n * Glyph for the header close button. Names this one dialog and wins over the provider's\n * `icons.close`; defaults to a multiplication sign when neither is set.\n */\n closeIcon?: ReactNode;\n /** Controlled open state. Defaults to `true`. */\n visible?: boolean;\n /** Combined result callback used when a dedicated confirm/cancel callback is absent. */\n onClose?: CloseDialog;\n /** Invoked by primary confirmation actions. */\n onConfirm?: ConfirmCallback;\n /** Invoked by cancellation actions. */\n onCancel?: CancelCallback;\n /** Predefined Arc buttons, custom footer content, or `null` for no footer. */\n buttons?: DialogButtons | ReactNode;\n /** Initial focus target. Defaults to the confirmation action. */\n initialFocus?: DialogInitialFocus;\n /** Dialog body content. */\n children: ReactNode;\n /** CSS width. Defaults to `450px`. */\n width?: string;\n /** Modal-root inline style. */\n style?: CSSProperties;\n /** Content-region inline style. */\n contentStyle?: CSSProperties;\n /**\n * @deprecated The Cratis dialog is viewport-bounded rather than resizable. Remove this prop.\n */\n resizable?: boolean;\n /** Whether the primary action is enabled. Defaults to `true`. */\n isValid?: boolean;\n /** Disables every action and dismissal path while work is in flight. */\n isBusy?: boolean;\n /** Label for the Ok action. Falls back to the provider's `dialog.ok` message, then `'Ok'`. */\n okLabel?: string;\n /** Label for the Cancel action. Falls back to the provider's `dialog.cancel` message, then `'Cancel'`. */\n cancelLabel?: string;\n /** Label for the Yes action. Falls back to the provider's `dialog.yes` message, then `'Yes'`. */\n yesLabel?: string;\n /** Label for the No action. Falls back to the provider's `dialog.no` message, then `'No'`. */\n noLabel?: string;\n /** Accessible label for the header close button. Falls back to the provider's `dialog.close` message, then `'Close'`. */\n closeAriaLabel?: string;\n /**\n * Combined default for header, Escape, and backdrop dismissal. Defaults to true\n * for predefined buttons and false for custom/no footer. Independent props override it.\n */\n dismissable?: boolean;\n /** Whether outside clicks dismiss the dialog. Falls back to `dismissable`; blocked while busy. */\n dismissOnOutsideClick?: boolean;\n /** Whether Escape dismisses the dialog. Falls back to `dismissable`; blocked while busy. */\n closeOnEscape?: boolean;\n /** Whether to show the header close button. Falls back to `dismissable`; disabled while busy. */\n showCloseButton?: boolean;\n /** Extra class name for the modal root. */\n className?: string;\n /** Cratis-owned per-part attributes. */\n pt?: DialogParts;\n /**\n * @deprecated Cratis parts always merge. Remove this renderer-era option.\n */\n ptOptions?: object;\n /**\n * @deprecated Components always uses consumer-owned CSS. Customize through `pt` and CSS instead.\n */\n unstyled?: boolean;\n}\n\nconst coreDialogDeclaration = Object.freeze({\n mode: 'atomic',\n fidelity: 'native',\n render: DialogImplementation,\n}) satisfies unstable_SlotDeclaration<'dialogs.dialog'>;\n\nconst slotHostDeclaration = Object.freeze({ render: DialogSlotHost });\n\n/**\n * A modal dialog with Arc host integration, typed footer actions, busy/validity\n * state, controlled dismissal, and stable Cratis-owned styling parts.\n */\nexport const Dialog = (props: DialogProps) => {\n const declaration = unstable_useSlot('dialogs.dialog', coreDialogDeclaration);\n if (declaration.render === DialogImplementation) return renderSlot(coreDialogDeclaration, props);\n // An adapter dialog receives the public props plus its Components-owned host.\n return renderSlot(slotHostDeclaration, { render: declaration.render, props });\n};\n"],"names":[],"mappings":";;;;;AAgLA,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;AACxC,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,QAAQ,EAAE,QAAQ;AAClB,IAAA,MAAM,EAAE,oBAAoB;AAC/B,CAAA,CAAsD;AAEvD,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;AAM9D,MAAM,MAAM,GAAG,CAAC,KAAkB,KAAI;IACzC,MAAM,WAAW,GAAG,gBAAgB,CAAC,gBAAgB,EAAE,qBAAqB,CAAC;AAC7E,IAAA,IAAI,WAAW,CAAC,MAAM,KAAK,oBAAoB;AAAE,QAAA,OAAO,UAAU,CAAC,qBAAqB,EAAE,KAAK,CAAC;AAEhG,IAAA,OAAO,UAAU,CAAC,mBAAmB,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;AACjF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DialogImplementation.d.ts","sourceRoot":"","sources":["../../../Dialogs/DialogImplementation.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAU,CAAC;AAsB5C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,kBAAmB,WAAW,
|
|
1
|
+
{"version":3,"file":"DialogImplementation.d.ts","sourceRoot":"","sources":["../../../Dialogs/DialogImplementation.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAU,CAAC;AAsB5C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,kBAAmB,WAAW,gCA6H9D,CAAC"}
|
|
@@ -48,6 +48,7 @@ const DialogImplementation = (incomingProps) => {
|
|
|
48
48
|
isBusy,
|
|
49
49
|
initialFocus: resolvedInitialFocus,
|
|
50
50
|
refusedMessage: labels.refused,
|
|
51
|
+
refusalFeedback: props.refusalFeedback,
|
|
51
52
|
});
|
|
52
53
|
const handleClose = useDialogClose(props, onRefused);
|
|
53
54
|
const dialogDocument = (jsx(DialogDocument, { stackZIndex: resolvedZIndex ?? DIALOG_ZINDEX_TOKEN, hostId: hostId, visible: visible, contentStyle: props.contentStyle, announcement: announcement, header: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DialogImplementation.js","sources":["../../../Dialogs/DialogImplementation.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogResult, DialogButtons } from '@cratis/arc.react/dialogs';\nimport { useId, useSyncExternalStore } from 'react';\nimport { unstable_useOverlayEnvironment } from '../renderer/RendererContext';\nimport { DialogInitialFocus } from './DialogInitialFocus';\nimport type { DialogProps } from './Dialog';\nimport { dismissalFor, resolveInitialFocus } from './dialogBehavior';\nimport { useCratisComponentsConfig } from '../Common/CratisComponentsProvider';\nimport { useCratisIcon } from '../configuration/useCratisIcon';\nimport { DIALOG_ZINDEX_TOKEN } from '../renderer/dialogStack';\nimport { useComponentPresentation } from '../configuration/identity/useComponentPresentation';\nimport { dialogDescriptor } from './dialogDescriptor';\nimport { DialogDocument } from './DialogDocument';\nimport { DialogModalShell, DialogServerShell } from './DialogShells';\nimport { resolveDialogLabels } from './resolveDialogLabels';\nimport { useDialogClose } from './useDialogClose';\nimport { useDialogFocus } from './useDialogFocus';\nimport { useDialogZIndex } from './useDialogZIndex';\n\nconst subscribeToBrowserEnvironment = () => () => undefined;\nconst useIsBrowser = () =>\n useSyncExternalStore(\n subscribeToBrowserEnvironment,\n () => true,\n () => false,\n );\n\n/**\n * A modal dialog with Arc host integration, typed footer actions, busy/validity\n * state, controlled dismissal, and stable Cratis-owned styling parts.\n */\nexport const DialogImplementation = (incomingProps: DialogProps) => {\n const [props, marker] = useComponentPresentation(dialogDescriptor, incomingProps);\n const {\n title,\n subtitle,\n placement = 'center',\n closeIcon,\n headerActions,\n hideGlobalHeaderActions = false,\n sliceLocation,\n isCommandDialog = false,\n visible = true,\n buttons = DialogButtons.OkCancel,\n initialFocus = DialogInitialFocus.Confirm,\n children,\n width = '450px',\n isValid,\n isBusy = false,\n pt,\n } = props;\n const { messages, dialogHeaderActions } = useCratisComponentsConfig();\n const dialogId = useId();\n const subtitleId = useId();\n const hostId = useId();\n const labels = resolveDialogLabels(props, messages?.dialog);\n const icon = useCratisIcon();\n const isBrowser = useIsBrowser();\n const overlayEnvironment = unstable_useOverlayEnvironment();\n\n const hasHeaderActions =\n headerActions != null || (dialogHeaderActions !== undefined && !hideGlobalHeaderActions);\n const hasSubtitle = subtitle !== undefined && subtitle !== null && subtitle !== false;\n const resolvedInitialFocus = resolveInitialFocus(initialFocus, buttons);\n const focus = {\n confirm: resolvedInitialFocus === DialogInitialFocus.Confirm,\n dismissing: resolvedInitialFocus === DialogInitialFocus.Cancel,\n };\n const { allowsOutsideDismissal, allowsEscapeDismissal, showsCloseButton } = dismissalFor(props, isBusy);\n\n const resolvedZIndex = useDialogZIndex(visible);\n const { titleRef, confirmRef, cancelRef, announcement, onRefused } = useDialogFocus({\n visible,\n isBusy,\n initialFocus: resolvedInitialFocus,\n refusedMessage: labels.refused,\n });\n const handleClose = useDialogClose(props, onRefused);\n\n const dialogDocument = (\n <DialogDocument\n stackZIndex={resolvedZIndex ?? DIALOG_ZINDEX_TOKEN}\n hostId={hostId}\n visible={visible}\n contentStyle={props.contentStyle}\n announcement={announcement}\n header={{\n dialogId,\n title,\n subtitle,\n subtitleId,\n hasSubtitle,\n hasHeaderActions,\n headerActions,\n globalHeaderActions: dialogHeaderActions,\n hideGlobalHeaderActions,\n isCommandDialog,\n sliceLocation,\n showsCloseButton,\n focusesTitle: resolvedInitialFocus === DialogInitialFocus.Content,\n titleRef,\n isBusy,\n closeAriaLabel: labels.closeAria,\n closeIcon: icon('close', '×', closeIcon),\n onClose: () => void handleClose(DialogResult.Cancelled),\n pt,\n }}\n footer={\n buttons === null\n ? null\n : {\n buttons,\n labels,\n focus,\n isBusy,\n isValid: isValid !== false,\n pt,\n confirmRef,\n cancelRef,\n onResult: (result) => void handleClose(result),\n }\n }\n >\n {children}\n </DialogDocument>\n );\n\n const shell = {\n placement,\n visible,\n isBusy,\n zIndex: resolvedZIndex,\n width,\n style: props.style,\n className: props.className,\n dialogId,\n marker,\n pt,\n children: dialogDocument,\n };\n\n // useSyncExternalStore supplies the server snapshot during hydration, so this\n // fallback is identical on the server and on the client's first render. React\n // switches to the portaled React Aria modal only after hydration completes.\n if (!isBrowser) return <DialogServerShell {...shell} />;\n\n return (\n <DialogModalShell\n {...shell}\n portalContainer={overlayEnvironment.getContainer}\n allowsOutsideDismissal={allowsOutsideDismissal}\n allowsEscapeDismissal={allowsEscapeDismissal}\n onDismiss={() => void handleClose(DialogResult.Cancelled)}\n />\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;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KAAK;IACrF,MAAM,oBAAoB,GAAG,mBAAmB,CAAC,YAAY,EAAE,OAAO,CAAC;AACvE,IAAA,MAAM,KAAK,GAAG;AACV,QAAA,OAAO,EAAE,oBAAoB,KAAK,kBAAkB,CAAC,OAAO;AAC5D,QAAA,UAAU,EAAE,oBAAoB,KAAK,kBAAkB,CAAC,MAAM;KACjE;AACD,IAAA,MAAM,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,GAAG,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC;AAEvG,IAAA,MAAM,cAAc,GAAG,eAAe,CAAC,OAAO,CAAC;AAC/C,IAAA,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC;QAChF,OAAO;QACP,MAAM;AACN,QAAA,YAAY,EAAE,oBAAoB;QAClC,cAAc,EAAE,MAAM,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"DialogImplementation.js","sources":["../../../Dialogs/DialogImplementation.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogResult, DialogButtons } from '@cratis/arc.react/dialogs';\nimport { useId, useSyncExternalStore } from 'react';\nimport { unstable_useOverlayEnvironment } from '../renderer/RendererContext';\nimport { DialogInitialFocus } from './DialogInitialFocus';\nimport type { DialogProps } from './Dialog';\nimport { dismissalFor, resolveInitialFocus } from './dialogBehavior';\nimport { useCratisComponentsConfig } from '../Common/CratisComponentsProvider';\nimport { useCratisIcon } from '../configuration/useCratisIcon';\nimport { DIALOG_ZINDEX_TOKEN } from '../renderer/dialogStack';\nimport { useComponentPresentation } from '../configuration/identity/useComponentPresentation';\nimport { dialogDescriptor } from './dialogDescriptor';\nimport { DialogDocument } from './DialogDocument';\nimport { DialogModalShell, DialogServerShell } from './DialogShells';\nimport { resolveDialogLabels } from './resolveDialogLabels';\nimport { useDialogClose } from './useDialogClose';\nimport { useDialogFocus } from './useDialogFocus';\nimport { useDialogZIndex } from './useDialogZIndex';\n\nconst subscribeToBrowserEnvironment = () => () => undefined;\nconst useIsBrowser = () =>\n useSyncExternalStore(\n subscribeToBrowserEnvironment,\n () => true,\n () => false,\n );\n\n/**\n * A modal dialog with Arc host integration, typed footer actions, busy/validity\n * state, controlled dismissal, and stable Cratis-owned styling parts.\n */\nexport const DialogImplementation = (incomingProps: DialogProps) => {\n const [props, marker] = useComponentPresentation(dialogDescriptor, incomingProps);\n const {\n title,\n subtitle,\n placement = 'center',\n closeIcon,\n headerActions,\n hideGlobalHeaderActions = false,\n sliceLocation,\n isCommandDialog = false,\n visible = true,\n buttons = DialogButtons.OkCancel,\n initialFocus = DialogInitialFocus.Confirm,\n children,\n width = '450px',\n isValid,\n isBusy = false,\n pt,\n } = props;\n const { messages, dialogHeaderActions } = useCratisComponentsConfig();\n const dialogId = useId();\n const subtitleId = useId();\n const hostId = useId();\n const labels = resolveDialogLabels(props, messages?.dialog);\n const icon = useCratisIcon();\n const isBrowser = useIsBrowser();\n const overlayEnvironment = unstable_useOverlayEnvironment();\n\n const hasHeaderActions =\n headerActions != null || (dialogHeaderActions !== undefined && !hideGlobalHeaderActions);\n const hasSubtitle = subtitle !== undefined && subtitle !== null && subtitle !== false;\n const resolvedInitialFocus = resolveInitialFocus(initialFocus, buttons);\n const focus = {\n confirm: resolvedInitialFocus === DialogInitialFocus.Confirm,\n dismissing: resolvedInitialFocus === DialogInitialFocus.Cancel,\n };\n const { allowsOutsideDismissal, allowsEscapeDismissal, showsCloseButton } = dismissalFor(props, isBusy);\n\n const resolvedZIndex = useDialogZIndex(visible);\n const { titleRef, confirmRef, cancelRef, announcement, onRefused } = useDialogFocus({\n visible,\n isBusy,\n initialFocus: resolvedInitialFocus,\n refusedMessage: labels.refused,\n refusalFeedback: props.refusalFeedback,\n });\n const handleClose = useDialogClose(props, onRefused);\n\n const dialogDocument = (\n <DialogDocument\n stackZIndex={resolvedZIndex ?? DIALOG_ZINDEX_TOKEN}\n hostId={hostId}\n visible={visible}\n contentStyle={props.contentStyle}\n announcement={announcement}\n header={{\n dialogId,\n title,\n subtitle,\n subtitleId,\n hasSubtitle,\n hasHeaderActions,\n headerActions,\n globalHeaderActions: dialogHeaderActions,\n hideGlobalHeaderActions,\n isCommandDialog,\n sliceLocation,\n showsCloseButton,\n focusesTitle: resolvedInitialFocus === DialogInitialFocus.Content,\n titleRef,\n isBusy,\n closeAriaLabel: labels.closeAria,\n closeIcon: icon('close', '×', closeIcon),\n onClose: () => void handleClose(DialogResult.Cancelled),\n pt,\n }}\n footer={\n buttons === null\n ? null\n : {\n buttons,\n labels,\n focus,\n isBusy,\n isValid: isValid !== false,\n pt,\n confirmRef,\n cancelRef,\n onResult: (result) => void handleClose(result),\n }\n }\n >\n {children}\n </DialogDocument>\n );\n\n const shell = {\n placement,\n visible,\n isBusy,\n zIndex: resolvedZIndex,\n width,\n style: props.style,\n className: props.className,\n dialogId,\n marker,\n pt,\n children: dialogDocument,\n };\n\n // useSyncExternalStore supplies the server snapshot during hydration, so this\n // fallback is identical on the server and on the client's first render. React\n // switches to the portaled React Aria modal only after hydration completes.\n if (!isBrowser) return <DialogServerShell {...shell} />;\n\n return (\n <DialogModalShell\n {...shell}\n portalContainer={overlayEnvironment.getContainer}\n allowsOutsideDismissal={allowsOutsideDismissal}\n allowsEscapeDismissal={allowsEscapeDismissal}\n onDismiss={() => void handleClose(DialogResult.Cancelled)}\n />\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,6BAA6B,GAAG,MAAM,MAAM,SAAS;AAC3D,MAAM,YAAY,GAAG,MACjB,oBAAoB,CAChB,6BAA6B,EAC7B,MAAM,IAAI,EACV,MAAM,KAAK,CACd;AAME,MAAM,oBAAoB,GAAG,CAAC,aAA0B,KAAI;AAC/D,IAAA,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,wBAAwB,CAAC,gBAAg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AAE;gBACF,UAAU;gBACV,SAAS;gBACT,QAAQ,EAAE,CAAC,MAAM,KAAK,KAAK,WAAW,CAAC,MAAM,CAAC;aACjD,EAAA,QAAA,EAGV,QAAQ,EAAA,CACI,CACpB;AAED,IAAA,MAAM,KAAK,GAAG;QACV,SAAS;QACT,OAAO;QACP,MAAM;AACN,QAAA,MAAM,EAAE,cAAc;QACtB,KAAK;QACL,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,QAAQ;QACR,MAAM;QACN,EAAE;AACF,QAAA,QAAQ,EAAE,cAAc;KAC3B;AAKD,IAAA,IAAI,CAAC,SAAS;AAAE,QAAA,OAAOA,GAAA,CAAC,iBAAiB,EAAA,EAAA,GAAK,KAAK,GAAI;AAEvD,IAAA,QACIA,GAAA,CAAC,gBAAgB,EAAA,EAAA,GACT,KAAK,EACT,eAAe,EAAE,kBAAkB,CAAC,YAAY,EAChD,sBAAsB,EAAE,sBAAsB,EAC9C,qBAAqB,EAAE,qBAAqB,EAC5C,SAAS,EAAE,MAAM,KAAK,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,EAAA,CAC3D;AAEV;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a dialog does after a refused confirm, in place of its defaults. Read at the moment the
|
|
3
|
+
* refusal is handled, so it can describe the outcome of the confirm that was just refused.
|
|
4
|
+
*/
|
|
5
|
+
export interface DialogRefusalFeedback {
|
|
6
|
+
/** Text for the live region. Defaults to the dialog's generic refusal message. */
|
|
7
|
+
message?: string;
|
|
8
|
+
/** Element to move focus to. Defaults to the confirm button, or the title when confirm is not enabled. */
|
|
9
|
+
focus?: HTMLElement | null;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=DialogRefusalFeedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogRefusalFeedback.d.ts","sourceRoot":"","sources":["../../../Dialogs/DialogRefusalFeedback.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IAClC,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogRefusalFeedback.js","sourceRoot":"","sources":["../../../Dialogs/DialogRefusalFeedback.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG","sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * What a dialog does after a refused confirm, in place of its defaults. Read at the moment the\n * refusal is handled, so it can describe the outcome of the confirm that was just refused.\n */\nexport interface DialogRefusalFeedback {\n /** Text for the live region. Defaults to the dialog's generic refusal message. */\n message?: string;\n /** Element to move focus to. Defaults to the confirm button, or the title when confirm is not enabled. */\n focus?: HTMLElement | null;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DialogSlotHost.d.ts","sourceRoot":"","sources":["../../../Dialogs/DialogSlotHost.tsx"],"names":[],"mappings":"AAIA,OAAO,EAA0E,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAMnH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAU,CAAC;AAK5C,OAAO,KAAK,EAA6B,gBAAgB,EAA6B,qBAAqB,EAAE,MAAM,iBAAc,CAAC;AAgDlI;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,UAAW,WAAW;;;;
|
|
1
|
+
{"version":3,"file":"DialogSlotHost.d.ts","sourceRoot":"","sources":["../../../Dialogs/DialogSlotHost.tsx"],"names":[],"mappings":"AAIA,OAAO,EAA0E,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAMnH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAU,CAAC;AAK5C,OAAO,KAAK,EAA6B,gBAAgB,EAA6B,qBAAqB,EAAE,MAAM,iBAAc,CAAC;AAgDlI;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,UAAW,WAAW;;;;CA+D/C,CAAC;AAEF,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,qBAAqB,CAAC,CAAC;IACtD,iCAAiC;IACjC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC/B;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,sBAAuB,mBAAmB,gCAkBpE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DialogSlotHost.js","sources":["../../../Dialogs/DialogSlotHost.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogButtons, DialogResult } from '@cratis/arc.react/dialogs';\nimport { createContext, createElement, use, useEffect, useId, useMemo, useState, type ComponentType } from 'react';\nimport { useCratisComponentsConfig } from '../Common/CratisComponentsProvider';\nimport { useCratisIcon } from '../configuration/useCratisIcon';\nimport { DIALOG_ZINDEX_TOKEN } from '../renderer/dialogStack';\nimport { DialogStackContext, OverlayHostContext } from '../renderer/DialogStackContext';\nimport { OverlayContainerScope, useOverlayContainer } from '../renderer/OverlayContainerScope';\nimport type { DialogProps } from './Dialog';\nimport { dismissalFor, resolveInitialFocus } from './dialogBehavior';\nimport { DialogContent, LiveRegion } from './DialogDocument';\nimport { DialogFooter } from './DialogFooter';\nimport { HeaderActions } from './DialogHeader';\nimport type { CratisDialogDismissSource, CratisDialogHost, CratisDialogHostDismissal, CratisDialogSlotProps } from './DialogHost';\nimport { DialogInitialFocus } from './DialogInitialFocus';\nimport { resolveDialogLabels } from './resolveDialogLabels';\nimport { useDialogClose } from './useDialogClose';\nimport { useDialogFocus } from './useDialogFocus';\nimport { useDialogZIndex } from './useDialogZIndex';\n\nconst useHeaderActions = (props: DialogProps, dialogId: string, showsCloseButton: boolean) => {\n const { dialogHeaderActions } = useCratisComponentsConfig();\n const { headerActions, hideGlobalHeaderActions = false } = props;\n const hasHeaderActions =\n headerActions != null || (dialogHeaderActions !== undefined && !hideGlobalHeaderActions);\n if (!hasHeaderActions) return null;\n return (\n <HeaderActions\n dialogId={dialogId}\n title={props.title}\n headerActions={headerActions}\n globalHeaderActions={dialogHeaderActions}\n hideGlobalHeaderActions={hideGlobalHeaderActions}\n isCommandDialog={props.isCommandDialog ?? false}\n sliceLocation={props.sliceLocation}\n showsCloseButton={showsCloseButton}\n pt={props.pt}\n />\n );\n};\n\n// Whether the adapter dialogs rendered inside may open: false until the nearest adapter dialog has\n// committed its own open state, so modals open parent-first, and false as soon as it hides.\nconst DescendantsMayOpenContext = createContext(true);\n\n// Passive effects run children-first, so this runs after the adapter dialog below opened itself.\nconst useDescendantsMayOpen = (visible: boolean) => {\n const [opened, setOpened] = useState(false);\n useEffect(() => setOpened(visible), [visible]);\n return visible && opened;\n};\n\ninterface DismissGuard {\n readonly visible: boolean;\n readonly isBusy: boolean;\n readonly dismissal: CratisDialogHostDismissal;\n}\n\nconst mayDismiss = ({ visible, isBusy, dismissal }: DismissGuard, source: CratisDialogDismissSource) =>\n visible && !isBusy && dismissal[source];\n\n/**\n * Builds the Components-owned host of one adapter-rendered dialog: its stack tier, the dialog\n * result flow, the footer and header actions, initial focus and the refused-confirmation\n * announcement, plus the overlay container its descendants portal through.\n * @param props The dialog's public props.\n * @returns The host handed to the adapter and the overlay container for its descendants.\n */\nexport const useDialogHost = (props: DialogProps) => {\n const { isBusy = false, buttons = DialogButtons.OkCancel, subtitle } = props;\n // A dialog nested in a hidden or still-opening adapter dialog stays closed until its parent is open.\n const visible = (props.visible ?? true) && use(DescendantsMayOpenContext);\n const { messages } = useCratisComponentsConfig();\n const icon = useCratisIcon();\n const id = useId();\n const subtitleId = useId();\n const labels = resolveDialogLabels(props, messages?.dialog);\n const initialFocus = resolveInitialFocus(props.initialFocus ?? DialogInitialFocus.Confirm, buttons);\n const { allowsOutsideDismissal, allowsEscapeDismissal, showsCloseButton } = dismissalFor(props, isBusy);\n const dismissal = { outside: allowsOutsideDismissal, escape: allowsEscapeDismissal, closeButton: showsCloseButton };\n const zIndex = useDialogZIndex(visible) ?? DIALOG_ZINDEX_TOKEN;\n const overlayContainer = useOverlayContainer(visible);\n const { titleRef, confirmRef, cancelRef, announcement, onRefused } = useDialogFocus({\n visible,\n isBusy,\n initialFocus,\n refusedMessage: labels.refused,\n });\n const handleClose = useDialogClose(props, onRefused);\n\n const host: CratisDialogHost = {\n id,\n zIndex,\n dismissal,\n closeAriaLabel: labels.closeAria,\n closeIcon: icon('close', '×', props.closeIcon),\n subtitleId,\n hasSubtitle: subtitle !== undefined && subtitle !== null && subtitle !== false,\n titleRef,\n content: (\n <DialogContent visible={visible} isBusy={isBusy} contentStyle={props.contentStyle} pt={props.pt}>\n {props.children}\n </DialogContent>\n ),\n headerActions: useHeaderActions(props, id, showsCloseButton),\n footer:\n buttons === null ? null : (\n <DialogFooter\n buttons={buttons}\n labels={labels}\n focus={{\n confirm: initialFocus === DialogInitialFocus.Confirm,\n dismissing: initialFocus === DialogInitialFocus.Cancel,\n }}\n isBusy={isBusy}\n isValid={props.isValid !== false}\n pt={props.pt}\n confirmRef={confirmRef}\n cancelRef={cancelRef}\n onResult={(result) => void handleClose(result)}\n />\n ),\n liveRegion: <LiveRegion announcement={announcement} />,\n dismiss: (source) => {\n if (mayDismiss({ visible, isBusy, dismissal }, source)) void handleClose(DialogResult.Cancelled);\n },\n registerOverlayContainer: overlayContainer.register,\n };\n\n return { host, overlayContainer, visible };\n};\n\n/** Props of {@link DialogSlotHost}. */\nexport interface DialogSlotHostProps {\n /** The adapter's dialog implementation. */\n readonly render: ComponentType<CratisDialogSlotProps>;\n /** The dialog's public props. */\n readonly props: DialogProps;\n}\n\n/**\n * Renders an adapter-owned dialog with its Components-owned host. Descendants read this dialog's\n * stack tier, see it as their overlay host, and portal through the overlay element the adapter\n * registered.\n */\nexport const DialogSlotHost = ({ render, props }: DialogSlotHostProps) => {\n const { host, overlayContainer, visible } = useDialogHost(props);\n const descendantsMayOpen = useDescendantsMayOpen(visible);\n const overlayHost = useMemo(\n () => ({ id: host.id, open: visible, stackZIndex: host.zIndex }),\n [host.id, visible, host.zIndex],\n );\n return (\n <DialogStackContext value={host.zIndex}>\n <OverlayHostContext value={overlayHost}>\n <DescendantsMayOpenContext value={descendantsMayOpen}>\n <OverlayContainerScope host={overlayContainer}>\n {createElement(render, { ...props, visible, host })}\n </OverlayContainerScope>\n </DescendantsMayOpenContext>\n </OverlayHostContext>\n </DialogStackContext>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,gBAAgB,GAAG,CAAC,KAAkB,EAAE,QAAgB,EAAE,gBAAyB,KAAI;AACzF,IAAA,MAAM,EAAE,mBAAmB,EAAE,GAAG,yBAAyB,EAAE;IAC3D,MAAM,EAAE,aAAa,EAAE,uBAAuB,GAAG,KAAK,EAAE,GAAG,KAAK;AAChE,IAAA,MAAM,gBAAgB,GAClB,aAAa,IAAI,IAAI,KAAK,mBAAmB,KAAK,SAAS,IAAI,CAAC,uBAAuB,CAAC;AAC5F,IAAA,IAAI,CAAC,gBAAgB;AAAE,QAAA,OAAO,IAAI;IAClC,QACIA,IAAC,aAAa,EAAA,EACV,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,aAAa,EAAE,aAAa,EAC5B,mBAAmB,EAAE,mBAAmB,EACxC,uBAAuB,EAAE,uBAAuB,EAChD,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,KAAK,EAC/C,aAAa,EAAE,KAAK,CAAC,aAAa,EAClC,gBAAgB,EAAE,gBAAgB,EAClC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAA,CACd;AAEV,CAAC;AAID,MAAM,yBAAyB,GAAG,aAAa,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AAA,QAAA,EAClCA,IAAC,yBAAyB,EAAA,EAAC,KAAK,EAAE,kBAAkB,EAAA,QAAA,EAChDA,IAAC,qBAAqB,EAAA,EAAC,IAAI,EAAE,gBAAgB,YACxC,aAAa,CAAC,MAAM,EAAE,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAC/B,EAAA,CACA,EAAA,CACX,EAAA,CACJ;AAE7B;;"}
|
|
1
|
+
{"version":3,"file":"DialogSlotHost.js","sources":["../../../Dialogs/DialogSlotHost.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogButtons, DialogResult } from '@cratis/arc.react/dialogs';\nimport { createContext, createElement, use, useEffect, useId, useMemo, useState, type ComponentType } from 'react';\nimport { useCratisComponentsConfig } from '../Common/CratisComponentsProvider';\nimport { useCratisIcon } from '../configuration/useCratisIcon';\nimport { DIALOG_ZINDEX_TOKEN } from '../renderer/dialogStack';\nimport { DialogStackContext, OverlayHostContext } from '../renderer/DialogStackContext';\nimport { OverlayContainerScope, useOverlayContainer } from '../renderer/OverlayContainerScope';\nimport type { DialogProps } from './Dialog';\nimport { dismissalFor, resolveInitialFocus } from './dialogBehavior';\nimport { DialogContent, LiveRegion } from './DialogDocument';\nimport { DialogFooter } from './DialogFooter';\nimport { HeaderActions } from './DialogHeader';\nimport type { CratisDialogDismissSource, CratisDialogHost, CratisDialogHostDismissal, CratisDialogSlotProps } from './DialogHost';\nimport { DialogInitialFocus } from './DialogInitialFocus';\nimport { resolveDialogLabels } from './resolveDialogLabels';\nimport { useDialogClose } from './useDialogClose';\nimport { useDialogFocus } from './useDialogFocus';\nimport { useDialogZIndex } from './useDialogZIndex';\n\nconst useHeaderActions = (props: DialogProps, dialogId: string, showsCloseButton: boolean) => {\n const { dialogHeaderActions } = useCratisComponentsConfig();\n const { headerActions, hideGlobalHeaderActions = false } = props;\n const hasHeaderActions =\n headerActions != null || (dialogHeaderActions !== undefined && !hideGlobalHeaderActions);\n if (!hasHeaderActions) return null;\n return (\n <HeaderActions\n dialogId={dialogId}\n title={props.title}\n headerActions={headerActions}\n globalHeaderActions={dialogHeaderActions}\n hideGlobalHeaderActions={hideGlobalHeaderActions}\n isCommandDialog={props.isCommandDialog ?? false}\n sliceLocation={props.sliceLocation}\n showsCloseButton={showsCloseButton}\n pt={props.pt}\n />\n );\n};\n\n// Whether the adapter dialogs rendered inside may open: false until the nearest adapter dialog has\n// committed its own open state, so modals open parent-first, and false as soon as it hides.\nconst DescendantsMayOpenContext = createContext(true);\n\n// Passive effects run children-first, so this runs after the adapter dialog below opened itself.\nconst useDescendantsMayOpen = (visible: boolean) => {\n const [opened, setOpened] = useState(false);\n useEffect(() => setOpened(visible), [visible]);\n return visible && opened;\n};\n\ninterface DismissGuard {\n readonly visible: boolean;\n readonly isBusy: boolean;\n readonly dismissal: CratisDialogHostDismissal;\n}\n\nconst mayDismiss = ({ visible, isBusy, dismissal }: DismissGuard, source: CratisDialogDismissSource) =>\n visible && !isBusy && dismissal[source];\n\n/**\n * Builds the Components-owned host of one adapter-rendered dialog: its stack tier, the dialog\n * result flow, the footer and header actions, initial focus and the refused-confirmation\n * announcement, plus the overlay container its descendants portal through.\n * @param props The dialog's public props.\n * @returns The host handed to the adapter and the overlay container for its descendants.\n */\nexport const useDialogHost = (props: DialogProps) => {\n const { isBusy = false, buttons = DialogButtons.OkCancel, subtitle } = props;\n // A dialog nested in a hidden or still-opening adapter dialog stays closed until its parent is open.\n const visible = (props.visible ?? true) && use(DescendantsMayOpenContext);\n const { messages } = useCratisComponentsConfig();\n const icon = useCratisIcon();\n const id = useId();\n const subtitleId = useId();\n const labels = resolveDialogLabels(props, messages?.dialog);\n const initialFocus = resolveInitialFocus(props.initialFocus ?? DialogInitialFocus.Confirm, buttons);\n const { allowsOutsideDismissal, allowsEscapeDismissal, showsCloseButton } = dismissalFor(props, isBusy);\n const dismissal = { outside: allowsOutsideDismissal, escape: allowsEscapeDismissal, closeButton: showsCloseButton };\n const zIndex = useDialogZIndex(visible) ?? DIALOG_ZINDEX_TOKEN;\n const overlayContainer = useOverlayContainer(visible);\n const { titleRef, confirmRef, cancelRef, announcement, onRefused } = useDialogFocus({\n visible,\n isBusy,\n initialFocus,\n refusedMessage: labels.refused,\n refusalFeedback: props.refusalFeedback,\n });\n const handleClose = useDialogClose(props, onRefused);\n\n const host: CratisDialogHost = {\n id,\n zIndex,\n dismissal,\n closeAriaLabel: labels.closeAria,\n closeIcon: icon('close', '×', props.closeIcon),\n subtitleId,\n hasSubtitle: subtitle !== undefined && subtitle !== null && subtitle !== false,\n titleRef,\n content: (\n <DialogContent visible={visible} isBusy={isBusy} contentStyle={props.contentStyle} pt={props.pt}>\n {props.children}\n </DialogContent>\n ),\n headerActions: useHeaderActions(props, id, showsCloseButton),\n footer:\n buttons === null ? null : (\n <DialogFooter\n buttons={buttons}\n labels={labels}\n focus={{\n confirm: initialFocus === DialogInitialFocus.Confirm,\n dismissing: initialFocus === DialogInitialFocus.Cancel,\n }}\n isBusy={isBusy}\n isValid={props.isValid !== false}\n pt={props.pt}\n confirmRef={confirmRef}\n cancelRef={cancelRef}\n onResult={(result) => void handleClose(result)}\n />\n ),\n liveRegion: <LiveRegion announcement={announcement} />,\n dismiss: (source) => {\n if (mayDismiss({ visible, isBusy, dismissal }, source)) void handleClose(DialogResult.Cancelled);\n },\n registerOverlayContainer: overlayContainer.register,\n };\n\n return { host, overlayContainer, visible };\n};\n\n/** Props of {@link DialogSlotHost}. */\nexport interface DialogSlotHostProps {\n /** The adapter's dialog implementation. */\n readonly render: ComponentType<CratisDialogSlotProps>;\n /** The dialog's public props. */\n readonly props: DialogProps;\n}\n\n/**\n * Renders an adapter-owned dialog with its Components-owned host. Descendants read this dialog's\n * stack tier, see it as their overlay host, and portal through the overlay element the adapter\n * registered.\n */\nexport const DialogSlotHost = ({ render, props }: DialogSlotHostProps) => {\n const { host, overlayContainer, visible } = useDialogHost(props);\n const descendantsMayOpen = useDescendantsMayOpen(visible);\n const overlayHost = useMemo(\n () => ({ id: host.id, open: visible, stackZIndex: host.zIndex }),\n [host.id, visible, host.zIndex],\n );\n return (\n <DialogStackContext value={host.zIndex}>\n <OverlayHostContext value={overlayHost}>\n <DescendantsMayOpenContext value={descendantsMayOpen}>\n <OverlayContainerScope host={overlayContainer}>\n {createElement(render, { ...props, visible, host })}\n </OverlayContainerScope>\n </DescendantsMayOpenContext>\n </OverlayHostContext>\n </DialogStackContext>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,gBAAgB,GAAG,CAAC,KAAkB,EAAE,QAAgB,EAAE,gBAAyB,KAAI;AACzF,IAAA,MAAM,EAAE,mBAAmB,EAAE,GAAG,yBAAyB,EAAE;IAC3D,MAAM,EAAE,aAAa,EAAE,uBAAuB,GAAG,KAAK,EAAE,GAAG,KAAK;AAChE,IAAA,MAAM,gBAAgB,GAClB,aAAa,IAAI,IAAI,KAAK,mBAAmB,KAAK,SAAS,IAAI,CAAC,uBAAuB,CAAC;AAC5F,IAAA,IAAI,CAAC,gBAAgB;AAAE,QAAA,OAAO,IAAI;IAClC,QACIA,IAAC,aAAa,EAAA,EACV,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,aAAa,EAAE,aAAa,EAC5B,mBAAmB,EAAE,mBAAmB,EACxC,uBAAuB,EAAE,uBAAuB,EAChD,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,KAAK,EAC/C,aAAa,EAAE,KAAK,CAAC,aAAa,EAClC,gBAAgB,EAAE,gBAAgB,EAClC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAA,CACd;AAEV,CAAC;AAID,MAAM,yBAAyB,GAAG,aAAa,CAAC,IAAI,CAAC;AAGrD,MAAM,qBAAqB,GAAG,CAAC,OAAgB,KAAI;IAC/C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,C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AAC,qBAAqB,EAAA,EAAC,IAAI,EAAE,gBAAgB,YACxC,aAAa,CAAC,MAAM,EAAE,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAC/B,EAAA,CACA,EAAA,CACX,EAAA,CACJ;AAE7B;;"}
|
|
@@ -2,6 +2,7 @@ export * from './BusyIndicatorDialog.js';
|
|
|
2
2
|
export * from './ConfirmationDialog.js';
|
|
3
3
|
export * from './Dialog.js';
|
|
4
4
|
export * from './DialogInitialFocus.js';
|
|
5
|
+
export type { DialogRefusalFeedback } from './DialogRefusalFeedback.js';
|
|
5
6
|
export type { CratisDialogDismissSource, CratisDialogHost, CratisDialogHostDismissal, CratisDialogSlotProps, } from './DialogHost.js';
|
|
6
7
|
export type { DialogHeaderContext } from '../configuration/DialogHeaderContext.js';
|
|
7
8
|
export type { DialogHeaderActionsRenderer } from '../configuration/DialogHeaderActionsRenderer.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../Dialogs/index.ts"],"names":[],"mappings":"AAGA,cAAc,0BAAuB,CAAC;AACtC,cAAc,yBAAsB,CAAC;AACrC,cAAc,aAAU,CAAC;AACzB,cAAc,yBAAsB,CAAC;AACrC,YAAY,EACR,yBAAyB,EACzB,gBAAgB,EAChB,yBAAyB,EACzB,qBAAqB,GACxB,MAAM,iBAAc,CAAC;AACtB,YAAY,EAAE,mBAAmB,EAAE,MAAM,yCAAsC,CAAC;AAChF,YAAY,EAAE,2BAA2B,EAAE,MAAM,iDAA8C,CAAC;AAChG,YAAY,EAAE,mBAAmB,EAAE,MAAM,yCAAsC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../Dialogs/index.ts"],"names":[],"mappings":"AAGA,cAAc,0BAAuB,CAAC;AACtC,cAAc,yBAAsB,CAAC;AACrC,cAAc,aAAU,CAAC;AACzB,cAAc,yBAAsB,CAAC;AACrC,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAAyB,CAAC;AACrE,YAAY,EACR,yBAAyB,EACzB,gBAAgB,EAChB,yBAAyB,EACzB,qBAAqB,GACxB,MAAM,iBAAc,CAAC;AACtB,YAAY,EAAE,mBAAmB,EAAE,MAAM,yCAAsC,CAAC;AAChF,YAAY,EAAE,2BAA2B,EAAE,MAAM,iDAA8C,CAAC;AAChG,YAAY,EAAE,mBAAmB,EAAE,MAAM,yCAAsC,CAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { DialogInitialFocus } from './DialogInitialFocus.js';
|
|
2
|
+
import type { DialogRefusalFeedback } from './DialogRefusalFeedback.js';
|
|
2
3
|
interface DialogFocusOptions {
|
|
3
4
|
visible: boolean;
|
|
4
5
|
isBusy: boolean;
|
|
5
6
|
initialFocus: DialogInitialFocus;
|
|
6
7
|
refusedMessage: string;
|
|
8
|
+
refusalFeedback?: () => DialogRefusalFeedback | undefined;
|
|
7
9
|
}
|
|
8
10
|
interface Announcement {
|
|
9
11
|
key: number;
|
|
@@ -12,10 +14,11 @@ interface Announcement {
|
|
|
12
14
|
/**
|
|
13
15
|
* Owns the dialog's focus behavior: initial focus, keeping focus off `<body>` while work is in
|
|
14
16
|
* flight, and returning focus and announcing the outcome after a refused confirm.
|
|
15
|
-
* @param options The dialog's visibility, busy state, resolved initial focus
|
|
17
|
+
* @param options The dialog's visibility, busy state, resolved initial focus, refusal message and
|
|
18
|
+
* optional refusal feedback that replaces the announced text and focus target.
|
|
16
19
|
* @returns The refs to attach to title and buttons, the live-region announcement and a refusal notifier.
|
|
17
20
|
*/
|
|
18
|
-
export declare const useDialogFocus: ({ visible, isBusy, initialFocus, refusedMessage }: DialogFocusOptions) => {
|
|
21
|
+
export declare const useDialogFocus: ({ visible, isBusy, initialFocus, refusedMessage, refusalFeedback, }: DialogFocusOptions) => {
|
|
19
22
|
titleRef: import("react").RefObject<HTMLHeadingElement | null>;
|
|
20
23
|
confirmRef: import("react").RefObject<HTMLButtonElement | null>;
|
|
21
24
|
cancelRef: import("react").RefObject<HTMLButtonElement | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDialogFocus.d.ts","sourceRoot":"","sources":["../../../Dialogs/useDialogFocus.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"useDialogFocus.d.ts","sourceRoot":"","sources":["../../../Dialogs/useDialogFocus.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAAyB,CAAC;AAErE,UAAU,kBAAkB;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,kBAAkB,CAAC;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,qBAAqB,GAAG,SAAS,CAAC;CAC7D;AAED,UAAU,YAAY;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CAChB;AAmBD;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,wEAMxB,kBAAkB;;;;;;CAmDpB,CAAC"}
|
|
@@ -7,13 +7,23 @@ const focusTitle = (title) => {
|
|
|
7
7
|
title.tabIndex = -1;
|
|
8
8
|
title.focus();
|
|
9
9
|
};
|
|
10
|
-
const
|
|
10
|
+
const focusAfterRefusal = (target, confirm, title) => {
|
|
11
|
+
if (target)
|
|
12
|
+
target.focus();
|
|
13
|
+
else if (confirm && !confirm.disabled)
|
|
14
|
+
confirm.focus();
|
|
15
|
+
else
|
|
16
|
+
focusTitle(title);
|
|
17
|
+
};
|
|
18
|
+
const useDialogFocus = ({ visible, isBusy, initialFocus, refusedMessage, refusalFeedback, }) => {
|
|
11
19
|
const titleRef = useRef(null);
|
|
12
20
|
const confirmRef = useRef(null);
|
|
13
21
|
const cancelRef = useRef(null);
|
|
14
22
|
const [refusals, setRefusals] = useState(0);
|
|
15
23
|
const handledRefusals = useRef(0);
|
|
16
24
|
const [announcement, setAnnouncement] = useState(null);
|
|
25
|
+
const refusalFeedbackRef = useRef(refusalFeedback);
|
|
26
|
+
refusalFeedbackRef.current = refusalFeedback;
|
|
17
27
|
useEffect(() => {
|
|
18
28
|
if (!visible)
|
|
19
29
|
return;
|
|
@@ -41,12 +51,9 @@ const useDialogFocus = ({ visible, isBusy, initialFocus, refusedMessage }) => {
|
|
|
41
51
|
if (refusals === handledRefusals.current || isBusy)
|
|
42
52
|
return;
|
|
43
53
|
handledRefusals.current = refusals;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
else
|
|
48
|
-
focusTitle(titleRef.current);
|
|
49
|
-
setAnnouncement({ key: refusals, text: refusedMessage });
|
|
54
|
+
const feedback = refusalFeedbackRef.current?.();
|
|
55
|
+
focusAfterRefusal(feedback?.focus, confirmRef.current, titleRef.current);
|
|
56
|
+
setAnnouncement({ key: refusals, text: feedback?.message ?? refusedMessage });
|
|
50
57
|
}, [refusals, isBusy, refusedMessage]);
|
|
51
58
|
const onRefused = () => setRefusals((count) => count + 1);
|
|
52
59
|
return { titleRef, confirmRef, cancelRef, announcement, onRefused };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDialogFocus.js","sources":["../../../Dialogs/useDialogFocus.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useEffect, useRef, useState } from 'react';\nimport { DialogInitialFocus } from './DialogInitialFocus';\n\ninterface DialogFocusOptions {\n visible: boolean;\n isBusy: boolean;\n initialFocus: DialogInitialFocus;\n refusedMessage: string;\n}\n\ninterface Announcement {\n key: number;\n text: string;\n}\n\nconst focusTitle = (title: HTMLHeadingElement | null) => {\n if (!title) return;\n title.tabIndex = -1;\n title.focus();\n};\n\n/**\n * Owns the dialog's focus behavior: initial focus, keeping focus off `<body>` while work is in\n * flight, and returning focus and announcing the outcome after a refused confirm.\n * @param options The dialog's visibility, busy state, resolved initial focus and refusal
|
|
1
|
+
{"version":3,"file":"useDialogFocus.js","sources":["../../../Dialogs/useDialogFocus.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useEffect, useRef, useState } from 'react';\nimport { DialogInitialFocus } from './DialogInitialFocus';\nimport type { DialogRefusalFeedback } from './DialogRefusalFeedback';\n\ninterface DialogFocusOptions {\n visible: boolean;\n isBusy: boolean;\n initialFocus: DialogInitialFocus;\n refusedMessage: string;\n refusalFeedback?: () => DialogRefusalFeedback | undefined;\n}\n\ninterface Announcement {\n key: number;\n text: string;\n}\n\nconst focusTitle = (title: HTMLHeadingElement | null) => {\n if (!title) return;\n title.tabIndex = -1;\n title.focus();\n};\n\n// After a refusal, focus goes to the feedback's target, else the enabled confirm button, else the title.\nconst focusAfterRefusal = (\n target: HTMLElement | null | undefined,\n confirm: HTMLButtonElement | null,\n title: HTMLHeadingElement | null,\n) => {\n if (target) target.focus();\n else if (confirm && !confirm.disabled) confirm.focus();\n else focusTitle(title);\n};\n\n/**\n * Owns the dialog's focus behavior: initial focus, keeping focus off `<body>` while work is in\n * flight, and returning focus and announcing the outcome after a refused confirm.\n * @param options The dialog's visibility, busy state, resolved initial focus, refusal message and\n * optional refusal feedback that replaces the announced text and focus target.\n * @returns The refs to attach to title and buttons, the live-region announcement and a refusal notifier.\n */\nexport const useDialogFocus = ({\n visible,\n isBusy,\n initialFocus,\n refusedMessage,\n refusalFeedback,\n}: DialogFocusOptions) => {\n const titleRef = useRef<HTMLHeadingElement>(null);\n const confirmRef = useRef<HTMLButtonElement>(null);\n const cancelRef = useRef<HTMLButtonElement>(null);\n const [refusals, setRefusals] = useState(0);\n const handledRefusals = useRef(0);\n const [announcement, setAnnouncement] = useState<Announcement | null>(null);\n // Held in a ref so a new callback identity each render does not re-run the refusal effect.\n const refusalFeedbackRef = useRef(refusalFeedback);\n refusalFeedbackRef.current = refusalFeedback;\n\n useEffect(() => {\n if (!visible) return;\n // The title is a heading, so it is made programmatically focusable before it takes focus.\n const focusTarget =\n initialFocus === DialogInitialFocus.Confirm\n ? () => confirmRef.current?.focus()\n : initialFocus === DialogInitialFocus.Cancel\n ? () => cancelRef.current?.focus()\n : () => focusTitle(titleRef.current);\n const frame = requestAnimationFrame(focusTarget);\n return () => cancelAnimationFrame(frame);\n }, [initialFocus, visible]);\n\n // Keyboard focus must never be stranded on <body> while work is in flight: the confirm\n // button stays focusable (aria-disabled), and a focus held by a now-inert field moves to it.\n useEffect(() => {\n if (!visible || !isBusy) return;\n setAnnouncement(null);\n const active = document.activeElement;\n if (active && active !== document.body) return;\n if (confirmRef.current) confirmRef.current.focus();\n else focusTitle(titleRef.current);\n }, [isBusy, visible]);\n\n // A refused confirm (the dialog stays open) returns focus to the confirm button, or to the\n // title when confirm is not enabled, and announces the outcome through the live region.\n // Refusal feedback, when given, replaces the focus target and the announced text.\n useEffect(() => {\n // Each refusal is handled once: a later busy-to-idle change, such as a successful retry,\n // must neither move focus nor announce the earlier refusal again.\n if (refusals === handledRefusals.current || isBusy) return;\n handledRefusals.current = refusals;\n const feedback = refusalFeedbackRef.current?.();\n focusAfterRefusal(feedback?.focus, confirmRef.current, titleRef.current);\n setAnnouncement({ key: refusals, text: feedback?.message ?? refusedMessage });\n }, [refusals, isBusy, refusedMessage]);\n\n const onRefused = () => setRefusals((count) => count + 1);\n\n return { titleRef, confirmRef, cancelRef, announcement, onRefused };\n};\n"],"names":[],"mappings":";;;AAoBA,MAAM,UAAU,GAAG,CAAC,KAAgC,KAAI;AACpD,IAAA,IAAI,CAAC,KAAK;QAAE;AACZ,IAAA,KAAK,CAAC,QAAQ,GAAG,EAAE;IACnB,KAAK,CAAC,KAAK,EAAE;AACjB,CAAC;AAGD,MAAM,iBAAiB,GAAG,CACtB,MAAsC,EAC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