index.js 1.1 KB

1234567891011121314151617181920212223
  1. Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
  2. const require_error = require("../../utils/error.js");
  3. let lodash_unified = require("lodash-unified");
  4. let vue = require("vue");
  5. //#region ../../packages/hooks/use-attrs/index.ts
  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 = (0, vue.computed)(() => {
  11. return (excludeKeys?.value || []).concat(DEFAULT_EXCLUDE_KEYS);
  12. });
  13. const instance = (0, vue.getCurrentInstance)();
  14. if (!instance) {
  15. require_error.debugWarn("use-attrs", "getCurrentInstance() returned null. useAttrs() must be called at the top of a setup function");
  16. return (0, vue.computed)(() => ({}));
  17. }
  18. return (0, vue.computed)(() => (0, lodash_unified.fromPairs)(Object.entries(instance.proxy?.$attrs).filter(([key]) => !allExcludeKeys.value.includes(key) && !(excludeListeners && LISTENER_PREFIX.test(key)))));
  19. };
  20. //#endregion
  21. exports.useAttrs = useAttrs;
  22. //# sourceMappingURL=index.js.map