@tamagui/portal 1.114.3 → 1.115.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/dist/cjs/GorhomPortal.cjs +216 -0
- package/dist/cjs/Portal.cjs +54 -0
- package/dist/cjs/Portal.native.cjs +59 -0
- package/dist/cjs/Portal.native.cjs.map +6 -0
- package/dist/cjs/PortalProps.cjs +16 -0
- package/dist/cjs/index.cjs +20 -0
- package/package.json +10 -9
- package/dist/cjs/GorhomPortal.js +0 -169
- package/dist/cjs/Portal.js +0 -46
- package/dist/cjs/PortalProps.js +0 -14
- package/dist/cjs/index.js +0 -17
- /package/dist/cjs/{GorhomPortal.js.map → GorhomPortal.cjs.map} +0 -0
- /package/dist/cjs/{Portal.js.map → Portal.cjs.map} +0 -0
- /package/dist/cjs/{PortalProps.js.map → PortalProps.cjs.map} +0 -0
- /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var GorhomPortal_exports = {};
|
|
33
|
+
__export(GorhomPortal_exports, {
|
|
34
|
+
ACTIONS: () => ACTIONS,
|
|
35
|
+
INITIAL_STATE: () => INITIAL_STATE,
|
|
36
|
+
PortalHost: () => PortalHost,
|
|
37
|
+
PortalItem: () => PortalItem,
|
|
38
|
+
PortalProvider: () => PortalProvider,
|
|
39
|
+
usePortal: () => usePortal
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(GorhomPortal_exports);
|
|
42
|
+
var import_constants = require("@tamagui/constants"),
|
|
43
|
+
import_core = require("@tamagui/core"),
|
|
44
|
+
import_react = __toESM(require("react")),
|
|
45
|
+
import_start_transition = require("@tamagui/start-transition"),
|
|
46
|
+
import_jsx_runtime = require("react/jsx-runtime"),
|
|
47
|
+
ACTIONS = /* @__PURE__ */(ACTIONS2 => (ACTIONS2[ACTIONS2.REGISTER_HOST = 0] = "REGISTER_HOST", ACTIONS2[ACTIONS2.DEREGISTER_HOST = 1] = "DEREGISTER_HOST", ACTIONS2[ACTIONS2.ADD_UPDATE_PORTAL = 2] = "ADD_UPDATE_PORTAL", ACTIONS2[ACTIONS2.REMOVE_PORTAL = 3] = "REMOVE_PORTAL", ACTIONS2))(ACTIONS || {});
|
|
48
|
+
const INITIAL_STATE = {};
|
|
49
|
+
const registerHost = (state, hostName) => (hostName in state || (state[hostName] = []), state),
|
|
50
|
+
deregisterHost = (state, hostName) => (delete state[hostName], state),
|
|
51
|
+
addUpdatePortal = (state, hostName, portalName, node) => {
|
|
52
|
+
hostName in state || (state = registerHost(state, hostName));
|
|
53
|
+
const index = state[hostName].findIndex(item => item.name === portalName);
|
|
54
|
+
return index !== -1 ? state[hostName][index].node = node : state[hostName].push({
|
|
55
|
+
name: portalName,
|
|
56
|
+
node
|
|
57
|
+
}), state;
|
|
58
|
+
},
|
|
59
|
+
removePortal = (state, hostName, portalName) => {
|
|
60
|
+
if (!(hostName in state)) return console.info(`Failed to remove portal '${portalName}', '${hostName}' was not registered!`), state;
|
|
61
|
+
const index = state[hostName].findIndex(item => item.name === portalName);
|
|
62
|
+
return index !== -1 && state[hostName].splice(index, 1), state;
|
|
63
|
+
},
|
|
64
|
+
reducer = (state, action) => {
|
|
65
|
+
const {
|
|
66
|
+
type
|
|
67
|
+
} = action;
|
|
68
|
+
switch (type) {
|
|
69
|
+
case 0 /* REGISTER_HOST */:
|
|
70
|
+
return registerHost({
|
|
71
|
+
...state
|
|
72
|
+
}, action.hostName);
|
|
73
|
+
case 1 /* DEREGISTER_HOST */:
|
|
74
|
+
return deregisterHost({
|
|
75
|
+
...state
|
|
76
|
+
}, action.hostName);
|
|
77
|
+
case 2 /* ADD_UPDATE_PORTAL */:
|
|
78
|
+
return addUpdatePortal({
|
|
79
|
+
...state
|
|
80
|
+
}, action.hostName, action.portalName, action.node);
|
|
81
|
+
case 3 /* REMOVE_PORTAL */:
|
|
82
|
+
return removePortal({
|
|
83
|
+
...state
|
|
84
|
+
}, action.hostName, action.portalName);
|
|
85
|
+
default:
|
|
86
|
+
return state;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
PortalStateContext = (0, import_react.createContext)(null),
|
|
90
|
+
PortalDispatchContext = (0, import_react.createContext)(null),
|
|
91
|
+
usePortalState = hostName => {
|
|
92
|
+
const state = (0, import_react.useContext)(PortalStateContext);
|
|
93
|
+
if (state === null) throw new Error("'PortalStateContext' cannot be null, please add 'PortalProvider' to the root component.");
|
|
94
|
+
return state[hostName] || [];
|
|
95
|
+
},
|
|
96
|
+
usePortal = (hostName = "root") => {
|
|
97
|
+
const dispatch = (0, import_react.useContext)(PortalDispatchContext);
|
|
98
|
+
if (dispatch === null) throw new Error("'PortalDispatchContext' cannot be null, please add 'PortalProvider' to the root component.");
|
|
99
|
+
const registerHost2 = (0, import_react.useCallback)(() => {
|
|
100
|
+
dispatch({
|
|
101
|
+
type: 0 /* REGISTER_HOST */,
|
|
102
|
+
hostName
|
|
103
|
+
});
|
|
104
|
+
}, []),
|
|
105
|
+
deregisterHost2 = (0, import_react.useCallback)(() => {
|
|
106
|
+
dispatch({
|
|
107
|
+
type: 1 /* DEREGISTER_HOST */,
|
|
108
|
+
hostName
|
|
109
|
+
});
|
|
110
|
+
}, []),
|
|
111
|
+
addUpdatePortal2 = (0, import_react.useCallback)((name, node) => {
|
|
112
|
+
dispatch({
|
|
113
|
+
type: 2 /* ADD_UPDATE_PORTAL */,
|
|
114
|
+
hostName,
|
|
115
|
+
portalName: name,
|
|
116
|
+
node
|
|
117
|
+
});
|
|
118
|
+
}, []),
|
|
119
|
+
removePortal2 = (0, import_react.useCallback)(name => {
|
|
120
|
+
dispatch({
|
|
121
|
+
type: 3 /* REMOVE_PORTAL */,
|
|
122
|
+
hostName,
|
|
123
|
+
portalName: name
|
|
124
|
+
});
|
|
125
|
+
}, []);
|
|
126
|
+
return {
|
|
127
|
+
registerHost: registerHost2,
|
|
128
|
+
deregisterHost: deregisterHost2,
|
|
129
|
+
addPortal: addUpdatePortal2,
|
|
130
|
+
updatePortal: addUpdatePortal2,
|
|
131
|
+
removePortal: removePortal2
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
PortalProviderComponent = ({
|
|
135
|
+
rootHostName = "root",
|
|
136
|
+
shouldAddRootHost = !0,
|
|
137
|
+
children
|
|
138
|
+
}) => {
|
|
139
|
+
const [state, dispatch] = (0, import_react.useReducer)(reducer, INITIAL_STATE),
|
|
140
|
+
transitionDispatch = (0, import_react.useMemo)(() => value => {
|
|
141
|
+
(0, import_start_transition.startTransition)(() => {
|
|
142
|
+
dispatch(value);
|
|
143
|
+
});
|
|
144
|
+
}, [dispatch]);
|
|
145
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PortalDispatchContext.Provider, {
|
|
146
|
+
value: transitionDispatch,
|
|
147
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(PortalStateContext.Provider, {
|
|
148
|
+
value: state,
|
|
149
|
+
children: [children, shouldAddRootHost && /* @__PURE__ */(0, import_jsx_runtime.jsx)(PortalHost, {
|
|
150
|
+
name: rootHostName
|
|
151
|
+
})]
|
|
152
|
+
})
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
PortalProvider = (0, import_react.memo)(PortalProviderComponent);
|
|
156
|
+
PortalProvider.displayName = "PortalProvider";
|
|
157
|
+
const defaultRenderer = children => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
158
|
+
children
|
|
159
|
+
}),
|
|
160
|
+
PortalHostComponent = props => {
|
|
161
|
+
const {
|
|
162
|
+
name,
|
|
163
|
+
forwardProps,
|
|
164
|
+
render = defaultRenderer
|
|
165
|
+
} = props,
|
|
166
|
+
state = usePortalState(name),
|
|
167
|
+
{
|
|
168
|
+
registerHost: registerHost2,
|
|
169
|
+
deregisterHost: deregisterHost2
|
|
170
|
+
} = usePortal(props.name);
|
|
171
|
+
return (0, import_react.useEffect)(() => {
|
|
172
|
+
if (!(typeof window > "u")) return registerHost2(), () => {
|
|
173
|
+
deregisterHost2();
|
|
174
|
+
};
|
|
175
|
+
}, []), render(forwardProps ? state.map(item => {
|
|
176
|
+
let next = item.node;
|
|
177
|
+
return forwardProps ? import_react.default.Children.map(next, child => import_react.default.isValidElement(child) ? import_react.default.cloneElement(child, {
|
|
178
|
+
key: child.key,
|
|
179
|
+
...forwardProps
|
|
180
|
+
}) : child) : next;
|
|
181
|
+
}) : state.map(item => item.node));
|
|
182
|
+
},
|
|
183
|
+
PortalHost = (0, import_react.memo)(PortalHostComponent);
|
|
184
|
+
PortalHost.displayName = "PortalHost";
|
|
185
|
+
const PortalComponent = props => {
|
|
186
|
+
const {
|
|
187
|
+
name: _providedName,
|
|
188
|
+
hostName,
|
|
189
|
+
handleOnMount: _providedHandleOnMount,
|
|
190
|
+
handleOnUnmount: _providedHandleOnUnmount,
|
|
191
|
+
handleOnUpdate: _providedHandleOnUpdate,
|
|
192
|
+
children
|
|
193
|
+
} = props,
|
|
194
|
+
{
|
|
195
|
+
addPortal: addUpdatePortal2,
|
|
196
|
+
removePortal: removePortal2
|
|
197
|
+
} = usePortal(hostName),
|
|
198
|
+
id = (0, import_react.useId)(),
|
|
199
|
+
name = _providedName || id,
|
|
200
|
+
handleOnMount = (0, import_core.useEvent)(() => {
|
|
201
|
+
_providedHandleOnMount ? _providedHandleOnMount(() => addUpdatePortal2(name, children)) : addUpdatePortal2(name, children);
|
|
202
|
+
}),
|
|
203
|
+
handleOnUnmount = (0, import_core.useEvent)(() => {
|
|
204
|
+
_providedHandleOnUnmount ? _providedHandleOnUnmount(() => removePortal2(name)) : removePortal2(name);
|
|
205
|
+
}),
|
|
206
|
+
handleOnUpdate = (0, import_core.useEvent)(() => {
|
|
207
|
+
_providedHandleOnUpdate ? _providedHandleOnUpdate(() => addUpdatePortal2(name, children)) : addUpdatePortal2(name, children);
|
|
208
|
+
});
|
|
209
|
+
return (0, import_constants.useIsomorphicLayoutEffect)(() => (handleOnMount(), () => {
|
|
210
|
+
handleOnUnmount();
|
|
211
|
+
}), []), (0, import_react.useEffect)(() => {
|
|
212
|
+
handleOnUpdate();
|
|
213
|
+
}, [children]), null;
|
|
214
|
+
},
|
|
215
|
+
PortalItem = (0, import_react.memo)(PortalComponent);
|
|
216
|
+
PortalItem.displayName = "Portal";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var Portal_exports = {};
|
|
33
|
+
__export(Portal_exports, {
|
|
34
|
+
Portal: () => Portal
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(Portal_exports);
|
|
37
|
+
var import_polyfill_dev = require("@tamagui/polyfill-dev"),
|
|
38
|
+
import_constants = require("@tamagui/constants"),
|
|
39
|
+
import_stacks = require("@tamagui/stacks"),
|
|
40
|
+
React = __toESM(require("react")),
|
|
41
|
+
import_react_dom = require("react-dom"),
|
|
42
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
43
|
+
const Portal = React.memo(({
|
|
44
|
+
host = globalThis.document?.body,
|
|
45
|
+
...props
|
|
46
|
+
}) => import_constants.isServer ? null : (0, import_react_dom.createPortal)(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.YStack, {
|
|
47
|
+
contain: "strict",
|
|
48
|
+
fullscreen: !0,
|
|
49
|
+
position: "fixed",
|
|
50
|
+
maxWidth: "100vw",
|
|
51
|
+
maxHeight: "100vh",
|
|
52
|
+
pointerEvents: "none",
|
|
53
|
+
...props
|
|
54
|
+
}), host));
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var Portal_native_exports = {};
|
|
33
|
+
__export(Portal_native_exports, {
|
|
34
|
+
Portal: () => Portal
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(Portal_native_exports);
|
|
37
|
+
var import_stacks = require("@tamagui/stacks"),
|
|
38
|
+
React = __toESM(require("react")),
|
|
39
|
+
import_react_native = require("react-native-web"),
|
|
40
|
+
import_GorhomPortal = require("./GorhomPortal.cjs"),
|
|
41
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
const isFabric = global?.nativeFabricUIManager;
|
|
43
|
+
let createPortal;
|
|
44
|
+
isFabric ? createPortal = require("react-native/Libraries/Renderer/shims/ReactFabric").createPortal : createPortal = require("react-native/Libraries/Renderer/shims/ReactNative").createPortal;
|
|
45
|
+
const Portal = props => {
|
|
46
|
+
const rootTag = React.useContext(import_react_native.RootTagContext),
|
|
47
|
+
contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.YStack, {
|
|
48
|
+
pointerEvents: "box-none",
|
|
49
|
+
fullscreen: !0,
|
|
50
|
+
position: "absolute",
|
|
51
|
+
maxWidth: "100%",
|
|
52
|
+
zIndex: 1e5,
|
|
53
|
+
...props
|
|
54
|
+
});
|
|
55
|
+
return process.env.TAMAGUI_USE_NATIVE_PORTAL === "false" || import_react_native.Platform.OS === "android" || !rootTag ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_GorhomPortal.PortalItem, {
|
|
56
|
+
hostName: "root",
|
|
57
|
+
children: contents
|
|
58
|
+
}) : createPortal(contents, rootTag);
|
|
59
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Portal.native.tsx"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB,4BACvB,QAAuB,2BAEvB,sBAAyC,yBAEzC,sBAA2B,2BAevB;AAZJ,MAAM,WAAW,QAAQ;AACzB,IAAI;AACA,WACF,eAAe,QAAQ,mDAAmD,EAAE,eAE5E,eAAe,QAAQ,mDAAmD,EAAE;AAGvE,MAAM,SAAS,CAAC,UAAuB;AAC5C,QAAM,UAAU,MAAM,WAAW,kCAAc,GAEzC,WACJ;AAAA,IAAC;AAAA;AAAA,MACC,eAAc;AAAA,MACd,YAAU;AAAA,MACV,UAAS;AAAA,MACT,UAAS;AAAA,MACT,QAAQ;AAAA,MACP,GAAG;AAAA;AAAA,EACN;AAGF,SACE,QAAQ,IAAI,8BAA8B,WAC1C,6BAAS,OAAO,aAChB,CAAC,UAEM,4CAAC,kCAAW,UAAS,QAAQ,oBAAS,IAGxC,aAAa,UAAU,OAAO;AACvC;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
};
|
|
12
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
13
|
+
value: !0
|
|
14
|
+
}), mod);
|
|
15
|
+
var PortalProps_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(PortalProps_exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./Portal.cjs"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./PortalProps.cjs"), module.exports);
|
|
20
|
+
__reExport(src_exports, require("./GorhomPortal.cjs"), module.exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/portal",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.115.0",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -25,22 +25,23 @@
|
|
|
25
25
|
"react-native": "./dist/cjs/index.native.js",
|
|
26
26
|
"types": "./types/index.d.ts",
|
|
27
27
|
"import": "./dist/esm/index.mjs",
|
|
28
|
-
"require": "./dist/cjs/index.
|
|
28
|
+
"require": "./dist/cjs/index.cjs",
|
|
29
|
+
"default": "./dist/cjs/index.native.js"
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"@tamagui/constants": "1.
|
|
33
|
-
"@tamagui/core": "1.
|
|
34
|
-
"@tamagui/stacks": "1.
|
|
35
|
-
"@tamagui/start-transition": "1.
|
|
36
|
-
"@tamagui/use-did-finish-ssr": "1.
|
|
37
|
-
"@tamagui/use-event": "1.
|
|
33
|
+
"@tamagui/constants": "1.115.0",
|
|
34
|
+
"@tamagui/core": "1.115.0",
|
|
35
|
+
"@tamagui/stacks": "1.115.0",
|
|
36
|
+
"@tamagui/start-transition": "1.115.0",
|
|
37
|
+
"@tamagui/use-did-finish-ssr": "1.115.0",
|
|
38
|
+
"@tamagui/use-event": "1.115.0"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"react": "*"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@tamagui/build": "1.
|
|
44
|
+
"@tamagui/build": "1.115.0",
|
|
44
45
|
"react": "^18.2.0 || ^19.0.0",
|
|
45
46
|
"react-native": "0.74.1"
|
|
46
47
|
},
|
package/dist/cjs/GorhomPortal.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
var GorhomPortal_exports = {};
|
|
24
|
-
__export(GorhomPortal_exports, {
|
|
25
|
-
ACTIONS: () => ACTIONS,
|
|
26
|
-
INITIAL_STATE: () => INITIAL_STATE,
|
|
27
|
-
PortalHost: () => PortalHost,
|
|
28
|
-
PortalItem: () => PortalItem,
|
|
29
|
-
PortalProvider: () => PortalProvider,
|
|
30
|
-
usePortal: () => usePortal
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(GorhomPortal_exports);
|
|
33
|
-
var import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_react = __toESM(require("react")), import_start_transition = require("@tamagui/start-transition"), import_jsx_runtime = require("react/jsx-runtime"), ACTIONS = /* @__PURE__ */ ((ACTIONS2) => (ACTIONS2[ACTIONS2.REGISTER_HOST = 0] = "REGISTER_HOST", ACTIONS2[ACTIONS2.DEREGISTER_HOST = 1] = "DEREGISTER_HOST", ACTIONS2[ACTIONS2.ADD_UPDATE_PORTAL = 2] = "ADD_UPDATE_PORTAL", ACTIONS2[ACTIONS2.REMOVE_PORTAL = 3] = "REMOVE_PORTAL", ACTIONS2))(ACTIONS || {});
|
|
34
|
-
const INITIAL_STATE = {};
|
|
35
|
-
const registerHost = (state, hostName) => (hostName in state || (state[hostName] = []), state), deregisterHost = (state, hostName) => (delete state[hostName], state), addUpdatePortal = (state, hostName, portalName, node) => {
|
|
36
|
-
hostName in state || (state = registerHost(state, hostName));
|
|
37
|
-
const index = state[hostName].findIndex((item) => item.name === portalName);
|
|
38
|
-
return index !== -1 ? state[hostName][index].node = node : state[hostName].push({
|
|
39
|
-
name: portalName,
|
|
40
|
-
node
|
|
41
|
-
}), state;
|
|
42
|
-
}, removePortal = (state, hostName, portalName) => {
|
|
43
|
-
if (!(hostName in state))
|
|
44
|
-
return console.info(
|
|
45
|
-
`Failed to remove portal '${portalName}', '${hostName}' was not registered!`
|
|
46
|
-
), state;
|
|
47
|
-
const index = state[hostName].findIndex((item) => item.name === portalName);
|
|
48
|
-
return index !== -1 && state[hostName].splice(index, 1), state;
|
|
49
|
-
}, reducer = (state, action) => {
|
|
50
|
-
const { type } = action;
|
|
51
|
-
switch (type) {
|
|
52
|
-
case 0 /* REGISTER_HOST */:
|
|
53
|
-
return registerHost({ ...state }, action.hostName);
|
|
54
|
-
case 1 /* DEREGISTER_HOST */:
|
|
55
|
-
return deregisterHost({ ...state }, action.hostName);
|
|
56
|
-
case 2 /* ADD_UPDATE_PORTAL */:
|
|
57
|
-
return addUpdatePortal(
|
|
58
|
-
{ ...state },
|
|
59
|
-
action.hostName,
|
|
60
|
-
action.portalName,
|
|
61
|
-
action.node
|
|
62
|
-
);
|
|
63
|
-
case 3 /* REMOVE_PORTAL */:
|
|
64
|
-
return removePortal(
|
|
65
|
-
{ ...state },
|
|
66
|
-
action.hostName,
|
|
67
|
-
action.portalName
|
|
68
|
-
);
|
|
69
|
-
default:
|
|
70
|
-
return state;
|
|
71
|
-
}
|
|
72
|
-
}, PortalStateContext = (0, import_react.createContext)(null), PortalDispatchContext = (0, import_react.createContext)(null), usePortalState = (hostName) => {
|
|
73
|
-
const state = (0, import_react.useContext)(PortalStateContext);
|
|
74
|
-
if (state === null)
|
|
75
|
-
throw new Error(
|
|
76
|
-
"'PortalStateContext' cannot be null, please add 'PortalProvider' to the root component."
|
|
77
|
-
);
|
|
78
|
-
return state[hostName] || [];
|
|
79
|
-
}, usePortal = (hostName = "root") => {
|
|
80
|
-
const dispatch = (0, import_react.useContext)(PortalDispatchContext);
|
|
81
|
-
if (dispatch === null)
|
|
82
|
-
throw new Error(
|
|
83
|
-
"'PortalDispatchContext' cannot be null, please add 'PortalProvider' to the root component."
|
|
84
|
-
);
|
|
85
|
-
const registerHost2 = (0, import_react.useCallback)(() => {
|
|
86
|
-
dispatch({
|
|
87
|
-
type: 0 /* REGISTER_HOST */,
|
|
88
|
-
hostName
|
|
89
|
-
});
|
|
90
|
-
}, []), deregisterHost2 = (0, import_react.useCallback)(() => {
|
|
91
|
-
dispatch({
|
|
92
|
-
type: 1 /* DEREGISTER_HOST */,
|
|
93
|
-
hostName
|
|
94
|
-
});
|
|
95
|
-
}, []), addUpdatePortal2 = (0, import_react.useCallback)((name, node) => {
|
|
96
|
-
dispatch({
|
|
97
|
-
type: 2 /* ADD_UPDATE_PORTAL */,
|
|
98
|
-
hostName,
|
|
99
|
-
portalName: name,
|
|
100
|
-
node
|
|
101
|
-
});
|
|
102
|
-
}, []), removePortal2 = (0, import_react.useCallback)((name) => {
|
|
103
|
-
dispatch({
|
|
104
|
-
type: 3 /* REMOVE_PORTAL */,
|
|
105
|
-
hostName,
|
|
106
|
-
portalName: name
|
|
107
|
-
});
|
|
108
|
-
}, []);
|
|
109
|
-
return {
|
|
110
|
-
registerHost: registerHost2,
|
|
111
|
-
deregisterHost: deregisterHost2,
|
|
112
|
-
addPortal: addUpdatePortal2,
|
|
113
|
-
updatePortal: addUpdatePortal2,
|
|
114
|
-
removePortal: removePortal2
|
|
115
|
-
};
|
|
116
|
-
}, PortalProviderComponent = ({
|
|
117
|
-
rootHostName = "root",
|
|
118
|
-
shouldAddRootHost = !0,
|
|
119
|
-
children
|
|
120
|
-
}) => {
|
|
121
|
-
const [state, dispatch] = (0, import_react.useReducer)(reducer, INITIAL_STATE), transitionDispatch = (0, import_react.useMemo)(() => (value) => {
|
|
122
|
-
(0, import_start_transition.startTransition)(() => {
|
|
123
|
-
dispatch(value);
|
|
124
|
-
});
|
|
125
|
-
}, [dispatch]);
|
|
126
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalDispatchContext.Provider, { value: transitionDispatch, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PortalStateContext.Provider, { value: state, children: [
|
|
127
|
-
children,
|
|
128
|
-
shouldAddRootHost && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalHost, { name: rootHostName })
|
|
129
|
-
] }) });
|
|
130
|
-
}, PortalProvider = (0, import_react.memo)(PortalProviderComponent);
|
|
131
|
-
PortalProvider.displayName = "PortalProvider";
|
|
132
|
-
const defaultRenderer = (children) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children }), PortalHostComponent = (props) => {
|
|
133
|
-
const { name, forwardProps, render = defaultRenderer } = props, state = usePortalState(name), { registerHost: registerHost2, deregisterHost: deregisterHost2 } = usePortal(props.name);
|
|
134
|
-
return (0, import_react.useEffect)(() => {
|
|
135
|
-
if (!(typeof window > "u"))
|
|
136
|
-
return registerHost2(), () => {
|
|
137
|
-
deregisterHost2();
|
|
138
|
-
};
|
|
139
|
-
}, []), render(
|
|
140
|
-
forwardProps ? state.map((item) => {
|
|
141
|
-
let next = item.node;
|
|
142
|
-
return forwardProps ? import_react.default.Children.map(next, (child) => import_react.default.isValidElement(child) ? import_react.default.cloneElement(child, { key: child.key, ...forwardProps }) : child) : next;
|
|
143
|
-
}) : state.map((item) => item.node)
|
|
144
|
-
);
|
|
145
|
-
}, PortalHost = (0, import_react.memo)(PortalHostComponent);
|
|
146
|
-
PortalHost.displayName = "PortalHost";
|
|
147
|
-
const PortalComponent = (props) => {
|
|
148
|
-
const {
|
|
149
|
-
name: _providedName,
|
|
150
|
-
hostName,
|
|
151
|
-
handleOnMount: _providedHandleOnMount,
|
|
152
|
-
handleOnUnmount: _providedHandleOnUnmount,
|
|
153
|
-
handleOnUpdate: _providedHandleOnUpdate,
|
|
154
|
-
children
|
|
155
|
-
} = props, { addPortal: addUpdatePortal2, removePortal: removePortal2 } = usePortal(hostName), id = (0, import_react.useId)(), name = _providedName || id, handleOnMount = (0, import_core.useEvent)(() => {
|
|
156
|
-
_providedHandleOnMount ? _providedHandleOnMount(() => addUpdatePortal2(name, children)) : addUpdatePortal2(name, children);
|
|
157
|
-
}), handleOnUnmount = (0, import_core.useEvent)(() => {
|
|
158
|
-
_providedHandleOnUnmount ? _providedHandleOnUnmount(() => removePortal2(name)) : removePortal2(name);
|
|
159
|
-
}), handleOnUpdate = (0, import_core.useEvent)(() => {
|
|
160
|
-
_providedHandleOnUpdate ? _providedHandleOnUpdate(() => addUpdatePortal2(name, children)) : addUpdatePortal2(name, children);
|
|
161
|
-
});
|
|
162
|
-
return (0, import_constants.useIsomorphicLayoutEffect)(() => (handleOnMount(), () => {
|
|
163
|
-
handleOnUnmount();
|
|
164
|
-
}), []), (0, import_react.useEffect)(() => {
|
|
165
|
-
handleOnUpdate();
|
|
166
|
-
}, [children]), null;
|
|
167
|
-
}, PortalItem = (0, import_react.memo)(PortalComponent);
|
|
168
|
-
PortalItem.displayName = "Portal";
|
|
169
|
-
//# sourceMappingURL=GorhomPortal.js.map
|
package/dist/cjs/Portal.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
var Portal_exports = {};
|
|
24
|
-
__export(Portal_exports, {
|
|
25
|
-
Portal: () => Portal
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(Portal_exports);
|
|
28
|
-
var import_polyfill_dev = require("@tamagui/polyfill-dev"), import_constants = require("@tamagui/constants"), import_stacks = require("@tamagui/stacks"), React = __toESM(require("react")), import_react_dom = require("react-dom"), import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
-
const Portal = React.memo(
|
|
30
|
-
({ host = globalThis.document?.body, ...props }) => import_constants.isServer ? null : (0, import_react_dom.createPortal)(
|
|
31
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
32
|
-
import_stacks.YStack,
|
|
33
|
-
{
|
|
34
|
-
contain: "strict",
|
|
35
|
-
fullscreen: !0,
|
|
36
|
-
position: "fixed",
|
|
37
|
-
maxWidth: "100vw",
|
|
38
|
-
maxHeight: "100vh",
|
|
39
|
-
pointerEvents: "none",
|
|
40
|
-
...props
|
|
41
|
-
}
|
|
42
|
-
),
|
|
43
|
-
host
|
|
44
|
-
)
|
|
45
|
-
);
|
|
46
|
-
//# sourceMappingURL=Portal.js.map
|
package/dist/cjs/PortalProps.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
};
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var PortalProps_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(PortalProps_exports);
|
|
14
|
-
//# sourceMappingURL=PortalProps.js.map
|
package/dist/cjs/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var src_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(src_exports);
|
|
14
|
-
__reExport(src_exports, require("./Portal"), module.exports);
|
|
15
|
-
__reExport(src_exports, require("./PortalProps"), module.exports);
|
|
16
|
-
__reExport(src_exports, require("./GorhomPortal"), module.exports);
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|