@prosopo/procaptcha-bundle 0.1.15 → 0.1.17
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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -20
- package/dist/index.js.map +1 -1
- package/package.json +18 -46
- package/src/index.html +11 -0
- package/src/index.tsx +125 -0
- package/tsconfig.json +27 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vite.config.ts +47 -0
- package/dist/index.html +0 -1
- package/dist/index.html.gz +0 -0
- package/dist/procaptcha_bundle.main.bundle.js +0 -102
- package/dist/procaptcha_bundle.main.bundle.js.LICENSE.txt +0 -61
- package/dist/procaptcha_bundle.main.bundle.js.LICENSE.txt.gz +0 -0
- package/dist/procaptcha_bundle.main.bundle.js.gz +0 -0
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAuB,mBAAmB,EAA4B,MAAM,qBAAqB,CAAA;AAqDxG,wBAAgB,MAAM,CAAC,SAAS,CAAC,EAAE,mBAAmB,QA0CrD;AAGD,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,KAAA,QAS/B"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
2
15
|
import { ApiParams, EnvironmentTypesSchema } from '@prosopo/types';
|
|
3
|
-
import {
|
|
16
|
+
import { LogLevelSchema } from '@prosopo/common';
|
|
17
|
+
import { ProcapchaEventNames } from '@prosopo/procaptcha';
|
|
4
18
|
import { Procaptcha } from '@prosopo/procaptcha-react';
|
|
5
19
|
import { createRoot } from 'react-dom/client';
|
|
6
20
|
function getConfig(siteKey) {
|
|
@@ -8,7 +22,7 @@ function getConfig(siteKey) {
|
|
|
8
22
|
siteKey = process.env.DAPP_SITE_KEY || process.env.PROSOPO_SITE_KEY || '';
|
|
9
23
|
}
|
|
10
24
|
return {
|
|
11
|
-
logLevel:
|
|
25
|
+
logLevel: LogLevelSchema.enum.Info,
|
|
12
26
|
defaultEnvironment: process.env.DEFAULT_ENVIRONMENT || EnvironmentTypesSchema.enum.development,
|
|
13
27
|
userAccountAddress: '',
|
|
14
28
|
web2: true,
|
|
@@ -25,8 +39,17 @@ function getConfig(siteKey) {
|
|
|
25
39
|
},
|
|
26
40
|
accounts: [],
|
|
27
41
|
},
|
|
42
|
+
[EnvironmentTypesSchema.enum.rococo]: {
|
|
43
|
+
endpoint: process.env.SUBSTRATE_NODE_URL || 'wss://rococo-contracts-rpc.polkadot.io:443',
|
|
44
|
+
contract: {
|
|
45
|
+
address: process.env.PROTOCOL_CONTRACT_ADDRESS || '5HiVWQhJrysNcFNEWf2crArKht16zrhro3FcekVWocyQjx5u',
|
|
46
|
+
name: 'prosopo',
|
|
47
|
+
},
|
|
48
|
+
accounts: [],
|
|
49
|
+
},
|
|
28
50
|
},
|
|
29
51
|
solutionThreshold: 80,
|
|
52
|
+
serverUrl: process.env.SERVER_URL || '',
|
|
30
53
|
};
|
|
31
54
|
}
|
|
32
55
|
function getParentForm(element) {
|
|
@@ -39,33 +62,43 @@ function getParentForm(element) {
|
|
|
39
62
|
}
|
|
40
63
|
return null;
|
|
41
64
|
}
|
|
42
|
-
export function render() {
|
|
65
|
+
export function render(callbacks) {
|
|
43
66
|
const elements = Array.from(document.getElementsByClassName('procaptcha'));
|
|
44
67
|
const siteKey = elements[0].getAttribute('data-sitekey') || undefined;
|
|
45
68
|
const config = getConfig(siteKey);
|
|
46
|
-
|
|
69
|
+
if (!callbacks) {
|
|
70
|
+
callbacks = {};
|
|
71
|
+
}
|
|
47
72
|
for (const element of elements) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
|
|
73
|
+
// get the custom callback functions for procaptcha events, if set
|
|
74
|
+
for (const callbackName of ProcapchaEventNames) {
|
|
75
|
+
const dataCallbackName = `data-${callbackName.toLowerCase()}`; // e.g. data-onhuman
|
|
76
|
+
const callback = element.getAttribute(dataCallbackName);
|
|
77
|
+
if (callback) {
|
|
78
|
+
callbacks[callbackName] = window[callback.replace('window.', '')];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// get the custom theme, if set
|
|
82
|
+
const customTheme = element.getAttribute(`data-custom-theme`);
|
|
83
|
+
if (customTheme) {
|
|
84
|
+
config['sx'] = JSON.parse(customTheme);
|
|
85
|
+
}
|
|
86
|
+
// set a default callback for onHuman, if not set
|
|
87
|
+
if (!callbacks['onHuman']) {
|
|
88
|
+
// append the prosopo payload to the containing form
|
|
89
|
+
callbacks['onHuman'] = function (payload) {
|
|
52
90
|
// get form
|
|
53
91
|
const form = getParentForm(element);
|
|
54
92
|
// add a listener to the onSubmit event of the form
|
|
55
93
|
if (form) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
(input.name = ApiParams.procaptchaResponse), (input.value = JSON.stringify(payload));
|
|
62
|
-
form.appendChild(input);
|
|
63
|
-
// submit the form
|
|
64
|
-
form.submit();
|
|
65
|
-
});
|
|
94
|
+
// add the payload to the form
|
|
95
|
+
const input = document.createElement('input');
|
|
96
|
+
input.type = 'hidden';
|
|
97
|
+
(input.name = ApiParams.procaptchaResponse), (input.value = JSON.stringify(payload));
|
|
98
|
+
form.appendChild(input);
|
|
66
99
|
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
69
102
|
const root = createRoot(element);
|
|
70
103
|
root.render(_jsx(Procaptcha, { config: config, callbacks: callbacks })); //wrap in fn and give user access to func
|
|
71
104
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAoB,sBAAsB,EAAoB,MAAM,gBAAgB,CAAA;AACtG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EAAE,SAAS,EAAoB,sBAAsB,EAAoB,MAAM,gBAAgB,CAAA;AACtG,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,mBAAmB,EAAiD,MAAM,qBAAqB,CAAA;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,SAAS,SAAS,CAAC,OAAgB;IAC/B,IAAI,CAAC,OAAO,EAAE;QACV,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,OAAO,CAA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M,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;oBAC7C,KAAK,CAAC,IAAI,GAAG,QAAQ,CACpB;oBAAA,CAAC,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,kBAAkB,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;oBACrF,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;iBAC1B;YACL,CAAC,CAAA;SACJ;QACD,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;QAChC,IAAI,CAAC,MAAM,CAAC,KAAC,UAAU,IAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAI,CAAC,CAAA,CAAC,yCAAyC;KAC9G;AACL,CAAC;AAED,uGAAuG;AACvG,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE;IAC5B,IAAI,QAAQ,IAAI,QAAQ,CAAC,UAAU,IAAI,SAAS,EAAE;QAC9C,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;QACzC,EAAE,EAAE,CAAA;KACP;SAAM;QACH,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;QACzC,kDAAkD;QAClD,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAA;KACpD;AACL,CAAC;AAED,KAAK,CAAC,MAAM,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/procaptcha-bundle",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"source": "./src/index.
|
|
9
|
+
"source": "./src/index.tsx",
|
|
9
10
|
"scripts": {
|
|
10
11
|
"clean": "tsc --build --clean",
|
|
11
12
|
"build": "tsc --build --verbose",
|
|
12
|
-
"start": "
|
|
13
|
-
"build:
|
|
14
|
-
"build:
|
|
15
|
-
"build:webpack:dev": "webpack --mode development",
|
|
16
|
-
"build:webpack:dev:copy": "webpack --mode development && cp dist/procaptcha_bundle.main.bundle.js ../../demos/client-bundle-example/src",
|
|
13
|
+
"start": "vite serve --mode development --host",
|
|
14
|
+
"build:dev": "npm run build && vite build --mode development --debug",
|
|
15
|
+
"build:prod": "npm run build && vite build --mode production",
|
|
17
16
|
"lint": "npx eslint .",
|
|
18
|
-
"lint:fix": "npx eslint . --fix"
|
|
17
|
+
"lint:fix": "npx eslint . --fix --config ../../.eslintrc.js"
|
|
19
18
|
},
|
|
20
19
|
"browserslist": [
|
|
21
20
|
"> 0.5%, last 2 versions, not dead"
|
|
22
21
|
],
|
|
23
22
|
"dependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
23
|
+
"@emotion/react": "^11.11.1",
|
|
24
|
+
"@emotion/styled": "^11.11.0",
|
|
25
|
+
"@mui/icons-material": "^5.14.3",
|
|
26
|
+
"@mui/material": "^5.14.5",
|
|
27
|
+
"@prosopo/common": "^0.1.17",
|
|
28
|
+
"@prosopo/procaptcha-react": "^0.1.17"
|
|
26
29
|
},
|
|
27
30
|
"repository": {
|
|
28
31
|
"type": "git",
|
|
@@ -37,41 +40,10 @@
|
|
|
37
40
|
"registry": "https://registry.npmjs.org"
|
|
38
41
|
},
|
|
39
42
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"@babel/preset-typescript": "^7.21.5",
|
|
46
|
-
"@rollup/plugin-babel": "^6.0.3",
|
|
47
|
-
"@rollup/plugin-commonjs": "^24.1.0",
|
|
48
|
-
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
49
|
-
"@types/react": "^18.2.7",
|
|
50
|
-
"@types/react-dom": "^18.2.4",
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "^5.59.5",
|
|
52
|
-
"@typescript-eslint/parser": "^5.30.7",
|
|
53
|
-
"babel-loader": "^9.1.2",
|
|
54
|
-
"babel-plugin-lodash": "^3.3.4",
|
|
55
|
-
"compression-webpack-plugin": "^10.0.0",
|
|
56
|
-
"css-loader": "^6.7.3",
|
|
57
|
-
"dotenv-webpack": "^8.0.1",
|
|
58
|
-
"eslint": "^8.40.0",
|
|
59
|
-
"eslint-config-prettier": "^8.5.0",
|
|
60
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
61
|
-
"eslint-plugin-unused-imports": "^2.0.0",
|
|
62
|
-
"eslint-webpack-plugin": "^4.0.1",
|
|
63
|
-
"html-webpack-plugin": "^5.5.1",
|
|
64
|
-
"mini-css-extract-plugin": "^2.7.5",
|
|
65
|
-
"parcel": "^2.8.3",
|
|
66
|
-
"react": "^18.2.0",
|
|
67
|
-
"react-dom": "^18.2.0",
|
|
68
|
-
"style-loader": "^3.3.2",
|
|
69
|
-
"terser-webpack-plugin": "^5.3.7",
|
|
70
|
-
"typescript": "^4.7.4",
|
|
71
|
-
"webpack": "^5.82.0",
|
|
72
|
-
"webpack-bundle-analyzer": "^4.8.0",
|
|
73
|
-
"webpack-dev-server": "^4.13.3",
|
|
74
|
-
"webpack-json-access-optimizer": "^1.1.0",
|
|
75
|
-
"webpack-cli": "^5.1.1"
|
|
43
|
+
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
44
|
+
"@prosopo/config": "^0.1.17",
|
|
45
|
+
"@rollup/plugin-typescript": "^11.1.2",
|
|
46
|
+
"@vitejs/plugin-react": "^4.0.4",
|
|
47
|
+
"webpack-merge": "^5.9.0"
|
|
76
48
|
}
|
|
77
49
|
}
|
package/src/index.html
ADDED
package/src/index.tsx
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { ApiParams, EnvironmentTypes, EnvironmentTypesSchema, ProcaptchaOutput } from '@prosopo/types'
|
|
15
|
+
import { LogLevelSchema } from '@prosopo/common'
|
|
16
|
+
import { ProcapchaEventNames, ProcaptchaCallbacks, ProcaptchaConfigOptional } from '@prosopo/procaptcha'
|
|
17
|
+
import { Procaptcha } from '@prosopo/procaptcha-react'
|
|
18
|
+
import { createRoot } from 'react-dom/client'
|
|
19
|
+
|
|
20
|
+
function getConfig(siteKey?: string): ProcaptchaConfigOptional {
|
|
21
|
+
if (!siteKey) {
|
|
22
|
+
siteKey = process.env.DAPP_SITE_KEY || process.env.PROSOPO_SITE_KEY || ''
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
logLevel: LogLevelSchema.enum.Info,
|
|
26
|
+
defaultEnvironment:
|
|
27
|
+
(process.env.DEFAULT_ENVIRONMENT as EnvironmentTypes) || EnvironmentTypesSchema.enum.development,
|
|
28
|
+
userAccountAddress: '',
|
|
29
|
+
web2: true,
|
|
30
|
+
dappName: 'Prosopo',
|
|
31
|
+
account: {
|
|
32
|
+
address: siteKey,
|
|
33
|
+
},
|
|
34
|
+
networks: {
|
|
35
|
+
[EnvironmentTypesSchema.enum.development]: {
|
|
36
|
+
endpoint: process.env.SUBSTRATE_NODE_URL || 'ws://127.0.0.1:9944',
|
|
37
|
+
contract: {
|
|
38
|
+
address: process.env.PROTOCOL_CONTRACT_ADDRESS || '',
|
|
39
|
+
name: 'prosopo',
|
|
40
|
+
},
|
|
41
|
+
accounts: [],
|
|
42
|
+
},
|
|
43
|
+
[EnvironmentTypesSchema.enum.rococo]: {
|
|
44
|
+
endpoint: process.env.SUBSTRATE_NODE_URL || 'wss://rococo-contracts-rpc.polkadot.io:443',
|
|
45
|
+
contract: {
|
|
46
|
+
address:
|
|
47
|
+
process.env.PROTOCOL_CONTRACT_ADDRESS || '5HiVWQhJrysNcFNEWf2crArKht16zrhro3FcekVWocyQjx5u',
|
|
48
|
+
name: 'prosopo',
|
|
49
|
+
},
|
|
50
|
+
accounts: [],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
solutionThreshold: 80,
|
|
54
|
+
serverUrl: process.env.SERVER_URL || '',
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getParentForm(element: Element): HTMLFormElement | null {
|
|
59
|
+
let parent = element.parentElement
|
|
60
|
+
while (parent) {
|
|
61
|
+
if (parent.tagName === 'FORM') {
|
|
62
|
+
return parent as HTMLFormElement
|
|
63
|
+
}
|
|
64
|
+
parent = parent.parentElement
|
|
65
|
+
}
|
|
66
|
+
return null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function render(callbacks?: ProcaptchaCallbacks) {
|
|
70
|
+
const elements: Element[] = Array.from(document.getElementsByClassName('procaptcha'))
|
|
71
|
+
const siteKey = elements[0].getAttribute('data-sitekey') || undefined
|
|
72
|
+
const config = getConfig(siteKey)
|
|
73
|
+
if (!callbacks) {
|
|
74
|
+
callbacks = {}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (const element of elements) {
|
|
78
|
+
// get the custom callback functions for procaptcha events, if set
|
|
79
|
+
for (const callbackName of ProcapchaEventNames) {
|
|
80
|
+
const dataCallbackName = `data-${callbackName.toLowerCase()}` // e.g. data-onhuman
|
|
81
|
+
const callback = element.getAttribute(dataCallbackName)
|
|
82
|
+
if (callback) {
|
|
83
|
+
callbacks[callbackName] = window[callback.replace('window.', '')]
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// get the custom theme, if set
|
|
87
|
+
const customTheme = element.getAttribute(`data-custom-theme`)
|
|
88
|
+
if (customTheme) {
|
|
89
|
+
config['sx'] = JSON.parse(customTheme)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// set a default callback for onHuman, if not set
|
|
93
|
+
if (!callbacks['onHuman']) {
|
|
94
|
+
// append the prosopo payload to the containing form
|
|
95
|
+
callbacks['onHuman'] = function (payload: ProcaptchaOutput) {
|
|
96
|
+
// get form
|
|
97
|
+
const form = getParentForm(element)
|
|
98
|
+
// add a listener to the onSubmit event of the form
|
|
99
|
+
if (form) {
|
|
100
|
+
// add the payload to the form
|
|
101
|
+
const input = document.createElement('input')
|
|
102
|
+
input.type = 'hidden'
|
|
103
|
+
;(input.name = ApiParams.procaptchaResponse), (input.value = JSON.stringify(payload))
|
|
104
|
+
form.appendChild(input)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const root = createRoot(element)
|
|
109
|
+
root.render(<Procaptcha config={config} callbacks={callbacks} />) //wrap in fn and give user access to func
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
//https://stackoverflow.com/questions/41174095/do-i-need-to-use-onload-to-start-my-webpack-bundled-code
|
|
114
|
+
export default function ready(fn) {
|
|
115
|
+
if (document && document.readyState != 'loading') {
|
|
116
|
+
console.log('document.readyState ready!')
|
|
117
|
+
fn()
|
|
118
|
+
} else {
|
|
119
|
+
console.log('DOMContentLoaded listener!')
|
|
120
|
+
// note sure if this is the correct event listener
|
|
121
|
+
document.addEventListener('DOMContentLoaded', fn)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
ready(render)
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.build.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"module": "esnext",
|
|
7
|
+
"target": "esnext",
|
|
8
|
+
"lib": [
|
|
9
|
+
"es6",
|
|
10
|
+
"dom"
|
|
11
|
+
],
|
|
12
|
+
"jsx": "react-jsx"
|
|
13
|
+
},
|
|
14
|
+
"include": [
|
|
15
|
+
"src/index.tsx",
|
|
16
|
+
"src/index.html"
|
|
17
|
+
],
|
|
18
|
+
"references": [
|
|
19
|
+
{
|
|
20
|
+
"path": "../../dev/config"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
|
|
24
|
+
"path": "../procaptcha-react"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|