fuma 0.3.22 → 0.3.24

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
  };
@@ -96,7 +96,7 @@ const getBoolean = (bool) => (_data) => typeof bool === "boolean" || bool === vo
96
96
  >
97
97
  <slot />
98
98
 
99
- {#if data.id}
99
+ {#if data?.id}
100
100
  <input type="hidden" name="id" value={data.id} />
101
101
  {/if}
102
102
 
@@ -137,7 +137,10 @@ const getBoolean = (bool) => (_data) => typeof bool === "boolean" || bool === vo
137
137
  <button class="btn btn-primary"> Valider </button>
138
138
  <div class="grow" />
139
139
  {#if data.id && actionDelete}
140
- <ButtonDelete formaction="{action}{actionDelete}">Supprimer</ButtonDelete>
140
+ {@const formaction = `${action}${actionDelete}`}
141
+ <slot name="delete" {formaction}>
142
+ <ButtonDelete {formaction}>Supprimer</ButtonDelete>
143
+ </slot>
141
144
  {/if}
142
145
  </div>
143
146
  </form>
@@ -33,6 +33,9 @@ declare class __sveltets_Render<Shape extends z.ZodRawShape, ReturnData extends
33
33
  };
34
34
  slots(): {
35
35
  default: {};
36
+ delete: {
37
+ formaction: any;
38
+ };
36
39
  };
37
40
  }
38
41
  export type FormProps<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormDataInput<Shape>, Data extends FormDataInput<Shape> = FormDataInput<Shape>> = ReturnType<__sveltets_Render<Shape, ReturnData, Data>['props']>;
@@ -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.24",
4
4
  "description": "My fullstack material build with sveltekit, daisyui, zod, prisma, lucia",
5
5
  "author": {
6
6
  "name": "Jonas Voisard",