UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 1.57 kB
{"version":3,"file":"index.mjs","sources":["../../../../../packages/hooks/use-attrs/index.ts"],"sourcesContent":["import { getCurrentInstance, computed } from 'vue'\nimport fromPairs from 'lodash/fromPairs'\nimport { debugWarn } from '@element-plus/utils/error'\n\nimport type { ComputedRef } from 'vue'\n\ninterface Params {\n excludeListeners?: boolean\n excludeKeys?: string[]\n}\n\nconst DEFAULT_EXCLUDE_KEYS = ['class', 'style']\nconst LISTENER_PREFIX = /^on[A-Z]/\n\nexport default (params: Params = {}): ComputedRef<Record<string, unknown>> => {\n const { excludeListeners = false, excludeKeys = [] } = params\n const allExcludeKeys = excludeKeys.concat(DEFAULT_EXCLUDE_KEYS)\n\n const instance = getCurrentInstance()\n if (!instance) {\n debugWarn(\n 'use-attrs',\n 'getCurrentInstance() returned null. useAttrs() must be called at the top of a setup function'\n )\n return computed(() => ({}))\n }\n\n return computed(() =>\n fromPairs(\n Object.entries(instance.proxy?.$attrs!).filter(\n ([key]) =>\n !allExcludeKeys.includes(key) &&\n !(excludeListeners && LISTENER_PREFIX.test(key))\n )\n )\n )\n}\n"],"names":[],"mappings":";;;;AAWA,MAAM,uBAAuB,CAAC,SAAS;AACvC,MAAM,kBAAkB;AAExB,eAAe,CAAC,SAAiB,OAA6C;AAC5E,QAAM,EAAE,mBAAmB,OAAO,cAAc,OAAO;AACvD,QAAM,iBAAiB,YAAY,OAAO;AAE1C,QAAM,WAAW;AACjB,MAAI,CAAC,UAAU;AACb,cACE,aACA;AAEF,WAAO,SAAS;AAAO;AAGzB,SAAO,SAAS,MAAG;AA3BrB;AA4BI,qBACE,OAAO,QAAQ,eAAS,UAAT,mBAAgB,QAAS,OACtC,CAAC,CAAC,SACA,CAAC,eAAe,SAAS,QACzB,sBAAsB,gBAAgB,KAAK;AAAA;AAAA;;;;"}