How to use the @remirror/core-helpers.isFunction function in @remirror/core-helpers

To help you get started, we’ve selected a few @remirror/core-helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ifiokjr / remirror / @remirror / ui / src / ui-utils.ts View on Github external
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,
    ),
github ifiokjr / remirror / @remirror / core-utils / src / prosemirror-rules.ts View on Github external
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);
      }
github ifiokjr / remirror / @remirror / core-utils / src / prosemirror-node-utils.ts View on Github external
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));
};
github ifiokjr / remirror / @remirror / react-hooks / src / react-hooks.ts View on Github external
      setState(prevState => [isFunction(value) ? value(prevState[0]) : value, cb]);
    },
github ifiokjr / remirror / @remirror / ui / src / ui-provider.tsx View on Github external
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,
github ifiokjr / remirror / @remirror / react-hooks / src / react-hooks.ts View on Github external
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],
  );
github ifiokjr / remirror / @remirror / react-hooks / src / react-hooks.ts View on Github external
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,
      );
    },
github ifiokjr / remirror / @remirror / core / src / extension-manager.helpers.ts View on Github external
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;
};
github ifiokjr / remirror / @remirror / core-utils / src / dom-utils.ts View on Github external
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;
};