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: heading node validate failed (#5370)

Lucas.Xu0c0bd54f5273
diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dart b/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dart
index e60782605a..da99886014 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dart
@@ -1,5 +1,6 @@
import 'dart:convert';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-document/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart'
@@ -10,7 +11,13 @@ import 'package:appflowy_editor/appflowy_editor.dart'
Delta,
ParagraphBlockKeys,
NodeIterator,
- NodeExternalValues;
+ NodeExternalValues,
+ HeadingBlockKeys,
+ QuoteBlockKeys,
+ NumberedListBlockKeys,
+ BulletedListBlockKeys,
+ blockComponentDelta;
+import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:collection/collection.dart';
import 'package:nanoid/nanoid.dart';
@@ -144,21 +151,25 @@ extension BlockToNode on BlockPB {
final deltaString = meta.textMap[externalId];
if (deltaString != null) {
final delta = jsonDecode(deltaString);
- map['delta'] = delta;
- // map.putIfAbsent(
- // 'delta',
- // () => delta,
- // );
+ map[blockComponentDelta] = delta;
}
}
}
+ Attributes adapterCallback(Attributes map) => map
+ ..putIfAbsent(
+ blockComponentDelta,
+ () => Delta().toJson(),
+ );
+
final adapter = {
- ParagraphBlockKeys.type: (Attributes map) => map
- ..putIfAbsent(
- 'delta',
- () => Delta().toJson(),
- ),
+ ParagraphBlockKeys.type: adapterCallback,
+ HeadingBlockKeys.type: adapterCallback,
+ CodeBlockKeys.type: adapterCallback,
+ QuoteBlockKeys.type: adapterCallback,
+ NumberedListBlockKeys.type: adapterCallback,
+ BulletedListBlockKeys.type: adapterCallback,
+ ToggleListBlockKeys.type: adapterCallback,
};
return adapter[ty]?.call(map) ?? map;
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
index 8f18cb1d58..c8222c5e03 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
@@ -1,6 +1,3 @@
-import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
-
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
@@ -13,6 +10,8 @@ import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:easy_localization/easy_localization.dart' hide TextDirection;
import 'package:flowy_infra/theme_extension.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Map<String, BlockComponentBuilder> getEditorBuilderMap({
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 3fdf332eb3..d16c035115 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
@@ -74,17 +74,9 @@ class _ErrorBlockComponentWidgetState extends State<ErrorBlockComponentWidget>
ClipboardServiceData(plainText: jsonEncode(node.toJson())),
);
},
- text: SizedBox(
- height: 52,
- child: Row(
- children: [
- const HSpace(4),
- FlowyText(
- LocaleKeys.document_errorBlock_theBlockIsNotSupported.tr(),
- ),
- ],
- ),
- ),
+ text: PlatformExtension.isDesktopOrWeb
+ ? _buildDesktopErrorBlock(context)
+ : _buildMobileErrorBlock(context),
),
);
@@ -111,4 +103,44 @@ class _ErrorBlockComponentWidgetState extends State<ErrorBlockComponentWidget>
return child;
}
+
+ Widget _buildDesktopErrorBlock(BuildContext context) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 12),
+ child: Wrap(
+ crossAxisAlignment: WrapCrossAlignment.center,
+ children: [
+ const HSpace(4),
+ FlowyText.regular(
+ LocaleKeys.document_errorBlock_theBlockIsNotSupported.tr(),
+ ),
+ const HSpace(4),
+ FlowyText.regular(
+ '(${LocaleKeys.document_errorBlock_clickToCopyTheBlockContent.tr()})',
+ color: Theme.of(context).hintColor,
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _buildMobileErrorBlock(BuildContext context) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 4),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ FlowyText.regular(
+ LocaleKeys.document_errorBlock_theBlockIsNotSupported.tr(),
+ ),
+ const VSpace(6),
+ FlowyText.regular(
+ '(${LocaleKeys.document_errorBlock_clickToCopyTheBlockContent.tr()})',
+ color: Theme.of(context).hintColor,
+ fontSize: 12.0,
+ ),
+ ],
+ ),
+ );
+ }
}
diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json
index 96c7314dbf..ff43722720 100644
--- a/frontend/resources/translations/en.json
+++ b/frontend/resources/translations/en.json
@@ -1204,7 +1204,8 @@
"resetToDefaultFont": "Reset to default"
},
"errorBlock": {
- "theBlockIsNotSupported": "The current version does not support this block.",
+ "theBlockIsNotSupported": "Unable to parse the block content",
+ "clickToCopyTheBlockContent": "Click to copy the block content",
"blockContentHasBeenCopied": "The block content has been copied."
},
"mobilePageSelector": {