Skip to content
Core

Locks and capabilities ​

Loading interactive example…Open in new tab ↗
Opening the live canvas…

The regular rectangle supports standard transforms. Lock it, select it and try Move regular or Delete selection: the verb reports rejection without changing the document. Unlock it to resume editing; lock changes are undoable.

The fixed-size card has no resize handles and does not rotate because its registered definition's ShapeBehavior declares those limits. Resize fixed demonstrates the same rejection through the API. It remains selectable and movable. Instance unlocking does not override the definition's behavior.

Locking is an editing constraint, not authentication. Application permissions belong in the host admission hook; see events and permissions.

Source ​

dart
DiagramController createCapabilitiesExample() {
  final hostShapes = DiagramExtension(
    id: 'example.capabilities',
    shapes: [
      ShapeDefinition(
        type: 'example.fixed-card',
        name: 'Fixed-size card',
        behavior: const ShapeBehavior(resizable: false, rotatable: false),
      ),
    ],
  );
  final seed = DiagramController(
    configuration: DiagramConfiguration(
      extensions: [...demoModelExtensions, ...demoEditing(), hostShapes],
    ),
    document: DiagramDocument.empty('capabilities'),
  );
  try {
    for (final (id, type, x, caption) in [
      ('regular', Shapes.rectangle, -160.0, 'Lock and unlock me'),
      ('fixed', 'example.fixed-card', 160.0, 'Move me; size stays fixed'),
    ]) {
      seed.edits.createShape(
        type,
        id: id,
        at: DiagramPoint(x, 0),
        size: const DiagramSize(240, 140),
        select: false,
        textStory: TextStory.paragraph(
          id: '$id-story',
          blockId: '$id-body',
          text: caption,
        ),
      );
    }
    return DiagramController(
      configuration: DiagramConfiguration(
        extensions: [...demoModelExtensions, ...demoEditing(), hostShapes],
      ),
      document: seed.document,
    );
  } finally {
    seed.dispose();
  }
}

See Shapes for the capability grammar and Controller for lock, selection and transform method contracts.