Skip to content

Commit 6a3fd4d

Browse files
committed
Implement conditions copy-pasting with node.
1 parent 14707bb commit 6a3fd4d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/src/api/custom_component.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class ComponentData with EquatableMixin, SerializableMixin {
9898
/// Node ID -> variables.
9999
final Map<String, Set<VariableData>> variables;
100100

101+
/// Node ID -> conditions.
102+
final Map<String, Set<BaseCondition>> conditions;
103+
101104
/// Returns containing rect of the component.
102105
RectC get rect => RectC.fromLTWH(0, 0, width, height);
103106

@@ -107,11 +110,12 @@ class ComponentData with EquatableMixin, SerializableMixin {
107110
required this.height,
108111
required this.nodes,
109112
this.variables = const {},
113+
this.conditions = const {},
110114
}) : assert(nodes.isNotEmpty),
111115
assert(width > 0 && height > 0);
112116

113117
@override
114-
List<Object?> get props => [width, height, nodes, variables];
118+
List<Object?> get props => [width, height, nodes, variables, conditions];
115119

116120
@override
117121
Map toJson() => _$ComponentDataToJson(this);
@@ -127,11 +131,13 @@ class ComponentData with EquatableMixin, SerializableMixin {
127131
double? height,
128132
Map<String, dynamic>? nodes,
129133
Map<String, Set<VariableData>>? variables,
134+
Map<String, Set<BaseCondition>>? conditions,
130135
}) =>
131136
ComponentData(
132137
width: width ?? this.width,
133138
height: height ?? this.height,
134139
nodes: nodes ?? this.nodes,
135140
variables: variables ?? this.variables,
141+
conditions: conditions ?? this.conditions,
136142
);
137143
}

lib/src/api/custom_component.g.dart

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/models/condition.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ sealed class BaseCondition with EquatableMixin, SerializableMixin {
360360

361361
/// Allows the provided [visitor] to visit this condition.
362362
R? accept<R>(ConditionVisitor<R> visitor);
363+
364+
/// Creates a copy of the condition with the provided values.
365+
BaseCondition copyWith({String? id});
363366
}
364367

365368
/// Represents an else condition. e.g. `else { ... }`. [actions] are performed
@@ -380,6 +383,7 @@ class ElseCondition extends BaseCondition {
380383
}) : actions = actions ?? [];
381384

382385
/// Duplicates the else condition with the provided actions list.
386+
@override
383387
ElseCondition copyWith({
384388
String? id,
385389
List<ActionModel>? actions,
@@ -430,7 +434,8 @@ class Condition extends BaseCondition {
430434
super.lastUpdated,
431435
});
432436

433-
/// CopyWith
437+
/// Creates a new [Condition] instance with provided properties overridden.
438+
@override
434439
Condition copyWith({
435440
String? id,
436441
BaseExpression? expression,
@@ -488,7 +493,8 @@ class ConditionGroup extends BaseCondition {
488493
super.lastUpdated,
489494
}) : elseIfConditions = elseIfConditions ?? [];
490495

491-
/// CopyWith
496+
/// Creates a new [ConditionGroup] with the provided parameters overridden.
497+
@override
492498
ConditionGroup copyWith({
493499
String? id,
494500
String? name,

0 commit comments

Comments
 (0)