create method

String create(
  1. ConnectorElement connector, {
  2. bool select = true,
})

Creates a connector through the same admission and history as gestures.

Implementation

String create(ConnectorElement connector, {bool select = true}) {
  if (diagramHasCanonicalId(store.state.document, connector.id)) {
    throw StateError('Element ${connector.id} already exists.');
  }
  final decision = evaluateConnector(connector);
  decision.requireAllowed();
  store.edits
      .dispatch(
        DiagramTransaction(
          label: 'Create connector',
          steps: [
            InsertElementsStep([connector]),
          ],
          selectionAfter: select
              ? ElementSelection({connector.id})
              : store.state.selection,
        ),
      )
      .requireAllowed();
  return connector.id;
}