@tamagui/adapt 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.
- package/dist/cjs/Adapt.cjs +460 -206
- package/dist/cjs/Adapt.native.cjs +551 -0
- package/dist/cjs/Adapt.native.js +517 -253
- package/dist/cjs/Adapt.native.js.map +1 -1
- package/dist/cjs/index.cjs +9 -11
- package/dist/cjs/index.native.cjs +20 -0
- package/dist/cjs/index.native.js +9 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Adapt.mjs +437 -177
- package/dist/esm/Adapt.mjs.map +1 -1
- package/dist/esm/Adapt.native.js +494 -224
- package/dist/esm/Adapt.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/package.json +9 -8
- package/src/Adapt.tsx +505 -152
- package/types/Adapt.d.ts +74 -29
- package/types/Adapt.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
package/dist/esm/Adapt.mjs
CHANGED
|
@@ -1,196 +1,456 @@
|
|
|
1
1
|
import { isAndroid, isIos, isTouchable, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
2
|
import { createStyledContext, useMedia } from "@tamagui/core";
|
|
3
3
|
import { withStaticProperties } from "@tamagui/helpers";
|
|
4
|
-
import { getPortal } from "@tamagui/native";
|
|
5
|
-
import { PortalHost, PortalItem } from "@tamagui/portal";
|
|
6
4
|
import { StackZIndexContext } from "@tamagui/z-index-stack";
|
|
7
|
-
import React, { createContext, useContext, useId
|
|
5
|
+
import React, { createContext, useContext, useId } from "react";
|
|
8
6
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
|
|
8
|
+
function createAdaptSlotStore() {
|
|
9
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
10
|
+
const store = {
|
|
11
|
+
element: null,
|
|
12
|
+
version: 0,
|
|
13
|
+
publish(element) {
|
|
14
|
+
store.element = element;
|
|
15
|
+
},
|
|
16
|
+
clear() {
|
|
17
|
+
store.element = null;
|
|
18
|
+
},
|
|
19
|
+
notify() {
|
|
20
|
+
store.version += 1;
|
|
21
|
+
for (const listener of listeners) {
|
|
22
|
+
listener();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
getSnapshot() {
|
|
26
|
+
return store.version;
|
|
27
|
+
},
|
|
28
|
+
subscribe(callback) {
|
|
29
|
+
listeners.add(callback);
|
|
30
|
+
return () => {
|
|
31
|
+
listeners.delete(callback);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return store;
|
|
23
36
|
}
|
|
24
|
-
const
|
|
37
|
+
const adaptContextKeys = [
|
|
38
|
+
"Contents",
|
|
39
|
+
"scopeName",
|
|
40
|
+
"portalName",
|
|
41
|
+
"active",
|
|
42
|
+
"setAdaptConfig",
|
|
43
|
+
"slot",
|
|
44
|
+
"handoff",
|
|
45
|
+
"targetFullyHidden",
|
|
46
|
+
"registerTarget",
|
|
47
|
+
"unregisterTarget",
|
|
48
|
+
"registerContents",
|
|
49
|
+
"unregisterContents",
|
|
50
|
+
"registerRenderCallback",
|
|
51
|
+
"unregisterRenderCallback"
|
|
52
|
+
];
|
|
25
53
|
const AdaptContext = createStyledContext({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
54
|
+
Contents: null,
|
|
55
|
+
scopeName: "",
|
|
56
|
+
portalName: "",
|
|
57
|
+
active: false,
|
|
58
|
+
setAdaptConfig: () => {},
|
|
59
|
+
slot: null,
|
|
60
|
+
handoff: {
|
|
61
|
+
hidden: true,
|
|
62
|
+
onTransition: () => {}
|
|
63
|
+
},
|
|
64
|
+
targetFullyHidden: true,
|
|
65
|
+
registerTarget: () => {},
|
|
66
|
+
unregisterTarget: () => {},
|
|
67
|
+
registerContents: () => {},
|
|
68
|
+
unregisterContents: () => {},
|
|
69
|
+
registerRenderCallback: () => {},
|
|
70
|
+
unregisterRenderCallback: () => {}
|
|
71
|
+
}, { keys: adaptContextKeys });
|
|
72
|
+
const AdaptCapabilitiesContext = createContext({});
|
|
34
73
|
const LastAdaptContextScope = createContext("");
|
|
35
|
-
const ProvideAdaptContext = ({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
children
|
|
48
|
-
})
|
|
49
|
-
});
|
|
74
|
+
const ProvideAdaptContext = ({ children, ...context }) => {
|
|
75
|
+
const scope = context.scopeName || "";
|
|
76
|
+
const lastScope = useContext(LastAdaptContextScope);
|
|
77
|
+
return /* @__PURE__ */ jsx(LastAdaptContextScope.Provider, {
|
|
78
|
+
value: lastScope || context.lastScope || "",
|
|
79
|
+
children: /* @__PURE__ */ jsx(AdaptContext.Provider, {
|
|
80
|
+
scope,
|
|
81
|
+
lastScope: lastScope || context.lastScope,
|
|
82
|
+
...context,
|
|
83
|
+
children
|
|
84
|
+
})
|
|
85
|
+
});
|
|
50
86
|
};
|
|
51
|
-
const useAdaptContext = scope => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
87
|
+
const useAdaptContext = (scope) => {
|
|
88
|
+
const lastScope = useContext(LastAdaptContextScope);
|
|
89
|
+
const adaptScope = scope ?? lastScope;
|
|
90
|
+
return AdaptContext.useStyledContext(adaptScope);
|
|
55
91
|
};
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
92
|
+
function findAdaptConfig(children, scope) {
|
|
93
|
+
for (const child of React.Children.toArray(children)) {
|
|
94
|
+
if (!React.isValidElement(child)) continue;
|
|
95
|
+
if (child.type === React.Fragment) {
|
|
96
|
+
const found = findAdaptConfig(child.props.children, scope);
|
|
97
|
+
if (found) return found;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (child.type === Adapt) {
|
|
101
|
+
const childProps = child.props;
|
|
102
|
+
if (childProps.scope == null || childProps.scope === scope) {
|
|
103
|
+
return childProps;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const AdaptParent = ({ children, adaptChildren, Contents, scope, open, onOpenChange, state }) => {
|
|
110
|
+
const id = useId();
|
|
111
|
+
const portalName = `AdaptPortal${scope}${id}`;
|
|
112
|
+
const slotRef = React.useRef(null);
|
|
113
|
+
if (!slotRef.current) {
|
|
114
|
+
slotRef.current = createAdaptSlotStore();
|
|
115
|
+
}
|
|
116
|
+
const staticConfig = React.useMemo(() => findAdaptConfig(adaptChildren, scope) ?? findAdaptConfig(children, scope), [
|
|
117
|
+
adaptChildren,
|
|
118
|
+
children,
|
|
119
|
+
scope
|
|
120
|
+
]);
|
|
121
|
+
const [publishedConfig, setPublishedConfig] = React.useState(null);
|
|
122
|
+
const rawActive = useAdaptIsActiveGiven(staticConfig ?? publishedConfig);
|
|
123
|
+
const staticConfigRef = React.useRef(staticConfig);
|
|
124
|
+
staticConfigRef.current = staticConfig;
|
|
125
|
+
const setAdaptConfig = React.useCallback((config) => {
|
|
126
|
+
if (staticConfigRef.current) return;
|
|
127
|
+
setPublishedConfig(config);
|
|
128
|
+
}, []);
|
|
129
|
+
const [exiting, setExiting] = React.useState(false);
|
|
130
|
+
const [present, setPresent] = React.useState(false);
|
|
131
|
+
const [targetFullyHidden, setTargetFullyHidden] = React.useState(!open);
|
|
132
|
+
const targetCountRef = React.useRef(0);
|
|
133
|
+
const contentsCountRef = React.useRef(0);
|
|
134
|
+
const renderCallbackCountRef = React.useRef(0);
|
|
135
|
+
const rawActiveRef = React.useRef(false);
|
|
136
|
+
const openRef = React.useRef(open);
|
|
137
|
+
const wasTargetHiddenRef = React.useRef(!rawActive);
|
|
138
|
+
const hasHadActiveTargetRef = React.useRef(false);
|
|
139
|
+
const shouldStartExit = !rawActive && present && Boolean(open);
|
|
140
|
+
const active = rawActive || exiting || shouldStartExit;
|
|
141
|
+
const targetHidden = !rawActive;
|
|
142
|
+
const skipNextAnimation = Boolean(rawActive && wasTargetHiddenRef.current && hasHadActiveTargetRef.current && open);
|
|
143
|
+
const releasePresenceLatch = React.useCallback(() => {
|
|
144
|
+
setExiting(false);
|
|
145
|
+
if (!rawActiveRef.current) {
|
|
146
|
+
setPresent(false);
|
|
147
|
+
}
|
|
148
|
+
}, []);
|
|
149
|
+
useIsomorphicLayoutEffect(() => {
|
|
150
|
+
if (shouldStartExit) {
|
|
151
|
+
setExiting(true);
|
|
152
|
+
}
|
|
153
|
+
}, [shouldStartExit]);
|
|
154
|
+
useIsomorphicLayoutEffect(() => {
|
|
155
|
+
rawActiveRef.current = rawActive;
|
|
156
|
+
openRef.current = open;
|
|
157
|
+
if (rawActive) {
|
|
158
|
+
hasHadActiveTargetRef.current = true;
|
|
159
|
+
}
|
|
160
|
+
wasTargetHiddenRef.current = targetHidden;
|
|
161
|
+
if (open && rawActive) {
|
|
162
|
+
setTargetFullyHidden(false);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (!open && !active) {
|
|
166
|
+
setTargetFullyHidden(true);
|
|
167
|
+
}
|
|
168
|
+
}, [
|
|
169
|
+
active,
|
|
170
|
+
open,
|
|
171
|
+
rawActive,
|
|
172
|
+
targetHidden
|
|
173
|
+
]);
|
|
174
|
+
useIsomorphicLayoutEffect(() => {
|
|
175
|
+
if (rawActive) {
|
|
176
|
+
setPresent(true);
|
|
177
|
+
} else if (!active) {
|
|
178
|
+
setPresent(false);
|
|
179
|
+
}
|
|
180
|
+
if (rawActive && exiting) {
|
|
181
|
+
setExiting(false);
|
|
182
|
+
}
|
|
183
|
+
}, [
|
|
184
|
+
active,
|
|
185
|
+
exiting,
|
|
186
|
+
rawActive
|
|
187
|
+
]);
|
|
188
|
+
const handoff = React.useMemo(() => ({
|
|
189
|
+
hidden: targetHidden,
|
|
190
|
+
skipNextAnimation,
|
|
191
|
+
onTransition(e) {
|
|
192
|
+
if (e.phase !== "end" || e.finished === false) return;
|
|
193
|
+
if (e.cause !== "close") {
|
|
194
|
+
setTargetFullyHidden(false);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (openRef.current && rawActiveRef.current) {
|
|
198
|
+
setTargetFullyHidden(false);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
setTargetFullyHidden(true);
|
|
202
|
+
releasePresenceLatch();
|
|
203
|
+
}
|
|
204
|
+
}), [
|
|
205
|
+
releasePresenceLatch,
|
|
206
|
+
skipNextAnimation,
|
|
207
|
+
targetHidden
|
|
208
|
+
]);
|
|
209
|
+
const registerTarget = React.useCallback(() => {
|
|
210
|
+
targetCountRef.current += 1;
|
|
211
|
+
if (process.env.NODE_ENV === "development" && targetCountRef.current > 1) {
|
|
212
|
+
console.error(`Adapt expected exactly one target in scope "${scope}", but ${targetCountRef.current} targets registered.`);
|
|
213
|
+
}
|
|
214
|
+
}, [scope]);
|
|
215
|
+
const unregisterTarget = React.useCallback(() => {
|
|
216
|
+
targetCountRef.current = Math.max(0, targetCountRef.current - 1);
|
|
217
|
+
}, []);
|
|
218
|
+
const registerContents = React.useCallback(() => {
|
|
219
|
+
contentsCountRef.current += 1;
|
|
220
|
+
}, []);
|
|
221
|
+
const unregisterContents = React.useCallback(() => {
|
|
222
|
+
contentsCountRef.current = Math.max(0, contentsCountRef.current - 1);
|
|
223
|
+
}, []);
|
|
224
|
+
const registerRenderCallback = React.useCallback(() => {
|
|
225
|
+
renderCallbackCountRef.current += 1;
|
|
226
|
+
}, []);
|
|
227
|
+
const unregisterRenderCallback = React.useCallback(() => {
|
|
228
|
+
renderCallbackCountRef.current = Math.max(0, renderCallbackCountRef.current - 1);
|
|
229
|
+
}, []);
|
|
230
|
+
React.useEffect(() => {
|
|
231
|
+
if (process.env.NODE_ENV !== "development") return;
|
|
232
|
+
if (!active) return;
|
|
233
|
+
const timer = setTimeout(() => {
|
|
234
|
+
if (rawActiveRef.current && targetCountRef.current === 0 && contentsCountRef.current === 0 && renderCallbackCountRef.current === 0) {
|
|
235
|
+
console.error(`Adapt is active in scope "${scope}" but no target registered with useAdaptTarget(), Adapt.Contents marker, or render callback consumed it.`);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
return () => clearTimeout(timer);
|
|
239
|
+
}, [active, scope]);
|
|
240
|
+
const FinalContents = Contents || AdaptSlotContents;
|
|
241
|
+
return /* @__PURE__ */ jsx(LastAdaptContextScope.Provider, {
|
|
242
|
+
value: scope,
|
|
243
|
+
children: /* @__PURE__ */ jsx(ProvideAdaptContext, {
|
|
244
|
+
Contents: FinalContents,
|
|
245
|
+
active,
|
|
246
|
+
setAdaptConfig,
|
|
247
|
+
portalName,
|
|
248
|
+
scopeName: scope,
|
|
249
|
+
slot: slotRef.current,
|
|
250
|
+
open,
|
|
251
|
+
onOpenChange,
|
|
252
|
+
state,
|
|
253
|
+
handoff,
|
|
254
|
+
targetFullyHidden,
|
|
255
|
+
registerTarget,
|
|
256
|
+
unregisterTarget,
|
|
257
|
+
registerContents,
|
|
258
|
+
unregisterContents,
|
|
259
|
+
registerRenderCallback,
|
|
260
|
+
unregisterRenderCallback,
|
|
261
|
+
children
|
|
262
|
+
})
|
|
263
|
+
});
|
|
104
264
|
};
|
|
105
|
-
const AdaptContents = ({
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
265
|
+
const AdaptContents = ({ scope, ...rest }) => {
|
|
266
|
+
const context = useAdaptContext(scope);
|
|
267
|
+
if (!context?.Contents) {
|
|
268
|
+
throw new Error(process.env.NODE_ENV === "production" ? `tamagui.dev/docs/intro/errors#warning-002` : `You're rendering a Tamagui <Adapt /> component without nesting it inside a parent that is able to adapt.`);
|
|
269
|
+
}
|
|
270
|
+
useIsomorphicLayoutEffect(() => {
|
|
271
|
+
if (!context.active) return;
|
|
272
|
+
context.registerContents();
|
|
273
|
+
return () => {
|
|
274
|
+
context.unregisterContents();
|
|
275
|
+
};
|
|
276
|
+
}, [
|
|
277
|
+
context.active,
|
|
278
|
+
context.registerContents,
|
|
279
|
+
context.unregisterContents
|
|
280
|
+
]);
|
|
281
|
+
return React.createElement(context.Contents, {
|
|
282
|
+
...rest,
|
|
283
|
+
scope,
|
|
284
|
+
key: `stable`
|
|
285
|
+
});
|
|
115
286
|
};
|
|
116
287
|
AdaptContents.shouldForwardSpace = true;
|
|
117
288
|
const Adapt = withStaticProperties(function Adapt2(props) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
289
|
+
const { children, platform, scope, when } = props;
|
|
290
|
+
const context = useAdaptContext(scope);
|
|
291
|
+
const enabled = context.active;
|
|
292
|
+
const isRenderCallback = typeof children === "function";
|
|
293
|
+
useIsomorphicLayoutEffect(() => {
|
|
294
|
+
context.setAdaptConfig({
|
|
295
|
+
when,
|
|
296
|
+
platform
|
|
297
|
+
});
|
|
298
|
+
return () => {
|
|
299
|
+
context.setAdaptConfig(null);
|
|
300
|
+
};
|
|
301
|
+
}, [
|
|
302
|
+
when,
|
|
303
|
+
platform,
|
|
304
|
+
context.setAdaptConfig
|
|
305
|
+
]);
|
|
306
|
+
useIsomorphicLayoutEffect(() => {
|
|
307
|
+
if (!enabled || !isRenderCallback) return;
|
|
308
|
+
context.registerRenderCallback();
|
|
309
|
+
return () => {
|
|
310
|
+
context.unregisterRenderCallback();
|
|
311
|
+
};
|
|
312
|
+
}, [
|
|
313
|
+
enabled,
|
|
314
|
+
isRenderCallback,
|
|
315
|
+
context.registerRenderCallback,
|
|
316
|
+
context.unregisterRenderCallback
|
|
317
|
+
]);
|
|
318
|
+
let output;
|
|
319
|
+
if (isRenderCallback) {
|
|
320
|
+
const Component = context?.Contents;
|
|
321
|
+
output = children(Component ? /* @__PURE__ */ jsx(Component, {}) : null, getAdaptRenderState(context));
|
|
322
|
+
} else {
|
|
323
|
+
output = children;
|
|
324
|
+
}
|
|
325
|
+
return /* @__PURE__ */ jsx(StackZIndexContext, { children: !enabled ? null : output });
|
|
326
|
+
}, { Contents: AdaptContents });
|
|
327
|
+
const AdaptPortalContents = (props) => {
|
|
328
|
+
const isActive = useAdaptIsActive(props.scope);
|
|
329
|
+
const { slot } = useAdaptContext(props.scope);
|
|
330
|
+
return /* @__PURE__ */ jsx(AdaptSlotPublisher, {
|
|
331
|
+
isActive,
|
|
332
|
+
slot,
|
|
333
|
+
children: props.children
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
function AdaptSlotContents({ scope }) {
|
|
337
|
+
const { slot } = useAdaptContext(scope);
|
|
338
|
+
React.useSyncExternalStore(slot?.subscribe ?? emptySubscribe, slot?.getSnapshot ?? emptySnapshot, slot?.getSnapshot ?? emptySnapshot);
|
|
339
|
+
return /* @__PURE__ */ jsx(Fragment, { children: slot?.element ?? null });
|
|
340
|
+
}
|
|
341
|
+
function AdaptSlotPublisher({ isActive, slot, children }) {
|
|
342
|
+
const publishedRef = React.useRef(null);
|
|
343
|
+
useIsomorphicLayoutEffect(() => {
|
|
344
|
+
if (!slot) return;
|
|
345
|
+
const published = publishedRef.current;
|
|
346
|
+
if (published && published.isActive === isActive && published.element === children) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
publishedRef.current = {
|
|
350
|
+
isActive,
|
|
351
|
+
element: children
|
|
352
|
+
};
|
|
353
|
+
if (isActive) {
|
|
354
|
+
slot.publish(children);
|
|
355
|
+
} else {
|
|
356
|
+
slot.clear();
|
|
357
|
+
}
|
|
358
|
+
slot.notify();
|
|
359
|
+
});
|
|
360
|
+
useIsomorphicLayoutEffect(() => {
|
|
361
|
+
return () => {
|
|
362
|
+
if (publishedRef.current?.isActive) {
|
|
363
|
+
slot?.clear();
|
|
364
|
+
slot?.notify();
|
|
365
|
+
}
|
|
366
|
+
publishedRef.current = null;
|
|
367
|
+
};
|
|
368
|
+
}, [slot]);
|
|
369
|
+
return isActive ? null : /* @__PURE__ */ jsx(Fragment, { children });
|
|
370
|
+
}
|
|
371
|
+
const emptySubscribe = () => () => {};
|
|
372
|
+
const emptySnapshot = () => 0;
|
|
373
|
+
const useAdaptIsActiveGiven = (config) => {
|
|
374
|
+
const media = useMedia();
|
|
375
|
+
const when = config?.when;
|
|
376
|
+
const platform = config?.platform;
|
|
377
|
+
if (when == null && platform == null) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
if (when === true) {
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
let enabled = false;
|
|
384
|
+
if (platform === "touch") enabled = isTouchable;
|
|
385
|
+
else if (platform === "native") enabled = !isWeb;
|
|
386
|
+
else if (platform === "web") enabled = isWeb;
|
|
387
|
+
else if (platform === "ios") enabled = isIos;
|
|
388
|
+
else if (platform === "android") enabled = isAndroid;
|
|
389
|
+
if (platform && enabled == false) {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
if (when && typeof when === "string") {
|
|
393
|
+
enabled = media[when];
|
|
394
|
+
}
|
|
395
|
+
return enabled;
|
|
396
|
+
};
|
|
397
|
+
const useAdaptIsActive = (scope) => {
|
|
398
|
+
return useAdaptContext(scope).active;
|
|
163
399
|
};
|
|
164
|
-
function
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
400
|
+
function useAdaptTarget(scope) {
|
|
401
|
+
const context = useAdaptContext(scope);
|
|
402
|
+
useIsomorphicLayoutEffect(() => {
|
|
403
|
+
if (!context.active) return;
|
|
404
|
+
context.registerTarget();
|
|
405
|
+
return () => {
|
|
406
|
+
context.unregisterTarget();
|
|
407
|
+
};
|
|
408
|
+
}, [
|
|
409
|
+
context.active,
|
|
410
|
+
context.registerTarget,
|
|
411
|
+
context.unregisterTarget
|
|
412
|
+
]);
|
|
413
|
+
if (!context.active) {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
open: context.open,
|
|
418
|
+
onOpenChange: context.onOpenChange,
|
|
419
|
+
handoff: context.handoff,
|
|
420
|
+
state: context.state
|
|
421
|
+
};
|
|
178
422
|
}
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
423
|
+
const AdaptCapabilities = ({ children, scroll, overlay, dismiss }) => {
|
|
424
|
+
const parent = useContext(AdaptCapabilitiesContext);
|
|
425
|
+
const value = React.useMemo(() => ({
|
|
426
|
+
scroll: scroll ?? parent.scroll,
|
|
427
|
+
overlay: overlay ?? parent.overlay,
|
|
428
|
+
dismiss: dismiss ?? parent.dismiss
|
|
429
|
+
}), [
|
|
430
|
+
dismiss,
|
|
431
|
+
overlay,
|
|
432
|
+
parent.dismiss,
|
|
433
|
+
parent.overlay,
|
|
434
|
+
parent.scroll,
|
|
435
|
+
scroll
|
|
436
|
+
]);
|
|
437
|
+
return /* @__PURE__ */ jsx(AdaptCapabilitiesContext.Provider, {
|
|
438
|
+
value,
|
|
439
|
+
children
|
|
440
|
+
});
|
|
191
441
|
};
|
|
192
|
-
const
|
|
193
|
-
|
|
442
|
+
const useAdaptedCapabilities = () => {
|
|
443
|
+
return useContext(AdaptCapabilitiesContext);
|
|
194
444
|
};
|
|
195
|
-
|
|
445
|
+
function getAdaptRenderState(context) {
|
|
446
|
+
return {
|
|
447
|
+
active: context.active,
|
|
448
|
+
open: context.open,
|
|
449
|
+
onOpenChange: context.onOpenChange,
|
|
450
|
+
state: context.state,
|
|
451
|
+
handoff: context.handoff
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export { Adapt, AdaptCapabilities, AdaptContents, AdaptContext, AdaptParent, AdaptPortalContents, ProvideAdaptContext, useAdaptContext, useAdaptIsActive, useAdaptTarget, useAdaptedCapabilities };
|
|
196
456
|
//# sourceMappingURL=Adapt.mjs.map
|