fuma 0.3.22 → 0.3.23

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.
@@ -1,11 +1,22 @@
1
1
  <script>import { mdiClipboardTextOutline } from "@mdi/js";
2
2
  import { toast } from "svelte-sonner";
3
3
  import { Icon } from "../icon/index.js";
4
- export let value;
5
- export let title;
4
+ let valueOrGetValue;
5
+ export { valueOrGetValue as value };
6
+ export let title = "";
6
7
  export let icon = mdiClipboardTextOutline;
7
8
  export let successMessage = "Copied";
8
- function handleClick() {
9
+ let isLoading = false;
10
+ async function loadValue() {
11
+ if (typeof valueOrGetValue === "string")
12
+ return valueOrGetValue;
13
+ return valueOrGetValue();
14
+ }
15
+ async function handleClick() {
16
+ if (isLoading)
17
+ return;
18
+ isLoading = true;
19
+ const value = await loadValue().finally(() => isLoading = false);
9
20
  navigator.clipboard.writeText(value).then(() => {
10
21
  toast.success(successMessage);
11
22
  }).catch((error) => {
@@ -14,6 +25,20 @@ function handleClick() {
14
25
  }
15
26
  </script>
16
27
 
17
- <button on:click|preventDefault={handleClick} class="btn btn-square btn-ghost btn-sm">
18
- <Icon path={icon} {title} size={22} />
19
- </button>
28
+ <div class="relative">
29
+ {#if isLoading}
30
+ <span class="loading loading-spinner absolute left-1 top-1 scale-125 opacity-25" />
31
+ {/if}
32
+ <button
33
+ class="btn btn-square btn-sm"
34
+ on:click|preventDefault={handleClick}
35
+ class:btn-disabled={isLoading}
36
+ >
37
+ <Icon
38
+ path={icon}
39
+ size={20}
40
+ {title}
41
+ class="transition-transform {isLoading ? 'scale-75' : ''}"
42
+ />
43
+ </button>
44
+ </div>
@@ -1,8 +1,8 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- value: string;
5
- title: string;
4
+ value: string | (() => Promise<string>);
5
+ title?: string | undefined;
6
6
  icon?: string | undefined;
7
7
  successMessage?: string | undefined;
8
8
  };
@@ -0,0 +1,2 @@
1
+ export type CSVFields<Item extends Record<string, unknown>> = Partial<Record<keyof Item, (item: Item) => string | number>>;
2
+ export declare function getCSV<Item extends Record<string, unknown>>(items: Item[], fields: CSVFields<Item>): string;
@@ -0,0 +1,8 @@
1
+ export function getCSV(items, fields) {
2
+ const headers = Object.keys(fields).join('\t');
3
+ const rows = items.map((m) => Object.values(fields)
4
+ .filter((getValue) => !!getValue)
5
+ .map((getValue) => getValue(m))
6
+ .join('\t'));
7
+ return [headers, rows.join('\r\n')].join('\r\n');
8
+ }
@@ -7,3 +7,4 @@ export * from './avatar.js';
7
7
  export * from './tippy.js';
8
8
  export * from './nestedPaths.js';
9
9
  export * from './constant.js';
10
+ export * from './csv.js';
@@ -7,3 +7,4 @@ export * from './avatar.js';
7
7
  export * from './tippy.js';
8
8
  export * from './nestedPaths.js';
9
9
  export * from './constant.js';
10
+ export * from './csv.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fuma",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "description": "My fullstack material build with sveltekit, daisyui, zod, prisma, lucia",
5
5
  "author": {
6
6
  "name": "Jonas Voisard",