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.

1 lines
5.2 KiB

{"ast":null,"code":"import { watch, nextTick, toRefs, computed } from 'vue';\nimport { pick } from 'lodash-unified';\nimport { ElSelect } from '../../select/index.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { UPDATE_MODEL_EVENT } from '../../../constants/event.mjs';\nconst useSelect = (props, {\n attrs,\n emit\n}, {\n select,\n tree,\n key\n}) => {\n const ns = useNamespace(\"tree-select\");\n watch(() => props.data, () => {\n if (props.filterable) {\n nextTick(() => {\n var _a, _b;\n (_b = tree.value) == null ? void 0 : _b.filter((_a = select.value) == null ? void 0 : _a.states.inputValue);\n });\n }\n }, {\n flush: \"post\"\n });\n const result = {\n ...pick(toRefs(props), Object.keys(ElSelect.props)),\n ...attrs,\n \"onUpdate:modelValue\": value => emit(UPDATE_MODEL_EVENT, value),\n valueKey: key,\n popperClass: computed(() => {\n const classes = [ns.e(\"popper\")];\n if (props.popperClass) classes.push(props.popperClass);\n return classes.join(\" \");\n }),\n filterMethod: (keyword = \"\") => {\n var _a;\n if (props.filterMethod) {\n props.filterMethod(keyword);\n } else if (props.remoteMethod) {\n props.remoteMethod(keyword);\n } else {\n (_a = tree.value) == null ? void 0 : _a.filter(keyword);\n }\n }\n };\n return result;\n};\nexport { useSelect };","map":{"version":3,"names":["useSelect","props","attrs","emit","select","tree","key","ns","useNamespace","watch","data","filterable","nextTick","_a","_b","value","filter","states","inputValue","flush","result","pick","toRefs","Object","keys","ElSelect","UPDATE_MODEL_EVENT","valueKey","popperClass","computed","classes","e","push","join","filterMethod","keyword","remoteMethod"],"sources":["../../../../../../packages/components/tree-select/src/select.ts"],"sourcesContent":["// @ts-nocheck\nimport { computed, nextTick, toRefs, watch } from 'vue'\nimport { pick } from 'lodash-unified'\nimport ElSelect from '@element-plus/components/select'\nimport { useNamespace } from '@element-plus/hooks'\nimport { UPDATE_MODEL_EVENT } from '@element-plus/constants'\nimport type { Ref } from 'vue'\nimport type ElTree from '@element-plus/components/tree'\n\nexport const useSelect = (\n props,\n { attrs, emit },\n {\n select,\n tree,\n key,\n }: {\n select: Ref<InstanceType<typeof ElSelect> | undefined>\n tree: Ref<InstanceType<typeof ElTree> | undefined>\n key: Ref<string>\n }\n) => {\n const ns = useNamespace('tree-select')\n\n // update tree data when use filterMethod/remoteMethod\n watch(\n () => props.data,\n () => {\n if (props.filterable) {\n nextTick(() => {\n // let tree node expand only, same with tree filter\n tree.value?.filter(select.value?.states.inputValue)\n })\n }\n },\n { flush: 'post' }\n )\n\n const result = {\n ...pick(toRefs(props), Object.keys(ElSelect.props)),\n ...attrs,\n // attrs is not reactive, when v-model binding source changes,\n // this listener is still old, see the bug(or test 'v-model source change'):\n // https://github.com/element-plus/element-plus/issues/14204\n 'onUpdate:modelValue': (value) => emit(UPDATE_MODEL_EVENT, value),\n valueKey: key,\n popperClass: computed(() => {\n const classes = [ns.e('popper')]\n if (props.popperClass) classes.push(props.popperClass)\n return classes.join(' ')\n }),\n filterMethod: (keyword = '') => {\n if (props.filterMethod) {\n props.filterMethod(keyword)\n } else if (props.remoteMethod) {\n props.remoteMethod(keyword)\n } else {\n // let tree node expand only, same with tree filter\n tree.value?.filter(keyword)\n }\n },\n }\n\n return result\n}\n"],"mappings":";;;;;AAKY,MAACA,SAAS,GAAGA,CAACC,KAAK,EAAE;EAAEC,KAAK;EAAEC;AAAI,CAAE,EAAE;EAChDC,MAAM;EACNC,IAAI;EACJC;AACF,CAAC,KAAK;EACJ,MAAMC,EAAE,GAAGC,YAAY,CAAC,aAAa,CAAC;EACtCC,KAAK,CAAC,MAAMR,KAAK,CAACS,IAAI,EAAE,MAAM;IAC5B,IAAIT,KAAK,CAACU,UAAU,EAAE;MACpBC,QAAQ,CAAC,MAAM;QACb,IAAIC,EAAE,EAAEC,EAAE;QACV,CAACA,EAAE,GAAGT,IAAI,CAACU,KAAK,KAAK,IAAI,GAAG,KAAK,CAAC,GAAGD,EAAE,CAAC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