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