Compare commits

..
Author SHA1 Message Date
Kilu d6e339158c fix: lazy load 2024-07-30 10:57:02 +08:00
Kilu 38784b9d73 fix: demond load outline 2024-07-29 22:44:05 +08:00
Kilu 49f8ae93c7 fix: replace appflowy icon 2024-07-29 22:32:13 +08:00
Kilu e323db2797 Merge branch 'fix/publish-view-bugs' into feat/support-global-comment-on-web 2024-07-29 22:29:30 +08:00
Kilu 7280d072f1 fix: global comments 2024-07-29 22:27:38 +08:00
Kilu 0ddabfa217 fix: text overflow 2024-07-25 14:41:02 +08:00
qinluhe 9d3a810847 fix: upgrade wasm package 2024-07-25 12:43:21 +08:00
qinluhe e0a70aa4d9 fix: adjust modal position 2024-07-24 14:38:00 +08:00
qinluhe 403fd2f5a0 fix: modified some copy 2024-07-24 12:30:00 +08:00
qinluhe 4976f870c8 fix: replace google svg 2024-07-24 10:31:54 +08:00
qinluhe 6fde3b9e3e feat: support duplicate UI on web 2024-07-24 10:22:35 +08:00
254 changed files with 4638 additions and 5049 deletions

No files matched your search

-18
View File
@@ -479,24 +479,6 @@ jobs:
cache-from: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/af_build_cache:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/af_build_cache:buildcache,mode=max
notify-failure:
runs-on: ubuntu-latest
needs:
- build-for-macOS-x86_64
- build-for-windows
- build-for-linux
if: failure()
steps:
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
text: |
🔴🔴🔴Workflow ${{ github.workflow }} in repository ${{ github.repository }} was failed 🔴🔴🔴.
fields: repo,message,author,eventName,ref,workflow
env:
SLACK_WEBHOOK_URL: ${{ secrets.RELEASE_SLACK_WEBHOOK }}
if: always()
notify-discord:
runs-on: ubuntu-latest
needs:
+25 -12
View File
@@ -12,8 +12,6 @@ env:
NODE_VERSION: "18.16.0"
PNPM_VERSION: "8.5.0"
RUST_TOOLCHAIN: "1.77.2"
CARGO_MAKE_VERSION: "0.36.6"
CI: true
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -24,6 +22,9 @@ jobs:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: self-hosted
env:
CI: true
steps:
- uses: actions/checkout@v4
- name: install frontend dependencies
@@ -48,11 +49,14 @@ jobs:
tauri-build-ubuntu:
if: github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
env:
CI: true
steps:
- uses: actions/checkout@v4
- name: Maximize build space
- name: Maximize build space (ubuntu only)
if: matrix.os == 'ubuntu-latest'
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
@@ -81,27 +85,36 @@ jobs:
override: true
profile: minimal
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: "./frontend/appflowy_web_app/src-tauri -> target"
- name: Node_modules cache
uses: actions/cache@v2
with:
path: frontend/appflowy_web_app/node_modules
key: node-modules-${{ runner.os }}
- name: install dependencies
- name: install dependencies (windows only)
if: matrix.os == 'windows-latest'
working-directory: frontend
run: |
cargo install --force duckscript_cli
vcpkg integrate install
- name: install dependencies (ubuntu only)
if: matrix.os == 'ubuntu-latest'
working-directory: frontend
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- uses: taiki-e/install-action@v2
with:
tool: cargo-make@${{ env.CARGO_MAKE_VERSION }}
- name: install tauri deps tools
- name: install cargo-make
working-directory: frontend
run: |
cargo install --force cargo-make
cargo make appflowy-tauri-deps-tools
shell: bash
- name: install frontend dependencies
working-directory: frontend/appflowy_web_app
+1 -1
View File
@@ -26,7 +26,7 @@ CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CARGO_MAKE_CRATE_FS_NAME = "dart_ffi"
CARGO_MAKE_CRATE_NAME = "dart-ffi"
LIB_NAME = "dart_ffi"
APPFLOWY_VERSION = "0.6.6"
APPFLOWY_VERSION = "0.6.5"
FLUTTER_DESKTOP_FEATURES = "dart"
PRODUCT_NAME = "AppFlowy"
MACOSX_DEPLOYMENT_TARGET = "11.0"
@@ -42,7 +42,7 @@ void main() {
await tester.tapAnonymousSignInButton();
await tester.expectToSeeHomePageWithGetStartedPage();
// rename the name of the anon user
// reanme the name of the anon user
await tester.openSettings();
await tester.openSettingsPage(SettingsPage.account);
await tester.pumpAndSettle();
@@ -16,8 +16,6 @@ import 'document_with_image_block_test.dart' as document_with_image_block_test;
import 'document_with_inline_math_equation_test.dart'
as document_with_inline_math_equation_test;
import 'document_with_inline_page_test.dart' as document_with_inline_page_test;
import 'document_with_multi_image_block_test.dart'
as document_with_multi_image_block_test;
import 'document_with_outline_block_test.dart' as document_with_outline_block;
import 'document_with_toggle_list_test.dart' as document_with_toggle_list_test;
import 'edit_document_test.dart' as document_edit_test;
@@ -40,7 +38,6 @@ void startTesting() {
document_text_direction_test.main();
document_option_action_test.main();
document_with_image_block_test.main();
document_with_multi_image_block_test.main();
document_inline_page_reference_test.main();
document_more_actions_test.main();
}
@@ -1,22 +1,21 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/core/config/kv.dart';
import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/embed_image_url_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_placeholder.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/resizeable_image.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/unsplash_image_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/embed_image_url_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy_editor/appflowy_editor.dart'
hide UploadImageMenu, ResizableImage;
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:path/path.dart' as p;
@@ -37,7 +36,7 @@ void main() {
// create a new document
await tester.createNewPageWithNameUnderParent(
name: LocaleKeys.document_plugins_image_addAnImageDesktop.tr(),
name: LocaleKeys.document_plugins_image_addAnImage.tr(),
);
// tap the first line of the document
@@ -85,7 +84,7 @@ void main() {
// create a new document
await tester.createNewPageWithNameUnderParent(
name: LocaleKeys.document_plugins_image_addAnImageDesktop.tr(),
name: LocaleKeys.document_plugins_image_addAnImage.tr(),
);
// tap the first line of the document
@@ -138,7 +137,7 @@ void main() {
// create a new document
await tester.createNewPageWithNameUnderParent(
name: LocaleKeys.document_plugins_image_addAnImageDesktop.tr(),
name: LocaleKeys.document_plugins_image_addAnImage.tr(),
);
// tap the first line of the document
@@ -162,67 +161,5 @@ void main() {
expect(find.byType(UnsplashImageWidget), findsOneWidget);
});
});
testWidgets('insert two images from local file at once', (tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();
// create a new document
await tester.createNewPageWithNameUnderParent(
name: LocaleKeys.document_plugins_image_addAnImageDesktop.tr(),
);
// tap the first line of the document
await tester.editor.tapLineOfEditorAt(0);
await tester.editor.showSlashMenu();
await tester.editor.tapSlashMenuItemWithName('Image');
expect(find.byType(CustomImageBlockComponent), findsOneWidget);
expect(find.byType(ImagePlaceholder), findsOneWidget);
expect(
find.descendant(
of: find.byType(ImagePlaceholder),
matching: find.byType(AppFlowyPopover),
),
findsOneWidget,
);
expect(find.byType(UploadImageMenu), findsOneWidget);
final firstImage =
await rootBundle.load('assets/test/images/sample.jpeg');
final secondImage =
await rootBundle.load('assets/test/images/sample.gif');
final tempDirectory = await getTemporaryDirectory();
final firstImagePath = p.join(tempDirectory.path, 'sample.jpeg');
final firstFile = File(firstImagePath)
..writeAsBytesSync(firstImage.buffer.asUint8List());
final secondImagePath = p.join(tempDirectory.path, 'sample.gif');
final secondFile = File(secondImagePath)
..writeAsBytesSync(secondImage.buffer.asUint8List());
mockPickFilePaths(paths: [firstImagePath, secondImagePath]);
await getIt<KeyValueStorage>().set(KVKeys.kCloudType, '0');
await tester.tapButtonWithName(
LocaleKeys.document_imageBlock_upload_placeholder.tr(),
);
await tester.pumpAndSettle();
expect(find.byType(ResizableImage), findsNWidgets(2));
final firstNode =
tester.editor.getCurrentEditorState().getNodeAtPath([0])!;
expect(firstNode.type, ImageBlockKeys.type);
expect(firstNode.attributes[ImageBlockKeys.url], isNotEmpty);
final secondNode =
tester.editor.getCurrentEditorState().getNodeAtPath([0])!;
expect(secondNode.type, ImageBlockKeys.type);
expect(secondNode.attributes[ImageBlockKeys.url], isNotEmpty);
// remove the temp files
await Future.wait([firstFile.delete(), secondFile.delete()]);
});
});
}
@@ -1,287 +0,0 @@
import 'dart:io';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/core/config/kv.dart';
import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_placeholder.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_layouts.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/embed_image_url_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/shared/appflowy_network_image.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_toolbar.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_viewer.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import '../../shared/mock/mock_file_picker.dart';
import '../../shared/util.dart';
import '../board/board_hide_groups_test.dart';
void main() {
setUp(() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
TestWidgetsFlutterBinding.ensureInitialized();
});
group('multi image block in document', () {
testWidgets('insert images from local and use interactive viewer',
(tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();
// create a new document
await tester.createNewPageWithNameUnderParent(
name: 'multi image block test',
);
// tap the first line of the document
await tester.editor.tapLineOfEditorAt(0);
await tester.editor.showSlashMenu();
await tester.editor.tapSlashMenuItemWithName('Photo gallery');
expect(find.byType(MultiImageBlockComponent), findsOneWidget);
expect(find.byType(MultiImagePlaceholder), findsOneWidget);
await tester.tap(find.byType(MultiImagePlaceholder));
await tester.pumpAndSettle();
expect(find.byType(UploadImageMenu), findsOneWidget);
final firstImage =
await rootBundle.load('assets/test/images/sample.jpeg');
final secondImage =
await rootBundle.load('assets/test/images/sample.gif');
final tempDirectory = await getTemporaryDirectory();
final firstImagePath = p.join(tempDirectory.path, 'sample.jpeg');
final firstFile = File(firstImagePath)
..writeAsBytesSync(firstImage.buffer.asUint8List());
final secondImagePath = p.join(tempDirectory.path, 'sample.gif');
final secondFile = File(secondImagePath)
..writeAsBytesSync(secondImage.buffer.asUint8List());
mockPickFilePaths(paths: [firstImagePath, secondImagePath]);
await getIt<KeyValueStorage>().set(KVKeys.kCloudType, '0');
await tester.tapButtonWithName(
LocaleKeys.document_imageBlock_upload_placeholder.tr(),
);
await tester.pumpAndSettle();
expect(find.byType(ImageBrowserLayout), findsOneWidget);
final node = tester.editor.getCurrentEditorState().getNodeAtPath([0])!;
expect(node.type, MultiImageBlockKeys.type);
final data = MultiImageData.fromJson(
node.attributes[MultiImageBlockKeys.images],
);
expect(data.images.length, 2);
// Start using the interactive viewer to view the image(s)
final imageFinder = find
.byWidgetPredicate(
(w) =>
w is Image &&
w.image is FileImage &&
(w.image as FileImage).file.path.endsWith('.jpeg'),
)
.first;
await tester.tap(imageFinder);
await tester.pump(kDoubleTapMinTime);
await tester.tap(imageFinder);
await tester.pumpAndSettle();
final ivFinder = find.byType(InteractiveImageViewer);
expect(ivFinder, findsOneWidget);
// go to next image
await tester.tap(find.byFlowySvg(FlowySvgs.arrow_right_s));
await tester.pumpAndSettle();
// Expect image to end with .gif
final gifImageFinder = find.byWidgetPredicate(
(w) =>
w is Image &&
w.image is FileImage &&
(w.image as FileImage).file.path.endsWith('.gif'),
);
gifImageFinder.evaluate();
expect(gifImageFinder.found.length, 2);
// go to previous image
await tester.tap(find.byFlowySvg(FlowySvgs.arrow_left_s));
await tester.pumpAndSettle();
gifImageFinder.evaluate();
expect(gifImageFinder.found.length, 1);
// remove the temp files
await Future.wait([firstFile.delete(), secondFile.delete()]);
});
testWidgets('insert and delete images from network', (tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();
// create a new document
await tester.createNewPageWithNameUnderParent(
name: 'multi image block test',
);
// tap the first line of the document
await tester.editor.tapLineOfEditorAt(0);
await tester.editor.showSlashMenu();
await tester.editor.tapSlashMenuItemWithName('Photo gallery');
expect(find.byType(MultiImageBlockComponent), findsOneWidget);
expect(find.byType(MultiImagePlaceholder), findsOneWidget);
await tester.tap(find.byType(MultiImagePlaceholder));
await tester.pumpAndSettle();
expect(find.byType(UploadImageMenu), findsOneWidget);
await tester.tapButtonWithName(
LocaleKeys.document_imageBlock_embedLink_label.tr(),
);
const url =
'https://images.unsplash.com/photo-1469474968028-56623f02e42e?ixlib=rb-4.0.3&q=85&fm=jpg&crop=entropy&cs=srgb&dl=david-marcu-78A265wPiO4-unsplash.jpg&w=640';
await tester.enterText(
find.descendant(
of: find.byType(EmbedImageUrlWidget),
matching: find.byType(TextField),
),
url,
);
await tester.pumpAndSettle();
await tester.tapButton(
find.descendant(
of: find.byType(EmbedImageUrlWidget),
matching: find.text(
LocaleKeys.document_imageBlock_embedLink_label.tr(),
findRichText: true,
),
),
);
await tester.pumpAndSettle();
expect(find.byType(ImageBrowserLayout), findsOneWidget);
final node = tester.editor.getCurrentEditorState().getNodeAtPath([0])!;
expect(node.type, MultiImageBlockKeys.type);
final data = MultiImageData.fromJson(
node.attributes[MultiImageBlockKeys.images],
);
expect(data.images.length, 1);
final imageFinder = find
.byWidgetPredicate(
(w) => w is FlowyNetworkImage && w.url == url,
)
.first;
// Insert two images from network
for (int i = 0; i < 2; i++) {
// Hover on the image to show the image toolbar
await tester.hoverOnWidget(
imageFinder,
onHover: () async {
// Click on the add
final addFinder = find.descendant(
of: find.byType(MultiImageMenu),
matching: find.byFlowySvg(FlowySvgs.add_s),
);
expect(addFinder, findsOneWidget);
await tester.tap(addFinder);
await tester.pumpAndSettle();
await tester.tapButtonWithName(
LocaleKeys.document_imageBlock_embedLink_label.tr(),
);
await tester.enterText(
find.descendant(
of: find.byType(EmbedImageUrlWidget),
matching: find.byType(TextField),
),
url,
);
await tester.pumpAndSettle();
await tester.tapButton(
find.descendant(
of: find.byType(EmbedImageUrlWidget),
matching: find.text(
LocaleKeys.document_imageBlock_embedLink_label.tr(),
findRichText: true,
),
),
);
await tester.pumpAndSettle();
},
);
}
await tester.pumpAndSettle();
// There should be 4 images visible now, where 2 are thumbnails
expect(find.byType(ThumbnailItem), findsNWidgets(3));
// And all three use ImageRender
expect(find.byType(ImageRender), findsNWidgets(4));
// Hover on and delete the first thumbnail image
await tester.hoverOnWidget(find.byType(ThumbnailItem).first);
final deleteFinder = find
.descendant(
of: find.byType(ThumbnailItem),
matching: find.byFlowySvg(FlowySvgs.delete_s),
)
.first;
expect(deleteFinder, findsOneWidget);
await tester.tap(deleteFinder);
await tester.pumpAndSettle();
expect(find.byType(ImageRender), findsNWidgets(3));
// Delete one from interactive viewer
await tester.tap(imageFinder);
await tester.pump(kDoubleTapMinTime);
await tester.tap(imageFinder);
await tester.pumpAndSettle();
final ivFinder = find.byType(InteractiveImageViewer);
expect(ivFinder, findsOneWidget);
await tester.tap(
find.descendant(
of: find.byType(InteractiveImageToolbar),
matching: find.byFlowySvg(FlowySvgs.delete_s),
),
);
await tester.pumpAndSettle();
expect(find.byType(InteractiveImageViewer), findsNothing);
// There should be 1 image and the thumbnail for said image still visible
expect(find.byType(ImageRender), findsNWidgets(2));
});
});
}
@@ -1,9 +1,6 @@
import 'dart:async';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/base/emoji/emoji_picker.dart';
import 'package:appflowy/plugins/base/emoji/emoji_skin_tone.dart';
@@ -13,10 +10,12 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/bl
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/cover_editor.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/embed_image_url_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/embed_image_url_widget.dart';
import 'package:appflowy/plugins/inline_actions/widgets/inline_actions_handler.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_emoji_mart/flutter_emoji_mart.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -1,14 +1,16 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/window_title_bar.dart';
import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class CocoaWindowChannel {
@@ -102,17 +104,19 @@ class MoveWindowDetectorState extends State<MoveWindowDetector> {
return const SizedBox.shrink();
}
final color = Theme.of(context).isLightMode ? Colors.white : Colors.black;
final textSpan = TextSpan(
children: [
TextSpan(
text: '${LocaleKeys.sideBar_openSidebar.tr()}\n',
style: context.tooltipTextStyle(),
style: Theme.of(context).textTheme.bodyMedium!.copyWith(color: color),
),
TextSpan(
text: Platform.isMacOS ? '⌘+.' : 'Ctrl+\\',
style: context
.tooltipTextStyle()
?.copyWith(color: Theme.of(context).hintColor),
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: Theme.of(context).hintColor),
),
],
);
@@ -17,7 +17,7 @@ class ChatAIMessageBloc extends Bloc<ChatAIMessageEvent, ChatAIMessageState> {
required this.questionId,
}) : super(ChatAIMessageState.initial(message)) {
if (state.stream != null) {
state.stream!.listen(
_subscription = state.stream!.listen(
onData: (text) {
if (!isClosed) {
add(ChatAIMessageEvent.updateText(text));
@@ -108,6 +108,13 @@ class ChatAIMessageBloc extends Bloc<ChatAIMessageEvent, ChatAIMessageState> {
);
}
@override
Future<void> close() {
_subscription?.cancel();
return super.close();
}
StreamSubscription<String>? _subscription;
final String chatId;
final Int64? questionId;
}
@@ -586,7 +586,7 @@ class AnswerStream {
_port.close();
}
void listen({
StreamSubscription<String> listen({
void Function(String text)? onData,
void Function()? onStart,
void Function()? onEnd,
@@ -602,5 +602,7 @@ class AnswerStream {
if (_onStart != null) {
_onStart!();
}
return _subscription;
}
}
@@ -1,5 +1,3 @@
import 'dart:async';
import 'package:appflowy/workspace/application/settings/ai/local_llm_listener.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
@@ -15,11 +13,6 @@ class ChatFileBloc extends Bloc<ChatFileEvent, ChatFileState> {
}) : listener = LocalLLMListener(),
super(const ChatFileState()) {
listener.start(
stateCallback: (pluginState) {
if (!isClosed) {
add(ChatFileEvent.updatePluginState(pluginState));
}
},
chatStateCallback: (chatState) {
if (!isClosed) {
add(ChatFileEvent.updateChatState(chatState));
@@ -45,55 +38,18 @@ class ChatFileBloc extends Bloc<ChatFileEvent, ChatFileState> {
},
);
},
newFile: (String filePath, String fileName) async {
emit(
state.copyWith(
indexFileIndicator: IndexFileIndicator.indexing(fileName),
),
);
newFile: (String filePath) {
final payload = ChatFilePB(filePath: filePath, chatId: chatId);
unawaited(
ChatEventChatWithFile(payload).send().then((result) {
if (!isClosed) {
result.fold((_) {
add(
ChatFileEvent.updateIndexFile(
IndexFileIndicator.finish(fileName),
),
);
}, (err) {
add(
ChatFileEvent.updateIndexFile(
IndexFileIndicator.error(err.msg),
),
);
});
}
}),
);
ChatEventChatWithFile(payload).send();
},
updateChatState: (LocalAIChatPB chatState) {
// Only user enable chat with file and the plugin is already running
final supportChatWithFile = chatState.fileEnabled &&
chatState.pluginState.state == RunningStatePB.Running;
emit(
state.copyWith(
supportChatWithFile: supportChatWithFile,
chatState: chatState,
),
state.copyWith(supportChatWithFile: supportChatWithFile),
);
},
updateIndexFile: (IndexFileIndicator indicator) {
emit(
state.copyWith(indexFileIndicator: indicator),
);
},
updatePluginState: (LocalAIPluginStatePB chatState) {
final fileEnabled = state.chatState?.fileEnabled ?? false;
final supportChatWithFile =
fileEnabled && chatState.state == RunningStatePB.Running;
emit(state.copyWith(supportChatWithFile: supportChatWithFile));
},
);
},
);
@@ -111,29 +67,20 @@ class ChatFileBloc extends Bloc<ChatFileEvent, ChatFileState> {
@freezed
class ChatFileEvent with _$ChatFileEvent {
const factory ChatFileEvent.initial() = Initial;
const factory ChatFileEvent.newFile(String filePath, String fileName) =
_NewFile;
const factory ChatFileEvent.newFile(String filePath) = _NewFile;
const factory ChatFileEvent.updateChatState(LocalAIChatPB chatState) =
_UpdateChatState;
const factory ChatFileEvent.updatePluginState(
LocalAIPluginStatePB chatState,
) = _UpdatePluginState;
const factory ChatFileEvent.updateIndexFile(IndexFileIndicator indicator) =
_UpdateIndexFile;
}
@freezed
class ChatFileState with _$ChatFileState {
const factory ChatFileState({
@Default(false) bool supportChatWithFile,
IndexFileIndicator? indexFileIndicator,
LocalAIChatPB? chatState,
}) = _ChatFileState;
}
@freezed
class IndexFileIndicator with _$IndexFileIndicator {
const factory IndexFileIndicator.finish(String fileName) = _Finish;
const factory IndexFileIndicator.indexing(String fileName) = _Indexing;
const factory IndexFileIndicator.error(String error) = _Error;
class LocalAIChatFileIndicator with _$LocalAIChatFileIndicator {
const factory LocalAIChatFileIndicator.ready(bool isEnabled) = _Ready;
const factory LocalAIChatFileIndicator.loading() = _Loading;
}
@@ -1,7 +1,5 @@
import 'package:appflowy/plugins/ai_chat/application/chat_file_bloc.dart';
import 'package:appflowy/plugins/ai_chat/application/chat_input_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -73,8 +71,7 @@ class AIChatPage extends StatelessWidget {
return MultiBlocProvider(
providers: [
BlocProvider(
create: (_) => ChatFileBloc(chatId: view.id.toString())
..add(const ChatFileEvent.initial()),
create: (_) => ChatFileBloc(chatId: view.id.toString()),
),
BlocProvider(
create: (_) => ChatBloc(
@@ -84,40 +81,28 @@ class AIChatPage extends StatelessWidget {
),
BlocProvider(create: (_) => ChatInputBloc()),
],
child: BlocListener<ChatFileBloc, ChatFileState>(
listenWhen: (previous, current) =>
previous.indexFileIndicator != current.indexFileIndicator,
listener: (context, state) {
_handleIndexIndicator(state.indexFileIndicator, context);
},
child: BlocBuilder<ChatFileBloc, ChatFileState>(
builder: (context, state) {
return DropTarget(
child: BlocBuilder<ChatFileBloc, ChatFileState>(
builder: (context, state) {
Widget child = _ChatContentPage(
view: view,
userProfile: userProfile,
);
// If the chat supports file upload, wrap the chat content with a drop target
if (state.supportChatWithFile) {
child = DropTarget(
onDragDone: (DropDoneDetails detail) async {
if (state.supportChatWithFile) {
await showConfirmDialog(
context: context,
style: ConfirmPopupStyle.cancelAndOk,
title: LocaleKeys.chat_chatWithFilePrompt.tr(),
confirmLabel: LocaleKeys.button_confirm.tr(),
onConfirm: () {
for (final file in detail.files) {
context
.read<ChatFileBloc>()
.add(ChatFileEvent.newFile(file.path, file.name));
}
},
description: '',
);
for (final file in detail.files) {
context
.read<ChatFileBloc>()
.add(ChatFileEvent.newFile(file.path));
}
},
child: _ChatContentPage(
view: view,
userProfile: userProfile,
),
child: child,
);
},
),
}
return child;
},
),
);
}
@@ -129,35 +114,6 @@ class AIChatPage extends StatelessWidget {
),
);
}
void _handleIndexIndicator(
IndexFileIndicator? indicator,
BuildContext context,
) {
if (indicator != null) {
indicator.when(
finish: (fileName) {
showSnackBarMessage(
context,
LocaleKeys.chat_indexFileSuccess.tr(args: [fileName]),
);
},
indexing: (fileName) {
showSnackBarMessage(
context,
LocaleKeys.chat_indexingFile.tr(args: [fileName]),
duration: const Duration(seconds: 2),
);
},
error: (err) {
showSnackBarMessage(
context,
err,
);
},
);
}
}
}
class _ChatContentPage extends StatefulWidget {
@@ -67,7 +67,8 @@ class _ChatInputState extends State<ChatInput> {
void initState() {
super.initState();
_textController = InputTextFieldController();
_textController =
widget.options.textEditingController ?? InputTextFieldController();
_handleSendButtonVisibilityModeChange();
}
@@ -84,7 +85,9 @@ class _ChatInputState extends State<ChatInput> {
final partialText = types.PartialText(text: trimmedText);
widget.onSendPressed(partialText);
_textController.clear();
if (widget.options.inputClearMode == InputClearMode.always) {
_textController.clear();
}
}
}
@@ -103,6 +106,7 @@ class _ChatInputState extends State<ChatInput> {
const inputPadding = EdgeInsets.all(6);
return Focus(
autofocus: !widget.options.autofocus,
child: Padding(
padding: inputPadding,
child: Material(
@@ -144,11 +148,15 @@ class _ChatInputState extends State<ChatInput> {
style: TextStyle(
color: AFThemeExtension.of(context).textColor,
),
keyboardType: TextInputType.multiline,
autocorrect: widget.options.autocorrect,
autofocus: widget.options.autofocus,
enableSuggestions: widget.options.enableSuggestions,
keyboardType: widget.options.keyboardType,
textCapitalization: TextCapitalization.sentences,
maxLines: 10,
minLines: 1,
onChanged: (_) {},
onChanged: widget.options.onTextChanged,
onTap: widget.options.onTextFieldTap,
),
);
}
@@ -199,6 +207,53 @@ class _ChatInputState extends State<ChatInput> {
);
}
@immutable
class InputOptions {
const InputOptions({
this.inputClearMode = InputClearMode.always,
this.keyboardType = TextInputType.multiline,
this.onTextChanged,
this.onTextFieldTap,
this.textEditingController,
this.autocorrect = true,
this.autofocus = false,
this.enableSuggestions = true,
this.enabled = true,
});
/// Controls the [ChatInput] clear behavior. Defaults to [InputClearMode.always].
final InputClearMode inputClearMode;
/// Controls the [ChatInput] keyboard type. Defaults to [TextInputType.multiline].
final TextInputType keyboardType;
/// Will be called whenever the text inside [TextField] changes.
final void Function(String)? onTextChanged;
/// Will be called on [TextField] tap.
final VoidCallback? onTextFieldTap;
/// Custom [TextEditingController]. If not provided, defaults to the
/// [InputTextFieldController], which extends [TextEditingController] and has
/// additional fatures like markdown support. If you want to keep additional
/// features but still need some methods from the default [TextEditingController],
/// you can create your own [InputTextFieldController] (imported from this lib)
/// and pass it here.
final TextEditingController? textEditingController;
/// Controls the [TextInput] autocorrect behavior. Defaults to [true].
final bool autocorrect;
/// Whether [TextInput] should have focus. Defaults to [false].
final bool autofocus;
/// Controls the [TextInput] enableSuggestions behavior. Defaults to [true].
final bool enableSuggestions;
/// Controls the [TextInput] enabled behavior. Defaults to [true].
final bool enabled;
}
final isMobile = defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS;
@@ -6,6 +6,7 @@ import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter/material.dart';
class RelatedQuestionList extends StatelessWidget {
const RelatedQuestionList({
required this.chatId,
@@ -96,7 +97,6 @@ class _RelatedQuestionItemState extends State<RelatedQuestionItem> {
style: TextStyle(
color: _isHovered ? Theme.of(context).colorScheme.primary : null,
fontSize: 14,
height: 1.5,
),
),
onTap: () {
@@ -52,6 +52,15 @@ class _AppFlowyEditorMarkdown extends StatefulWidget {
class _AppFlowyEditorMarkdownState extends State<_AppFlowyEditorMarkdown> {
late EditorState editorState;
late final styleCustomizer = EditorStyleCustomizer(
context: context,
padding: EdgeInsets.zero,
);
late final editorStyle = styleCustomizer.style().copyWith(
// hide the cursor
cursorColor: Colors.transparent,
cursorWidth: 0,
);
late EditorScrollController scrollController;
@override
@@ -90,17 +99,6 @@ class _AppFlowyEditorMarkdownState extends State<_AppFlowyEditorMarkdown> {
@override
Widget build(BuildContext context) {
// don't lazy load the styleCustomizer and blockBuilders,
// it needs the context to get the theme.
final styleCustomizer = EditorStyleCustomizer(
context: context,
padding: EdgeInsets.zero,
);
final editorStyle = styleCustomizer.style().copyWith(
// hide the cursor
cursorColor: Colors.transparent,
cursorWidth: 0,
);
final blockBuilders = getEditorBuilderMap(
context: context,
editorState: editorState,
@@ -1,3 +1,5 @@
import 'package:flutter/material.dart';
import 'package:appflowy/plugins/database/application/calculations/calculation_type_ext.dart';
import 'package:appflowy/plugins/database/application/field/field_info.dart';
import 'package:appflowy/plugins/database/application/field/type_option/number_format_bloc.dart';
@@ -14,7 +16,6 @@ import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class CalculateCell extends StatefulWidget {
@@ -140,14 +141,11 @@ class _CalculateCellState extends State<CalculateCell> {
TextSpan(
text: widget.calculation!.calculationType.shortLabel
.toUpperCase(),
style: context.tooltipTextStyle(),
),
const TextSpan(text: ' '),
TextSpan(
text: calculateValue,
style: context
.tooltipTextStyle()
?.copyWith(fontWeight: FontWeight.w500),
style: const TextStyle(fontWeight: FontWeight.w500),
),
],
),
@@ -6,10 +6,7 @@ import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/banner.dart';
import 'package:appflowy/plugins/document/presentation/editor_notification.dart';
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_image.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/cover/document_immersive_cover.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/startup/startup.dart';
@@ -19,17 +16,10 @@ import 'package:appflowy/workspace/application/view/prelude.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:desktop_drop/desktop_drop.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/widget/error_page.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
const _excludeFromDropTarget = [
ImageBlockKeys.type,
CustomImageBlockKeys.type,
MultiImageBlockKeys.type,
];
class DocumentPage extends StatefulWidget {
const DocumentPage({
super.key,
@@ -135,62 +125,15 @@ class _DocumentPageState extends State<DocumentPage>
},
);
} else {
child = DropTarget(
onDragExited: (_) =>
state.editorState!.selectionService.removeDropTarget(),
onDragUpdated: (details) {
final data = state.editorState!.selectionService
.getDropTargetRenderData(details.globalPosition);
if (data != null &&
data.dropTarget != null &&
// We implement custom Drop logic for image blocks, this is
// how we can exclude them from the Drop Target
!_excludeFromDropTarget.contains(data.cursorNode?.type)) {
// Render the drop target
state.editorState!.selectionService
.renderDropTargetForOffset(details.globalPosition);
} else {
state.editorState!.selectionService.removeDropTarget();
}
},
onDragDone: (details) async {
state.editorState!.selectionService.removeDropTarget();
final data = state.editorState!.selectionService
.getDropTargetRenderData(details.globalPosition);
if (data != null) {
if (data.cursorNode != null) {
if ([
ImageBlockKeys.type,
CustomImageBlockKeys.type,
MultiImageBlockKeys.type,
].contains(data.cursorNode?.type)) {
return;
}
final isLocalMode = context.read<DocumentBloc>().isLocalMode;
await editorState!.dropImages(
data.dropTarget!,
details.files,
widget.view.id,
isLocalMode,
);
}
}
},
child: AppFlowyEditorPage(
editorState: state.editorState!,
styleCustomizer: EditorStyleCustomizer(
context: context,
// the 44 is the width of the left action list
padding: EditorStyleCustomizer.documentPadding,
),
header: _buildCoverAndIcon(context, state),
initialSelection: widget.initialSelection,
child = AppFlowyEditorPage(
editorState: state.editorState!,
styleCustomizer: EditorStyleCustomizer(
context: context,
// the 44 is the width of the left action list
padding: EditorStyleCustomizer.documentPadding,
),
header: _buildCoverAndIcon(context, state),
initialSelection: widget.initialSelection,
);
}
@@ -1,20 +1,17 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/code_block/code_block_copy_button.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:easy_localization/easy_localization.dart' hide TextDirection;
import 'package:flowy_infra/theme_extension.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Map<String, BlockComponentBuilder> getEditorBuilderMap({
@@ -110,31 +107,11 @@ Map<String, BlockComponentBuilder> getEditorBuilderMap({
ImageBlockKeys.type: CustomImageBlockComponentBuilder(
configuration: configuration,
showMenu: true,
menuBuilder: (node, state) => Positioned(
top: 10,
right: 10,
child: ImageMenu(node: node, state: state),
),
),
MultiImageBlockKeys.type: MultiImageBlockComponentBuilder(
configuration: configuration,
showMenu: true,
menuBuilder: (
Node node,
MultiImageBlockComponentState state,
ValueNotifier<int> indexNotifier,
VoidCallback onImageDeleted,
) =>
menuBuilder: (Node node, CustomImageBlockComponentState state) =>
Positioned(
top: 10,
right: 10,
child: MultiImageMenu(
node: node,
state: state,
indexNotifier: indexNotifier,
isLocalMode: context.read<DocumentBloc>().isLocalMode,
onImageDeleted: onImageDeleted,
),
child: ImageMenu(node: node, state: state),
),
),
TableBlockKeys.type: TableBlockComponentBuilder(
@@ -1,8 +1,5 @@
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_configuration.dart';
@@ -31,6 +28,8 @@ import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
final codeBlockLocalization = CodeBlockLocalizations(
@@ -353,10 +352,6 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
},
child: VSpace(PlatformExtension.isDesktopOrWeb ? 200 : 400),
),
dropTargetStyle: AppFlowyDropTargetStyle(
color: Theme.of(context).colorScheme.primary.withOpacity(0.8),
margin: const EdgeInsets.only(left: 44),
),
),
);
@@ -420,7 +415,6 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
emojiMenuItem,
autoGeneratorMenuItem,
dateMenuItem,
multiImageMenuItem,
];
}
@@ -91,8 +91,10 @@ class _AlignmentButtonsState extends State<_AlignmentButtons> {
margin: const EdgeInsets.all(4),
direction: PopoverDirection.bottomWithCenterAligned,
offset: const Offset(0, 10),
decorationColor: Theme.of(context).colorScheme.onTertiary,
borderRadius: const BorderRadius.all(Radius.circular(4)),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.onTertiary,
borderRadius: const BorderRadius.all(Radius.circular(4)),
),
popupBuilder: (_) {
keepEditorFocusNotifier.increase();
return _AlignButtons(onAlignChanged: widget.onAlignChanged);
@@ -3,16 +3,12 @@ import 'dart:typed_data';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_util.dart';
import 'package:appflowy/shared/patterns/common_patterns.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/settings/application_data_storage.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:cross_file/cross_file.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/uuid.dart';
import 'package:path/path.dart' as p;
@@ -25,42 +21,6 @@ extension PasteFromImage on EditorState {
'gif',
];
Future<void> dropImages(
Node dropNode,
List<XFile> files,
String documentId,
bool isLocalMode,
) async {
final imageFiles = files.where(
(file) =>
file.mimeType?.startsWith('image/') ??
false || imgExtensionRegex.hasMatch(file.name),
);
for (final file in imageFiles) {
String? path;
CustomImageType? type;
if (isLocalMode) {
path = await saveImageToLocalStorage(file.path);
type = CustomImageType.local;
} else {
(path, _) = await saveImageToCloudStorage(file.path, documentId);
type = CustomImageType.internal;
}
if (path == null) {
continue;
}
final t = transaction
..insertNode(
dropNode.path,
customImageNode(url: path, type: type),
);
await apply(t);
}
}
Future<bool> pasteImage(
String format,
Uint8List imageBytes,
@@ -1,7 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
@@ -11,9 +9,9 @@ import 'package:appflowy/plugins/base/icon/icon_picker.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/desktop_cover.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_util.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/migration/editor_migration.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/shared/appflowy_network_image.dart';
@@ -25,6 +23,7 @@ import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/widget/rounded_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:string_validator/string_validator.dart';
@@ -483,12 +482,9 @@ class DocumentCoverState extends State<DocumentCover> {
UploadImageType.url,
UploadImageType.unsplash,
],
onSelectedLocalImages: (paths) async {
onSelectedLocalImage: (path) async {
context.pop();
widget.onChangeCover(
CoverType.file,
paths.first,
);
widget.onChangeCover(CoverType.file, path);
},
onSelectedAIImage: (_) {
throw UnimplementedError();
@@ -612,9 +608,9 @@ class DocumentCoverState extends State<DocumentCover> {
UploadImageType.url,
UploadImageType.unsplash,
],
onSelectedLocalImages: (paths) {
onSelectedLocalImage: (path) {
popoverController.close();
onCoverChanged(CoverType.file, paths.first);
onCoverChanged(CoverType.file, path);
},
onSelectedAIImage: (_) {
throw UnimplementedError();
@@ -1,64 +0,0 @@
import 'dart:io';
import 'package:flutter/widgets.dart';
enum CustomImageType {
local,
internal, // the images saved in self-host cloud
external; // the images linked from network, like unsplash, https://xxx/yyy/zzz.jpg
static CustomImageType fromIntValue(int value) {
switch (value) {
case 0:
return CustomImageType.local;
case 1:
return CustomImageType.internal;
case 2:
return CustomImageType.external;
default:
throw UnimplementedError();
}
}
int toIntValue() {
switch (this) {
case CustomImageType.local:
return 0;
case CustomImageType.internal:
return 1;
case CustomImageType.external:
return 2;
}
}
}
class ImageBlockData {
factory ImageBlockData.fromJson(Map<String, dynamic> json) {
return ImageBlockData(
url: json['url'] as String? ?? '',
type: CustomImageType.fromIntValue(json['type'] as int),
);
}
ImageBlockData({required this.url, required this.type});
final String url;
final CustomImageType type;
bool get isLocal => type == CustomImageType.local;
bool get isNotInternal => type != CustomImageType.internal;
Map<String, dynamic> toJson() {
return {'url': url, 'type': type.toIntValue()};
}
ImageProvider toImageProvider() {
switch (type) {
case CustomImageType.internal:
case CustomImageType.external:
return NetworkImage(url);
case CustomImageType.local:
return FileImage(File(url));
}
}
}
@@ -4,28 +4,53 @@ import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/widgets/flowy_option_tile.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/mobile/presentation/widgets/widgets.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/unsupport_image_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_placeholder.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/resizeable_image.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/unsupport_image_widget.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/string_extension.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/image_provider.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_viewer.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide ResizableImage;
import 'package:easy_localization/easy_localization.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:string_validator/string_validator.dart';
import '../common.dart';
const kImagePlaceholderKey = 'imagePlaceholderKey';
enum CustomImageType {
local,
internal, // the images saved in self-host cloud
external; // the images linked from network, like unsplash, https://xxx/yyy/zzz.jpg
static CustomImageType fromIntValue(int value) {
switch (value) {
case 0:
return CustomImageType.local;
case 1:
return CustomImageType.internal;
case 2:
return CustomImageType.external;
default:
throw UnimplementedError();
}
}
int toIntValue() {
switch (this) {
case CustomImageType.local:
return 0;
case CustomImageType.internal:
return 1;
case CustomImageType.external:
return 2;
}
}
}
class CustomImageBlockKeys {
const CustomImageBlockKeys._();
@@ -59,25 +84,6 @@ class CustomImageBlockKeys {
static const String imageType = 'image_type';
}
Node customImageNode({
required String url,
String align = 'center',
double? height,
double? width,
CustomImageType type = CustomImageType.local,
}) {
return Node(
type: CustomImageBlockKeys.type,
attributes: {
CustomImageBlockKeys.url: url,
CustomImageBlockKeys.align: align,
CustomImageBlockKeys.height: height,
CustomImageBlockKeys.width: width,
CustomImageBlockKeys.imageType: type.toIntValue(),
},
);
}
typedef CustomImageBlockComponentMenuBuilder = Widget Function(
Node node,
CustomImageBlockComponentState state,
@@ -176,7 +182,7 @@ class CustomImageBlockComponentState extends State<CustomImageBlockComponent>
);
} else if (imageType != CustomImageType.internal &&
!_checkIfURLIsValid(src)) {
child = const UnsupportedImageWidget();
child = const UnSupportImageWidget();
} else {
child = ResizableImage(
src: src,
@@ -185,22 +191,11 @@ class CustomImageBlockComponentState extends State<CustomImageBlockComponent>
editable: editorState.editable,
alignment: alignment,
type: imageType,
onDoubleTap: () => showDialog(
context: context,
builder: (_) => InteractiveImageViewer(
userProfile: context.read<DocumentBloc>().state.userProfilePB,
imageProvider: AFBlockImageProvider(
images: [ImageBlockData(url: src, type: imageType)],
onDeleteImage: (_) async {
final transaction = editorState.transaction..deleteNode(node);
await editorState.apply(transaction);
},
),
),
),
onResize: (width) {
final transaction = editorState.transaction
..updateNode(node, {CustomImageBlockKeys.width: width});
..updateNode(node, {
CustomImageBlockKeys.width: width,
});
editorState.apply(transaction);
},
);
@@ -212,11 +207,21 @@ class CustomImageBlockComponentState extends State<CustomImageBlockComponent>
delegate: this,
listenable: editorState.selectionNotifier,
blockColor: editorState.editorStyle.selectionColor,
supportTypes: const [BlockSelectionType.block],
child: Padding(key: imageKey, padding: padding, child: child),
supportTypes: const [
BlockSelectionType.block,
],
child: Padding(
key: imageKey,
padding: padding,
child: child,
),
);
} else {
child = Padding(key: imageKey, padding: padding, child: child);
child = Padding(
key: imageKey,
padding: padding,
child: child,
);
}
if (widget.showActions && widget.actionBuilder != null) {
@@ -241,7 +246,7 @@ class CustomImageBlockComponentState extends State<CustomImageBlockComponent>
opaque: false,
child: ValueListenableBuilder<bool>(
valueListenable: showActionsNotifier,
builder: (_, value, child) {
builder: (context, value, child) {
final url = node.attributes[CustomImageBlockKeys.url];
return Stack(
children: [
@@ -254,7 +259,10 @@ class CustomImageBlockComponentState extends State<CustomImageBlockComponent>
child: child!,
),
if (value && url.isNotEmpty == true)
widget.menuBuilder!(widget.node, this),
widget.menuBuilder!(
widget.node,
this,
),
],
);
},
@@ -0,0 +1,40 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/base/app_bar/app_bar_actions.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter/material.dart';
class ImagePickerPage extends StatefulWidget {
const ImagePickerPage({
super.key,
// required this.onSelected,
});
// final void Function(EmojiPickerResult) onSelected;
@override
State<ImagePickerPage> createState() => _ImagePickerPageState();
}
class _ImagePickerPageState extends State<ImagePickerPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
titleSpacing: 0,
title: FlowyText.semibold(
LocaleKeys.titleBar_pageIcon.tr(),
fontSize: 14.0,
),
leading: const AppBarBackButton(),
),
body: SafeArea(
child: UploadImageMenu(
onSubmitted: (_) {},
onUpload: (_) {},
),
),
);
}
}
@@ -1,27 +1,26 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/align_toolbar_item/align_toolbar_item.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/block_menu/block_menu_button.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/util/string_extension.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/image_provider.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_viewer.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/widget/ignore_parent_gesture.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
class ImageMenu extends StatefulWidget {
const ImageMenu({super.key, required this.node, required this.state});
const ImageMenu({
super.key,
required this.node,
required this.state,
});
final Node node;
final CustomImageBlockComponentState state;
@@ -31,7 +30,7 @@ class ImageMenu extends StatefulWidget {
}
class _ImageMenuState extends State<ImageMenu> {
late final String? url = widget.node.attributes[CustomImageBlockKeys.url];
late final String? url = widget.node.attributes[ImageBlockKeys.url];
@override
Widget build(BuildContext context) {
@@ -51,12 +50,6 @@ class _ImageMenuState extends State<ImageMenu> {
),
child: Row(
children: [
const HSpace(4),
MenuBlockButton(
tooltip: LocaleKeys.document_imageBlock_openFullScreen.tr(),
iconData: FlowySvgs.full_view_s,
onTap: openFullScreen,
),
const HSpace(4),
// disable the copy link button if the image is hosted on appflowy cloud
// because the url needs the verification token to be accessible
@@ -68,7 +61,10 @@ class _ImageMenuState extends State<ImageMenu> {
),
const HSpace(4),
],
_ImageAlignButton(node: widget.node, state: widget.state),
_ImageAlignButton(
node: widget.node,
state: widget.state,
),
const _Divider(),
MenuBlockButton(
tooltip: LocaleKeys.button_delete.tr(),
@@ -99,34 +95,13 @@ class _ImageMenuState extends State<ImageMenu> {
transaction.afterSelection = null;
await editorState.apply(transaction);
}
void openFullScreen() {
showDialog(
context: context,
builder: (_) => InteractiveImageViewer(
userProfile: context.read<DocumentBloc>().state.userProfilePB,
imageProvider: AFBlockImageProvider(
images: [
ImageBlockData(
url: url!,
type: CustomImageType.fromIntValue(
widget.node.attributes[CustomImageBlockKeys.imageType] ?? 2,
),
),
],
onDeleteImage: (_) async {
final transaction = widget.state.editorState.transaction;
transaction.deleteNode(widget.node);
await widget.state.editorState.apply(transaction);
},
),
),
);
}
}
class _ImageAlignButton extends StatefulWidget {
const _ImageAlignButton({required this.node, required this.state});
const _ImageAlignButton({
required this.node,
required this.state,
});
final Node node;
final CustomImageBlockComponentState state;
@@ -135,28 +110,30 @@ class _ImageAlignButton extends StatefulWidget {
State<_ImageAlignButton> createState() => _ImageAlignButtonState();
}
const _interceptorKey = 'image-align';
const interceptorKey = 'image-align';
class _ImageAlignButtonState extends State<_ImageAlignButton> {
final gestureInterceptor = SelectionGestureInterceptor(
key: _interceptorKey,
key: interceptorKey,
canTap: (details) => false,
);
String get align =>
widget.node.attributes[CustomImageBlockKeys.align] ?? centerAlignmentKey;
widget.node.attributes[ImageBlockKeys.align] ?? centerAlignmentKey;
final popoverController = PopoverController();
late final EditorState editorState;
@override
void initState() {
super.initState();
editorState = context.read<EditorState>();
}
@override
void dispose() {
allowMenuClose();
super.dispose();
}
@@ -176,7 +153,9 @@ class _ImageAlignButtonState extends State<_ImageAlignButton> {
),
popupBuilder: (_) {
preventMenuClose();
return _AlignButtons(onAlignChanged: onAlignChanged);
return _AlignButtons(
onAlignChanged: onAlignChanged,
);
},
),
);
@@ -186,7 +165,9 @@ class _ImageAlignButtonState extends State<_ImageAlignButton> {
popoverController.close();
final transaction = editorState.transaction;
transaction.updateNode(widget.node, {CustomImageBlockKeys.align: align});
transaction.updateNode(widget.node, {
ImageBlockKeys.align: align,
});
editorState.apply(transaction);
allowMenuClose();
@@ -202,7 +183,7 @@ class _ImageAlignButtonState extends State<_ImageAlignButton> {
void allowMenuClose() {
widget.state.alwaysShowMenu = false;
editorState.service.selectionService.unregisterGestureInterceptor(
_interceptorKey,
interceptorKey,
);
}
@@ -220,7 +201,9 @@ class _ImageAlignButtonState extends State<_ImageAlignButton> {
}
class _AlignButtons extends StatelessWidget {
const _AlignButtons({required this.onAlignChanged});
const _AlignButtons({
required this.onAlignChanged,
});
final Function(String align) onAlignChanged;
@@ -263,7 +246,10 @@ class _Divider extends StatelessWidget {
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8),
child: Container(width: 1, color: Colors.grey),
child: Container(
width: 1,
color: Colors.grey,
),
);
}
}
@@ -1,40 +1,13 @@
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/flowy_image_picker.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/base/app_bar/app_bar_actions.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
class MobileImagePickerScreen extends StatelessWidget {
const MobileImagePickerScreen({super.key});
static const routeName = '/image_picker';
@override
Widget build(BuildContext context) => const ImagePickerPage();
}
class ImagePickerPage extends StatelessWidget {
const ImagePickerPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
titleSpacing: 0,
title: FlowyText.semibold(
LocaleKeys.titleBar_pageIcon.tr(),
fontSize: 14.0,
),
leading: const AppBarBackButton(),
),
body: SafeArea(
child: UploadImageMenu(
onSubmitted: (_) {},
onUpload: (_) {},
),
),
);
return const ImagePickerPage();
}
}
@@ -1,29 +1,24 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/plugins/document/application/prelude.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_util.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart';
import 'package:appflowy/shared/patterns/common_patterns.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/settings/application_data_storage.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log, UploadImageMenu;
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/uuid.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flowy_infra_ui/style_widget/snap_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:http/http.dart';
@@ -31,7 +26,10 @@ import 'package:path/path.dart' as p;
import 'package:string_validator/string_validator.dart';
class ImagePlaceholder extends StatefulWidget {
const ImagePlaceholder({super.key, required this.node});
const ImagePlaceholder({
super.key,
required this.node,
});
final Node node;
@@ -47,20 +45,12 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
bool showLoading = false;
String? errorMessage;
bool isDraggingFiles = false;
@override
Widget build(BuildContext context) {
final Widget child = DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(4),
border: isDraggingFiles
? Border.all(
color: Theme.of(context).colorScheme.primary,
width: 2,
)
: null,
),
child: FlowyHover(
style: HoverStyle(
@@ -95,23 +85,18 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
clickHandler: PopoverClickHandler.gestureDetector,
popupBuilder: (context) {
return UploadImageMenu(
allowMultipleImages: true,
limitMaximumImageSize: !_isLocalMode(),
supportTypes: const [
UploadImageType.local,
UploadImageType.url,
UploadImageType.unsplash,
// UploadImageType.openAI,
UploadImageType.stabilityAI,
],
onSelectedLocalImages: (paths) {
onSelectedLocalImage: (path) {
controller.close();
WidgetsBinding.instance.addPostFrameCallback((_) async {
final List<String> items = List.from(
paths.where((url) => url != null && url.isNotEmpty),
);
if (items.isNotEmpty) {
await insertMultipleLocalImages(items);
}
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await insertLocalImage(path);
});
},
onSelectedAIImage: (url) {
@@ -128,27 +113,7 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
},
);
},
child: DropTarget(
onDragEntered: (_) => setState(() => isDraggingFiles = true),
onDragExited: (_) => setState(() => isDraggingFiles = false),
onDragDone: (details) {
// Only accept files where the mimetype is an image,
// otherwise we assume it's a file we cannot display.
final imageFiles = details.files
.where(
(file) =>
file.mimeType?.startsWith('image/') ??
false || imgExtensionRegex.hasMatch(file.name),
)
.toList();
final paths = imageFiles.map((file) => file.path).toList();
WidgetsBinding.instance.addPostFrameCallback(
(_) async => insertMultipleLocalImages(paths),
);
},
child: child,
),
child: child,
);
} else {
return MobileBlockActionButtons(
@@ -168,11 +133,8 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
List<Widget> _buildTrailing(BuildContext context) {
if (errorMessage != null) {
return [
Flexible(
child: FlowyText(
'${LocaleKeys.document_plugins_image_imageUploadFailed.tr()}: ${errorMessage!}',
maxLines: 3,
),
FlowyText(
'${LocaleKeys.document_plugins_image_imageUploadFailed.tr()}: ${errorMessage!}',
),
];
} else if (showLoading) {
@@ -185,14 +147,8 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
];
} else {
return [
Flexible(
child: FlowyText(
PlatformExtension.isDesktop
? isDraggingFiles
? LocaleKeys.document_plugins_image_dropImageToInsert.tr()
: LocaleKeys.document_plugins_image_addAnImageDesktop.tr()
: LocaleKeys.document_plugins_image_addAnImageMobile.tr(),
),
FlowyText(
LocaleKeys.document_plugins_image_addAnImage.tr(),
),
];
}
@@ -223,14 +179,9 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
UploadImageType.url,
UploadImageType.unsplash,
],
onSelectedLocalImages: (paths) async {
onSelectedLocalImage: (path) async {
context.pop();
final List<String> items = List.from(
paths.where((url) => url != null && url.isNotEmpty),
);
await insertMultipleLocalImages(items);
await insertLocalImage(path);
},
onSelectedAIImage: (url) async {
context.pop();
@@ -247,102 +198,77 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
}
}
Future<void> insertMultipleLocalImages(List<String> urls) async {
Future<void> insertLocalImage(String? url) async {
controller.close();
setState(() {
showLoading = true;
errorMessage = null;
if (url == null || url.isEmpty) {
return;
}
final transaction = editorState.transaction;
String? path;
String? errorMessage;
CustomImageType imageType = CustomImageType.local;
// if the user is using local authenticator, we need to save the image to local storage
if (_isLocalMode()) {
// don't limit the image size for local mode.
path = await saveImageToLocalStorage(url);
} else {
final documentId = context.read<DocumentBloc>().documentId;
if (documentId.isEmpty) {
return;
}
// else we should save the image to cloud storage
setState(() {
showLoading = true;
this.errorMessage = null;
});
(path, errorMessage) = await saveImageToCloudStorage(url, documentId);
setState(() {
showLoading = false;
this.errorMessage = errorMessage;
});
imageType = CustomImageType.internal;
}
if (mounted && path == null) {
showSnackBarMessage(
context,
errorMessage == null
? LocaleKeys.document_imageBlock_error_invalidImage.tr()
: ': $errorMessage',
);
setState(() {
this.errorMessage = errorMessage;
});
return;
}
transaction.updateNode(widget.node, {
CustomImageBlockKeys.url: path,
CustomImageBlockKeys.imageType: imageType.toIntValue(),
});
bool hasError = false;
if (_isLocalMode()) {
final first = urls.removeAt(0);
final firstPath = await saveImageToLocalStorage(first);
final transaction = editorState.transaction;
transaction.updateNode(widget.node, {
CustomImageBlockKeys.url: firstPath,
CustomImageBlockKeys.imageType: CustomImageType.local.toIntValue(),
});
if (urls.isNotEmpty) {
// Create new nodes for the rest of the images:
final paths = await Future.wait(urls.map(saveImageToLocalStorage));
paths.removeWhere((url) => url == null || url.isEmpty);
transaction.insertNodes(
widget.node.path.next,
paths.map((url) => customImageNode(url: url!)).toList(),
);
}
await editorState.apply(transaction);
} else {
final transaction = editorState.transaction;
bool isFirst = true;
for (final url in urls) {
// Upload to cloud
final (path, error) = await saveImageToCloudStorage(
url,
context.read<DocumentBloc>().documentId,
);
if (error != null) {
hasError = true;
if (isFirst) {
setState(() => errorMessage = error);
}
continue;
}
if (path != null) {
if (isFirst) {
isFirst = false;
transaction.updateNode(widget.node, {
CustomImageBlockKeys.url: path,
CustomImageBlockKeys.imageType:
CustomImageType.internal.toIntValue(),
});
} else {
transaction.insertNode(
widget.node.path.next,
customImageNode(
url: path,
type: CustomImageType.internal,
),
);
}
}
}
await editorState.apply(transaction);
}
setState(() => showLoading = false);
if (hasError && mounted) {
showSnapBar(
context,
LocaleKeys.document_imageBlock_error_multipleImagesFailed.tr(),
);
}
await editorState.apply(transaction);
}
Future<void> insertAIImage(String url) async {
if (url.isEmpty || !isURL(url)) {
// show error
return showSnackBarMessage(
showSnackBarMessage(
context,
LocaleKeys.document_imageBlock_error_invalidImage.tr(),
);
return;
}
final path = await getIt<ApplicationDataStorage>().getPath();
final imagePath = p.join(path, 'images');
final imagePath = p.join(
path,
'images',
);
try {
// create the directory if not exists
final directory = Directory(imagePath);
@@ -357,7 +283,7 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
final response = await get(uri);
await File(copyToPath).writeAsBytes(response.bodyBytes);
await insertMultipleLocalImages([copyToPath]);
await insertLocalImage(copyToPath);
await File(copyToPath).delete();
} catch (e) {
Log.error('cannot save image file', e);
@@ -367,16 +293,16 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
Future<void> insertNetworkImage(String url) async {
if (url.isEmpty || !isURL(url)) {
// show error
return showSnackBarMessage(
showSnackBarMessage(
context,
LocaleKeys.document_imageBlock_error_invalidImage.tr(),
);
return;
}
final transaction = editorState.transaction;
transaction.updateNode(widget.node, {
CustomImageBlockKeys.url: url,
CustomImageBlockKeys.imageType: CustomImageType.external.toIntValue(),
ImageBlockKeys.url: url,
});
await editorState.apply(transaction);
}
@@ -1,54 +1,27 @@
import 'package:flutter/material.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_placeholder.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
final customImageMenuItem = SelectionMenuItem(
getName: () => AppFlowyEditorL10n.current.image,
icon: (_, isSelected, style) => SelectionMenuIconWidget(
icon: (editorState, isSelected, style) => SelectionMenuIconWidget(
name: 'image',
isSelected: isSelected,
style: style,
),
keywords: ['image', 'picture', 'img', 'photo'],
handler: (editorState, _, __) async {
handler: (editorState, menuService, context) async {
// use the key to retrieve the state of the image block to show the popover automatically
final imagePlaceholderKey = GlobalKey<ImagePlaceholderState>();
await editorState.insertEmptyImageBlock(imagePlaceholderKey);
WidgetsBinding.instance.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
imagePlaceholderKey.currentState?.controller.show();
});
},
);
final multiImageMenuItem = SelectionMenuItem(
getName: () => LocaleKeys.document_plugins_photoGallery_name.tr(),
icon: (_, isSelected, style) => SelectionMenuIconWidget(
icon: Icons.photo_library_outlined,
isSelected: isSelected,
style: style,
),
keywords: [
LocaleKeys.document_plugins_photoGallery_imageKeyword.tr(),
LocaleKeys.document_plugins_photoGallery_imageGalleryKeyword.tr(),
LocaleKeys.document_plugins_photoGallery_photoKeyword.tr(),
LocaleKeys.document_plugins_photoGallery_photoBrowserKeyword.tr(),
LocaleKeys.document_plugins_photoGallery_galleryKeyword.tr(),
],
handler: (editorState, _, __) async {
final imagePlaceholderKey = GlobalKey<ImagePlaceholderState>();
await editorState.insertEmptyMultiImageBlock(imagePlaceholderKey);
WidgetsBinding.instance.addPostFrameCallback(
(_) => imagePlaceholderKey.currentState?.controller.show(),
);
},
);
extension InsertImage on EditorState {
Future<void> insertEmptyImageBlock(GlobalKey key) async {
final selection = this.selection;
@@ -60,49 +33,31 @@ extension InsertImage on EditorState {
return;
}
final emptyImage = imageNode(url: '')
..extraInfos = {kImagePlaceholderKey: key};
..extraInfos = {
kImagePlaceholderKey: key,
};
final transaction = this.transaction;
// if the current node is empty paragraph, replace it with image node
if (node.type == ParagraphBlockKeys.type &&
(node.delta?.isEmpty ?? false)) {
transaction
..insertNode(node.path, emptyImage)
..insertNode(
node.path,
emptyImage,
)
..deleteNode(node);
} else {
transaction.insertNode(node.path.next, emptyImage);
transaction.insertNode(
node.path.next,
emptyImage,
);
}
transaction.afterSelection =
Selection.collapsed(Position(path: node.path.next));
transaction.selectionExtraInfo = {};
return apply(transaction);
}
Future<void> insertEmptyMultiImageBlock(GlobalKey key) async {
final selection = this.selection;
if (selection == null || !selection.isCollapsed) {
return;
}
final node = getNodeAtPath(selection.end.path);
if (node == null) {
return;
}
final emptyBlock = multiImageNode()
..extraInfos = {kMultiImagePlaceholderKey: key};
final transaction = this.transaction;
// if the current node is empty paragraph, replace it with image node
if (node.type == ParagraphBlockKeys.type &&
(node.delta?.isEmpty ?? false)) {
transaction
..insertNode(node.path, emptyBlock)
..deleteNode(node);
} else {
transaction.insertNode(node.path.next, emptyBlock);
}
transaction.afterSelection =
Selection.collapsed(Position(path: node.path.next));
transaction.afterSelection = Selection.collapsed(
Position(
path: node.path.next,
),
);
transaction.selectionExtraInfo = {};
return apply(transaction);
@@ -1,20 +1,15 @@
import 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/prelude.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/shared/custom_image_cache_manager.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/file_extension.dart';
import 'package:appflowy/workspace/application/settings/application_data_storage.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_backend/dispatch/error.dart';
import 'package:appflowy_backend/log.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/uuid.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:path/path.dart' as p;
Future<String?> saveImageToLocalStorage(String localImagePath) async {
@@ -78,49 +73,3 @@ Future<(String? path, String? errorMessage)> saveImageToCloudStorage(
},
);
}
Future<List<ImageBlockData>> extractAndUploadImages(
BuildContext context,
List<String?> urls,
bool isLocalMode,
) async {
final List<ImageBlockData> images = [];
bool hasError = false;
for (final url in urls) {
if (url == null || url.isEmpty) {
continue;
}
String? path;
String? errorMsg;
CustomImageType imageType = CustomImageType.local;
// If the user is using local authenticator, we save the image to local storage
if (isLocalMode) {
path = await saveImageToLocalStorage(url);
} else {
// Else we save the image to cloud storage
(path, errorMsg) = await saveImageToCloudStorage(
url,
context.read<DocumentBloc>().documentId,
);
imageType = CustomImageType.internal;
}
if (path != null && errorMsg == null) {
images.add(ImageBlockData(url: path, type: imageType));
} else {
hasError = true;
}
}
if (context.mounted && hasError) {
showSnackBarMessage(
context,
LocaleKeys.document_imageBlock_error_multipleImagesFailed.tr(),
);
}
return images;
}
@@ -1,9 +1,8 @@
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_placeholder.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
final imageMobileToolbarItem = MobileToolbarItem.action(
itemIconBuilder: (_, __, ___) => const FlowySvg(FlowySvgs.m_toolbar_imae_lg),
@@ -11,7 +10,7 @@ final imageMobileToolbarItem = MobileToolbarItem.action(
final imagePlaceholderKey = GlobalKey<ImagePlaceholderState>();
await editorState.insertEmptyImageBlock(imagePlaceholderKey);
WidgetsBinding.instance.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
imagePlaceholderKey.currentState?.showUploadImageMenu();
});
},
@@ -1,331 +0,0 @@
import 'package:flutter/material.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_placeholder.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_layouts.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:provider/provider.dart';
const kMultiImagePlaceholderKey = 'multiImagePlaceholderKey';
Node multiImageNode() => Node(
type: MultiImageBlockKeys.type,
attributes: {
MultiImageBlockKeys.images: MultiImageData(images: []).toJson(),
MultiImageBlockKeys.layout: MultiImageLayout.browser.toIntValue(),
},
);
class MultiImageBlockKeys {
const MultiImageBlockKeys._();
static const String type = 'multi_image';
/// The image data for the block, stored as a JSON encoded list of [ImageBlockData].
///
static const String images = 'images';
/// The layout of the images.
///
/// The value is a MultiImageLayout enum.
///
static const String layout = 'layout';
}
typedef MultiImageBlockComponentMenuBuilder = Widget Function(
Node node,
MultiImageBlockComponentState state,
ValueNotifier<int> indexNotifier,
VoidCallback onImageDeleted,
);
class MultiImageBlockComponentBuilder extends BlockComponentBuilder {
MultiImageBlockComponentBuilder({
super.configuration,
this.showMenu = false,
this.menuBuilder,
});
final bool showMenu;
final MultiImageBlockComponentMenuBuilder? menuBuilder;
@override
BlockComponentWidget build(BlockComponentContext blockComponentContext) {
final node = blockComponentContext.node;
return MultiImageBlockComponent(
key: node.key,
node: node,
showActions: showActions(node),
configuration: configuration,
actionBuilder: (_, state) => actionBuilder(blockComponentContext, state),
showMenu: showMenu,
menuBuilder: menuBuilder,
);
}
@override
bool validate(Node node) => node.delta == null && node.children.isEmpty;
}
class MultiImageBlockComponent extends BlockComponentStatefulWidget {
const MultiImageBlockComponent({
super.key,
required super.node,
super.showActions,
this.showMenu = false,
this.menuBuilder,
super.configuration = const BlockComponentConfiguration(),
super.actionBuilder,
});
final bool showMenu;
final MultiImageBlockComponentMenuBuilder? menuBuilder;
@override
State<MultiImageBlockComponent> createState() =>
MultiImageBlockComponentState();
}
class MultiImageBlockComponentState extends State<MultiImageBlockComponent>
with SelectableMixin, BlockComponentConfigurable {
@override
BlockComponentConfiguration get configuration => widget.configuration;
@override
Node get node => widget.node;
final multiImageKey = GlobalKey();
RenderBox? get _renderBox => context.findRenderObject() as RenderBox?;
late final editorState = Provider.of<EditorState>(context, listen: false);
final showActionsNotifier = ValueNotifier<bool>(false);
ValueNotifier<int> indexNotifier = ValueNotifier(0);
bool alwaysShowMenu = false;
@override
Widget build(BuildContext context) {
final data = MultiImageData.fromJson(
node.attributes[MultiImageBlockKeys.images],
);
Widget child;
if (data.images.isEmpty) {
final multiImagePlaceholderKey =
node.extraInfos?[kMultiImagePlaceholderKey];
child = MultiImagePlaceholder(
key: multiImagePlaceholderKey is GlobalKey
? multiImagePlaceholderKey
: null,
node: node,
);
} else {
child = ImageBrowserLayout(
node: node,
images: data.images,
editorState: editorState,
indexNotifier: indexNotifier,
isLocalMode: context.read<DocumentBloc>().isLocalMode,
onIndexChanged: (index) => setState(() => indexNotifier.value = index),
);
}
if (PlatformExtension.isDesktopOrWeb) {
child = BlockSelectionContainer(
node: node,
delegate: this,
listenable: editorState.selectionNotifier,
blockColor: editorState.editorStyle.selectionColor,
supportTypes: const [BlockSelectionType.block],
child: Padding(key: multiImageKey, padding: padding, child: child),
);
} else {
child = Padding(key: multiImageKey, padding: padding, child: child);
}
if (widget.showActions && widget.actionBuilder != null) {
child = BlockComponentActionWrapper(
node: node,
actionBuilder: widget.actionBuilder!,
child: child,
);
}
if (PlatformExtension.isDesktopOrWeb) {
if (widget.showMenu && widget.menuBuilder != null) {
child = MouseRegion(
onEnter: (_) => showActionsNotifier.value = true,
onExit: (_) {
if (!alwaysShowMenu) {
showActionsNotifier.value = false;
}
},
hitTestBehavior: HitTestBehavior.opaque,
opaque: false,
child: ValueListenableBuilder<bool>(
valueListenable: showActionsNotifier,
builder: (context, value, child) {
return Stack(
children: [
BlockSelectionContainer(
node: node,
delegate: this,
listenable: editorState.selectionNotifier,
cursorColor: editorState.editorStyle.cursorColor,
selectionColor: editorState.editorStyle.selectionColor,
child: child!,
),
if (value && data.images.isNotEmpty)
widget.menuBuilder!(
widget.node,
this,
indexNotifier,
() => setState(
() => indexNotifier.value = indexNotifier.value > 0
? indexNotifier.value - 1
: 0,
),
),
],
);
},
child: child,
),
);
}
} else {
// show a fixed menu on mobile
child = MobileBlockActionButtons(
showThreeDots: false,
node: node,
editorState: editorState,
child: child,
);
}
return child;
}
@override
Position start() => Position(path: widget.node.path);
@override
Position end() => Position(path: widget.node.path, offset: 1);
@override
Position getPositionInOffset(Offset start) => end();
@override
bool get shouldCursorBlink => false;
@override
CursorStyle get cursorStyle => CursorStyle.cover;
@override
Rect getBlockRect({
bool shiftWithBaseOffset = false,
}) {
final imageBox = multiImageKey.currentContext?.findRenderObject();
if (imageBox is RenderBox) {
return Offset.zero & imageBox.size;
}
return Rect.zero;
}
@override
Rect? getCursorRectInPosition(
Position position, {
bool shiftWithBaseOffset = false,
}) {
final rects = getRectsInSelection(Selection.collapsed(position));
return rects.firstOrNull;
}
@override
List<Rect> getRectsInSelection(
Selection selection, {
bool shiftWithBaseOffset = false,
}) {
if (_renderBox == null) {
return [];
}
final parentBox = context.findRenderObject();
final imageBox = multiImageKey.currentContext?.findRenderObject();
if (parentBox is RenderBox && imageBox is RenderBox) {
return [
imageBox.localToGlobal(Offset.zero, ancestor: parentBox) &
imageBox.size,
];
}
return [Offset.zero & _renderBox!.size];
}
@override
Selection getSelectionInRange(Offset start, Offset end) => Selection.single(
path: widget.node.path,
startOffset: 0,
endOffset: 1,
);
@override
Offset localToGlobal(
Offset offset, {
bool shiftWithBaseOffset = false,
}) =>
_renderBox!.localToGlobal(offset);
}
/// The data for a multi-image block, primarily used for
/// serializing and deserializing the block's images.
///
class MultiImageData {
factory MultiImageData.fromJson(List<dynamic> json) {
final images = json
.map((e) => ImageBlockData.fromJson(e as Map<String, dynamic>))
.toList();
return MultiImageData(images: images);
}
MultiImageData({required this.images});
final List<ImageBlockData> images;
List<dynamic> toJson() => images.map((e) => e.toJson()).toList();
}
enum MultiImageLayout {
browser,
masonry,
grid;
int toIntValue() {
switch (this) {
case MultiImageLayout.browser:
return 0;
case MultiImageLayout.masonry:
return 1;
case MultiImageLayout.grid:
return 2;
}
}
static MultiImageLayout fromIntValue(int value) {
switch (value) {
case 0:
return MultiImageLayout.browser;
case 1:
return MultiImageLayout.masonry;
case 2:
return MultiImageLayout.grid;
default:
throw UnimplementedError();
}
}
}
@@ -1,332 +0,0 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/block_menu/block_menu_button.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_util.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/string_extension.dart';
import 'package:appflowy/workspace/application/settings/application_data_storage.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/image_provider.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_viewer.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide UploadImageMenu, Log;
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/uuid.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:http/http.dart';
import 'package:path/path.dart' as p;
import 'package:provider/provider.dart';
import 'package:string_validator/string_validator.dart';
const _interceptorKey = 'add-image';
class MultiImageMenu extends StatefulWidget {
const MultiImageMenu({
super.key,
required this.node,
required this.state,
required this.indexNotifier,
this.isLocalMode = true,
required this.onImageDeleted,
});
final Node node;
final MultiImageBlockComponentState state;
final ValueNotifier<int> indexNotifier;
final bool isLocalMode;
final VoidCallback onImageDeleted;
@override
State<MultiImageMenu> createState() => _MultiImageMenuState();
}
class _MultiImageMenuState extends State<MultiImageMenu> {
final gestureInterceptor = SelectionGestureInterceptor(
key: _interceptorKey,
canTap: (details) => false,
);
final PopoverController controller = PopoverController();
late List<ImageBlockData> images;
late final EditorState editorState;
@override
void initState() {
super.initState();
editorState = context.read<EditorState>();
images = MultiImageData.fromJson(
widget.node.attributes[MultiImageBlockKeys.images] ?? {},
).images;
}
@override
void dispose() {
allowMenuClose();
controller.close();
super.dispose();
}
@override
void didUpdateWidget(covariant MultiImageMenu oldWidget) {
images = MultiImageData.fromJson(
widget.node.attributes[MultiImageBlockKeys.images] ?? {},
).images;
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Container(
height: 32,
decoration: BoxDecoration(
color: theme.cardColor,
boxShadow: [
BoxShadow(
blurRadius: 5,
spreadRadius: 1,
color: Colors.black.withOpacity(0.1),
),
],
borderRadius: BorderRadius.circular(4.0),
),
child: Row(
children: [
const HSpace(4),
MenuBlockButton(
tooltip: LocaleKeys.document_imageBlock_openFullScreen.tr(),
iconData: FlowySvgs.full_view_s,
onTap: openFullScreen,
),
AppFlowyPopover(
controller: controller,
direction: PopoverDirection.bottomWithRightAligned,
onClose: allowMenuClose,
constraints: const BoxConstraints(
maxWidth: 540,
maxHeight: 360,
minHeight: 80,
),
offset: const Offset(0, 10),
popupBuilder: (context) {
preventMenuClose();
return UploadImageMenu(
allowMultipleImages: true,
supportTypes: const [
UploadImageType.local,
UploadImageType.url,
UploadImageType.unsplash,
UploadImageType.stabilityAI,
],
onSelectedLocalImages: insertLocalImages,
onSelectedAIImage: insertAIImage,
onSelectedNetworkImage: insertNetworkImage,
);
},
child: MenuBlockButton(
tooltip:
LocaleKeys.document_plugins_photoGallery_addImageTooltip.tr(),
iconData: FlowySvgs.add_s,
onTap: () {},
),
),
// disable the copy link button if the image is hosted on appflowy cloud
// because the url needs the verification token to be accessible
if (!images[widget.indexNotifier.value].url.isAppFlowyCloudUrl) ...[
const HSpace(4),
MenuBlockButton(
tooltip: LocaleKeys.editor_copyLink.tr(),
iconData: FlowySvgs.copy_s,
onTap: copyImageLink,
),
],
const _Divider(),
MenuBlockButton(
tooltip: LocaleKeys.button_delete.tr(),
iconData: FlowySvgs.delete_s,
onTap: deleteImage,
),
const HSpace(4),
],
),
);
}
void copyImageLink() {
Clipboard.setData(
ClipboardData(text: images[widget.indexNotifier.value].url),
);
showSnackBarMessage(
context,
LocaleKeys.document_plugins_image_copiedToPasteBoard.tr(),
);
}
Future<void> deleteImage() async {
final node = widget.node;
final editorState = context.read<EditorState>();
final transaction = editorState.transaction;
transaction.deleteNode(node);
transaction.afterSelection = null;
await editorState.apply(transaction);
}
void openFullScreen() {
showDialog(
context: context,
builder: (_) => InteractiveImageViewer(
userProfile: context.read<DocumentBloc>().state.userProfilePB,
imageProvider: AFBlockImageProvider(
images: images,
initialIndex: widget.indexNotifier.value,
onDeleteImage: (index) async {
final transaction = editorState.transaction;
final newImages = List<ImageBlockData>.from(images);
newImages.removeAt(index);
images = newImages;
widget.onImageDeleted();
final imagesJson =
newImages.map((image) => image.toJson()).toList();
transaction.updateNode(widget.node, {
MultiImageBlockKeys.images: imagesJson,
// Default to Browser layout
MultiImageBlockKeys.layout: MultiImageLayout.browser.toIntValue(),
});
await editorState.apply(transaction);
},
),
),
);
}
void preventMenuClose() {
widget.state.alwaysShowMenu = true;
editorState.service.selectionService.registerGestureInterceptor(
gestureInterceptor,
);
}
void allowMenuClose() {
widget.state.alwaysShowMenu = false;
editorState.service.selectionService.unregisterGestureInterceptor(
_interceptorKey,
);
}
Future<void> insertLocalImages(List<String?> urls) async {
controller.close();
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (urls.isEmpty || urls.every((path) => path?.isEmpty ?? true)) {
return;
}
final transaction = editorState.transaction;
final newImages =
await extractAndUploadImages(context, urls, widget.isLocalMode);
if (newImages.isEmpty) {
return;
}
newImages.addAll(images);
final imagesJson = newImages.map((image) => image.toJson()).toList();
transaction.updateNode(widget.node, {
MultiImageBlockKeys.images: imagesJson,
// Default to Browser layout
MultiImageBlockKeys.layout: MultiImageLayout.browser.toIntValue(),
});
await editorState.apply(transaction);
setState(() => images = newImages);
});
}
Future<void> insertAIImage(String url) async {
controller.close();
if (url.isEmpty || !isURL(url)) {
// show error
return showSnackBarMessage(
context,
LocaleKeys.document_imageBlock_error_invalidImage.tr(),
);
}
final path = await getIt<ApplicationDataStorage>().getPath();
final imagePath = p.join(path, 'images');
try {
// create the directory if not exists
final directory = Directory(imagePath);
if (!directory.existsSync()) {
await directory.create(recursive: true);
}
final uri = Uri.parse(url);
final copyToPath = p.join(
imagePath,
'${uuid()}${p.extension(uri.path)}',
);
final response = await get(uri);
await File(copyToPath).writeAsBytes(response.bodyBytes);
await insertLocalImages([copyToPath]);
await File(copyToPath).delete();
} catch (e) {
Log.error('cannot save image file', e);
}
}
Future<void> insertNetworkImage(String url) async {
controller.close();
if (url.isEmpty || !isURL(url)) {
// show error
return showSnackBarMessage(
context,
LocaleKeys.document_imageBlock_error_invalidImage.tr(),
);
}
final transaction = editorState.transaction;
final newImages = [
...images,
ImageBlockData(url: url, type: CustomImageType.external),
];
final imagesJson = newImages.map((image) => image.toJson()).toList();
transaction.updateNode(widget.node, {
MultiImageBlockKeys.images: imagesJson,
// Default to Browser layout
MultiImageBlockKeys.layout: MultiImageLayout.browser.toIntValue(),
});
await editorState.apply(transaction);
setState(() => images = newImages);
}
}
class _Divider extends StatelessWidget {
const _Divider();
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8),
child: Container(width: 1, color: Colors.grey),
);
}
}
@@ -1,294 +0,0 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/application/document_service.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_util.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart';
import 'package:appflowy/shared/patterns/common_patterns.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/settings/application_data_storage.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide UploadImageMenu, Log;
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/uuid.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:go_router/go_router.dart';
import 'package:http/http.dart';
import 'package:path/path.dart' as p;
import 'package:provider/provider.dart';
import 'package:string_validator/string_validator.dart';
class MultiImagePlaceholder extends StatefulWidget {
const MultiImagePlaceholder({super.key, required this.node});
final Node node;
@override
State<MultiImagePlaceholder> createState() => MultiImagePlaceholderState();
}
class MultiImagePlaceholderState extends State<MultiImagePlaceholder> {
final controller = PopoverController();
final documentService = DocumentService();
late final editorState = context.read<EditorState>();
bool isDraggingFiles = false;
@override
Widget build(BuildContext context) {
final child = DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(4),
border: isDraggingFiles
? Border.all(
color: Theme.of(context).colorScheme.primary,
width: 2,
)
: null,
),
child: FlowyHover(
style: HoverStyle(
borderRadius: BorderRadius.circular(4),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 12),
child: Row(
children: [
const Icon(Icons.photo_library_outlined, size: 24),
const HSpace(10),
FlowyText(
PlatformExtension.isDesktop
? isDraggingFiles
? LocaleKeys.document_plugins_image_dropImageToInsert
.tr()
: LocaleKeys.document_plugins_image_addAnImageDesktop
.tr()
: LocaleKeys.document_plugins_image_addAnImageMobile.tr(),
),
],
),
),
),
);
if (PlatformExtension.isDesktopOrWeb) {
return AppFlowyPopover(
controller: controller,
direction: PopoverDirection.bottomWithCenterAligned,
constraints: const BoxConstraints(
maxWidth: 540,
maxHeight: 360,
minHeight: 80,
),
clickHandler: PopoverClickHandler.gestureDetector,
popupBuilder: (_) {
return UploadImageMenu(
allowMultipleImages: true,
limitMaximumImageSize: !_isLocalMode(),
supportTypes: const [
UploadImageType.local,
UploadImageType.url,
UploadImageType.unsplash,
UploadImageType.stabilityAI,
],
onSelectedLocalImages: (paths) {
controller.close();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await insertLocalImages(paths);
});
},
onSelectedAIImage: (url) {
controller.close();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await insertAIImage(url);
});
},
onSelectedNetworkImage: (url) {
controller.close();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await insertNetworkImage(url);
});
},
);
},
child: DropTarget(
onDragEntered: (_) => setState(() => isDraggingFiles = true),
onDragExited: (_) => setState(() => isDraggingFiles = false),
onDragDone: (details) {
// Only accept files where the mimetype is an image,
// or the file extension is a known image format,
// otherwise we assume it's a file we cannot display.
final imageFiles = details.files
.where(
(file) =>
file.mimeType?.startsWith('image/') ??
false || imgExtensionRegex.hasMatch(file.name),
)
.toList();
final paths = imageFiles.map((file) => file.path).toList();
WidgetsBinding.instance.addPostFrameCallback(
(_) async => insertLocalImages(paths),
);
},
child: child,
),
);
} else {
return MobileBlockActionButtons(
node: widget.node,
editorState: editorState,
child: GestureDetector(
onTap: () {
editorState.updateSelectionWithReason(null, extraInfo: {});
showUploadImageMenu();
},
child: child,
),
);
}
}
void showUploadImageMenu() {
if (PlatformExtension.isDesktopOrWeb) {
controller.show();
} else {
final isLocalMode = _isLocalMode();
showMobileBottomSheet(
context,
title: LocaleKeys.editor_image.tr(),
showHeader: true,
showCloseButton: true,
showDragHandle: true,
builder: (context) {
return Container(
margin: const EdgeInsets.only(top: 12.0),
constraints: const BoxConstraints(
maxHeight: 340,
minHeight: 80,
),
child: UploadImageMenu(
limitMaximumImageSize: !isLocalMode,
allowMultipleImages: true,
supportTypes: const [
UploadImageType.local,
UploadImageType.url,
UploadImageType.unsplash,
],
onSelectedLocalImages: (paths) async {
context.pop();
await insertLocalImages(paths);
},
onSelectedAIImage: (url) async {
context.pop();
await insertAIImage(url);
},
onSelectedNetworkImage: (url) async {
context.pop();
await insertNetworkImage(url);
},
),
);
},
);
}
}
Future<void> insertLocalImages(List<String?> urls) async {
controller.close();
if (urls.isEmpty || urls.every((path) => path?.isEmpty ?? true)) {
return;
}
final transaction = editorState.transaction;
final images = await extractAndUploadImages(context, urls, _isLocalMode());
if (images.isEmpty) {
return;
}
final imagesJson = images.map((image) => image.toJson()).toList();
transaction.updateNode(widget.node, {
MultiImageBlockKeys.images: imagesJson,
// Default to Browser layout
MultiImageBlockKeys.layout: MultiImageLayout.browser.toIntValue(),
});
await editorState.apply(transaction);
}
Future<void> insertAIImage(String url) async {
if (url.isEmpty || !isURL(url)) {
// show error
return showSnackBarMessage(
context,
LocaleKeys.document_imageBlock_error_invalidImage.tr(),
);
}
final path = await getIt<ApplicationDataStorage>().getPath();
final imagePath = p.join(path, 'images');
try {
// create the directory if not exists
final directory = Directory(imagePath);
if (!directory.existsSync()) {
await directory.create(recursive: true);
}
final uri = Uri.parse(url);
final copyToPath = p.join(
imagePath,
'${uuid()}${p.extension(uri.path)}',
);
final response = await get(uri);
await File(copyToPath).writeAsBytes(response.bodyBytes);
await insertLocalImages([copyToPath]);
await File(copyToPath).delete();
} catch (e) {
Log.error('cannot save image file', e);
}
}
Future<void> insertNetworkImage(String url) async {
if (url.isEmpty || !isURL(url)) {
// show error
return showSnackBarMessage(
context,
LocaleKeys.document_imageBlock_error_invalidImage.tr(),
);
}
final transaction = editorState.transaction;
final images = [
ImageBlockData(
url: url,
type: CustomImageType.external,
),
];
transaction.updateNode(widget.node, {
MultiImageBlockKeys.images:
images.map((image) => image.toJson()).toList(),
// Default to Browser layout
MultiImageBlockKeys.layout: MultiImageLayout.browser.toIntValue(),
});
await editorState.apply(transaction);
}
bool _isLocalMode() {
return context.read<DocumentBloc>().isLocalMode;
}
}
@@ -1,451 +0,0 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_util.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';
import 'package:appflowy/shared/appflowy_network_image.dart';
import 'package:appflowy/shared/patterns/common_patterns.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/image_provider.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_viewer.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide ResizableImage;
import 'package:collection/collection.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:provider/provider.dart';
const _thumbnailItemSize = 100.0;
abstract class ImageBlockMultiLayout extends StatefulWidget {
const ImageBlockMultiLayout({
super.key,
required this.node,
required this.editorState,
required this.images,
required this.indexNotifier,
required this.isLocalMode,
});
final Node node;
final EditorState editorState;
final List<ImageBlockData> images;
final ValueNotifier<int> indexNotifier;
final bool isLocalMode;
}
class ImageBrowserLayout extends ImageBlockMultiLayout {
const ImageBrowserLayout({
super.key,
required super.node,
required super.editorState,
required super.images,
required super.indexNotifier,
required super.isLocalMode,
required this.onIndexChanged,
});
final void Function(int) onIndexChanged;
@override
State<ImageBrowserLayout> createState() => _ImageBrowserLayoutState();
}
class _ImageBrowserLayoutState extends State<ImageBrowserLayout> {
UserProfilePB? _userProfile;
bool isDraggingFiles = false;
@override
void initState() {
super.initState();
_userProfile = context.read<DocumentBloc>().state.userProfilePB;
}
@override
Widget build(BuildContext context) {
return Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 400,
width: MediaQuery.of(context).size.width,
child: GestureDetector(
onDoubleTap: () => _openInteractiveViewer(context),
child: ImageRender(
image: widget.images[widget.indexNotifier.value],
userProfile: _userProfile,
fit: BoxFit.contain,
),
),
),
const VSpace(8),
LayoutBuilder(
builder: (context, constraints) {
final maxItems =
(constraints.maxWidth / (_thumbnailItemSize + 4)).floor();
final items = widget.images.take(maxItems).toList();
return Wrap(
children: items.mapIndexed((index, image) {
final isLast = items.last == image;
final amountLeft = widget.images.length - items.length;
if (isLast && amountLeft > 0) {
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () => _openInteractiveViewer(
context,
maxItems - 1,
),
child: Container(
width: _thumbnailItemSize,
height: _thumbnailItemSize,
padding: const EdgeInsets.all(2),
margin: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: Corners.s8Border,
border: Border.all(
width: 2,
color: Theme.of(context).dividerColor,
),
),
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: Corners.s6Border,
image: image.type == CustomImageType.local
? DecorationImage(
image: FileImage(File(image.url)),
fit: BoxFit.cover,
opacity: 0.5,
)
: null,
),
child: Stack(
children: [
if (image.type != CustomImageType.local)
Positioned.fill(
child: Container(
clipBehavior: Clip.antiAlias,
decoration: const BoxDecoration(
borderRadius: Corners.s6Border,
),
child: FlowyNetworkImage(
url: image.url,
userProfilePB: _userProfile,
),
),
),
DecoratedBox(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.5),
),
child: Center(
child: FlowyText(
'+$amountLeft',
color: AFThemeExtension.of(context)
.strongText,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
),
),
);
}
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () => widget.onIndexChanged(index),
child: ThumbnailItem(
images: widget.images,
index: index,
selectedIndex: widget.indexNotifier.value,
userProfile: _userProfile,
onDeleted: () async {
final transaction = widget.editorState.transaction;
final images = widget.images.toList();
images.removeAt(index);
transaction.updateNode(
widget.node,
{
MultiImageBlockKeys.images:
images.map((e) => e.toJson()).toList(),
MultiImageBlockKeys.layout: widget.node
.attributes[MultiImageBlockKeys.layout],
},
);
await widget.editorState.apply(transaction);
widget.onIndexChanged(
widget.indexNotifier.value > 0
? widget.indexNotifier.value - 1
: 0,
);
},
),
),
);
}).toList(),
);
},
),
],
),
Positioned.fill(
child: DropTarget(
onDragEntered: (_) => setState(() => isDraggingFiles = true),
onDragExited: (_) => setState(() => isDraggingFiles = false),
onDragDone: (details) {
setState(() => isDraggingFiles = false);
// Only accept files where the mimetype is an image,
// or the file extension is a known image format,
// otherwise we assume it's a file we cannot display.
final imageFiles = details.files
.where(
(file) =>
file.mimeType?.startsWith('image/') ??
false || imgExtensionRegex.hasMatch(file.name),
)
.toList();
final paths = imageFiles.map((file) => file.path).toList();
WidgetsBinding.instance.addPostFrameCallback(
(_) async => insertLocalImages(paths),
);
},
child: !isDraggingFiles
? const SizedBox.shrink()
: SizedBox.expand(
child: DecoratedBox(
decoration:
BoxDecoration(color: Colors.white.withOpacity(0.5)),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const FlowySvg(
FlowySvgs.import_s,
size: Size.square(28),
),
const HSpace(12),
Flexible(
child: FlowyText(
LocaleKeys
.document_plugins_image_dropImageToInsert
.tr(),
color: AFThemeExtension.of(context).strongText,
fontSize: 22,
fontWeight: FontWeight.w500,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
),
),
),
),
],
);
}
void _openInteractiveViewer(BuildContext context, [int? index]) => showDialog(
context: context,
builder: (_) => InteractiveImageViewer(
userProfile: _userProfile,
imageProvider: AFBlockImageProvider(
images: widget.images,
initialIndex: index ?? widget.indexNotifier.value,
onDeleteImage: (index) async {
final transaction = widget.editorState.transaction;
final newImages = widget.images.toList();
newImages.removeAt(index);
widget.onIndexChanged(
widget.indexNotifier.value > 0
? widget.indexNotifier.value - 1
: 0,
);
if (newImages.isNotEmpty) {
transaction.updateNode(
widget.node,
{
MultiImageBlockKeys.images:
newImages.map((e) => e.toJson()).toList(),
MultiImageBlockKeys.layout:
widget.node.attributes[MultiImageBlockKeys.layout],
},
);
} else {
transaction.deleteNode(widget.node);
}
await widget.editorState.apply(transaction);
},
),
),
);
Future<void> insertLocalImages(List<String?> urls) async {
if (urls.isEmpty || urls.every((path) => path?.isEmpty ?? true)) {
return;
}
final isLocalMode = context.read<DocumentBloc>().isLocalMode;
final transaction = widget.editorState.transaction;
final images = await extractAndUploadImages(context, urls, isLocalMode);
if (images.isEmpty) {
return;
}
final newImages = [...widget.images, ...images];
final imagesJson = newImages.map((image) => image.toJson()).toList();
transaction.updateNode(widget.node, {
MultiImageBlockKeys.images: imagesJson,
MultiImageBlockKeys.layout: MultiImageLayout.browser.toIntValue(),
});
await widget.editorState.apply(transaction);
}
}
@visibleForTesting
class ThumbnailItem extends StatefulWidget {
const ThumbnailItem({
super.key,
required this.images,
required this.index,
required this.selectedIndex,
required this.onDeleted,
this.userProfile,
});
final List<ImageBlockData> images;
final int index;
final int selectedIndex;
final VoidCallback onDeleted;
final UserProfilePB? userProfile;
@override
State<ThumbnailItem> createState() => _ThumbnailItemState();
}
class _ThumbnailItemState extends State<ThumbnailItem> {
bool isHovering = false;
@override
Widget build(BuildContext context) {
return MouseRegion(
onEnter: (_) => setState(() => isHovering = true),
onExit: (_) => setState(() => isHovering = false),
child: Container(
width: _thumbnailItemSize,
height: _thumbnailItemSize,
padding: const EdgeInsets.all(2),
margin: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: Corners.s8Border,
border: Border.all(
width: 2,
color: widget.index == widget.selectedIndex
? Theme.of(context).colorScheme.primary
: Theme.of(context).dividerColor,
),
),
child: Stack(
children: [
Positioned.fill(
child: ImageRender(
image: widget.images[widget.index],
userProfile: widget.userProfile,
),
),
Positioned(
top: 4,
right: 4,
child: AnimatedOpacity(
opacity: isHovering ? 1 : 0,
duration: const Duration(milliseconds: 100),
child: FlowyTooltip(
message: LocaleKeys.button_delete.tr(),
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: widget.onDeleted,
child: FlowyHover(
resetHoverOnRebuild: false,
style: HoverStyle(
backgroundColor: Colors.black.withOpacity(0.6),
hoverColor: Colors.black.withOpacity(0.9),
),
child: const Padding(
padding: EdgeInsets.all(4),
child: FlowySvg(
FlowySvgs.delete_s,
color: Colors.white,
),
),
),
),
),
),
),
],
),
),
);
}
}
@visibleForTesting
class ImageRender extends StatelessWidget {
const ImageRender({
super.key,
required this.image,
this.userProfile,
this.fit = BoxFit.cover,
});
final ImageBlockData image;
final UserProfilePB? userProfile;
final BoxFit fit;
@override
Widget build(BuildContext context) {
final child = switch (image.type) {
CustomImageType.internal || CustomImageType.external => FlowyNetworkImage(
url: image.url,
userProfilePB: userProfile,
fit: fit,
),
CustomImageType.local => Image.file(File(image.url), fit: fit),
};
return Container(
clipBehavior: Clip.antiAlias,
decoration: const BoxDecoration(borderRadius: Corners.s6Border),
child: child,
);
}
}
@@ -1,15 +1,14 @@
import 'dart:io';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/plugins/document/application/prelude.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component.dart';
import 'package:appflowy/shared/appflowy_network_image.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:string_validator/string_validator.dart';
@@ -24,7 +23,6 @@ class ResizableImage extends StatefulWidget {
required this.width,
required this.src,
this.height,
this.onDoubleTap,
});
final String src;
@@ -33,7 +31,6 @@ class ResizableImage extends StatefulWidget {
final double? height;
final Alignment alignment;
final bool editable;
final VoidCallback? onDoubleTap;
final void Function(double width) onResize;
@@ -44,23 +41,26 @@ class ResizableImage extends StatefulWidget {
const _kImageBlockComponentMinWidth = 30.0;
class _ResizableImageState extends State<ResizableImage> {
final documentService = DocumentService();
late double imageWidth;
double initialOffset = 0;
double moveDistance = 0;
Widget? _cacheImage;
late double imageWidth;
Widget? _cacheImage;
@visibleForTesting
bool onFocus = false;
final documentService = DocumentService();
UserProfilePB? _userProfilePB;
@override
void initState() {
super.initState();
imageWidth = widget.width;
_userProfilePB = context.read<DocumentBloc>().state.userProfilePB;
}
@@ -72,12 +72,13 @@ class _ResizableImageState extends State<ResizableImage> {
width: max(_kImageBlockComponentMinWidth, imageWidth - moveDistance),
height: widget.height,
child: MouseRegion(
onEnter: (_) => setState(() => onFocus = true),
onExit: (_) => setState(() => onFocus = false),
child: GestureDetector(
onDoubleTap: widget.onDoubleTap,
child: _buildResizableImage(context),
),
onEnter: (event) => setState(() {
onFocus = true;
}),
onExit: (event) => setState(() {
onFocus = false;
}),
child: _buildResizableImage(context),
),
),
);
@@ -96,11 +97,12 @@ class _ResizableImageState extends State<ResizableImage> {
url: widget.src,
width: imageWidth - moveDistance,
userProfilePB: _userProfilePB,
progressIndicatorBuilder: (context, _, __) => _buildLoading(context),
errorWidgetBuilder: (_, __, error) => _ImageLoadFailedWidget(
errorWidgetBuilder: (context, url, error) => _ImageLoadFailedWidget(
width: imageWidth,
error: error,
),
progressIndicatorBuilder: (context, url, progress) =>
_buildLoading(context),
);
child = _cacheImage!;
@@ -119,7 +121,11 @@ class _ResizableImageState extends State<ResizableImage> {
left: 5,
bottom: 0,
width: 5,
onUpdate: (distance) => setState(() => moveDistance = distance),
onUpdate: (distance) {
setState(() {
moveDistance = distance;
});
},
),
_buildEdgeGesture(
context,
@@ -127,7 +133,11 @@ class _ResizableImageState extends State<ResizableImage> {
right: 5,
bottom: 0,
width: 5,
onUpdate: (distance) => setState(() => moveDistance = -distance),
onUpdate: (distance) {
setState(() {
moveDistance = -distance;
});
},
),
],
],
@@ -144,7 +154,9 @@ class _ResizableImageState extends State<ResizableImage> {
size: const Size(18, 18),
child: const CircularProgressIndicator(),
),
SizedBox.fromSize(size: const Size(10, 10)),
SizedBox.fromSize(
size: const Size(10, 10),
),
Text(AppFlowyEditorL10n.current.loading),
],
),
@@ -172,7 +184,7 @@ class _ResizableImageState extends State<ResizableImage> {
},
onHorizontalDragUpdate: (details) {
if (onUpdate != null) {
double offset = details.globalPosition.dx - initialOffset;
var offset = details.globalPosition.dx - initialOffset;
if (widget.alignment == Alignment.center) {
offset *= 2.0;
}
@@ -210,7 +222,10 @@ class _ResizableImageState extends State<ResizableImage> {
}
class _ImageLoadFailedWidget extends StatelessWidget {
const _ImageLoadFailedWidget({required this.width, required this.error});
const _ImageLoadFailedWidget({
required this.width,
required this.error,
});
final double width;
final Object error;
@@ -225,7 +240,9 @@ class _ImageLoadFailedWidget extends StatelessWidget {
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
border: Border.all(color: Colors.grey.withOpacity(0.6)),
border: Border.all(
color: Colors.grey.withOpacity(0.6),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
@@ -234,7 +251,9 @@ class _ImageLoadFailedWidget extends StatelessWidget {
FlowySvgs.broken_image_xl,
size: Size.square(48),
),
FlowyText(AppFlowyEditorL10n.current.imageLoadFailed),
FlowyText(
AppFlowyEditorL10n.current.imageLoadFailed,
),
const VSpace(6),
if (error != null)
FlowyText(
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:appflowy/mobile/presentation/widgets/flowy_mobile_search_text_field.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:unsplash_client/unsplash_client.dart';
const _accessKeyA = 'YyD-LbW5bVolHWZBq5fWRM_';
@@ -49,6 +48,7 @@ class _UnsplashImageWidgetState extends State<UnsplashImageWidget> {
@override
void initState() {
super.initState();
randomPhotos = unsplash.photos
.random(count: 18, orientation: PhotoOrientation.landscape)
.goAndGet();
@@ -57,6 +57,7 @@ class _UnsplashImageWidgetState extends State<UnsplashImageWidget> {
@override
void dispose() {
unsplash.close();
super.dispose();
}
@@ -131,16 +132,18 @@ class _UnsplashImagesState extends State<_UnsplashImages> {
@override
Widget build(BuildContext context) {
const mainAxisSpacing = 16.0;
final crossAxisCount = switch (widget.type) {
UnsplashImageType.halfScreen => 3,
UnsplashImageType.fullScreen => 2,
};
final mainAxisSpacing = switch (widget.type) {
UnsplashImageType.halfScreen => 16.0,
UnsplashImageType.fullScreen => 16.0,
};
final crossAxisSpacing = switch (widget.type) {
UnsplashImageType.halfScreen => 10.0,
UnsplashImageType.fullScreen => 16.0,
};
return GridView.count(
crossAxisCount: crossAxisCount,
mainAxisSpacing: mainAxisSpacing,
@@ -152,11 +155,15 @@ class _UnsplashImagesState extends State<_UnsplashImages> {
return _UnsplashImage(
type: widget.type,
photo: photo,
isSelected: index == _selectedPhotoIndex,
onTap: () {
widget.onSelectUnsplashImage(photo.urls.regular.toString());
setState(() => _selectedPhotoIndex = index);
widget.onSelectUnsplashImage(
photo.urls.regular.toString(),
);
setState(() {
_selectedPhotoIndex = index;
});
},
isSelected: index == _selectedPhotoIndex,
);
}).toList(),
);
@@ -212,7 +219,10 @@ class _UnsplashImage extends StatelessWidget {
),
),
const HSpace(2.0),
FlowyText('by ${photo.name}', fontSize: 10.0),
FlowyText(
'by ${photo.name}',
fontSize: 10.0,
),
],
);
}
@@ -223,12 +233,14 @@ class _UnsplashImage extends StatelessWidget {
child: Stack(
children: [
LayoutBuilder(
builder: (_, constraints) => Image.network(
photo.urls.thumb.toString(),
fit: BoxFit.cover,
width: constraints.maxWidth,
height: constraints.maxHeight,
),
builder: (context, constraints) {
return Image.network(
photo.urls.thumb.toString(),
fit: BoxFit.cover,
width: constraints.maxWidth,
height: constraints.maxHeight,
);
},
),
Positioned(
bottom: 9,
@@ -249,9 +261,13 @@ extension on Photo {
String get name {
if (user.username.isNotEmpty) {
return user.username;
} else if (user.name.isNotEmpty) {
}
if (user.name.isNotEmpty) {
return user.name;
} else if (user.email?.isNotEmpty == true) {
}
if (user.email?.isNotEmpty == true) {
return user.email!;
}
@@ -1,13 +1,14 @@
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flutter/material.dart';
class UnsupportedImageWidget extends StatelessWidget {
const UnsupportedImageWidget({super.key});
class UnSupportImageWidget extends StatelessWidget {
const UnSupportImageWidget({
super.key,
});
@override
Widget build(BuildContext context) {
@@ -17,7 +18,9 @@ class UnsupportedImageWidget extends StatelessWidget {
borderRadius: BorderRadius.circular(4),
),
child: FlowyHover(
style: HoverStyle(borderRadius: BorderRadius.circular(4)),
style: HoverStyle(
borderRadius: BorderRadius.circular(4),
),
child: SizedBox(
height: 52,
child: Row(
@@ -28,7 +31,9 @@ class UnsupportedImageWidget extends StatelessWidget {
size: Size.square(24),
),
const HSpace(10),
FlowyText(LocaleKeys.document_imageBlock_unableToLoadImage.tr()),
FlowyText(
LocaleKeys.document_imageBlock_unableToLoadImage.tr(),
),
],
),
),
@@ -1,5 +1,3 @@
import 'package:flutter/material.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/permission/permission_checker.dart';
import 'package:appflowy/startup/startup.dart';
@@ -9,19 +7,18 @@ 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';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
class UploadImageFileWidget extends StatelessWidget {
const UploadImageFileWidget({
super.key,
required this.onPickFiles,
required this.onPickFile,
this.allowedExtensions = const ['jpg', 'png', 'jpeg'],
this.allowMultipleImages = false,
});
final void Function(List<String?>) onPickFiles;
final void Function(String? path) onPickFile;
final List<String> allowedExtensions;
final bool allowMultipleImages;
@override
Widget build(BuildContext context) {
@@ -38,7 +35,9 @@ class UploadImageFileWidget extends StatelessWidget {
);
if (PlatformExtension.isDesktopOrWeb) {
return FlowyHover(child: child);
return FlowyHover(
child: child,
);
}
return child;
@@ -51,9 +50,8 @@ class UploadImageFileWidget extends StatelessWidget {
dialogTitle: '',
type: FileType.custom,
allowedExtensions: allowedExtensions,
allowMultiple: allowMultipleImages,
);
onPickFiles(result?.files.map((f) => f.path).toList() ?? const []);
onPickFile(result?.files.firstOrNull?.path);
} else {
final photoPermission =
await PermissionChecker.checkPhotoPermission(context);
@@ -62,8 +60,8 @@ class UploadImageFileWidget extends StatelessWidget {
return;
}
// on mobile, the users can pick a image file from camera or image library
final result = await ImagePicker().pickMultiImage();
onPickFiles(result.map((f) => f.path).toList());
final result = await ImagePicker().pickImage(source: ImageSource.gallery);
onPickFile(result?.path);
}
}
}
@@ -1,10 +1,9 @@
import 'package:flutter/material.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/cover_editor.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/embed_image_url_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/stability_ai_image_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/unsplash_image_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/stability_ai_image_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/upload_image_file_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_file_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/user/application/user_service.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide ColorOption;
@@ -12,8 +11,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'widgets/embed_image_url_widget.dart';
import 'package:flutter/material.dart';
enum UploadImageType {
local,
@@ -44,22 +42,20 @@ enum UploadImageType {
class UploadImageMenu extends StatefulWidget {
const UploadImageMenu({
super.key,
required this.onSelectedLocalImages,
required this.onSelectedLocalImage,
required this.onSelectedAIImage,
required this.onSelectedNetworkImage,
this.onSelectedColor,
this.supportTypes = UploadImageType.values,
this.limitMaximumImageSize = false,
this.allowMultipleImages = false,
});
final void Function(List<String?>) onSelectedLocalImages;
final void Function(String? path) onSelectedLocalImage;
final void Function(String url) onSelectedAIImage;
final void Function(String url) onSelectedNetworkImage;
final void Function(String color)? onSelectedColor;
final List<UploadImageType> supportTypes;
final bool limitMaximumImageSize;
final bool allowMultipleImages;
@override
State<UploadImageMenu> createState() => _UploadImageMenuState();
@@ -137,7 +133,9 @@ class _UploadImageMenuState extends State<UploadImageMenu> {
},
).toList(),
),
const Divider(height: 2),
const Divider(
height: 2,
),
_buildTab(),
],
),
@@ -157,8 +155,7 @@ class _UploadImageMenuState extends State<UploadImageMenu> {
child: Column(
children: [
UploadImageFileWidget(
allowMultipleImages: widget.allowMultipleImages,
onPickFiles: widget.onSelectedLocalImages,
onPickFile: widget.onSelectedLocalImage,
),
if (widget.limitMaximumImageSize) ...[
const VSpace(6.0),
@@ -188,13 +185,30 @@ class _UploadImageMenuState extends State<UploadImageMenu> {
),
),
);
// case UploadImageType.openAI:
// return supportOpenAI
// ? Expanded(
// child: Container(
// padding: const EdgeInsets.all(8.0),
// constraints: constraints,
// child: OpenAIImageWidget(
// onSelectNetworkImage: widget.onSelectedAIImage,
// ),
// ),
// )
// : Padding(
// padding: const EdgeInsets.all(8.0),
// child: FlowyText(
// LocaleKeys.document_imageBlock_pleaseInputYourOpenAIKey.tr(),
// ),
// );
case UploadImageType.stabilityAI:
return supportStabilityAI
? Expanded(
child: Container(
padding: const EdgeInsets.all(8.0),
child: StabilityAIImageWidget(
onSelectImage: (url) => widget.onSelectedLocalImages([url]),
onSelectImage: widget.onSelectedLocalImage,
),
),
)
@@ -1,6 +1,3 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/block_menu/block_menu_button.dart';
@@ -10,10 +7,10 @@ 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_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import '../image/custom_image_block_component/custom_image_block_component.dart';
class LinkPreviewMenu extends StatefulWidget {
const LinkPreviewMenu({
super.key,
@@ -75,7 +72,7 @@ class _LinkPreviewMenuState extends State<LinkPreviewMenu> {
}
void copyImageLink() {
final url = widget.node.attributes[CustomImageBlockKeys.url];
final url = widget.node.attributes[ImageBlockKeys.url];
if (url != null) {
Clipboard.setData(ClipboardData(text: url));
showSnackBarMessage(
@@ -7,8 +7,6 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/base/type_option_menu_item.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_placeholder.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_placeholder.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mobile_page_selector_sheet.dart';
@@ -198,19 +196,6 @@ class _AddBlockMenu extends StatelessWidget {
});
},
),
TypeOptionMenuItemValue(
value: MultiImageBlockKeys.type,
backgroundColor: colorMap[ImageBlockKeys.type]!,
text: LocaleKeys.document_plugins_photoGallery_name.tr(),
icon: FlowySvgs.m_add_block_photo_gallery_s,
onTap: (_, __) async {
AppGlobals.rootNavKey.currentContext?.pop(true);
Future.delayed(const Duration(milliseconds: 400), () async {
final imagePlaceholderKey = GlobalKey<MultiImagePlaceholderState>();
await editorState.insertEmptyMultiImageBlock(imagePlaceholderKey);
});
},
),
// date
TypeOptionMenuItemValue(
@@ -12,6 +12,7 @@ import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/decoration.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:provider/provider.dart';
@@ -117,6 +118,10 @@ class _SmartEditBlockComponentWidgetState
triggerActions: PopoverTriggerFlags.none,
margin: EdgeInsets.zero,
constraints: BoxConstraints(maxWidth: width),
decoration: FlowyDecoration.decoration(
Colors.transparent,
Colors.transparent,
),
child: const SizedBox(
width: double.infinity,
),
@@ -1,7 +1,5 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import '../image/custom_image_block_component/custom_image_block_component.dart';
class CustomImageNodeParser extends NodeParser {
const CustomImageNodeParser();
@@ -11,7 +9,7 @@ class CustomImageNodeParser extends NodeParser {
@override
String transform(Node node, DocumentMarkdownEncoder? encoder) {
assert(node.children.isEmpty);
final url = node.attributes[CustomImageBlockKeys.url];
final url = node.attributes[ImageBlockKeys.url];
assert(url != null);
return '![]($url)\n';
}
@@ -19,8 +19,7 @@ export 'font/customize_font_toolbar_item.dart';
export 'header/cover_editor_bloc.dart';
export 'header/custom_cover_picker.dart';
export 'header/document_header_node_widget.dart';
export 'image/custom_image_block_component/image_menu.dart';
export 'image/multi_image_block_component/multi_image_menu.dart';
export 'image/image_menu.dart';
export 'image/image_selection_menu.dart';
export 'image/mobile_image_toolbar_item.dart';
export 'inline_math_equation/inline_math_equation.dart';
@@ -4,7 +4,6 @@ import 'package:appflowy/core/config/kv.dart';
import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
typedef FeatureFlagMap = Map<FeatureFlag, bool>;
@@ -92,7 +91,7 @@ enum FeatureFlag {
bool get isOn {
if ([
FeatureFlag.planBilling,
// FeatureFlag.planBilling,
// release this feature in version 0.6.1
FeatureFlag.spaceDesign,
// release this feature in version 0.5.9
@@ -13,9 +13,6 @@ const _imgUrlPattern =
r'(https?:\/\/)([^\s(["<,>/]*)(\/)[^\s[",><]*(.png|.jpg|.gif|.webm)(\?[^\s[",><]*)?';
final imgUrlRegex = RegExp(_imgUrlPattern);
const _imgExtensionPattern = r'\.(gif|jpe?g|tiff?|png|webp|bmp)$';
final imgExtensionRegex = RegExp(_imgExtensionPattern);
/// This pattern allows for both HTTP and HTTPS Scheme
/// It allows for query parameters
/// It only allows the following video extensions:
@@ -1,69 +0,0 @@
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/workspace.pb.dart';
import 'package:appflowy_result/appflowy_result.dart';
import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'local_ai_on_boarding_bloc.freezed.dart';
class LocalAIOnBoardingBloc
extends Bloc<LocalAIOnBoardingEvent, LocalAIOnBoardingState> {
LocalAIOnBoardingBloc(this.workspaceId)
: super(const LocalAIOnBoardingState()) {
_dispatch();
}
final String workspaceId;
void _dispatch() {
on<LocalAIOnBoardingEvent>((event, emit) {
event.when(
started: () {
_loadSubscriptionPlans();
},
didGetSubscriptionPlans: (result) {
result.fold(
(workspaceSubInfo) {
final isPurchaseAILocal = workspaceSubInfo.addOns.any((addOn) {
return addOn.type == WorkspaceAddOnPBType.AddOnAiLocal;
});
emit(
state.copyWith(isPurchaseAILocal: isPurchaseAILocal),
);
},
(err) {
Log.error("Failed to get subscription plans: $err");
},
);
},
);
});
}
void _loadSubscriptionPlans() {
final payload = UserWorkspaceIdPB()..workspaceId = workspaceId;
UserEventGetWorkspaceSubscriptionInfo(payload).send().then((result) {
if (!isClosed) {
add(LocalAIOnBoardingEvent.didGetSubscriptionPlans(result));
}
});
}
}
@freezed
class LocalAIOnBoardingEvent with _$LocalAIOnBoardingEvent {
const factory LocalAIOnBoardingEvent.started() = _Started;
const factory LocalAIOnBoardingEvent.didGetSubscriptionPlans(
FlowyResult<WorkspaceSubscriptionInfoPB, FlowyError> result,
) = _LoadSubscriptionPlans;
}
@freezed
class LocalAIOnBoardingState with _$LocalAIOnBoardingState {
const factory LocalAIOnBoardingState({
@Default(false) bool isPurchaseAILocal,
}) = _LocalAIOnBoardingState;
}
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:appflowy/core/helpers/url_launcher.dart';
import 'package:appflowy/workspace/application/settings/ai/local_llm_listener.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
@@ -68,20 +67,8 @@ class PluginStateBloc extends Bloc<PluginStateEvent, PluginStateState> {
break;
}
},
restartLocalAI: () async {
emit(
const PluginStateState(action: PluginStateAction.loadingPlugin()),
);
unawaited(ChatEventRestartLocalAIChat().send());
},
openModelDirectory: () async {
final result = await ChatEventGetModelStorageDirectory().send();
result.fold(
(data) {
afLaunchUrl(Uri.file(data.filePath));
},
(err) => Log.error(err.toString()),
);
restartLocalAI: () {
ChatEventRestartLocalAIChat().send();
},
);
}
@@ -93,15 +80,12 @@ class PluginStateEvent with _$PluginStateEvent {
const factory PluginStateEvent.updateState(LocalAIPluginStatePB pluginState) =
_UpdatePluginState;
const factory PluginStateEvent.restartLocalAI() = _RestartLocalAI;
const factory PluginStateEvent.openModelDirectory() =
_OpenModelStorageDirectory;
}
@freezed
class PluginStateState with _$PluginStateState {
const factory PluginStateState({
required PluginStateAction action,
}) = _PluginStateState;
const factory PluginStateState({required PluginStateAction action}) =
_PluginStateState;
}
@freezed
@@ -1,8 +1,9 @@
import 'package:flutter/material.dart';
import 'package:appflowy/workspace/application/settings/appearance/base_appearance.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flutter/material.dart';
class DesktopAppearance extends BaseAppearance {
@override
@@ -74,12 +75,18 @@ class DesktopAppearance extends BaseAppearance {
contentTextStyle: TextStyle(color: colorScheme.onSurface),
),
scrollbarTheme: ScrollbarThemeData(
thumbColor: WidgetStateProperty.resolveWith(
(states) => states.any(scrollbarInteractiveStates.contains)
? theme.scrollbarHoverColor
: theme.scrollbarColor,
),
thickness: WidgetStateProperty.resolveWith((_) => 4.0),
thumbColor: WidgetStateProperty.resolveWith((states) {
if (states.any(scrollbarInteractiveStates.contains)) {
return theme.shader3;
}
return theme.shader5;
}),
thickness: WidgetStateProperty.resolveWith((states) {
if (states.any(scrollbarInteractiveStates.contains)) {
return 4;
}
return 3.0;
}),
crossAxisMargin: 0.0,
mainAxisMargin: 6.0,
radius: Corners.s10Radius,
@@ -140,9 +147,6 @@ class DesktopAppearance extends BaseAppearance {
),
onBackground: theme.text,
background: theme.surface,
borderColor: theme.borderColor,
scrollbarColor: theme.scrollbarColor,
scrollbarHoverColor: theme.scrollbarHoverColor,
),
],
);
@@ -1,10 +1,11 @@
import 'package:flutter/material.dart';
// ThemeData in mobile
import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_toolbar_theme.dart';
import 'package:appflowy/workspace/application/settings/appearance/base_appearance.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flutter/material.dart';
class MobileAppearance extends BaseAppearance {
static const _primaryColor = Color(0xFF00BCF0); //primary 100
@@ -275,9 +276,6 @@ class MobileAppearance extends BaseAppearance {
),
onBackground: onBackground,
background: background,
borderColor: theme.borderColor,
scrollbarColor: theme.scrollbarColor,
scrollbarHoverColor: theme.scrollbarHoverColor,
),
ToolbarColorExtension.fromBrightness(brightness),
],
@@ -1,3 +1,6 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/plugins/blank/blank.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart';
@@ -24,13 +27,12 @@ import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
show UserProfilePB;
import 'package:flowy_infra_ui/style_widget/container.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:sized_context/sized_context.dart';
import 'package:styled_widget/styled_widget.dart';
import '../widgets/edit_panel/edit_panel.dart';
import '../widgets/sidebar_resizer.dart';
import 'home_layout.dart';
import 'home_stack.dart';
@@ -162,9 +164,7 @@ class DesktopHomeScreen extends StatelessWidget {
userProfile: userProfile,
workspaceSetting: workspaceSetting,
);
final homeMenuResizer =
layout.showMenu ? const SidebarResizer() : const SizedBox.shrink();
final homeMenuResizer = _buildHomeMenuResizer(context, layout: layout);
final editPanel = _buildEditPanel(context, layout: layout);
return _layoutWidgets(
@@ -218,6 +218,39 @@ class DesktopHomeScreen extends StatelessWidget {
);
}
Widget _buildHomeMenuResizer(
BuildContext context, {
required HomeLayout layout,
}) {
if (!layout.showMenu) {
return const SizedBox.shrink();
}
return MouseRegion(
cursor: SystemMouseCursors.resizeLeftRight,
child: GestureDetector(
dragStartBehavior: DragStartBehavior.down,
onHorizontalDragStart: (details) => context
.read<HomeSettingBloc>()
.add(const HomeSettingEvent.editPanelResizeStart()),
onHorizontalDragUpdate: (details) => context
.read<HomeSettingBloc>()
.add(HomeSettingEvent.editPanelResized(details.localPosition.dx)),
onHorizontalDragEnd: (details) => context
.read<HomeSettingBloc>()
.add(const HomeSettingEvent.editPanelResizeEnd()),
onHorizontalDragCancel: () => context
.read<HomeSettingBloc>()
.add(const HomeSettingEvent.editPanelResizeEnd()),
behavior: HitTestBehavior.translucent,
child: SizedBox(
width: 10,
height: MediaQuery.of(context).size.height,
),
),
);
}
Widget _layoutWidgets({
required HomeLayout layout,
required Widget sidebar,
@@ -263,7 +296,7 @@ class DesktopHomeScreen extends StatelessWidget {
)
.positioned(left: 0, top: 0, width: layout.menuWidth, bottom: 0),
homeMenuResizer
.positioned(left: layout.menuWidth)
.positioned(left: layout.menuWidth - 5)
.animate(layout.animDuration, Curves.easeOutQuad),
],
);
@@ -1,5 +1,4 @@
import 'dart:io' show Platform;
import 'dart:math';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
import 'package:flowy_infra/size.dart';
@@ -17,8 +16,6 @@ class HomeLayout {
menuWidth = Sizes.sideBarWidth;
menuWidth += homeSetting.resizeOffset;
menuWidth = max(menuWidth, HomeSizes.minimumSidebarWidth);
final screenWidthPx = context.widthPx;
context
.read<HomeSettingBloc>()
@@ -8,7 +8,6 @@ class HomeSizes {
static const double workspaceSectionHeight = 32;
static const double searchSectionHeight = 30;
static const double newPageSectionHeight = 30;
static const double minimumSidebarWidth = 268;
}
class HomeInsets {
@@ -1,5 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/startup/tasks/app_window_size_manager.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
@@ -9,7 +11,6 @@ import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/sidebar_setting.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:flutter/material.dart';
import 'package:hotkey_manager/hotkey_manager.dart';
import 'package:provider/provider.dart';
import 'package:scaled_app/scaled_app.dart';
@@ -17,7 +18,6 @@ import 'package:scaled_app/scaled_app.dart';
typedef KeyDownHandler = void Function(HotKey hotKey);
ValueNotifier<int> switchToTheNextSpace = ValueNotifier(0);
ValueNotifier<int> createNewPageNotifier = ValueNotifier(0);
/// Helper class that utilizes the global [HotKeyManager] to easily
/// add a [HotKey] with different handlers.
@@ -180,16 +180,6 @@ class _HomeHotKeysState extends State<HomeHotKeys> {
keyDownHandler: (_) => switchToTheNextSpace.value++,
),
// Create a new page
HotKeyItem(
hotKey: HotKey(
KeyCode.keyN,
modifiers: [Platform.isMacOS ? KeyModifier.meta : KeyModifier.control],
scope: HotKeyScope.inapp,
),
keyDownHandler: (_) => createNewPageNotifier.value++,
),
// Open settings dialog
openSettingsHotKey(context, widget.userProfile),
];
@@ -11,6 +11,7 @@ import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/decoration.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -171,6 +172,11 @@ class FavoriteMoreButton extends StatelessWidget {
constraints: const BoxConstraints(
minWidth: minWidth,
),
decoration: FlowyDecoration.decoration(
Theme.of(context).cardColor,
Theme.of(context).colorScheme.shadow,
borderRadius: 10.0,
),
popupBuilder: (_) {
return MultiBlocProvider(
providers: [
@@ -137,7 +137,6 @@ class _FavoriteGroups extends StatelessWidget {
state.otherViews,
LocaleKeys.sideBar_others.tr(),
);
return Container(
width: minWidth - 2 * _kHorizontalPadding,
constraints: const BoxConstraints(
@@ -150,14 +149,15 @@ class _FavoriteGroups extends StatelessWidget {
children: [
if (today.isNotEmpty) ...[
...today,
const FlowyDivider(),
const VSpace(16),
const VSpace(8),
const Divider(height: 1),
const VSpace(8),
],
if (thisWeek.isNotEmpty) ...[
...thisWeek,
const VSpace(8),
const FlowyDivider(),
const VSpace(16),
const Divider(height: 1),
const VSpace(8),
],
...others.isNotEmpty && (today.isNotEmpty || thisWeek.isNotEmpty)
? others
@@ -182,10 +182,13 @@ class _FavoriteGroups extends StatelessWidget {
return [
if (views.isNotEmpty) ...[
if (showHeader)
FlowyText(
title,
fontSize: 12.0,
color: Theme.of(context).hintColor,
SizedBox(
height: 24,
child: FlowyText(
title,
fontSize: 12.0,
color: Theme.of(context).hintColor,
),
),
const VSpace(2),
_FavoriteGroupedViews(views: views),
@@ -21,8 +21,8 @@ class FavoritePinAction extends StatelessWidget {
: LocaleKeys.favorite_addToSidebar.tr();
final icon = FlowySvg(
view.isPinned
? FlowySvgs.favorite_section_unpin_s
: FlowySvgs.favorite_section_pin_s,
? FlowySvgs.favorite_section_pin_s
: FlowySvgs.favorite_section_unpin_s,
);
return FlowyTooltip(
message: tooltip,
@@ -1,6 +1,5 @@
import 'package:appflowy/shared/feature_flags.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/footer/sidebar_toast.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
@@ -20,12 +19,7 @@ class SidebarFooter extends StatelessWidget {
Widget build(BuildContext context) {
return Column(
children: [
if (FeatureFlag.planBilling.isOn)
BillingGateGuard(
builder: (context) {
return const SidebarToast();
},
),
if (FeatureFlag.planBilling.isOn) const SidebarToast(),
const Row(
children: [
Expanded(child: SidebarTrashButton()),
@@ -3,6 +3,7 @@ import 'dart:io' show Platform;
import 'package:appflowy/core/frameless_window.dart';
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/home/home_setting_bloc.dart';
import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
@@ -64,17 +65,20 @@ class SidebarTopMenu extends StatelessWidget {
}
Widget _buildCollapseMenuButton(BuildContext context) {
final color = Theme.of(context).isLightMode ? Colors.white : Colors.black;
final textSpan = TextSpan(
children: [
TextSpan(
text: '${LocaleKeys.sideBar_closeSidebar.tr()}\n',
style: context.tooltipTextStyle(),
style:
Theme.of(context).tooltipTheme.textStyle!.copyWith(color: color),
),
TextSpan(
text: Platform.isMacOS ? '⌘+.' : 'Ctrl+\\',
style: context
.tooltipTextStyle()
?.copyWith(color: Theme.of(context).hintColor),
style: Theme.of(context)
.tooltipTheme
.textStyle!
.copyWith(color: Theme.of(context).hintColor),
),
],
);
@@ -1,4 +1,3 @@
import 'package:appflowy/generated/locale_keys.g.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/sidebar/space/space_search_bloc.dart';
@@ -6,12 +5,9 @@ import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -127,15 +123,12 @@ class _MovePageMenuState extends State<MovePageMenu> {
expand: true,
height: 30,
showCreateButton: false,
child: FlowyTooltip(
message: LocaleKeys.space_switchSpace.tr(),
child: CurrentSpace(
onTapBlankArea: () {
// move the page to current space
widget.onSelected(space, space);
},
space: space,
),
child: CurrentSpace(
onTapBlankArea: () {
// move the page to current space
widget.onSelected(space, space);
},
space: space,
),
),
Expanded(
@@ -4,7 +4,6 @@ import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:appflowy/workspace/presentation/home/hotkeys.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/rename_view_dialog.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -12,35 +11,18 @@ import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class SidebarNewPageButton extends StatefulWidget {
class SidebarNewPageButton extends StatelessWidget {
const SidebarNewPageButton({
super.key,
});
@override
State<SidebarNewPageButton> createState() => _SidebarNewPageButtonState();
}
class _SidebarNewPageButtonState extends State<SidebarNewPageButton> {
@override
void initState() {
super.initState();
createNewPageNotifier.addListener(_createNewPage);
}
@override
void dispose() {
createNewPageNotifier.removeListener(_createNewPage);
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8),
height: HomeSizes.newPageSectionHeight,
child: FlowyButton(
onTap: () async => _createNewPage(),
onTap: () async => _createNewPage(context),
leftIcon: const FlowySvg(
FlowySvgs.new_app_m,
blendMode: null,
@@ -56,7 +38,7 @@ class _SidebarNewPageButtonState extends State<SidebarNewPageButton> {
);
}
Future<void> _createNewPage() async {
Future<void> _createNewPage(BuildContext context) async {
return createViewAndShowRenameDialogIfNeeded(
context,
LocaleKeys.newPageText.tr(),
@@ -1,5 +1,7 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/blank/blank.dart';
@@ -33,8 +35,9 @@ import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
show UserProfilePB;
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flowy_infra_ui/style_widget/button.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Loading? _duplicateSpaceLoading;
@@ -330,7 +333,10 @@ class _SidebarState extends State<_Sidebar> {
child: child,
);
},
child: const FlowyDivider(),
child: const Divider(
color: Color(0x141F2329),
height: 0.5,
),
),
),
@@ -340,7 +346,7 @@ class _SidebarState extends State<_Sidebar> {
Padding(
padding: menuHorizontalInset +
const EdgeInsets.symmetric(horizontal: 4.0),
child: const FlowyDivider(),
child: const Divider(height: 0.5, color: Color(0x141F2329)),
),
const VSpace(8),
@@ -397,16 +403,13 @@ class _SidebarState extends State<_Sidebar> {
: Expanded(
child: Padding(
padding: menuHorizontalInset - const EdgeInsets.only(right: 6),
child: FlowyScrollbar(
child: SingleChildScrollView(
padding: const EdgeInsets.only(right: 6),
controller: _scrollController,
child: SingleChildScrollView(
padding: const EdgeInsets.only(right: 6),
controller: _scrollController,
physics: const ClampingScrollPhysics(),
child: SidebarSpace(
userProfile: widget.userProfile,
isHoverEnabled: !_isScrolling,
),
physics: const ClampingScrollPhysics(),
child: SidebarSpace(
userProfile: widget.userProfile,
isHoverEnabled: !_isScrolling,
),
),
),
@@ -1,8 +0,0 @@
import 'package:appflowy/util/theme_extension.dart';
import 'package:flutter/material.dart';
extension SpacePermissionColorExtension on BuildContext {
Color get enableBorderColor => Theme.of(this).isLightMode
? const Color(0x1E171717)
: const Color(0xFF3A3F49);
}
@@ -1,6 +1,5 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/_extension.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/space_icon_popup.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -25,22 +24,19 @@ class _CreateSpacePopupState extends State<CreateSpacePopup> {
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
width: 524,
width: 500,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
FlowyText(
LocaleKeys.space_createNewSpace.tr(),
fontSize: 18.0,
figmaLineHeight: 24.0,
),
const VSpace(2.0),
FlowyText(
const VSpace(6.0),
FlowyText.regular(
LocaleKeys.space_createSpaceDescription.tr(),
fontSize: 14.0,
fontWeight: FontWeight.w300,
color: Theme.of(context).hintColor,
figmaLineHeight: 18.0,
maxLines: 2,
),
const VSpace(16.0),
@@ -110,16 +106,14 @@ class _SpaceNameTextField extends StatelessWidget {
LocaleKeys.space_spaceName.tr(),
fontSize: 14.0,
color: Theme.of(context).hintColor,
figmaLineHeight: 18.0,
),
const VSpace(6.0),
SizedBox(
height: 40,
child: FlowyTextField(
hintText: LocaleKeys.space_spaceNamePlaceholder.tr(),
hintText: LocaleKeys.space_spaceName.tr(),
onChanged: onChanged,
onSubmitted: onSubmitted,
enableBorderColor: context.enableBorderColor,
),
),
],
@@ -1,3 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/util/theme_extension.dart';
@@ -6,7 +10,6 @@ import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/_extension.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/sidebar_space_menu.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/space_icon.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
@@ -16,11 +19,9 @@ import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/decoration.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class SpacePermissionSwitch extends StatefulWidget {
@@ -54,7 +55,6 @@ class _SpacePermissionSwitchState extends State<SpacePermissionSwitch> {
LocaleKeys.space_permission.tr(),
fontSize: 14.0,
color: Theme.of(context).hintColor,
figmaLineHeight: 18.0,
),
const VSpace(6.0),
AppFlowyPopover(
@@ -63,11 +63,16 @@ class _SpacePermissionSwitchState extends State<SpacePermissionSwitch> {
constraints: const BoxConstraints(maxWidth: 500),
offset: const Offset(0, 4),
margin: EdgeInsets.zero,
decoration: FlowyDecoration.decoration(
Theme.of(context).cardColor,
Theme.of(context).colorScheme.shadow,
borderRadius: 10,
),
popupBuilder: (_) => _buildPermissionButtons(),
child: DecoratedBox(
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(color: context.enableBorderColor),
side: BorderSide(color: Theme.of(context).colorScheme.outline),
borderRadius: BorderRadius.circular(10),
),
),
@@ -143,13 +148,9 @@ class SpacePermissionButton extends StatelessWidget {
radius: BorderRadius.circular(10),
iconPadding: 16.0,
leftIcon: FlowySvg(icon),
leftIconSize: const Size.square(20),
rightIcon: showArrow
? const FlowySvg(FlowySvgs.space_permission_dropdown_s)
: null,
borderColor: Theme.of(context).isLightMode
? const Color(0x1E171717)
: const Color(0xFF3A3F49),
text: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -461,29 +462,32 @@ class CurrentSpace extends StatelessWidget {
@override
Widget build(BuildContext context) {
final child = Row(
mainAxisSize: MainAxisSize.min,
children: [
SpaceIcon(
dimension: 20,
space: space,
cornerRadius: 6.0,
),
const HSpace(10),
Flexible(
child: FlowyText.medium(
space.name,
fontSize: 14.0,
overflow: TextOverflow.ellipsis,
final child = FlowyTooltip(
message: LocaleKeys.space_switchSpace.tr(),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
SpaceIcon(
dimension: 20,
space: space,
cornerRadius: 6.0,
),
),
const HSpace(4.0),
FlowySvg(
context.read<SpaceBloc>().state.isExpanded
? FlowySvgs.workspace_drop_down_menu_show_s
: FlowySvgs.workspace_drop_down_menu_hide_s,
),
],
const HSpace(10),
Flexible(
child: FlowyText.medium(
space.name,
fontSize: 14.0,
overflow: TextOverflow.ellipsis,
),
),
const HSpace(4.0),
FlowySvg(
context.read<SpaceBloc>().state.isExpanded
? FlowySvgs.workspace_drop_down_menu_show_s
: FlowySvgs.workspace_drop_down_menu_hide_s,
),
],
),
);
if (onTapBlankArea != null) {
@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/manage_space_popup.dart';
@@ -104,17 +105,20 @@ class _SidebarSpaceHeaderState extends State<SidebarSpaceHeader> {
}
Widget _buildChild() {
final color = Theme.of(context).isLightMode ? Colors.white : Colors.black;
final textSpan = TextSpan(
children: [
TextSpan(
text: '${LocaleKeys.space_quicklySwitch.tr()}\n',
style: context.tooltipTextStyle(),
style:
Theme.of(context).tooltipTheme.textStyle!.copyWith(color: color),
),
TextSpan(
text: Platform.isMacOS ? '⌘+O' : 'Ctrl+O',
style: context
.tooltipTextStyle()
?.copyWith(color: Theme.of(context).hintColor),
style: Theme.of(context)
.tooltipTheme
.textStyle!
.copyWith(color: Theme.of(context).hintColor),
),
],
);
@@ -40,7 +40,9 @@ class SidebarSpaceMenu extends StatelessWidget {
if (showCreateButton) ...[
const Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: FlowyDivider(),
child: Divider(
height: 0.5,
),
),
const SizedBox(
height: HomeSpaceViewSizes.viewHeight,
@@ -36,24 +36,24 @@ extension ViewMoreActionTypeExtension on SpaceMoreActionType {
}
}
FlowySvgData get leftIconSvg {
Widget get leftIcon {
switch (this) {
case SpaceMoreActionType.delete:
return FlowySvgs.trash_s;
return const FlowySvg(FlowySvgs.trash_s, blendMode: null);
case SpaceMoreActionType.rename:
return FlowySvgs.view_item_rename_s;
return const FlowySvg(FlowySvgs.view_item_rename_s);
case SpaceMoreActionType.changeIcon:
return FlowySvgs.change_icon_s;
return const FlowySvg(FlowySvgs.change_icon_s);
case SpaceMoreActionType.collapseAllPages:
return FlowySvgs.collapse_all_page_s;
return const FlowySvg(FlowySvgs.collapse_all_page_s);
case SpaceMoreActionType.addNewSpace:
return FlowySvgs.space_add_s;
return const FlowySvg(FlowySvgs.space_add_s);
case SpaceMoreActionType.manage:
return FlowySvgs.space_manage_s;
return const FlowySvg(FlowySvgs.space_manage_s);
case SpaceMoreActionType.duplicate:
return FlowySvgs.duplicate_s;
return const FlowySvg(FlowySvgs.duplicate_s);
case SpaceMoreActionType.divider:
throw UnsupportedError('Divider does not have an icon');
return const SizedBox.shrink();
}
}
@@ -3,6 +3,7 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/decoration.dart';
import 'package:flutter/material.dart';
final builtInSpaceColors = [
@@ -58,6 +59,11 @@ class _SpaceIconPopupState extends State<SpaceIconPopup> {
Widget build(BuildContext context) {
return AppFlowyPopover(
offset: const Offset(0, 4),
decoration: FlowyDecoration.decoration(
Theme.of(context).cardColor,
Theme.of(context).colorScheme.shadow,
borderRadius: 10,
),
constraints: const BoxConstraints(maxWidth: 220),
margin: const EdgeInsets.symmetric(horizontal: 14.0, vertical: 12.0),
direction: PopoverDirection.bottomWithCenterAligned,
@@ -129,7 +129,7 @@ class SpaceMoreActionTypeWrapper extends CustomActionCell {
Widget _buildDivider() {
return const Padding(
padding: EdgeInsets.all(8.0),
child: FlowyDivider(),
child: Divider(height: 1.0),
);
}
@@ -158,24 +158,22 @@ class SpaceMoreActionTypeWrapper extends CustomActionCell {
padding: const EdgeInsets.symmetric(vertical: 2.0),
child: Opacity(
opacity: disable ? 0.3 : 1.0,
child: FlowyIconTextButton(
child: FlowyButton(
disable: disable,
margin: const EdgeInsets.symmetric(horizontal: 6),
leftIcon: inner.leftIcon,
rightIcon: inner.rightIcon,
iconPadding: 10.0,
text: SizedBox(
// height: 16.0,
child: FlowyText.regular(
inner.name,
color: inner == SpaceMoreActionType.delete
? Theme.of(context).colorScheme.error
: null,
),
),
onTap: onTap,
leftIconBuilder: (onHover) => FlowySvg(
inner.leftIconSvg,
color: inner == SpaceMoreActionType.delete && onHover
? Theme.of(context).colorScheme.error
: null,
),
rightIconBuilder: (_) => inner.rightIcon,
textBuilder: (onHover) => FlowyText.regular(
inner.name,
color: inner == SpaceMoreActionType.delete && onHover
? Theme.of(context).colorScheme.error
: null,
),
),
),
);
@@ -49,31 +49,32 @@ extension ViewMoreActionTypeExtension on ViewMoreActionType {
}
}
FlowySvgData get leftIconSvg {
Widget get leftIcon {
switch (this) {
case ViewMoreActionType.delete:
return FlowySvgs.trash_s;
return const FlowySvg(FlowySvgs.trash_s, blendMode: null);
case ViewMoreActionType.favorite:
return FlowySvgs.favorite_s;
return const FlowySvg(FlowySvgs.favorite_s);
case ViewMoreActionType.unFavorite:
return FlowySvgs.unfavorite_s;
return const FlowySvg(FlowySvgs.unfavorite_s);
case ViewMoreActionType.duplicate:
return FlowySvgs.duplicate_s;
return const FlowySvg(FlowySvgs.duplicate_s);
case ViewMoreActionType.copyLink:
return const Icon(Icons.copy);
case ViewMoreActionType.rename:
return FlowySvgs.view_item_rename_s;
return const FlowySvg(FlowySvgs.view_item_rename_s);
case ViewMoreActionType.moveTo:
return FlowySvgs.move_to_s;
return const FlowySvg(FlowySvgs.move_to_s);
case ViewMoreActionType.openInNewTab:
return FlowySvgs.view_item_open_in_new_tab_s;
return const FlowySvg(FlowySvgs.view_item_open_in_new_tab_s);
case ViewMoreActionType.changeIcon:
return FlowySvgs.change_icon_s;
return const FlowySvg(FlowySvgs.change_icon_s);
case ViewMoreActionType.collapseAllPages:
return FlowySvgs.collapse_all_page_s;
return const FlowySvg(FlowySvgs.collapse_all_page_s);
case ViewMoreActionType.divider:
case ViewMoreActionType.lastModified:
case ViewMoreActionType.copyLink:
case ViewMoreActionType.created:
throw UnsupportedError('No left icon for $this');
return const SizedBox.shrink();
}
}
@@ -491,7 +491,6 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
final name = FlowyText.regular(
widget.view.name,
overflow: TextOverflow.ellipsis,
// figmaLineHeight: 18.0,
);
final children = [
const HSpace(2),
@@ -101,8 +101,7 @@ class ViewMoreActionButton extends StatelessWidget {
]);
// Chat doesn't change collapse
// Only show collapse all pages if the view has child views
if (view.layout != ViewLayoutPB.Chat && view.childViews.isNotEmpty) {
if (view.layout != ViewLayoutPB.Chat) {
actionTypes.add(ViewMoreActionType.collapseAllPages);
actionTypes.add(ViewMoreActionType.divider);
}
@@ -205,7 +204,7 @@ class ViewMoreActionTypeWrapper extends CustomActionCell {
Widget _buildDivider() {
return const Padding(
padding: EdgeInsets.all(8.0),
child: FlowyDivider(),
child: Divider(height: 1.0),
);
}
@@ -238,24 +237,18 @@ class ViewMoreActionTypeWrapper extends CustomActionCell {
return Container(
height: 34,
padding: const EdgeInsets.symmetric(vertical: 2.0),
child: FlowyIconTextButton(
child: FlowyButton(
margin: const EdgeInsets.symmetric(horizontal: 6),
onTap: onTap,
// show the error color when delete is hovered
leftIconBuilder: (onHover) => FlowySvg(
inner.leftIconSvg,
color: inner == ViewMoreActionType.delete && onHover
? Theme.of(context).colorScheme.error
: null,
),
rightIconBuilder: (_) => inner.rightIcon,
leftIcon: inner.leftIcon,
rightIcon: inner.rightIcon,
iconPadding: 10.0,
textBuilder: (onHover) => FlowyText.regular(
text: FlowyText.regular(
inner.name,
color: inner == ViewMoreActionType.delete && onHover
color: inner == ViewMoreActionType.delete
? Theme.of(context).colorScheme.error
: null,
),
onTap: onTap,
),
);
}
@@ -2,6 +2,7 @@ import 'dart:io';
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/home/home_setting_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
@@ -64,17 +65,23 @@ class FlowyNavigation extends StatelessWidget {
buildWhen: (p, c) => p.isMenuCollapsed != c.isMenuCollapsed,
builder: (context, state) {
if (!PlatformExtension.isWindows && state.isMenuCollapsed) {
final color =
Theme.of(context).isLightMode ? Colors.white : Colors.black;
final textSpan = TextSpan(
children: [
TextSpan(
text: '${LocaleKeys.sideBar_openSidebar.tr()}\n',
style: context.tooltipTextStyle(),
style: Theme.of(context)
.tooltipTheme
.textStyle!
.copyWith(color: color),
),
TextSpan(
text: Platform.isMacOS ? '⌘+.' : 'Ctrl+\\',
style: context
.tooltipTextStyle()
?.copyWith(color: Theme.of(context).hintColor),
style: Theme.of(context)
.tooltipTheme
.textStyle!
.copyWith(color: Theme.of(context).hintColor),
),
],
);
@@ -37,10 +37,15 @@ class DownloadingIndicator extends StatelessWidget {
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Column(
children: [
DownloadingProgressBar(onCancel: onCancel),
],
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
children: [
// const DownloadingPrompt(),
// const VSpace(12),
DownloadingProgressBar(onCancel: onCancel),
],
),
),
),
),
@@ -60,12 +65,9 @@ class DownloadingProgressBar extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Opacity(
opacity: 0.6,
child: FlowyText(
"${LocaleKeys.settings_aiPage_keys_downloadingModel.tr()}: ${state.object}",
fontSize: 11,
),
FlowyText(
"${LocaleKeys.settings_aiPage_keys_downloadingModel.tr()}: ${state.object}",
fontSize: 11,
),
IntrinsicHeight(
child: Row(
@@ -1,7 +1,7 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/workspace/application/settings/ai/local_ai_chat_bloc.dart';
import 'package:appflowy/workspace/application/settings/ai/local_ai_chat_toggle_bloc.dart';
import 'package:appflowy/workspace/presentation/settings/pages/setting_ai_view/downloading_model.dart';
import 'package:appflowy/workspace/presentation/settings/pages/setting_ai_view/downloading.dart';
import 'package:appflowy/workspace/presentation/settings/pages/setting_ai_view/init_local_ai.dart';
import 'package:appflowy/workspace/presentation/settings/pages/setting_ai_view/plugin_state.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
@@ -70,7 +70,7 @@ class LocalAIChatSetting extends StatelessWidget {
header: const LocalAIChatSettingHeader(),
collapsed: const SizedBox.shrink(),
expanded: Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -240,7 +240,7 @@ class _LocalLLMInfoWidget extends StatelessWidget {
);
},
finishDownload: () => const InitLocalAIIndicator(),
checkPluginState: () => const PluginStateIndicator(),
checkPluginState: () => const CheckPluginStateIndicator(),
);
return Padding(
@@ -253,12 +253,9 @@ class _LocalLLMInfoWidget extends StatelessWidget {
} else {
return Opacity(
opacity: 0.5,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: FlowyText(
error.msg,
maxLines: 10,
),
child: FlowyText(
error.msg,
maxLines: 10,
),
);
}
@@ -6,7 +6,6 @@ import 'package:appflowy/workspace/presentation/widgets/toggle/toggle.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:expandable/expandable.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/workspace/application/settings/ai/settings_ai_bloc.dart';
@@ -56,7 +55,6 @@ class _LocalAISettingState extends State<LocalAISetting> {
collapsed: const SizedBox.shrink(),
expanded: Column(
children: [
const VSpace(6),
DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context)
@@ -66,8 +64,11 @@ class _LocalAISettingState extends State<LocalAISetting> {
const BorderRadius.all(Radius.circular(4)),
),
child: const Padding(
padding:
EdgeInsets.symmetric(horizontal: 12, vertical: 6),
padding: EdgeInsets.only(
left: 12.0,
top: 6,
bottom: 6,
),
child: LocalAIChatSetting(),
),
),
@@ -8,8 +8,8 @@ import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class PluginStateIndicator extends StatelessWidget {
const PluginStateIndicator({super.key});
class CheckPluginStateIndicator extends StatelessWidget {
const CheckPluginStateIndicator({super.key});
@override
Widget build(BuildContext context) {
@@ -20,7 +20,7 @@ class PluginStateIndicator extends StatelessWidget {
builder: (context, state) {
return state.action.when(
init: () => const _InitPlugin(),
ready: () => const _LocalAIReadyToUse(),
ready: () => const _ReadyToUse(),
restart: () => const _ReloadButton(),
loadingPlugin: () => const _InitPlugin(),
);
@@ -74,8 +74,8 @@ class _ReloadButton extends StatelessWidget {
}
}
class _LocalAIReadyToUse extends StatelessWidget {
const _LocalAIReadyToUse();
class _ReadyToUse extends StatelessWidget {
const _ReadyToUse();
@override
Widget build(BuildContext context) {
@@ -87,7 +87,7 @@ class _LocalAIReadyToUse extends StatelessWidget {
),
),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
const HSpace(8),
@@ -101,23 +101,6 @@ class _LocalAIReadyToUse extends StatelessWidget {
fontSize: 11,
color: const Color(0xFF1E4620),
),
const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 6),
child: FlowyButton(
useIntrinsicWidth: true,
text: FlowyText(
LocaleKeys.settings_aiPage_keys_openModelDirectory.tr(),
fontSize: 11,
color: const Color(0xFF1E4620),
),
onTap: () {
context.read<PluginStateBloc>().add(
const PluginStateEvent.openModelDirectory(),
);
},
),
),
],
),
),
@@ -1,13 +1,4 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/shared/feature_flags.dart';
import 'package:appflowy/workspace/application/settings/ai/local_ai_on_boarding_bloc.dart';
import 'package:appflowy/workspace/application/settings/settings_dialog_bloc.dart';
import 'package:appflowy/workspace/presentation/settings/pages/setting_ai_view/local_ai_setting.dart';
import 'package:appflowy/workspace/presentation/settings/pages/setting_ai_view/model_selection.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
@@ -52,12 +43,9 @@ class SettingsAIView extends StatelessWidget {
const AIModelSelection(),
];
// children.add(const LocalAISetting());
children.add(const _AISearchToggle(value: false));
children.add(
_LocalAIOnBoarding(
workspaceId: userProfile.workspaceId,
),
);
return SettingsBody(
title: LocaleKeys.settings_aiPage_title.tr(),
@@ -113,113 +101,3 @@ class _AISearchToggle extends StatelessWidget {
);
}
}
class _LocalAIOnBoarding extends StatelessWidget {
const _LocalAIOnBoarding({required this.workspaceId});
final String workspaceId;
@override
Widget build(BuildContext context) {
if (FeatureFlag.planBilling.isOn) {
return BillingGateGuard(
builder: (context) {
return BlocProvider(
create: (context) => LocalAIOnBoardingBloc(workspaceId)
..add(const LocalAIOnBoardingEvent.started()),
child: BlocBuilder<LocalAIOnBoardingBloc, LocalAIOnBoardingState>(
builder: (context, state) {
// Show the local AI settings if the user has purchased the AI Local plan
if (kDebugMode || state.isPurchaseAILocal) {
return const LocalAISetting();
} else {
// Show the upgrade to AI Local plan button if the user has not purchased the AI Local plan
return _UpgradeToAILocalPlan(
onTap: () {
context.read<SettingsDialogBloc>().add(
const SettingsDialogEvent.setSelectedPage(
SettingsPage.plan,
),
);
},
);
}
},
),
);
},
);
} else {
return const SizedBox.shrink();
}
}
}
class _UpgradeToAILocalPlan extends StatefulWidget {
const _UpgradeToAILocalPlan({required this.onTap});
final VoidCallback onTap;
@override
State<_UpgradeToAILocalPlan> createState() => _UpgradeToAILocalPlanState();
}
class _UpgradeToAILocalPlanState extends State<_UpgradeToAILocalPlan> {
bool _isHovered = false;
@override
Widget build(BuildContext context) {
const textGradient = LinearGradient(
begin: Alignment.bottomLeft,
end: Alignment.bottomRight,
colors: [Color(0xFF8032FF), Color(0xFFEF35FF)],
stops: [0.1545, 0.8225],
);
final backgroundGradient = LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
_isHovered
? const Color(0xFF8032FF).withOpacity(0.3)
: Colors.transparent,
_isHovered
? const Color(0xFFEF35FF).withOpacity(0.3)
: Colors.transparent,
],
);
return GestureDetector(
onTap: widget.onTap,
child: MouseRegion(
cursor: SystemMouseCursors.click,
onEnter: (_) => setState(() => _isHovered = true),
onExit: (_) => setState(() => _isHovered = false),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
gradient: backgroundGradient,
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
const FlowySvg(
FlowySvgs.upgrade_storage_s,
blendMode: null,
),
const HSpace(6),
ShaderMask(
shaderCallback: (bounds) => textGradient.createShader(bounds),
blendMode: BlendMode.srcIn,
child: FlowyText(
LocaleKeys.sideBar_upgradeToAILocal.tr(),
color: AFThemeExtension.of(context).strongText,
),
),
],
),
),
),
);
}
}
@@ -1,5 +1,3 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:appflowy/util/int64_extension.dart';
@@ -211,26 +209,22 @@ class _SettingsBillingViewState extends State<SettingsBillingView> {
),
),
const SettingsDashedDivider(),
// Currently, the AI Local tile is only available on macOS
// TODO(nathan): enable windows and linux
if (Platform.isMacOS)
_AITile(
plan: SubscriptionPlanPB.AiLocal,
label: LocaleKeys
.settings_billingPage_addons_aiOnDevice_label
.tr(),
description: LocaleKeys
.settings_billingPage_addons_aiOnDevice_description,
activeDescription: LocaleKeys
.settings_billingPage_addons_aiOnDevice_activeDescription,
canceledDescription: LocaleKeys
.settings_billingPage_addons_aiOnDevice_canceledDescription,
subscriptionInfo:
state.subscriptionInfo.addOns.firstWhereOrNull(
(a) => a.type == WorkspaceAddOnPBType.AddOnAiLocal,
),
_AITile(
plan: SubscriptionPlanPB.AiLocal,
label: LocaleKeys
.settings_billingPage_addons_aiOnDevice_label
.tr(),
description: LocaleKeys
.settings_billingPage_addons_aiOnDevice_description,
activeDescription: LocaleKeys
.settings_billingPage_addons_aiOnDevice_activeDescription,
canceledDescription: LocaleKeys
.settings_billingPage_addons_aiOnDevice_canceledDescription,
subscriptionInfo:
state.subscriptionInfo.addOns.firstWhereOrNull(
(a) => a.type == WorkspaceAddOnPBType.AddOnAiLocal,
),
),
],
),
],
@@ -1,8 +1,5 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/core/helpers/url_launcher.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
@@ -29,6 +26,8 @@ import 'package:flowy_infra_ui/style_widget/button.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttertoast/fluttertoast.dart';
@@ -65,13 +64,13 @@ class SettingsManageDataView extends StatelessWidget {
label: LocaleKeys.settings_common_reset.tr(),
onPressed: () => showConfirmDialog(
context: context,
confirmLabel: LocaleKeys.button_confirm.tr(),
title: LocaleKeys
.settings_manageDataPage_dataStorage_resetDialog_title
.tr(),
description: LocaleKeys
.settings_manageDataPage_dataStorage_resetDialog_description
.tr(),
confirmLabel: LocaleKeys.button_confirm.tr(),
onConfirm: () async {
final directory =
await appFlowyApplicationDataDirectory();
@@ -1,5 +1,3 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
@@ -138,46 +136,38 @@ class _SettingsPlanViewState extends State<SettingsPlanView> {
),
),
const HSpace(8),
// Currently, the AI Local tile is only available on macOS
// TODO(nathan): enable windows and linux
if (Platform.isMacOS)
Flexible(
child: _AddOnBox(
title: LocaleKeys
.settings_planPage_planUsage_addons_aiOnDevice_title
.tr(),
description: LocaleKeys
.settings_planPage_planUsage_addons_aiOnDevice_description
.tr(),
price: LocaleKeys
.settings_planPage_planUsage_addons_aiOnDevice_price
.tr(
args: [
SubscriptionPlanPB.AiLocal.priceAnnualBilling,
],
),
priceInfo: LocaleKeys
.settings_planPage_planUsage_addons_aiOnDevice_priceInfo
.tr(),
billingInfo: LocaleKeys
.settings_planPage_planUsage_addons_aiOnDevice_billingInfo
.tr(
args: [
SubscriptionPlanPB.AiLocal.priceMonthBilling,
],
),
buttonText: state.subscriptionInfo.hasAIOnDevice
? LocaleKeys
.settings_planPage_planUsage_addons_activeLabel
.tr()
: LocaleKeys
.settings_planPage_planUsage_addons_addLabel
.tr(),
isActive: state.subscriptionInfo.hasAIOnDevice,
plan: SubscriptionPlanPB.AiLocal,
Flexible(
child: _AddOnBox(
title: LocaleKeys
.settings_planPage_planUsage_addons_aiOnDevice_title
.tr(),
description: LocaleKeys
.settings_planPage_planUsage_addons_aiOnDevice_description
.tr(),
price: LocaleKeys
.settings_planPage_planUsage_addons_aiOnDevice_price
.tr(
args: [SubscriptionPlanPB.AiLocal.priceAnnualBilling],
),
priceInfo: LocaleKeys
.settings_planPage_planUsage_addons_aiOnDevice_priceInfo
.tr(),
billingInfo: LocaleKeys
.settings_planPage_planUsage_addons_aiOnDevice_billingInfo
.tr(
args: [SubscriptionPlanPB.AiLocal.priceMonthBilling],
),
buttonText: state.subscriptionInfo.hasAIOnDevice
? LocaleKeys
.settings_planPage_planUsage_addons_activeLabel
.tr()
: LocaleKeys
.settings_planPage_planUsage_addons_addLabel
.tr(),
isActive: state.subscriptionInfo.hasAIOnDevice,
plan: SubscriptionPlanPB.AiLocal,
),
),
],
),
],
@@ -1,5 +1,7 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
@@ -43,7 +45,6 @@ import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';
@@ -878,7 +879,16 @@ class _FontSelectorDropdownState extends State<_FontSelectorDropdown> {
maxHeight: 150,
maxWidth: constraints.maxWidth - 90,
),
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.10),
blurRadius: 6,
),
],
),
popupBuilder: (_) => _FontListPopup(
currentFont: appearance.font,
scrollController: _scrollController,
@@ -1,5 +1,3 @@
import 'package:appflowy_backend/log.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
@@ -329,51 +327,3 @@ class AppFlowyCloudEnableSync extends StatelessWidget {
);
}
}
class BillingGateGuard extends StatelessWidget {
const BillingGateGuard({required this.builder, super.key});
final Widget Function(BuildContext context) builder;
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: isBillingEnabled(),
builder: (context, snapshot) {
final isBillingEnabled = snapshot.data ?? false;
if (isBillingEnabled &&
snapshot.connectionState == ConnectionState.done) {
return builder(context);
}
// If the billing is not enabled, show nothing
return const SizedBox.shrink();
},
);
}
}
Future<bool> isBillingEnabled() async {
final result = await UserEventGetCloudConfig().send();
return result.fold((cloudSetting) {
final whiteList = [
"https://beta.appflowy.cloud",
"https://test.appflowy.cloud",
];
if (kDebugMode) {
whiteList.add("http://localhost:8000");
}
if (whiteList.contains(cloudSetting.serverUrl)) {
return true;
} else {
Log.warn(
"Billing is not enabled for this server:${cloudSetting.serverUrl}",
);
return false;
}
}, (err) {
Log.error("Failed to get cloud config: $err");
return false;
});
}
@@ -1,67 +0,0 @@
import 'package:flutter/widgets.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/shared/appflowy_network_image.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
/// Abstract class for providing images to the [InteractiveImageViewer].
///
abstract class AFImageProvider {
const AFImageProvider({this.onDeleteImage});
/// Provide this callback if you want it to be possible to
/// delete the Image through the [InteractiveImageViewer].
///
final Function(int index)? onDeleteImage;
int get imageCount;
int get initialIndex;
ImageBlockData getImage(int index);
Widget renderImage(
BuildContext context,
int index, [
UserProfilePB? userProfile,
]);
}
class AFBlockImageProvider implements AFImageProvider {
const AFBlockImageProvider({
required this.images,
this.initialIndex = 0,
required this.onDeleteImage,
});
final List<ImageBlockData> images;
@override
final Function(int) onDeleteImage;
@override
final int initialIndex;
@override
int get imageCount => images.length;
@override
ImageBlockData getImage(int index) => images[index];
@override
Widget renderImage(
BuildContext context,
int index, [
UserProfilePB? userProfile,
]) {
final image = getImage(index);
if (image.type == CustomImageType.local) {
return Image(image: image.toImageProvider());
}
return FlowyNetworkImage(
url: image.url,
userProfilePB: userProfile,
fit: BoxFit.contain,
);
}
}
@@ -1,338 +0,0 @@
import 'dart:convert';
import 'dart:io';
import 'package:appflowy/core/helpers/url_launcher.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/file_picker/file_picker_impl.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flowy_infra_ui/style_widget/snap_bar.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart';
class InteractiveImageToolbar extends StatelessWidget {
const InteractiveImageToolbar({
super.key,
required this.currentImage,
required this.imageCount,
required this.isFirstIndex,
required this.isLastIndex,
required this.currentScale,
required this.onPrevious,
required this.onNext,
required this.onZoomIn,
required this.onZoomOut,
required this.onScaleChanged,
this.onDelete,
this.userProfile,
});
final ImageBlockData currentImage;
final int imageCount;
final bool isFirstIndex;
final bool isLastIndex;
final int currentScale;
final VoidCallback onPrevious;
final VoidCallback onNext;
final VoidCallback onZoomIn;
final VoidCallback onZoomOut;
final Function(double scale) onScaleChanged;
final UserProfilePB? userProfile;
final VoidCallback? onDelete;
@override
Widget build(BuildContext context) {
return Positioned(
bottom: 16,
left: 0,
right: 0,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: SizedBox(
width: 200,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (imageCount > 1)
_renderToolbarItems(
children: [
_ToolbarItem(
isDisabled: isFirstIndex,
tooltip: LocaleKeys
.document_imageBlock_interactiveViewer_toolbar_previousImageTooltip
.tr(),
icon: FlowySvgs.arrow_left_s,
onTap: () {
if (!isFirstIndex) {
onPrevious();
}
},
),
_ToolbarItem(
isDisabled: isLastIndex,
tooltip: LocaleKeys
.document_imageBlock_interactiveViewer_toolbar_nextImageTooltip
.tr(),
icon: FlowySvgs.arrow_right_s,
onTap: () {
if (!isLastIndex) {
onNext();
}
},
),
],
),
const HSpace(10),
_renderToolbarItems(
children: [
_ToolbarItem(
tooltip: LocaleKeys
.document_imageBlock_interactiveViewer_toolbar_zoomOutTooltip
.tr(),
icon: FlowySvgs.minus_s,
onTap: onZoomOut,
),
AppFlowyPopover(
offset: const Offset(0, -8),
decorationColor: Colors.transparent,
direction: PopoverDirection.topWithCenterAligned,
constraints: const BoxConstraints(maxHeight: 50),
popupBuilder: (context) => _renderToolbarItems(
children: [
_ScaleSlider(
currentScale: currentScale,
onScaleChanged: onScaleChanged,
),
],
),
child: FlowyTooltip(
message: LocaleKeys
.document_imageBlock_interactiveViewer_toolbar_changeZoomLevelTooltip
.tr(),
child: FlowyHover(
resetHoverOnRebuild: false,
style: HoverStyle(
hoverColor: Colors.white.withOpacity(0.1),
borderRadius: BorderRadius.circular(4),
),
child: Padding(
padding: const EdgeInsets.all(6),
child: SizedBox(
width: 40,
child: Center(
child: FlowyText(
LocaleKeys
.document_imageBlock_interactiveViewer_toolbar_scalePercentage
.tr(args: [currentScale.toString()]),
color: Colors.white,
),
),
),
),
),
),
),
_ToolbarItem(
tooltip: LocaleKeys
.document_imageBlock_interactiveViewer_toolbar_zoomInTooltip
.tr(),
icon: FlowySvgs.add_s,
onTap: onZoomIn,
),
],
),
const HSpace(10),
_renderToolbarItems(
children: [
if (onDelete != null)
_ToolbarItem(
tooltip: LocaleKeys
.document_imageBlock_interactiveViewer_toolbar_deleteImageTooltip
.tr(),
icon: FlowySvgs.delete_s,
onTap: () {
onDelete!();
Navigator.of(context).pop();
},
),
if (!PlatformExtension.isMobile) ...[
_ToolbarItem(
tooltip: currentImage.isNotInternal
? LocaleKeys
.document_imageBlock_interactiveViewer_toolbar_openLocalImage
.tr()
: LocaleKeys
.document_imageBlock_interactiveViewer_toolbar_downloadImage
.tr(),
icon: currentImage.isNotInternal
? currentImage.isLocal
? FlowySvgs.folder_m
: FlowySvgs.m_aa_link_s
: FlowySvgs.import_s,
onTap: () => _locateOrDownloadImage(context),
),
],
],
),
const HSpace(10),
_renderToolbarItems(
children: [
_ToolbarItem(
tooltip: LocaleKeys
.document_imageBlock_interactiveViewer_toolbar_closeViewer
.tr(),
icon: FlowySvgs.close_s,
onTap: () => Navigator.of(context).pop(),
),
],
),
],
),
),
),
);
}
Widget _renderToolbarItems({required List<Widget> children}) {
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: Colors.black.withOpacity(0.6),
),
child: Padding(
padding: const EdgeInsets.all(4),
child: SeparatedRow(
mainAxisSize: MainAxisSize.min,
separatorBuilder: () => const HSpace(4),
children: children,
),
),
);
}
Future<void> _locateOrDownloadImage(BuildContext context) async {
if (currentImage.isLocal) {
/// If the image type is local, we simply open the image
await afLaunchUrl(Uri.file(currentImage.url));
} else if (currentImage.isNotInternal) {
// In case of eg. Unsplash images (images without extension type in URL),
// we don't know their mimetype. In the future we can write a parser
// using the Mime package and read the image to get the proper extension.
await afLaunchUrl(Uri.parse(currentImage.url));
} else {
if (userProfile == null) {
return showSnapBar(
context,
LocaleKeys.document_plugins_image_imageDownloadFailedToken.tr(),
);
}
final uri = Uri.parse(currentImage.url);
final imgFile = File(uri.pathSegments.last);
final savePath = await FilePicker().saveFile(
fileName: basename(imgFile.path),
);
if (savePath != null) {
final uri = Uri.parse(currentImage.url);
final token = jsonDecode(userProfile!.token)['access_token'];
final response = await http.get(
uri,
headers: {'Authorization': 'Bearer $token'},
);
if (response.statusCode == 200) {
final imgFile = File(savePath);
await imgFile.writeAsBytes(response.bodyBytes);
} else if (context.mounted) {
showSnapBar(
context,
LocaleKeys.document_plugins_image_imageDownloadFailed.tr(),
);
}
}
}
}
}
class _ToolbarItem extends StatelessWidget {
const _ToolbarItem({
required this.tooltip,
required this.icon,
required this.onTap,
this.isDisabled = false,
});
final String tooltip;
final FlowySvgData icon;
final VoidCallback onTap;
final bool isDisabled;
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: FlowyTooltip(
message: tooltip,
child: FlowyHover(
resetHoverOnRebuild: false,
style: HoverStyle(
hoverColor:
isDisabled ? Colors.transparent : Colors.white.withOpacity(0.1),
borderRadius: BorderRadius.circular(4),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: FlowySvg(
icon,
size: const Size.square(16),
color: isDisabled ? Colors.grey : Colors.white,
),
),
),
),
);
}
}
class _ScaleSlider extends StatefulWidget {
const _ScaleSlider({
required this.currentScale,
required this.onScaleChanged,
});
final int currentScale;
final Function(double scale) onScaleChanged;
@override
State<_ScaleSlider> createState() => __ScaleSliderState();
}
class __ScaleSliderState extends State<_ScaleSlider> {
late int _currentScale = widget.currentScale;
@override
Widget build(BuildContext context) {
return Slider(
max: 5.0,
min: 0.5,
value: _currentScale / 100,
onChanged: (scale) {
widget.onScaleChanged(scale);
setState(
() => _currentScale = (scale * 100).toInt(),
);
},
);
}
}
@@ -1,185 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/image_provider.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_toolbar.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:provider/provider.dart';
const double _minScaleFactor = .5;
const double _maxScaleFactor = 5;
class InteractiveImageViewer extends StatefulWidget {
const InteractiveImageViewer({
super.key,
this.userProfile,
required this.imageProvider,
});
final UserProfilePB? userProfile;
final AFImageProvider imageProvider;
@override
State<InteractiveImageViewer> createState() => _InteractiveImageViewerState();
}
class _InteractiveImageViewerState extends State<InteractiveImageViewer> {
final TransformationController controller = TransformationController();
final focusNode = FocusNode();
int currentScale = 100;
late int currentIndex = widget.imageProvider.initialIndex;
bool get isLastIndex => currentIndex == widget.imageProvider.imageCount - 1;
bool get isFirstIndex => currentIndex == 0;
late ImageBlockData currentImage;
UserProfilePB? userProfile;
@override
void initState() {
super.initState();
controller.addListener(_onControllerChanged);
currentImage = widget.imageProvider.getImage(currentIndex);
userProfile =
widget.userProfile ?? context.read<DocumentBloc>().state.userProfilePB;
focusNode.requestFocus();
}
void _onControllerChanged() {
final scale = controller.value.getMaxScaleOnAxis();
final percentage = (scale * 100).toInt();
setState(() => currentScale = percentage);
}
@override
void dispose() {
controller.removeListener(_onControllerChanged);
controller.dispose();
focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return KeyboardListener(
focusNode: focusNode,
onKeyEvent: (event) {
if (event is! KeyDownEvent) {
return;
}
if (event.logicalKey == LogicalKeyboardKey.arrowLeft) {
_move(-1);
} else if (event.logicalKey == LogicalKeyboardKey.arrowRight) {
_move(1);
} else if ([
LogicalKeyboardKey.add,
LogicalKeyboardKey.numpadAdd,
].contains(event.logicalKey)) {
_zoom(1.1, size);
} else if ([
LogicalKeyboardKey.minus,
LogicalKeyboardKey.numpadSubtract,
].contains(event.logicalKey)) {
_zoom(.9, size);
} else if ([
LogicalKeyboardKey.numpad0,
LogicalKeyboardKey.digit0,
].contains(event.logicalKey)) {
controller.value = Matrix4.identity();
_onControllerChanged();
}
},
child: Stack(
fit: StackFit.expand,
children: [
SizedBox.expand(
child: InteractiveViewer(
boundaryMargin: const EdgeInsets.all(double.infinity),
transformationController: controller,
constrained: false,
minScale: _minScaleFactor,
maxScale: _maxScaleFactor,
scaleFactor: 500,
child: SizedBox(
height: size.height,
width: size.width,
child: widget.imageProvider.renderImage(
context,
currentIndex,
userProfile,
),
),
),
),
InteractiveImageToolbar(
currentImage: currentImage,
imageCount: widget.imageProvider.imageCount,
isFirstIndex: isFirstIndex,
isLastIndex: isLastIndex,
currentScale: currentScale,
userProfile: userProfile,
onPrevious: () => _move(-1),
onNext: () => _move(1),
onZoomIn: () => _zoom(1.1, size),
onZoomOut: () => _zoom(.9, size),
onScaleChanged: (scale) {
final currentScale = controller.value.getMaxScaleOnAxis();
final scaleStep = scale / currentScale;
_zoom(scaleStep, size);
},
onDelete: () =>
widget.imageProvider.onDeleteImage?.call(currentIndex),
),
],
),
);
}
void _move(int steps) {
setState(() {
final index = currentIndex + steps;
currentIndex = index.clamp(0, widget.imageProvider.imageCount - 1);
currentImage = widget.imageProvider.getImage(currentIndex);
});
}
void _zoom(double scaleStep, Size size) {
final center = Offset(size.width / 2, size.height / 2);
final scenePointBefore = controller.toScene(center);
final currentScale = controller.value.getMaxScaleOnAxis();
final newScale = (currentScale * scaleStep).clamp(
_minScaleFactor,
_maxScaleFactor,
);
// Create a new transformation
final newMatrix = Matrix4.identity()
..translate(scenePointBefore.dx, scenePointBefore.dy)
..scale(newScale / currentScale)
..translate(-scenePointBefore.dx, -scenePointBefore.dy);
// Apply the new transformation
controller.value = newMatrix * controller.value;
// Convert the center point to scene coordinates after scaling
final scenePointAfter = controller.toScene(center);
// Compute difference to keep the same center point
final dx = scenePointAfter.dx - scenePointBefore.dx;
final dy = scenePointAfter.dy - scenePointBefore.dy;
// Apply the translation
controller.value = Matrix4.identity()
..translate(-dx, -dy)
..multiply(controller.value);
_onControllerChanged();
}
}
@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flutter/material.dart';
import 'package:styled_widget/styled_widget.dart';
class PopoverActionList<T extends PopoverAction> extends StatefulWidget {
@@ -53,6 +54,7 @@ class _PopoverActionListState<T extends PopoverAction>
@override
Widget build(BuildContext context) {
final child = widget.buildChild(popoverController);
return AppFlowyPopover(
asBarrier: widget.asBarrier,
controller: popoverController,
@@ -1,84 +0,0 @@
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class SidebarResizer extends StatefulWidget {
const SidebarResizer({super.key});
@override
State<SidebarResizer> createState() => _SidebarResizerState();
}
class _SidebarResizerState extends State<SidebarResizer> {
final ValueNotifier<bool> isHovered = ValueNotifier(false);
final ValueNotifier<bool> isDragging = ValueNotifier(false);
@override
void dispose() {
isHovered.dispose();
isDragging.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MouseRegion(
cursor: SystemMouseCursors.resizeLeftRight,
onEnter: (_) => isHovered.value = true,
onExit: (_) => isHovered.value = false,
child: GestureDetector(
dragStartBehavior: DragStartBehavior.down,
behavior: HitTestBehavior.translucent,
onHorizontalDragStart: (details) {
isDragging.value = true;
context
.read<HomeSettingBloc>()
.add(const HomeSettingEvent.editPanelResizeStart());
},
onHorizontalDragUpdate: (details) {
isDragging.value = true;
context
.read<HomeSettingBloc>()
.add(HomeSettingEvent.editPanelResized(details.localPosition.dx));
},
onHorizontalDragEnd: (details) {
isDragging.value = false;
context
.read<HomeSettingBloc>()
.add(const HomeSettingEvent.editPanelResizeEnd());
},
onHorizontalDragCancel: () {
isDragging.value = false;
context
.read<HomeSettingBloc>()
.add(const HomeSettingEvent.editPanelResizeEnd());
},
child: ValueListenableBuilder(
valueListenable: isHovered,
builder: (context, isHovered, _) {
return ValueListenableBuilder(
valueListenable: isDragging,
builder: (context, isDragging, _) {
return Container(
width: 2,
// increase the width of the resizer to make it easier to drag
margin: const EdgeInsets.only(right: 2.0),
height: MediaQuery.of(context).size.height,
color: isHovered || isDragging
? const Color(0xFF00B5FF)
: Colors.transparent,
);
},
);
},
),
),
);
}
}
@@ -246,7 +246,6 @@ class _ViewTitleState extends State<_ViewTitle> {
opacity: isEditable ? 1.0 : 0.5,
child: FlowyText.regular(
state.name,
fontSize: 14.0,
overflow: TextOverflow.ellipsis,
),
),
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra/utils/color_converter.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'dandelion.dart';
@@ -86,9 +87,6 @@ class FlowyColorScheme {
required this.toggleButtonBGColor,
required this.calendarWeekendBGColor,
required this.gridRowCountColor,
required this.borderColor,
required this.scrollbarColor,
required this.scrollbarHoverColor,
});
final Color surface;
@@ -147,11 +145,6 @@ class FlowyColorScheme {
//grid bottom count color
final Color gridRowCountColor;
final Color borderColor;
final Color scrollbarColor;
final Color scrollbarHoverColor;
factory FlowyColorScheme.fromJson(Map<String, dynamic> json) =>
_$FlowyColorSchemeFromJson(json);
@@ -1,4 +1,3 @@
import 'package:flowy_infra/colorscheme/default_colorscheme.dart';
import 'package:flutter/material.dart';
import 'colorscheme.dart';
@@ -82,9 +81,6 @@ class DandelionColorScheme extends FlowyColorScheme {
toggleButtonBGColor: _lightDandelionYellow,
calendarWeekendBGColor: const Color(0xFFFBFBFC),
gridRowCountColor: _black,
borderColor: ColorSchemeConstants.lightBorderColor,
scrollbarColor: const Color(0x3F171717),
scrollbarHoverColor: const Color(0x7F171717),
);
const DandelionColorScheme.dark()
@@ -139,8 +135,5 @@ class DandelionColorScheme extends FlowyColorScheme {
toggleButtonBGColor: _darkShader1,
calendarWeekendBGColor: const Color(0xff121212),
gridRowCountColor: _darkMain1,
borderColor: ColorSchemeConstants.darkBorderColor,
scrollbarColor: const Color(0x40FFFFFF),
scrollbarHoverColor: const Color(0x80FFFFFF),
);
}
@@ -2,48 +2,44 @@ import 'package:flutter/material.dart';
import 'colorscheme.dart';
class ColorSchemeConstants {
static const white = Color(0xFFFFFFFF);
static const lightHover = Color(0xFFe0f8FF);
static const lightSelector = Color(0xFFf2fcFF);
static const lightBg1 = Color(0xFFf7f8fc);
static const lightBg2 = Color(0x0F1F2329);
static const lightShader1 = Color(0xFF333333);
static const lightShader3 = Color(0xFF828282);
static const lightShader5 = Color(0xFFe0e0e0);
static const lightShader6 = Color(0xFFf2f2f2);
static const lightMain1 = Color(0xFF00bcf0);
static const lightTint9 = Color(0xFFe1fbFF);
static const darkShader1 = Color(0xFF131720);
static const darkShader2 = Color(0xFF1A202C);
static const darkShader3 = Color(0xFF363D49);
static const darkShader5 = Color(0xFFBBC3CD);
static const darkShader6 = Color(0xFFF2F2F2);
static const darkMain1 = Color(0xFF00BCF0);
static const darkMain2 = Color(0xFF00BCF0);
static const darkInput = Color(0xFF282E3A);
static const lightBorderColor = Color(0xFFEDEDEE);
static const darkBorderColor = Color(0xFF3A3F49);
}
const _white = Color(0xFFFFFFFF);
const _lightHover = Color(0xFFe0f8FF);
const _lightSelector = Color(0xFFf2fcFF);
const _lightBg1 = Color(0xFFf7f8fc);
const _lightBg2 = Color(0x0F1F2329);
const _lightShader1 = Color(0xFF333333);
const _lightShader3 = Color(0xFF828282);
const _lightShader5 = Color(0xFFe0e0e0);
const _lightShader6 = Color(0xFFf2f2f2);
const _lightMain1 = Color(0xFF00bcf0);
const _lightTint9 = Color(0xFFe1fbFF);
const _darkShader1 = Color(0xFF131720);
const _darkShader2 = Color(0xFF1A202C);
const _darkShader3 = Color(0xFF363D49);
const _darkShader5 = Color(0xFFBBC3CD);
const _darkShader6 = Color(0xFFF2F2F2);
const _darkMain1 = Color(0xFF00BCF0);
const _darkMain2 = Color(0xFF00BCF0);
const _darkInput = Color(0xFF282E3A);
class DefaultColorScheme extends FlowyColorScheme {
const DefaultColorScheme.light()
: super(
surface: ColorSchemeConstants.white,
hover: ColorSchemeConstants.lightHover,
selector: ColorSchemeConstants.lightSelector,
surface: _white,
hover: _lightHover,
selector: _lightSelector,
red: const Color(0xFFfb006d),
yellow: const Color(0xFFFFd667),
green: const Color(0xFF66cf80),
shader1: ColorSchemeConstants.lightShader1,
shader1: _lightShader1,
shader2: const Color(0xFF4f4f4f),
shader3: ColorSchemeConstants.lightShader3,
shader3: _lightShader3,
shader4: const Color(0xFFbdbdbd),
shader5: ColorSchemeConstants.lightShader5,
shader6: ColorSchemeConstants.lightShader6,
shader7: ColorSchemeConstants.lightShader1,
bg1: ColorSchemeConstants.lightBg1,
bg2: ColorSchemeConstants.lightBg2,
shader5: _lightShader5,
shader6: _lightShader6,
shader7: _lightShader1,
bg1: _lightBg1,
bg2: _lightBg2,
bg3: const Color(0xFFe2e4eb),
bg4: const Color(0xFF2c144b),
tint1: const Color(0xFFe8e0FF),
@@ -54,54 +50,51 @@ class DefaultColorScheme extends FlowyColorScheme {
tint6: const Color(0xFFf5FFdc),
tint7: const Color(0xFFddFFd6),
tint8: const Color(0xFFdeFFf1),
tint9: ColorSchemeConstants.lightTint9,
main1: ColorSchemeConstants.lightMain1,
tint9: _lightTint9,
main1: _lightMain1,
main2: const Color(0xFF00b7ea),
shadow: const Color.fromRGBO(0, 0, 0, 0.15),
sidebarBg: ColorSchemeConstants.lightBg1,
divider: ColorSchemeConstants.lightShader6,
topbarBg: ColorSchemeConstants.white,
icon: ColorSchemeConstants.lightShader1,
text: ColorSchemeConstants.lightShader1,
sidebarBg: _lightBg1,
divider: _lightShader6,
topbarBg: _white,
icon: _lightShader1,
text: _lightShader1,
secondaryText: const Color(0xFF4f4f4f),
strongText: Colors.black,
input: ColorSchemeConstants.white,
hint: ColorSchemeConstants.lightShader3,
primary: ColorSchemeConstants.lightMain1,
onPrimary: ColorSchemeConstants.white,
hoverBG1: ColorSchemeConstants.lightBg2,
hoverBG2: ColorSchemeConstants.lightHover,
hoverBG3: ColorSchemeConstants.lightShader6,
hoverFG: ColorSchemeConstants.lightShader1,
questionBubbleBG: ColorSchemeConstants.lightSelector,
progressBarBGColor: ColorSchemeConstants.lightTint9,
toolbarColor: ColorSchemeConstants.lightShader1,
toggleButtonBGColor: ColorSchemeConstants.lightShader5,
input: _white,
hint: _lightShader3,
primary: _lightMain1,
onPrimary: _white,
hoverBG1: _lightBg2,
hoverBG2: _lightHover,
hoverBG3: _lightShader6,
hoverFG: _lightShader1,
questionBubbleBG: _lightSelector,
progressBarBGColor: _lightTint9,
toolbarColor: _lightShader1,
toggleButtonBGColor: _lightShader5,
calendarWeekendBGColor: const Color(0xFFFBFBFC),
gridRowCountColor: ColorSchemeConstants.lightShader1,
borderColor: ColorSchemeConstants.lightBorderColor,
scrollbarColor: const Color(0x3F171717),
scrollbarHoverColor: const Color(0x7F171717),
gridRowCountColor: _lightShader1,
);
const DefaultColorScheme.dark()
: super(
surface: ColorSchemeConstants.darkShader2,
hover: ColorSchemeConstants.darkMain1,
selector: ColorSchemeConstants.darkShader2,
surface: _darkShader2,
hover: _darkMain1,
selector: _darkShader2,
red: const Color(0xFFfb006d),
yellow: const Color(0xFFF7CF46),
green: const Color(0xFF66CF80),
shader1: ColorSchemeConstants.darkShader1,
shader2: ColorSchemeConstants.darkShader2,
shader3: ColorSchemeConstants.darkShader3,
shader1: _darkShader1,
shader2: _darkShader2,
shader3: _darkShader3,
shader4: const Color(0xFF505469),
shader5: ColorSchemeConstants.darkShader5,
shader6: ColorSchemeConstants.darkShader6,
shader7: ColorSchemeConstants.white,
shader5: _darkShader5,
shader6: _darkShader6,
shader7: _white,
bg1: const Color(0xFF1A202C),
bg2: const Color(0xFFEDEEF2),
bg3: ColorSchemeConstants.darkMain1,
bg3: _darkMain1,
bg4: const Color(0xFF2C144B),
tint1: const Color(0x4d9327FF),
tint2: const Color(0x66FC0088),
@@ -112,32 +105,29 @@ class DefaultColorScheme extends FlowyColorScheme {
tint7: const Color(0x5900BD2A),
tint8: const Color(0x80008890),
tint9: const Color(0x4d0029FF),
main1: ColorSchemeConstants.darkMain2,
main1: _darkMain2,
main2: const Color(0xFF00B7EA),
shadow: const Color(0xFF0F131C),
sidebarBg: const Color(0xFF232B38),
divider: ColorSchemeConstants.darkShader3,
topbarBg: ColorSchemeConstants.darkShader1,
icon: ColorSchemeConstants.darkShader5,
text: ColorSchemeConstants.darkShader5,
secondaryText: ColorSchemeConstants.darkShader5,
divider: _darkShader3,
topbarBg: _darkShader1,
icon: _darkShader5,
text: _darkShader5,
secondaryText: _darkShader5,
strongText: Colors.white,
input: ColorSchemeConstants.darkInput,
input: _darkInput,
hint: const Color(0xFF59647a),
primary: ColorSchemeConstants.darkMain2,
onPrimary: ColorSchemeConstants.darkShader1,
primary: _darkMain2,
onPrimary: _darkShader1,
hoverBG1: const Color(0x1AFFFFFF),
hoverBG2: ColorSchemeConstants.darkMain1,
hoverBG3: ColorSchemeConstants.darkShader3,
hoverBG2: _darkMain1,
hoverBG3: _darkShader3,
hoverFG: const Color(0xE5FFFFFF),
questionBubbleBG: ColorSchemeConstants.darkShader3,
progressBarBGColor: ColorSchemeConstants.darkShader3,
toolbarColor: ColorSchemeConstants.darkInput,
questionBubbleBG: _darkShader3,
progressBarBGColor: _darkShader3,
toolbarColor: _darkInput,
toggleButtonBGColor: const Color(0xFF828282),
calendarWeekendBGColor: ColorSchemeConstants.darkShader1,
gridRowCountColor: ColorSchemeConstants.darkShader5,
borderColor: ColorSchemeConstants.darkBorderColor,
scrollbarColor: const Color(0x40FFFFFF),
scrollbarHoverColor: const Color(0x80FFFFFF),
calendarWeekendBGColor: _darkShader1,
gridRowCountColor: _darkShader5,
);
}
@@ -1,4 +1,3 @@
import 'package:flowy_infra/colorscheme/default_colorscheme.dart';
import 'package:flutter/material.dart';
import 'colorscheme.dart';
@@ -78,9 +77,6 @@ class LavenderColorScheme extends FlowyColorScheme {
toggleButtonBGColor: _lightSelector,
calendarWeekendBGColor: const Color(0xFFFBFBFC),
gridRowCountColor: _black,
borderColor: ColorSchemeConstants.lightBorderColor,
scrollbarColor: const Color(0x3F171717),
scrollbarHoverColor: const Color(0x7F171717),
);
const LavenderColorScheme.dark()
@@ -135,8 +131,5 @@ class LavenderColorScheme extends FlowyColorScheme {
toggleButtonBGColor: _darkShader1,
calendarWeekendBGColor: const Color(0xff121212),
gridRowCountColor: _darkMain1,
borderColor: ColorSchemeConstants.darkBorderColor,
scrollbarColor: const Color(0x40FFFFFF),
scrollbarHoverColor: const Color(0x80FFFFFF),
);
}
@@ -1,4 +1,3 @@
import 'package:flowy_infra/colorscheme/default_colorscheme.dart';
import 'package:flutter/material.dart';
import 'colorscheme.dart';
@@ -84,9 +83,6 @@ class LemonadeColorScheme extends FlowyColorScheme {
toggleButtonBGColor: _lightDandelionYellow,
calendarWeekendBGColor: const Color(0xFFFBFBFC),
gridRowCountColor: _black,
borderColor: ColorSchemeConstants.lightBorderColor,
scrollbarColor: const Color(0x3F171717),
scrollbarHoverColor: const Color(0x7F171717),
);
const LemonadeColorScheme.dark()
@@ -141,8 +137,5 @@ class LemonadeColorScheme extends FlowyColorScheme {
toggleButtonBGColor: _darkShader1,
calendarWeekendBGColor: const Color(0xff121212),
gridRowCountColor: _darkMain1,
borderColor: ColorSchemeConstants.darkBorderColor,
scrollbarColor: const Color(0x40FFFFFF),
scrollbarHoverColor: const Color(0x80FFFFFF),
);
}
Loaded 100 of 254 files, more files were not shown because too many files have changed in this diff. Show more