mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: heading node validate failed (#5370)
This commit is contained in:
parent
f1b035e362
commit
0c0bd54f52
@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
|
||||||
import 'package:appflowy_backend/log.dart';
|
import 'package:appflowy_backend/log.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-document/protobuf.dart';
|
import 'package:appflowy_backend/protobuf/flowy-document/protobuf.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart'
|
import 'package:appflowy_editor/appflowy_editor.dart'
|
||||||
@ -10,7 +11,13 @@ import 'package:appflowy_editor/appflowy_editor.dart'
|
|||||||
Delta,
|
Delta,
|
||||||
ParagraphBlockKeys,
|
ParagraphBlockKeys,
|
||||||
NodeIterator,
|
NodeIterator,
|
||||||
NodeExternalValues;
|
NodeExternalValues,
|
||||||
|
HeadingBlockKeys,
|
||||||
|
QuoteBlockKeys,
|
||||||
|
NumberedListBlockKeys,
|
||||||
|
BulletedListBlockKeys,
|
||||||
|
blockComponentDelta;
|
||||||
|
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:nanoid/nanoid.dart';
|
import 'package:nanoid/nanoid.dart';
|
||||||
|
|
||||||
@ -144,21 +151,25 @@ extension BlockToNode on BlockPB {
|
|||||||
final deltaString = meta.textMap[externalId];
|
final deltaString = meta.textMap[externalId];
|
||||||
if (deltaString != null) {
|
if (deltaString != null) {
|
||||||
final delta = jsonDecode(deltaString);
|
final delta = jsonDecode(deltaString);
|
||||||
map['delta'] = delta;
|
map[blockComponentDelta] = delta;
|
||||||
// map.putIfAbsent(
|
|
||||||
// 'delta',
|
|
||||||
// () => delta,
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Attributes adapterCallback(Attributes map) => map
|
||||||
|
..putIfAbsent(
|
||||||
|
blockComponentDelta,
|
||||||
|
() => Delta().toJson(),
|
||||||
|
);
|
||||||
|
|
||||||
final adapter = {
|
final adapter = {
|
||||||
ParagraphBlockKeys.type: (Attributes map) => map
|
ParagraphBlockKeys.type: adapterCallback,
|
||||||
..putIfAbsent(
|
HeadingBlockKeys.type: adapterCallback,
|
||||||
'delta',
|
CodeBlockKeys.type: adapterCallback,
|
||||||
() => Delta().toJson(),
|
QuoteBlockKeys.type: adapterCallback,
|
||||||
),
|
NumberedListBlockKeys.type: adapterCallback,
|
||||||
|
BulletedListBlockKeys.type: adapterCallback,
|
||||||
|
ToggleListBlockKeys.type: adapterCallback,
|
||||||
};
|
};
|
||||||
return adapter[ty]?.call(map) ?? map;
|
return adapter[ty]?.call(map) ?? map;
|
||||||
}
|
}
|
||||||
|
@ -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/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
|
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_page.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:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart' hide TextDirection;
|
import 'package:easy_localization/easy_localization.dart' hide TextDirection;
|
||||||
import 'package:flowy_infra/theme_extension.dart';
|
import 'package:flowy_infra/theme_extension.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
Map<String, BlockComponentBuilder> getEditorBuilderMap({
|
Map<String, BlockComponentBuilder> getEditorBuilderMap({
|
||||||
|
@ -74,17 +74,9 @@ class _ErrorBlockComponentWidgetState extends State<ErrorBlockComponentWidget>
|
|||||||
ClipboardServiceData(plainText: jsonEncode(node.toJson())),
|
ClipboardServiceData(plainText: jsonEncode(node.toJson())),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
text: SizedBox(
|
text: PlatformExtension.isDesktopOrWeb
|
||||||
height: 52,
|
? _buildDesktopErrorBlock(context)
|
||||||
child: Row(
|
: _buildMobileErrorBlock(context),
|
||||||
children: [
|
|
||||||
const HSpace(4),
|
|
||||||
FlowyText(
|
|
||||||
LocaleKeys.document_errorBlock_theBlockIsNotSupported.tr(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -111,4 +103,44 @@ class _ErrorBlockComponentWidgetState extends State<ErrorBlockComponentWidget>
|
|||||||
|
|
||||||
return child;
|
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,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1204,7 +1204,8 @@
|
|||||||
"resetToDefaultFont": "Reset to default"
|
"resetToDefaultFont": "Reset to default"
|
||||||
},
|
},
|
||||||
"errorBlock": {
|
"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."
|
"blockContentHasBeenCopied": "The block content has been copied."
|
||||||
},
|
},
|
||||||
"mobilePageSelector": {
|
"mobilePageSelector": {
|
||||||
|
Loading…
Reference in New Issue
Block a user