You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB

1 month ago
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var core = require('@vueuse/core');
  5. var index = require('../use-namespace/index.js');
  6. var error = require('../../utils/error.js');
  7. const defaultIdInjection = {
  8. prefix: Math.floor(Math.random() * 1e4),
  9. current: 0
  10. };
  11. const ID_INJECTION_KEY = Symbol("elIdInjection");
  12. const useIdInjection = () => {
  13. return vue.getCurrentInstance() ? vue.inject(ID_INJECTION_KEY, defaultIdInjection) : defaultIdInjection;
  14. };
  15. const useId = (deterministicId) => {
  16. const idInjection = useIdInjection();
  17. if (!core.isClient && idInjection === defaultIdInjection) {
  18. error.debugWarn("IdInjection", `Looks like you are using server rendering, you must provide a id provider to ensure the hydration process to be succeed
  19. usage: app.provide(ID_INJECTION_KEY, {
  20. prefix: number,
  21. current: number,
  22. })`);
  23. }
  24. const namespace = index.useGetDerivedNamespace();
  25. const idRef = core.computedEager(() => vue.unref(deterministicId) || `${namespace.value}-id-${idInjection.prefix}-${idInjection.current++}`);
  26. return idRef;
  27. };
  28. exports.ID_INJECTION_KEY = ID_INJECTION_KEY;
  29. exports.useId = useId;
  30. exports.useIdInjection = useIdInjection;
  31. //# sourceMappingURL=index.js.map