mldong-flow-designer-plus
Version:
本项目包含了作者为B站课堂视频[《工作流设计器开发最佳实践》](https://www.bilibili.com/cheese/play/ss24484)的过程源码。教程中开发的组件也可用于实际生产环境中。以下是和使用文档和课程章节说明。 ## 实战项目 [演示地址](https://flow-pro.mldong.com/)
1,648 lines • 187 kB
JavaScript
import { _ as _extends, a9 as warning, P as PropTypes, b as _objectSpread2, h as classNames, F as isValidElement, r as flattenChildren, g as canUseDom, aa as warningOnce, I as noteOnce, O as resetComponent, V as textEllipsis, H as merge, Q as resetIcon, t as genComponentStyleHook, $ as useConfigInject, a0 as useInjectDisabled, D as DefaultRenderEmpty, s as functionType, U as stringType, f as booleanType, S as someType } from "./index-DwKsTObm.js";
import { defineComponent, computed, ref, createVNode, isVNode, cloneVNode, inject, provide, onUnmounted, shallowRef, watch, watchEffect, onMounted, createTextVNode, Fragment, onBeforeUnmount, isRef, reactive, toRefs, toRaw, nextTick, onUpdated, unref, toRef } from "vue";
import { T as Trigger } from "./Trigger-xL7uGTW1.js";
import { K as KeyCode } from "./KeyCode-CnYuZtHO.js";
import { c as cloneElement } from "./vnode-5QtKZFuZ.js";
import { B as BaseInput, R as ResizeObserver, S as SearchOutlined, g as getMergedStatus, a as getStatusClassNames } from "./index-DFYPQlI_.js";
import { p as pickAttrs } from "./pickAttrs-CHViqAAd.js";
import { i as initDefaultProps, w as wrapperRaf } from "./raf-0P1My3fX.js";
import { i as initMotion, s as supportsPassive } from "./motion-CKgd-zx5.js";
import { o as omit } from "./omit-C0r0G03h.js";
import { u as useState, g as genCompactItemStyle } from "./compact-item-whQH9h8_.js";
import { I as Icon } from "./AntdIcon-CltaWHRq.js";
import { L as LoadingOutlined } from "./LoadingOutlined-XKO9CrGl.js";
import { C as CloseOutlined } from "./CloseOutlined-RCkU_R0S.js";
import { C as CloseCircleFilled } from "./CloseCircleFilled-ScruBXcD.js";
import { u as useInjectFormItemContext, F as FormItemInputContext } from "./FormItemContext-cgWkWCrO.js";
import { b as getTransitionName, g as getTransitionDirection } from "./transition-t9_7J_yI.js";
import { u as useCompactItemContext } from "./Compact-CXMNSCdJ.js";
import { K as Keyframe } from "./motionUtil-C3pKw7LX.js";
import { d as devWarning } from "./createContext-ne6PasgT.js";
const moveDownIn = new Keyframe("antMoveDownIn", {
"0%": {
transform: "translate3d(0, 100%, 0)",
transformOrigin: "0 0",
opacity: 0
},
"100%": {
transform: "translate3d(0, 0, 0)",
transformOrigin: "0 0",
opacity: 1
}
});
const moveDownOut = new Keyframe("antMoveDownOut", {
"0%": {
transform: "translate3d(0, 0, 0)",
transformOrigin: "0 0",
opacity: 1
},
"100%": {
transform: "translate3d(0, 100%, 0)",
transformOrigin: "0 0",
opacity: 0
}
});
const moveLeftIn = new Keyframe("antMoveLeftIn", {
"0%": {
transform: "translate3d(-100%, 0, 0)",
transformOrigin: "0 0",
opacity: 0
},
"100%": {
transform: "translate3d(0, 0, 0)",
transformOrigin: "0 0",
opacity: 1
}
});
const moveLeftOut = new Keyframe("antMoveLeftOut", {
"0%": {
transform: "translate3d(0, 0, 0)",
transformOrigin: "0 0",
opacity: 1
},
"100%": {
transform: "translate3d(-100%, 0, 0)",
transformOrigin: "0 0",
opacity: 0
}
});
const moveRightIn = new Keyframe("antMoveRightIn", {
"0%": {
transform: "translate3d(100%, 0, 0)",
transformOrigin: "0 0",
opacity: 0
},
"100%": {
transform: "translate3d(0, 0, 0)",
transformOrigin: "0 0",
opacity: 1
}
});
const moveRightOut = new Keyframe("antMoveRightOut", {
"0%": {
transform: "translate3d(0, 0, 0)",
transformOrigin: "0 0",
opacity: 1
},
"100%": {
transform: "translate3d(100%, 0, 0)",
transformOrigin: "0 0",
opacity: 0
}
});
const moveUpIn = new Keyframe("antMoveUpIn", {
"0%": {
transform: "translate3d(0, -100%, 0)",
transformOrigin: "0 0",
opacity: 0
},
"100%": {
transform: "translate3d(0, 0, 0)",
transformOrigin: "0 0",
opacity: 1
}
});
const moveUpOut = new Keyframe("antMoveUpOut", {
"0%": {
transform: "translate3d(0, 0, 0)",
transformOrigin: "0 0",
opacity: 1
},
"100%": {
transform: "translate3d(0, -100%, 0)",
transformOrigin: "0 0",
opacity: 0
}
});
const moveMotion = {
"move-up": {
inKeyframes: moveUpIn,
outKeyframes: moveUpOut
},
"move-down": {
inKeyframes: moveDownIn,
outKeyframes: moveDownOut
},
"move-left": {
inKeyframes: moveLeftIn,
outKeyframes: moveLeftOut
},
"move-right": {
inKeyframes: moveRightIn,
outKeyframes: moveRightOut
}
};
const initMoveMotion = (token, motionName) => {
const {
antCls
} = token;
const motionCls = `${antCls}-${motionName}`;
const {
inKeyframes,
outKeyframes
} = moveMotion[motionName];
return [initMotion(motionCls, inKeyframes, outKeyframes, token.motionDurationMid), {
[`
${motionCls}-enter,
${motionCls}-appear
`]: {
opacity: 0,
animationTimingFunction: token.motionEaseOutCirc
},
[`${motionCls}-leave`]: {
animationTimingFunction: token.motionEaseInOutCirc
}
}];
};
const slideUpIn = new Keyframe("antSlideUpIn", {
"0%": {
transform: "scaleY(0.8)",
transformOrigin: "0% 0%",
opacity: 0
},
"100%": {
transform: "scaleY(1)",
transformOrigin: "0% 0%",
opacity: 1
}
});
const slideUpOut = new Keyframe("antSlideUpOut", {
"0%": {
transform: "scaleY(1)",
transformOrigin: "0% 0%",
opacity: 1
},
"100%": {
transform: "scaleY(0.8)",
transformOrigin: "0% 0%",
opacity: 0
}
});
const slideDownIn = new Keyframe("antSlideDownIn", {
"0%": {
transform: "scaleY(0.8)",
transformOrigin: "100% 100%",
opacity: 0
},
"100%": {
transform: "scaleY(1)",
transformOrigin: "100% 100%",
opacity: 1
}
});
const slideDownOut = new Keyframe("antSlideDownOut", {
"0%": {
transform: "scaleY(1)",
transformOrigin: "100% 100%",
opacity: 1
},
"100%": {
transform: "scaleY(0.8)",
transformOrigin: "100% 100%",
opacity: 0
}
});
const slideLeftIn = new Keyframe("antSlideLeftIn", {
"0%": {
transform: "scaleX(0.8)",
transformOrigin: "0% 0%",
opacity: 0
},
"100%": {
transform: "scaleX(1)",
transformOrigin: "0% 0%",
opacity: 1
}
});
const slideLeftOut = new Keyframe("antSlideLeftOut", {
"0%": {
transform: "scaleX(1)",
transformOrigin: "0% 0%",
opacity: 1
},
"100%": {
transform: "scaleX(0.8)",
transformOrigin: "0% 0%",
opacity: 0
}
});
const slideRightIn = new Keyframe("antSlideRightIn", {
"0%": {
transform: "scaleX(0.8)",
transformOrigin: "100% 0%",
opacity: 0
},
"100%": {
transform: "scaleX(1)",
transformOrigin: "100% 0%",
opacity: 1
}
});
const slideRightOut = new Keyframe("antSlideRightOut", {
"0%": {
transform: "scaleX(1)",
transformOrigin: "100% 0%",
opacity: 1
},
"100%": {
transform: "scaleX(0.8)",
transformOrigin: "100% 0%",
opacity: 0
}
});
const slideMotion = {
"slide-up": {
inKeyframes: slideUpIn,
outKeyframes: slideUpOut
},
"slide-down": {
inKeyframes: slideDownIn,
outKeyframes: slideDownOut
},
"slide-left": {
inKeyframes: slideLeftIn,
outKeyframes: slideLeftOut
},
"slide-right": {
inKeyframes: slideRightIn,
outKeyframes: slideRightOut
}
};
const initSlideMotion = (token, motionName) => {
const {
antCls
} = token;
const motionCls = `${antCls}-${motionName}`;
const {
inKeyframes,
outKeyframes
} = slideMotion[motionName];
return [initMotion(motionCls, inKeyframes, outKeyframes, token.motionDurationMid), {
[`
${motionCls}-enter,
${motionCls}-appear
`]: {
transform: "scale(0)",
transformOrigin: "0% 0%",
opacity: 0,
animationTimingFunction: token.motionEaseOutQuint
},
[`${motionCls}-leave`]: {
animationTimingFunction: token.motionEaseInQuint
}
}];
};
function getKey(data, index) {
const {
key
} = data;
let value;
if ("value" in data) {
({
value
} = data);
}
if (key !== null && key !== void 0) {
return key;
}
if (value !== void 0) {
return value;
}
return `rc-index-key-${index}`;
}
function fillFieldNames(fieldNames, childrenAsData) {
const {
label,
value,
options
} = fieldNames || {};
return {
label: label || (childrenAsData ? "children" : "label"),
value: value || "value",
options: options || "options"
};
}
function flattenOptions(options) {
let {
fieldNames,
childrenAsData
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
const flattenList = [];
const {
label: fieldLabel,
value: fieldValue,
options: fieldOptions
} = fillFieldNames(fieldNames, false);
function dig(list, isGroupOption) {
list.forEach((data) => {
const label = data[fieldLabel];
if (isGroupOption || !(fieldOptions in data)) {
const value = data[fieldValue];
flattenList.push({
key: getKey(data, flattenList.length),
groupOption: isGroupOption,
data,
label,
value
});
} else {
let grpLabel = label;
if (grpLabel === void 0 && childrenAsData) {
grpLabel = data.label;
}
flattenList.push({
key: getKey(data, flattenList.length),
group: true,
data,
label: grpLabel
});
dig(data[fieldOptions], true);
}
});
}
dig(options, false);
return flattenList;
}
function injectPropsWithOption(option) {
const newOption = _extends({}, option);
if (!("props" in newOption)) {
Object.defineProperty(newOption, "props", {
get() {
warning(false, "Return type is option instead of Option instance. Please read value directly instead of reading from `props`.");
return newOption;
}
});
}
return newOption;
}
function getSeparatedContent(text, tokens) {
if (!tokens || !tokens.length) {
return null;
}
let match = false;
function separate(str, _ref) {
let [token, ...restTokens] = _ref;
if (!token) {
return [str];
}
const list2 = str.split(token);
match = match || list2.length > 1;
return list2.reduce((prevList, unitStr) => [...prevList, ...separate(unitStr, restTokens)], []).filter((unit) => unit);
}
const list = separate(text, tokens);
return match ? list : null;
}
var __rest$7 = function(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
const getBuiltInPlacements = (dropdownMatchSelectWidth) => {
const adjustX = dropdownMatchSelectWidth === true ? 0 : 1;
return {
bottomLeft: {
points: ["tl", "bl"],
offset: [0, 4],
overflow: {
adjustX,
adjustY: 1
}
},
bottomRight: {
points: ["tr", "br"],
offset: [0, 4],
overflow: {
adjustX,
adjustY: 1
}
},
topLeft: {
points: ["bl", "tl"],
offset: [0, -4],
overflow: {
adjustX,
adjustY: 1
}
},
topRight: {
points: ["br", "tr"],
offset: [0, -4],
overflow: {
adjustX,
adjustY: 1
}
}
};
};
const SelectTrigger = defineComponent({
name: "SelectTrigger",
inheritAttrs: false,
props: {
dropdownAlign: Object,
visible: {
type: Boolean,
default: void 0
},
disabled: {
type: Boolean,
default: void 0
},
dropdownClassName: String,
dropdownStyle: PropTypes.object,
placement: String,
empty: {
type: Boolean,
default: void 0
},
prefixCls: String,
popupClassName: String,
animation: String,
transitionName: String,
getPopupContainer: Function,
dropdownRender: Function,
containerWidth: Number,
dropdownMatchSelectWidth: PropTypes.oneOfType([Number, Boolean]).def(true),
popupElement: PropTypes.any,
direction: String,
getTriggerDOMNode: Function,
onPopupVisibleChange: Function,
onPopupMouseEnter: Function,
onPopupFocusin: Function,
onPopupFocusout: Function
},
setup(props2, _ref) {
let {
slots,
attrs,
expose
} = _ref;
const builtInPlacements = computed(() => {
const {
dropdownMatchSelectWidth
} = props2;
return getBuiltInPlacements(dropdownMatchSelectWidth);
});
const popupRef = ref();
expose({
getPopupElement: () => {
return popupRef.value;
}
});
return () => {
const _a = _extends(_extends({}, props2), attrs), {
empty = false
} = _a, restProps = __rest$7(_a, ["empty"]);
const {
visible,
dropdownAlign,
prefixCls,
popupElement,
dropdownClassName,
dropdownStyle,
direction = "ltr",
placement,
dropdownMatchSelectWidth,
containerWidth,
dropdownRender,
animation,
transitionName,
getPopupContainer,
getTriggerDOMNode,
onPopupVisibleChange,
onPopupMouseEnter,
onPopupFocusin,
onPopupFocusout
} = restProps;
const dropdownPrefixCls = `${prefixCls}-dropdown`;
let popupNode = popupElement;
if (dropdownRender) {
popupNode = dropdownRender({
menuNode: popupElement,
props: props2
});
}
const mergedTransitionName = animation ? `${dropdownPrefixCls}-${animation}` : transitionName;
const popupStyle = _extends({
minWidth: `${containerWidth}px`
}, dropdownStyle);
if (typeof dropdownMatchSelectWidth === "number") {
popupStyle.width = `${dropdownMatchSelectWidth}px`;
} else if (dropdownMatchSelectWidth) {
popupStyle.width = `${containerWidth}px`;
}
return createVNode(Trigger, _objectSpread2(_objectSpread2({}, props2), {}, {
"showAction": onPopupVisibleChange ? ["click"] : [],
"hideAction": onPopupVisibleChange ? ["click"] : [],
"popupPlacement": placement || (direction === "rtl" ? "bottomRight" : "bottomLeft"),
"builtinPlacements": builtInPlacements.value,
"prefixCls": dropdownPrefixCls,
"popupTransitionName": mergedTransitionName,
"popupAlign": dropdownAlign,
"popupVisible": visible,
"getPopupContainer": getPopupContainer,
"popupClassName": classNames(dropdownClassName, {
[`${dropdownPrefixCls}-empty`]: empty
}),
"popupStyle": popupStyle,
"getTriggerDOMNode": getTriggerDOMNode,
"onPopupVisibleChange": onPopupVisibleChange
}), {
default: slots.default,
popup: () => createVNode("div", {
"ref": popupRef,
"onMouseenter": onPopupMouseEnter,
"onFocusin": onPopupFocusin,
"onFocusout": onPopupFocusout
}, [popupNode])
});
};
}
});
const TransBtn = (props2, _ref) => {
let {
slots
} = _ref;
var _a;
const {
class: className,
customizeIcon,
customizeIconProps,
onMousedown,
onClick
} = props2;
let icon;
if (typeof customizeIcon === "function") {
icon = customizeIcon(customizeIconProps);
} else {
icon = isVNode(customizeIcon) ? cloneVNode(customizeIcon) : customizeIcon;
}
return createVNode("span", {
"class": className,
"onMousedown": (event) => {
event.preventDefault();
if (onMousedown) {
onMousedown(event);
}
},
"style": {
userSelect: "none",
WebkitUserSelect: "none"
},
"unselectable": "on",
"onClick": onClick,
"aria-hidden": true
}, [icon !== void 0 ? icon : createVNode("span", {
"class": className.split(/\s+/).map((cls) => `${cls}-icon`)
}, [(_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)])]);
};
TransBtn.inheritAttrs = false;
TransBtn.displayName = "TransBtn";
TransBtn.props = {
class: String,
customizeIcon: PropTypes.any,
customizeIconProps: PropTypes.any,
onMousedown: Function,
onClick: Function
};
const inputProps = {
inputRef: PropTypes.any,
prefixCls: String,
id: String,
inputElement: PropTypes.VueNode,
disabled: {
type: Boolean,
default: void 0
},
autofocus: {
type: Boolean,
default: void 0
},
autocomplete: String,
editable: {
type: Boolean,
default: void 0
},
activeDescendantId: String,
value: String,
open: {
type: Boolean,
default: void 0
},
tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/** Pass accessibility props to input */
attrs: PropTypes.object,
onKeydown: {
type: Function
},
onMousedown: {
type: Function
},
onChange: {
type: Function
},
onPaste: {
type: Function
},
onCompositionstart: {
type: Function
},
onCompositionend: {
type: Function
},
onFocus: {
type: Function
},
onBlur: {
type: Function
}
};
const Input = defineComponent({
compatConfig: {
MODE: 3
},
name: "SelectInput",
inheritAttrs: false,
props: inputProps,
setup(props2) {
let blurTimeout = null;
const VCSelectContainerEvent = inject("VCSelectContainerEvent");
return () => {
var _a;
const {
prefixCls,
id,
inputElement,
disabled,
tabindex,
autofocus,
autocomplete,
editable,
activeDescendantId,
value,
onKeydown,
onMousedown,
onChange,
onPaste,
onCompositionstart,
onCompositionend,
onFocus,
onBlur,
open: open2,
inputRef,
attrs
} = props2;
let inputNode = inputElement || createVNode(BaseInput, null, null);
const inputProps2 = inputNode.props || {};
const {
onKeydown: onOriginKeyDown,
onInput: onOriginInput,
onFocus: onOriginFocus,
onBlur: onOriginBlur,
onMousedown: onOriginMouseDown,
onCompositionstart: onOriginCompositionStart,
onCompositionend: onOriginCompositionEnd,
style
} = inputProps2;
inputNode = cloneElement(inputNode, _extends(_extends(_extends(_extends(_extends({
type: "search"
}, inputProps2), {
id,
ref: inputRef,
disabled,
tabindex,
lazy: false,
autocomplete: autocomplete || "off",
autofocus,
class: classNames(`${prefixCls}-selection-search-input`, (_a = inputNode === null || inputNode === void 0 ? void 0 : inputNode.props) === null || _a === void 0 ? void 0 : _a.class),
role: "combobox",
"aria-expanded": open2,
"aria-haspopup": "listbox",
"aria-owns": `${id}_list`,
"aria-autocomplete": "list",
"aria-controls": `${id}_list`,
"aria-activedescendant": activeDescendantId
}), attrs), {
value: editable ? value : "",
readonly: !editable,
unselectable: !editable ? "on" : null,
style: _extends(_extends({}, style), {
opacity: editable ? null : 0
}),
onKeydown: (event) => {
onKeydown(event);
if (onOriginKeyDown) {
onOriginKeyDown(event);
}
},
onMousedown: (event) => {
onMousedown(event);
if (onOriginMouseDown) {
onOriginMouseDown(event);
}
},
onInput: (event) => {
onChange(event);
if (onOriginInput) {
onOriginInput(event);
}
},
onCompositionstart(event) {
onCompositionstart(event);
if (onOriginCompositionStart) {
onOriginCompositionStart(event);
}
},
onCompositionend(event) {
onCompositionend(event);
if (onOriginCompositionEnd) {
onOriginCompositionEnd(event);
}
},
onPaste,
onFocus: function() {
clearTimeout(blurTimeout);
onOriginFocus && onOriginFocus(arguments.length <= 0 ? void 0 : arguments[0]);
onFocus && onFocus(arguments.length <= 0 ? void 0 : arguments[0]);
VCSelectContainerEvent === null || VCSelectContainerEvent === void 0 ? void 0 : VCSelectContainerEvent.focus(arguments.length <= 0 ? void 0 : arguments[0]);
},
onBlur: function() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
blurTimeout = setTimeout(() => {
onOriginBlur && onOriginBlur(args[0]);
onBlur && onBlur(args[0]);
VCSelectContainerEvent === null || VCSelectContainerEvent === void 0 ? void 0 : VCSelectContainerEvent.blur(args[0]);
}, 100);
}
}), inputNode.type === "textarea" ? {} : {
type: "search"
}), true, true);
return inputNode;
};
}
});
const OverflowContextProviderKey = Symbol("OverflowContextProviderKey");
const OverflowContextProvider = defineComponent({
compatConfig: {
MODE: 3
},
name: "OverflowContextProvider",
inheritAttrs: false,
props: {
value: {
type: Object
}
},
setup(props2, _ref) {
let {
slots
} = _ref;
provide(OverflowContextProviderKey, computed(() => props2.value));
return () => {
var _a;
return (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots);
};
}
});
const useInjectOverflowContext = () => {
return inject(OverflowContextProviderKey, computed(() => null));
};
var __rest$6 = function(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
const UNDEFINED = void 0;
const Item$1 = defineComponent({
compatConfig: {
MODE: 3
},
name: "Item",
props: {
prefixCls: String,
item: PropTypes.any,
renderItem: Function,
responsive: Boolean,
itemKey: {
type: [String, Number]
},
registerSize: Function,
display: Boolean,
order: Number,
component: PropTypes.any,
invalidate: Boolean
},
setup(props2, _ref) {
let {
slots,
expose
} = _ref;
const mergedHidden = computed(() => props2.responsive && !props2.display);
const itemNodeRef = ref();
expose({
itemNodeRef
});
function internalRegisterSize(width) {
props2.registerSize(props2.itemKey, width);
}
onUnmounted(() => {
internalRegisterSize(null);
});
return () => {
var _a;
const {
prefixCls,
invalidate,
item,
renderItem,
responsive,
registerSize,
itemKey,
display,
order,
component: Component = "div"
} = props2, restProps = __rest$6(props2, ["prefixCls", "invalidate", "item", "renderItem", "responsive", "registerSize", "itemKey", "display", "order", "component"]);
const children = (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots);
const childNode = renderItem && item !== UNDEFINED ? renderItem(item) : children;
let overflowStyle;
if (!invalidate) {
overflowStyle = {
opacity: mergedHidden.value ? 0 : 1,
height: mergedHidden.value ? 0 : UNDEFINED,
overflowY: mergedHidden.value ? "hidden" : UNDEFINED,
order: responsive ? order : UNDEFINED,
pointerEvents: mergedHidden.value ? "none" : UNDEFINED,
position: mergedHidden.value ? "absolute" : UNDEFINED
};
}
const overflowProps2 = {};
if (mergedHidden.value) {
overflowProps2["aria-hidden"] = true;
}
return createVNode(ResizeObserver, {
"disabled": !responsive,
"onResize": (_ref2) => {
let {
offsetWidth
} = _ref2;
internalRegisterSize(offsetWidth);
}
}, {
default: () => createVNode(Component, _objectSpread2(_objectSpread2(_objectSpread2({
"class": classNames(!invalidate && prefixCls),
"style": overflowStyle
}, overflowProps2), restProps), {}, {
"ref": itemNodeRef
}), {
default: () => [childNode]
})
});
};
}
});
var __rest$5 = function(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
const RawItem = defineComponent({
compatConfig: {
MODE: 3
},
name: "RawItem",
inheritAttrs: false,
props: {
component: PropTypes.any,
title: PropTypes.any,
id: String,
onMouseenter: {
type: Function
},
onMouseleave: {
type: Function
},
onClick: {
type: Function
},
onKeydown: {
type: Function
},
onFocus: {
type: Function
},
role: String,
tabindex: Number
},
setup(props2, _ref) {
let {
slots,
attrs
} = _ref;
const context = useInjectOverflowContext();
return () => {
var _a;
if (!context.value) {
const {
component: Component = "div"
} = props2, restProps2 = __rest$5(props2, ["component"]);
return createVNode(Component, _objectSpread2(_objectSpread2({}, restProps2), attrs), {
default: () => [(_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)]
});
}
const _b = context.value, {
className: contextClassName
} = _b, restContext = __rest$5(_b, ["className"]);
const {
class: className
} = attrs, restProps = __rest$5(attrs, ["class"]);
return createVNode(OverflowContextProvider, {
"value": null
}, {
default: () => [createVNode(Item$1, _objectSpread2(_objectSpread2(_objectSpread2({
"class": classNames(contextClassName, className)
}, restContext), restProps), props2), slots)]
});
};
}
});
var __rest$4 = function(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
const RESPONSIVE = "responsive";
const INVALIDATE = "invalidate";
function defaultRenderRest(omittedItems) {
return `+ ${omittedItems.length} ...`;
}
const overflowProps = () => {
return {
id: String,
prefixCls: String,
data: Array,
itemKey: [String, Number, Function],
/** Used for `responsive`. It will limit render node to avoid perf issue */
itemWidth: {
type: Number,
default: 10
},
renderItem: Function,
/** @private Do not use in your production. Render raw node that need wrap Item by developer self */
renderRawItem: Function,
maxCount: [Number, String],
renderRest: Function,
/** @private Do not use in your production. Render raw node that need wrap Item by developer self */
renderRawRest: Function,
suffix: PropTypes.any,
component: String,
itemComponent: PropTypes.any,
/** @private This API may be refactor since not well design */
onVisibleChange: Function,
/** When set to `full`, ssr will render full items by default and remove at client side */
ssr: String,
onMousedown: Function,
role: String
};
};
const Overflow = defineComponent({
name: "Overflow",
inheritAttrs: false,
props: overflowProps(),
emits: ["visibleChange"],
setup(props2, _ref) {
let {
attrs,
emit,
slots
} = _ref;
const fullySSR = computed(() => props2.ssr === "full");
const containerWidth = shallowRef(null);
const mergedContainerWidth = computed(() => containerWidth.value || 0);
const itemWidths = shallowRef(/* @__PURE__ */ new Map());
const prevRestWidth = shallowRef(0);
const restWidth = shallowRef(0);
const suffixWidth = shallowRef(0);
const suffixFixedStart = shallowRef(null);
const displayCount = shallowRef(null);
const mergedDisplayCount = computed(() => {
if (displayCount.value === null && fullySSR.value) {
return Number.MAX_SAFE_INTEGER;
}
return displayCount.value || 0;
});
const restReady = shallowRef(false);
const itemPrefixCls = computed(() => `${props2.prefixCls}-item`);
const mergedRestWidth = computed(() => Math.max(prevRestWidth.value, restWidth.value));
const isResponsive = computed(() => !!(props2.data.length && props2.maxCount === RESPONSIVE));
const invalidate = computed(() => props2.maxCount === INVALIDATE);
const showRest = computed(() => isResponsive.value || typeof props2.maxCount === "number" && props2.data.length > props2.maxCount);
const mergedData = computed(() => {
let items = props2.data;
if (isResponsive.value) {
if (containerWidth.value === null && fullySSR.value) {
items = props2.data;
} else {
items = props2.data.slice(0, Math.min(props2.data.length, mergedContainerWidth.value / props2.itemWidth));
}
} else if (typeof props2.maxCount === "number") {
items = props2.data.slice(0, props2.maxCount);
}
return items;
});
const omittedItems = computed(() => {
if (isResponsive.value) {
return props2.data.slice(mergedDisplayCount.value + 1);
}
return props2.data.slice(mergedData.value.length);
});
const getKey2 = (item, index) => {
var _a;
if (typeof props2.itemKey === "function") {
return props2.itemKey(item);
}
return (_a = props2.itemKey && (item === null || item === void 0 ? void 0 : item[props2.itemKey])) !== null && _a !== void 0 ? _a : index;
};
const mergedRenderItem = computed(() => props2.renderItem || ((item) => item));
const updateDisplayCount = (count, notReady) => {
displayCount.value = count;
if (!notReady) {
restReady.value = count < props2.data.length - 1;
emit("visibleChange", count);
}
};
const onOverflowResize = (_, element) => {
containerWidth.value = element.clientWidth;
};
const registerSize = (key, width) => {
const clone = new Map(itemWidths.value);
if (width === null) {
clone.delete(key);
} else {
clone.set(key, width);
}
itemWidths.value = clone;
};
const registerOverflowSize = (_, width) => {
prevRestWidth.value = restWidth.value;
restWidth.value = width;
};
const registerSuffixSize = (_, width) => {
suffixWidth.value = width;
};
const getItemWidth = (index) => {
return itemWidths.value.get(getKey2(mergedData.value[index], index));
};
watch([mergedContainerWidth, itemWidths, restWidth, suffixWidth, () => props2.itemKey, mergedData], () => {
if (mergedContainerWidth.value && mergedRestWidth.value && mergedData.value) {
let totalWidth = suffixWidth.value;
const len = mergedData.value.length;
const lastIndex = len - 1;
if (!len) {
updateDisplayCount(0);
suffixFixedStart.value = null;
return;
}
for (let i = 0; i < len; i += 1) {
const currentItemWidth = getItemWidth(i);
if (currentItemWidth === void 0) {
updateDisplayCount(i - 1, true);
break;
}
totalWidth += currentItemWidth;
if (
// Only one means `totalWidth` is the final width
lastIndex === 0 && totalWidth <= mergedContainerWidth.value || // Last two width will be the final width
i === lastIndex - 1 && totalWidth + getItemWidth(lastIndex) <= mergedContainerWidth.value
) {
updateDisplayCount(lastIndex);
suffixFixedStart.value = null;
break;
} else if (totalWidth + mergedRestWidth.value > mergedContainerWidth.value) {
updateDisplayCount(i - 1);
suffixFixedStart.value = totalWidth - currentItemWidth - suffixWidth.value + restWidth.value;
break;
}
}
if (props2.suffix && getItemWidth(0) + suffixWidth.value > mergedContainerWidth.value) {
suffixFixedStart.value = null;
}
}
});
return () => {
const displayRest = restReady.value && !!omittedItems.value.length;
const {
itemComponent,
renderRawItem,
renderRawRest,
renderRest,
prefixCls = "rc-overflow",
suffix,
component: Component = "div",
id,
onMousedown
} = props2;
const {
class: className,
style
} = attrs, restAttrs = __rest$4(attrs, ["class", "style"]);
let suffixStyle = {};
if (suffixFixedStart.value !== null && isResponsive.value) {
suffixStyle = {
position: "absolute",
left: `${suffixFixedStart.value}px`,
top: 0
};
}
const itemSharedProps = {
prefixCls: itemPrefixCls.value,
responsive: isResponsive.value,
component: itemComponent,
invalidate: invalidate.value
};
const internalRenderItemNode = renderRawItem ? (item, index) => {
const key = getKey2(item, index);
return createVNode(OverflowContextProvider, {
"key": key,
"value": _extends(_extends({}, itemSharedProps), {
order: index,
item,
itemKey: key,
registerSize,
display: index <= mergedDisplayCount.value
})
}, {
default: () => [renderRawItem(item, index)]
});
} : (item, index) => {
const key = getKey2(item, index);
return createVNode(Item$1, _objectSpread2(_objectSpread2({}, itemSharedProps), {}, {
"order": index,
"key": key,
"item": item,
"renderItem": mergedRenderItem.value,
"itemKey": key,
"registerSize": registerSize,
"display": index <= mergedDisplayCount.value
}), null);
};
let restNode = () => null;
const restContextProps = {
order: displayRest ? mergedDisplayCount.value : Number.MAX_SAFE_INTEGER,
className: `${itemPrefixCls.value} ${itemPrefixCls.value}-rest`,
registerSize: registerOverflowSize,
display: displayRest
};
if (!renderRawRest) {
const mergedRenderRest = renderRest || defaultRenderRest;
restNode = () => createVNode(Item$1, _objectSpread2(_objectSpread2({}, itemSharedProps), restContextProps), {
default: () => typeof mergedRenderRest === "function" ? mergedRenderRest(omittedItems.value) : mergedRenderRest
});
} else if (renderRawRest) {
restNode = () => createVNode(OverflowContextProvider, {
"value": _extends(_extends({}, itemSharedProps), restContextProps)
}, {
default: () => [renderRawRest(omittedItems.value)]
});
}
const overflowNode = () => {
var _a;
return createVNode(Component, _objectSpread2({
"id": id,
"class": classNames(!invalidate.value && prefixCls, className),
"style": style,
"onMousedown": onMousedown,
"role": props2.role
}, restAttrs), {
default: () => [mergedData.value.map(internalRenderItemNode), showRest.value ? restNode() : null, suffix && createVNode(Item$1, _objectSpread2(_objectSpread2({}, itemSharedProps), {}, {
"order": mergedDisplayCount.value,
"class": `${itemPrefixCls.value}-suffix`,
"registerSize": registerSuffixSize,
"display": true,
"style": suffixStyle
}), {
default: () => suffix
}), (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)]
});
};
return createVNode(ResizeObserver, {
"disabled": !isResponsive.value,
"onResize": onOverflowResize
}, {
default: overflowNode
});
};
}
});
Overflow.Item = RawItem;
Overflow.RESPONSIVE = RESPONSIVE;
Overflow.INVALIDATE = INVALIDATE;
const TreeSelectLegacyContextPropsKey = Symbol("TreeSelectLegacyContextPropsKey");
function useInjectLegacySelectContext() {
return inject(TreeSelectLegacyContextPropsKey, {});
}
const props$1 = {
id: String,
prefixCls: String,
values: PropTypes.array,
open: {
type: Boolean,
default: void 0
},
searchValue: String,
inputRef: PropTypes.any,
placeholder: PropTypes.any,
disabled: {
type: Boolean,
default: void 0
},
mode: String,
showSearch: {
type: Boolean,
default: void 0
},
autofocus: {
type: Boolean,
default: void 0
},
autocomplete: String,
activeDescendantId: String,
tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
compositionStatus: Boolean,
removeIcon: PropTypes.any,
choiceTransitionName: String,
maxTagCount: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
maxTagTextLength: Number,
maxTagPlaceholder: PropTypes.any.def(() => (omittedValues) => `+ ${omittedValues.length} ...`),
tagRender: Function,
onToggleOpen: {
type: Function
},
onRemove: Function,
onInputChange: Function,
onInputPaste: Function,
onInputKeyDown: Function,
onInputMouseDown: Function,
onInputCompositionStart: Function,
onInputCompositionEnd: Function
};
const onPreventMouseDown = (event) => {
event.preventDefault();
event.stopPropagation();
};
const SelectSelector = defineComponent({
name: "MultipleSelectSelector",
inheritAttrs: false,
props: props$1,
setup(props2) {
const measureRef = shallowRef();
const inputWidth = shallowRef(0);
const focused = shallowRef(false);
const legacyTreeSelectContext = useInjectLegacySelectContext();
const selectionPrefixCls = computed(() => `${props2.prefixCls}-selection`);
const inputValue = computed(() => props2.open || props2.mode === "tags" ? props2.searchValue : "");
const inputEditable = computed(() => props2.mode === "tags" || props2.showSearch && (props2.open || focused.value));
const targetValue = ref("");
watchEffect(() => {
targetValue.value = inputValue.value;
});
onMounted(() => {
watch(targetValue, () => {
inputWidth.value = measureRef.value.scrollWidth;
}, {
flush: "post",
immediate: true
});
});
function defaultRenderSelector(title, content, itemDisabled, closable, onClose) {
return createVNode("span", {
"class": classNames(`${selectionPrefixCls.value}-item`, {
[`${selectionPrefixCls.value}-item-disabled`]: itemDisabled
}),
"title": typeof title === "string" || typeof title === "number" ? title.toString() : void 0
}, [createVNode("span", {
"class": `${selectionPrefixCls.value}-item-content`
}, [content]), closable && createVNode(TransBtn, {
"class": `${selectionPrefixCls.value}-item-remove`,
"onMousedown": onPreventMouseDown,
"onClick": onClose,
"customizeIcon": props2.removeIcon
}, {
default: () => [createTextVNode("×")]
})]);
}
function customizeRenderSelector(value, content, itemDisabled, closable, onClose, option) {
var _a;
const onMouseDown = (e) => {
onPreventMouseDown(e);
props2.onToggleOpen(!open);
};
let originData = option;
if (legacyTreeSelectContext.keyEntities) {
originData = ((_a = legacyTreeSelectContext.keyEntities[value]) === null || _a === void 0 ? void 0 : _a.node) || {};
}
return createVNode("span", {
"key": value,
"onMousedown": onMouseDown
}, [props2.tagRender({
label: content,
value,
disabled: itemDisabled,
closable,
onClose,
option: originData
})]);
}
function renderItem(valueItem) {
const {
disabled: itemDisabled,
label,
value,
option
} = valueItem;
const closable = !props2.disabled && !itemDisabled;
let displayLabel = label;
if (typeof props2.maxTagTextLength === "number") {
if (typeof label === "string" || typeof label === "number") {
const strLabel = String(displayLabel);
if (strLabel.length > props2.maxTagTextLength) {
displayLabel = `${strLabel.slice(0, props2.maxTagTextLength)}...`;
}
}
}
const onClose = (event) => {
var _a;
if (event) event.stopPropagation();
(_a = props2.onRemove) === null || _a === void 0 ? void 0 : _a.call(props2, valueItem);
};
return typeof props2.tagRender === "function" ? customizeRenderSelector(value, displayLabel, itemDisabled, closable, onClose, option) : defaultRenderSelector(label, displayLabel, itemDisabled, closable, onClose);
}
function renderRest(omittedValues) {
const {
maxTagPlaceholder = (omittedValues2) => `+ ${omittedValues2.length} ...`
} = props2;
const content = typeof maxTagPlaceholder === "function" ? maxTagPlaceholder(omittedValues) : maxTagPlaceholder;
return defaultRenderSelector(content, content, false);
}
const handleInput = (e) => {
const composing = e.target.composing;
targetValue.value = e.target.value;
if (!composing) {
props2.onInputChange(e);
}
};
return () => {
const {
id,
prefixCls,
values,
open: open2,
inputRef,
placeholder,
disabled,
autofocus,
autocomplete,
activeDescendantId,
tabindex,
compositionStatus,
onInputPaste,
onInputKeyDown,
onInputMouseDown,
onInputCompositionStart,
onInputCompositionEnd
} = props2;
const inputNode = createVNode("div", {
"class": `${selectionPrefixCls.value}-search`,
"style": {
width: inputWidth.value + "px"
},
"key": "input"
}, [createVNode(Input, {
"inputRef": inputRef,
"open": open2,
"prefixCls": prefixCls,
"id": id,
"inputElement": null,
"disabled": disabled,
"autofocus": autofocus,
"autocomplete": autocomplete,
"editable": inputEditable.value,
"activeDescendantId": activeDescendantId,
"value": targetValue.value,
"onKeydown": onInputKeyDown,
"onMousedown": onInputMouseDown,
"onChange": handleInput,
"onPaste": onInputPaste,
"onCompositionstart": onInputCompositionStart,
"onCompositionend": onInputCompositionEnd,
"tabindex": tabindex,
"attrs": pickAttrs(props2, true),
"onFocus": () => focused.value = true,
"onBlur": () => focused.value = false
}, null), createVNode("span", {
"ref": measureRef,
"class": `${selectionPrefixCls.value}-search-mirror`,
"aria-hidden": true
}, [targetValue.value, createTextVNode(" ")])]);
const selectionNode = createVNode(Overflow, {
"prefixCls": `${selectionPrefixCls.value}-overflow`,
"data": values,
"renderItem": renderItem,
"renderRest": renderRest,
"suffix": inputNode,
"itemKey": "key",
"maxCount": props2.maxTagCount,
"key": "overflow"
}, null);
return createVNode(Fragment, null, [selectionNode, !values.length && !inputValue.value && !compositionStatus && createVNode("span", {
"class": `${selectionPrefixCls.value}-placeholder`
}, [placeholder])]);
};
}
});
const props = {
inputElement: PropTypes.any,
id: String,
prefixCls: String,
values: PropTypes.array,
open: {
type: Boolean,
default: void 0
},
searchValue: String,
inputRef: PropTypes.any,
placeholder: PropTypes.any,
compositionStatus: {
type: Boolean,
default: void 0
},
disabled: {
type: Boolean,
default: void 0
},
mode: String,
showSearch: {
type: Boolean,
default: void 0
},
autofocus: {
type: Boolean,
default: void 0
},
autocomplete: String,
activeDescendantId: String,
tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
activeValue: String,
backfill: {
type: Boolean,
default: void 0
},
optionLabelRender: Function,
onInputChange: Function,
onInputPaste: Function,
onInputKeyDown: Function,
onInputMouseDown: Function,
onInputCompositionStart: Function,
onInputCompositionEnd: Function
};
const SingleSelector = defineComponent({
name: "SingleSelector",
setup(props2) {
const inputChanged = shallowRef(false);
const combobox = computed(() => props2.mode === "combobox");
const inputEditable = computed(() => combobox.value || props2.showSearch);
const inputValue = computed(() => {
let inputValue2 = props2.searchValue || "";
if (combobox.value && props2.activeValue && !inputChanged.value) {
inputValue2 = props2.activeValue;
}
return inputValue2;
});
const legacyTreeSelectContext = useInjectLegacySelectContext();
watch([combobox, () => props2.activeValue], () => {
if (combobox.value) {
inputChanged.value = false;
}
}, {
immediate: true
});
const hasTextInput = computed(() => props2.mode !== "combobox" && !props2.open && !props2.showSearch ? false : !!inputValue.value || props2.compositionStatus);
const title = computed(() => {
const item = props2.values[0];
return item && (typeof item.label === "string" || typeof item.label === "number") ? item.label.toString() : void 0;
});
const renderPlaceholder = () => {
if (props2.values[0]) {
return null;
}
const hiddenStyle = hasTextInput.value ? {
visibility: "hidden"
} : void 0;
return createVNode("span", {
"class": `${props2.prefixCls}-selection-placeholder`,
"style": hiddenStyle
}, [props2.placeholder]);
};
const handleInput = (e) => {
const composing = e.target.composing;
if (!composing) {
inputChanged.value = true;
props2.onInputChange(e);
}
};
return () => {
var _a, _b, _c, _d;
const {
inputElement,
prefixCls,
id,
values,
inputRef,
disabled,
autofocus,
autocomplete,
activeDescendantId,
open: open2,
tabindex,
optionLabelRender,
onInputKeyDown,
onInputMouseDown,
onInputPaste,
onInputCompositionStart,
onInputCompositionEnd
} = props2;
const item = values[0];
let titleNode = null;
if (item && legacyTreeSelectContext.customSlots) {
const key = (_a = item.key) !== null && _a !== void 0 ? _a : item.value;
const originData = ((_b = legacyTreeSelectContext.keyEntities[key]) === null || _b === void 0 ? void 0 : _b.node) || {};
titleNode = legacyTreeSelectContext.customSlots[(_c = originData.slots) === null || _c === void 0 ? void 0 : _c.title] || legacyTreeSelectContext.customSlots.title || item.label;
if (typeof titleNode === "function") {
titleNode = titleNode(originData);
}
} else {
titleNode = optionLabelRender && item ? optionLabelRender(item.option) : item === null || item === void 0 ? void 0 : item.label;
}
return createVNode(Fragment, null, [createVNode("span", {
"class": `${prefixCls}-selection-search`
}, [createVNode(Input, {
"inputRef": inputRef,
"prefixCls": prefixCls,
"id": id,
"open": open2,
"inputElement": inputElement,
"disabled": disabled,
"autofocus": autofocus,
"autocomplete": autocomplete,
"editable": inputEditable.value,
"activeDescendantId": activeDescendantId,
"value": inputValue.value,
"onKeydown": onInputKeyDown,
"onMousedown": onInputMouseDown,
"onChange": handleInput,
"onPaste": onInputPaste,
"onCompositionstart": onInputCompositionStart,
"onCompositionend": onInputCompositionEnd,
"tabindex": tabindex,
"attrs": pickAttrs(props2, true)
}, null)]), !combobox.value && item && !hasTextInput.value && createVNode("span", {
"class": `${prefixCls}-selection-item`,
"title": title.value
}, [createVNode(Fragment, {
"key": (_d = item.key) !== null && _d !== void 0 ? _d : item.value
}, [titleNode])]), renderPlaceholder()]);
};
}
});
SingleSelector.props = props;
SingleSelector.inheritAttrs = false;
function isValidateOpenKey(currentKeyCode) {
return ![
// System function button
KeyCode.ESC,
KeyCode.SHIFT,
KeyCode.BACKSPACE,
KeyCode.TAB,
KeyCode.WIN_KEY,
KeyCode.ALT,
KeyCode.META,
KeyCode.WIN_KEY_RIGHT,
KeyCode.CTRL,
KeyCode.SEMICOLON,
KeyCode.EQUALS,
KeyCode.CAPS_LOCK,
KeyCode.CONTEXT_MENU,
// F1-F12
Key