Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
styles.map(style =>
isArray(style)
? sx(...style)(theme)
: isFunction(style)
? css(style(theme))(theme)
: isSerializedStyle(style)
? style
: isPlainObject(style)
? css(style as WithVariants)(theme)
: style,
),
return new InputRule(regexp, (state, match, start, end) => {
const { tr } = state;
const attrs = isFunction(getAttrs) ? getAttrs(match) : getAttrs;
let markEnd = end;
if (match[1]) {
const startSpaces = match[0].search(/\S/);
const textStart = start + match[0].indexOf(match[1]);
const textEnd = textStart + match[1].length;
if (textEnd < end) {
tr.delete(textEnd, end);
}
if (textStart > start) {
tr.delete(start + startSpaces, textStart);
}
export const findChildren = ({ node, predicate, descend }: FindChildrenParams) => {
if (!node) {
throw new Error('Invalid "node" parameter');
} else if (!isFunction(predicate)) {
throw new Error('Invalid "predicate" parameter');
}
return flatten({ node, descend }).filter(child => predicate(child.node));
};
setState(prevState => [isFunction(value) ? value(prevState[0]) : value, cb]);
},
const emotionTheme = useEmotionTheme();
const [colorMode, setColorMode] = useState(initialColorMode ?? outer.colorMode);
const parentEmotionTheme = isRoot(outer) && !disableMergeWithEmotion ? emotionTheme : {};
const parent = disableMergeWithParent
? hasParent(outer)
? outer.parent
: Object.create(null)
: isRoot(outer) && disableMergeWithBase
? Object.create(null)
: outer.theme;
const themeWithoutColorMode: RemirrorTheme = deepMerge(
parentEmotionTheme,
parent,
isFunction(themeProp) ? themeProp(parent) : themeProp,
);
const theme = applyColorMode(themeWithoutColorMode, colorMode);
const [get, colorModes] = useMemo(() => [getFactory(theme), getColorModes(theme)], [theme]);
const value = {
...defaultRemirrorThemeValue,
...(withoutEmotion
? withoutEmotionProps
: {
sxx: (...args: Parameters) =>
defaultRemirrorThemeValue.sx(...args)(theme),
}),
parent,
theme,
export const useStateWithCallback: UseStateWithCallback = (
initialState?: GState | (() => GState),
) => {
const [[state, callback], setState] = useState<[GState | undefined, (() => void) | undefined]>([
isFunction(initialState) ? initialState() : initialState,
undefined,
]);
useEffect(() => {
if (callback) {
callback();
setState([state, undefined]);
}
}, [callback, state]);
const setStateWithCallback = useCallback(
(value: SetStateAction, cb?: () => void) => {
setState(prevState => [isFunction(value) ? value(prevState[0]) : value, cb]);
},
[setState],
);
export const useSetState = (
initialState: GState | (() => GState) = Object.create(null),
): readonly [
GState,
DispatchWithCallback>,
(callback?: () => void) => void,
] => {
const [state, setStateWithCallback] = useStateWithCallback(
isFunction(initialState) ? initialState() : initialState,
);
const resetState = useCallback(
(cb?: () => void) => {
setStateWithCallback(initialState, cb);
},
[initialState, setStateWithCallback],
);
const setState = useCallback(
(patch: PartialSetStateAction, cb?: () => void) => {
setStateWithCallback(
(prevState: GState) => ({ ...prevState, ...(isFunction(patch) ? patch(prevState) : patch) }),
cb,
);
},
export const ignoreFunctions = (obj: Record) => {
const newObject: Record = Object.create(null);
for (const key of Object.keys(obj)) {
if (isFunction(obj[key])) {
continue;
}
newObject[key] = obj[key];
}
return newObject;
};
export const nodeNameMatchesList = (
node: ProsemirrorNode | null | undefined,
nodeMatches: NodeMatch[],
): node is ProsemirrorNode => {
let outcome = false;
if (!node) {
return outcome;
}
const name = node.type.name;
for (const checker of nodeMatches) {
outcome = isRegexTuple(checker)
? regexTest(checker, name)
: isFunction(checker)
? checker(name, node)
: checker === name;
if (outcome) {
return outcome;
}
}
return outcome;
};