@prosopo/procaptcha-react 0.2.29 → 0.2.32

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.
Files changed (30) hide show
  1. package/dist/cjs/components/CaptchaComponent.cjs +41 -64
  2. package/dist/cjs/components/CaptchaWidget.cjs +37 -43
  3. package/dist/cjs/components/ExtensionAccountSelect.cjs +26 -26
  4. package/dist/cjs/components/Procaptcha.cjs +134 -140
  5. package/dist/cjs/components/theme.cjs +12 -27
  6. package/dist/components/CaptchaComponent.d.ts.map +1 -1
  7. package/dist/components/CaptchaComponent.js +43 -43
  8. package/dist/components/CaptchaComponent.js.map +1 -1
  9. package/dist/components/CaptchaPlaceholder.d.ts +6 -0
  10. package/dist/components/CaptchaPlaceholder.d.ts.map +1 -0
  11. package/dist/components/CaptchaPlaceholder.js +77 -0
  12. package/dist/components/CaptchaPlaceholder.js.map +1 -0
  13. package/dist/components/Procaptcha.d.ts +5 -6
  14. package/dist/components/Procaptcha.d.ts.map +1 -1
  15. package/dist/components/Procaptcha.js +6 -168
  16. package/dist/components/Procaptcha.js.map +1 -1
  17. package/dist/components/ProcaptchaWidget.d.ts +8 -0
  18. package/dist/components/ProcaptchaWidget.d.ts.map +1 -0
  19. package/dist/components/ProcaptchaWidget.js +170 -0
  20. package/dist/components/ProcaptchaWidget.js.map +1 -0
  21. package/dist/components/index.d.ts +2 -0
  22. package/dist/components/index.d.ts.map +1 -1
  23. package/dist/components/index.js +2 -0
  24. package/dist/components/index.js.map +1 -1
  25. package/package.json +7 -9
  26. package/dist/cjs/components/Button.cjs +0 -68
  27. package/dist/cjs/components/Checkbox.cjs +0 -56
  28. package/dist/cjs/components/LoadingSpinner.cjs +0 -30
  29. package/dist/cjs/components/Modal.cjs +0 -35
  30. package/dist/cjs/components/collector.cjs +0 -25
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
- const jsxRuntime = require("@emotion/react/jsx-runtime");
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const material = require("@mui/material");
3
4
  const CaptchaWidget = require("./CaptchaWidget.cjs");
4
5
  const util = require("@prosopo/util");
5
6
  const theme = require("./theme.cjs");
6
- const React = require("react");
7
+ const react = require("react");
7
8
  const common = require("@prosopo/common");
8
- const Button = require("./Button.cjs");
9
9
  const index = require("../util/index.cjs");
10
10
  const CaptchaComponent = ({
11
11
  challenge,
@@ -20,48 +20,46 @@ const CaptchaComponent = ({
20
20
  const { t } = common.useTranslation();
21
21
  const captcha = challenge.captchas ? util.at(challenge.captchas, index$1) : null;
22
22
  const solution = solutions ? util.at(solutions, index$1) : [];
23
- const theme$1 = React.useMemo(() => themeColor === "light" ? theme.lightTheme : theme.darkTheme, [themeColor]);
23
+ const theme$1 = react.useMemo(() => themeColor === "light" ? theme.lightTheme : theme.darkTheme, [themeColor]);
24
24
  return /* @__PURE__ */ jsxRuntime.jsx(
25
- "div",
25
+ material.Box,
26
26
  {
27
- style: {
27
+ sx: {
28
28
  // introduce scroll bars when screen < minWidth of children
29
29
  overflowX: "auto",
30
30
  overflowY: "auto",
31
31
  width: "100%",
32
32
  maxWidth: "500px",
33
- maxHeight: "100%",
34
- display: "flex",
35
- flexDirection: "column"
33
+ maxHeight: "100%"
36
34
  },
37
35
  children: /* @__PURE__ */ jsxRuntime.jsxs(
38
- "div",
36
+ material.Box,
39
37
  {
40
- style: {
41
- backgroundColor: theme$1.palette.background.default,
38
+ bgcolor: theme$1.palette.background.default,
39
+ sx: {
42
40
  display: "flex",
43
41
  flexDirection: "column",
44
42
  minWidth: "300px"
45
43
  },
46
44
  children: [
47
45
  /* @__PURE__ */ jsxRuntime.jsxs(
48
- "div",
46
+ material.Box,
49
47
  {
50
- style: {
48
+ px: 2,
49
+ py: 3,
50
+ sx: {
51
51
  display: "flex",
52
52
  alignItems: "center",
53
- width: "100%",
54
- backgroundColor: theme$1.palette.primary.main,
55
- padding: "24px 16px"
53
+ width: "100%"
56
54
  },
55
+ bgcolor: theme$1.palette.primary.main,
57
56
  children: [
58
57
  /* @__PURE__ */ jsxRuntime.jsxs(
59
- "p",
58
+ material.Typography,
60
59
  {
61
- style: {
60
+ sx: {
62
61
  color: "#ffffff",
63
- fontWeight: 700,
64
- lineHeight: 1.5
62
+ fontWeight: 700
65
63
  },
66
64
  children: [
67
65
  t("WIDGET.SELECT_ALL"),
@@ -70,13 +68,14 @@ const CaptchaComponent = ({
70
68
  }
71
69
  ),
72
70
  /* @__PURE__ */ jsxRuntime.jsx(
73
- "p",
71
+ material.Typography,
74
72
  {
75
- style: {
73
+ px: 1,
74
+ sx: {
76
75
  color: "#ffffff",
77
76
  fontWeight: 700,
78
77
  textTransform: "capitalize",
79
- lineHeight: 1.5
78
+ fontSize: theme$1.typography.h6.fontSize
80
79
  },
81
80
  children: `${util.at(challenge.captchas, index$1).captcha.target}`
82
81
  }
@@ -84,19 +83,13 @@ const CaptchaComponent = ({
84
83
  ]
85
84
  }
86
85
  ),
87
- /* @__PURE__ */ jsxRuntime.jsx("div", { ...index({ dev: { cy: "captcha-" + index$1 } }), children: captcha && /* @__PURE__ */ jsxRuntime.jsx(
88
- CaptchaWidget.CaptchaWidget,
89
- {
90
- challenge: captcha,
91
- solution,
92
- onClick,
93
- themeColor
94
- }
95
- ) }),
86
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { ...index({ dev: { cy: "captcha-" + index$1 } }), children: captcha && /* @__PURE__ */ jsxRuntime.jsx(CaptchaWidget.CaptchaWidget, { challenge: captcha, solution, onClick }) }),
96
87
  /* @__PURE__ */ jsxRuntime.jsx(
97
- "div",
88
+ material.Box,
98
89
  {
99
- style: {
90
+ px: 2,
91
+ py: 1,
92
+ sx: {
100
93
  display: "flex",
101
94
  alignItems: "center",
102
95
  justifyContent: "center",
@@ -105,43 +98,27 @@ const CaptchaComponent = ({
105
98
  ...index({ dev: { cy: "dots-captcha" } })
106
99
  }
107
100
  ),
108
- /* @__PURE__ */ jsxRuntime.jsx(
109
- "div",
110
- {
111
- style: {
112
- padding: "8px 16px",
113
- display: "flex",
114
- width: "100%"
115
- }
116
- }
117
- ),
118
101
  /* @__PURE__ */ jsxRuntime.jsxs(
119
- "div",
102
+ material.Box,
120
103
  {
121
- style: {
122
- padding: "0 16px 16px",
104
+ px: 2,
105
+ pt: 0,
106
+ pb: 2,
107
+ sx: {
123
108
  display: "flex",
124
109
  alignItems: "center",
125
- justifyContent: "space-between",
126
- lineHeight: 1.75
110
+ justifyContent: "space-between"
127
111
  },
128
112
  children: [
113
+ /* @__PURE__ */ jsxRuntime.jsx(material.Button, { onClick: onCancel, variant: "text", children: t("WIDGET.CANCEL") }),
129
114
  /* @__PURE__ */ jsxRuntime.jsx(
130
- Button,
131
- {
132
- themeColor,
133
- buttonType: "cancel",
134
- onClick: onCancel,
135
- text: t("WIDGET.CANCEL")
136
- }
137
- ),
138
- /* @__PURE__ */ jsxRuntime.jsx(
139
- Button,
115
+ material.Button,
140
116
  {
141
- themeColor,
142
- buttonType: "next",
143
- text: index$1 < challenge.captchas.length - 1 ? t("WIDGET.NEXT") : t("WIDGET.SUBMIT"),
144
- onClick: index$1 < challenge.captchas.length - 1 ? onNext : onSubmit
117
+ color: "primary",
118
+ onClick: index$1 < challenge.captchas.length - 1 ? onNext : onSubmit,
119
+ variant: "contained",
120
+ ...index({ dev: { cy: "button-next" } }),
121
+ children: index$1 < challenge.captchas.length - 1 ? t("WIDGET.NEXT") : t("WIDGET.SUBMIT")
145
122
  }
146
123
  )
147
124
  ]
@@ -1,25 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxRuntime = require("@emotion/react/jsx-runtime");
4
- const common = require("@prosopo/common");
5
- const theme = require("./theme.cjs");
6
- const React = require("react");
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const material = require("@mui/material");
5
+ const CheckIcon = require("@mui/icons-material/Check.js");
6
+ const normalizeIcon = (Icon) => {
7
+ return Icon.default ? Icon.default : Icon;
8
+ };
9
+ const CheckIconNormalized = normalizeIcon(CheckIcon);
7
10
  const getHash = (item) => {
8
11
  if (!item.hash) {
9
- throw new common.ProsopoDatasetError("CAPTCHA.MISSING_ITEM_HASH", { context: { item } });
12
+ throw new Error("item.hash is undefined");
10
13
  }
11
14
  return item.hash;
12
15
  };
13
- const CaptchaWidget = ({ challenge, solution, onClick, themeColor }) => {
16
+ const CaptchaWidget = ({ challenge, solution, onClick }) => {
14
17
  const items = challenge.captcha.items;
15
- const theme$1 = React.useMemo(() => themeColor === "light" ? theme.lightTheme : theme.darkTheme, [themeColor]);
18
+ const theme = material.useTheme();
16
19
  const isTouchDevice = "ontouchstart" in window;
17
20
  return /* @__PURE__ */ jsxRuntime.jsx(
18
- "div",
21
+ material.Box,
19
22
  {
20
- style: {
21
- paddingRight: 0.5,
22
- paddingBottom: 0.5,
23
+ component: "div",
24
+ pr: 0.5,
25
+ pb: 0.5,
26
+ sx: {
23
27
  // expand to full height / width of parent
24
28
  width: "100%",
25
29
  height: "100%",
@@ -31,11 +35,11 @@ const CaptchaWidget = ({ challenge, solution, onClick, themeColor }) => {
31
35
  children: items.map((item, index) => {
32
36
  const hash = getHash(item);
33
37
  return /* @__PURE__ */ jsxRuntime.jsx(
34
- "div",
38
+ material.Box,
35
39
  {
36
- style: {
37
- paddingTop: "4px",
38
- paddingLeft: "4px",
40
+ pt: 0.5,
41
+ pl: 0.5,
42
+ sx: {
39
43
  // enable the items in the grid to grow in width to use up excess space
40
44
  flexGrow: 1,
41
45
  // make the width of each item 1/3rd of the width overall, i.e. 3 columns
@@ -44,19 +48,19 @@ const CaptchaWidget = ({ challenge, solution, onClick, themeColor }) => {
44
48
  boxSizing: "border-box"
45
49
  },
46
50
  children: /* @__PURE__ */ jsxRuntime.jsxs(
47
- "div",
51
+ material.Box,
48
52
  {
49
- style: { cursor: "pointer", height: "100%", width: "100%" },
53
+ sx: { cursor: "pointer", height: "100%", width: "100%" },
50
54
  onClick: isTouchDevice ? void 0 : () => onClick(hash),
51
55
  onTouchStart: isTouchDevice ? () => onClick(hash) : void 0,
52
56
  children: [
53
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { border: 1, borderColor: theme$1.palette.grey[300] }, children: /* @__PURE__ */ jsxRuntime.jsx(
57
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { border: 1, borderColor: theme.palette.grey[300] }, children: /* @__PURE__ */ jsxRuntime.jsx(
54
58
  "img",
55
59
  {
56
60
  style: {
57
61
  width: "100%",
58
62
  // image should be full width / height of the item
59
- backgroundColor: theme$1.palette.grey[300],
63
+ backgroundColor: theme.palette.grey[300],
60
64
  // colour of the bands when letterboxing and image
61
65
  opacity: solution.includes(hash) && isTouchDevice ? "50%" : "100%",
62
66
  // iphone workaround
@@ -71,10 +75,10 @@ const CaptchaWidget = ({ challenge, solution, onClick, themeColor }) => {
71
75
  alt: `Captcha image ${index + 1}`
72
76
  }
73
77
  ) }),
74
- /* @__PURE__ */ jsxRuntime.jsx(
75
- "div",
78
+ /* @__PURE__ */ jsxRuntime.jsx(material.Fade, { in: solution.includes(hash), children: /* @__PURE__ */ jsxRuntime.jsx(
79
+ material.Box,
76
80
  {
77
- style: {
81
+ sx: {
78
82
  // relative to where the element _should_ be positioned
79
83
  position: "relative",
80
84
  // make the overlay the full height/width of an item
@@ -82,15 +86,14 @@ const CaptchaWidget = ({ challenge, solution, onClick, themeColor }) => {
82
86
  height: "100%",
83
87
  // shift it up 100% to overlay the item element
84
88
  top: "-100%",
85
- visibility: solution.includes(hash) ? "visible" : "hidden",
86
89
  // transition on opacity upon (de)selection
87
- transition: "opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
88
- opacity: 1
90
+ transitionDuration: "300ms",
91
+ transitionProperty: "opacity"
89
92
  },
90
93
  children: /* @__PURE__ */ jsxRuntime.jsx(
91
- "div",
94
+ material.Box,
92
95
  {
93
- style: {
96
+ sx: {
94
97
  // make the overlay absolute positioned compare to its container
95
98
  position: "absolute",
96
99
  // spread across 100% width/height of the item box
@@ -108,31 +111,22 @@ const CaptchaWidget = ({ challenge, solution, onClick, themeColor }) => {
108
111
  backgroundColor: "rgba(0,0,0,0.5)"
109
112
  },
110
113
  children: /* @__PURE__ */ jsxRuntime.jsx(
111
- "svg",
114
+ CheckIconNormalized,
112
115
  {
113
- style: {
114
- backgroundColor: "transparent",
115
- // img must be displayed as block otherwise gets a bottom whitespace border
116
+ htmlColor: theme.palette.background.default,
117
+ sx: {
118
+ // img must be displayed as block otherwise get's a bottom whitespace border
116
119
  display: "block",
117
120
  // how big the overlay icon is
118
121
  width: "35%",
119
- height: "35%",
120
- transition: "fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
121
- userSelect: "none",
122
- fill: "currentcolor"
123
- },
124
- focusable: "false",
125
- color: "#fff",
126
- "aria-hidden": "true",
127
- viewBox: "0 0 24 24",
128
- "data-testid": "CheckIcon",
129
- children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" })
122
+ height: "35%"
123
+ }
130
124
  }
131
125
  )
132
126
  }
133
127
  )
134
128
  }
135
- )
129
+ ) })
136
130
  ]
137
131
  }
138
132
  )
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const jsxRuntime = require("@emotion/react/jsx-runtime");
4
- const React = require("react");
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const material = require("@mui/material");
5
+ const react = require("react");
5
6
  const common = require("@prosopo/common");
6
7
  const extensionDapp = require("@polkadot/extension-dapp");
7
8
  const ExtensionAccountSelect = ({
@@ -10,8 +11,8 @@ const ExtensionAccountSelect = ({
10
11
  onChange
11
12
  }) => {
12
13
  const { t } = common.useTranslation();
13
- const [accounts, setAccounts] = React.useState([]);
14
- React.useEffect(() => {
14
+ const [accounts, setAccounts] = react.useState([]);
15
+ react.useEffect(() => {
15
16
  const prom = extensionDapp.web3Enable(dappName).then(() => {
16
17
  return extensionDapp.web3AccountsSubscribe(setAccounts);
17
18
  });
@@ -20,28 +21,27 @@ const ExtensionAccountSelect = ({
20
21
  };
21
22
  }, []);
22
23
  const account = accounts.find((a) => a.address === value) || null;
23
- return (
24
- // react select box
25
- /* @__PURE__ */ jsxRuntime.jsx(
26
- "select",
27
- {
28
- id: "select-account",
29
- onChange: (e) => {
30
- const value2 = e.target.value;
31
- const account2 = accounts.find((a) => a.address === value2) || null;
32
- if (account2) {
33
- console.log("Selected account:", value2);
34
- onChange(account2.address);
35
- } else {
36
- console.log("Deselected account");
37
- onChange("");
38
- }
39
- },
40
- value: accounts.length > 0 && account ? account.address : void 0,
41
- style: { width: "550px" },
42
- children: accounts.map(({ address, meta: { name } }) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: address, children: name }))
43
- }
44
- )
24
+ return /* @__PURE__ */ jsxRuntime.jsx(
25
+ material.Autocomplete,
26
+ {
27
+ disablePortal: true,
28
+ id: "select-account",
29
+ options: accounts,
30
+ value: account,
31
+ isOptionEqualToValue: (option, value2) => option.address === value2.address,
32
+ onChange: (event, value2) => {
33
+ if (value2) {
34
+ console.log("Selected account:", value2);
35
+ onChange(value2.address);
36
+ } else {
37
+ console.log("Deselected account");
38
+ onChange("");
39
+ }
40
+ },
41
+ sx: { width: 550 },
42
+ getOptionLabel: (option) => `${option.meta.name}: ${option.address}`,
43
+ renderInput: (props) => /* @__PURE__ */ jsxRuntime.jsx(material.TextField, { ...props, label: t("WIDGET.SELECT_ACCOUNT") })
44
+ }
45
45
  );
46
46
  };
47
47
  exports.ExtensionAccountSelect = ExtensionAccountSelect;