seeder-st2110-components 1.6.2 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +597 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +596 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { memo, useState, useCallback, useMemo, useEffect, useRef } from 'react';
|
|
2
|
-
import { Tooltip, App, Modal, Form, Input, Alert, message, Dropdown, Spin, Divider, Typography, InputNumber, ConfigProvider, Badge, Switch,
|
|
2
|
+
import { Tooltip, App, Modal, Form, Input, Alert, message, Dropdown, Spin, Select, Divider, Typography, InputNumber, ConfigProvider, Badge, Switch, List, Empty, Button, Space, Flex, Checkbox, Row, Col } from 'antd';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { useWebSocket, useInterval } from 'ahooks';
|
|
5
5
|
import { LoadingOutlined, ExclamationCircleFilled, PlusOutlined } from '@ant-design/icons';
|
|
@@ -790,6 +790,601 @@ const useSystemOperations = function () {
|
|
|
790
790
|
};
|
|
791
791
|
var useSystemOperations$1 = useSystemOperations;
|
|
792
792
|
|
|
793
|
+
var isCheckBoxInput = (element) => element.type === 'checkbox';
|
|
794
|
+
|
|
795
|
+
var isDateObject = (value) => value instanceof Date;
|
|
796
|
+
|
|
797
|
+
var isNullOrUndefined = (value) => value == null;
|
|
798
|
+
|
|
799
|
+
const isObjectType = (value) => typeof value === 'object';
|
|
800
|
+
var isObject = (value) => !isNullOrUndefined(value) &&
|
|
801
|
+
!Array.isArray(value) &&
|
|
802
|
+
isObjectType(value) &&
|
|
803
|
+
!isDateObject(value);
|
|
804
|
+
|
|
805
|
+
var getEventValue = (event) => isObject(event) && event.target
|
|
806
|
+
? isCheckBoxInput(event.target)
|
|
807
|
+
? event.target.checked
|
|
808
|
+
: event.target.value
|
|
809
|
+
: event;
|
|
810
|
+
|
|
811
|
+
var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
|
|
812
|
+
|
|
813
|
+
var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
|
|
814
|
+
|
|
815
|
+
var isPlainObject = (tempObject) => {
|
|
816
|
+
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
|
|
817
|
+
return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
var isWeb = typeof window !== 'undefined' &&
|
|
821
|
+
typeof window.HTMLElement !== 'undefined' &&
|
|
822
|
+
typeof document !== 'undefined';
|
|
823
|
+
|
|
824
|
+
function cloneObject(data) {
|
|
825
|
+
let copy;
|
|
826
|
+
const isArray = Array.isArray(data);
|
|
827
|
+
const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
|
|
828
|
+
if (data instanceof Date) {
|
|
829
|
+
copy = new Date(data);
|
|
830
|
+
}
|
|
831
|
+
else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
|
|
832
|
+
(isArray || isObject(data))) {
|
|
833
|
+
copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
834
|
+
if (!isArray && !isPlainObject(data)) {
|
|
835
|
+
copy = data;
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
for (const key in data) {
|
|
839
|
+
if (data.hasOwnProperty(key)) {
|
|
840
|
+
copy[key] = cloneObject(data[key]);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
else {
|
|
846
|
+
return data;
|
|
847
|
+
}
|
|
848
|
+
return copy;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
var isKey = (value) => /^\w*$/.test(value);
|
|
852
|
+
|
|
853
|
+
var isUndefined = (val) => val === undefined;
|
|
854
|
+
|
|
855
|
+
var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
|
|
856
|
+
|
|
857
|
+
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
|
858
|
+
|
|
859
|
+
var get = (object, path, defaultValue) => {
|
|
860
|
+
if (!path || !isObject(object)) {
|
|
861
|
+
return defaultValue;
|
|
862
|
+
}
|
|
863
|
+
const result = (isKey(path) ? [path] : stringToPath(path)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], object);
|
|
864
|
+
return isUndefined(result) || result === object
|
|
865
|
+
? isUndefined(object[path])
|
|
866
|
+
? defaultValue
|
|
867
|
+
: object[path]
|
|
868
|
+
: result;
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
var isBoolean = (value) => typeof value === 'boolean';
|
|
872
|
+
|
|
873
|
+
var set = (object, path, value) => {
|
|
874
|
+
let index = -1;
|
|
875
|
+
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
876
|
+
const length = tempPath.length;
|
|
877
|
+
const lastIndex = length - 1;
|
|
878
|
+
while (++index < length) {
|
|
879
|
+
const key = tempPath[index];
|
|
880
|
+
let newValue = value;
|
|
881
|
+
if (index !== lastIndex) {
|
|
882
|
+
const objValue = object[key];
|
|
883
|
+
newValue =
|
|
884
|
+
isObject(objValue) || Array.isArray(objValue)
|
|
885
|
+
? objValue
|
|
886
|
+
: !isNaN(+tempPath[index + 1])
|
|
887
|
+
? []
|
|
888
|
+
: {};
|
|
889
|
+
}
|
|
890
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
object[key] = newValue;
|
|
894
|
+
object = object[key];
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
|
|
898
|
+
const EVENTS = {
|
|
899
|
+
BLUR: 'blur',
|
|
900
|
+
FOCUS_OUT: 'focusout',
|
|
901
|
+
CHANGE: 'change',
|
|
902
|
+
};
|
|
903
|
+
const VALIDATION_MODE = {
|
|
904
|
+
onBlur: 'onBlur',
|
|
905
|
+
onChange: 'onChange',
|
|
906
|
+
onSubmit: 'onSubmit',
|
|
907
|
+
onTouched: 'onTouched',
|
|
908
|
+
all: 'all',
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
const HookFormContext = React.createContext(null);
|
|
912
|
+
HookFormContext.displayName = 'HookFormContext';
|
|
913
|
+
/**
|
|
914
|
+
* This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
|
|
915
|
+
*
|
|
916
|
+
* @remarks
|
|
917
|
+
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
918
|
+
*
|
|
919
|
+
* @returns return all useForm methods
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* ```tsx
|
|
923
|
+
* function App() {
|
|
924
|
+
* const methods = useForm();
|
|
925
|
+
* const onSubmit = data => console.log(data);
|
|
926
|
+
*
|
|
927
|
+
* return (
|
|
928
|
+
* <FormProvider {...methods} >
|
|
929
|
+
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
930
|
+
* <NestedInput />
|
|
931
|
+
* <input type="submit" />
|
|
932
|
+
* </form>
|
|
933
|
+
* </FormProvider>
|
|
934
|
+
* );
|
|
935
|
+
* }
|
|
936
|
+
*
|
|
937
|
+
* function NestedInput() {
|
|
938
|
+
* const { register } = useFormContext(); // retrieve all hook methods
|
|
939
|
+
* return <input {...register("test")} />;
|
|
940
|
+
* }
|
|
941
|
+
* ```
|
|
942
|
+
*/
|
|
943
|
+
const useFormContext = () => React.useContext(HookFormContext);
|
|
944
|
+
|
|
945
|
+
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
|
946
|
+
const result = {
|
|
947
|
+
defaultValues: control._defaultValues,
|
|
948
|
+
};
|
|
949
|
+
for (const key in formState) {
|
|
950
|
+
Object.defineProperty(result, key, {
|
|
951
|
+
get: () => {
|
|
952
|
+
const _key = key;
|
|
953
|
+
if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
|
|
954
|
+
control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
|
|
955
|
+
}
|
|
956
|
+
localProxyFormState && (localProxyFormState[_key] = true);
|
|
957
|
+
return formState[_key];
|
|
958
|
+
},
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
return result;
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
|
|
968
|
+
*
|
|
969
|
+
* @remarks
|
|
970
|
+
* [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
|
|
971
|
+
*
|
|
972
|
+
* @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
|
|
973
|
+
*
|
|
974
|
+
* @example
|
|
975
|
+
* ```tsx
|
|
976
|
+
* function App() {
|
|
977
|
+
* const { register, handleSubmit, control } = useForm({
|
|
978
|
+
* defaultValues: {
|
|
979
|
+
* firstName: "firstName"
|
|
980
|
+
* }});
|
|
981
|
+
* const { dirtyFields } = useFormState({
|
|
982
|
+
* control
|
|
983
|
+
* });
|
|
984
|
+
* const onSubmit = (data) => console.log(data);
|
|
985
|
+
*
|
|
986
|
+
* return (
|
|
987
|
+
* <form onSubmit={handleSubmit(onSubmit)}>
|
|
988
|
+
* <input {...register("firstName")} placeholder="First Name" />
|
|
989
|
+
* {dirtyFields.firstName && <p>Field is dirty.</p>}
|
|
990
|
+
* <input type="submit" />
|
|
991
|
+
* </form>
|
|
992
|
+
* );
|
|
993
|
+
* }
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
function useFormState(props) {
|
|
997
|
+
const methods = useFormContext();
|
|
998
|
+
const { control = methods.control, disabled, name, exact } = props || {};
|
|
999
|
+
const [formState, updateFormState] = React.useState(control._formState);
|
|
1000
|
+
const _localProxyFormState = React.useRef({
|
|
1001
|
+
isDirty: false,
|
|
1002
|
+
isLoading: false,
|
|
1003
|
+
dirtyFields: false,
|
|
1004
|
+
touchedFields: false,
|
|
1005
|
+
validatingFields: false,
|
|
1006
|
+
isValidating: false,
|
|
1007
|
+
isValid: false,
|
|
1008
|
+
errors: false,
|
|
1009
|
+
});
|
|
1010
|
+
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
1011
|
+
name,
|
|
1012
|
+
formState: _localProxyFormState.current,
|
|
1013
|
+
exact,
|
|
1014
|
+
callback: (formState) => {
|
|
1015
|
+
!disabled &&
|
|
1016
|
+
updateFormState({
|
|
1017
|
+
...control._formState,
|
|
1018
|
+
...formState,
|
|
1019
|
+
});
|
|
1020
|
+
},
|
|
1021
|
+
}), [name, disabled, exact]);
|
|
1022
|
+
React.useEffect(() => {
|
|
1023
|
+
_localProxyFormState.current.isValid && control._setValid(true);
|
|
1024
|
+
}, [control]);
|
|
1025
|
+
return React.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
var isString = (value) => typeof value === 'string';
|
|
1029
|
+
|
|
1030
|
+
var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
|
|
1031
|
+
if (isString(names)) {
|
|
1032
|
+
isGlobal && _names.watch.add(names);
|
|
1033
|
+
return get(formValues, names, defaultValue);
|
|
1034
|
+
}
|
|
1035
|
+
if (Array.isArray(names)) {
|
|
1036
|
+
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
|
|
1037
|
+
get(formValues, fieldName)));
|
|
1038
|
+
}
|
|
1039
|
+
isGlobal && (_names.watchAll = true);
|
|
1040
|
+
return formValues;
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
1044
|
+
|
|
1045
|
+
function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
1046
|
+
if (isPrimitive(object1) || isPrimitive(object2)) {
|
|
1047
|
+
return object1 === object2;
|
|
1048
|
+
}
|
|
1049
|
+
if (isDateObject(object1) && isDateObject(object2)) {
|
|
1050
|
+
return object1.getTime() === object2.getTime();
|
|
1051
|
+
}
|
|
1052
|
+
const keys1 = Object.keys(object1);
|
|
1053
|
+
const keys2 = Object.keys(object2);
|
|
1054
|
+
if (keys1.length !== keys2.length) {
|
|
1055
|
+
return false;
|
|
1056
|
+
}
|
|
1057
|
+
if (_internal_visited.has(object1) || _internal_visited.has(object2)) {
|
|
1058
|
+
return true;
|
|
1059
|
+
}
|
|
1060
|
+
_internal_visited.add(object1);
|
|
1061
|
+
_internal_visited.add(object2);
|
|
1062
|
+
for (const key of keys1) {
|
|
1063
|
+
const val1 = object1[key];
|
|
1064
|
+
if (!keys2.includes(key)) {
|
|
1065
|
+
return false;
|
|
1066
|
+
}
|
|
1067
|
+
if (key !== 'ref') {
|
|
1068
|
+
const val2 = object2[key];
|
|
1069
|
+
if ((isDateObject(val1) && isDateObject(val2)) ||
|
|
1070
|
+
(isObject(val1) && isObject(val2)) ||
|
|
1071
|
+
(Array.isArray(val1) && Array.isArray(val2))
|
|
1072
|
+
? !deepEqual(val1, val2, _internal_visited)
|
|
1073
|
+
: val1 !== val2) {
|
|
1074
|
+
return false;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
return true;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Custom hook to subscribe to field change and isolate re-rendering at the component level.
|
|
1083
|
+
*
|
|
1084
|
+
* @remarks
|
|
1085
|
+
*
|
|
1086
|
+
* [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* ```tsx
|
|
1090
|
+
* const { control } = useForm();
|
|
1091
|
+
* const values = useWatch({
|
|
1092
|
+
* name: "fieldName"
|
|
1093
|
+
* control,
|
|
1094
|
+
* })
|
|
1095
|
+
* ```
|
|
1096
|
+
*/
|
|
1097
|
+
function useWatch(props) {
|
|
1098
|
+
const methods = useFormContext();
|
|
1099
|
+
const { control = methods.control, name, defaultValue, disabled, exact, compute, } = props || {};
|
|
1100
|
+
const _defaultValue = React.useRef(defaultValue);
|
|
1101
|
+
const _compute = React.useRef(compute);
|
|
1102
|
+
const _computeFormValues = React.useRef(undefined);
|
|
1103
|
+
_compute.current = compute;
|
|
1104
|
+
const defaultValueMemo = React.useMemo(() => control._getWatch(name, _defaultValue.current), [control, name]);
|
|
1105
|
+
const [value, updateValue] = React.useState(_compute.current ? _compute.current(defaultValueMemo) : defaultValueMemo);
|
|
1106
|
+
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
1107
|
+
name,
|
|
1108
|
+
formState: {
|
|
1109
|
+
values: true,
|
|
1110
|
+
},
|
|
1111
|
+
exact,
|
|
1112
|
+
callback: (formState) => {
|
|
1113
|
+
if (!disabled) {
|
|
1114
|
+
const formValues = generateWatchOutput(name, control._names, formState.values || control._formValues, false, _defaultValue.current);
|
|
1115
|
+
if (_compute.current) {
|
|
1116
|
+
const computedFormValues = _compute.current(formValues);
|
|
1117
|
+
if (!deepEqual(computedFormValues, _computeFormValues.current)) {
|
|
1118
|
+
updateValue(computedFormValues);
|
|
1119
|
+
_computeFormValues.current = computedFormValues;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
else {
|
|
1123
|
+
updateValue(formValues);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
},
|
|
1127
|
+
}), [control, disabled, name, exact]);
|
|
1128
|
+
React.useEffect(() => control._removeUnmounted());
|
|
1129
|
+
return value;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
|
|
1134
|
+
*
|
|
1135
|
+
* @remarks
|
|
1136
|
+
* [API](https://react-hook-form.com/docs/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
|
|
1137
|
+
*
|
|
1138
|
+
* @param props - the path name to the form field value, and validation rules.
|
|
1139
|
+
*
|
|
1140
|
+
* @returns field properties, field and form state. {@link UseControllerReturn}
|
|
1141
|
+
*
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```tsx
|
|
1144
|
+
* function Input(props) {
|
|
1145
|
+
* const { field, fieldState, formState } = useController(props);
|
|
1146
|
+
* return (
|
|
1147
|
+
* <div>
|
|
1148
|
+
* <input {...field} placeholder={props.name} />
|
|
1149
|
+
* <p>{fieldState.isTouched && "Touched"}</p>
|
|
1150
|
+
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
|
|
1151
|
+
* </div>
|
|
1152
|
+
* );
|
|
1153
|
+
* }
|
|
1154
|
+
* ```
|
|
1155
|
+
*/
|
|
1156
|
+
function useController(props) {
|
|
1157
|
+
const methods = useFormContext();
|
|
1158
|
+
const { name, disabled, control = methods.control, shouldUnregister, defaultValue, } = props;
|
|
1159
|
+
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
1160
|
+
const defaultValueMemo = React.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
|
|
1161
|
+
const value = useWatch({
|
|
1162
|
+
control,
|
|
1163
|
+
name,
|
|
1164
|
+
defaultValue: defaultValueMemo,
|
|
1165
|
+
exact: true,
|
|
1166
|
+
});
|
|
1167
|
+
const formState = useFormState({
|
|
1168
|
+
control,
|
|
1169
|
+
name,
|
|
1170
|
+
exact: true,
|
|
1171
|
+
});
|
|
1172
|
+
const _props = React.useRef(props);
|
|
1173
|
+
const _registerProps = React.useRef(control.register(name, {
|
|
1174
|
+
...props.rules,
|
|
1175
|
+
value,
|
|
1176
|
+
...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),
|
|
1177
|
+
}));
|
|
1178
|
+
_props.current = props;
|
|
1179
|
+
const fieldState = React.useMemo(() => Object.defineProperties({}, {
|
|
1180
|
+
invalid: {
|
|
1181
|
+
enumerable: true,
|
|
1182
|
+
get: () => !!get(formState.errors, name),
|
|
1183
|
+
},
|
|
1184
|
+
isDirty: {
|
|
1185
|
+
enumerable: true,
|
|
1186
|
+
get: () => !!get(formState.dirtyFields, name),
|
|
1187
|
+
},
|
|
1188
|
+
isTouched: {
|
|
1189
|
+
enumerable: true,
|
|
1190
|
+
get: () => !!get(formState.touchedFields, name),
|
|
1191
|
+
},
|
|
1192
|
+
isValidating: {
|
|
1193
|
+
enumerable: true,
|
|
1194
|
+
get: () => !!get(formState.validatingFields, name),
|
|
1195
|
+
},
|
|
1196
|
+
error: {
|
|
1197
|
+
enumerable: true,
|
|
1198
|
+
get: () => get(formState.errors, name),
|
|
1199
|
+
},
|
|
1200
|
+
}), [formState, name]);
|
|
1201
|
+
const onChange = React.useCallback((event) => _registerProps.current.onChange({
|
|
1202
|
+
target: {
|
|
1203
|
+
value: getEventValue(event),
|
|
1204
|
+
name: name,
|
|
1205
|
+
},
|
|
1206
|
+
type: EVENTS.CHANGE,
|
|
1207
|
+
}), [name]);
|
|
1208
|
+
const onBlur = React.useCallback(() => _registerProps.current.onBlur({
|
|
1209
|
+
target: {
|
|
1210
|
+
value: get(control._formValues, name),
|
|
1211
|
+
name: name,
|
|
1212
|
+
},
|
|
1213
|
+
type: EVENTS.BLUR,
|
|
1214
|
+
}), [name, control._formValues]);
|
|
1215
|
+
const ref = React.useCallback((elm) => {
|
|
1216
|
+
const field = get(control._fields, name);
|
|
1217
|
+
if (field && elm) {
|
|
1218
|
+
field._f.ref = {
|
|
1219
|
+
focus: () => elm.focus && elm.focus(),
|
|
1220
|
+
select: () => elm.select && elm.select(),
|
|
1221
|
+
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
1222
|
+
reportValidity: () => elm.reportValidity(),
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
}, [control._fields, name]);
|
|
1226
|
+
const field = React.useMemo(() => ({
|
|
1227
|
+
name,
|
|
1228
|
+
value,
|
|
1229
|
+
...(isBoolean(disabled) || formState.disabled
|
|
1230
|
+
? { disabled: formState.disabled || disabled }
|
|
1231
|
+
: {}),
|
|
1232
|
+
onChange,
|
|
1233
|
+
onBlur,
|
|
1234
|
+
ref,
|
|
1235
|
+
}), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
|
|
1236
|
+
React.useEffect(() => {
|
|
1237
|
+
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
|
1238
|
+
control.register(name, {
|
|
1239
|
+
..._props.current.rules,
|
|
1240
|
+
...(isBoolean(_props.current.disabled)
|
|
1241
|
+
? { disabled: _props.current.disabled }
|
|
1242
|
+
: {}),
|
|
1243
|
+
});
|
|
1244
|
+
const updateMounted = (name, value) => {
|
|
1245
|
+
const field = get(control._fields, name);
|
|
1246
|
+
if (field && field._f) {
|
|
1247
|
+
field._f.mount = value;
|
|
1248
|
+
}
|
|
1249
|
+
};
|
|
1250
|
+
updateMounted(name, true);
|
|
1251
|
+
if (_shouldUnregisterField) {
|
|
1252
|
+
const value = cloneObject(get(control._options.defaultValues, name));
|
|
1253
|
+
set(control._defaultValues, name, value);
|
|
1254
|
+
if (isUndefined(get(control._formValues, name))) {
|
|
1255
|
+
set(control._formValues, name, value);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
!isArrayField && control.register(name);
|
|
1259
|
+
return () => {
|
|
1260
|
+
(isArrayField
|
|
1261
|
+
? _shouldUnregisterField && !control._state.action
|
|
1262
|
+
: _shouldUnregisterField)
|
|
1263
|
+
? control.unregister(name)
|
|
1264
|
+
: updateMounted(name, false);
|
|
1265
|
+
};
|
|
1266
|
+
}, [name, control, isArrayField, shouldUnregister]);
|
|
1267
|
+
React.useEffect(() => {
|
|
1268
|
+
control._setDisabledField({
|
|
1269
|
+
disabled,
|
|
1270
|
+
name,
|
|
1271
|
+
});
|
|
1272
|
+
}, [disabled, name, control]);
|
|
1273
|
+
return React.useMemo(() => ({
|
|
1274
|
+
field,
|
|
1275
|
+
formState,
|
|
1276
|
+
fieldState,
|
|
1277
|
+
}), [field, formState, fieldState]);
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
/**
|
|
1281
|
+
* Component based on `useController` hook to work with controlled component.
|
|
1282
|
+
*
|
|
1283
|
+
* @remarks
|
|
1284
|
+
* [API](https://react-hook-form.com/docs/usecontroller/controller) • [Demo](https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw) • [Video](https://www.youtube.com/watch?v=N2UNk_UCVyA)
|
|
1285
|
+
*
|
|
1286
|
+
* @param props - the path name to the form field value, and validation rules.
|
|
1287
|
+
*
|
|
1288
|
+
* @returns provide field handler functions, field and form state.
|
|
1289
|
+
*
|
|
1290
|
+
* @example
|
|
1291
|
+
* ```tsx
|
|
1292
|
+
* function App() {
|
|
1293
|
+
* const { control } = useForm<FormValues>({
|
|
1294
|
+
* defaultValues: {
|
|
1295
|
+
* test: ""
|
|
1296
|
+
* }
|
|
1297
|
+
* });
|
|
1298
|
+
*
|
|
1299
|
+
* return (
|
|
1300
|
+
* <form>
|
|
1301
|
+
* <Controller
|
|
1302
|
+
* control={control}
|
|
1303
|
+
* name="test"
|
|
1304
|
+
* render={({ field: { onChange, onBlur, value, ref }, formState, fieldState }) => (
|
|
1305
|
+
* <>
|
|
1306
|
+
* <input
|
|
1307
|
+
* onChange={onChange} // send value to hook form
|
|
1308
|
+
* onBlur={onBlur} // notify when input is touched
|
|
1309
|
+
* value={value} // return updated value
|
|
1310
|
+
* ref={ref} // set ref for focus management
|
|
1311
|
+
* />
|
|
1312
|
+
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
|
|
1313
|
+
* <p>{fieldState.isTouched ? "touched" : ""}</p>
|
|
1314
|
+
* </>
|
|
1315
|
+
* )}
|
|
1316
|
+
* />
|
|
1317
|
+
* </form>
|
|
1318
|
+
* );
|
|
1319
|
+
* }
|
|
1320
|
+
* ```
|
|
1321
|
+
*/
|
|
1322
|
+
const Controller = (props) => props.render(useController(props));
|
|
1323
|
+
|
|
1324
|
+
// 获取 LSM 中的IP映射列表
|
|
1325
|
+
async function get_lsm_data() {
|
|
1326
|
+
return request('/api/get_lsm_data', {
|
|
1327
|
+
method: 'GET'
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
const useLSMLabel = function () {
|
|
1332
|
+
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1333
|
+
const [lsmList, setLsmList] = useState([]);
|
|
1334
|
+
const {
|
|
1335
|
+
name,
|
|
1336
|
+
label = "Label",
|
|
1337
|
+
control,
|
|
1338
|
+
onLsmSelect,
|
|
1339
|
+
fetchLsmData = get_lsm_data,
|
|
1340
|
+
formItemProps = {},
|
|
1341
|
+
selectProps = {},
|
|
1342
|
+
fieldNames = {
|
|
1343
|
+
label: 'label',
|
|
1344
|
+
value: 'label'
|
|
1345
|
+
}
|
|
1346
|
+
} = props;
|
|
1347
|
+
useEffect(() => {
|
|
1348
|
+
const loadLsmData = async () => {
|
|
1349
|
+
try {
|
|
1350
|
+
const res = await fetchLsmData();
|
|
1351
|
+
if (res !== null && res !== void 0 && res.length) {
|
|
1352
|
+
setLsmList(res);
|
|
1353
|
+
}
|
|
1354
|
+
} catch (error) {
|
|
1355
|
+
console.error('Failed to fetch LSM data:', error);
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
loadLsmData();
|
|
1359
|
+
}, [fetchLsmData]);
|
|
1360
|
+
const renderLSMField = () => /*#__PURE__*/jsx(Controller, {
|
|
1361
|
+
name: name,
|
|
1362
|
+
control: control,
|
|
1363
|
+
render: _ref => {
|
|
1364
|
+
let {
|
|
1365
|
+
field
|
|
1366
|
+
} = _ref;
|
|
1367
|
+
return /*#__PURE__*/jsx(Form.Item, _objectSpread2(_objectSpread2({
|
|
1368
|
+
label: label
|
|
1369
|
+
}, formItemProps), {}, {
|
|
1370
|
+
children: /*#__PURE__*/jsx(Select, _objectSpread2(_objectSpread2(_objectSpread2({}, field), selectProps), {}, {
|
|
1371
|
+
options: lsmList,
|
|
1372
|
+
fieldNames: fieldNames,
|
|
1373
|
+
allowClear: true,
|
|
1374
|
+
showSearch: true,
|
|
1375
|
+
optionFilterProp: "label",
|
|
1376
|
+
onChange: (value, option) => {
|
|
1377
|
+
field.onChange(value);
|
|
1378
|
+
onLsmSelect === null || onLsmSelect === void 0 || onLsmSelect(value === undefined ? undefined : option);
|
|
1379
|
+
},
|
|
1380
|
+
placeholder: selectProps.placeholder || 'Please select label'
|
|
1381
|
+
}))
|
|
1382
|
+
}));
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
return renderLSMField;
|
|
1386
|
+
};
|
|
1387
|
+
|
|
793
1388
|
const NetworkFieldGroup = _ref => {
|
|
794
1389
|
var _fieldConfig$netmask$, _fieldConfig$netmask;
|
|
795
1390
|
let {
|
|
@@ -1041,8 +1636,6 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
1041
1636
|
setSubmitLoading(true);
|
|
1042
1637
|
try {
|
|
1043
1638
|
const values = await form.validateFields();
|
|
1044
|
-
// console.log("Direct form values:", values);
|
|
1045
|
-
|
|
1046
1639
|
const updatePromises = [];
|
|
1047
1640
|
|
|
1048
1641
|
// 更新LAN配置
|
|
@@ -3786,5 +4379,5 @@ function DraggableNumberInput(_ref2) {
|
|
|
3786
4379
|
}));
|
|
3787
4380
|
}
|
|
3788
4381
|
|
|
3789
|
-
export { AuthorizationModal$1 as AuthorizationModal, CommonHeader$1 as CommonHeader, DraggableNumberInput, NetworkSettingsModal$1 as NetworkSettingsModal, PresetModal, PtpModal$1 as PtpModal, SystemOperations$1 as SystemOperations, UpgradeManager$1 as UpgradeManager, useAuth, useHardwareUsage$1 as useHardwareUsage, useSystemOperations$1 as useSystemOperations, useUpgrade$1 as useUpgrade };
|
|
4382
|
+
export { AuthorizationModal$1 as AuthorizationModal, CommonHeader$1 as CommonHeader, DraggableNumberInput, NetworkSettingsModal$1 as NetworkSettingsModal, PresetModal, PtpModal$1 as PtpModal, SystemOperations$1 as SystemOperations, UpgradeManager$1 as UpgradeManager, useAuth, useHardwareUsage$1 as useHardwareUsage, useLSMLabel, useSystemOperations$1 as useSystemOperations, useUpgrade$1 as useUpgrade };
|
|
3790
4383
|
//# sourceMappingURL=index.esm.js.map
|