@skeletonlabs/skeleton 2.7.1-dev.c283b123 → 2.8.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.
|
@@ -62,48 +62,73 @@ onMount(() => {
|
|
|
62
62
|
function onInputHandler() {
|
|
63
63
|
inputValid = true;
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
function validateCustom(chip) {
|
|
66
|
+
return validation === void 0 || validation(chip);
|
|
67
|
+
}
|
|
68
|
+
function validateCount() {
|
|
69
|
+
return max === -1 || value.length < max;
|
|
70
|
+
}
|
|
71
|
+
function validateLength(chip) {
|
|
72
|
+
return (minlength === -1 || chip.length >= minlength) && (maxlength === -1 || chip.length <= maxlength);
|
|
73
|
+
}
|
|
74
|
+
function validateWhiteList(chip) {
|
|
75
|
+
return whitelist.length === 0 || whitelist.includes(chip);
|
|
76
|
+
}
|
|
77
|
+
function validateDuplicates(chip) {
|
|
78
|
+
return allowDuplicates || !value.includes(chip);
|
|
79
|
+
}
|
|
80
|
+
function validate(chip = "") {
|
|
81
|
+
if (!chip && !input)
|
|
80
82
|
return false;
|
|
81
|
-
|
|
83
|
+
chip = chip !== "" ? chip.trim() : input.trim();
|
|
84
|
+
return validateCustom(chip) && validateCount() && validateLength(chip) && validateWhiteList(chip) && validateDuplicates(chip);
|
|
85
|
+
}
|
|
86
|
+
function addChipCommon(chip) {
|
|
87
|
+
chip = allowUpperCase ? chip : chip.toLowerCase();
|
|
88
|
+
value.push(chip);
|
|
89
|
+
value = value;
|
|
90
|
+
chipValues.push({ val: chip, id: Math.random() });
|
|
91
|
+
chipValues = chipValues;
|
|
92
|
+
}
|
|
93
|
+
function removeChipCommon(chip) {
|
|
94
|
+
let chipIndex = value.indexOf(chip);
|
|
95
|
+
value.splice(chipIndex, 1);
|
|
96
|
+
value = value;
|
|
97
|
+
chipValues.splice(chipIndex, 1);
|
|
98
|
+
chipValues = chipValues;
|
|
82
99
|
}
|
|
83
|
-
function
|
|
100
|
+
function addChipInternally(event) {
|
|
84
101
|
event.preventDefault();
|
|
85
102
|
inputValid = validate();
|
|
86
103
|
if (inputValid === false) {
|
|
87
104
|
dispatch("invalid", { event, input });
|
|
88
105
|
return;
|
|
89
106
|
}
|
|
90
|
-
input
|
|
91
|
-
value.push(input);
|
|
92
|
-
value = value;
|
|
93
|
-
chipValues.push({ val: input, id: Math.random() });
|
|
94
|
-
chipValues = chipValues;
|
|
107
|
+
addChipCommon(input);
|
|
95
108
|
dispatch("add", { event, chipIndex: value.length - 1, chipValue: input });
|
|
96
109
|
input = "";
|
|
97
110
|
}
|
|
98
|
-
function
|
|
111
|
+
function removeChipInternally(event, chipIndex, chipValue) {
|
|
99
112
|
if ($$restProps.disabled)
|
|
100
113
|
return;
|
|
101
|
-
|
|
102
|
-
value = value;
|
|
103
|
-
chipValues.splice(chipIndex, 1);
|
|
104
|
-
chipValues = chipValues;
|
|
114
|
+
removeChipCommon(chipValue);
|
|
105
115
|
dispatch("remove", { event, chipIndex, chipValue });
|
|
106
116
|
}
|
|
117
|
+
export function addChip(chip) {
|
|
118
|
+
inputValid = validate(chip);
|
|
119
|
+
if (inputValid === false) {
|
|
120
|
+
dispatch("invalidManually", { input: chip });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
addChipCommon(chip);
|
|
124
|
+
dispatch("addManually", { chipIndex: value.length - 1, chipValue: chip });
|
|
125
|
+
}
|
|
126
|
+
export function removeChip(chip) {
|
|
127
|
+
if ($$restProps.disabled)
|
|
128
|
+
return;
|
|
129
|
+
removeChipCommon(chip);
|
|
130
|
+
dispatch("removeManually", { chipValue: chip });
|
|
131
|
+
}
|
|
107
132
|
$:
|
|
108
133
|
classesInvalid = inputValid === false ? invalid : "";
|
|
109
134
|
$:
|
|
@@ -133,7 +158,7 @@ $:
|
|
|
133
158
|
<!-- Chip Wrapper -->
|
|
134
159
|
<div class="input-chip-wrapper {classesChipWrapper}">
|
|
135
160
|
<!-- Input Field -->
|
|
136
|
-
<form on:submit={
|
|
161
|
+
<form on:submit={addChipInternally}>
|
|
137
162
|
<input
|
|
138
163
|
type="text"
|
|
139
164
|
bind:value={input}
|
|
@@ -159,9 +184,7 @@ $:
|
|
|
159
184
|
<button
|
|
160
185
|
type="button"
|
|
161
186
|
class="chip {chips}"
|
|
162
|
-
on:click={(e) =>
|
|
163
|
-
removeChip(e, i, val);
|
|
164
|
-
}}
|
|
187
|
+
on:click={(e) => removeChipInternally(e, i, val)}
|
|
165
188
|
on:click
|
|
166
189
|
on:keypress
|
|
167
190
|
on:keydown
|
|
@@ -64,6 +64,8 @@ declare class __sveltets_Render<ListTransitionIn extends Transition = FlyTransit
|
|
|
64
64
|
chipTransitionOut?: ChipTransitionOut | undefined;
|
|
65
65
|
/** Transition params provided to `ChipTransitionOut`.*/
|
|
66
66
|
chipTransitionOutParams?: TransitionParams<ChipTransitionOut> | undefined;
|
|
67
|
+
addChip?: ((chip: string) => void) | undefined;
|
|
68
|
+
removeChip?: ((chip: string) => void) | undefined;
|
|
67
69
|
};
|
|
68
70
|
events(): {
|
|
69
71
|
input: Event;
|
|
@@ -83,10 +85,20 @@ declare class __sveltets_Render<ListTransitionIn extends Transition = FlyTransit
|
|
|
83
85
|
chipIndex: number;
|
|
84
86
|
chipValue: string;
|
|
85
87
|
}>;
|
|
88
|
+
addManually: CustomEvent<{
|
|
89
|
+
chipIndex: number;
|
|
90
|
+
chipValue: string;
|
|
91
|
+
}>;
|
|
92
|
+
removeManually: CustomEvent<{
|
|
93
|
+
chipValue: string;
|
|
94
|
+
}>;
|
|
86
95
|
invalid: CustomEvent<{
|
|
87
96
|
event: SubmitEvent;
|
|
88
97
|
input: string;
|
|
89
98
|
}>;
|
|
99
|
+
invalidManually: CustomEvent<{
|
|
100
|
+
input: string;
|
|
101
|
+
}>;
|
|
90
102
|
} & {
|
|
91
103
|
[evt: string]: CustomEvent<any>;
|
|
92
104
|
};
|
|
@@ -96,5 +108,7 @@ export type InputChipProps<ListTransitionIn extends Transition = FlyTransition,
|
|
|
96
108
|
export type InputChipEvents<ListTransitionIn extends Transition = FlyTransition, ListTransitionOut extends Transition = FlyTransition, ChipTransitionIn extends Transition = ScaleTransition, ChipTransitionOut extends Transition = ScaleTransition> = ReturnType<__sveltets_Render<ListTransitionIn, ListTransitionOut, ChipTransitionIn, ChipTransitionOut>['events']>;
|
|
97
109
|
export type InputChipSlots<ListTransitionIn extends Transition = FlyTransition, ListTransitionOut extends Transition = FlyTransition, ChipTransitionIn extends Transition = ScaleTransition, ChipTransitionOut extends Transition = ScaleTransition> = ReturnType<__sveltets_Render<ListTransitionIn, ListTransitionOut, ChipTransitionIn, ChipTransitionOut>['slots']>;
|
|
98
110
|
export default class InputChip<ListTransitionIn extends Transition = FlyTransition, ListTransitionOut extends Transition = FlyTransition, ChipTransitionIn extends Transition = ScaleTransition, ChipTransitionOut extends Transition = ScaleTransition> extends SvelteComponentTyped<InputChipProps<ListTransitionIn, ListTransitionOut, ChipTransitionIn, ChipTransitionOut>, InputChipEvents<ListTransitionIn, ListTransitionOut, ChipTransitionIn, ChipTransitionOut>, InputChipSlots<ListTransitionIn, ListTransitionOut, ChipTransitionIn, ChipTransitionOut>> {
|
|
111
|
+
get addChip(): (chip: string) => void;
|
|
112
|
+
get removeChip(): (chip: string) => void;
|
|
99
113
|
}
|
|
100
114
|
export {};
|