index.mjs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { isClient } from "../../utils/browser.mjs";
  2. import { isNumber } from "../../utils/types.mjs";
  3. import { debugWarn } from "../../utils/error.mjs";
  4. import { computed, getCurrentInstance, inject, ref, unref } from "vue";
  5. //#region ../../packages/hooks/use-z-index/index.ts
  6. const initial = { current: 0 };
  7. const zIndex = ref(0);
  8. const defaultInitialZIndex = 2e3;
  9. const ZINDEX_INJECTION_KEY = Symbol("elZIndexContextKey");
  10. const zIndexContextKey = Symbol("zIndexContextKey");
  11. const useZIndex = (zIndexOverrides) => {
  12. const increasingInjection = getCurrentInstance() ? inject(ZINDEX_INJECTION_KEY, initial) : initial;
  13. const zIndexInjection = zIndexOverrides || (getCurrentInstance() ? inject(zIndexContextKey, void 0) : void 0);
  14. const initialZIndex = computed(() => {
  15. const zIndexFromInjection = unref(zIndexInjection);
  16. return isNumber(zIndexFromInjection) ? zIndexFromInjection : defaultInitialZIndex;
  17. });
  18. const currentZIndex = computed(() => initialZIndex.value + zIndex.value);
  19. const nextZIndex = () => {
  20. increasingInjection.current++;
  21. zIndex.value = increasingInjection.current;
  22. return currentZIndex.value;
  23. };
  24. if (!isClient && !inject(ZINDEX_INJECTION_KEY)) debugWarn("ZIndexInjection", `Looks like you are using server rendering, you must provide a z-index provider to ensure the hydration process to be succeed
  25. usage: app.provide(ZINDEX_INJECTION_KEY, { current: 0 })`);
  26. return {
  27. initialZIndex,
  28. currentZIndex,
  29. nextZIndex
  30. };
  31. };
  32. //#endregion
  33. export { ZINDEX_INJECTION_KEY, defaultInitialZIndex, useZIndex, zIndexContextKey };
  34. //# sourceMappingURL=index.mjs.map