@tamagui/dialog 2.7.7 → 3.0.0-beta.1093.1

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.
@@ -0,0 +1,677 @@
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var Dialog_exports = {};
30
+ __export(Dialog_exports, {
31
+ Dialog: () => Dialog,
32
+ DialogClose: () => DialogClose,
33
+ DialogContent: () => DialogContent,
34
+ DialogContext: () => DialogContext,
35
+ DialogDescription: () => DialogDescription,
36
+ DialogOverlay: () => DialogOverlay,
37
+ DialogOverlayFrame: () => DialogOverlayFrame,
38
+ DialogPortal: () => DialogPortal,
39
+ DialogPortalFrame: () => DialogPortalFrame,
40
+ DialogProvider: () => DialogProvider,
41
+ DialogTitle: () => DialogTitle,
42
+ DialogTrigger: () => DialogTrigger,
43
+ DialogWarningProvider: () => DialogWarningProvider,
44
+ useDialogContext: () => useDialogContext
45
+ });
46
+ module.exports = __toCommonJS(Dialog_exports);
47
+ var import_jsx_runtime = require("react/jsx-runtime");
48
+ var import_adapt = require("@tamagui/adapt");
49
+ var import_animate = require("@tamagui/animate");
50
+ var import_compose_refs = require("@tamagui/compose-refs");
51
+ var import_constants = require("@tamagui/constants");
52
+ var import_core = require("@tamagui/core");
53
+ var import_create_context = require("@tamagui/create-context");
54
+ var import_dismissable = require("@tamagui/dismissable");
55
+ var import_focus_scope = require("@tamagui/focus-scope");
56
+ var import_helpers = require("@tamagui/helpers");
57
+ var import_portal = require("@tamagui/portal");
58
+ var import_remove_scroll = require("@tamagui/remove-scroll");
59
+ var import_stacks = require("@tamagui/stacks");
60
+ var import_text = require("@tamagui/text");
61
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
62
+ var import_z_index_stack = require("@tamagui/z-index-stack");
63
+ var React = __toESM(require("react"), 1);
64
+ var DialogContext = (0, import_core.createStyledContext)({}, "Dialog__");
65
+ var { useStyledContext: useDialogContext, Provider: DialogProvider } = DialogContext;
66
+ var DialogTriggerFrame = (0, import_core.styled)(import_core.View, { displayName: "DialogTrigger" });
67
+ var DialogTrigger = (0, import_core.createStyledHOC)(DialogTriggerFrame, function DialogTrigger2(props, forwardedRef) {
68
+ var { scope, ...triggerProps } = props;
69
+ var isInsideButton = React.useContext(import_stacks.ButtonNestingContext);
70
+ var context = useDialogContext(scope);
71
+ var composedTriggerRef = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.triggerRef);
72
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, {
73
+ value: props.asChild ? isInsideButton : true,
74
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTriggerFrame, {
75
+ render: isInsideButton ? "span" : "button",
76
+ "aria-haspopup": "dialog",
77
+ "aria-expanded": context.open,
78
+ "aria-controls": context.contentId,
79
+ "data-state": getState(context.open),
80
+ ...triggerProps,
81
+ ref: composedTriggerRef,
82
+ onPress: (0, import_helpers.composeEventHandlers)(props.onPress, context.onOpenToggle)
83
+ })
84
+ });
85
+ });
86
+ var DialogPortalFrame = (0, import_core.styled)(import_stacks.YStack, {
87
+ pointerEvents: "none",
88
+ alignItems: "center",
89
+ justifyContent: "center",
90
+ position: "absolute web:fixed",
91
+ inset: 0,
92
+ borderWidth: "web:0px",
93
+ backgroundColor: "web:transparent",
94
+ color: "web:inherit",
95
+ maxInlineSize: "web:none",
96
+ margin: "web:0px",
97
+ width: "web:auto",
98
+ height: "web:auto",
99
+ maxHeight: "web:100vh",
100
+ zIndex: "web:1",
101
+ render: "dialog"
102
+ });
103
+ var needsRepropagation = (0, import_portal.needsPortalRepropagation)();
104
+ var DialogPortalItem = function(param) {
105
+ var { context, children } = param;
106
+ var themeName = (0, import_core.useThemeName)();
107
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
108
+ var adaptContext = (0, import_adapt.useAdaptContext)(context.adaptScope);
109
+ var content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
110
+ name: themeName,
111
+ children
112
+ });
113
+ if (needsRepropagation) {
114
+ content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_adapt.ProvideAdaptContext, {
115
+ ...adaptContext,
116
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogProvider, {
117
+ ...context,
118
+ children: content
119
+ })
120
+ });
121
+ }
122
+ return isAdapted ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_adapt.AdaptPortalContents, {
123
+ scope: context.adaptScope,
124
+ children: content
125
+ }) : context.modal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
126
+ hostName: "root",
127
+ children: content
128
+ }) : content;
129
+ };
130
+ var DialogPortal = (0, import_core.createRefComponent)(function(props, forwardedRef) {
131
+ var { scope, forceMount, children, ...frameProps } = props;
132
+ var dialogRef = React.useRef(null);
133
+ var ref = (0, import_compose_refs.composeRefs)(dialogRef, forwardedRef);
134
+ var context = useDialogContext(scope);
135
+ var portalContext = forceMount ? {
136
+ ...context,
137
+ forceMount: true
138
+ } : context;
139
+ var keepMounted = forceMount || context.keepChildrenMounted;
140
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
141
+ var isVisible = context.open || context.hasPresentParts;
142
+ if (import_constants.isWeb) {
143
+ (0, import_constants.useIsomorphicLayoutEffect)(function() {
144
+ var node = dialogRef.current;
145
+ if (!(node instanceof HTMLDialogElement)) return;
146
+ if (isVisible) {
147
+ var _node_show;
148
+ (_node_show = node.show) === null || _node_show === void 0 ? void 0 : _node_show.call(node);
149
+ } else {
150
+ var _node_close;
151
+ (_node_close = node.close) === null || _node_close === void 0 ? void 0 : _node_close.call(node);
152
+ }
153
+ }, [isVisible]);
154
+ }
155
+ var zIndex = (0, import_core.getExpandedShorthand)("zIndex", props);
156
+ var contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, {
157
+ zIndex: (0, import_portal.resolveViewZIndex)(zIndex),
158
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogProvider, {
159
+ scope: context.dialogScope,
160
+ ...portalContext,
161
+ children
162
+ })
163
+ });
164
+ var framedContents = !isVisible && !keepMounted && !isAdapted ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.LayoutMeasurementController, {
165
+ disable: !context.open,
166
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogPortalFrame, {
167
+ ref,
168
+ ...import_constants.isWeb && context.open && context.modal && { "aria-modal": true },
169
+ pointerEvents: context.open && context.modal ? "auto" : "none",
170
+ ...frameProps,
171
+ className: `_no_backdrop ` + (frameProps.className || ""),
172
+ children: contents
173
+ })
174
+ });
175
+ if (import_constants.isWeb) {
176
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.Portal, {
177
+ zIndex,
178
+ stackZIndex: 1e5,
179
+ passThrough: isAdapted,
180
+ hidden: !isVisible,
181
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PassthroughTheme, {
182
+ passThrough: isAdapted,
183
+ children: framedContents
184
+ })
185
+ });
186
+ }
187
+ return isAdapted ? framedContents : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogPortalItem, {
188
+ context: portalContext,
189
+ children: framedContents
190
+ });
191
+ });
192
+ var PassthroughTheme = function(param) {
193
+ var { children, passThrough } = param;
194
+ var themeName = (0, import_core.useThemeName)();
195
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
196
+ passThrough,
197
+ name: themeName,
198
+ forceClassName: true,
199
+ children
200
+ });
201
+ };
202
+ function useDialogAnimationReporter(context) {
203
+ var onAnimationCompleteRef = React.useRef(context.onAnimationComplete);
204
+ onAnimationCompleteRef.current = context.onAnimationComplete;
205
+ var openRef = React.useRef(context.open);
206
+ var pendingTransitionRef = React.useRef(context.open ? true : null);
207
+ if (openRef.current !== context.open) {
208
+ openRef.current = context.open;
209
+ pendingTransitionRef.current = context.open;
210
+ }
211
+ var reportComplete = React.useCallback(function(open) {
212
+ var _onAnimationCompleteRef_current;
213
+ if (pendingTransitionRef.current !== open) return;
214
+ if (openRef.current !== open) return;
215
+ pendingTransitionRef.current = null;
216
+ (_onAnimationCompleteRef_current = onAnimationCompleteRef.current) === null || _onAnimationCompleteRef_current === void 0 ? void 0 : _onAnimationCompleteRef_current.call(onAnimationCompleteRef, { open });
217
+ }, []);
218
+ return React.useMemo(function() {
219
+ return {
220
+ onEnterComplete: function() {
221
+ return reportComplete(true);
222
+ },
223
+ onExitComplete: function() {
224
+ return reportComplete(false);
225
+ }
226
+ };
227
+ }, [reportComplete]);
228
+ }
229
+ function useDialogPartPresence(context, options) {
230
+ var [isFullyHidden, setIsFullyHidden] = React.useState(!context.open);
231
+ var reactId = React.useId();
232
+ var partPresenceId = `${context.contentId}-${options.id}-${reactId}`;
233
+ var keepMounted = options.forceMount || context.keepChildrenMounted;
234
+ var isPresent = context.open || !isFullyHidden;
235
+ (0, import_constants.useIsomorphicLayoutEffect)(function() {
236
+ if (context.open && isFullyHidden) {
237
+ setIsFullyHidden(false);
238
+ }
239
+ }, [context.open, isFullyHidden]);
240
+ (0, import_constants.useIsomorphicLayoutEffect)(function() {
241
+ if (options.disabled) return;
242
+ context.setPartPresence(partPresenceId, isPresent);
243
+ return function() {
244
+ context.setPartPresence(partPresenceId, false);
245
+ };
246
+ }, [
247
+ context.setPartPresence,
248
+ isPresent,
249
+ options.disabled,
250
+ partPresenceId
251
+ ]);
252
+ var onExitComplete = React.useCallback(function() {
253
+ var _options_onExitComplete;
254
+ setIsFullyHidden(true);
255
+ (_options_onExitComplete = options.onExitComplete) === null || _options_onExitComplete === void 0 ? void 0 : _options_onExitComplete.call(options);
256
+ }, [options.onExitComplete]);
257
+ return {
258
+ keepMounted,
259
+ onExitComplete,
260
+ shouldRender: Boolean(keepMounted || context.open || !isFullyHidden)
261
+ };
262
+ }
263
+ var OVERLAY_NAME = "DialogOverlay";
264
+ var DialogOverlayFrame = (0, import_core.styled)(import_stacks.YStack, {
265
+ displayName: OVERLAY_NAME,
266
+ zIndex: 1,
267
+ inset: 0,
268
+ position: "absolute",
269
+ pointerEvents: "auto",
270
+ variants: { open: {
271
+ true: { pointerEvents: "auto" },
272
+ false: { pointerEvents: "none" }
273
+ } }
274
+ });
275
+ var DialogOverlay = (0, import_core.createStyledHOC)(DialogOverlayFrame, function DialogOverlay2(param, forwardedRef) {
276
+ var { scope, ...props } = param;
277
+ var context = useDialogContext(scope);
278
+ var { forceMount = context.forceMount, ...overlayProps } = props;
279
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
280
+ var presence = useDialogPartPresence(context, {
281
+ disabled: isAdapted,
282
+ forceMount,
283
+ id: "overlay"
284
+ });
285
+ if (!forceMount && isAdapted) {
286
+ return null;
287
+ }
288
+ if (!presence.shouldRender) {
289
+ return null;
290
+ }
291
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_animate.Animate, {
292
+ type: "presence",
293
+ present: Boolean(context.open),
294
+ keepChildrenMounted: Boolean(presence.keepMounted),
295
+ onExitComplete: presence.onExitComplete,
296
+ passThrough: isAdapted,
297
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogOverlayFrame, {
298
+ "data-state": getState(context.open),
299
+ pointerEvents: context.open && context.modal ? "auto exit:none" : "none",
300
+ ...overlayProps,
301
+ ref: forwardedRef
302
+ }, `${context.contentId}-overlay`)
303
+ });
304
+ });
305
+ var CONTENT_NAME = "DialogContent";
306
+ var DialogContentFrame = (0, import_core.styled)(import_stacks.YStack, {
307
+ displayName: CONTENT_NAME,
308
+ zIndex: 2,
309
+ position: "relative",
310
+ pointerEvents: "auto",
311
+ variants: {
312
+ elevate: { true: {
313
+ shadowColor: "shadow-color",
314
+ shadowRadius: 24,
315
+ shadowOffset: {
316
+ width: 0,
317
+ height: 12
318
+ }
319
+ } },
320
+ bordered: { true: {
321
+ borderWidth: 1,
322
+ borderColor: "border-color"
323
+ } }
324
+ }
325
+ });
326
+ var DialogContent = (0, import_core.createStyledHOC)(DialogContentFrame, function DialogContent2(param, forwardedRef) {
327
+ var { scope, ...props } = param;
328
+ var context = useDialogContext(scope);
329
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
330
+ var reporter = useDialogAnimationReporter(context);
331
+ var onTransitionProp = props.onTransition;
332
+ var onTransition = React.useCallback(function(event) {
333
+ if (event.phase === "end" && event.cause === "enter") {
334
+ reporter.onEnterComplete();
335
+ }
336
+ onTransitionProp === null || onTransitionProp === void 0 ? void 0 : onTransitionProp(event);
337
+ }, [reporter.onEnterComplete, onTransitionProp]);
338
+ var presence = useDialogPartPresence(context, {
339
+ disabled: isAdapted,
340
+ forceMount: context.forceMount,
341
+ id: "content",
342
+ onExitComplete: reporter.onExitComplete
343
+ });
344
+ var contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: context.modal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentModal, {
345
+ context,
346
+ ...props,
347
+ onTransition,
348
+ ref: forwardedRef
349
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentNonModal, {
350
+ context,
351
+ ...props,
352
+ onTransition,
353
+ ref: forwardedRef
354
+ }) });
355
+ if (isAdapted) {
356
+ if (!import_constants.isWeb || context.disableRemoveScroll) {
357
+ return contents;
358
+ }
359
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remove_scroll.RemoveScroll, {
360
+ enabled: context.open && context.modal,
361
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
362
+ "data-remove-scroll-container": true,
363
+ className: "_dsp_contents",
364
+ children: contents
365
+ })
366
+ });
367
+ }
368
+ if (!presence.shouldRender) {
369
+ return null;
370
+ }
371
+ var animated = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_animate.Animate, {
372
+ type: "presence",
373
+ present: Boolean(context.open),
374
+ keepChildrenMounted: Boolean(presence.keepMounted),
375
+ onExitComplete: presence.onExitComplete,
376
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(React.Fragment, { children: contents }, context.contentId)
377
+ });
378
+ if (!import_constants.isWeb || context.disableRemoveScroll) {
379
+ return animated;
380
+ }
381
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remove_scroll.RemoveScroll, {
382
+ enabled: context.open && context.modal,
383
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
384
+ "data-remove-scroll-container": true,
385
+ className: "_dsp_contents",
386
+ children: animated
387
+ })
388
+ });
389
+ });
390
+ var DialogContentModal = (0, import_core.createRefComponent)(function(param, forwardedRef) {
391
+ var { children, context: contextProp, ...props } = param;
392
+ var context = useDialogContext(contextProp.dialogScope);
393
+ var contentRef = React.useRef(null);
394
+ var composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.contentRef, contentRef);
395
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentImpl, {
396
+ ...props,
397
+ context,
398
+ ref: composedRefs,
399
+ trapFocus: context.open,
400
+ disableOutsidePointerEvents: true,
401
+ onCloseAutoFocus: (0, import_helpers.composeEventHandlers)(props.onCloseAutoFocus, function(event) {
402
+ var _context_triggerRef_current;
403
+ event.cancel();
404
+ (_context_triggerRef_current = context.triggerRef.current) === null || _context_triggerRef_current === void 0 ? void 0 : _context_triggerRef_current.focus();
405
+ }),
406
+ onPointerDownOutside: (0, import_helpers.composeEventHandlers)(props.onPointerDownOutside, function(event) {
407
+ var originalEvent = event.event;
408
+ if (!originalEvent) return;
409
+ var ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
410
+ var isRightClick = originalEvent.button === 2 || ctrlLeftClick;
411
+ if (isRightClick) event.cancel();
412
+ }),
413
+ onFocusOutside: (0, import_helpers.composeEventHandlers)(props.onFocusOutside, function(event) {
414
+ return event.cancel();
415
+ }),
416
+ outlineStyle: "none",
417
+ children
418
+ });
419
+ });
420
+ var DialogContentNonModal = (0, import_core.createRefComponent)(function(props, forwardedRef) {
421
+ var context = useDialogContext(props.context.dialogScope);
422
+ var hasInteractedOutsideRef = React.useRef(false);
423
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentImpl, {
424
+ ...props,
425
+ context,
426
+ ref: forwardedRef,
427
+ trapFocus: false,
428
+ disableOutsidePointerEvents: false,
429
+ onCloseAutoFocus: function(event) {
430
+ var _props_onCloseAutoFocus;
431
+ (_props_onCloseAutoFocus = props.onCloseAutoFocus) === null || _props_onCloseAutoFocus === void 0 ? void 0 : _props_onCloseAutoFocus.call(props, event);
432
+ if (!event.isCanceled) {
433
+ if (!hasInteractedOutsideRef.current) {
434
+ var _props_context_triggerRef_current;
435
+ (_props_context_triggerRef_current = props.context.triggerRef.current) === null || _props_context_triggerRef_current === void 0 ? void 0 : _props_context_triggerRef_current.focus();
436
+ }
437
+ event.cancel();
438
+ }
439
+ hasInteractedOutsideRef.current = false;
440
+ },
441
+ onInteractOutside: function(event) {
442
+ var _props_onInteractOutside, _event_event;
443
+ (_props_onInteractOutside = props.onInteractOutside) === null || _props_onInteractOutside === void 0 ? void 0 : _props_onInteractOutside.call(props, event);
444
+ if (!event.isCanceled) hasInteractedOutsideRef.current = true;
445
+ var target = (_event_event = event.event) === null || _event_event === void 0 ? void 0 : _event_event.target;
446
+ var trigger = props.context.triggerRef.current;
447
+ if (!target || !(trigger instanceof HTMLElement)) return;
448
+ var targetIsTrigger = trigger.contains(target);
449
+ if (targetIsTrigger) event.cancel();
450
+ }
451
+ });
452
+ });
453
+ var DialogContentImpl = (0, import_core.createRefComponent)(function(props, forwardedRef) {
454
+ var { trapFocus, onOpenAutoFocus, onCloseAutoFocus, disableOutsidePointerEvents, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, context, onTransition, ...contentProps } = props;
455
+ var contentRef = React.useRef(null);
456
+ var composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, contentRef);
457
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
458
+ var adaptContext = (0, import_adapt.useAdaptContext)(context.adaptScope);
459
+ if (isAdapted) {
460
+ if (!context.open && !context.keepChildrenMounted && adaptContext.targetFullyHidden) {
461
+ return null;
462
+ }
463
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogPortalItem, {
464
+ context,
465
+ children: contentProps.children
466
+ });
467
+ }
468
+ var contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentFrame, {
469
+ ref: composedRefs,
470
+ id: context.contentId,
471
+ role: "dialog",
472
+ "aria-modal": context.modal,
473
+ "aria-describedby": context.descriptionId,
474
+ "aria-labelledby": context.titleId,
475
+ "data-state": getState(context.open),
476
+ pointerEvents: context.open ? "auto" : "none",
477
+ onTransition,
478
+ ...contentProps
479
+ });
480
+ if (!import_constants.isWeb) {
481
+ return contents;
482
+ }
483
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dismissable.Dismissable, {
484
+ disableOutsidePointerEvents: context.open && disableOutsidePointerEvents,
485
+ forceUnmount: !context.open,
486
+ onEscapeKeyDown,
487
+ onPointerDownOutside,
488
+ onFocusOutside,
489
+ onInteractOutside,
490
+ onDismiss: function() {
491
+ var _context_onOpenChange;
492
+ return context === null || context === void 0 ? void 0 : (_context_onOpenChange = context.onOpenChange) === null || _context_onOpenChange === void 0 ? void 0 : _context_onOpenChange.call(context, false);
493
+ },
494
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_focus_scope.FocusScope, {
495
+ loop: true,
496
+ enabled: context.open,
497
+ trapped: trapFocus,
498
+ onMountAutoFocus: onOpenAutoFocus,
499
+ forceUnmount: !context.open,
500
+ onUnmountAutoFocus: onCloseAutoFocus,
501
+ children: contents
502
+ })
503
+ }), process.env.NODE_ENV === "development" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TitleWarning, { titleId: context.titleId }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionWarning, {
504
+ contentRef,
505
+ descriptionId: context.descriptionId
506
+ })] })] });
507
+ });
508
+ var DialogTitleFrame = (0, import_core.styled)(import_text.H2, { displayName: "DialogTitle" });
509
+ var DialogTitle = (0, import_core.createStyledHOC)(DialogTitleFrame, function DialogTitle2(props, forwardedRef) {
510
+ var { scope, ...titleProps } = props;
511
+ var context = useDialogContext(scope);
512
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitleFrame, {
513
+ id: context.titleId,
514
+ ...titleProps,
515
+ ref: forwardedRef
516
+ });
517
+ });
518
+ var DialogDescriptionFrame = (0, import_core.styled)(import_text.Paragraph, { displayName: "DialogDescription" });
519
+ var DialogDescription = (0, import_core.createStyledHOC)(DialogDescriptionFrame, function DialogDescription2(props, forwardedRef) {
520
+ var { scope, ...descriptionProps } = props;
521
+ var context = useDialogContext(scope);
522
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogDescriptionFrame, {
523
+ id: context.descriptionId,
524
+ ...descriptionProps,
525
+ ref: forwardedRef
526
+ });
527
+ });
528
+ var CLOSE_NAME = "DialogClose";
529
+ var DialogCloseFrame = (0, import_core.styled)(import_core.View, {
530
+ displayName: CLOSE_NAME,
531
+ render: "button"
532
+ });
533
+ var DialogClose = (0, import_core.createStyledHOC)(DialogCloseFrame, function(props, forwardedRef) {
534
+ var { scope, displayWhenAdapted, ...closeProps } = props;
535
+ var context = useDialogContext(scope);
536
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
537
+ var isInsideButton = React.useContext(import_stacks.ButtonNestingContext);
538
+ if (isAdapted && !displayWhenAdapted) {
539
+ return null;
540
+ }
541
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogCloseFrame, {
542
+ "aria-label": "Dialog Close",
543
+ render: isInsideButton ? "span" : "button",
544
+ ...closeProps,
545
+ ref: forwardedRef,
546
+ onPress: (0, import_helpers.composeEventHandlers)(props.onPress, function() {
547
+ context.onOpenChange(false);
548
+ })
549
+ });
550
+ });
551
+ function getState(open) {
552
+ return open ? "open" : "closed";
553
+ }
554
+ var TITLE_WARNING_NAME = "DialogTitleWarning";
555
+ var [DialogWarningProvider, useWarningContext] = (0, import_create_context.createContext)(TITLE_WARNING_NAME, {
556
+ contentName: CONTENT_NAME,
557
+ titleName: "DialogTitle",
558
+ docsSlug: "dialog"
559
+ });
560
+ var TitleWarning = function(param) {
561
+ var { titleId } = param;
562
+ if (process.env.NODE_ENV === "development") {
563
+ var titleWarningContext = useWarningContext(TITLE_WARNING_NAME);
564
+ var MESSAGE = `\`${titleWarningContext.contentName}\` wants a \`${titleWarningContext.titleName}\` to be accessible. If you want to hide the \`${titleWarningContext.titleName}\`, wrap it with <VisuallyHidden />.`;
565
+ React.useEffect(function() {
566
+ if (!import_constants.isWeb) return;
567
+ if (titleId) {
568
+ var hasTitle = document.getElementById(titleId);
569
+ if (!hasTitle) {
570
+ console.warn(MESSAGE);
571
+ }
572
+ }
573
+ }, [MESSAGE, titleId]);
574
+ }
575
+ return null;
576
+ };
577
+ var DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning";
578
+ var DescriptionWarning = function(param) {
579
+ var { contentRef, descriptionId } = param;
580
+ if (process.env.NODE_ENV === "development") {
581
+ var descriptionWarningContext = useWarningContext(DESCRIPTION_WARNING_NAME);
582
+ var MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
583
+ React.useEffect(function() {
584
+ if (!import_constants.isWeb) return;
585
+ var contentNode = contentRef.current;
586
+ if (!(contentNode instanceof HTMLElement)) {
587
+ return;
588
+ }
589
+ var describedById = contentNode.getAttribute("aria-describedby");
590
+ if (descriptionId && describedById) {
591
+ var hasDescription = document.getElementById(descriptionId);
592
+ if (!hasDescription) {
593
+ console.warn(MESSAGE);
594
+ }
595
+ }
596
+ }, [
597
+ MESSAGE,
598
+ contentRef,
599
+ descriptionId
600
+ ]);
601
+ }
602
+ return null;
603
+ };
604
+ var Dialog = (0, import_helpers.withStaticProperties)((0, import_core.createRefComponent)(function Dialog2(props) {
605
+ var { scope = "", children, open: openProp, defaultOpen = false, onOpenChange, modal = true, keepChildrenMounted, disableRemoveScroll = false, onAnimationComplete } = props;
606
+ var baseId = React.useId();
607
+ var dialogId = `Dialog-${scope}-${baseId}`;
608
+ var contentId = `${dialogId}-content`;
609
+ var titleId = `${dialogId}-title`;
610
+ var descriptionId = `${dialogId}-description`;
611
+ var triggerRef = React.useRef(null);
612
+ var contentRef = React.useRef(null);
613
+ var presentPartIdsRef = React.useRef(/* @__PURE__ */ new Set());
614
+ var [presentPartCount, setPresentPartCount] = React.useState(0);
615
+ var [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
616
+ prop: openProp,
617
+ defaultProp: defaultOpen,
618
+ onChange: onOpenChange
619
+ });
620
+ var onOpenToggle = React.useCallback(function() {
621
+ setOpen(function(prevOpen) {
622
+ return !prevOpen;
623
+ });
624
+ }, [setOpen]);
625
+ var adaptScope = `DialogAdapt${scope}`;
626
+ var setPartPresence = React.useCallback(function(id, present) {
627
+ var presentPartIds = presentPartIdsRef.current;
628
+ var hasPart = presentPartIds.has(id);
629
+ if (present && !hasPart) {
630
+ presentPartIds.add(id);
631
+ setPresentPartCount(presentPartIds.size);
632
+ } else if (!present && hasPart) {
633
+ presentPartIds.delete(id);
634
+ setPresentPartCount(presentPartIds.size);
635
+ }
636
+ }, []);
637
+ var context = {
638
+ dialogScope: scope,
639
+ adaptScope,
640
+ triggerRef,
641
+ contentRef,
642
+ contentId,
643
+ titleId,
644
+ descriptionId,
645
+ open,
646
+ onOpenChange: setOpen,
647
+ onOpenToggle,
648
+ modal,
649
+ keepChildrenMounted,
650
+ disableRemoveScroll,
651
+ hasPresentParts: presentPartCount > 0,
652
+ setPartPresence,
653
+ onAnimationComplete
654
+ };
655
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_adapt.AdaptParent, {
656
+ scope: adaptScope,
657
+ adaptChildren: children,
658
+ open,
659
+ onOpenChange: setOpen,
660
+ state: context,
661
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogProvider, {
662
+ scope,
663
+ ...context,
664
+ children
665
+ })
666
+ });
667
+ }), {
668
+ Trigger: DialogTrigger,
669
+ Portal: DialogPortal,
670
+ Overlay: DialogOverlay,
671
+ Content: DialogContent,
672
+ Title: DialogTitle,
673
+ Description: DialogDescription,
674
+ Close: DialogClose,
675
+ FocusScope: import_focus_scope.FocusScopeController,
676
+ Adapt: import_adapt.Adapt
677
+ });