@arcblock/ux 2.13.13 → 2.13.15

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 (72) hide show
  1. package/lib/Address/responsive-did-address.js +3 -1
  2. package/lib/Config/theme-mode-toggle.js +1 -1
  3. package/lib/DIDConnect/app-icon.d.ts +8 -0
  4. package/lib/DIDConnect/app-icon.js +31 -0
  5. package/lib/DIDConnect/app-info-item.d.ts +7 -0
  6. package/lib/DIDConnect/app-info-item.js +73 -0
  7. package/lib/DIDConnect/did-connect-footer.d.ts +4 -0
  8. package/lib/DIDConnect/did-connect-footer.js +54 -0
  9. package/lib/DIDConnect/did-connect-logo.d.ts +1 -0
  10. package/lib/DIDConnect/did-connect-logo.js +11 -0
  11. package/lib/DIDConnect/index.d.ts +7 -0
  12. package/lib/DIDConnect/index.js +7 -0
  13. package/lib/DIDConnect/powered-by.d.ts +3 -0
  14. package/lib/DIDConnect/powered-by.js +46 -0
  15. package/lib/DIDConnect/with-container.d.ts +11 -0
  16. package/lib/DIDConnect/with-container.js +273 -0
  17. package/lib/DIDConnect/with-ux-theme.d.ts +1 -0
  18. package/lib/DIDConnect/with-ux-theme.js +23 -0
  19. package/lib/Datatable/CustomToolbar.js +0 -3
  20. package/lib/Datatable/index.d.ts +3 -0
  21. package/lib/Datatable/index.js +36 -20
  22. package/lib/Dialog/confirm.d.ts +6 -1
  23. package/lib/Dialog/confirm.js +7 -3
  24. package/lib/Dialog/use-confirm.js +6 -0
  25. package/lib/LoadingMask/index.js +1 -1
  26. package/lib/Locale/util.d.ts +3 -3
  27. package/lib/Locale/util.js +6 -1
  28. package/lib/LoginButton/index.d.ts +12 -0
  29. package/lib/LoginButton/index.js +74 -0
  30. package/lib/NavMenu/style.js +0 -1
  31. package/lib/SessionUser/components/un-login.js +42 -31
  32. package/lib/SharedBridge/index.d.ts +16 -0
  33. package/lib/SharedBridge/index.js +109 -0
  34. package/lib/SharedBridge/need-storage-access-api-dialog.d.ts +7 -0
  35. package/lib/SharedBridge/need-storage-access-api-dialog.js +212 -0
  36. package/lib/Theme/index.d.ts +2 -2
  37. package/lib/Theme/index.js +1 -1
  38. package/lib/Util/iframe.d.ts +5 -0
  39. package/lib/Util/iframe.js +24 -0
  40. package/lib/Util/index.d.ts +10 -1
  41. package/lib/Util/index.js +67 -4
  42. package/lib/hooks/use-blocklet-logo.d.ts +8 -0
  43. package/lib/hooks/use-blocklet-logo.js +31 -0
  44. package/lib/hooks/use-mobile.d.ts +4 -0
  45. package/lib/hooks/use-mobile.js +7 -0
  46. package/package.json +7 -6
  47. package/src/Address/responsive-did-address.tsx +11 -1
  48. package/src/Config/theme-mode-toggle.tsx +1 -1
  49. package/src/DIDConnect/app-icon.tsx +36 -0
  50. package/src/DIDConnect/app-info-item.tsx +82 -0
  51. package/src/DIDConnect/did-connect-footer.tsx +51 -0
  52. package/src/DIDConnect/did-connect-logo.tsx +8 -0
  53. package/src/DIDConnect/index.ts +7 -0
  54. package/src/DIDConnect/powered-by.tsx +48 -0
  55. package/src/DIDConnect/with-container.tsx +307 -0
  56. package/src/DIDConnect/with-ux-theme.tsx +22 -0
  57. package/src/Datatable/CustomToolbar.jsx +0 -1
  58. package/src/Datatable/index.jsx +32 -20
  59. package/src/Dialog/confirm.jsx +31 -23
  60. package/src/Dialog/use-confirm.jsx +6 -0
  61. package/src/LoadingMask/index.tsx +1 -1
  62. package/src/Locale/util.ts +7 -2
  63. package/src/LoginButton/index.tsx +73 -0
  64. package/src/NavMenu/style.ts +0 -1
  65. package/src/SessionUser/components/un-login.tsx +34 -27
  66. package/src/SharedBridge/index.tsx +123 -0
  67. package/src/SharedBridge/need-storage-access-api-dialog.tsx +171 -0
  68. package/src/Theme/index.ts +2 -2
  69. package/src/Util/iframe.ts +19 -0
  70. package/src/Util/index.ts +77 -4
  71. package/src/hooks/use-blocklet-logo.tsx +32 -0
  72. package/src/hooks/use-mobile.tsx +6 -0
@@ -58,7 +58,10 @@ import { styled } from '../Theme';
58
58
  * components?: ModifiedMUIDataTableProps['components'],
59
59
  * emptyNode?: import('react').ReactNode,
60
60
  * durable?: string,
61
- * durableKeys?: 'page' | 'rowsPerPage' | 'searchText' | 'sortOrder'
61
+ * durableKeys?: 'page' | 'rowsPerPage' | 'searchText' | 'sortOrder',
62
+ * bgColor?: string,
63
+ * hoverColor?: string,
64
+ * stripColor?: string
62
65
  * } & ModifiedMUIDataTableProps} DataTableProps
63
66
  */
64
67
 
@@ -179,6 +182,9 @@ function ReDataTable({
179
182
  emptyNode,
180
183
  durable,
181
184
  durableKeys,
185
+ bgColor = 'transparent',
186
+ hoverColor,
187
+ stripColor,
182
188
  ...rest
183
189
  }) {
184
190
  const oldState = useRef(null);
@@ -419,6 +425,9 @@ function ReDataTable({
419
425
  };
420
426
  return /*#__PURE__*/_jsx(TableContainer, {
421
427
  verticalKeyWidth: verticalKeyWidth,
428
+ bgColor: bgColor,
429
+ hoverColor: hoverColor,
430
+ stripColor: stripColor,
422
431
  className: clsx({
423
432
  'datatable-stripped': stripped,
424
433
  'datatable-hide-header': hideTableHeader
@@ -448,7 +457,10 @@ ReDataTable.propTypes = {
448
457
  components: PropTypes.object,
449
458
  emptyNode: PropTypes.node,
450
459
  durable: PropTypes.string,
451
- durableKeys: PropTypes.array
460
+ durableKeys: PropTypes.array,
461
+ bgColor: PropTypes.string,
462
+ hoverColor: PropTypes.string,
463
+ stripColor: PropTypes.string
452
464
  };
453
465
  ReDataTable.defaultProps = {
454
466
  options: {},
@@ -465,7 +477,10 @@ ReDataTable.defaultProps = {
465
477
  components: {},
466
478
  emptyNode: '',
467
479
  durable: '',
468
- durableKeys: ['page', 'rowsPerPage', 'searchText', 'sortOrder']
480
+ durableKeys: ['page', 'rowsPerPage', 'searchText', 'sortOrder'],
481
+ bgColor: 'transparent',
482
+ hoverColor: '',
483
+ stripColor: ''
469
484
  };
470
485
  const alignCss = css`
471
486
  .MuiTableCell-head {
@@ -502,15 +517,17 @@ const alignCss = css`
502
517
  }
503
518
  `;
504
519
  const TableContainer = styled('div', {
505
- shouldForwardProp: prop => prop !== 'verticalKeyWidth'
520
+ shouldForwardProp: prop => !['verticalKeyWidth', 'bgColor', 'hoverColor', 'stripColor'].includes(prop)
506
521
  })(({
507
522
  theme,
508
- verticalKeyWidth
523
+ verticalKeyWidth,
524
+ bgColor,
525
+ hoverColor,
526
+ stripColor
509
527
  }) => {
510
528
  const primaryTextColor = theme.palette.text.primary;
511
- const defaultBgColor = theme.palette.background.default;
512
- const hoverBgColor = theme.palette.action.hover;
513
- const oddRowBgColor = theme.palette.grey[50];
529
+ const defaultHoverColor = theme.palette.action.hover;
530
+ const defaultStripColor = theme.palette.grey[50];
514
531
  const verticalKeyWidthStyle = verticalKeyWidth ? `
515
532
  ${theme.breakpoints.down('md')} {
516
533
  [class*='MUIDataTable-responsiveBase'] {
@@ -552,7 +569,7 @@ const TableContainer = styled('div', {
552
569
  height: 100%;
553
570
  box-shadow: none;
554
571
  background: none;
555
- background-color: ${defaultBgColor};
572
+ background-color: ${bgColor};
556
573
  }
557
574
  ${theme.breakpoints.down('md')} {
558
575
  td.MuiTableCell-body {
@@ -593,7 +610,7 @@ const TableContainer = styled('div', {
593
610
 
594
611
  .MuiTableCell-head {
595
612
  color: ${primaryTextColor};
596
- background-color: ${defaultBgColor};
613
+ background-color: ${bgColor};
597
614
  }
598
615
 
599
616
  .MuiTableCell-root {
@@ -601,26 +618,26 @@ const TableContainer = styled('div', {
601
618
  }
602
619
 
603
620
  .MuiTableRow-root {
604
- background-color: ${defaultBgColor};
605
- &:nth-of-type(even) {
606
- background-color: ${defaultBgColor};
607
- }
621
+ background-color: ${bgColor};
608
622
  &:hover {
609
- background-color: ${hoverBgColor};
623
+ background-color: ${hoverColor || defaultHoverColor};
610
624
  }
611
625
  &.MuiTableRow-footer {
612
- background-color: ${defaultBgColor};
626
+ background-color: ${bgColor};
613
627
  }
614
628
  }
615
629
 
616
630
  &.datatable-stripped {
617
631
  .MuiTableRow-root:nth-of-type(odd) {
618
- background-color: ${oddRowBgColor};
632
+ background-color: ${stripColor || defaultStripColor};
619
633
  &:hover {
620
- background-color: ${hoverBgColor};
634
+ background-color: ${hoverColor || defaultHoverColor};
635
+ }
636
+ &.MuiTableRow-head {
637
+ background-color: ${bgColor};
621
638
  }
622
639
  &.MuiTableRow-footer {
623
- background-color: ${defaultBgColor};
640
+ background-color: ${bgColor};
624
641
  }
625
642
  }
626
643
  }
@@ -629,7 +646,6 @@ const TableContainer = styled('div', {
629
646
  const FooterContainer = styled('div')`
630
647
  display: flex;
631
648
  align-items: center;
632
- background-color: ${props => props.theme.palette.background.default};
633
649
  .datatable-footer {
634
650
  position: relative;
635
651
  margin-left: auto;
@@ -9,6 +9,7 @@
9
9
  * children?: React.ReactNode,
10
10
  * showCancelButton?: true | false,
11
11
  * showCloseButton?: true | false,
12
+ * showConfirmButton?: true | false,
12
13
  * fullScreen?: false | true,
13
14
  * confirmButton?: {text: React.ReactNode, props?: ButtonProps}
14
15
  * cancelButton?: {text: React.ReactNode, props?: ButtonProps}
@@ -20,7 +21,7 @@
20
21
  * @param {ConfirmProps} props
21
22
  * @returns {import('react').ReactComponentElement}
22
23
  */
23
- declare function Confirm({ title, children, onConfirm, onCancel, showCloseButton, showCancelButton, fullScreen, confirmButton, cancelButton, PaperProps, ...rest }: ConfirmProps): import("react").ReactComponentElement<any, Pick<any, string | number | symbol>>;
24
+ declare function Confirm({ title, children, onConfirm, onCancel, showCloseButton, showCancelButton, showConfirmButton, fullScreen, confirmButton, cancelButton, PaperProps, ...rest }: ConfirmProps): import("react").ReactComponentElement<any, Pick<any, string | number | symbol>>;
24
25
  declare namespace Confirm {
25
26
  namespace propTypes {
26
27
  let title: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
@@ -29,6 +30,7 @@ declare namespace Confirm {
29
30
  let onCancel: PropTypes.Validator<(...args: any[]) => any>;
30
31
  let children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
31
32
  let showCancelButton: PropTypes.Requireable<boolean>;
33
+ let showConfirmButton: PropTypes.Requireable<boolean>;
32
34
  let showCloseButton: PropTypes.Requireable<boolean>;
33
35
  let fullScreen: PropTypes.Requireable<boolean>;
34
36
  let confirmButton: PropTypes.Requireable<PropTypes.InferProps<{
@@ -44,6 +46,8 @@ declare namespace Confirm {
44
46
  namespace defaultProps {
45
47
  let showCancelButton_1: boolean;
46
48
  export { showCancelButton_1 as showCancelButton };
49
+ let showConfirmButton_1: boolean;
50
+ export { showConfirmButton_1 as showConfirmButton };
47
51
  let showCloseButton_1: boolean;
48
52
  export { showCloseButton_1 as showCloseButton };
49
53
  let fullScreen_1: boolean;
@@ -72,6 +76,7 @@ export type ConfirmProps = {
72
76
  children?: React.ReactNode;
73
77
  showCancelButton?: true | false;
74
78
  showCloseButton?: true | false;
79
+ showConfirmButton?: true | false;
75
80
  fullScreen?: false | true;
76
81
  confirmButton?: {
77
82
  text: React.ReactNode;
@@ -15,6 +15,7 @@ import Dialog from './dialog';
15
15
  * children?: React.ReactNode,
16
16
  * showCancelButton?: true | false,
17
17
  * showCloseButton?: true | false,
18
+ * showConfirmButton?: true | false,
18
19
  * fullScreen?: false | true,
19
20
  * confirmButton?: {text: React.ReactNode, props?: ButtonProps}
20
21
  * cancelButton?: {text: React.ReactNode, props?: ButtonProps}
@@ -35,6 +36,7 @@ export default function Confirm({
35
36
  onCancel,
36
37
  showCloseButton,
37
38
  showCancelButton,
39
+ showConfirmButton,
38
40
  fullScreen,
39
41
  confirmButton,
40
42
  cancelButton,
@@ -74,7 +76,7 @@ export default function Confirm({
74
76
  }
75
77
  }
76
78
  },
77
- actions: /*#__PURE__*/_jsxs(_Fragment, {
79
+ actions: showCancelButton || showConfirmButton ? /*#__PURE__*/_jsxs(_Fragment, {
78
80
  children: [showCancelButton && /*#__PURE__*/_jsx(Button, {
79
81
  onClick: e => {
80
82
  e.stopPropagation();
@@ -83,7 +85,7 @@ export default function Confirm({
83
85
  color: "primary",
84
86
  ...cancelButton.props,
85
87
  children: cancelButton.text
86
- }), /*#__PURE__*/_jsx(Button, {
88
+ }), showConfirmButton && /*#__PURE__*/_jsx(Button, {
87
89
  onClick: e => {
88
90
  e.stopPropagation();
89
91
  onConfirm(e);
@@ -93,7 +95,7 @@ export default function Confirm({
93
95
  ...confirmButton.props,
94
96
  children: confirmButton.text
95
97
  })]
96
- }),
98
+ }) : null,
97
99
  children: children
98
100
  });
99
101
  }
@@ -104,6 +106,7 @@ Confirm.propTypes = {
104
106
  onCancel: PropTypes.func.isRequired,
105
107
  children: PropTypes.node,
106
108
  showCancelButton: PropTypes.bool,
109
+ showConfirmButton: PropTypes.bool,
107
110
  showCloseButton: PropTypes.bool,
108
111
  fullScreen: PropTypes.bool,
109
112
  // 可以传入 {text: ..., props: ...}
@@ -119,6 +122,7 @@ Confirm.propTypes = {
119
122
  };
120
123
  Confirm.defaultProps = {
121
124
  showCancelButton: true,
125
+ showConfirmButton: true,
122
126
  showCloseButton: true,
123
127
  fullScreen: false,
124
128
  confirmButton: {
@@ -18,6 +18,7 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
18
18
  loading: false,
19
19
  showCancelButton: true,
20
20
  showCloseButton: true,
21
+ showConfirmButton: true,
21
22
  confirmButtonText: 'Confirm',
22
23
  confirmButtonProps: {},
23
24
  cancelButtonText: 'Cancel',
@@ -42,6 +43,7 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
42
43
  state.onCancel = params.onCancel || noop;
43
44
  state.showCloseButton = params.showCloseButton ?? true;
44
45
  state.showCancelButton = params.showCancelButton ?? true;
46
+ state.showConfirmButton = params.showConfirmButton ?? true;
45
47
  if (params.confirmButtonText) state.confirmButtonText = params.confirmButtonText;
46
48
  if (params.confirmButtonProps) state.confirmButtonProps = params.confirmButtonProps;
47
49
  if (params.cancelButtonText) state.cancelButtonText = params.cancelButtonText;
@@ -60,6 +62,9 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
60
62
  state.confirmButtonProps = {};
61
63
  state.cancelButtonText = 'Cancel';
62
64
  state.cancelButtonProps = {};
65
+ state.showConfirmButton = true;
66
+ state.showCancelButton = true;
67
+ state.showCloseButton = true;
63
68
  });
64
69
  const close = useMemoizedFn(() => {
65
70
  state.show = false;
@@ -125,6 +130,7 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
125
130
  },
126
131
  showCloseButton: state.showCloseButton,
127
132
  showCancelButton: state.showCancelButton,
133
+ showConfirmButton: state.showConfirmButton,
128
134
  cancelButton: {
129
135
  text: state.cancelButtonText,
130
136
  props: {
@@ -52,7 +52,7 @@ export default function LoadingMask({
52
52
  right: finialBorderWidth,
53
53
  top: finialBorderWidth,
54
54
  bottom: finialBorderWidth,
55
- backgroundColor: 'white',
55
+ backgroundColor: 'background.default',
56
56
  borderRadius: `${finialRadius - finialBorderWidth}px`
57
57
  },
58
58
  '&::before': {
@@ -1,4 +1,4 @@
1
1
  import type { Locale, Translations } from '../type';
2
- export declare const replace: (template: string, data: Record<string, any>) => string;
3
- export declare const translate: (translations: Translations, key: string, locale: Locale, fallbackLocale?: string, data?: {}) => string;
4
- export declare const t: (translations: Translations, key: string, locale: Locale, fallbackLocale?: string, data?: {}) => string;
2
+ export declare const replace: (template: string | Function, data: Record<string, any>) => any;
3
+ export declare const translate: (translations: Translations, key: string, locale: Locale, fallbackLocale?: string, data?: {}) => any;
4
+ export declare const t: (translations: Translations, key: string, locale: Locale, fallbackLocale?: string, data?: {}) => any;
@@ -1,6 +1,11 @@
1
1
  import get from 'lodash/get';
2
2
  /* eslint-disable no-prototype-builtins */
3
- export const replace = (template, data) => template.replace(/{(\w*)}/g, (m, key) => data.hasOwnProperty(key) ? data[key] : '');
3
+ export const replace = (template, data) => {
4
+ if (typeof template === 'function') {
5
+ return template(data);
6
+ }
7
+ return template.replace(/{(\w*)}/g, (m, key) => data.hasOwnProperty(key) ? data[key] : '');
8
+ };
4
9
  export const translate = (translations, key, locale, fallbackLocale = 'en', data = {}) => {
5
10
  const translation = translations[locale];
6
11
  const translationValue = get(translation, key);
@@ -0,0 +1,12 @@
1
+ import { Locale } from '../type';
2
+ type LoginButtonProps = {
3
+ onClick: (options?: {
4
+ openMode?: 'popup' | 'window';
5
+ }) => void;
6
+ render: (options: {
7
+ onClick: () => void;
8
+ }) => React.ReactNode;
9
+ locale?: Locale;
10
+ };
11
+ export default function LoginButton({ onClick, render, locale }: LoginButtonProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
12
+ export {};
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box } from '@mui/material';
3
+ import { joinURL } from 'ufo';
4
+ import { useRef, useState } from 'react';
5
+ import { useMemoizedFn } from 'ahooks';
6
+ import { useBrowser } from '@arcblock/react-hooks';
7
+ import SharedBridge from '../SharedBridge';
8
+ import { setVisitorId } from '../Util';
9
+ import { getFederatedEnabled, getMaster } from '../Util/federated';
10
+ import { callIframe } from '../Util/iframe';
11
+ export default function LoginButton({
12
+ onClick,
13
+ render,
14
+ locale
15
+ }) {
16
+ const blocklet = window?.blocklet;
17
+ const federatedEnabled = getFederatedEnabled(blocklet);
18
+ const masterSite = getMaster(blocklet);
19
+ const sharedBridgeRef = useRef(null);
20
+ const [hasStorageAccess, setHasStorageAccess] = useState(false);
21
+ const browser = useBrowser();
22
+ const handleClick = useMemoizedFn(() => {
23
+ if (hasStorageAccess) {
24
+ onClick({
25
+ openMode: 'popup'
26
+ });
27
+ } else {
28
+ onClick();
29
+ }
30
+ });
31
+ const handleLoad = useMemoizedFn(async () => {
32
+ const {
33
+ value: visitorId
34
+ } = await callIframe(sharedBridgeRef.current, 'getVisitorId');
35
+ if (visitorId) {
36
+ setHasStorageAccess(true);
37
+ setVisitorId(visitorId);
38
+ }
39
+ });
40
+ const handleClickBridge = useMemoizedFn(({
41
+ value,
42
+ visitorId
43
+ }) => {
44
+ if (visitorId) {
45
+ setVisitorId(visitorId);
46
+ }
47
+ if (value) {
48
+ onClick({
49
+ openMode: 'popup'
50
+ });
51
+ } else {
52
+ onClick();
53
+ }
54
+ });
55
+ if (browser.arcSphere || browser.wallet) {
56
+ return render({
57
+ onClick
58
+ });
59
+ }
60
+ return /*#__PURE__*/_jsxs(Box, {
61
+ sx: {
62
+ position: 'relative'
63
+ },
64
+ children: [render({
65
+ onClick: handleClick
66
+ }), masterSite?.appUrl && federatedEnabled ? /*#__PURE__*/_jsx(SharedBridge, {
67
+ locale: locale,
68
+ iframeRef: sharedBridgeRef,
69
+ onLoad: handleLoad,
70
+ onClick: handleClickBridge,
71
+ src: joinURL(masterSite.appUrl, '/.well-known/service/share/shared-bridge.html')
72
+ }) : null]
73
+ });
74
+ }
@@ -12,7 +12,6 @@ export const NavMenuStyled = styled('nav', {
12
12
  minWidth: '50px',
13
13
  // FIXME: @zhanghan 这个只是临时的解决方案,会导致 header align right 不能真正的右对齐,需要修改 header 才能真正解决这个问题
14
14
  flexGrow: 100,
15
- backgroundColor: $bgColor,
16
15
  color: $textColor,
17
16
  fontSize: '16px',
18
17
  '&.navmenu--inline': {
@@ -14,6 +14,7 @@ import { translations } from '../libs/translation';
14
14
  import Typography from '../../Typography';
15
15
  import QuickLoginItem from './quick-login-item';
16
16
  import { getFederatedEnabled, getMaster } from '../../Util/federated';
17
+ import LoginButton from '../../LoginButton';
17
18
  export default function UnLogin({
18
19
  session,
19
20
  onLogin = noop,
@@ -40,16 +41,20 @@ export default function UnLogin({
40
41
  const onTogglePopper = useMemoizedFn((value = !currentState.open) => {
41
42
  currentState.open = value;
42
43
  });
43
- const _onLogin = useMemoizedFn(() => {
44
+ const _onLogin = useMemoizedFn(({
45
+ openMode
46
+ } = {}) => {
44
47
  if (isFirstLoading) {
45
48
  return;
46
49
  }
47
- session.login(onLogin);
50
+ session.login(onLogin, {
51
+ openMode
52
+ });
48
53
  });
49
54
  const blocklet = window?.blocklet;
50
55
  const federatedEnabled = getFederatedEnabled(blocklet);
51
- const master = getMaster(blocklet);
52
- const loginApp = federatedEnabled && master ? master : blocklet;
56
+ const masterSite = getMaster(blocklet);
57
+ const loginApp = federatedEnabled && masterSite ? masterSite : blocklet;
53
58
  const loginAppName = loginApp?.appName || 'DID Connect';
54
59
  const loginAppLogo = joinURL(loginApp?.appUrl || '/', loginApp?.appLogo || '/.well-known/service/blocklet/logo?imageFilter=convert&f=png&h=80');
55
60
  useEffect(() => {
@@ -83,36 +88,42 @@ export default function UnLogin({
83
88
  }
84
89
  });
85
90
  return /*#__PURE__*/_jsxs(_Fragment, {
86
- children: [/*#__PURE__*/_jsx(Box, {
87
- children: /*#__PURE__*/_jsx(IconButton, {
88
- ref: userAnchorRef,
89
- onClick: _onLogin,
90
- "data-cy": "sessionManager-login",
91
- className: "arc-session-user-unlogin",
92
- size: "medium",
93
- "aria-label": "Login button",
94
- children: isFirstLoading ? /*#__PURE__*/_jsx(Box, {
95
- width: size,
96
- height: size,
97
- display: "flex",
98
- justifyContent: "center",
99
- alignItems: "center",
100
- children: /*#__PURE__*/_jsx(CircularProgress, {
91
+ children: [/*#__PURE__*/_jsx(LoginButton, {
92
+ locale: locale,
93
+ onClick: _onLogin,
94
+ render: ({
95
+ onClick
96
+ }) => {
97
+ return /*#__PURE__*/_jsx(IconButton, {
98
+ ref: userAnchorRef,
99
+ "data-cy": "sessionManager-login",
100
+ className: "arc-session-user-unlogin",
101
+ size: "medium",
102
+ onClick: onClick,
103
+ "aria-label": "Login button",
104
+ children: isFirstLoading ? /*#__PURE__*/_jsx(Box, {
105
+ width: size,
106
+ height: size,
107
+ display: "flex",
108
+ justifyContent: "center",
109
+ alignItems: "center",
110
+ children: /*#__PURE__*/_jsx(CircularProgress, {
111
+ style: {
112
+ width: size - 4,
113
+ height: size - 4,
114
+ color: dark ? '#fff' : ''
115
+ }
116
+ })
117
+ }) : /*#__PURE__*/_jsx(Icon, {
118
+ icon: UserIcon,
119
+ fontSize: size,
120
+ color: dark ? '#fff' : 'inherit',
101
121
  style: {
102
- width: size - 4,
103
- height: size - 4,
104
- color: dark ? '#fff' : ''
122
+ transform: 'scale(1.25)'
105
123
  }
106
124
  })
107
- }) : /*#__PURE__*/_jsx(Icon, {
108
- icon: UserIcon,
109
- fontSize: size,
110
- color: dark ? '#fff' : 'inherit',
111
- style: {
112
- transform: 'scale(1.25)'
113
- }
114
- })
115
- })
125
+ });
126
+ }
116
127
  }), /*#__PURE__*/_jsx(Popper, {
117
128
  open: currentState.open,
118
129
  anchorEl: userAnchorRef.current,
@@ -0,0 +1,16 @@
1
+ import type { SxProps } from '@mui/material';
2
+ import React from 'react';
3
+ import { Locale } from '../type';
4
+ declare const SharedBridge: React.NamedExoticComponent<{
5
+ src: string;
6
+ onClick: (data: {
7
+ action: string;
8
+ value: boolean;
9
+ visitorId?: string;
10
+ }) => void;
11
+ onLoad: () => void;
12
+ sx?: SxProps;
13
+ iframeRef?: React.RefObject<HTMLIFrameElement>;
14
+ locale?: Locale;
15
+ }>;
16
+ export default SharedBridge;
@@ -0,0 +1,109 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box } from '@mui/material';
3
+ import React, { memo, useEffect, useId, useRef } from 'react';
4
+ import { withQuery } from 'ufo';
5
+ import { useMemoizedFn, useReactive } from 'ahooks';
6
+ import { mergeSx } from '../Util/style';
7
+ import { callIframe, getCallbackAction } from '../Util/iframe';
8
+ import NeedStorageAccessApiDialog from './need-storage-access-api-dialog';
9
+ import { withContainer, withUxTheme } from '../DIDConnect';
10
+ const SharedBridge = /*#__PURE__*/memo(function SharedBridge({
11
+ src,
12
+ onClick,
13
+ onLoad,
14
+ sx,
15
+ iframeRef,
16
+ locale = 'en',
17
+ ...rest
18
+ }) {
19
+ const _iframeRef = useRef(null);
20
+ const refId = useId();
21
+ const dataId = `shared-bridge_${refId}`;
22
+ const currentState = useReactive({
23
+ open: false,
24
+ hasStorageAccess: false,
25
+ get origin() {
26
+ try {
27
+ return new URL(src).origin;
28
+ } catch (error) {
29
+ return src;
30
+ }
31
+ },
32
+ get host() {
33
+ try {
34
+ return new URL(src).host;
35
+ } catch (error) {
36
+ return src;
37
+ }
38
+ }
39
+ });
40
+ const targetIframeRef = iframeRef ?? _iframeRef;
41
+ useEffect(() => {
42
+ async function handleMessage(event) {
43
+ const {
44
+ data
45
+ } = event;
46
+ if (data.action === getCallbackAction(dataId, 'requestStorageAccess')) {
47
+ currentState.open = false;
48
+ if (!data.value) {
49
+ onClick(data);
50
+ return;
51
+ }
52
+ const {
53
+ value: visitorId
54
+ } = await callIframe(targetIframeRef.current, 'getVisitorId');
55
+ onClick({
56
+ ...data,
57
+ visitorId
58
+ });
59
+ } else if (data.action === getCallbackAction(dataId, 'preRequestStorageAccess')) {
60
+ currentState.open = true;
61
+ }
62
+ }
63
+ window.addEventListener('message', handleMessage);
64
+ return () => {
65
+ window.removeEventListener('message', handleMessage);
66
+ };
67
+ // eslint-disable-next-line react-hooks/exhaustive-deps
68
+ }, [onClick, dataId, targetIframeRef?.current]);
69
+ const DialogComponent = withUxTheme(withContainer(NeedStorageAccessApiDialog));
70
+ const handleLoad = useMemoizedFn(() => {
71
+ callIframe(targetIframeRef.current, 'hasStorageAccess').then(({
72
+ value
73
+ }) => {
74
+ currentState.hasStorageAccess = value;
75
+ });
76
+ onLoad();
77
+ });
78
+ return currentState.hasStorageAccess ? null : /*#__PURE__*/_jsxs(_Fragment, {
79
+ children: [/*#__PURE__*/_jsx(DialogComponent, {
80
+ popup: true,
81
+ locale: locale,
82
+ blocklet: window.blocklet,
83
+ open: currentState.open,
84
+ origin: currentState.origin,
85
+ host: currentState.host,
86
+ onClose: () => {}
87
+ }), /*#__PURE__*/_jsx(Box, {
88
+ ...rest,
89
+ component: "iframe",
90
+ ref: targetIframeRef,
91
+ onLoad: handleLoad,
92
+ title: "shared-bridge",
93
+ "data-id": dataId,
94
+ src: withQuery(src, {
95
+ id: dataId
96
+ }),
97
+ sx: mergeSx({
98
+ border: 0,
99
+ position: 'absolute',
100
+ top: 0,
101
+ left: 0,
102
+ width: '100%',
103
+ height: '100%',
104
+ cursor: 'pointer'
105
+ }, sx)
106
+ })]
107
+ });
108
+ });
109
+ export default SharedBridge;
@@ -0,0 +1,7 @@
1
+ import { Locale } from '../type';
2
+ export default function NeedStorageAccessApiDialog({ locale, origin, host, setColor, }: {
3
+ locale?: Locale;
4
+ origin: string;
5
+ host: string;
6
+ setColor: (color: string) => void;
7
+ }): import("react/jsx-runtime").JSX.Element;