This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
import type { InjectionKey, Ref } from 'vue';
export interface ElZIndexInjectionContext {
current: number;
}
export declare const defaultInitialZIndex = 2000;
export declare const ZINDEX_INJECTION_KEY: InjectionKey<ElZIndexInjectionContext>;
export declare const zIndexContextKey: InjectionKey<Ref<number | undefined>>;
export declare const useZIndex: (zIndexOverrides?: Ref<number>) => {
initialZIndex: import("vue").ComputedRef<number>;
currentZIndex: import("vue").ComputedRef<number>;
nextZIndex: () => number;
};
export type UseZIndexReturn = ReturnType<typeof useZIndex>;

View File

@@ -0,0 +1,34 @@
import { ref, getCurrentInstance, inject, computed, unref } from 'vue';
import { isNumber } from '../../utils/types.mjs';
import { isClient } from '@vueuse/core';
const initial = {
current: 0
};
const zIndex = ref(0);
const defaultInitialZIndex = 2e3;
const ZINDEX_INJECTION_KEY = Symbol("elZIndexContextKey");
const zIndexContextKey = Symbol("zIndexContextKey");
const useZIndex = (zIndexOverrides) => {
const increasingInjection = getCurrentInstance() ? inject(ZINDEX_INJECTION_KEY, initial) : initial;
const zIndexInjection = zIndexOverrides || (getCurrentInstance() ? inject(zIndexContextKey, void 0) : void 0);
const initialZIndex = computed(() => {
const zIndexFromInjection = unref(zIndexInjection);
return isNumber(zIndexFromInjection) ? zIndexFromInjection : defaultInitialZIndex;
});
const currentZIndex = computed(() => initialZIndex.value + zIndex.value);
const nextZIndex = () => {
increasingInjection.current++;
zIndex.value = increasingInjection.current;
return currentZIndex.value;
};
if (!isClient && !inject(ZINDEX_INJECTION_KEY)) ;
return {
initialZIndex,
currentZIndex,
nextZIndex
};
};
export { ZINDEX_INJECTION_KEY, defaultInitialZIndex, useZIndex, zIndexContextKey };
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":["../../../../../packages/hooks/use-z-index/index.ts"],"sourcesContent":["import { computed, getCurrentInstance, inject, ref, unref } from 'vue'\nimport { debugWarn, isClient, isNumber } from '@element-plus/utils'\n\nimport type { InjectionKey, Ref } from 'vue'\n\nexport interface ElZIndexInjectionContext {\n current: number\n}\n\nconst initial: ElZIndexInjectionContext = {\n current: 0,\n}\n\nconst zIndex = ref(0)\n\nexport const defaultInitialZIndex = 2000\n\n// For SSR\nexport const ZINDEX_INJECTION_KEY: InjectionKey<ElZIndexInjectionContext> =\n Symbol('elZIndexContextKey')\n\nexport const zIndexContextKey: InjectionKey<Ref<number | undefined>> =\n Symbol('zIndexContextKey')\n\nexport const useZIndex = (zIndexOverrides?: Ref<number>) => {\n const increasingInjection = getCurrentInstance()\n ? inject(ZINDEX_INJECTION_KEY, initial)\n : initial\n\n const zIndexInjection =\n zIndexOverrides ||\n (getCurrentInstance() ? inject(zIndexContextKey, undefined) : undefined)\n\n const initialZIndex = computed(() => {\n const zIndexFromInjection = unref(zIndexInjection)\n return isNumber(zIndexFromInjection)\n ? zIndexFromInjection\n : defaultInitialZIndex\n })\n\n const currentZIndex = computed(() => initialZIndex.value + zIndex.value)\n\n const nextZIndex = () => {\n increasingInjection.current++\n zIndex.value = increasingInjection.current\n return currentZIndex.value\n }\n\n if (!isClient && !inject(ZINDEX_INJECTION_KEY)) {\n debugWarn(\n 'ZIndexInjection',\n `Looks like you are using server rendering, you must provide a z-index provider to ensure the hydration process to be succeed\nusage: app.provide(ZINDEX_INJECTION_KEY, { current: 0 })`\n )\n }\n\n return {\n initialZIndex,\n currentZIndex,\n nextZIndex,\n }\n}\n\nexport type UseZIndexReturn = ReturnType<typeof useZIndex>\n"],"names":[],"mappings":";;;;AAEA,MAAM,OAAO,GAAG;AAChB,EAAE,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AACF,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AACV,MAAC,oBAAoB,GAAG,IAAI;AAC5B,MAAC,oBAAoB,GAAG,MAAM,CAAC,oBAAoB,EAAE;AACrD,MA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