How to use the @remirror/core.isProsemirrorNode function in @remirror/core

To help you get started, we’ve selected a few @remirror/core 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 / jest-remirror / src / jest-remirror-matchers.ts View on Github external
toEqualRemirrorDocument(actual: ProsemirrorNode, expected: TaggedProsemirrorNode) {
    // Because schema is created dynamically, expected value is a function (schema) => PMNode;
    // That's why this magic is necessary. It simplifies writing assertions, so
    // instead of expect(doc).toEqualRemirrorDocument(doc(p())(schema)) we can just do:
    // expect(doc).toEqualRemirrorDocument(doc(p())).

    // Also it fixes issues that happens sometimes when actual schema and expected schema
    // are different objects, making this case impossible by always using actual schema to create expected node.

    if (!isProsemirrorNode(expected) || !isProsemirrorNode(actual)) {
      return {
        pass: false,
        actual,
        expected,
        name: 'toEqualRemirrorDocument',
        message: () => 'Expected both values to be instance of prosemirror-model Node.',
      };
    }

    if (expected.type.schema !== actual.type.schema) {
      return {
        pass: false,
        actual,
        expected,
        name: 'toEqualRemirrorDocument',
        message: () => 'Expected both values to be using the same schema.',
github ifiokjr / remirror / @remirror / editor-markdown / src / markdown-editor.tsx View on Github external
const createInitialContent = ({ content, schema }: CreateInitialContentParams): Content => {
  if (isString(content)) {
    return {
      markdown: content,
      wysiwyg: fromMarkdown(content, schema),
    };
  }

  if (isProsemirrorNode(content)) {
    return {
      markdown: toMarkdown(content),
      wysiwyg: content,
    };
  }

  if (!isObjectNode(content)) {
    throw new Error('Invalid content passed into the editor');
  }

  const pmNode = createDocumentNode({ content, schema });

  return {
    markdown: toMarkdown(pmNode),
    wysiwyg: pmNode,
  };
github ifiokjr / remirror / packages / jest-remirror / src / jest-remirror-matchers.ts View on Github external
toContainRemirrorDocument(state: EditorState, expected: TaggedProsemirrorNode) {
    if (!isProsemirrorNode(expected)) {
      return {
        pass: false,
        actual: state,
        expected,
        name: 'toContainRemirrorDocument',
        message: () => 'The expected value should be an instance of ProsemirrorNode.',
      };
    }

    if (!isEditorState(state)) {
      return {
        pass: false,
        actual: state,
        expected,
        name: 'toContainRemirrorDocument',
        message: () => 'Expected the value passed in to be an EditorState',
github ifiokjr / remirror / packages / jest-remirror / src / jest-remirror-builder.ts View on Github external
const isTaggedProsemirrorNode = (value: unknown): value is TaggedProsemirrorNode =>
  isProsemirrorNode(value) && !isTagTracker(value);
github ifiokjr / remirror / packages / jest-remirror / src / jest-remirror-builder.ts View on Github external
return node.reduce((acc, next) => {
      if (isProsemirrorNode(next)) {
        acc.push(PMNode.fromJSON(schema, next.toJSON()));
      }
      return acc;
    }, [] as PMNode[]);
  }
github ifiokjr / remirror / packages / jest-remirror / src / jest-remirror-utils.ts View on Github external
export const isTaggedNode = (val: unknown): val is TaggedProsemirrorNode =>
  isProsemirrorNode(val) && isObject((val as any).tags);
github ifiokjr / remirror / packages / jest-remirror / src / jest-remirror-builder.ts View on Github external
export const clean = ({ schema, content }: CleanParams) => {
  const node = content;
  if (Array.isArray(node)) {
    return node.reduce((acc, next) => {
      if (isProsemirrorNode(next)) {
        acc.push(PMNode.fromJSON(schema, next.toJSON()));
      }
      return acc;
    }, [] as PMNode[]);
  }
  return isProsemirrorNode(node) ? PMNode.fromJSON(schema, node.toJSON()) : undefined;
};