fuma 0.0.1

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.
Files changed (242) hide show
  1. package/README.md +58 -0
  2. package/dist/Meta.svelte +55 -0
  3. package/dist/Meta.svelte.d.ts +20 -0
  4. package/dist/action/index.d.ts +4 -0
  5. package/dist/action/index.js +4 -0
  6. package/dist/action/list/handlers.d.ts +16 -0
  7. package/dist/action/list/handlers.js +92 -0
  8. package/dist/action/list/index.css +40 -0
  9. package/dist/action/list/index.d.ts +23 -0
  10. package/dist/action/list/index.js +44 -0
  11. package/dist/action/list/store.d.ts +3 -0
  12. package/dist/action/list/store.js +1 -0
  13. package/dist/action/list/style.d.ts +2 -0
  14. package/dist/action/list/style.js +14 -0
  15. package/dist/action/list/trigger.d.ts +12 -0
  16. package/dist/action/list/trigger.js +124 -0
  17. package/dist/action/list/utils.d.ts +18 -0
  18. package/dist/action/list/utils.js +68 -0
  19. package/dist/action/portal.d.ts +3 -0
  20. package/dist/action/portal.js +9 -0
  21. package/dist/action/selector.d.ts +15 -0
  22. package/dist/action/selector.js +71 -0
  23. package/dist/action/tip.d.ts +6 -0
  24. package/dist/action/tip.js +12 -0
  25. package/dist/index.d.ts +3 -0
  26. package/dist/index.js +3 -0
  27. package/dist/server/index.d.ts +5 -0
  28. package/dist/server/index.js +5 -0
  29. package/dist/server/json.d.ts +1 -0
  30. package/dist/server/json.js +16 -0
  31. package/dist/server/parseFormData.d.ts +20 -0
  32. package/dist/server/parseFormData.js +63 -0
  33. package/dist/server/parseQuery.d.ts +11 -0
  34. package/dist/server/parseQuery.js +15 -0
  35. package/dist/server/sse.d.ts +6 -0
  36. package/dist/server/sse.js +35 -0
  37. package/dist/server/try.d.ts +6 -0
  38. package/dist/server/try.js +31 -0
  39. package/dist/store/index.d.ts +2 -0
  40. package/dist/store/index.js +2 -0
  41. package/dist/store/isSmallScreen.d.ts +2 -0
  42. package/dist/store/isSmallScreen.js +14 -0
  43. package/dist/store/param.d.ts +24 -0
  44. package/dist/store/param.js +61 -0
  45. package/dist/store/session.d.ts +2 -0
  46. package/dist/store/session.js +13 -0
  47. package/dist/ui/ButtonCopy.svelte +18 -0
  48. package/dist/ui/ButtonCopy.svelte.d.ts +18 -0
  49. package/dist/ui/ButtonDelete.svelte +43 -0
  50. package/dist/ui/ButtonDelete.svelte.d.ts +22 -0
  51. package/dist/ui/Dialog.svelte +58 -0
  52. package/dist/ui/Dialog.svelte.d.ts +25 -0
  53. package/dist/ui/DialogConfirm.svelte +22 -0
  54. package/dist/ui/DialogConfirm.svelte.d.ts +21 -0
  55. package/dist/ui/Icon.svelte +46 -0
  56. package/dist/ui/Icon.svelte.d.ts +24 -0
  57. package/dist/ui/Pagination.svelte +28 -0
  58. package/dist/ui/Pagination.svelte.d.ts +16 -0
  59. package/dist/ui/Placeholder.svelte +11 -0
  60. package/dist/ui/Placeholder.svelte.d.ts +19 -0
  61. package/dist/ui/PlaceholderImage.svelte +14 -0
  62. package/dist/ui/PlaceholderImage.svelte.d.ts +19 -0
  63. package/dist/ui/card/Card.svelte +38 -0
  64. package/dist/ui/card/Card.svelte.d.ts +26 -0
  65. package/dist/ui/card/CardBasic.svelte +14 -0
  66. package/dist/ui/card/CardBasic.svelte.d.ts +20 -0
  67. package/dist/ui/card/CardCollapse.svelte +61 -0
  68. package/dist/ui/card/CardCollapse.svelte.d.ts +22 -0
  69. package/dist/ui/card/CardFullScreen.svelte +28 -0
  70. package/dist/ui/card/CardFullScreen.svelte.d.ts +23 -0
  71. package/dist/ui/card/CardLink.svelte +21 -0
  72. package/dist/ui/card/CardLink.svelte.d.ts +20 -0
  73. package/dist/ui/card/index.d.ts +5 -0
  74. package/dist/ui/card/index.js +5 -0
  75. package/dist/ui/index.d.ts +14 -0
  76. package/dist/ui/index.js +14 -0
  77. package/dist/ui/input/FormControl.svelte +53 -0
  78. package/dist/ui/input/FormControl.svelte.d.ts +30 -0
  79. package/dist/ui/input/InputBoolean.svelte +29 -0
  80. package/dist/ui/input/InputBoolean.svelte.d.ts +21 -0
  81. package/dist/ui/input/InputCheckboxs.svelte +68 -0
  82. package/dist/ui/input/InputCheckboxs.svelte.d.ts +41 -0
  83. package/dist/ui/input/InputCheckboxsMenu.svelte +93 -0
  84. package/dist/ui/input/InputCheckboxsMenu.svelte.d.ts +43 -0
  85. package/dist/ui/input/InputCheckboxsTree.svelte +15 -0
  86. package/dist/ui/input/InputCheckboxsTree.svelte.d.ts +21 -0
  87. package/dist/ui/input/InputCheckboxsTreeNodes.svelte +60 -0
  88. package/dist/ui/input/InputCheckboxsTreeNodes.svelte.d.ts +23 -0
  89. package/dist/ui/input/InputDate.svelte +26 -0
  90. package/dist/ui/input/InputDate.svelte.d.ts +19 -0
  91. package/dist/ui/input/InputDatetime.svelte +21 -0
  92. package/dist/ui/input/InputDatetime.svelte.d.ts +19 -0
  93. package/dist/ui/input/InputImage.svelte +107 -0
  94. package/dist/ui/input/InputImage.svelte.d.ts +35 -0
  95. package/dist/ui/input/InputImagePreview.svelte +56 -0
  96. package/dist/ui/input/InputImagePreview.svelte.d.ts +23 -0
  97. package/dist/ui/input/InputNumber.svelte +22 -0
  98. package/dist/ui/input/InputNumber.svelte.d.ts +23 -0
  99. package/dist/ui/input/InputOptionInParam.svelte +34 -0
  100. package/dist/ui/input/InputOptionInParam.svelte.d.ts +20 -0
  101. package/dist/ui/input/InputOptions.svelte +79 -0
  102. package/dist/ui/input/InputOptions.svelte.d.ts +17 -0
  103. package/dist/ui/input/InputPassword.svelte +21 -0
  104. package/dist/ui/input/InputPassword.svelte.d.ts +36 -0
  105. package/dist/ui/input/InputRadio.svelte +79 -0
  106. package/dist/ui/input/InputRadio.svelte.d.ts +40 -0
  107. package/dist/ui/input/InputRelation.svelte +114 -0
  108. package/dist/ui/input/InputRelation.svelte.d.ts +52 -0
  109. package/dist/ui/input/InputRelations.svelte +138 -0
  110. package/dist/ui/input/InputRelations.svelte.d.ts +49 -0
  111. package/dist/ui/input/InputSearch.svelte +43 -0
  112. package/dist/ui/input/InputSearch.svelte.d.ts +23 -0
  113. package/dist/ui/input/InputSelect.svelte +59 -0
  114. package/dist/ui/input/InputSelect.svelte.d.ts +26 -0
  115. package/dist/ui/input/InputText.svelte +32 -0
  116. package/dist/ui/input/InputText.svelte.d.ts +31 -0
  117. package/dist/ui/input/InputTextarea.svelte +20 -0
  118. package/dist/ui/input/InputTextarea.svelte.d.ts +23 -0
  119. package/dist/ui/input/InputTime.svelte +19 -0
  120. package/dist/ui/input/InputTime.svelte.d.ts +19 -0
  121. package/dist/ui/input/RelationAfter.svelte +42 -0
  122. package/dist/ui/input/RelationAfter.svelte.d.ts +22 -0
  123. package/dist/ui/input/SelectorList.svelte +46 -0
  124. package/dist/ui/input/SelectorList.svelte.d.ts +40 -0
  125. package/dist/ui/input/action.d.ts +13 -0
  126. package/dist/ui/input/action.js +56 -0
  127. package/dist/ui/input/index.d.ts +25 -0
  128. package/dist/ui/input/index.js +25 -0
  129. package/dist/ui/input/textRich/InputTextRich.svelte +58 -0
  130. package/dist/ui/input/textRich/InputTextRich.svelte.d.ts +20 -0
  131. package/dist/ui/input/textRich/SuggesionList.svelte +21 -0
  132. package/dist/ui/input/textRich/SuggesionList.svelte.d.ts +19 -0
  133. package/dist/ui/input/textRich/ToolMark.svelte +19 -0
  134. package/dist/ui/input/textRich/ToolMark.svelte.d.ts +21 -0
  135. package/dist/ui/input/textRich/ToolMarkColor.svelte +32 -0
  136. package/dist/ui/input/textRich/ToolMarkColor.svelte.d.ts +19 -0
  137. package/dist/ui/input/textRich/ToolMarkLink.svelte +63 -0
  138. package/dist/ui/input/textRich/ToolMarkLink.svelte.d.ts +17 -0
  139. package/dist/ui/input/textRich/ToolMenu.svelte +50 -0
  140. package/dist/ui/input/textRich/ToolMenu.svelte.d.ts +29 -0
  141. package/dist/ui/input/textRich/ToolMenuAlign.svelte +46 -0
  142. package/dist/ui/input/textRich/ToolMenuAlign.svelte.d.ts +17 -0
  143. package/dist/ui/input/textRich/ToolMenuInsert.svelte +49 -0
  144. package/dist/ui/input/textRich/ToolMenuInsert.svelte.d.ts +19 -0
  145. package/dist/ui/input/textRich/ToolMenuNode.svelte +56 -0
  146. package/dist/ui/input/textRich/ToolMenuNode.svelte.d.ts +17 -0
  147. package/dist/ui/input/textRich/ToolsBar.svelte +60 -0
  148. package/dist/ui/input/textRich/ToolsBar.svelte.d.ts +18 -0
  149. package/dist/ui/input/textRich/extensions.d.ts +2 -0
  150. package/dist/ui/input/textRich/extensions.js +62 -0
  151. package/dist/ui/input/textRich/indent.d.ts +13 -0
  152. package/dist/ui/input/textRich/indent.js +112 -0
  153. package/dist/ui/input/textRich/suggestion.d.ts +9 -0
  154. package/dist/ui/input/textRich/suggestion.js +56 -0
  155. package/dist/ui/input/types.d.ts +15 -0
  156. package/dist/ui/input/types.js +1 -0
  157. package/dist/ui/menu/ContextMenu.svelte +47 -0
  158. package/dist/ui/menu/ContextMenu.svelte.d.ts +28 -0
  159. package/dist/ui/menu/DropDown.svelte +110 -0
  160. package/dist/ui/menu/DropDown.svelte.d.ts +38 -0
  161. package/dist/ui/menu/dropdown.css +33 -0
  162. package/dist/ui/menu/index.d.ts +2 -0
  163. package/dist/ui/menu/index.js +2 -0
  164. package/dist/ui/period/PeriodPicker.svelte +53 -0
  165. package/dist/ui/period/PeriodPicker.svelte.d.ts +22 -0
  166. package/dist/ui/period/PeriodPickerButton.svelte +73 -0
  167. package/dist/ui/period/PeriodPickerButton.svelte.d.ts +14 -0
  168. package/dist/ui/period/index.d.ts +6 -0
  169. package/dist/ui/period/index.js +2 -0
  170. package/dist/ui/table/Table.svelte +42 -0
  171. package/dist/ui/table/Table.svelte.d.ts +39 -0
  172. package/dist/ui/table/TableBody.svelte +29 -0
  173. package/dist/ui/table/TableBody.svelte.d.ts +33 -0
  174. package/dist/ui/table/TableCell.svelte +27 -0
  175. package/dist/ui/table/TableCell.svelte.d.ts +28 -0
  176. package/dist/ui/table/TableFieldsEdition.svelte +122 -0
  177. package/dist/ui/table/TableFieldsEdition.svelte.d.ts +31 -0
  178. package/dist/ui/table/TableHead.svelte +31 -0
  179. package/dist/ui/table/TableHead.svelte.d.ts +29 -0
  180. package/dist/ui/table/TableViewSelect.svelte +127 -0
  181. package/dist/ui/table/TableViewSelect.svelte.d.ts +24 -0
  182. package/dist/ui/table/cell/TableCellArray.svelte +10 -0
  183. package/dist/ui/table/cell/TableCellArray.svelte.d.ts +16 -0
  184. package/dist/ui/table/cell/TableCellBoolean.svelte +12 -0
  185. package/dist/ui/table/cell/TableCellBoolean.svelte.d.ts +16 -0
  186. package/dist/ui/table/cell/TableCellNumber.svelte +6 -0
  187. package/dist/ui/table/cell/TableCellNumber.svelte.d.ts +16 -0
  188. package/dist/ui/table/cell/TableCellString.svelte +7 -0
  189. package/dist/ui/table/cell/TableCellString.svelte.d.ts +18 -0
  190. package/dist/ui/table/cell/index.d.ts +4 -0
  191. package/dist/ui/table/cell/index.js +4 -0
  192. package/dist/ui/table/context.d.ts +14 -0
  193. package/dist/ui/table/context.js +10 -0
  194. package/dist/ui/table/field.d.ts +79 -0
  195. package/dist/ui/table/field.js +29 -0
  196. package/dist/ui/table/head/TableHeadBoolean.svelte +12 -0
  197. package/dist/ui/table/head/TableHeadBoolean.svelte.d.ts +17 -0
  198. package/dist/ui/table/head/TableHeadDate.svelte +100 -0
  199. package/dist/ui/table/head/TableHeadDate.svelte.d.ts +17 -0
  200. package/dist/ui/table/head/TableHeadDefault.svelte +7 -0
  201. package/dist/ui/table/head/TableHeadDefault.svelte.d.ts +17 -0
  202. package/dist/ui/table/head/TableHeadNumber.svelte +80 -0
  203. package/dist/ui/table/head/TableHeadNumber.svelte.d.ts +17 -0
  204. package/dist/ui/table/head/TableHeadSelect.svelte +75 -0
  205. package/dist/ui/table/head/TableHeadSelect.svelte.d.ts +20 -0
  206. package/dist/ui/table/head/TableHeadString.svelte +35 -0
  207. package/dist/ui/table/head/TableHeadString.svelte.d.ts +17 -0
  208. package/dist/ui/table/head/index.d.ts +19 -0
  209. package/dist/ui/table/head/index.js +22 -0
  210. package/dist/ui/table/index.d.ts +10 -0
  211. package/dist/ui/table/index.js +10 -0
  212. package/dist/ui/table/server.d.ts +1 -0
  213. package/dist/ui/table/server.js +32 -0
  214. package/dist/ui/tabs/Tabs.svelte +28 -0
  215. package/dist/ui/tabs/Tabs.svelte.d.ts +18 -0
  216. package/dist/ui/tabs/TabsIcon.svelte +56 -0
  217. package/dist/ui/tabs/TabsIcon.svelte.d.ts +20 -0
  218. package/dist/ui/tabs/index.d.ts +8 -0
  219. package/dist/ui/tabs/index.js +2 -0
  220. package/dist/utils/avatar.d.ts +1 -0
  221. package/dist/utils/avatar.js +5 -0
  222. package/dist/utils/component.d.ts +7 -0
  223. package/dist/utils/component.js +3 -0
  224. package/dist/utils/formatRange.d.ts +8 -0
  225. package/dist/utils/formatRange.js +25 -0
  226. package/dist/utils/index.d.ts +7 -0
  227. package/dist/utils/index.js +7 -0
  228. package/dist/utils/jsonParse.d.ts +1 -0
  229. package/dist/utils/jsonParse.js +10 -0
  230. package/dist/utils/normalizePath.d.ts +1 -0
  231. package/dist/utils/normalizePath.js +11 -0
  232. package/dist/utils/options.d.ts +7 -0
  233. package/dist/utils/options.js +20 -0
  234. package/dist/utils/tippy.d.ts +5 -0
  235. package/dist/utils/tippy.js +4 -0
  236. package/dist/validation/form.d.ts +31 -0
  237. package/dist/validation/form.js +94 -0
  238. package/dist/validation/index.d.ts +2 -0
  239. package/dist/validation/index.js +2 -0
  240. package/dist/validation/zod.d.ts +338 -0
  241. package/dist/validation/zod.js +100 -0
  242. package/package.json +86 -0
@@ -0,0 +1,71 @@
1
+ export function selector(node, { trigger, focusIndex = -1, listQuerySelector = 'ul', itemsQuerySelector = 'li', onSelect = () => { }, onFocus = () => { }, keyDownEvent = undefined, keyDownPreventDefault = true, }) {
2
+ trigger?.addEventListener('keydown', handleKeydown);
3
+ function handleKeydown(event) {
4
+ const items = node.querySelectorAll(itemsQuerySelector);
5
+ if (event.key === 'Enter') {
6
+ if (keyDownPreventDefault)
7
+ event.preventDefault();
8
+ onSelect(focusIndex);
9
+ return;
10
+ }
11
+ if (event.key === 'ArrowUp') {
12
+ if (keyDownPreventDefault)
13
+ event.preventDefault();
14
+ focusIndex--;
15
+ if (focusIndex < 0)
16
+ focusIndex = items.length - 1;
17
+ onFocus(focusIndex);
18
+ scrollToSelected(items);
19
+ return;
20
+ }
21
+ if (event.key === 'ArrowDown') {
22
+ if (keyDownPreventDefault)
23
+ event.preventDefault();
24
+ focusIndex++;
25
+ if (focusIndex > items.length - 1)
26
+ focusIndex = 0;
27
+ onFocus(focusIndex);
28
+ scrollToSelected(items);
29
+ return;
30
+ }
31
+ }
32
+ function scrollToSelected(items) {
33
+ const list = node.tagName === 'UL' ? node : node.querySelector(listQuerySelector);
34
+ if (!(list instanceof HTMLElement)) {
35
+ console.error('wrapper element not found');
36
+ return;
37
+ }
38
+ const item = items[focusIndex];
39
+ if (!item)
40
+ return;
41
+ const top = item.offsetTop - 4;
42
+ if (top < list.scrollTop) {
43
+ list.scrollTo({ top });
44
+ return;
45
+ }
46
+ const bottom = item.offsetTop + item.offsetHeight;
47
+ const delta = bottom - (list.scrollTop + list.offsetHeight) + 10;
48
+ if (delta > 0) {
49
+ list.scrollTo({ top: list.scrollTop + delta });
50
+ return;
51
+ }
52
+ }
53
+ return {
54
+ update(props) {
55
+ if (props.focusIndex !== undefined)
56
+ focusIndex = props.focusIndex;
57
+ if (props.trigger) {
58
+ trigger?.removeEventListener('keydown', handleKeydown);
59
+ trigger = props.trigger;
60
+ trigger?.addEventListener('keydown', handleKeydown);
61
+ }
62
+ if (props.keyDownEvent && keyDownEvent !== props.keyDownEvent) {
63
+ keyDownEvent = props.keyDownEvent;
64
+ handleKeydown(keyDownEvent);
65
+ }
66
+ },
67
+ destroy() {
68
+ trigger?.removeEventListener('keydown', handleKeydown);
69
+ },
70
+ };
71
+ }
@@ -0,0 +1,6 @@
1
+ import { type TippyProps } from '../utils/tippy.js';
2
+ export declare function tip(node: HTMLElement, options?: Partial<TippyProps> & {
3
+ disable?: boolean;
4
+ }): {
5
+ destroy(): void;
6
+ } | undefined;
@@ -0,0 +1,12 @@
1
+ import { tippy } from '../utils/tippy.js';
2
+ export function tip(node, options = { disable: false }) {
3
+ const { disable, ...tippyProps } = options;
4
+ if (disable)
5
+ return;
6
+ const _tip = tippy(node, tippyProps);
7
+ return {
8
+ destroy() {
9
+ _tip.destroy();
10
+ }
11
+ };
12
+ }
@@ -0,0 +1,3 @@
1
+ export * from './ui/index.js';
2
+ export * from './utils/index.js';
3
+ export * from './store/index.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './ui/index.js';
2
+ export * from './utils/index.js';
3
+ export * from './store/index.js';
@@ -0,0 +1,5 @@
1
+ export * from './json.js';
2
+ export * from './parseFormData.js';
3
+ export * from './parseQuery.js';
4
+ export * from './sse.js';
5
+ export * from './try.js';
@@ -0,0 +1,5 @@
1
+ export * from './json.js';
2
+ export * from './parseFormData.js';
3
+ export * from './parseQuery.js';
4
+ export * from './sse.js';
5
+ export * from './try.js';
@@ -0,0 +1 @@
1
+ export declare function json(data: unknown, init?: ResponseInit): Response;
@@ -0,0 +1,16 @@
1
+ import * as devalue from 'devalue';
2
+ export function json(data, init) {
3
+ const body = devalue.stringify(data);
4
+ const headers = new Headers(init?.headers);
5
+ if (!headers.has('content-length')) {
6
+ headers.set('content-length', encoder.encode(body).byteLength.toString());
7
+ }
8
+ if (!headers.has('content-type')) {
9
+ headers.set('content-type', 'application/json');
10
+ }
11
+ return new Response(body, {
12
+ ...init,
13
+ headers,
14
+ });
15
+ }
16
+ const encoder = new TextEncoder();
@@ -0,0 +1,20 @@
1
+ /// <reference types="@sveltejs/kit" />
2
+ import z from 'zod';
3
+ export declare function parseFormData<Type extends z.ZodRawShape>(requestOrFormData: Request | FormData, shaps: Type | Type[], validation?: z.SuperRefinement<z.objectOutputType<Type, z.ZodTypeAny>>): Promise<{
4
+ formData: FormData;
5
+ err: import("@sveltejs/kit").ActionFailure<{
6
+ issues: {
7
+ message: string;
8
+ path: (string | number)[];
9
+ code: "invalid_type" | "invalid_literal" | "unrecognized_keys" | "invalid_union" | "invalid_union_discriminator" | "invalid_enum_value" | "invalid_arguments" | "invalid_return_type" | "invalid_date" | "invalid_string" | "too_small" | "too_big" | "invalid_intersection_types" | "not_multiple_of" | "not_finite" | "custom";
10
+ received: string;
11
+ expected: string;
12
+ unionErrors: z.typeToFlattenedError<any, string>[] | undefined;
13
+ }[];
14
+ }>;
15
+ data?: undefined;
16
+ } | {
17
+ data: { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Type>, { [k in keyof z.baseObjectOutputType<Type>]: undefined extends z.baseObjectOutputType<Type>[k] ? never : k; }[keyof Type]>]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Type>, { [k_2 in keyof z.baseObjectOutputType<Type>]: undefined extends z.baseObjectOutputType<Type>[k_2] ? never : k_2; }[keyof Type]>[k_1]; };
18
+ formData: FormData;
19
+ err?: undefined;
20
+ }>;
@@ -0,0 +1,63 @@
1
+ import z from 'zod';
2
+ import { fail } from '@sveltejs/kit';
3
+ export async function parseFormData(requestOrFormData, shaps, validation) {
4
+ const formData = requestOrFormData instanceof Request ? await requestOrFormData.formData() : requestOrFormData;
5
+ const [firstShap, ...unionShaps] = Array.isArray(shaps) ? shaps : [shaps];
6
+ const shema = z.object(firstShap).superRefine(validation || (() => { }));
7
+ unionShaps.forEach((shap) => shema.or(z.object(shap)));
8
+ const formDataFlateObject = Object.fromEntries(formData);
9
+ const formDataObject = flateToNeestedObject(formDataFlateObject);
10
+ const parsed = shema.safeParse(formDataObject);
11
+ if (parsed.success === false) {
12
+ const issueToPOJO = (issue) => ({
13
+ message: issue.message,
14
+ path: issue.path,
15
+ code: issue.code,
16
+ received: issue.received,
17
+ expected: issue.expected,
18
+ unionErrors: issue.unionErrors?.map((err) => err.flatten()),
19
+ });
20
+ const issues = parsed.error.issues.map(issueToPOJO);
21
+ return { formData, err: fail(400, { issues }) };
22
+ }
23
+ return { data: parsed.data, formData };
24
+ }
25
+ function flateToNeestedObject(flatObject) {
26
+ const obj = {};
27
+ Object.entries(flatObject).forEach(([key, value]) => {
28
+ set(obj, key, value);
29
+ });
30
+ return obj;
31
+ }
32
+ function set(obj, path, value) {
33
+ if (typeof path === 'number')
34
+ path = [path];
35
+ if (!path || path.length === 0)
36
+ return obj;
37
+ if (typeof path === 'string')
38
+ return set(obj, path.split('.').map(getKey), value);
39
+ const currentPath = path[0];
40
+ const currentValue = obj[currentPath];
41
+ if (path.length === 1) {
42
+ if (currentValue === undefined) {
43
+ obj[currentPath] = value;
44
+ }
45
+ return currentValue;
46
+ }
47
+ if (currentValue === undefined) {
48
+ //check if we assume an array
49
+ if (typeof path[1] === 'number') {
50
+ obj[currentPath] = [];
51
+ }
52
+ else {
53
+ obj[currentPath] = {};
54
+ }
55
+ }
56
+ return set(obj[currentPath], path.slice(1), value);
57
+ }
58
+ function getKey(key) {
59
+ const intKey = parseInt(key);
60
+ if (intKey.toString() === key)
61
+ return intKey;
62
+ return key;
63
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="@sveltejs/kit" />
2
+ import type { ZodRawShape } from 'zod';
3
+ export declare function parseQuery<Type extends ZodRawShape>(url: URL, shape: Type): {
4
+ err: import("@sveltejs/kit").ActionFailure<{
5
+ issues: import("zod").ZodIssue[];
6
+ }>;
7
+ data?: undefined;
8
+ } | {
9
+ data: { [k_1 in keyof import("zod").objectUtil.addQuestionMarks<import("zod").baseObjectOutputType<Type>, { [k in keyof import("zod").baseObjectOutputType<Type>]: undefined extends import("zod").baseObjectOutputType<Type>[k] ? never : k; }[keyof Type]>]: import("zod").objectUtil.addQuestionMarks<import("zod").baseObjectOutputType<Type>, { [k_2 in keyof import("zod").baseObjectOutputType<Type>]: undefined extends import("zod").baseObjectOutputType<Type>[k_2] ? never : k_2; }[keyof Type]>[k_1]; };
10
+ err?: undefined;
11
+ };
@@ -0,0 +1,15 @@
1
+ import { fail } from '@sveltejs/kit';
2
+ import { z } from '../validation/zod.js';
3
+ export function parseQuery(url, shape) {
4
+ const queryRaw = {};
5
+ Object.keys(shape).forEach((name) => {
6
+ const param = url.searchParams.get(name);
7
+ if (param)
8
+ queryRaw[name] = param;
9
+ });
10
+ const parsed = z.object(shape).safeParse(queryRaw);
11
+ if (parsed.success === false) {
12
+ return { err: fail(400, { issues: parsed.error.issues }) };
13
+ }
14
+ return { data: parsed.data };
15
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import type { EventEmitter } from 'node:events';
3
+ export declare function createSSE(last_id?: number, retry?: number): {
4
+ readable: ReadableStream<any>;
5
+ subscribe(eventEmitter: EventEmitter, event: string): Promise<void>;
6
+ };
@@ -0,0 +1,35 @@
1
+ // thanks: https://github.com/sveltejs/kit/issues/5344#issuecomment-1265286081
2
+ export function createSSE(last_id = 0, retry = 0) {
3
+ let id = last_id;
4
+ const { readable, writable } = new TransformStream({
5
+ start(controller) {
6
+ controller.enqueue(': hello\n\n');
7
+ if (retry > 0)
8
+ controller.enqueue(`retry: ${retry}\n\n`);
9
+ },
10
+ transform({ event, data }, controller) {
11
+ let msg = `id: ${++id}\n`;
12
+ if (event)
13
+ msg += `event: ${event}\n`;
14
+ if (typeof data === 'string') {
15
+ msg += 'data: ' + data.trim().replace(/\n+/gm, '\ndata: ') + '\n';
16
+ }
17
+ else {
18
+ msg += `data: ${JSON.stringify(data)}\n`;
19
+ }
20
+ controller.enqueue(msg + '\n');
21
+ },
22
+ });
23
+ const writer = writable.getWriter();
24
+ return {
25
+ readable,
26
+ async subscribe(eventEmitter, event) {
27
+ function listener(data) {
28
+ writer.write({ event, data });
29
+ }
30
+ eventEmitter.on(event, listener);
31
+ await writer.closed.catch(() => { });
32
+ eventEmitter.off(event, listener);
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,6 @@
1
+ import { type ActionFailure } from '@sveltejs/kit';
2
+ export declare function tryOrFail<T = unknown>(fn: () => Promise<T>,
3
+ /** You can redirect on success */
4
+ redirectTo?: string | ((res: T) => string)): Promise<T | ActionFailure<{
5
+ message: string;
6
+ }>>;
@@ -0,0 +1,31 @@
1
+ import { fail, redirect } from '@sveltejs/kit';
2
+ export async function tryOrFail(fn,
3
+ /** You can redirect on success */
4
+ redirectTo) {
5
+ let result = null;
6
+ let isSuccess = false;
7
+ try {
8
+ result = await fn();
9
+ isSuccess = true;
10
+ return result;
11
+ }
12
+ catch (error) {
13
+ if ('status' in error && 'body' in error && 'message' in error.body) {
14
+ return fail(error.status, { message: error.body.message });
15
+ }
16
+ if ('meta' in error && error.meta && 'cause' in error.meta) {
17
+ return fail(400, { message: error.meta.cause });
18
+ }
19
+ const { message } = error;
20
+ return fail(400, { message });
21
+ }
22
+ finally {
23
+ if (isSuccess && redirectTo) {
24
+ if (typeof redirectTo === 'string')
25
+ redirect(302, redirectTo);
26
+ else if (result)
27
+ redirect(302, redirectTo(result));
28
+ console.warn('No result can be provide in redirectTo() function. Please use a simple string.');
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,2 @@
1
+ export * from './isSmallScreen.js';
2
+ export * from './param.js';
@@ -0,0 +1,2 @@
1
+ export * from './isSmallScreen.js';
2
+ export * from './param.js';
@@ -0,0 +1,2 @@
1
+ /// <reference types="svelte" />
2
+ export declare const isSmallScreen: import("svelte/store").Readable<boolean>;
@@ -0,0 +1,14 @@
1
+ import { browser } from '$app/environment';
2
+ import { readable } from 'svelte/store';
3
+ const getValue = () => browser && document.body.clientWidth < 600;
4
+ export const isSmallScreen = readable(getValue(), (set) => {
5
+ if (!browser)
6
+ return;
7
+ const update = () => {
8
+ set(getValue());
9
+ };
10
+ window.addEventListener('resize', update);
11
+ return () => {
12
+ window.removeEventListener('resize', update);
13
+ };
14
+ });
@@ -0,0 +1,24 @@
1
+ /// <reference types="svelte" />
2
+ /// <reference types="@sveltejs/kit" />
3
+ export declare const param: import("svelte/store").Readable<{
4
+ with: (params: Record<string, string | number>, ...keysToRemove: string[]) => string;
5
+ without: (...keys: string[]) => string;
6
+ toggle: (params: Record<string, string>, ...keysToRemove: string[]) => string;
7
+ /** Check if key exist in url params */
8
+ has: (key: string) => boolean;
9
+ get: (key: string) => string | null;
10
+ /** Check if value match in url params */
11
+ hasValue: (key: string, value: string) => boolean;
12
+ page: import("@sveltejs/kit").Page<Record<string, string>, string | null>;
13
+ }>;
14
+ export declare const urlParam: import("svelte/store").Readable<{
15
+ with: (params: Record<string, string | number>, ...keysToRemove: string[]) => string;
16
+ without: (...keys: string[]) => string;
17
+ toggle: (params: Record<string, string>, ...keysToRemove: string[]) => string;
18
+ /** Check if key exist in url params */
19
+ has: (key: string) => boolean;
20
+ get: (key: string) => string | null;
21
+ /** Check if value match in url params */
22
+ hasValue: (key: string, value: string) => boolean;
23
+ page: import("@sveltejs/kit").Page<Record<string, string>, string | null>;
24
+ }>;
@@ -0,0 +1,61 @@
1
+ import { derived } from 'svelte/store';
2
+ import { page } from '$app/stores';
3
+ export const param = derived(page, (_page) => {
4
+ /** Return new url with new params */
5
+ const _with = (params, ...keysToRemove) => {
6
+ const url = new URL(_page.url);
7
+ Object.entries(params).forEach(([key, value]) => url.searchParams.set(key, String(value)));
8
+ keysToRemove.forEach((key) => url.searchParams.delete(key));
9
+ return url.search;
10
+ };
11
+ /** Return new url without params keys provided */
12
+ const without = (...keys) => {
13
+ const url = new URL(_page.url);
14
+ keys.forEach((key) => url.searchParams.delete(key));
15
+ return url.search;
16
+ };
17
+ /** Return new url with toggle params */
18
+ const toggle = (params, ...keysToRemove) => {
19
+ const url = new URL(_page.url);
20
+ Object.entries(params).forEach(([key, value]) => {
21
+ if (url.searchParams.get(key) === value)
22
+ url.searchParams.delete(key);
23
+ else
24
+ url.searchParams.set(key, value);
25
+ });
26
+ keysToRemove.forEach((key) => url.searchParams.delete(key));
27
+ return url.search;
28
+ };
29
+ return {
30
+ with: _with,
31
+ without,
32
+ toggle,
33
+ /** Check if key exist in url params */
34
+ has: (key) => _page.url.searchParams.has(key),
35
+ get: (key) => _page.url.searchParams.get(key),
36
+ /** Check if value match in url params */
37
+ hasValue: (key, value) => _page.url.searchParams.get(key) === value,
38
+ page: _page
39
+ };
40
+ });
41
+ export const urlParam = derived(param, (_param) => {
42
+ const { pathname } = _param.page.url;
43
+ /** Return new url with new params */
44
+ const _with = (params, ...keysToRemove) => {
45
+ return pathname + _param.with(params, ...keysToRemove);
46
+ };
47
+ /** Return new url without params keys provided */
48
+ const without = (...keys) => {
49
+ return pathname + _param.without(...keys);
50
+ };
51
+ /** Return new url with toggle params */
52
+ const toggle = (params, ...keysToRemove) => {
53
+ return pathname + _param.toggle(params, ...keysToRemove);
54
+ };
55
+ return {
56
+ ..._param,
57
+ with: _with,
58
+ without,
59
+ toggle
60
+ };
61
+ });
@@ -0,0 +1,2 @@
1
+ /// <reference types="svelte" />
2
+ export declare function sessionStore<T>(key: string, value: T): import("svelte/store").Writable<T>;
@@ -0,0 +1,13 @@
1
+ import { writable } from 'svelte/store';
2
+ import { browser } from '$app/environment';
3
+ import { jsonParse } from '../utils/index.js';
4
+ export function sessionStore(key, value) {
5
+ if (!browser)
6
+ return writable(value);
7
+ const initialValue = jsonParse(sessionStorage.getItem(key), value);
8
+ const store = writable(initialValue);
9
+ store.subscribe((newValue) => {
10
+ sessionStorage.setItem(key, JSON.stringify(newValue));
11
+ });
12
+ return store;
13
+ }
@@ -0,0 +1,18 @@
1
+ <script>import { mdiClipboardTextOutline } from "@mdi/js";
2
+ import { toast } from "svelte-sonner";
3
+ import { Icon } from "./index.js";
4
+ export let value;
5
+ export let title;
6
+ export let successMessage = "Copied";
7
+ function handleClick() {
8
+ navigator.clipboard.writeText(value).then(() => {
9
+ toast.success(successMessage);
10
+ }).catch((error) => {
11
+ toast.error(error);
12
+ });
13
+ }
14
+ </script>
15
+
16
+ <button on:click|preventDefault={handleClick} class="btn btn-square btn-ghost btn-sm">
17
+ <Icon path={mdiClipboardTextOutline} {title} size={22} />
18
+ </button>
@@ -0,0 +1,18 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ value: string;
5
+ title: string;
6
+ successMessage?: string | undefined;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export type ButtonCopyProps = typeof __propDef.props;
14
+ export type ButtonCopyEvents = typeof __propDef.events;
15
+ export type ButtonCopySlots = typeof __propDef.slots;
16
+ export default class ButtonCopy extends SvelteComponent<ButtonCopyProps, ButtonCopyEvents, ButtonCopySlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,43 @@
1
+ <script>let klass = "";
2
+ export { klass as class };
3
+ export let formaction;
4
+ export let disabled = false;
5
+ export let btn = true;
6
+ let button;
7
+ let width = 0;
8
+ let ready = false;
9
+ let timeout;
10
+ function handleClick(event) {
11
+ if (ready)
12
+ return;
13
+ width = button.offsetWidth;
14
+ event.preventDefault();
15
+ ready = true;
16
+ timeout = setTimeout(() => ready = false, 2e3);
17
+ }
18
+ function handleLeave() {
19
+ ready = false;
20
+ clearTimeout(timeout);
21
+ }
22
+ </script>
23
+
24
+ <button
25
+ bind:this={button}
26
+ class={klass}
27
+ class:btn
28
+ class:btn-error={btn && ready}
29
+ class:btn-outline={btn && ready}
30
+ class:text-error={btn && !ready}
31
+ class:btn-ghost={btn && !ready}
32
+ class:btn-disabled={disabled}
33
+ style:width={ready ? `${width}px` : ''}
34
+ on:click={handleClick}
35
+ on:mouseleave={handleLeave}
36
+ formaction={ready ? formaction : undefined}
37
+ >
38
+ {#if ready}
39
+ <slot name="ready"><span>T'es sur ?</span></slot>
40
+ {:else}
41
+ <slot>Supprimer</slot>
42
+ {/if}
43
+ </button>
@@ -0,0 +1,22 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ class?: string | undefined;
5
+ formaction: string;
6
+ disabled?: boolean | undefined;
7
+ btn?: boolean | undefined;
8
+ };
9
+ events: {
10
+ [evt: string]: CustomEvent<any>;
11
+ };
12
+ slots: {
13
+ ready: {};
14
+ default: {};
15
+ };
16
+ };
17
+ export type ButtonDeleteProps = typeof __propDef.props;
18
+ export type ButtonDeleteEvents = typeof __propDef.events;
19
+ export type ButtonDeleteSlots = typeof __propDef.slots;
20
+ export default class ButtonDelete extends SvelteComponent<ButtonDeleteProps, ButtonDeleteEvents, ButtonDeleteSlots> {
21
+ }
22
+ export {};
@@ -0,0 +1,58 @@
1
+ <script>import { createEventDispatcher, onMount } from "svelte";
2
+ import { mdiClose } from "@mdi/js";
3
+ import { Icon } from "../index.js";
4
+ export let dialog;
5
+ export let hideCloseButton = false;
6
+ let klass = "";
7
+ export { klass as class };
8
+ const dispatch = createEventDispatcher();
9
+ onMount(() => {
10
+ const inputsSelector = 'input:not([type=hidden], [tabindex="-1"])';
11
+ const inputs = dialog.querySelectorAll(inputsSelector);
12
+ const buttons = dialog.querySelectorAll("button");
13
+ inputs.forEach((input) => input.tabIndex = -1);
14
+ buttons.forEach((button) => button.tabIndex = -1);
15
+ function onDialogOpen() {
16
+ dispatch("open");
17
+ inputs.forEach((input) => input.tabIndex = 0);
18
+ buttons.forEach((button) => button.tabIndex = 0);
19
+ if (!inputs[0])
20
+ return;
21
+ inputs[0].focus();
22
+ inputs[0].select();
23
+ }
24
+ function onDialogClose() {
25
+ dispatch("close");
26
+ inputs.forEach((input) => input.tabIndex = -1);
27
+ buttons.forEach((button) => button.tabIndex = -1);
28
+ }
29
+ const observer = new MutationObserver(() => dialog.open ? onDialogOpen() : onDialogClose());
30
+ observer.observe(dialog, { attributeFilter: ["open"] });
31
+ return () => observer.disconnect();
32
+ });
33
+ </script>
34
+
35
+ <dialog bind:this={dialog} class="modal" tabindex="-1">
36
+ <div class="modal-box p-0 rounded-lg flex flex-col border bordered">
37
+ <div class="p-4 border-b flex relative items-center">
38
+ <div class="grow">
39
+ <slot name="header" />
40
+ </div>
41
+
42
+ {#if !hideCloseButton}
43
+ <button
44
+ type="button"
45
+ class="btn btn-square btn-ghost btn-sm ml"
46
+ on:click={() => dialog.close()}
47
+ >
48
+ <Icon path={mdiClose} />
49
+ </button>
50
+ {/if}
51
+ </div>
52
+ <div class="p-4 grow overflow-auto {klass}">
53
+ <slot />
54
+ </div>
55
+
56
+ <slot name="footer" />
57
+ </div>
58
+ </dialog>
@@ -0,0 +1,25 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ dialog: HTMLDialogElement;
5
+ hideCloseButton?: boolean | undefined;
6
+ class?: string | undefined;
7
+ };
8
+ events: {
9
+ open: CustomEvent<void>;
10
+ close: CustomEvent<void>;
11
+ } & {
12
+ [evt: string]: CustomEvent<any>;
13
+ };
14
+ slots: {
15
+ header: {};
16
+ default: {};
17
+ footer: {};
18
+ };
19
+ };
20
+ export type DialogProps = typeof __propDef.props;
21
+ export type DialogEvents = typeof __propDef.events;
22
+ export type DialogSlots = typeof __propDef.slots;
23
+ export default class Dialog extends SvelteComponent<DialogProps, DialogEvents, DialogSlots> {
24
+ }
25
+ export {};