first commit
This commit is contained in:
30
frontend/node_modules/rc-textarea/es/ResizableTextArea.d.ts
generated
vendored
Normal file
30
frontend/node_modules/rc-textarea/es/ResizableTextArea.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import * as React from 'react';
|
||||
import type { ResizableTextAreaRef } from './interface';
|
||||
declare const ResizableTextArea: React.ForwardRefExoticComponent<Omit<import("./interface").HTMLTextareaProps, "value" | "onResize"> & {
|
||||
value?: string | number | bigint | readonly string[];
|
||||
prefixCls?: string;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
autoSize?: boolean | import("./interface").AutoSizeType;
|
||||
onPressEnter?: React.KeyboardEventHandler<HTMLTextAreaElement>;
|
||||
onResize?: (size: {
|
||||
width: number;
|
||||
height: number;
|
||||
}) => void;
|
||||
classNames?: {
|
||||
affixWrapper?: string;
|
||||
prefix?: string;
|
||||
suffix?: string;
|
||||
groupWrapper?: string;
|
||||
wrapper?: string;
|
||||
variant?: string;
|
||||
} & {
|
||||
textarea?: string;
|
||||
count?: string;
|
||||
};
|
||||
styles?: {
|
||||
textarea?: React.CSSProperties;
|
||||
count?: React.CSSProperties;
|
||||
};
|
||||
} & Pick<import("rc-input/lib/interface").BaseInputProps, "allowClear" | "suffix"> & Pick<import("rc-input").InputProps, "showCount" | "count" | "onClear"> & React.RefAttributes<ResizableTextAreaRef>>;
|
||||
export default ResizableTextArea;
|
||||
154
frontend/node_modules/rc-textarea/es/ResizableTextArea.js
generated
vendored
Normal file
154
frontend/node_modules/rc-textarea/es/ResizableTextArea.js
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
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 _typeof from "@babel/runtime/helpers/esm/typeof";
|
||||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
||||
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
||||
var _excluded = ["prefixCls", "defaultValue", "value", "autoSize", "onResize", "className", "style", "disabled", "onChange", "onInternalAutoSize"];
|
||||
import classNames from 'classnames';
|
||||
import ResizeObserver from 'rc-resize-observer';
|
||||
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
|
||||
import useMergedState from "rc-util/es/hooks/useMergedState";
|
||||
import raf from "rc-util/es/raf";
|
||||
import * as React from 'react';
|
||||
import calculateAutoSizeStyle from "./calculateNodeHeight";
|
||||
var RESIZE_START = 0;
|
||||
var RESIZE_MEASURING = 1;
|
||||
var RESIZE_STABLE = 2;
|
||||
var ResizableTextArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
||||
var _ref = props,
|
||||
prefixCls = _ref.prefixCls,
|
||||
defaultValue = _ref.defaultValue,
|
||||
value = _ref.value,
|
||||
autoSize = _ref.autoSize,
|
||||
onResize = _ref.onResize,
|
||||
className = _ref.className,
|
||||
style = _ref.style,
|
||||
disabled = _ref.disabled,
|
||||
onChange = _ref.onChange,
|
||||
onInternalAutoSize = _ref.onInternalAutoSize,
|
||||
restProps = _objectWithoutProperties(_ref, _excluded);
|
||||
|
||||
// =============================== Value ================================
|
||||
var _useMergedState = useMergedState(defaultValue, {
|
||||
value: value,
|
||||
postState: function postState(val) {
|
||||
return val !== null && val !== void 0 ? val : '';
|
||||
}
|
||||
}),
|
||||
_useMergedState2 = _slicedToArray(_useMergedState, 2),
|
||||
mergedValue = _useMergedState2[0],
|
||||
setMergedValue = _useMergedState2[1];
|
||||
var onInternalChange = function onInternalChange(event) {
|
||||
setMergedValue(event.target.value);
|
||||
onChange === null || onChange === void 0 || onChange(event);
|
||||
};
|
||||
|
||||
// ================================ Ref =================================
|
||||
var textareaRef = React.useRef();
|
||||
React.useImperativeHandle(ref, function () {
|
||||
return {
|
||||
textArea: textareaRef.current
|
||||
};
|
||||
});
|
||||
|
||||
// ============================== AutoSize ==============================
|
||||
var _React$useMemo = React.useMemo(function () {
|
||||
if (autoSize && _typeof(autoSize) === 'object') {
|
||||
return [autoSize.minRows, autoSize.maxRows];
|
||||
}
|
||||
return [];
|
||||
}, [autoSize]),
|
||||
_React$useMemo2 = _slicedToArray(_React$useMemo, 2),
|
||||
minRows = _React$useMemo2[0],
|
||||
maxRows = _React$useMemo2[1];
|
||||
var needAutoSize = !!autoSize;
|
||||
|
||||
// =============================== Resize ===============================
|
||||
var _React$useState = React.useState(RESIZE_STABLE),
|
||||
_React$useState2 = _slicedToArray(_React$useState, 2),
|
||||
resizeState = _React$useState2[0],
|
||||
setResizeState = _React$useState2[1];
|
||||
var _React$useState3 = React.useState(),
|
||||
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
||||
autoSizeStyle = _React$useState4[0],
|
||||
setAutoSizeStyle = _React$useState4[1];
|
||||
var startResize = function startResize() {
|
||||
setResizeState(RESIZE_START);
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
onInternalAutoSize === null || onInternalAutoSize === void 0 || onInternalAutoSize();
|
||||
}
|
||||
};
|
||||
|
||||
// Change to trigger resize measure
|
||||
useLayoutEffect(function () {
|
||||
if (needAutoSize) {
|
||||
startResize();
|
||||
}
|
||||
}, [value, minRows, maxRows, needAutoSize]);
|
||||
useLayoutEffect(function () {
|
||||
if (resizeState === RESIZE_START) {
|
||||
setResizeState(RESIZE_MEASURING);
|
||||
} else if (resizeState === RESIZE_MEASURING) {
|
||||
var textareaStyles = calculateAutoSizeStyle(textareaRef.current, false, minRows, maxRows);
|
||||
|
||||
// Safari has bug that text will keep break line on text cut when it's prev is break line.
|
||||
// ZombieJ: This not often happen. So we just skip it.
|
||||
// const { selectionStart, selectionEnd, scrollTop } = textareaRef.current;
|
||||
// const { value: tmpValue } = textareaRef.current;
|
||||
// textareaRef.current.value = '';
|
||||
// textareaRef.current.value = tmpValue;
|
||||
|
||||
// if (document.activeElement === textareaRef.current) {
|
||||
// textareaRef.current.scrollTop = scrollTop;
|
||||
// textareaRef.current.setSelectionRange(selectionStart, selectionEnd);
|
||||
// }
|
||||
|
||||
setResizeState(RESIZE_STABLE);
|
||||
setAutoSizeStyle(textareaStyles);
|
||||
} else {
|
||||
// https://github.com/react-component/textarea/pull/23
|
||||
// Firefox has blink issue before but fixed in latest version.
|
||||
}
|
||||
}, [resizeState]);
|
||||
|
||||
// We lock resize trigger by raf to avoid Safari warning
|
||||
var resizeRafRef = React.useRef();
|
||||
var cleanRaf = function cleanRaf() {
|
||||
raf.cancel(resizeRafRef.current);
|
||||
};
|
||||
var onInternalResize = function onInternalResize(size) {
|
||||
if (resizeState === RESIZE_STABLE) {
|
||||
onResize === null || onResize === void 0 || onResize(size);
|
||||
if (autoSize) {
|
||||
cleanRaf();
|
||||
resizeRafRef.current = raf(function () {
|
||||
startResize();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
React.useEffect(function () {
|
||||
return cleanRaf;
|
||||
}, []);
|
||||
|
||||
// =============================== Render ===============================
|
||||
var mergedAutoSizeStyle = needAutoSize ? autoSizeStyle : null;
|
||||
var mergedStyle = _objectSpread(_objectSpread({}, style), mergedAutoSizeStyle);
|
||||
if (resizeState === RESIZE_START || resizeState === RESIZE_MEASURING) {
|
||||
mergedStyle.overflowY = 'hidden';
|
||||
mergedStyle.overflowX = 'hidden';
|
||||
}
|
||||
return /*#__PURE__*/React.createElement(ResizeObserver, {
|
||||
onResize: onInternalResize,
|
||||
disabled: !(autoSize || onResize)
|
||||
}, /*#__PURE__*/React.createElement("textarea", _extends({}, restProps, {
|
||||
ref: textareaRef,
|
||||
style: mergedStyle,
|
||||
className: classNames(prefixCls, className, _defineProperty({}, "".concat(prefixCls, "-disabled"), disabled)),
|
||||
disabled: disabled,
|
||||
value: mergedValue,
|
||||
onChange: onInternalChange
|
||||
})));
|
||||
});
|
||||
export default ResizableTextArea;
|
||||
30
frontend/node_modules/rc-textarea/es/TextArea.d.ts
generated
vendored
Normal file
30
frontend/node_modules/rc-textarea/es/TextArea.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import React from 'react';
|
||||
import type { TextAreaRef } from './interface';
|
||||
declare const TextArea: React.ForwardRefExoticComponent<Omit<import("./interface").HTMLTextareaProps, "value" | "onResize"> & {
|
||||
value?: string | number | bigint | readonly string[];
|
||||
prefixCls?: string;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
autoSize?: boolean | import("./interface").AutoSizeType;
|
||||
onPressEnter?: React.KeyboardEventHandler<HTMLTextAreaElement>;
|
||||
onResize?: (size: {
|
||||
width: number;
|
||||
height: number;
|
||||
}) => void;
|
||||
classNames?: {
|
||||
affixWrapper?: string;
|
||||
prefix?: string;
|
||||
suffix?: string;
|
||||
groupWrapper?: string;
|
||||
wrapper?: string;
|
||||
variant?: string;
|
||||
} & {
|
||||
textarea?: string;
|
||||
count?: string;
|
||||
};
|
||||
styles?: {
|
||||
textarea?: React.CSSProperties;
|
||||
count?: React.CSSProperties;
|
||||
};
|
||||
} & Pick<import("rc-input/lib/interface").BaseInputProps, "allowClear" | "suffix"> & Pick<import("rc-input").InputProps, "showCount" | "count" | "onClear"> & React.RefAttributes<TextAreaRef>>;
|
||||
export default TextArea;
|
||||
228
frontend/node_modules/rc-textarea/es/TextArea.js
generated
vendored
Normal file
228
frontend/node_modules/rc-textarea/es/TextArea.js
generated
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
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 _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
||||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
||||
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
||||
var _excluded = ["defaultValue", "value", "onFocus", "onBlur", "onChange", "allowClear", "maxLength", "onCompositionStart", "onCompositionEnd", "suffix", "prefixCls", "showCount", "count", "className", "style", "disabled", "hidden", "classNames", "styles", "onResize", "onClear", "onPressEnter", "readOnly", "autoSize", "onKeyDown"];
|
||||
import clsx from 'classnames';
|
||||
import { BaseInput } from 'rc-input';
|
||||
import useCount from "rc-input/es/hooks/useCount";
|
||||
import { resolveOnChange } from "rc-input/es/utils/commonUtils";
|
||||
import useMergedState from "rc-util/es/hooks/useMergedState";
|
||||
import React, { useEffect, useImperativeHandle, useRef } from 'react';
|
||||
import ResizableTextArea from "./ResizableTextArea";
|
||||
var TextArea = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
||||
var _countConfig$max;
|
||||
var defaultValue = _ref.defaultValue,
|
||||
customValue = _ref.value,
|
||||
onFocus = _ref.onFocus,
|
||||
onBlur = _ref.onBlur,
|
||||
onChange = _ref.onChange,
|
||||
allowClear = _ref.allowClear,
|
||||
maxLength = _ref.maxLength,
|
||||
onCompositionStart = _ref.onCompositionStart,
|
||||
onCompositionEnd = _ref.onCompositionEnd,
|
||||
suffix = _ref.suffix,
|
||||
_ref$prefixCls = _ref.prefixCls,
|
||||
prefixCls = _ref$prefixCls === void 0 ? 'rc-textarea' : _ref$prefixCls,
|
||||
showCount = _ref.showCount,
|
||||
count = _ref.count,
|
||||
className = _ref.className,
|
||||
style = _ref.style,
|
||||
disabled = _ref.disabled,
|
||||
hidden = _ref.hidden,
|
||||
classNames = _ref.classNames,
|
||||
styles = _ref.styles,
|
||||
onResize = _ref.onResize,
|
||||
onClear = _ref.onClear,
|
||||
onPressEnter = _ref.onPressEnter,
|
||||
readOnly = _ref.readOnly,
|
||||
autoSize = _ref.autoSize,
|
||||
onKeyDown = _ref.onKeyDown,
|
||||
rest = _objectWithoutProperties(_ref, _excluded);
|
||||
var _useMergedState = useMergedState(defaultValue, {
|
||||
value: customValue,
|
||||
defaultValue: defaultValue
|
||||
}),
|
||||
_useMergedState2 = _slicedToArray(_useMergedState, 2),
|
||||
value = _useMergedState2[0],
|
||||
setValue = _useMergedState2[1];
|
||||
var formatValue = value === undefined || value === null ? '' : String(value);
|
||||
var _React$useState = React.useState(false),
|
||||
_React$useState2 = _slicedToArray(_React$useState, 2),
|
||||
focused = _React$useState2[0],
|
||||
setFocused = _React$useState2[1];
|
||||
var compositionRef = React.useRef(false);
|
||||
var _React$useState3 = React.useState(null),
|
||||
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
||||
textareaResized = _React$useState4[0],
|
||||
setTextareaResized = _React$useState4[1];
|
||||
|
||||
// =============================== Ref ================================
|
||||
var holderRef = useRef(null);
|
||||
var resizableTextAreaRef = useRef(null);
|
||||
var getTextArea = function getTextArea() {
|
||||
var _resizableTextAreaRef;
|
||||
return (_resizableTextAreaRef = resizableTextAreaRef.current) === null || _resizableTextAreaRef === void 0 ? void 0 : _resizableTextAreaRef.textArea;
|
||||
};
|
||||
var focus = function focus() {
|
||||
getTextArea().focus();
|
||||
};
|
||||
useImperativeHandle(ref, function () {
|
||||
var _holderRef$current;
|
||||
return {
|
||||
resizableTextArea: resizableTextAreaRef.current,
|
||||
focus: focus,
|
||||
blur: function blur() {
|
||||
getTextArea().blur();
|
||||
},
|
||||
nativeElement: ((_holderRef$current = holderRef.current) === null || _holderRef$current === void 0 ? void 0 : _holderRef$current.nativeElement) || getTextArea()
|
||||
};
|
||||
});
|
||||
useEffect(function () {
|
||||
setFocused(function (prev) {
|
||||
return !disabled && prev;
|
||||
});
|
||||
}, [disabled]);
|
||||
|
||||
// =========================== Select Range ===========================
|
||||
var _React$useState5 = React.useState(null),
|
||||
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
||||
selection = _React$useState6[0],
|
||||
setSelection = _React$useState6[1];
|
||||
React.useEffect(function () {
|
||||
if (selection) {
|
||||
var _getTextArea;
|
||||
(_getTextArea = getTextArea()).setSelectionRange.apply(_getTextArea, _toConsumableArray(selection));
|
||||
}
|
||||
}, [selection]);
|
||||
|
||||
// ============================== Count ===============================
|
||||
var countConfig = useCount(count, showCount);
|
||||
var mergedMax = (_countConfig$max = countConfig.max) !== null && _countConfig$max !== void 0 ? _countConfig$max : maxLength;
|
||||
|
||||
// Max length value
|
||||
var hasMaxLength = Number(mergedMax) > 0;
|
||||
var valueLength = countConfig.strategy(formatValue);
|
||||
var isOutOfRange = !!mergedMax && valueLength > mergedMax;
|
||||
|
||||
// ============================== Change ==============================
|
||||
var triggerChange = function triggerChange(e, currentValue) {
|
||||
var cutValue = currentValue;
|
||||
if (!compositionRef.current && countConfig.exceedFormatter && countConfig.max && countConfig.strategy(currentValue) > countConfig.max) {
|
||||
cutValue = countConfig.exceedFormatter(currentValue, {
|
||||
max: countConfig.max
|
||||
});
|
||||
if (currentValue !== cutValue) {
|
||||
setSelection([getTextArea().selectionStart || 0, getTextArea().selectionEnd || 0]);
|
||||
}
|
||||
}
|
||||
setValue(cutValue);
|
||||
resolveOnChange(e.currentTarget, e, onChange, cutValue);
|
||||
};
|
||||
|
||||
// =========================== Value Update ===========================
|
||||
var onInternalCompositionStart = function onInternalCompositionStart(e) {
|
||||
compositionRef.current = true;
|
||||
onCompositionStart === null || onCompositionStart === void 0 || onCompositionStart(e);
|
||||
};
|
||||
var onInternalCompositionEnd = function onInternalCompositionEnd(e) {
|
||||
compositionRef.current = false;
|
||||
triggerChange(e, e.currentTarget.value);
|
||||
onCompositionEnd === null || onCompositionEnd === void 0 || onCompositionEnd(e);
|
||||
};
|
||||
var onInternalChange = function onInternalChange(e) {
|
||||
triggerChange(e, e.target.value);
|
||||
};
|
||||
var handleKeyDown = function handleKeyDown(e) {
|
||||
if (e.key === 'Enter' && onPressEnter) {
|
||||
onPressEnter(e);
|
||||
}
|
||||
onKeyDown === null || onKeyDown === void 0 || onKeyDown(e);
|
||||
};
|
||||
var handleFocus = function handleFocus(e) {
|
||||
setFocused(true);
|
||||
onFocus === null || onFocus === void 0 || onFocus(e);
|
||||
};
|
||||
var handleBlur = function handleBlur(e) {
|
||||
setFocused(false);
|
||||
onBlur === null || onBlur === void 0 || onBlur(e);
|
||||
};
|
||||
|
||||
// ============================== Reset ===============================
|
||||
var handleReset = function handleReset(e) {
|
||||
setValue('');
|
||||
focus();
|
||||
resolveOnChange(getTextArea(), e, onChange);
|
||||
};
|
||||
var suffixNode = suffix;
|
||||
var dataCount;
|
||||
if (countConfig.show) {
|
||||
if (countConfig.showFormatter) {
|
||||
dataCount = countConfig.showFormatter({
|
||||
value: formatValue,
|
||||
count: valueLength,
|
||||
maxLength: mergedMax
|
||||
});
|
||||
} else {
|
||||
dataCount = "".concat(valueLength).concat(hasMaxLength ? " / ".concat(mergedMax) : '');
|
||||
}
|
||||
suffixNode = /*#__PURE__*/React.createElement(React.Fragment, null, suffixNode, /*#__PURE__*/React.createElement("span", {
|
||||
className: clsx("".concat(prefixCls, "-data-count"), classNames === null || classNames === void 0 ? void 0 : classNames.count),
|
||||
style: styles === null || styles === void 0 ? void 0 : styles.count
|
||||
}, dataCount));
|
||||
}
|
||||
var handleResize = function handleResize(size) {
|
||||
var _getTextArea2;
|
||||
onResize === null || onResize === void 0 || onResize(size);
|
||||
if ((_getTextArea2 = getTextArea()) !== null && _getTextArea2 !== void 0 && _getTextArea2.style.height) {
|
||||
setTextareaResized(true);
|
||||
}
|
||||
};
|
||||
var isPureTextArea = !autoSize && !showCount && !allowClear;
|
||||
return /*#__PURE__*/React.createElement(BaseInput, {
|
||||
ref: holderRef,
|
||||
value: formatValue,
|
||||
allowClear: allowClear,
|
||||
handleReset: handleReset,
|
||||
suffix: suffixNode,
|
||||
prefixCls: prefixCls,
|
||||
classNames: _objectSpread(_objectSpread({}, classNames), {}, {
|
||||
affixWrapper: clsx(classNames === null || classNames === void 0 ? void 0 : classNames.affixWrapper, _defineProperty(_defineProperty({}, "".concat(prefixCls, "-show-count"), showCount), "".concat(prefixCls, "-textarea-allow-clear"), allowClear))
|
||||
}),
|
||||
disabled: disabled,
|
||||
focused: focused,
|
||||
className: clsx(className, isOutOfRange && "".concat(prefixCls, "-out-of-range")),
|
||||
style: _objectSpread(_objectSpread({}, style), textareaResized && !isPureTextArea ? {
|
||||
height: 'auto'
|
||||
} : {}),
|
||||
dataAttrs: {
|
||||
affixWrapper: {
|
||||
'data-count': typeof dataCount === 'string' ? dataCount : undefined
|
||||
}
|
||||
},
|
||||
hidden: hidden,
|
||||
readOnly: readOnly,
|
||||
onClear: onClear
|
||||
}, /*#__PURE__*/React.createElement(ResizableTextArea, _extends({}, rest, {
|
||||
autoSize: autoSize,
|
||||
maxLength: maxLength,
|
||||
onKeyDown: handleKeyDown,
|
||||
onChange: onInternalChange,
|
||||
onFocus: handleFocus,
|
||||
onBlur: handleBlur,
|
||||
onCompositionStart: onInternalCompositionStart,
|
||||
onCompositionEnd: onInternalCompositionEnd,
|
||||
className: clsx(classNames === null || classNames === void 0 ? void 0 : classNames.textarea),
|
||||
style: _objectSpread(_objectSpread({}, styles === null || styles === void 0 ? void 0 : styles.textarea), {}, {
|
||||
resize: style === null || style === void 0 ? void 0 : style.resize
|
||||
}),
|
||||
disabled: disabled,
|
||||
prefixCls: prefixCls,
|
||||
onResize: handleResize,
|
||||
ref: resizableTextAreaRef,
|
||||
readOnly: readOnly
|
||||
})));
|
||||
});
|
||||
export default TextArea;
|
||||
9
frontend/node_modules/rc-textarea/es/calculateNodeHeight.d.ts
generated
vendored
Normal file
9
frontend/node_modules/rc-textarea/es/calculateNodeHeight.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type React from 'react';
|
||||
export interface NodeType {
|
||||
sizingStyle: string;
|
||||
paddingSize: number;
|
||||
borderSize: number;
|
||||
boxSizing: string;
|
||||
}
|
||||
export declare function calculateNodeStyling(node: HTMLElement, useCache?: boolean): NodeType;
|
||||
export default function calculateAutoSizeStyle(uiTextNode: HTMLTextAreaElement, useCache?: boolean, minRows?: number | null, maxRows?: number | null): React.CSSProperties;
|
||||
114
frontend/node_modules/rc-textarea/es/calculateNodeHeight.js
generated
vendored
Normal file
114
frontend/node_modules/rc-textarea/es/calculateNodeHeight.js
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
// Thanks to https://github.com/andreypopp/react-textarea-autosize/
|
||||
|
||||
/**
|
||||
* calculateNodeHeight(uiTextNode, useCache = false)
|
||||
*/
|
||||
|
||||
var HIDDEN_TEXTAREA_STYLE = "\n min-height:0 !important;\n max-height:none !important;\n height:0 !important;\n visibility:hidden !important;\n overflow:hidden !important;\n position:absolute !important;\n z-index:-1000 !important;\n top:0 !important;\n right:0 !important;\n pointer-events: none !important;\n";
|
||||
var SIZING_STYLE = ['letter-spacing', 'line-height', 'padding-top', 'padding-bottom', 'font-family', 'font-weight', 'font-size', 'font-variant', 'text-rendering', 'text-transform', 'width', 'text-indent', 'padding-left', 'padding-right', 'border-width', 'box-sizing', 'word-break', 'white-space'];
|
||||
var computedStyleCache = {};
|
||||
var hiddenTextarea;
|
||||
export function calculateNodeStyling(node) {
|
||||
var useCache = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||||
var nodeRef = node.getAttribute('id') || node.getAttribute('data-reactid') || node.getAttribute('name');
|
||||
if (useCache && computedStyleCache[nodeRef]) {
|
||||
return computedStyleCache[nodeRef];
|
||||
}
|
||||
var style = window.getComputedStyle(node);
|
||||
var boxSizing = style.getPropertyValue('box-sizing') || style.getPropertyValue('-moz-box-sizing') || style.getPropertyValue('-webkit-box-sizing');
|
||||
var paddingSize = parseFloat(style.getPropertyValue('padding-bottom')) + parseFloat(style.getPropertyValue('padding-top'));
|
||||
var borderSize = parseFloat(style.getPropertyValue('border-bottom-width')) + parseFloat(style.getPropertyValue('border-top-width'));
|
||||
var sizingStyle = SIZING_STYLE.map(function (name) {
|
||||
return "".concat(name, ":").concat(style.getPropertyValue(name));
|
||||
}).join(';');
|
||||
var nodeInfo = {
|
||||
sizingStyle: sizingStyle,
|
||||
paddingSize: paddingSize,
|
||||
borderSize: borderSize,
|
||||
boxSizing: boxSizing
|
||||
};
|
||||
if (useCache && nodeRef) {
|
||||
computedStyleCache[nodeRef] = nodeInfo;
|
||||
}
|
||||
return nodeInfo;
|
||||
}
|
||||
export default function calculateAutoSizeStyle(uiTextNode) {
|
||||
var useCache = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||||
var minRows = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
||||
var maxRows = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
||||
if (!hiddenTextarea) {
|
||||
hiddenTextarea = document.createElement('textarea');
|
||||
hiddenTextarea.setAttribute('tab-index', '-1');
|
||||
hiddenTextarea.setAttribute('aria-hidden', 'true');
|
||||
// fix: A form field element should have an id or name attribute
|
||||
// A form field element has neither an id nor a name attribute. This might prevent the browser from correctly autofilling the form.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
|
||||
hiddenTextarea.setAttribute('name', 'hiddenTextarea');
|
||||
document.body.appendChild(hiddenTextarea);
|
||||
}
|
||||
|
||||
// Fix wrap="off" issue
|
||||
// https://github.com/ant-design/ant-design/issues/6577
|
||||
if (uiTextNode.getAttribute('wrap')) {
|
||||
hiddenTextarea.setAttribute('wrap', uiTextNode.getAttribute('wrap'));
|
||||
} else {
|
||||
hiddenTextarea.removeAttribute('wrap');
|
||||
}
|
||||
|
||||
// Copy all CSS properties that have an impact on the height of the content in
|
||||
// the textbox
|
||||
var _calculateNodeStyling = calculateNodeStyling(uiTextNode, useCache),
|
||||
paddingSize = _calculateNodeStyling.paddingSize,
|
||||
borderSize = _calculateNodeStyling.borderSize,
|
||||
boxSizing = _calculateNodeStyling.boxSizing,
|
||||
sizingStyle = _calculateNodeStyling.sizingStyle;
|
||||
|
||||
// Need to have the overflow attribute to hide the scrollbar otherwise
|
||||
// text-lines will not calculated properly as the shadow will technically be
|
||||
// narrower for content
|
||||
hiddenTextarea.setAttribute('style', "".concat(sizingStyle, ";").concat(HIDDEN_TEXTAREA_STYLE));
|
||||
hiddenTextarea.value = uiTextNode.value || uiTextNode.placeholder || '';
|
||||
var minHeight = undefined;
|
||||
var maxHeight = undefined;
|
||||
var overflowY;
|
||||
var height = hiddenTextarea.scrollHeight;
|
||||
if (boxSizing === 'border-box') {
|
||||
// border-box: add border, since height = content + padding + border
|
||||
height += borderSize;
|
||||
} else if (boxSizing === 'content-box') {
|
||||
// remove padding, since height = content
|
||||
height -= paddingSize;
|
||||
}
|
||||
if (minRows !== null || maxRows !== null) {
|
||||
// measure height of a textarea with a single row
|
||||
hiddenTextarea.value = ' ';
|
||||
var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize;
|
||||
if (minRows !== null) {
|
||||
minHeight = singleRowHeight * minRows;
|
||||
if (boxSizing === 'border-box') {
|
||||
minHeight = minHeight + paddingSize + borderSize;
|
||||
}
|
||||
height = Math.max(minHeight, height);
|
||||
}
|
||||
if (maxRows !== null) {
|
||||
maxHeight = singleRowHeight * maxRows;
|
||||
if (boxSizing === 'border-box') {
|
||||
maxHeight = maxHeight + paddingSize + borderSize;
|
||||
}
|
||||
overflowY = height > maxHeight ? '' : 'hidden';
|
||||
height = Math.min(maxHeight, height);
|
||||
}
|
||||
}
|
||||
var style = {
|
||||
height: height,
|
||||
overflowY: overflowY,
|
||||
resize: 'none'
|
||||
};
|
||||
if (minHeight) {
|
||||
style.minHeight = minHeight;
|
||||
}
|
||||
if (maxHeight) {
|
||||
style.maxHeight = maxHeight;
|
||||
}
|
||||
return style;
|
||||
}
|
||||
4
frontend/node_modules/rc-textarea/es/index.d.ts
generated
vendored
Normal file
4
frontend/node_modules/rc-textarea/es/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import TextArea from './TextArea';
|
||||
export { default as ResizableTextArea } from './ResizableTextArea';
|
||||
export type { AutoSizeType, ResizableTextAreaRef, TextAreaProps, TextAreaRef, } from './interface';
|
||||
export default TextArea;
|
||||
3
frontend/node_modules/rc-textarea/es/index.js
generated
vendored
Normal file
3
frontend/node_modules/rc-textarea/es/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import TextArea from "./TextArea";
|
||||
export { default as ResizableTextArea } from "./ResizableTextArea";
|
||||
export default TextArea;
|
||||
37
frontend/node_modules/rc-textarea/es/interface.d.ts
generated
vendored
Normal file
37
frontend/node_modules/rc-textarea/es/interface.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { BaseInputProps, CommonInputProps, InputProps } from 'rc-input/lib/interface';
|
||||
import type React from 'react';
|
||||
import type { CSSProperties } from 'react';
|
||||
export interface AutoSizeType {
|
||||
minRows?: number;
|
||||
maxRows?: number;
|
||||
}
|
||||
export interface ResizableTextAreaRef {
|
||||
textArea: HTMLTextAreaElement;
|
||||
}
|
||||
export type HTMLTextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement>;
|
||||
export type TextAreaProps = Omit<HTMLTextareaProps, 'onResize' | 'value'> & {
|
||||
value?: HTMLTextareaProps['value'] | bigint;
|
||||
prefixCls?: string;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
autoSize?: boolean | AutoSizeType;
|
||||
onPressEnter?: React.KeyboardEventHandler<HTMLTextAreaElement>;
|
||||
onResize?: (size: {
|
||||
width: number;
|
||||
height: number;
|
||||
}) => void;
|
||||
classNames?: CommonInputProps['classNames'] & {
|
||||
textarea?: string;
|
||||
count?: string;
|
||||
};
|
||||
styles?: {
|
||||
textarea?: CSSProperties;
|
||||
count?: CSSProperties;
|
||||
};
|
||||
} & Pick<BaseInputProps, 'allowClear' | 'suffix'> & Pick<InputProps, 'showCount' | 'count' | 'onClear'>;
|
||||
export type TextAreaRef = {
|
||||
resizableTextArea: ResizableTextAreaRef;
|
||||
focus: () => void;
|
||||
blur: () => void;
|
||||
nativeElement: HTMLElement;
|
||||
};
|
||||
1
frontend/node_modules/rc-textarea/es/interface.js
generated
vendored
Normal file
1
frontend/node_modules/rc-textarea/es/interface.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in New Issue
Block a user