sprintify-ui 0.2.11 → 0.2.12
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/sprintify-ui.es.js +3729 -3725
- package/package.json +1 -1
- package/src/components/BaseNumber.vue +37 -23
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
leave-to-class="transform scale-90 opacity-0"
|
|
10
10
|
>
|
|
11
11
|
<div
|
|
12
|
-
v-if="showInvalidInput"
|
|
12
|
+
v-if="showInvalidInput && invalidInput"
|
|
13
13
|
class="absolute left-0 top-full z-[1]"
|
|
14
14
|
>
|
|
15
15
|
<div
|
|
@@ -171,34 +171,50 @@ function convertToNumber(
|
|
|
171
171
|
value: string | number | null | undefined
|
|
172
172
|
): number | null {
|
|
173
173
|
if (value === null) return null;
|
|
174
|
-
|
|
174
|
+
const number = parseFloat(value + '');
|
|
175
175
|
if (Number.isNaN(number)) {
|
|
176
176
|
return null;
|
|
177
177
|
}
|
|
178
|
+
return number;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function convertToValidNumber(
|
|
182
|
+
value: string | number | null | undefined
|
|
183
|
+
): number | null {
|
|
184
|
+
let number = convertToNumber(value);
|
|
185
|
+
|
|
186
|
+
if (number === null) return null;
|
|
187
|
+
|
|
178
188
|
if (hasMax.value) {
|
|
179
189
|
number = Math.min(number, props.max as number);
|
|
180
190
|
}
|
|
191
|
+
|
|
181
192
|
if (hasMin.value) {
|
|
182
193
|
number = Math.max(number, props.min as number);
|
|
183
194
|
}
|
|
195
|
+
|
|
184
196
|
return round(number, precision.value);
|
|
185
197
|
}
|
|
186
198
|
|
|
187
199
|
const valueInternal = ref<null | string | number>(null);
|
|
188
200
|
|
|
189
|
-
const
|
|
201
|
+
const valueInternalNumber = computed<number | null>(() => {
|
|
190
202
|
return convertToNumber(valueInternal.value);
|
|
191
203
|
});
|
|
192
204
|
|
|
205
|
+
const valueInternalValidNumber = computed<number | null>(() => {
|
|
206
|
+
return convertToValidNumber(valueInternal.value);
|
|
207
|
+
});
|
|
208
|
+
|
|
193
209
|
const realValueInternalAsString = computed<string>(() => {
|
|
194
|
-
if (
|
|
195
|
-
return
|
|
210
|
+
if (valueInternalValidNumber.value === null) return '';
|
|
211
|
+
return valueInternalValidNumber.value.toLocaleString('fullwide', {
|
|
196
212
|
useGrouping: false,
|
|
197
213
|
});
|
|
198
214
|
});
|
|
199
215
|
|
|
200
216
|
const invalidInput = computed(() => {
|
|
201
|
-
if (
|
|
217
|
+
if (valueInternalValidNumber.value == null && valueInternal.value == '') {
|
|
202
218
|
return false;
|
|
203
219
|
}
|
|
204
220
|
|
|
@@ -206,13 +222,13 @@ const invalidInput = computed(() => {
|
|
|
206
222
|
});
|
|
207
223
|
|
|
208
224
|
const tooBig = computed(() => {
|
|
209
|
-
if (
|
|
210
|
-
return hasMax.value &&
|
|
225
|
+
if (valueInternalNumber.value === null) return false;
|
|
226
|
+
return hasMax.value && valueInternalNumber.value > (props.max as number);
|
|
211
227
|
});
|
|
212
228
|
|
|
213
229
|
const tooSmall = computed(() => {
|
|
214
|
-
if (
|
|
215
|
-
return hasMin.value &&
|
|
230
|
+
if (valueInternalNumber.value === null) return false;
|
|
231
|
+
return hasMin.value && valueInternalNumber.value < (props.min as number);
|
|
216
232
|
});
|
|
217
233
|
|
|
218
234
|
const tooPrecise = computed(() => {
|
|
@@ -224,10 +240,8 @@ const tooPrecise = computed(() => {
|
|
|
224
240
|
return parts[1].length > precision.value;
|
|
225
241
|
});
|
|
226
242
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (valueInternal.value != props.modelValue) {
|
|
230
|
-
emitUpdate(realValueInternal.value);
|
|
243
|
+
if (convertToValidNumber(props.modelValue) != props.modelValue) {
|
|
244
|
+
emitUpdate(valueInternalValidNumber.value);
|
|
231
245
|
}
|
|
232
246
|
|
|
233
247
|
let timeoutId = undefined as undefined | number;
|
|
@@ -247,7 +261,7 @@ function onInput(event: any) {
|
|
|
247
261
|
|
|
248
262
|
valueInternal.value = value;
|
|
249
263
|
|
|
250
|
-
emitUpdate(
|
|
264
|
+
emitUpdate(valueInternalValidNumber.value);
|
|
251
265
|
|
|
252
266
|
nextTick(() => {
|
|
253
267
|
showHideInvalidOnInput();
|
|
@@ -306,46 +320,46 @@ function updateInternalValueToRealValue() {
|
|
|
306
320
|
if (!props.autoFix) {
|
|
307
321
|
return;
|
|
308
322
|
}
|
|
309
|
-
if (
|
|
323
|
+
if (valueInternalValidNumber.value === null) {
|
|
310
324
|
valueInternal.value = '';
|
|
311
325
|
return;
|
|
312
326
|
}
|
|
313
327
|
valueInternal.value = round(
|
|
314
|
-
|
|
328
|
+
valueInternalValidNumber.value ?? defaultValue.value,
|
|
315
329
|
precision.value
|
|
316
330
|
);
|
|
317
331
|
}
|
|
318
332
|
|
|
319
333
|
function increment() {
|
|
320
334
|
if (props.disabled) return;
|
|
321
|
-
if (
|
|
335
|
+
if (valueInternalValidNumber.value === null) {
|
|
322
336
|
valueInternal.value = defaultValue.value;
|
|
323
337
|
} else {
|
|
324
338
|
const newValue = round(
|
|
325
|
-
|
|
339
|
+
valueInternalValidNumber.value + stepNormalized.value,
|
|
326
340
|
precision.value
|
|
327
341
|
);
|
|
328
342
|
if (!hasMax.value || newValue <= (props.max as number)) {
|
|
329
343
|
valueInternal.value = newValue;
|
|
330
344
|
}
|
|
331
345
|
}
|
|
332
|
-
emitUpdate(
|
|
346
|
+
emitUpdate(valueInternalValidNumber.value);
|
|
333
347
|
}
|
|
334
348
|
|
|
335
349
|
function decrement() {
|
|
336
350
|
if (props.disabled) return;
|
|
337
|
-
if (
|
|
351
|
+
if (valueInternalValidNumber.value === null) {
|
|
338
352
|
valueInternal.value = defaultValue.value;
|
|
339
353
|
} else {
|
|
340
354
|
const newValue = round(
|
|
341
|
-
|
|
355
|
+
valueInternalValidNumber.value - stepNormalized.value,
|
|
342
356
|
precision.value
|
|
343
357
|
);
|
|
344
358
|
if (!hasMin.value || newValue >= (props.min as number)) {
|
|
345
359
|
valueInternal.value = newValue;
|
|
346
360
|
}
|
|
347
361
|
}
|
|
348
|
-
emitUpdate(
|
|
362
|
+
emitUpdate(valueInternalValidNumber.value);
|
|
349
363
|
}
|
|
350
364
|
|
|
351
365
|
const borderColor = computed(() => {
|