seeder-st2110-components 1.6.3 → 1.6.5
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 +57 -599
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +56 -598
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -792,601 +792,6 @@ const useSystemOperations = function () {
|
|
|
792
792
|
};
|
|
793
793
|
var useSystemOperations$1 = useSystemOperations;
|
|
794
794
|
|
|
795
|
-
var isCheckBoxInput = (element) => element.type === 'checkbox';
|
|
796
|
-
|
|
797
|
-
var isDateObject = (value) => value instanceof Date;
|
|
798
|
-
|
|
799
|
-
var isNullOrUndefined = (value) => value == null;
|
|
800
|
-
|
|
801
|
-
const isObjectType = (value) => typeof value === 'object';
|
|
802
|
-
var isObject = (value) => !isNullOrUndefined(value) &&
|
|
803
|
-
!Array.isArray(value) &&
|
|
804
|
-
isObjectType(value) &&
|
|
805
|
-
!isDateObject(value);
|
|
806
|
-
|
|
807
|
-
var getEventValue = (event) => isObject(event) && event.target
|
|
808
|
-
? isCheckBoxInput(event.target)
|
|
809
|
-
? event.target.checked
|
|
810
|
-
: event.target.value
|
|
811
|
-
: event;
|
|
812
|
-
|
|
813
|
-
var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
|
|
814
|
-
|
|
815
|
-
var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
|
|
816
|
-
|
|
817
|
-
var isPlainObject = (tempObject) => {
|
|
818
|
-
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
|
|
819
|
-
return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
|
|
820
|
-
};
|
|
821
|
-
|
|
822
|
-
var isWeb = typeof window !== 'undefined' &&
|
|
823
|
-
typeof window.HTMLElement !== 'undefined' &&
|
|
824
|
-
typeof document !== 'undefined';
|
|
825
|
-
|
|
826
|
-
function cloneObject(data) {
|
|
827
|
-
let copy;
|
|
828
|
-
const isArray = Array.isArray(data);
|
|
829
|
-
const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
|
|
830
|
-
if (data instanceof Date) {
|
|
831
|
-
copy = new Date(data);
|
|
832
|
-
}
|
|
833
|
-
else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
|
|
834
|
-
(isArray || isObject(data))) {
|
|
835
|
-
copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
836
|
-
if (!isArray && !isPlainObject(data)) {
|
|
837
|
-
copy = data;
|
|
838
|
-
}
|
|
839
|
-
else {
|
|
840
|
-
for (const key in data) {
|
|
841
|
-
if (data.hasOwnProperty(key)) {
|
|
842
|
-
copy[key] = cloneObject(data[key]);
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
else {
|
|
848
|
-
return data;
|
|
849
|
-
}
|
|
850
|
-
return copy;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
var isKey = (value) => /^\w*$/.test(value);
|
|
854
|
-
|
|
855
|
-
var isUndefined = (val) => val === undefined;
|
|
856
|
-
|
|
857
|
-
var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
|
|
858
|
-
|
|
859
|
-
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
|
860
|
-
|
|
861
|
-
var get = (object, path, defaultValue) => {
|
|
862
|
-
if (!path || !isObject(object)) {
|
|
863
|
-
return defaultValue;
|
|
864
|
-
}
|
|
865
|
-
const result = (isKey(path) ? [path] : stringToPath(path)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], object);
|
|
866
|
-
return isUndefined(result) || result === object
|
|
867
|
-
? isUndefined(object[path])
|
|
868
|
-
? defaultValue
|
|
869
|
-
: object[path]
|
|
870
|
-
: result;
|
|
871
|
-
};
|
|
872
|
-
|
|
873
|
-
var isBoolean = (value) => typeof value === 'boolean';
|
|
874
|
-
|
|
875
|
-
var set = (object, path, value) => {
|
|
876
|
-
let index = -1;
|
|
877
|
-
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
878
|
-
const length = tempPath.length;
|
|
879
|
-
const lastIndex = length - 1;
|
|
880
|
-
while (++index < length) {
|
|
881
|
-
const key = tempPath[index];
|
|
882
|
-
let newValue = value;
|
|
883
|
-
if (index !== lastIndex) {
|
|
884
|
-
const objValue = object[key];
|
|
885
|
-
newValue =
|
|
886
|
-
isObject(objValue) || Array.isArray(objValue)
|
|
887
|
-
? objValue
|
|
888
|
-
: !isNaN(+tempPath[index + 1])
|
|
889
|
-
? []
|
|
890
|
-
: {};
|
|
891
|
-
}
|
|
892
|
-
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
893
|
-
return;
|
|
894
|
-
}
|
|
895
|
-
object[key] = newValue;
|
|
896
|
-
object = object[key];
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
|
|
900
|
-
const EVENTS = {
|
|
901
|
-
BLUR: 'blur',
|
|
902
|
-
FOCUS_OUT: 'focusout',
|
|
903
|
-
CHANGE: 'change',
|
|
904
|
-
};
|
|
905
|
-
const VALIDATION_MODE = {
|
|
906
|
-
onBlur: 'onBlur',
|
|
907
|
-
onChange: 'onChange',
|
|
908
|
-
onSubmit: 'onSubmit',
|
|
909
|
-
onTouched: 'onTouched',
|
|
910
|
-
all: 'all',
|
|
911
|
-
};
|
|
912
|
-
|
|
913
|
-
const HookFormContext = React.createContext(null);
|
|
914
|
-
HookFormContext.displayName = 'HookFormContext';
|
|
915
|
-
/**
|
|
916
|
-
* 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}.
|
|
917
|
-
*
|
|
918
|
-
* @remarks
|
|
919
|
-
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
920
|
-
*
|
|
921
|
-
* @returns return all useForm methods
|
|
922
|
-
*
|
|
923
|
-
* @example
|
|
924
|
-
* ```tsx
|
|
925
|
-
* function App() {
|
|
926
|
-
* const methods = useForm();
|
|
927
|
-
* const onSubmit = data => console.log(data);
|
|
928
|
-
*
|
|
929
|
-
* return (
|
|
930
|
-
* <FormProvider {...methods} >
|
|
931
|
-
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
932
|
-
* <NestedInput />
|
|
933
|
-
* <input type="submit" />
|
|
934
|
-
* </form>
|
|
935
|
-
* </FormProvider>
|
|
936
|
-
* );
|
|
937
|
-
* }
|
|
938
|
-
*
|
|
939
|
-
* function NestedInput() {
|
|
940
|
-
* const { register } = useFormContext(); // retrieve all hook methods
|
|
941
|
-
* return <input {...register("test")} />;
|
|
942
|
-
* }
|
|
943
|
-
* ```
|
|
944
|
-
*/
|
|
945
|
-
const useFormContext = () => React.useContext(HookFormContext);
|
|
946
|
-
|
|
947
|
-
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
|
948
|
-
const result = {
|
|
949
|
-
defaultValues: control._defaultValues,
|
|
950
|
-
};
|
|
951
|
-
for (const key in formState) {
|
|
952
|
-
Object.defineProperty(result, key, {
|
|
953
|
-
get: () => {
|
|
954
|
-
const _key = key;
|
|
955
|
-
if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
|
|
956
|
-
control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
|
|
957
|
-
}
|
|
958
|
-
localProxyFormState && (localProxyFormState[_key] = true);
|
|
959
|
-
return formState[_key];
|
|
960
|
-
},
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
|
-
return result;
|
|
964
|
-
};
|
|
965
|
-
|
|
966
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
967
|
-
|
|
968
|
-
/**
|
|
969
|
-
* 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.
|
|
970
|
-
*
|
|
971
|
-
* @remarks
|
|
972
|
-
* [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
|
|
973
|
-
*
|
|
974
|
-
* @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
|
|
975
|
-
*
|
|
976
|
-
* @example
|
|
977
|
-
* ```tsx
|
|
978
|
-
* function App() {
|
|
979
|
-
* const { register, handleSubmit, control } = useForm({
|
|
980
|
-
* defaultValues: {
|
|
981
|
-
* firstName: "firstName"
|
|
982
|
-
* }});
|
|
983
|
-
* const { dirtyFields } = useFormState({
|
|
984
|
-
* control
|
|
985
|
-
* });
|
|
986
|
-
* const onSubmit = (data) => console.log(data);
|
|
987
|
-
*
|
|
988
|
-
* return (
|
|
989
|
-
* <form onSubmit={handleSubmit(onSubmit)}>
|
|
990
|
-
* <input {...register("firstName")} placeholder="First Name" />
|
|
991
|
-
* {dirtyFields.firstName && <p>Field is dirty.</p>}
|
|
992
|
-
* <input type="submit" />
|
|
993
|
-
* </form>
|
|
994
|
-
* );
|
|
995
|
-
* }
|
|
996
|
-
* ```
|
|
997
|
-
*/
|
|
998
|
-
function useFormState(props) {
|
|
999
|
-
const methods = useFormContext();
|
|
1000
|
-
const { control = methods.control, disabled, name, exact } = props || {};
|
|
1001
|
-
const [formState, updateFormState] = React.useState(control._formState);
|
|
1002
|
-
const _localProxyFormState = React.useRef({
|
|
1003
|
-
isDirty: false,
|
|
1004
|
-
isLoading: false,
|
|
1005
|
-
dirtyFields: false,
|
|
1006
|
-
touchedFields: false,
|
|
1007
|
-
validatingFields: false,
|
|
1008
|
-
isValidating: false,
|
|
1009
|
-
isValid: false,
|
|
1010
|
-
errors: false,
|
|
1011
|
-
});
|
|
1012
|
-
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
1013
|
-
name,
|
|
1014
|
-
formState: _localProxyFormState.current,
|
|
1015
|
-
exact,
|
|
1016
|
-
callback: (formState) => {
|
|
1017
|
-
!disabled &&
|
|
1018
|
-
updateFormState({
|
|
1019
|
-
...control._formState,
|
|
1020
|
-
...formState,
|
|
1021
|
-
});
|
|
1022
|
-
},
|
|
1023
|
-
}), [name, disabled, exact]);
|
|
1024
|
-
React.useEffect(() => {
|
|
1025
|
-
_localProxyFormState.current.isValid && control._setValid(true);
|
|
1026
|
-
}, [control]);
|
|
1027
|
-
return React.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
var isString = (value) => typeof value === 'string';
|
|
1031
|
-
|
|
1032
|
-
var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
|
|
1033
|
-
if (isString(names)) {
|
|
1034
|
-
isGlobal && _names.watch.add(names);
|
|
1035
|
-
return get(formValues, names, defaultValue);
|
|
1036
|
-
}
|
|
1037
|
-
if (Array.isArray(names)) {
|
|
1038
|
-
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
|
|
1039
|
-
get(formValues, fieldName)));
|
|
1040
|
-
}
|
|
1041
|
-
isGlobal && (_names.watchAll = true);
|
|
1042
|
-
return formValues;
|
|
1043
|
-
};
|
|
1044
|
-
|
|
1045
|
-
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
1046
|
-
|
|
1047
|
-
function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
1048
|
-
if (isPrimitive(object1) || isPrimitive(object2)) {
|
|
1049
|
-
return object1 === object2;
|
|
1050
|
-
}
|
|
1051
|
-
if (isDateObject(object1) && isDateObject(object2)) {
|
|
1052
|
-
return object1.getTime() === object2.getTime();
|
|
1053
|
-
}
|
|
1054
|
-
const keys1 = Object.keys(object1);
|
|
1055
|
-
const keys2 = Object.keys(object2);
|
|
1056
|
-
if (keys1.length !== keys2.length) {
|
|
1057
|
-
return false;
|
|
1058
|
-
}
|
|
1059
|
-
if (_internal_visited.has(object1) || _internal_visited.has(object2)) {
|
|
1060
|
-
return true;
|
|
1061
|
-
}
|
|
1062
|
-
_internal_visited.add(object1);
|
|
1063
|
-
_internal_visited.add(object2);
|
|
1064
|
-
for (const key of keys1) {
|
|
1065
|
-
const val1 = object1[key];
|
|
1066
|
-
if (!keys2.includes(key)) {
|
|
1067
|
-
return false;
|
|
1068
|
-
}
|
|
1069
|
-
if (key !== 'ref') {
|
|
1070
|
-
const val2 = object2[key];
|
|
1071
|
-
if ((isDateObject(val1) && isDateObject(val2)) ||
|
|
1072
|
-
(isObject(val1) && isObject(val2)) ||
|
|
1073
|
-
(Array.isArray(val1) && Array.isArray(val2))
|
|
1074
|
-
? !deepEqual(val1, val2, _internal_visited)
|
|
1075
|
-
: val1 !== val2) {
|
|
1076
|
-
return false;
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
return true;
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
/**
|
|
1084
|
-
* Custom hook to subscribe to field change and isolate re-rendering at the component level.
|
|
1085
|
-
*
|
|
1086
|
-
* @remarks
|
|
1087
|
-
*
|
|
1088
|
-
* [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
|
|
1089
|
-
*
|
|
1090
|
-
* @example
|
|
1091
|
-
* ```tsx
|
|
1092
|
-
* const { control } = useForm();
|
|
1093
|
-
* const values = useWatch({
|
|
1094
|
-
* name: "fieldName"
|
|
1095
|
-
* control,
|
|
1096
|
-
* })
|
|
1097
|
-
* ```
|
|
1098
|
-
*/
|
|
1099
|
-
function useWatch(props) {
|
|
1100
|
-
const methods = useFormContext();
|
|
1101
|
-
const { control = methods.control, name, defaultValue, disabled, exact, compute, } = props || {};
|
|
1102
|
-
const _defaultValue = React.useRef(defaultValue);
|
|
1103
|
-
const _compute = React.useRef(compute);
|
|
1104
|
-
const _computeFormValues = React.useRef(undefined);
|
|
1105
|
-
_compute.current = compute;
|
|
1106
|
-
const defaultValueMemo = React.useMemo(() => control._getWatch(name, _defaultValue.current), [control, name]);
|
|
1107
|
-
const [value, updateValue] = React.useState(_compute.current ? _compute.current(defaultValueMemo) : defaultValueMemo);
|
|
1108
|
-
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
1109
|
-
name,
|
|
1110
|
-
formState: {
|
|
1111
|
-
values: true,
|
|
1112
|
-
},
|
|
1113
|
-
exact,
|
|
1114
|
-
callback: (formState) => {
|
|
1115
|
-
if (!disabled) {
|
|
1116
|
-
const formValues = generateWatchOutput(name, control._names, formState.values || control._formValues, false, _defaultValue.current);
|
|
1117
|
-
if (_compute.current) {
|
|
1118
|
-
const computedFormValues = _compute.current(formValues);
|
|
1119
|
-
if (!deepEqual(computedFormValues, _computeFormValues.current)) {
|
|
1120
|
-
updateValue(computedFormValues);
|
|
1121
|
-
_computeFormValues.current = computedFormValues;
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
else {
|
|
1125
|
-
updateValue(formValues);
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
},
|
|
1129
|
-
}), [control, disabled, name, exact]);
|
|
1130
|
-
React.useEffect(() => control._removeUnmounted());
|
|
1131
|
-
return value;
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
/**
|
|
1135
|
-
* 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.
|
|
1136
|
-
*
|
|
1137
|
-
* @remarks
|
|
1138
|
-
* [API](https://react-hook-form.com/docs/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
|
|
1139
|
-
*
|
|
1140
|
-
* @param props - the path name to the form field value, and validation rules.
|
|
1141
|
-
*
|
|
1142
|
-
* @returns field properties, field and form state. {@link UseControllerReturn}
|
|
1143
|
-
*
|
|
1144
|
-
* @example
|
|
1145
|
-
* ```tsx
|
|
1146
|
-
* function Input(props) {
|
|
1147
|
-
* const { field, fieldState, formState } = useController(props);
|
|
1148
|
-
* return (
|
|
1149
|
-
* <div>
|
|
1150
|
-
* <input {...field} placeholder={props.name} />
|
|
1151
|
-
* <p>{fieldState.isTouched && "Touched"}</p>
|
|
1152
|
-
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
|
|
1153
|
-
* </div>
|
|
1154
|
-
* );
|
|
1155
|
-
* }
|
|
1156
|
-
* ```
|
|
1157
|
-
*/
|
|
1158
|
-
function useController(props) {
|
|
1159
|
-
const methods = useFormContext();
|
|
1160
|
-
const { name, disabled, control = methods.control, shouldUnregister, defaultValue, } = props;
|
|
1161
|
-
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
1162
|
-
const defaultValueMemo = React.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
|
|
1163
|
-
const value = useWatch({
|
|
1164
|
-
control,
|
|
1165
|
-
name,
|
|
1166
|
-
defaultValue: defaultValueMemo,
|
|
1167
|
-
exact: true,
|
|
1168
|
-
});
|
|
1169
|
-
const formState = useFormState({
|
|
1170
|
-
control,
|
|
1171
|
-
name,
|
|
1172
|
-
exact: true,
|
|
1173
|
-
});
|
|
1174
|
-
const _props = React.useRef(props);
|
|
1175
|
-
const _registerProps = React.useRef(control.register(name, {
|
|
1176
|
-
...props.rules,
|
|
1177
|
-
value,
|
|
1178
|
-
...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),
|
|
1179
|
-
}));
|
|
1180
|
-
_props.current = props;
|
|
1181
|
-
const fieldState = React.useMemo(() => Object.defineProperties({}, {
|
|
1182
|
-
invalid: {
|
|
1183
|
-
enumerable: true,
|
|
1184
|
-
get: () => !!get(formState.errors, name),
|
|
1185
|
-
},
|
|
1186
|
-
isDirty: {
|
|
1187
|
-
enumerable: true,
|
|
1188
|
-
get: () => !!get(formState.dirtyFields, name),
|
|
1189
|
-
},
|
|
1190
|
-
isTouched: {
|
|
1191
|
-
enumerable: true,
|
|
1192
|
-
get: () => !!get(formState.touchedFields, name),
|
|
1193
|
-
},
|
|
1194
|
-
isValidating: {
|
|
1195
|
-
enumerable: true,
|
|
1196
|
-
get: () => !!get(formState.validatingFields, name),
|
|
1197
|
-
},
|
|
1198
|
-
error: {
|
|
1199
|
-
enumerable: true,
|
|
1200
|
-
get: () => get(formState.errors, name),
|
|
1201
|
-
},
|
|
1202
|
-
}), [formState, name]);
|
|
1203
|
-
const onChange = React.useCallback((event) => _registerProps.current.onChange({
|
|
1204
|
-
target: {
|
|
1205
|
-
value: getEventValue(event),
|
|
1206
|
-
name: name,
|
|
1207
|
-
},
|
|
1208
|
-
type: EVENTS.CHANGE,
|
|
1209
|
-
}), [name]);
|
|
1210
|
-
const onBlur = React.useCallback(() => _registerProps.current.onBlur({
|
|
1211
|
-
target: {
|
|
1212
|
-
value: get(control._formValues, name),
|
|
1213
|
-
name: name,
|
|
1214
|
-
},
|
|
1215
|
-
type: EVENTS.BLUR,
|
|
1216
|
-
}), [name, control._formValues]);
|
|
1217
|
-
const ref = React.useCallback((elm) => {
|
|
1218
|
-
const field = get(control._fields, name);
|
|
1219
|
-
if (field && elm) {
|
|
1220
|
-
field._f.ref = {
|
|
1221
|
-
focus: () => elm.focus && elm.focus(),
|
|
1222
|
-
select: () => elm.select && elm.select(),
|
|
1223
|
-
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
1224
|
-
reportValidity: () => elm.reportValidity(),
|
|
1225
|
-
};
|
|
1226
|
-
}
|
|
1227
|
-
}, [control._fields, name]);
|
|
1228
|
-
const field = React.useMemo(() => ({
|
|
1229
|
-
name,
|
|
1230
|
-
value,
|
|
1231
|
-
...(isBoolean(disabled) || formState.disabled
|
|
1232
|
-
? { disabled: formState.disabled || disabled }
|
|
1233
|
-
: {}),
|
|
1234
|
-
onChange,
|
|
1235
|
-
onBlur,
|
|
1236
|
-
ref,
|
|
1237
|
-
}), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
|
|
1238
|
-
React.useEffect(() => {
|
|
1239
|
-
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
|
1240
|
-
control.register(name, {
|
|
1241
|
-
..._props.current.rules,
|
|
1242
|
-
...(isBoolean(_props.current.disabled)
|
|
1243
|
-
? { disabled: _props.current.disabled }
|
|
1244
|
-
: {}),
|
|
1245
|
-
});
|
|
1246
|
-
const updateMounted = (name, value) => {
|
|
1247
|
-
const field = get(control._fields, name);
|
|
1248
|
-
if (field && field._f) {
|
|
1249
|
-
field._f.mount = value;
|
|
1250
|
-
}
|
|
1251
|
-
};
|
|
1252
|
-
updateMounted(name, true);
|
|
1253
|
-
if (_shouldUnregisterField) {
|
|
1254
|
-
const value = cloneObject(get(control._options.defaultValues, name));
|
|
1255
|
-
set(control._defaultValues, name, value);
|
|
1256
|
-
if (isUndefined(get(control._formValues, name))) {
|
|
1257
|
-
set(control._formValues, name, value);
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
!isArrayField && control.register(name);
|
|
1261
|
-
return () => {
|
|
1262
|
-
(isArrayField
|
|
1263
|
-
? _shouldUnregisterField && !control._state.action
|
|
1264
|
-
: _shouldUnregisterField)
|
|
1265
|
-
? control.unregister(name)
|
|
1266
|
-
: updateMounted(name, false);
|
|
1267
|
-
};
|
|
1268
|
-
}, [name, control, isArrayField, shouldUnregister]);
|
|
1269
|
-
React.useEffect(() => {
|
|
1270
|
-
control._setDisabledField({
|
|
1271
|
-
disabled,
|
|
1272
|
-
name,
|
|
1273
|
-
});
|
|
1274
|
-
}, [disabled, name, control]);
|
|
1275
|
-
return React.useMemo(() => ({
|
|
1276
|
-
field,
|
|
1277
|
-
formState,
|
|
1278
|
-
fieldState,
|
|
1279
|
-
}), [field, formState, fieldState]);
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
/**
|
|
1283
|
-
* Component based on `useController` hook to work with controlled component.
|
|
1284
|
-
*
|
|
1285
|
-
* @remarks
|
|
1286
|
-
* [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)
|
|
1287
|
-
*
|
|
1288
|
-
* @param props - the path name to the form field value, and validation rules.
|
|
1289
|
-
*
|
|
1290
|
-
* @returns provide field handler functions, field and form state.
|
|
1291
|
-
*
|
|
1292
|
-
* @example
|
|
1293
|
-
* ```tsx
|
|
1294
|
-
* function App() {
|
|
1295
|
-
* const { control } = useForm<FormValues>({
|
|
1296
|
-
* defaultValues: {
|
|
1297
|
-
* test: ""
|
|
1298
|
-
* }
|
|
1299
|
-
* });
|
|
1300
|
-
*
|
|
1301
|
-
* return (
|
|
1302
|
-
* <form>
|
|
1303
|
-
* <Controller
|
|
1304
|
-
* control={control}
|
|
1305
|
-
* name="test"
|
|
1306
|
-
* render={({ field: { onChange, onBlur, value, ref }, formState, fieldState }) => (
|
|
1307
|
-
* <>
|
|
1308
|
-
* <input
|
|
1309
|
-
* onChange={onChange} // send value to hook form
|
|
1310
|
-
* onBlur={onBlur} // notify when input is touched
|
|
1311
|
-
* value={value} // return updated value
|
|
1312
|
-
* ref={ref} // set ref for focus management
|
|
1313
|
-
* />
|
|
1314
|
-
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
|
|
1315
|
-
* <p>{fieldState.isTouched ? "touched" : ""}</p>
|
|
1316
|
-
* </>
|
|
1317
|
-
* )}
|
|
1318
|
-
* />
|
|
1319
|
-
* </form>
|
|
1320
|
-
* );
|
|
1321
|
-
* }
|
|
1322
|
-
* ```
|
|
1323
|
-
*/
|
|
1324
|
-
const Controller = (props) => props.render(useController(props));
|
|
1325
|
-
|
|
1326
|
-
// 获取 LSM 中的IP映射列表
|
|
1327
|
-
async function get_lsm_data() {
|
|
1328
|
-
return request('/api/get_lsm_data', {
|
|
1329
|
-
method: 'GET'
|
|
1330
|
-
});
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
const useLSMLabel = function () {
|
|
1334
|
-
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1335
|
-
const [lsmList, setLsmList] = React.useState([]);
|
|
1336
|
-
const {
|
|
1337
|
-
name,
|
|
1338
|
-
label = "Label",
|
|
1339
|
-
control,
|
|
1340
|
-
onLsmSelect,
|
|
1341
|
-
fetchLsmData = get_lsm_data,
|
|
1342
|
-
formItemProps = {},
|
|
1343
|
-
selectProps = {},
|
|
1344
|
-
fieldNames = {
|
|
1345
|
-
label: 'label',
|
|
1346
|
-
value: 'label'
|
|
1347
|
-
}
|
|
1348
|
-
} = props;
|
|
1349
|
-
React.useEffect(() => {
|
|
1350
|
-
const loadLsmData = async () => {
|
|
1351
|
-
try {
|
|
1352
|
-
const res = await fetchLsmData();
|
|
1353
|
-
if (res !== null && res !== void 0 && res.length) {
|
|
1354
|
-
setLsmList(res);
|
|
1355
|
-
}
|
|
1356
|
-
} catch (error) {
|
|
1357
|
-
console.error('Failed to fetch LSM data:', error);
|
|
1358
|
-
}
|
|
1359
|
-
};
|
|
1360
|
-
loadLsmData();
|
|
1361
|
-
}, [fetchLsmData]);
|
|
1362
|
-
const renderLSMField = () => /*#__PURE__*/jsxRuntime.jsx(Controller, {
|
|
1363
|
-
name: name,
|
|
1364
|
-
control: control,
|
|
1365
|
-
render: _ref => {
|
|
1366
|
-
let {
|
|
1367
|
-
field
|
|
1368
|
-
} = _ref;
|
|
1369
|
-
return /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, _objectSpread2(_objectSpread2({
|
|
1370
|
-
label: label
|
|
1371
|
-
}, formItemProps), {}, {
|
|
1372
|
-
children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, _objectSpread2(_objectSpread2(_objectSpread2({}, field), selectProps), {}, {
|
|
1373
|
-
options: lsmList,
|
|
1374
|
-
fieldNames: fieldNames,
|
|
1375
|
-
allowClear: true,
|
|
1376
|
-
showSearch: true,
|
|
1377
|
-
optionFilterProp: "label",
|
|
1378
|
-
onChange: (value, option) => {
|
|
1379
|
-
field.onChange(value);
|
|
1380
|
-
onLsmSelect === null || onLsmSelect === void 0 || onLsmSelect(value === undefined ? undefined : option);
|
|
1381
|
-
},
|
|
1382
|
-
placeholder: selectProps.placeholder || 'Please select label'
|
|
1383
|
-
}))
|
|
1384
|
-
}));
|
|
1385
|
-
}
|
|
1386
|
-
});
|
|
1387
|
-
return renderLSMField;
|
|
1388
|
-
};
|
|
1389
|
-
|
|
1390
795
|
const NetworkFieldGroup = _ref => {
|
|
1391
796
|
var _fieldConfig$netmask$, _fieldConfig$netmask;
|
|
1392
797
|
let {
|
|
@@ -3827,7 +3232,8 @@ const SystemOperations = _ref => {
|
|
|
3827
3232
|
powerOffLabel = "Power Off",
|
|
3828
3233
|
restartLabel = "Restart",
|
|
3829
3234
|
iconClassName = "seeder-iconfont seeder-icon-guanji1 text-xl text-neutral-400",
|
|
3830
|
-
|
|
3235
|
+
confirmMessage = "Are you sure you want to {action} the system? This action cannot be undone.",
|
|
3236
|
+
confirmTitle = "Confirmation Required",
|
|
3831
3237
|
cancelText = "No",
|
|
3832
3238
|
okText = "Yes",
|
|
3833
3239
|
run
|
|
@@ -3849,9 +3255,16 @@ const SystemOperations = _ref => {
|
|
|
3849
3255
|
}];
|
|
3850
3256
|
const doAction = action => {
|
|
3851
3257
|
try {
|
|
3258
|
+
// 根据action决定显示的确认信息
|
|
3259
|
+
const actionLabels = {
|
|
3260
|
+
poweroff: "power off",
|
|
3261
|
+
restart: "restart"
|
|
3262
|
+
};
|
|
3263
|
+
const actionText = actionLabels[action] || action;
|
|
3852
3264
|
AntdModal.confirm({
|
|
3853
3265
|
icon: /*#__PURE__*/jsxRuntime.jsx(icons.ExclamationCircleFilled, {}),
|
|
3854
|
-
title:
|
|
3266
|
+
title: confirmTitle,
|
|
3267
|
+
content: confirmMessage.replace('{action}', actionText),
|
|
3855
3268
|
cancelText,
|
|
3856
3269
|
okText,
|
|
3857
3270
|
onOk: () => {
|
|
@@ -4066,6 +3479,51 @@ CommonHeader.propTypes = {
|
|
|
4066
3479
|
};
|
|
4067
3480
|
var CommonHeader$1 = CommonHeader;
|
|
4068
3481
|
|
|
3482
|
+
const LSMLabelField = props => {
|
|
3483
|
+
const [lsmList, setLsmList] = React.useState([]);
|
|
3484
|
+
const {
|
|
3485
|
+
label = "Label",
|
|
3486
|
+
onLsmSelect,
|
|
3487
|
+
fetchLsmData,
|
|
3488
|
+
formItemProps = {},
|
|
3489
|
+
selectProps = {},
|
|
3490
|
+
fieldNames = {
|
|
3491
|
+
label: 'label',
|
|
3492
|
+
value: 'label'
|
|
3493
|
+
}
|
|
3494
|
+
} = props;
|
|
3495
|
+
React.useEffect(() => {
|
|
3496
|
+
const loadLsmData = async () => {
|
|
3497
|
+
try {
|
|
3498
|
+
const res = await fetchLsmData();
|
|
3499
|
+
if (res !== null && res !== void 0 && res.length) {
|
|
3500
|
+
setLsmList(res);
|
|
3501
|
+
}
|
|
3502
|
+
} catch (error) {
|
|
3503
|
+
console.error('Failed to fetch LSM data:', error);
|
|
3504
|
+
}
|
|
3505
|
+
};
|
|
3506
|
+
loadLsmData();
|
|
3507
|
+
}, [fetchLsmData]);
|
|
3508
|
+
return /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, _objectSpread2(_objectSpread2({
|
|
3509
|
+
label: label
|
|
3510
|
+
}, formItemProps), {}, {
|
|
3511
|
+
children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, _objectSpread2(_objectSpread2(_objectSpread2({}, field), selectProps), {}, {
|
|
3512
|
+
options: lsmList,
|
|
3513
|
+
fieldNames: fieldNames,
|
|
3514
|
+
allowClear: true,
|
|
3515
|
+
showSearch: true,
|
|
3516
|
+
optionFilterProp: "label",
|
|
3517
|
+
onChange: (value, option) => {
|
|
3518
|
+
field.onChange(value);
|
|
3519
|
+
onLsmSelect === null || onLsmSelect === void 0 || onLsmSelect(value === undefined ? undefined : option);
|
|
3520
|
+
},
|
|
3521
|
+
placeholder: selectProps.placeholder || 'Please select label'
|
|
3522
|
+
}))
|
|
3523
|
+
}));
|
|
3524
|
+
};
|
|
3525
|
+
var LSMLabelField$1 = /*#__PURE__*/React.memo(LSMLabelField);
|
|
3526
|
+
|
|
4069
3527
|
const _excluded = ["value", "min", "max", "className", "disablePointerLock", "modifierKeys", "decimalPlaces", "onChange", "onDragStart", "onDragEnd", "style"];
|
|
4070
3528
|
|
|
4071
3529
|
// 默认配置
|
|
@@ -4384,6 +3842,7 @@ function DraggableNumberInput(_ref2) {
|
|
|
4384
3842
|
exports.AuthorizationModal = AuthorizationModal$1;
|
|
4385
3843
|
exports.CommonHeader = CommonHeader$1;
|
|
4386
3844
|
exports.DraggableNumberInput = DraggableNumberInput;
|
|
3845
|
+
exports.LSMLabelField = LSMLabelField$1;
|
|
4387
3846
|
exports.NetworkSettingsModal = NetworkSettingsModal$1;
|
|
4388
3847
|
exports.PresetModal = PresetModal;
|
|
4389
3848
|
exports.PtpModal = PtpModal$1;
|
|
@@ -4391,7 +3850,6 @@ exports.SystemOperations = SystemOperations$1;
|
|
|
4391
3850
|
exports.UpgradeManager = UpgradeManager$1;
|
|
4392
3851
|
exports.useAuth = useAuth;
|
|
4393
3852
|
exports.useHardwareUsage = useHardwareUsage$1;
|
|
4394
|
-
exports.useLSMLabel = useLSMLabel;
|
|
4395
3853
|
exports.useSystemOperations = useSystemOperations$1;
|
|
4396
3854
|
exports.useUpgrade = useUpgrade$1;
|
|
4397
3855
|
//# sourceMappingURL=index.js.map
|