@ssa-ui-kit/core 2.16.4-canary-4606151-20250507 → 2.17.0
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/components/Typeahead/Typeahead.context.d.ts +12 -12
- package/dist/components/Typeahead/Typeahead.d.ts +1 -1
- package/dist/components/Typeahead/types.d.ts +5 -4
- package/dist/components/Typeahead/useTypeahead.d.ts +16 -15
- package/dist/index.js +259 -270
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -14027,7 +14027,8 @@ const Calendar_DatePickerCalendar = () => {
|
|
|
14027
14027
|
paddingTop: 16,
|
|
14028
14028
|
width: 346,
|
|
14029
14029
|
height: 370,
|
|
14030
|
-
alignItems: 'flex-start'
|
|
14030
|
+
alignItems: 'flex-start',
|
|
14031
|
+
margin: '14px 0 0 -14px'
|
|
14031
14032
|
}, true ? "" : 0, true ? "" : 0),
|
|
14032
14033
|
children: [(0,jsx_runtime_namespaceObject.jsx)(Header_Header, {}), (0,jsx_runtime_namespaceObject.jsx)(PopoverDescription, {
|
|
14033
14034
|
as: "div",
|
|
@@ -17799,6 +17800,7 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
|
|
|
17799
17800
|
options: [],
|
|
17800
17801
|
placeholder: '',
|
|
17801
17802
|
useFormResult: {},
|
|
17803
|
+
error: undefined,
|
|
17802
17804
|
setValue: () => {
|
|
17803
17805
|
/* no-op */
|
|
17804
17806
|
},
|
|
@@ -17806,7 +17808,7 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
|
|
|
17806
17808
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
17807
17809
|
return {};
|
|
17808
17810
|
},
|
|
17809
|
-
|
|
17811
|
+
onChange: () => {
|
|
17810
17812
|
/* no-op */
|
|
17811
17813
|
},
|
|
17812
17814
|
handleClearAll: () => {
|
|
@@ -17826,9 +17828,6 @@ const TypeaheadContext = /*#__PURE__*/external_react_namespaceObject.createConte
|
|
|
17826
17828
|
},
|
|
17827
17829
|
handleRemoveSelectedClick: () => () => {
|
|
17828
17830
|
/* no-op */
|
|
17829
|
-
},
|
|
17830
|
-
handleSelectedClick: () => {
|
|
17831
|
-
/* no-op */
|
|
17832
17831
|
}
|
|
17833
17832
|
});
|
|
17834
17833
|
const useTypeaheadContext = () => external_react_namespaceObject.useContext(TypeaheadContext);
|
|
@@ -17836,10 +17835,18 @@ const useTypeaheadContext = () => external_react_namespaceObject.useContext(Type
|
|
|
17836
17835
|
|
|
17837
17836
|
|
|
17838
17837
|
|
|
17838
|
+
const findExactMatch = (input, options) => {
|
|
17839
|
+
const normalizedInput = input.toLowerCase();
|
|
17840
|
+
return Object.values(options).find(opt => {
|
|
17841
|
+
const labelText = (opt.label ?? opt.value).toString().toLowerCase();
|
|
17842
|
+
return labelText === normalizedInput;
|
|
17843
|
+
});
|
|
17844
|
+
};
|
|
17839
17845
|
const useTypeahead = ({
|
|
17840
17846
|
name = 'typeahead-input',
|
|
17841
17847
|
isOpen: isInitOpen,
|
|
17842
|
-
selectedItems,
|
|
17848
|
+
selectedItems: providedSelectedItems,
|
|
17849
|
+
defaultSelectedItems,
|
|
17843
17850
|
isDisabled,
|
|
17844
17851
|
isMultiple,
|
|
17845
17852
|
children,
|
|
@@ -17852,8 +17859,8 @@ const useTypeahead = ({
|
|
|
17852
17859
|
error,
|
|
17853
17860
|
success,
|
|
17854
17861
|
placeholder,
|
|
17855
|
-
|
|
17856
|
-
|
|
17862
|
+
filterOptions = true,
|
|
17863
|
+
autoSelect = true,
|
|
17857
17864
|
onChange,
|
|
17858
17865
|
onClearAll,
|
|
17859
17866
|
onRemoveSelectedClick,
|
|
@@ -17861,271 +17868,263 @@ const useTypeahead = ({
|
|
|
17861
17868
|
renderOption
|
|
17862
17869
|
}) => {
|
|
17863
17870
|
const inputName = `${name}-text`;
|
|
17864
|
-
const
|
|
17865
|
-
const
|
|
17866
|
-
const
|
|
17867
|
-
|
|
17868
|
-
|
|
17869
|
-
|
|
17870
|
-
|
|
17871
|
-
const
|
|
17872
|
-
const
|
|
17873
|
-
|
|
17874
|
-
|
|
17875
|
-
const triggerRef = (0,external_react_namespaceObject.useRef)(null);
|
|
17876
|
-
const useFormResult = (0,external_react_hook_form_namespaceObject.useForm)();
|
|
17877
|
-
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17878
|
-
if (!register) {
|
|
17879
|
-
console.warn('Typeahead component must be used within a Form component');
|
|
17880
|
-
}
|
|
17881
|
-
}, []);
|
|
17882
|
-
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17883
|
-
if (isMultiple) {
|
|
17884
|
-
setValue?.(name, selected, {
|
|
17885
|
-
shouldDirty: !isFirstRender
|
|
17886
|
-
});
|
|
17887
|
-
setInputValue('');
|
|
17888
|
-
setFirstSuggestion('');
|
|
17889
|
-
} else {
|
|
17890
|
-
setValue?.(name, selected.length ? selected[0] : [], {
|
|
17891
|
-
shouldDirty: !isFirstRender
|
|
17892
|
-
});
|
|
17871
|
+
const defaultForm = (0,external_react_hook_form_namespaceObject.useForm)();
|
|
17872
|
+
const form = (0,external_react_hook_form_namespaceObject.useFormContext)() ?? defaultForm;
|
|
17873
|
+
const {
|
|
17874
|
+
register,
|
|
17875
|
+
setValue,
|
|
17876
|
+
watch
|
|
17877
|
+
} = form;
|
|
17878
|
+
const formFieldValue = watch(name);
|
|
17879
|
+
const controlledValue = (() => {
|
|
17880
|
+
if (providedSelectedItems) {
|
|
17881
|
+
return providedSelectedItems;
|
|
17893
17882
|
}
|
|
17894
|
-
|
|
17895
|
-
|
|
17896
|
-
|
|
17897
|
-
if (isDisabled && isOpen) {
|
|
17898
|
-
setIsOpen(false);
|
|
17883
|
+
// controlledValue should be undefined if defaultSelectedItems is provided
|
|
17884
|
+
if (defaultSelectedItems) {
|
|
17885
|
+
return;
|
|
17899
17886
|
}
|
|
17900
|
-
|
|
17901
|
-
|
|
17902
|
-
const status = success ? 'success' : useFormResult.formState.errors[name] ? 'error' : 'basic';
|
|
17903
|
-
setStatus(status);
|
|
17904
|
-
}, [useFormResult.formState.errors[name], success]);
|
|
17905
|
-
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17906
|
-
if (error) {
|
|
17907
|
-
useFormResult.setError(name, error);
|
|
17908
|
-
} else {
|
|
17909
|
-
setStatus('basic');
|
|
17910
|
-
useFormResult.resetField(name);
|
|
17887
|
+
if (isMultiple) {
|
|
17888
|
+
return Array.isArray(formFieldValue) ? formFieldValue : [];
|
|
17911
17889
|
}
|
|
17912
|
-
|
|
17913
|
-
|
|
17914
|
-
|
|
17915
|
-
|
|
17890
|
+
return ['number', 'string'].includes(typeof formFieldValue) ? [formFieldValue] : [];
|
|
17891
|
+
})();
|
|
17892
|
+
const [isOpen, _setIsOpen] = (0,hooks_namespaceObject.useUncontrolled)({
|
|
17893
|
+
defaultValue: isInitOpen,
|
|
17894
|
+
finalValue: false
|
|
17895
|
+
});
|
|
17896
|
+
const [selectedItems, setSelected] = (0,hooks_namespaceObject.useUncontrolled)({
|
|
17897
|
+
value: controlledValue,
|
|
17898
|
+
defaultValue: defaultSelectedItems,
|
|
17899
|
+
finalValue: []
|
|
17900
|
+
});
|
|
17901
|
+
const [rawInput, setRawInput] = (0,external_react_namespaceObject.useState)(null);
|
|
17902
|
+
const {
|
|
17903
|
+
ref: inputRef
|
|
17904
|
+
} = (0,hooks_namespaceObject.useElementSize)();
|
|
17905
|
+
const triggerRef = (0,external_react_namespaceObject.useRef)(null);
|
|
17906
|
+
(0,external_react_hook_form_namespaceObject.useController)({
|
|
17907
|
+
control: form.control,
|
|
17908
|
+
name,
|
|
17909
|
+
rules: validationSchema,
|
|
17910
|
+
defaultValue: isMultiple ? selectedItems : selectedItems[0]
|
|
17911
|
+
});
|
|
17912
|
+
const typeaheadId = (0,external_react_namespaceObject.useId)();
|
|
17913
|
+
const optionsWithKey = (0,external_react_namespaceObject.useMemo)(() => {
|
|
17914
|
+
const opts = {};
|
|
17915
|
+
external_react_default().Children.forEach(children, child => {
|
|
17916
|
+
if (/*#__PURE__*/external_react_default().isValidElement(child)) {
|
|
17917
|
+
opts[child.props.value] = child.props;
|
|
17918
|
+
}
|
|
17916
17919
|
});
|
|
17920
|
+
return opts;
|
|
17917
17921
|
}, [children]);
|
|
17918
17922
|
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17919
|
-
|
|
17920
|
-
if (selectedItems
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
|
|
17924
|
-
|
|
17925
|
-
|
|
17926
|
-
|
|
17927
|
-
|
|
17928
|
-
setFirstSuggestion('');
|
|
17923
|
+
const validSelected = selectedItems.filter(item => optionsWithKey[item]);
|
|
17924
|
+
if (validSelected.length !== selectedItems.length) {
|
|
17925
|
+
setSelected(validSelected);
|
|
17926
|
+
const fieldValue = isMultiple ? validSelected : undefined;
|
|
17927
|
+
setValue?.(name, fieldValue);
|
|
17928
|
+
setRawInput(null);
|
|
17929
|
+
form.clearErrors(name);
|
|
17930
|
+
form.trigger(name);
|
|
17931
|
+
onEmptyChange?.(validSelected.length === 0);
|
|
17929
17932
|
}
|
|
17930
|
-
|
|
17931
|
-
|
|
17933
|
+
}, [optionsWithKey, selectedItems]);
|
|
17934
|
+
const inputValue = (0,external_react_namespaceObject.useMemo)(() => {
|
|
17935
|
+
if (isMultiple) return rawInput ?? '';
|
|
17936
|
+
if (rawInput != null) return rawInput;
|
|
17937
|
+
return selectedItems.length === 1 ? optionsWithKey[selectedItems[0]]?.label?.toString() || '' : '';
|
|
17938
|
+
}, [isMultiple, rawInput, selectedItems, optionsWithKey]);
|
|
17939
|
+
const filteredChildren = (0,external_react_namespaceObject.useMemo)(() => {
|
|
17940
|
+
// if filtering is disabled, or there's no input, show all
|
|
17941
|
+
if (!filterOptions || !inputValue) return external_react_default().Children.toArray(children);
|
|
17942
|
+
const needle = inputValue.toLowerCase();
|
|
17943
|
+
return external_react_default().Children.toArray(children).filter(child => {
|
|
17944
|
+
if (! /*#__PURE__*/external_react_default().isValidElement(child)) return false;
|
|
17945
|
+
const {
|
|
17946
|
+
label,
|
|
17947
|
+
value
|
|
17948
|
+
} = child.props;
|
|
17949
|
+
const text = (label ?? value)?.toString().toLowerCase() || '';
|
|
17950
|
+
return text.includes(needle);
|
|
17932
17951
|
});
|
|
17933
|
-
}, [
|
|
17934
|
-
(0,external_react_namespaceObject.
|
|
17935
|
-
|
|
17936
|
-
|
|
17937
|
-
|
|
17952
|
+
}, [children, inputValue]);
|
|
17953
|
+
const items = (0,external_react_namespaceObject.useMemo)(() => {
|
|
17954
|
+
return filteredChildren.map((child, index) => {
|
|
17955
|
+
if (! /*#__PURE__*/external_react_default().isValidElement(child)) return null;
|
|
17956
|
+
const isActive = selectedItems.includes(child.props.value);
|
|
17938
17957
|
const {
|
|
17939
|
-
id,
|
|
17940
17958
|
value,
|
|
17941
17959
|
label,
|
|
17960
|
+
id,
|
|
17942
17961
|
isDisabled
|
|
17943
17962
|
} = child.props;
|
|
17944
|
-
const isActive = selected.includes(child.props.value);
|
|
17945
17963
|
return /*#__PURE__*/external_react_default().cloneElement(child, {
|
|
17946
|
-
index,
|
|
17947
17964
|
...child.props,
|
|
17965
|
+
index,
|
|
17948
17966
|
isActive,
|
|
17949
17967
|
isDisabled,
|
|
17950
|
-
|
|
17968
|
+
role: 'option',
|
|
17951
17969
|
'aria-selected': isActive,
|
|
17952
17970
|
'aria-labelledby': `typeahead-label-${name}`,
|
|
17953
|
-
|
|
17954
|
-
|
|
17955
|
-
event.preventDefault();
|
|
17971
|
+
onClick: e => {
|
|
17972
|
+
e.preventDefault();
|
|
17956
17973
|
if (!isDisabled) {
|
|
17957
|
-
|
|
17974
|
+
const shouldClose = !isMultiple;
|
|
17975
|
+
handleChange({
|
|
17976
|
+
value,
|
|
17977
|
+
shouldClose
|
|
17978
|
+
});
|
|
17958
17979
|
}
|
|
17959
17980
|
},
|
|
17960
|
-
children: renderOption
|
|
17981
|
+
children: renderOption?.({
|
|
17961
17982
|
value: id || value,
|
|
17962
|
-
input: inputValue
|
|
17983
|
+
input: inputValue,
|
|
17963
17984
|
label
|
|
17964
|
-
})
|
|
17985
|
+
}) ?? child.props.children ?? label ?? value
|
|
17965
17986
|
});
|
|
17966
17987
|
});
|
|
17967
|
-
|
|
17968
|
-
|
|
17969
|
-
|
|
17970
|
-
|
|
17971
|
-
|
|
17972
|
-
if (!
|
|
17973
|
-
|
|
17974
|
-
|
|
17975
|
-
|
|
17976
|
-
setSelected([foundItem.value]);
|
|
17988
|
+
}, [children, selectedItems, inputValue]);
|
|
17989
|
+
const firstSuggestion = (0,external_react_namespaceObject.useMemo)(() => {
|
|
17990
|
+
if (!inputValue) return '';
|
|
17991
|
+
const needle = inputValue.toLowerCase();
|
|
17992
|
+
for (const child of filteredChildren) {
|
|
17993
|
+
if (! /*#__PURE__*/external_react_default().isValidElement(child)) continue;
|
|
17994
|
+
const labelText = (child.props.label ?? child.props.value).toString();
|
|
17995
|
+
if (labelText.toLowerCase().startsWith(needle)) {
|
|
17996
|
+
return inputValue + labelText.slice(inputValue.length);
|
|
17977
17997
|
}
|
|
17978
17998
|
}
|
|
17979
|
-
|
|
17980
|
-
|
|
17981
|
-
|
|
17982
|
-
|
|
17983
|
-
|
|
17984
|
-
});
|
|
17985
|
-
}, [selected]);
|
|
17986
|
-
(0,external_react_namespaceObject.useEffect)(() => {
|
|
17987
|
-
if (inputValue) {
|
|
17988
|
-
const newFirstSuggestion = Object.values(optionsWithKey)?.find(item => {
|
|
17989
|
-
const label = (0,utils_namespaceObject.propOr)('', 'label')(item);
|
|
17990
|
-
return label.toLowerCase().startsWith(inputValue.toLowerCase());
|
|
17991
|
-
});
|
|
17992
|
-
const firstSuggestionLabel = (0,utils_namespaceObject.propOr)('', 'label')(newFirstSuggestion);
|
|
17993
|
-
const humanSuggestionLabel = inputValue.concat(firstSuggestionLabel.slice(inputValue.length));
|
|
17994
|
-
setFirstSuggestion(humanSuggestionLabel);
|
|
17995
|
-
} else {
|
|
17996
|
-
setFirstSuggestion('');
|
|
17997
|
-
if (isMultiple) {
|
|
17998
|
-
setInputValue('');
|
|
17999
|
-
}
|
|
18000
|
-
}
|
|
18001
|
-
}, [inputValue, items, selected]);
|
|
18002
|
-
const processSingleSelected = ({
|
|
18003
|
-
optionsWithKeyLocal = {},
|
|
18004
|
-
selectedLocal = []
|
|
18005
|
-
}) => {
|
|
18006
|
-
if (!isMultiple && selectedLocal.length && Object.keys(optionsWithKeyLocal).length) {
|
|
18007
|
-
const currentOption = optionsWithKeyLocal[selectedLocal[0]];
|
|
18008
|
-
const optionText = currentOption && (currentOption.children || currentOption.label || currentOption.value);
|
|
18009
|
-
setInputValue(`${optionText}`);
|
|
17999
|
+
return '';
|
|
18000
|
+
}, [inputValue, filteredChildren]);
|
|
18001
|
+
const setIsOpen = open => {
|
|
18002
|
+
if (!open) {
|
|
18003
|
+
form.trigger(name);
|
|
18010
18004
|
}
|
|
18005
|
+
_setIsOpen(open);
|
|
18011
18006
|
};
|
|
18012
|
-
const
|
|
18013
|
-
|
|
18007
|
+
const handleChange = ({
|
|
18008
|
+
value,
|
|
18009
|
+
shouldClose = true,
|
|
18010
|
+
resetInput = true
|
|
18014
18011
|
}) => {
|
|
18015
|
-
|
|
18016
|
-
const
|
|
18017
|
-
|
|
18018
|
-
|
|
18019
|
-
|
|
18020
|
-
|
|
18021
|
-
|
|
18022
|
-
|
|
18023
|
-
|
|
18024
|
-
|
|
18025
|
-
setOptionsWithKey(keyedOptions);
|
|
18026
|
-
setItems(childItems);
|
|
18027
|
-
processSingleSelected({
|
|
18028
|
-
optionsWithKeyLocal: keyedOptions,
|
|
18029
|
-
selectedLocal
|
|
18030
|
-
});
|
|
18031
|
-
setFirstRender(false);
|
|
18032
|
-
};
|
|
18033
|
-
const handleOnEmptyChange = newIsEmptyValue => {
|
|
18034
|
-
if (newIsEmptyValue !== isEmpty) {
|
|
18035
|
-
setIsEmpty(newIsEmptyValue);
|
|
18036
|
-
onEmptyChange?.(newIsEmptyValue);
|
|
18012
|
+
if (isDisabled || value == null) return;
|
|
18013
|
+
const alreadySelected = selectedItems.includes(value);
|
|
18014
|
+
const updatedSelected = isMultiple ? alreadySelected ? selectedItems.filter(item => item !== value) : [...selectedItems, value] : alreadySelected ? [] : [value];
|
|
18015
|
+
const fieldValue = isMultiple ? updatedSelected : updatedSelected[0];
|
|
18016
|
+
setSelected(updatedSelected);
|
|
18017
|
+
setValue?.(name, fieldValue);
|
|
18018
|
+
form.clearErrors(name);
|
|
18019
|
+
if (resetInput) {
|
|
18020
|
+
const rawInputValue = isMultiple ? null : updatedSelected.length ? String(optionsWithKey[value]?.label) : null;
|
|
18021
|
+
setRawInput(rawInputValue);
|
|
18037
18022
|
}
|
|
18038
|
-
|
|
18039
|
-
|
|
18040
|
-
if (!isDisabled) {
|
|
18041
|
-
setIsOpen(open);
|
|
18023
|
+
if (shouldClose) {
|
|
18024
|
+
setIsOpen(false);
|
|
18042
18025
|
}
|
|
18026
|
+
onChange?.(value, !alreadySelected);
|
|
18027
|
+
onEmptyChange?.(updatedSelected.length === 0);
|
|
18043
18028
|
};
|
|
18044
|
-
const
|
|
18045
|
-
if (isDisabled
|
|
18046
|
-
|
|
18047
|
-
|
|
18048
|
-
|
|
18049
|
-
|
|
18050
|
-
if (isMultiple) {
|
|
18051
|
-
setSelected(currentSelected => isChangingItemSelected ? currentSelected.filter(current => current !== changingValue) : [...currentSelected, changingValue]);
|
|
18052
|
-
setInputValue('');
|
|
18053
|
-
} else {
|
|
18054
|
-
if (selected[0] === changingValue) {
|
|
18055
|
-
setSelected([]);
|
|
18056
|
-
setInputValue('');
|
|
18057
|
-
} else {
|
|
18058
|
-
setSelected([changingValue]);
|
|
18059
|
-
}
|
|
18060
|
-
}
|
|
18029
|
+
const handleClearAll = e => {
|
|
18030
|
+
if (isDisabled) return;
|
|
18031
|
+
e.preventDefault();
|
|
18032
|
+
e.stopPropagation();
|
|
18033
|
+
setSelected([]);
|
|
18034
|
+
setRawInput(null);
|
|
18061
18035
|
setIsOpen(false);
|
|
18062
|
-
|
|
18036
|
+
setValue?.(name, undefined);
|
|
18037
|
+
form.trigger(name);
|
|
18063
18038
|
inputRef.current?.focus();
|
|
18064
|
-
|
|
18065
|
-
|
|
18066
|
-
useFormResult.trigger(name);
|
|
18067
|
-
onChange?.(changingValue, isNewSelected);
|
|
18039
|
+
onClearAll?.();
|
|
18040
|
+
onEmptyChange?.(true);
|
|
18068
18041
|
};
|
|
18069
|
-
const
|
|
18070
|
-
|
|
18042
|
+
const handleInputChange = e => {
|
|
18043
|
+
const input = e.target.value;
|
|
18044
|
+
setRawInput(input);
|
|
18045
|
+
if (!autoSelect || !filterOptions) return;
|
|
18046
|
+
const match = findExactMatch(input, optionsWithKey);
|
|
18047
|
+
if (match) {
|
|
18048
|
+
handleChange({
|
|
18049
|
+
value: match.value,
|
|
18050
|
+
shouldClose: false
|
|
18051
|
+
});
|
|
18071
18052
|
return;
|
|
18072
18053
|
}
|
|
18073
|
-
|
|
18074
|
-
|
|
18075
|
-
|
|
18076
|
-
|
|
18077
|
-
|
|
18078
|
-
|
|
18079
|
-
|
|
18080
|
-
|
|
18081
|
-
onClearAll?.();
|
|
18054
|
+
// unset selected value if not fully matched
|
|
18055
|
+
if (!isMultiple && selectedItems.length > 0) {
|
|
18056
|
+
handleChange({
|
|
18057
|
+
value: selectedItems[0],
|
|
18058
|
+
shouldClose: false,
|
|
18059
|
+
resetInput: false
|
|
18060
|
+
});
|
|
18061
|
+
}
|
|
18082
18062
|
};
|
|
18083
|
-
const handleInputClick =
|
|
18063
|
+
const handleInputClick = e => {
|
|
18064
|
+
e.stopPropagation();
|
|
18065
|
+
e.preventDefault();
|
|
18084
18066
|
if (!isDisabled) {
|
|
18085
18067
|
inputRef.current?.focus();
|
|
18086
18068
|
setIsOpen(true);
|
|
18087
18069
|
}
|
|
18088
|
-
event.stopPropagation();
|
|
18089
|
-
event.preventDefault();
|
|
18090
18070
|
};
|
|
18091
|
-
const handleInputKeyDown =
|
|
18092
|
-
|
|
18093
|
-
|
|
18094
|
-
|
|
18095
|
-
|
|
18096
|
-
|
|
18097
|
-
|
|
18098
|
-
|
|
18099
|
-
handleChange(foundItem?.value);
|
|
18100
|
-
if (foundItem) {
|
|
18101
|
-
setInputValue(`${foundItem?.label}`);
|
|
18071
|
+
const handleInputKeyDown = e => {
|
|
18072
|
+
const isEnterOrTab = ['Enter', 'Tab'].includes(e.code);
|
|
18073
|
+
if (isEnterOrTab && firstSuggestion && firstSuggestion !== inputValue) {
|
|
18074
|
+
const match = findExactMatch(firstSuggestion, optionsWithKey);
|
|
18075
|
+
if (match) {
|
|
18076
|
+
handleChange({
|
|
18077
|
+
value: match.value
|
|
18078
|
+
});
|
|
18102
18079
|
}
|
|
18103
|
-
|
|
18104
|
-
return
|
|
18105
|
-
}
|
|
18106
|
-
|
|
18107
|
-
|
|
18108
|
-
|
|
18109
|
-
|
|
18080
|
+
e.preventDefault();
|
|
18081
|
+
return;
|
|
18082
|
+
}
|
|
18083
|
+
if (isMultiple && e.code === 'Backspace' && selectedItems.length && !inputValue) {
|
|
18084
|
+
const lastSelected = selectedItems[selectedItems.length - 1];
|
|
18085
|
+
handleChange({
|
|
18086
|
+
value: lastSelected,
|
|
18087
|
+
shouldClose: false
|
|
18088
|
+
});
|
|
18089
|
+
e.preventDefault();
|
|
18090
|
+
return;
|
|
18091
|
+
}
|
|
18092
|
+
if (!isOpen && firstSuggestion !== inputValue) {
|
|
18110
18093
|
setIsOpen(true);
|
|
18111
18094
|
}
|
|
18112
18095
|
};
|
|
18113
|
-
const
|
|
18114
|
-
|
|
18115
|
-
|
|
18116
|
-
|
|
18117
|
-
|
|
18096
|
+
const handleRemoveSelectedClick = value => e => {
|
|
18097
|
+
e.stopPropagation();
|
|
18098
|
+
handleChange({
|
|
18099
|
+
value
|
|
18100
|
+
});
|
|
18101
|
+
onRemoveSelectedClick?.(value);
|
|
18102
|
+
form.trigger(name);
|
|
18118
18103
|
};
|
|
18119
|
-
const
|
|
18120
|
-
|
|
18121
|
-
|
|
18122
|
-
|
|
18104
|
+
const handleOpenChange = (open, event, reason) => {
|
|
18105
|
+
if (isDisabled || reason === 'reference-press') {
|
|
18106
|
+
return;
|
|
18107
|
+
}
|
|
18108
|
+
setIsOpen(open);
|
|
18109
|
+
if (!isMultiple && selectedItems.length > 0) {
|
|
18110
|
+
const selectedValue = selectedItems[0];
|
|
18111
|
+
const label = optionsWithKey[selectedValue]?.label;
|
|
18112
|
+
setRawInput(label ? String(label) : null);
|
|
18113
|
+
return;
|
|
18114
|
+
}
|
|
18115
|
+
setRawInput(null);
|
|
18123
18116
|
};
|
|
18117
|
+
const status = (() => {
|
|
18118
|
+
if (form.formState.errors[name]) return 'error';
|
|
18119
|
+
if (error) return 'error';
|
|
18120
|
+
if (success) return 'success';
|
|
18121
|
+
return 'basic';
|
|
18122
|
+
})();
|
|
18124
18123
|
return {
|
|
18125
18124
|
isOpen,
|
|
18126
18125
|
isDisabled,
|
|
18127
18126
|
optionsWithKey,
|
|
18128
|
-
selectedItems
|
|
18127
|
+
selectedItems,
|
|
18129
18128
|
inputRef,
|
|
18130
18129
|
firstSuggestion,
|
|
18131
18130
|
isMultiple,
|
|
@@ -18141,18 +18140,18 @@ const useTypeahead = ({
|
|
|
18141
18140
|
inputValue,
|
|
18142
18141
|
validationSchema,
|
|
18143
18142
|
status,
|
|
18143
|
+
error: error ?? form.formState.errors[name],
|
|
18144
18144
|
placeholder,
|
|
18145
18145
|
options: items,
|
|
18146
|
-
useFormResult,
|
|
18146
|
+
useFormResult: form,
|
|
18147
18147
|
register,
|
|
18148
18148
|
setValue,
|
|
18149
|
-
|
|
18149
|
+
onChange,
|
|
18150
18150
|
handleClearAll,
|
|
18151
18151
|
handleOpenChange,
|
|
18152
18152
|
handleInputChange,
|
|
18153
18153
|
handleInputClick,
|
|
18154
18154
|
handleInputKeyDown,
|
|
18155
|
-
handleSelectedClick,
|
|
18156
18155
|
handleRemoveSelectedClick
|
|
18157
18156
|
};
|
|
18158
18157
|
};
|
|
@@ -18216,7 +18215,7 @@ const TypeaheadInputsGroupWrapper = /*#__PURE__*/base_default()(Wrapper_Wrapper,
|
|
|
18216
18215
|
}) => isOpen ? '50px' : 'auto', ";flex-direction:column!important;" + ( true ? "" : 0));
|
|
18217
18216
|
const TypeaheadTrigger = /*#__PURE__*/base_default()(PopoverTrigger, true ? {
|
|
18218
18217
|
target: "e1vig1dw0"
|
|
18219
|
-
} : 0)("position:relative;border-radius:
|
|
18218
|
+
} : 0)("position:relative;border-radius:12px;border:1px solid ", ({
|
|
18220
18219
|
status,
|
|
18221
18220
|
theme
|
|
18222
18221
|
}) => status === 'basic' ? theme.colors.grey : status === 'error' ? theme.colors.red : theme.colors.greenLighter, ";min-height:44px;height:auto;background:#fff;gap:8px;padding:5px 28px 5px 8px;width:100%;flex-wrap:wrap;border-color:", ({
|
|
@@ -18266,7 +18265,7 @@ const MultipleTrigger = () => {
|
|
|
18266
18265
|
const theme = (0,react_namespaceObject.useTheme)();
|
|
18267
18266
|
const context = useTypeaheadContext();
|
|
18268
18267
|
const typeaheadInputAdditionalProps = {};
|
|
18269
|
-
if (!context.selectedItems.length && !!context.placeholder) {
|
|
18268
|
+
if (!context.selectedItems.length && !context.inputValue && !!context.placeholder) {
|
|
18270
18269
|
typeaheadInputAdditionalProps.placeholder = context.placeholder;
|
|
18271
18270
|
}
|
|
18272
18271
|
return (0,jsx_runtime_namespaceObject.jsxs)((external_react_default()).Fragment, {
|
|
@@ -18274,7 +18273,7 @@ const MultipleTrigger = () => {
|
|
|
18274
18273
|
const currentOption = context.optionsWithKey[selectedItem];
|
|
18275
18274
|
const optionText = currentOption ? currentOption.children || currentOption.label || currentOption.value : '';
|
|
18276
18275
|
return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadItem, {
|
|
18277
|
-
onClick:
|
|
18276
|
+
onClick: e => e.stopPropagation(),
|
|
18278
18277
|
isDisabled: context.isDisabled,
|
|
18279
18278
|
children: [(0,jsx_runtime_namespaceObject.jsx)(TypeaheadItemLabel, {
|
|
18280
18279
|
isDisabled: context.isDisabled,
|
|
@@ -18318,11 +18317,6 @@ const MultipleTrigger = () => {
|
|
|
18318
18317
|
disabled: context.isDisabled,
|
|
18319
18318
|
className: ['typeahead-input', TypeaheadInput(theme), TypeaheadInputPlaceholder].join(' '),
|
|
18320
18319
|
...typeaheadInputAdditionalProps
|
|
18321
|
-
}), (0,jsx_runtime_namespaceObject.jsx)("input", {
|
|
18322
|
-
type: "hidden",
|
|
18323
|
-
readOnly: true,
|
|
18324
|
-
value: context.selectedItems,
|
|
18325
|
-
...context.register?.(context.name, context.validationSchema)
|
|
18326
18320
|
})]
|
|
18327
18321
|
}), !context.isDisabled && context.selectedItems.length ? (0,jsx_runtime_namespaceObject.jsx)(Button_Button, {
|
|
18328
18322
|
variant: "tertiary",
|
|
@@ -18349,7 +18343,7 @@ const SingleTrigger = () => {
|
|
|
18349
18343
|
const context = useTypeaheadContext();
|
|
18350
18344
|
const theme = (0,react_namespaceObject.useTheme)();
|
|
18351
18345
|
const typeaheadInputAdditionalProps = {};
|
|
18352
|
-
if (!context.selectedItems.length && !!context.placeholder) {
|
|
18346
|
+
if (!context.selectedItems.length && !context.inputValue && !!context.placeholder) {
|
|
18353
18347
|
typeaheadInputAdditionalProps.placeholder = context.placeholder;
|
|
18354
18348
|
}
|
|
18355
18349
|
return (0,jsx_runtime_namespaceObject.jsxs)(TypeaheadInputsGroupWrapper, {
|
|
@@ -18378,11 +18372,6 @@ const SingleTrigger = () => {
|
|
|
18378
18372
|
tabIndex: -1,
|
|
18379
18373
|
className: ['typeahead-input', TypeaheadInput(theme), TypeaheadInputPlaceholder].join(' '),
|
|
18380
18374
|
...typeaheadInputAdditionalProps
|
|
18381
|
-
}), (0,jsx_runtime_namespaceObject.jsx)("input", {
|
|
18382
|
-
type: "hidden",
|
|
18383
|
-
readOnly: true,
|
|
18384
|
-
value: context.selectedItems[0] || '',
|
|
18385
|
-
...context.register?.(context.name, context.validationSchema)
|
|
18386
18375
|
}), !context.isDisabled && context.selectedItems.length ? (0,jsx_runtime_namespaceObject.jsx)(Button_Button, {
|
|
18387
18376
|
variant: "tertiary",
|
|
18388
18377
|
"data-testid": "remove-all-button",
|
|
@@ -18489,6 +18478,7 @@ const Typeahead = ({
|
|
|
18489
18478
|
name = 'typeahead-search',
|
|
18490
18479
|
label,
|
|
18491
18480
|
selectedItems,
|
|
18481
|
+
defaultSelectedItems,
|
|
18492
18482
|
isOpen,
|
|
18493
18483
|
isDisabled,
|
|
18494
18484
|
isMultiple,
|
|
@@ -18506,8 +18496,6 @@ const Typeahead = ({
|
|
|
18506
18496
|
optionsClassName,
|
|
18507
18497
|
wrapperClassName,
|
|
18508
18498
|
width = 300,
|
|
18509
|
-
setValue,
|
|
18510
|
-
register,
|
|
18511
18499
|
onChange,
|
|
18512
18500
|
onEmptyChange,
|
|
18513
18501
|
onClearAll,
|
|
@@ -18518,6 +18506,7 @@ const Typeahead = ({
|
|
|
18518
18506
|
const hookResult = useTypeahead({
|
|
18519
18507
|
name,
|
|
18520
18508
|
selectedItems,
|
|
18509
|
+
defaultSelectedItems,
|
|
18521
18510
|
isOpen,
|
|
18522
18511
|
isDisabled,
|
|
18523
18512
|
isMultiple,
|
|
@@ -18531,8 +18520,6 @@ const Typeahead = ({
|
|
|
18531
18520
|
success,
|
|
18532
18521
|
validationSchema,
|
|
18533
18522
|
placeholder,
|
|
18534
|
-
setValue,
|
|
18535
|
-
register,
|
|
18536
18523
|
onChange,
|
|
18537
18524
|
onEmptyChange,
|
|
18538
18525
|
renderOption,
|
|
@@ -18580,7 +18567,7 @@ const Typeahead = ({
|
|
|
18580
18567
|
status: hookResult.status,
|
|
18581
18568
|
disabled: isDisabled,
|
|
18582
18569
|
"data-testid": "helper-text",
|
|
18583
|
-
children: error ? error?.message : helperText
|
|
18570
|
+
children: hookResult.error ? hookResult.error?.message?.toString() : helperText
|
|
18584
18571
|
})]
|
|
18585
18572
|
})
|
|
18586
18573
|
});
|
|
@@ -19458,6 +19445,7 @@ const SelectWidget = props => {
|
|
|
19458
19445
|
placeholder,
|
|
19459
19446
|
onChange,
|
|
19460
19447
|
onBlur,
|
|
19448
|
+
onFocus,
|
|
19461
19449
|
onChangeOverride,
|
|
19462
19450
|
value
|
|
19463
19451
|
} = props;
|
|
@@ -19472,43 +19460,44 @@ const SelectWidget = props => {
|
|
|
19472
19460
|
const handleBlur = ({
|
|
19473
19461
|
target
|
|
19474
19462
|
}) => onBlur(id, target && target.value);
|
|
19463
|
+
const handleFocus = ({
|
|
19464
|
+
target
|
|
19465
|
+
}) => onFocus(id, target && target.value);
|
|
19475
19466
|
const onEmptyChange = isEmpty => {
|
|
19476
19467
|
if (isEmpty) {
|
|
19477
19468
|
handleChange();
|
|
19478
19469
|
}
|
|
19479
19470
|
};
|
|
19480
|
-
const register = fieldName => ({
|
|
19481
|
-
onBlur: handleBlur,
|
|
19482
|
-
onChange: handleChange,
|
|
19483
|
-
name: fieldName,
|
|
19484
|
-
ref: () => {}
|
|
19485
|
-
});
|
|
19486
19471
|
const items = Array.isArray(enumOptions) ? enumOptions : [];
|
|
19487
19472
|
const selectedItems = selectedIndex ? [items[Number(selectedIndex)].value] : [];
|
|
19488
|
-
return (0,jsx_runtime_namespaceObject.jsx)(
|
|
19489
|
-
|
|
19490
|
-
|
|
19491
|
-
|
|
19492
|
-
|
|
19493
|
-
|
|
19494
|
-
|
|
19495
|
-
|
|
19496
|
-
|
|
19497
|
-
|
|
19498
|
-
|
|
19499
|
-
|
|
19500
|
-
|
|
19501
|
-
|
|
19502
|
-
|
|
19503
|
-
|
|
19504
|
-
|
|
19505
|
-
|
|
19506
|
-
|
|
19507
|
-
|
|
19508
|
-
|
|
19509
|
-
|
|
19510
|
-
|
|
19511
|
-
|
|
19473
|
+
return (0,jsx_runtime_namespaceObject.jsx)("div", {
|
|
19474
|
+
id: id,
|
|
19475
|
+
onBlur: handleBlur,
|
|
19476
|
+
onFocus: handleFocus,
|
|
19477
|
+
children: (0,jsx_runtime_namespaceObject.jsx)(Typeahead, {
|
|
19478
|
+
width: "100%",
|
|
19479
|
+
selectedItems: selectedItems,
|
|
19480
|
+
isDisabled: disabled,
|
|
19481
|
+
name: name
|
|
19482
|
+
// RJSF provides placeholder as empty string
|
|
19483
|
+
,
|
|
19484
|
+
placeholder: placeholder || undefined,
|
|
19485
|
+
onChange: handleChange,
|
|
19486
|
+
onEmptyChange: onEmptyChange,
|
|
19487
|
+
renderOption: ({
|
|
19488
|
+
label,
|
|
19489
|
+
input
|
|
19490
|
+
}) => highlightInputMatch(label, input),
|
|
19491
|
+
children: items.map(({
|
|
19492
|
+
label,
|
|
19493
|
+
value
|
|
19494
|
+
}) => (0,jsx_runtime_namespaceObject.jsx)(TypeaheadOption_TypeaheadOption, {
|
|
19495
|
+
value: value,
|
|
19496
|
+
label: label || value,
|
|
19497
|
+
isDisabled: disabled || Array.isArray(enumDisabled) && enumDisabled.includes(value),
|
|
19498
|
+
children: label || value
|
|
19499
|
+
}, value))
|
|
19500
|
+
})
|
|
19512
19501
|
});
|
|
19513
19502
|
};
|
|
19514
19503
|
;// ./src/components/JsonSchemaForm/widgets/PasswordWidget.tsx
|