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.

28 lines
1.1 KiB

1 month ago
  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("use-attrs", "getCurrentInstance() returned null. useAttrs() must be called at the top of a setup function");
  16. return vue.computed(() => ({}));
  17. }
  18. return vue.computed(() => {
  19. var _a;
  20. return lodashUnified.fromPairs(Object.entries((_a = instance.proxy) == null ? void 0 : _a.$attrs).filter(([key]) => !allExcludeKeys.value.includes(key) && !(excludeListeners && LISTENER_PREFIX.test(key))));
  21. });
  22. };
  23. exports.useAttrs = useAttrs;
  24. //# sourceMappingURL=index.js.map