@oxyhq/bloom 0.4.0 → 0.5.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/README.md +105 -90
- package/lib/commonjs/bottom-sheet/index.js +2 -2
- package/lib/commonjs/context-menu/index.js +18 -19
- package/lib/commonjs/context-menu/index.js.map +1 -1
- package/lib/commonjs/dialog/BloomDialogProvider.js +61 -0
- package/lib/commonjs/dialog/BloomDialogProvider.js.map +1 -0
- package/lib/commonjs/dialog/BloomDialogProvider.web.js +45 -0
- package/lib/commonjs/dialog/BloomDialogProvider.web.js.map +1 -0
- package/lib/commonjs/dialog/Dialog.js +197 -100
- package/lib/commonjs/dialog/Dialog.js.map +1 -1
- package/lib/commonjs/dialog/Dialog.web.js +194 -84
- package/lib/commonjs/dialog/Dialog.web.js.map +1 -1
- package/lib/commonjs/dialog/SheetShell.js +149 -0
- package/lib/commonjs/dialog/SheetShell.js.map +1 -0
- package/lib/commonjs/dialog/alert-store.js +116 -0
- package/lib/commonjs/dialog/alert-store.js.map +1 -0
- package/lib/commonjs/dialog/alert.js +38 -0
- package/lib/commonjs/dialog/alert.js.map +1 -0
- package/lib/commonjs/dialog/context.js +10 -2
- package/lib/commonjs/dialog/context.js.map +1 -1
- package/lib/commonjs/dialog/index.js +8 -24
- package/lib/commonjs/dialog/index.js.map +1 -1
- package/lib/commonjs/dialog/index.web.js +10 -20
- package/lib/commonjs/dialog/index.web.js.map +1 -1
- package/lib/commonjs/index.js +101 -66
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +101 -66
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/menu/index.js +21 -23
- package/lib/commonjs/menu/index.js.map +1 -1
- package/lib/commonjs/select/index.js +26 -27
- package/lib/commonjs/select/index.js.map +1 -1
- package/lib/commonjs/toast/index.js +42 -13
- package/lib/commonjs/toast/index.js.map +1 -1
- package/lib/commonjs/toast/index.web.js +19 -15
- package/lib/commonjs/toast/index.web.js.map +1 -1
- package/lib/module/bottom-sheet/index.js +2 -2
- package/lib/module/context-menu/index.js +15 -16
- package/lib/module/context-menu/index.js.map +1 -1
- package/lib/module/dialog/BloomDialogProvider.js +57 -0
- package/lib/module/dialog/BloomDialogProvider.js.map +1 -0
- package/lib/module/dialog/BloomDialogProvider.web.js +41 -0
- package/lib/module/dialog/BloomDialogProvider.web.js.map +1 -0
- package/lib/module/dialog/Dialog.js +199 -87
- package/lib/module/dialog/Dialog.js.map +1 -1
- package/lib/module/dialog/Dialog.web.js +195 -70
- package/lib/module/dialog/Dialog.web.js.map +1 -1
- package/lib/module/dialog/SheetShell.js +143 -0
- package/lib/module/dialog/SheetShell.js.map +1 -0
- package/lib/module/dialog/alert-store.js +107 -0
- package/lib/module/dialog/alert-store.js.map +1 -0
- package/lib/module/dialog/alert.js +35 -0
- package/lib/module/dialog/alert.js.map +1 -0
- package/lib/module/dialog/context.js +10 -2
- package/lib/module/dialog/context.js.map +1 -1
- package/lib/module/dialog/index.js +3 -1
- package/lib/module/dialog/index.js.map +1 -1
- package/lib/module/dialog/index.web.js +9 -7
- package/lib/module/dialog/index.web.js.map +1 -1
- package/lib/module/index.js +2 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +2 -3
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/menu/index.js +11 -13
- package/lib/module/menu/index.js.map +1 -1
- package/lib/module/select/index.js +27 -28
- package/lib/module/select/index.js.map +1 -1
- package/lib/module/toast/index.js +41 -11
- package/lib/module/toast/index.js.map +1 -1
- package/lib/module/toast/index.web.js +18 -13
- package/lib/module/toast/index.web.js.map +1 -1
- package/lib/typescript/commonjs/__tests__/Dialog.test.d.ts +2 -0
- package/lib/typescript/commonjs/__tests__/Dialog.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/bottom-sheet/index.d.ts +1 -1
- package/lib/typescript/commonjs/context-menu/index.d.ts +4 -3
- package/lib/typescript/commonjs/context-menu/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/BloomDialogProvider.d.ts +27 -0
- package/lib/typescript/commonjs/dialog/BloomDialogProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/dialog/BloomDialogProvider.web.d.ts +15 -0
- package/lib/typescript/commonjs/dialog/BloomDialogProvider.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/dialog/Dialog.d.ts +37 -10
- package/lib/typescript/commonjs/dialog/Dialog.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/Dialog.web.d.ts +26 -10
- package/lib/typescript/commonjs/dialog/Dialog.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/SheetShell.d.ts +31 -0
- package/lib/typescript/commonjs/dialog/SheetShell.d.ts.map +1 -0
- package/lib/typescript/commonjs/dialog/alert-store.d.ts +70 -0
- package/lib/typescript/commonjs/dialog/alert-store.d.ts.map +1 -0
- package/lib/typescript/commonjs/dialog/alert.d.ts +27 -0
- package/lib/typescript/commonjs/dialog/alert.d.ts.map +1 -0
- package/lib/typescript/commonjs/dialog/context.d.ts +7 -0
- package/lib/typescript/commonjs/dialog/context.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/index.d.ts +5 -2
- package/lib/typescript/commonjs/dialog/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/index.web.d.ts +5 -2
- package/lib/typescript/commonjs/dialog/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/types.d.ts +70 -15
- package/lib/typescript/commonjs/dialog/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +3 -3
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.web.d.ts +3 -3
- package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/menu/index.d.ts +4 -4
- package/lib/typescript/commonjs/menu/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/select/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/toast/index.d.ts +32 -3
- package/lib/typescript/commonjs/toast/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/toast/index.web.d.ts +14 -7
- package/lib/typescript/commonjs/toast/index.web.d.ts.map +1 -1
- package/lib/typescript/module/__tests__/Dialog.test.d.ts +2 -0
- package/lib/typescript/module/__tests__/Dialog.test.d.ts.map +1 -0
- package/lib/typescript/module/bottom-sheet/index.d.ts +1 -1
- package/lib/typescript/module/context-menu/index.d.ts +4 -3
- package/lib/typescript/module/context-menu/index.d.ts.map +1 -1
- package/lib/typescript/module/dialog/BloomDialogProvider.d.ts +27 -0
- package/lib/typescript/module/dialog/BloomDialogProvider.d.ts.map +1 -0
- package/lib/typescript/module/dialog/BloomDialogProvider.web.d.ts +15 -0
- package/lib/typescript/module/dialog/BloomDialogProvider.web.d.ts.map +1 -0
- package/lib/typescript/module/dialog/Dialog.d.ts +37 -10
- package/lib/typescript/module/dialog/Dialog.d.ts.map +1 -1
- package/lib/typescript/module/dialog/Dialog.web.d.ts +26 -10
- package/lib/typescript/module/dialog/Dialog.web.d.ts.map +1 -1
- package/lib/typescript/module/dialog/SheetShell.d.ts +31 -0
- package/lib/typescript/module/dialog/SheetShell.d.ts.map +1 -0
- package/lib/typescript/module/dialog/alert-store.d.ts +70 -0
- package/lib/typescript/module/dialog/alert-store.d.ts.map +1 -0
- package/lib/typescript/module/dialog/alert.d.ts +27 -0
- package/lib/typescript/module/dialog/alert.d.ts.map +1 -0
- package/lib/typescript/module/dialog/context.d.ts +7 -0
- package/lib/typescript/module/dialog/context.d.ts.map +1 -1
- package/lib/typescript/module/dialog/index.d.ts +5 -2
- package/lib/typescript/module/dialog/index.d.ts.map +1 -1
- package/lib/typescript/module/dialog/index.web.d.ts +5 -2
- package/lib/typescript/module/dialog/index.web.d.ts.map +1 -1
- package/lib/typescript/module/dialog/types.d.ts +70 -15
- package/lib/typescript/module/dialog/types.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +3 -3
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/index.web.d.ts +3 -3
- package/lib/typescript/module/index.web.d.ts.map +1 -1
- package/lib/typescript/module/menu/index.d.ts +4 -4
- package/lib/typescript/module/menu/index.d.ts.map +1 -1
- package/lib/typescript/module/select/index.d.ts.map +1 -1
- package/lib/typescript/module/toast/index.d.ts +32 -3
- package/lib/typescript/module/toast/index.d.ts.map +1 -1
- package/lib/typescript/module/toast/index.web.d.ts +14 -7
- package/lib/typescript/module/toast/index.web.d.ts.map +1 -1
- package/package.json +3 -14
- package/src/__tests__/Dialog.test.tsx +177 -0
- package/src/bottom-sheet/index.tsx +3 -3
- package/src/context-menu/index.tsx +12 -12
- package/src/dialog/BloomDialogProvider.tsx +61 -0
- package/src/dialog/BloomDialogProvider.web.tsx +46 -0
- package/src/dialog/Dialog.tsx +217 -64
- package/src/dialog/Dialog.web.tsx +240 -75
- package/src/dialog/SheetShell.tsx +154 -0
- package/src/dialog/alert-store.ts +126 -0
- package/src/dialog/alert.ts +42 -0
- package/src/dialog/context.ts +14 -3
- package/src/dialog/index.ts +14 -2
- package/src/dialog/index.web.ts +20 -8
- package/src/dialog/types.ts +73 -16
- package/src/index.ts +17 -3
- package/src/index.web.ts +17 -3
- package/src/menu/index.tsx +13 -17
- package/src/select/index.tsx +30 -30
- package/src/toast/index.tsx +55 -11
- package/src/toast/index.web.tsx +33 -13
- package/lib/commonjs/prompt/Prompt.js +0 -267
- package/lib/commonjs/prompt/Prompt.js.map +0 -1
- package/lib/commonjs/prompt/index.js +0 -61
- package/lib/commonjs/prompt/index.js.map +0 -1
- package/lib/module/prompt/Prompt.js +0 -250
- package/lib/module/prompt/Prompt.js.map +0 -1
- package/lib/module/prompt/index.js +0 -4
- package/lib/module/prompt/index.js.map +0 -1
- package/lib/typescript/commonjs/prompt/Prompt.d.ts +0 -42
- package/lib/typescript/commonjs/prompt/Prompt.d.ts.map +0 -1
- package/lib/typescript/commonjs/prompt/index.d.ts +0 -3
- package/lib/typescript/commonjs/prompt/index.d.ts.map +0 -1
- package/lib/typescript/module/prompt/Prompt.d.ts +0 -42
- package/lib/typescript/module/prompt/Prompt.d.ts.map +0 -1
- package/lib/typescript/module/prompt/index.d.ts +0 -3
- package/lib/typescript/module/prompt/index.d.ts.map +0 -1
- package/src/prompt/Prompt.tsx +0 -247
- package/src/prompt/index.ts +0 -13
|
@@ -1,22 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import React, { createContext, useCallback,
|
|
4
|
-
import { Pressable, Text, View } from 'react-native';
|
|
3
|
+
import React, { createContext, useCallback, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { Pressable, Text, TouchableOpacity, View } from 'react-native';
|
|
5
5
|
import { RemoveScrollBar } from 'react-remove-scroll-bar';
|
|
6
|
-
import { useTheme } from "../theme/use-theme.js";
|
|
7
6
|
import { Portal } from "../portal/index.web.js";
|
|
8
|
-
import {
|
|
7
|
+
import { useTheme } from "../theme/use-theme.js";
|
|
8
|
+
import { Context, useDialogContext, useDialogControl } from "./context.js";
|
|
9
9
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
-
export { useDialogContext, useDialogControl } from "./context.js";
|
|
11
10
|
const FADE_OUT_DURATION = 150;
|
|
12
11
|
const stopPropagation = e => e.stopPropagation();
|
|
13
12
|
const ClosingContext = /*#__PURE__*/createContext(false);
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Web variant of `<Dialog>`.
|
|
16
|
+
*
|
|
17
|
+
* A centered modal card rendered into the bloom Portal at the end of
|
|
18
|
+
* `document.body`. Same prop API as native — `title`, `description`,
|
|
19
|
+
* `actions`, or arbitrary `children` — so call sites are platform
|
|
20
|
+
* agnostic.
|
|
21
|
+
*
|
|
22
|
+
* Accessibility: the panel has `role="dialog"` and the `title`/`description`
|
|
23
|
+
* props (when provided) become the `aria-labelledby` / `aria-describedby`
|
|
24
|
+
* targets. Pressing the backdrop dismisses. Pressing `Escape` dismisses.
|
|
25
|
+
* Focus is locked inside the dialog while it's open.
|
|
26
|
+
*/
|
|
27
|
+
export function Dialog({
|
|
16
28
|
control,
|
|
17
29
|
onClose,
|
|
18
30
|
testID,
|
|
19
|
-
|
|
31
|
+
title,
|
|
32
|
+
description,
|
|
33
|
+
actions,
|
|
34
|
+
style,
|
|
35
|
+
label,
|
|
36
|
+
children
|
|
20
37
|
}) {
|
|
21
38
|
const [isOpen, setIsOpen] = useState(false);
|
|
22
39
|
const [isClosing, setIsClosing] = useState(false);
|
|
@@ -36,18 +53,36 @@ export function Outer({
|
|
|
36
53
|
const timer = setTimeout(() => {
|
|
37
54
|
setIsOpen(false);
|
|
38
55
|
setIsClosing(false);
|
|
39
|
-
|
|
56
|
+
const queued = closeCallbacksRef.current;
|
|
57
|
+
closeCallbacksRef.current = [];
|
|
58
|
+
for (const cb of queued) {
|
|
40
59
|
try {
|
|
41
60
|
cb();
|
|
42
61
|
} catch (e) {
|
|
43
|
-
|
|
62
|
+
if (typeof console !== 'undefined' && console.error) {
|
|
63
|
+
console.error('Dialog close callback error:', e);
|
|
64
|
+
}
|
|
44
65
|
}
|
|
45
66
|
}
|
|
46
|
-
closeCallbacksRef.current = [];
|
|
47
67
|
onClose?.();
|
|
48
68
|
}, FADE_OUT_DURATION);
|
|
49
69
|
return () => clearTimeout(timer);
|
|
50
70
|
}, [isClosing, onClose]);
|
|
71
|
+
|
|
72
|
+
// Escape-to-close while open. The listener is intentionally scoped to the
|
|
73
|
+
// open lifetime so stacked dialogs don't fight for the keydown — the
|
|
74
|
+
// top-most one wins via document-level event order.
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!isOpen || typeof document === 'undefined') return;
|
|
77
|
+
const handler = e => {
|
|
78
|
+
if (e.key === 'Escape') {
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
close();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
document.addEventListener('keydown', handler);
|
|
84
|
+
return () => document.removeEventListener('keydown', handler);
|
|
85
|
+
}, [close, isOpen]);
|
|
51
86
|
useImperativeHandle(control.ref, () => ({
|
|
52
87
|
open,
|
|
53
88
|
close
|
|
@@ -72,23 +107,19 @@ export function Outer({
|
|
|
72
107
|
bottom: 0,
|
|
73
108
|
zIndex: 50,
|
|
74
109
|
alignItems: 'center',
|
|
75
|
-
justifyContent:
|
|
76
|
-
paddingHorizontal: 20
|
|
77
|
-
paddingVertical: '10vh',
|
|
78
|
-
...{
|
|
79
|
-
overflowY: 'auto'
|
|
80
|
-
}
|
|
110
|
+
justifyContent: 'center',
|
|
111
|
+
paddingHorizontal: 20
|
|
81
112
|
},
|
|
82
113
|
children: [/*#__PURE__*/_jsx(DialogBackdrop, {
|
|
83
114
|
isClosing: isClosing
|
|
84
|
-
}), /*#__PURE__*/_jsx(
|
|
115
|
+
}), /*#__PURE__*/_jsx(DialogPanel, {
|
|
85
116
|
testID: testID,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
117
|
+
label: label,
|
|
118
|
+
title: title,
|
|
119
|
+
description: description,
|
|
120
|
+
actions: actions,
|
|
121
|
+
style: style,
|
|
122
|
+
isClosing: isClosing,
|
|
92
123
|
children: children
|
|
93
124
|
})]
|
|
94
125
|
})]
|
|
@@ -96,26 +127,33 @@ export function Outer({
|
|
|
96
127
|
})
|
|
97
128
|
});
|
|
98
129
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
style,
|
|
130
|
+
function DialogPanel({
|
|
131
|
+
testID,
|
|
102
132
|
label,
|
|
103
|
-
|
|
104
|
-
|
|
133
|
+
title,
|
|
134
|
+
description,
|
|
135
|
+
actions,
|
|
136
|
+
style,
|
|
137
|
+
isClosing,
|
|
138
|
+
children
|
|
105
139
|
}) {
|
|
106
140
|
const theme = useTheme();
|
|
107
|
-
const
|
|
141
|
+
const titleId = useId();
|
|
142
|
+
const descriptionId = useId();
|
|
108
143
|
return /*#__PURE__*/_jsxs(View, {
|
|
109
144
|
role: "dialog",
|
|
110
145
|
"aria-label": label,
|
|
146
|
+
"aria-labelledby": title ? titleId : undefined,
|
|
147
|
+
"aria-describedby": description ? descriptionId : undefined,
|
|
148
|
+
testID: testID,
|
|
111
149
|
onStartShouldSetResponder: () => true,
|
|
112
150
|
onResponderRelease: stopPropagation,
|
|
113
151
|
onClick: stopPropagation,
|
|
114
152
|
style: [{
|
|
115
153
|
position: 'relative',
|
|
116
|
-
borderRadius:
|
|
154
|
+
borderRadius: 20,
|
|
117
155
|
width: '100%',
|
|
118
|
-
maxWidth:
|
|
156
|
+
maxWidth: 480,
|
|
119
157
|
backgroundColor: theme.colors.background,
|
|
120
158
|
borderWidth: 1,
|
|
121
159
|
borderColor: theme.isDark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.1)',
|
|
@@ -126,62 +164,128 @@ export function Inner({
|
|
|
126
164
|
width: 0,
|
|
127
165
|
height: 4
|
|
128
166
|
},
|
|
129
|
-
|
|
167
|
+
padding: 20,
|
|
168
|
+
zIndex: 60
|
|
130
169
|
}, isClosing ? {
|
|
131
170
|
animation: `bloomDialogZoomFadeOut ease-in ${FADE_OUT_DURATION}ms forwards`
|
|
132
171
|
} : {
|
|
133
172
|
animation: 'bloomDialogZoomFadeIn cubic-bezier(0.16, 1, 0.3, 1) 0.3s'
|
|
134
173
|
}, style],
|
|
135
|
-
children: [
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
174
|
+
children: [title ? /*#__PURE__*/_jsx(Text, {
|
|
175
|
+
nativeID: titleId,
|
|
176
|
+
style: {
|
|
177
|
+
fontSize: 22,
|
|
178
|
+
fontWeight: '600',
|
|
179
|
+
color: theme.colors.text,
|
|
180
|
+
paddingBottom: description ? 4 : 16,
|
|
181
|
+
lineHeight: 30
|
|
182
|
+
},
|
|
183
|
+
children: title
|
|
184
|
+
}) : null, description ? /*#__PURE__*/_jsx(Text, {
|
|
185
|
+
nativeID: descriptionId,
|
|
186
|
+
style: {
|
|
187
|
+
fontSize: 16,
|
|
188
|
+
color: theme.colors.textSecondary,
|
|
189
|
+
paddingBottom: 16,
|
|
190
|
+
lineHeight: 22
|
|
191
|
+
},
|
|
192
|
+
children: description
|
|
193
|
+
}) : null, children, actions && actions.length > 0 ? /*#__PURE__*/_jsx(ActionRow, {
|
|
194
|
+
actions: actions
|
|
195
|
+
}) : null]
|
|
141
196
|
});
|
|
142
197
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
198
|
+
function ActionRow({
|
|
199
|
+
actions
|
|
200
|
+
}) {
|
|
201
|
+
return /*#__PURE__*/_jsx(View, {
|
|
202
|
+
style: {
|
|
203
|
+
width: '100%',
|
|
204
|
+
gap: 8,
|
|
205
|
+
justifyContent: 'flex-end'
|
|
206
|
+
},
|
|
207
|
+
children: actions.map((action, idx) => /*#__PURE__*/_jsx(ActionButton, {
|
|
208
|
+
action: action
|
|
209
|
+
}, `${action.label}-${idx}`))
|
|
146
210
|
});
|
|
147
211
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
export function Close() {
|
|
212
|
+
function ActionButton({
|
|
213
|
+
action
|
|
214
|
+
}) {
|
|
152
215
|
const {
|
|
153
216
|
close
|
|
154
217
|
} = useDialogContext();
|
|
155
218
|
const theme = useTheme();
|
|
156
|
-
|
|
219
|
+
const color = action.color ?? 'default';
|
|
220
|
+
const shouldCloseOnPress = action.shouldCloseOnPress ?? true;
|
|
221
|
+
const {
|
|
222
|
+
background,
|
|
223
|
+
foreground
|
|
224
|
+
} = getActionPalette(color, theme.colors);
|
|
225
|
+
const handlePress = useCallback(e => {
|
|
226
|
+
const onPress = action.onPress;
|
|
227
|
+
if (color === 'cancel') {
|
|
228
|
+
close(onPress ? () => onPress(e) : undefined);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (shouldCloseOnPress) {
|
|
232
|
+
close(onPress ? () => onPress(e) : undefined);
|
|
233
|
+
} else {
|
|
234
|
+
onPress?.(e);
|
|
235
|
+
}
|
|
236
|
+
}, [action.onPress, close, color, shouldCloseOnPress]);
|
|
237
|
+
return /*#__PURE__*/_jsx(TouchableOpacity, {
|
|
157
238
|
style: {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
239
|
+
borderRadius: 9999,
|
|
240
|
+
alignItems: 'center',
|
|
241
|
+
justifyContent: 'center',
|
|
242
|
+
backgroundColor: background,
|
|
243
|
+
opacity: action.disabled ? 0.5 : 1,
|
|
244
|
+
paddingVertical: 12,
|
|
245
|
+
paddingHorizontal: 24
|
|
162
246
|
},
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
247
|
+
onPress: handlePress,
|
|
248
|
+
disabled: action.disabled,
|
|
249
|
+
activeOpacity: 0.7,
|
|
250
|
+
testID: action.testID,
|
|
251
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
166
252
|
style: {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
backgroundColor: theme.isDark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.05)',
|
|
171
|
-
alignItems: 'center',
|
|
172
|
-
justifyContent: 'center'
|
|
253
|
+
fontSize: 16,
|
|
254
|
+
fontWeight: '500',
|
|
255
|
+
color: foreground
|
|
173
256
|
},
|
|
174
|
-
children:
|
|
175
|
-
style: {
|
|
176
|
-
fontSize: 18,
|
|
177
|
-
color: theme.colors.text,
|
|
178
|
-
lineHeight: 20
|
|
179
|
-
},
|
|
180
|
-
children: '\u00D7'
|
|
181
|
-
})
|
|
257
|
+
children: action.label
|
|
182
258
|
})
|
|
183
259
|
});
|
|
184
260
|
}
|
|
261
|
+
function getActionPalette(color, colors) {
|
|
262
|
+
switch (color) {
|
|
263
|
+
case 'destructive':
|
|
264
|
+
return {
|
|
265
|
+
background: colors.negative,
|
|
266
|
+
foreground: colors.negativeForeground
|
|
267
|
+
};
|
|
268
|
+
case 'cancel':
|
|
269
|
+
return {
|
|
270
|
+
background: colors.contrast50,
|
|
271
|
+
foreground: colors.text
|
|
272
|
+
};
|
|
273
|
+
case 'default':
|
|
274
|
+
return {
|
|
275
|
+
background: colors.primary,
|
|
276
|
+
foreground: '#FFFFFF'
|
|
277
|
+
};
|
|
278
|
+
/* c8 ignore next 3 -- TS exhaustiveness guard */
|
|
279
|
+
default:
|
|
280
|
+
{
|
|
281
|
+
const _exhaustive = color;
|
|
282
|
+
return {
|
|
283
|
+
background: colors.primary,
|
|
284
|
+
foreground: '#FFFFFF'
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
185
289
|
function DialogBackdrop({
|
|
186
290
|
isClosing
|
|
187
291
|
}) {
|
|
@@ -201,8 +305,29 @@ function DialogBackdrop({
|
|
|
201
305
|
style: style
|
|
202
306
|
});
|
|
203
307
|
}
|
|
204
|
-
|
|
205
|
-
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Inline imperative dialog used by `alert()`. Mounts and immediately
|
|
311
|
+
* presents; resolves the host's `onResolve` once the dialog has finished
|
|
312
|
+
* its exit animation.
|
|
313
|
+
*/
|
|
314
|
+
export function AutoMountedDialog({
|
|
315
|
+
title,
|
|
316
|
+
description,
|
|
317
|
+
actions,
|
|
318
|
+
onResolve
|
|
319
|
+
}) {
|
|
320
|
+
const control = useDialogControl();
|
|
321
|
+
useEffect(() => {
|
|
322
|
+
control.open();
|
|
323
|
+
}, [control]);
|
|
324
|
+
return /*#__PURE__*/_jsx(Dialog, {
|
|
325
|
+
control: control,
|
|
326
|
+
title: title,
|
|
327
|
+
description: description,
|
|
328
|
+
actions: actions,
|
|
329
|
+
onClose: onResolve
|
|
330
|
+
});
|
|
206
331
|
}
|
|
207
332
|
|
|
208
333
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","createContext","useCallback","
|
|
1
|
+
{"version":3,"names":["React","createContext","useCallback","useEffect","useId","useImperativeHandle","useMemo","useRef","useState","Pressable","Text","TouchableOpacity","View","RemoveScrollBar","Portal","useTheme","Context","useDialogContext","useDialogControl","jsx","_jsx","jsxs","_jsxs","FADE_OUT_DURATION","stopPropagation","e","ClosingContext","Dialog","control","onClose","testID","title","description","actions","style","label","children","isOpen","setIsOpen","isClosing","setIsClosing","closeCallbacksRef","open","close","cb","current","push","timer","setTimeout","queued","console","error","clearTimeout","document","handler","key","addEventListener","removeEventListener","ref","context","isWithinDialog","Provider","value","onPress","position","top","left","right","bottom","zIndex","alignItems","justifyContent","paddingHorizontal","DialogBackdrop","DialogPanel","theme","titleId","descriptionId","role","undefined","onStartShouldSetResponder","onResponderRelease","onClick","borderRadius","width","maxWidth","backgroundColor","colors","background","borderWidth","borderColor","isDark","shadowColor","shadowOpacity","shadowRadius","shadowOffset","height","padding","animation","nativeID","fontSize","fontWeight","color","text","paddingBottom","lineHeight","textSecondary","length","ActionRow","gap","map","action","idx","ActionButton","shouldCloseOnPress","foreground","getActionPalette","handlePress","opacity","disabled","paddingVertical","activeOpacity","negative","negativeForeground","contrast50","primary","_exhaustive","AutoMountedDialog","onResolve","BLOOM_DIALOG_CSS"],"sourceRoot":"../../../src","sources":["dialog/Dialog.web.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IACVC,aAAa,EACbC,WAAW,EAEXC,SAAS,EACTC,KAAK,EACLC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,SACEC,SAAS,EACTC,IAAI,EACJC,gBAAgB,EAChBC,IAAI,QAGC,cAAc;AACrB,SAASC,eAAe,QAAQ,yBAAyB;AAEzD,SAASC,MAAM,QAAQ,wBAAqB;AAE5C,SAASC,QAAQ,QAAQ,uBAAoB;AAC7C,SAASC,OAAO,EAAEC,gBAAgB,EAAEC,gBAAgB,QAAQ,cAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAQxE,MAAMC,iBAAiB,GAAG,GAAG;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;IACLC,OAAO,EAAEA,OAAQ;IACjBG,KAAK,EAAEA,KAAM;IACbC,WAAW,EAAEA,WAAY;IACzBC,OAAO,EAAEA,OAAQ;IACjBJ,OAAO,EAAEmG;EAAU,CACpB,CAAC;AAEN;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAG;AAChC;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal bottom-sheet shell shared by `Menu`, `Select` and `ContextMenu`.
|
|
5
|
+
*
|
|
6
|
+
* Not exported from the public `@oxyhq/bloom` surface — these three
|
|
7
|
+
* components historically used the low-level `Dialog.Outer / Inner /
|
|
8
|
+
* Handle` primitives, which are gone in 0.5.0. This shell captures the
|
|
9
|
+
* shared shape (BottomSheet + drag handle + close-on-tap context) in a
|
|
10
|
+
* single place so the three internal call sites stay symmetrical.
|
|
11
|
+
*
|
|
12
|
+
* Consumers needing the same behaviour for app code should use the public
|
|
13
|
+
* `BottomSheet` primitive directly.
|
|
14
|
+
*/
|
|
15
|
+
import React, { useCallback, useImperativeHandle, useMemo, useRef } from 'react';
|
|
16
|
+
import { Pressable, StyleSheet, View } from 'react-native';
|
|
17
|
+
import { BottomSheet } from "../bottom-sheet/index.js";
|
|
18
|
+
import { useTheme } from "../theme/use-theme.js";
|
|
19
|
+
import { Context } from "./context.js";
|
|
20
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
21
|
+
/**
|
|
22
|
+
* Bottom-sheet shell with an embedded drag handle. Exposes the bloom
|
|
23
|
+
* dialog `close()` context to descendants — `Menu.Item`, `Select.Item`
|
|
24
|
+
* etc. rely on it to dismiss the sheet after selection.
|
|
25
|
+
*/
|
|
26
|
+
export function SheetShell({
|
|
27
|
+
control,
|
|
28
|
+
label,
|
|
29
|
+
header,
|
|
30
|
+
onClose,
|
|
31
|
+
contentStyle,
|
|
32
|
+
children
|
|
33
|
+
}) {
|
|
34
|
+
const theme = useTheme();
|
|
35
|
+
const ref = useRef(null);
|
|
36
|
+
const closeCallbacks = useRef([]);
|
|
37
|
+
const callQueuedCallbacks = useCallback(() => {
|
|
38
|
+
const queued = closeCallbacks.current;
|
|
39
|
+
closeCallbacks.current = [];
|
|
40
|
+
for (const cb of queued) {
|
|
41
|
+
try {
|
|
42
|
+
cb();
|
|
43
|
+
} catch (e) {
|
|
44
|
+
if (typeof console !== 'undefined' && console.error) {
|
|
45
|
+
console.error('SheetShell close callback error:', e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, []);
|
|
50
|
+
const open = useCallback(() => {
|
|
51
|
+
ref.current?.present();
|
|
52
|
+
}, []);
|
|
53
|
+
const close = useCallback(cb => {
|
|
54
|
+
if (typeof cb === 'function') {
|
|
55
|
+
closeCallbacks.current.push(cb);
|
|
56
|
+
}
|
|
57
|
+
ref.current?.dismiss();
|
|
58
|
+
}, []);
|
|
59
|
+
const handleDismiss = useCallback(() => {
|
|
60
|
+
callQueuedCallbacks();
|
|
61
|
+
onClose?.();
|
|
62
|
+
}, [callQueuedCallbacks, onClose]);
|
|
63
|
+
useImperativeHandle(control.ref, () => ({
|
|
64
|
+
open,
|
|
65
|
+
close
|
|
66
|
+
}), [open, close]);
|
|
67
|
+
const context = useMemo(() => ({
|
|
68
|
+
close,
|
|
69
|
+
isWithinDialog: true
|
|
70
|
+
}), [close]);
|
|
71
|
+
const sheetStyle = useMemo(() => ({
|
|
72
|
+
maxWidth: 500,
|
|
73
|
+
backgroundColor: theme.colors.background,
|
|
74
|
+
borderRadius: 20
|
|
75
|
+
}), [theme.colors.background]);
|
|
76
|
+
return /*#__PURE__*/_jsx(BottomSheet, {
|
|
77
|
+
ref: ref,
|
|
78
|
+
onDismiss: handleDismiss,
|
|
79
|
+
enablePanDownToClose: true,
|
|
80
|
+
detached: true,
|
|
81
|
+
backdropOpacity: 0.7,
|
|
82
|
+
style: sheetStyle,
|
|
83
|
+
children: /*#__PURE__*/_jsxs(Context.Provider, {
|
|
84
|
+
value: context,
|
|
85
|
+
children: [/*#__PURE__*/_jsx(SheetHandle, {
|
|
86
|
+
onPress: () => close()
|
|
87
|
+
}), header, /*#__PURE__*/_jsx(View, {
|
|
88
|
+
accessibilityLabel: label,
|
|
89
|
+
style: [styles.body, {
|
|
90
|
+
backgroundColor: theme.colors.background
|
|
91
|
+
}, contentStyle],
|
|
92
|
+
children: children
|
|
93
|
+
})]
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function SheetHandle({
|
|
98
|
+
onPress
|
|
99
|
+
}) {
|
|
100
|
+
const theme = useTheme();
|
|
101
|
+
return /*#__PURE__*/_jsx(View, {
|
|
102
|
+
style: styles.handleContainer,
|
|
103
|
+
children: /*#__PURE__*/_jsx(Pressable, {
|
|
104
|
+
onPress: onPress,
|
|
105
|
+
accessibilityLabel: "Dismiss",
|
|
106
|
+
accessibilityHint: "Tap to close",
|
|
107
|
+
hitSlop: {
|
|
108
|
+
top: 10,
|
|
109
|
+
bottom: 10,
|
|
110
|
+
left: 40,
|
|
111
|
+
right: 40
|
|
112
|
+
},
|
|
113
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
114
|
+
style: [styles.handleBar, {
|
|
115
|
+
backgroundColor: theme.colors.text
|
|
116
|
+
}]
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const styles = StyleSheet.create({
|
|
122
|
+
handleContainer: {
|
|
123
|
+
position: 'absolute',
|
|
124
|
+
width: '100%',
|
|
125
|
+
alignItems: 'center',
|
|
126
|
+
zIndex: 10,
|
|
127
|
+
height: 20
|
|
128
|
+
},
|
|
129
|
+
handleBar: {
|
|
130
|
+
top: 8,
|
|
131
|
+
width: 35,
|
|
132
|
+
height: 5,
|
|
133
|
+
borderRadius: 3,
|
|
134
|
+
alignSelf: 'center',
|
|
135
|
+
opacity: 0.5
|
|
136
|
+
},
|
|
137
|
+
body: {
|
|
138
|
+
paddingTop: 20,
|
|
139
|
+
paddingHorizontal: 20,
|
|
140
|
+
paddingBottom: 20
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=SheetShell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useCallback","useImperativeHandle","useMemo","useRef","Pressable","StyleSheet","View","BottomSheet","useTheme","Context","jsx","_jsx","jsxs","_jsxs","SheetShell","control","label","header","onClose","contentStyle","children","theme","ref","closeCallbacks","callQueuedCallbacks","queued","current","cb","e","console","error","open","present","close","push","dismiss","handleDismiss","context","isWithinDialog","sheetStyle","maxWidth","backgroundColor","colors","background","borderRadius","onDismiss","enablePanDownToClose","detached","backdropOpacity","style","Provider","value","SheetHandle","onPress","accessibilityLabel","styles","body","handleContainer","accessibilityHint","hitSlop","top","bottom","left","right","handleBar","text","create","position","width","alignItems","zIndex","height","alignSelf","opacity","paddingTop","paddingHorizontal","paddingBottom"],"sourceRoot":"../../../src","sources":["dialog/SheetShell.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,mBAAmB,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAChF,SAASC,SAAS,EAAEC,UAAU,EAAEC,IAAI,QAAwC,cAAc;AAE1F,SAASC,WAAW,QAA6B,0BAAiB;AAClE,SAASC,QAAQ,QAAQ,uBAAoB;AAC7C,SAASC,OAAO,QAAQ,cAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAapC;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAAC;EACzBC,OAAO;EACPC,KAAK;EACLC,MAAM;EACNC,OAAO;EACPC,YAAY;EACZC;AACe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BAAkB,EAAC,SAAS;MAC5BI,iBAAiB,EAAC,cAAc;MAChCC,OAAO,EAAE;QAAEC,GAAG,EAAE,EAAE;QAAEC,MAAM,EAAE,EAAE;QAAEC,IAAI,EAAE,EAAE;QAAEC,KAAK,EAAE;MAAG,CAAE;MAAA3C,QAAA,eAEtDT,IAAA,CAACL,IAAI;QAAC2C,KAAK,EAAE,CAACM,MAAM,CAACS,SAAS,EAAE;UAAEvB,eAAe,EAAEpB,KAAK,CAACqB,MAAM,CAACuB;QAAK,CAAC;MAAE,CAAE;IAAC,CAClE;EAAC,CACR,CAAC;AAEX;AAEA,MAAMV,MAAM,GAAGlD,UAAU,CAAC6D,MAAM,CAAC;EAC/BT,eAAe,EAAE;IACfU,QAAQ,EAAE,UAAU;IACpBC,KAAK,EAAE,MAAM;IACbC,UAAU,EAAE,QAAQ;IACpBC,MAAM,EAAE,EAAE;IACVC,MAAM,EAAE;EACV,CAAC;EACDP,SAAS,EAAE;IACTJ,GAAG,EAAE,CAAC;IACNQ,KAAK,EAAE,EAAE;IACTG,MAAM,EAAE,CAAC;IACT3B,YAAY,EAAE,CAAC;IACf4B,SAAS,EAAE,QAAQ;IACnBC,OAAO,EAAE;EACX,CAAC;EACDjB,IAAI,EAAE;IACJkB,UAAU,EAAE,EAAE;IACdC,iBAAiB,EAAE,EAAE;IACrBC,aAAa,EAAE;EACjB;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
let idCounter = 0;
|
|
4
|
+
function genId() {
|
|
5
|
+
idCounter += 1;
|
|
6
|
+
return `bloom-alert-${idCounter}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Imperative-alert store.
|
|
11
|
+
*
|
|
12
|
+
* The store sits in module scope so `alert()` works from anywhere — event
|
|
13
|
+
* handlers, async callbacks, top-level helpers — without threading a
|
|
14
|
+
* provider context through every call site.
|
|
15
|
+
*
|
|
16
|
+
* The visible UI is owned by a single subscriber (the `<BloomDialogProvider>`
|
|
17
|
+
* mounted inside the app's React tree). When there is no subscriber yet —
|
|
18
|
+
* because `alert()` was called before the provider mounted, or because the
|
|
19
|
+
* app forgot to mount the provider — entries accumulate in the queue and
|
|
20
|
+
* drain as soon as a subscriber attaches.
|
|
21
|
+
*
|
|
22
|
+
* Multiple subscribers are not supported by design. Two providers would
|
|
23
|
+
* race for the same alert; we instead enforce a single listener and let
|
|
24
|
+
* the most recent subscription win (the older one falls back to no-op).
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
let queue = [];
|
|
28
|
+
let listener = null;
|
|
29
|
+
function emit() {
|
|
30
|
+
if (listener) listener(queue);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Enqueue an alert. Returns the generated id so callers can dismiss it
|
|
35
|
+
* imperatively (rare — usually the dialog dismisses itself via a button
|
|
36
|
+
* tap). The runtime guarantees this enqueues even before any provider
|
|
37
|
+
* mounts; the provider drains pending entries on subscribe.
|
|
38
|
+
*/
|
|
39
|
+
export function enqueueAlert(entry) {
|
|
40
|
+
const id = genId();
|
|
41
|
+
queue = [...queue, {
|
|
42
|
+
...entry,
|
|
43
|
+
id
|
|
44
|
+
}];
|
|
45
|
+
emit();
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Remove an alert from the queue. Called by the provider once the bloom
|
|
51
|
+
* Dialog has finished closing for that entry.
|
|
52
|
+
*/
|
|
53
|
+
export function dismissAlert(id) {
|
|
54
|
+
const next = queue.filter(e => e.id !== id);
|
|
55
|
+
if (next.length === queue.length) return;
|
|
56
|
+
queue = next;
|
|
57
|
+
emit();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to queue changes. Replaces any previously-registered listener
|
|
62
|
+
* (single-subscriber model — see header). Returns an unsubscribe function.
|
|
63
|
+
*
|
|
64
|
+
* On subscribe, the current queue is delivered synchronously so the
|
|
65
|
+
* subscriber can render pending entries that arrived before mount.
|
|
66
|
+
*/
|
|
67
|
+
export function subscribeAlerts(fn) {
|
|
68
|
+
listener = fn;
|
|
69
|
+
// Deliver the current queue immediately so a freshly-mounted provider
|
|
70
|
+
// catches up with whatever accumulated before it subscribed.
|
|
71
|
+
fn(queue);
|
|
72
|
+
return () => {
|
|
73
|
+
if (listener === fn) listener = null;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Inspect the current queue. Used internally and by tests. */
|
|
78
|
+
export function getAlertQueue() {
|
|
79
|
+
return queue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Translate an alert button to the action shape the unified `Dialog`
|
|
84
|
+
* accepts. Pure — no React, no theme — so it can be reused on web and
|
|
85
|
+
* native without forking.
|
|
86
|
+
*/
|
|
87
|
+
export function buttonToAction(button) {
|
|
88
|
+
return {
|
|
89
|
+
label: button.text,
|
|
90
|
+
onPress: button.onPress ? () => button.onPress?.() : undefined,
|
|
91
|
+
color: button.style === 'destructive' ? 'destructive' : button.style === 'cancel' ? 'cancel' : 'default'
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Compute the effective button set for an alert. Mirrors React Native's
|
|
97
|
+
* `Alert.alert` semantics — an empty/omitted buttons array implies a
|
|
98
|
+
* single `OK` confirmation button.
|
|
99
|
+
*/
|
|
100
|
+
export function resolveButtons(buttons) {
|
|
101
|
+
if (buttons && buttons.length > 0) return buttons;
|
|
102
|
+
return [{
|
|
103
|
+
text: 'OK',
|
|
104
|
+
style: 'default'
|
|
105
|
+
}];
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=alert-store.js.map
|