merge: upstream

This commit is contained in:
Marie 2024-02-03 20:19:44 +01:00
commit 11628e4b6a
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
285 changed files with 3413 additions and 1913 deletions

View file

@ -88,17 +88,18 @@ const focused = ref(false);
const changed = ref(false);
const invalid = ref(false);
const filled = computed(() => v.value !== '' && v.value != null);
const inputEl = shallowRef<HTMLElement>();
const inputEl = shallowRef<HTMLInputElement>();
const prefixEl = shallowRef<HTMLElement>();
const suffixEl = shallowRef<HTMLElement>();
const height =
props.small ? 33 :
props.large ? 39 :
36;
let autocomplete: Autocomplete;
let autocompleteWorker: Autocomplete | null = null;
const focus = () => inputEl.value.focus();
const onInput = (ev: KeyboardEvent) => {
const focus = () => inputEl.value?.focus();
const onInput = (event: Event) => {
const ev = event as KeyboardEvent;
changed.value = true;
emit('change', ev);
};
@ -115,9 +116,9 @@ const onKeydown = (ev: KeyboardEvent) => {
const updated = () => {
changed.value = false;
if (type.value === 'number') {
emit('update:modelValue', parseFloat(v.value));
emit('update:modelValue', typeof v.value === 'number' ? v.value : parseFloat(v.value ?? '0'));
} else {
emit('update:modelValue', v.value);
emit('update:modelValue', v.value ?? '');
}
};
@ -127,7 +128,7 @@ watch(modelValue, newValue => {
v.value = newValue;
});
watch(v, newValue => {
watch(v, () => {
if (!props.manualSave) {
if (props.debounce) {
debouncedUpdated();
@ -136,12 +137,14 @@ watch(v, newValue => {
}
}
invalid.value = inputEl.value.validity.badInput;
invalid.value = inputEl.value?.validity.badInput ?? true;
});
//
// 0
useInterval(() => {
if (inputEl.value == null) return;
if (prefixEl.value) {
if (prefixEl.value.offsetWidth) {
inputEl.value.style.paddingLeft = prefixEl.value.offsetWidth + 'px';
@ -163,15 +166,15 @@ onMounted(() => {
focus();
}
});
if (props.mfmAutocomplete) {
autocomplete = new Autocomplete(inputEl.value, v, props.mfmAutocomplete === true ? null : props.mfmAutocomplete);
if (props.mfmAutocomplete && inputEl.value) {
autocompleteWorker = new Autocomplete(inputEl.value, v, props.mfmAutocomplete === true ? undefined : props.mfmAutocomplete);
}
});
onUnmounted(() => {
if (autocomplete) {
autocomplete.detach();
if (autocompleteWorker) {
autocompleteWorker.detach();
}
});