first commit
This commit is contained in:
2
frontend/node_modules/antd/es/form/hooks/useChildren.d.ts
generated
vendored
Normal file
2
frontend/node_modules/antd/es/form/hooks/useChildren.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { FormItemProps } from '../FormItem';
|
||||
export default function useChildren(children?: FormItemProps['children']): FormItemProps['children'];
|
||||
8
frontend/node_modules/antd/es/form/hooks/useChildren.js
generated
vendored
Normal file
8
frontend/node_modules/antd/es/form/hooks/useChildren.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import toArray from "rc-util/es/Children/toArray";
|
||||
export default function useChildren(children) {
|
||||
if (typeof children === 'function') {
|
||||
return children;
|
||||
}
|
||||
const childList = toArray(children);
|
||||
return childList.length <= 1 ? childList[0] : childList;
|
||||
}
|
||||
1
frontend/node_modules/antd/es/form/hooks/useDebounce.d.ts
generated
vendored
Normal file
1
frontend/node_modules/antd/es/form/hooks/useDebounce.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default function useDebounce<T>(value: T[]): T[];
|
||||
13
frontend/node_modules/antd/es/form/hooks/useDebounce.js
generated
vendored
Normal file
13
frontend/node_modules/antd/es/form/hooks/useDebounce.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import * as React from 'react';
|
||||
export default function useDebounce(value) {
|
||||
const [cacheValue, setCacheValue] = React.useState(value);
|
||||
React.useEffect(() => {
|
||||
const timeout = setTimeout(() => {
|
||||
setCacheValue(value);
|
||||
}, value.length ? 0 : 10);
|
||||
return () => {
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
}, [value]);
|
||||
return cacheValue;
|
||||
}
|
||||
9
frontend/node_modules/antd/es/form/hooks/useForm.d.ts
generated
vendored
Normal file
9
frontend/node_modules/antd/es/form/hooks/useForm.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { FormInstance as RcFormInstance } from 'rc-field-form';
|
||||
import type { NamePath, ScrollOptions } from '../interface';
|
||||
export interface FormInstance<Values = any> extends RcFormInstance<Values> {
|
||||
scrollToField: (name: NamePath, options?: ScrollOptions) => void;
|
||||
focusField: (name: NamePath) => void;
|
||||
getFieldInstance: (name: NamePath) => any;
|
||||
}
|
||||
export declare function toNamePathStr(name: NamePath): string;
|
||||
export default function useForm<Values = any>(form?: FormInstance<Values>): [FormInstance<Values>];
|
||||
75
frontend/node_modules/antd/es/form/hooks/useForm.js
generated
vendored
Normal file
75
frontend/node_modules/antd/es/form/hooks/useForm.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
var __rest = this && this.__rest || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import * as React from 'react';
|
||||
import { useForm as useRcForm } from 'rc-field-form';
|
||||
import { getDOM } from "rc-util/es/Dom/findDOMNode";
|
||||
import scrollIntoView from 'scroll-into-view-if-needed';
|
||||
import { getFieldId, toArray } from '../util';
|
||||
export function toNamePathStr(name) {
|
||||
const namePath = toArray(name);
|
||||
return namePath.join('_');
|
||||
}
|
||||
function getFieldDOMNode(name, wrapForm) {
|
||||
const field = wrapForm.getFieldInstance(name);
|
||||
const fieldDom = getDOM(field);
|
||||
if (fieldDom) {
|
||||
return fieldDom;
|
||||
}
|
||||
const fieldId = getFieldId(toArray(name), wrapForm.__INTERNAL__.name);
|
||||
if (fieldId) {
|
||||
return document.getElementById(fieldId);
|
||||
}
|
||||
}
|
||||
export default function useForm(form) {
|
||||
const [rcForm] = useRcForm();
|
||||
const itemsRef = React.useRef({});
|
||||
const wrapForm = React.useMemo(() => form !== null && form !== void 0 ? form : Object.assign(Object.assign({}, rcForm), {
|
||||
__INTERNAL__: {
|
||||
itemRef: name => node => {
|
||||
const namePathStr = toNamePathStr(name);
|
||||
if (node) {
|
||||
itemsRef.current[namePathStr] = node;
|
||||
} else {
|
||||
delete itemsRef.current[namePathStr];
|
||||
}
|
||||
}
|
||||
},
|
||||
scrollToField: (name, options = {}) => {
|
||||
const {
|
||||
focus
|
||||
} = options,
|
||||
restOpt = __rest(options, ["focus"]);
|
||||
const node = getFieldDOMNode(name, wrapForm);
|
||||
if (node) {
|
||||
scrollIntoView(node, Object.assign({
|
||||
scrollMode: 'if-needed',
|
||||
block: 'nearest'
|
||||
}, restOpt));
|
||||
// Focus if scroll success
|
||||
if (focus) {
|
||||
wrapForm.focusField(name);
|
||||
}
|
||||
}
|
||||
},
|
||||
focusField: name => {
|
||||
var _a, _b;
|
||||
const itemRef = wrapForm.getFieldInstance(name);
|
||||
if (typeof (itemRef === null || itemRef === void 0 ? void 0 : itemRef.focus) === 'function') {
|
||||
itemRef.focus();
|
||||
} else {
|
||||
(_b = (_a = getFieldDOMNode(name, wrapForm)) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a);
|
||||
}
|
||||
},
|
||||
getFieldInstance: name => {
|
||||
const namePathStr = toNamePathStr(name);
|
||||
return itemsRef.current[namePathStr];
|
||||
}
|
||||
}), [form, rcForm]);
|
||||
return [wrapForm];
|
||||
}
|
||||
2
frontend/node_modules/antd/es/form/hooks/useFormInstance.d.ts
generated
vendored
Normal file
2
frontend/node_modules/antd/es/form/hooks/useFormInstance.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { FormInstance } from './useForm';
|
||||
export default function useFormInstance<Value = any>(): FormInstance<Value>;
|
||||
8
frontend/node_modules/antd/es/form/hooks/useFormInstance.js
generated
vendored
Normal file
8
frontend/node_modules/antd/es/form/hooks/useFormInstance.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import { FormContext } from '../context';
|
||||
export default function useFormInstance() {
|
||||
const {
|
||||
form
|
||||
} = React.useContext(FormContext);
|
||||
return form;
|
||||
}
|
||||
9
frontend/node_modules/antd/es/form/hooks/useFormItemStatus.d.ts
generated
vendored
Normal file
9
frontend/node_modules/antd/es/form/hooks/useFormItemStatus.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as React from 'react';
|
||||
import type { ValidateStatus } from 'antd/es/form/FormItem';
|
||||
type UseFormItemStatus = () => {
|
||||
status?: ValidateStatus;
|
||||
errors: React.ReactNode[];
|
||||
warnings: React.ReactNode[];
|
||||
};
|
||||
declare const useFormItemStatus: UseFormItemStatus;
|
||||
export default useFormItemStatus;
|
||||
22
frontend/node_modules/antd/es/form/hooks/useFormItemStatus.js
generated
vendored
Normal file
22
frontend/node_modules/antd/es/form/hooks/useFormItemStatus.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import * as React from 'react';
|
||||
import { devUseWarning } from '../../_util/warning';
|
||||
import { FormItemInputContext } from '../context';
|
||||
const useFormItemStatus = () => {
|
||||
const {
|
||||
status,
|
||||
errors = [],
|
||||
warnings = []
|
||||
} = React.useContext(FormItemInputContext);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
const warning = devUseWarning('Form.Item');
|
||||
process.env.NODE_ENV !== "production" ? warning(status !== undefined, 'usage', 'Form.Item.useStatus should be used under Form.Item component. For more information: https://u.ant.design/form-item-usestatus') : void 0;
|
||||
}
|
||||
return {
|
||||
status,
|
||||
errors,
|
||||
warnings
|
||||
};
|
||||
};
|
||||
// Only used for compatible package. Not promise this will work on future version.
|
||||
useFormItemStatus.Context = FormItemInputContext;
|
||||
export default useFormItemStatus;
|
||||
2
frontend/node_modules/antd/es/form/hooks/useFormWarning.d.ts
generated
vendored
Normal file
2
frontend/node_modules/antd/es/form/hooks/useFormWarning.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { FormProps } from '../Form';
|
||||
export default function useFormWarning({ name }: FormProps): void;
|
||||
17
frontend/node_modules/antd/es/form/hooks/useFormWarning.js
generated
vendored
Normal file
17
frontend/node_modules/antd/es/form/hooks/useFormWarning.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as React from 'react';
|
||||
import { devUseWarning } from '../../_util/warning';
|
||||
const names = {};
|
||||
export default function useFormWarning({
|
||||
name
|
||||
}) {
|
||||
const warning = devUseWarning('Form');
|
||||
React.useEffect(() => {
|
||||
if (name) {
|
||||
names[name] = (names[name] || 0) + 1;
|
||||
process.env.NODE_ENV !== "production" ? warning(names[name] <= 1, 'usage', 'There exist multiple Form with same `name`.') : void 0;
|
||||
return () => {
|
||||
names[name] -= 1;
|
||||
};
|
||||
}
|
||||
}, [name]);
|
||||
}
|
||||
3
frontend/node_modules/antd/es/form/hooks/useFrameState.d.ts
generated
vendored
Normal file
3
frontend/node_modules/antd/es/form/hooks/useFrameState.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
type Updater<ValueType> = (prev?: ValueType) => ValueType;
|
||||
export default function useFrameState<ValueType>(defaultValue: ValueType): [ValueType, (updater: Updater<ValueType>) => void];
|
||||
export {};
|
||||
36
frontend/node_modules/antd/es/form/hooks/useFrameState.js
generated
vendored
Normal file
36
frontend/node_modules/antd/es/form/hooks/useFrameState.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import * as React from 'react';
|
||||
import raf from "rc-util/es/raf";
|
||||
export default function useFrameState(defaultValue) {
|
||||
const [value, setValue] = React.useState(defaultValue);
|
||||
const frameRef = React.useRef(null);
|
||||
const batchRef = React.useRef([]);
|
||||
const destroyRef = React.useRef(false);
|
||||
React.useEffect(() => {
|
||||
destroyRef.current = false;
|
||||
return () => {
|
||||
destroyRef.current = true;
|
||||
raf.cancel(frameRef.current);
|
||||
frameRef.current = null;
|
||||
};
|
||||
}, []);
|
||||
function setFrameValue(updater) {
|
||||
if (destroyRef.current) {
|
||||
return;
|
||||
}
|
||||
if (frameRef.current === null) {
|
||||
batchRef.current = [];
|
||||
frameRef.current = raf(() => {
|
||||
frameRef.current = null;
|
||||
setValue(prevValue => {
|
||||
let current = prevValue;
|
||||
batchRef.current.forEach(func => {
|
||||
current = func(current);
|
||||
});
|
||||
return current;
|
||||
});
|
||||
});
|
||||
}
|
||||
batchRef.current.push(updater);
|
||||
}
|
||||
return [value, setFrameValue];
|
||||
}
|
||||
3
frontend/node_modules/antd/es/form/hooks/useItemRef.d.ts
generated
vendored
Normal file
3
frontend/node_modules/antd/es/form/hooks/useItemRef.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import * as React from 'react';
|
||||
import type { InternalNamePath } from '../interface';
|
||||
export default function useItemRef(): (name: InternalNamePath, children: any) => React.Ref<any> | undefined;
|
||||
21
frontend/node_modules/antd/es/form/hooks/useItemRef.js
generated
vendored
Normal file
21
frontend/node_modules/antd/es/form/hooks/useItemRef.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as React from 'react';
|
||||
import { composeRef, getNodeRef } from "rc-util/es/ref";
|
||||
import { FormContext } from '../context';
|
||||
export default function useItemRef() {
|
||||
const {
|
||||
itemRef
|
||||
} = React.useContext(FormContext);
|
||||
const cacheRef = React.useRef({});
|
||||
function getRef(name, children) {
|
||||
// Outer caller already check the `supportRef`
|
||||
const childrenRef = children && typeof children === 'object' && getNodeRef(children);
|
||||
const nameStr = name.join('_');
|
||||
if (cacheRef.current.name !== nameStr || cacheRef.current.originRef !== childrenRef) {
|
||||
cacheRef.current.name = nameStr;
|
||||
cacheRef.current.originRef = childrenRef;
|
||||
cacheRef.current.ref = composeRef(itemRef(name), childrenRef);
|
||||
}
|
||||
return cacheRef.current.ref;
|
||||
}
|
||||
return getRef;
|
||||
}
|
||||
7
frontend/node_modules/antd/es/form/hooks/useVariants.d.ts
generated
vendored
Normal file
7
frontend/node_modules/antd/es/form/hooks/useVariants.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { ConfigProviderProps, Variant } from '../../config-provider';
|
||||
type VariantComponents = keyof Pick<ConfigProviderProps, 'input' | 'inputNumber' | 'textArea' | 'mentions' | 'select' | 'cascader' | 'treeSelect' | 'datePicker' | 'timePicker' | 'rangePicker' | 'card'>;
|
||||
/**
|
||||
* Compatible for legacy `bordered` prop.
|
||||
*/
|
||||
declare const useVariant: (component: VariantComponents, variant?: Variant, legacyBordered?: boolean) => [Variant, boolean];
|
||||
export default useVariant;
|
||||
27
frontend/node_modules/antd/es/form/hooks/useVariants.js
generated
vendored
Normal file
27
frontend/node_modules/antd/es/form/hooks/useVariants.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import * as React from 'react';
|
||||
import { ConfigContext, Variants } from '../../config-provider';
|
||||
import { VariantContext } from '../context';
|
||||
/**
|
||||
* Compatible for legacy `bordered` prop.
|
||||
*/
|
||||
const useVariant = (component, variant, legacyBordered) => {
|
||||
var _a, _b;
|
||||
const {
|
||||
variant: configVariant,
|
||||
[component]: componentConfig
|
||||
} = React.useContext(ConfigContext);
|
||||
const ctxVariant = React.useContext(VariantContext);
|
||||
const configComponentVariant = componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.variant;
|
||||
let mergedVariant;
|
||||
if (typeof variant !== 'undefined') {
|
||||
mergedVariant = variant;
|
||||
} else if (legacyBordered === false) {
|
||||
mergedVariant = 'borderless';
|
||||
} else {
|
||||
// form variant > component global variant > global variant
|
||||
mergedVariant = (_b = (_a = ctxVariant !== null && ctxVariant !== void 0 ? ctxVariant : configComponentVariant) !== null && _a !== void 0 ? _a : configVariant) !== null && _b !== void 0 ? _b : 'outlined';
|
||||
}
|
||||
const enableVariantCls = Variants.includes(mergedVariant);
|
||||
return [mergedVariant, enableVariantCls];
|
||||
};
|
||||
export default useVariant;
|
||||
Reference in New Issue
Block a user