Skip to content

Commit

Permalink
Add layer merging
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Oct 23, 2024
1 parent de25892 commit 7e664f2
Show file tree
Hide file tree
Showing 13 changed files with 509 additions and 227 deletions.
4 changes: 4 additions & 0 deletions api/lib/src/protocol/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class DocumentEvent extends ReplayEvent with _$DocumentEvent {
String id,
) = LayerRemoved;

const factory DocumentEvent.layersMerged(
List<String> layers,
) = LayersMerged;

const factory DocumentEvent.layerOrderChanged(
String id,
int index,
Expand Down
107 changes: 107 additions & 0 deletions api/lib/src/protocol/event.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ DocumentEvent _$DocumentEventFromJson(Map<String, dynamic> json) {
return LayerChanged.fromJson(json);
case 'layerRemoved':
return LayerRemoved.fromJson(json);
case 'layersMerged':
return LayersMerged.fromJson(json);
case 'layerOrderChanged':
return LayerOrderChanged.fromJson(json);
case 'layerVisibilityChanged':
Expand Down Expand Up @@ -3391,6 +3393,111 @@ abstract class LayerRemoved extends DocumentEvent {
throw _privateConstructorUsedError;
}

/// @nodoc
abstract class _$$LayersMergedImplCopyWith<$Res> {
factory _$$LayersMergedImplCopyWith(
_$LayersMergedImpl value, $Res Function(_$LayersMergedImpl) then) =
__$$LayersMergedImplCopyWithImpl<$Res>;
@useResult
$Res call({List<String> layers});
}

/// @nodoc
class __$$LayersMergedImplCopyWithImpl<$Res>
extends _$DocumentEventCopyWithImpl<$Res, _$LayersMergedImpl>
implements _$$LayersMergedImplCopyWith<$Res> {
__$$LayersMergedImplCopyWithImpl(
_$LayersMergedImpl _value, $Res Function(_$LayersMergedImpl) _then)
: super(_value, _then);

/// Create a copy of DocumentEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? layers = null,
}) {
return _then(_$LayersMergedImpl(
null == layers
? _value._layers
: layers // ignore: cast_nullable_to_non_nullable
as List<String>,
));
}
}

/// @nodoc
@JsonSerializable()
class _$LayersMergedImpl extends LayersMerged {
const _$LayersMergedImpl(final List<String> layers, {final String? $type})
: _layers = layers,
$type = $type ?? 'layersMerged',
super._();

factory _$LayersMergedImpl.fromJson(Map<String, dynamic> json) =>
_$$LayersMergedImplFromJson(json);

final List<String> _layers;
@override
List<String> get layers {
if (_layers is EqualUnmodifiableListView) return _layers;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_layers);
}

@JsonKey(name: 'type')
final String $type;

@override
String toString() {
return 'DocumentEvent.layersMerged(layers: $layers)';
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LayersMergedImpl &&
const DeepCollectionEquality().equals(other._layers, _layers));
}

@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(_layers));

/// Create a copy of DocumentEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$LayersMergedImplCopyWith<_$LayersMergedImpl> get copyWith =>
__$$LayersMergedImplCopyWithImpl<_$LayersMergedImpl>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$LayersMergedImplToJson(
this,
);
}
}

abstract class LayersMerged extends DocumentEvent {
const factory LayersMerged(final List<String> layers) = _$LayersMergedImpl;
const LayersMerged._() : super._();

factory LayersMerged.fromJson(Map<String, dynamic> json) =
_$LayersMergedImpl.fromJson;

List<String> get layers;

/// Create a copy of DocumentEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$LayersMergedImplCopyWith<_$LayersMergedImpl> get copyWith =>
throw _privateConstructorUsedError;
}

/// @nodoc
abstract class _$$LayerOrderChangedImplCopyWith<$Res> {
factory _$$LayerOrderChangedImplCopyWith(_$LayerOrderChangedImpl value,
Expand Down
11 changes: 11 additions & 0 deletions api/lib/src/protocol/event.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions api/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ packages:
dependency: transitive
description:
name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
build:
dependency: transitive
description:
Expand Down Expand Up @@ -146,10 +146,10 @@ packages:
dependency: "direct main"
description:
name: collection
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
url: "https://pub.dev"
source: hosted
version: "1.19.0"
version: "1.19.1"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -178,10 +178,10 @@ packages:
dependency: transitive
description:
name: dart_mappable
sha256: "47269caf2060533c29b823ff7fa9706502355ffcb61e7f2a374e3a0fb2f2c3f0"
sha256: f69a961ae8589724ebb542e588f228ae844c5f78028899cbe2cc718977c1b382
url: "https://pub.dev"
source: hosted
version: "4.2.2"
version: "4.3.0"
dart_style:
dependency: transitive
description:
Expand Down Expand Up @@ -258,10 +258,10 @@ packages:
dependency: transitive
description:
name: http_parser
sha256: "40f592dd352890c3b60fec1b68e786cefb9603e05ff303dbc4dda49b304ecdf4"
sha256: "76d306a1c3afb33fe82e2bbacad62a61f409b5634c915fceb0d799de1a913360"
url: "https://pub.dev"
source: hosted
version: "4.1.0"
version: "4.1.1"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -603,10 +603,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
url: "https://pub.dev"
source: hosted
version: "14.3.0"
version: "14.3.1"
watcher:
dependency: transitive
description:
Expand Down
24 changes: 24 additions & 0 deletions app/lib/bloc/document_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,30 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
);
});

on<LayersMerged>((event, emit) {
final current = state;
if (current is! DocumentLoadSuccess) return;
if (!(current.embedding?.editable ?? true)) return;
if (event.layers.length < 2) return;
final mainLayer = event.layers.first;
final mergedLayers = event.layers.skip(1).toList();
var layer = current.page.getLayer(mainLayer);
layer = layer.copyWith(content: [
...layer.content,
...mergedLayers.expand((e) => current.page.getLayer(e).content)
]);
final newLayers = current.page.layers
.where((e) => !mergedLayers.contains(e.id))
.map((e) => e.id == mainLayer ? layer : e)
.toList();
return _saveState(
emit,
state: current.copyWith(
page: current.page.copyWith(layers: newLayers),
),
);
});

on<CurrentLayerChanged>((event, emit) {
final current = state;
if (current is! DocumentLoadSuccess) return;
Expand Down
15 changes: 14 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -620,5 +620,18 @@
"homeScreen": "Home screen",
"lastNote": "Last note",
"newNote": "New note",
"convertToLayer": "Convert to layer"
"convertToLayer": "Convert to layer",
"merge": "Merge",
"up": "Up",
"down": "Down",
"other": "Other",
"countElements": "{count,plural, =0{No elements} =1{1 element} other{{count} elements}}",
"@countElements": {
"placeholders": {
"count": {
"type": "int",
"example": "1"
}
}
}
}
2 changes: 1 addition & 1 deletion app/lib/settings/general.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
PhosphorIconsLight.identificationCard),
title: Text(AppLocalizations.of(context).imprint),
onTap: () => launchUrl(
Uri.https('go.linwood.dev', 'impress'),
Uri.https('go.linwood.dev', 'imprint'),
mode: LaunchMode.externalApplication)),
ListTile(
leading:
Expand Down
Loading

0 comments on commit 7e664f2

Please sign in to comment.