@tap-payments/apple-pay-button 0.0.3 → 0.0.4-staging
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/LICENSE +21 -21
- package/README.md +240 -194
- package/build/@types/ApplePayButtonProps.d.ts +129 -0
- package/build/@types/ApplePayButtonProps.js +1 -0
- package/build/@types/charge.d.ts +57 -0
- package/build/@types/charge.js +1 -0
- package/build/@types/checkoutProfile.d.ts +216 -0
- package/build/@types/checkoutProfile.js +1 -0
- package/build/@types/enums.d.ts +65 -0
- package/build/@types/enums.js +76 -0
- package/build/@types/index.d.ts +6 -82
- package/build/@types/index.js +6 -1
- package/build/@types/tapLocalisation.d.ts +193 -0
- package/build/@types/tapLocalisation.js +1 -0
- package/build/@types/tapTheme.d.ts +842 -0
- package/build/@types/tapTheme.js +1 -0
- package/build/api.d.ts +29 -0
- package/build/{api/app.service.js → api.js} +244 -253
- package/build/constants/index.d.ts +3 -51
- package/build/constants/index.js +3 -51
- package/build/features/ApplePayButton/ApplePayButton.d.ts +4 -6
- package/build/features/ApplePayButton/ApplePayButton.js +49 -80
- package/build/features/ApplePayButton/index.d.ts +3 -3
- package/build/features/ApplePayButton/index.js +2 -2
- package/build/hooks/index.d.ts +1 -1
- package/build/hooks/index.js +1 -1
- package/build/hooks/useApplePay.d.ts +93 -9
- package/build/hooks/useApplePay.js +449 -243
- package/build/hooks/useMerchantApplePay.d.ts +20 -0
- package/build/hooks/useMerchantApplePay.js +188 -0
- package/build/index.d.ts +4 -4
- package/build/index.js +13 -10
- package/build/utils/config.d.ts +14 -11
- package/build/utils/config.js +65 -72
- package/build/utils/defaultValues.d.ts +2 -0
- package/build/utils/defaultValues.js +27 -0
- package/build/utils/html.d.ts +1 -1
- package/build/utils/html.js +9 -9
- package/build/utils/index.d.ts +4 -1
- package/build/utils/index.js +4 -1
- package/build/utils/theme.d.ts +12 -0
- package/build/utils/theme.js +61 -0
- package/package.json +109 -104
- package/build/api/app.service.d.ts +0 -23
- package/build/api/base.d.ts +0 -9
- package/build/api/base.js +0 -45
- package/build/api/httpClient.d.ts +0 -8
- package/build/api/httpClient.js +0 -33
- package/build/features/ApplePayButton/ApplePayButton.css +0 -21
- package/build/hooks/useScript.d.ts +0 -1
- package/build/hooks/useScript.js +0 -39
package/package.json
CHANGED
|
@@ -1,104 +1,109 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@tap-payments/apple-pay-button",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Apple Pay Button React Component",
|
|
5
|
-
"main": "build/index.js",
|
|
6
|
-
"module": "build/index.js",
|
|
7
|
-
"types": "build/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"build",
|
|
10
|
-
"README.md"
|
|
11
|
-
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"prettier
|
|
16
|
-
"
|
|
17
|
-
"lint
|
|
18
|
-
"
|
|
19
|
-
"build": "cross-env NODE_ENV=production webpack",
|
|
20
|
-
"copy:files": "copyfiles -u 1 src/**/*.css build/",
|
|
21
|
-
"tsc:alias": "tsc-alias -p tsconfig.json",
|
|
22
|
-
"ts:build": "rm -rf build && tsc && yarn tsc:alias && yarn copy:files",
|
|
23
|
-
"push": "npm publish --access public --tag
|
|
24
|
-
},
|
|
25
|
-
"keywords": [],
|
|
26
|
-
"author": {
|
|
27
|
-
"name": "Ahmed Elsharkawy",
|
|
28
|
-
"email": "a.elsharkawy@tap.company"
|
|
29
|
-
},
|
|
30
|
-
"license": "ISC",
|
|
31
|
-
"
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"eslint-plugin
|
|
52
|
-
"eslint
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"webpack-
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
]
|
|
103
|
-
|
|
104
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@tap-payments/apple-pay-button",
|
|
3
|
+
"version": "0.0.4-staging",
|
|
4
|
+
"description": "Apple Pay Button React Component",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"module": "build/index.js",
|
|
7
|
+
"types": "build/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"build",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"start": "cross-env NODE_ENV=staging webpack serve",
|
|
14
|
+
"prepare": "npx husky install",
|
|
15
|
+
"prettier": "prettier --list-different \"src/**/*.{md,mdx,ts,js,tsx,jsx,json}\" *.json *.js",
|
|
16
|
+
"prettier:fix": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md,css,json}\" *.json *.js",
|
|
17
|
+
"lint": "eslint src --color --ext .js,.jsx,.ts,.tsx,.json",
|
|
18
|
+
"lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
|
|
19
|
+
"build": "cross-env NODE_ENV=production webpack",
|
|
20
|
+
"copy:files": "copyfiles -u 1 src/**/*.gif build/ && copyfiles -u 1 src/**/*.css build/",
|
|
21
|
+
"tsc:alias": "tsc-alias -p tsconfig.json",
|
|
22
|
+
"ts:build": "rm -rf build && tsc && yarn tsc:alias && yarn copy:files",
|
|
23
|
+
"push": "npm publish --access public --tag staging"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [],
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "Ahmed Elsharkawy",
|
|
28
|
+
"email": "a.elsharkawy@tap.company"
|
|
29
|
+
},
|
|
30
|
+
"license": "ISC",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@tap-payments/acceptance-sdk": "^0.0.46",
|
|
33
|
+
"@tap-payments/browser-info": "^1.0.2",
|
|
34
|
+
"@tap-payments/web-error-handing": "^1.0.1",
|
|
35
|
+
"axios": "^1.2.2",
|
|
36
|
+
"framer-motion": "^10.16.5",
|
|
37
|
+
"jsencrypt": "^3.3.2",
|
|
38
|
+
"lottie-react": "^2.4.0",
|
|
39
|
+
"react": "^18.2.0",
|
|
40
|
+
"react-dom": "^18.2.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@babel/core": "^7.18.6",
|
|
44
|
+
"@babel/preset-env": "^7.18.6",
|
|
45
|
+
"@babel/preset-react": "^7.18.6",
|
|
46
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
47
|
+
"@types/applepayjs": "^14.0.3",
|
|
48
|
+
"@types/crypto-js": "^4.1.1",
|
|
49
|
+
"@types/react": "^18.0.15",
|
|
50
|
+
"@types/react-dom": "^18.0.6",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^5.30.5",
|
|
52
|
+
"@typescript-eslint/parser": "^5.30.5",
|
|
53
|
+
"babel-loader": "^8.2.5",
|
|
54
|
+
"copyfiles": "^2.4.1",
|
|
55
|
+
"cross-env": "^7.0.3",
|
|
56
|
+
"css-loader": "^6.7.1",
|
|
57
|
+
"css-minimizer-webpack-plugin": "^4.0.0",
|
|
58
|
+
"eslint": "^8.19.0",
|
|
59
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
60
|
+
"eslint-config-prettier": "^8.5.0",
|
|
61
|
+
"eslint-plugin-import": "^2.26.0",
|
|
62
|
+
"eslint-plugin-jsx-a11y": "^6.6.0",
|
|
63
|
+
"eslint-plugin-node": "^11.1.0",
|
|
64
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
65
|
+
"eslint-plugin-react": "^7.30.1",
|
|
66
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
67
|
+
"file-loader": "^6.2.0",
|
|
68
|
+
"fork-ts-checker-webpack-plugin": "^7.2.12",
|
|
69
|
+
"html-loader": "^3.1.2",
|
|
70
|
+
"html-webpack-plugin": "^5.5.0",
|
|
71
|
+
"husky": "^8.0.1",
|
|
72
|
+
"lint-staged": "^13.0.3",
|
|
73
|
+
"mini-css-extract-plugin": "^2.6.1",
|
|
74
|
+
"prettier": "^2.7.1",
|
|
75
|
+
"sass": "^1.53.0",
|
|
76
|
+
"sass-loader": "^13.0.2",
|
|
77
|
+
"style-loader": "^3.3.1",
|
|
78
|
+
"terser-webpack-plugin": "^5.3.3",
|
|
79
|
+
"tsc-alias": "^1.6.11",
|
|
80
|
+
"typescript": "^4.7.4",
|
|
81
|
+
"webpack": "^5.73.0",
|
|
82
|
+
"webpack-cli": "^4.10.0",
|
|
83
|
+
"webpack-dev-server": "^4.9.3",
|
|
84
|
+
"webpack-merge": "^5.8.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": ">=17.0.2",
|
|
88
|
+
"react-dom": ">=17.0.2"
|
|
89
|
+
},
|
|
90
|
+
"lint-staged": {
|
|
91
|
+
"src/**/*.{ts,tsx,json,js,jsx}": [
|
|
92
|
+
"yarn run prettier:fix",
|
|
93
|
+
"yarn run lint",
|
|
94
|
+
"git add ."
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
"browserslist": {
|
|
98
|
+
"production": [
|
|
99
|
+
">0.2%",
|
|
100
|
+
"not dead",
|
|
101
|
+
"not op_mini all"
|
|
102
|
+
],
|
|
103
|
+
"development": [
|
|
104
|
+
"last 1 chrome version",
|
|
105
|
+
"last 1 firefox version",
|
|
106
|
+
"last 1 safari version"
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { MerchantResponse, ApplePayButtonProps } from '../@types';
|
|
2
|
-
import BaseService from './base';
|
|
3
|
-
declare class APPService extends BaseService {
|
|
4
|
-
private baseUrl;
|
|
5
|
-
private env;
|
|
6
|
-
constructor();
|
|
7
|
-
setEnv(env: ApplePayButtonProps['environment']): void;
|
|
8
|
-
setBaseUrl(): void;
|
|
9
|
-
getHeaderPublicKey(): "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8AX++RtxPZFtns4XzXFlDIxPBh0umN4qRXZaKDIlb6a3MknaB7psJWmf2l+e4Cfh9b5tey/+rZqpQ065eXTZfGCAuBLt+fYLQBhLfjRpk8S6hlIzc1Kdjg65uqzMwcTd0p7I4KLwHk1I0oXzuEu53fU1LSZhWp4Mnd6wjVgXAsQIDAQAB\n-----END PUBLIC KEY-----" | "" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
|
|
10
|
-
setBrowserHeaders({ locale, pk, domain }: {
|
|
11
|
-
locale: string;
|
|
12
|
-
pk: string;
|
|
13
|
-
domain: string;
|
|
14
|
-
}): Promise<void>;
|
|
15
|
-
checkoutProfile(merchantId?: string): Promise<{
|
|
16
|
-
merchant: any;
|
|
17
|
-
payment_options: any;
|
|
18
|
-
}>;
|
|
19
|
-
appleSession(merchant: MerchantResponse, validationURL: string, merchantRegisteredDomain: string, merchantIdentifier: string): Promise<any>;
|
|
20
|
-
tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
|
|
21
|
-
}
|
|
22
|
-
declare const appService: APPService;
|
|
23
|
-
export default appService;
|
package/build/api/base.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
-
export default class BaseService {
|
|
3
|
-
httpClient: AxiosInstance;
|
|
4
|
-
constructor(httpClient: AxiosInstance);
|
|
5
|
-
get(url: string, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
6
|
-
post(url: string, data?: any, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
7
|
-
put(url: string, data?: any, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
8
|
-
delete(url: string, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
9
|
-
}
|
package/build/api/base.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
var BaseService = (function () {
|
|
2
|
-
function BaseService(httpClient) {
|
|
3
|
-
Object.defineProperty(this, "httpClient", {
|
|
4
|
-
enumerable: true,
|
|
5
|
-
configurable: true,
|
|
6
|
-
writable: true,
|
|
7
|
-
value: void 0
|
|
8
|
-
});
|
|
9
|
-
this.httpClient = httpClient;
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(BaseService.prototype, "get", {
|
|
12
|
-
enumerable: false,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: function (url, config) {
|
|
16
|
-
return this.httpClient.get(url, config);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(BaseService.prototype, "post", {
|
|
20
|
-
enumerable: false,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: function (url, data, config) {
|
|
24
|
-
return this.httpClient.post(url, data, config);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(BaseService.prototype, "put", {
|
|
28
|
-
enumerable: false,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: function (url, data, config) {
|
|
32
|
-
return this.httpClient.put(url, data, config);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(BaseService.prototype, "delete", {
|
|
36
|
-
enumerable: false,
|
|
37
|
-
configurable: true,
|
|
38
|
-
writable: true,
|
|
39
|
-
value: function (url, config) {
|
|
40
|
-
return this.httpClient.delete(url, config);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return BaseService;
|
|
44
|
-
}());
|
|
45
|
-
export default BaseService;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare const MW_BASE_LIVE_URL = "https://mw-sdk.tap.company/v2/checkout";
|
|
2
|
-
export declare const MW_BASE_STAGING_URL = "https://mw-sdk.staing.tap.company/v2/checkout";
|
|
3
|
-
export declare const MW_BASE_DEV_URL = "https://mw-sdk.dev.tap.company/v2/checkout";
|
|
4
|
-
export declare const MW_BASE_BETA_URL = "https://mw-sdk.dev.tap.company/v2/checkout";
|
|
5
|
-
export declare const MW_BASE_SANDBOX_URL = "https://mw-sdk.sandbox.tap.company/v2/checkout";
|
|
6
|
-
declare const httpClient: import("axios").AxiosInstance;
|
|
7
|
-
export declare const setAxiosGlobalHeaders: (headers: Record<string, string>) => void;
|
|
8
|
-
export default httpClient;
|
package/build/api/httpClient.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import axios from 'axios';
|
|
13
|
-
export var MW_BASE_LIVE_URL = 'https://mw-sdk.tap.company/v2/checkout';
|
|
14
|
-
export var MW_BASE_STAGING_URL = 'https://mw-sdk.staing.tap.company/v2/checkout';
|
|
15
|
-
export var MW_BASE_DEV_URL = 'https://mw-sdk.dev.tap.company/v2/checkout';
|
|
16
|
-
export var MW_BASE_BETA_URL = 'https://mw-sdk.dev.tap.company/v2/checkout';
|
|
17
|
-
export var MW_BASE_SANDBOX_URL = 'https://mw-sdk.sandbox.tap.company/v2/checkout';
|
|
18
|
-
var httpClient = axios.create({
|
|
19
|
-
headers: {
|
|
20
|
-
'Content-Type': 'application/json',
|
|
21
|
-
Accept: 'application/json'
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
httpClient.interceptors.request.use(function (config) {
|
|
25
|
-
return config;
|
|
26
|
-
});
|
|
27
|
-
httpClient.interceptors.response.use(function (response) {
|
|
28
|
-
return response;
|
|
29
|
-
});
|
|
30
|
-
export var setAxiosGlobalHeaders = function (headers) {
|
|
31
|
-
httpClient.defaults.headers.common = __assign(__assign({}, httpClient.defaults.headers.common), headers);
|
|
32
|
-
};
|
|
33
|
-
export default httpClient;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
.button-applepay-tap {
|
|
2
|
-
-webkit-appearance: -apple-pay-button;
|
|
3
|
-
display: block;
|
|
4
|
-
width: 100%;
|
|
5
|
-
height: 48px;
|
|
6
|
-
min-height: 30px;
|
|
7
|
-
cursor: pointer;
|
|
8
|
-
}
|
|
9
|
-
.button-applepay-tap:disabled {
|
|
10
|
-
cursor: default;
|
|
11
|
-
}
|
|
12
|
-
.black {
|
|
13
|
-
-apple-pay-button-style: black;
|
|
14
|
-
}
|
|
15
|
-
.white {
|
|
16
|
-
-apple-pay-button-style: white;
|
|
17
|
-
}
|
|
18
|
-
.whiteOutline {
|
|
19
|
-
-apple-pay-button-style: white;
|
|
20
|
-
border: solid 1px gray;
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useScript(src: string, async?: boolean): "loading" | "ready" | "idle" | "error";
|
package/build/hooks/useScript.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
export function useScript(src, async) {
|
|
3
|
-
if (async === void 0) { async = true; }
|
|
4
|
-
var _a = useState(src ? 'loading' : 'idle'), status = _a[0], setStatus = _a[1];
|
|
5
|
-
useEffect(function () {
|
|
6
|
-
if (!src) {
|
|
7
|
-
setStatus('idle');
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
var script = document.querySelector("script[src=\"".concat(src, "\"]"));
|
|
11
|
-
if (!script) {
|
|
12
|
-
script = document.createElement('script');
|
|
13
|
-
script.src = src;
|
|
14
|
-
script.async = async;
|
|
15
|
-
script.setAttribute('data-status', 'loading');
|
|
16
|
-
document.body.appendChild(script);
|
|
17
|
-
var setAttributeFromEvent = function (event) {
|
|
18
|
-
script.setAttribute('data-status', event.type === 'load' ? 'ready' : 'error');
|
|
19
|
-
};
|
|
20
|
-
script.addEventListener('load', setAttributeFromEvent);
|
|
21
|
-
script.addEventListener('error', setAttributeFromEvent);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
setStatus(script.getAttribute('data-status'));
|
|
25
|
-
}
|
|
26
|
-
var setStateFromEvent = function (event) {
|
|
27
|
-
setStatus(event.type === 'load' ? 'ready' : 'error');
|
|
28
|
-
};
|
|
29
|
-
script.addEventListener('load', setStateFromEvent);
|
|
30
|
-
script.addEventListener('error', setStateFromEvent);
|
|
31
|
-
return function () {
|
|
32
|
-
if (script) {
|
|
33
|
-
script.removeEventListener('load', setStateFromEvent);
|
|
34
|
-
script.removeEventListener('error', setStateFromEvent);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}, [src]);
|
|
38
|
-
return status;
|
|
39
|
-
}
|