@marianmeres/stuic 1.125.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.
- package/README.md +2 -8
- package/dist/_shared.css +2 -0
- package/dist/actions/autogrow.svelte.d.ts +6 -0
- package/dist/actions/autogrow.svelte.js +19 -0
- package/dist/actions/highlight-dragover.svelte.d.ts +7 -0
- package/dist/actions/highlight-dragover.svelte.js +38 -0
- package/dist/actions/index.d.ts +7 -0
- package/dist/actions/index.js +7 -0
- package/dist/actions/on-submit-validity-check.svelte.d.ts +15 -0
- package/dist/actions/on-submit-validity-check.svelte.js +58 -0
- package/dist/actions/tooltip/index.css +34 -0
- package/dist/actions/tooltip/tooltip.svelte.d.ts +13 -0
- package/dist/actions/tooltip/tooltip.svelte.js +203 -0
- package/dist/actions/trim.svelte.d.ts +4 -0
- package/dist/actions/trim.svelte.js +17 -0
- package/dist/actions/{validate.d.ts → validate.svelte.d.ts} +8 -8
- package/dist/actions/validate.svelte.js +90 -0
- package/dist/components/AlertConfirmPrompt/AlertConfirmPrompt.svelte +59 -385
- package/dist/components/AlertConfirmPrompt/AlertConfirmPrompt.svelte.d.ts +9 -101
- package/dist/components/AlertConfirmPrompt/Current.svelte +202 -0
- package/dist/components/AlertConfirmPrompt/Current.svelte.d.ts +22 -0
- package/dist/components/AlertConfirmPrompt/acp-icons.d.ts +7 -2
- package/dist/components/AlertConfirmPrompt/acp-icons.js +8 -8
- package/dist/components/AlertConfirmPrompt/alert-confirm-prompt-stack.svelte.d.ts +63 -0
- package/dist/components/AlertConfirmPrompt/alert-confirm-prompt-stack.svelte.js +144 -0
- package/dist/components/AlertConfirmPrompt/index.d.ts +2 -0
- package/dist/components/AlertConfirmPrompt/index.js +2 -0
- package/dist/components/AnimatedElipsis/AnimatedEllipsis.svelte +47 -0
- package/dist/components/AnimatedElipsis/AnimatedEllipsis.svelte.d.ts +7 -0
- package/dist/components/AnimatedElipsis/index.d.ts +1 -0
- package/dist/components/AnimatedElipsis/index.js +1 -0
- package/dist/components/AppShell/AppShell.svelte +188 -127
- package/dist/components/AppShell/AppShell.svelte.d.ts +62 -43
- package/dist/components/AppShell/index.d.ts +1 -0
- package/dist/components/AppShell/index.js +1 -0
- package/dist/components/Backdrop/Backdrop.svelte +149 -49
- package/dist/components/Backdrop/Backdrop.svelte.d.ts +22 -37
- package/dist/components/Backdrop/index.d.ts +1 -0
- package/dist/components/Backdrop/index.js +1 -0
- package/dist/components/Button/Button.svelte +122 -146
- package/dist/components/Button/Button.svelte.d.ts +22 -80
- package/dist/components/Button/index.css +16 -0
- package/dist/components/Button/index.d.ts +1 -0
- package/dist/components/Button/index.js +1 -0
- package/dist/components/ColResize/ColResize.svelte +0 -0
- package/dist/components/ColResize/ColResize.svelte.d.ts +26 -0
- package/dist/components/ColorScheme/{LocalColorScheme.svelte → ColorSchemeLocal.svelte} +2 -2
- package/dist/components/ColorScheme/ColorSchemeLocal.svelte.d.ts +26 -0
- package/dist/components/ColorScheme/{SystemAwareColorScheme.svelte → ColorSchemeSystemAware.svelte} +4 -4
- package/dist/components/ColorScheme/ColorSchemeSystemAware.svelte.d.ts +26 -0
- package/dist/components/ColorScheme/color-scheme.d.ts +26 -8
- package/dist/components/ColorScheme/color-scheme.js +40 -16
- package/dist/components/ColorScheme/index.d.ts +3 -0
- package/dist/components/ColorScheme/index.js +3 -0
- package/dist/components/DismissibleMessage/DismissibleMessage.svelte +76 -83
- package/dist/components/DismissibleMessage/DismissibleMessage.svelte.d.ts +16 -37
- package/dist/components/DismissibleMessage/index.css +13 -0
- package/dist/components/DismissibleMessage/index.d.ts +1 -0
- package/dist/components/DismissibleMessage/index.js +1 -0
- package/dist/components/Drawer/Drawer.svelte +155 -84
- package/dist/components/Drawer/Drawer.svelte.d.ts +24 -35
- package/dist/components/Drawer/index.d.ts +1 -0
- package/dist/components/Drawer/index.js +1 -0
- package/dist/components/HoverExpandableWidth/HoverExpandableWidth.svelte +150 -111
- package/dist/components/HoverExpandableWidth/HoverExpandableWidth.svelte.d.ts +16 -29
- package/dist/components/HoverExpandableWidth/index.d.ts +1 -0
- package/dist/components/HoverExpandableWidth/index.js +1 -0
- package/dist/components/Input/FieldCheckbox.svelte +174 -132
- package/dist/components/Input/FieldCheckbox.svelte.d.ts +28 -64
- package/dist/components/Input/FieldFile.svelte +166 -0
- package/dist/components/Input/FieldFile.svelte.d.ts +41 -0
- package/dist/components/Input/FieldInput.svelte +143 -0
- package/dist/components/Input/FieldInput.svelte.d.ts +41 -0
- package/dist/components/Input/FieldLikeButton.svelte +206 -0
- package/dist/components/Input/FieldLikeButton.svelte.d.ts +41 -0
- package/dist/components/Input/FieldOptions.svelte +646 -0
- package/dist/components/Input/FieldOptions.svelte.d.ts +58 -0
- package/dist/components/Input/FieldRadios.svelte +126 -77
- package/dist/components/Input/FieldRadios.svelte.d.ts +23 -61
- package/dist/components/Input/FieldSelect.svelte +160 -239
- package/dist/components/Input/FieldSelect.svelte.d.ts +40 -88
- package/dist/components/Input/FieldSwitch.svelte +132 -0
- package/dist/components/Input/FieldSwitch.svelte.d.ts +41 -0
- package/dist/components/Input/FieldTextarea.svelte +146 -0
- package/dist/components/Input/FieldTextarea.svelte.d.ts +44 -0
- package/dist/components/Input/Fieldset.svelte +21 -17
- package/dist/components/Input/Fieldset.svelte.d.ts +10 -27
- package/dist/components/Input/_internal/FieldRadioInternal.svelte +186 -0
- package/dist/components/Input/_internal/FieldRadioInternal.svelte.d.ts +30 -0
- package/dist/components/Input/_internal/InputWrap.svelte +216 -0
- package/dist/components/Input/_internal/InputWrap.svelte.d.ts +36 -0
- package/dist/components/Input/index.css +134 -0
- package/dist/components/Input/index.d.ts +11 -0
- package/dist/components/Input/index.js +11 -0
- package/dist/components/Input/types.d.ts +11 -0
- package/dist/components/KbdShortcut/KbdShortcut.svelte +89 -0
- package/dist/components/KbdShortcut/KbdShortcut.svelte.d.ts +17 -0
- package/dist/components/KbdShortcut/index.d.ts +1 -0
- package/dist/components/KbdShortcut/index.js +1 -0
- package/dist/components/Modal/Modal.svelte +127 -0
- package/dist/components/Modal/Modal.svelte.d.ts +32 -0
- package/dist/components/Modal/index.d.ts +1 -0
- package/dist/components/Modal/index.js +1 -0
- package/dist/components/ModalDialog/ModalDialog.svelte +137 -81
- package/dist/components/ModalDialog/ModalDialog.svelte.d.ts +17 -38
- package/dist/components/ModalDialog/index.d.ts +1 -0
- package/dist/components/ModalDialog/index.js +1 -0
- package/dist/components/Notifications/Notifications.svelte +259 -173
- package/dist/components/Notifications/Notifications.svelte.d.ts +32 -60
- package/dist/components/Notifications/index.css +12 -0
- package/dist/components/Notifications/index.d.ts +2 -0
- package/dist/components/Notifications/index.js +2 -0
- package/dist/components/Notifications/notifications-icons.d.ts +1 -1
- package/dist/components/Notifications/notifications-icons.js +4 -4
- package/dist/components/Notifications/notifications-stack.svelte.d.ts +89 -0
- package/dist/components/Notifications/notifications-stack.svelte.js +161 -0
- package/dist/components/Progress/Progress.svelte +26 -0
- package/dist/components/Progress/Progress.svelte.d.ts +10 -0
- package/dist/components/Progress/_internal/Bar.svelte +31 -0
- package/dist/components/Progress/_internal/Bar.svelte.d.ts +10 -0
- package/dist/components/Progress/_internal/Circle.svelte +10 -0
- package/dist/components/Progress/_internal/Circle.svelte.d.ts +7 -0
- package/dist/components/Progress/index.css +7 -0
- package/dist/components/Progress/index.d.ts +1 -0
- package/dist/components/Progress/index.js +1 -0
- package/dist/components/Spinner/Spinner.svelte +52 -37
- package/dist/components/Spinner/Spinner.svelte.d.ts +10 -22
- package/dist/components/Spinner/index.d.ts +1 -0
- package/dist/components/Spinner/index.js +1 -0
- package/dist/components/Switch/Switch.svelte +158 -118
- package/dist/components/Switch/Switch.svelte.d.ts +25 -66
- package/dist/components/Switch/SwitchButton.svelte +131 -0
- package/dist/components/Switch/SwitchButton.svelte.d.ts +21 -0
- package/dist/components/Switch/index.css +7 -0
- package/dist/components/Switch/index.d.ts +2 -0
- package/dist/components/Switch/index.js +2 -0
- package/dist/components/Thc/Thc.svelte +67 -10
- package/dist/components/Thc/Thc.svelte.d.ts +18 -22
- package/dist/components/Thc/index.d.ts +1 -0
- package/dist/components/Thc/index.js +1 -0
- package/dist/components/TwCheck/TwCheck.svelte +34 -0
- package/dist/components/TwCheck/TwCheck.svelte.d.ts +10 -0
- package/dist/components/TwCheck/index.css +5 -0
- package/dist/components/TwCheck/index.d.ts +1 -0
- package/dist/components/TwCheck/index.js +1 -0
- package/dist/components/X/X.svelte +12 -5
- package/dist/components/X/X.svelte.d.ts +6 -18
- package/dist/components/X/index.d.ts +1 -0
- package/dist/components/X/index.js +1 -0
- package/dist/index.css +26 -0
- package/dist/index.d.ts +21 -39
- package/dist/index.js +23 -54
- package/dist/types.d.ts +251 -2
- package/dist/types.js +248 -0
- package/dist/utils/breakpoint.svelte.d.ts +19 -0
- package/dist/utils/breakpoint.svelte.js +42 -0
- package/dist/utils/debounce.d.ts +13 -0
- package/dist/utils/debounce.js +22 -0
- package/dist/utils/device-pointer.svelte.d.ts +11 -0
- package/dist/utils/device-pointer.svelte.js +26 -0
- package/dist/utils/event-modifiers.d.ts +4 -0
- package/dist/utils/event-modifiers.js +29 -0
- package/dist/utils/get-id.d.ts +1 -1
- package/dist/utils/get-id.js +3 -1
- package/dist/utils/index.d.ts +21 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/is-browser.d.ts +1 -0
- package/dist/utils/is-browser.js +5 -0
- package/dist/utils/is-mac.d.ts +1 -0
- package/dist/utils/is-mac.js +11 -0
- package/dist/utils/maybe-json-parse.d.ts +1 -0
- package/dist/utils/maybe-json-parse.js +12 -0
- package/dist/utils/maybe-json-stringify.d.ts +1 -0
- package/dist/utils/maybe-json-stringify.js +11 -0
- package/dist/utils/move-array-item.d.ts +4 -0
- package/dist/utils/move-array-item.js +20 -0
- package/dist/utils/omit-pick.d.ts +2 -2
- package/dist/utils/omit-pick.js +10 -8
- package/dist/utils/paint.d.ts +18 -0
- package/dist/utils/paint.js +32 -0
- package/dist/utils/persistent-state.svelte.d.ts +23 -0
- package/dist/utils/persistent-state.svelte.js +48 -0
- package/dist/utils/prefers-reduced-motion.svelte.d.ts +2 -0
- package/dist/utils/prefers-reduced-motion.svelte.js +4 -0
- package/dist/utils/qsa.d.ts +1 -0
- package/dist/utils/qsa.js +3 -0
- package/dist/utils/sleep.d.ts +28 -0
- package/dist/utils/sleep.js +33 -0
- package/dist/utils/storage-abstraction.d.ts +35 -0
- package/dist/utils/storage-abstraction.js +136 -0
- package/dist/utils/str-hash.d.ts +7 -0
- package/dist/utils/str-hash.js +35 -0
- package/dist/utils/throttle.d.ts +1 -0
- package/dist/utils/throttle.js +47 -0
- package/dist/utils/to-integer.d.ts +1 -0
- package/dist/utils/to-integer.js +11 -0
- package/dist/utils/tr.d.ts +5 -0
- package/dist/utils/tr.js +13 -0
- package/dist/utils/tw-merge.d.ts +10 -0
- package/dist/utils/tw-merge.js +16 -0
- package/dist/utils/ucfirst.d.ts +1 -0
- package/dist/utils/ucfirst.js +6 -0
- package/package.json +66 -73
- package/dist/actions/autogrow.d.ts +0 -8
- package/dist/actions/autogrow.js +0 -22
- package/dist/actions/autoscroll.d.ts +0 -21
- package/dist/actions/autoscroll.js +0 -60
- package/dist/actions/drag-drop.d.ts +0 -28
- package/dist/actions/drag-drop.js +0 -152
- package/dist/actions/on-outside.d.ts +0 -9
- package/dist/actions/on-outside.js +0 -27
- package/dist/actions/pre-submit-validity-check.d.ts +0 -3
- package/dist/actions/pre-submit-validity-check.js +0 -21
- package/dist/actions/tooltip/_make-visible.d.ts +0 -3
- package/dist/actions/tooltip/_make-visible.js +0 -25
- package/dist/actions/tooltip/_maybe-pick-safe-placement.d.ts +0 -3
- package/dist/actions/tooltip/_maybe-pick-safe-placement.js +0 -86
- package/dist/actions/tooltip/_set-position.d.ts +0 -2
- package/dist/actions/tooltip/_set-position.js +0 -125
- package/dist/actions/tooltip/tooltip.d.ts +0 -42
- package/dist/actions/tooltip/tooltip.js +0 -299
- package/dist/actions/trim.d.ts +0 -4
- package/dist/actions/trim.js +0 -18
- package/dist/actions/validate.js +0 -80
- package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.d.ts +0 -58
- package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.js +0 -141
- package/dist/components/ColorScheme/LocalColorScheme.svelte.d.ts +0 -25
- package/dist/components/ColorScheme/SystemAwareColorScheme.svelte.d.ts +0 -25
- package/dist/components/Input/Field.svelte +0 -315
- package/dist/components/Input/Field.svelte.d.ts +0 -102
- package/dist/components/Input/PinInput.svelte +0 -151
- package/dist/components/Input/PinInput.svelte.d.ts +0 -51
- package/dist/components/Input/XFieldRadioInternal.svelte +0 -143
- package/dist/components/Input/XFieldRadioInternal.svelte.d.ts +0 -45
- package/dist/components/Notifications/notifications.d.ts +0 -78
- package/dist/components/Notifications/notifications.js +0 -215
- package/dist/components/Popover/Popover.svelte +0 -24
- package/dist/components/Popover/Popover.svelte.d.ts +0 -22
- package/dist/components/Spinner/Spinner.v5.svelte +0 -114
- package/dist/components/Spinner/Spinner.v5.svelte.d.ts +0 -16
- package/dist/utils/calculate-alignment.d.ts +0 -68
- package/dist/utils/calculate-alignment.js +0 -183
- package/dist/utils/device-pointer.d.ts +0 -5
- package/dist/utils/device-pointer.js +0 -10
- package/dist/utils/prefers-reduced-motion.d.ts +0 -6
- package/dist/utils/prefers-reduced-motion.js +0 -26
- package/dist/utils/tw-merge2.d.ts +0 -3
- package/dist/utils/tw-merge2.js +0 -9
- package/dist/utils/tw-types.d.ts +0 -1
- package/dist/utils/window-size.d.ts +0 -22
- package/dist/utils/window-size.js +0 -35
- /package/dist/{utils/tw-types.js → components/Input/types.js} +0 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
4
|
+
import { trim } from "../../actions/trim.svelte.js";
|
|
5
|
+
import {
|
|
6
|
+
validate as validateAction,
|
|
7
|
+
type ValidateOptions,
|
|
8
|
+
type ValidationResult,
|
|
9
|
+
} from "../../actions/validate.svelte.js";
|
|
10
|
+
import { getId } from "../../utils/get-id.js";
|
|
11
|
+
import { twMerge } from "../../utils/tw-merge.js";
|
|
12
|
+
import type { THC } from "../Thc/Thc.svelte";
|
|
13
|
+
import InputWrap from "./_internal/InputWrap.svelte";
|
|
14
|
+
|
|
15
|
+
type SnippetWithId = Snippet<[{ id: string }]>;
|
|
16
|
+
|
|
17
|
+
interface Props extends HTMLInputAttributes, Record<string, any> {
|
|
18
|
+
input?: HTMLInputElement;
|
|
19
|
+
value?: string | number; // badInput
|
|
20
|
+
label?: SnippetWithId | THC;
|
|
21
|
+
type?: string;
|
|
22
|
+
description?: SnippetWithId | THC;
|
|
23
|
+
class?: string;
|
|
24
|
+
id?: string;
|
|
25
|
+
tabindex?: number; // tooShort
|
|
26
|
+
renderSize?: "sm" | "md" | "lg" | string;
|
|
27
|
+
useTrim?: boolean;
|
|
28
|
+
//
|
|
29
|
+
required?: boolean;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
//
|
|
32
|
+
validate?: boolean | Omit<ValidateOptions, "setValidationResult">;
|
|
33
|
+
// wrap snippets
|
|
34
|
+
labelAfter?: SnippetWithId | THC;
|
|
35
|
+
inputBefore?: SnippetWithId | THC;
|
|
36
|
+
inputAfter?: SnippetWithId | THC;
|
|
37
|
+
inputBelow?: SnippetWithId | THC;
|
|
38
|
+
below?: SnippetWithId | THC;
|
|
39
|
+
//
|
|
40
|
+
labelLeft?: boolean;
|
|
41
|
+
labelLeftWidth?: "normal" | "wide";
|
|
42
|
+
labelLeftBreakpoint?: number;
|
|
43
|
+
//
|
|
44
|
+
classInput?: string;
|
|
45
|
+
classLabel?: string;
|
|
46
|
+
classLabelBox?: string;
|
|
47
|
+
classInputBox?: string;
|
|
48
|
+
classInputBoxWrap?: string;
|
|
49
|
+
classDescBox?: string;
|
|
50
|
+
classBelowBox?: string;
|
|
51
|
+
//
|
|
52
|
+
style?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let {
|
|
56
|
+
input = $bindable(),
|
|
57
|
+
value = $bindable(),
|
|
58
|
+
label = "",
|
|
59
|
+
id = getId(),
|
|
60
|
+
type = "text",
|
|
61
|
+
tabindex = 0,
|
|
62
|
+
description,
|
|
63
|
+
class: classProp,
|
|
64
|
+
renderSize = "md",
|
|
65
|
+
useTrim = true,
|
|
66
|
+
//
|
|
67
|
+
required = false,
|
|
68
|
+
disabled = false,
|
|
69
|
+
//
|
|
70
|
+
validate,
|
|
71
|
+
//
|
|
72
|
+
labelAfter,
|
|
73
|
+
inputBefore,
|
|
74
|
+
inputAfter,
|
|
75
|
+
inputBelow,
|
|
76
|
+
below,
|
|
77
|
+
//
|
|
78
|
+
labelLeft = false,
|
|
79
|
+
labelLeftWidth = "normal",
|
|
80
|
+
labelLeftBreakpoint = 480,
|
|
81
|
+
//
|
|
82
|
+
classInput,
|
|
83
|
+
classLabel,
|
|
84
|
+
classLabelBox,
|
|
85
|
+
classInputBox,
|
|
86
|
+
classInputBoxWrap,
|
|
87
|
+
classDescBox,
|
|
88
|
+
classBelowBox,
|
|
89
|
+
style,
|
|
90
|
+
//
|
|
91
|
+
...rest
|
|
92
|
+
}: Props = $props();
|
|
93
|
+
|
|
94
|
+
//
|
|
95
|
+
let validation: ValidationResult | undefined = $state();
|
|
96
|
+
const setValidationResult = (res: ValidationResult) => (validation = res);
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
<InputWrap
|
|
100
|
+
{description}
|
|
101
|
+
class={classProp}
|
|
102
|
+
size={renderSize}
|
|
103
|
+
{id}
|
|
104
|
+
{label}
|
|
105
|
+
{labelAfter}
|
|
106
|
+
{inputBefore}
|
|
107
|
+
{inputAfter}
|
|
108
|
+
{below}
|
|
109
|
+
{required}
|
|
110
|
+
{disabled}
|
|
111
|
+
{labelLeft}
|
|
112
|
+
{labelLeftWidth}
|
|
113
|
+
{labelLeftBreakpoint}
|
|
114
|
+
{classLabel}
|
|
115
|
+
{classLabelBox}
|
|
116
|
+
{classInputBox}
|
|
117
|
+
{classInputBoxWrap}
|
|
118
|
+
{classDescBox}
|
|
119
|
+
{classBelowBox}
|
|
120
|
+
{validation}
|
|
121
|
+
{style}
|
|
122
|
+
>
|
|
123
|
+
<input
|
|
124
|
+
bind:value
|
|
125
|
+
bind:this={input}
|
|
126
|
+
{type}
|
|
127
|
+
{id}
|
|
128
|
+
class={twMerge("form-input", renderSize, classInput)}
|
|
129
|
+
use:trim={() => ({
|
|
130
|
+
enabled: useTrim,
|
|
131
|
+
setValue: (v: string) => useTrim && (value = v),
|
|
132
|
+
})}
|
|
133
|
+
use:validateAction={() => ({
|
|
134
|
+
enabled: !!validate,
|
|
135
|
+
...(typeof validate === "boolean" ? {} : validate),
|
|
136
|
+
setValidationResult,
|
|
137
|
+
})}
|
|
138
|
+
{tabindex}
|
|
139
|
+
{required}
|
|
140
|
+
{disabled}
|
|
141
|
+
{...rest}
|
|
142
|
+
/>
|
|
143
|
+
</InputWrap>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
3
|
+
import { type ValidateOptions } from "../../actions/validate.svelte.js";
|
|
4
|
+
import type { THC } from "../Thc/Thc.svelte";
|
|
5
|
+
type SnippetWithId = Snippet<[{
|
|
6
|
+
id: string;
|
|
7
|
+
}]>;
|
|
8
|
+
interface Props extends HTMLInputAttributes, Record<string, any> {
|
|
9
|
+
input?: HTMLInputElement;
|
|
10
|
+
value?: string | number;
|
|
11
|
+
label?: SnippetWithId | THC;
|
|
12
|
+
type?: string;
|
|
13
|
+
description?: SnippetWithId | THC;
|
|
14
|
+
class?: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
tabindex?: number;
|
|
17
|
+
renderSize?: "sm" | "md" | "lg" | string;
|
|
18
|
+
useTrim?: boolean;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
validate?: boolean | Omit<ValidateOptions, "setValidationResult">;
|
|
22
|
+
labelAfter?: SnippetWithId | THC;
|
|
23
|
+
inputBefore?: SnippetWithId | THC;
|
|
24
|
+
inputAfter?: SnippetWithId | THC;
|
|
25
|
+
inputBelow?: SnippetWithId | THC;
|
|
26
|
+
below?: SnippetWithId | THC;
|
|
27
|
+
labelLeft?: boolean;
|
|
28
|
+
labelLeftWidth?: "normal" | "wide";
|
|
29
|
+
labelLeftBreakpoint?: number;
|
|
30
|
+
classInput?: string;
|
|
31
|
+
classLabel?: string;
|
|
32
|
+
classLabelBox?: string;
|
|
33
|
+
classInputBox?: string;
|
|
34
|
+
classInputBoxWrap?: string;
|
|
35
|
+
classDescBox?: string;
|
|
36
|
+
classBelowBox?: string;
|
|
37
|
+
style?: string;
|
|
38
|
+
}
|
|
39
|
+
declare const FieldInput: import("svelte").Component<Props, {}, "value" | "input">;
|
|
40
|
+
type FieldInput = ReturnType<typeof FieldInput>;
|
|
41
|
+
export default FieldInput;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import {
|
|
4
|
+
validate as validateAction,
|
|
5
|
+
type ValidateOptions,
|
|
6
|
+
type ValidationResult,
|
|
7
|
+
} from "../../actions/validate.svelte.js";
|
|
8
|
+
import { getId } from "../../utils/get-id.js";
|
|
9
|
+
import { twMerge } from "../../utils/tw-merge.js";
|
|
10
|
+
import type { THC } from "../Thc/Thc.svelte";
|
|
11
|
+
import InputWrap from "./_internal/InputWrap.svelte";
|
|
12
|
+
|
|
13
|
+
type SnippetWithId = Snippet<[{ id: string }]>;
|
|
14
|
+
|
|
15
|
+
interface Props extends Record<string, any> {
|
|
16
|
+
input?: HTMLInputElement;
|
|
17
|
+
value: string;
|
|
18
|
+
label?: SnippetWithId | THC;
|
|
19
|
+
// type?: "submit" | "reset" | "button";
|
|
20
|
+
description?: SnippetWithId | THC;
|
|
21
|
+
class?: string;
|
|
22
|
+
id?: string;
|
|
23
|
+
tabindex?: number; // tooShort
|
|
24
|
+
renderSize?: "sm" | "md" | "lg" | string;
|
|
25
|
+
useTrim?: boolean;
|
|
26
|
+
name?: string;
|
|
27
|
+
//
|
|
28
|
+
required?: boolean;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
//
|
|
31
|
+
validate?: boolean | Omit<ValidateOptions, "setValidationResult">;
|
|
32
|
+
// wrap snippets
|
|
33
|
+
labelAfter?: SnippetWithId | THC;
|
|
34
|
+
inputBefore?: SnippetWithId | THC;
|
|
35
|
+
inputAfter?: SnippetWithId | THC;
|
|
36
|
+
inputBelow?: SnippetWithId | THC;
|
|
37
|
+
below?: SnippetWithId | THC;
|
|
38
|
+
//
|
|
39
|
+
labelLeft?: boolean;
|
|
40
|
+
labelLeftWidth?: "normal" | "wide";
|
|
41
|
+
labelLeftBreakpoint?: number;
|
|
42
|
+
//
|
|
43
|
+
classInput?: string;
|
|
44
|
+
classLabel?: string;
|
|
45
|
+
classLabelBox?: string;
|
|
46
|
+
classInputBox?: string;
|
|
47
|
+
classInputBoxWrap?: string;
|
|
48
|
+
classDescBox?: string;
|
|
49
|
+
classBelowBox?: string;
|
|
50
|
+
//
|
|
51
|
+
style?: string;
|
|
52
|
+
//
|
|
53
|
+
renderValue?: (rawValue: any) => string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let {
|
|
57
|
+
input = $bindable(),
|
|
58
|
+
value = $bindable(),
|
|
59
|
+
label = "",
|
|
60
|
+
id = getId(),
|
|
61
|
+
// type = "button",
|
|
62
|
+
tabindex = 0,
|
|
63
|
+
description,
|
|
64
|
+
class: classProp,
|
|
65
|
+
renderSize = "md",
|
|
66
|
+
useTrim = true,
|
|
67
|
+
name,
|
|
68
|
+
//
|
|
69
|
+
required = false,
|
|
70
|
+
disabled = false,
|
|
71
|
+
//
|
|
72
|
+
validate,
|
|
73
|
+
//
|
|
74
|
+
labelAfter,
|
|
75
|
+
inputBefore,
|
|
76
|
+
inputAfter,
|
|
77
|
+
inputBelow,
|
|
78
|
+
below,
|
|
79
|
+
//
|
|
80
|
+
labelLeft = false,
|
|
81
|
+
labelLeftWidth = "normal",
|
|
82
|
+
labelLeftBreakpoint = 480,
|
|
83
|
+
//
|
|
84
|
+
classInput,
|
|
85
|
+
classLabel,
|
|
86
|
+
classLabelBox,
|
|
87
|
+
classInputBox,
|
|
88
|
+
classInputBoxWrap,
|
|
89
|
+
classDescBox,
|
|
90
|
+
classBelowBox,
|
|
91
|
+
style = "",
|
|
92
|
+
//
|
|
93
|
+
renderValue,
|
|
94
|
+
//
|
|
95
|
+
...rest
|
|
96
|
+
}: Props = $props();
|
|
97
|
+
|
|
98
|
+
let _value_renderer: any = $derived(
|
|
99
|
+
typeof renderValue === "function"
|
|
100
|
+
? renderValue
|
|
101
|
+
: (v: any) => {
|
|
102
|
+
// by default, we're expecting JSON value
|
|
103
|
+
try {
|
|
104
|
+
return JSON.stringify(JSON.parse(v));
|
|
105
|
+
} catch (e) {
|
|
106
|
+
return `${e}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// let rendered = $derived(renderValue?.(value) ?? value);
|
|
112
|
+
let rendered: string | Snippet<[value: string]> = $derived(_value_renderer(value));
|
|
113
|
+
|
|
114
|
+
// once button rendered, trigger change on the input, so that the validation re/triggers
|
|
115
|
+
$effect(() => {
|
|
116
|
+
rendered;
|
|
117
|
+
input?.dispatchEvent(new Event("change", { bubbles: true }));
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
//
|
|
121
|
+
let validation: ValidationResult | undefined = $state();
|
|
122
|
+
const setValidationResult = (res: ValidationResult) => (validation = res);
|
|
123
|
+
|
|
124
|
+
// $inspect("validation", validation);
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<InputWrap
|
|
128
|
+
{description}
|
|
129
|
+
class={classProp}
|
|
130
|
+
size={renderSize}
|
|
131
|
+
{id}
|
|
132
|
+
{label}
|
|
133
|
+
{labelAfter}
|
|
134
|
+
{inputBefore}
|
|
135
|
+
{inputAfter}
|
|
136
|
+
{below}
|
|
137
|
+
{required}
|
|
138
|
+
{disabled}
|
|
139
|
+
{labelLeft}
|
|
140
|
+
{labelLeftWidth}
|
|
141
|
+
{labelLeftBreakpoint}
|
|
142
|
+
{classLabel}
|
|
143
|
+
{classLabelBox}
|
|
144
|
+
{classInputBox}
|
|
145
|
+
{classInputBoxWrap}
|
|
146
|
+
{classDescBox}
|
|
147
|
+
{classBelowBox}
|
|
148
|
+
{validation}
|
|
149
|
+
{style}
|
|
150
|
+
>
|
|
151
|
+
<button
|
|
152
|
+
type="button"
|
|
153
|
+
class={twMerge(
|
|
154
|
+
"no-focus-visible",
|
|
155
|
+
"w-full text-left py-2 px-3 border-0 bg-transparent",
|
|
156
|
+
"focus:outline-0 focus-visible:outline-0",
|
|
157
|
+
renderSize,
|
|
158
|
+
classInput
|
|
159
|
+
)}
|
|
160
|
+
{disabled}
|
|
161
|
+
{...rest as any}
|
|
162
|
+
{tabindex}
|
|
163
|
+
>
|
|
164
|
+
{#if typeof rendered === "function"}
|
|
165
|
+
{@render rendered(value)}
|
|
166
|
+
{:else if rendered}
|
|
167
|
+
{@html rendered}
|
|
168
|
+
{:else}
|
|
169
|
+
|
|
170
|
+
{/if}
|
|
171
|
+
</button>
|
|
172
|
+
|
|
173
|
+
<input
|
|
174
|
+
bind:value
|
|
175
|
+
bind:this={input}
|
|
176
|
+
type="hidden"
|
|
177
|
+
{id}
|
|
178
|
+
{name}
|
|
179
|
+
use:validateAction={() => ({
|
|
180
|
+
enabled: !!validate,
|
|
181
|
+
...(typeof validate === "boolean"
|
|
182
|
+
? {
|
|
183
|
+
// PROBLEM with hidden inputs is that they:
|
|
184
|
+
// 1. do not report required (AFAICT)
|
|
185
|
+
// 2. do not report el.validationMessage even if invalid via custom validation
|
|
186
|
+
customValidator(val, ctx, el) {
|
|
187
|
+
// so, here, we're fixing (1.) and will handle the (2.) elsewhere
|
|
188
|
+
// (the message will be ignored anyway, we just need to send non-empty string)
|
|
189
|
+
if (required && !val) return "valueMissing";
|
|
190
|
+
|
|
191
|
+
// also, by default, JSON validation is built in
|
|
192
|
+
try {
|
|
193
|
+
JSON.parse(val);
|
|
194
|
+
return "";
|
|
195
|
+
} catch (e) {
|
|
196
|
+
return "typeMismatch";
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
: validate),
|
|
201
|
+
setValidationResult,
|
|
202
|
+
})}
|
|
203
|
+
{required}
|
|
204
|
+
{disabled}
|
|
205
|
+
/>
|
|
206
|
+
</InputWrap>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import { type ValidateOptions } from "../../actions/validate.svelte.js";
|
|
3
|
+
import type { THC } from "../Thc/Thc.svelte";
|
|
4
|
+
type SnippetWithId = Snippet<[{
|
|
5
|
+
id: string;
|
|
6
|
+
}]>;
|
|
7
|
+
interface Props extends Record<string, any> {
|
|
8
|
+
input?: HTMLInputElement;
|
|
9
|
+
value: string;
|
|
10
|
+
label?: SnippetWithId | THC;
|
|
11
|
+
description?: SnippetWithId | THC;
|
|
12
|
+
class?: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
tabindex?: number;
|
|
15
|
+
renderSize?: "sm" | "md" | "lg" | string;
|
|
16
|
+
useTrim?: boolean;
|
|
17
|
+
name?: string;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
validate?: boolean | Omit<ValidateOptions, "setValidationResult">;
|
|
21
|
+
labelAfter?: SnippetWithId | THC;
|
|
22
|
+
inputBefore?: SnippetWithId | THC;
|
|
23
|
+
inputAfter?: SnippetWithId | THC;
|
|
24
|
+
inputBelow?: SnippetWithId | THC;
|
|
25
|
+
below?: SnippetWithId | THC;
|
|
26
|
+
labelLeft?: boolean;
|
|
27
|
+
labelLeftWidth?: "normal" | "wide";
|
|
28
|
+
labelLeftBreakpoint?: number;
|
|
29
|
+
classInput?: string;
|
|
30
|
+
classLabel?: string;
|
|
31
|
+
classLabelBox?: string;
|
|
32
|
+
classInputBox?: string;
|
|
33
|
+
classInputBoxWrap?: string;
|
|
34
|
+
classDescBox?: string;
|
|
35
|
+
classBelowBox?: string;
|
|
36
|
+
style?: string;
|
|
37
|
+
renderValue?: (rawValue: any) => string;
|
|
38
|
+
}
|
|
39
|
+
declare const FieldLikeButton: import("svelte").Component<Props, {}, "value" | "input">;
|
|
40
|
+
type FieldLikeButton = ReturnType<typeof FieldLikeButton>;
|
|
41
|
+
export default FieldLikeButton;
|