|
9 | 9 | <script lang="ts">
|
10 | 10 | import { env } from '$lib/util/env';
|
11 | 11 | import { dismissPromotion, getActivePromotion } from '$lib/util/promos/promo';
|
| 12 | + import { stateStore } from '$lib/util/state'; |
| 13 | + import { MCBaseURL } from '$lib/util/util'; |
| 14 | + import type { ComponentProps } from 'svelte'; |
| 15 | + import DropdownNavMenu from './DropdownNavMenu.svelte'; |
12 | 16 | import Privacy from './Privacy.svelte';
|
13 | 17 | import Theme from './Theme.svelte';
|
14 | 18 |
|
15 | 19 | const { isEnabledMermaidChartLinks } = env;
|
16 | 20 |
|
17 | 21 | let isMenuOpen = $state(false);
|
18 |
| -
|
| 22 | + const isReferral = document.referrer.includes(MCBaseURL); |
19 | 23 | function toggleMenu() {
|
20 | 24 | isMenuOpen = !isMenuOpen;
|
21 | 25 | }
|
22 | 26 |
|
23 |
| - interface Link { |
24 |
| - href: string; |
25 |
| - title?: string; |
26 |
| - icon?: string; |
27 |
| - img?: string; |
28 |
| - } |
| 27 | + type Links = ComponentProps<typeof DropdownNavMenu>['links']; |
29 | 28 |
|
30 |
| - let links: Link[] = [ |
31 |
| - { |
32 |
| - title: 'Documentation', |
33 |
| - href: 'https://mermaid.js.org/intro/getting-started.html' |
34 |
| - }, |
| 29 | + const githubLinks: Links = [ |
| 30 | + { title: 'Mermaid JS', href: 'https://github.com/mermaid-js/mermaid' }, |
35 | 31 | {
|
36 |
| - title: 'Tutorial', |
37 |
| - href: 'https://mermaid.js.org/ecosystem/tutorials.html' |
| 32 | + title: 'Mermaid Live Editor', |
| 33 | + href: 'https://github.com/mermaid-js/mermaid-live-editor' |
38 | 34 | },
|
39 | 35 | {
|
40 |
| - title: 'Mermaid', |
41 |
| - href: 'https://github.com/mermaid-js/mermaid' |
42 |
| - }, |
43 |
| - { |
44 |
| - title: 'CLI', |
| 36 | + title: 'Mermaid CLI', |
45 | 37 | href: 'https://github.com/mermaid-js/mermaid-cli'
|
46 |
| - }, |
47 |
| - { |
48 |
| - href: 'https://github.com/mermaid-js/mermaid-live-editor', |
49 |
| - icon: 'fab fa-github fa-lg' |
50 | 38 | }
|
51 | 39 | ];
|
52 | 40 |
|
53 |
| - if (isEnabledMermaidChartLinks) { |
54 |
| - links.push({ |
55 |
| - href: 'https://mermaidchart.com', |
56 |
| - img: './mermaidchart-logo.svg' |
57 |
| - }); |
58 |
| - } |
| 41 | + const documentationLinks: Links = [ |
| 42 | + { title: 'Getting started', href: 'https://mermaid.js.org/intro/getting-started.html' }, |
| 43 | + { title: 'Tutorials', href: 'https://mermaid.js.org/ecosystem/tutorials.html' }, |
| 44 | + { |
| 45 | + title: 'Integrations', |
| 46 | + href: 'https://mermaid.js.org/ecosystem/integrations-community.html' |
| 47 | + } |
| 48 | + ]; |
59 | 49 |
|
60 | 50 | let activePromotion = $state(getActivePromotion());
|
61 | 51 |
|
|
93 | 83 | </div>
|
94 | 84 | {/if}
|
95 | 85 |
|
96 |
| -<div class="navbar bg-primary p-0 shadow-lg"> |
97 |
| - <div class="mx-2 flex-1 px-2"> |
98 |
| - <span class="text-lg font-bold"> |
99 |
| - <a href="/">Mermaid<span class="text-xs font-thin">v{version}</span> Live Editor</a> |
100 |
| - </span> |
| 86 | +<div class="navbar z-50 bg-primary p-0 shadow-lg"> |
| 87 | + <div class="mx-2 flex flex-1 gap-2 px-2"> |
| 88 | + <a href="/"><img class="size-6" src="./favicon.svg" alt="Mermaid Live Editor" /></a> |
| 89 | + <div |
| 90 | + id="switcher" |
| 91 | + class="flex items-center justify-center gap-2 font-bold" |
| 92 | + class:flex-row-reverse={isReferral}> |
| 93 | + <a href="/"> |
| 94 | + {#if !isReferral} |
| 95 | + Mermaid |
| 96 | + {/if} |
| 97 | + Live Editor |
| 98 | + </a> |
| 99 | + {#if isEnabledMermaidChartLinks} |
| 100 | + <input |
| 101 | + type="checkbox" |
| 102 | + class="toggle toggle-primary" |
| 103 | + id="editorMode" |
| 104 | + checked={isReferral} |
| 105 | + onclick={() => { |
| 106 | + logEvent('playgroundToggle', { isReferred: isReferral }); |
| 107 | + window.open( |
| 108 | + `${MCBaseURL}/play#${$stateStore.serialized}`, |
| 109 | + '_self', |
| 110 | + // Do not send referrer header, if the user already came from playground |
| 111 | + isReferral ? 'noreferrer' : '' |
| 112 | + ); |
| 113 | + }} /> |
| 114 | + <a href="{MCBaseURL}/play#{$stateStore.serialized}">Playground</a> |
| 115 | + {/if} |
| 116 | + </div> |
101 | 117 | </div>
|
102 | 118 |
|
103 | 119 | <label
|
|
140 | 156 | onclick={toggleMenu} />
|
141 | 157 |
|
142 | 158 | <div class="hidden w-full lg:flex lg:w-auto lg:items-center" id="menu">
|
143 |
| - <Theme /> |
| 159 | + <span class="text-sm">v{version}</span> |
144 | 160 | <ul class="items-center justify-between pt-4 text-base lg:flex lg:pt-0">
|
145 | 161 | <li>
|
146 | 162 | <Privacy />
|
147 | 163 | </li>
|
148 |
| - {#each links as { title, href, icon, img }} |
| 164 | + <li> |
| 165 | + <Theme /> |
| 166 | + </li> |
| 167 | + <li> |
| 168 | + <DropdownNavMenu label="Documentation" links={documentationLinks} /> |
| 169 | + </li> |
| 170 | + <li> |
| 171 | + <DropdownNavMenu icon="fab fa-github fa-lg" links={githubLinks} /> |
| 172 | + </li> |
| 173 | + |
| 174 | + {#if isEnabledMermaidChartLinks} |
149 | 175 | <li>
|
150 |
| - <a class="btn btn-ghost" target="_blank" {href}> |
151 |
| - {#if icon} |
152 |
| - <i class={icon}></i> |
153 |
| - {:else if img} |
154 |
| - <img src={img} alt={title} /> |
155 |
| - {/if} |
156 |
| - {#if title} |
157 |
| - {title} |
158 |
| - {/if} |
| 176 | + <a class="btn btn-ghost" target="_blank" href="https://mermaidchart.com"> |
| 177 | + <img class="size-6" src="./mermaidchart-logo.svg" alt="Mermaid Chart" /> |
159 | 178 | </a>
|
160 | 179 | </li>
|
161 |
| - {/each} |
| 180 | + {/if} |
162 | 181 | </ul>
|
163 | 182 | </div>
|
164 | 183 | </div>
|
|
171 | 190 | background: #661ae6;
|
172 | 191 | display: flex;
|
173 | 192 | }
|
174 |
| -
|
175 |
| - .navbar { |
176 |
| - z-index: 10000; |
177 |
| - } |
178 |
| -
|
179 |
| - img { |
180 |
| - width: 1.5rem; |
181 |
| - height: 1.5rem; |
182 |
| - } |
183 | 193 | </style>
|
0 commit comments