Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: potentially missing field in todo list (#6540)

Lucasf3fe729900f0
diff --git a/frontend/appflowy_flutter/analysis_options.yaml b/frontend/appflowy_flutter/analysis_options.yaml
index c8066c92a5..8da401ef26 100644
--- a/frontend/appflowy_flutter/analysis_options.yaml
+++ b/frontend/appflowy_flutter/analysis_options.yaml
@@ -1,13 +1,3 @@
-# This file configures the analyzer, which statically analyzes Dart code to
-# check for errors, warnings, and lints.
-#
-# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
-# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
-# invoked from the command line by running `flutter analyze`.
-
-# The following line activates a set of recommended lints for Flutter apps,
-# packages, and plugins designed to encourage good coding practices.
-
include: package:flutter_lints/flutter.yaml
analyzer:
@@ -16,17 +6,6 @@ analyzer:
- "**/*.freezed.dart"
linter:
- # The lint rules applied to this project can be customized in the
- # section below to disable rules from the `package:flutter_lints/flutter.yaml`
- # included above or to enable additional rules. A list of all available lints
- # and their documentation is published at
- # https://dart-lang.github.io/linter/lints/index.html.
- #
- # Instead of disabling a lint rule for the entire project in the
- # section below, it can also be suppressed for a single line of code
- # or a specific dart file by using the `// ignore: name_of_lint` and
- # `// ignore_for_file: name_of_lint` syntax on the line or in the file
- # producing the lint.
rules:
- require_trailing_commas
@@ -51,8 +30,5 @@ linter:
- sort_constructors_first
- unawaited_futures
-# Additional information about this file can be found at
-# https://dart.dev/guides/language/analysis-options
-
errors:
invalid_annotation_target: ignore
diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart b/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart
index 0fd3ddc445..7738ed655c 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart
@@ -281,8 +281,8 @@ extension on UpdateOperation {
assert(parentId.isNotEmpty);
// create the external text if the node contains the delta in its data.
- final prevDelta = oldAttributes['delta'];
- final delta = attributes['delta'];
+ final prevDelta = oldAttributes[blockComponentDelta];
+ final delta = attributes[blockComponentDelta];
final diff = prevDelta != null && delta != null
? Delta.fromJson(prevDelta).diff(
Delta.fromJson(delta),
@@ -290,6 +290,7 @@ extension on UpdateOperation {
: null;
final composedAttributes = composeAttributes(oldAttributes, attributes);
+ final composedDelta = composedAttributes?[blockComponentDelta];
composedAttributes?.remove(blockComponentDelta);
final payload = BlockActionPayloadPB()
@@ -306,12 +307,13 @@ extension on UpdateOperation {
if (textId == null || textId.isEmpty) {
// to be compatible with the old version, we create a new text id if the text id is empty.
final textId = nanoid(6);
- final textDeltaPayloadPB = delta == null
+ final textDelta = composedDelta ?? delta ?? prevDelta;
+ final textDeltaPayloadPB = textDelta == null
? null
: TextDeltaPayloadPB(
documentId: documentId,
textId: textId,
- delta: jsonEncode(delta),
+ delta: jsonEncode(textDelta),
);
node.externalValues = ExternalValues(
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart
index c718ec2e13..66442b25cc 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart
@@ -92,9 +92,9 @@ class CalloutBlockComponentBuilder extends BlockComponentBuilder {
);
}
- // validate the data of the node, if the result is false, the node will be rendered as a placeholder
@override
- bool validate(Node node) => node.delta != null && node.children.isEmpty;
+ BlockComponentValidate get validate =>
+ (node) => node.delta != null && node.children.isEmpty;
}
// the main widget for rendering the callout block
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/database/database_view_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/database/database_view_block_component.dart
index f3292226aa..630d612bcd 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/database/database_view_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/database/database_view_block_component.dart
@@ -36,7 +36,7 @@ class DatabaseViewBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) =>
+ BlockComponentValidate get validate => (node) =>
node.children.isEmpty &&
node.attributes[DatabaseBlockKeys.parentID] is String &&
node.attributes[DatabaseBlockKeys.viewID] is String;
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/error/error_block_component_builder.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/error/error_block_component_builder.dart
index 7d443791f5..a37ed29150 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/error/error_block_component_builder.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/error/error_block_component_builder.dart
@@ -34,7 +34,7 @@ class ErrorBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) => true;
+ BlockComponentValidate get validate => (_) => true;
}
class ErrorBlockComponentWidget extends BlockComponentStatefulWidget {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart
index 67e41e01a7..e9b8862257 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart
@@ -1,5 +1,3 @@
-import 'package:flutter/material.dart';
-
import 'package:appflowy/core/helpers/url_launcher.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
@@ -20,6 +18,7 @@ import 'package:desktop_drop/desktop_drop.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
+import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:open_filex/open_filex.dart';
import 'package:provider/provider.dart';
@@ -137,7 +136,7 @@ class FileBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) => node.delta == null && node.children.isEmpty;
+ BlockComponentValidate get validate => (node) => node.children.isEmpty;
}
class FileBlockComponent extends BlockComponentStatefulWidget {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart
index ccba9b3f2e..7a68ad99b9 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart
@@ -111,7 +111,7 @@ class CustomImageBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) => node.delta == null && node.children.isEmpty;
+ BlockComponentValidate get validate => (node) => node.children.isEmpty;
}
class CustomImageBlockComponent extends BlockComponentStatefulWidget {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart
index 5bf1238367..272b492835 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart
@@ -69,7 +69,7 @@ class MultiImageBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) => node.delta == null && node.children.isEmpty;
+ BlockComponentValidate get validate => (node) => node.children.isEmpty;
}
class MultiImageBlockComponent extends BlockComponentStatefulWidget {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart
index fd9d854cfb..6330fd7fd8 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart
@@ -82,7 +82,7 @@ class MathEquationBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) =>
+ BlockComponentValidate get validate => (node) =>
node.children.isEmpty &&
node.attributes[MathEquationBlockKeys.formula] is String;
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart
index 2b6b3e267a..7d637b1273 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart
@@ -75,11 +75,10 @@ class AutoCompletionBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) {
- return node.children.isEmpty &&
- node.attributes[AutoCompletionBlockKeys.prompt] is String &&
- node.attributes[AutoCompletionBlockKeys.startSelection] is Map;
- }
+ BlockComponentValidate get validate => (node) =>
+ node.children.isEmpty &&
+ node.attributes[AutoCompletionBlockKeys.prompt] is String &&
+ node.attributes[AutoCompletionBlockKeys.startSelection] is Map;
}
class AutoCompletionBlockComponent extends BlockComponentStatefulWidget {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart
index 0e7090f95f..445611ef1d 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart
@@ -63,7 +63,7 @@ class SmartEditBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) =>
+ BlockComponentValidate get validate => (node) =>
node.attributes[SmartEditBlockKeys.action] is int &&
node.attributes[SmartEditBlockKeys.content] is String;
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart
index f9b0388c88..ee4ba205f3 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart
@@ -60,7 +60,7 @@ class OutlineBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) => node.children.isEmpty;
+ BlockComponentValidate get validate => (node) => node.children.isEmpty;
}
class OutlineBlockWidget extends BlockComponentStatefulWidget {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/sub_page/sub_page_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/sub_page/sub_page_block_component.dart
index eb9be0b3e5..fec677146a 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/sub_page/sub_page_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/sub_page/sub_page_block_component.dart
@@ -1,5 +1,3 @@
-import 'package:flutter/material.dart';
-
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart';
import 'package:appflowy/plugins/trash/application/trash_listener.dart';
@@ -17,6 +15,7 @@ import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
+import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Node subPageNode({String? viewId}) {
@@ -60,7 +59,7 @@ class SubPageBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) => node.delta == null && node.children.isEmpty;
+ BlockComponentValidate get validate => (node) => node.children.isEmpty;
}
class SubPageBlockComponent extends BlockComponentStatefulWidget {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart
index 638efe7cf1..73e4a4f39b 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart
@@ -78,7 +78,7 @@ class ToggleListBlockComponentBuilder extends BlockComponentBuilder {
}
@override
- bool validate(Node node) => node.delta != null;
+ BlockComponentValidate get validate => (node) => node.delta != null;
}
class ToggleListBlockComponentWidget extends BlockComponentStatefulWidget {
diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock
index 28779f3182..2805904da8 100644
--- a/frontend/appflowy_flutter/pubspec.lock
+++ b/frontend/appflowy_flutter/pubspec.lock
@@ -53,17 +53,17 @@ packages:
dependency: "direct main"
description:
path: "."
- ref: "0a0d441"
- resolved-ref: "0a0d44133981f87e233bcb102b1482488ef43e91"
+ ref: a0b3c72
+ resolved-ref: a0b3c7289b8c4073b47793f665e70a511324f9b9
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
source: git
- version: "3.3.0"
+ version: "4.0.0"
appflowy_editor_plugins:
dependency: "direct main"
description:
path: "packages/appflowy_editor_plugins"
- ref: b228456
- resolved-ref: b228456d59fcfa08752353ccd665a9ecc7304f94
+ ref: "2d3d4fb"
+ resolved-ref: "2d3d4fb536f32cbcdf9fcd52dfe3033429666285"
url: "https://github.com/AppFlowy-IO/AppFlowy-plugins.git"
source: git
version: "0.0.6"
@@ -1535,10 +1535,10 @@ packages:
dependency: transitive
description:
name: platform
- sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
+ sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
url: "https://pub.dev"
source: hosted
- version: "3.1.4"
+ version: "3.1.5"
plugin_platform_interface:
dependency: "direct dev"
description:
@@ -1933,10 +1933,10 @@ packages:
dependency: transitive
description:
name: string_scanner
- sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
+ sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
url: "https://pub.dev"
source: hosted
- version: "1.2.0"
+ version: "1.3.0"
string_validator:
dependency: "direct main"
description:
@@ -2238,10 +2238,10 @@ packages:
dependency: transitive
description:
name: vm_service
- sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
+ sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
- version: "14.2.1"
+ version: "14.2.5"
watcher:
dependency: transitive
description:
diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yaml
index 38d947e463..e079aebdd0 100644
--- a/frontend/appflowy_flutter/pubspec.yaml
+++ b/frontend/appflowy_flutter/pubspec.yaml
@@ -170,13 +170,13 @@ dependency_overrides:
appflowy_editor:
git:
url: https://github.com/AppFlowy-IO/appflowy-editor.git
- ref: "0a0d441"
+ ref: "a0b3c72"
appflowy_editor_plugins:
git:
url: https://github.com/AppFlowy-IO/AppFlowy-plugins.git
path: "packages/appflowy_editor_plugins"
- ref: "b228456"
+ ref: "2d3d4fb"
sheet:
git:
diff --git a/frontend/appflowy_flutter/test/unit_test/editor/transaction_adapter_test.dart b/frontend/appflowy_flutter/test/unit_test/editor/transaction_adapter_test.dart
index 64c81fb7f7..2982b75c68 100644
--- a/frontend/appflowy_flutter/test/unit_test/editor/transaction_adapter_test.dart
+++ b/frontend/appflowy_flutter/test/unit_test/editor/transaction_adapter_test.dart
@@ -222,5 +222,73 @@ void main() {
);
await completer.future;
});
+
+ test('use delta from prev attributes if current delta is null', () async {
+ final node = todoListNode(
+ checked: false,
+ delta: Delta()..insert('AppFlowy'),
+ );
+ final document = Document(
+ root: pageNode(
+ children: [
+ node,
+ ],
+ ),
+ );
+ final transactionAdapter = TransactionAdapter(
+ documentId: '',
+ documentService: DocumentService(),
+ );
+
+ final editorState = EditorState(
+ document: document,
+ );
+
+ final completer = Completer();
+ editorState.transactionStream.listen((event) {
+ final time = event.$1;
+ if (time == TransactionTime.before) {
+ final actions = transactionAdapter.transactionToBlockActions(
+ event.$2,
+ editorState,
+ );
+ final textActions =
+ transactionAdapter.filterTextDeltaActions(actions);
+ final blockActions = transactionAdapter.filterBlockActions(actions);
+ expect(textActions.length, 1);
+ expect(blockActions.length, 1);
+
+ // check text operation
+ final textAction = textActions.first;
+ final textId = textAction.textDeltaPayloadPB?.textId;
+ {
+ expect(textAction.textDeltaType, TextDeltaType.create);
+
+ expect(textId, isNotEmpty);
+ final delta = textAction.textDeltaPayloadPB?.delta;
+ expect(delta, equals('[{"insert":"AppFlowy"}]'));
+ }
+
+ // check block operation
+ {
+ final blockAction = blockActions.first;
+ expect(blockAction.action, BlockActionTypePB.Update);
+ expect(blockAction.payload.block.id, node.id);
+ expect(
+ blockAction.payload.block.externalId,
+ textId,
+ );
+ expect(blockAction.payload.block.externalType, 'text');
+ }
+ } else if (time == TransactionTime.after) {
+ completer.complete();
+ }
+ });
+
+ final transaction = editorState.transaction;
+ transaction.updateNode(node, {TodoListBlockKeys.checked: true});
+ await editorState.apply(transaction);
+ await completer.future;
+ });
});
}