index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. require('../../utils/index.js');
  5. var types = require('../../utils/types.js');
  6. var core = require('@vueuse/core');
  7. var error = require('../../utils/error.js');
  8. const initial = {
  9. current: 0
  10. };
  11. const zIndex = vue.ref(0);
  12. const defaultInitialZIndex = 2e3;
  13. const ZINDEX_INJECTION_KEY = Symbol("elZIndexContextKey");
  14. const zIndexContextKey = Symbol("zIndexContextKey");
  15. const useZIndex = (zIndexOverrides) => {
  16. const increasingInjection = vue.getCurrentInstance() ? vue.inject(ZINDEX_INJECTION_KEY, initial) : initial;
  17. const zIndexInjection = zIndexOverrides || (vue.getCurrentInstance() ? vue.inject(zIndexContextKey, void 0) : void 0);
  18. const initialZIndex = vue.computed(() => {
  19. const zIndexFromInjection = vue.unref(zIndexInjection);
  20. return types.isNumber(zIndexFromInjection) ? zIndexFromInjection : defaultInitialZIndex;
  21. });
  22. const currentZIndex = vue.computed(() => initialZIndex.value + zIndex.value);
  23. const nextZIndex = () => {
  24. increasingInjection.current++;
  25. zIndex.value = increasingInjection.current;
  26. return currentZIndex.value;
  27. };
  28. if (!core.isClient && !vue.inject(ZINDEX_INJECTION_KEY)) {
  29. error.debugWarn("ZIndexInjection", `Looks like you are using server rendering, you must provide a z-index provider to ensure the hydration process to be succeed
  30. usage: app.provide(ZINDEX_INJECTION_KEY, { current: 0 })`);
  31. }
  32. return {
  33. initialZIndex,
  34. currentZIndex,
  35. nextZIndex
  36. };
  37. };
  38. exports.ZINDEX_INJECTION_KEY = ZINDEX_INJECTION_KEY;
  39. exports.defaultInitialZIndex = defaultInitialZIndex;
  40. exports.useZIndex = useZIndex;
  41. exports.zIndexContextKey = zIndexContextKey;
  42. //# sourceMappingURL=index.js.map