duckylib 0.1.11 → 0.1.13

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.
@@ -8,13 +8,26 @@
8
8
  import { MediaQuery } from "svelte/reactivity";
9
9
  import Symbol from "../text/Symbol.svelte";
10
10
  import Row from "../containers/Row.svelte";
11
+ import Text from "../text/Text.svelte"
12
+
13
+ interface ContextMenuEntry {
14
+ label: string;
15
+ symbol: string;
16
+ href: string;
17
+ disabled: boolean;
18
+ }
19
+
20
+ interface ContextMenuSection {
21
+ items: ContextMenuEntry[];
22
+ }
11
23
 
12
24
  interface UserToastProps {
13
25
  user: Auth.User;
26
+ contextMenu: ContextMenuSection[];
14
27
  onlogout?: () => Promise<void>;
15
28
  }
16
29
 
17
- let { user, onlogout }: UserToastProps = $props();
30
+ let { user, onlogout, contextMenu }: UserToastProps = $props();
18
31
 
19
32
  let showContextMenu = $state(false);
20
33
 
@@ -61,19 +74,40 @@
61
74
  <!-- svelte-ignore a11y_click_events_have_key_events -->
62
75
  <!-- svelte-ignore a11y_no_static_element_interactions -->
63
76
  <contextentry data-disabled="true" id="informative-username">
64
- <span class="material-symbols-outlined">account_circle</span>
65
- {user.username}
77
+ <Symbol name="account_circle" inheritColor={true} />
78
+ <Text weight="bolder" sizeEm={1.1}>{user.username}</Text>
66
79
  </contextentry>
80
+ <hr />
67
81
  {/if}
82
+ {#each contextMenu as section}
83
+ {#each section.items as item}
84
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
85
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
86
+ <contextentry
87
+ data-disabled="{item.disabled}"
88
+ id="{item.label.replaceAll(/ +/gim, "-").toLowerCase()}"
89
+ onclick={async () => {
90
+ if(browser) window.location.replace(item.href)
91
+ }}
92
+ >
93
+ <Symbol name={item.symbol} inheritColor={true} />
94
+ <Text weight="bolder" sizeEm={1}>{item.label}</Text>
95
+
96
+ </contextentry>
97
+ <hr />
98
+ {/each}
99
+ {/each}
68
100
  <!-- svelte-ignore a11y_click_events_have_key_events -->
69
101
  <!-- svelte-ignore a11y_no_static_element_interactions -->
70
102
  <contextentry
71
103
  data-disabled="false"
72
104
  id="log-out"
73
- onclick={async () => {if(onlogout) await onlogout()}}
105
+ onclick={async () => {
106
+ if (onlogout) await onlogout();
107
+ }}
74
108
  >
75
- <span class="material-symbols-outlined">logout</span>
76
- <red>Log Out</red>
109
+ <Symbol name="logout" inheritColor={true} />
110
+ <Text weight="bold" sizeEm={1} classList={["red"]}>Log Out</Text>
77
111
  </contextentry>
78
112
  <hr />
79
113
  <!-- svelte-ignore a11y_click_events_have_key_events -->
@@ -197,7 +231,7 @@
197
231
  margin-right: auto;
198
232
  background-color: var(--overlay-0);
199
233
  opacity: 0.6;
200
- margin: 0.66em 0;
234
+ margin: 0.4em 0;
201
235
  margin-left: 0.33em;
202
236
  width: 92%;
203
237
  border: none;
@@ -236,7 +270,7 @@
236
270
 
237
271
  width: 95%;
238
272
  cursor: pointer;
239
- padding: 0.1em 0.33em;
273
+ padding: 0em 0.33em;
240
274
  margin: 0.1em 0em;
241
275
 
242
276
  border-radius: 8px;
@@ -1,6 +1,16 @@
1
1
  import type { Auth } from "../../types.ts";
2
+ interface ContextMenuEntry {
3
+ label: string;
4
+ symbol: string;
5
+ href: string;
6
+ disabled: boolean;
7
+ }
8
+ interface ContextMenuSection {
9
+ items: ContextMenuEntry[];
10
+ }
2
11
  interface UserToastProps {
3
12
  user: Auth.User;
13
+ contextMenu: ContextMenuSection[];
4
14
  onlogout?: () => Promise<void>;
5
15
  }
6
16
  declare const UserToast: import("svelte").Component<UserToastProps, {}, "">;
@@ -41,7 +41,13 @@
41
41
  if(button.onclick) {
42
42
  await button.onclick(e)
43
43
  } else {
44
- if(browser && button.href) window.open(button.href, "_blank")
44
+ if(browser && button.href) {
45
+ if(button.href.startsWith("/")) {
46
+ window.open(button.href, "_self")
47
+ } else {
48
+ confirm(`${button.href} will open in a new tab.\n\nContinue?`) ? window.open(button.href, "_blank") : () => {};
49
+ }
50
+ }
45
51
  }
46
52
  }}>{#if button.href && !button.onclick}<Row heightPx="fit" gapEm={0.66}><Text inheritColor={true} weight="bolder">{button.text}</Text><Symbol name="open_in_new" sizePx={18} inheritColor={true} /></Row>{:else}<Text inheritColor={true} weight="bolder">{button.text}</Text>{/if}</button>
47
53
  {/each}
@@ -12,6 +12,17 @@
12
12
  import { PUBLIC_MOBILE_SIZE_PX, PUBLIC_TABLET_SIZE_PX } from "$env/static/public";
13
13
  import SearchBar, { type QueryMapKeys, type SearchResult } from "./SearchBar.svelte";
14
14
 
15
+ interface ContextMenuEntry {
16
+ label: string;
17
+ symbol: string;
18
+ href: string;
19
+ disabled: boolean;
20
+ }
21
+
22
+ interface ContextMenuSection {
23
+ items: ContextMenuEntry[];
24
+ }
25
+
15
26
  export interface HeaderNavigation {
16
27
  label: string;
17
28
  pathname: string;
@@ -38,8 +49,10 @@
38
49
  defaultNav?: boolean;
39
50
 
40
51
  authFeatures?: boolean;
52
+ loginButtonLabel?: string;
41
53
  onlogin?: (() => Promise<void>) | null;
42
54
  onlogout?: (() => Promise<void>) | null;
55
+ userContextMenu?: ContextMenuSection[]
43
56
 
44
57
  nav?: HeaderNavigation[];
45
58
  }
@@ -70,8 +83,10 @@
70
83
  label = "",
71
84
 
72
85
  authFeatures = false,
86
+ loginButtonLabel,
73
87
  onlogin = null,
74
88
  onlogout = null,
89
+ userContextMenu = [],
75
90
 
76
91
  nav = [],
77
92
  }: HeaderProps = $props();
@@ -164,9 +179,9 @@
164
179
  <Row widthPx="fit">
165
180
 
166
181
  {#if user !== null && onlogout}
167
- <UserToast {user} {onlogout} />
182
+ <UserToast contextMenu={userContextMenu} {user} {onlogout} />
168
183
  {:else if onlogin}
169
- <LoginButton {onlogin} label="Log in to Join" />
184
+ <LoginButton {onlogin} label={loginButtonLabel ? loginButtonLabel : "Log In"} />
170
185
  {/if}
171
186
  </Row>
172
187
  {/if}
@@ -1,5 +1,14 @@
1
1
  import type { Snippet } from "svelte";
2
2
  import { type QueryMapKeys, type SearchResult } from "./SearchBar.svelte";
3
+ interface ContextMenuEntry {
4
+ label: string;
5
+ symbol: string;
6
+ href: string;
7
+ disabled: boolean;
8
+ }
9
+ interface ContextMenuSection {
10
+ items: ContextMenuEntry[];
11
+ }
3
12
  export interface HeaderNavigation {
4
13
  label: string;
5
14
  pathname: string;
@@ -22,8 +31,10 @@ interface HeaderProps {
22
31
  searchQueryDataKey?: string;
23
32
  defaultNav?: boolean;
24
33
  authFeatures?: boolean;
34
+ loginButtonLabel?: string;
25
35
  onlogin?: (() => Promise<void>) | null;
26
36
  onlogout?: (() => Promise<void>) | null;
37
+ userContextMenu?: ContextMenuSection[];
27
38
  nav?: HeaderNavigation[];
28
39
  }
29
40
  declare const Header: import("svelte").Component<HeaderProps, {}, "">;
package/dist/index.js CHANGED
@@ -77,9 +77,6 @@ export function getUserData() {
77
77
  }
78
78
  export function setUserData(user) {
79
79
  console.log("SET USER DATA", user);
80
- // if(b) {
81
80
  if (window !== undefined)
82
- window.localStorage.setItem("userData", JSON.stringify(user));
83
- // writable()
84
- // }
81
+ window.localStorage.setItem("userData", JSON.stringify(user) || "null");
85
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "duckylib",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",