This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
import CascaderPanel from './src/index.vue';
import type { SFCWithInstall } from 'element-plus/es/utils';
export declare const ElCascaderPanel: SFCWithInstall<typeof CascaderPanel>;
export default ElCascaderPanel;
export * from './src/types';
export * from './src/config';
export * from './src/instance';

View File

@@ -0,0 +1,20 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var index = require('./src/index.js');
var types = require('./src/types.js');
var config = require('./src/config.js');
var install = require('../../utils/vue/install.js');
const ElCascaderPanel = install.withInstall(index["default"]);
exports.CASCADER_PANEL_INJECTION_KEY = types.CASCADER_PANEL_INJECTION_KEY;
exports.CommonProps = config.CommonProps;
exports.DefaultProps = config.DefaultProps;
exports.cascaderPanelEmits = config.cascaderPanelEmits;
exports.cascaderPanelProps = config.cascaderPanelProps;
exports.useCascaderConfig = config.useCascaderConfig;
exports.ElCascaderPanel = ElCascaderPanel;
exports["default"] = ElCascaderPanel;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../../../../packages/components/cascader-panel/index.ts"],"sourcesContent":["import { withInstall } from '@element-plus/utils'\nimport CascaderPanel from './src/index.vue'\n\nimport type { SFCWithInstall } from '@element-plus/utils'\n\nexport const ElCascaderPanel: SFCWithInstall<typeof CascaderPanel> =\n withInstall(CascaderPanel)\n\nexport default ElCascaderPanel\nexport * from './src/types'\nexport * from './src/config'\nexport * from './src/instance'\n"],"names":["withInstall","CascaderPanel"],"mappings":";;;;;;;;;AAEY,MAAC,eAAe,GAAGA,mBAAW,CAACC,gBAAa;;;;;;;;;;;"}

View File

@@ -0,0 +1,55 @@
import type { PropType } from 'vue';
import type { CascaderConfig, CascaderNodePathValue, CascaderOption, CascaderProps, CascaderValue, RenderLabel } from './types';
export declare const CommonProps: {
readonly modelValue: {
readonly type: PropType<import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => string | number | Record<string, any> | CascaderNodePathValue | (import("./types").CascaderNodeValue | CascaderNodePathValue)[]) | (() => CascaderValue | null) | ((new (...args: any[]) => string | number | Record<string, any> | CascaderNodePathValue | (import("./types").CascaderNodeValue | CascaderNodePathValue)[]) | (() => CascaderValue | null))[], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly options: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => CascaderOption[]) | (() => CascaderOption[]) | ((new (...args: any[]) => CascaderOption[]) | (() => CascaderOption[]))[], unknown, unknown, () => CascaderOption[], boolean>;
readonly props: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => CascaderProps) | (() => CascaderProps) | ((new (...args: any[]) => CascaderProps) | (() => CascaderProps))[], unknown, unknown, () => CascaderProps, boolean>;
};
export declare const DefaultProps: CascaderConfig;
export declare const cascaderPanelProps: {
border: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, boolean, boolean>;
renderLabel: {
readonly type: PropType<RenderLabel>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
modelValue: {
readonly type: PropType<import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => string | number | Record<string, any> | CascaderNodePathValue | (import("./types").CascaderNodeValue | CascaderNodePathValue)[]) | (() => CascaderValue | null) | ((new (...args: any[]) => string | number | Record<string, any> | CascaderNodePathValue | (import("./types").CascaderNodeValue | CascaderNodePathValue)[]) | (() => CascaderValue | null))[], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
options: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => CascaderOption[]) | (() => CascaderOption[]) | ((new (...args: any[]) => CascaderOption[]) | (() => CascaderOption[]))[], unknown, unknown, () => CascaderOption[], boolean>;
props: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => CascaderProps) | (() => CascaderProps) | ((new (...args: any[]) => CascaderProps) | (() => CascaderProps))[], unknown, unknown, () => CascaderProps, boolean>;
};
export declare const cascaderPanelEmits: {
"update:modelValue": (value: CascaderValue | undefined | null) => boolean;
change: (value: CascaderValue | undefined | null) => boolean;
close: () => boolean;
'expand-change': (value: CascaderNodePathValue) => CascaderNodePathValue;
};
export declare const useCascaderConfig: (props: {
props: CascaderProps;
}) => import("vue").ComputedRef<{
expandTrigger: import("./types").ExpandTrigger;
multiple: boolean;
checkStrictly: boolean;
emitPath: boolean;
lazy: boolean;
lazyLoad: import("./types").LazyLoad;
value: string;
label: string;
children: string;
disabled: string | import("./types").isDisabled;
leaf: string | import("./types").isLeaf;
hoverThreshold: number;
checkOnClickNode: boolean;
checkOnClickLeaf: boolean;
showPrefix: boolean;
}>;

View File

@@ -0,0 +1,69 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var runtime = require('../../../utils/vue/props/runtime.js');
var shared = require('@vue/shared');
var event = require('../../../constants/event.js');
const CommonProps = runtime.buildProps({
modelValue: {
type: runtime.definePropType([Number, String, Array, Object])
},
options: {
type: runtime.definePropType(Array),
default: () => []
},
props: {
type: runtime.definePropType(Object),
default: () => ({})
}
});
const DefaultProps = {
expandTrigger: "click",
multiple: false,
checkStrictly: false,
emitPath: true,
lazy: false,
lazyLoad: shared.NOOP,
value: "value",
label: "label",
children: "children",
leaf: "leaf",
disabled: "disabled",
hoverThreshold: 500,
checkOnClickNode: false,
checkOnClickLeaf: true,
showPrefix: true
};
const cascaderPanelProps = runtime.buildProps({
...CommonProps,
border: {
type: Boolean,
default: true
},
renderLabel: {
type: Function
}
});
const emitChangeFn = (value) => true;
const cascaderPanelEmits = {
[event.UPDATE_MODEL_EVENT]: emitChangeFn,
[event.CHANGE_EVENT]: emitChangeFn,
close: () => true,
"expand-change": (value) => value
};
const useCascaderConfig = (props) => {
return vue.computed(() => ({
...DefaultProps,
...props.props
}));
};
exports.CommonProps = CommonProps;
exports.DefaultProps = DefaultProps;
exports.cascaderPanelEmits = cascaderPanelEmits;
exports.cascaderPanelProps = cascaderPanelProps;
exports.useCascaderConfig = useCascaderConfig;
//# sourceMappingURL=config.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,292 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var lodashUnified = require('lodash-unified');
var menu = require('./menu.js');
var store = require('./store.js');
var node = require('./node.js');
var config = require('./config.js');
var utils = require('./utils.js');
var types = require('./types.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var arrays = require('../../../utils/arrays.js');
var scroll = require('../../../utils/dom/scroll.js');
var aria$1 = require('../../../utils/dom/aria.js');
var index = require('../../../hooks/use-namespace/index.js');
var event = require('../../../constants/event.js');
var types$1 = require('../../../utils/types.js');
var core = require('@vueuse/core');
var aria = require('../../../constants/aria.js');
const __default__ = vue.defineComponent({
name: "ElCascaderPanel",
inheritAttrs: false
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
...__default__,
props: config.cascaderPanelProps,
emits: config.cascaderPanelEmits,
setup(__props, { expose, emit }) {
const props = __props;
let manualChecked = false;
const ns = index.useNamespace("cascader");
const config$1 = config.useCascaderConfig(props);
const slots = vue.useSlots();
let store$1;
const initialLoaded = vue.ref(true);
const menuList = vue.ref([]);
const checkedValue = vue.ref();
const menus = vue.ref([]);
const expandingNode = vue.ref();
const checkedNodes = vue.ref([]);
const isHoverMenu = vue.computed(() => config$1.value.expandTrigger === "hover");
const renderLabelFn = vue.computed(() => props.renderLabel || slots.default);
const initStore = () => {
const { options } = props;
const cfg = config$1.value;
manualChecked = false;
store$1 = new store["default"](options, cfg);
menus.value = [store$1.getNodes()];
if (cfg.lazy && types$1.isEmpty(props.options)) {
initialLoaded.value = false;
lazyLoad(void 0, (list) => {
if (list) {
store$1 = new store["default"](list, cfg);
menus.value = [store$1.getNodes()];
}
initialLoaded.value = true;
syncCheckedValue(false, true);
});
} else {
syncCheckedValue(false, true);
}
};
const lazyLoad = (node$1, cb) => {
const cfg = config$1.value;
node$1 = node$1 || new node["default"]({}, cfg, void 0, true);
node$1.loading = true;
const resolve = (dataList) => {
const _node = node$1;
const parent = _node.root ? null : _node;
_node.loading = false;
_node.loaded = true;
_node.childrenData = _node.childrenData || [];
dataList && (store$1 == null ? void 0 : store$1.appendNodes(dataList, parent));
dataList && (cb == null ? void 0 : cb(dataList));
};
cfg.lazyLoad(node$1, resolve);
};
const expandNode = (node, silent) => {
var _a;
const { level } = node;
const newMenus = menus.value.slice(0, level);
let newExpandingNode;
if (node.isLeaf) {
newExpandingNode = node.pathNodes[level - 2];
} else {
newExpandingNode = node;
newMenus.push(node.children);
}
if (((_a = expandingNode.value) == null ? void 0 : _a.uid) !== (newExpandingNode == null ? void 0 : newExpandingNode.uid)) {
expandingNode.value = node;
menus.value = newMenus;
!silent && emit("expand-change", (node == null ? void 0 : node.pathValues) || []);
}
};
const handleCheckChange = (node, checked, emitClose = true) => {
const { checkStrictly, multiple } = config$1.value;
const oldNode = checkedNodes.value[0];
manualChecked = true;
!multiple && (oldNode == null ? void 0 : oldNode.doCheck(false));
node.doCheck(checked);
calculateCheckedValue();
emitClose && !multiple && !checkStrictly && emit("close");
!emitClose && !multiple && !checkStrictly && expandParentNode(node);
};
const expandParentNode = (node) => {
if (!node)
return;
node = node.parent;
expandParentNode(node);
node && expandNode(node);
};
const getFlattedNodes = (leafOnly) => store$1 == null ? void 0 : store$1.getFlattedNodes(leafOnly);
const getCheckedNodes = (leafOnly) => {
var _a;
return (_a = getFlattedNodes(leafOnly)) == null ? void 0 : _a.filter(({ checked }) => checked !== false);
};
const clearCheckedNodes = () => {
checkedNodes.value.forEach((node) => node.doCheck(false));
calculateCheckedValue();
menus.value = menus.value.slice(0, 1);
expandingNode.value = void 0;
emit("expand-change", []);
};
const calculateCheckedValue = () => {
var _a;
const { checkStrictly, multiple } = config$1.value;
const oldNodes = checkedNodes.value;
const newNodes = getCheckedNodes(!checkStrictly);
const nodes = utils.sortByOriginalOrder(oldNodes, newNodes);
const values = nodes.map((node) => node.valueByOption);
checkedNodes.value = nodes;
checkedValue.value = multiple ? values : (_a = values[0]) != null ? _a : null;
};
const syncCheckedValue = (loaded = false, forced = false) => {
const { modelValue } = props;
const { lazy, multiple, checkStrictly } = config$1.value;
const leafOnly = !checkStrictly;
if (!initialLoaded.value || manualChecked || !forced && lodashUnified.isEqual(modelValue, checkedValue.value))
return;
if (lazy && !loaded) {
const values = arrays.unique(lodashUnified.flattenDeep(arrays.castArray(modelValue)));
const nodes = values.map((val) => store$1 == null ? void 0 : store$1.getNodeByValue(val)).filter((node) => !!node && !node.loaded && !node.loading);
if (nodes.length) {
nodes.forEach((node) => {
lazyLoad(node, () => syncCheckedValue(false, forced));
});
} else {
syncCheckedValue(true, forced);
}
} else {
const values = multiple ? arrays.castArray(modelValue) : [modelValue];
const nodes = arrays.unique(values.map((val) => store$1 == null ? void 0 : store$1.getNodeByValue(val, leafOnly)));
syncMenuState(nodes, forced);
checkedValue.value = lodashUnified.cloneDeep(modelValue != null ? modelValue : void 0);
}
};
const syncMenuState = (newCheckedNodes, reserveExpandingState = true) => {
const { checkStrictly } = config$1.value;
const oldNodes = checkedNodes.value;
const newNodes = newCheckedNodes.filter((node) => !!node && (checkStrictly || node.isLeaf));
const oldExpandingNode = store$1 == null ? void 0 : store$1.getSameNode(expandingNode.value);
const newExpandingNode = reserveExpandingState && oldExpandingNode || newNodes[0];
if (newExpandingNode) {
newExpandingNode.pathNodes.forEach((node) => expandNode(node, true));
} else {
expandingNode.value = void 0;
}
oldNodes.forEach((node) => node.doCheck(false));
vue.reactive(newNodes).forEach((node) => node.doCheck(true));
checkedNodes.value = newNodes;
vue.nextTick(scrollToExpandingNode);
};
const scrollToExpandingNode = () => {
if (!core.isClient)
return;
menuList.value.forEach((menu) => {
const menuElement = menu == null ? void 0 : menu.$el;
if (menuElement) {
const container = menuElement.querySelector(`.${ns.namespace.value}-scrollbar__wrap`);
const activeNode = menuElement.querySelector(`.${ns.b("node")}.${ns.is("active")}:last-child`) || menuElement.querySelector(`.${ns.b("node")}.in-active-path`);
scroll.scrollIntoView(container, activeNode);
}
});
};
const handleKeyDown = (e) => {
const target = e.target;
const { code } = e;
switch (code) {
case aria.EVENT_CODE.up:
case aria.EVENT_CODE.down: {
e.preventDefault();
const distance = code === aria.EVENT_CODE.up ? -1 : 1;
aria$1.focusNode(aria$1.getSibling(target, distance, `.${ns.b("node")}[tabindex="-1"]`));
break;
}
case aria.EVENT_CODE.left: {
e.preventDefault();
const preMenu = menuList.value[utils.getMenuIndex(target) - 1];
const expandedNode = preMenu == null ? void 0 : preMenu.$el.querySelector(`.${ns.b("node")}[aria-expanded="true"]`);
aria$1.focusNode(expandedNode);
break;
}
case aria.EVENT_CODE.right: {
e.preventDefault();
const nextMenu = menuList.value[utils.getMenuIndex(target) + 1];
const firstNode = nextMenu == null ? void 0 : nextMenu.$el.querySelector(`.${ns.b("node")}[tabindex="-1"]`);
aria$1.focusNode(firstNode);
break;
}
case aria.EVENT_CODE.enter:
case aria.EVENT_CODE.numpadEnter:
utils.checkNode(target);
break;
}
};
vue.provide(types.CASCADER_PANEL_INJECTION_KEY, vue.reactive({
config: config$1,
expandingNode,
checkedNodes,
isHoverMenu,
initialLoaded,
renderLabelFn,
lazyLoad,
expandNode,
handleCheckChange
}));
vue.watch(config$1, (newVal, oldVal) => {
if (lodashUnified.isEqual(newVal, oldVal))
return;
initStore();
}, {
immediate: true
});
vue.watch(() => props.options, initStore, {
deep: true
});
vue.watch(() => props.modelValue, () => {
manualChecked = false;
syncCheckedValue();
}, {
deep: true
});
vue.watch(() => checkedValue.value, (val) => {
if (!lodashUnified.isEqual(val, props.modelValue)) {
emit(event.UPDATE_MODEL_EVENT, val);
emit(event.CHANGE_EVENT, val);
}
});
vue.onBeforeUpdate(() => menuList.value = []);
vue.onMounted(() => !types$1.isEmpty(props.modelValue) && syncCheckedValue());
expose({
menuList,
menus,
checkedNodes,
handleKeyDown,
handleCheckChange,
getFlattedNodes,
getCheckedNodes,
clearCheckedNodes,
calculateCheckedValue,
scrollToExpandingNode
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div", {
class: vue.normalizeClass([vue.unref(ns).b("panel"), vue.unref(ns).is("bordered", _ctx.border)]),
onKeydown: handleKeyDown
}, [
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(menus.value, (menu$1, index) => {
return vue.openBlock(), vue.createBlock(menu["default"], {
key: index,
ref_for: true,
ref: (item) => menuList.value[index] = item,
index,
nodes: [...menu$1]
}, {
empty: vue.withCtx(() => [
vue.renderSlot(_ctx.$slots, "empty")
]),
_: 2
}, 1032, ["index", "nodes"]);
}), 128))
], 34);
};
}
});
var CascaderPanel = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "index.vue"]]);
exports["default"] = CascaderPanel;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,197 @@
import Node from './node';
import type { CascaderNodeValue, CascaderOption, CascaderValue } from './types';
import type { CascaderMenuInstance } from './instance';
declare function __VLS_template(): {
empty?(_: {}): any;
};
declare const __VLS_component: import("vue").DefineComponent<{
border: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, boolean, boolean>;
renderLabel: {
readonly type: import("vue").PropType<import("./types").RenderLabel>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
modelValue: {
readonly type: import("vue").PropType<import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => string | number | Record<string, any> | import("./types").CascaderNodePathValue | (CascaderNodeValue | import("./types").CascaderNodePathValue)[]) | (() => CascaderValue | null) | ((new (...args: any[]) => string | number | Record<string, any> | import("./types").CascaderNodePathValue | (CascaderNodeValue | import("./types").CascaderNodePathValue)[]) | (() => CascaderValue | null))[], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
options: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => CascaderOption[]) | (() => CascaderOption[]) | ((new (...args: any[]) => CascaderOption[]) | (() => CascaderOption[]))[], unknown, unknown, () => CascaderOption[], boolean>;
props: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => import("./types").CascaderProps) | (() => import("./types").CascaderProps) | ((new (...args: any[]) => import("./types").CascaderProps) | (() => import("./types").CascaderProps))[], unknown, unknown, () => import("./types").CascaderProps, boolean>;
}, {
menuList: import("vue").Ref<CascaderMenuInstance[]>;
menus: import("vue").Ref<{
readonly uid: number;
readonly level: number;
readonly value: CascaderNodeValue;
readonly label: string;
readonly pathNodes: any[];
readonly pathValues: CascaderNodeValue[];
readonly pathLabels: string[];
childrenData: {
[x: string]: unknown;
label?: string | undefined;
value?: CascaderNodeValue | undefined;
children?: any[] | undefined;
disabled?: boolean | undefined;
leaf?: boolean | undefined;
}[] | undefined;
children: any[];
text: string;
loaded: boolean;
checked: boolean;
indeterminate: boolean;
loading: boolean;
readonly data: {
[x: string]: unknown;
label?: string | undefined;
value?: CascaderNodeValue | undefined;
children?: any[] | undefined;
disabled?: boolean | undefined;
leaf?: boolean | undefined;
};
readonly config: {
expandTrigger: import("./types").ExpandTrigger;
multiple: boolean;
checkStrictly: boolean;
emitPath: boolean;
lazy: boolean;
lazyLoad: import("./types").LazyLoad;
value: string;
label: string;
children: string;
disabled: string | import("./types").isDisabled;
leaf: string | import("./types").isLeaf;
hoverThreshold: number;
checkOnClickNode: boolean;
checkOnClickLeaf: boolean;
showPrefix: boolean;
};
readonly parent?: any | undefined;
readonly root: boolean;
readonly isDisabled: boolean;
readonly isLeaf: boolean;
readonly valueByOption: CascaderNodeValue | CascaderNodeValue[];
appendChild: (childData: CascaderOption) => Node;
calcText: (allLevels: boolean, separator: string) => string;
broadcast: (checked: boolean) => void;
emit: () => void;
onParentCheck: (checked: boolean) => void;
onChildCheck: () => void;
setCheckState: (checked: boolean) => void;
doCheck: (checked: boolean) => void;
}[][]>;
checkedNodes: import("vue").Ref<{
readonly uid: number;
readonly level: number;
readonly value: CascaderNodeValue;
readonly label: string;
readonly pathNodes: any[];
readonly pathValues: CascaderNodeValue[];
readonly pathLabels: string[];
childrenData: {
[x: string]: unknown;
label?: string | undefined;
value?: CascaderNodeValue | undefined;
children?: any[] | undefined;
disabled?: boolean | undefined;
leaf?: boolean | undefined;
}[] | undefined;
children: any[];
text: string;
loaded: boolean;
checked: boolean;
indeterminate: boolean;
loading: boolean;
readonly data: {
[x: string]: unknown;
label?: string | undefined;
value?: CascaderNodeValue | undefined;
children?: any[] | undefined;
disabled?: boolean | undefined;
leaf?: boolean | undefined;
};
readonly config: {
expandTrigger: import("./types").ExpandTrigger;
multiple: boolean;
checkStrictly: boolean;
emitPath: boolean;
lazy: boolean;
lazyLoad: import("./types").LazyLoad;
value: string;
label: string;
children: string;
disabled: string | import("./types").isDisabled;
leaf: string | import("./types").isLeaf;
hoverThreshold: number;
checkOnClickNode: boolean;
checkOnClickLeaf: boolean;
showPrefix: boolean;
};
readonly parent?: any | undefined;
readonly root: boolean;
readonly isDisabled: boolean;
readonly isLeaf: boolean;
readonly valueByOption: CascaderNodeValue | CascaderNodeValue[];
appendChild: (childData: CascaderOption) => Node;
calcText: (allLevels: boolean, separator: string) => string;
broadcast: (checked: boolean) => void;
emit: () => void;
onParentCheck: (checked: boolean) => void;
onChildCheck: () => void;
setCheckState: (checked: boolean) => void;
doCheck: (checked: boolean) => void;
}[]>;
handleKeyDown: (e: KeyboardEvent) => void;
handleCheckChange: (node: Node, checked: boolean, emitClose?: boolean) => void;
getFlattedNodes: (leafOnly: boolean) => Node[];
/**
* @description get an array of currently selected node,(leafOnly) whether only return the leaf checked nodes, default is `false`
*/
getCheckedNodes: (leafOnly: boolean) => Node[];
/**
* @description clear checked nodes
*/
clearCheckedNodes: () => void;
calculateCheckedValue: () => void;
scrollToExpandingNode: () => void;
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
"update:modelValue": (value: CascaderValue | null | undefined) => void;
change: (value: CascaderValue | null | undefined) => void;
close: () => void;
"expand-change": (value: import("./types").CascaderNodePathValue) => void;
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
border: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, boolean, boolean>;
renderLabel: {
readonly type: import("vue").PropType<import("./types").RenderLabel>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
modelValue: {
readonly type: import("vue").PropType<import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => string | number | Record<string, any> | import("./types").CascaderNodePathValue | (CascaderNodeValue | import("./types").CascaderNodePathValue)[]) | (() => CascaderValue | null) | ((new (...args: any[]) => string | number | Record<string, any> | import("./types").CascaderNodePathValue | (CascaderNodeValue | import("./types").CascaderNodePathValue)[]) | (() => CascaderValue | null))[], unknown, unknown>>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
options: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => CascaderOption[]) | (() => CascaderOption[]) | ((new (...args: any[]) => CascaderOption[]) | (() => CascaderOption[]))[], unknown, unknown, () => CascaderOption[], boolean>;
props: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => import("./types").CascaderProps) | (() => import("./types").CascaderProps) | ((new (...args: any[]) => import("./types").CascaderProps) | (() => import("./types").CascaderProps))[], unknown, unknown, () => import("./types").CascaderProps, boolean>;
}>> & {
"onUpdate:modelValue"?: ((value: CascaderValue | null | undefined) => any) | undefined;
onChange?: ((value: CascaderValue | null | undefined) => any) | undefined;
onClose?: (() => any) | undefined;
"onExpand-change"?: ((value: import("./types").CascaderNodePathValue) => any) | undefined;
}, {
border: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
props: import("./types").CascaderProps;
options: CascaderOption[];
}>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
export default _default;
type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
$slots: S;
};
};

View File

@@ -0,0 +1,4 @@
import type CascaderPanel from './index.vue';
import type Menu from './menu.vue';
export type CascaderMenuInstance = InstanceType<typeof Menu> & unknown;
export type CascaderPanelInstance = InstanceType<typeof CascaderPanel> & unknown;

View File

@@ -0,0 +1,3 @@
'use strict';
//# sourceMappingURL=instance.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"instance.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}

View File

@@ -0,0 +1,139 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var index$3 = require('../../scrollbar/index.js');
var iconsVue = require('@element-plus/icons-vue');
var index$4 = require('../../icon/index.js');
var node = require('./node2.js');
var types = require('./types.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var index = require('../../../hooks/use-namespace/index.js');
var index$1 = require('../../../hooks/use-locale/index.js');
var index$2 = require('../../../hooks/use-id/index.js');
const __default__ = vue.defineComponent({
name: "ElCascaderMenu"
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
...__default__,
props: {
nodes: {
type: Array,
required: true
},
index: {
type: Number,
required: true
}
},
setup(__props) {
const props = __props;
const instance = vue.getCurrentInstance();
const ns = index.useNamespace("cascader-menu");
const { t } = index$1.useLocale();
const id = index$2.useId();
let activeNode;
let hoverTimer;
const panel = vue.inject(types.CASCADER_PANEL_INJECTION_KEY);
const hoverZone = vue.ref();
const isEmpty = vue.computed(() => !props.nodes.length);
const isLoading = vue.computed(() => !panel.initialLoaded);
const menuId = vue.computed(() => `${id.value}-${props.index}`);
const handleExpand = (e) => {
activeNode = e.target;
};
const handleMouseMove = (e) => {
if (!panel.isHoverMenu || !activeNode || !hoverZone.value)
return;
if (activeNode.contains(e.target)) {
clearHoverTimer();
const el = instance.vnode.el;
const { left } = el.getBoundingClientRect();
const { offsetWidth, offsetHeight } = el;
const startX = e.clientX - left;
const top = activeNode.offsetTop;
const bottom = top + activeNode.offsetHeight;
hoverZone.value.innerHTML = `
<path style="pointer-events: auto;" fill="transparent" d="M${startX} ${top} L${offsetWidth} 0 V${top} Z" />
<path style="pointer-events: auto;" fill="transparent" d="M${startX} ${bottom} L${offsetWidth} ${offsetHeight} V${bottom} Z" />
`;
} else if (!hoverTimer) {
hoverTimer = window.setTimeout(clearHoverZone, panel.config.hoverThreshold);
}
};
const clearHoverTimer = () => {
if (!hoverTimer)
return;
clearTimeout(hoverTimer);
hoverTimer = void 0;
};
const clearHoverZone = () => {
if (!hoverZone.value)
return;
hoverZone.value.innerHTML = "";
clearHoverTimer();
};
return (_ctx, _cache) => {
return vue.openBlock(), vue.createBlock(vue.unref(index$3.ElScrollbar), {
key: vue.unref(menuId),
tag: "ul",
role: "menu",
class: vue.normalizeClass(vue.unref(ns).b()),
"wrap-class": vue.unref(ns).e("wrap"),
"view-class": [vue.unref(ns).e("list"), vue.unref(ns).is("empty", vue.unref(isEmpty))],
onMousemove: handleMouseMove,
onMouseleave: clearHoverZone
}, {
default: vue.withCtx(() => {
var _a;
return [
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(__props.nodes, (node$1) => {
return vue.openBlock(), vue.createBlock(node["default"], {
key: node$1.uid,
node: node$1,
"menu-id": vue.unref(menuId),
onExpand: handleExpand
}, null, 8, ["node", "menu-id"]);
}), 128)),
vue.unref(isLoading) ? (vue.openBlock(), vue.createElementBlock("div", {
key: 0,
class: vue.normalizeClass(vue.unref(ns).e("empty-text"))
}, [
vue.createVNode(vue.unref(index$4.ElIcon), {
size: "14",
class: vue.normalizeClass(vue.unref(ns).is("loading"))
}, {
default: vue.withCtx(() => [
vue.createVNode(vue.unref(iconsVue.Loading))
]),
_: 1
}, 8, ["class"]),
vue.createTextVNode(" " + vue.toDisplayString(vue.unref(t)("el.cascader.loading")), 1)
], 2)) : vue.unref(isEmpty) ? (vue.openBlock(), vue.createElementBlock("div", {
key: 1,
class: vue.normalizeClass(vue.unref(ns).e("empty-text"))
}, [
vue.renderSlot(_ctx.$slots, "empty", {}, () => [
vue.createTextVNode(vue.toDisplayString(vue.unref(t)("el.cascader.noData")), 1)
])
], 2)) : ((_a = vue.unref(panel)) == null ? void 0 : _a.isHoverMenu) ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 2 }, [
vue.createCommentVNode(" eslint-disable-next-line vue/html-self-closing "),
(vue.openBlock(), vue.createElementBlock("svg", {
ref_key: "hoverZone",
ref: hoverZone,
class: vue.normalizeClass(vue.unref(ns).e("hover-zone"))
}, null, 2))
], 2112)) : vue.createCommentVNode("v-if", true)
];
}),
_: 3
}, 8, ["class", "wrap-class", "view-class"]);
};
}
});
var ElCascaderMenu = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "menu.vue"]]);
exports["default"] = ElCascaderMenu;
//# sourceMappingURL=menu.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,31 @@
import type { CascaderNode } from './types';
import type { PropType } from 'vue';
declare function __VLS_template(): {
empty?(_: {}): any;
};
declare const __VLS_component: import("vue").DefineComponent<{
nodes: {
type: PropType<CascaderNode[]>;
required: true;
};
index: {
type: NumberConstructor;
required: true;
};
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
nodes: {
type: PropType<CascaderNode[]>;
required: true;
};
index: {
type: NumberConstructor;
required: true;
};
}>>, {}>;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
export default _default;
type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
$slots: S;
};
};

View File

@@ -0,0 +1,14 @@
import type { PropType } from 'vue';
import type { CascaderNode } from './types';
declare const _default: import("vue").DefineComponent<{
node: {
type: PropType<CascaderNode>;
required: true;
};
}, () => JSX.Element, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
node: {
type: PropType<CascaderNode>;
required: true;
};
}>>, {}>;
export default _default;

View File

@@ -0,0 +1,49 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var types = require('./types.js');
var index = require('../../../hooks/use-namespace/index.js');
var shared = require('@vue/shared');
function isVNodeEmpty(vnodes) {
return !!(shared.isArray(vnodes) ? vnodes.every(({
type
}) => type === vue.Comment) : (vnodes == null ? void 0 : vnodes.type) === vue.Comment);
}
var NodeContent = vue.defineComponent({
name: "NodeContent",
props: {
node: {
type: Object,
required: true
}
},
setup(props) {
const ns = index.useNamespace("cascader-node");
const {
renderLabelFn
} = vue.inject(types.CASCADER_PANEL_INJECTION_KEY);
const {
node
} = props;
const {
data,
label: nodeLabel
} = node;
const label = () => {
const renderLabel = renderLabelFn == null ? void 0 : renderLabelFn({
node,
data
});
return isVNodeEmpty(renderLabel) ? nodeLabel : renderLabel != null ? renderLabel : nodeLabel;
};
return () => vue.createVNode("span", {
"class": ns.e("label")
}, [label()]);
}
});
exports["default"] = NodeContent;
//# sourceMappingURL=node-content.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"node-content.js","sources":["../../../../../../packages/components/cascader-panel/src/node-content.tsx"],"sourcesContent":["import { Comment, defineComponent, inject } from 'vue'\nimport { useNamespace } from '@element-plus/hooks'\nimport { isArray } from '@element-plus/utils'\nimport { CASCADER_PANEL_INJECTION_KEY } from './types'\n\nimport type { PropType, VNode } from 'vue'\nimport type { CascaderNode } from './types'\n\nfunction isVNodeEmpty(vnodes?: VNode[] | VNode) {\n return !!(isArray(vnodes)\n ? vnodes.every(({ type }) => type === Comment)\n : vnodes?.type === Comment)\n}\n\nexport default defineComponent({\n name: 'NodeContent',\n props: {\n node: {\n type: Object as PropType<CascaderNode>,\n required: true,\n },\n },\n setup(props) {\n const ns = useNamespace('cascader-node')\n const { renderLabelFn } = inject(CASCADER_PANEL_INJECTION_KEY)!\n const { node } = props\n const { data, label: nodeLabel } = node\n\n const label = () => {\n const renderLabel = renderLabelFn?.({ node, data })\n return isVNodeEmpty(renderLabel) ? nodeLabel : renderLabel ?? nodeLabel\n }\n return () => <span class={ns.e('label')}>{label()}</span>\n },\n})\n"],"names":["isVNodeEmpty","vnodes","type","defineComponent","name","props","node","required","useNamespace","inject","renderLabelFn","label","nodeLabel","renderLabel","data"],"mappings":";;;;;;;;;;AAQA,EAASA,OAAAA,CAAAA,EAAAA,cAAAA,CAAAA,MAAaC,CAAAA,GAA0B,MAAA,CAAA,KAAA,CAAA,CAAA;IACvC,IAAA;AACaC,GAAAA,KAAAA,IAAAA,KAAAA,WAAAA,CAAAA,GAAAA,CAAAA,MAAAA,IAAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,MAAAA,CAAAA,IAAAA,MAAAA,WAAAA,CAAAA,CAAAA;;AAErB,kBAAAC,mBAAA,CAAA;;AAED,EAAA,KAAA,EAAA;AACEC,IAAAA,IAAM,EADuB;AAE7BC,MAAAA,IAAO,EAAA,MAAA;AACLC,MAAAA,QAAM,EAAA,IAAA;AACJJ,KAAAA;AACAK,GAAAA;AAFI,EAAA,KAAA,CAAA,KAAA,EAAA;IAHqB,MAAA,EAAA,GAAAC,kBAAA,CAAA,eAAA,CAAA,CAAA;;MAQxB,aAAQ;AACX,KAAA,GAAAC,UAAQ,CAAGD,kCAAY,CAAvB,CAAA;IACA,MAAM;AAAEE,MAAAA,IAAAA;KAAkBD,GAAAA,KAAAA,CAAM;IAChC,MAAM;AAAEH,MAAAA,IAAAA;AAAF,MAAA,KAAN,EAAA,SAAA;KACM,GAAA,IAAA,CAAA;UAAA,KAAA,GAAA,MAAA;AAAQK,MAAAA,MAAOC,WAAAA,GAAAA,aAAAA,IAAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,aAAAA,CAAAA;AAAf,QAA6BN,IAAnC;;OAEMK,CAAAA,CAAAA;MACJ,OAAME,YAAcH,CAAAA,WAAAA,CAAAA,GAAgB,SAAA,GAAA,WAAA,IAAA,IAAA,GAAA,WAAA,GAAA,SAAA,CAAA;;AAAQI,IAAAA,OAAAA,MAAAA,eAAAA,CAAAA,MAAAA,EAAAA;AAAR,MAAA,OAApC,EAAA,EAAA,CAAA,CAAA,CAAA,OAAA,CAAA;OACOd,CAAAA,KAAAA,EAAAA,CAAAA,CAAAA,CAAAA;;;;;;"}

View File

@@ -0,0 +1,50 @@
import type { CascaderConfig, CascaderNodePathValue, CascaderNodeValue, CascaderOption } from './types';
type ChildrenData = CascaderOption[] | undefined;
declare class Node {
readonly data: CascaderOption;
readonly config: CascaderConfig;
readonly parent?: Node | undefined;
readonly root: boolean;
readonly uid: number;
readonly level: number;
readonly value: CascaderNodeValue;
readonly label: string;
readonly pathNodes: Node[];
readonly pathValues: CascaderNodePathValue;
readonly pathLabels: string[];
childrenData: ChildrenData;
children: Node[];
text: string;
loaded: boolean;
/**
* Is it checked
*
* @default false
*/
checked: boolean;
/**
* Used to indicate the intermediate state of unchecked and fully checked child nodes
*
* @default false
*/
indeterminate: boolean;
/**
* Loading Status
*
* @default false
*/
loading: boolean;
constructor(data: CascaderOption, config: CascaderConfig, parent?: Node | undefined, root?: boolean);
get isDisabled(): boolean;
get isLeaf(): boolean;
get valueByOption(): CascaderNodeValue | CascaderNodePathValue;
appendChild(childData: CascaderOption): Node;
calcText(allLevels: boolean, separator: string): string;
broadcast(checked: boolean): void;
emit(): void;
onParentCheck(checked: boolean): void;
onChildCheck(): void;
setCheckState(checked: boolean): void;
doCheck(checked: boolean): void;
}
export default Node;

View File

@@ -0,0 +1,125 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var types = require('../../../utils/types.js');
var shared = require('@vue/shared');
let uid = 0;
const calculatePathNodes = (node) => {
const nodes = [node];
let { parent } = node;
while (parent) {
nodes.unshift(parent);
parent = parent.parent;
}
return nodes;
};
class Node {
constructor(data, config, parent, root = false) {
this.data = data;
this.config = config;
this.parent = parent;
this.root = root;
this.uid = uid++;
this.checked = false;
this.indeterminate = false;
this.loading = false;
const { value: valueKey, label: labelKey, children: childrenKey } = config;
const childrenData = data[childrenKey];
const pathNodes = calculatePathNodes(this);
this.level = root ? 0 : parent ? parent.level + 1 : 1;
this.value = data[valueKey];
this.label = data[labelKey];
this.pathNodes = pathNodes;
this.pathValues = pathNodes.map((node) => node.value);
this.pathLabels = pathNodes.map((node) => node.label);
this.childrenData = childrenData;
this.children = (childrenData || []).map((child) => new Node(child, config, this));
this.loaded = !config.lazy || this.isLeaf || !types.isEmpty(childrenData);
this.text = "";
}
get isDisabled() {
const { data, parent, config } = this;
const { disabled, checkStrictly } = config;
const isDisabled = shared.isFunction(disabled) ? disabled(data, this) : !!data[disabled];
return isDisabled || !checkStrictly && !!(parent == null ? void 0 : parent.isDisabled);
}
get isLeaf() {
const { data, config, childrenData, loaded } = this;
const { lazy, leaf } = config;
const isLeaf = shared.isFunction(leaf) ? leaf(data, this) : data[leaf];
return types.isUndefined(isLeaf) ? lazy && !loaded ? false : !(shared.isArray(childrenData) && childrenData.length) : !!isLeaf;
}
get valueByOption() {
return this.config.emitPath ? this.pathValues : this.value;
}
appendChild(childData) {
const { childrenData, children } = this;
const node = new Node(childData, this.config, this);
if (shared.isArray(childrenData)) {
childrenData.push(childData);
} else {
this.childrenData = [childData];
}
children.push(node);
return node;
}
calcText(allLevels, separator) {
const text = allLevels ? this.pathLabels.join(separator) : this.label;
this.text = text;
return text;
}
broadcast(checked) {
this.children.forEach((child) => {
var _a;
if (child) {
child.broadcast(checked);
(_a = child.onParentCheck) == null ? void 0 : _a.call(child, checked);
}
});
}
emit() {
var _a;
const { parent } = this;
if (parent) {
(_a = parent.onChildCheck) == null ? void 0 : _a.call(parent);
parent.emit();
}
}
onParentCheck(checked) {
if (!this.isDisabled) {
this.setCheckState(checked);
}
}
onChildCheck() {
const { children } = this;
const validChildren = children.filter((child) => !child.isDisabled);
const checked = validChildren.length ? validChildren.every((child) => child.checked) : false;
this.setCheckState(checked);
}
setCheckState(checked) {
const totalNum = this.children.length;
const checkedNum = this.children.reduce((c, p) => {
const num = p.checked ? 1 : p.indeterminate ? 0.5 : 0;
return c + num;
}, 0);
this.checked = this.loaded && this.children.filter((child) => !child.isDisabled).every((child) => child.loaded && child.checked) && checked;
this.indeterminate = this.loaded && checkedNum !== totalNum && checkedNum > 0;
}
doCheck(checked) {
if (this.checked === checked)
return;
const { checkStrictly, multiple } = this.config;
if (checkStrictly || !multiple) {
this.checked = checked;
} else {
this.broadcast(checked);
this.setCheckState(checked);
this.emit();
}
}
}
exports["default"] = Node;
//# sourceMappingURL=node.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,20 @@
import type { CascaderNode } from './types';
import type { PropType } from 'vue';
declare const _default: import("vue").DefineComponent<{
node: {
type: PropType<CascaderNode>;
required: true;
};
menuId: StringConstructor;
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
expand: (...args: any[]) => void;
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
node: {
type: PropType<CascaderNode>;
required: true;
};
menuId: StringConstructor;
}>> & {
onExpand?: ((...args: any[]) => any) | undefined;
}, {}>;
export default _default;

View File

@@ -0,0 +1,187 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var index$1 = require('../../checkbox/index.js');
var index$2 = require('../../radio/index.js');
var index$3 = require('../../icon/index.js');
var iconsVue = require('@element-plus/icons-vue');
var nodeContent = require('./node-content.js');
var types = require('./types.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var index = require('../../../hooks/use-namespace/index.js');
const __default__ = vue.defineComponent({
name: "ElCascaderNode"
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
...__default__,
props: {
node: {
type: Object,
required: true
},
menuId: String
},
emits: ["expand"],
setup(__props, { emit }) {
const props = __props;
const panel = vue.inject(types.CASCADER_PANEL_INJECTION_KEY);
const ns = index.useNamespace("cascader-node");
const isHoverMenu = vue.computed(() => panel.isHoverMenu);
const multiple = vue.computed(() => panel.config.multiple);
const checkStrictly = vue.computed(() => panel.config.checkStrictly);
const showPrefix = vue.computed(() => panel.config.showPrefix);
const checkedNodeId = vue.computed(() => {
var _a;
return (_a = panel.checkedNodes[0]) == null ? void 0 : _a.uid;
});
const isDisabled = vue.computed(() => props.node.isDisabled);
const isLeaf = vue.computed(() => props.node.isLeaf);
const expandable = vue.computed(() => checkStrictly.value && !isLeaf.value || !isDisabled.value);
const inExpandingPath = vue.computed(() => isInPath(panel.expandingNode));
const inCheckedPath = vue.computed(() => checkStrictly.value && panel.checkedNodes.some(isInPath));
const isInPath = (node) => {
var _a;
const { level, uid } = props.node;
return ((_a = node == null ? void 0 : node.pathNodes[level - 1]) == null ? void 0 : _a.uid) === uid;
};
const doExpand = () => {
if (inExpandingPath.value)
return;
panel.expandNode(props.node);
};
const doCheck = (checked) => {
const { node } = props;
if (checked === node.checked)
return;
panel.handleCheckChange(node, checked);
};
const doLoad = () => {
panel.lazyLoad(props.node, () => {
if (!isLeaf.value)
doExpand();
});
};
const handleHoverExpand = (e) => {
if (!isHoverMenu.value)
return;
handleExpand();
!isLeaf.value && emit("expand", e);
};
const handleExpand = () => {
const { node } = props;
if (!expandable.value || node.loading)
return;
node.loaded ? doExpand() : doLoad();
};
const handleClick = () => {
if (isLeaf.value && !isDisabled.value && !checkStrictly.value && !multiple.value) {
handleCheck(true);
} else if ((panel.config.checkOnClickNode && (multiple.value || checkStrictly.value) || isLeaf.value && panel.config.checkOnClickLeaf) && !isDisabled.value) {
handleSelectCheck(!props.node.checked);
} else if (!isHoverMenu.value) {
handleExpand();
}
};
const handleSelectCheck = (checked) => {
if (checkStrictly.value) {
doCheck(checked);
if (props.node.loaded) {
doExpand();
}
} else {
handleCheck(checked);
}
};
const handleCheck = (checked) => {
if (!props.node.loaded) {
doLoad();
} else {
doCheck(checked);
!checkStrictly.value && doExpand();
}
};
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("li", {
id: `${__props.menuId}-${__props.node.uid}`,
role: "menuitem",
"aria-haspopup": !vue.unref(isLeaf),
"aria-owns": vue.unref(isLeaf) ? void 0 : __props.menuId,
"aria-expanded": vue.unref(inExpandingPath),
tabindex: vue.unref(expandable) ? -1 : void 0,
class: vue.normalizeClass([
vue.unref(ns).b(),
vue.unref(ns).is("selectable", vue.unref(checkStrictly)),
vue.unref(ns).is("active", __props.node.checked),
vue.unref(ns).is("disabled", !vue.unref(expandable)),
vue.unref(inExpandingPath) && "in-active-path",
vue.unref(inCheckedPath) && "in-checked-path"
]),
onMouseenter: handleHoverExpand,
onFocus: handleHoverExpand,
onClick: handleClick
}, [
vue.createCommentVNode(" prefix "),
vue.unref(multiple) && vue.unref(showPrefix) ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElCheckbox), {
key: 0,
"model-value": __props.node.checked,
indeterminate: __props.node.indeterminate,
disabled: vue.unref(isDisabled),
onClick: vue.withModifiers(() => {
}, ["stop"]),
"onUpdate:modelValue": handleSelectCheck
}, null, 8, ["model-value", "indeterminate", "disabled", "onClick"])) : vue.unref(checkStrictly) && vue.unref(showPrefix) ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.ElRadio), {
key: 1,
"model-value": vue.unref(checkedNodeId),
label: __props.node.uid,
disabled: vue.unref(isDisabled),
"onUpdate:modelValue": handleSelectCheck,
onClick: vue.withModifiers(() => {
}, ["stop"])
}, {
default: vue.withCtx(() => [
vue.createCommentVNode("\n Add an empty element to avoid render label,\n do not use empty fragment here for https://github.com/vuejs/vue-next/pull/2485\n "),
vue.createElementVNode("span")
]),
_: 1
}, 8, ["model-value", "label", "disabled", "onClick"])) : vue.unref(isLeaf) && __props.node.checked ? (vue.openBlock(), vue.createBlock(vue.unref(index$3.ElIcon), {
key: 2,
class: vue.normalizeClass(vue.unref(ns).e("prefix"))
}, {
default: vue.withCtx(() => [
vue.createVNode(vue.unref(iconsVue.Check))
]),
_: 1
}, 8, ["class"])) : vue.createCommentVNode("v-if", true),
vue.createCommentVNode(" content "),
vue.createVNode(vue.unref(nodeContent["default"]), { node: __props.node }, null, 8, ["node"]),
vue.createCommentVNode(" postfix "),
!vue.unref(isLeaf) ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 3 }, [
__props.node.loading ? (vue.openBlock(), vue.createBlock(vue.unref(index$3.ElIcon), {
key: 0,
class: vue.normalizeClass([vue.unref(ns).is("loading"), vue.unref(ns).e("postfix")])
}, {
default: vue.withCtx(() => [
vue.createVNode(vue.unref(iconsVue.Loading))
]),
_: 1
}, 8, ["class"])) : (vue.openBlock(), vue.createBlock(vue.unref(index$3.ElIcon), {
key: 1,
class: vue.normalizeClass(["arrow-right", vue.unref(ns).e("postfix")])
}, {
default: vue.withCtx(() => [
vue.createVNode(vue.unref(iconsVue.ArrowRight))
]),
_: 1
}, 8, ["class"]))
], 64)) : vue.createCommentVNode("v-if", true)
], 42, ["id", "aria-haspopup", "aria-owns", "aria-expanded", "tabindex"]);
};
}
});
var ElCascaderNode = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "node.vue"]]);
exports["default"] = ElCascaderNode;
//# sourceMappingURL=node2.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,17 @@
import Node from './node';
import type { Nullable } from 'element-plus/es/utils';
import type { CascaderConfig, CascaderNodePathValue, CascaderNodeValue, CascaderOption } from './types';
export default class Store {
readonly config: CascaderConfig;
readonly nodes: Node[];
readonly allNodes: Node[];
readonly leafNodes: Node[];
constructor(data: CascaderOption[], config: CascaderConfig);
getNodes(): Node[];
getFlattedNodes(leafOnly: boolean): Node[];
appendNode(nodeData: CascaderOption, parentNode?: Node): void;
appendNodes(nodeDataList: CascaderOption[], parentNode: Node): void;
appendAllNodesAndLeafNodes(node: Node): void;
getNodeByValue(value: CascaderNodeValue | CascaderNodePathValue, leafOnly?: boolean): Nullable<Node>;
getSameNode(node: Node): Nullable<Node>;
}

View File

@@ -0,0 +1,71 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var lodashUnified = require('lodash-unified');
var node = require('./node.js');
var types = require('../../../utils/types.js');
const flatNodes = (nodes, leafOnly) => {
return nodes.reduce((res, node) => {
if (node.isLeaf) {
res.push(node);
} else {
!leafOnly && res.push(node);
res = res.concat(flatNodes(node.children, leafOnly));
}
return res;
}, []);
};
class Store {
constructor(data, config) {
this.config = config;
const nodes = (data || []).map((nodeData) => new node["default"](nodeData, this.config));
this.nodes = nodes;
this.allNodes = flatNodes(nodes, false);
this.leafNodes = flatNodes(nodes, true);
}
getNodes() {
return this.nodes;
}
getFlattedNodes(leafOnly) {
return leafOnly ? this.leafNodes : this.allNodes;
}
appendNode(nodeData, parentNode) {
const node$1 = parentNode ? parentNode.appendChild(nodeData) : new node["default"](nodeData, this.config);
if (!parentNode)
this.nodes.push(node$1);
this.appendAllNodesAndLeafNodes(node$1);
}
appendNodes(nodeDataList, parentNode) {
if (nodeDataList.length > 0) {
nodeDataList.forEach((nodeData) => this.appendNode(nodeData, parentNode));
} else {
parentNode && parentNode.isLeaf && this.leafNodes.push(parentNode);
}
}
appendAllNodesAndLeafNodes(node) {
this.allNodes.push(node);
node.isLeaf && this.leafNodes.push(node);
if (node.children) {
node.children.forEach((subNode) => {
this.appendAllNodesAndLeafNodes(subNode);
});
}
}
getNodeByValue(value, leafOnly = false) {
if (types.isPropAbsent(value))
return null;
const node = this.getFlattedNodes(leafOnly).find((node2) => lodashUnified.isEqual(node2.value, value) || lodashUnified.isEqual(node2.pathValues, value));
return node || null;
}
getSameNode(node) {
if (!node)
return null;
const node_ = this.getFlattedNodes(false).find(({ value, level }) => lodashUnified.isEqual(node.value, value) && node.level === level);
return node_ || null;
}
}
exports["default"] = Store;
//# sourceMappingURL=store.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,62 @@
import type { InjectionKey, VNode } from 'vue';
import type { Nullable } from 'element-plus/es/utils';
import type { default as CascaderNode } from './node';
export type { CascaderNode, Nullable };
export type CascaderNodeValue = string | number | Record<string, any>;
export type CascaderNodePathValue = CascaderNodeValue[];
export type CascaderValue = CascaderNodeValue | CascaderNodePathValue | (CascaderNodeValue | CascaderNodePathValue)[];
export type CascaderConfig = Required<CascaderProps>;
export type ExpandTrigger = 'click' | 'hover';
export type isDisabled = (data: CascaderOption, node: CascaderNode) => boolean;
export type isLeaf = (data: CascaderOption, node: CascaderNode) => boolean;
export type Resolve = (dataList?: CascaderOption[]) => void;
export type LazyLoad = (node: CascaderNode, resolve: Resolve) => void;
export interface RenderLabelProps {
node: CascaderNode;
data: CascaderOption;
}
export type RenderLabel = (props: RenderLabelProps) => VNode | VNode[];
export interface CascaderOption extends Record<string, unknown> {
label?: string;
value?: CascaderNodeValue;
children?: CascaderOption[];
disabled?: boolean;
leaf?: boolean;
}
export interface CascaderProps {
expandTrigger?: ExpandTrigger;
multiple?: boolean;
checkStrictly?: boolean;
emitPath?: boolean;
lazy?: boolean;
lazyLoad?: LazyLoad;
value?: string;
label?: string;
children?: string;
disabled?: string | isDisabled;
leaf?: string | isLeaf;
hoverThreshold?: number;
checkOnClickNode?: boolean;
checkOnClickLeaf?: boolean;
showPrefix?: boolean;
}
export interface Tag {
node?: CascaderNode;
key: number;
text: string;
hitState?: boolean;
closable: boolean;
isCollapseTag: boolean;
}
export interface ElCascaderPanelContext {
config: CascaderConfig;
expandingNode: CascaderNode | undefined;
checkedNodes: CascaderNode[];
isHoverMenu: boolean;
initialLoaded: boolean;
renderLabelFn: RenderLabel;
lazyLoad: (node?: CascaderNode, cb?: (dataList: CascaderOption[]) => void) => void;
expandNode: (node: CascaderNode, silent?: boolean) => void;
handleCheckChange: (node: CascaderNode, checked: boolean, emitClose?: boolean) => void;
}
export declare const CASCADER_PANEL_INJECTION_KEY: InjectionKey<ElCascaderPanelContext>;

View File

@@ -0,0 +1,8 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const CASCADER_PANEL_INJECTION_KEY = Symbol();
exports.CASCADER_PANEL_INJECTION_KEY = CASCADER_PANEL_INJECTION_KEY;
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sources":["../../../../../../packages/components/cascader-panel/src/types.ts"],"sourcesContent":["import type { InjectionKey, VNode } from 'vue'\nimport type { Nullable } from '@element-plus/utils'\nimport type { default as CascaderNode } from './node'\n\nexport type { CascaderNode, Nullable }\nexport type CascaderNodeValue = string | number | Record<string, any>\nexport type CascaderNodePathValue = CascaderNodeValue[]\nexport type CascaderValue =\n | CascaderNodeValue\n | CascaderNodePathValue\n | (CascaderNodeValue | CascaderNodePathValue)[]\nexport type CascaderConfig = Required<CascaderProps>\nexport type ExpandTrigger = 'click' | 'hover'\nexport type isDisabled = (data: CascaderOption, node: CascaderNode) => boolean\nexport type isLeaf = (data: CascaderOption, node: CascaderNode) => boolean\nexport type Resolve = (dataList?: CascaderOption[]) => void\nexport type LazyLoad = (node: CascaderNode, resolve: Resolve) => void\nexport interface RenderLabelProps {\n node: CascaderNode\n data: CascaderOption\n}\nexport type RenderLabel = (props: RenderLabelProps) => VNode | VNode[]\nexport interface CascaderOption extends Record<string, unknown> {\n label?: string\n value?: CascaderNodeValue\n children?: CascaderOption[]\n disabled?: boolean\n leaf?: boolean\n}\n\nexport interface CascaderProps {\n expandTrigger?: ExpandTrigger\n multiple?: boolean\n checkStrictly?: boolean\n emitPath?: boolean\n lazy?: boolean\n lazyLoad?: LazyLoad\n value?: string\n label?: string\n children?: string\n disabled?: string | isDisabled\n leaf?: string | isLeaf\n hoverThreshold?: number\n checkOnClickNode?: boolean\n checkOnClickLeaf?: boolean\n showPrefix?: boolean\n}\n\nexport interface Tag {\n node?: CascaderNode\n key: number\n text: string\n hitState?: boolean\n closable: boolean\n isCollapseTag: boolean\n}\n\nexport interface ElCascaderPanelContext {\n config: CascaderConfig\n expandingNode: CascaderNode | undefined\n checkedNodes: CascaderNode[]\n isHoverMenu: boolean\n initialLoaded: boolean\n renderLabelFn: RenderLabel\n lazyLoad: (\n node?: CascaderNode,\n cb?: (dataList: CascaderOption[]) => void\n ) => void\n expandNode: (node: CascaderNode, silent?: boolean) => void\n handleCheckChange: (\n node: CascaderNode,\n checked: boolean,\n emitClose?: boolean\n ) => void\n}\n\nexport const CASCADER_PANEL_INJECTION_KEY: InjectionKey<ElCascaderPanelContext> =\n Symbol()\n"],"names":[],"mappings":";;;;AAAY,MAAC,4BAA4B,GAAG,MAAM;;;;"}

View File

@@ -0,0 +1,4 @@
import type { CascaderNode } from './types';
export declare const getMenuIndex: (el: HTMLElement) => number;
export declare const checkNode: (el: HTMLElement) => void;
export declare const sortByOriginalOrder: (oldNodes: CascaderNode[], newNodes: CascaderNode[]) => CascaderNode[];

View File

@@ -0,0 +1,42 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var aria = require('../../../utils/dom/aria.js');
const getMenuIndex = (el) => {
if (!el)
return 0;
const pieces = el.id.split("-");
return Number(pieces[pieces.length - 2]);
};
const checkNode = (el) => {
if (!el)
return;
const input = el.querySelector("input");
if (input) {
input.click();
} else if (aria.isLeaf(el)) {
el.click();
}
};
const sortByOriginalOrder = (oldNodes, newNodes) => {
const newNodesCopy = newNodes.slice(0);
const newIds = newNodesCopy.map((node) => node.uid);
const res = oldNodes.reduce((acc, item) => {
const index = newIds.indexOf(item.uid);
if (index > -1) {
acc.push(item);
newNodesCopy.splice(index, 1);
newIds.splice(index, 1);
}
return acc;
}, []);
res.push(...newNodesCopy);
return res;
};
exports.checkNode = checkNode;
exports.getMenuIndex = getMenuIndex;
exports.sortByOriginalOrder = sortByOriginalOrder;
//# sourceMappingURL=utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.js","sources":["../../../../../../packages/components/cascader-panel/src/utils.ts"],"sourcesContent":["import { isLeaf } from '@element-plus/utils'\n\nimport type { CascaderNode } from './types'\n\nexport const getMenuIndex = (el: HTMLElement) => {\n if (!el) return 0\n const pieces = el.id.split('-')\n return Number(pieces[pieces.length - 2])\n}\n\nexport const checkNode = (el: HTMLElement) => {\n if (!el) return\n\n const input = el.querySelector('input')\n if (input) {\n input.click()\n } else if (isLeaf(el)) {\n el.click()\n }\n}\n\nexport const sortByOriginalOrder = (\n oldNodes: CascaderNode[],\n newNodes: CascaderNode[]\n) => {\n const newNodesCopy = newNodes.slice(0)\n const newIds = newNodesCopy.map((node) => node.uid)\n const res = oldNodes.reduce((acc, item) => {\n const index = newIds.indexOf(item.uid)\n if (index > -1) {\n acc.push(item)\n newNodesCopy.splice(index, 1)\n newIds.splice(index, 1)\n }\n return acc\n }, [] as CascaderNode[])\n\n res.push(...newNodesCopy)\n\n return res\n}\n"],"names":["isLeaf"],"mappings":";;;;;;AACY,MAAC,YAAY,GAAG,CAAC,EAAE,KAAK;AACpC,EAAE,IAAI,CAAC,EAAE;AACT,IAAI,OAAO,CAAC,CAAC;AACb,EAAE,MAAM,MAAM,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAClC,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AAC3C,EAAE;AACU,MAAC,SAAS,GAAG,CAAC,EAAE,KAAK;AACjC,EAAE,IAAI,CAAC,EAAE;AACT,IAAI,OAAO;AACX,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AAC1C,EAAE,IAAI,KAAK,EAAE;AACb,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;AAClB,GAAG,MAAM,IAAIA,WAAM,CAAC,EAAE,CAAC,EAAE;AACzB,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC;AACf,GAAG;AACH,EAAE;AACU,MAAC,mBAAmB,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK;AAC3D,EAAE,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACzC,EAAE,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC;AACtD,EAAE,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK;AAC7C,IAAI,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3C,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;AACpB,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrB,MAAM,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;AACpC,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;AAC9B,KAAK;AACL,IAAI,OAAO,GAAG,CAAC;AACf,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;AAC5B,EAAE,OAAO,GAAG,CAAC;AACb;;;;;;"}

View File

@@ -0,0 +1,5 @@
import 'element-plus/es/components/base/style/css';
import 'element-plus/theme-chalk/el-cascader-panel.css';
import 'element-plus/es/components/checkbox/style/css';
import 'element-plus/es/components/radio/style/css';
import 'element-plus/es/components/scrollbar/style/css';

View File

@@ -0,0 +1,9 @@
'use strict';
require('../../base/style/css.js');
require('element-plus/theme-chalk/el-cascader-panel.css');
require('../../checkbox/style/css.js');
require('../../radio/style/css.js');
require('../../scrollbar/style/css.js');
//# sourceMappingURL=css.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}

View File

@@ -0,0 +1,5 @@
import 'element-plus/es/components/base/style';
import 'element-plus/theme-chalk/src/cascader-panel.scss';
import 'element-plus/es/components/checkbox/style';
import 'element-plus/es/components/radio/style';
import 'element-plus/es/components/scrollbar/style';

View File

@@ -0,0 +1,9 @@
'use strict';
require('../../base/style/index.js');
require('element-plus/theme-chalk/src/cascader-panel.scss');
require('../../checkbox/style/index.js');
require('../../radio/style/index.js');
require('../../scrollbar/style/index.js');
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}