fix: heading node validate failed (#5370)

This commit is contained in:
Lucas.Xu 2024-05-20 17:18:39 +08:00 committed by GitHub
parent f1b035e362
commit 0c0bd54f52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 69 additions and 26 deletions

View File

@ -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;
}

View File

@ -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({

View File

@ -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,
),
],
),
);
}
}

View File

@ -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": {