chore: hide Log and PlatformExtension (#886)

This commit is contained in:
Lucas.Xu 2024-09-11 17:51:53 +08:00 • committed by GitHub
commit 72512df842
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
60 changed files with 236 additions and 253 deletions

View file

@ -20,6 +20,7 @@ import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:printing/printing.dart'; import 'package:printing/printing.dart';
import 'package:universal_html/html.dart' as html; import 'package:universal_html/html.dart' as html;
import 'package:universal_platform/universal_platform.dart';
enum ExportFileType { enum ExportFileType {
documentJson, documentJson,
@ -60,7 +61,7 @@ class _HomePageState extends State<HomePage> {
void initState() { void initState() {
super.initState(); super.initState();
_jsonString = PlatformExtension.isDesktopOrWeb _jsonString = UniversalPlatform.isDesktopOrWeb
? rootBundle.loadString('assets/example.json') ? rootBundle.loadString('assets/example.json')
: rootBundle.loadString('assets/mobile_example.json'); : rootBundle.loadString('assets/mobile_example.json');
@ -91,7 +92,7 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
extendBodyBehindAppBar: PlatformExtension.isDesktopOrWeb, extendBodyBehindAppBar: UniversalPlatform.isDesktopOrWeb,
drawer: _buildDrawer(context), drawer: _buildDrawer(context),
appBar: AppBar( appBar: AppBar(
backgroundColor: const Color.fromARGB(255, 134, 46, 247), backgroundColor: const Color.fromARGB(255, 134, 46, 247),
@ -123,7 +124,7 @@ class _HomePageState extends State<HomePage> {
// AppFlowy Editor Demo // AppFlowy Editor Demo
_buildSeparator(context, 'AppFlowy Editor Demo'), _buildSeparator(context, 'AppFlowy Editor Demo'),
_buildListTile(context, 'With Example.json', () { _buildListTile(context, 'With Example.json', () {
final jsonString = PlatformExtension.isDesktopOrWeb final jsonString = UniversalPlatform.isDesktopOrWeb
? rootBundle.loadString('assets/example.json') ? rootBundle.loadString('assets/example.json')
: rootBundle.loadString('assets/mobile_example.json'); : rootBundle.loadString('assets/mobile_example.json');
_loadEditor(context, jsonString); _loadEditor(context, jsonString);
@ -358,7 +359,7 @@ class _HomePageState extends State<HomePage> {
) )
..setAttribute('download', 'document.${fileType.extension}') ..setAttribute('download', 'document.${fileType.extension}')
..click(); ..click();
} else if (PlatformExtension.isMobile) { } else if (UniversalPlatform.isMobile) {
final appStorageDirectory = await getApplicationDocumentsDirectory(); final appStorageDirectory = await getApplicationDocumentsDirectory();
final path = File( final path = File(

View file

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:universal_platform/universal_platform.dart';
class CollabSelectionEditor extends StatefulWidget { class CollabSelectionEditor extends StatefulWidget {
const CollabSelectionEditor({super.key}); const CollabSelectionEditor({super.key});
@ -54,7 +55,7 @@ class _CollabSelectionEditorState extends State<CollabSelectionEditor> {
void initState() { void initState() {
super.initState(); super.initState();
future = PlatformExtension.isDesktopOrWeb future = UniversalPlatform.isDesktopOrWeb
? rootBundle.loadString('assets/example.json') ? rootBundle.loadString('assets/example.json')
: rootBundle.loadString('assets/mobile_example.json').then((value) { : rootBundle.loadString('assets/mobile_example.json').then((value) {
return value; return value;

View file

@ -5,6 +5,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:universal_platform/universal_platform.dart';
class CustomizeThemeForEditor extends StatefulWidget { class CustomizeThemeForEditor extends StatefulWidget {
const CustomizeThemeForEditor({super.key}); const CustomizeThemeForEditor({super.key});
@ -21,7 +22,7 @@ class _CustomizeThemeForEditorState extends State<CustomizeThemeForEditor> {
void initState() { void initState() {
super.initState(); super.initState();
final jsonString = PlatformExtension.isDesktopOrWeb final jsonString = UniversalPlatform.isDesktopOrWeb
? rootBundle.loadString('assets/example.json') ? rootBundle.loadString('assets/example.json')
: rootBundle.loadString('assets/mobile_example.json'); : rootBundle.loadString('assets/mobile_example.json');
editorState = jsonString.then((value) { editorState = jsonString.then((value) {
@ -152,7 +153,7 @@ class _CustomizeThemeForEditorState extends State<CustomizeThemeForEditor> {
/// custom the text style /// custom the text style
EditorStyle customizeEditorStyle() { EditorStyle customizeEditorStyle() {
return EditorStyle( return EditorStyle(
padding: PlatformExtension.isDesktopOrWeb padding: UniversalPlatform.isDesktopOrWeb
? const EdgeInsets.only(left: 200, right: 200) ? const EdgeInsets.only(left: 200, right: 200)
: const EdgeInsets.symmetric(horizontal: 20), : const EdgeInsets.symmetric(horizontal: 20),
cursorColor: Colors.green, cursorColor: Colors.green,

View file

@ -59,7 +59,6 @@ class _DesktopEditorState extends State<DesktopEditor> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(PlatformExtension.isDesktopOrWeb);
return FloatingToolbar( return FloatingToolbar(
items: [ items: [
paragraphItem, paragraphItem,

View file

@ -1,11 +1,10 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:example/pages/desktop_editor.dart'; import 'package:example/pages/desktop_editor.dart';
import 'package:example/pages/mobile_editor.dart'; import 'package:example/pages/mobile_editor.dart';
import 'package:flutter/material.dart';
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:universal_platform/universal_platform.dart';
class Editor extends StatefulWidget { class Editor extends StatefulWidget {
const Editor({ const Editor({
@ -97,7 +96,7 @@ class _EditorState extends State<Editor> {
editorState.logConfiguration editorState.logConfiguration
..handler = debugPrint ..handler = debugPrint
..level = LogLevel.off; ..level = AppFlowyEditorLogLevel.off;
editorState.transactionStream.listen((event) { editorState.transactionStream.listen((event) {
if (event.$1 == TransactionTime.after) { if (event.$1 == TransactionTime.after) {
@ -111,12 +110,12 @@ class _EditorState extends State<Editor> {
registerWordCounter(); registerWordCounter();
} }
if (PlatformExtension.isDesktopOrWeb) { if (UniversalPlatform.isDesktopOrWeb) {
return DesktopEditor( return DesktopEditor(
editorState: editorState!, editorState: editorState!,
textDirection: widget.textDirection, textDirection: widget.textDirection,
); );
} else if (PlatformExtension.isMobile) { } else if (UniversalPlatform.isMobile) {
return MobileEditor(editorState: editorState!); return MobileEditor(editorState: editorState!);
} }
} }
@ -134,7 +133,7 @@ class _EditorState extends State<Editor> {
color: Colors.black.withOpacity(0.1), color: Colors.black.withOpacity(0.1),
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
topLeft: const Radius.circular(8), topLeft: const Radius.circular(8),
bottomLeft: PlatformExtension.isMobile bottomLeft: UniversalPlatform.isMobile
? const Radius.circular(8) ? const Radius.circular(8)
: Radius.zero, : Radius.zero,
), ),

View file

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:universal_platform/universal_platform.dart';
class FocusExampleForEditor extends StatefulWidget { class FocusExampleForEditor extends StatefulWidget {
const FocusExampleForEditor({super.key}); const FocusExampleForEditor({super.key});
@ -18,7 +19,7 @@ class _FocusExampleForEditorState extends State<FocusExampleForEditor> {
void initState() { void initState() {
super.initState(); super.initState();
final jsonString = PlatformExtension.isDesktopOrWeb final jsonString = UniversalPlatform.isDesktopOrWeb
? rootBundle.loadString('assets/example.json') ? rootBundle.loadString('assets/example.json')
: rootBundle.loadString('assets/mobile_example.json'); : rootBundle.loadString('assets/mobile_example.json');
editorState = jsonString.then((value) { editorState = jsonString.then((value) {

View file

@ -47,7 +47,6 @@ class _MobileEditorState extends State<MobileEditor> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(PlatformExtension.isMobile);
return MobileToolbarV2( return MobileToolbarV2(
toolbarHeight: 48.0, toolbarHeight: 48.0,
toolbarItems: [ toolbarItems: [

View file

@ -46,6 +46,7 @@ dependencies:
printing: ^5.11.1 printing: ^5.11.1
appflowy_editor_plugins: ^0.0.6 appflowy_editor_plugins: ^0.0.6
markdown: markdown:
universal_platform: ^1.1.0
dependency_overrides: dependency_overrides:
appflowy_editor: appflowy_editor:

View file

@ -147,7 +147,8 @@ final class Node extends ChangeNotifier with LinkedListEntry<Node> {
final length = _children.length; final length = _children.length;
index ??= length; index ??= length;
Log.editor.debug('insert Node $entry at path ${path + [index]}}'); AppFlowyEditorLog.editor
.debug('insert Node $entry at path ${path + [index]}}');
entry._resetRelationshipIfNeeded(); entry._resetRelationshipIfNeeded();
entry.parent = this; entry.parent = this;
@ -202,7 +203,7 @@ final class Node extends ChangeNotifier with LinkedListEntry<Node> {
if (parent == null || list == null) { if (parent == null || list == null) {
return false; return false;
} }
Log.editor.debug('delete Node $this from path $path'); AppFlowyEditorLog.editor.debug('delete Node $this from path $path');
super.unlink(); super.unlink();
parent?._cacheChildren = null; parent?._cacheChildren = null;

View file

@ -205,7 +205,8 @@ extension TextTransaction on Transaction {
} }
if (index < 0 || index > delta.length) { if (index < 0 || index > delta.length) {
Log.editor.info('The index($index) is out of range or negative.'); AppFlowyEditorLog.editor
.info('The index($index) is out of range or negative.');
return; return;
} }

View file

@ -1,4 +1,5 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/util/platform_extension.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';

View file

@ -193,7 +193,7 @@ void _addRow(Node tableNode, int position, EditorState editorState) async {
} }
if (error) { if (error) {
Log.editor.debug('unable to insert row'); AppFlowyEditorLog.editor.debug('unable to insert row');
return; return;
} }

View file

@ -113,14 +113,15 @@ class TableBlockComponentBuilder extends BlockComponentBuilder {
bool validate(Node node) { bool validate(Node node) {
// check the node is valid // check the node is valid
if (node.attributes.isEmpty) { if (node.attributes.isEmpty) {
Log.editor.debug('TableBlockComponentBuilder: node is empty'); AppFlowyEditorLog.editor
.debug('TableBlockComponentBuilder: node is empty');
return false; return false;
} }
// check the node has rowPosition and colPosition // check the node has rowPosition and colPosition
if (!node.attributes.containsKey(TableBlockKeys.colsLen) || if (!node.attributes.containsKey(TableBlockKeys.colsLen) ||
!node.attributes.containsKey(TableBlockKeys.rowsLen)) { !node.attributes.containsKey(TableBlockKeys.rowsLen)) {
Log.editor.debug( AppFlowyEditorLog.editor.debug(
'TableBlockComponentBuilder: node has no colsLen or rowsLen', 'TableBlockComponentBuilder: node has no colsLen or rowsLen',
); );
return false; return false;
@ -132,12 +133,13 @@ class TableBlockComponentBuilder extends BlockComponentBuilder {
// check its children // check its children
final children = node.children; final children = node.children;
if (children.isEmpty) { if (children.isEmpty) {
Log.editor.debug('TableBlockComponentBuilder: children is empty'); AppFlowyEditorLog.editor
.debug('TableBlockComponentBuilder: children is empty');
return false; return false;
} }
if (children.length != colsLen * rowsLen) { if (children.length != colsLen * rowsLen) {
Log.editor.debug( AppFlowyEditorLog.editor.debug(
'TableBlockComponentBuilder: children length(${children.length}) is not equal to colsLen * rowsLen($colsLen * $rowsLen)', 'TableBlockComponentBuilder: children length(${children.length}) is not equal to colsLen * rowsLen($colsLen * $rowsLen)',
); );
return false; return false;
@ -152,7 +154,7 @@ class TableBlockComponentBuilder extends BlockComponentBuilder {
n.attributes[TableCellBlockKeys.rowPosition] == j, n.attributes[TableCellBlockKeys.rowPosition] == j,
); );
if (child.isEmpty) { if (child.isEmpty) {
Log.editor.debug( AppFlowyEditorLog.editor.debug(
'TableBlockComponentBuilder: child($i, $j) is empty', 'TableBlockComponentBuilder: child($i, $j) is empty',
); );
return false; return false;
@ -160,7 +162,7 @@ class TableBlockComponentBuilder extends BlockComponentBuilder {
// should only contains one child // should only contains one child
if (child.length != 1) { if (child.length != 1) {
Log.editor.debug( AppFlowyEditorLog.editor.debug(
'TableBlockComponentBuilder: child($i, $j) is not unique', 'TableBlockComponentBuilder: child($i, $j) is not unique',
); );
return false; return false;

View file

@ -13,7 +13,7 @@ class TableNode {
required this.node, required this.node,
}) : _config = TableConfig.fromJson(node.attributes) { }) : _config = TableConfig.fromJson(node.attributes) {
if (node.type != TableBlockKeys.type) { if (node.type != TableBlockKeys.type) {
Log.editor.debug('TableNode: node is not a table'); AppFlowyEditorLog.editor.debug('TableNode: node is not a table');
return; return;
} }
@ -25,14 +25,14 @@ class TableNode {
rowsLen == null || rowsLen == null ||
colsLen is! int || colsLen is! int ||
rowsLen is! int) { rowsLen is! int) {
Log.editor.debug( AppFlowyEditorLog.editor.debug(
'TableNode: colsLen or rowsLen is not an integer or null', 'TableNode: colsLen or rowsLen is not an integer or null',
); );
return; return;
} }
if (node.children.length != colsLen * rowsLen) { if (node.children.length != colsLen * rowsLen) {
Log.editor.debug( AppFlowyEditorLog.editor.debug(
'TableNode: the number of children is not equal to the number of cells', 'TableNode: the number of children is not equal to the number of cells',
); );
return; return;
@ -42,7 +42,8 @@ class TableNode {
for (final child in node.children) { for (final child in node.children) {
if (!child.attributes.containsKey(TableCellBlockKeys.rowPosition) || if (!child.attributes.containsKey(TableCellBlockKeys.rowPosition) ||
!child.attributes.containsKey(TableCellBlockKeys.colPosition)) { !child.attributes.containsKey(TableCellBlockKeys.colPosition)) {
Log.editor.debug('TableNode: cell has no rowPosition or colPosition'); AppFlowyEditorLog.editor
.debug('TableNode: cell has no rowPosition or colPosition');
return; return;
} }
} }
@ -59,7 +60,7 @@ class TableNode {
.firstOrNull; .firstOrNull;
if (cell == null) { if (cell == null) {
Log.editor.debug('TableNode: cell is empty'); AppFlowyEditorLog.editor.debug('TableNode: cell is empty');
_cells.clear(); _cells.clear();
return; return;
} }

View file

@ -1,4 +1,5 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/util/platform_extension.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// Arrow down key events. /// Arrow down key events.

View file

@ -175,7 +175,7 @@ extension SelectionTransform on EditorState {
// After the selection is deleted, we want to move the selection to the // After the selection is deleted, we want to move the selection to the
// beginning of the deleted selection. // beginning of the deleted selection.
transaction.afterSelection = selection.collapse(atStart: true); transaction.afterSelection = selection.collapse(atStart: true);
Log.editor AppFlowyEditorLog.editor
.debug(transaction.operations.map((e) => e.toString()).toString()); .debug(transaction.operations.map((e) => e.toString()).toString());
// Apply the transaction. // Apply the transaction.

View file

@ -1,10 +1,9 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
Future<void> onPerformAction( Future<void> onPerformAction(
TextInputAction action, TextInputAction action,
EditorState editorState, EditorState editorState,
) async { ) async {
Log.input.debug('onPerformAction: $action'); AppFlowyEditorLog.input.debug('onPerformAction: $action');
} }

View file

@ -6,7 +6,7 @@ Future<void> onDelete(
TextEditingDeltaDeletion deletion, TextEditingDeltaDeletion deletion,
EditorState editorState, EditorState editorState,
) async { ) async {
Log.input.debug('onDelete: $deletion'); AppFlowyEditorLog.input.debug('onDelete: $deletion');
final selection = editorState.selection; final selection = editorState.selection;
if (selection == null) { if (selection == null) {

View file

@ -1,5 +1,6 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/selection/mobile_selection_service.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/selection/mobile_selection_service.dart';
import 'package:appflowy_editor/src/editor/util/platform_extension.dart';
import 'package:appflowy_editor/src/render/selection/mobile_basic_handle.dart'; import 'package:appflowy_editor/src/render/selection/mobile_basic_handle.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -10,7 +11,8 @@ Future<void> onFloatingCursorUpdate(
RawFloatingCursorPoint point, RawFloatingCursorPoint point,
EditorState editorState, EditorState editorState,
) async { ) async {
Log.input.debug('onFloatingCursorUpdate: ${point.state}, ${point.offset}'); AppFlowyEditorLog.input
.debug('onFloatingCursorUpdate: ${point.state}, ${point.offset}');
// support updating the cursor position via the space bar on iOS/Android. // support updating the cursor position via the space bar on iOS/Android.
if (PlatformExtension.isDesktopOrWeb) { if (PlatformExtension.isDesktopOrWeb) {

View file

@ -8,7 +8,7 @@ Future<void> onInsert(
EditorState editorState, EditorState editorState,
List<CharacterShortcutEvent> characterShortcutEvents, List<CharacterShortcutEvent> characterShortcutEvents,
) async { ) async {
Log.input.debug('onInsert: $insertion'); AppFlowyEditorLog.input.debug('onInsert: $insertion');
final textInserted = insertion.textInserted; final textInserted = insertion.textInserted;

Some files were not shown because too many files have changed in this diff Show more