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.

24 lines
999 B

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