@opensig/opendesign
Version:
69 lines (68 loc) • 2.42 kB
JavaScript
;
const vue = require("vue");
const provide = require("./provide.js");
const types = require("./types.js");
const menu = require("./menu.js");
const is = require("../_utils/is.js");
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "OMenu",
props: types.menuProps,
emits: ["update:modelValue", "change", "update:expanded", "expanded-change"],
setup(__props, { emit: __emit }) {
const props = __props;
const emits = __emit;
const menuTree = new menu(NaN, null);
const { size, accordion, modelValue, defaultValue, expanded, defaultExpanded } = vue.toRefs(props);
const innerValue = vue.ref((modelValue == null ? void 0 : modelValue.value) ?? defaultValue.value);
const realValue = vue.computed(() => (modelValue == null ? void 0 : modelValue.value) ?? innerValue.value);
const updateModelValue = (val) => {
innerValue.value = val;
emits("update:modelValue", val);
emits("change", val);
};
const innerExpanded = vue.ref(is.isArray(expanded == null ? void 0 : expanded.value) ? expanded == null ? void 0 : expanded.value : defaultExpanded.value);
const realExpanded = vue.computed(() => {
if (is.isArray(expanded == null ? void 0 : expanded.value)) {
return expanded.value;
}
return innerExpanded.value;
});
const activeNodes = vue.ref([]);
const notifyTreeChange = () => {
activeNodes.value = menuTree.selectNode(realValue.value || "");
};
vue.watch(realValue, notifyTreeChange, { flush: "post" });
vue.onMounted(() => notifyTreeChange());
const updateExpanded = (val) => {
innerExpanded.value = val;
emits("update:expanded", val);
emits("expanded-change", val);
};
vue.provide(provide.menuInjectKey, {
size,
accordion,
realValue,
activeNodes,
realExpanded,
menuTree,
notifyTreeChange,
updateModelValue,
updateExpanded,
arrowPosition: vue.toRef(props, "arrowPosition")
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock(
"ul",
{
class: vue.normalizeClass(["o-menu", `o-menu-${vue.unref(size)}`, _ctx.arrowPosition && `o-menu-arrow-${_ctx.arrowPosition}`])
},
[
vue.renderSlot(_ctx.$slots, "default")
],
2
/* CLASS */
);
};
}
});
module.exports = _sfc_main;