@frontegg/react-hooks 6.104.0-alpha.0 → 6.104.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/common/CustomComponentHolder.d.ts +14 -0
- package/common/CustomComponentHolder.js +100 -0
- package/common/index.d.ts +1 -1
- package/common/index.js +2 -1
- package/index.js +1 -1
- package/node/common/CustomComponentHolder.js +109 -0
- package/node/common/index.js +17 -0
- package/node/index.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FC, ReactElement } from 'react';
|
|
2
|
+
import { FronteggAppInstance } from '@frontegg/types';
|
|
3
|
+
/**
|
|
4
|
+
* CustomComponentRegister is used to support using react hooks inside custom components.
|
|
5
|
+
*/
|
|
6
|
+
export declare class CustomComponentHolder {
|
|
7
|
+
private static components;
|
|
8
|
+
static set(name: string, element: any): void;
|
|
9
|
+
static get(name: string): ReactElement;
|
|
10
|
+
}
|
|
11
|
+
export declare const CustomComponentRegister: FC<{
|
|
12
|
+
app: FronteggAppInstance;
|
|
13
|
+
themeOptions: any;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React, { isValidElement, useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { isElement } from 'react-is';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CustomComponentRegister is used to support using react hooks inside custom components.
|
|
7
|
+
*/
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
|
+
export class CustomComponentHolder {
|
|
11
|
+
static set(name, element) {
|
|
12
|
+
CustomComponentHolder.components[name] = element;
|
|
13
|
+
}
|
|
14
|
+
static get(name) {
|
|
15
|
+
return CustomComponentHolder.components[name];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
CustomComponentHolder.components = {};
|
|
19
|
+
const overrideValue = (object, key, value) => {
|
|
20
|
+
const keys = key.split('.');
|
|
21
|
+
let iterator = object;
|
|
22
|
+
while (keys.length > 1) {
|
|
23
|
+
iterator = iterator[keys.shift()];
|
|
24
|
+
}
|
|
25
|
+
iterator[keys.shift()] = value;
|
|
26
|
+
};
|
|
27
|
+
const Registerer = props => {
|
|
28
|
+
var _app$loginBoxContaine;
|
|
29
|
+
const {
|
|
30
|
+
app,
|
|
31
|
+
themeKey
|
|
32
|
+
} = props;
|
|
33
|
+
const value = CustomComponentHolder.get(themeKey);
|
|
34
|
+
const [mounted, setMounted] = useState(false);
|
|
35
|
+
const mount = useCallback(() => {
|
|
36
|
+
setMounted(true);
|
|
37
|
+
}, []);
|
|
38
|
+
const unmount = useCallback(() => {
|
|
39
|
+
setMounted(false);
|
|
40
|
+
}, []);
|
|
41
|
+
overrideValue(app.options.themeOptions, themeKey, {
|
|
42
|
+
type: 'slot',
|
|
43
|
+
themeKey,
|
|
44
|
+
mount,
|
|
45
|
+
unmount
|
|
46
|
+
});
|
|
47
|
+
let element = (_app$loginBoxContaine = app.loginBoxContainer) == null ? void 0 : _app$loginBoxContaine.querySelector(`[slot="${themeKey}"]`);
|
|
48
|
+
if (!element && typeof document !== undefined) {
|
|
49
|
+
var _app$loginBoxContaine2;
|
|
50
|
+
element = document.createElement('div');
|
|
51
|
+
element.slot = themeKey;
|
|
52
|
+
(_app$loginBoxContaine2 = app.loginBoxContainer) == null ? void 0 : _app$loginBoxContaine2.appendChild(element);
|
|
53
|
+
}
|
|
54
|
+
return element && mounted ? /*#__PURE__*/_jsx(React.Fragment, {
|
|
55
|
+
children: /*#__PURE__*/ReactDOM.createPortal(value, element)
|
|
56
|
+
}) : /*#__PURE__*/_jsx(_Fragment, {});
|
|
57
|
+
};
|
|
58
|
+
export const CustomComponentRegister = ({
|
|
59
|
+
app,
|
|
60
|
+
themeOptions
|
|
61
|
+
}) => {
|
|
62
|
+
const keys = useMemo(() => {
|
|
63
|
+
if (!themeOptions || !themeOptions.loginBox) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
const loop = (key, obj, keyPath) => {
|
|
67
|
+
if (typeof obj !== 'object' && typeof obj !== 'function') {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
if (typeof obj === 'function') {
|
|
71
|
+
try {
|
|
72
|
+
obj = /*#__PURE__*/React.createElement(obj);
|
|
73
|
+
if ( /*#__PURE__*/isValidElement(obj) || isElement(obj)) {
|
|
74
|
+
const generatedKey = `${keyPath}.${key}`;
|
|
75
|
+
CustomComponentHolder.set(generatedKey, obj);
|
|
76
|
+
return [generatedKey];
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {}
|
|
79
|
+
}
|
|
80
|
+
if ( /*#__PURE__*/isValidElement(obj) || isElement(obj) || obj === null) {
|
|
81
|
+
const generatedKey = `${keyPath}.${key}`;
|
|
82
|
+
CustomComponentHolder.set(generatedKey, obj);
|
|
83
|
+
return [generatedKey];
|
|
84
|
+
} else {
|
|
85
|
+
const elements = [];
|
|
86
|
+
Object.keys(obj).forEach(k => {
|
|
87
|
+
elements.push(...loop(k, obj[k], keyPath === '' ? key : `${keyPath}.${key}`));
|
|
88
|
+
});
|
|
89
|
+
return elements;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
return loop('loginBox', themeOptions.loginBox, '');
|
|
93
|
+
}, []);
|
|
94
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
95
|
+
children: keys.map(key => /*#__PURE__*/_jsx(Registerer, {
|
|
96
|
+
app: app,
|
|
97
|
+
themeKey: key
|
|
98
|
+
}, key))
|
|
99
|
+
});
|
|
100
|
+
};
|
package/common/index.d.ts
CHANGED
|
@@ -16,4 +16,4 @@ export interface DomContext extends ShadowDomContextData {
|
|
|
16
16
|
export declare const ShadowDomContext: import("react").Context<ShadowDomContextData>;
|
|
17
17
|
export declare const useShadowDom: () => DomContext;
|
|
18
18
|
export declare const useRootState: () => FronteggState['root'];
|
|
19
|
-
export
|
|
19
|
+
export * from './CustomComponentHolder';
|
package/common/index.js
CHANGED
package/index.js
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.CustomComponentRegister = exports.CustomComponentHolder = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
10
|
+
var _reactIs = require("react-is");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
+
/**
|
|
15
|
+
* CustomComponentRegister is used to support using react hooks inside custom components.
|
|
16
|
+
*/
|
|
17
|
+
class CustomComponentHolder {
|
|
18
|
+
static set(name, element) {
|
|
19
|
+
CustomComponentHolder.components[name] = element;
|
|
20
|
+
}
|
|
21
|
+
static get(name) {
|
|
22
|
+
return CustomComponentHolder.components[name];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.CustomComponentHolder = CustomComponentHolder;
|
|
26
|
+
CustomComponentHolder.components = {};
|
|
27
|
+
const overrideValue = (object, key, value) => {
|
|
28
|
+
const keys = key.split('.');
|
|
29
|
+
let iterator = object;
|
|
30
|
+
while (keys.length > 1) {
|
|
31
|
+
iterator = iterator[keys.shift()];
|
|
32
|
+
}
|
|
33
|
+
iterator[keys.shift()] = value;
|
|
34
|
+
};
|
|
35
|
+
const Registerer = props => {
|
|
36
|
+
var _app$loginBoxContaine;
|
|
37
|
+
const {
|
|
38
|
+
app,
|
|
39
|
+
themeKey
|
|
40
|
+
} = props;
|
|
41
|
+
const value = CustomComponentHolder.get(themeKey);
|
|
42
|
+
const [mounted, setMounted] = (0, _react.useState)(false);
|
|
43
|
+
const mount = (0, _react.useCallback)(() => {
|
|
44
|
+
setMounted(true);
|
|
45
|
+
}, []);
|
|
46
|
+
const unmount = (0, _react.useCallback)(() => {
|
|
47
|
+
setMounted(false);
|
|
48
|
+
}, []);
|
|
49
|
+
overrideValue(app.options.themeOptions, themeKey, {
|
|
50
|
+
type: 'slot',
|
|
51
|
+
themeKey,
|
|
52
|
+
mount,
|
|
53
|
+
unmount
|
|
54
|
+
});
|
|
55
|
+
let element = (_app$loginBoxContaine = app.loginBoxContainer) == null ? void 0 : _app$loginBoxContaine.querySelector(`[slot="${themeKey}"]`);
|
|
56
|
+
if (!element && typeof document !== undefined) {
|
|
57
|
+
var _app$loginBoxContaine2;
|
|
58
|
+
element = document.createElement('div');
|
|
59
|
+
element.slot = themeKey;
|
|
60
|
+
(_app$loginBoxContaine2 = app.loginBoxContainer) == null ? void 0 : _app$loginBoxContaine2.appendChild(element);
|
|
61
|
+
}
|
|
62
|
+
return element && mounted ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.default.Fragment, {
|
|
63
|
+
children: /*#__PURE__*/_reactDom.default.createPortal(value, element)
|
|
64
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
|
|
65
|
+
};
|
|
66
|
+
const CustomComponentRegister = ({
|
|
67
|
+
app,
|
|
68
|
+
themeOptions
|
|
69
|
+
}) => {
|
|
70
|
+
const keys = (0, _react.useMemo)(() => {
|
|
71
|
+
if (!themeOptions || !themeOptions.loginBox) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const loop = (key, obj, keyPath) => {
|
|
75
|
+
if (typeof obj !== 'object' && typeof obj !== 'function') {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
if (typeof obj === 'function') {
|
|
79
|
+
try {
|
|
80
|
+
obj = /*#__PURE__*/_react.default.createElement(obj);
|
|
81
|
+
if ( /*#__PURE__*/(0, _react.isValidElement)(obj) || (0, _reactIs.isElement)(obj)) {
|
|
82
|
+
const generatedKey = `${keyPath}.${key}`;
|
|
83
|
+
CustomComponentHolder.set(generatedKey, obj);
|
|
84
|
+
return [generatedKey];
|
|
85
|
+
}
|
|
86
|
+
} catch (e) {}
|
|
87
|
+
}
|
|
88
|
+
if ( /*#__PURE__*/(0, _react.isValidElement)(obj) || (0, _reactIs.isElement)(obj) || obj === null) {
|
|
89
|
+
const generatedKey = `${keyPath}.${key}`;
|
|
90
|
+
CustomComponentHolder.set(generatedKey, obj);
|
|
91
|
+
return [generatedKey];
|
|
92
|
+
} else {
|
|
93
|
+
const elements = [];
|
|
94
|
+
Object.keys(obj).forEach(k => {
|
|
95
|
+
elements.push(...loop(k, obj[k], keyPath === '' ? key : `${keyPath}.${key}`));
|
|
96
|
+
});
|
|
97
|
+
return elements;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return loop('loginBox', themeOptions.loginBox, '');
|
|
101
|
+
}, []);
|
|
102
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
103
|
+
children: keys.map(key => /*#__PURE__*/(0, _jsxRuntime.jsx)(Registerer, {
|
|
104
|
+
app: app,
|
|
105
|
+
themeKey: key
|
|
106
|
+
}, key))
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
exports.CustomComponentRegister = CustomComponentRegister;
|
package/node/common/index.js
CHANGED
|
@@ -4,12 +4,29 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
var _exportNames = {
|
|
8
|
+
ShadowDomContext: true,
|
|
9
|
+
useShadowDom: true,
|
|
10
|
+
useRootState: true
|
|
11
|
+
};
|
|
7
12
|
exports.useShadowDom = exports.useRootState = exports.ShadowDomContext = void 0;
|
|
8
13
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
14
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
10
15
|
var _react = require("react");
|
|
11
16
|
var _FronteggStoreContext = require("../FronteggStoreContext");
|
|
12
17
|
var _reactRedux = require("react-redux");
|
|
18
|
+
var _CustomComponentHolder = require("./CustomComponentHolder");
|
|
19
|
+
Object.keys(_CustomComponentHolder).forEach(function (key) {
|
|
20
|
+
if (key === "default" || key === "__esModule") return;
|
|
21
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
22
|
+
if (key in exports && exports[key] === _CustomComponentHolder[key]) return;
|
|
23
|
+
Object.defineProperty(exports, key, {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () {
|
|
26
|
+
return _CustomComponentHolder[key];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
13
30
|
const _excluded = ["urlStrategy", "onRedirectTo", "renderByRoute", "customLoader", "customStyles", "contextOptions"];
|
|
14
31
|
const ShadowDomContext = /*#__PURE__*/(0, _react.createContext)({});
|
|
15
32
|
exports.ShadowDomContext = ShadowDomContext;
|
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/react-hooks",
|
|
3
|
-
"version": "6.104.0
|
|
3
|
+
"version": "6.104.0",
|
|
4
4
|
"main": "./node/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Frontegg LTD",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@babel/runtime": "^7.18.6",
|
|
9
|
-
"@frontegg/redux-store": "6.104.0
|
|
10
|
-
"@frontegg/types": "6.104.0
|
|
9
|
+
"@frontegg/redux-store": "6.104.0",
|
|
10
|
+
"@frontegg/types": "6.104.0",
|
|
11
11
|
"@types/react": "*",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"react-redux": "^7.x"
|