@tamagui/portal 1.0.1-beta.20 → 1.0.1-beta.200
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.js +266 -0
- package/dist/cjs/GorhomPortal.js.map +7 -0
- package/dist/cjs/Portal.js +19 -31
- package/dist/cjs/Portal.js.map +2 -2
- package/dist/cjs/Portal.native.js +59 -0
- package/dist/cjs/Portal.native.js.map +7 -0
- package/dist/cjs/PortalProps.js +17 -0
- package/dist/cjs/PortalProps.js.map +7 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/GorhomPortal.js +237 -0
- package/dist/esm/GorhomPortal.js.map +7 -0
- package/dist/esm/Portal.js +11 -15
- package/dist/esm/Portal.js.map +2 -2
- package/dist/esm/Portal.native.js +29 -0
- package/dist/esm/Portal.native.js.map +7 -0
- package/dist/esm/PortalProps.js +1 -0
- package/dist/esm/PortalProps.js.map +7 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/jsx/GorhomPortal.js +223 -0
- package/dist/jsx/GorhomPortal.js.map +7 -0
- package/dist/jsx/Portal.js +6 -12
- package/dist/jsx/Portal.js.map +7 -0
- package/dist/jsx/Portal.native.js +21 -0
- package/dist/jsx/Portal.native.js.map +7 -0
- package/dist/jsx/PortalProps.js +1 -0
- package/dist/jsx/PortalProps.js.map +7 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +7 -0
- package/package.json +9 -7
- package/src/GorhomPortal.tsx +401 -0
- package/src/Portal.native.tsx +35 -0
- package/src/Portal.tsx +37 -0
- package/src/PortalProps.tsx +6 -0
- package/src/index.tsx +2 -0
- package/types/GorhomPortal.d.ts +106 -0
- package/types/Portal.d.ts +3 -3
- package/types/Portal.native.d.ts +3 -0
- package/types/PortalProps.d.ts +6 -0
- package/types/index.d.ts +1 -0
- package/types/Portal.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var GorhomPortal_exports = {};
|
|
20
|
+
__export(GorhomPortal_exports, {
|
|
21
|
+
ACTIONS: () => ACTIONS,
|
|
22
|
+
INITIAL_STATE: () => INITIAL_STATE,
|
|
23
|
+
PortalHost: () => PortalHost,
|
|
24
|
+
PortalItem: () => PortalItem,
|
|
25
|
+
PortalProvider: () => PortalProvider,
|
|
26
|
+
usePortal: () => usePortal
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(GorhomPortal_exports);
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
var import_core = require("@tamagui/core");
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
var import_react2 = require("react");
|
|
33
|
+
var ACTIONS = /* @__PURE__ */ ((ACTIONS2) => {
|
|
34
|
+
ACTIONS2[ACTIONS2["REGISTER_HOST"] = 0] = "REGISTER_HOST";
|
|
35
|
+
ACTIONS2[ACTIONS2["DEREGISTER_HOST"] = 1] = "DEREGISTER_HOST";
|
|
36
|
+
ACTIONS2[ACTIONS2["ADD_UPDATE_PORTAL"] = 2] = "ADD_UPDATE_PORTAL";
|
|
37
|
+
ACTIONS2[ACTIONS2["REMOVE_PORTAL"] = 3] = "REMOVE_PORTAL";
|
|
38
|
+
return ACTIONS2;
|
|
39
|
+
})(ACTIONS || {});
|
|
40
|
+
const INITIAL_STATE = {};
|
|
41
|
+
const registerHost = (state, hostName) => {
|
|
42
|
+
if (!(hostName in state)) {
|
|
43
|
+
state[hostName] = [];
|
|
44
|
+
}
|
|
45
|
+
return state;
|
|
46
|
+
};
|
|
47
|
+
const deregisterHost = (state, hostName) => {
|
|
48
|
+
delete state[hostName];
|
|
49
|
+
return state;
|
|
50
|
+
};
|
|
51
|
+
const addUpdatePortal = (state, hostName, portalName, node) => {
|
|
52
|
+
if (!(hostName in state)) {
|
|
53
|
+
state = registerHost(state, hostName);
|
|
54
|
+
}
|
|
55
|
+
const index = state[hostName].findIndex((item) => item.name === portalName);
|
|
56
|
+
if (index !== -1) {
|
|
57
|
+
state[hostName][index].node = node;
|
|
58
|
+
} else {
|
|
59
|
+
state[hostName].push({
|
|
60
|
+
name: portalName,
|
|
61
|
+
node
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return state;
|
|
65
|
+
};
|
|
66
|
+
const removePortal = (state, hostName, portalName) => {
|
|
67
|
+
if (!(hostName in state)) {
|
|
68
|
+
console.log(`Failed to remove portal '${portalName}', '${hostName}' was not registered!`);
|
|
69
|
+
return state;
|
|
70
|
+
}
|
|
71
|
+
const index = state[hostName].findIndex((item) => item.name === portalName);
|
|
72
|
+
if (index !== -1)
|
|
73
|
+
state[hostName].splice(index, 1);
|
|
74
|
+
return state;
|
|
75
|
+
};
|
|
76
|
+
const reducer = (state, action) => {
|
|
77
|
+
const { type } = action;
|
|
78
|
+
switch (type) {
|
|
79
|
+
case 0 /* REGISTER_HOST */:
|
|
80
|
+
return registerHost({ ...state }, action.hostName);
|
|
81
|
+
case 1 /* DEREGISTER_HOST */:
|
|
82
|
+
return deregisterHost({ ...state }, action.hostName);
|
|
83
|
+
case 2 /* ADD_UPDATE_PORTAL */:
|
|
84
|
+
return addUpdatePortal(
|
|
85
|
+
{ ...state },
|
|
86
|
+
action.hostName,
|
|
87
|
+
action.portalName,
|
|
88
|
+
action.node
|
|
89
|
+
);
|
|
90
|
+
case 3 /* REMOVE_PORTAL */:
|
|
91
|
+
return removePortal({ ...state }, action.hostName, action.portalName);
|
|
92
|
+
default:
|
|
93
|
+
return state;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const PortalStateContext = (0, import_react2.createContext)(null);
|
|
97
|
+
const PortalDispatchContext = (0, import_react2.createContext)(null);
|
|
98
|
+
const usePortalState = (hostName) => {
|
|
99
|
+
const state = (0, import_react2.useContext)(PortalStateContext);
|
|
100
|
+
if (state === null) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
"'PortalStateContext' cannot be null, please add 'PortalProvider' to the root component."
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
return state[hostName] || [];
|
|
106
|
+
};
|
|
107
|
+
const usePortal = (hostName = "root") => {
|
|
108
|
+
const dispatch = (0, import_react2.useContext)(PortalDispatchContext);
|
|
109
|
+
if (dispatch === null) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
"'PortalDispatchContext' cannot be null, please add 'PortalProvider' to the root component."
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
const registerHost2 = (0, import_react2.useCallback)(() => {
|
|
115
|
+
dispatch({
|
|
116
|
+
type: 0 /* REGISTER_HOST */,
|
|
117
|
+
hostName
|
|
118
|
+
});
|
|
119
|
+
}, []);
|
|
120
|
+
const deregisterHost2 = (0, import_react2.useCallback)(() => {
|
|
121
|
+
dispatch({
|
|
122
|
+
type: 1 /* DEREGISTER_HOST */,
|
|
123
|
+
hostName
|
|
124
|
+
});
|
|
125
|
+
}, []);
|
|
126
|
+
const addUpdatePortal2 = (0, import_react2.useCallback)((name, node) => {
|
|
127
|
+
dispatch({
|
|
128
|
+
type: 2 /* ADD_UPDATE_PORTAL */,
|
|
129
|
+
hostName,
|
|
130
|
+
portalName: name,
|
|
131
|
+
node
|
|
132
|
+
});
|
|
133
|
+
}, []);
|
|
134
|
+
const removePortal2 = (0, import_react2.useCallback)((name) => {
|
|
135
|
+
dispatch({
|
|
136
|
+
type: 3 /* REMOVE_PORTAL */,
|
|
137
|
+
hostName,
|
|
138
|
+
portalName: name
|
|
139
|
+
});
|
|
140
|
+
}, []);
|
|
141
|
+
return {
|
|
142
|
+
registerHost: registerHost2,
|
|
143
|
+
deregisterHost: deregisterHost2,
|
|
144
|
+
addPortal: addUpdatePortal2,
|
|
145
|
+
updatePortal: addUpdatePortal2,
|
|
146
|
+
removePortal: removePortal2
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
const PortalProviderComponent = ({
|
|
150
|
+
rootHostName = "root",
|
|
151
|
+
shouldAddRootHost = true,
|
|
152
|
+
children
|
|
153
|
+
}) => {
|
|
154
|
+
const [state, dispatch] = (0, import_react2.useReducer)(reducer, INITIAL_STATE);
|
|
155
|
+
const transitionDispatch = (0, import_react.useMemo)(() => {
|
|
156
|
+
const next = (value) => {
|
|
157
|
+
(0, import_react.startTransition)(() => {
|
|
158
|
+
dispatch(value);
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
return next;
|
|
162
|
+
}, [dispatch]);
|
|
163
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalDispatchContext.Provider, {
|
|
164
|
+
value: transitionDispatch,
|
|
165
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PortalStateContext.Provider, {
|
|
166
|
+
value: state,
|
|
167
|
+
children: [
|
|
168
|
+
children,
|
|
169
|
+
shouldAddRootHost && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalHost, {
|
|
170
|
+
name: rootHostName
|
|
171
|
+
})
|
|
172
|
+
]
|
|
173
|
+
})
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
const PortalProvider = (0, import_react2.memo)(PortalProviderComponent);
|
|
177
|
+
PortalProvider.displayName = "PortalProvider";
|
|
178
|
+
const PortalHostComponent = ({ name }) => {
|
|
179
|
+
const isServer = !(0, import_core.useDidFinishSSR)();
|
|
180
|
+
const state = usePortalState(name);
|
|
181
|
+
const { registerHost: registerHost2, deregisterHost: deregisterHost2 } = usePortal(name);
|
|
182
|
+
(0, import_react2.useEffect)(() => {
|
|
183
|
+
if (isServer)
|
|
184
|
+
return;
|
|
185
|
+
registerHost2();
|
|
186
|
+
return () => {
|
|
187
|
+
deregisterHost2();
|
|
188
|
+
};
|
|
189
|
+
}, [isServer]);
|
|
190
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
191
|
+
children: state.map((item) => item.node)
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
const PortalHost = (0, import_react2.memo)(PortalHostComponent);
|
|
195
|
+
PortalHost.displayName = "PortalHost";
|
|
196
|
+
const PortalComponent = ({
|
|
197
|
+
name: _providedName,
|
|
198
|
+
hostName,
|
|
199
|
+
handleOnMount: _providedHandleOnMount,
|
|
200
|
+
handleOnUnmount: _providedHandleOnUnmount,
|
|
201
|
+
handleOnUpdate: _providedHandleOnUpdate,
|
|
202
|
+
children
|
|
203
|
+
}) => {
|
|
204
|
+
const { addPortal: addUpdatePortal2, removePortal: removePortal2 } = usePortal(hostName);
|
|
205
|
+
let id = 0;
|
|
206
|
+
const nanoid = () => {
|
|
207
|
+
id = (id + 1) % Number.MAX_SAFE_INTEGER;
|
|
208
|
+
return `${id}`;
|
|
209
|
+
};
|
|
210
|
+
const name = (0, import_react.useMemo)(() => _providedName || nanoid(), [_providedName]);
|
|
211
|
+
const handleOnMountRef = (0, import_react.useRef)();
|
|
212
|
+
const handleOnUnmountRef = (0, import_react.useRef)();
|
|
213
|
+
const handleOnUpdateRef = (0, import_react.useRef)();
|
|
214
|
+
const handleOnMount = (0, import_react2.useCallback)(() => {
|
|
215
|
+
if (_providedHandleOnMount) {
|
|
216
|
+
_providedHandleOnMount(() => addUpdatePortal2(name, children));
|
|
217
|
+
} else {
|
|
218
|
+
addUpdatePortal2(name, children);
|
|
219
|
+
}
|
|
220
|
+
}, [_providedHandleOnMount, addUpdatePortal2]);
|
|
221
|
+
handleOnMountRef.current = handleOnMount;
|
|
222
|
+
const handleOnUnmount = (0, import_react2.useCallback)(() => {
|
|
223
|
+
if (_providedHandleOnUnmount) {
|
|
224
|
+
_providedHandleOnUnmount(() => removePortal2(name));
|
|
225
|
+
} else {
|
|
226
|
+
removePortal2(name);
|
|
227
|
+
}
|
|
228
|
+
}, [_providedHandleOnUnmount, removePortal2]);
|
|
229
|
+
handleOnUnmountRef.current = handleOnUnmount;
|
|
230
|
+
const handleOnUpdate = (0, import_react2.useCallback)(() => {
|
|
231
|
+
if (_providedHandleOnUpdate) {
|
|
232
|
+
_providedHandleOnUpdate(() => addUpdatePortal2(name, children));
|
|
233
|
+
} else {
|
|
234
|
+
addUpdatePortal2(name, children);
|
|
235
|
+
}
|
|
236
|
+
}, [_providedHandleOnUpdate, addUpdatePortal2, children]);
|
|
237
|
+
handleOnUpdateRef.current = handleOnUpdate;
|
|
238
|
+
(0, import_react2.useEffect)(() => {
|
|
239
|
+
var _a;
|
|
240
|
+
(_a = handleOnMountRef.current) == null ? void 0 : _a.call(handleOnMountRef);
|
|
241
|
+
return () => {
|
|
242
|
+
var _a2;
|
|
243
|
+
(_a2 = handleOnUnmountRef.current) == null ? void 0 : _a2.call(handleOnUnmountRef);
|
|
244
|
+
handleOnMountRef.current = void 0;
|
|
245
|
+
handleOnUnmountRef.current = void 0;
|
|
246
|
+
handleOnUpdateRef.current = void 0;
|
|
247
|
+
};
|
|
248
|
+
}, []);
|
|
249
|
+
(0, import_react2.useEffect)(() => {
|
|
250
|
+
var _a;
|
|
251
|
+
(_a = handleOnUpdateRef.current) == null ? void 0 : _a.call(handleOnUpdateRef);
|
|
252
|
+
}, [children]);
|
|
253
|
+
return null;
|
|
254
|
+
};
|
|
255
|
+
const PortalItem = (0, import_react2.memo)(PortalComponent);
|
|
256
|
+
PortalItem.displayName = "Portal";
|
|
257
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
258
|
+
0 && (module.exports = {
|
|
259
|
+
ACTIONS,
|
|
260
|
+
INITIAL_STATE,
|
|
261
|
+
PortalHost,
|
|
262
|
+
PortalItem,
|
|
263
|
+
PortalProvider,
|
|
264
|
+
usePortal
|
|
265
|
+
});
|
|
266
|
+
//# sourceMappingURL=GorhomPortal.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/GorhomPortal.tsx"],
|
|
4
|
+
"sourcesContent": ["// from https://github.com/gorhom/react-native-portal\n// MIT License Copyright (c) 2020 Mo Gorhom\n// fixing SSR issue\n\nimport { useDidFinishSSR } from '@tamagui/core'\nimport { ReactNode, startTransition, useMemo, useRef } from 'react'\nimport React, { createContext, memo, useCallback, useContext, useEffect, useReducer } from 'react'\n\ninterface PortalType {\n name: string\n node: ReactNode\n}\n\nenum ACTIONS {\n REGISTER_HOST,\n DEREGISTER_HOST,\n ADD_UPDATE_PORTAL,\n REMOVE_PORTAL,\n}\n\nconst INITIAL_STATE = {}\n\nexport { ACTIONS, INITIAL_STATE }\n\nexport interface AddUpdatePortalAction {\n type: ACTIONS\n hostName: string\n portalName: string\n node: ReactNode\n}\n\nexport interface RemovePortalAction {\n type: ACTIONS\n hostName: string\n portalName: string\n}\n\nexport interface RegisterHostAction {\n type: ACTIONS\n hostName: string\n}\n\nexport interface UnregisterHostAction {\n type: ACTIONS\n hostName: string\n}\n\nexport type ActionTypes =\n | AddUpdatePortalAction\n | RemovePortalAction\n | RegisterHostAction\n | UnregisterHostAction\n\nconst registerHost = (state: Record<string, Array<PortalType>>, hostName: string) => {\n if (!(hostName in state)) {\n state[hostName] = []\n }\n return state\n}\n\nconst deregisterHost = (state: Record<string, Array<PortalType>>, hostName: string) => {\n delete state[hostName]\n return state\n}\n\nconst addUpdatePortal = (\n state: Record<string, Array<PortalType>>,\n hostName: string,\n portalName: string,\n node: any\n) => {\n if (!(hostName in state)) {\n state = registerHost(state, hostName)\n }\n\n /**\n * updated portal, if it was already added.\n */\n const index = state[hostName].findIndex((item) => item.name === portalName)\n if (index !== -1) {\n state[hostName][index].node = node\n } else {\n state[hostName].push({\n name: portalName,\n node,\n })\n }\n return state\n}\n\nconst removePortal = (\n state: Record<string, Array<PortalType>>,\n hostName: string,\n portalName: string\n) => {\n if (!(hostName in state)) {\n console.log(`Failed to remove portal '${portalName}', '${hostName}' was not registered!`)\n return state\n }\n\n const index = state[hostName].findIndex((item) => item.name === portalName)\n if (index !== -1) state[hostName].splice(index, 1)\n return state\n}\n\nconst reducer = (state: Record<string, Array<PortalType>>, action: ActionTypes) => {\n const { type } = action\n switch (type) {\n case ACTIONS.REGISTER_HOST:\n return registerHost({ ...state }, action.hostName)\n case ACTIONS.DEREGISTER_HOST:\n return deregisterHost({ ...state }, action.hostName)\n case ACTIONS.ADD_UPDATE_PORTAL:\n return addUpdatePortal(\n { ...state },\n action.hostName,\n (action as AddUpdatePortalAction).portalName,\n (action as AddUpdatePortalAction).node\n )\n case ACTIONS.REMOVE_PORTAL:\n return removePortal({ ...state }, action.hostName, (action as RemovePortalAction).portalName)\n default:\n return state\n }\n}\n\nconst PortalStateContext = createContext<Record<string, Array<PortalType>> | null>(null)\nconst PortalDispatchContext = createContext<React.Dispatch<ActionTypes> | null>(null)\n\nconst usePortalState = (hostName: string) => {\n const state = useContext(PortalStateContext)\n\n if (state === null) {\n throw new Error(\n \"'PortalStateContext' cannot be null, please add 'PortalProvider' to the root component.\"\n )\n }\n\n return state[hostName] || []\n}\n\nexport const usePortal = (hostName = 'root') => {\n const dispatch = useContext(PortalDispatchContext)\n\n if (dispatch === null) {\n throw new Error(\n \"'PortalDispatchContext' cannot be null, please add 'PortalProvider' to the root component.\"\n )\n }\n\n //#region methods\n const registerHost = useCallback(() => {\n dispatch({\n type: ACTIONS.REGISTER_HOST,\n hostName: hostName,\n })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const deregisterHost = useCallback(() => {\n dispatch({\n type: ACTIONS.DEREGISTER_HOST,\n hostName: hostName,\n })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const addUpdatePortal = useCallback((name: string, node: ReactNode) => {\n dispatch({\n type: ACTIONS.ADD_UPDATE_PORTAL,\n hostName,\n portalName: name,\n node,\n })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n const removePortal = useCallback((name: string) => {\n dispatch({\n type: ACTIONS.REMOVE_PORTAL,\n hostName,\n portalName: name,\n })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n //#endregion\n\n return {\n registerHost,\n deregisterHost,\n addPortal: addUpdatePortal,\n updatePortal: addUpdatePortal,\n removePortal,\n }\n}\n\nexport interface PortalProviderProps {\n /**\n * Defines whether to add a default root host or not.\n *\n * @default true\n * @type boolean\n */\n shouldAddRootHost?: boolean\n\n /**\n * Defines the root portal host name.\n *\n * @default \"root\"\n * @type string\n */\n rootHostName?: string\n\n children: ReactNode | ReactNode[]\n}\n\nconst PortalProviderComponent = ({\n rootHostName = 'root',\n shouldAddRootHost = true,\n children,\n}: PortalProviderProps) => {\n const [state, dispatch] = useReducer(reducer, INITIAL_STATE)\n const transitionDispatch = useMemo(() => {\n const next = (value: any) => {\n startTransition(() => {\n dispatch(value)\n })\n }\n return next as typeof dispatch\n }, [dispatch])\n return (\n <PortalDispatchContext.Provider value={transitionDispatch}>\n <PortalStateContext.Provider value={state}>\n {children}\n {shouldAddRootHost && <PortalHost name={rootHostName} />}\n </PortalStateContext.Provider>\n </PortalDispatchContext.Provider>\n )\n}\n\nexport const PortalProvider = memo(PortalProviderComponent)\nPortalProvider.displayName = 'PortalProvider'\n\nexport interface PortalHostProps {\n /**\n * Host's key or name to be used as an identifier.\n * @type string\n */\n name: string\n}\n\nconst PortalHostComponent = ({ name }: PortalHostProps) => {\n //#region hooks\n const isServer = !useDidFinishSSR()\n const state = usePortalState(name)\n const { registerHost, deregisterHost } = usePortal(name)\n //#endregion\n\n //#region effects\n useEffect(() => {\n if (isServer) return\n registerHost()\n return () => {\n deregisterHost()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isServer])\n //#endregion\n\n //#region render\n return <>{state.map((item) => item.node)}</>\n //#endregion\n}\n\nexport const PortalHost = memo(PortalHostComponent)\nPortalHost.displayName = 'PortalHost'\n\nexport interface PortalItemProps {\n /**\n * Portal's key or name to be used as an identifier.\n * @type string\n * @default nanoid generated unique key.\n */\n name?: string\n /**\n * Host's name to teleport the portal content to.\n * @type string\n * @default 'root'\n */\n hostName?: string\n /**\n * Override internal mounting functionality, this is useful\n * if you want to trigger any action before mounting the portal content.\n * @type (mount?: () => void) => void\n * @default undefined\n */\n handleOnMount?: (mount: () => void) => void\n /**\n * Override internal un-mounting functionality, this is useful\n * if you want to trigger any action before un-mounting the portal content.\n * @type (unmount?: () => void) => void\n * @default undefined\n */\n handleOnUnmount?: (unmount: () => void) => void\n /**\n * Override internal updating functionality, this is useful\n * if you want to trigger any action before updating the portal content.\n * @type (update?: () => void) => void\n * @default undefined\n */\n handleOnUpdate?: (update: () => void) => void\n /**\n * Portal's content.\n * @type ReactNode\n * @default undefined\n */\n children?: ReactNode | ReactNode[]\n}\n\nconst PortalComponent = ({\n name: _providedName,\n hostName,\n handleOnMount: _providedHandleOnMount,\n handleOnUnmount: _providedHandleOnUnmount,\n handleOnUpdate: _providedHandleOnUpdate,\n children,\n}: PortalItemProps) => {\n //#region hooks\n const { addPortal: addUpdatePortal, removePortal } = usePortal(hostName)\n //#endregion\n\n let id = 0\n const nanoid = () => {\n id = (id + 1) % Number.MAX_SAFE_INTEGER\n return `${id}`\n }\n\n //#region variables\n const name = useMemo(() => _providedName || nanoid(), [_providedName])\n //#endregion\n\n //#region refs\n const handleOnMountRef = useRef<Function>()\n const handleOnUnmountRef = useRef<Function>()\n const handleOnUpdateRef = useRef<Function>()\n //#endregion\n\n //#region callbacks\n const handleOnMount = useCallback(() => {\n if (_providedHandleOnMount) {\n _providedHandleOnMount(() => addUpdatePortal(name, children))\n } else {\n addUpdatePortal(name, children)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [_providedHandleOnMount, addUpdatePortal])\n handleOnMountRef.current = handleOnMount\n\n const handleOnUnmount = useCallback(() => {\n if (_providedHandleOnUnmount) {\n _providedHandleOnUnmount(() => removePortal(name))\n } else {\n removePortal(name)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [_providedHandleOnUnmount, removePortal])\n handleOnUnmountRef.current = handleOnUnmount\n\n const handleOnUpdate = useCallback(() => {\n if (_providedHandleOnUpdate) {\n _providedHandleOnUpdate(() => addUpdatePortal(name, children))\n } else {\n addUpdatePortal(name, children)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [_providedHandleOnUpdate, addUpdatePortal, children])\n handleOnUpdateRef.current = handleOnUpdate\n //#endregion\n\n //#region effects\n useEffect(() => {\n handleOnMountRef.current?.()\n return () => {\n handleOnUnmountRef.current?.()\n\n // remove callbacks refs\n handleOnMountRef.current = undefined\n handleOnUnmountRef.current = undefined\n handleOnUpdateRef.current = undefined\n }\n }, [])\n useEffect(() => {\n handleOnUpdateRef.current?.()\n }, [children])\n //#endregion\n\n return null\n}\n\nexport const PortalItem = memo(PortalComponent)\nPortalItem.displayName = 'Portal'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwOM;AApON,kBAAgC;AAChC,mBAA4D;AAC5D,IAAAA,gBAA2F;AAO3F,IAAK,UAAL,kBAAKC,aAAL;AACE,EAAAA,kBAAA;AACA,EAA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YlB;AAwYI,4BAAkB,YAAlB;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAGb,SAAO;AACT;AAEO,MAAM,iBAAa,oBAAK,eAAe;AAC9C,WAAW,cAAc;",
|
|
6
|
+
"names": ["import_react", "ACTIONS", "registerHost", "deregisterHost", "addUpdatePortal", "removePortal", "_a"]
|
|
7
|
+
}
|
package/dist/cjs/Portal.js
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
22
8
|
var __export = (target, all) => {
|
|
23
9
|
for (var name in all)
|
|
24
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -31,39 +17,41 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
31
17
|
}
|
|
32
18
|
return to;
|
|
33
19
|
};
|
|
34
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
35
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
25
|
var Portal_exports = {};
|
|
37
26
|
__export(Portal_exports, {
|
|
38
27
|
Portal: () => Portal
|
|
39
28
|
});
|
|
40
29
|
module.exports = __toCommonJS(Portal_exports);
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
31
|
var import_polyfill_dev = require("@tamagui/polyfill-dev");
|
|
42
32
|
var import_core = require("@tamagui/core");
|
|
43
33
|
var import_stacks = require("@tamagui/stacks");
|
|
44
34
|
var React = __toESM(require("react"));
|
|
45
35
|
var import_react_dom = require("react-dom");
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
fullscreen: true
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
36
|
+
const Portal = ({ host = ((_a) => (_a = globalThis.document) == null ? void 0 : _a.body)(), ...props }) => {
|
|
37
|
+
const contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.YStack, {
|
|
38
|
+
pointerEvents: "box-none",
|
|
39
|
+
contain: "strict",
|
|
40
|
+
fullscreen: true,
|
|
41
|
+
position: import_core.isWeb ? "fixed" : "absolute",
|
|
42
|
+
maxWidth: import_core.isWeb ? "100vw" : "100%",
|
|
43
|
+
maxHeight: import_core.isWeb ? "100vh" : "100%",
|
|
44
|
+
...props
|
|
45
|
+
});
|
|
57
46
|
const [hostElement, setHostElement] = React.useState(null);
|
|
58
47
|
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, []);
|
|
48
|
+
setHostElement(host);
|
|
49
|
+
}, [host]);
|
|
62
50
|
if (hostElement) {
|
|
63
51
|
return (0, import_react_dom.createPortal)(contents, hostElement);
|
|
64
52
|
}
|
|
65
53
|
return null;
|
|
66
|
-
}
|
|
54
|
+
};
|
|
67
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
68
56
|
0 && (module.exports = {
|
|
69
57
|
Portal
|
package/dist/cjs/Portal.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Portal.tsx"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/* eslint-disable react-hooks/rules-of-hooks */\nimport '@tamagui/polyfill-dev'\n\nimport { isWeb, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { YStack } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { PortalProps } from './PortalProps'\n\nexport const Portal = ({ host = globalThis.document?.body, ...props }: PortalProps) => {\n const contents = (\n <YStack\n pointerEvents=\"box-none\"\n contain=\"strict\"\n fullscreen\n // @ts-expect-error ok on web\n position={isWeb ? 'fixed' : 'absolute'}\n maxWidth={isWeb ? '100vw' : '100%'}\n maxHeight={isWeb ? '100vh' : '100%'}\n {...props}\n />\n )\n\n const [hostElement, setHostElement] = React.useState<any>(null)\n\n useIsomorphicLayoutEffect(() => {\n setHostElement(host)\n }, [host])\n\n if (hostElement) {\n return createPortal(contents, hostElement)\n }\n\n // ssr return null\n return null\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYI;AAXJ,0BAAO;AAEP,kBAAiD;AACjD,oBAAuB;AACvB,YAAuB;AACvB,uBAA6B;AAItB,MAAM,SAAS,CAAC,EAAE,QAAO,yBAAW,aAAX,mBAAqB,YAAS,MAAM,MAAmB;AACrF,QAAM,WACJ,4CAAC;AAAA,IACC,eAAc;AAAA,IACd,SAAQ;AAAA,IACR,YAAU;AAAA,IAEV,UAAU,oBAAQ,UAAU;AAAA,IAC5B,UAAU,oBAAQ,UAAU;AAAA,IAC5B,WAAW,oBAAQ,UAAU;AAAA,IAC5B,GAAG;AAAA,GACN;AAGF,QAAM,CAAC,aAAa,cAAc,IAAI,MAAM,SAAc,IAAI;AAE9D,6CAA0B,MAAM;AAC9B,mBAAe,IAAI;AAAA,EACrB,GAAG,CAAC,IAAI,CAAC;AAET,MAAI,aAAa;AACf,eAAO,+BAAa,UAAU,WAAW;AAAA,EAC3C;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], 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
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var Portal_native_exports = {};
|
|
26
|
+
__export(Portal_native_exports, {
|
|
27
|
+
Portal: () => Portal
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(Portal_native_exports);
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
var import_stacks = require("@tamagui/stacks");
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_react_native = require("react-native");
|
|
34
|
+
var import_ReactNative = require("react-native/Libraries/Renderer/shims/ReactNative");
|
|
35
|
+
const Portal = (props) => {
|
|
36
|
+
const rootTag = React.useContext(import_react_native.RootTagContext);
|
|
37
|
+
const contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.YStack, {
|
|
38
|
+
pointerEvents: "box-none",
|
|
39
|
+
fullscreen: true,
|
|
40
|
+
position: "absolute",
|
|
41
|
+
maxWidth: "100%",
|
|
42
|
+
zIndex: 1e5,
|
|
43
|
+
...props
|
|
44
|
+
});
|
|
45
|
+
if (rootTag) {
|
|
46
|
+
return (0, import_ReactNative.createPortal)(contents, rootTag);
|
|
47
|
+
}
|
|
48
|
+
if (process.env.NODE_ENV === "development") {
|
|
49
|
+
console.warn(
|
|
50
|
+
`Missing rootTag, this is a bug - you may need a different React Native version, or to avoid using "modal" on native.`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
Portal
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=Portal.native.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Portal.native.tsx"],
|
|
4
|
+
"sourcesContent": ["import { YStack, YStackProps } from '@tamagui/stacks'\nimport * as React from 'react'\n// @ts-ignore\nimport { RootTagContext } from 'react-native'\nimport { createPortal } from 'react-native/Libraries/Renderer/shims/ReactNative'\n\nimport { PortalProps } from './PortalProps'\n\nexport const Portal = (props: PortalProps) => {\n const rootTag = React.useContext(RootTagContext)\n\n const contents = (\n <YStack\n pointerEvents=\"box-none\"\n fullscreen\n position=\"absolute\"\n maxWidth=\"100%\"\n zIndex={100000}\n {...props}\n />\n )\n\n if (rootTag) {\n return createPortal(contents, rootTag)\n }\n\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(\n `Missing rootTag, this is a bug - you may need a different React Native version, or to avoid using \"modal\" on native.`\n )\n }\n\n return null\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYI;AAZJ,oBAAoC;AACpC,YAAuB;AAEvB,0BAA+B;AAC/B,yBAA6B;AAItB,MAAM,SAAS,CAAC,UAAuB;AAC5C,QAAM,UAAU,MAAM,WAAW,kCAAc;AAE/C,QAAM,WACJ,4CAAC;AAAA,IACC,eAAc;AAAA,IACd,YAAU;AAAA,IACV,UAAS;AAAA,IACT,UAAS;AAAA,IACT,QAAQ;AAAA,IACP,GAAG;AAAA,GACN;AAGF,MAAI,SAAS;AACX,eAAO,iCAAa,UAAU,OAAO;AAAA,EACvC;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAE1C,YAAQ;AAAA,MACN;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var PortalProps_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(PortalProps_exports);
|
|
17
|
+
//# sourceMappingURL=PortalProps.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/PortalProps.tsx"],
|
|
4
|
+
"sourcesContent": ["import { YStackProps } from '@tamagui/stacks'\n\nexport type PortalProps = YStackProps & {\n host?: any // element\n inactive?: boolean\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -15,4 +16,5 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
15
16
|
var src_exports = {};
|
|
16
17
|
module.exports = __toCommonJS(src_exports);
|
|
17
18
|
__reExport(src_exports, require("./Portal"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./GorhomPortal"), module.exports);
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.tsx"],
|
|
4
|
-
"sourcesContent": ["export * from './Portal'\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export * from './Portal'\nexport * from './GorhomPortal'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,qBAAd;AACA,wBAAc,2BADd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|