add all frontend files

This commit is contained in:
2026-01-17 15:16:36 -05:00
parent ff16ae7858
commit e40287e4aa
25704 changed files with 1935289 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
import * as React from 'react';
export interface IconProps extends React.HtmlHTMLAttributes<HTMLElement> {
icon?: React.ReactNode;
type: 'suffix' | 'clear';
}
export default function Icon(props: IconProps): React.JSX.Element;
export interface ClearIconProps extends Omit<IconProps, 'type'> {
onClear: VoidFunction;
}
export declare function ClearIcon({ onClear, ...restProps }: ClearIconProps): React.JSX.Element;

31
node_modules/rc-picker/es/PickerInput/Selector/Icon.js generated vendored Normal file
View File

@@ -0,0 +1,31 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["icon", "type"],
_excluded2 = ["onClear"];
import * as React from 'react';
import PickerContext from "../context";
export default function Icon(props) {
var icon = props.icon,
type = props.type,
restProps = _objectWithoutProperties(props, _excluded);
var _React$useContext = React.useContext(PickerContext),
prefixCls = _React$useContext.prefixCls;
return icon ? /*#__PURE__*/React.createElement("span", _extends({
className: "".concat(prefixCls, "-").concat(type)
}, restProps), icon) : null;
}
export function ClearIcon(_ref) {
var onClear = _ref.onClear,
restProps = _objectWithoutProperties(_ref, _excluded2);
return /*#__PURE__*/React.createElement(Icon, _extends({}, restProps, {
type: "clear",
role: "button",
onMouseDown: function onMouseDown(e) {
e.preventDefault();
},
onClick: function onClick(e) {
e.stopPropagation();
onClear();
}
}));
}

View File

@@ -0,0 +1,28 @@
import * as React from 'react';
import type { PickerRef } from '../../interface';
export interface InputRef extends PickerRef {
inputElement: HTMLInputElement;
}
export interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> {
format?: string;
validateFormat: (value: string) => boolean;
active?: boolean;
/** Used for single picker only */
showActiveCls?: boolean;
suffixIcon?: React.ReactNode;
value?: string;
onChange: (value: string) => void;
onSubmit: VoidFunction;
/** Meaning current is from the hover cell getting the placeholder text */
helped?: boolean;
/**
* Trigger when input need additional help.
* Like open the popup for interactive.
*/
onHelp: () => void;
preserveInvalidOnBlur?: boolean;
invalid?: boolean;
clearIcon?: React.ReactNode;
}
declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<InputRef>>;
export default Input;

368
node_modules/rc-picker/es/PickerInput/Selector/Input.js generated vendored Normal file
View File

@@ -0,0 +1,368 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["active", "showActiveCls", "suffixIcon", "format", "validateFormat", "onChange", "onInput", "helped", "onHelp", "onSubmit", "onKeyDown", "preserveInvalidOnBlur", "invalid", "clearIcon"];
import classNames from 'classnames';
import { useEvent } from 'rc-util';
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
import raf from "rc-util/es/raf";
import * as React from 'react';
import { leftPad } from "../../utils/miscUtil";
import PickerContext from "../context";
import useLockEffect from "../hooks/useLockEffect";
import Icon from "./Icon";
import MaskFormat from "./MaskFormat";
import { getMaskRange } from "./util";
// Format logic
//
// First time on focus:
// 1. check if the text is valid, if not fill with format
// 2. set highlight cell to the first cell
// Cells
// 1. Selection the index cell, set inner `cacheValue` to ''
// 2. Key input filter non-number char, patch after the `cacheValue`
// 1. Replace the `cacheValue` with input align the cell length
// 2. Re-selection the mask cell
// 3. If `cacheValue` match the limit length or cell format (like 1 ~ 12 month), go to next cell
var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
var active = props.active,
_props$showActiveCls = props.showActiveCls,
showActiveCls = _props$showActiveCls === void 0 ? true : _props$showActiveCls,
suffixIcon = props.suffixIcon,
format = props.format,
validateFormat = props.validateFormat,
onChange = props.onChange,
onInput = props.onInput,
helped = props.helped,
onHelp = props.onHelp,
onSubmit = props.onSubmit,
onKeyDown = props.onKeyDown,
_props$preserveInvali = props.preserveInvalidOnBlur,
preserveInvalidOnBlur = _props$preserveInvali === void 0 ? false : _props$preserveInvali,
invalid = props.invalid,
clearIcon = props.clearIcon,
restProps = _objectWithoutProperties(props, _excluded);
var value = props.value,
onFocus = props.onFocus,
onBlur = props.onBlur,
onMouseUp = props.onMouseUp;
var _React$useContext = React.useContext(PickerContext),
prefixCls = _React$useContext.prefixCls,
_React$useContext$inp = _React$useContext.input,
Component = _React$useContext$inp === void 0 ? 'input' : _React$useContext$inp;
var inputPrefixCls = "".concat(prefixCls, "-input");
// ======================== Value =========================
var _React$useState = React.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
focused = _React$useState2[0],
setFocused = _React$useState2[1];
var _React$useState3 = React.useState(value),
_React$useState4 = _slicedToArray(_React$useState3, 2),
internalInputValue = _React$useState4[0],
setInputValue = _React$useState4[1];
var _React$useState5 = React.useState(''),
_React$useState6 = _slicedToArray(_React$useState5, 2),
focusCellText = _React$useState6[0],
setFocusCellText = _React$useState6[1];
var _React$useState7 = React.useState(null),
_React$useState8 = _slicedToArray(_React$useState7, 2),
focusCellIndex = _React$useState8[0],
setFocusCellIndex = _React$useState8[1];
var _React$useState9 = React.useState(null),
_React$useState10 = _slicedToArray(_React$useState9, 2),
forceSelectionSyncMark = _React$useState10[0],
forceSelectionSync = _React$useState10[1];
var inputValue = internalInputValue || '';
// Sync value if needed
React.useEffect(function () {
setInputValue(value);
}, [value]);
// ========================= Refs =========================
var holderRef = React.useRef();
var inputRef = React.useRef();
React.useImperativeHandle(ref, function () {
return {
nativeElement: holderRef.current,
inputElement: inputRef.current,
focus: function focus(options) {
inputRef.current.focus(options);
},
blur: function blur() {
inputRef.current.blur();
}
};
});
// ======================== Format ========================
var maskFormat = React.useMemo(function () {
return new MaskFormat(format || '');
}, [format]);
var _React$useMemo = React.useMemo(function () {
if (helped) {
return [0, 0];
}
return maskFormat.getSelection(focusCellIndex);
}, [maskFormat, focusCellIndex, helped]),
_React$useMemo2 = _slicedToArray(_React$useMemo, 2),
selectionStart = _React$useMemo2[0],
selectionEnd = _React$useMemo2[1];
// ======================== Modify ========================
// When input modify content, trigger `onHelp` if is not the format
var onModify = function onModify(text) {
if (text && text !== format && text !== value) {
onHelp();
}
};
// ======================== Change ========================
/**
* Triggered by paste, keyDown and focus to show format
*/
var triggerInputChange = useEvent(function (text) {
if (validateFormat(text)) {
onChange(text);
}
setInputValue(text);
onModify(text);
});
// Directly trigger `onChange` if `format` is empty
var onInternalChange = function onInternalChange(event) {
// Hack `onChange` with format to do nothing
if (!format) {
var text = event.target.value;
onModify(text);
setInputValue(text);
onChange(text);
}
};
var onFormatPaste = function onFormatPaste(event) {
// Get paste text
var pasteText = event.clipboardData.getData('text');
if (validateFormat(pasteText)) {
triggerInputChange(pasteText);
}
};
// ======================== Mouse =========================
// When `mouseDown` get focus, it's better to not to change the selection
// Since the up position maybe not is the first cell
var mouseDownRef = React.useRef(false);
var onFormatMouseDown = function onFormatMouseDown() {
mouseDownRef.current = true;
};
var onFormatMouseUp = function onFormatMouseUp(event) {
var _ref = event.target,
start = _ref.selectionStart;
var closeMaskIndex = maskFormat.getMaskCellIndex(start);
setFocusCellIndex(closeMaskIndex);
// Force update the selection
forceSelectionSync({});
onMouseUp === null || onMouseUp === void 0 || onMouseUp(event);
mouseDownRef.current = false;
};
// ====================== Focus Blur ======================
var onFormatFocus = function onFormatFocus(event) {
setFocused(true);
setFocusCellIndex(0);
setFocusCellText('');
onFocus(event);
};
var onSharedBlur = function onSharedBlur(event) {
onBlur(event);
};
var onFormatBlur = function onFormatBlur(event) {
setFocused(false);
onSharedBlur(event);
};
// ======================== Active ========================
// Check if blur need reset input value
useLockEffect(active, function () {
if (!active && !preserveInvalidOnBlur) {
setInputValue(value);
}
});
// ======================= Keyboard =======================
var onSharedKeyDown = function onSharedKeyDown(event) {
if (event.key === 'Enter' && validateFormat(inputValue)) {
onSubmit();
}
onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
};
var onFormatKeyDown = function onFormatKeyDown(event) {
onSharedKeyDown(event);
var key = event.key;
// Save the cache with cell text
var nextCellText = null;
// Fill in the input
var nextFillText = null;
var maskCellLen = selectionEnd - selectionStart;
var cellFormat = format.slice(selectionStart, selectionEnd);
// Cell Index
var offsetCellIndex = function offsetCellIndex(offset) {
setFocusCellIndex(function (idx) {
var nextIndex = idx + offset;
nextIndex = Math.max(nextIndex, 0);
nextIndex = Math.min(nextIndex, maskFormat.size() - 1);
return nextIndex;
});
};
// Range
var offsetCellValue = function offsetCellValue(offset) {
var _getMaskRange = getMaskRange(cellFormat),
_getMaskRange2 = _slicedToArray(_getMaskRange, 3),
rangeStart = _getMaskRange2[0],
rangeEnd = _getMaskRange2[1],
rangeDefault = _getMaskRange2[2];
var currentText = inputValue.slice(selectionStart, selectionEnd);
var currentTextNum = Number(currentText);
if (isNaN(currentTextNum)) {
return String(rangeDefault ? rangeDefault : offset > 0 ? rangeStart : rangeEnd);
}
var num = currentTextNum + offset;
var range = rangeEnd - rangeStart + 1;
return String(rangeStart + (range + num - rangeStart) % range);
};
switch (key) {
// =============== Remove ===============
case 'Backspace':
case 'Delete':
nextCellText = '';
nextFillText = cellFormat;
break;
// =============== Arrows ===============
// Left key
case 'ArrowLeft':
nextCellText = '';
offsetCellIndex(-1);
break;
// Right key
case 'ArrowRight':
nextCellText = '';
offsetCellIndex(1);
break;
// Up key
case 'ArrowUp':
nextCellText = '';
nextFillText = offsetCellValue(1);
break;
// Down key
case 'ArrowDown':
nextCellText = '';
nextFillText = offsetCellValue(-1);
break;
// =============== Number ===============
default:
if (!isNaN(Number(key))) {
nextCellText = focusCellText + key;
nextFillText = nextCellText;
}
break;
}
// Update cell text
if (nextCellText !== null) {
setFocusCellText(nextCellText);
if (nextCellText.length >= maskCellLen) {
// Go to next cell
offsetCellIndex(1);
setFocusCellText('');
}
}
// Update the input text
if (nextFillText !== null) {
// Replace selection range with `nextCellText`
var nextFocusValue =
// before
inputValue.slice(0, selectionStart) +
// replace
leftPad(nextFillText, maskCellLen) +
// after
inputValue.slice(selectionEnd);
triggerInputChange(nextFocusValue.slice(0, format.length));
}
// Always trigger selection sync after key down
forceSelectionSync({});
};
// ======================== Format ========================
var rafRef = React.useRef();
useLayoutEffect(function () {
if (!focused || !format || mouseDownRef.current) {
return;
}
// Reset with format if not match
if (!maskFormat.match(inputValue)) {
triggerInputChange(format);
return;
}
// Match the selection range
inputRef.current.setSelectionRange(selectionStart, selectionEnd);
// Chrome has the bug anchor position looks not correct but actually correct
rafRef.current = raf(function () {
inputRef.current.setSelectionRange(selectionStart, selectionEnd);
});
return function () {
raf.cancel(rafRef.current);
};
}, [maskFormat, format, focused, inputValue, focusCellIndex, selectionStart, selectionEnd, forceSelectionSyncMark, triggerInputChange]);
// ======================== Render ========================
// Input props for format
var inputProps = format ? {
onFocus: onFormatFocus,
onBlur: onFormatBlur,
onKeyDown: onFormatKeyDown,
onMouseDown: onFormatMouseDown,
onMouseUp: onFormatMouseUp,
onPaste: onFormatPaste
} : {};
return /*#__PURE__*/React.createElement("div", {
ref: holderRef,
className: classNames(inputPrefixCls, _defineProperty(_defineProperty({}, "".concat(inputPrefixCls, "-active"), active && showActiveCls), "".concat(inputPrefixCls, "-placeholder"), helped))
}, /*#__PURE__*/React.createElement(Component, _extends({
ref: inputRef,
"aria-invalid": invalid,
autoComplete: "off"
}, restProps, {
onKeyDown: onSharedKeyDown,
onBlur: onSharedBlur
// Replace with format
}, inputProps, {
// Value
value: inputValue,
onChange: onInternalChange
})), /*#__PURE__*/React.createElement(Icon, {
type: "suffix",
icon: suffixIcon
}), clearIcon);
});
if (process.env.NODE_ENV !== 'production') {
Input.displayName = 'Input';
}
export default Input;

View File

@@ -0,0 +1,22 @@
declare const FORMAT_KEYS: string[];
export type FormatKey = (typeof FORMAT_KEYS)[number];
export interface Cell {
text: string;
mask: boolean;
start: number;
end: number;
}
export default class MaskFormat {
format: string;
maskFormat: string;
cells: Cell[];
maskCells: Cell[];
constructor(format: string);
getSelection(maskCellIndex: number): [start: number, end: number];
/** Check given text match format */
match(text: string): boolean;
/** Get mask cell count */
size(): number;
getMaskCellIndex(anchorIndex: number): number;
}
export {};

View File

@@ -0,0 +1,103 @@
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
var FORMAT_KEYS = ['YYYY', 'MM', 'DD', 'HH', 'mm', 'ss', 'SSS'];
// Use Chinese character to avoid conflict with the mask format
var REPLACE_KEY = '顧';
var MaskFormat = /*#__PURE__*/function () {
function MaskFormat(format) {
_classCallCheck(this, MaskFormat);
_defineProperty(this, "format", void 0);
_defineProperty(this, "maskFormat", void 0);
_defineProperty(this, "cells", void 0);
_defineProperty(this, "maskCells", void 0);
this.format = format;
// Generate mask format
var replaceKeys = FORMAT_KEYS.map(function (key) {
return "(".concat(key, ")");
}).join('|');
var replaceReg = new RegExp(replaceKeys, 'g');
this.maskFormat = format.replace(replaceReg,
// Use Chinese character to avoid user use it in format
function (key) {
return REPLACE_KEY.repeat(key.length);
});
// Generate cells
var cellReg = new RegExp("(".concat(FORMAT_KEYS.join('|'), ")"));
var strCells = (format.split(cellReg) || []).filter(function (str) {
return str;
});
var offset = 0;
this.cells = strCells.map(function (text) {
var mask = FORMAT_KEYS.includes(text);
var start = offset;
var end = offset + text.length;
offset = end;
return {
text: text,
mask: mask,
start: start,
end: end
};
});
// Mask cells
this.maskCells = this.cells.filter(function (cell) {
return cell.mask;
});
}
_createClass(MaskFormat, [{
key: "getSelection",
value: function getSelection(maskCellIndex) {
var _ref = this.maskCells[maskCellIndex] || {},
start = _ref.start,
end = _ref.end;
return [start || 0, end || 0];
}
/** Check given text match format */
}, {
key: "match",
value: function match(text) {
for (var i = 0; i < this.maskFormat.length; i += 1) {
var maskChar = this.maskFormat[i];
var textChar = text[i];
if (!textChar || maskChar !== REPLACE_KEY && maskChar !== textChar) {
return false;
}
}
return true;
}
/** Get mask cell count */
}, {
key: "size",
value: function size() {
return this.maskCells.length;
}
}, {
key: "getMaskCellIndex",
value: function getMaskCellIndex(anchorIndex) {
var closetDist = Number.MAX_SAFE_INTEGER;
var closetIndex = 0;
for (var i = 0; i < this.maskCells.length; i += 1) {
var _this$maskCells$i = this.maskCells[i],
start = _this$maskCells$i.start,
end = _this$maskCells$i.end;
if (anchorIndex >= start && anchorIndex <= end) {
return i;
}
var dist = Math.min(Math.abs(anchorIndex - start), Math.abs(anchorIndex - end));
if (dist < closetDist) {
closetDist = dist;
closetIndex = i;
}
}
return closetIndex;
}
}]);
return MaskFormat;
}();
export { MaskFormat as default };

View File

@@ -0,0 +1,26 @@
import * as React from 'react';
import type { RangePickerRef, SelectorProps } from '../../interface';
export type SelectorIdType = string | {
start?: string;
end?: string;
};
export interface RangeSelectorProps<DateType = any> extends SelectorProps<DateType> {
id?: SelectorIdType;
activeIndex: number | null;
separator?: React.ReactNode;
value?: [DateType?, DateType?];
onChange: (date: DateType, index?: number) => void;
disabled: [boolean, boolean];
/** All the field show as `placeholder` */
allHelp: boolean;
placeholder?: string | [string, string];
invalid: [boolean, boolean];
placement?: string;
/**
* Trigger when the active bar offset position changed.
* This is used for popup panel offset.
*/
onActiveInfo: (info: [activeInputLeft: number, activeInputRight: number, selectorWidth: number]) => void;
}
declare const RefRangeSelector: React.ForwardRefExoticComponent<RangeSelectorProps<object> & React.RefAttributes<RangePickerRef>>;
export default RefRangeSelector;

View File

@@ -0,0 +1,209 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _typeof from "@babel/runtime/helpers/esm/typeof";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["id", "prefix", "clearIcon", "suffixIcon", "separator", "activeIndex", "activeHelp", "allHelp", "focused", "onFocus", "onBlur", "onKeyDown", "locale", "generateConfig", "placeholder", "className", "style", "onClick", "onClear", "value", "onChange", "onSubmit", "onInputChange", "format", "maskFormat", "preserveInvalidOnBlur", "onInvalid", "disabled", "invalid", "inputReadOnly", "direction", "onOpenChange", "onActiveInfo", "placement", "onMouseDown", "required", "aria-required", "autoFocus", "tabIndex"],
_excluded2 = ["index"];
import classNames from 'classnames';
import ResizeObserver from 'rc-resize-observer';
import { useEvent } from 'rc-util';
import * as React from 'react';
import PickerContext from "../context";
import useInputProps from "./hooks/useInputProps";
import useRootProps from "./hooks/useRootProps";
import Icon, { ClearIcon } from "./Icon";
import Input from "./Input";
function RangeSelector(props, ref) {
var id = props.id,
prefix = props.prefix,
clearIcon = props.clearIcon,
suffixIcon = props.suffixIcon,
_props$separator = props.separator,
separator = _props$separator === void 0 ? '~' : _props$separator,
activeIndex = props.activeIndex,
activeHelp = props.activeHelp,
allHelp = props.allHelp,
focused = props.focused,
onFocus = props.onFocus,
onBlur = props.onBlur,
onKeyDown = props.onKeyDown,
locale = props.locale,
generateConfig = props.generateConfig,
placeholder = props.placeholder,
className = props.className,
style = props.style,
onClick = props.onClick,
onClear = props.onClear,
value = props.value,
onChange = props.onChange,
onSubmit = props.onSubmit,
onInputChange = props.onInputChange,
format = props.format,
maskFormat = props.maskFormat,
preserveInvalidOnBlur = props.preserveInvalidOnBlur,
onInvalid = props.onInvalid,
disabled = props.disabled,
invalid = props.invalid,
inputReadOnly = props.inputReadOnly,
direction = props.direction,
onOpenChange = props.onOpenChange,
onActiveInfo = props.onActiveInfo,
placement = props.placement,
_onMouseDown = props.onMouseDown,
required = props.required,
ariaRequired = props['aria-required'],
autoFocus = props.autoFocus,
tabIndex = props.tabIndex,
restProps = _objectWithoutProperties(props, _excluded);
var rtl = direction === 'rtl';
// ======================== Prefix ========================
var _React$useContext = React.useContext(PickerContext),
prefixCls = _React$useContext.prefixCls;
// ========================== Id ==========================
var ids = React.useMemo(function () {
if (typeof id === 'string') {
return [id];
}
var mergedId = id || {};
return [mergedId.start, mergedId.end];
}, [id]);
// ========================= Refs =========================
var rootRef = React.useRef();
var inputStartRef = React.useRef();
var inputEndRef = React.useRef();
var getInput = function getInput(index) {
var _index;
return (_index = [inputStartRef, inputEndRef][index]) === null || _index === void 0 ? void 0 : _index.current;
};
React.useImperativeHandle(ref, function () {
return {
nativeElement: rootRef.current,
focus: function focus(options) {
if (_typeof(options) === 'object') {
var _getInput;
var _ref = options || {},
_ref$index = _ref.index,
_index2 = _ref$index === void 0 ? 0 : _ref$index,
rest = _objectWithoutProperties(_ref, _excluded2);
(_getInput = getInput(_index2)) === null || _getInput === void 0 || _getInput.focus(rest);
} else {
var _getInput2;
(_getInput2 = getInput(options !== null && options !== void 0 ? options : 0)) === null || _getInput2 === void 0 || _getInput2.focus();
}
},
blur: function blur() {
var _getInput3, _getInput4;
(_getInput3 = getInput(0)) === null || _getInput3 === void 0 || _getInput3.blur();
(_getInput4 = getInput(1)) === null || _getInput4 === void 0 || _getInput4.blur();
}
};
});
// ======================== Props =========================
var rootProps = useRootProps(restProps);
// ===================== Placeholder ======================
var mergedPlaceholder = React.useMemo(function () {
return Array.isArray(placeholder) ? placeholder : [placeholder, placeholder];
}, [placeholder]);
// ======================== Inputs ========================
var _useInputProps = useInputProps(_objectSpread(_objectSpread({}, props), {}, {
id: ids,
placeholder: mergedPlaceholder
})),
_useInputProps2 = _slicedToArray(_useInputProps, 1),
getInputProps = _useInputProps2[0];
// ====================== ActiveBar =======================
var _React$useState = React.useState({
position: 'absolute',
width: 0
}),
_React$useState2 = _slicedToArray(_React$useState, 2),
activeBarStyle = _React$useState2[0],
setActiveBarStyle = _React$useState2[1];
var syncActiveOffset = useEvent(function () {
var input = getInput(activeIndex);
if (input) {
var inputRect = input.nativeElement.getBoundingClientRect();
var parentRect = rootRef.current.getBoundingClientRect();
var rectOffset = inputRect.left - parentRect.left;
setActiveBarStyle(function (ori) {
return _objectSpread(_objectSpread({}, ori), {}, {
width: inputRect.width,
left: rectOffset
});
});
onActiveInfo([inputRect.left, inputRect.right, parentRect.width]);
}
});
React.useEffect(function () {
syncActiveOffset();
}, [activeIndex]);
// ======================== Clear =========================
var showClear = clearIcon && (value[0] && !disabled[0] || value[1] && !disabled[1]);
// ======================= Disabled =======================
var startAutoFocus = autoFocus && !disabled[0];
var endAutoFocus = autoFocus && !startAutoFocus && !disabled[1];
// ======================== Render ========================
return /*#__PURE__*/React.createElement(ResizeObserver, {
onResize: syncActiveOffset
}, /*#__PURE__*/React.createElement("div", _extends({}, rootProps, {
className: classNames(prefixCls, "".concat(prefixCls, "-range"), _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-focused"), focused), "".concat(prefixCls, "-disabled"), disabled.every(function (i) {
return i;
})), "".concat(prefixCls, "-invalid"), invalid.some(function (i) {
return i;
})), "".concat(prefixCls, "-rtl"), rtl), className),
style: style,
ref: rootRef,
onClick: onClick
// Not lose current input focus
,
onMouseDown: function onMouseDown(e) {
var target = e.target;
if (target !== inputStartRef.current.inputElement && target !== inputEndRef.current.inputElement) {
e.preventDefault();
}
_onMouseDown === null || _onMouseDown === void 0 || _onMouseDown(e);
}
}), prefix && /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-prefix")
}, prefix), /*#__PURE__*/React.createElement(Input, _extends({
ref: inputStartRef
}, getInputProps(0), {
autoFocus: startAutoFocus,
tabIndex: tabIndex,
"date-range": "start"
})), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-range-separator")
}, separator), /*#__PURE__*/React.createElement(Input, _extends({
ref: inputEndRef
}, getInputProps(1), {
autoFocus: endAutoFocus,
tabIndex: tabIndex,
"date-range": "end"
})), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-active-bar"),
style: activeBarStyle
}), /*#__PURE__*/React.createElement(Icon, {
type: "suffix",
icon: suffixIcon
}), showClear && /*#__PURE__*/React.createElement(ClearIcon, {
icon: clearIcon,
onClear: onClear
})));
}
var RefRangeSelector = /*#__PURE__*/React.forwardRef(RangeSelector);
if (process.env.NODE_ENV !== 'production') {
RefRangeSelector.displayName = 'RangeSelector';
}
export default RefRangeSelector;

View File

@@ -0,0 +1,12 @@
import * as React from 'react';
import type { PickerProps } from '../../SinglePicker';
export interface MultipleDatesProps<DateType extends object = any> extends Pick<PickerProps, 'maxTagCount'> {
prefixCls: string;
value: DateType[];
onRemove: (value: DateType) => void;
removeIcon?: React.ReactNode;
formatDate: (date: DateType) => string;
disabled?: boolean;
placeholder?: React.ReactNode;
}
export default function MultipleDates<DateType extends object = any>(props: MultipleDatesProps<DateType>): React.JSX.Element;

View File

@@ -0,0 +1,66 @@
import classNames from 'classnames';
import Overflow from 'rc-overflow';
import * as React from 'react';
export default function MultipleDates(props) {
var prefixCls = props.prefixCls,
value = props.value,
onRemove = props.onRemove,
_props$removeIcon = props.removeIcon,
removeIcon = _props$removeIcon === void 0 ? '×' : _props$removeIcon,
formatDate = props.formatDate,
disabled = props.disabled,
maxTagCount = props.maxTagCount,
placeholder = props.placeholder;
var selectorCls = "".concat(prefixCls, "-selector");
var selectionCls = "".concat(prefixCls, "-selection");
var overflowCls = "".concat(selectionCls, "-overflow");
// ========================= Item =========================
function renderSelector(content, onClose) {
return /*#__PURE__*/React.createElement("span", {
className: classNames("".concat(selectionCls, "-item")),
title: typeof content === 'string' ? content : null
}, /*#__PURE__*/React.createElement("span", {
className: "".concat(selectionCls, "-item-content")
}, content), !disabled && onClose && /*#__PURE__*/React.createElement("span", {
onMouseDown: function onMouseDown(e) {
e.preventDefault();
},
onClick: onClose,
className: "".concat(selectionCls, "-item-remove")
}, removeIcon));
}
function renderItem(date) {
var displayLabel = formatDate(date);
var onClose = function onClose(event) {
if (event) event.stopPropagation();
onRemove(date);
};
return renderSelector(displayLabel, onClose);
}
// ========================= Rest =========================
function renderRest(omittedValues) {
var content = "+ ".concat(omittedValues.length, " ...");
return renderSelector(content);
}
// ======================== Render ========================
return /*#__PURE__*/React.createElement("div", {
className: selectorCls
}, /*#__PURE__*/React.createElement(Overflow, {
prefixCls: overflowCls,
data: value,
renderItem: renderItem,
renderRest: renderRest
// suffix={inputNode}
,
itemKey: function itemKey(date) {
return formatDate(date);
},
maxCount: maxTagCount
}), !value.length && /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-selection-placeholder")
}, placeholder));
}

View File

@@ -0,0 +1,18 @@
import * as React from 'react';
import type { InternalMode, PickerRef, SelectorProps } from '../../../interface';
import type { PickerProps } from '../../SinglePicker';
export interface SingleSelectorProps<DateType extends object = any> extends SelectorProps<DateType>, Pick<PickerProps, 'multiple' | 'maxTagCount'> {
id?: string;
value?: DateType[];
onChange: (date: DateType[]) => void;
internalPicker: InternalMode;
disabled: boolean;
/** All the field show as `placeholder` */
allHelp: boolean;
placeholder?: string;
invalid: boolean;
onInvalid: (valid: boolean) => void;
removeIcon?: React.ReactNode;
}
declare const RefSingleSelector: React.ForwardRefExoticComponent<SingleSelectorProps<object> & React.RefAttributes<PickerRef>>;
export default RefSingleSelector;

View File

@@ -0,0 +1,177 @@
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["id", "open", "prefix", "clearIcon", "suffixIcon", "activeHelp", "allHelp", "focused", "onFocus", "onBlur", "onKeyDown", "locale", "generateConfig", "placeholder", "className", "style", "onClick", "onClear", "internalPicker", "value", "onChange", "onSubmit", "onInputChange", "multiple", "maxTagCount", "format", "maskFormat", "preserveInvalidOnBlur", "onInvalid", "disabled", "invalid", "inputReadOnly", "direction", "onOpenChange", "onMouseDown", "required", "aria-required", "autoFocus", "tabIndex", "removeIcon"];
import classNames from 'classnames';
import * as React from 'react';
import { isSame } from "../../../utils/dateUtil";
import PickerContext from "../../context";
import Icon, { ClearIcon } from "../Icon";
import Input from "../Input";
import useInputProps from "../hooks/useInputProps";
import useRootProps from "../hooks/useRootProps";
import MultipleDates from "./MultipleDates";
function SingleSelector(props, ref) {
var id = props.id,
open = props.open,
prefix = props.prefix,
clearIcon = props.clearIcon,
suffixIcon = props.suffixIcon,
activeHelp = props.activeHelp,
allHelp = props.allHelp,
focused = props.focused,
onFocus = props.onFocus,
onBlur = props.onBlur,
onKeyDown = props.onKeyDown,
locale = props.locale,
generateConfig = props.generateConfig,
placeholder = props.placeholder,
className = props.className,
style = props.style,
onClick = props.onClick,
onClear = props.onClear,
internalPicker = props.internalPicker,
value = props.value,
onChange = props.onChange,
onSubmit = props.onSubmit,
onInputChange = props.onInputChange,
multiple = props.multiple,
maxTagCount = props.maxTagCount,
format = props.format,
maskFormat = props.maskFormat,
preserveInvalidOnBlur = props.preserveInvalidOnBlur,
onInvalid = props.onInvalid,
disabled = props.disabled,
invalid = props.invalid,
inputReadOnly = props.inputReadOnly,
direction = props.direction,
onOpenChange = props.onOpenChange,
_onMouseDown = props.onMouseDown,
required = props.required,
ariaRequired = props['aria-required'],
autoFocus = props.autoFocus,
tabIndex = props.tabIndex,
removeIcon = props.removeIcon,
restProps = _objectWithoutProperties(props, _excluded);
var rtl = direction === 'rtl';
// ======================== Prefix ========================
var _React$useContext = React.useContext(PickerContext),
prefixCls = _React$useContext.prefixCls;
// ========================= Refs =========================
var rootRef = React.useRef();
var inputRef = React.useRef();
React.useImperativeHandle(ref, function () {
return {
nativeElement: rootRef.current,
focus: function focus(options) {
var _inputRef$current;
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus(options);
},
blur: function blur() {
var _inputRef$current2;
(_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 || _inputRef$current2.blur();
}
};
});
// ======================== Props =========================
var rootProps = useRootProps(restProps);
// ======================== Change ========================
var onSingleChange = function onSingleChange(date) {
onChange([date]);
};
var onMultipleRemove = function onMultipleRemove(date) {
var nextValues = value.filter(function (oriDate) {
return oriDate && !isSame(generateConfig, locale, oriDate, date, internalPicker);
});
onChange(nextValues);
// When `open`, it means user is operating the
if (!open) {
onSubmit();
}
};
// ======================== Inputs ========================
var _useInputProps = useInputProps(_objectSpread(_objectSpread({}, props), {}, {
onChange: onSingleChange
}), function (_ref) {
var valueTexts = _ref.valueTexts;
return {
value: valueTexts[0] || '',
active: focused
};
}),
_useInputProps2 = _slicedToArray(_useInputProps, 2),
getInputProps = _useInputProps2[0],
getText = _useInputProps2[1];
// ======================== Clear =========================
var showClear = !!(clearIcon && value.length && !disabled);
// ======================= Multiple =======================
var selectorNode = multiple ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MultipleDates, {
prefixCls: prefixCls,
value: value,
onRemove: onMultipleRemove,
formatDate: getText,
maxTagCount: maxTagCount,
disabled: disabled,
removeIcon: removeIcon,
placeholder: placeholder
}), /*#__PURE__*/React.createElement("input", {
className: "".concat(prefixCls, "-multiple-input"),
value: value.map(getText).join(','),
ref: inputRef,
readOnly: true,
autoFocus: autoFocus,
tabIndex: tabIndex
}), /*#__PURE__*/React.createElement(Icon, {
type: "suffix",
icon: suffixIcon
}), showClear && /*#__PURE__*/React.createElement(ClearIcon, {
icon: clearIcon,
onClear: onClear
})) : /*#__PURE__*/React.createElement(Input, _extends({
ref: inputRef
}, getInputProps(), {
autoFocus: autoFocus,
tabIndex: tabIndex,
suffixIcon: suffixIcon,
clearIcon: showClear && /*#__PURE__*/React.createElement(ClearIcon, {
icon: clearIcon,
onClear: onClear
}),
showActiveCls: false
}));
// ======================== Render ========================
return /*#__PURE__*/React.createElement("div", _extends({}, rootProps, {
className: classNames(prefixCls, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-multiple"), multiple), "".concat(prefixCls, "-focused"), focused), "".concat(prefixCls, "-disabled"), disabled), "".concat(prefixCls, "-invalid"), invalid), "".concat(prefixCls, "-rtl"), rtl), className),
style: style,
ref: rootRef,
onClick: onClick
// Not lose current input focus
,
onMouseDown: function onMouseDown(e) {
var _inputRef$current3;
var target = e.target;
if (target !== ((_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 ? void 0 : _inputRef$current3.inputElement)) {
e.preventDefault();
}
_onMouseDown === null || _onMouseDown === void 0 || _onMouseDown(e);
}
}), prefix && /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-prefix")
}, prefix), selectorNode);
}
var RefSingleSelector = /*#__PURE__*/React.forwardRef(SingleSelector);
if (process.env.NODE_ENV !== 'production') {
RefSingleSelector.displayName = 'SingleSelector';
}
export default RefSingleSelector;

View File

@@ -0,0 +1,8 @@
import type { ReactNode } from 'react';
import * as React from 'react';
/**
* Used for `useFilledProps` since it already in the React.useMemo
*/
export declare function fillClearIcon(prefixCls: string, allowClear?: boolean | {
clearIcon?: ReactNode;
}, clearIcon?: ReactNode): string | number | true | Iterable<ReactNode> | React.JSX.Element;

View File

@@ -0,0 +1,19 @@
import _typeof from "@babel/runtime/helpers/esm/typeof";
import warning from "rc-util/es/warning";
import * as React from 'react';
/**
* Used for `useFilledProps` since it already in the React.useMemo
*/
export function fillClearIcon(prefixCls, allowClear, clearIcon) {
if (process.env.NODE_ENV !== 'production' && clearIcon) {
warning(false, '`clearIcon` will be removed in future. Please use `allowClear` instead.');
}
if (allowClear === false) {
return null;
}
var config = allowClear && _typeof(allowClear) === 'object' ? allowClear : {};
return config.clearIcon || clearIcon || /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-clear-btn")
});
}

View File

@@ -0,0 +1,16 @@
import type { SelectorProps } from '../../../interface';
import type { InputProps } from '../Input';
export default function useInputProps<DateType extends object = any>(props: Pick<SelectorProps, 'maskFormat' | 'format' | 'generateConfig' | 'locale' | 'preserveInvalidOnBlur' | 'inputReadOnly' | 'required' | 'aria-required' | 'onSubmit' | 'onFocus' | 'onBlur' | 'onInputChange' | 'onInvalid' | 'onOpenChange' | 'onKeyDown' | 'activeHelp' | 'name' | 'autoComplete' | 'open' | 'picker'> & {
id?: string | string[];
value?: DateType[];
invalid?: boolean | [boolean, boolean];
placeholder?: string | [string, string];
disabled?: boolean | [boolean, boolean];
onChange: (value: DateType | null, index?: number) => void;
allHelp: boolean;
activeIndex?: number | null;
},
/** Used for SinglePicker */
postProps?: (info: {
valueTexts: string[];
}) => Partial<InputProps>): readonly [(index?: number) => InputProps, (date: DateType) => string];

View File

@@ -0,0 +1,173 @@
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { warning } from 'rc-util';
import pickAttrs from "rc-util/es/pickAttrs";
import * as React from 'react';
import { formatValue } from "../../../utils/dateUtil";
export default function useInputProps(props, /** Used for SinglePicker */
postProps) {
var format = props.format,
maskFormat = props.maskFormat,
generateConfig = props.generateConfig,
locale = props.locale,
preserveInvalidOnBlur = props.preserveInvalidOnBlur,
inputReadOnly = props.inputReadOnly,
required = props.required,
ariaRequired = props['aria-required'],
onSubmit = props.onSubmit,
_onFocus = props.onFocus,
_onBlur = props.onBlur,
onInputChange = props.onInputChange,
onInvalid = props.onInvalid,
open = props.open,
onOpenChange = props.onOpenChange,
_onKeyDown = props.onKeyDown,
_onChange = props.onChange,
activeHelp = props.activeHelp,
name = props.name,
autoComplete = props.autoComplete,
id = props.id,
value = props.value,
invalid = props.invalid,
placeholder = props.placeholder,
disabled = props.disabled,
activeIndex = props.activeIndex,
allHelp = props.allHelp,
picker = props.picker;
// ======================== Parser ========================
var parseDate = function parseDate(str, formatStr) {
var parsed = generateConfig.locale.parse(locale.locale, str, [formatStr]);
return parsed && generateConfig.isValidate(parsed) ? parsed : null;
};
// ========================= Text =========================
var firstFormat = format[0];
var getText = React.useCallback(function (date) {
return formatValue(date, {
locale: locale,
format: firstFormat,
generateConfig: generateConfig
});
}, [locale, generateConfig, firstFormat]);
var valueTexts = React.useMemo(function () {
return value.map(getText);
}, [value, getText]);
// ========================= Size =========================
var size = React.useMemo(function () {
var defaultSize = picker === 'time' ? 8 : 10;
var length = typeof firstFormat === 'function' ? firstFormat(generateConfig.getNow()).length : firstFormat.length;
return Math.max(defaultSize, length) + 2;
}, [firstFormat, picker, generateConfig]);
// ======================= Validate =======================
var _validateFormat = function validateFormat(text) {
for (var i = 0; i < format.length; i += 1) {
var singleFormat = format[i];
// Only support string type
if (typeof singleFormat === 'string') {
var parsed = parseDate(text, singleFormat);
if (parsed) {
return parsed;
}
}
}
return false;
};
// ======================== Input =========================
var getInputProps = function getInputProps(index) {
function getProp(propValue) {
return index !== undefined ? propValue[index] : propValue;
}
var pickedAttrs = pickAttrs(props, {
aria: true,
data: true
});
var inputProps = _objectSpread(_objectSpread({}, pickedAttrs), {}, {
// ============== Shared ==============
format: maskFormat,
validateFormat: function validateFormat(text) {
return !!_validateFormat(text);
},
preserveInvalidOnBlur: preserveInvalidOnBlur,
readOnly: inputReadOnly,
required: required,
'aria-required': ariaRequired,
name: name,
autoComplete: autoComplete,
size: size,
// ============= By Index =============
id: getProp(id),
value: getProp(valueTexts) || '',
invalid: getProp(invalid),
placeholder: getProp(placeholder),
active: activeIndex === index,
helped: allHelp || activeHelp && activeIndex === index,
disabled: getProp(disabled),
onFocus: function onFocus(event) {
_onFocus(event, index);
},
onBlur: function onBlur(event) {
// Blur do not trigger close
// Since it may focus to the popup panel
_onBlur(event, index);
},
onSubmit: onSubmit,
// Get validate text value
onChange: function onChange(text) {
onInputChange();
var parsed = _validateFormat(text);
if (parsed) {
onInvalid(false, index);
_onChange(parsed, index);
return;
}
// Tell outer that the value typed is invalid.
// If text is empty, it means valid.
onInvalid(!!text, index);
},
onHelp: function onHelp() {
onOpenChange(true, {
index: index
});
},
onKeyDown: function onKeyDown(event) {
var prevented = false;
_onKeyDown === null || _onKeyDown === void 0 || _onKeyDown(event, function () {
if (process.env.NODE_ENV !== 'production') {
warning(false, '`preventDefault` callback is deprecated. Please call `event.preventDefault` directly.');
}
prevented = true;
});
if (!event.defaultPrevented && !prevented) {
switch (event.key) {
case 'Escape':
onOpenChange(false, {
index: index
});
break;
case 'Enter':
if (!open) {
onOpenChange(true);
}
break;
}
}
}
}, postProps === null || postProps === void 0 ? void 0 : postProps({
valueTexts: valueTexts
}));
// ============== Clean Up ==============
Object.keys(inputProps).forEach(function (key) {
if (inputProps[key] === undefined) {
delete inputProps[key];
}
});
return inputProps;
};
return [getInputProps, getText];
}

View File

@@ -0,0 +1,2 @@
import * as React from 'react';
export default function useRootProps(props: React.HTMLAttributes<any>): React.HTMLAttributes<any>;

View File

@@ -0,0 +1,8 @@
import * as React from 'react';
import { pickProps } from "../../../utils/miscUtil";
var propNames = ['onMouseEnter', 'onMouseLeave'];
export default function useRootProps(props) {
return React.useMemo(function () {
return pickProps(props, propNames);
}, [props]);
}

View File

@@ -0,0 +1 @@
export declare function getMaskRange(key: string): [startVal: number, endVal: number, defaultVal?: number];

12
node_modules/rc-picker/es/PickerInput/Selector/util.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
export function getMaskRange(key) {
var PresetRange = {
YYYY: [0, 9999, new Date().getFullYear()],
MM: [1, 12],
DD: [1, 31],
HH: [0, 23],
mm: [0, 59],
ss: [0, 59],
SSS: [0, 999]
};
return PresetRange[key];
}