Skip to content

Commit

Permalink
Merge branch 'AppFlowy-IO:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
suntorytimed authored Jul 12, 2024
2 parents a503be1 + a2336f5 commit 552f135
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import 'package:appflowy/plugins/ai_chat/presentation/chat_avatar.dart';
import 'package:appflowy/plugins/ai_chat/presentation/chat_input.dart';
import 'package:appflowy/plugins/ai_chat/presentation/chat_popmenu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/shared/markdown_to_document.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme_extension.dart';
Expand Down Expand Up @@ -183,7 +183,7 @@ class CopyButton extends StatelessWidget {
color: Theme.of(context).colorScheme.primary,
),
onPressed: () async {
final document = markdownToDocument(textMessage.text);
final document = customMarkdownToDocument(textMessage.text);
await getIt<ClipboardService>().setData(
ClipboardServiceData(
plainText: textMessage.text,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appflowy/plugins/document/presentation/editor_configuration.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/shared/markdown_to_document.dart';
import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flowy_infra/theme_extension.dart';
Expand Down Expand Up @@ -120,12 +121,7 @@ class _AppFlowyEditorMarkdownState extends State<_AppFlowyEditorMarkdown> {
}

EditorState _parseMarkdown(String markdown) {
final document = markdownToDocument(
markdown,
markdownParsers: [
const MarkdownCodeBlockParser(),
],
);
final document = customMarkdownToDocument(markdown);
final editorState = EditorState(document: document);
return editorState;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flutter/material.dart';
import 'package:percent_indicator/percent_indicator.dart';

import '../../application/cell/bloc/checklist_cell_bloc.dart';

class ChecklistProgressBar extends StatefulWidget {
Expand Down Expand Up @@ -68,7 +68,7 @@ class _ChecklistProgressBarState extends State<ChecklistProgressBar> {
),
),
SizedBox(
width: PlatformExtension.isDesktop ? 36 : 45,
width: 45,
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: Text(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import 'package:flutter/material.dart';
import 'dart:convert';

import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flutter/material.dart';

CodeBlockCopyBuilder codeBlockCopyBuilder =
(_, node) => _CopyButton(node: node);
Expand All @@ -28,16 +29,26 @@ class _CopyButton extends StatelessWidget {
message: LocaleKeys.document_codeBlock_copyTooltip.tr(),
child: FlowyIconButton(
onPressed: () async {
final delta = node.delta;
if (delta == null) {
return;
}

final document = Document.blank()
..insert([0], [node.copyWith()])
..toJson();

await getIt<ClipboardService>().setData(
ClipboardServiceData(
plainText: node.delta?.toPlainText(),
plainText: delta.toPlainText(),
inAppJson: jsonEncode(document.toJson()),
),
);

if (context.mounted) {
showSnackBarMessage(
showToastNotification(
context,
LocaleKeys.document_codeBlock_codeCopiedSnackbar.tr(),
message: LocaleKeys.document_codeBlock_codeCopiedSnackbar.tr(),
);
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:flutter/material.dart';

import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/editor_state_paste_node_extension.dart';
Expand All @@ -10,6 +8,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_p
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:string_validator/string_validator.dart';

Expand Down Expand Up @@ -54,6 +53,7 @@ CommandShortcutEventHandler _pasteCommandHandler = (editorState) {

// try to paste the content in order, if any of them is failed, then try the next one
if (inAppJson != null && inAppJson.isNotEmpty) {
debugPrint('paste in app json: $inAppJson');
await editorState.deleteSelectionIfNeeded();
if (await editorState.pasteInAppJson(inAppJson)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ class MarkdownCodeBlockParser extends CustomMarkdownParser {
language = languageClass.substring('language-'.length);
}

final deltaDecoder = DeltaMarkdownDecoder();

return [
codeBlockNode(
language: language,
delta: deltaDecoder.convertNodes(code.children),
delta: Delta()..insert(code.textContent.trimRight()),
),
];
}
Expand Down
11 changes: 11 additions & 0 deletions frontend/appflowy_flutter/lib/shared/markdown_to_document.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:appflowy/plugins/document/presentation/editor_plugins/parsers/markdown_code_parser.dart';
import 'package:appflowy_editor/appflowy_editor.dart';

Document customMarkdownToDocument(String markdown) {
return markdownToDocument(
markdown,
markdownParsers: [
const MarkdownCodeBlockParser(),
],
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/startup/startup.dart';

class WindowSizeManager {
static const double minWindowHeight = 600.0;
static const double minWindowWidth = 800.0;
static const double minWindowHeight = 640.0;
static const double minWindowWidth = 960.0;
// Preventing failed assertion due to Texture Descriptor Validation
static const double maxWindowHeight = 8192.0;
static const double maxWindowWidth = 8192.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import 'dart:io';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_data_pb_extension.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/migration/editor_migration.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/parsers/markdown_code_parser.dart';
import 'package:appflowy/shared/markdown_to_document.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/settings/share/import_service.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/import/import_type.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/file_picker/file_picker_service.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
Expand Down Expand Up @@ -221,12 +220,7 @@ class _ImportPanelState extends State<ImportPanel> {
Uint8List? _documentDataFrom(ImportType importType, String data) {
switch (importType) {
case ImportType.markdownOrText:
final document = markdownToDocument(
data,
markdownParsers: [
const MarkdownCodeBlockParser(),
],
);
final document = customMarkdownToDocument(data);
return DocumentDataPBFromTo.fromDocument(document)?.writeToBuffer();
case ImportType.historyDocument:
final document = EditorMigration.migrateDocument(data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
Expand Down Expand Up @@ -268,6 +269,22 @@ enum ConfirmPopupStyle {
cancelAndOk,
}

class ConfirmPopupColor {
static Color titleColor(BuildContext context) {
if (Theme.of(context).isLightMode) {
return const Color(0xFF171717).withOpacity(0.8);
}
return const Color(0xFFffffff).withOpacity(0.8);
}

static Color descriptionColor(BuildContext context) {
if (Theme.of(context).isLightMode) {
return const Color(0xFF171717).withOpacity(0.8);
}
return const Color(0xFFffffff).withOpacity(0.72);
}
}

class ConfirmPopup extends StatefulWidget {
const ConfirmPopup({
super.key,
Expand Down Expand Up @@ -328,6 +345,7 @@ class _ConfirmPopupState extends State<ConfirmPopup> {
widget.title,
fontSize: 14.0,
overflow: TextOverflow.ellipsis,
color: ConfirmPopupColor.titleColor(context),
),
),
const HSpace(6.0),
Expand All @@ -344,7 +362,7 @@ class _ConfirmPopupState extends State<ConfirmPopup> {
return FlowyText.regular(
widget.description,
fontSize: 12.0,
color: Theme.of(context).hintColor,
color: ConfirmPopupColor.descriptionColor(context),
maxLines: 3,
lineHeight: 1.4,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/util/color_to_hex_string.dart';
import 'package:appflowy/workspace/presentation/settings/shared/settings_alert_dialog.dart';
Expand Down Expand Up @@ -137,13 +138,19 @@ class DocumentColorSettingDialogState
onChanged: (_) => _updateSelectedColor(),
onFieldSubmitted: (_) => _updateSelectedColor(),
validator: (v) => validateHexValue(v, opacityController.text),
suffixIcon: GestureDetector(
onTap: () => _showColorPickerDialog(
context: context,
currentColor: widget.currentColor,
updateColor: _updateColor,
suffixIcon: Padding(
padding: const EdgeInsets.all(6.0),
child: FlowyIconButton(
onPressed: () => _showColorPickerDialog(
context: context,
currentColor: widget.currentColor,
updateColor: _updateColor,
),
icon: const FlowySvg(
FlowySvgs.m_aa_color_s,
size: Size.square(20),
),
),
child: const Icon(Icons.color_lens_rounded),
),
),
const VSpace(8),
Expand Down Expand Up @@ -378,7 +385,9 @@ void _showColorPickerDialog({
barrierColor: const Color.fromARGB(128, 0, 0, 0),
builder: (context) {
return AlertDialog(
icon: const Icon(Icons.palette),
icon: const FlowySvg(
FlowySvgs.m_aa_color_s,
),
title: Text(
title ??
LocaleKeys.settings_appearance_documentSettings_pickColor.tr(),
Expand Down
4 changes: 2 additions & 2 deletions frontend/appflowy_flutter/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: d2d9873
resolved-ref: d2d987312d3a667336c7e12c36da7dbbb62d66db
ref: e0d673a
resolved-ref: e0d673afbbbcaf9df0276f7e0b6405d8f6e98112
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
source: git
version: "3.1.0"
Expand Down
2 changes: 1 addition & 1 deletion frontend/appflowy_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ dependency_overrides:
appflowy_editor:
git:
url: https://github.com/AppFlowy-IO/appflowy-editor.git
ref: "d2d9873"
ref: "e0d673a"

appflowy_editor_plugins:
git:
Expand Down

0 comments on commit 552f135

Please sign in to comment.