nodes property

Implementation

@override
late final List<FluentNodeDefinition<FNode>> nodes = [
  FluentNodeDefinition<FNode>(
    type: 'root',
    nodeClass: Root,
    decode: _decodeRoot,
    create: (_) => Root(),
    buildWidget: (_, _, _, _) => const SizedBox.shrink(),
    children: (node) => (node as Root).nodes,
    mutableChildren: (node) => (node as Root).nodes,
  ),
  FluentNodeDefinition<FNode>(
    type: 'fragment',
    nodeClass: Fragment,
    decode: (json, _) => Fragment.fromJson(json),
    create: (options) => Fragment(options['text'] as String? ?? ''),
    buildWidget: (node, document, anchor, focus) => FluentFragmentWidget(
      key: document.getKeyForNode(node.id),
      node: node as Fragment,
      anchorOffset: anchor,
      focusOffset: focus,
    ),
    inline: true,
  ),
  FluentNodeDefinition<FNode>(
    type: 'paragraph',
    nodeClass: Paragraph,
    decode: _decodeParagraph,
    create: (options) => Paragraph(text: options['text'] as String? ?? ''),
    buildWidget: (node, document, _, _) => FluentParagraphWidget(
      key: document.getKeyForNode(node.id),
      node: node,
      document: document,
    ),
    children: (node) => (node as Paragraph).fragments,
    mutableChildren: (node) => (node as Paragraph).fragments,
  ),
  FluentNodeDefinition<FNode>(
    type: 'link',
    nodeClass: Link,
    decode: _decodeLink,
    create: (options) => Link(
      url: options['url'] as String? ?? '',
      text: options['text'] as String?,
    ),
    buildWidget: (node, document, _, _) => FluentLinkWidget(
      key: document.getKeyForNode(node.id),
      node: node as Link,
      document: document,
    ),
    children: (node) => (node as Link).fragments,
    mutableChildren: (node) => (node as Link).fragments,
    inline: true,
  ),
  FluentNodeDefinition<FNode>(
    type: 'image',
    nodeClass: FluentImage,
    decode: (json, _) => FluentImage.fromJson(json),
    create: (options) => FluentImage(options['src'] as String? ?? ''),
    buildWidget: (node, document, _, _) => FluentImageWidget(
      key: document.getKeyForNode(node.id),
      node: node as FluentImage,
      document: document,
    ),
    inline: true,
    atomic: true,
  ),
  FluentNodeDefinition<FNode>(
    type: 'hr',
    nodeClass: HorizontalRule,
    decode: (json, _) => HorizontalRule.fromJson(json),
    create: (_) => HorizontalRule(),
    buildWidget: (node, document, _, _) => FluentHrWidget(
      key: document.getKeyForNode(node.id),
      node: node as HorizontalRule,
      document: document,
    ),
    atomic: true,
  ),
  FluentNodeDefinition<FNode>(
    type: 'list',
    nodeClass: FluentList,
    decode: _decodeList,
    create: (options) {
      final type = options['listType'] as String? ?? 'bullet';
      return FluentList(listType: type)
        ..items = [
          ListItem(
            bulletType: type,
            indexList: const [1],
            children: [Paragraph()],
          ),
        ];
    },
    buildWidget: (node, document, _, _) => FluentListWidget(
      key: document.getKeyForNode(node.id),
      node: node as FluentList,
      document: document,
    ),
    children: (node) => (node as FluentList).items,
    mutableChildren: (node) => (node as FluentList).items,
  ),
  FluentNodeDefinition<FNode>(
    type: 'listItem',
    nodeClass: ListItem,
    decode: _decodeListItem,
    create: (options) => ListItem(
      bulletType: options['bulletType'] as String? ?? 'bullet',
      indexList: (options['indexList'] as List<int>?) ?? const [1],
    ),
    buildWidget: (node, document, _, _) => FluentListItemWidget(
      key: document.getKeyForNode(node.id),
      node: node as ListItem,
      document: document,
    ),
    children: (node) => (node as ListItem).children,
    mutableChildren: (node) => (node as ListItem).children,
  ),
  FluentNodeDefinition<FNode>(
    type: 'table',
    nodeClass: FluentTable,
    decode: _decodeTable,
    create: _createTable,
    buildWidget: (node, document, _, _) => FluentTableWidget(
      key: document.getKeyForNode(node.id),
      node: node as FluentTable,
      document: document,
    ),
    children: (node) => (node as FluentTable).rows,
    mutableChildren: (node) => (node as FluentTable).rows,
  ),
  FluentNodeDefinition<FNode>(
    type: 'row',
    nodeClass: FluentRow,
    decode: _decodeRow,
    create: (_) => FluentRow(),
    buildWidget: (_, _, _, _) => const SizedBox.shrink(),
    children: (node) => (node as FluentRow).getChildren(),
    mutableChildren: (node) => (node as FluentRow).getChildren(),
  ),
  FluentNodeDefinition<FNode>(
    type: 'cell',
    nodeClass: FluentCell,
    decode: _decodeCell,
    create: (_) => FluentCell(),
    buildWidget: (node, document, _, _) => FluentCellWidget(
      key: document.getKeyForNode(node.id),
      node: node as FluentCell,
      document: document,
    ),
    children: (node) => (node as FluentCell).children,
    mutableChildren: (node) => (node as FluentCell).children,
  ),
];