mirror of
https://github.com/certd/certd.git
synced 2026-05-16 21:27:34 +08:00
chore: code format
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import type { RendererElement } from "vue";
|
||||
|
||||
defineOptions({
|
||||
name: "CollapseTransition"
|
||||
name: "CollapseTransition",
|
||||
});
|
||||
|
||||
const reset = (el: RendererElement) => {
|
||||
@@ -85,7 +85,7 @@ const on = {
|
||||
|
||||
leaveCancelled(el: RendererElement) {
|
||||
reset(el);
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ interface Props {
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
dotClass: "",
|
||||
dotStyle: () => ({})
|
||||
dotStyle: () => ({}),
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
|
||||
@@ -18,7 +18,7 @@ const variantsMap: Record<string, string> = {
|
||||
destructive: "bg-destructive",
|
||||
primary: "bg-primary",
|
||||
success: "bg-green-500",
|
||||
warning: "bg-yellow-500"
|
||||
warning: "bg-yellow-500",
|
||||
};
|
||||
|
||||
const isDot = computed(() => props.badgeType === "dot");
|
||||
@@ -36,7 +36,7 @@ const badgeClass = computed(() => {
|
||||
const badgeStyle = computed(() => {
|
||||
if (badgeClass.value && isValidColor(badgeClass.value)) {
|
||||
return {
|
||||
backgroundColor: badgeClass.value
|
||||
backgroundColor: badgeClass.value,
|
||||
};
|
||||
}
|
||||
return {};
|
||||
|
||||
@@ -14,7 +14,7 @@ interface Props extends MenuItemProps {}
|
||||
defineOptions({ name: "MenuItem" });
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
disabled: false
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{ click: [MenuItemRegistered] }>();
|
||||
@@ -38,7 +38,7 @@ const showTooltip = computed(() => rootMenu.props.mode === "vertical" && isTopLe
|
||||
const item: MenuItemRegistered = reactive({
|
||||
active,
|
||||
parentPaths: parentPaths.value,
|
||||
path: props.path || ""
|
||||
path: props.path || "",
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -54,7 +54,7 @@ function handleClick() {
|
||||
}
|
||||
rootMenu?.handleMenuItemClick?.({
|
||||
parentPaths: parentPaths.value,
|
||||
path: props.path
|
||||
path: props.path,
|
||||
});
|
||||
emit("click", item);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
collapse: false,
|
||||
mode: "vertical",
|
||||
rounded: true,
|
||||
theme: "dark"
|
||||
theme: "dark",
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -66,7 +66,7 @@ const getSlot = computed(() => {
|
||||
|
||||
watch(
|
||||
() => props.collapse,
|
||||
(value) => {
|
||||
value => {
|
||||
if (value) openedMenus.value = [];
|
||||
}
|
||||
);
|
||||
@@ -109,7 +109,7 @@ createMenuContext(
|
||||
removeSubMenu,
|
||||
subMenus,
|
||||
theme: toRef(props, "theme"),
|
||||
items
|
||||
items,
|
||||
})
|
||||
);
|
||||
|
||||
@@ -117,7 +117,7 @@ createSubMenuContext({
|
||||
addSubMenu,
|
||||
level: 1,
|
||||
mouseInChild,
|
||||
removeSubMenu
|
||||
removeSubMenu,
|
||||
});
|
||||
|
||||
function calcMenuItemWidth(menuItem: HTMLElement) {
|
||||
@@ -132,7 +132,7 @@ function calcSliceIndex() {
|
||||
return -1;
|
||||
}
|
||||
const items = [...(menu.value?.childNodes ?? [])].filter(
|
||||
(item) =>
|
||||
item =>
|
||||
// remove comment type node #12634
|
||||
item.nodeName !== "#comment" && (item.nodeName !== "#text" || item.nodeValue)
|
||||
) as HTMLElement[];
|
||||
@@ -198,7 +198,7 @@ function initMenu() {
|
||||
|
||||
// 展开该菜单项的路径上所有子菜单
|
||||
// expand all subMenus of the menu item
|
||||
parentPaths.forEach((path) => {
|
||||
parentPaths.forEach(path => {
|
||||
const subMenu = subMenus.value[path];
|
||||
subMenu && openMenu(path, subMenu.parentPaths);
|
||||
});
|
||||
|
||||
@@ -9,14 +9,14 @@ import { VbenIcon } from "../../../shadcn-ui";
|
||||
interface Props extends NormalMenuProps {}
|
||||
|
||||
defineOptions({
|
||||
name: "NormalMenu"
|
||||
name: "NormalMenu",
|
||||
});
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
activePath: "",
|
||||
collapse: false,
|
||||
menus: () => [],
|
||||
theme: "dark"
|
||||
theme: "dark",
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
||||
@@ -19,7 +19,7 @@ defineOptions({ name: "SubMenuContent" });
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
isMenuMore: false,
|
||||
level: 0
|
||||
level: 0,
|
||||
});
|
||||
|
||||
const rootMenu = useMenuContext();
|
||||
|
||||
@@ -20,7 +20,7 @@ defineOptions({ name: "SubMenu" });
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
disabled: false,
|
||||
isSubMenuMore: false
|
||||
isSubMenuMore: false,
|
||||
});
|
||||
|
||||
const { parentMenu, parentPaths } = useMenu();
|
||||
@@ -41,7 +41,7 @@ createSubMenuContext({
|
||||
handleMouseleave,
|
||||
level: (subMenu?.level ?? 0) + 1,
|
||||
mouseInChild,
|
||||
removeSubMenu
|
||||
removeSubMenu,
|
||||
});
|
||||
|
||||
const opened = computed(() => {
|
||||
@@ -61,20 +61,20 @@ const contentProps = computed((): HoverCardContentProps => {
|
||||
return {
|
||||
collisionPadding: { top: 20 },
|
||||
side,
|
||||
sideOffset: isHorizontal ? 5 : 10
|
||||
sideOffset: isHorizontal ? 5 : 10,
|
||||
};
|
||||
});
|
||||
|
||||
const active = computed(() => {
|
||||
let isActive = false;
|
||||
|
||||
Object.values(items.value).forEach((item) => {
|
||||
Object.values(items.value).forEach(item => {
|
||||
if (item.active) {
|
||||
isActive = true;
|
||||
}
|
||||
});
|
||||
|
||||
Object.values(subMenus.value).forEach((subItem) => {
|
||||
Object.values(subMenus.value).forEach(subItem => {
|
||||
if (subItem.active) {
|
||||
isActive = true;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ function handleClick() {
|
||||
rootMenu?.handleSubMenuClick({
|
||||
active: active.value,
|
||||
parentPaths: parentPaths.value,
|
||||
path: props.path
|
||||
path: props.path,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ const menuIcon = computed(() => (active.value ? props.activeIcon || props.icon :
|
||||
const item = reactive({
|
||||
active,
|
||||
parentPaths,
|
||||
path: props.path
|
||||
path: props.path,
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
@@ -183,7 +183,7 @@ onBeforeUnmount(() => {
|
||||
</template>
|
||||
</SubMenuContent>
|
||||
</template>
|
||||
<div :class="[nsMenu.is(mode, true), nsMenu.e('popup')]" @focus="(e) => handleMouseenter(e, 100)" @mouseenter="(e) => handleMouseenter(e, 100)" @mouseleave="() => handleMouseleave(true)">
|
||||
<div :class="[nsMenu.is(mode, true), nsMenu.e('popup')]" @focus="e => handleMouseenter(e, 100)" @mouseenter="e => handleMouseenter(e, 100)" @mouseleave="() => handleMouseleave(true)">
|
||||
<ul :class="[nsMenu.b(), is('rounded', rounded)]" :style="subMenuStyle">
|
||||
<slot></slot>
|
||||
</ul>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './use-menu';
|
||||
export * from './use-menu-context';
|
||||
export * from "./use-menu";
|
||||
export * from "./use-menu-context";
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { MenuProvider, SubMenuProvider } from '../types';
|
||||
import type { MenuProvider, SubMenuProvider } from "../types";
|
||||
|
||||
import { getCurrentInstance, inject, provide } from 'vue';
|
||||
import { getCurrentInstance, inject, provide } from "vue";
|
||||
|
||||
import { findComponentUpward } from '../utils';
|
||||
import { findComponentUpward } from "../utils";
|
||||
|
||||
const menuContextKey = Symbol('menuContext');
|
||||
const menuContextKey = Symbol("menuContext");
|
||||
|
||||
/**
|
||||
* @zh_CN Provide menu context
|
||||
@@ -28,7 +28,7 @@ function createSubMenuContext(injectSubMenuData: SubMenuProvider) {
|
||||
function useMenuContext() {
|
||||
const instance = getCurrentInstance();
|
||||
if (!instance) {
|
||||
throw new Error('instance is required');
|
||||
throw new Error("instance is required");
|
||||
}
|
||||
const rootMenu = inject(menuContextKey) as MenuProvider;
|
||||
return rootMenu;
|
||||
@@ -40,16 +40,11 @@ function useMenuContext() {
|
||||
function useSubMenuContext() {
|
||||
const instance = getCurrentInstance();
|
||||
if (!instance) {
|
||||
throw new Error('instance is required');
|
||||
throw new Error("instance is required");
|
||||
}
|
||||
const parentMenu = findComponentUpward(instance, ['Menu', 'SubMenu']);
|
||||
const parentMenu = findComponentUpward(instance, ["Menu", "SubMenu"]);
|
||||
const subMenu = inject(`subMenu:${parentMenu?.uid}`) as SubMenuProvider;
|
||||
return subMenu;
|
||||
}
|
||||
|
||||
export {
|
||||
createMenuContext,
|
||||
createSubMenuContext,
|
||||
useMenuContext,
|
||||
useSubMenuContext,
|
||||
};
|
||||
export { createMenuContext, createSubMenuContext, useMenuContext, useSubMenuContext };
|
||||
|
||||
@@ -32,14 +32,14 @@ function useMenu() {
|
||||
|
||||
return {
|
||||
parentMenu,
|
||||
parentPaths
|
||||
parentPaths,
|
||||
};
|
||||
}
|
||||
|
||||
function useMenuStyle(menu?: SubMenuProvider) {
|
||||
const subMenuStyle = computed(() => {
|
||||
return {
|
||||
"--menu-level": menu ? menu?.level ?? 0 + 1 : 0
|
||||
"--menu-level": menu ? (menu?.level ?? 0 + 1) : 0,
|
||||
};
|
||||
});
|
||||
return subMenuStyle;
|
||||
|
||||
@@ -13,11 +13,11 @@ interface Props extends MenuProps {
|
||||
}
|
||||
|
||||
defineOptions({
|
||||
name: "MenuView"
|
||||
name: "MenuView",
|
||||
});
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
collapse: false
|
||||
collapse: false,
|
||||
// theme: 'dark',
|
||||
});
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ interface Props {
|
||||
}
|
||||
|
||||
defineOptions({
|
||||
name: "SubMenuUi"
|
||||
name: "SubMenuUi",
|
||||
});
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {});
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import type {
|
||||
ComponentInternalInstance,
|
||||
VNode,
|
||||
VNodeChild,
|
||||
VNodeNormalizedChildren,
|
||||
} from 'vue';
|
||||
import type { ComponentInternalInstance, VNode, VNodeChild, VNodeNormalizedChildren } from "vue";
|
||||
|
||||
import { isVNode } from 'vue';
|
||||
import { isVNode } from "vue";
|
||||
|
||||
type VNodeChildAtom = Exclude<VNodeChild, Array<any>>;
|
||||
type RawSlots = Exclude<VNodeNormalizedChildren, Array<any> | null | string>;
|
||||
@@ -17,24 +12,19 @@ type FlattenVNodes = Array<RawSlots | VNodeChildAtom>;
|
||||
* @param instance
|
||||
* @param parentNames
|
||||
*/
|
||||
function findComponentUpward(
|
||||
instance: ComponentInternalInstance,
|
||||
parentNames: string[],
|
||||
) {
|
||||
function findComponentUpward(instance: ComponentInternalInstance, parentNames: string[]) {
|
||||
let parent = instance.parent;
|
||||
while (parent && !parentNames.includes(parent?.type?.name ?? '')) {
|
||||
while (parent && !parentNames.includes(parent?.type?.name ?? "")) {
|
||||
parent = parent.parent;
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
const flattedChildren = (
|
||||
children: FlattenVNodes | VNode | VNodeNormalizedChildren,
|
||||
): FlattenVNodes => {
|
||||
const flattedChildren = (children: FlattenVNodes | VNode | VNodeNormalizedChildren): FlattenVNodes => {
|
||||
const vNodes = Array.isArray(children) ? children : [children];
|
||||
const result: FlattenVNodes = [];
|
||||
|
||||
vNodes.forEach((child) => {
|
||||
vNodes.forEach(child => {
|
||||
if (Array.isArray(child)) {
|
||||
result.push(...flattedChildren(child));
|
||||
} else if (isVNode(child) && Array.isArray(child.children)) {
|
||||
|
||||
Reference in New Issue
Block a user