Merge remote-tracking branch 'misskey-dev/develop' into io

This commit is contained in:
まっちゃとーにゅ 2024-01-31 05:10:06 +09:00
commit 9ffa56aa1b
No known key found for this signature in database
GPG key ID: 143DE582A97FE052
200 changed files with 2833 additions and 4369 deletions

View file

@ -31,11 +31,12 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
import { onMounted, nextTick, ref, watch, computed, toRefs, VNode, useSlots } from 'vue';
import { onMounted, nextTick, ref, watch, computed, toRefs, VNode, useSlots, VNodeChild } from 'vue';
import MkButton from '@/components/MkButton.vue';
import * as os from '@/os.js';
import { useInterval } from '@/scripts/use-interval.js';
import { i18n } from '@/i18n.js';
import { MenuItem } from '@/types/menu.js';
const props = defineProps<{
modelValue: string | null;
@ -51,7 +52,7 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
(ev: 'changeByUser'): void;
(ev: 'changeByUser', value: string | null): void;
(ev: 'update:modelValue', value: string | null): void;
}>();
@ -73,7 +74,7 @@ const height =
props.large ? 39 :
36;
const focus = () => inputEl.value.focus();
const focus = () => inputEl.value?.focus();
const onInput = (ev) => {
changed.value = true;
};
@ -87,17 +88,19 @@ watch(modelValue, newValue => {
v.value = newValue;
});
watch(v, newValue => {
watch(v, () => {
if (!props.manualSave) {
updated();
}
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';
@ -121,39 +124,41 @@ onMounted(() => {
});
});
function show(ev: MouseEvent) {
function show() {
if (inputEl.value && inputEl.value.hasAttribute('disabled')) {
return;
}
focused.value = true;
opening.value = true;
const menu = [];
const menu: MenuItem[] = [];
let options = slots.default!();
const pushOption = (option: VNode) => {
menu.push({
text: option.children,
active: computed(() => v.value === option.props.value),
text: option.children as string,
active: computed(() => v.value === option.props?.value),
action: () => {
v.value = option.props.value;
v.value = option.props?.value;
emit('changeByUser', v.value);
},
});
};
const scanOptions = (options: VNode[]) => {
const scanOptions = (options: VNodeChild[]) => {
for (const vnode of options) {
if (typeof vnode !== 'object' || vnode === null || Array.isArray(vnode)) continue;
if (vnode.type === 'optgroup') {
const optgroup = vnode;
menu.push({
type: 'label',
text: optgroup.props.label,
text: optgroup.props?.label,
});
scanOptions(optgroup.children);
if (Array.isArray(optgroup.children)) scanOptions(optgroup.children);
} else if (Array.isArray(vnode.children)) { //
const fragment = vnode;
scanOptions(fragment.children);
if (Array.isArray(fragment.children)) scanOptions(fragment.children);
} else if (vnode.props == null) { // v-if false
// nop?
} else {
@ -166,7 +171,7 @@ function show(ev: MouseEvent) {
scanOptions(options);
os.popupMenu(menu, container.value, {
width: container.value.offsetWidth,
width: container.value?.offsetWidth,
onClosing: () => {
opening.value = false;
},