Skip to content

Domain diagnostics ​

DiagramDiagnostics.check runs explicit checks against an immutable document. DiagramDiagnostics and DiagramDiagnostic are engine types in package:vyuh_diagram_core/adapter.dart. Use it to review drafts without preventing incomplete edits. Keep hard admission rules in a beforeChange rule.

dart
import 'package:vyuh_diagram_core/adapter.dart';
import 'package:vyuh_diagram_core/vyuh_diagram_core.dart';

final report = DiagramDiagnostics.check(controller.document, rules: [
  (document) => [
    for (final shape in document.elements.whereType<ShapeElement>())
      if (shape.type == Shapes.rectangle && shape.parentId == null)
        DiagramDiagnostic(
          id: 'department:${shape.id}',
          message: 'Assign this task to a department.',
          elementIds: [shape.id],
        ),
  ],
]);

if (report.isCurrent(controller.document) && report.items.isNotEmpty) {
  controller.select(report.items.first.elementIds);
}

Each finding has a unique ID, message, severity and optional element targets. Targets must exist in the checked document. hasErrors ignores informational findings and warnings. Check isCurrent before using a result; rerun checks after content changes. Rules must be pure. Checks run only when called, not on pointer movement or camera updates.

The engine provides reports; presenting them is up to the host. The examples below mount a small review panel that owns a Run checks button and a list of findings. Selecting a finding selects its target elements. For targets hidden inside collapsed frames, it selects the nearest visible containing frame without expanding it or changing undo history: hidden bundle members select their visible representative, and hidden internal connectors use their endpoint frames even without a parent. Edits mark the report stale (isCurrent turns false) and disable its selection actions until checks run again.

Try network review for a missing backbone binding or department ownership for an unassigned review task. Both demonstrate repair, rechecking, and undo using host-owned rules.