update<E extends DiagramElement> static method
DiagramVerb
update<E extends DiagramElement>({
- required String id,
- required String label,
- required E? update(
- E element,
- DiagramVerbCall call
- String description = '',
- List<
DiagramVerbParameter< parameters = const [],Object?> > - DiagramVerbTarget target = DiagramVerbTarget.elements,
- bool appliesTo(
- DiagramElement element,
- ShapeRegistry registry
- bool admitsLockedTargets = false,
- EditResult? check(
- DiagramVerbCall call
- String editLabel(
- DiagramVerbCall call
A setter that replaces each target element of type E with update's
result, as one edit labeled label. update returns the element
unchanged, or null, when there is nothing to change.
Implementation
static DiagramVerb update<E extends DiagramElement>({
required String id,
required String label,
required E? Function(E element, DiagramVerbCall call) update,
String description = '',
List<DiagramVerbParameter<Object?>> parameters = const [],
DiagramVerbTarget target = DiagramVerbTarget.elements,
bool Function(DiagramElement element, ShapeRegistry registry)? appliesTo,
bool admitsLockedTargets = false,
EditResult? Function(DiagramVerbCall call)? check,
String Function(DiagramVerbCall call)? editLabel,
}) => DiagramVerb._(
id: id,
label: label,
symmetry: DiagramVerbSymmetry.setter,
update: (element, call) => update(element as E, call),
description: description,
parameters: parameters,
target: target,
appliesTo: (element, registry) =>
element is E && (appliesTo?.call(element, registry) ?? true),
admitsLockedTargets: admitsLockedTargets,
check: check,
perform: (call) {
final document = call.document;
final steps = <DiagramStep>[];
for (final id in call.ids) {
final before = document.elementById(id)! as E;
final after = update(before, call);
if (after != null && after != before) {
steps.add(ReplaceElementStep(before: before, after: after));
}
}
if (steps.isEmpty) return const EditResult.allow();
return call.submit(
DiagramTransaction(label: editLabel?.call(call) ?? label, steps: steps),
);
},
);