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 createTrailingNodePlugin = ({ extension, tags, schema }: CreateTrailingNodePluginParams) => {
const { options, pluginKey } = extension;
const { disableTags, ignoredNodes, nodeName } = options;
// The names of the nodes for whom this rule should not be applied.
const notAfter: string[] = disableTags
? uniqueArray([...ignoredNodes, nodeName])
: uniqueArray([...ignoredNodes, ...tags.general.lastNodeCompatible, nodeName]);
// The node that will be inserted when the criteria match.
const type = schema.nodes[nodeName];
// The list of nodes for this schema that should have content injected after
// them.
const types = entries(schema.nodes)
.map(([, entry]) => entry)
.filter(entry => !notAfter.includes(entry.name));
return new Plugin({
key: extension.pluginKey,
view() {
return {
update: view => {
end,
indexes,
items,
hoveredIndex,
}: GetHighlightedIndexesParams) => {
const max = items.length - 1;
const groupIndexes = isValidIndex(start)
? range(
clamp({ min: 0, max, value: start }),
clamp({ min: 0, max, value: isValidIndex(end) ? end : start }),
)
: [];
const hoveredIndexes = isValidIndex(hoveredIndex) ? [hoveredIndex] : [];
return uniqueArray([...hoveredIndexes, ...indexes, ...groupIndexes], true);
};
export const cloneElement = }> = any>(
element: ReactElement,
props: GProps,
...rest: ReactNode[]
) => {
const children = uniqueArray([
...(isArray(props.children) ? props.children : props.children ? [props.children] : []),
...rest,
]);
return jsx(
element.type,
{
key: element.key,
ref: element.props.ref,
...element.props,
...props,
},
...children,
);
};
});
const extra = isHighlighted
? {
highlightedIndexes: indexes.filter(ii => ii !== index),
highlightedGroupEndIndex: undefined,
highlightedGroupStartIndex: -1,
}
: { highlightedIndexes: indexes, highlightedGroupStartIndex: index };
const changes = { ...defaultReturn, ...extra };
return omitUnchangedState(changes, params);
}
if (shiftKeyPressed) {
const indexes = uniqueArray(state.highlightedIndexes, true);
const extra = isValidIndex(state.highlightedGroupStartIndex)
? {
highlightedIndexes: indexes,
highlightedGroupStartIndex: state.highlightedGroupStartIndex,
highlightedGroupEndIndex: index,
}
: { highlightedIndexes: indexes, highlightedGroupStartIndex: index };
const changes = { ...defaultReturn, ...extra };
return omitUnchangedState(changes, params);
}
return omitUnchangedState(
{
...defaultReturn,