UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 3.45 kB
{"version":3,"file":"tree-select.mjs","names":[],"sources":["../../../../../../packages/components/tree-select/src/tree-select.vue"],"sourcesContent":["<script lang=\"ts\">\nimport { computed, defineComponent, h, onMounted, reactive, ref } from 'vue'\nimport { pick } from 'lodash-unified'\nimport { ElSelect, selectProps } from '@element-plus/components/select'\nimport { ElTree, treeProps } from '@element-plus/components/tree'\nimport { useSelect } from './select'\nimport { useTree } from './tree'\nimport CacheOptions from './cache-options'\n\nimport type { TreeInstance } from '@element-plus/components/tree'\nimport type { SelectInstance } from '@element-plus/components/select'\n\nexport default defineComponent({\n name: 'ElTreeSelect',\n // disable `ElSelect` inherit current attrs\n inheritAttrs: false,\n props: {\n ...selectProps,\n ...treeProps,\n /**\n * @description The cached data of the lazy node, the structure is the same as the data, used to get the label of the unloaded data\n */\n cacheData: {\n type: Array,\n default: () => [],\n },\n },\n setup(props, context) {\n const { slots, expose, emit, attrs } = context\n const childAttrs = {\n ...attrs,\n onChange: undefined,\n }\n\n const select = ref<SelectInstance>()\n const tree = ref<TreeInstance>()\n\n const key = computed(() => props.nodeKey || props.valueKey || 'value')\n\n const selectProps = useSelect(props, { attrs, emit }, { select, tree, key })\n const { cacheOptions, ...treeProps } = useTree(\n props,\n { attrs: childAttrs, slots, emit },\n {\n select,\n tree,\n key,\n }\n )\n\n // expose ElTree/ElSelect methods\n const methods = reactive({})\n expose(methods)\n onMounted(() => {\n Object.assign(methods, {\n //TODO: let only tree and select in 3.0\n ...pick(tree.value, [\n 'filter',\n 'updateKeyChildren',\n 'getCheckedNodes',\n 'setCheckedNodes',\n 'getCheckedKeys',\n 'setCheckedKeys',\n 'setChecked',\n 'getHalfCheckedNodes',\n 'getHalfCheckedKeys',\n 'getCurrentKey',\n 'getCurrentNode',\n 'setCurrentKey',\n 'setCurrentNode',\n 'getNode',\n 'remove',\n 'append',\n 'insertBefore',\n 'insertAfter',\n ]),\n ...pick(select.value, ['focus', 'blur', 'selectedLabel']),\n treeRef: tree.value,\n selectRef: select.value,\n })\n })\n\n return () =>\n h(\n ElSelect,\n /**\n * 1. The `props` is processed into `Refs`, but `v-bind` and\n * render function props cannot read `Refs`, so use `reactive`\n * unwrap the `Refs` and keep reactive.\n * 2. The keyword `ref` requires `Ref`, but `reactive` broke it,\n * so use function.\n */\n reactive({\n ...selectProps,\n ref: (ref: SelectInstance) => (select.value = ref),\n }),\n {\n ...slots,\n default: () => [\n h(CacheOptions, { data: cacheOptions.value }),\n h(\n ElTree,\n reactive({\n ...treeProps,\n ref: (ref: TreeInstance) => (tree.value = ref),\n })\n ),\n ],\n }\n )\n },\n})\n</script>\n"],"mappings":""}