nodeSchema function

Json nodeSchema(
  1. Catalog catalog
)

The JSON Schema of a node in catalog (its type one of the catalog's node types; the node keys and the behaviors as declared).

Implementation

Json nodeSchema(Catalog catalog) => {
      'type': 'object',
      'required': ['type'],
      'properties': {
        'type': {
          'type': 'string',
          'enum': [for (final w in catalog.widgets) w.type],
        },
        'name': {'type': 'string'},
        'children': {
          'type': 'array',
          'items': {'type': 'string'},
          'description': 'Child ids, in order (they may arrive in later ops).',
        },
        'slots': {
          'type': 'object',
          'additionalProperties': {'type': 'string'},
          'description': 'Slot name → child id (a canvas: body, appBar, bottomNavigationBar, floatingActionButton).',
        },
        'layout': {
          'type': 'object',
          'description': 'Size and placement: ${[for (final f in LayoutFields.all) f.key].join(', ')}.',
        },
        'decoration': {
          'type': 'object',
          'description': 'Paint: ${[for (final f in DecorationFields.all) f.key].join(', ')}.',
        },
        'props': {'type': 'object', 'description': 'The node type\'s own parameters (text, style, spacing...).'},
        'bind': {
          'type': 'object',
          'additionalProperties': {'type': 'string'},
          'description': 'Binding path → expression (`props.text`: `\${user.name}`).',
        },
        'actions': {'type': 'array', 'description': 'Reactions: {"trigger": {"type": "click"}, "actions": [...]}.'},
        'visible': {'type': 'boolean'},
        'opacity': {'type': 'number'},
        'media': {'type': 'array', 'description': 'Rules by screen width: [{"maxWidth": 599, "patch": {...}}].'},
        for (final k in Behaviors.keys) k: <String, Object?>{},
        for (final k in editNodeKeys)
          if (!const {'type', 'name', 'children', 'slots', 'layout', 'decoration', 'props', 'bind', 'actions', 'visible', 'opacity', 'media'}
              .contains(k))
            k: <String, Object?>{},
      },
      'additionalProperties': false,
    };