Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getCombinedItems = (triggerChar: string, matches: AutocompleteLookupData[]): ItemTypes.ItemSpec[] => {
const columns = Options.findMap(matches, (m) => Option.from(m.columns)).getOr(1);
return Arr.bind(matches, (match) => {
const choices = match.items;
return createAutocompleteItems(
choices,
match.matchText,
(itemValue, itemMeta) => {
const nr = editor.selection.getRng();
getContext(editor.dom, nr, triggerChar).fold(
// tslint:disable-next-line:no-console
() => console.error('Lost context. Cursor probably moved'),
({ range }) => {
const autocompleterApi: InlineContent.AutocompleterInstanceApi = {
hide: () => {
cancelIfNecessary();
},
reload: (fetchOptions: Record) => {
const generateItem = (rawItem: FormatItem, response: IrrelevantStyleItemResponse, disabled: boolean, value: Option): Option => {
const translatedText = backstage.shared.providers.translate(rawItem.title);
if (rawItem.type === 'separator') {
return Option.some({
type: 'separator',
text: translatedText
});
} else if (rawItem.type === 'submenu') {
const items = Arr.bind(rawItem.getStyleItems(), (si) => validate(si, response, value));
if (response === IrrelevantStyleItemResponse.Hide && items.length <= 0) {
return Option.none();
} else {
return Option.some({
type: 'nestedmenuitem',
text: translatedText,
disabled: items.length <= 0,
getSubmenuItems: () => Arr.bind(rawItem.getStyleItems(), (si) => validate(si, response, value))
});
}
} else {
return Option.some({
// ONLY TOGGLEMENUITEMS HANDLE STYLE META.
// See ToggleMenuItem and ItemStructure for how it's handled.
// If this type ever changes, we'll need to change that too
type: 'togglemenuitem',
const getDownOrRightCells = (grid: RowCells[], selectedCells: DetailExt[], generators: Generators): Element[] => {
// Get rows down or at the row of the top left cell (including rowspans)
const downGrid = grid.slice(selectedCells[0].row() + selectedCells[0].rowspan() - 1, grid.length);
const downDetails = toDetailList(downGrid, generators);
// Get an array of the cells down or to the right of the bottom right cell
return Arr.bind(downDetails, (detail) => {
const slicedCells = detail.cells().slice(selectedCells[0].column() + selectedCells[0].colspan() - 1, + detail.cells().length);
return Arr.map(slicedCells, (cell) => {
return cell.element();
});
});
};
const composeEntries = (editor, entries: Entry[]): Element[] => {
return Arr.bind(Arr.groupBy(entries, isIndented), (entries) => {
const groupIsIndented = Arr.head(entries).map(isIndented).getOr(false);
return groupIsIndented ? indentedComposer(editor, entries) : outdentedComposer(editor, entries);
});
};
const getFormatItems = (fmt) => {
const subs = fmt.items;
return subs !== undefined && subs.length > 0 ? Arr.bind(subs, getFormatItems) : [ { title: fmt.title, format: fmt.format } ];
};
const flattenedItems = Arr.bind(getStyleFormats(editor), getFormatItems);
const flatten = (fmt): string[] => {
const subs = fmt.items;
return subs !== undefined && subs.length > 0 ? Arr.bind(subs, flatten) : [ fmt.format ];
};
const getCorners = (getYAxisValue, tds: HTMLElement[]): Corner[] => {
return Arr.bind(tds, (td) => {
const rect = deflate(roundRect(td.getBoundingClientRect()), -1);
return [
{ x: rect.left, y: getYAxisValue(rect), cell: td },
{ x: rect.right, y: getYAxisValue(rect), cell: td }
];
});
};
const validateItems = (preItems: FormatItem[]) => {
const value = spec.getCurrentValue();
const response = spec.shouldHide ? IrrelevantStyleItemResponse.Hide : IrrelevantStyleItemResponse.Disable;
return Arr.bind(preItems, (item) => validate(item, response, value));
};