@marianmeres/stuic 1.126.0 → 2.0.0-next.2

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 (252) 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/autoscroll.d.ts +0 -21
  207. package/dist/actions/autoscroll.js +0 -60
  208. package/dist/actions/drag-drop.d.ts +0 -28
  209. package/dist/actions/drag-drop.js +0 -152
  210. package/dist/actions/on-outside.d.ts +0 -9
  211. package/dist/actions/on-outside.js +0 -27
  212. package/dist/actions/pre-submit-validity-check.d.ts +0 -3
  213. package/dist/actions/pre-submit-validity-check.js +0 -21
  214. package/dist/actions/tooltip/_make-visible.d.ts +0 -3
  215. package/dist/actions/tooltip/_make-visible.js +0 -25
  216. package/dist/actions/tooltip/_maybe-pick-safe-placement.d.ts +0 -3
  217. package/dist/actions/tooltip/_maybe-pick-safe-placement.js +0 -86
  218. package/dist/actions/tooltip/_set-position.d.ts +0 -2
  219. package/dist/actions/tooltip/_set-position.js +0 -125
  220. package/dist/actions/tooltip/tooltip.d.ts +0 -42
  221. package/dist/actions/tooltip/tooltip.js +0 -299
  222. package/dist/actions/trim.d.ts +0 -4
  223. package/dist/actions/trim.js +0 -18
  224. package/dist/actions/validate.js +0 -80
  225. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.d.ts +0 -58
  226. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.js +0 -141
  227. package/dist/components/ColorScheme/LocalColorScheme.svelte.d.ts +0 -25
  228. package/dist/components/ColorScheme/SystemAwareColorScheme.svelte.d.ts +0 -25
  229. package/dist/components/Input/Field.svelte +0 -315
  230. package/dist/components/Input/Field.svelte.d.ts +0 -102
  231. package/dist/components/Input/PinInput.svelte +0 -151
  232. package/dist/components/Input/PinInput.svelte.d.ts +0 -51
  233. package/dist/components/Input/XFieldRadioInternal.svelte +0 -143
  234. package/dist/components/Input/XFieldRadioInternal.svelte.d.ts +0 -45
  235. package/dist/components/Notifications/notifications.d.ts +0 -78
  236. package/dist/components/Notifications/notifications.js +0 -215
  237. package/dist/components/Popover/Popover.svelte +0 -24
  238. package/dist/components/Popover/Popover.svelte.d.ts +0 -22
  239. package/dist/components/Spinner/Spinner.v5.svelte +0 -114
  240. package/dist/components/Spinner/Spinner.v5.svelte.d.ts +0 -16
  241. package/dist/utils/calculate-alignment.d.ts +0 -68
  242. package/dist/utils/calculate-alignment.js +0 -183
  243. package/dist/utils/device-pointer.d.ts +0 -5
  244. package/dist/utils/device-pointer.js +0 -10
  245. package/dist/utils/prefers-reduced-motion.d.ts +0 -6
  246. package/dist/utils/prefers-reduced-motion.js +0 -26
  247. package/dist/utils/tw-merge2.d.ts +0 -3
  248. package/dist/utils/tw-merge2.js +0 -9
  249. package/dist/utils/tw-types.d.ts +0 -1
  250. package/dist/utils/window-size.d.ts +0 -22
  251. package/dist/utils/window-size.js +0 -35
  252. /package/dist/{utils/tw-types.js → components/Input/types.js} +0 -0
@@ -1,299 +0,0 @@
1
- import { createStore } from '@marianmeres/store';
2
- import { derived, get as storeGet, writable, } from 'svelte/store';
3
- import { twMerge2 } from '../../utils/tw-merge2.js';
4
- import { windowSize } from '../../utils/window-size.js';
5
- import { _makeInVisible, _makeVisible } from './_make-visible.js';
6
- import { _setPosition } from './_set-position.js';
7
- export class TooltipConfig {
8
- static presetBase = `
9
- text-sm
10
- bg-gray-950 dark:bg-gray-950
11
- text-gray-50 dark:text-gray-50
12
- px-3 py-2
13
- rounded-md
14
- shadow-lg
15
- z-50
16
- max-w-96 w-max
17
- `;
18
- static class = '';
19
- static arrowPresetBase = `border-gray-950 dark:border-gray-950 z-50`;
20
- static arrowClass = ``;
21
- static defaultOptions = {};
22
- }
23
- export class PopoverConfig {
24
- static presetBase = `
25
- text-sm
26
- bg-gray-950 dark:bg-gray-950
27
- text-gray-50 dark:text-gray-50
28
- px-3 py-2
29
- rounded-md
30
- shadow-lg
31
- z-50
32
- `;
33
- // max-w-96 w-max
34
- static class = '';
35
- static arrowPresetBase = `border-gray-950 dark:border-gray-950 z-50`;
36
- static arrowClass = ``;
37
- static defaultOptions = {};
38
- }
39
- const DEFAULTS = {
40
- content: '',
41
- popover: null,
42
- alignment: 'top',
43
- allowHtml: true,
44
- delay: 300,
45
- triggers: ['hover'], // 'focus', 'click'
46
- class: '',
47
- arrowClass: '',
48
- arrowSize: 8,
49
- offset: 10,
50
- hideOnInsufficientSpace: false,
51
- };
52
- const TRIGGERS = {
53
- hover: { show: ['mouseover'], hide: ['mouseout'] },
54
- focus: { show: ['focusin'], hide: ['blur'] },
55
- click: { show: ['click'], hide: [] }, // no hide for click, will toggle instead
56
- };
57
- // default TW value
58
- export const _TRANSITION_OPACITY_DUR = 150;
59
- const _ensureDiv = (div, opts, log) => {
60
- log('_ensureDiv', div);
61
- if (!div) {
62
- log('creating tooltip div...');
63
- div = document.createElement('div');
64
- (opts?.getAppendChildTarget?.() || document.body).appendChild(div);
65
- }
66
- else {
67
- log('div exists... going to apply classes');
68
- }
69
- let classes = '';
70
- if (opts.popover) {
71
- classes = [PopoverConfig.presetBase, PopoverConfig.class, opts.class].join(' ');
72
- }
73
- else {
74
- classes = [TooltipConfig.presetBase, TooltipConfig.class, opts.class].join(' ');
75
- }
76
- // make sure these are never overwritten (must come last)
77
- classes = twMerge2(classes, 'fixed block transition-opacity')
78
- .split(/\s/)
79
- .filter(Boolean);
80
- div.classList.add(...classes);
81
- div.style.opacity = '0';
82
- // log(`Div classes applied (+ opacity 0)`, classes);
83
- return div;
84
- };
85
- const _ensureArrow = (arrow, opts, log) => {
86
- log('_ensureArrow');
87
- if (!arrow) {
88
- log('creating tooltip arrow...');
89
- arrow = document.createElement('div');
90
- (opts?.getAppendChildTarget?.() || document.body).appendChild(arrow);
91
- }
92
- else {
93
- log('arrow exists... going to apply classes');
94
- }
95
- let classes = '';
96
- // prettier-ignore
97
- if (opts.popover) {
98
- classes = [PopoverConfig.arrowPresetBase, PopoverConfig.arrowClass, opts.arrowClass].join(' ');
99
- }
100
- else {
101
- classes = [TooltipConfig.arrowPresetBase, TooltipConfig.arrowClass, opts.arrowClass].join(' ');
102
- }
103
- // make sure these are never overwritten (must come last)
104
- classes = twMerge2(classes, 'fixed block size-0 transition-opacity')
105
- .split(/\s/)
106
- .filter(Boolean);
107
- arrow.classList.add(...classes);
108
- arrow.style.opacity = '0';
109
- // log(`Arrow classes applied (+ opacity 0)`, classes);
110
- return arrow;
111
- };
112
- // the action api
113
- export function tooltip(node, initialOptions = {}) {
114
- if (typeof initialOptions === 'string')
115
- initialOptions = { content: initialOptions };
116
- //
117
- initialOptions ??= {};
118
- let defaults = DEFAULTS;
119
- if (initialOptions.popover) {
120
- defaults = { ...defaults, ...PopoverConfig.defaultOptions };
121
- }
122
- else {
123
- defaults = { ...defaults, ...TooltipConfig.defaultOptions };
124
- }
125
- let opts = { ...defaults, ...initialOptions };
126
- const content = createStore(opts.content || '');
127
- // maybe use aria-label (if present and content is not set)
128
- const ariaLabel = node.getAttribute('aria-label');
129
- if (ariaLabel && !content.get())
130
- content.set(ariaLabel);
131
- const _log = (...args) => typeof opts.logger === 'function' &&
132
- opts.logger.apply(null, [`[tooltip/${node.id || '?'}]`, ...args]);
133
- //
134
- let _delayTimer;
135
- const _resetDelayTimer = () => {
136
- if (_delayTimer)
137
- clearTimeout(_delayTimer);
138
- _delayTimer = null;
139
- };
140
- const _planDelayedExec = (_fn, _delay) => {
141
- _resetDelayTimer();
142
- _delayTimer = setTimeout(() => {
143
- _fn();
144
- _resetDelayTimer();
145
- }, _delay);
146
- };
147
- // use popover if provided, otherwise new div will be created
148
- let div = opts.popover;
149
- let arrow;
150
- let _isOn = writable(false); // internal state store
151
- //
152
- const _show = async () => {
153
- _log('_show');
154
- // return early on no content
155
- if (!opts.popover && !content.get()) {
156
- _log('Nothing to show (neither popover, nor content provided)');
157
- return;
158
- }
159
- // create, apply core styles and append to DOM
160
- div = _ensureDiv(div, opts, _log);
161
- arrow = _ensureArrow(arrow, opts, _log);
162
- // set content
163
- if (!opts.popover) {
164
- if (opts.allowHtml)
165
- div.innerHTML = content.get();
166
- else
167
- div.textContent = content.get();
168
- }
169
- // measure stuff and set position (provided opts.alignment is considered just as
170
- // "preferred", which means it may be overwritten if there is no available space)
171
- if (await _setPosition(opts.boundaryRoot, node, div, arrow, opts, _log)) {
172
- // finally, fade in
173
- _makeVisible(div, arrow, _log);
174
- setTimeout(() => _isOn.set(true), _TRANSITION_OPACITY_DUR);
175
- }
176
- else {
177
- _makeInVisible(div, arrow, _log);
178
- }
179
- };
180
- let show = () => _planDelayedExec(_show, opts.delay);
181
- //
182
- const _hide = async () => {
183
- _log('_hide');
184
- _makeInVisible(div, arrow, _log);
185
- setTimeout(() => {
186
- destroy();
187
- _isOn.set(false);
188
- }, _TRANSITION_OPACITY_DUR);
189
- };
190
- const hide = () => _planDelayedExec(_hide, opts.delay);
191
- // no delay for toggle
192
- const toggle = async () => {
193
- _log('toggle');
194
- storeGet(_isOn) ? await _hide() : await _show();
195
- };
196
- //
197
- const destroy = () => {
198
- // for obscure cases, where parent node might have be removed from DOM
199
- // before the planned show/hide happens
200
- _resetDelayTimer();
201
- if (!div && !arrow && !opts.popover && !storeGet(_isOn))
202
- return;
203
- _log('destroy');
204
- if (!opts.popover) {
205
- div?.remove();
206
- div = null;
207
- }
208
- arrow?.remove();
209
- arrow = null;
210
- _isOn.set(false);
211
- };
212
- //
213
- let unsubs = [_isOn.subscribe((v) => opts?.notifier?.set(v))];
214
- // by default, listen to windowSize change, as well as window and boundaryRoot scroll
215
- const _scrollSignal = writable(0);
216
- const onScroll = () => _scrollSignal.set(Date.now());
217
- if (opts.boundaryRoot) {
218
- opts.boundaryRoot.addEventListener('scroll', onScroll);
219
- unsubs.push(() => opts.boundaryRoot?.removeEventListener('scroll', onScroll));
220
- }
221
- // also listen to window scroll
222
- window.addEventListener('scroll', onScroll);
223
- unsubs.push(() => window.removeEventListener('scroll', onScroll));
224
- const _setPositionTriggers = [_scrollSignal, windowSize];
225
- if (opts.touch?.subscribe)
226
- _setPositionTriggers.push(opts.touch);
227
- const touch = derived(_setPositionTriggers, ([_]) => Date.now());
228
- // final, derived, notifier
229
- let _touchCount = 0;
230
- unsubs.push(touch.subscribe(async () => {
231
- // ignore first
232
- if (_touchCount++) {
233
- _log('touch...');
234
- if (await _setPosition(opts.boundaryRoot, node, div, arrow, opts, _log)) {
235
- _makeVisible(div, arrow, _log);
236
- }
237
- else {
238
- _makeInVisible(div, arrow, _log);
239
- }
240
- }
241
- }));
242
- // important to normalize triggers - if does contain 'click' remove all others
243
- if (opts.triggers.includes('click')) {
244
- _log('Click trigger recognized...');
245
- opts.triggers = ['click'];
246
- _log('Patching show as toggle');
247
- show = toggle; // also patch show/hide logic, since click does not have 'out' event...
248
- }
249
- // if manual trigger exists... (use raw show/hide, not the delayed one)
250
- if (opts.trigger?.subscribe) {
251
- unsubs.push(opts.trigger.subscribe((v) => (v ? _show() : _hide())));
252
- }
253
- // add show
254
- opts.triggers?.forEach((trigger) => {
255
- TRIGGERS[trigger]?.show.forEach((eventName) => {
256
- _log('addEventListener', eventName, 'show');
257
- node.addEventListener(eventName, show);
258
- });
259
- });
260
- // add hide
261
- opts.triggers?.forEach((trigger) => {
262
- TRIGGERS[trigger]?.hide.forEach((eventName) => {
263
- _log('addEventListener', eventName, 'hide');
264
- node.addEventListener(eventName, hide);
265
- });
266
- });
267
- return {
268
- //
269
- update(newOptions) {
270
- if (typeof newOptions === 'string')
271
- newOptions = { content: newOptions };
272
- destroy();
273
- // these are not allowed to update on existing instance
274
- delete newOptions.triggers;
275
- delete newOptions.boundaryRoot;
276
- delete newOptions.touch;
277
- //
278
- opts = { ...opts, ...newOptions };
279
- content.set(opts.content);
280
- },
281
- //
282
- destroy() {
283
- unsubs.forEach((unsub) => typeof unsub === 'function' && unsub());
284
- destroy();
285
- // remove show
286
- opts.triggers?.forEach((trigger) => {
287
- TRIGGERS[trigger]?.show.forEach((eventName) => {
288
- node.removeEventListener(eventName, show);
289
- });
290
- });
291
- // remove hide
292
- opts.triggers?.forEach((trigger) => {
293
- TRIGGERS[trigger]?.hide.forEach((eventName) => {
294
- node.removeEventListener(eventName, hide);
295
- });
296
- });
297
- },
298
- };
299
- }
@@ -1,4 +0,0 @@
1
- export declare const trim: (el: HTMLInputElement | HTMLTextAreaElement, enabled?: boolean) => {
2
- update(enabledFlag?: boolean): void;
3
- destroy(): void;
4
- };
@@ -1,18 +0,0 @@
1
- export const trim = (el, enabled = true) => {
2
- const trim = (e) => {
3
- if (enabled && typeof el.value === 'string') {
4
- el.value = el.value.trim();
5
- }
6
- };
7
- el.addEventListener('change', trim);
8
- return {
9
- update(enabledFlag) {
10
- if (enabledFlag !== undefined) {
11
- enabled = !!enabled;
12
- }
13
- },
14
- destroy() {
15
- el.removeEventListener('change', trim);
16
- },
17
- };
18
- };
@@ -1,80 +0,0 @@
1
- export const validate = (el, options) => {
2
- let _doValidate = !!options;
3
- let context = options?.context;
4
- let customValidator = options?.customValidator;
5
- let onEventName = options?.on || 'change';
6
- const t = (reason, value, fallback) => {
7
- if (!reason || options?.t === false)
8
- return fallback;
9
- // local t (if any)
10
- if (typeof options?.t === 'function')
11
- return options.t(reason, value, fallback);
12
- // global t (if any)
13
- if (typeof validate.t === 'function')
14
- return validate.t(reason, value, fallback);
15
- //
16
- return fallback;
17
- };
18
- const doValidate = (event) => {
19
- if (!_doValidate)
20
- return;
21
- el.checkValidity();
22
- if (typeof customValidator === 'function') {
23
- el.setCustomValidity(customValidator(el.value, context, el) || '');
24
- }
25
- // this triggers the bubble
26
- // el.reportValidity();
27
- const validityState = el.validity;
28
- // prettier-ignore
29
- const reasons = [
30
- 'badInput', 'customError', 'patternMismatch', 'rangeOverflow', 'rangeUnderflow',
31
- 'stepMismatch', 'tooLong', 'tooShort', 'typeMismatch', 'valueMissing'
32
- ].reduce((m, k) => {
33
- if (validityState[k])
34
- m.push(k);
35
- return m;
36
- }, []);
37
- if (typeof options?.setValidationResult === 'function') {
38
- options.setValidationResult({
39
- validity: validityState,
40
- reasons,
41
- valid: validityState?.valid,
42
- // use translate fn for first reason (if fn provided and allowed),
43
- // otherwise fallback to native msg
44
- message: t(reasons?.[0], el.value, el.validationMessage),
45
- });
46
- }
47
- };
48
- el.addEventListener(onEventName, doValidate);
49
- //
50
- let _touchCount = 0;
51
- const onFocus = (e) => _touchCount++;
52
- el.addEventListener('focus', onFocus);
53
- // also validate on first blur
54
- const onBlur = (e) => _touchCount === 1 && doValidate(e);
55
- el.addEventListener('blur', onBlur);
56
- //
57
- // const onChange = (e) => doValidate(e);
58
- // el.addEventListener('change', onChange);
59
- //
60
- // const onInput = (e) => _touchCount > 1 && doValidate(e);
61
- // el.addEventListener('input', onInput);
62
- //
63
- return {
64
- update(newOptions) {
65
- _doValidate = !!newOptions;
66
- // allow only context to update
67
- context = newOptions?.context;
68
- },
69
- destroy() {
70
- el.removeEventListener(onEventName, doValidate);
71
- el.removeEventListener('focus', onFocus);
72
- el.removeEventListener('blur', onBlur);
73
- // el.removeEventListener('change', onChange);
74
- // el.removeEventListener('input', onInput);
75
- },
76
- };
77
- };
78
- // ReasonTranslate
79
- const t = null;
80
- validate.t = t;
@@ -1,58 +0,0 @@
1
- import type { THC } from '../Thc/Thc.svelte';
2
- export declare enum AlertConfirmPromptType {
3
- ALERT = "alert",
4
- CONFIRM = "confirm",
5
- PROMPT = "prompt"
6
- }
7
- export type AlertConfirmPromptVariant = 'info' | 'success' | 'warn' | 'error';
8
- type FnOnOK = (value: any) => any;
9
- type FnOnCancel = (value: false) => any;
10
- type FnOnEscape = () => void;
11
- type FnOnCustom = (value: any) => any;
12
- export interface AlertConfirmPromptKnownClasses {
13
- dialog: string;
14
- icon: string;
15
- contentBlock: string;
16
- title: string;
17
- content: string;
18
- inputBox: string;
19
- inputField: string;
20
- menu: string;
21
- button: string;
22
- spinnerBox: string;
23
- }
24
- export interface AlertConfirmPromptOptions extends Record<string, any> {
25
- type: AlertConfirmPromptType.ALERT | AlertConfirmPromptType.CONFIRM | AlertConfirmPromptType.PROMPT;
26
- title: THC;
27
- content: THC;
28
- value: any;
29
- labelOk: THC;
30
- onOk: FnOnOK;
31
- labelCancel: THC;
32
- onCancel: FnOnCancel;
33
- onEscape: FnOnEscape;
34
- labelCustom?: THC;
35
- onCustom?: FnOnCustom;
36
- promptFieldProps?: any;
37
- variant: AlertConfirmPromptVariant;
38
- iconFn: (() => string) | boolean;
39
- class?: Partial<AlertConfirmPromptKnownClasses>;
40
- forceAsHtml?: boolean;
41
- }
42
- export declare const createAlertConfirmPromptStore: (defaults?: Partial<AlertConfirmPromptOptions>) => {
43
- subscribe: (cb: import("@marianmeres/store").Subscribe<AlertConfirmPromptOptions[]>) => import("@marianmeres/store").Unsubscribe;
44
- get: () => AlertConfirmPromptOptions[];
45
- push: (o: Partial<AlertConfirmPromptOptions>) => void;
46
- shift: () => void;
47
- reset: (stack?: AlertConfirmPromptOptions[]) => void;
48
- escape: () => void;
49
- close: () => void;
50
- setHeadValue: (value: string) => void;
51
- alert: (o?: Partial<AlertConfirmPromptOptions> | string) => void;
52
- confirm: (onOk: FnOnOK, o?: Partial<AlertConfirmPromptOptions>) => void;
53
- prompt: (onOk: FnOnOK, o?: Partial<AlertConfirmPromptOptions>) => void;
54
- };
55
- export declare const createAlert: (acp: ReturnType<typeof createAlertConfirmPromptStore>, defaults?: Partial<AlertConfirmPromptOptions>) => (message: string, o?: Partial<AlertConfirmPromptOptions>) => Promise<undefined>;
56
- export declare const createConfirm: (acp: ReturnType<typeof createAlertConfirmPromptStore>, defaults?: Partial<AlertConfirmPromptOptions>) => (message: string, o?: Partial<AlertConfirmPromptOptions>) => Promise<boolean>;
57
- export declare const createPrompt: (acp: ReturnType<typeof createAlertConfirmPromptStore>, defaults?: Partial<AlertConfirmPromptOptions>) => (message: string, defaultValue?: string, o?: Partial<AlertConfirmPromptOptions>) => Promise<string | null>;
58
- export {};
@@ -1,141 +0,0 @@
1
- import { createClog } from '@marianmeres/clog';
2
- import { createStore } from '@marianmeres/store';
3
- const clog = createClog('alert-confirm-prompt');
4
- export var AlertConfirmPromptType;
5
- (function (AlertConfirmPromptType) {
6
- AlertConfirmPromptType["ALERT"] = "alert";
7
- AlertConfirmPromptType["CONFIRM"] = "confirm";
8
- AlertConfirmPromptType["PROMPT"] = "prompt";
9
- })(AlertConfirmPromptType || (AlertConfirmPromptType = {}));
10
- const isFn = (v) => typeof v === 'function';
11
- const ucf = (s) => `${s}`[0].toUpperCase() + `${s}`.slice(1);
12
- export const createAlertConfirmPromptStore = (defaults) => {
13
- // fifo
14
- const _stack = createStore([]);
15
- const push = (o) => {
16
- defaults ??= {};
17
- o ??= {};
18
- defaults = {
19
- ...{
20
- labelOk: 'OK',
21
- labelCancel: 'Cancel',
22
- iconFn: true,
23
- title: ucf(o.type),
24
- },
25
- ...defaults,
26
- };
27
- if (!isFn(o.onOk))
28
- o.onOk = shift;
29
- if (!isFn(o.onCancel))
30
- o.onCancel = shift;
31
- if (!isFn(o.onEscape))
32
- o.onEscape = shift;
33
- if (!isFn(o.onCustom))
34
- o.onCustom = () => undefined;
35
- o.labelOk ??= defaults.labelOk;
36
- o.labelCancel ??= defaults.labelCancel;
37
- o.title ??= defaults.title;
38
- // variant defaults to info
39
- if (!['info', 'success', 'warn', 'error'].includes(o?.variant)) {
40
- o.variant = 'info';
41
- }
42
- o._id = Math.random().toString(36).slice(2);
43
- //
44
- _stack.update((old) => [...old, o]);
45
- };
46
- const shift = () => _stack.update((old) => {
47
- old.shift();
48
- return [...old];
49
- });
50
- const reset = (stack = []) => _stack.set(stack);
51
- const escape = () => {
52
- if (_stack.get().length)
53
- _stack.get()[0].onEscape();
54
- shift();
55
- };
56
- // will update value of the current (at index 0) element. Relevant for prompts, when validation
57
- // is needed
58
- const setHeadValue = (value) => {
59
- const head = _stack.get()[0];
60
- if (head) {
61
- head.value = value;
62
- _stack.update((old) => [head, ...old.slice(1)]);
63
- }
64
- };
65
- return {
66
- subscribe: _stack.subscribe,
67
- get: _stack.get,
68
- push,
69
- shift,
70
- reset,
71
- escape,
72
- // human alias
73
- close: shift,
74
- //
75
- setHeadValue,
76
- // sugar below
77
- //
78
- alert: (o) => {
79
- if (typeof o === 'string')
80
- o = { title: o };
81
- push({ ...(o || {}), type: AlertConfirmPromptType.ALERT });
82
- },
83
- //
84
- confirm: (onOk, o) => push({ onOk, value: false, ...o, type: AlertConfirmPromptType.CONFIRM }),
85
- //
86
- prompt: (onOk, o) => push({ onOk, value: '', ...o, type: AlertConfirmPromptType.PROMPT }),
87
- };
88
- };
89
- // sugar helpers to patch the native window.alert/confirm/prompt
90
- export const createAlert = (acp, defaults) =>
91
- // allowing to add the custom param outside of the native signature
92
- (message, o) => new Promise((resolve) => acp.alert({
93
- ...(defaults || {}),
94
- onOk: () => {
95
- acp.close();
96
- resolve(undefined);
97
- },
98
- content: message,
99
- onEscape: () => {
100
- acp.close();
101
- resolve(undefined);
102
- },
103
- ...(o || {}),
104
- }));
105
- export const createConfirm = (acp, defaults) =>
106
- // allowing to add the custom param outside of the native signature
107
- (message, o) => new Promise((resolve) => acp.confirm(() => {
108
- acp.close();
109
- resolve(true);
110
- }, {
111
- ...(defaults || {}),
112
- content: message,
113
- onCancel: () => {
114
- acp.close();
115
- resolve(false);
116
- },
117
- onEscape: () => {
118
- acp.close();
119
- resolve(false);
120
- },
121
- ...(o || {}),
122
- }));
123
- export const createPrompt = (acp, defaults) =>
124
- // allowing to add the custom param outside of the native signature
125
- (message, defaultValue = '', o) => new Promise((resolve) => acp.prompt((value) => {
126
- acp.close();
127
- resolve(value);
128
- }, {
129
- ...(defaults || {}),
130
- content: message,
131
- value: defaultValue,
132
- onCancel: () => {
133
- acp.close();
134
- resolve(null);
135
- },
136
- onEscape: () => {
137
- acp.close();
138
- resolve(null);
139
- },
140
- ...(o || {}),
141
- }));
@@ -1,25 +0,0 @@
1
- /** @typedef {typeof __propDef.props} LocalColorSchemeProps */
2
- /** @typedef {typeof __propDef.events} LocalColorSchemeEvents */
3
- /** @typedef {typeof __propDef.slots} LocalColorSchemeSlots */
4
- export default class LocalColorScheme extends SvelteComponent<{
5
- [x: string]: never;
6
- }, {
7
- [evt: string]: CustomEvent<any>;
8
- }, {}> {
9
- }
10
- export type LocalColorSchemeProps = typeof __propDef.props;
11
- export type LocalColorSchemeEvents = typeof __propDef.events;
12
- export type LocalColorSchemeSlots = typeof __propDef.slots;
13
- import { SvelteComponent } from "svelte";
14
- declare const __propDef: {
15
- props: {
16
- [x: string]: never;
17
- };
18
- events: {
19
- [evt: string]: CustomEvent<any>;
20
- };
21
- slots: {};
22
- exports?: undefined;
23
- bindings?: undefined;
24
- };
25
- export {};
@@ -1,25 +0,0 @@
1
- /** @typedef {typeof __propDef.props} SystemAwareColorSchemeProps */
2
- /** @typedef {typeof __propDef.events} SystemAwareColorSchemeEvents */
3
- /** @typedef {typeof __propDef.slots} SystemAwareColorSchemeSlots */
4
- export default class SystemAwareColorScheme extends SvelteComponent<{
5
- [x: string]: never;
6
- }, {
7
- [evt: string]: CustomEvent<any>;
8
- }, {}> {
9
- }
10
- export type SystemAwareColorSchemeProps = typeof __propDef.props;
11
- export type SystemAwareColorSchemeEvents = typeof __propDef.events;
12
- export type SystemAwareColorSchemeSlots = typeof __propDef.slots;
13
- import { SvelteComponent } from "svelte";
14
- declare const __propDef: {
15
- props: {
16
- [x: string]: never;
17
- };
18
- events: {
19
- [evt: string]: CustomEvent<any>;
20
- };
21
- slots: {};
22
- exports?: undefined;
23
- bindings?: undefined;
24
- };
25
- export {};