@atls/react-app-links 0.0.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/app-link.component.js +15 -0
- package/dist/app-url.interfaces.js +2 -0
- package/dist/index.js +15 -0
- package/dist/use-app-url.hook.js +17 -0
- package/dist/use-browser-effect.hook.js +11 -0
- package/package.json +36 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppLink = void 0;
|
|
4
|
+
const use_app_url_hook_1 = require("./use-app-url.hook");
|
|
5
|
+
const AppLink = ({ children, subdomain, pathname }) => {
|
|
6
|
+
const url = (0, use_app_url_hook_1.useAppUrl)({ subdomain, pathname });
|
|
7
|
+
if (!children || !url) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
if (typeof children !== 'function') {
|
|
11
|
+
throw new Error('AppLink - children must be a function.');
|
|
12
|
+
}
|
|
13
|
+
return children(url);
|
|
14
|
+
};
|
|
15
|
+
exports.AppLink = AppLink;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./app-link.component"), exports);
|
|
14
|
+
__exportStar(require("./app-url.interfaces"), exports);
|
|
15
|
+
__exportStar(require("./use-app-url.hook"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAppUrl = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const tldjs_1 = require("tldjs");
|
|
6
|
+
const use_browser_effect_hook_1 = require("./use-browser-effect.hook");
|
|
7
|
+
const useAppUrl = ({ subdomain, pathname = '/' } = {}) => {
|
|
8
|
+
const [url, setUrl] = (0, react_1.useState)(null);
|
|
9
|
+
(0, use_browser_effect_hook_1.useBrowserEffect)(() => {
|
|
10
|
+
const { hostname, protocol } = window.location;
|
|
11
|
+
const domain = (0, tldjs_1.getDomain)(hostname);
|
|
12
|
+
const origin = subdomain ? `${protocol}//${subdomain}.${domain}` : `${protocol}//${domain}`;
|
|
13
|
+
setUrl(`${origin}${pathname}`);
|
|
14
|
+
}, [subdomain, pathname]);
|
|
15
|
+
return url;
|
|
16
|
+
};
|
|
17
|
+
exports.useAppUrl = useAppUrl;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBrowserEffect = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useBrowserEffect = (effect, deps) => {
|
|
6
|
+
if (typeof window === 'undefined') {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return (0, react_1.useEffect)(effect, deps);
|
|
10
|
+
};
|
|
11
|
+
exports.useBrowserEffect = useBrowserEffect;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atls/react-app-links",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"license": "BSD-3-Clause",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "yarn library build",
|
|
11
|
+
"prepack": "yarn run build",
|
|
12
|
+
"postpack": "rm -rf dist"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"tldjs": "^2.3.1"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@testing-library/jest-dom": "^5.16.1",
|
|
19
|
+
"@testing-library/react": "^12.1.2",
|
|
20
|
+
"@testing-library/react-hooks": "^7.0.2",
|
|
21
|
+
"@types/react": "^17.0.38",
|
|
22
|
+
"@types/react-dom": "^17.0.11",
|
|
23
|
+
"@types/testing-library__jest-dom": "^5.14.2",
|
|
24
|
+
"react": "^17.0.2",
|
|
25
|
+
"react-dom": "^17.0.2"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": "^17.0.1"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"main": "dist/index.js",
|
|
33
|
+
"typings": "dist/index.d.ts"
|
|
34
|
+
},
|
|
35
|
+
"typings": "dist/index.d.ts"
|
|
36
|
+
}
|