apps-key-guard 0.0.2 → 0.0.3

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.mts CHANGED
@@ -18,6 +18,7 @@ interface KeyGuardProps {
18
18
  showFloatingButton?: boolean;
19
19
  authorWechat?: string;
20
20
  authorQrCode?: string;
21
+ allowGuestAccess?: boolean;
21
22
  }
22
23
  declare const KeyGuard: React.FC<KeyGuardProps>;
23
24
 
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ interface KeyGuardProps {
18
18
  showFloatingButton?: boolean;
19
19
  authorWechat?: string;
20
20
  authorQrCode?: string;
21
+ allowGuestAccess?: boolean;
21
22
  }
22
23
  declare const KeyGuard: React.FC<KeyGuardProps>;
23
24
 
package/dist/index.js CHANGED
@@ -57,7 +57,8 @@ var KeyGuard = ({
57
57
  buttonText = "\u9A8C\u8BC1",
58
58
  showFloatingButton = true,
59
59
  authorWechat = "zhoulixiang0305",
60
- authorQrCode = "https://i.postimg.cc/bJz33sy2/saler.jpg"
60
+ authorQrCode = "https://i.postimg.cc/bJz33sy2/saler.jpg",
61
+ allowGuestAccess = false
61
62
  }) => {
62
63
  const [isValidated, setIsValidated] = (0, import_react.useState)(false);
63
64
  const [keyValue, setKeyValue] = (0, import_react.useState)("");
@@ -68,6 +69,7 @@ var KeyGuard = ({
68
69
  const [showPanel, setShowPanel] = (0, import_react.useState)(false);
69
70
  const [showKey, setShowKey] = (0, import_react.useState)(false);
70
71
  const [showContactDialog, setShowContactDialog] = (0, import_react.useState)(false);
72
+ const [guestButtonHover, setGuestButtonHover] = (0, import_react.useState)(false);
71
73
  const storageKey = `${STORAGE_KEY_PREFIX}${appName}`;
72
74
  const storageInfoKey = `${STORAGE_KEY_PREFIX}${appName}_info`;
73
75
  const verifyKey = async (key) => {
@@ -145,6 +147,17 @@ var KeyGuard = ({
145
147
  }
146
148
  setLoading(false);
147
149
  };
150
+ const handleGuestAccess = () => {
151
+ const guestInfo = {
152
+ keyValue: "guest",
153
+ level: "guest" /* Guest */
154
+ };
155
+ setUserInfo(guestInfo);
156
+ setIsValidated(true);
157
+ if (onValidated) {
158
+ onValidated("guest" /* Guest */);
159
+ }
160
+ };
148
161
  const handleLogout = () => {
149
162
  localStorage.removeItem(storageKey);
150
163
  localStorage.removeItem(storageInfoKey);
@@ -380,7 +393,22 @@ var KeyGuard = ({
380
393
  ),
381
394
  error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: errorStyle, children: error }),
382
395
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "submit", style: buttonStyle, disabled: loading, children: loading ? "\u9A8C\u8BC1\u4E2D..." : buttonText })
383
- ] })
396
+ ] }),
397
+ allowGuestAccess && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: guestAccessContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
398
+ "button",
399
+ {
400
+ type: "button",
401
+ onClick: handleGuestAccess,
402
+ onMouseEnter: () => setGuestButtonHover(true),
403
+ onMouseLeave: () => setGuestButtonHover(false),
404
+ style: {
405
+ ...guestAccessButtonStyle,
406
+ color: guestButtonHover ? "#007bff" : "#6c757d"
407
+ },
408
+ disabled: loading,
409
+ children: "\u4EE5\u6E38\u5BA2\u8EAB\u4EFD\u8BBF\u95EE"
410
+ }
411
+ ) })
384
412
  ] }) });
385
413
  };
386
414
  var defaultContainerStyle = {
@@ -679,6 +707,20 @@ var qrCodeImageStyle = {
679
707
  borderRadius: "8px",
680
708
  border: "1px solid #e9ecef"
681
709
  };
710
+ var guestAccessContainerStyle = {
711
+ textAlign: "center",
712
+ paddingTop: "0.75rem"
713
+ };
714
+ var guestAccessButtonStyle = {
715
+ background: "none",
716
+ border: "none",
717
+ color: "#6c757d",
718
+ fontSize: "0.75rem",
719
+ cursor: "pointer",
720
+ textDecoration: "none",
721
+ padding: "0.25rem 0.5rem",
722
+ transition: "color 0.2s"
723
+ };
682
724
  var index_default = KeyGuard;
683
725
  // Annotate the CommonJS export names for ESM import in node:
684
726
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -21,7 +21,8 @@ var KeyGuard = ({
21
21
  buttonText = "\u9A8C\u8BC1",
22
22
  showFloatingButton = true,
23
23
  authorWechat = "zhoulixiang0305",
24
- authorQrCode = "https://i.postimg.cc/bJz33sy2/saler.jpg"
24
+ authorQrCode = "https://i.postimg.cc/bJz33sy2/saler.jpg",
25
+ allowGuestAccess = false
25
26
  }) => {
26
27
  const [isValidated, setIsValidated] = useState(false);
27
28
  const [keyValue, setKeyValue] = useState("");
@@ -32,6 +33,7 @@ var KeyGuard = ({
32
33
  const [showPanel, setShowPanel] = useState(false);
33
34
  const [showKey, setShowKey] = useState(false);
34
35
  const [showContactDialog, setShowContactDialog] = useState(false);
36
+ const [guestButtonHover, setGuestButtonHover] = useState(false);
35
37
  const storageKey = `${STORAGE_KEY_PREFIX}${appName}`;
36
38
  const storageInfoKey = `${STORAGE_KEY_PREFIX}${appName}_info`;
37
39
  const verifyKey = async (key) => {
@@ -109,6 +111,17 @@ var KeyGuard = ({
109
111
  }
110
112
  setLoading(false);
111
113
  };
114
+ const handleGuestAccess = () => {
115
+ const guestInfo = {
116
+ keyValue: "guest",
117
+ level: "guest" /* Guest */
118
+ };
119
+ setUserInfo(guestInfo);
120
+ setIsValidated(true);
121
+ if (onValidated) {
122
+ onValidated("guest" /* Guest */);
123
+ }
124
+ };
112
125
  const handleLogout = () => {
113
126
  localStorage.removeItem(storageKey);
114
127
  localStorage.removeItem(storageInfoKey);
@@ -344,7 +357,22 @@ var KeyGuard = ({
344
357
  ),
345
358
  error && /* @__PURE__ */ jsx("div", { style: errorStyle, children: error }),
346
359
  /* @__PURE__ */ jsx("button", { type: "submit", style: buttonStyle, disabled: loading, children: loading ? "\u9A8C\u8BC1\u4E2D..." : buttonText })
347
- ] })
360
+ ] }),
361
+ allowGuestAccess && /* @__PURE__ */ jsx("div", { style: guestAccessContainerStyle, children: /* @__PURE__ */ jsx(
362
+ "button",
363
+ {
364
+ type: "button",
365
+ onClick: handleGuestAccess,
366
+ onMouseEnter: () => setGuestButtonHover(true),
367
+ onMouseLeave: () => setGuestButtonHover(false),
368
+ style: {
369
+ ...guestAccessButtonStyle,
370
+ color: guestButtonHover ? "#007bff" : "#6c757d"
371
+ },
372
+ disabled: loading,
373
+ children: "\u4EE5\u6E38\u5BA2\u8EAB\u4EFD\u8BBF\u95EE"
374
+ }
375
+ ) })
348
376
  ] }) });
349
377
  };
350
378
  var defaultContainerStyle = {
@@ -643,6 +671,20 @@ var qrCodeImageStyle = {
643
671
  borderRadius: "8px",
644
672
  border: "1px solid #e9ecef"
645
673
  };
674
+ var guestAccessContainerStyle = {
675
+ textAlign: "center",
676
+ paddingTop: "0.75rem"
677
+ };
678
+ var guestAccessButtonStyle = {
679
+ background: "none",
680
+ border: "none",
681
+ color: "#6c757d",
682
+ fontSize: "0.75rem",
683
+ cursor: "pointer",
684
+ textDecoration: "none",
685
+ padding: "0.25rem 0.5rem",
686
+ transition: "color 0.2s"
687
+ };
646
688
  var index_default = KeyGuard;
647
689
  export {
648
690
  KeyGuard,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-key-guard",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A React component for key-based access control with localStorage caching",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",