Bridge Training
Rich Text

model

Domain types, constants, and suit utilities.

The @workspace/rich-text root barrel exports the canonical RichText domain types used across the application. These are the types stored in the database -- editor-specific formats (Plate/Slate) are internal implementation details.

import type { RichText, LocalizedRichText } from '@workspace/rich-text';
import type { Suit } from '@workspace/bridge/types';
import { EMPTY_RICH_TEXT, GLYPH_TO_SUIT, SUIT_TO_GLYPH } from '@workspace/rich-text';

Types

RichText

The root type: an array of block nodes.

type RichText = RichBlockNode[];

type RichBlockNode = RichParagraphNode | RichListNode;

Block Nodes

type RichParagraphNode = {
  type: 'paragraph';
  children: RichInlineNode[];
};

type RichListNode = {
  type: 'list';
  ordered: boolean;
  children: RichListItemNode[];
};

type RichListItemNode = {
  type: 'list-item';
  children: RichInlineNode[];
};

Inline Nodes

type RichInlineNode = RichTextNode | RichSuitNode;

type RichTextNode = {
  type: 'text';
  text: string;
  bold?: boolean;
  italic?: boolean;
};

type RichSuitNode = {
  type: 'suit';
  suit: Suit;
  bold?: boolean;
  italic?: boolean;
};

type Suit = 'S' | 'H' | 'D' | 'C';

LocalizedRichText

type LocalizedRichText = Record<string, RichText>;
// e.g. { en: [...], fr: [...] }

Constants

ExportTypeValue
EMPTY_RICH_TEXTRichText[]
LINE_SEPARATORstring'\n'

Suit Utilities

ExportTypeDescription
SUIT_TO_GLYPHRecord<Suit, string>{ S: '\u2660', H: '\u2665', D: '\u2666', C: '\u2663' }
GLYPH_TO_SUITRecord<string, Suit>Reverse mapping
isSuitCode(s)(s: string) => s is SuitType guard