simplesvelte 2.4.12 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +214 -214
- package/dist/Grid.svelte +44 -5
- package/dist/Grid.svelte.d.ts +9 -2
- package/dist/Input.svelte +145 -145
- package/dist/Label.svelte +43 -43
- package/dist/Modal.svelte +39 -39
- package/dist/Select.svelte +696 -694
- package/dist/Select.svelte.d.ts +1 -0
- package/dist/ag-grid-refactored.d.ts +70 -0
- package/dist/ag-grid-refactored.js +95 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/styles.css +15 -15
- package/package.json +69 -69
package/dist/Input.svelte
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { SvelteDate } from 'svelte/reactivity'
|
|
3
|
-
import Label from './Label.svelte'
|
|
4
|
-
type Props = {
|
|
5
|
-
value?: any
|
|
6
|
-
name?: string
|
|
7
|
-
label?: string
|
|
8
|
-
class?: string
|
|
9
|
-
required?: boolean
|
|
10
|
-
disabled?: boolean
|
|
11
|
-
element?: HTMLElement
|
|
12
|
-
type?:
|
|
13
|
-
| 'text'
|
|
14
|
-
| 'number'
|
|
15
|
-
| 'password'
|
|
16
|
-
| 'email'
|
|
17
|
-
| 'number'
|
|
18
|
-
| 'tel'
|
|
19
|
-
| 'url'
|
|
20
|
-
| 'date'
|
|
21
|
-
| 'datetime-local'
|
|
22
|
-
| 'color'
|
|
23
|
-
| 'file'
|
|
24
|
-
| 'checkbox'
|
|
25
|
-
error?: string
|
|
26
|
-
hideOptional?: boolean
|
|
27
|
-
zodErrors?: {
|
|
28
|
-
expected: string
|
|
29
|
-
code: string
|
|
30
|
-
path: string[]
|
|
31
|
-
message: string
|
|
32
|
-
}[]
|
|
33
|
-
[x: string]: any
|
|
34
|
-
}
|
|
35
|
-
let {
|
|
36
|
-
value = $bindable(),
|
|
37
|
-
element = $bindable(),
|
|
38
|
-
label,
|
|
39
|
-
type = 'text',
|
|
40
|
-
name,
|
|
41
|
-
required,
|
|
42
|
-
disabled,
|
|
43
|
-
class: myClass,
|
|
44
|
-
error,
|
|
45
|
-
hideOptional,
|
|
46
|
-
zodErrors,
|
|
47
|
-
...rest
|
|
48
|
-
}: Props = $props()
|
|
49
|
-
function getValue() {
|
|
50
|
-
if (type == 'date') {
|
|
51
|
-
if (!value) return ''
|
|
52
|
-
const dateString = new Date(value).toISOString().split('T')[0]
|
|
53
|
-
return dateString
|
|
54
|
-
} else if (type == 'datetime-local') {
|
|
55
|
-
if (!value) return ''
|
|
56
|
-
const date = new Date(value)
|
|
57
|
-
const dateString = new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().slice(0, -1)
|
|
58
|
-
return dateString
|
|
59
|
-
}
|
|
60
|
-
return value ?? ''
|
|
61
|
-
}
|
|
62
|
-
function setValue(newValue: any) {
|
|
63
|
-
if (type == 'number') {
|
|
64
|
-
if (isNaN(Number(newValue))) {
|
|
65
|
-
value = null
|
|
66
|
-
} else {
|
|
67
|
-
value = Number(newValue)
|
|
68
|
-
}
|
|
69
|
-
} else if (type == 'date') {
|
|
70
|
-
const date = new SvelteDate(newValue)
|
|
71
|
-
if (isNaN(date.getTime())) {
|
|
72
|
-
value = null
|
|
73
|
-
} else {
|
|
74
|
-
date.setUTCHours(0, 0, 0, 0)
|
|
75
|
-
value = date
|
|
76
|
-
}
|
|
77
|
-
} else if (type == 'datetime-local') {
|
|
78
|
-
const date = new SvelteDate(newValue)
|
|
79
|
-
if (isNaN(date.getTime())) {
|
|
80
|
-
value = null
|
|
81
|
-
} else {
|
|
82
|
-
date.setSeconds(0, 0)
|
|
83
|
-
value = date
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
value = newValue
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// File input handlers - FileList is readonly
|
|
91
|
-
function getFiles() {
|
|
92
|
-
return value
|
|
93
|
-
}
|
|
94
|
-
function setFiles(fileList: FileList | null) {
|
|
95
|
-
// FileList is readonly, so we just set it directly
|
|
96
|
-
value = fileList
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let inputClass = $derived.by(() => {
|
|
100
|
-
if (type == 'file') return 'file-input w-full'
|
|
101
|
-
if (type == 'checkbox') return 'checkbox checkbox-lg'
|
|
102
|
-
return 'input w-full'
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
let showOptional = $derived.by(() => {
|
|
106
|
-
if (hideOptional) return false
|
|
107
|
-
return !required && !disabled && type != 'checkbox'
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
const errorText = $derived.by(() => {
|
|
111
|
-
if (error) return error
|
|
112
|
-
if (!name) return undefined
|
|
113
|
-
if (zodErrors) return zodErrors.find((e) => e.path.includes(name))?.message
|
|
114
|
-
return undefined
|
|
115
|
-
})
|
|
116
|
-
</script>
|
|
117
|
-
|
|
118
|
-
{#if type != 'file'}
|
|
119
|
-
<input type="hidden" {name} value={value ?? ''} />
|
|
120
|
-
{/if}
|
|
121
|
-
|
|
122
|
-
<Label class={myClass} {label} {name} optional={showOptional} {disabled} error={errorText}>
|
|
123
|
-
{#if type == 'checkbox'}
|
|
124
|
-
<input bind:this={element} type="checkbox" {disabled} class={inputClass} {...rest} bind:checked={value} />
|
|
125
|
-
{:else if type == 'file'}
|
|
126
|
-
<input
|
|
127
|
-
bind:this={element}
|
|
128
|
-
{name}
|
|
129
|
-
type="file"
|
|
130
|
-
{disabled}
|
|
131
|
-
{required}
|
|
132
|
-
class={inputClass}
|
|
133
|
-
{...rest}
|
|
134
|
-
bind:files={getFiles, setFiles} />
|
|
135
|
-
{:else}
|
|
136
|
-
<input
|
|
137
|
-
bind:this={element}
|
|
138
|
-
{type}
|
|
139
|
-
{disabled}
|
|
140
|
-
{required}
|
|
141
|
-
class="disabled:text-base-content disabled:!border-base-content/20 {inputClass} "
|
|
142
|
-
{...rest}
|
|
143
|
-
bind:value={getValue, setValue} />
|
|
144
|
-
{/if}
|
|
145
|
-
</Label>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { SvelteDate } from 'svelte/reactivity'
|
|
3
|
+
import Label from './Label.svelte'
|
|
4
|
+
type Props = {
|
|
5
|
+
value?: any
|
|
6
|
+
name?: string
|
|
7
|
+
label?: string
|
|
8
|
+
class?: string
|
|
9
|
+
required?: boolean
|
|
10
|
+
disabled?: boolean
|
|
11
|
+
element?: HTMLElement
|
|
12
|
+
type?:
|
|
13
|
+
| 'text'
|
|
14
|
+
| 'number'
|
|
15
|
+
| 'password'
|
|
16
|
+
| 'email'
|
|
17
|
+
| 'number'
|
|
18
|
+
| 'tel'
|
|
19
|
+
| 'url'
|
|
20
|
+
| 'date'
|
|
21
|
+
| 'datetime-local'
|
|
22
|
+
| 'color'
|
|
23
|
+
| 'file'
|
|
24
|
+
| 'checkbox'
|
|
25
|
+
error?: string
|
|
26
|
+
hideOptional?: boolean
|
|
27
|
+
zodErrors?: {
|
|
28
|
+
expected: string
|
|
29
|
+
code: string
|
|
30
|
+
path: string[]
|
|
31
|
+
message: string
|
|
32
|
+
}[]
|
|
33
|
+
[x: string]: any
|
|
34
|
+
}
|
|
35
|
+
let {
|
|
36
|
+
value = $bindable(),
|
|
37
|
+
element = $bindable(),
|
|
38
|
+
label,
|
|
39
|
+
type = 'text',
|
|
40
|
+
name,
|
|
41
|
+
required,
|
|
42
|
+
disabled,
|
|
43
|
+
class: myClass,
|
|
44
|
+
error,
|
|
45
|
+
hideOptional,
|
|
46
|
+
zodErrors,
|
|
47
|
+
...rest
|
|
48
|
+
}: Props = $props()
|
|
49
|
+
function getValue() {
|
|
50
|
+
if (type == 'date') {
|
|
51
|
+
if (!value) return ''
|
|
52
|
+
const dateString = new Date(value).toISOString().split('T')[0]
|
|
53
|
+
return dateString
|
|
54
|
+
} else if (type == 'datetime-local') {
|
|
55
|
+
if (!value) return ''
|
|
56
|
+
const date = new Date(value)
|
|
57
|
+
const dateString = new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().slice(0, -1)
|
|
58
|
+
return dateString
|
|
59
|
+
}
|
|
60
|
+
return value ?? ''
|
|
61
|
+
}
|
|
62
|
+
function setValue(newValue: any) {
|
|
63
|
+
if (type == 'number') {
|
|
64
|
+
if (isNaN(Number(newValue))) {
|
|
65
|
+
value = null
|
|
66
|
+
} else {
|
|
67
|
+
value = Number(newValue)
|
|
68
|
+
}
|
|
69
|
+
} else if (type == 'date') {
|
|
70
|
+
const date = new SvelteDate(newValue)
|
|
71
|
+
if (isNaN(date.getTime())) {
|
|
72
|
+
value = null
|
|
73
|
+
} else {
|
|
74
|
+
date.setUTCHours(0, 0, 0, 0)
|
|
75
|
+
value = date
|
|
76
|
+
}
|
|
77
|
+
} else if (type == 'datetime-local') {
|
|
78
|
+
const date = new SvelteDate(newValue)
|
|
79
|
+
if (isNaN(date.getTime())) {
|
|
80
|
+
value = null
|
|
81
|
+
} else {
|
|
82
|
+
date.setSeconds(0, 0)
|
|
83
|
+
value = date
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
value = newValue
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// File input handlers - FileList is readonly
|
|
91
|
+
function getFiles() {
|
|
92
|
+
return value
|
|
93
|
+
}
|
|
94
|
+
function setFiles(fileList: FileList | null) {
|
|
95
|
+
// FileList is readonly, so we just set it directly
|
|
96
|
+
value = fileList
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let inputClass = $derived.by(() => {
|
|
100
|
+
if (type == 'file') return 'file-input w-full'
|
|
101
|
+
if (type == 'checkbox') return 'checkbox checkbox-lg'
|
|
102
|
+
return 'input w-full'
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
let showOptional = $derived.by(() => {
|
|
106
|
+
if (hideOptional) return false
|
|
107
|
+
return !required && !disabled && type != 'checkbox'
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
const errorText = $derived.by(() => {
|
|
111
|
+
if (error) return error
|
|
112
|
+
if (!name) return undefined
|
|
113
|
+
if (zodErrors) return zodErrors.find((e) => e.path.includes(name))?.message
|
|
114
|
+
return undefined
|
|
115
|
+
})
|
|
116
|
+
</script>
|
|
117
|
+
|
|
118
|
+
{#if type != 'file'}
|
|
119
|
+
<input type="hidden" {name} value={value ?? ''} />
|
|
120
|
+
{/if}
|
|
121
|
+
|
|
122
|
+
<Label class={myClass} {label} {name} optional={showOptional} {disabled} error={errorText}>
|
|
123
|
+
{#if type == 'checkbox'}
|
|
124
|
+
<input bind:this={element} type="checkbox" {disabled} class={inputClass} {...rest} bind:checked={value} />
|
|
125
|
+
{:else if type == 'file'}
|
|
126
|
+
<input
|
|
127
|
+
bind:this={element}
|
|
128
|
+
{name}
|
|
129
|
+
type="file"
|
|
130
|
+
{disabled}
|
|
131
|
+
{required}
|
|
132
|
+
class={inputClass}
|
|
133
|
+
{...rest}
|
|
134
|
+
bind:files={getFiles, setFiles} />
|
|
135
|
+
{:else}
|
|
136
|
+
<input
|
|
137
|
+
bind:this={element}
|
|
138
|
+
{type}
|
|
139
|
+
{disabled}
|
|
140
|
+
{required}
|
|
141
|
+
class="disabled:text-base-content disabled:!border-base-content/20 {inputClass} "
|
|
142
|
+
{...rest}
|
|
143
|
+
bind:value={getValue, setValue} />
|
|
144
|
+
{/if}
|
|
145
|
+
</Label>
|
package/dist/Label.svelte
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { type Snippet } from 'svelte'
|
|
3
|
-
type Props = {
|
|
4
|
-
class?: string
|
|
5
|
-
labelClass?: string
|
|
6
|
-
label: string | undefined
|
|
7
|
-
name?: string
|
|
8
|
-
optional?: boolean
|
|
9
|
-
disabled?: boolean
|
|
10
|
-
children?: Snippet
|
|
11
|
-
error?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let {
|
|
15
|
-
class: className = '',
|
|
16
|
-
labelClass = '',
|
|
17
|
-
name = '',
|
|
18
|
-
optional = false,
|
|
19
|
-
label,
|
|
20
|
-
disabled,
|
|
21
|
-
children,
|
|
22
|
-
error,
|
|
23
|
-
}: Props = $props()
|
|
24
|
-
</script>
|
|
25
|
-
|
|
26
|
-
{#if label}
|
|
27
|
-
<label class="flex w-full flex-col {className}" for={name}>
|
|
28
|
-
<div class="label mb-1 p-0 text-sm">
|
|
29
|
-
<span class={labelClass}>{label}</span>
|
|
30
|
-
{#if optional && !disabled}
|
|
31
|
-
<span class="label">(Optional)</span>
|
|
32
|
-
{/if}
|
|
33
|
-
</div>
|
|
34
|
-
{@render children?.()}
|
|
35
|
-
{#if error}
|
|
36
|
-
<div>
|
|
37
|
-
<span class="text-xs text-red-500">{error}</span>
|
|
38
|
-
</div>
|
|
39
|
-
{/if}
|
|
40
|
-
</label>
|
|
41
|
-
{:else}
|
|
42
|
-
{@render children?.()}
|
|
43
|
-
{/if}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { type Snippet } from 'svelte'
|
|
3
|
+
type Props = {
|
|
4
|
+
class?: string
|
|
5
|
+
labelClass?: string
|
|
6
|
+
label: string | undefined
|
|
7
|
+
name?: string
|
|
8
|
+
optional?: boolean
|
|
9
|
+
disabled?: boolean
|
|
10
|
+
children?: Snippet
|
|
11
|
+
error?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let {
|
|
15
|
+
class: className = '',
|
|
16
|
+
labelClass = '',
|
|
17
|
+
name = '',
|
|
18
|
+
optional = false,
|
|
19
|
+
label,
|
|
20
|
+
disabled,
|
|
21
|
+
children,
|
|
22
|
+
error,
|
|
23
|
+
}: Props = $props()
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
{#if label}
|
|
27
|
+
<label class="flex w-full flex-col {className}" for={name}>
|
|
28
|
+
<div class="label mb-1 p-0 text-sm">
|
|
29
|
+
<span class={labelClass}>{label}</span>
|
|
30
|
+
{#if optional && !disabled}
|
|
31
|
+
<span class="label">(Optional)</span>
|
|
32
|
+
{/if}
|
|
33
|
+
</div>
|
|
34
|
+
{@render children?.()}
|
|
35
|
+
{#if error}
|
|
36
|
+
<div>
|
|
37
|
+
<span class="text-xs text-red-500">{error}</span>
|
|
38
|
+
</div>
|
|
39
|
+
{/if}
|
|
40
|
+
</label>
|
|
41
|
+
{:else}
|
|
42
|
+
{@render children?.()}
|
|
43
|
+
{/if}
|
package/dist/Modal.svelte
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type { Snippet } from 'svelte'
|
|
3
|
-
|
|
4
|
-
let { open = $bindable(), title, children }: Props = $props()
|
|
5
|
-
|
|
6
|
-
let dialogEl: HTMLDialogElement | undefined = $state()
|
|
7
|
-
interface Props {
|
|
8
|
-
open: boolean
|
|
9
|
-
title: string
|
|
10
|
-
children?: Snippet
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
$effect(() => {
|
|
14
|
-
if (!dialogEl) return
|
|
15
|
-
|
|
16
|
-
if (open) {
|
|
17
|
-
dialogEl.showModal()
|
|
18
|
-
} else {
|
|
19
|
-
dialogEl.close()
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
</script>
|
|
23
|
-
|
|
24
|
-
<dialog bind:this={dialogEl} onclose={() => (open = false)} class="modal modal-middle overflow-auto">
|
|
25
|
-
<div class="modal-box pt-12 md:min-w-[32rem]">
|
|
26
|
-
<form method="dialog">
|
|
27
|
-
<button
|
|
28
|
-
class="btn btn-sm btn-circle btn-ghost absolute top-2 right-2"
|
|
29
|
-
onclick={() => {
|
|
30
|
-
open = false
|
|
31
|
-
}}>✕</button>
|
|
32
|
-
</form>
|
|
33
|
-
<h1 class="absolute top-2 text-lg font-semibold text-red-700 uppercase">{title}</h1>
|
|
34
|
-
|
|
35
|
-
{#if open}
|
|
36
|
-
{@render children?.()}
|
|
37
|
-
{/if}
|
|
38
|
-
</div>
|
|
39
|
-
</dialog>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte'
|
|
3
|
+
|
|
4
|
+
let { open = $bindable(), title, children }: Props = $props()
|
|
5
|
+
|
|
6
|
+
let dialogEl: HTMLDialogElement | undefined = $state()
|
|
7
|
+
interface Props {
|
|
8
|
+
open: boolean
|
|
9
|
+
title: string
|
|
10
|
+
children?: Snippet
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
$effect(() => {
|
|
14
|
+
if (!dialogEl) return
|
|
15
|
+
|
|
16
|
+
if (open) {
|
|
17
|
+
dialogEl.showModal()
|
|
18
|
+
} else {
|
|
19
|
+
dialogEl.close()
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<dialog bind:this={dialogEl} onclose={() => (open = false)} class="modal modal-middle overflow-auto">
|
|
25
|
+
<div class="modal-box pt-12 md:min-w-[32rem]">
|
|
26
|
+
<form method="dialog">
|
|
27
|
+
<button
|
|
28
|
+
class="btn btn-sm btn-circle btn-ghost absolute top-2 right-2"
|
|
29
|
+
onclick={() => {
|
|
30
|
+
open = false
|
|
31
|
+
}}>✕</button>
|
|
32
|
+
</form>
|
|
33
|
+
<h1 class="absolute top-2 text-lg font-semibold text-red-700 uppercase">{title}</h1>
|
|
34
|
+
|
|
35
|
+
{#if open}
|
|
36
|
+
{@render children?.()}
|
|
37
|
+
{/if}
|
|
38
|
+
</div>
|
|
39
|
+
</dialog>
|