Skip to content

Commit

Permalink
chore: hide Log and PlatformExtension (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Sep 11, 2024
1 parent 14ea32a commit 72512df
Show file tree
Hide file tree
Showing 60 changed files with 236 additions and 253 deletions.
9 changes: 5 additions & 4 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:printing/printing.dart';
import 'package:universal_html/html.dart' as html;
import 'package:universal_platform/universal_platform.dart';

enum ExportFileType {
documentJson,
Expand Down Expand Up @@ -60,7 +61,7 @@ class _HomePageState extends State<HomePage> {
void initState() {
super.initState();

_jsonString = PlatformExtension.isDesktopOrWeb
_jsonString = UniversalPlatform.isDesktopOrWeb
? rootBundle.loadString('assets/example.json')
: rootBundle.loadString('assets/mobile_example.json');

Expand Down Expand Up @@ -91,7 +92,7 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
extendBodyBehindAppBar: PlatformExtension.isDesktopOrWeb,
extendBodyBehindAppBar: UniversalPlatform.isDesktopOrWeb,
drawer: _buildDrawer(context),
appBar: AppBar(
backgroundColor: const Color.fromARGB(255, 134, 46, 247),
Expand Down Expand Up @@ -123,7 +124,7 @@ class _HomePageState extends State<HomePage> {
// AppFlowy Editor Demo
_buildSeparator(context, 'AppFlowy Editor Demo'),
_buildListTile(context, 'With Example.json', () {
final jsonString = PlatformExtension.isDesktopOrWeb
final jsonString = UniversalPlatform.isDesktopOrWeb
? rootBundle.loadString('assets/example.json')
: rootBundle.loadString('assets/mobile_example.json');
_loadEditor(context, jsonString);
Expand Down Expand Up @@ -358,7 +359,7 @@ class _HomePageState extends State<HomePage> {
)
..setAttribute('download', 'document.${fileType.extension}')
..click();
} else if (PlatformExtension.isMobile) {
} else if (UniversalPlatform.isMobile) {
final appStorageDirectory = await getApplicationDocumentsDirectory();

final path = File(
Expand Down
3 changes: 2 additions & 1 deletion example/lib/pages/collab_selection_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:universal_platform/universal_platform.dart';

class CollabSelectionEditor extends StatefulWidget {
const CollabSelectionEditor({super.key});
Expand Down Expand Up @@ -54,7 +55,7 @@ class _CollabSelectionEditorState extends State<CollabSelectionEditor> {
void initState() {
super.initState();

future = PlatformExtension.isDesktopOrWeb
future = UniversalPlatform.isDesktopOrWeb
? rootBundle.loadString('assets/example.json')
: rootBundle.loadString('assets/mobile_example.json').then((value) {
return value;
Expand Down
5 changes: 3 additions & 2 deletions example/lib/pages/customize_theme_for_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:universal_platform/universal_platform.dart';

class CustomizeThemeForEditor extends StatefulWidget {
const CustomizeThemeForEditor({super.key});
Expand All @@ -21,7 +22,7 @@ class _CustomizeThemeForEditorState extends State<CustomizeThemeForEditor> {
void initState() {
super.initState();

final jsonString = PlatformExtension.isDesktopOrWeb
final jsonString = UniversalPlatform.isDesktopOrWeb
? rootBundle.loadString('assets/example.json')
: rootBundle.loadString('assets/mobile_example.json');
editorState = jsonString.then((value) {
Expand Down Expand Up @@ -152,7 +153,7 @@ class _CustomizeThemeForEditorState extends State<CustomizeThemeForEditor> {
/// custom the text style
EditorStyle customizeEditorStyle() {
return EditorStyle(
padding: PlatformExtension.isDesktopOrWeb
padding: UniversalPlatform.isDesktopOrWeb
? const EdgeInsets.only(left: 200, right: 200)
: const EdgeInsets.symmetric(horizontal: 20),
cursorColor: Colors.green,
Expand Down
1 change: 0 additions & 1 deletion example/lib/pages/desktop_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class _DesktopEditorState extends State<DesktopEditor> {

@override
Widget build(BuildContext context) {
assert(PlatformExtension.isDesktopOrWeb);
return FloatingToolbar(
items: [
paragraphItem,
Expand Down
15 changes: 7 additions & 8 deletions example/lib/pages/editor.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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/mobile_editor.dart';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:universal_platform/universal_platform.dart';

class Editor extends StatefulWidget {
const Editor({
Expand Down Expand Up @@ -97,7 +96,7 @@ class _EditorState extends State<Editor> {

editorState.logConfiguration
..handler = debugPrint
..level = LogLevel.off;
..level = AppFlowyEditorLogLevel.off;

editorState.transactionStream.listen((event) {
if (event.$1 == TransactionTime.after) {
Expand All @@ -111,12 +110,12 @@ class _EditorState extends State<Editor> {
registerWordCounter();
}

if (PlatformExtension.isDesktopOrWeb) {
if (UniversalPlatform.isDesktopOrWeb) {
return DesktopEditor(
editorState: editorState!,
textDirection: widget.textDirection,
);
} else if (PlatformExtension.isMobile) {
} else if (UniversalPlatform.isMobile) {
return MobileEditor(editorState: editorState!);
}
}
Expand All @@ -134,7 +133,7 @@ class _EditorState extends State<Editor> {
color: Colors.black.withOpacity(0.1),
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(8),
bottomLeft: PlatformExtension.isMobile
bottomLeft: UniversalPlatform.isMobile
? const Radius.circular(8)
: Radius.zero,
),
Expand Down
3 changes: 2 additions & 1 deletion example/lib/pages/focus_example_for_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:universal_platform/universal_platform.dart';

class FocusExampleForEditor extends StatefulWidget {
const FocusExampleForEditor({super.key});
Expand All @@ -18,7 +19,7 @@ class _FocusExampleForEditorState extends State<FocusExampleForEditor> {
void initState() {
super.initState();

final jsonString = PlatformExtension.isDesktopOrWeb
final jsonString = UniversalPlatform.isDesktopOrWeb
? rootBundle.loadString('assets/example.json')
: rootBundle.loadString('assets/mobile_example.json');
editorState = jsonString.then((value) {
Expand Down
1 change: 0 additions & 1 deletion example/lib/pages/mobile_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class _MobileEditorState extends State<MobileEditor> {

@override
Widget build(BuildContext context) {
assert(PlatformExtension.isMobile);
return MobileToolbarV2(
toolbarHeight: 48.0,
toolbarItems: [
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies:
printing: ^5.11.1
appflowy_editor_plugins: ^0.0.6
markdown:
universal_platform: ^1.1.0

dependency_overrides:
appflowy_editor:
Expand Down
5 changes: 3 additions & 2 deletions lib/src/core/document/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ final class Node extends ChangeNotifier with LinkedListEntry<Node> {
final length = _children.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.parent = this;
Expand Down Expand Up @@ -202,7 +203,7 @@ final class Node extends ChangeNotifier with LinkedListEntry<Node> {
if (parent == null || list == null) {
return false;
}
Log.editor.debug('delete Node $this from path $path');
AppFlowyEditorLog.editor.debug('delete Node $this from path $path');
super.unlink();

parent?._cacheChildren = null;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/core/transform/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ extension TextTransaction on Transaction {
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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/services.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void _addRow(Node tableNode, int position, EditorState editorState) async {
}

if (error) {
Log.editor.debug('unable to insert row');
AppFlowyEditorLog.editor.debug('unable to insert row');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ class TableBlockComponentBuilder extends BlockComponentBuilder {
bool validate(Node node) {
// check the node is valid
if (node.attributes.isEmpty) {
Log.editor.debug('TableBlockComponentBuilder: node is empty');
AppFlowyEditorLog.editor
.debug('TableBlockComponentBuilder: node is empty');
return false;
}

// check the node has rowPosition and colPosition
if (!node.attributes.containsKey(TableBlockKeys.colsLen) ||
!node.attributes.containsKey(TableBlockKeys.rowsLen)) {
Log.editor.debug(
AppFlowyEditorLog.editor.debug(
'TableBlockComponentBuilder: node has no colsLen or rowsLen',
);
return false;
Expand All @@ -132,12 +133,13 @@ class TableBlockComponentBuilder extends BlockComponentBuilder {
// check its children
final children = node.children;
if (children.isEmpty) {
Log.editor.debug('TableBlockComponentBuilder: children is empty');
AppFlowyEditorLog.editor
.debug('TableBlockComponentBuilder: children is empty');
return false;
}

if (children.length != colsLen * rowsLen) {
Log.editor.debug(
AppFlowyEditorLog.editor.debug(
'TableBlockComponentBuilder: children length(${children.length}) is not equal to colsLen * rowsLen($colsLen * $rowsLen)',
);
return false;
Expand All @@ -152,15 +154,15 @@ class TableBlockComponentBuilder extends BlockComponentBuilder {
n.attributes[TableCellBlockKeys.rowPosition] == j,
);
if (child.isEmpty) {
Log.editor.debug(
AppFlowyEditorLog.editor.debug(
'TableBlockComponentBuilder: child($i, $j) is empty',
);
return false;
}

// should only contains one child
if (child.length != 1) {
Log.editor.debug(
AppFlowyEditorLog.editor.debug(
'TableBlockComponentBuilder: child($i, $j) is not unique',
);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TableNode {
required this.node,
}) : _config = TableConfig.fromJson(node.attributes) {
if (node.type != TableBlockKeys.type) {
Log.editor.debug('TableNode: node is not a table');
AppFlowyEditorLog.editor.debug('TableNode: node is not a table');
return;
}

Expand All @@ -25,14 +25,14 @@ class TableNode {
rowsLen == null ||
colsLen is! int ||
rowsLen is! int) {
Log.editor.debug(
AppFlowyEditorLog.editor.debug(
'TableNode: colsLen or rowsLen is not an integer or null',
);
return;
}

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',
);
return;
Expand All @@ -42,7 +42,8 @@ class TableNode {
for (final child in node.children) {
if (!child.attributes.containsKey(TableCellBlockKeys.rowPosition) ||
!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;
}
}
Expand All @@ -59,7 +60,7 @@ class TableNode {
.firstOrNull;

if (cell == null) {
Log.editor.debug('TableNode: cell is empty');
AppFlowyEditorLog.editor.debug('TableNode: cell is empty');
_cells.clear();
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/util/platform_extension.dart';
import 'package:flutter/material.dart';

/// Arrow down key events.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/editor/command/selection_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ extension SelectionTransform on EditorState {
// After the selection is deleted, we want to move the selection to the
// beginning of the deleted selection.
transaction.afterSelection = selection.collapse(atStart: true);
Log.editor
AppFlowyEditorLog.editor
.debug(transaction.operations.map((e) => e.toString()).toString());

// Apply the transaction.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:appflowy_editor/appflowy_editor.dart';

import 'package:flutter/material.dart';

Future<void> onPerformAction(
TextInputAction action,
EditorState editorState,
) async {
Log.input.debug('onPerformAction: $action');
AppFlowyEditorLog.input.debug('onPerformAction: $action');
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Future<void> onDelete(
TextEditingDeltaDeletion deletion,
EditorState editorState,
) async {
Log.input.debug('onDelete: $deletion');
AppFlowyEditorLog.input.debug('onDelete: $deletion');

final selection = editorState.selection;
if (selection == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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/util/platform_extension.dart';
import 'package:appflowy_editor/src/render/selection/mobile_basic_handle.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -10,7 +11,8 @@ Future<void> onFloatingCursorUpdate(
RawFloatingCursorPoint point,
EditorState editorState,
) 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.
if (PlatformExtension.isDesktopOrWeb) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Future<void> onInsert(
EditorState editorState,
List<CharacterShortcutEvent> characterShortcutEvents,
) async {
Log.input.debug('onInsert: $insertion');
AppFlowyEditorLog.input.debug('onInsert: $insertion');

final textInserted = insertion.textInserted;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/util/platform_extension.dart';
import 'package:flutter/services.dart';

Future<void> onNonTextUpdate(
Expand Down
Loading

0 comments on commit 72512df

Please sign in to comment.