How to use the @remirror/core-helpers.isNullOrUndefined 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 / packages / multishift / src / multishift.ts View on Github external
setInternalTimeout(() => {
          if (
            !contextRef.current.isMouseDown &&
            (isNullOrUndefined(document.activeElement) || document.activeElement.id !== menuId) &&
            document.activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
          ) {
            actions.toggleButtonBlur();
          }
        });
      }),
github ifiokjr / remirror / @remirror / core-extensions / src / extensions / position-tracker-extension.ts View on Github external
apply: (tr, decorationSet) => {
          // Map the decoration based on the changes to the document.
          decorationSet = decorationSet.map(tr.mapping, tr.doc);

          // Get tracker updates from the meta data
          const tracker = getPluginMeta(key, tr);

          if (isNullOrUndefined(tracker)) {
            return decorationSet;
          }

          if (tracker.add) {
            const { defaultClassName, defaultElement } = this.options;
            const { className, element = defaultElement } = tracker.add;
            const widget = isString(element) ? document.createElement(element) : element;
            const classNames = className ? [defaultClassName, className] : [defaultClassName];

            widget.classList.add(...classNames);

            const deco = Decoration.widget(tracker.add.pos, widget, {
              id: tracker.add.id,
              type: name,
            });
github ifiokjr / remirror / @remirror / core-utils / src / prosemirror-utils.ts View on Github external
export const findPositionOfNodeAfter = (
  value: Selection | ResolvedPos | EditorState,
): FindProsemirrorNodeResult | undefined => {
  const $pos = isResolvedPos(value) ? value : isSelection(value) ? value.$from : value.selection.$from;

  if (isNullOrUndefined($pos)) {
    throw new Error('Invalid value passed in.');
  }

  const { nodeAfter } = $pos;
  const selection = PMSelection.findFrom($pos, 1);

  if (!selection || !nodeAfter) {
    return;
  }

  const parent = findParentNodeOfType({ types: nodeAfter.type, selection });

  return parent
    ? parent
    : {
        node: nodeAfter,
github ifiokjr / remirror / @remirror / core-utils / src / prosemirror-rules.ts View on Github external
return new InputRule(regexp, (state, match, start, end) => {
    const value = transformMatch(match);

    if (isNullOrUndefined(value)) {
      return null;
    }

    const { tr } = state;

    if (value === '') {
      tr.delete(start, end);
    } else {
      tr.replaceWith(start, end, state.schema.text(value) as any);
    }

    if (updateSelection) {
      const $pos = tr.doc.resolve(start);
      tr.setSelection(new TextSelection($pos));
    }
    return tr;
github ifiokjr / remirror / @remirror / core-utils / src / dom-utils.ts View on Github external
export const isDocNodeEmpty = (node: ProsemirrorNode) => {
  const nodeChild = node.content.firstChild;

  if (node.childCount !== 1 || !nodeChild) {
    return false;
  }

  return (
    nodeChild.type.isBlock &&
    !nodeChild.childCount &&
    nodeChild.nodeSize === 2 &&
    (isNullOrUndefined(nodeChild.marks) || nodeChild.marks.length === 0)
  );
};
github ifiokjr / remirror / @remirror / core-utils / src / dom-utils.ts View on Github external
export const getOffsetParent = ({ view, element }: GetOffsetParentParams): HTMLElement =>
  isNullOrUndefined(element)
    ? ((view.dom as HTMLElement).offsetParent as HTMLElement)
    : (element.offsetParent as HTMLElement);
github ifiokjr / remirror / @remirror / core-utils / src / dom-utils.ts View on Github external
export const closestElement = (domNode: Node | null | undefined, selector: string): HTMLElement | null => {
  if (!isElementDOMNode(domNode)) {
    return null;
  }
  if (isNullOrUndefined(document.documentElement) || !document.documentElement.contains(domNode)) {
    return null;
  }
  const matches = isFunction(domNode.matches) ? 'matches' : Cast<'matches'>('msMatchesSelector');

  do {
    if (isFunction(domNode[matches]) && domNode[matches](selector)) {
      return domNode;
    }
    domNode = (domNode.parentElement ?? domNode.parentNode) as HTMLElement;
  } while (isElementDOMNode(domNode));
  return null;
};
github ifiokjr / remirror / @remirror / core-utils / src / prosemirror-utils.ts View on Github external
export const findElementAtPosition = (position: number, view: EditorView): HTMLElement => {
  const dom = view.domAtPos(position);
  const node = dom.node.childNodes[dom.offset];

  if (isTextDOMNode(dom.node)) {
    return dom.node.parentNode as HTMLElement;
  }

  if (isNullOrUndefined(node) || isTextDOMNode(node)) {
    return dom.node as HTMLElement;
  }

  return node as HTMLElement;
};
github ifiokjr / remirror / packages / multishift / src / multishift.ts View on Github external
setInternalTimeout(() => {
          if (
            !contextRef.current.isMouseDown &&
            (isNullOrUndefined(document.activeElement) ||
              (![
                refs.comboBox.current,
                refs.input.current,
                refs.toggleButton.current,
                ...refs.items.current,
                ...refs.ignored.current,
              ].some(node => node && isOrContainsNode(node, document.activeElement)) &&
                document.activeElement !== blurTarget))
          ) {
            actions.menuBlur();
          }
        });
      }),
github ifiokjr / remirror / @remirror / core-utils / src / prosemirror-utils.ts View on Github external
export const findPositionOfNodeBefore = (
  value: Selection | ResolvedPos | EditorState | Transaction,
): FindProsemirrorNodeResult | undefined => {
  const $pos = isResolvedPos(value) ? value : isSelection(value) ? value.$from : value.selection.$from;

  if (isNullOrUndefined($pos)) {
    throw new Error('Invalid value passed in.');
  }

  const { nodeBefore } = $pos;
  const selection = PMSelection.findFrom($pos, -1);

  if (!selection || !nodeBefore) {
    return;
  }

  const parent = findParentNodeOfType({ types: nodeBefore.type, selection });

  return parent
    ? parent
    : {
        node: nodeBefore,