1
This commit is contained in:
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function isPlatformMac(): boolean;
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isPlatformMac = isPlatformMac;
|
||||
function isPlatformMac() {
|
||||
return true;
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import type { DisplayValueType } from '../BaseSelect';
|
||||
export declare function toArray<T>(value: T | T[]): T[];
|
||||
export declare const isClient: HTMLElement;
|
||||
/** Is client side and not jsdom */
|
||||
export declare const isBrowserClient: HTMLElement;
|
||||
export declare function hasValue(value: any): boolean;
|
||||
/** combo mode no value judgment function */
|
||||
export declare function isComboNoValue(value: any): boolean;
|
||||
export declare function getTitle(item: DisplayValueType): string;
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getTitle = getTitle;
|
||||
exports.hasValue = hasValue;
|
||||
exports.isClient = exports.isBrowserClient = void 0;
|
||||
exports.isComboNoValue = isComboNoValue;
|
||||
exports.toArray = toArray;
|
||||
function toArray(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return value;
|
||||
}
|
||||
return value !== undefined ? [value] : [];
|
||||
}
|
||||
const isClient = exports.isClient = typeof window !== 'undefined' && window.document && window.document.documentElement;
|
||||
|
||||
/** Is client side and not jsdom */
|
||||
const isBrowserClient = exports.isBrowserClient = process.env.NODE_ENV !== 'test' && isClient;
|
||||
function hasValue(value) {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
|
||||
/** combo mode no value judgment function */
|
||||
function isComboNoValue(value) {
|
||||
return !value && value !== 0;
|
||||
}
|
||||
function isTitleType(title) {
|
||||
return ['string', 'number'].includes(typeof title);
|
||||
}
|
||||
function getTitle(item) {
|
||||
let title = undefined;
|
||||
if (item) {
|
||||
if (isTitleType(item.title)) {
|
||||
title = item.title.toString();
|
||||
} else if (isTitleType(item.label)) {
|
||||
title = item.label.toString();
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/** keyCode Judgment function */
|
||||
export declare function isValidateOpenKey(currentKeyCode: number): boolean;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isValidateOpenKey = isValidateOpenKey;
|
||||
var _KeyCode = _interopRequireDefault(require("@rc-component/util/lib/KeyCode"));
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
/** keyCode Judgment function */
|
||||
function isValidateOpenKey(currentKeyCode) {
|
||||
return (
|
||||
// Undefined for Edge bug:
|
||||
// https://github.com/ant-design/ant-design/issues/51292
|
||||
currentKeyCode &&
|
||||
// Other keys
|
||||
![
|
||||
// System function button
|
||||
_KeyCode.default.ESC, _KeyCode.default.SHIFT, _KeyCode.default.BACKSPACE, _KeyCode.default.TAB, _KeyCode.default.WIN_KEY, _KeyCode.default.ALT, _KeyCode.default.META, _KeyCode.default.WIN_KEY_RIGHT, _KeyCode.default.CTRL, _KeyCode.default.SEMICOLON, _KeyCode.default.EQUALS, _KeyCode.default.CAPS_LOCK, _KeyCode.default.CONTEXT_MENU,
|
||||
// Arrow keys - should not trigger open when navigating in input
|
||||
_KeyCode.default.UP,
|
||||
// KeyCode.DOWN,
|
||||
_KeyCode.default.LEFT, _KeyCode.default.RIGHT,
|
||||
// F1-F12
|
||||
_KeyCode.default.F1, _KeyCode.default.F2, _KeyCode.default.F3, _KeyCode.default.F4, _KeyCode.default.F5, _KeyCode.default.F6, _KeyCode.default.F7, _KeyCode.default.F8, _KeyCode.default.F9, _KeyCode.default.F10, _KeyCode.default.F11, _KeyCode.default.F12].includes(currentKeyCode)
|
||||
);
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import * as React from 'react';
|
||||
import type { BaseOptionType, DefaultOptionType } from '../Select';
|
||||
export declare function convertChildrenToData<OptionType extends BaseOptionType = DefaultOptionType>(nodes: React.ReactNode, optionOnly?: boolean): OptionType[];
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.convertChildrenToData = convertChildrenToData;
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
var _toArray = _interopRequireDefault(require("@rc-component/util/lib/Children/toArray"));
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
||||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
||||
function convertNodeToOption(node) {
|
||||
const {
|
||||
key,
|
||||
props: {
|
||||
children,
|
||||
value,
|
||||
...restProps
|
||||
}
|
||||
} = node;
|
||||
return {
|
||||
key,
|
||||
value: value !== undefined ? value : key,
|
||||
children,
|
||||
...restProps
|
||||
};
|
||||
}
|
||||
function convertChildrenToData(nodes, optionOnly = false) {
|
||||
return (0, _toArray.default)(nodes).map((node, index) => {
|
||||
if (! /*#__PURE__*/React.isValidElement(node) || !node.type) {
|
||||
return null;
|
||||
}
|
||||
const {
|
||||
type: {
|
||||
isSelectOptGroup
|
||||
},
|
||||
key,
|
||||
props: {
|
||||
children,
|
||||
...restProps
|
||||
}
|
||||
} = node;
|
||||
if (optionOnly || !isSelectOptGroup) {
|
||||
return convertNodeToOption(node);
|
||||
}
|
||||
return {
|
||||
key: `__RC_SELECT_GRP__${key === null ? index : key}__`,
|
||||
label: key,
|
||||
...restProps,
|
||||
options: convertChildrenToData(children)
|
||||
};
|
||||
}).filter(data => data);
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export declare function isPlatformMac(): boolean;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isPlatformMac = isPlatformMac;
|
||||
/* istanbul ignore file */
|
||||
function isPlatformMac() {
|
||||
return /(mac\sos|macintosh)/i.test(navigator.appVersion);
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import type { BaseOptionType, DefaultOptionType } from '../Select';
|
||||
import type { FieldNames } from '../Select';
|
||||
import type { FlattenOptionData } from '../interface';
|
||||
export declare function isValidCount(value?: number): boolean;
|
||||
export declare function fillFieldNames(fieldNames: FieldNames | undefined, childrenAsData: boolean): {
|
||||
label: string;
|
||||
value: string;
|
||||
options: string;
|
||||
groupLabel: string;
|
||||
};
|
||||
/**
|
||||
* Flat options into flatten list.
|
||||
* We use `optionOnly` here is aim to avoid user use nested option group.
|
||||
* Here is simply set `key` to the index if not provided.
|
||||
*/
|
||||
export declare function flattenOptions<OptionType extends BaseOptionType = DefaultOptionType>(options: OptionType[], { fieldNames, childrenAsData }?: {
|
||||
fieldNames?: FieldNames;
|
||||
childrenAsData?: boolean;
|
||||
}): FlattenOptionData<OptionType>[];
|
||||
/**
|
||||
* Inject `props` into `option` for legacy usage
|
||||
*/
|
||||
export declare function injectPropsWithOption<T extends object>(option: T): T;
|
||||
export declare const getSeparatedContent: (text: string, tokens: string[], end?: number) => string[];
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.fillFieldNames = fillFieldNames;
|
||||
exports.flattenOptions = flattenOptions;
|
||||
exports.getSeparatedContent = void 0;
|
||||
exports.injectPropsWithOption = injectPropsWithOption;
|
||||
exports.isValidCount = isValidCount;
|
||||
var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function getKey(data, index) {
|
||||
const {
|
||||
key
|
||||
} = data;
|
||||
let value;
|
||||
if ('value' in data) {
|
||||
({
|
||||
value
|
||||
} = data);
|
||||
}
|
||||
if (key !== null && key !== undefined) {
|
||||
return key;
|
||||
}
|
||||
if (value !== undefined) {
|
||||
return value;
|
||||
}
|
||||
return `rc-index-key-${index}`;
|
||||
}
|
||||
function isValidCount(value) {
|
||||
return typeof value !== 'undefined' && !Number.isNaN(value);
|
||||
}
|
||||
function fillFieldNames(fieldNames, childrenAsData) {
|
||||
const {
|
||||
label,
|
||||
value,
|
||||
options,
|
||||
groupLabel
|
||||
} = fieldNames || {};
|
||||
const mergedLabel = label || (childrenAsData ? 'children' : 'label');
|
||||
return {
|
||||
label: mergedLabel,
|
||||
value: value || 'value',
|
||||
options: options || 'options',
|
||||
groupLabel: groupLabel || mergedLabel
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Flat options into flatten list.
|
||||
* We use `optionOnly` here is aim to avoid user use nested option group.
|
||||
* Here is simply set `key` to the index if not provided.
|
||||
*/
|
||||
function flattenOptions(options, {
|
||||
fieldNames,
|
||||
childrenAsData
|
||||
} = {}) {
|
||||
const flattenList = [];
|
||||
const {
|
||||
label: fieldLabel,
|
||||
value: fieldValue,
|
||||
options: fieldOptions,
|
||||
groupLabel
|
||||
} = fillFieldNames(fieldNames, false);
|
||||
function dig(list, isGroupOption) {
|
||||
if (!Array.isArray(list)) {
|
||||
return;
|
||||
}
|
||||
list.forEach(data => {
|
||||
if (isGroupOption || !(fieldOptions in data)) {
|
||||
const value = data[fieldValue];
|
||||
|
||||
// Option
|
||||
flattenList.push({
|
||||
key: getKey(data, flattenList.length),
|
||||
groupOption: isGroupOption,
|
||||
data,
|
||||
label: data[fieldLabel],
|
||||
value
|
||||
});
|
||||
} else {
|
||||
let grpLabel = data[groupLabel];
|
||||
if (grpLabel === undefined && childrenAsData) {
|
||||
grpLabel = data.label;
|
||||
}
|
||||
|
||||
// Option Group
|
||||
flattenList.push({
|
||||
key: getKey(data, flattenList.length),
|
||||
group: true,
|
||||
data,
|
||||
label: grpLabel
|
||||
});
|
||||
dig(data[fieldOptions], true);
|
||||
}
|
||||
});
|
||||
}
|
||||
dig(options, false);
|
||||
return flattenList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject `props` into `option` for legacy usage
|
||||
*/
|
||||
function injectPropsWithOption(option) {
|
||||
const newOption = {
|
||||
...option
|
||||
};
|
||||
if (!('props' in newOption)) {
|
||||
Object.defineProperty(newOption, 'props', {
|
||||
get() {
|
||||
(0, _warning.default)(false, 'Return type is option instead of Option instance. Please read value directly instead of reading from `props`.');
|
||||
return newOption;
|
||||
}
|
||||
});
|
||||
}
|
||||
return newOption;
|
||||
}
|
||||
const getSeparatedContent = (text, tokens, end) => {
|
||||
if (!tokens || !tokens.length) {
|
||||
return null;
|
||||
}
|
||||
let match = false;
|
||||
const separate = (str, [token, ...restTokens]) => {
|
||||
if (!token) {
|
||||
return [str];
|
||||
}
|
||||
const list = str.split(token);
|
||||
match = match || list.length > 1;
|
||||
return list.reduce((prevList, unitStr) => [...prevList, ...separate(unitStr, restTokens)], []).filter(Boolean);
|
||||
};
|
||||
const list = separate(text, tokens);
|
||||
if (match) {
|
||||
return typeof end !== 'undefined' ? list.slice(0, end) : list;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
exports.getSeparatedContent = getSeparatedContent;
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { DefaultOptionType, FieldNames, SelectProps } from '../Select';
|
||||
declare function warningProps(props: SelectProps): void;
|
||||
export declare function warningNullOptions(options: DefaultOptionType[], fieldNames: FieldNames): void;
|
||||
export default warningProps;
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
exports.warningNullOptions = warningNullOptions;
|
||||
var _toArray = _interopRequireDefault(require("@rc-component/util/lib/Children/toArray"));
|
||||
var _warning = _interopRequireWildcard(require("@rc-component/util/lib/warning"));
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
var _BaseSelect = require("../BaseSelect");
|
||||
var _commonUtil = require("./commonUtil");
|
||||
var _legacyUtil = require("./legacyUtil");
|
||||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
||||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function warningProps(props) {
|
||||
const {
|
||||
mode,
|
||||
options,
|
||||
children,
|
||||
backfill,
|
||||
allowClear,
|
||||
placeholder,
|
||||
getInputElement,
|
||||
showSearch,
|
||||
onSearch,
|
||||
defaultOpen,
|
||||
autoFocus,
|
||||
labelInValue,
|
||||
value,
|
||||
optionLabelProp
|
||||
} = props;
|
||||
const multiple = (0, _BaseSelect.isMultiple)(mode);
|
||||
const mergedShowSearch = showSearch !== undefined ? showSearch : multiple || mode === 'combobox';
|
||||
const mergedOptions = options || (0, _legacyUtil.convertChildrenToData)(children);
|
||||
|
||||
// `tags` should not set option as disabled
|
||||
(0, _warning.default)(mode !== 'tags' || mergedOptions.every(opt => !opt.disabled), 'Please avoid setting option to disabled in tags mode since user can always type text as tag.');
|
||||
|
||||
// `combobox` & `tags` should option be `string` type
|
||||
if (mode === 'tags' || mode === 'combobox') {
|
||||
const hasNumberValue = mergedOptions.some(item => {
|
||||
if (item.options) {
|
||||
return item.options.some(opt => typeof ('value' in opt ? opt.value : opt.key) === 'number');
|
||||
}
|
||||
return typeof ('value' in item ? item.value : item.key) === 'number';
|
||||
});
|
||||
(0, _warning.default)(!hasNumberValue, '`value` of Option should not use number type when `mode` is `tags` or `combobox`.');
|
||||
}
|
||||
|
||||
// `combobox` should not use `optionLabelProp`
|
||||
(0, _warning.default)(mode !== 'combobox' || !optionLabelProp, '`combobox` mode not support `optionLabelProp`. Please set `value` on Option directly.');
|
||||
|
||||
// Only `combobox` support `backfill`
|
||||
(0, _warning.default)(mode === 'combobox' || !backfill, '`backfill` only works with `combobox` mode.');
|
||||
|
||||
// Only `combobox` support `getInputElement`
|
||||
(0, _warning.default)(mode === 'combobox' || !getInputElement, '`getInputElement` only work with `combobox` mode.');
|
||||
|
||||
// Customize `getInputElement` should not use `allowClear` & `placeholder`
|
||||
(0, _warning.noteOnce)(mode !== 'combobox' || !getInputElement || !allowClear || !placeholder, 'Customize `getInputElement` should customize clear and placeholder logic instead of configuring `allowClear` and `placeholder`.');
|
||||
|
||||
// `onSearch` should use in `combobox` or `showSearch`
|
||||
if (onSearch && !mergedShowSearch && mode !== 'combobox' && mode !== 'tags') {
|
||||
(0, _warning.default)(false, '`onSearch` should work with `showSearch` instead of use alone.');
|
||||
}
|
||||
(0, _warning.noteOnce)(!defaultOpen || autoFocus, '`defaultOpen` makes Select open without focus which means it will not close by click outside. You can set `autoFocus` if needed.');
|
||||
if (value !== undefined && value !== null) {
|
||||
const values = (0, _commonUtil.toArray)(value);
|
||||
(0, _warning.default)(!labelInValue || values.every(val => typeof val === 'object' && ('key' in val || 'value' in val)), '`value` should in shape of `{ value: string | number, label?: ReactNode }` when you set `labelInValue` to `true`');
|
||||
(0, _warning.default)(!multiple || Array.isArray(value), '`value` should be array when `mode` is `multiple` or `tags`');
|
||||
}
|
||||
|
||||
// Syntactic sugar should use correct children type
|
||||
if (children) {
|
||||
let invalidateChildType = null;
|
||||
(0, _toArray.default)(children).some(node => {
|
||||
if (! /*#__PURE__*/React.isValidElement(node) || !node.type) {
|
||||
return false;
|
||||
}
|
||||
const {
|
||||
type
|
||||
} = node;
|
||||
if (type.isSelectOption) {
|
||||
return false;
|
||||
}
|
||||
if (type.isSelectOptGroup) {
|
||||
const allChildrenValid = (0, _toArray.default)(node.props.children).every(subNode => {
|
||||
if (! /*#__PURE__*/React.isValidElement(subNode) || !node.type || subNode.type.isSelectOption) {
|
||||
return true;
|
||||
}
|
||||
invalidateChildType = subNode.type;
|
||||
return false;
|
||||
});
|
||||
if (allChildrenValid) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
invalidateChildType = type;
|
||||
return true;
|
||||
});
|
||||
if (invalidateChildType) {
|
||||
(0, _warning.default)(false, `\`children\` should be \`Select.Option\` or \`Select.OptGroup\` instead of \`${invalidateChildType.displayName || invalidateChildType.name || invalidateChildType}\`.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// value in Select option should not be null
|
||||
// note: OptGroup has options too
|
||||
function warningNullOptions(options, fieldNames) {
|
||||
if (options) {
|
||||
const recursiveOptions = (optionsList, inGroup = false) => {
|
||||
for (let i = 0; i < optionsList.length; i++) {
|
||||
const option = optionsList[i];
|
||||
if (option[fieldNames?.value] === null) {
|
||||
(0, _warning.default)(false, '`value` in Select options should not be `null`.');
|
||||
return true;
|
||||
}
|
||||
if (!inGroup && Array.isArray(option[fieldNames?.options]) && recursiveOptions(option[fieldNames?.options], true)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
recursiveOptions(options);
|
||||
}
|
||||
}
|
||||
var _default = exports.default = warningProps;
|
||||
Reference in New Issue
Block a user