1
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
import * as React from 'react';
|
||||
export declare function parseChildren(children: React.ReactNode | undefined, keyPath: string[]): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import toArray from "@rc-component/util/es/Children/toArray";
|
||||
import * as React from 'react';
|
||||
export function parseChildren(children, keyPath) {
|
||||
return toArray(children).map((child, index) => {
|
||||
if ( /*#__PURE__*/React.isValidElement(child)) {
|
||||
const {
|
||||
key
|
||||
} = child;
|
||||
let eventKey = child.props?.eventKey ?? key;
|
||||
const emptyKey = eventKey === null || eventKey === undefined;
|
||||
if (emptyKey) {
|
||||
eventKey = `tmp_key-${[...keyPath, index].join('-')}`;
|
||||
}
|
||||
const cloneProps = {
|
||||
key: eventKey,
|
||||
eventKey
|
||||
};
|
||||
if (process.env.NODE_ENV !== 'production' && emptyKey) {
|
||||
cloneProps.warnKey = true;
|
||||
}
|
||||
return /*#__PURE__*/React.cloneElement(child, cloneProps);
|
||||
}
|
||||
return child;
|
||||
});
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import type { CSSMotionProps } from '@rc-component/motion';
|
||||
export declare function getMotion(mode: string, motion?: CSSMotionProps, defaultMotions?: Record<string, CSSMotionProps>): CSSMotionProps;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
export function getMotion(mode, motion, defaultMotions) {
|
||||
if (motion) {
|
||||
return motion;
|
||||
}
|
||||
if (defaultMotions) {
|
||||
return defaultMotions[mode] || defaultMotions.other;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import * as React from 'react';
|
||||
import type { Components, ItemType } from '../interface';
|
||||
export declare function parseItems(children: React.ReactNode | undefined, items: ItemType[] | undefined, keyPath: string[], components: Components, prefixCls?: string): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
||||
import * as React from 'react';
|
||||
import Divider from "../Divider";
|
||||
import MenuItem from "../MenuItem";
|
||||
import MenuItemGroup from "../MenuItemGroup";
|
||||
import SubMenu from "../SubMenu";
|
||||
import { parseChildren } from "./commonUtil";
|
||||
function convertItemsToNodes(list, components, prefixCls) {
|
||||
const {
|
||||
item: MergedMenuItem,
|
||||
group: MergedMenuItemGroup,
|
||||
submenu: MergedSubMenu,
|
||||
divider: MergedDivider
|
||||
} = components;
|
||||
return (list || []).map((opt, index) => {
|
||||
if (opt && typeof opt === 'object') {
|
||||
const {
|
||||
label,
|
||||
children,
|
||||
key,
|
||||
type,
|
||||
extra,
|
||||
...restProps
|
||||
} = opt;
|
||||
const mergedKey = key ?? `tmp-${index}`;
|
||||
|
||||
// MenuItemGroup & SubMenuItem
|
||||
if (children || type === 'group') {
|
||||
if (type === 'group') {
|
||||
// Group
|
||||
return /*#__PURE__*/React.createElement(MergedMenuItemGroup, _extends({
|
||||
key: mergedKey
|
||||
}, restProps, {
|
||||
title: label
|
||||
}), convertItemsToNodes(children, components, prefixCls));
|
||||
}
|
||||
|
||||
// Sub Menu
|
||||
return /*#__PURE__*/React.createElement(MergedSubMenu, _extends({
|
||||
key: mergedKey
|
||||
}, restProps, {
|
||||
title: label
|
||||
}), convertItemsToNodes(children, components, prefixCls));
|
||||
}
|
||||
|
||||
// MenuItem & Divider
|
||||
if (type === 'divider') {
|
||||
return /*#__PURE__*/React.createElement(MergedDivider, _extends({
|
||||
key: mergedKey
|
||||
}, restProps));
|
||||
}
|
||||
return /*#__PURE__*/React.createElement(MergedMenuItem, _extends({
|
||||
key: mergedKey
|
||||
}, restProps, {
|
||||
extra: extra
|
||||
}), label, (!!extra || extra === 0) && /*#__PURE__*/React.createElement("span", {
|
||||
className: `${prefixCls}-item-extra`
|
||||
}, extra));
|
||||
}
|
||||
return null;
|
||||
}).filter(opt => opt);
|
||||
}
|
||||
export function parseItems(children, items, keyPath, components, prefixCls) {
|
||||
let childNodes = children;
|
||||
const mergedComponents = {
|
||||
divider: Divider,
|
||||
item: MenuItem,
|
||||
group: MenuItemGroup,
|
||||
submenu: SubMenu,
|
||||
...components
|
||||
};
|
||||
if (items) {
|
||||
childNodes = convertItemsToNodes(items, mergedComponents, prefixCls);
|
||||
}
|
||||
return parseChildren(childNodes, keyPath);
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export declare function nextSlice(callback: () => void): void;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export function nextSlice(callback) {
|
||||
/* istanbul ignore next */
|
||||
Promise.resolve().then(callback);
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/// <reference types="react" />
|
||||
/**
|
||||
* `onClick` event return `info.item` which point to react node directly.
|
||||
* We should warning this since it will not work on FC.
|
||||
*/
|
||||
export declare function warnItemProp<T extends {
|
||||
item: React.ReactInstance;
|
||||
}>({ item, ...restInfo }: T): T;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import warning from "@rc-component/util/es/warning";
|
||||
|
||||
/**
|
||||
* `onClick` event return `info.item` which point to react node directly.
|
||||
* We should warning this since it will not work on FC.
|
||||
*/
|
||||
export function warnItemProp({
|
||||
item,
|
||||
...restInfo
|
||||
}) {
|
||||
Object.defineProperty(restInfo, 'item', {
|
||||
get: () => {
|
||||
warning(false, '`info.item` is deprecated since we will move to function component that not provides React Node instance in future.');
|
||||
return item;
|
||||
}
|
||||
});
|
||||
return restInfo;
|
||||
}
|
||||
Reference in New Issue
Block a user