@webamoki/web-svelte 0.5.17 → 0.5.19
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/dist/components/form/fields/ChoiceField.svelte +3 -1
- package/dist/components/form/fields/ChoiceMultiField.svelte +4 -3
- package/dist/components/form/fields/ChoiceMultiField.svelte.d.ts +1 -1
- package/dist/components/form/fields/SelectField.svelte +6 -4
- package/dist/components/form/fields/SelectMultiField.svelte +6 -4
- package/dist/components/form/fields/TextFieldNullable.svelte +1 -5
- package/dist/components/form/index.d.ts +9 -9
- package/dist/components/form/index.js +9 -9
- package/dist/components/ui/choice/ChoiceInternal.svelte +9 -1
- package/dist/components/ui/choice/ChoiceInternal.svelte.d.ts +2 -0
- package/dist/utils/search.d.ts +2 -0
- package/dist/utils/search.js +63 -0
- package/package.json +1 -1
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
label,
|
|
22
22
|
description,
|
|
23
23
|
disabled,
|
|
24
|
-
readonly
|
|
24
|
+
readonly,
|
|
25
|
+
buttonContent
|
|
25
26
|
}: Props = $props();
|
|
26
27
|
</script>
|
|
27
28
|
|
|
@@ -33,6 +34,7 @@
|
|
|
33
34
|
{getKey}
|
|
34
35
|
{getLabel}
|
|
35
36
|
{onChange}
|
|
37
|
+
{buttonContent}
|
|
36
38
|
{vertical}
|
|
37
39
|
{disabled}
|
|
38
40
|
{readonly}
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
lang="ts"
|
|
3
3
|
generics="V, K extends string | number | symbol,T extends Record<string, unknown>, U extends FormPath<T>, M"
|
|
4
4
|
>
|
|
5
|
+
import ChoiceMulti, { type ChoiceMultiProps } from '../../ui/choice/ChoiceMulti.svelte';
|
|
5
6
|
import type { FormPath } from 'sveltekit-superforms';
|
|
6
7
|
import FieldWrapper, { type FieldWrapperProps } from '../FieldWrapper.svelte';
|
|
7
|
-
import { type ChoiceMultiProps } from '../../ui/choice/ChoiceMulti.svelte';
|
|
8
|
-
import ChoiceMulti from '../../ui/choice/ChoiceMulti.svelte';
|
|
9
8
|
|
|
10
9
|
type Props = FieldWrapperProps<T, U, M> & ChoiceMultiProps<V, K>;
|
|
11
10
|
let {
|
|
@@ -22,7 +21,8 @@
|
|
|
22
21
|
label,
|
|
23
22
|
description,
|
|
24
23
|
disabled,
|
|
25
|
-
readonly
|
|
24
|
+
readonly,
|
|
25
|
+
buttonContent
|
|
26
26
|
}: Props = $props();
|
|
27
27
|
</script>
|
|
28
28
|
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
{getLabel}
|
|
36
36
|
{onAdd}
|
|
37
37
|
{onRemove}
|
|
38
|
+
{buttonContent}
|
|
38
39
|
{disabled}
|
|
39
40
|
{readonly}
|
|
40
41
|
{vertical}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type ChoiceMultiProps } from '../../ui/choice/ChoiceMulti.svelte';
|
|
1
2
|
import type { FormPath } from 'sveltekit-superforms';
|
|
2
3
|
import { type FieldWrapperProps } from '../FieldWrapper.svelte';
|
|
3
|
-
import { type ChoiceMultiProps } from '../../ui/choice/ChoiceMulti.svelte';
|
|
4
4
|
declare function $$render<V, K extends string | number | symbol, T extends Record<string, unknown>, U extends FormPath<T>, M>(): {
|
|
5
5
|
props: FieldWrapperProps<T, U, M> & ChoiceMultiProps<V, K>;
|
|
6
6
|
exports: {};
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
lang="ts"
|
|
3
3
|
generics="I,V, K extends string | number,T extends Record<string, unknown>, U extends FormPath<T>, M"
|
|
4
4
|
>
|
|
5
|
-
import type { FormPath } from 'sveltekit-superforms';
|
|
6
|
-
import FieldWrapper, { type FieldWrapperProps } from '../FieldWrapper.svelte';
|
|
7
5
|
import {
|
|
8
6
|
Select,
|
|
9
7
|
SelectContent,
|
|
@@ -13,6 +11,8 @@
|
|
|
13
11
|
SelectTrigger
|
|
14
12
|
} from '../../../shadcn/components/ui/select/index.js';
|
|
15
13
|
import { cn } from '../../../shadcn/utils.js';
|
|
14
|
+
import type { FormPath } from 'sveltekit-superforms';
|
|
15
|
+
import FieldWrapper, { type FieldWrapperProps } from '../FieldWrapper.svelte';
|
|
16
16
|
|
|
17
17
|
interface Props extends FieldWrapperProps<T, U, M> {
|
|
18
18
|
value?: V;
|
|
@@ -63,8 +63,10 @@
|
|
|
63
63
|
<FieldWrapper {...fieldProps}>
|
|
64
64
|
{#snippet formElem(props)}
|
|
65
65
|
<Select type="single" {...props} bind:value={getKeyFromValue, setValueFromKey}>
|
|
66
|
-
<SelectTrigger class={cn('w-[180px] cursor-pointer', className)}>
|
|
67
|
-
|
|
66
|
+
<SelectTrigger class={cn('w-[180px] cursor-pointer truncate', className)}>
|
|
67
|
+
<span class="block truncate">
|
|
68
|
+
{value ? getLabel(valueToItem.get(value)!) : placeholder}
|
|
69
|
+
</span>
|
|
68
70
|
</SelectTrigger>
|
|
69
71
|
<SelectContent>
|
|
70
72
|
<SelectGroup>
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
lang="ts"
|
|
3
3
|
generics="I,V, K extends string | number,T extends Record<string, unknown>, U extends FormPath<T>, M"
|
|
4
4
|
>
|
|
5
|
-
import type { FormPath } from 'sveltekit-superforms';
|
|
6
|
-
import FieldWrapper, { type FieldWrapperProps } from '../FieldWrapper.svelte';
|
|
7
5
|
import {
|
|
8
6
|
Select,
|
|
9
7
|
SelectContent,
|
|
@@ -13,6 +11,8 @@
|
|
|
13
11
|
SelectTrigger
|
|
14
12
|
} from '../../../shadcn/components/ui/select/index.js';
|
|
15
13
|
import { cn } from '../../../shadcn/utils.js';
|
|
14
|
+
import type { FormPath } from 'sveltekit-superforms';
|
|
15
|
+
import FieldWrapper, { type FieldWrapperProps } from '../FieldWrapper.svelte';
|
|
16
16
|
|
|
17
17
|
interface Props extends FieldWrapperProps<T, U, M> {
|
|
18
18
|
values?: V[];
|
|
@@ -70,8 +70,10 @@
|
|
|
70
70
|
<FieldWrapper {...fieldProps}>
|
|
71
71
|
{#snippet formElem(props)}
|
|
72
72
|
<Select type="multiple" {...props} bind:value={getKeyFromValue, setValueFromKey}>
|
|
73
|
-
<SelectTrigger class={cn('w-[180px] cursor-pointer', className)}>
|
|
74
|
-
|
|
73
|
+
<SelectTrigger class={cn('w-[180px] cursor-pointer truncate', className)}>
|
|
74
|
+
<span class="block truncate">
|
|
75
|
+
{getPreview()}
|
|
76
|
+
</span>
|
|
75
77
|
</SelectTrigger>
|
|
76
78
|
<SelectContent>
|
|
77
79
|
<SelectGroup>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import Form from './Form.svelte';
|
|
2
1
|
import Button from './Button.svelte';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import TimeField from './fields/TimeField.svelte';
|
|
2
|
+
import ChoiceField from './fields/ChoiceField.svelte';
|
|
3
|
+
import ChoiceMultiField from './fields/ChoiceMultiField.svelte';
|
|
6
4
|
import DateField from './fields/DateField.svelte';
|
|
5
|
+
import HexColorField from './fields/HexColorField.svelte';
|
|
7
6
|
import NumberField from './fields/NumberField.svelte';
|
|
7
|
+
import PasswordField from './fields/PasswordField.svelte';
|
|
8
8
|
import SelectField from './fields/SelectField.svelte';
|
|
9
9
|
import SelectMultiField from './fields/SelectMultiField.svelte';
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import ChoiceMultiField from './fields/ChoiceMultiField.svelte';
|
|
10
|
+
import TextField from './fields/TextField.svelte';
|
|
11
|
+
import TextFieldNullable from './fields/TextFieldNullable.svelte';
|
|
12
|
+
import TimeField from './fields/TimeField.svelte';
|
|
14
13
|
import WeekdayChoiceField from './fields/WeekdayChoiceField.svelte';
|
|
15
14
|
import WeekdayChoiceMultiField from './fields/WeekdayChoiceMultiField.svelte';
|
|
16
|
-
|
|
15
|
+
import Form from './Form.svelte';
|
|
16
|
+
export { Button, ChoiceField, ChoiceMultiField, DateField, Form, HexColorField, NumberField, PasswordField, SelectField, SelectMultiField, TextField, TextFieldNullable, TimeField, WeekdayChoiceField, WeekdayChoiceMultiField };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import Form from './Form.svelte';
|
|
2
1
|
import Button from './Button.svelte';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import TimeField from './fields/TimeField.svelte';
|
|
2
|
+
import ChoiceField from './fields/ChoiceField.svelte';
|
|
3
|
+
import ChoiceMultiField from './fields/ChoiceMultiField.svelte';
|
|
6
4
|
import DateField from './fields/DateField.svelte';
|
|
5
|
+
import HexColorField from './fields/HexColorField.svelte';
|
|
7
6
|
import NumberField from './fields/NumberField.svelte';
|
|
7
|
+
import PasswordField from './fields/PasswordField.svelte';
|
|
8
8
|
import SelectField from './fields/SelectField.svelte';
|
|
9
9
|
import SelectMultiField from './fields/SelectMultiField.svelte';
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import ChoiceMultiField from './fields/ChoiceMultiField.svelte';
|
|
10
|
+
import TextField from './fields/TextField.svelte';
|
|
11
|
+
import TextFieldNullable from './fields/TextFieldNullable.svelte';
|
|
12
|
+
import TimeField from './fields/TimeField.svelte';
|
|
14
13
|
import WeekdayChoiceField from './fields/WeekdayChoiceField.svelte';
|
|
15
14
|
import WeekdayChoiceMultiField from './fields/WeekdayChoiceMultiField.svelte';
|
|
16
|
-
|
|
15
|
+
import Form from './Form.svelte';
|
|
16
|
+
export { Button, ChoiceField, ChoiceMultiField, DateField, Form, HexColorField, NumberField, PasswordField, SelectField, SelectMultiField, TextField, TextFieldNullable, TimeField, WeekdayChoiceField, WeekdayChoiceMultiField };
|
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
getKey: (item: T) => K;
|
|
6
6
|
getLabel: (item: T) => string;
|
|
7
7
|
vertical?: boolean;
|
|
8
|
+
buttonContent?: Snippet<[label: string]>;
|
|
8
9
|
}
|
|
9
10
|
</script>
|
|
10
11
|
|
|
11
12
|
<script lang="ts" generics="T, K extends string | number | symbol">
|
|
12
13
|
import type { FormAttrs } from '../../form/FieldWrapper.svelte';
|
|
13
14
|
import { cn } from '../../../shadcn/utils.js';
|
|
15
|
+
import type { Snippet } from 'svelte';
|
|
14
16
|
|
|
15
17
|
interface Props extends ChoiceInternalProps<T, K> {
|
|
16
18
|
handleItemClick: (item: T) => void;
|
|
@@ -27,6 +29,7 @@
|
|
|
27
29
|
disabled,
|
|
28
30
|
readonly,
|
|
29
31
|
'aria-invalid': ariaInvalid,
|
|
32
|
+
buttonContent,
|
|
30
33
|
...control
|
|
31
34
|
}: Props = $props();
|
|
32
35
|
</script>
|
|
@@ -51,7 +54,12 @@
|
|
|
51
54
|
}}
|
|
52
55
|
data-state={isActive(item) ? 'active' : 'inactive'}
|
|
53
56
|
class="h-8 cursor-pointer rounded-lg bg-transparent p-2 text-muted-foreground hover:text-foreground hover:outline-2 focus-visible:outline-ring data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm"
|
|
54
|
-
|
|
57
|
+
>
|
|
58
|
+
{#if buttonContent}
|
|
59
|
+
{@render buttonContent(getLabel(item))}
|
|
60
|
+
{:else}
|
|
61
|
+
{getLabel(item)}
|
|
62
|
+
{/if}
|
|
55
63
|
</button>
|
|
56
64
|
{/each}
|
|
57
65
|
</div>
|
|
@@ -3,8 +3,10 @@ export interface ChoiceInternalProps<T, K extends string | number | symbol> exte
|
|
|
3
3
|
getKey: (item: T) => K;
|
|
4
4
|
getLabel: (item: T) => string;
|
|
5
5
|
vertical?: boolean;
|
|
6
|
+
buttonContent?: Snippet<[label: string]>;
|
|
6
7
|
}
|
|
7
8
|
import type { FormAttrs } from '../../form/FieldWrapper.svelte';
|
|
9
|
+
import type { Snippet } from 'svelte';
|
|
8
10
|
declare function $$render<T, K extends string | number | symbol>(): {
|
|
9
11
|
props: ChoiceInternalProps<T, K> & {
|
|
10
12
|
handleItemClick: (item: T) => void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export function fuzzySearchHighlight(needle, haystack) {
|
|
2
|
+
const hlen = haystack.length;
|
|
3
|
+
const nlen = needle.length;
|
|
4
|
+
if (nlen === 0)
|
|
5
|
+
return `<span>${haystack}</span>`;
|
|
6
|
+
if (nlen > hlen)
|
|
7
|
+
return null;
|
|
8
|
+
let result = '';
|
|
9
|
+
let j = 0; // haystack pointer
|
|
10
|
+
let matchedCount = 0;
|
|
11
|
+
for (let i = 0; i < nlen; i++) {
|
|
12
|
+
const nch = needle[i].toLowerCase();
|
|
13
|
+
let found = false;
|
|
14
|
+
while (j < hlen) {
|
|
15
|
+
const hch = haystack[j];
|
|
16
|
+
if (hch.toLowerCase() === nch) {
|
|
17
|
+
// match found → wrap in <b>
|
|
18
|
+
result += `<b>${hch}</b>`;
|
|
19
|
+
j++;
|
|
20
|
+
found = true;
|
|
21
|
+
matchedCount++;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// non-match → normal text
|
|
26
|
+
result += hch;
|
|
27
|
+
j++;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!found) {
|
|
31
|
+
// no match for current needle char → fail entirely
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// add remaining unmatched characters
|
|
36
|
+
result += haystack.slice(j);
|
|
37
|
+
// sanity check — must have matched all needle chars
|
|
38
|
+
if (matchedCount < nlen)
|
|
39
|
+
return null;
|
|
40
|
+
return `<span>${result}</span>`;
|
|
41
|
+
}
|
|
42
|
+
export function fuzzySearch(needle, haystack) {
|
|
43
|
+
const hlen = haystack.length;
|
|
44
|
+
const nlen = needle.length;
|
|
45
|
+
if (nlen > hlen) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (nlen === hlen) {
|
|
49
|
+
return needle.toLowerCase() === haystack.toLowerCase();
|
|
50
|
+
}
|
|
51
|
+
const lowerNeedle = needle.toLowerCase();
|
|
52
|
+
const lowerHaystack = haystack.toLowerCase();
|
|
53
|
+
outer: for (let i = 0, j = 0; i < nlen; i++) {
|
|
54
|
+
const nch = lowerNeedle.charCodeAt(i);
|
|
55
|
+
while (j < hlen) {
|
|
56
|
+
if (lowerHaystack.charCodeAt(j++) === nch) {
|
|
57
|
+
continue outer;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|