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