How to use the @remirror/core-helpers.isString 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 / react-node-view / src / react-node-view.tsx View on Github external
public createDomRef(): HTMLElement {
    const { toDOM } = this.node.type.spec;

    if (toDOM) {
      const domSpec = toDOM(this.node);
      if (isString(domSpec)) {
        return document.createElement(domSpec);
      }

      if (isDOMNode(domSpec)) {
        if (!isElementDOMNode(domSpec)) {
          throw new Error('Invalid HTML Element provided in the DOM Spec');
        }
        return domSpec;
      }

      // Use the outer element string to render the dom node
      return document.createElement(domSpec[0]);
    }
    return this.node.isInline ? document.createElement('span') : document.createElement('div');
  }
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,
            });

            return decorationSet.add(tr.doc, [deco]);
          }

          if (tracker.remove) {
            const { remove } = tracker;
            const found = decorationSet.find(undefined, undefined, spec => spec.id === remove.id);
github ifiokjr / remirror / @remirror / core-utils / src / dom-utils.ts View on Github external
fallback = EMPTY_PARAGRAPH_NODE,
}: CreateDocumentNodeParams): ProsemirrorNode => {
  if (isProsemirrorNode(content)) {
    return content;
  }

  if (isObjectNode(content)) {
    try {
      return schema.nodeFromJSON(content);
    } catch (e) {
      console.error(e);
      return fallbackContent({ fallback, schema });
    }
  }

  if (isString(content) && stringHandler) {
    return stringHandler({ doc, content, schema });
  }

  return fallbackContent({ fallback, schema });
};
github ifiokjr / remirror / @remirror / ui / src / ui-utils.ts View on Github external
export const cssValueUnits = (val: unknown): string | undefined =>
  isString(val) ? val.replace(/[0-9 ]+/g, '') : undefined;
github ifiokjr / remirror / @remirror / react-node-view / src / react-node-view.tsx View on Github external
public setDomAttrs(node: ProsemirrorNode, element: HTMLElement) {
    const { toDOM } = this.node.type.spec;
    if (toDOM) {
      const domSpec = toDOM(node);

      if (isString(domSpec) || isDOMNode(domSpec)) {
        return;
      }

      const attrs = domSpec[1];

      if (isPlainObject(attrs)) {
        keys(attrs).forEach(attr => {
          element.setAttribute(attr, String(attrs[attr]));
        });

        return;
      }
    }

    keys(node.attrs).forEach(attr => {
      element.setAttribute(attr, node.attrs[attr]);
github ifiokjr / remirror / @remirror / ui / src / ui-hsl.ts View on Github external
const createValidPercent = (value: number | string) => {
  const percent = isString(value) ? Number(value.replace(/[%\s]+/g, '')) : value;

  if (!isValidPercent(percent)) {
    throw new Error(`Invalid 'percentage': ${value}`);
  }

  return percent;
};
github ifiokjr / remirror / @remirror / ui / src / ui-hsl.ts View on Github external
const createValidAlpha = (value: number | string | undefined): Alpha => {
  const alpha = isString(value)
    ? value.includes('%')
      ? Number(value.replace(/[%\s]+/g, ''))
      : Number(value) * 100
    : value;

  if (isUndefined(alpha)) {
    return createValidPercent(100);
  }

  return createValidPercent(alpha);
};
github ifiokjr / remirror / packages / prosemirror-suggest / src / suggest-predicates.ts View on Github external
export const isExitReason = (value: unknown): value is ExitReason =>
  isString(value) && Object.values(ExitReason).includes(value as ExitReason);
export const isChangeReason = (value: unknown): value is ChangeReason =>