lutra 0.0.33 → 0.1.0
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 +4 -24
- package/dist/components/AspectRatio.svelte +26 -0
- package/dist/components/AspectRatio.svelte.d.ts +8 -0
- package/dist/components/Dialog.svelte +78 -0
- package/dist/components/Dialog.svelte.d.ts +14 -0
- package/dist/components/Layout.svelte +32 -0
- package/dist/components/Layout.svelte.d.ts +11 -0
- package/dist/components/PageContent.svelte +108 -0
- package/dist/components/PageContent.svelte.d.ts +38 -0
- package/dist/components/Theme.svelte +87 -0
- package/dist/components/Theme.svelte.d.ts +17 -0
- package/dist/{display → components}/Tooltip.svelte +33 -8
- package/dist/components/Tooltip.svelte.d.ts +12 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.js +18 -0
- package/dist/css/0-layers.css +1 -0
- package/dist/css/1-props.css +775 -0
- package/dist/css/2-base.css +209 -0
- package/dist/css/3-typo.css +65 -0
- package/dist/css/4-layout.css +5 -0
- package/dist/css/5-media.css +21 -0
- package/dist/css/lutra.css +6 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -2
- package/dist/types.d.ts +39 -0
- package/dist/types.js +25 -0
- package/package.json +29 -82
- package/dist/color.css +0 -0
- package/dist/display/Avatar.svelte +0 -61
- package/dist/display/Avatar.svelte.d.ts +0 -19
- package/dist/display/Badge.svelte +0 -91
- package/dist/display/Badge.svelte.d.ts +0 -30
- package/dist/display/Callout.svelte +0 -109
- package/dist/display/Callout.svelte.d.ts +0 -28
- package/dist/display/Close.svelte +0 -58
- package/dist/display/Close.svelte.d.ts +0 -18
- package/dist/display/Code.svelte +0 -190
- package/dist/display/Code.svelte.d.ts +0 -32
- package/dist/display/ContextTip.svelte +0 -23
- package/dist/display/ContextTip.svelte.d.ts +0 -18
- package/dist/display/DataList.svelte +0 -16
- package/dist/display/DataList.svelte.d.ts +0 -21
- package/dist/display/Details.svelte +0 -49
- package/dist/display/Details.svelte.d.ts +0 -27
- package/dist/display/Hero.svelte +0 -50
- package/dist/display/Hero.svelte.d.ts +0 -26
- package/dist/display/Icon.svelte +0 -39
- package/dist/display/Icon.svelte.d.ts +0 -19
- package/dist/display/IconButton.svelte +0 -91
- package/dist/display/IconButton.svelte.d.ts +0 -27
- package/dist/display/Image.svelte +0 -91
- package/dist/display/Image.svelte.d.ts +0 -26
- package/dist/display/Indicator.svelte +0 -352
- package/dist/display/Indicator.svelte.d.ts +0 -23
- package/dist/display/Inset.svelte +0 -18
- package/dist/display/Inset.svelte.d.ts +0 -18
- package/dist/display/LineChart.svelte +0 -385
- package/dist/display/LineChart.svelte.d.ts +0 -24
- package/dist/display/LoadingIndicator.svelte +0 -33
- package/dist/display/LoadingIndicator.svelte.d.ts +0 -15
- package/dist/display/Modal.svelte +0 -116
- package/dist/display/Modal.svelte.d.ts +0 -27
- package/dist/display/Notification.svelte +0 -104
- package/dist/display/Notification.svelte.d.ts +0 -23
- package/dist/display/Panel.svelte +0 -23
- package/dist/display/Panel.svelte.d.ts +0 -19
- package/dist/display/Popup.svelte +0 -111
- package/dist/display/Popup.svelte.d.ts +0 -25
- package/dist/display/Stat.svelte +0 -81
- package/dist/display/Stat.svelte.d.ts +0 -30
- package/dist/display/Table.svelte +0 -28
- package/dist/display/Table.svelte.d.ts +0 -24
- package/dist/display/TablePaginator.svelte +0 -51
- package/dist/display/TablePaginator.svelte.d.ts +0 -21
- package/dist/display/Tag.svelte +0 -90
- package/dist/display/Tag.svelte.d.ts +0 -32
- package/dist/display/Tooltip.svelte.d.ts +0 -23
- package/dist/display/chart.d.ts +0 -78
- package/dist/display/chart.js +0 -212
- package/dist/display/index.d.ts +0 -24
- package/dist/display/index.js +0 -24
- package/dist/display/notifications.svelte.d.ts +0 -21
- package/dist/display/notifications.svelte.js +0 -31
- package/dist/form/Button.svelte +0 -39
- package/dist/form/Button.svelte.d.ts +0 -26
- package/dist/form/FieldActions.svelte +0 -68
- package/dist/form/FieldActions.svelte.d.ts +0 -20
- package/dist/form/FieldContainer.svelte +0 -37
- package/dist/form/FieldContainer.svelte.d.ts +0 -19
- package/dist/form/FieldContent.svelte +0 -153
- package/dist/form/FieldContent.svelte.d.ts +0 -31
- package/dist/form/FieldError.svelte +0 -14
- package/dist/form/FieldError.svelte.d.ts +0 -18
- package/dist/form/FieldSection.svelte +0 -86
- package/dist/form/FieldSection.svelte.d.ts +0 -20
- package/dist/form/Fieldset.svelte +0 -68
- package/dist/form/Fieldset.svelte.d.ts +0 -31
- package/dist/form/Form.svelte +0 -136
- package/dist/form/Form.svelte.d.ts +0 -38
- package/dist/form/ImageUpload.svelte +0 -259
- package/dist/form/ImageUpload.svelte.d.ts +0 -31
- package/dist/form/Input.svelte +0 -326
- package/dist/form/Input.svelte.d.ts +0 -117
- package/dist/form/InputLength.svelte +0 -32
- package/dist/form/InputLength.svelte.d.ts +0 -20
- package/dist/form/Label.svelte +0 -44
- package/dist/form/Label.svelte.d.ts +0 -25
- package/dist/form/LogoUpload.svelte +0 -100
- package/dist/form/LogoUpload.svelte.d.ts +0 -29
- package/dist/form/Select.svelte +0 -136
- package/dist/form/Select.svelte.d.ts +0 -70
- package/dist/form/Textarea.svelte +0 -163
- package/dist/form/Textarea.svelte.d.ts +0 -108
- package/dist/form/Toggle.svelte +0 -2
- package/dist/form/Toggle.svelte.d.ts +0 -15
- package/dist/form/client.svelte.d.ts +0 -44
- package/dist/form/client.svelte.js +0 -98
- package/dist/form/form.d.ts +0 -54
- package/dist/form/form.js +0 -340
- package/dist/form/index.d.ts +0 -18
- package/dist/form/index.js +0 -18
- package/dist/form/types.d.ts +0 -62
- package/dist/form/types.js +0 -1
- package/dist/icons/IconAlert.svelte +0 -3
- package/dist/icons/IconAlert.svelte.d.ts +0 -23
- package/dist/icons/IconCopy.svelte +0 -3
- package/dist/icons/IconCopy.svelte.d.ts +0 -23
- package/dist/icons/IconDone.svelte +0 -3
- package/dist/icons/IconDone.svelte.d.ts +0 -23
- package/dist/icons/IconError.svelte +0 -3
- package/dist/icons/IconError.svelte.d.ts +0 -23
- package/dist/icons/IconHelp.svelte +0 -3
- package/dist/icons/IconHelp.svelte.d.ts +0 -23
- package/dist/icons/IconHide.svelte +0 -3
- package/dist/icons/IconHide.svelte.d.ts +0 -23
- package/dist/icons/IconInfo.svelte +0 -3
- package/dist/icons/IconInfo.svelte.d.ts +0 -23
- package/dist/icons/IconLink.svelte +0 -3
- package/dist/icons/IconLink.svelte.d.ts +0 -23
- package/dist/icons/IconMenuBurger.svelte +0 -3
- package/dist/icons/IconMenuBurger.svelte.d.ts +0 -23
- package/dist/icons/IconMenuDots.svelte +0 -3
- package/dist/icons/IconMenuDots.svelte.d.ts +0 -23
- package/dist/icons/IconSearch.svelte +0 -3
- package/dist/icons/IconSearch.svelte.d.ts +0 -23
- package/dist/icons/IconShow.svelte +0 -3
- package/dist/icons/IconShow.svelte.d.ts +0 -23
- package/dist/icons/IconSuccess.svelte +0 -3
- package/dist/icons/IconSuccess.svelte.d.ts +0 -23
- package/dist/icons/IconWarning.svelte +0 -3
- package/dist/icons/IconWarning.svelte.d.ts +0 -23
- package/dist/icons/index.d.ts +0 -14
- package/dist/icons/index.js +0 -14
- package/dist/layout/Layout.svelte +0 -47
- package/dist/layout/Layout.svelte.d.ts +0 -22
- package/dist/layout/LayoutFooter.svelte +0 -21
- package/dist/layout/LayoutFooter.svelte.d.ts +0 -18
- package/dist/layout/LayoutGrid.svelte +0 -51
- package/dist/layout/LayoutGrid.svelte.d.ts +0 -27
- package/dist/layout/LayoutHeader.svelte +0 -97
- package/dist/layout/LayoutHeader.svelte.d.ts +0 -34
- package/dist/layout/LayoutSideMenu.svelte +0 -55
- package/dist/layout/LayoutSideMenu.svelte.d.ts +0 -21
- package/dist/layout/LayoutTypes.d.ts +0 -15
- package/dist/layout/LayoutTypes.js +0 -9
- package/dist/layout/Overlay.svelte +0 -20
- package/dist/layout/Overlay.svelte.d.ts +0 -25
- package/dist/layout/OverlayContainer.svelte +0 -28
- package/dist/layout/OverlayContainer.svelte.d.ts +0 -15
- package/dist/layout/OverlayLayer.svelte +0 -140
- package/dist/layout/OverlayLayer.svelte.d.ts +0 -19
- package/dist/layout/PageContent.svelte +0 -82
- package/dist/layout/PageContent.svelte.d.ts +0 -25
- package/dist/layout/Theme.svelte +0 -243
- package/dist/layout/Theme.svelte.d.ts +0 -19
- package/dist/layout/UIContent.svelte +0 -15
- package/dist/layout/UIContent.svelte.d.ts +0 -18
- package/dist/layout/index.d.ts +0 -11
- package/dist/layout/index.js +0 -11
- package/dist/layout/overlays.svelte.d.ts +0 -34
- package/dist/layout/overlays.svelte.js +0 -44
- package/dist/nav/Breadcrumb.svelte +0 -82
- package/dist/nav/Breadcrumb.svelte.d.ts +0 -28
- package/dist/nav/Menu.svelte +0 -170
- package/dist/nav/Menu.svelte.d.ts +0 -27
- package/dist/nav/MenuItem.svelte +0 -147
- package/dist/nav/MenuItem.svelte.d.ts +0 -22
- package/dist/nav/MenuTypes.d.ts +0 -58
- package/dist/nav/MenuTypes.js +0 -1
- package/dist/nav/NavMenu.svelte +0 -181
- package/dist/nav/NavMenu.svelte.d.ts +0 -19
- package/dist/nav/TabbedContent.svelte +0 -43
- package/dist/nav/TabbedContent.svelte.d.ts +0 -23
- package/dist/nav/Tabs.svelte +0 -158
- package/dist/nav/Tabs.svelte.d.ts +0 -25
- package/dist/nav/index.d.ts +0 -7
- package/dist/nav/index.js +0 -6
- package/dist/style.css +0 -950
- package/dist/typo/Clamp.svelte +0 -25
- package/dist/typo/Clamp.svelte.d.ts +0 -24
- package/dist/typo/H.svelte +0 -52
- package/dist/typo/H.svelte.d.ts +0 -28
- package/dist/typo/H1.svelte +0 -14
- package/dist/typo/H1.svelte.d.ts +0 -26
- package/dist/typo/H2.svelte +0 -14
- package/dist/typo/H2.svelte.d.ts +0 -26
- package/dist/typo/H3.svelte +0 -14
- package/dist/typo/H3.svelte.d.ts +0 -26
- package/dist/typo/H4.svelte +0 -14
- package/dist/typo/H4.svelte.d.ts +0 -26
- package/dist/typo/H5.svelte +0 -14
- package/dist/typo/H5.svelte.d.ts +0 -26
- package/dist/typo/H6.svelte +0 -14
- package/dist/typo/H6.svelte.d.ts +0 -26
- package/dist/typo/P.svelte +0 -34
- package/dist/typo/P.svelte.d.ts +0 -26
- package/dist/typo/index.d.ts +0 -9
- package/dist/typo/index.js +0 -9
- package/dist/utils/StringOrComponent.svelte +0 -14
- package/dist/utils/StringOrComponent.svelte.d.ts +0 -19
- package/dist/utils/StringOrSnippet.svelte +0 -11
- package/dist/utils/StringOrSnippet.svelte.d.ts +0 -19
- package/dist/utils/attr.d.ts +0 -5
- package/dist/utils/attr.js +0 -21
- package/dist/utils/color.d.ts +0 -51
- package/dist/utils/color.js +0 -97
- package/dist/utils/defaults.d.ts +0 -4
- package/dist/utils/defaults.js +0 -1
- package/dist/utils/dom.d.ts +0 -15
- package/dist/utils/dom.js +0 -74
- package/dist/utils/hooks.server.d.ts +0 -2
- package/dist/utils/hooks.server.js +0 -16
- package/dist/utils/id.d.ts +0 -1
- package/dist/utils/id.js +0 -3
- package/dist/utils/index.d.ts +0 -9
- package/dist/utils/index.js +0 -6
- package/dist/utils/isSnippet.d.ts +0 -3
- package/dist/utils/isSnippet.js +0 -11
- package/dist/utils/keyboard.svelte.d.ts +0 -22
- package/dist/utils/keyboard.svelte.js +0 -161
- /package/dist/{utils → util}/transitions.d.ts +0 -0
- /package/dist/{utils → util}/transitions.js +0 -0
@@ -1,163 +0,0 @@
|
|
1
|
-
<script lang="ts">import { getContext, onMount } from "svelte";
|
2
|
-
import { createId } from "../utils/id.js";
|
3
|
-
import { IconCopy, IconDone, IconShow } from "../icons/index.js";
|
4
|
-
import { Tooltip, IconButton } from "../display/index.js";
|
5
|
-
import { FieldContent, fieldChange, fieldKeydown, ignoreKeys, getFromObjWithStringPath } from "../form/index.js";
|
6
|
-
import { ZodType } from "zod";
|
7
|
-
let {
|
8
|
-
autofocus,
|
9
|
-
autocapitalize,
|
10
|
-
autocomplete,
|
11
|
-
autocorrect,
|
12
|
-
autoresize,
|
13
|
-
checked,
|
14
|
-
contained,
|
15
|
-
copyable,
|
16
|
-
defaultValue,
|
17
|
-
dirname,
|
18
|
-
disabled,
|
19
|
-
enterkeyhint,
|
20
|
-
help,
|
21
|
-
id = $bindable(createId()),
|
22
|
-
inputmode,
|
23
|
-
label,
|
24
|
-
labelTip,
|
25
|
-
list,
|
26
|
-
maxlength,
|
27
|
-
minlength,
|
28
|
-
name,
|
29
|
-
pattern,
|
30
|
-
placeholder,
|
31
|
-
suffix,
|
32
|
-
onblur,
|
33
|
-
onchange,
|
34
|
-
onclick,
|
35
|
-
onfocus,
|
36
|
-
onkeydown,
|
37
|
-
onkeyup,
|
38
|
-
onkeypress,
|
39
|
-
prefix,
|
40
|
-
readonly,
|
41
|
-
required,
|
42
|
-
resize = true,
|
43
|
-
shape = "rounded",
|
44
|
-
step,
|
45
|
-
style,
|
46
|
-
tabindex,
|
47
|
-
title,
|
48
|
-
value = $bindable(),
|
49
|
-
...rest
|
50
|
-
} = $props();
|
51
|
-
let el = $state();
|
52
|
-
let copyTitle = $state("Copy");
|
53
|
-
let viewTitle = $state("Show");
|
54
|
-
let copyTooltipOpen = $state(false);
|
55
|
-
let copyBtnIcon = $state(IconCopy);
|
56
|
-
let viewBtnIcon = $state(IconShow);
|
57
|
-
let resizeClass = $derived(resize === true ? "resize" : resize === false ? "" : resize);
|
58
|
-
const form = getContext("form");
|
59
|
-
const field = $derived(form?.fields[name]);
|
60
|
-
const issue = $derived(form?.issues?.find((issue2) => issue2.name === name));
|
61
|
-
const validator = getContext("form.validators")?.[name];
|
62
|
-
const data = form?.data;
|
63
|
-
const originalData = form?.originalData;
|
64
|
-
if (!value) value = form ? getFromObjWithStringPath(Object.assign(originalData ?? {}, data ?? {}), name) || form?.fields?.[name]?.defaultValue : "";
|
65
|
-
function copy(e) {
|
66
|
-
e.preventDefault();
|
67
|
-
if (!el) return;
|
68
|
-
if (navigator.clipboard) {
|
69
|
-
navigator.clipboard.writeText(value);
|
70
|
-
} else {
|
71
|
-
el.focus();
|
72
|
-
el.select();
|
73
|
-
document.execCommand("copy");
|
74
|
-
}
|
75
|
-
copyBtnIcon = IconDone;
|
76
|
-
copyTitle = "Copied!";
|
77
|
-
copyTooltipOpen = true;
|
78
|
-
setTimeout(() => {
|
79
|
-
copyBtnIcon = IconCopy;
|
80
|
-
copyTitle = "Copy";
|
81
|
-
copyTooltipOpen = false;
|
82
|
-
}, 1500);
|
83
|
-
el.focus();
|
84
|
-
}
|
85
|
-
function onresize() {
|
86
|
-
if (!autoresize || !el || !value) return;
|
87
|
-
setTimeout(() => {
|
88
|
-
el.style.height = "auto";
|
89
|
-
el.style.height = `${el.scrollHeight + 2}px`;
|
90
|
-
}, 0);
|
91
|
-
}
|
92
|
-
onMount(() => {
|
93
|
-
if (value) fieldChange(form, name, () => el)({});
|
94
|
-
setTimeout(() => {
|
95
|
-
onresize();
|
96
|
-
}, 5);
|
97
|
-
});
|
98
|
-
</script>
|
99
|
-
|
100
|
-
<svelte:window onresize={onresize} />
|
101
|
-
|
102
|
-
<FieldContent
|
103
|
-
{id}
|
104
|
-
{label}
|
105
|
-
{labelTip}
|
106
|
-
{field}
|
107
|
-
{issue}
|
108
|
-
{help}
|
109
|
-
{suffix}
|
110
|
-
{required}
|
111
|
-
>
|
112
|
-
<textarea
|
113
|
-
class="{resizeClass}"
|
114
|
-
bind:this={el}
|
115
|
-
{autofocus}
|
116
|
-
autocapitalize={typeof autocapitalize === 'string' ? autocapitalize : (typeof autocapitalize === 'boolean' ? (autocapitalize ? 'on' : 'off') : undefined)}
|
117
|
-
{autocomplete}
|
118
|
-
autocorrect={typeof autocorrect === 'boolean' ? (autocorrect ? 'on' : 'off') : undefined}
|
119
|
-
{dirname}
|
120
|
-
{disabled}
|
121
|
-
{enterkeyhint}
|
122
|
-
{id}
|
123
|
-
maxlength={maxlength ? maxlength : field?.maxlength}
|
124
|
-
minlength={minlength ? minlength : field?.minlength}
|
125
|
-
{name}
|
126
|
-
{onblur}
|
127
|
-
{onclick}
|
128
|
-
onchange={fieldChange(form, name, () => el, validator, onchange)}
|
129
|
-
{onfocus}
|
130
|
-
onkeydown={() => { onresize(); return fieldKeydown(form, name, () => el, validator, onkeydown) }}
|
131
|
-
{onkeyup}
|
132
|
-
{onkeypress}
|
133
|
-
{placeholder}
|
134
|
-
{readonly}
|
135
|
-
required={required || field?.required}
|
136
|
-
{tabindex}
|
137
|
-
{title}
|
138
|
-
bind:value={value}
|
139
|
-
{style}
|
140
|
-
{...rest}
|
141
|
-
></textarea>
|
142
|
-
|
143
|
-
{#if copyable}
|
144
|
-
<Tooltip tip={copyTitle} open={copyTooltipOpen}>
|
145
|
-
<IconButton icon={copyBtnIcon} onclick={copy} disabled={copyTooltipOpen} />
|
146
|
-
</Tooltip>
|
147
|
-
{/if}
|
148
|
-
</FieldContent>
|
149
|
-
|
150
|
-
<style>
|
151
|
-
textarea {
|
152
|
-
resize: none;
|
153
|
-
}
|
154
|
-
textarea.resize {
|
155
|
-
resize: both;
|
156
|
-
}
|
157
|
-
textarea.resize.horizontal {
|
158
|
-
resize: horizontal;
|
159
|
-
}
|
160
|
-
textarea.resize.vertical {
|
161
|
-
resize: vertical;
|
162
|
-
}
|
163
|
-
</style>
|
@@ -1,108 +0,0 @@
|
|
1
|
-
import { type Snippet } from "svelte";
|
2
|
-
import type { Autocomplete } from "../form/types.js";
|
3
|
-
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
4
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
5
|
-
$$bindings?: Bindings;
|
6
|
-
} & Exports;
|
7
|
-
(internal: unknown, props: Props & {
|
8
|
-
$$events?: Events;
|
9
|
-
$$slots?: Slots;
|
10
|
-
}): Exports;
|
11
|
-
z_$$bindings?: Bindings;
|
12
|
-
}
|
13
|
-
declare const Textarea: $$__sveltets_2_IsomorphicComponent<{
|
14
|
-
/** Whether the input should be autofocused. */
|
15
|
-
autofocus?: boolean;
|
16
|
-
/** Whether the input should be autocapitalized. */
|
17
|
-
autocapitalize?: boolean | "off" | "none" | "on" | "sentences" | "words" | "characters";
|
18
|
-
/** Specifies whether autocomplete is enabled for the input. */
|
19
|
-
autocomplete?: Autocomplete;
|
20
|
-
/** Whether the input should be autocorrected. (Safari only) */
|
21
|
-
autocorrect?: boolean;
|
22
|
-
/** Whether the input should resize automatically. */
|
23
|
-
autoresize?: boolean;
|
24
|
-
/** A hint to the browser for which capture method to use. */
|
25
|
-
capture?: "user" | "environment";
|
26
|
-
/** Whether the input should be checked. */
|
27
|
-
checked?: boolean;
|
28
|
-
/** Whether the input should be contained. */
|
29
|
-
contained?: boolean;
|
30
|
-
/** Whether the input should be copyable. */
|
31
|
-
copyable?: boolean;
|
32
|
-
/** The default value of the input element. */
|
33
|
-
defaultValue?: string;
|
34
|
-
/** Form field name for the directionality of the element's text content during form submission */
|
35
|
-
dirname?: string;
|
36
|
-
/** Whether the input should be disabled. */
|
37
|
-
disabled?: boolean;
|
38
|
-
/** A hint to the browser for which enter key to display for the input. */
|
39
|
-
enterkeyhint?: "enter" | "done" | "go" | "next" | "previous" | "search" | "send";
|
40
|
-
/** The height of the input element. Valid for image inputs. */
|
41
|
-
height?: number;
|
42
|
-
/** Help text to display below the input. */
|
43
|
-
help?: string | Snippet;
|
44
|
-
/** A random id is generated if not provided. */
|
45
|
-
id?: string;
|
46
|
-
/** Whether the input should be indeterminate. */
|
47
|
-
indeterminate?: boolean;
|
48
|
-
/** A hint to the browser for which keyboard to display. This is only used for type="text" inputs. Strongly consider using type="email" or type="url" etc. instead */
|
49
|
-
inputmode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search";
|
50
|
-
/** The label for the input */
|
51
|
-
label?: string | Snippet;
|
52
|
-
/** Context tooltip for a label. Renders with a questionmark using ContextTip. */
|
53
|
-
labelTip?: string | Snippet;
|
54
|
-
/** The id of a datalist element that contains pre-defined options for the input element. */
|
55
|
-
list?: string;
|
56
|
-
/** The maximum number of characters (as UTF-16 code units) the user can enter into the input. Valid for text, search, url, tel, email, and password. */
|
57
|
-
maxlength?: number;
|
58
|
-
/** The minimum number of characters (as UTF-16 code units) the user can enter into the input. Valid for text, search, url, tel, email, and password. */
|
59
|
-
minlength?: number;
|
60
|
-
/** The name of the input element. */
|
61
|
-
name: string;
|
62
|
-
/** The onblur event handler */
|
63
|
-
onblur?: (e: FocusEvent) => void;
|
64
|
-
/** Onchange event handler */
|
65
|
-
onchange?: (e: Event) => void;
|
66
|
-
/** Onclick event handler */
|
67
|
-
onclick?: (e: MouseEvent) => void;
|
68
|
-
/** Onfocus event handler */
|
69
|
-
onfocus?: (e: FocusEvent) => void;
|
70
|
-
/** Keyup event handler */
|
71
|
-
onkeyup?: (e: KeyboardEvent) => void;
|
72
|
-
/** Keydown event handler */
|
73
|
-
onkeydown?: (e: KeyboardEvent) => void;
|
74
|
-
/** Keypress event handler */
|
75
|
-
onkeypress?: (e: KeyboardEvent) => void;
|
76
|
-
/** A regular expression that the input's value is checked against. Valid for text, search, url, tel, email, and password. */
|
77
|
-
pattern?: string;
|
78
|
-
/** Placeholder text to display when the input is empty. */
|
79
|
-
placeholder?: string;
|
80
|
-
/** Suffix content, to display after the input. */
|
81
|
-
suffix?: string | Snippet;
|
82
|
-
/** Prefix content, to display before the input. */
|
83
|
-
prefix?: string | Snippet;
|
84
|
-
/** Whether the input should be read-only. */
|
85
|
-
readonly?: boolean;
|
86
|
-
/** Whether the input should be required. */
|
87
|
-
required?: boolean;
|
88
|
-
/** Whether the textarea is resizable. */
|
89
|
-
resize?: boolean | "both" | "horizontal" | "vertical" | "none";
|
90
|
-
/** The shape of the input element. */
|
91
|
-
shape?: "default" | "rounded" | "pill" | "circle";
|
92
|
-
/** Spellcheck the input. */
|
93
|
-
spellcheck?: boolean;
|
94
|
-
/** A number that specifies the granularity that the value must adhere to. Valid for date, month, week, time, datetime-local, number, and range. */
|
95
|
-
step?: number;
|
96
|
-
/** Inline styles to apply to the input element. */
|
97
|
-
style?: string;
|
98
|
-
/** An integer attribute indicating if the element can take input focus (is focusable), if it should participate to sequential keyboard navigation. */
|
99
|
-
tabindex?: number;
|
100
|
-
/** A string that defines the title of the input element. */
|
101
|
-
title?: string;
|
102
|
-
/** The value of the input element. */
|
103
|
-
value?: string | null;
|
104
|
-
}, {
|
105
|
-
[evt: string]: CustomEvent<any>;
|
106
|
-
}, {}, {}, "value" | "id">;
|
107
|
-
type Textarea = InstanceType<typeof Textarea>;
|
108
|
-
export default Textarea;
|
package/dist/form/Toggle.svelte
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
2
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
3
|
-
$$bindings?: Bindings;
|
4
|
-
} & Exports;
|
5
|
-
(internal: unknown, props: {
|
6
|
-
$$events?: Events;
|
7
|
-
$$slots?: Slots;
|
8
|
-
}): Exports;
|
9
|
-
z_$$bindings?: Bindings;
|
10
|
-
}
|
11
|
-
declare const Toggle: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
12
|
-
[evt: string]: CustomEvent<any>;
|
13
|
-
}, {}, {}, string>;
|
14
|
-
type Toggle = InstanceType<typeof Toggle>;
|
15
|
-
export default Toggle;
|
@@ -1,44 +0,0 @@
|
|
1
|
-
import type { ZodType } from "zod";
|
2
|
-
import type { LutraForm } from "./types.js";
|
3
|
-
/**
|
4
|
-
* Use a form in a Svelte component.
|
5
|
-
* @param {Form} form - The form to use.
|
6
|
-
* @returns
|
7
|
-
*/
|
8
|
-
export declare function useForm(form: LutraForm<any>): LutraForm<any> & {
|
9
|
-
originalData: any;
|
10
|
-
data: any;
|
11
|
-
state: string;
|
12
|
-
};
|
13
|
-
/**
|
14
|
-
* Validate a single field.
|
15
|
-
* @param {Form} form - The form to validate.
|
16
|
-
* @param {string} name - The name of the field to validate.
|
17
|
-
* @param {HTMLInputElement | HTMLSelectElement} el - The element to validate.
|
18
|
-
* @param {ZodType} validator - The validator to use.
|
19
|
-
*/
|
20
|
-
export declare function fieldValidate(form: LutraForm<any>, name: string, el?: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement, validator?: ZodType<any, any>): void;
|
21
|
-
/**
|
22
|
-
* Keydown event handler for a field.
|
23
|
-
* @param {KeyboardEvent} e - The event.
|
24
|
-
* @param {Form} form - The form to use.
|
25
|
-
* @param {string} name - The name of the field.
|
26
|
-
* @param {HTMLInputElement | HTMLSelectElement} el - The element to validate.
|
27
|
-
* @param {ZodType} validator - The validator to use.
|
28
|
-
* @param {(e: KeyboardEvent) => void} onkeydown - The onkeydown event handler.
|
29
|
-
*/
|
30
|
-
export declare function fieldKeydown(form: LutraForm<any>, name: string, el: () => HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | undefined, validator?: ZodType<any, any>, onkeydown?: (e: KeyboardEvent) => void): (e: KeyboardEvent) => Promise<void>;
|
31
|
-
/**
|
32
|
-
* Change event handler for a field.
|
33
|
-
* @param {Event} e - The event.
|
34
|
-
* @param {Form} form - The form to use.
|
35
|
-
* @param {string} name - The name of the field.
|
36
|
-
* @param {HTMLInputElement | HTMLSelectElement} el - The element to validate.
|
37
|
-
* @param {ZodType} validator - The validator to use.
|
38
|
-
* @param {(e: Event) => void} onchange - The onchange event handler.
|
39
|
-
*/
|
40
|
-
export declare function fieldChange(form: LutraForm<any>, name: string, el: () => HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | undefined, validator?: ZodType<any, any>, onchange?: (e: Event) => void): (e: Event) => Promise<void>;
|
41
|
-
/**
|
42
|
-
* Keys that should be ignored when marking a field as tainted.
|
43
|
-
*/
|
44
|
-
export declare const ignoreKeys: string[];
|
@@ -1,98 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Use a form in a Svelte component.
|
3
|
-
* @param {Form} form - The form to use.
|
4
|
-
* @returns
|
5
|
-
*/
|
6
|
-
export function useForm(form) {
|
7
|
-
let _form = Object.assign(form, {
|
8
|
-
originalData: JSON.parse(JSON.stringify(form.data ?? {})),
|
9
|
-
data: form.data ?? {},
|
10
|
-
state: 'idle',
|
11
|
-
});
|
12
|
-
// Have to declare a variable separately to use in the return object
|
13
|
-
// as the compiler is looking for a declaration.
|
14
|
-
let __form = $state(_form);
|
15
|
-
return __form;
|
16
|
-
}
|
17
|
-
/**
|
18
|
-
* Validate a single field.
|
19
|
-
* @param {Form} form - The form to validate.
|
20
|
-
* @param {string} name - The name of the field to validate.
|
21
|
-
* @param {HTMLInputElement | HTMLSelectElement} el - The element to validate.
|
22
|
-
* @param {ZodType} validator - The validator to use.
|
23
|
-
*/
|
24
|
-
export function fieldValidate(form, name, el, validator) {
|
25
|
-
if (!validator)
|
26
|
-
return;
|
27
|
-
const result = validator.safeParse(getTypedValue(el));
|
28
|
-
if (result.success) {
|
29
|
-
form.issues = (form.issues || []).filter((issue) => issue.name !== name);
|
30
|
-
form.valid = form.issues.length === 0;
|
31
|
-
}
|
32
|
-
else {
|
33
|
-
form.valid = false;
|
34
|
-
form.issues = (form.issues || []).filter((issue) => issue.name !== name);
|
35
|
-
form.issues?.push({
|
36
|
-
name, // Include the path of the field.
|
37
|
-
...((result.error?.issues?.length ? result.error.issues : [])?.[0]), // Include the first issue as we only care about one at a time.
|
38
|
-
});
|
39
|
-
}
|
40
|
-
}
|
41
|
-
/**
|
42
|
-
* Keydown event handler for a field.
|
43
|
-
* @param {KeyboardEvent} e - The event.
|
44
|
-
* @param {Form} form - The form to use.
|
45
|
-
* @param {string} name - The name of the field.
|
46
|
-
* @param {HTMLInputElement | HTMLSelectElement} el - The element to validate.
|
47
|
-
* @param {ZodType} validator - The validator to use.
|
48
|
-
* @param {(e: KeyboardEvent) => void} onkeydown - The onkeydown event handler.
|
49
|
-
*/
|
50
|
-
export function fieldKeydown(form, name, el, validator, onkeydown) {
|
51
|
-
return async function (e) {
|
52
|
-
setTimeout(() => {
|
53
|
-
if (form) {
|
54
|
-
const possibleKey = e?.key;
|
55
|
-
if (ignoreKeys.includes(possibleKey))
|
56
|
-
return;
|
57
|
-
form.data[name] = el()?.value || '';
|
58
|
-
fieldValidate(form, name, el(), validator);
|
59
|
-
}
|
60
|
-
}, 0); // Wait for the key to be updated in the input.
|
61
|
-
if (onkeydown)
|
62
|
-
return onkeydown(e);
|
63
|
-
};
|
64
|
-
}
|
65
|
-
function getTypedValue(el) {
|
66
|
-
if (el?.type === 'number')
|
67
|
-
return parseFloat(el.value);
|
68
|
-
if (el?.type === 'checkbox')
|
69
|
-
return el.checked;
|
70
|
-
return el?.value;
|
71
|
-
}
|
72
|
-
/**
|
73
|
-
* Change event handler for a field.
|
74
|
-
* @param {Event} e - The event.
|
75
|
-
* @param {Form} form - The form to use.
|
76
|
-
* @param {string} name - The name of the field.
|
77
|
-
* @param {HTMLInputElement | HTMLSelectElement} el - The element to validate.
|
78
|
-
* @param {ZodType} validator - The validator to use.
|
79
|
-
* @param {(e: Event) => void} onchange - The onchange event handler.
|
80
|
-
*/
|
81
|
-
export function fieldChange(form, name, el, validator, onchange) {
|
82
|
-
return async function (e) {
|
83
|
-
if (form && form.fields[name]) {
|
84
|
-
console.log('fieldChange', name, el()?.value, form.data[name]);
|
85
|
-
// Update the form data with the new value.
|
86
|
-
form.data[name] = getTypedValue(el());
|
87
|
-
// if the value is the same as the original value, then the field is not tainted
|
88
|
-
form.fields[name].tainted = form.data[name] !== form.originalData[name];
|
89
|
-
fieldValidate(form, name, el(), validator);
|
90
|
-
}
|
91
|
-
if (onchange)
|
92
|
-
return onchange(e);
|
93
|
-
};
|
94
|
-
}
|
95
|
-
/**
|
96
|
-
* Keys that should be ignored when marking a field as tainted.
|
97
|
-
*/
|
98
|
-
export const ignoreKeys = ['Tab', 'Shift', 'Control', 'Alt', 'Meta', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'PageUp', 'PageDown', 'Escape', 'CapsLock', 'NumLock', 'ScrollLock', 'Pause', 'ContextMenu', 'PrintScreen', 'Help', 'Clear', 'OS', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F12'];
|
package/dist/form/form.d.ts
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
import { Bodyguard, type BodyguardFormConfig, type BodyguardResult, type GenericIssue, type JSONLike } from "@auth70/bodyguard";
|
2
|
-
import type { RequestEvent } from "@sveltejs/kit";
|
3
|
-
import type { ZodType, infer as Infer } from "zod";
|
4
|
-
import type { LutraForm, FormField, FormIssue, ZodTypes } from "./types.js";
|
5
|
-
export declare const bodyguard: Bodyguard;
|
6
|
-
/**
|
7
|
-
* Get fields from a Zod schema.
|
8
|
-
* @param {ZodObject<any>} schema - The schema to get fields from.
|
9
|
-
* @returns {Record<string, any>} - The fields from the schema.
|
10
|
-
*/
|
11
|
-
export declare function getFieldsFromSchema(schema: ZodType, data?: BodyguardResult<any>, parents?: string[]): Record<string, FormField>;
|
12
|
-
/**
|
13
|
-
* Server page load call. Optionally with a default object to populate the form with from locals.
|
14
|
-
* @param {ZodType} schema - The schema to parse the form with.
|
15
|
-
* @param {RequestEvent} event - The event to load the (possible) form from.
|
16
|
-
* @param {JSONLike | string} objOrName - The default object to populate the form with, or the name of the object in locals.
|
17
|
-
* @param {JSONLike} obj - The default object to populate the form with.
|
18
|
-
* @returns {Promise<Form<Z>>} - The form to use.
|
19
|
-
*/
|
20
|
-
export declare function loadForm<Z extends ZodTypes>(schema: Z, event: RequestEvent, objOrName?: JSONLike | string, obj?: JSONLike): Promise<LutraForm<Z>>;
|
21
|
-
/**
|
22
|
-
* Parse zod issues into form issues (with a path string).
|
23
|
-
* @param {ZodIssue[]} issues - The issues to parse.
|
24
|
-
* @returns {FormIssue[]} - The parsed issues.
|
25
|
-
*/
|
26
|
-
export declare function parseFormIssues(issues: GenericIssue[]): FormIssue[];
|
27
|
-
/**
|
28
|
-
* Parse a form using a schema.
|
29
|
-
* @param {ZodType} schema - The schema to parse the form with.
|
30
|
-
* @param {Request} request - The request to parse.
|
31
|
-
* @param {BodyguardFormConfig | string} optsOrName - The options for the form validation, or the name of the form in locals.
|
32
|
-
* @param {BodyguardFormConfig} opts - The options for the form validation.
|
33
|
-
* @returns {Promise<{ valid: false } | { valid: true, data: Infer<Z> }>} - The result of the form validation.
|
34
|
-
*/
|
35
|
-
export declare function parseForm<Z extends ZodType>(schema: Z, event: RequestEvent, optsOrName?: BodyguardFormConfig | string, opts?: BodyguardFormConfig): Promise<LutraForm<Z>>;
|
36
|
-
/**
|
37
|
-
* Convert an array path from a Zod issue to a string path for a form field.
|
38
|
-
* @param {(string | number)[]} path - The path to convert.
|
39
|
-
* @returns {string} - The string path.
|
40
|
-
*/
|
41
|
-
export declare function arrayPathToStringPath(path: (string | number)[]): string;
|
42
|
-
/**
|
43
|
-
* Get a value from an object using a string path.
|
44
|
-
* @param {any} obj - The object to get the value from.
|
45
|
-
* @param {string} path - The path to get the value from.
|
46
|
-
* @returns {string | number | Date | boolean | object | undefined} - The value from the object.
|
47
|
-
*/
|
48
|
-
export declare function getFromObjWithStringPath(obj: any, path: string): string | number | Date | boolean | object | undefined;
|
49
|
-
/**
|
50
|
-
* Get individual validators for each field in a form.
|
51
|
-
* @param {Form} form - The form to get the validators from.
|
52
|
-
* @returns {Record<keyof Infer<T>, (value: any) => boolean>} - The validators for each field.
|
53
|
-
*/
|
54
|
-
export declare function getIndividualValidators<T extends ZodTypes>(form?: LutraForm<T>): Record<keyof Infer<T>, (value: any) => boolean>;
|