index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var lodashUnified = require('lodash-unified');
  5. var error = require('../../utils/error.js');
  6. const DEFAULT_EXCLUDE_KEYS = ["class", "style"];
  7. const LISTENER_PREFIX = /^on[A-Z]/;
  8. const useAttrs = (params = {}) => {
  9. const { excludeListeners = false, excludeKeys } = params;
  10. const allExcludeKeys = vue.computed(() => {
  11. return ((excludeKeys == null ? void 0 : excludeKeys.value) || []).concat(DEFAULT_EXCLUDE_KEYS);
  12. });
  13. const instance = vue.getCurrentInstance();
  14. if (!instance) {
  15. error.debugWarn(
  16. "use-attrs",
  17. "getCurrentInstance() returned null. useAttrs() must be called at the top of a setup function"
  18. );
  19. return vue.computed(() => ({}));
  20. }
  21. return vue.computed(
  22. () => {
  23. var _a;
  24. return lodashUnified.fromPairs(
  25. Object.entries((_a = instance.proxy) == null ? void 0 : _a.$attrs).filter(
  26. ([key]) => !allExcludeKeys.value.includes(key) && !(excludeListeners && LISTENER_PREFIX.test(key))
  27. )
  28. );
  29. }
  30. );
  31. };
  32. exports.useAttrs = useAttrs;
  33. //# sourceMappingURL=index.js.map