@tamagui/portal 1.14.0 → 1.14.2
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 +270 -1
- package/dist/cjs/GorhomPortal.js.map +2 -2
- package/dist/cjs/Portal.js +65 -1
- package/dist/cjs/Portal.js.map +2 -2
- package/dist/cjs/Portal.native.js +69 -1
- package/dist/cjs/Portal.native.js.map +2 -2
- package/dist/cjs/PortalProps.js +16 -1
- package/dist/cjs/PortalProps.js.map +2 -2
- package/dist/cjs/index.js +20 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/GorhomPortal.js +241 -1
- package/dist/esm/GorhomPortal.js.map +2 -2
- package/dist/esm/GorhomPortal.mjs +241 -1
- package/dist/esm/GorhomPortal.mjs.map +2 -2
- package/dist/esm/Portal.js +31 -1
- package/dist/esm/Portal.js.map +2 -2
- package/dist/esm/Portal.mjs +31 -1
- package/dist/esm/Portal.mjs.map +2 -2
- package/dist/esm/Portal.native.js +35 -1
- package/dist/esm/Portal.native.js.map +2 -2
- package/dist/esm/Portal.native.mjs +35 -1
- package/dist/esm/Portal.native.mjs.map +2 -2
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +3 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/cjs/GorhomPortal.js
CHANGED
|
@@ -1,2 +1,271 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
+
// 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", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var GorhomPortal_exports = {};
|
|
30
|
+
__export(GorhomPortal_exports, {
|
|
31
|
+
ACTIONS: () => ACTIONS,
|
|
32
|
+
INITIAL_STATE: () => INITIAL_STATE,
|
|
33
|
+
PortalHost: () => PortalHost,
|
|
34
|
+
PortalItem: () => PortalItem,
|
|
35
|
+
PortalProvider: () => PortalProvider,
|
|
36
|
+
usePortal: () => usePortal
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(GorhomPortal_exports);
|
|
39
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
+
var import_core = require("@tamagui/core");
|
|
41
|
+
var import_react = __toESM(require("react"));
|
|
42
|
+
var ACTIONS = /* @__PURE__ */ ((ACTIONS2) => {
|
|
43
|
+
ACTIONS2[ACTIONS2["REGISTER_HOST"] = 0] = "REGISTER_HOST";
|
|
44
|
+
ACTIONS2[ACTIONS2["DEREGISTER_HOST"] = 1] = "DEREGISTER_HOST";
|
|
45
|
+
ACTIONS2[ACTIONS2["ADD_UPDATE_PORTAL"] = 2] = "ADD_UPDATE_PORTAL";
|
|
46
|
+
ACTIONS2[ACTIONS2["REMOVE_PORTAL"] = 3] = "REMOVE_PORTAL";
|
|
47
|
+
return ACTIONS2;
|
|
48
|
+
})(ACTIONS || {});
|
|
49
|
+
const INITIAL_STATE = {};
|
|
50
|
+
const registerHost = (state, hostName) => {
|
|
51
|
+
if (!(hostName in state)) {
|
|
52
|
+
state[hostName] = [];
|
|
53
|
+
}
|
|
54
|
+
return state;
|
|
55
|
+
};
|
|
56
|
+
const deregisterHost = (state, hostName) => {
|
|
57
|
+
delete state[hostName];
|
|
58
|
+
return state;
|
|
59
|
+
};
|
|
60
|
+
const addUpdatePortal = (state, hostName, portalName, node) => {
|
|
61
|
+
if (!(hostName in state)) {
|
|
62
|
+
state = registerHost(state, hostName);
|
|
63
|
+
}
|
|
64
|
+
const index = state[hostName].findIndex((item) => item.name === portalName);
|
|
65
|
+
if (index !== -1) {
|
|
66
|
+
state[hostName][index].node = node;
|
|
67
|
+
} else {
|
|
68
|
+
state[hostName].push({
|
|
69
|
+
name: portalName,
|
|
70
|
+
node
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return state;
|
|
74
|
+
};
|
|
75
|
+
const removePortal = (state, hostName, portalName) => {
|
|
76
|
+
if (!(hostName in state)) {
|
|
77
|
+
console.log(
|
|
78
|
+
`Failed to remove portal '${portalName}', '${hostName}' was not registered!`
|
|
79
|
+
);
|
|
80
|
+
return state;
|
|
81
|
+
}
|
|
82
|
+
const index = state[hostName].findIndex((item) => item.name === portalName);
|
|
83
|
+
if (index !== -1)
|
|
84
|
+
state[hostName].splice(index, 1);
|
|
85
|
+
return state;
|
|
86
|
+
};
|
|
87
|
+
const reducer = (state, action) => {
|
|
88
|
+
const { type } = action;
|
|
89
|
+
switch (type) {
|
|
90
|
+
case 0 /* REGISTER_HOST */:
|
|
91
|
+
return registerHost({ ...state }, action.hostName);
|
|
92
|
+
case 1 /* DEREGISTER_HOST */:
|
|
93
|
+
return deregisterHost({ ...state }, action.hostName);
|
|
94
|
+
case 2 /* ADD_UPDATE_PORTAL */:
|
|
95
|
+
return addUpdatePortal(
|
|
96
|
+
{ ...state },
|
|
97
|
+
action.hostName,
|
|
98
|
+
action.portalName,
|
|
99
|
+
action.node
|
|
100
|
+
);
|
|
101
|
+
case 3 /* REMOVE_PORTAL */:
|
|
102
|
+
return removePortal(
|
|
103
|
+
{ ...state },
|
|
104
|
+
action.hostName,
|
|
105
|
+
action.portalName
|
|
106
|
+
);
|
|
107
|
+
default:
|
|
108
|
+
return state;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const PortalStateContext = (0, import_react.createContext)(null);
|
|
112
|
+
const PortalDispatchContext = (0, import_react.createContext)(null);
|
|
113
|
+
const usePortalState = (hostName) => {
|
|
114
|
+
const state = (0, import_react.useContext)(PortalStateContext);
|
|
115
|
+
if (state === null) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
"'PortalStateContext' cannot be null, please add 'PortalProvider' to the root component."
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return state[hostName] || [];
|
|
121
|
+
};
|
|
122
|
+
const usePortal = (hostName = "root") => {
|
|
123
|
+
const dispatch = (0, import_react.useContext)(PortalDispatchContext);
|
|
124
|
+
if (dispatch === null) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
"'PortalDispatchContext' cannot be null, please add 'PortalProvider' to the root component."
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
const registerHost2 = (0, import_react.useCallback)(() => {
|
|
130
|
+
dispatch({
|
|
131
|
+
type: 0 /* REGISTER_HOST */,
|
|
132
|
+
hostName
|
|
133
|
+
});
|
|
134
|
+
}, []);
|
|
135
|
+
const deregisterHost2 = (0, import_react.useCallback)(() => {
|
|
136
|
+
dispatch({
|
|
137
|
+
type: 1 /* DEREGISTER_HOST */,
|
|
138
|
+
hostName
|
|
139
|
+
});
|
|
140
|
+
}, []);
|
|
141
|
+
const addUpdatePortal2 = (0, import_react.useCallback)((name, node) => {
|
|
142
|
+
dispatch({
|
|
143
|
+
type: 2 /* ADD_UPDATE_PORTAL */,
|
|
144
|
+
hostName,
|
|
145
|
+
portalName: name,
|
|
146
|
+
node
|
|
147
|
+
});
|
|
148
|
+
}, []);
|
|
149
|
+
const removePortal2 = (0, import_react.useCallback)((name) => {
|
|
150
|
+
dispatch({
|
|
151
|
+
type: 3 /* REMOVE_PORTAL */,
|
|
152
|
+
hostName,
|
|
153
|
+
portalName: name
|
|
154
|
+
});
|
|
155
|
+
}, []);
|
|
156
|
+
return {
|
|
157
|
+
registerHost: registerHost2,
|
|
158
|
+
deregisterHost: deregisterHost2,
|
|
159
|
+
addPortal: addUpdatePortal2,
|
|
160
|
+
updatePortal: addUpdatePortal2,
|
|
161
|
+
removePortal: removePortal2
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
const PortalProviderComponent = ({
|
|
165
|
+
rootHostName = "root",
|
|
166
|
+
shouldAddRootHost = true,
|
|
167
|
+
children
|
|
168
|
+
}) => {
|
|
169
|
+
const [state, dispatch] = (0, import_react.useReducer)(reducer, INITIAL_STATE);
|
|
170
|
+
const transitionDispatch = (0, import_react.useMemo)(() => {
|
|
171
|
+
const next = (value) => {
|
|
172
|
+
(0, import_react.startTransition)(() => {
|
|
173
|
+
dispatch(value);
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
return next;
|
|
177
|
+
}, [dispatch]);
|
|
178
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalDispatchContext.Provider, { value: transitionDispatch, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PortalStateContext.Provider, { value: state, children: [
|
|
179
|
+
children,
|
|
180
|
+
shouldAddRootHost && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalHost, { name: rootHostName })
|
|
181
|
+
] }) });
|
|
182
|
+
};
|
|
183
|
+
const PortalProvider = (0, import_react.memo)(PortalProviderComponent);
|
|
184
|
+
PortalProvider.displayName = "PortalProvider";
|
|
185
|
+
const defaultRenderer = (children) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
186
|
+
const PortalHostComponent = (props) => {
|
|
187
|
+
const { name, forwardProps, render = defaultRenderer } = props;
|
|
188
|
+
const isServer = !(0, import_core.useDidFinishSSR)();
|
|
189
|
+
const state = usePortalState(name);
|
|
190
|
+
const { registerHost: registerHost2, deregisterHost: deregisterHost2 } = usePortal(props.name);
|
|
191
|
+
(0, import_react.useEffect)(() => {
|
|
192
|
+
if (isServer)
|
|
193
|
+
return;
|
|
194
|
+
registerHost2();
|
|
195
|
+
return () => {
|
|
196
|
+
deregisterHost2();
|
|
197
|
+
};
|
|
198
|
+
}, [isServer]);
|
|
199
|
+
if (forwardProps) {
|
|
200
|
+
return render(
|
|
201
|
+
state.map((item) => {
|
|
202
|
+
let next = item.node;
|
|
203
|
+
if (forwardProps) {
|
|
204
|
+
return import_react.default.Children.map(next, (child) => {
|
|
205
|
+
return import_react.default.isValidElement(child) ? import_react.default.cloneElement(child, { key: child.key, ...forwardProps }) : child;
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return next;
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return render(state.map((item) => item.node));
|
|
213
|
+
};
|
|
214
|
+
const PortalHost = (0, import_react.memo)(PortalHostComponent);
|
|
215
|
+
PortalHost.displayName = "PortalHost";
|
|
216
|
+
const PortalComponent = (props) => {
|
|
217
|
+
const {
|
|
218
|
+
name: _providedName,
|
|
219
|
+
hostName,
|
|
220
|
+
handleOnMount: _providedHandleOnMount,
|
|
221
|
+
handleOnUnmount: _providedHandleOnUnmount,
|
|
222
|
+
handleOnUpdate: _providedHandleOnUpdate,
|
|
223
|
+
children
|
|
224
|
+
} = props;
|
|
225
|
+
const { addPortal: addUpdatePortal2, removePortal: removePortal2 } = usePortal(hostName);
|
|
226
|
+
const id = (0, import_react.useId)();
|
|
227
|
+
const name = _providedName || id;
|
|
228
|
+
const handleOnMount = (0, import_core.useEvent)(() => {
|
|
229
|
+
if (_providedHandleOnMount) {
|
|
230
|
+
_providedHandleOnMount(() => addUpdatePortal2(name, children));
|
|
231
|
+
} else {
|
|
232
|
+
addUpdatePortal2(name, children);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
const handleOnUnmount = (0, import_core.useEvent)(() => {
|
|
236
|
+
if (_providedHandleOnUnmount) {
|
|
237
|
+
_providedHandleOnUnmount(() => removePortal2(name));
|
|
238
|
+
} else {
|
|
239
|
+
removePortal2(name);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
const handleOnUpdate = (0, import_core.useEvent)(() => {
|
|
243
|
+
if (_providedHandleOnUpdate) {
|
|
244
|
+
_providedHandleOnUpdate(() => addUpdatePortal2(name, children));
|
|
245
|
+
} else {
|
|
246
|
+
addUpdatePortal2(name, children);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
250
|
+
handleOnMount();
|
|
251
|
+
return () => {
|
|
252
|
+
handleOnUnmount();
|
|
253
|
+
};
|
|
254
|
+
}, []);
|
|
255
|
+
(0, import_react.useEffect)(() => {
|
|
256
|
+
handleOnUpdate();
|
|
257
|
+
}, [children]);
|
|
258
|
+
return null;
|
|
259
|
+
};
|
|
260
|
+
const PortalItem = (0, import_react.memo)(PortalComponent);
|
|
261
|
+
PortalItem.displayName = "Portal";
|
|
262
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
263
|
+
0 && (module.exports = {
|
|
264
|
+
ACTIONS,
|
|
265
|
+
INITIAL_STATE,
|
|
266
|
+
PortalHost,
|
|
267
|
+
PortalItem,
|
|
268
|
+
PortalProvider,
|
|
269
|
+
usePortal
|
|
270
|
+
});
|
|
2
271
|
//# sourceMappingURL=GorhomPortal.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/GorhomPortal.tsx"],
|
|
4
4
|
"sourcesContent": ["// from https://github.com/gorhom/react-native-portal\n// MIT License Copyright (c) 2020 Mo Gorhom\n// fixing SSR issue\nimport { useDidFinishSSR, useEvent, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport React, {\n ReactNode,\n createContext,\n memo,\n startTransition,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useReducer,\n} 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 // eslint-disable-next-line no-console\n console.log(\n `Failed to remove portal '${portalName}', '${hostName}' was not registered!`\n )\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(\n { ...state },\n action.hostName,\n (action as RemovePortalAction).portalName\n )\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\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 forwardProps?: Record<string, any>\n\n /**\n * Useful when trying to animate children with AnimatePresence.\n *\n * Not a part of gorhom/react-native-portal\n */\n render?: (children: React.ReactNode) => React.ReactElement\n}\nconst defaultRenderer: PortalHostProps['render'] = (children) => <>{children}</>\n\nconst PortalHostComponent = (props: PortalHostProps) => {\n const { name, forwardProps, render = defaultRenderer } = props\n const isServer = !useDidFinishSSR()\n const state = usePortalState(name)\n const { registerHost, deregisterHost } = usePortal(props.name)\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 if (forwardProps) {\n return render(\n state.map((item) => {\n let next = item.node\n\n if (forwardProps) {\n return React.Children.map(next, (child) => {\n return React.isValidElement(child)\n ? React.cloneElement(child, { key: child.key, ...forwardProps })\n : child\n })\n }\n\n return next\n })\n )\n }\n\n //#region render\n return render(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 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 = (props: PortalItemProps) => {\n const {\n name: _providedName,\n hostName,\n handleOnMount: _providedHandleOnMount,\n handleOnUnmount: _providedHandleOnUnmount,\n handleOnUpdate: _providedHandleOnUpdate,\n children,\n } = props\n const { addPortal: addUpdatePortal, removePortal } = usePortal(hostName)\n const id = useId()\n const name = _providedName || id\n\n const handleOnMount = useEvent(() => {\n if (_providedHandleOnMount) {\n _providedHandleOnMount(() => addUpdatePortal(name, children))\n } else {\n addUpdatePortal(name, children)\n }\n })\n\n const handleOnUnmount = useEvent(() => {\n if (_providedHandleOnUnmount) {\n _providedHandleOnUnmount(() => removePortal(name))\n } else {\n removePortal(name)\n }\n })\n\n const handleOnUpdate = useEvent(() => {\n if (_providedHandleOnUpdate) {\n _providedHandleOnUpdate(() => addUpdatePortal(name, children))\n } else {\n addUpdatePortal(name, children)\n }\n })\n\n useIsomorphicLayoutEffect(() => {\n handleOnMount()\n return () => {\n handleOnUnmount()\n }\n }, [])\n\n useEffect(() => {\n handleOnUpdate()\n }, [children])\n\n return null\n}\n\nexport const PortalItem = memo(PortalComponent)\nPortalItem.displayName = 'Portal'\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyPM;AAtPN,kBAAqE;AACrE,mBAWO;AAOP,IAAK,UAAL,kBAAKA,aAAL;AACE,EAAAA,kBAAA;AACA,EAAAA,kBAAA;AACA,EAAAA,kBAAA;AACA,EAAAA,kBAAA;AAJG,SAAAA;AAAA,GAAA;AAOL,MAAM,gBAAgB,CAAC;AAiCvB,MAAM,eAAe,CAAC,OAA0C,aAAqB;AACnF,MAAI,EAAE,YAAY,QAAQ;AACxB,UAAM,QAAQ,IAAI,CAAC;AAAA,EACrB;AACA,SAAO;AACT;AAEA,MAAM,iBAAiB,CAAC,OAA0C,aAAqB;AACrF,SAAO,MAAM,QAAQ;AACrB,SAAO;AACT;AAEA,MAAM,kBAAkB,CACtB,OACA,UACA,YACA,SACG;AACH,MAAI,EAAE,YAAY,QAAQ;AACxB,YAAQ,aAAa,OAAO,QAAQ;AAAA,EACtC;AAKA,QAAM,QAAQ,MAAM,QAAQ,EAAE,UAAU,CAAC,SAAS,KAAK,SAAS,UAAU;AAC1E,MAAI,UAAU,IAAI;AAChB,UAAM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AAQ;AACvE,QAAM,SAAK,oBAAM;AACjB,QAAM,OAAO,iBAAiB;AAE9B,QAAM,oBAAgB,sBAAS,MAAM;AACnC,QAAI,wBAAwB;AAC1B,6BAAuB,MAAMD,iBAAgB,MAAM,QAAQ,CAAC;AAAA,IAC9D,OAAO;AACL,MAAAA,iBAAgB,MAAM,QAAQ;AAAA,IAChC;AAAA,EACF,CAAC;AAED,QAAM,sBAAkB,sBAAS,MAAM;AACrC,QAAI,0BAA0B;AAC5B,+BAAyB,MAAMC,cAAa,IAAI,CAAC;AAAA,IACnD,OAAO;AACL,MAAAA,cAAa,IAAI;AAAA,IACnB;AAAA,EACF,CAAC;AAED,QAAM,qBAAiB,sBAAS,MAAM;AACpC,QAAI,yBAAyB;AAC3B,8BAAwB,MAAMD,iBAAgB,MAAM,QAAQ,CAAC;AAAA,IAC/D,OAAO;AACL,MAAAA,iBAAgB,MAAM,QAAQ;AAAA,IAChC;AAAA,EACF,CAAC;AAED,6CAA0B,MAAM;AAC9B,kBAAc;AACd,WAAO,MAAM;AACX,sBAAgB;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,8BAAU,MAAM;AACd,mBAAe;AAAA,EACjB,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AACT;AAEO,MAAM,iBAAa,mBAAK,eAAe;AAC9C,WAAW,cAAc;",
|
|
6
|
+
"names": ["ACTIONS", "registerHost", "deregisterHost", "addUpdatePortal", "removePortal", "React"]
|
|
7
7
|
}
|
package/dist/cjs/Portal.js
CHANGED
|
@@ -1,2 +1,66 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
+
// 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", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Portal_exports = {};
|
|
30
|
+
__export(Portal_exports, {
|
|
31
|
+
Portal: () => Portal
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(Portal_exports);
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
var import_polyfill_dev = require("@tamagui/polyfill-dev");
|
|
36
|
+
var import_core = require("@tamagui/core");
|
|
37
|
+
var import_stacks = require("@tamagui/stacks");
|
|
38
|
+
var React = __toESM(require("react"));
|
|
39
|
+
var import_react_dom = require("react-dom");
|
|
40
|
+
const Portal = ({ host = ((_a) => (_a = globalThis.document) == null ? void 0 : _a.body)(), ...props }) => {
|
|
41
|
+
const contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
42
|
+
import_stacks.YStack,
|
|
43
|
+
{
|
|
44
|
+
contain: "strict",
|
|
45
|
+
fullscreen: true,
|
|
46
|
+
position: import_core.isWeb ? "fixed" : "absolute",
|
|
47
|
+
maxWidth: import_core.isWeb ? "100vw" : "100%",
|
|
48
|
+
maxHeight: import_core.isWeb ? "100vh" : "100%",
|
|
49
|
+
pointerEvents: "none",
|
|
50
|
+
...props
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
const [hostElement, setHostElement] = React.useState(null);
|
|
54
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
55
|
+
setHostElement(host);
|
|
56
|
+
}, [host]);
|
|
57
|
+
if (hostElement) {
|
|
58
|
+
return (0, import_react_dom.createPortal)(contents, hostElement);
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
Portal
|
|
65
|
+
});
|
|
2
66
|
//# sourceMappingURL=Portal.js.map
|
package/dist/cjs/Portal.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Portal.tsx"],
|
|
4
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 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 pointerEvents=\"none\"\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": "
|
|
6
|
-
"names": [
|
|
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,SAAM,GAAG,MAAM,MAAmB;AACrF,QAAM,WACJ;AAAA,IAAC;AAAA;AAAA,MACC,SAAQ;AAAA,MACR,YAAU;AAAA,MAEV,UAAU,oBAAQ,UAAU;AAAA,MAC5B,UAAU,oBAAQ,UAAU;AAAA,MAC5B,WAAW,oBAAQ,UAAU;AAAA,MAC7B,eAAc;AAAA,MACb,GAAG;AAAA;AAAA,EACN;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
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,70 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
+
// 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", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Portal_native_exports = {};
|
|
30
|
+
__export(Portal_native_exports, {
|
|
31
|
+
Portal: () => Portal
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(Portal_native_exports);
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
var import_stacks = require("@tamagui/stacks");
|
|
36
|
+
var React = __toESM(require("react"));
|
|
37
|
+
var import_react_native = require("react-native");
|
|
38
|
+
var import_ReactNative = require("react-native/Libraries/Renderer/shims/ReactNative");
|
|
39
|
+
var import_GorhomPortal = require("./GorhomPortal");
|
|
40
|
+
const Portal = (props) => {
|
|
41
|
+
const rootTag = React.useContext(import_react_native.RootTagContext);
|
|
42
|
+
const contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
43
|
+
import_stacks.YStack,
|
|
44
|
+
{
|
|
45
|
+
pointerEvents: "box-none",
|
|
46
|
+
fullscreen: true,
|
|
47
|
+
position: "absolute",
|
|
48
|
+
maxWidth: "100%",
|
|
49
|
+
zIndex: 1e5,
|
|
50
|
+
...props
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
if (import_react_native.Platform.OS === "android") {
|
|
54
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_GorhomPortal.PortalItem, { hostName: "root", children: contents });
|
|
55
|
+
}
|
|
56
|
+
if (rootTag) {
|
|
57
|
+
return (0, import_ReactNative.createPortal)(contents, rootTag);
|
|
58
|
+
}
|
|
59
|
+
if (process.env.NODE_ENV === "development") {
|
|
60
|
+
console.warn(
|
|
61
|
+
`Missing rootTag, this is a bug - you may need a different React Native version, or to avoid using "modal" on native.`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
};
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
Portal
|
|
69
|
+
});
|
|
2
70
|
//# sourceMappingURL=Portal.native.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Portal.native.tsx"],
|
|
4
4
|
"sourcesContent": ["import { YStack } from '@tamagui/stacks'\nimport * as React from 'react'\n// @ts-ignore\nimport { Platform, RootTagContext } from 'react-native'\nimport { createPortal } from 'react-native/Libraries/Renderer/shims/ReactNative'\n\nimport { PortalItem } from './GorhomPortal'\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 (Platform.OS === 'android') {\n return <PortalItem hostName=\"root\">{contents}</PortalItem>\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": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaI;AAbJ,oBAAuB;AACvB,YAAuB;AAEvB,0BAAyC;AACzC,yBAA6B;AAE7B,0BAA2B;AAGpB,MAAM,SAAS,CAAC,UAAuB;AAC5C,QAAM,UAAU,MAAM,WAAW,kCAAc;AAE/C,QAAM,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,MAAI,6BAAS,OAAO,WAAW;AAC7B,WAAO,4CAAC,kCAAW,UAAS,QAAQ,oBAAS;AAAA,EAC/C;AAEA,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
7
|
}
|
package/dist/cjs/PortalProps.js
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
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);
|
|
2
17
|
//# sourceMappingURL=PortalProps.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/PortalProps.tsx"],
|
|
4
4
|
"sourcesContent": ["import { YStackProps } from '@tamagui/stacks'\n\nexport type PortalProps = YStackProps & {\n host?: any // element\n inactive?: boolean\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./Portal"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./PortalProps"), module.exports);
|
|
20
|
+
__reExport(src_exports, require("./GorhomPortal"), module.exports);
|
|
2
21
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.tsx"],
|
|
4
4
|
"sourcesContent": ["export * from './Portal'\nexport * from './PortalProps'\nexport * from './GorhomPortal'\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,qBAAd;AACA,wBAAc,0BADd;AAEA,wBAAc,2BAFd;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|