Skip to content

Commit

Permalink
Merge branch 'main' into feat-zhiya
Browse files Browse the repository at this point in the history
* main:
  chore: upgrade flutter version to 3.19.0 (AppFlowy-IO#719)
  fix: the positioning of the slash command menu in the web version (AppFlowy-IO#709)
  fix: unable to export image block in markdown format (AppFlowy-IO#713)
  feat: debounce on word count service (AppFlowy-IO#711)
  feat: on demand word count without listening (AppFlowy-IO#710)
  feat: support selection counters (AppFlowy-IO#706)
  feat: word counter service (AppFlowy-IO#705)
  chore: bump version 2.3.2
  chore: update Chinese i18n (AppFlowy-IO#698)
  fix: fix checkbox not work as expected in html module. (AppFlowy-IO#700)
  chore: revert ime changes (AppFlowy-IO#701)
  • Loading branch information
q200892907 committed Feb 19, 2024
2 parents fba2de2 + f38328d commit 8773098
Show file tree
Hide file tree
Showing 33 changed files with 600 additions and 99 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.3.2
* fix: platform api cause error on web platform.

## 2.3.1
* feat: backslash to ignore shortcut event by @hyj1204 in [#635](https://github.com/AppFlowy-IO/appflowy-editor/pull/635)
* feat: support formatting greater hyphen to single arrow by @Jayaprakash-dev in [#665](https://github.com/AppFlowy-IO/appflowy-editor/pull/665)
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -342,7 +342,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -420,7 +420,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -469,7 +469,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
18 changes: 7 additions & 11 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import 'dart:convert';
import 'dart:io';
import 'dart:math';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:example/pages/customize_theme_for_editor.dart';
import 'package:example/pages/editor.dart';
import 'package:example/pages/editor_list.dart';
import 'package:example/pages/focus_example_for_editor.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:universal_html/html.dart' as html;

import 'package:appflowy_editor/appflowy_editor.dart';

enum ExportFileType {
documentJson,
markdown,
Expand Down Expand Up @@ -93,9 +95,7 @@ class _HomePageState extends State<HomePage> {
surfaceTintColor: Colors.transparent,
title: const Text('AppFlowy Editor'),
),
body: SafeArea(
child: _buildBody(context),
),
body: SafeArea(child: _widgetBuilder(context)),
);
}

Expand Down Expand Up @@ -220,10 +220,6 @@ class _HomePageState extends State<HomePage> {
);
}

Widget _buildBody(BuildContext context) {
return _widgetBuilder(context);
}

Widget _buildListTile(
BuildContext context,
String text,
Expand Down
162 changes: 119 additions & 43 deletions example/lib/pages/editor.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:convert';

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

import 'package:example/pages/desktop_editor.dart';
import 'package:example/pages/mobile_editor.dart';
import 'package:flutter/material.dart';

import 'package:appflowy_editor/appflowy_editor.dart';

class Editor extends StatefulWidget {
const Editor({
Expand All @@ -25,58 +27,132 @@ class Editor extends StatefulWidget {
}

class _EditorState extends State<Editor> {
bool isInitialized = false;

EditorState? editorState;
WordCountService? wordCountService;

@override
void didUpdateWidget(covariant Editor oldWidget) {
if (oldWidget.jsonString != widget.jsonString) {
editorState = null;
isInitialized = false;
}
super.didUpdateWidget(oldWidget);
}

int wordCount = 0;
int charCount = 0;

int selectedWordCount = 0;
int selectedCharCount = 0;

void registerWordCounter() {
wordCountService?.removeListener(onWordCountUpdate);
wordCountService?.dispose();

wordCountService = WordCountService(editorState: editorState!)..register();
wordCountService!.addListener(onWordCountUpdate);

WidgetsBinding.instance.addPostFrameCallback((_) {
onWordCountUpdate();
});
}

void onWordCountUpdate() {
setState(() {
wordCount = wordCountService!.documentCounters.wordCount;
charCount = wordCountService!.documentCounters.charCount;
selectedWordCount = wordCountService!.selectionCounters.wordCount;
selectedCharCount = wordCountService!.selectionCounters.charCount;
});
}

@override
void dispose() {
editorState?.dispose();

super.dispose();
}

@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: FutureBuilder<String>(
future: widget.jsonString,
builder: (context, snapshot) {
if (snapshot.hasData &&
snapshot.connectionState == ConnectionState.done) {
EditorState editorState = EditorState(
document: Document.fromJson(
Map<String, Object>.from(
json.decode(snapshot.data!),
),
),
);
editorState.logConfiguration
..handler = debugPrint
..level = LogLevel.off;

editorState.transactionStream.listen((event) {
if (event.$1 == TransactionTime.after) {
widget.onEditorStateChange(editorState);
return Stack(
children: [
ColoredBox(
color: Colors.white,
child: FutureBuilder<String>(
future: widget.jsonString,
builder: (context, snapshot) {
if (snapshot.hasData &&
snapshot.connectionState == ConnectionState.done) {
if (!isInitialized || editorState == null) {
isInitialized = true;
EditorState editorState = EditorState(
document: Document.fromJson(
Map<String, Object>.from(
json.decode(snapshot.data!),
),
),
);

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

editorState.transactionStream.listen((event) {
if (event.$1 == TransactionTime.after) {
widget.onEditorStateChange(editorState);
}
});

this.editorState = editorState;
registerWordCounter();
}

if (PlatformExtension.isDesktopOrWeb) {
return DesktopEditor(
editorState: editorState!,
textDirection: widget.textDirection,
);
} else if (PlatformExtension.isMobile) {
return MobileEditor(editorState: editorState!);
}
}
});

this.editorState = editorState;

if (PlatformExtension.isDesktopOrWeb) {
return DesktopEditor(
editorState: editorState,
textDirection: widget.textDirection,
);
} else if (PlatformExtension.isMobile) {
return MobileEditor(
editorState: editorState,
);
}
}

return const SizedBox.shrink();
},
),

return const SizedBox.shrink();
},
),
),
Positioned(
bottom: 0,
right: 0,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 12),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.1),
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(8),
bottomLeft: PlatformExtension.isMobile
? const Radius.circular(8)
: Radius.zero,
),
),
child: Column(
children: [
Text(
'Word Count: $wordCount | Character Count: $charCount',
style: const TextStyle(fontSize: 11),
),
if (!(editorState?.selection?.isCollapsed ?? true))
Text(
'(In-selection) Word Count: $selectedWordCount | Character Count: $selectedCharCount',
style: const TextStyle(fontSize: 11),
),
],
),
),
),
],
);
}
}
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
5 changes: 4 additions & 1 deletion lib/l10n/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,8 @@
"rowDuplicate": "复制整行",
"colClear": "清空整列",
"rowClear": "清空整行",
"slashPlaceHolder": "单击 / 以插入内容,或开始输入"
"slashPlaceHolder": "单击 / 以插入内容,或开始输入",
"textAlignLeft": "靠左对齐",
"textAlignCenter": "居中对齐",
"textAlignRight": "靠右对齐"
}
5 changes: 4 additions & 1 deletion lib/l10n/intl_zh_TW.arb
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,8 @@
"rowDuplicate": "複製整列",
"colClear": "清空整行",
"rowClear": "清空整列",
"slashPlaceHolder": "輸入 / 以插入内容,或開始鍵入"
"slashPlaceHolder": "輸入 / 以插入内容,或開始鍵入",
"textAlignLeft": "靠左對齊",
"textAlignCenter": "置中對齊",
"textAlignRight": "靠右對齊"
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void showActionMenu(
);
},
).build();
Overlay.of(context).insert(overlay!);
Overlay.of(context, rootOverlay: true).insert(overlay!);
}

Widget _menuItem(
Expand Down Expand Up @@ -192,5 +192,5 @@ void _showColorMenu(
);
},
).build();
Overlay.of(context).insert(overlay!);
Overlay.of(context, rootOverlay: true).insert(overlay!);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Future<void> onNonTextUpdate(
final selection = editorState.selection;

if (PlatformExtension.isWindows) {
if (selection != null) {
editorState.updateSelectionWithReason(
Selection.collapsed(
Position(
path: selection.start.path,
offset: nonTextUpdate.selection.start,
),
if (selection != null &&
nonTextUpdate.composing == TextRange.empty &&
nonTextUpdate.selection.isCollapsed) {
editorState.selection = Selection.collapsed(
Position(
path: selection.start.path,
offset: nonTextUpdate.selection.start,
),
);
}
Expand All @@ -31,6 +31,9 @@ Future<void> onNonTextUpdate(
offset: nonTextUpdate.selection.start,
),
),
extraInfo: {
selectionExtraInfoDoNotAttachTextService: true,
},
);
}
} else if (PlatformExtension.isMacOS) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:io';
import 'dart:math';

import 'package:appflowy_editor/appflowy_editor.dart';
Expand Down Expand Up @@ -203,7 +202,7 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
}

// solve the issue where the Chinese IME doesn't continue deleting after the input content has been deleted.
if (Platform.isMacOS && (composingTextRange?.isCollapsed ?? false)) {
if (composingTextRange?.isCollapsed ?? false) {
composingTextRange = TextRange.empty;
}
}
Expand Down
Loading

0 comments on commit 8773098

Please sign in to comment.