|
9 | 9 | import type { Observable } from 'rxjs' |
10 | 10 | import type { Notification } from '../types.js' |
11 | 11 |
|
12 | | - const { device } = configuration |
| 12 | + const { device, containerElements } = configuration |
13 | 13 | const accountCenter$ = state |
14 | 14 | .select('accountCenter') |
15 | 15 | .pipe(startWith(state.get().accountCenter), shareReplay(1)) |
|
50 | 50 | : Promise.resolve(null) |
51 | 51 |
|
52 | 52 | $: sharedContainer = |
| 53 | + !accountCenterMountToElement && |
53 | 54 | $accountCenter$.enabled && |
54 | 55 | $notify$.enabled && |
55 | 56 | $notify$.position === $accountCenter$.position |
|
58 | 59 | device.type === 'mobile' || $accountCenter$.position === $notify$.position |
59 | 60 |
|
60 | 61 | $: sharedMobileContainerCheck = |
61 | | - device.type === 'mobile' && |
62 | | - (($notify$.position.includes('bottom') && |
| 62 | + ($notify$.position.includes('bottom') && |
63 | 63 | $accountCenter$.position.includes('bottom')) || |
64 | | - ($notify$.position.includes('top') && |
65 | | - $accountCenter$.position.includes('top'))) |
66 | | -
|
67 | | - $: separateMobileContainerCheck = |
68 | | - device.type === 'mobile' && |
69 | | - (($notify$.position.includes('top') && |
70 | | - $accountCenter$.position.includes('bottom')) || |
71 | | - ($notify$.position.includes('bottom') && |
72 | | - $accountCenter$.position.includes('top'))) |
| 64 | + ($notify$.position.includes('top') && |
| 65 | + $accountCenter$.position.includes('top')) |
73 | 66 |
|
74 | 67 | $: displayNotifySeparate = |
75 | 68 | $notify$.enabled && |
76 | 69 | (!$accountCenter$.enabled || |
| 70 | + accountCenterMountToElement || |
77 | 71 | ($notify$.position !== $accountCenter$.position && |
78 | 72 | device.type !== 'mobile') || |
79 | | - separateMobileContainerCheck || |
| 73 | + (device.type === 'mobile' && !sharedMobileContainerCheck) || |
80 | 74 | !$wallets$.length) |
81 | 75 |
|
82 | 76 | $: displayAccountCenterSeparate = |
83 | 77 | $accountCenter$.enabled && |
84 | 78 | (!$notify$.enabled || |
85 | 79 | ($notify$.position !== $accountCenter$.position && |
86 | 80 | device.type !== 'mobile') || |
87 | | - separateMobileContainerCheck) && |
| 81 | + (device.type === 'mobile' && !sharedMobileContainerCheck)) && |
88 | 82 | $wallets$.length |
89 | 83 |
|
90 | 84 | $: displayAccountCenterNotifySameContainer = |
91 | 85 | $notify$.enabled && |
92 | 86 | $accountCenter$.enabled && |
93 | | - $wallets$.length && |
94 | | - (sharedContainer || sharedMobileContainerCheck) |
| 87 | + (sharedContainer || |
| 88 | + (device.type === 'mobile' && sharedMobileContainerCheck)) && |
| 89 | + $wallets$.length |
| 90 | +
|
| 91 | + const accountCenterMountToElement = |
| 92 | + $accountCenter$.enabled && |
| 93 | + containerElements && |
| 94 | + containerElements.accountCenter |
| 95 | +
|
| 96 | + if (accountCenterMountToElement) { |
| 97 | + const accountCenter = document.createElement('onboard-account-center') |
| 98 | + const target = accountCenter.attachShadow({ mode: 'open' }) |
| 99 | +
|
| 100 | + let getW3OEl = document.querySelector('onboard-v2') |
| 101 | + let w3OStyleSheets = getW3OEl.shadowRoot.styleSheets |
| 102 | + const accountCenterStyleSheet = new CSSStyleSheet() |
| 103 | +
|
| 104 | + // Copy Onboard stylesheets over to AccountCenter shadow DOM |
| 105 | + Object.values(w3OStyleSheets).forEach(sheet => { |
| 106 | + const styleRules = Object.values(sheet.cssRules) |
| 107 | + styleRules.forEach(rule => |
| 108 | + accountCenterStyleSheet.insertRule(rule.cssText) |
| 109 | + ) |
| 110 | + }) |
| 111 | + target.adoptedStyleSheets = [accountCenterStyleSheet] |
| 112 | +
|
| 113 | + const containerElement = document.querySelector(accountCenterMountToElement) |
| 114 | +
|
| 115 | + containerElement.appendChild(accountCenter) |
| 116 | + if (!containerElement) { |
| 117 | + throw new Error( |
| 118 | + `Element with query ${accountCenterMountToElement} does not exist.` |
| 119 | + ) |
| 120 | + } |
| 121 | +
|
| 122 | + const getACComp = async () => { |
| 123 | + let acComponent = await accountCenterComponent |
| 124 | + if (acComponent) { |
| 125 | + new acComponent({ |
| 126 | + target, |
| 127 | + props: { |
| 128 | + settings: $accountCenter$, |
| 129 | + mountInContainer: true |
| 130 | + } |
| 131 | + }) |
| 132 | + } |
| 133 | + } |
| 134 | + getACComp() |
| 135 | + } |
95 | 136 | </script> |
96 | 137 |
|
97 | 138 | <style> |
|
389 | 430 | > |
390 | 431 | {#await accountCenterComponent then AccountCenter} |
391 | 432 | {#if AccountCenter} |
392 | | - <svelte:component this={AccountCenter} settings={$accountCenter$} /> |
| 433 | + <svelte:component this={AccountCenter} /> |
393 | 434 | {/if} |
394 | 435 | {/await} |
395 | 436 | </div> |
|
432 | 473 | {#if $accountCenter$.enabled && $wallets$.length} |
433 | 474 | {#await accountCenterComponent then AccountCenter} |
434 | 475 | {#if AccountCenter} |
435 | | - <svelte:component this={AccountCenter} settings={$accountCenter$} /> |
| 476 | + <svelte:component this={AccountCenter} /> |
436 | 477 | {/if} |
437 | 478 | {/await} |
438 | 479 | {/if} |
|
0 commit comments