@marianmeres/stuic 1.126.0 → 2.0.0-next.3

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 (250) hide show
  1. package/README.md +2 -8
  2. package/dist/_shared.css +2 -0
  3. package/dist/actions/autogrow.svelte.d.ts +6 -0
  4. package/dist/actions/autogrow.svelte.js +19 -0
  5. package/dist/actions/highlight-dragover.svelte.d.ts +7 -0
  6. package/dist/actions/highlight-dragover.svelte.js +38 -0
  7. package/dist/actions/index.d.ts +7 -0
  8. package/dist/actions/index.js +7 -0
  9. package/dist/actions/on-submit-validity-check.svelte.d.ts +15 -0
  10. package/dist/actions/on-submit-validity-check.svelte.js +58 -0
  11. package/dist/actions/tooltip/index.css +34 -0
  12. package/dist/actions/tooltip/tooltip.svelte.d.ts +13 -0
  13. package/dist/actions/tooltip/tooltip.svelte.js +203 -0
  14. package/dist/actions/trim.svelte.d.ts +4 -0
  15. package/dist/actions/trim.svelte.js +17 -0
  16. package/dist/actions/{validate.d.ts → validate.svelte.d.ts} +8 -8
  17. package/dist/actions/validate.svelte.js +90 -0
  18. package/dist/components/AlertConfirmPrompt/AlertConfirmPrompt.svelte +59 -385
  19. package/dist/components/AlertConfirmPrompt/AlertConfirmPrompt.svelte.d.ts +9 -101
  20. package/dist/components/AlertConfirmPrompt/Current.svelte +202 -0
  21. package/dist/components/AlertConfirmPrompt/Current.svelte.d.ts +22 -0
  22. package/dist/components/AlertConfirmPrompt/acp-icons.d.ts +7 -2
  23. package/dist/components/AlertConfirmPrompt/acp-icons.js +8 -8
  24. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt-stack.svelte.d.ts +63 -0
  25. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt-stack.svelte.js +144 -0
  26. package/dist/components/AlertConfirmPrompt/index.d.ts +2 -0
  27. package/dist/components/AlertConfirmPrompt/index.js +2 -0
  28. package/dist/components/AnimatedElipsis/AnimatedEllipsis.svelte +47 -0
  29. package/dist/components/AnimatedElipsis/AnimatedEllipsis.svelte.d.ts +7 -0
  30. package/dist/components/AnimatedElipsis/index.d.ts +1 -0
  31. package/dist/components/AnimatedElipsis/index.js +1 -0
  32. package/dist/components/AppShell/AppShell.svelte +188 -127
  33. package/dist/components/AppShell/AppShell.svelte.d.ts +62 -43
  34. package/dist/components/AppShell/index.d.ts +1 -0
  35. package/dist/components/AppShell/index.js +1 -0
  36. package/dist/components/Backdrop/Backdrop.svelte +149 -49
  37. package/dist/components/Backdrop/Backdrop.svelte.d.ts +22 -37
  38. package/dist/components/Backdrop/index.d.ts +1 -0
  39. package/dist/components/Backdrop/index.js +1 -0
  40. package/dist/components/Button/Button.svelte +122 -146
  41. package/dist/components/Button/Button.svelte.d.ts +22 -80
  42. package/dist/components/Button/index.css +16 -0
  43. package/dist/components/Button/index.d.ts +1 -0
  44. package/dist/components/Button/index.js +1 -0
  45. package/dist/components/ColResize/ColResize.svelte +0 -0
  46. package/dist/components/ColResize/ColResize.svelte.d.ts +26 -0
  47. package/dist/components/ColorScheme/{LocalColorScheme.svelte → ColorSchemeLocal.svelte} +2 -2
  48. package/dist/components/ColorScheme/ColorSchemeLocal.svelte.d.ts +26 -0
  49. package/dist/components/ColorScheme/{SystemAwareColorScheme.svelte → ColorSchemeSystemAware.svelte} +4 -4
  50. package/dist/components/ColorScheme/ColorSchemeSystemAware.svelte.d.ts +26 -0
  51. package/dist/components/ColorScheme/color-scheme.d.ts +26 -8
  52. package/dist/components/ColorScheme/color-scheme.js +40 -16
  53. package/dist/components/ColorScheme/index.d.ts +3 -0
  54. package/dist/components/ColorScheme/index.js +3 -0
  55. package/dist/components/DismissibleMessage/DismissibleMessage.svelte +76 -83
  56. package/dist/components/DismissibleMessage/DismissibleMessage.svelte.d.ts +16 -37
  57. package/dist/components/DismissibleMessage/index.css +13 -0
  58. package/dist/components/DismissibleMessage/index.d.ts +1 -0
  59. package/dist/components/DismissibleMessage/index.js +1 -0
  60. package/dist/components/Drawer/Drawer.svelte +155 -84
  61. package/dist/components/Drawer/Drawer.svelte.d.ts +24 -35
  62. package/dist/components/Drawer/index.d.ts +1 -0
  63. package/dist/components/Drawer/index.js +1 -0
  64. package/dist/components/HoverExpandableWidth/HoverExpandableWidth.svelte +150 -111
  65. package/dist/components/HoverExpandableWidth/HoverExpandableWidth.svelte.d.ts +16 -29
  66. package/dist/components/HoverExpandableWidth/index.d.ts +1 -0
  67. package/dist/components/HoverExpandableWidth/index.js +1 -0
  68. package/dist/components/Input/FieldCheckbox.svelte +174 -132
  69. package/dist/components/Input/FieldCheckbox.svelte.d.ts +28 -64
  70. package/dist/components/Input/FieldFile.svelte +166 -0
  71. package/dist/components/Input/FieldFile.svelte.d.ts +41 -0
  72. package/dist/components/Input/FieldInput.svelte +143 -0
  73. package/dist/components/Input/FieldInput.svelte.d.ts +41 -0
  74. package/dist/components/Input/FieldLikeButton.svelte +206 -0
  75. package/dist/components/Input/FieldLikeButton.svelte.d.ts +41 -0
  76. package/dist/components/Input/FieldOptions.svelte +646 -0
  77. package/dist/components/Input/FieldOptions.svelte.d.ts +58 -0
  78. package/dist/components/Input/FieldRadios.svelte +126 -77
  79. package/dist/components/Input/FieldRadios.svelte.d.ts +23 -61
  80. package/dist/components/Input/FieldSelect.svelte +160 -239
  81. package/dist/components/Input/FieldSelect.svelte.d.ts +40 -88
  82. package/dist/components/Input/FieldSwitch.svelte +132 -0
  83. package/dist/components/Input/FieldSwitch.svelte.d.ts +41 -0
  84. package/dist/components/Input/FieldTextarea.svelte +146 -0
  85. package/dist/components/Input/FieldTextarea.svelte.d.ts +44 -0
  86. package/dist/components/Input/Fieldset.svelte +21 -17
  87. package/dist/components/Input/Fieldset.svelte.d.ts +10 -27
  88. package/dist/components/Input/_internal/FieldRadioInternal.svelte +186 -0
  89. package/dist/components/Input/_internal/FieldRadioInternal.svelte.d.ts +30 -0
  90. package/dist/components/Input/_internal/InputWrap.svelte +216 -0
  91. package/dist/components/Input/_internal/InputWrap.svelte.d.ts +36 -0
  92. package/dist/components/Input/index.css +134 -0
  93. package/dist/components/Input/index.d.ts +11 -0
  94. package/dist/components/Input/index.js +11 -0
  95. package/dist/components/Input/types.d.ts +11 -0
  96. package/dist/components/KbdShortcut/KbdShortcut.svelte +89 -0
  97. package/dist/components/KbdShortcut/KbdShortcut.svelte.d.ts +17 -0
  98. package/dist/components/KbdShortcut/index.d.ts +1 -0
  99. package/dist/components/KbdShortcut/index.js +1 -0
  100. package/dist/components/Modal/Modal.svelte +127 -0
  101. package/dist/components/Modal/Modal.svelte.d.ts +32 -0
  102. package/dist/components/Modal/index.d.ts +1 -0
  103. package/dist/components/Modal/index.js +1 -0
  104. package/dist/components/ModalDialog/ModalDialog.svelte +137 -81
  105. package/dist/components/ModalDialog/ModalDialog.svelte.d.ts +17 -38
  106. package/dist/components/ModalDialog/index.d.ts +1 -0
  107. package/dist/components/ModalDialog/index.js +1 -0
  108. package/dist/components/Notifications/Notifications.svelte +259 -173
  109. package/dist/components/Notifications/Notifications.svelte.d.ts +32 -60
  110. package/dist/components/Notifications/index.css +12 -0
  111. package/dist/components/Notifications/index.d.ts +2 -0
  112. package/dist/components/Notifications/index.js +2 -0
  113. package/dist/components/Notifications/notifications-icons.d.ts +1 -1
  114. package/dist/components/Notifications/notifications-icons.js +4 -4
  115. package/dist/components/Notifications/notifications-stack.svelte.d.ts +89 -0
  116. package/dist/components/Notifications/notifications-stack.svelte.js +161 -0
  117. package/dist/components/Progress/Progress.svelte +26 -0
  118. package/dist/components/Progress/Progress.svelte.d.ts +10 -0
  119. package/dist/components/Progress/_internal/Bar.svelte +31 -0
  120. package/dist/components/Progress/_internal/Bar.svelte.d.ts +10 -0
  121. package/dist/components/Progress/_internal/Circle.svelte +10 -0
  122. package/dist/components/Progress/_internal/Circle.svelte.d.ts +7 -0
  123. package/dist/components/Progress/index.css +7 -0
  124. package/dist/components/Progress/index.d.ts +1 -0
  125. package/dist/components/Progress/index.js +1 -0
  126. package/dist/components/Spinner/Spinner.svelte +56 -41
  127. package/dist/components/Spinner/Spinner.svelte.d.ts +10 -22
  128. package/dist/components/Spinner/index.d.ts +1 -0
  129. package/dist/components/Spinner/index.js +1 -0
  130. package/dist/components/Switch/Switch.svelte +158 -118
  131. package/dist/components/Switch/Switch.svelte.d.ts +25 -66
  132. package/dist/components/Switch/SwitchButton.svelte +131 -0
  133. package/dist/components/Switch/SwitchButton.svelte.d.ts +21 -0
  134. package/dist/components/Switch/index.css +7 -0
  135. package/dist/components/Switch/index.d.ts +2 -0
  136. package/dist/components/Switch/index.js +2 -0
  137. package/dist/components/Thc/Thc.svelte +67 -10
  138. package/dist/components/Thc/Thc.svelte.d.ts +18 -22
  139. package/dist/components/Thc/index.d.ts +1 -0
  140. package/dist/components/Thc/index.js +1 -0
  141. package/dist/components/TwCheck/TwCheck.svelte +34 -0
  142. package/dist/components/TwCheck/TwCheck.svelte.d.ts +10 -0
  143. package/dist/components/TwCheck/index.css +5 -0
  144. package/dist/components/TwCheck/index.d.ts +1 -0
  145. package/dist/components/TwCheck/index.js +1 -0
  146. package/dist/components/X/X.svelte +12 -5
  147. package/dist/components/X/X.svelte.d.ts +6 -18
  148. package/dist/components/X/index.d.ts +1 -0
  149. package/dist/components/X/index.js +1 -0
  150. package/dist/index.css +26 -0
  151. package/dist/index.d.ts +21 -39
  152. package/dist/index.js +23 -54
  153. package/dist/types.d.ts +251 -2
  154. package/dist/types.js +248 -0
  155. package/dist/utils/breakpoint.svelte.d.ts +19 -0
  156. package/dist/utils/breakpoint.svelte.js +42 -0
  157. package/dist/utils/debounce.d.ts +13 -0
  158. package/dist/utils/debounce.js +22 -0
  159. package/dist/utils/device-pointer.svelte.d.ts +11 -0
  160. package/dist/utils/device-pointer.svelte.js +26 -0
  161. package/dist/utils/event-modifiers.d.ts +4 -0
  162. package/dist/utils/event-modifiers.js +29 -0
  163. package/dist/utils/get-id.d.ts +1 -1
  164. package/dist/utils/get-id.js +3 -1
  165. package/dist/utils/index.d.ts +21 -0
  166. package/dist/utils/index.js +21 -0
  167. package/dist/utils/is-browser.d.ts +1 -0
  168. package/dist/utils/is-browser.js +5 -0
  169. package/dist/utils/is-mac.d.ts +1 -0
  170. package/dist/utils/is-mac.js +11 -0
  171. package/dist/utils/maybe-json-parse.d.ts +1 -0
  172. package/dist/utils/maybe-json-parse.js +12 -0
  173. package/dist/utils/maybe-json-stringify.d.ts +1 -0
  174. package/dist/utils/maybe-json-stringify.js +11 -0
  175. package/dist/utils/move-array-item.d.ts +4 -0
  176. package/dist/utils/move-array-item.js +20 -0
  177. package/dist/utils/omit-pick.d.ts +2 -2
  178. package/dist/utils/omit-pick.js +10 -8
  179. package/dist/utils/paint.d.ts +18 -0
  180. package/dist/utils/paint.js +32 -0
  181. package/dist/utils/persistent-state.svelte.d.ts +23 -0
  182. package/dist/utils/persistent-state.svelte.js +48 -0
  183. package/dist/utils/prefers-reduced-motion.svelte.d.ts +2 -0
  184. package/dist/utils/prefers-reduced-motion.svelte.js +4 -0
  185. package/dist/utils/qsa.d.ts +1 -0
  186. package/dist/utils/qsa.js +3 -0
  187. package/dist/utils/sleep.d.ts +28 -0
  188. package/dist/utils/sleep.js +33 -0
  189. package/dist/utils/storage-abstraction.d.ts +35 -0
  190. package/dist/utils/storage-abstraction.js +136 -0
  191. package/dist/utils/str-hash.d.ts +7 -0
  192. package/dist/utils/str-hash.js +35 -0
  193. package/dist/utils/throttle.d.ts +1 -0
  194. package/dist/utils/throttle.js +47 -0
  195. package/dist/utils/to-integer.d.ts +1 -0
  196. package/dist/utils/to-integer.js +11 -0
  197. package/dist/utils/tr.d.ts +5 -0
  198. package/dist/utils/tr.js +13 -0
  199. package/dist/utils/tw-merge.d.ts +10 -0
  200. package/dist/utils/tw-merge.js +16 -0
  201. package/dist/utils/ucfirst.d.ts +1 -0
  202. package/dist/utils/ucfirst.js +6 -0
  203. package/package.json +66 -73
  204. package/dist/actions/autogrow.d.ts +0 -8
  205. package/dist/actions/autogrow.js +0 -22
  206. package/dist/actions/drag-drop.d.ts +0 -28
  207. package/dist/actions/drag-drop.js +0 -152
  208. package/dist/actions/on-outside.d.ts +0 -9
  209. package/dist/actions/on-outside.js +0 -27
  210. package/dist/actions/pre-submit-validity-check.d.ts +0 -3
  211. package/dist/actions/pre-submit-validity-check.js +0 -21
  212. package/dist/actions/tooltip/_make-visible.d.ts +0 -3
  213. package/dist/actions/tooltip/_make-visible.js +0 -25
  214. package/dist/actions/tooltip/_maybe-pick-safe-placement.d.ts +0 -3
  215. package/dist/actions/tooltip/_maybe-pick-safe-placement.js +0 -86
  216. package/dist/actions/tooltip/_set-position.d.ts +0 -2
  217. package/dist/actions/tooltip/_set-position.js +0 -125
  218. package/dist/actions/tooltip/tooltip.d.ts +0 -42
  219. package/dist/actions/tooltip/tooltip.js +0 -299
  220. package/dist/actions/trim.d.ts +0 -4
  221. package/dist/actions/trim.js +0 -18
  222. package/dist/actions/validate.js +0 -80
  223. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.d.ts +0 -58
  224. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.js +0 -141
  225. package/dist/components/ColorScheme/LocalColorScheme.svelte.d.ts +0 -25
  226. package/dist/components/ColorScheme/SystemAwareColorScheme.svelte.d.ts +0 -25
  227. package/dist/components/Input/Field.svelte +0 -315
  228. package/dist/components/Input/Field.svelte.d.ts +0 -102
  229. package/dist/components/Input/PinInput.svelte +0 -151
  230. package/dist/components/Input/PinInput.svelte.d.ts +0 -51
  231. package/dist/components/Input/XFieldRadioInternal.svelte +0 -143
  232. package/dist/components/Input/XFieldRadioInternal.svelte.d.ts +0 -45
  233. package/dist/components/Notifications/notifications.d.ts +0 -78
  234. package/dist/components/Notifications/notifications.js +0 -215
  235. package/dist/components/Popover/Popover.svelte +0 -24
  236. package/dist/components/Popover/Popover.svelte.d.ts +0 -22
  237. package/dist/components/Spinner/Spinner.v5.svelte +0 -114
  238. package/dist/components/Spinner/Spinner.v5.svelte.d.ts +0 -16
  239. package/dist/utils/calculate-alignment.d.ts +0 -68
  240. package/dist/utils/calculate-alignment.js +0 -183
  241. package/dist/utils/device-pointer.d.ts +0 -5
  242. package/dist/utils/device-pointer.js +0 -10
  243. package/dist/utils/prefers-reduced-motion.d.ts +0 -6
  244. package/dist/utils/prefers-reduced-motion.js +0 -26
  245. package/dist/utils/tw-merge2.d.ts +0 -3
  246. package/dist/utils/tw-merge2.js +0 -9
  247. package/dist/utils/tw-types.d.ts +0 -1
  248. package/dist/utils/window-size.d.ts +0 -22
  249. package/dist/utils/window-size.js +0 -35
  250. /package/dist/{utils/tw-types.js → components/Input/types.js} +0 -0
@@ -1,143 +0,0 @@
1
- <script context="module">import { createEventDispatcher } from "svelte";
2
- import { slide } from "svelte/transition";
3
- import { validate as validateAction } from "../../actions/validate.js";
4
- import { getId } from "../../utils/get-id.js";
5
- import { twMerge2 } from "../../utils/tw-merge2.js";
6
- import Thc from "../Thc/Thc.svelte";
7
- import {
8
- FieldRadiosConfig
9
- } from "./FieldRadios.svelte";
10
- const _PRESET = {
11
- box: "flex items-start",
12
- label: "block w-full",
13
- input: `
14
- size-4 rounded-full
15
- bg-neutral-100
16
- border-neutral-300
17
- shadow-sm
18
- text-stuic-primary dark:text-stuic-primary-dark
19
- cursor-pointer
20
- focus:border-stuic-primary
21
- focus:ring-4
22
- focus:ring-offset-0
23
- focus:ring-stuic-primary
24
- focus:ring-opacity-20
25
- disabled:cursor-not-allowed
26
- `,
27
- validationMessage: "text-xs text-stuic-primary dark:text-stuic-primary-dark tracking-tight",
28
- description: "text-sm opacity-50"
29
- };
30
- const _PRESET_BY_SIZE = {
31
- sm: { label: "text-sm" },
32
- md: { label: "text-base" },
33
- lg: { label: "text-base font-bold" }
34
- };
35
- </script>
36
-
37
- <script>const dispatch = createEventDispatcher();
38
- let _class = {};
39
- export { _class as class };
40
- export let classBySize = {};
41
- export let size = "md";
42
- export let value;
43
- export let group;
44
- export let label;
45
- export let name;
46
- export let description = "";
47
- export let tabindex = 0;
48
- export let disabled = false;
49
- export let required = false;
50
- export let validate = void 0;
51
- let validation;
52
- const setValidationResult = (res) => {
53
- validation = res;
54
- dispatch("validation", validation);
55
- };
56
- let id = getId();
57
- let idDesc = getId();
58
- const _collectClasses = (k, extra = "") => [
59
- _PRESET?.[k] || "",
60
- _PRESET_BY_SIZE?.[size]?.[k] || "",
61
- FieldRadiosConfig?.class?.[k] || "",
62
- FieldRadiosConfig?.classBySize?.[size]?.[k] || "",
63
- extra || "",
64
- _class?.[k] || "",
65
- classBySize?.[size]?.[k] || ""
66
- ].join(" ");
67
- $:
68
- _boxClass = twMerge2(_collectClasses("box"));
69
- $:
70
- _inputClass = twMerge2(
71
- _collectClasses(
72
- "input",
73
- validation && !validation.valid ? _collectClasses("invalid") : ""
74
- )
75
- );
76
- $:
77
- _labelClass = twMerge2(_collectClasses("label"));
78
- $:
79
- _validationMessageClass = twMerge2(_collectClasses("validationMessage"));
80
- $:
81
- _descriptionClass = twMerge2(_collectClasses("description"));
82
- </script>
83
-
84
- <div class={_boxClass}>
85
- <div class="flex h-6 items-center ml-1">
86
- <input
87
- {id}
88
- type="radio"
89
- {value}
90
- bind:group
91
- aria-describedby={description ? idDesc : undefined}
92
- {name}
93
- class={_inputClass}
94
- {disabled}
95
- {required}
96
- {tabindex}
97
- use:validateAction={validate
98
- ? { ...(validate === true ? {} : validate), setValidationResult }
99
- : undefined}
100
- on:blur
101
- on:change
102
- on:click
103
- on:focus
104
- on:input
105
- on:keydown
106
- on:keyup
107
- on:touchstart|passive
108
- on:touchend|passive
109
- on:touchmove|passive
110
- on:touchcancel
111
- on:mouseenter
112
- on:mouseleave
113
- />
114
- </div>
115
- <div class="ml-3 w-full">
116
- {#if label}
117
- <label
118
- for={id}
119
- class={_labelClass}
120
- class:cursor-pointer={!disabled}
121
- class:cursor-not-allowed={disabled}
122
- >
123
- <Thc thc={label} forceAsHtml />
124
- </label>
125
- {/if}
126
- {#if validation && !validation?.valid}
127
- <div transition:slide={{ duration: 150 }} class={_validationMessageClass}>
128
- {@html validation.message}
129
- </div>
130
- {/if}
131
- {#if description}
132
- <!-- svelte-ignore a11y-click-events-have-key-events a11y-no-static-element-interactions -->
133
- <div
134
- class={_descriptionClass}
135
- class:cursor-pointer={!disabled}
136
- class:cursor-not-allowed={disabled}
137
- on:click={() => !disabled && (group = value)}
138
- >
139
- <Thc thc={description} forceAsHtml />
140
- </div>
141
- {/if}
142
- </div>
143
- </div>
@@ -1,45 +0,0 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { ValidateOptions } from '../../actions/validate.js';
3
- import { type FieldRadiosConfigClasses, type FieldRadiosConfigClassesBySize } from './FieldRadios.svelte';
4
- declare const __propDef: {
5
- props: {
6
- class?: FieldRadiosConfigClasses;
7
- classBySize?: FieldRadiosConfigClassesBySize;
8
- size?: "sm" | "md" | "lg";
9
- value: any;
10
- group: any;
11
- label: string;
12
- name: string;
13
- description?: string;
14
- tabindex?: number;
15
- disabled?: boolean;
16
- required?: boolean;
17
- validate?: ValidateOptions | true | undefined;
18
- };
19
- events: {
20
- blur: FocusEvent;
21
- change: Event;
22
- click: MouseEvent;
23
- focus: FocusEvent;
24
- input: Event;
25
- keydown: KeyboardEvent;
26
- keyup: KeyboardEvent;
27
- touchstart: TouchEvent;
28
- touchend: TouchEvent;
29
- touchmove: TouchEvent;
30
- touchcancel: TouchEvent;
31
- mouseenter: MouseEvent;
32
- mouseleave: MouseEvent;
33
- } & {
34
- [evt: string]: CustomEvent<any>;
35
- };
36
- slots: {};
37
- exports?: {} | undefined;
38
- bindings?: string | undefined;
39
- };
40
- export type XFieldRadioInternalProps = typeof __propDef.props;
41
- export type XFieldRadioInternalEvents = typeof __propDef.events;
42
- export type XFieldRadioInternalSlots = typeof __propDef.slots;
43
- export default class XFieldRadioInternal extends SvelteComponent<XFieldRadioInternalProps, XFieldRadioInternalEvents, XFieldRadioInternalSlots> {
44
- }
45
- export {};
@@ -1,78 +0,0 @@
1
- import type { THC } from '../Thc/Thc.svelte';
2
- export type NotificationsSortOrder = 'asc' | 'desc';
3
- export type NotificationOnEventHandler = (eventName: string, self: Notification, all: Notification[], data: any) => void;
4
- export type NotificationType = 'info' | 'success' | 'warn' | 'error' | string;
5
- interface ComponentWrap {
6
- component: Function;
7
- props?: any;
8
- }
9
- export interface NotificationKnownClasses {
10
- box: string;
11
- count: string;
12
- icon: string;
13
- content: string;
14
- button: string;
15
- x: string;
16
- }
17
- export interface NotificationInput extends Record<string, any> {
18
- id: any;
19
- type: NotificationType;
20
- content: THC;
21
- on: NotificationOnEventHandler;
22
- onClick: (self: Notification, all: Notification[], data: any) => void;
23
- ttl: number;
24
- count: number;
25
- component?: Function | ComponentWrap;
26
- iconFn: (() => string) | boolean;
27
- class?: Partial<NotificationKnownClasses>;
28
- forceAsHtml: boolean | undefined;
29
- }
30
- export interface Notification extends NotificationInput {
31
- created: Date;
32
- }
33
- export type NotificationCreateParam = string | Partial<NotificationInput>;
34
- export interface NotiticationsCreateStoreOptions {
35
- maxCapacity: number;
36
- defaultType: string;
37
- defaultTtl: number;
38
- sortOrder?: NotificationsSortOrder;
39
- logger: (...v: any) => void;
40
- }
41
- export declare const NOTIFICATION_EVENT: {
42
- CLICK: string;
43
- CREATE: string;
44
- REMOVE: string;
45
- AUTO_DISPOSE: string;
46
- MOUSEOVER: string;
47
- MOUSEOUT: string;
48
- };
49
- export declare const createNotificationsStore: (initial?: NotificationCreateParam[], opts?: Partial<NotiticationsCreateStoreOptions>) => {
50
- subscribe: (cb: CallableFunction) => () => void;
51
- get: () => Notification[];
52
- add: (notif: NotificationCreateParam[] | NotificationCreateParam) => void;
53
- event: (id: string, eventName: string, data?: any) => boolean;
54
- find: (id: string) => Notification | null;
55
- remove: (id: string) => boolean;
56
- options: {
57
- maxCapacity?: number | undefined;
58
- defaultType?: string | undefined;
59
- defaultTtl?: number | undefined;
60
- sortOrder?: NotificationsSortOrder | undefined;
61
- logger?: ((...v: any) => void) | undefined;
62
- };
63
- EVENT: {
64
- CLICK: string;
65
- CREATE: string;
66
- REMOVE: string;
67
- AUTO_DISPOSE: string;
68
- MOUSEOVER: string;
69
- MOUSEOUT: string;
70
- };
71
- setMaxCapacity: (v: number) => void;
72
- setSortOrder: (v: string) => void;
73
- info: (content: THC, n?: Partial<NotificationInput>) => void;
74
- success: (content: THC, n?: Partial<NotificationInput>) => void;
75
- warn: (content: THC, n?: Partial<NotificationInput>) => void;
76
- error: (content: THC, n?: Partial<NotificationInput>) => void;
77
- };
78
- export {};
@@ -1,215 +0,0 @@
1
- import { createClog } from '@marianmeres/clog';
2
- import { createStore } from '@marianmeres/store';
3
- import { createTicker } from '@marianmeres/ticker';
4
- const isFn = (v) => typeof v === 'function';
5
- const DEFAULT_OPTIONS = {
6
- maxCapacity: 5,
7
- defaultTtl: 10,
8
- defaultType: 'info',
9
- sortOrder: 'asc',
10
- logger: createClog('notifications'),
11
- };
12
- export const NOTIFICATION_EVENT = {
13
- CLICK: 'click',
14
- CREATE: 'create',
15
- // `remove` programatically, or e.g. by clicking on X
16
- REMOVE: 'remove',
17
- // triggered when auto disposed by ttl expiration
18
- AUTO_DISPOSE: 'auto_dispose',
19
- // usefull for detecting interacion (so internally may notify as "seen")
20
- MOUSEOVER: 'mouseover',
21
- MOUSEOUT: 'mouseout',
22
- };
23
- // https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
24
- const _strHash = (str) => `${str || ''}`.split('').reduce((a, b) => {
25
- a = (a << 5) - a + b.charCodeAt(0);
26
- return a & a;
27
- }, 0);
28
- const _id = (type, content) => {
29
- const str = content?.component
30
- ? 'component'
31
- : content?.html || content?.text || content;
32
- return ['id', type, _strHash(str)].join('-');
33
- };
34
- export const createNotificationsStore = (initial = [], opts = {}) => {
35
- if (!Array.isArray(initial))
36
- initial = [initial];
37
- // merge provided with defaults
38
- opts = { ...DEFAULT_OPTIONS, ...(opts || {}) };
39
- const _log = (...args) => isFn(opts.logger) && opts.logger.apply(null, [...args]);
40
- const _setOption = (k, v) => {
41
- // _log(`INFO: setting option '${k} = ${v}'`);
42
- if (/^maxCapacity|defaultTtl$/.test(k)) {
43
- v = parseInt(v, 10);
44
- if (isNaN(v) || v < 0) {
45
- _log(`WARN: invalid '${k}' option, falling back to default`);
46
- opts[k] = DEFAULT_OPTIONS[k];
47
- }
48
- else {
49
- opts[k] = v;
50
- }
51
- }
52
- else {
53
- opts[k] = v;
54
- }
55
- };
56
- // sanitize options
57
- ['maxCapacity', 'defaultTtl'].forEach((k) => _setOption(k, opts[k]));
58
- const _factory = (notification) => {
59
- let o = typeof notification === 'string' ? { id: 0, content: notification } : notification;
60
- // ignore invalid (empty) notifs
61
- if (!o.content) {
62
- _log(`WARN: ignoring empty notification`);
63
- return null;
64
- }
65
- o.type ||= opts.defaultType; //
66
- o.id ||= _id(o.type, [o.content].join());
67
- o.created = new Date(o.created || Date.now());
68
- o.count ??= 1;
69
- //
70
- if (o.ttl === undefined)
71
- o.ttl = opts.defaultTtl;
72
- return o;
73
- };
74
- const _findIndexById = (notifs, id) => notifs.findIndex((n) => n.id === id);
75
- const _removeByIdx = (notifs, idx) => {
76
- if (idx > -1) {
77
- notifs.splice(idx, 1);
78
- notifs = [...notifs];
79
- }
80
- return notifs;
81
- };
82
- const _add = (notifs, notification, onAddHook = null) => {
83
- const notif = _factory(notification);
84
- // return early on invalid
85
- if (!notif)
86
- return notifs;
87
- const _isDesc = opts.sortOrder === 'desc';
88
- const idx = _findIndexById(notifs, notif.id);
89
- if (idx > -1) {
90
- notifs[idx].count++;
91
- notifs[idx].created = new Date(Math.max(notifs[idx].created.valueOf(), notif.created.valueOf()));
92
- }
93
- else {
94
- notifs.push(notif);
95
- notifs.sort((a, b) => {
96
- let _a = a.created.valueOf();
97
- let _b = b.created.valueOf();
98
- return _isDesc ? _b - _a : _a - _b;
99
- });
100
- }
101
- if (isFn(onAddHook))
102
- onAddHook?.(notif);
103
- // keep only `maxCapacity` in the queue
104
- if (opts.maxCapacity && notifs.length > opts.maxCapacity) {
105
- notifs = _isDesc
106
- ? notifs.slice(0, opts.maxCapacity)
107
- : notifs.slice(-1 * opts.maxCapacity);
108
- }
109
- return [...notifs];
110
- };
111
- // main internal store
112
- let notifs = [];
113
- initial.forEach((n) => (notifs = _add(notifs, n)));
114
- const _store = createStore(notifs);
115
- // auto dispose feature
116
- const ticker = createTicker(1_000);
117
- const _tickerInit = () => {
118
- const _tickerUnsub = ticker.start().subscribe((ts) => {
119
- if (ts) {
120
- const { disposed, kept } = _store.get().reduce((memo, n) => {
121
- if (n.ttl) {
122
- const expiry = n.created.valueOf() + n.ttl * 1000;
123
- expiry >= Date.now() ? memo.kept.push(n) : memo.disposed.push(n);
124
- }
125
- else {
126
- memo.kept.push(n);
127
- }
128
- return memo;
129
- }, { disposed: [], kept: [] });
130
- if (disposed.length) {
131
- disposed.forEach((n) => event(n.id, NOTIFICATION_EVENT.AUTO_DISPOSE));
132
- _store.set(kept);
133
- }
134
- }
135
- });
136
- return () => {
137
- ticker.stop();
138
- _tickerUnsub();
139
- };
140
- };
141
- //
142
- const findById = (id) => {
143
- const notifs = _store.get();
144
- const idx = _findIndexById(notifs, id);
145
- return idx > -1 ? notifs[idx] : null;
146
- };
147
- const event = (id, eventName, data = null) => {
148
- const n = findById(id);
149
- if (n) {
150
- if (isFn(n.on)) {
151
- n.on(eventName, n, _store.get(), data);
152
- }
153
- if (eventName === NOTIFICATION_EVENT.CLICK && isFn(n.onClick)) {
154
- n.onClick(n, _store.get(), data);
155
- }
156
- return true;
157
- }
158
- return false;
159
- };
160
- // we need to keep track of subscriptions count, so we can do the cleanup
161
- let _subsCount = 0;
162
- let _tickerDestroy;
163
- const subscribe = (cb) => {
164
- if (!_subsCount++)
165
- _tickerDestroy = _tickerInit();
166
- const unsub = _store.subscribe(cb);
167
- return () => {
168
- if (!--_subsCount)
169
- _tickerDestroy();
170
- unsub();
171
- };
172
- };
173
- const add = (notif) => {
174
- if (!Array.isArray(notif))
175
- notif = [notif];
176
- let notifs = _store.get();
177
- notif.forEach((n) => (notifs = _add(notifs, n, (_n) => event(_n.id, NOTIFICATION_EVENT.CREATE))));
178
- _store.set(notifs);
179
- };
180
- return {
181
- subscribe,
182
- //
183
- get: () => _store.get(),
184
- //
185
- add,
186
- //
187
- event,
188
- //
189
- find: findById,
190
- //
191
- remove: (id) => {
192
- let notifs = _store.get();
193
- const idx = _findIndexById(notifs, id);
194
- if (idx > -1) {
195
- const notif = notifs[idx];
196
- event(id, NOTIFICATION_EVENT.REMOVE);
197
- _store.set(_removeByIdx(notifs, idx));
198
- return true;
199
- }
200
- return false;
201
- },
202
- //
203
- options: { ...opts },
204
- //
205
- EVENT: NOTIFICATION_EVENT,
206
- // some options setters (for playground mostly)
207
- setMaxCapacity: (v) => _setOption('maxCapacity', v),
208
- setSortOrder: (v) => _setOption('sortOrder', v),
209
- // sugar
210
- info: (content, n) => add({ ...(n || {}), type: 'info', content }),
211
- success: (content, n) => add({ ...(n || {}), type: 'success', content }),
212
- warn: (content, n) => add({ ...(n || {}), type: 'warn', content }),
213
- error: (content, n) => add({ ...(n || {}), type: 'error', content }),
214
- };
215
- };
@@ -1,24 +0,0 @@
1
- <script>import { tooltip } from "../../actions/tooltip/tooltip.js";
2
- export let options = {};
3
- const POPOVER_DEFAULTS = {
4
- hideOnInsufficientSpace: true,
5
- triggers: ["click"]
6
- };
7
- let popover;
8
- </script>
9
-
10
- {#if popover}
11
- <span
12
- use:tooltip={{
13
- ...POPOVER_DEFAULTS,
14
- ...(options || {}),
15
- popover,
16
- }}
17
- >
18
- <slot />
19
- </span>
20
- {/if}
21
-
22
- <div bind:this={popover} class="hidden">
23
- <slot name="popover" />
24
- </div>
@@ -1,22 +0,0 @@
1
- import { SvelteComponent } from "svelte";
2
- import { type TooltipOptions } from '../../actions/tooltip/tooltip.js';
3
- declare const __propDef: {
4
- props: {
5
- options?: Partial<TooltipOptions>;
6
- };
7
- events: {
8
- [evt: string]: CustomEvent<any>;
9
- };
10
- slots: {
11
- default: {};
12
- popover: {};
13
- };
14
- exports?: {} | undefined;
15
- bindings?: string | undefined;
16
- };
17
- export type PopoverProps = typeof __propDef.props;
18
- export type PopoverEvents = typeof __propDef.events;
19
- export type PopoverSlots = typeof __propDef.slots;
20
- export default class Popover extends SvelteComponent<PopoverProps, PopoverEvents, PopoverSlots> {
21
- }
22
- export {};
@@ -1,114 +0,0 @@
1
- <script>import { twMerge2 } from "@marianmeres/stuic";
2
- let {
3
- class: _class,
4
- duration = 1e3,
5
- // one "loop" duration (in ms)
6
- count = 8,
7
- // "hands" count
8
- thickness = "normal",
9
- height = "normal",
10
- direction = "cw"
11
- } = $props();
12
- let _count = $derived(Math.max(3, Math.min(12, count)));
13
- let _segments = $derived.by(() => {
14
- let out = [];
15
- for (let i = 0; i < _count; i++) {
16
- out.push({
17
- rotate: 360 / _count * i,
18
- delay: (direction === "ccw" ? 1 : -1) * (duration - duration / _count * (i + 1)),
19
- duration
20
- });
21
- }
22
- return out;
23
- });
24
- let _thickness = $derived(
25
- "thickness-" + (["normal", "thin", "thick"].includes(thickness) ? thickness : "normal")
26
- );
27
- let _height = $derived(
28
- "height-" + (["normal", "tall", "short"].includes(height) ? height : "normal")
29
- );
30
- </script>
31
-
32
- <div class="spinner {_thickness} {_height} {twMerge2('inline-block w-5', _class)}">
33
- {#each _segments as s}
34
- <div
35
- style={[
36
- `transform: rotate(${s.rotate}deg);`,
37
- `animation-delay: ${s.delay}ms;`,
38
- `animation-duration: ${s.duration}ms;`
39
- ].join('')}
40
- ></div>
41
- {/each}
42
- </div>
43
-
44
- <style>
45
- .spinner,
46
- .spinner div,
47
- .spinner div:after {
48
- box-sizing: border-box;
49
- }
50
-
51
- .spinner {
52
- /* display: inline-block; */
53
- position: relative;
54
- aspect-ratio: 1/1;
55
- pointer-events: none;
56
- }
57
-
58
- .spinner div {
59
- width: 100%;
60
- height: 100%;
61
- position: absolute;
62
- inset: 0;
63
- /* animation: spinner 1.2s linear infinite; */
64
- animation-name: spinner;
65
- animation-timing-function: linear;
66
- animation-iteration-count: infinite;
67
- }
68
-
69
- .spinner div:after {
70
- content: ' ';
71
- display: block;
72
- position: absolute;
73
-
74
- top: 0;
75
- /* left: 46%;
76
- width: 8%;
77
- height: 27%; */
78
- border-radius: 35%;
79
- background: currentColor;
80
- }
81
- /* thickness */
82
- .spinner.thickness-thin div:after {
83
- left: 47.5%;
84
- width: 5%;
85
- }
86
- .spinner.thickness-normal div:after {
87
- left: 46%;
88
- width: 8%;
89
- }
90
- .spinner.thickness-thick div:after {
91
- left: 44.5%;
92
- width: 11%;
93
- }
94
-
95
- /* height */
96
- .spinner.height-short div:after {
97
- height: 21%;
98
- }
99
- .spinner.height-normal div:after {
100
- height: 27%;
101
- }
102
- .spinner.height-tall div:after {
103
- height: 33%;
104
- }
105
-
106
- @keyframes spinner {
107
- 0% {
108
- opacity: 1;
109
- }
110
- 100% {
111
- opacity: 0;
112
- }
113
- }
114
- </style>
@@ -1,16 +0,0 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: Record<string, never>;
4
- events: {
5
- [evt: string]: CustomEvent<any>;
6
- };
7
- slots: {};
8
- exports?: {} | undefined;
9
- bindings?: string | undefined;
10
- };
11
- export type SpinnerProps = typeof __propDef.props;
12
- export type SpinnerEvents = typeof __propDef.events;
13
- export type SpinnerSlots = typeof __propDef.slots;
14
- export default class Spinner extends SvelteComponent<SpinnerProps, SpinnerEvents, SpinnerSlots> {
15
- }
16
- export {};