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