revert unnecessary MaybeRef in components

This commit is contained in:
Lhcfl 2024-04-20 00:05:37 +08:00
parent c6e2776298
commit ab221c98a7
7 changed files with 18 additions and 25 deletions

View file

@ -28,11 +28,10 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { Ref } from "vue";
import MkTooltip from "./MkTooltip.vue"; import MkTooltip from "./MkTooltip.vue";
const props = defineProps<{ const props = defineProps<{
showing: Ref<boolean>; showing: boolean;
x: number; x: number;
y: number; y: number;
title?: string; title?: string;

View file

@ -19,13 +19,12 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { Ref } from "vue";
import type { entities } from "firefish-js"; import type { entities } from "firefish-js";
import MkTooltip from "./MkTooltip.vue"; import MkTooltip from "./MkTooltip.vue";
import XReactionIcon from "@/components/MkReactionIcon.vue"; import XReactionIcon from "@/components/MkReactionIcon.vue";
defineProps<{ defineProps<{
showing: Ref<boolean>; showing: boolean;
reaction: string; reaction: string;
emojis: entities.EmojiLite[]; emojis: entities.EmojiLite[];
targetElement: HTMLElement; targetElement: HTMLElement;

View file

@ -30,13 +30,12 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { Ref } from "vue";
import type { entities } from "firefish-js"; import type { entities } from "firefish-js";
import MkTooltip from "./MkTooltip.vue"; import MkTooltip from "./MkTooltip.vue";
import XReactionIcon from "@/components/MkReactionIcon.vue"; import XReactionIcon from "@/components/MkReactionIcon.vue";
defineProps<{ defineProps<{
showing: Ref<boolean>; showing: boolean;
reaction: string; reaction: string;
users: entities.User[]; // TODO users: entities.User[]; // TODO
count: number; count: number;

View file

@ -5,7 +5,7 @@
@after-leave="emit('closed')" @after-leave="emit('closed')"
> >
<div <div
v-show="unref(showing)" v-show="showing"
ref="el" ref="el"
class="buebdbiu _acrylic _shadow" class="buebdbiu _acrylic _shadow"
:style="{ zIndex, maxWidth: maxWidth + 'px' }" :style="{ zIndex, maxWidth: maxWidth + 'px' }"
@ -19,21 +19,14 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { import { nextTick, onMounted, onUnmounted, ref } from "vue";
type MaybeRef,
nextTick,
onMounted,
onUnmounted,
ref,
unref,
} from "vue";
import * as os from "@/os"; import * as os from "@/os";
import { calcPopupPosition } from "@/scripts/popup-position"; import { calcPopupPosition } from "@/scripts/popup-position";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
showing: MaybeRef<boolean>; showing: boolean;
targetElement?: HTMLElement | null; targetElement?: HTMLElement | null;
x?: number; x?: number;
y?: number; y?: number;

View file

@ -19,12 +19,11 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { Ref } from "vue";
import type { entities } from "firefish-js"; import type { entities } from "firefish-js";
import MkTooltip from "./MkTooltip.vue"; import MkTooltip from "./MkTooltip.vue";
defineProps<{ defineProps<{
showing: Ref<boolean>; showing: boolean;
users: entities.User[]; users: entities.User[];
count: number; count: number;
targetElement?: HTMLElement; targetElement?: HTMLElement;

View file

@ -13,7 +13,7 @@
]" ]"
> >
<i <i
v-if="unref(success)" v-if="success"
:class="[$style.icon, $style.success, iconify('ph-check')]" :class="[$style.icon, $style.success, iconify('ph-check')]"
></i> ></i>
<MkLoading <MkLoading
@ -29,16 +29,15 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { MaybeRef } from "vue"; import { shallowRef, watch } from "vue";
import { shallowRef, unref, watch } from "vue";
import MkModal from "@/components/MkModal.vue"; import MkModal from "@/components/MkModal.vue";
import iconify from "@/scripts/icon"; import iconify from "@/scripts/icon";
const modal = shallowRef<InstanceType<typeof MkModal>>(); const modal = shallowRef<InstanceType<typeof MkModal>>();
const props = defineProps<{ const props = defineProps<{
success: MaybeRef<boolean>; success: boolean;
showing: MaybeRef<boolean>; showing: boolean;
text?: string; text?: string;
}>(); }>();

View file

@ -3,7 +3,7 @@
import { EventEmitter } from "eventemitter3"; import { EventEmitter } from "eventemitter3";
import { type Endpoints, type entities, api as firefishApi } from "firefish-js"; import { type Endpoints, type entities, api as firefishApi } from "firefish-js";
import insertTextAtCursor from "insert-text-at-cursor"; import insertTextAtCursor from "insert-text-at-cursor";
import type { Component, Ref } from "vue"; import type { Component, MaybeRef, Ref } from "vue";
import { defineAsyncComponent, markRaw, ref } from "vue"; import { defineAsyncComponent, markRaw, ref } from "vue";
import { i18n } from "./i18n"; import { i18n } from "./i18n";
import MkDialog from "@/components/MkDialog.vue"; import MkDialog from "@/components/MkDialog.vue";
@ -213,9 +213,13 @@ interface VueComponentConstructor<P, E> {
type NonArrayAble<A> = A extends Array<unknown> ? never : A; type NonArrayAble<A> = A extends Array<unknown> ? never : A;
type CanUseRef<T> = {
[K in keyof T]: MaybeRef<T[K]>;
};
export async function popup<Props, Emits>( export async function popup<Props, Emits>(
component: VueComponentConstructor<Props, Emits>, component: VueComponentConstructor<Props, Emits>,
props: Props, props: CanUseRef<Props>,
events: Partial<NonArrayAble<NonNullable<Emits>>> = {}, events: Partial<NonArrayAble<NonNullable<Emits>>> = {},
disposeEvent?: keyof Partial<NonArrayAble<NonNullable<Emits>>>, disposeEvent?: keyof Partial<NonArrayAble<NonNullable<Emits>>>,
) { ) {
@ -240,6 +244,7 @@ export async function popup<Props, Emits>(
id, id,
}; };
// Hint: Vue will automatically resolve ref here, so it is safe to use ref in props
popups.value.push(state); popups.value.push(state);
return { return {