Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const getHighlightedIndexOnOpen = (
props: Pick, 'items' | 'initialHighlightedIndexes' | 'defaultHighlightedIndexes'>,
state: MultishiftState,
offset: number,
getItemId: GetItemId,
): number[] => {
const { items, initialHighlightedIndexes, defaultHighlightedIndexes } = props;
const { selectedItems, highlightedIndexes } = state;
// initialHighlightedIndexes will give value to highlightedIndex on initial
// state only.
if (!isUndefined(initialHighlightedIndexes) && highlightedIndexes.length) {
return initialHighlightedIndexes;
}
if (defaultHighlightedIndexes) {
return defaultHighlightedIndexes;
}
if (selectedItems.length) {
const idsOfItems = items.map(getItemId);
const index = selectedItems
.map(selectedItem => idsOfItems.indexOf(getItemId(selectedItem)))
.findIndex(isValidIndex);
if (!isValidIndex(index)) {
return [];
}
const isPrefixValid = (
prefix: string,
{
invalidPrefixCharacters,
validPrefixCharacters,
}: Pick, 'invalidPrefixCharacters' | 'validPrefixCharacters'>,
) => {
if (!isUndefined(invalidPrefixCharacters)) {
const regex = new RegExp(regexToString(invalidPrefixCharacters));
return !regex.test(prefix);
}
{
const regex = new RegExp(regexToString(validPrefixCharacters));
return regex.test(prefix);
}
};
const createValidAlpha = (value: number | string | undefined): Alpha => {
const alpha = isString(value)
? value.includes('%')
? Number(value.replace(/[%\s]+/g, ''))
: Number(value) * 100
: value;
if (isUndefined(alpha)) {
return createValidPercent(100);
}
return createValidPercent(alpha);
};
const getComboBoxProps = (
{ refKey = 'ref' as GRefKey, ref, ...rest }: GetComboBoxPropsOptions = {
refKey: 'ref' as GRefKey,
},
): GetComboBoxPropsReturn => {
if (type !== Type.ComboBox) {
throw new Error('`getComboBoxProps` is only available for the autocomplete dropdown');
}
const extra = isUndefined(rest['aria-label']) ? { 'aria-labelledby': labelId } : {};
return {
[refKey]: composeRefs(ref as Ref, refs.comboBox),
role: 'combobox',
'aria-expanded': isOpen,
'aria-haspopup': 'listbox',
'aria-owns': isOpen ? menuId : null,
...extra,
...rest,
} as GetComboBoxPropsReturn;
};
const noUndefined = (fallback: GType, values: Array): GType => {
for (const value of values) {
if (!isUndefined(value)) {
return value;
}
}
return fallback;
};
[MarkGroup.Indentation]: [],
[MarkGroup.Link]: [],
[MarkGroup.Code]: [],
};
const node: NodeExtensionTags = { [NodeGroup.Block]: [], [NodeGroup.Inline]: [] };
for (const extension of extensions) {
if (isNodeExtension(extension)) {
const group = extension.schema.group as NodeGroup;
node[group] = isUndefined(node[group])
? [extension.name as GNodes]
: [...node[group], extension.name as GNodes];
} else if (isMarkExtension(extension)) {
const group = extension.schema.group as MarkGroup;
mark[group] = isUndefined(mark[group])
? [extension.name as GMarks]
: [...mark[group], extension.name as GMarks];
}
(extension.tags as Tags[]).forEach(tag => {
general[tag] = isUndefined(general[tag])
? [extension.name as GNames]
: [...general[tag], extension.name as GNames];
});
}
return {
general,
mark,
node,
} as any;