index.js 1.1 KB

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