How to use @remirror/core-constants - 10 common examples

To help you get started, we’ve selected a few @remirror/core-constants 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 / core / src / extension.ts View on Github external
protected getExtraAttrs(domNode: Node) {
    if (this.type === ExtensionType.Plain) {
      throw new Error('Invalid use of extraAttrs within a plain extension.');
    }

    const extraAttrs = (this.options.extraAttrs as ExtraAttrs[] | undefined) ?? [];
    const attrs: Attrs = Object.create(null);

    for (const item of extraAttrs) {
      if (Array.isArray(item)) {
        // Use the default
        const [name, , attributeName] = item;
        attrs[name] = attributeName ? (domNode as Element).getAttribute(attributeName) : undefined;
      } else if (isString(item)) {
        // Assume the name is the same
        attrs[item] = (domNode as Element).getAttribute(item);
      } else {
        const { name, getAttrs, default: fallback } = item;
github ifiokjr / remirror / @remirror / core / src / __tests__ / node-extension.spec.ts View on Github external
get schema(): NodeExtensionSpec {
    return {
      content: 'inline*',
      group: NodeGroup.Block,
      attrs: this.extraAttrs(),
      draggable: false,
      parseDOM: [
        {
          tag: 'p',
          getAttrs: node => this.getExtraAttrs(node as Element),
        },
      ],
      toDOM: () => ['p', 0],
    };
  }
}
github ifiokjr / remirror / @remirror / core / src / __tests__ / extension-manager.spec.tsx View on Github external
export const helpers = {
  getState: Cast(jest.fn(() => state)),
  portalContainer: new PortalContainer(),
  getTheme: () => defaultRemirrorThemeValue,
};

const innerMock = jest.fn();
const mock = jest.fn((_: Attrs) => innerMock);
const getInformation = jest.fn(() => 'information');

const SSRComponent: FC = () =&gt; <div>;

class DummyExtension extends Extension {
  public name = 'dummy';
  public tags = ['simple', Tags.LastNodeCompatible];
  public commands() {
    return { dummy: mock };
  }

  public helpers() {
    return {
      getInformation,
    };
  }

  public attributes() {
    return {
      class: 'custom',
    };
  }
}</div>
github ifiokjr / remirror / @remirror / core / src / extension-manager.helpers.ts View on Github external
[Tags.FormattingNode]: [],
    [Tags.LastNodeCompatible]: [],
    [Tags.NodeCursor]: [],
  };

  const mark: MarkExtensionTags = {
    [MarkGroup.Alignment]: [],
    [MarkGroup.Behavior]: [],
    [MarkGroup.Color]: [],
    [MarkGroup.FontStyle]: [],
    [MarkGroup.Indentation]: [],
    [MarkGroup.Link]: [],
    [MarkGroup.Code]: [],
  };

  const node: NodeExtensionTags = { [NodeGroup.Block]: [], [NodeGroup.Inline]: [] };

  for (const extension of extensions) {
    if (isNodeExtension(extension)) {
      const group = extension.schema.group as NodeGroup;
      node[group] = isUndefined(node[group])
        ? [extension.name as GNodes]
        : [...node[group], extension.name as GNodes];
    } else if (isMarkExtension(extension)) {
      const group = extension.schema.group as MarkGroup;
      mark[group] = isUndefined(mark[group])
        ? [extension.name as GMarks]
        : [...mark[group], extension.name as GMarks];
    }

    (extension.tags as Tags[]).forEach(tag =&gt; {
      general[tag] = isUndefined(general[tag])
github ifiokjr / remirror / packages / jest-prosemirror / src / jest-prosemirror-schema.ts View on Github external
group: 'inline',
  atom: true,
  selectable: true,
  parseDOM: [
    {
      tag: 'span[data-node-type="atomInline"]',
    },
  ],
  toDOM: () => {
    return ['span', { 'data-node-type': 'atomInline' }];
  },
};

const atomBlock: NodeSpec = {
  inline: false,
  group: NodeGroup.Block,
  atom: true,
  selectable: true,
  parseDOM: [
    {
      tag: 'div[data-node-type="atomBlock"]',
    },
  ],
  toDOM: () => {
    return ['div', { 'data-node-type': 'atomBlock' }];
  },
};

const atomContainer: NodeSpec = {
  inline: false,
  group: NodeGroup.Block,
  content: 'atomBlock+',
github ifiokjr / remirror / packages / jest-prosemirror / src / jest-prosemirror-schema.ts View on Github external
group: NodeGroup.Block,
  atom: true,
  selectable: true,
  parseDOM: [
    {
      tag: 'div[data-node-type="atomBlock"]',
    },
  ],
  toDOM: () => {
    return ['div', { 'data-node-type': 'atomBlock' }];
  },
};

const atomContainer: NodeSpec = {
  inline: false,
  group: NodeGroup.Block,
  content: 'atomBlock+',
  parseDOM: [
    {
      tag: 'div[data-node-type="atomBlockContainer"]',
    },
  ],
  toDOM: () => {
    return ['div', { 'data-node-type': 'atomBlockContainer' }];
  },
};

const containerWithRestrictedContent: NodeSpec = {
  inline: false,
  group: NodeGroup.Block,
  content: 'paragraph+',
  parseDOM: [
github ifiokjr / remirror / @remirror / core / src / extension-helpers.ts View on Github external
export const isMarkExtension = (extension: unknown): extension is MarkExtension =&gt;
  isExtension(extension) &amp;&amp; extension.type === ExtensionType.Mark;
github ifiokjr / remirror / @remirror / core / src / mark-extension.ts View on Github external
get type(): ExtensionType.Mark {
    return ExtensionType.Mark;
  }
github ifiokjr / remirror / @remirror / core / src / node-extension.ts View on Github external
get type(): ExtensionType.Node {
    return ExtensionType.Node;
  }
github ifiokjr / remirror / @remirror / core / src / extension-helpers.ts View on Github external
export const isNodeExtension = (extension: unknown): extension is NodeExtension =&gt;
  isExtension(extension) &amp;&amp; extension.type === ExtensionType.Node;