chore: hide Log and PlatformExtension (#886)
This commit is contained in:
parent
14ea32a06c
commit
72512df842
60 changed files with 236 additions and 253 deletions
|
|
@ -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,
|
||||
|
|
@ -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');
|
||||
|
||||
|
|
@ -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),
|
||||
|
|
@ -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);
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ class _DesktopEditorState extends State<DesktopEditor> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(PlatformExtension.isDesktopOrWeb);
|
||||
return FloatingToolbar(
|
||||
items: [
|
||||
paragraphItem,
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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!);
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ class _MobileEditorState extends State<MobileEditor> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(PlatformExtension.isMobile);
|
||||
return MobileToolbarV2(
|
||||
toolbarHeight: 48.0,
|
||||
toolbarItems: [
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -152,7 +154,7 @@ 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;
|
||||
|
|
@ -160,7 +162,7 @@ class TableBlockComponentBuilder extends BlockComponentBuilder {
|
|||
|
||||
// should only contains one child
|
||||
if (child.length != 1) {
|
||||
Log.editor.debug(
|
||||
AppFlowyEditorLog.editor.debug(
|
||||
'TableBlockComponentBuilder: child($i, $j) is not unique',
|
||||
);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue