code-monkey-ui
Version:
A Component Library for Vue 3
183 lines (178 loc) • 5.89 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var index = require('../../checkbox/index.js');
require('../../../hooks/index.js');
var useOption = require('./useOption.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var index$1 = require('../../../hooks/use-namespace/index.js');
var index$2 = require('../../../hooks/use-id/index.js');
const _sfc_main = vue.defineComponent({
name: "ElDshOption",
componentName: "ElDshOption",
components: {
ElCheckbox: index.ElCheckbox
},
props: {
value: {
required: true,
type: [String, Number, Boolean, Object]
},
label: [String, Number],
created: Boolean,
disabled: Boolean,
tip: [String, Number]
},
setup(props) {
const ns = index$1.useNamespace("dsh-select");
const id = index$2.useId();
const containerKls = vue.computed(() => [
ns.be("dropdown", "item"),
ns.is("disabled", vue.unref(isDisabled)),
{
selected: vue.unref(itemSelected),
hover: vue.unref(hover)
}
]);
const states = vue.reactive({
index: -1,
groupDisabled: false,
visible: true,
hitState: false,
hover: false
});
const {
currentLabel,
itemSelected,
isDisabled,
select,
currentTip,
hoverItem,
checkBoxRef,
currentValue,
onlyThis
} = useOption.useOption(props, states);
const { visible, hover } = vue.toRefs(states);
const vm = vue.getCurrentInstance().proxy;
select.onOptionCreate(vm);
vue.onBeforeUnmount(() => {
const key = vm.value;
const { selected } = select;
const selectedOptions = select.props.multiple ? selected : [selected];
const doesSelected = selectedOptions.some((item) => {
return item.value === vm.value;
});
vue.nextTick(() => {
if (select.cachedOptions.get(key) === vm && !doesSelected) {
select.cachedOptions.delete(key);
}
});
select.onOptionDestroy(key, vm);
});
const selectOptionClick = (value) => {
if (props.value === "select-all") {
select.handleOptionSelect("select-all");
vue.nextTick(() => {
value.target.className.includes("select-dropdown") && select.handleCheckAllChange(!select.checkAll);
select.resetCheckBoxValues();
});
return;
}
if (props.value === "reverse") {
select.handleOptionSelect("reverse");
vue.nextTick(() => {
select.resetCheckBoxValues();
});
return;
}
if (props.value === "select-hidden") {
select.handleOptionSelect("select-hidden");
vue.nextTick(() => {
select.resetCheckBoxValues();
});
return;
}
if (props.disabled !== true && states.groupDisabled !== true) {
select.handleOptionSelect(vm);
vue.nextTick(() => {
value.target.className.includes("select-dropdown") && [
select.resetCheckBoxValues(),
select.handleCheckedChange()
];
});
}
};
const onlyCheck = (event) => {
select.deleteSelected(event);
setTimeout(() => {
select.handleOptionSelect(vm);
vue.nextTick(() => {
select.resetCheckBoxValues();
select.handleCheckedChange();
select.handleConfirm();
});
});
};
return {
ns,
id,
containerKls,
currentLabel,
currentValue,
currentTip,
itemSelected,
isDisabled,
select,
hoverItem,
visible,
hover,
selectOptionClick,
states,
checkBoxRef,
onlyThis,
onlyCheck
};
}
});
const _hoisted_1 = ["id", "aria-disabled", "aria-selected"];
const _hoisted_2 = { class: "text-sub" };
const _hoisted_3 = /* @__PURE__ */ vue.createElementVNode("span", null, "\u4EC5\u7B5B\u9009\u6B64\u9879", -1);
const _hoisted_4 = [
_hoisted_3
];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_el_checkbox = vue.resolveComponent("el-checkbox");
return _ctx.visible ? (vue.openBlock(), vue.createElementBlock("li", {
key: 0,
id: _ctx.id,
class: vue.normalizeClass(_ctx.containerKls),
role: "option",
"aria-disabled": _ctx.isDisabled || void 0,
"aria-selected": _ctx.itemSelected,
onMouseenter: _cache[1] || (_cache[1] = (...args) => _ctx.hoverItem && _ctx.hoverItem(...args)),
onClick: _cache[2] || (_cache[2] = vue.withModifiers((...args) => _ctx.selectOptionClick && _ctx.selectOptionClick(...args), ["stop"]))
}, [
vue.renderSlot(_ctx.$slots, "default", {}, () => [
(vue.openBlock(), vue.createBlock(_component_el_checkbox, {
ref: "checkBoxRef",
key: _ctx.currentValue,
label: _ctx.currentValue,
onClick: vue.withModifiers(_ctx.selectOptionClick, ["stop"])
}, {
default: vue.withCtx(() => [
vue.createElementVNode("span", null, vue.toDisplayString(_ctx.currentLabel), 1),
vue.createElementVNode("span", _hoisted_2, vue.toDisplayString(_ctx.currentTip), 1)
]),
_: 1
}, 8, ["label", "onClick"])),
_ctx.onlyThis ? (vue.openBlock(), vue.createElementBlock("div", {
key: 0,
class: "select-tag",
onClick: _cache[0] || (_cache[0] = (...args) => _ctx.onlyCheck && _ctx.onlyCheck(...args))
}, _hoisted_4)) : vue.createCommentVNode("v-if", true)
])
], 42, _hoisted_1)) : vue.createCommentVNode("v-if", true);
}
var DshOption = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "D:\\project\\work\\code-monkey-ui\\packages\\components\\dsh-select\\src\\option.vue"]]);
exports["default"] = DshOption;
//# sourceMappingURL=option.js.map