@dartech/arsenal-ui 1.4.20 → 1.4.22
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/index.js +42 -38
- package/package.json +1 -1
- package/src/lib/Forms/ControlAceEditor.d.ts +1 -0
package/index.js
CHANGED
@@ -810,6 +810,7 @@ const ControlAutocomplete = _a => {
|
|
810
810
|
};
|
811
811
|
|
812
812
|
function ControlQueryAutocomplete(_a) {
|
813
|
+
var _b;
|
813
814
|
var {
|
814
815
|
name,
|
815
816
|
label,
|
@@ -831,7 +832,7 @@ function ControlQueryAutocomplete(_a) {
|
|
831
832
|
requiredErrorText = ''
|
832
833
|
} = _a,
|
833
834
|
autocompleteProps = __rest(_a, ["name", "label", "control", "required", "searchBy", "labelKey", "multiple", "disabled", "valueKey", "sortBy", "hideErrorMessage", "disableCloseOnSelect", "textFieldProps", "onChange", "queryFunction", "validate", "itemQueryFunction", "requiredErrorText"]);
|
834
|
-
const
|
835
|
+
const _c = useController({
|
835
836
|
control,
|
836
837
|
name,
|
837
838
|
defaultValue: multiple ? [] : null,
|
@@ -840,20 +841,19 @@ function ControlQueryAutocomplete(_a) {
|
|
840
841
|
validate
|
841
842
|
}
|
842
843
|
}),
|
843
|
-
|
844
|
+
_d = _c.field,
|
844
845
|
{
|
845
846
|
ref,
|
846
847
|
onChange: setFieldValue,
|
847
848
|
value: formValue
|
848
|
-
} =
|
849
|
-
fieldProps = __rest(
|
849
|
+
} = _d,
|
850
|
+
fieldProps = __rest(_d, ["ref", "onChange", "value"]),
|
850
851
|
{
|
851
852
|
fieldState: {
|
852
853
|
error,
|
853
854
|
isDirty
|
854
855
|
}
|
855
|
-
} =
|
856
|
-
// const formValue = useWatch({ control, name, defaultValue: });
|
856
|
+
} = _c;
|
857
857
|
const {
|
858
858
|
getOptionLabel,
|
859
859
|
isOptionEqualToValue,
|
@@ -865,13 +865,25 @@ function ControlQueryAutocomplete(_a) {
|
|
865
865
|
const [open, setOpen] = useState(false);
|
866
866
|
const [inputValue, setInputValue] = useState('');
|
867
867
|
const [searchValue, setSearchValue] = useState('');
|
868
|
-
const [totalItems, setTotalItems] = useState(0);
|
869
868
|
const [page, setPage] = useState(0);
|
870
|
-
const
|
869
|
+
const {
|
870
|
+
data,
|
871
|
+
isFetching
|
872
|
+
} = useQuery(['options', page, searchValue], () => {
|
873
|
+
const params = qs.parse(Object.assign({
|
874
|
+
page: `${page}`,
|
875
|
+
size: '20',
|
876
|
+
sort: sortBy
|
877
|
+
}, searchValue ? {
|
878
|
+
[searchBy]: searchValue
|
879
|
+
} : {}), {
|
880
|
+
ignoreQueryPrefix: true
|
881
|
+
});
|
882
|
+
return queryFunction(params);
|
883
|
+
});
|
871
884
|
const debouncedChange = useDebounce(val => {
|
872
885
|
setPage(0);
|
873
886
|
setSearchValue(val);
|
874
|
-
setOptions([]);
|
875
887
|
}, 500);
|
876
888
|
const handleInputChange = useCallback((_, value) => {
|
877
889
|
setInputValue(value);
|
@@ -897,10 +909,10 @@ function ControlQueryAutocomplete(_a) {
|
|
897
909
|
}, [formValue, isDirty, valueKey, labelKey, itemQueryFunction, setFieldValue]);
|
898
910
|
const handleOnScroll = useCallback(event => {
|
899
911
|
const listboxNode = event.currentTarget;
|
900
|
-
if (listboxNode.scrollHeight - listboxNode.scrollTop - listboxNode.clientHeight <= 1 &&
|
912
|
+
if (listboxNode.scrollHeight - listboxNode.scrollTop - listboxNode.clientHeight <= 1 && (data === null || data === void 0 ? void 0 : data.collection.length) < (data === null || data === void 0 ? void 0 : data.totalItems)) {
|
901
913
|
setPage(page => page + 1);
|
902
914
|
}
|
903
|
-
}, [
|
915
|
+
}, [data]);
|
904
916
|
const handleOpen = () => {
|
905
917
|
setOpen(true);
|
906
918
|
};
|
@@ -908,33 +920,12 @@ function ControlQueryAutocomplete(_a) {
|
|
908
920
|
setOpen(false);
|
909
921
|
setSearchValue('');
|
910
922
|
};
|
911
|
-
const {
|
912
|
-
data,
|
913
|
-
isFetching
|
914
|
-
} = useQuery(['options', page, searchValue], () => {
|
915
|
-
const params = qs.parse(Object.assign({
|
916
|
-
page: `${page}`,
|
917
|
-
size: '20',
|
918
|
-
sort: sortBy
|
919
|
-
}, searchValue ? {
|
920
|
-
[searchBy]: searchValue
|
921
|
-
} : {}), {
|
922
|
-
ignoreQueryPrefix: true
|
923
|
-
});
|
924
|
-
return queryFunction(params);
|
925
|
-
});
|
926
|
-
useEffect(() => {
|
927
|
-
if (data) {
|
928
|
-
setOptions(prevOptions => [...prevOptions, ...data.collection]);
|
929
|
-
setTotalItems(data.totalItems);
|
930
|
-
}
|
931
|
-
}, [data]);
|
932
923
|
return jsx(Autocomplete, Object.assign({}, fieldProps, {
|
933
924
|
fullWidth: true,
|
934
925
|
disablePortal: true,
|
935
926
|
size: "small",
|
936
927
|
readOnly: disabled,
|
937
|
-
options:
|
928
|
+
options: (_b = data === null || data === void 0 ? void 0 : data.collection) !== null && _b !== void 0 ? _b : [],
|
938
929
|
multiple: multiple,
|
939
930
|
getOptionLabel: getOptionLabel,
|
940
931
|
isOptionEqualToValue: isOptionEqualToValue,
|
@@ -1066,9 +1057,10 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
|
|
1066
1057
|
fontSize = 16,
|
1067
1058
|
validate = true,
|
1068
1059
|
parseValue,
|
1069
|
-
requiredErrorText = ''
|
1060
|
+
requiredErrorText = '',
|
1061
|
+
useCleanValue
|
1070
1062
|
} = _a,
|
1071
|
-
otherProps = __rest(_a, ["control", "name", "mode", "label", "width", "height", "readOnly", "required", "validateJson", "hideErrorMessage", "fontSize", "validate", "parseValue", "requiredErrorText"]);
|
1063
|
+
otherProps = __rest(_a, ["control", "name", "mode", "label", "width", "height", "readOnly", "required", "validateJson", "hideErrorMessage", "fontSize", "validate", "parseValue", "requiredErrorText", "useCleanValue"]);
|
1072
1064
|
const _b = useController({
|
1073
1065
|
control,
|
1074
1066
|
name,
|
@@ -1106,6 +1098,16 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
|
|
1106
1098
|
javascript: [langs.javascript()],
|
1107
1099
|
python: [langs.python()]
|
1108
1100
|
}), []);
|
1101
|
+
const safeValue = useMemo(() => {
|
1102
|
+
if (mode === 'json' && typeof value !== 'string') {
|
1103
|
+
if (value === null) return '';
|
1104
|
+
return useCleanValue ? JSON.stringify(value, null, 2).replace(/\\"/g, '') : JSON.stringify(value, null, 2);
|
1105
|
+
}
|
1106
|
+
if (typeof value === 'string') {
|
1107
|
+
return useCleanValue ? value.replace(/\\"/g, '') : value;
|
1108
|
+
}
|
1109
|
+
return value;
|
1110
|
+
}, [value, useCleanValue, mode]);
|
1109
1111
|
const handleChange = useCallback(value => {
|
1110
1112
|
if (parseValue) {
|
1111
1113
|
try {
|
@@ -1157,7 +1159,7 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
|
|
1157
1159
|
isolation: 'isolate'
|
1158
1160
|
},
|
1159
1161
|
readOnly: readOnly,
|
1160
|
-
value:
|
1162
|
+
value: safeValue,
|
1161
1163
|
onChange: handleChange,
|
1162
1164
|
extensions: extensions[mode]
|
1163
1165
|
}, otherProps)), error && !hideErrorMessage && jsx(FormHelperText, Object.assign({
|
@@ -6035,7 +6037,8 @@ const PropertyFiller = ({
|
|
6035
6037
|
control: control,
|
6036
6038
|
label: valueLabel,
|
6037
6039
|
parseValue: true,
|
6038
|
-
hideErrorMessage: true
|
6040
|
+
hideErrorMessage: true,
|
6041
|
+
useCleanValue: true
|
6039
6042
|
}) : jsx(ControlInput, {
|
6040
6043
|
control: control,
|
6041
6044
|
name: name,
|
@@ -6294,7 +6297,8 @@ const MultiplePropertyFiller = ({
|
|
6294
6297
|
control: control,
|
6295
6298
|
label: valueLabel,
|
6296
6299
|
parseValue: true,
|
6297
|
-
hideErrorMessage: true
|
6300
|
+
hideErrorMessage: true,
|
6301
|
+
useCleanValue: true
|
6298
6302
|
}) : jsx(ControlInput, {
|
6299
6303
|
required: true,
|
6300
6304
|
hideErrorMessage: true,
|
package/package.json
CHANGED
@@ -17,6 +17,7 @@ export interface ControlAceEditorProps {
|
|
17
17
|
parseValue?: boolean;
|
18
18
|
requiredErrorText?: string;
|
19
19
|
[key: string]: unknown;
|
20
|
+
useCleanValue?: boolean;
|
20
21
|
}
|
21
22
|
export declare const ControlAceEditor: import("react").ForwardRefExoticComponent<Omit<ControlAceEditorProps, "ref"> & import("react").RefAttributes<ReactCodeMirrorRef>>;
|
22
23
|
export default ControlAceEditor;
|