UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 2.71 kB
{"version":3,"file":"tree-select-option.mjs","sources":["../../../../../../packages/components/tree-select/src/tree-select-option.ts"],"sourcesContent":["import { defineComponent, getCurrentInstance, nextTick, watch } from 'vue'\nimport { ElOption } from '@element-plus/components/select'\n\nconst component = defineComponent({\n extends: ElOption,\n setup(props, ctx) {\n const result = (ElOption.setup as NonNullable<any>)(props, ctx)\n\n // use methods.selectOptionClick\n delete result.selectOptionClick\n\n const vm = (getCurrentInstance() as NonNullable<any>).proxy\n\n // Fix: https://github.com/element-plus/element-plus/issues/7917\n // `el-option` will delete the cache before unmount,\n // This is normal for flat arrays `<el-select><el-option v-for=\"3\"></el-select>`,\n // Because the same node key does not create a difference node,\n // But in tree data, the same key at different levels will create diff nodes,\n // So the destruction of `el-option` in `nextTick` will be slower than\n // the creation of new `el-option`, which will delete the new node,\n // here restore the deleted node.\n // @link https://github.com/element-plus/element-plus/blob/6df6e49db07b38d6cc3b5e9a960782bd30879c11/packages/components/select/src/option.vue#L78\n nextTick(() => {\n if (!result.select.states.cachedOptions.get(vm.value)) {\n result.select.onOptionCreate(vm)\n }\n })\n\n watch(\n () => ctx.attrs.visible,\n (val) => {\n nextTick(() => {\n result.states.visible = val\n })\n },\n {\n immediate: true,\n }\n )\n\n return result\n },\n methods: {\n selectOptionClick() {\n // $el.parentElement => el-tree-node__content\n this.$el.parentElement.click()\n },\n },\n})\n\nexport default component\n"],"names":[],"mappings":";;;AAGA,MAAM,YAAY,eAAgB,CAAA;AAAA,EAChC,OAAS,EAAA,QAAA;AAAA,EACT,KAAA,CAAM,OAAO,GAAK,EAAA;AAChB,IAAA,MAAM,MAAU,GAAA,QAAA,CAAS,KAA2B,CAAA,KAAA,EAAO,GAAG,CAAA,CAAA;AAG9D,IAAA,OAAO,MAAO,CAAA,iBAAA,CAAA;AAEd,IAAM,MAAA,EAAA,GAAM,oBAA0C,CAAA,KAAA,CAAA;AAWtD,IAAA,QAAA,CAAS,MAAM;AACb,MAAI,IAAA,CAAC,OAAO,MAAO,CAAA,MAAA,CAAO,cAAc,GAAI,CAAA,EAAA,CAAG,KAAK,CAAG,EAAA;AACrD,QAAO,MAAA,CAAA,MAAA,CAAO,eAAe,EAAE,CAAA,CAAA;AAAA,OACjC;AAAA,KACD,CAAA,CAAA;AAED,IAAA,KAAA;AAAA,MACE,MAAM,IAAI,KAAM,CAAA,OAAA;AAAA,MAChB,CAAC,GAAQ,KAAA;AACP,QAAA,QAAA,CAAS,MAAM;AACb,UAAA,MAAA,CAAO,OAAO,OAAU,GAAA,GAAA,CAAA;AAAA,SACzB,CAAA,CAAA;AAAA,OACH;AAAA,MACA;AAAA,QACE,SAAW,EAAA,IAAA;AAAA,OACb;AAAA,KACF,CAAA;AAEA,IAAO,OAAA,MAAA,CAAA;AAAA,GACT;AAAA,EACA,OAAS,EAAA;AAAA,IACP,iBAAoB,GAAA;AAElB,MAAK,IAAA,CAAA,GAAA,CAAI,cAAc,KAAM,EAAA,CAAA;AAAA,KAC/B;AAAA,GACF;AACF,CAAC;;;;"}