Compare commits

..
75 Commits
Author SHA1 Message Date
Mathias Mogensen 966547faa0 fix: reminder launch review (#3716) 2023-10-17 14:48:58 +08:00
Muhammad Saad Tanveer 3647af44c9 fix: Shortcut settings Reset to default is missing bottom margin #3710 (#3715) 2023-10-17 05:47:07 +02:00
Lucas.Xu 25b4a647b0 fix: unable to export image to markdown (#3709) 2023-10-16 15:56:30 +08:00
Lucas.Xu c6e3c1fd7c feat: customizing the background of a block with theme color (#3691) 2023-10-16 14:11:05 +08:00
ルビーDog 4fd35d0de4 feat: improve translations ja_JP (#3702) (#3705) 2023-10-16 10:56:06 +08:00
Lucas.Xu 7406c5e6a5 feat: add toggle list and callout node parser (#3700) 2023-10-16 10:09:33 +08:00
CrazyRikin aa70885b21 feat: added hindi translation (#3575) 2023-10-15 22:13:14 +08:00
Yijing Huang 8699c9c125 fix: lemonade theme issues (#3686) 2023-10-15 22:12:25 +08:00
Pedro Coelho bc758e0b06 chore: update translations pt-PT (#3687) 2023-10-15 22:12:01 +08:00
Jakob Gerhardt e38980ccc3 chore: update translations de-DE (#3693) 2023-10-15 22:11:28 +08:00
Verdy Bangkit 8dd180046f chore: update translations id_ID and ru_RU (#3701) 2023-10-15 22:10:41 +08:00
Lucas.Xu 0cd2726752 chore: disable toolbar in code block (#3682) 2023-10-15 22:01:17 +08:00
Lucas.Xu 11daa15b89 feat: auto pop up the menu after inserting image block (#3698) 2023-10-15 13:04:24 +08:00
Lucas.Xu 8436bc6144 fix: the disk space of CI machines always runs out (#3689) 2023-10-14 20:37:44 +08:00
Ekaksh JanwejaandLucas.Xu 59851f46b7 feat: edit the field by clicking on the drag icon (#3656)
* feat: edit the field by clicking on the drag icon

* Added localization

* Added .tr() function

* fix: BlockActionButton only show when _isFieldHover is true.

* fix: BlockActionButton only show when _isFieldHover is true.

* fix: Worked on requested changes

* fix: Fixed Location of Field Popover

* fixed pubspec.lock

* Updated pubspec.lock

---------

Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
2023-10-13 23:47:49 +08:00
Sarthak Kimtani 62f1d6eb82 fix: 3620 unchecked checkbox color (#3685) 2023-10-13 21:06:13 +08:00
Nathan.fooo ec80f72c8f feat: af cloud database (#3684)
* chore: forece user to logout when token is invalid

* chore: update client api rev
2023-10-12 20:25:00 +08:00
Richard Shiue b2c80981cc fix: build app (#3681) 2023-10-11 22:46:32 -07:00
Yijing Huang 8fa425a76c chore: bump version 0.3.6 (#3680) 2023-10-12 13:14:37 +08:00
Mathias Mogensen ebe112581d feat: toggle notifications on/off (#3672) 2023-10-12 12:54:08 +08:00
Mathias Mogensen bc8f35d7db feat: reminder improvements (#3658) 2023-10-12 10:19:36 +08:00
Nathan.fooo 058eeec932 feat: implement file storage using appflowy cloud (#3675)
* feat: implement file storage using appflowy cloud

* chore: clippy
2023-10-12 09:54:45 +08:00
Lucas.Xu 8e10cba8e5 feat: support toggling the markdown style by shortcuts (#3674) 2023-10-11 23:12:23 +08:00
Yijing Huang 7a24f6b6f0 feat: add lemonade theme color (#3666) 2023-10-11 22:01:05 +08:00
Richard Shiue 4f40945458 fix: integration tests (#3673)
* fix: fix integration tests

* fix: initiate isScreenSmall properly
2023-10-11 20:36:10 +08:00
Nathan.fooo e59870e421 refactor: rename flowy-test to event-integration (#3667) 2023-10-11 20:02:09 +08:00
Tran Nguyen Sinh cf521fe20b chore: update translations for Vietnamese (#3632) 2023-10-11 17:15:59 +07:00
Mathias Mogensen f0d47ee50c fix: esc to close date picker dialog (#3648) 2023-10-11 05:49:32 +02:00
Lucas.Xu 2a5d393c9f fix: missing dependency (libnotify) in appimage (#3665) 2023-10-11 09:46:59 +08:00
Shreesh Nautiyal 98e0b832ec feat: 1674 Auto-hide sidebar when re-sizing the window (#3659)
* feat: 1674 Auto-hide sidebar when re-sizing the window

* chore: removed unnecessary print statements

* chore: updated to a more approprite name for 'screenSmall' event
2023-10-10 19:26:11 +02:00
Nathan.fooo 77e7cbe9ec chore: sync document (#3653)
* chore: sync document

* chore: update collab rev

* chore: update collab rev
2023-10-10 19:05:55 +08:00
Dhruv Sharma acd53eb640 fix: correct svg for row actions (#3664)
Closes: #3450
2023-10-10 17:30:44 +08:00
Lucas.Xu ffdf5d24a0 fix: openAI image expiration (#3660)
* feat: save the openAI image to local storage

* feat: support rendering error block

* fix: enter on Toggle list moves heading down without contents
2023-10-10 12:43:31 +08:00
Dhruv Sharma b247a49417 chore: resolve issue (#3621) 2023-10-09 20:47:24 +02:00
Lucas.Xu dace02d34d feat: generate image by Stability AI / openAI (#3642) 2023-10-09 23:14:24 +08:00
Muhammad Saad Tanveer 41d4351176 feat: 3625 Added Ukrainian Language (#3644) 2023-10-09 12:19:35 +08:00
Lucas.Xu d4bc575c03 fix: image block issues (#3637) 2023-10-07 13:45:38 +08:00
Nathan.fooo a59561aee3 chore: sign in with provider (#3592)
* chore: sign in with provider

* feat: implement oauth flow of appflowy cloud

* chore: rename env

* chore: fix deadlock

* fix: login bugs

* chore: clippyt

* chore: update client api

* chore: fmt
2023-10-07 09:58:44 +08:00
Mathias Mogensen 92523321f1 fix: notification button delayed tooltip (#3635) 2023-10-06 09:29:36 +02:00
Richard Shiue 537c9d0865 fix: wrong date selected in CDT (#3627) 2023-10-06 10:13:46 +08:00
Richard Shiue b4051c7e9f fix: url underline issue (#3618) 2023-10-05 17:35:50 +08:00
Richard Shiue 9e61133886 chore: bump version 0.3.5 (#3616) 2023-10-05 12:01:38 +08:00
Lucas.Xu 36f47f3636 feat: image block revamp (#3615) 2023-10-05 10:40:41 +08:00
Mayur Mahajan 40dcd13394 refactor: ui improvement in appearance (#3553) 2023-10-05 09:48:19 +08:00
Yijing Huang eb20c7c117 feat: emoji picker improvement (#3591) 2023-10-05 09:36:29 +08:00
Devanshu Rawat e9852a3934 fix: restore page banner ui improvement (#3604) 2023-10-05 09:34:36 +08:00
Alazar GeneneandAlazar Genene 78d8ec9a3e fix: use Image.file instead of DecoratedBox and FileImage (#3606)
Co-authored-by: Alazar Genene <alazargenene@Alazars-MacBook-Pro-2.local>
2023-10-04 23:48:31 +02:00
Juan David 4220309cf8 Updated translation part in project readme (#3609) 2023-10-04 15:50:42 +02:00
Jaskeerat Singh 812af0979e Fix: Missing WhiteSpace b/w Primary Field Text and Row Icon (#3602)
* Update link to OS Specific Development

* fix: Missing white space b/w primary field text & row's icon

* fix: Updated emoji padding
2023-10-04 11:50:26 +02:00
Narayan cca5005541 fix: remove current page link option in page reference (#3600)
* fix: remove current page link option in page reference

* fix: removed context and added view id as parameter
2023-10-04 11:49:22 +02:00
Mathias Mogensen 9306d4a4ee docs: update links in readm (#3589) 2023-10-04 11:35:37 +02:00
Ahsan AhmadandLucas.Xu 3ab1ff5e73 fix:The placeholder text for URL cells shouldn't be underlined (#3565)
* fix:The placeholder text for URL cells shouldn't be underlined

* Update frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/url_cell/url_cell.dart

Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>

---------

Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
2023-10-04 11:35:02 +02:00
Aditya AroraandMathias Mogensen 05fa306782 feat: Delay tooltip presentations by 300ms (#3558)
* feat:added wait duration to ToolTip widgets

* feat:added wait Duration to more tooltips

* feat:added wait Duration to more_button tooltip

* fix: use flowytooltip

* fix:undo install_macos.sh file

* fix:undo install_macos.sh file

* fix:refactored FlowyTooltip.delayedTooltip to FlowyTooltip.delayed

---------

Co-authored-by: Mathias Mogensen <mathias@appflowy.io>
2023-10-04 11:34:44 +02:00
Mathias Mogensen d054439df4 fix: provide default options for inline actions always (#3601) 2023-10-03 18:07:46 +02:00
Jaskeerat Singh 15aaacc4b7 Update link to OS Specific Development (#3590) 2023-10-02 20:12:02 +02:00
Mathias Mogensen ef9de52cbc docs: update link to conventions (#3581) 2023-10-02 15:48:02 +02:00
Lucas.Xu 8d9d0e9358 chore: bump version 0.3.4 (#3572)
* chore: bump version 0.3.4

* fix: docker file build
2023-10-02 20:48:56 +08:00
7f44b181bd feat: integrate client-api (#3430)
* chore: update client-api rev

* chore: update collab rev id

* feat: add sign_in_request and import shared entity

* feat: added to userworkspace from af_workspace

* chore: add script to update the client-api rev id

* chore: update client-api rev

* feat: add workspaces api

* feat: added check user

* chore: config

* chore: update client_api version

* chore: ws connect

* chore: ws connect

* chore: update crate versions

* chore: rename event

* chore: update client-appi

* chore: set appflowy cloud env

* chore: add env template

* chore: update env name

* docs: update docs

* fix: check_user

* feat: impl sign_in_with_url

* feat: add file storage placeholders

* chore: update client-api

* chore: disable test

* feat: impl workspace add and remove

* chore: sign up test

* feat: select cover image on upload (#3488)

* fix: close popover after item selection in settings view (#3362)

* fix: close popover after item selection in settings view

* fix: add missing await before closing popover

* fix: find popover container by context instead of passing controllers around

* fix: add requested changes

* feat: close text direction settings popups after selection

* fix: clean up

* fix: restore theme value dropdown as StatefulWidget

* feat: openai and stabilityai integration (#3439)

* chore: create trait

* test: add tests

* chore: remove log

* chore: disable log

* chore: checklist ux flow redesign (#3418)

* chore: ux flow redesign

* chore: remove unused imports

* fix: allow creation of tasks of the same name

* chore: apply code suggestions from Mathias

* fix: add padding below field title text field (#3440)

* Fixed Issue no #3426

* Reversed the pubspec.lock mistaken update

* FIXED PADDING

* Fixed Padding issue on calender field edit popup

* chore: rename package name (#3501)

* fix: right icon size sam as left one (#3494)

* feat: enable removing user icon (#3487)

* feat: enable removing user icon

* fix: generate to true

* fix: review comments

* fix: more review comments

* fix: integration test and final changes

* fix: made cursor grab and background color when hovering on Appearance Options Buttons (#3498)

* chore: calendar UI polish (#3484)

* chore: update calendar theming

* feat: add event popup editor

* chore: new event button redesign and add card shadows

* chore: unscheduled events button

* chore: event title text field

* fix: focus node double dispose

* chore: show popover when create new event

* test: integrate some tests for integration testing purposes

* fix: some fixes and more integration tests

* chore: add more space between font item and font menu

* feat: add reset font button in toolbar

* feat: only show text direction toolbar item when RTL is enabled

* fix:  unable to change RTL of heading block

* test: add integration test for ltr/rtl mode

* chore: update inlang project settings (#3441)

* feat: using script to update the collab source. (#3508)

* chore: add script

* chore: update script

* chore: update bytes version

* chore: submit lock file

* chore: update test

* chore: update test

* chore: bump version

* chore: update

* ci: fix

* ci: fix

* chore: update commit id

* chore: update commit id

* chore: update commit id

* fix: is cloud enable

---------

Co-authored-by: Fu Zi Xiang <speed2exe@live.com.sg>
Co-authored-by: Mathias Mogensen <42929161+Xazin@users.noreply.github.com>
Co-authored-by: Vincenzo De Petris <37916223+vincendep@users.noreply.github.com>
Co-authored-by: Richard Shiue <71320345+richardshiue@users.noreply.github.com>
Co-authored-by: Aryan More <61151896+aryan-more@users.noreply.github.com>
Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
Co-authored-by: Lakhan Baheti <94619783+1akhanBaheti@users.noreply.github.com>
Co-authored-by: Nitin-Poojary <70025277+Nitin-Poojary@users.noreply.github.com>
Co-authored-by: Jannes Blobel <72493222+jannesblobel@users.noreply.github.com>
2023-10-02 17:22:22 +08:00
Aman Negi 01c3fec5aa feat: improve snackbar UI style (#3562) 2023-10-02 15:14:40 +08:00
Mathias Mogensen 94a3a59001 fix: avoid non-null promise on null value (#3569) 2023-10-02 15:13:39 +08:00
Mathias Mogensen 4a433a3176 feat: reminder (#3374) 2023-10-02 15:12:24 +08:00
Ricky Putra f7749bdccc chore: add integration tests for user language settings (#3560) 2023-10-02 13:55:57 +08:00
Lucas.Xu c864e836ee feat: integrate find and replace into AppFlowy (#3566)
* chore: update editor version

* feat: redesign find and replace ui

* chore: update language file
2023-10-02 13:54:51 +08:00
Richard Shiue 0738b5f87d feat: show hidden fields in row detail page (#3545) 2023-10-02 10:52:22 +08:00
Anurag De 6198c3907f fix: updated githook helper link (#3563) 2023-10-02 10:07:51 +08:00
Ahsan AhmadandMathias Mogensen 891d794900 fix:Spacing above New row in grid (#3564)
* fix:Spacing above New row in grid

* revert: update frontend/appflowy_flutter/ios/Podfile.lock

---------

Co-authored-by: Mathias Mogensen <42929161+Xazin@users.noreply.github.com>
2023-10-01 23:22:21 +02:00
Yijing Huang 890f52a00a feat: dandelion theme improvement (#3550) 2023-09-28 14:18:40 +08:00
Yijing Huang d007f98af6 fix: emoji picker menu issue (#3551) 2023-09-28 14:18:01 +08:00
Yijing Huang 15e9d65798 feat: go_router refactor and bottom navigation bar in mobile (#3459) 2023-09-28 14:17:38 +08:00
Lakhan Baheti 0626f0deb7 fix: on hover change_cover button correct mouse cursor (#3548) 2023-09-27 22:59:33 +08:00
Richard Shiue 007c649c31 fix: still show drag icon while dragging (#3547)
* fix: still show drag icon while dragging

* chore: use click cursor on windows
2023-09-27 20:02:44 +08:00
Norbert 34ea508f5b chore: update pl-PL translations (#3539) 2023-09-27 15:35:45 +08:00
fangwufeng-v f70aef68be feat: drag and drop a row in the Grid (#3376)
* feat: new style ui

* feat: drag row

* feat: hooks for auto scroll feature when dragging

* feat: shared UI status that control auto scroll when dragging row.

* feat: optimize the drag interaction UI effect

* feat: refactor drag positon

* feat: drag column header

* feat: fix review issue
2023-09-27 15:13:25 +08:00
Borris 61a31c90ee chore: update translations for id-ID (#3518) 2023-09-27 11:32:49 +08:00
Richard Shiue c7e3ed805a fix: checklist cell style for checklist cells (#3538) 2023-09-26 22:31:15 +08:00
530 changed files with 19376 additions and 10139 deletions

No files matched your search

+1 -1
View File
@@ -44,7 +44,7 @@ test "" = "$(grep '^Signed-off-by: ' "$1" |
if [ $? -ne 0 ]
then
printError "Please fix your commit message to match AppFlowy coding standards"
printError "https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/software-contributions/submitting-code/code-submission-guidelines#commit-message-guidelines"
printError "https://docs.appflowy.io/docs/documentation/software-contributions/conventions/git-conventions"
exit 1
fi
+1 -1
View File
@@ -21,7 +21,7 @@ Before you mark this PR ready for review, run through this checklist!
#### PR Checklist
- [ ] My code adheres to the [AppFlowy Style Guide](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/software-contributions/submitting-code/style-guides)
- [ ] My code adheres to [AppFlowy's Conventions](https://docs.appflowy.io/docs/documentation/software-contributions/conventions)
- [ ] I've listed at least one issue that this PR fixes in the description above.
- [ ] I've added a test(s) to validate changes in this PR, or this PR only contains semantic changes.
- [ ] All existing tests are passing.
+10 -1
View File
@@ -49,6 +49,15 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
# the following step is required to avoid running out of space
- name: Maximize build space
if: matrix.os == 'ubuntu-latest'
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Checkout source code
uses: actions/checkout@v2
@@ -88,7 +97,7 @@ jobs:
sudo wget -qO /etc/apt/sources.list.d/dart_stable.list https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list
sudo apt-get update
sudo apt-get install -y dart curl build-essential libssl-dev clang cmake ninja-build pkg-config libgtk-3-dev
sudo apt-get install keybinder-3.0
sudo apt-get install keybinder-3.0 libnotify-dev
elif [ "$RUNNER_OS" == "Windows" ]; then
vcpkg integrate install
elif [ "$RUNNER_OS" == "macOS" ]; then
+10 -1
View File
@@ -45,6 +45,15 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
# the following step is required to avoid running out of space
- name: Maximize build space
if: matrix.os == 'ubuntu-latest'
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
df -h
- name: Checkout source code
uses: actions/checkout@v2
@@ -85,7 +94,7 @@ jobs:
sudo wget -qO /etc/apt/sources.list.d/dart_stable.list https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list
sudo apt-get update
sudo apt-get install -y dart curl build-essential libssl-dev clang cmake ninja-build pkg-config libgtk-3-dev
sudo apt-get install keybinder-3.0
sudo apt-get install keybinder-3.0 libnotify-dev
elif [ "$RUNNER_OS" == "Windows" ]; then
vcpkg integrate install
elif [ "$RUNNER_OS" == "macOS" ]; then
+1 -1
View File
@@ -388,7 +388,7 @@ jobs:
sudo wget -qO /etc/apt/trusted.gpg.d/dart_linux_signing_key.asc https://dl-ssl.google.com/linux/linux_signing_key.pub
sudo apt-get update
sudo apt-get install -y build-essential libsqlite3-dev libssl-dev clang cmake ninja-build pkg-config libgtk-3-dev
sudo apt-get install keybinder-3.0
sudo apt-get install keybinder-3.0 libnotify-dev
sudo apt-get -y install alien
source $HOME/.cargo/env
cargo install --force cargo-make
+2 -2
View File
@@ -60,8 +60,8 @@ jobs:
echo SUPABASE_ANON_KEY=${{ secrets.SUPABASE_ANON_KEY }} >> .env.ci
echo SUPABASE_JWT_SECRET=${{ secrets.SUPABASE_JWT_SECRET }} >> .env.ci
- name: Create .env file in flowy-test
working-directory: frontend/rust-lib/flowy-test
- name: Create .env file in event-integration
working-directory: frontend/rust-lib/event-integration
run: |
touch .env.ci
echo SUPABASE_URL=${{ secrets.SUPABASE_URL }} >> .env.ci
+40
View File
@@ -1,5 +1,45 @@
# Release Notes
## Version 0.3.6 - 10/16/2023
### New Features
- Support setting Markdown styles through keyboard shortcuts.
- Added Ukrainian language.
- Support auto-hiding sidebar feature, ensuring a streamlined view even when resizing to a smaller window.
- Support toggling the notifitcation on/off.
- Added Lemonade theme.
### Bug fixes
- Improve Vietnamese translations.
- Improve reminder feature.
- Fix some UI issues.
## Version 0.3.5 - 10/09/2023
### New Features
- Added support for browsing and inserting images from Unsplash.
- Revamp and unify the emoji picker throughout AppFlowy.
### Bug fixes
- Improve layout of the settings page.
- Improve design of the restore page banner.
- Improve UX of the reminders.
- Other UI fixes.
## Version 0.3.4 - 10/02/2023
### New Features
- Added support for creating a reminder.
- Added support for finding and replacing in the document page.
- Added support for showing the hidden fields in row detail page.
- Adjust the toolbar style in RTL mode.
### Bug fixes
- Improve snackbar UI design.
- Improve dandelion theme.
- Improve id-ID and pl-PL language translations.
## Version 0.3.3 - 09/24/2023
### New Features
+2 -2
View File
@@ -47,7 +47,7 @@ You are in charge of your data and customizations.
## Getting Started with development
Please view the [documentation](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy) for OS specific development instructions
Please view the [documentation](https://docs.appflowy.io/docs/documentation/appflowy/from-source) for OS specific development instructions
## Roadmap
@@ -73,7 +73,7 @@ Proudly wear your T-shirt and show it to us by tagging [@appflowy](https://twitt
[![translation badge](https://inlang.com/badge?url=github.com/AppFlowy-IO/AppFlowy)](https://inlang.com/editor/github.com/AppFlowy-IO/AppFlowy?ref=badge)
To add translations, you can manually edit the JSON translation files in `/frontend/appflowy_flutter/assets/translations`, use the [inlang online editor](https://inlang.com/editor/github.com/AppFlowy-IO/AppFlowy), or run `npx inlang machine translate` to add missing translations.
To add translations, you can manually edit the JSON translation files in `/frontend/resources/translations`, use the [inlang online editor](https://inlang.com/editor/github.com/AppFlowy-IO/AppFlowy), or run `npx inlang machine translate` to add missing translations.
## Join the community to build AppFlowy together
+8
View File
@@ -285,6 +285,14 @@
"options": {
"cwd": "${workspaceFolder}/appflowy_flutter"
}
},
{
"label": "AF: Generate AppFlowyEnv",
"type": "shell",
"command": "dart run build_runner build --delete-conflicting-outputs",
"options": {
"cwd": "${workspaceFolder}/appflowy_flutter/packages/appflowy_backend"
}
}
]
}
+1 -1
View File
@@ -25,7 +25,7 @@ CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CARGO_MAKE_CRATE_FS_NAME = "dart_ffi"
CARGO_MAKE_CRATE_NAME = "dart-ffi"
LIB_NAME = "dart_ffi"
CURRENT_APP_VERSION = "0.3.3"
CURRENT_APP_VERSION = "0.3.6"
FLUTTER_DESKTOP_FEATURES = "dart,rev-sqlite"
PRODUCT_NAME = "AppFlowy"
# CRATE_TYPE: https://doc.rust-lang.org/reference/linkage.html
+2 -2
View File
@@ -69,8 +69,8 @@ windows/flutter/dart_ffi/
**/.sandbox
**/.vscode/
*.env
*.env.*
.env
.env.*
coverage/
+14 -16
View File
@@ -13,11 +13,13 @@ This Repository contains the codebase for the frontend of the application, curre
- Linux
- macOS
- Windows
> We later expect to extend support to Android and iOS devices using Flutter.
> We are actively working on support for Android & iOS!
_Additionally, we are working on a Web version built with Tauri!_
### Am I Eligible to Contribute?
Yes! You are eligible to contribute, check out the ways in which you can [contribute to AppFlowy](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/contributing-to-appflowy). Some of the ways in which you can contribute are:
Yes! You are eligible to contribute, check out the ways in which you can [contribute to AppFlowy](https://docs.appflowy.io/docs/documentation/software-contributions/contributing-to-appflowy). Some of the ways in which you can contribute are:
- Non-Coding Contributions
- Documentation
@@ -26,27 +28,23 @@ Yes! You are eligible to contribute, check out the ways in which you can [contri
- Improve Translations
- Coding Contributions
To contribute to `AppFlowy_Flutter` codebase specifically (coding contribution) we suggest you to have basic knowledge of Flutter. In case you are new to Flutter, we may suggest you to learn the basics and then try to contribute, get started with Flutter [here](https://flutter.dev/docs/get-started/codelab).
To contribute to `AppFlowy_Flutter` codebase specifically (coding contribution) we suggest you to have basic knowledge of Flutter. In case you are new to Flutter, we suggest you learn the basics, and then contribute afterwards. To get started with Flutter read [here](https://flutter.dev/docs/get-started/codelab).
### What OS Should I Use for Development?
### What OS should I use for development?
We support all OS for Development i.e Linux, macOS and Windows. However, most of us promote macOS and Linux over Windows. We have detailed [docs](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/software-contributions/environment-setup) on How to Setup `AppFlowy_Flutter` in your local system in each OS.
We support all OS for Development i.e. Linux, MacOS and Windows. However, most of us promote macOS and Linux over Windows. We have detailed [docs](https://docs.appflowy.io/docs/documentation/appflowy/from-source/environment-setup) on how to setup `AppFlowy_Flutter` on your local system respectively per operating system.
### Getting Started ❇
We have a detailed documentation, on how to [get started](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/contributing-to-appflowy) with the project, and make your first contribution. However, we do have some specific picks for you.
We have detailed documentation on how to [get started](https://docs.appflowy.io/docs/documentation/software-contributions/contributing-to-appflowy) with the project, and make your first contribution. However, we do have some specific picks for you:
- [Code Architecture](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/frontend/frontend/codemap)
- [Making Your First PR](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/software-contributions/submitting-code/submitting-your-first-pull-request)
- [The Style Guide](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/software-contributions/submitting-code/style-guides)
- [How to run/debug the application](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/software-contributions/launcher-and-tasks)
- [Styleguide & Conventions](https://docs.appflowy.io/docs/documentation/software-contributions/conventions/naming-conventions)
- [Making Your First PR](https://docs.appflowy.io/docs/documentation/software-contributions/submitting-code/submitting-your-first-pull-request)
- [All AppFlowy Documentation](https://docs.appflowy.io/docs/documentation/appflowy) - Contribution guide, build and run, debugging, testing, localization, etc.
### Need Help?
- New to GitHub? Follow [these](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/software-contributions/submitting-code/setting-up-your-repositories) steps to get started
- Stuck Somewhere? Join the [Discord](https://discord.gg/9Q2xaN37tV) Group and we are there to help you!
<!--
## release check
1. [entitlements](https://flutter.dev/desktop#setting-up-entitlements)
2. [symbols stripped](https://flutter.dev/docs/development/platform-integration/c-interop) -->
- New to GitHub? Follow [these](https://docs.appflowy.io/docs/documentation/software-contributions/submitting-code/setting-up-your-repositories) steps to get started
- Stuck Somewhere? Join our [Discord](https://discord.gg/9Q2xaN37tV), we're there to help you!
- Find out more about the [community initiatives](https://docs.appflowy.io/docs/appflowy/community).
+23
View File
@@ -0,0 +1,23 @@
# Initial Setup
# 1. Copy the dev.env file to .env:
# cp dev.env .env
# 2. Alternatively, you can generate the .env file using the "Generate Env File" task in VSCode.
# Configuring Cloud Type
# This configuration file is used to specify the cloud type and the necessary configurations for each cloud type. The available options are:
# Local: 0
# Supabase: 1
# AppFlowy Cloud: 2
CLOUD_TYPE=0
# Supabase Configuration
# If you're using Supabase (CLOUD_TYPE=1), you need to provide the following configurations:
SUPABASE_URL=replace-with-your-supabase-url
SUPABASE_ANON_KEY=replace-with-your-supabase-key
# AppFlowy Cloud Configuration
# If you're using AppFlowy Cloud (CLOUD_TYPE=2), you need to provide the following configurations:
APPFLOWY_CLOUD_BASE_URL=replace-with-your-appflowy-cloud-url
APPFLOWY_CLOUD_WS_BASE_URL=replace-with-your-appflowy-cloud-ws-url
APPFLOWY_CLOUD_GOTRUE_URL=replace-with-your-appflowy-cloud-gotrue-url
@@ -146,7 +146,7 @@ void main() {
await tester.openFirstRowDetailPage();
// Assert that the first field in the row details page is the select
// option tyoe
// option type
tester.assertFirstFieldInRowDetailByType(FieldType.SingleSelect);
// Reorder first field in list
@@ -168,6 +168,54 @@ void main() {
tester.assertFirstFieldInRowDetailByType(FieldType.SingleSelect);
});
testWidgets('hide and show hidden fields', (tester) async {
await tester.initializeAppFlowy();
await tester.tapGoButton();
// Create a new grid
await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
// Hover first row and then open the row page
await tester.openFirstRowDetailPage();
// Assert that the show hidden fields button isn't visible
tester.assertToggleShowHiddenFieldsVisibility(false);
// Hide the first field in the field list
await tester.tapGridFieldWithNameInRowDetailPage("Type");
await tester.tapHidePropertyButtonInFieldEditor();
// Assert that the field is now hidden
tester.noFieldWithName("Type");
// Assert that the show hidden fields button appears
tester.assertToggleShowHiddenFieldsVisibility(true);
// Click on the show hidden fields button
await tester.toggleShowHiddenFields();
// Assert that the hidden field is shown again and that the show
// hidden fields button is still present
tester.findFieldWithName("Type");
tester.assertToggleShowHiddenFieldsVisibility(true);
// Click hide hidden fields
await tester.toggleShowHiddenFields();
// Assert that the hidden field has vanished
tester.noFieldWithName("Type");
// Click show hidden fields
await tester.toggleShowHiddenFields();
// delete the hidden field
await tester.tapGridFieldWithNameInRowDetailPage("Type");
await tester.tapDeletePropertyInFieldEditor();
// Assert that the that the show hidden fields button is gone
tester.assertToggleShowHiddenFieldsVisibility(false);
});
testWidgets('check document exists in row detail page', (tester) async {
await tester.initializeAppFlowy();
await tester.tapGoButton();
@@ -197,7 +245,7 @@ void main() {
await tester.wait(500);
// Focus on the editor
final textBlock = find.byType(TextBlockComponentWidget);
final textBlock = find.byType(ParagraphBlockComponentWidget);
await tester.tapAt(tester.getCenter(textBlock));
await tester.pumpAndSettle();
@@ -24,7 +24,7 @@ void main() {
LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
);
// and with one paragraph block
expect(find.byType(TextBlockComponentWidget), findsOneWidget);
expect(find.byType(ParagraphBlockComponentWidget), findsOneWidget);
});
testWidgets('delete the readme page and restore it', (tester) async {
@@ -9,6 +9,7 @@ import 'document_option_action_test.dart' as document_option_action_test;
import 'document_text_direction_test.dart' as document_text_direction_test;
import 'document_with_cover_image_test.dart' as document_with_cover_image_test;
import 'document_with_database_test.dart' as document_with_database_test;
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;
@@ -33,4 +34,5 @@ void startTesting() {
document_alignment_test.main();
document_text_direction_test.main();
document_option_action_test.main();
document_with_image_block_test.main();
}
@@ -1,4 +1,4 @@
import 'package:appflowy/workspace/application/appearance.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@@ -0,0 +1,163 @@
import 'dart:io';
import 'package:appflowy/generated/locale_keys.g.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/unsplash_image_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide UploadImageMenu;
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;
import 'package:path_provider/path_provider.dart';
import 'package:run_with_network_images/run_with_network_images.dart';
import '../util/mock/mock_file_picker.dart';
import '../util/util.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
TestWidgetsFlutterBinding.ensureInitialized();
group('image block in document', () {
testWidgets('insert an image from local file', (tester) async {
await tester.initializeAppFlowy();
await tester.tapGoButton();
// create a new document
await tester.createNewPageWithName(
name: LocaleKeys.document_plugins_image_addAnImage.tr(),
layout: ViewLayoutPB.Document,
);
// 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 image = await rootBundle.load('assets/test/images/sample.jpeg');
final tempDirectory = await getTemporaryDirectory();
final imagePath = p.join(tempDirectory.path, 'sample.jpeg');
final file = File(imagePath)
..writeAsBytesSync(image.buffer.asUint8List());
mockPickFilePaths(
paths: [imagePath],
);
await tester.tapButtonWithName(
LocaleKeys.document_imageBlock_upload_placeholder.tr(),
);
await tester.pumpAndSettle();
expect(find.byType(ResizableImage), findsOneWidget);
final node = tester.editor.getCurrentEditorState().getNodeAtPath([0])!;
expect(node.type, ImageBlockKeys.type);
expect(node.attributes[ImageBlockKeys.url], isNotEmpty);
// remove the temp file
file.deleteSync();
});
testWidgets('insert an image from network', (tester) async {
await tester.initializeAppFlowy();
await tester.tapGoButton();
// create a new document
await tester.createNewPageWithName(
name: LocaleKeys.document_plugins_image_addAnImage.tr(),
layout: ViewLayoutPB.Document,
);
// 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);
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.tapButton(
find.descendant(
of: find.byType(EmbedImageUrlWidget),
matching: find.text(
LocaleKeys.document_imageBlock_embedLink_label.tr(),
findRichText: true,
),
),
);
await tester.pumpAndSettle();
expect(find.byType(ResizableImage), findsOneWidget);
final node = tester.editor.getCurrentEditorState().getNodeAtPath([0])!;
expect(node.type, ImageBlockKeys.type);
expect(node.attributes[ImageBlockKeys.url], url);
});
testWidgets('insert an image from unsplash', (tester) async {
await runWithNetworkImages(() async {
await tester.initializeAppFlowy();
await tester.tapGoButton();
// create a new document
await tester.createNewPageWithName(
name: LocaleKeys.document_plugins_image_addAnImage.tr(),
layout: ViewLayoutPB.Document,
);
// 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);
await tester.tapButtonWithName(
'Unsplash',
);
expect(find.byType(UnsplashImageWidget), findsOneWidget);
});
});
});
}
@@ -0,0 +1,118 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';
import 'package:appflowy/user/application/user_settings_service.dart';
import 'package:appflowy/workspace/application/settings/date_time/date_format_ext.dart';
import 'package:appflowy/workspace/presentation/widgets/toggle/toggle.dart';
import 'package:appflowy_backend/protobuf/flowy-user/date_time.pbenum.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:calendar_view/calendar_view.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/text_field.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../util/base.dart';
import '../util/common_operations.dart';
import '../util/editor_test_operations.dart';
import '../util/keyboard.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Reminder in Document', () {
testWidgets('Add reminder for tomorrow, and include time', (tester) async {
const time = "23:59";
await tester.initializeAppFlowy();
await tester.tapGoButton();
final dateTimeSettings =
await UserSettingsBackendService().getDateTimeSettings();
await tester.editor.tapLineOfEditorAt(0);
await tester.editor.getCurrentEditorState().insertNewLine();
await tester.pumpAndSettle();
// Trigger iline action menu and type 'remind tomorrow'
final tomorrow = await _insertReminderTomorrow(tester);
Node node = tester.editor.getCurrentEditorState().getNodeAtPath([1])!;
Map<String, dynamic> mentionAttr =
node.delta!.first.attributes![MentionBlockKeys.mention];
expect(node.type, 'paragraph');
expect(mentionAttr['type'], MentionType.reminder.name);
expect(mentionAttr['date'], tomorrow.toIso8601String());
await tester.tap(
find.text(dateTimeSettings.dateFormat.formatDate(tomorrow, false)),
);
await tester.pumpAndSettle();
await tester.tap(find.byType(Toggle));
await tester.pumpAndSettle();
await tester.enterText(find.byType(FlowyTextField), time);
// Leave text field to submit
await tester.tap(find.text(LocaleKeys.grid_field_includeTime.tr()));
await tester.pumpAndSettle();
node = tester.editor.getCurrentEditorState().getNodeAtPath([1])!;
mentionAttr = node.delta!.first.attributes![MentionBlockKeys.mention];
final tomorrowWithTime =
_dateWithTime(dateTimeSettings.timeFormat, tomorrow, time);
expect(node.type, 'paragraph');
expect(mentionAttr['type'], MentionType.reminder.name);
expect(mentionAttr['date'], tomorrowWithTime.toIso8601String());
});
});
}
Future<DateTime> _insertReminderTomorrow(WidgetTester tester) async {
await tester.editor.showAtMenu();
await FlowyTestKeyboard.simulateKeyDownEvent(
[
LogicalKeyboardKey.keyR,
LogicalKeyboardKey.keyE,
LogicalKeyboardKey.keyM,
LogicalKeyboardKey.keyI,
LogicalKeyboardKey.keyN,
LogicalKeyboardKey.keyD,
LogicalKeyboardKey.space,
LogicalKeyboardKey.keyT,
LogicalKeyboardKey.keyO,
LogicalKeyboardKey.keyM,
LogicalKeyboardKey.keyO,
LogicalKeyboardKey.keyR,
LogicalKeyboardKey.keyR,
LogicalKeyboardKey.keyO,
LogicalKeyboardKey.keyW,
],
tester: tester,
);
await FlowyTestKeyboard.simulateKeyDownEvent(
[LogicalKeyboardKey.enter],
tester: tester,
);
return DateTime.now().add(const Duration(days: 1)).withoutTime;
}
DateTime _dateWithTime(UserTimeFormatPB format, DateTime date, String time) {
final t = format == UserTimeFormatPB.TwelveHour
? DateFormat.jm().parse(time)
: DateFormat.Hm().parse(time);
return DateTime.parse(
'${date.year}${_padZeroLeft(date.month)}${_padZeroLeft(date.day)} ${_padZeroLeft(t.hour)}:${_padZeroLeft(t.minute)}',
);
}
String _padZeroLeft(int a) => a.toString().padLeft(2, '0');
@@ -22,6 +22,8 @@ import 'tabs_test.dart' as tabs_test;
import 'hotkeys_test.dart' as hotkeys_test;
import 'appearance_settings_test.dart' as appearance_test_runner;
import 'auth/auth_test.dart' as auth_test_runner;
import 'settings/user_icon_test.dart' as user_icon_test;
import 'settings/user_language_test.dart' as user_language_test;
/// The main task runner for all integration tests in AppFlowy.
///
@@ -67,7 +69,11 @@ void main() {
// Appearance integration test
appearance_test_runner.main();
if (isSupabaseEnabled) {
// User settings
user_icon_test.main();
user_language_test.main();
if (isCloudEnabled) {
auth_test_runner.main();
}
@@ -0,0 +1,69 @@
import 'dart:ui';
import 'package:appflowy/workspace/presentation/settings/widgets/settings_language_view.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import '../util/util.dart';
import 'package:appflowy/workspace/application/settings/prelude.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Settings: user language tests', () {
testWidgets('select language, language changed', (tester) async {
await tester.initializeAppFlowy();
await tester.tapGoButton();
tester.expectToSeeHomePage();
await tester.openSettings();
await tester.openSettingsPage(SettingsPage.language);
final userLanguageFinder = find.descendant(
of: find.byType(SettingsLanguageView),
matching: find.byType(LanguageSelector),
);
// Grab current locale
LanguageSelector userLanguage =
tester.widget<LanguageSelector>(userLanguageFinder);
Locale currentLocale = userLanguage.currentLocale;
// Open language selector
await tester.tap(userLanguageFinder);
await tester.pumpAndSettle();
// Select first option that isn't default
await tester.tap(find.byType(LanguageItem).at(1));
await tester.pumpAndSettle();
// Make sure the new locale is not the same as previous one
userLanguage = tester.widget<LanguageSelector>(userLanguageFinder);
expect(
userLanguage.currentLocale,
isNot(equals(currentLocale)),
reason: "new language shouldn't equal the previous selected language",
);
// Update the current locale to a new one
currentLocale = userLanguage.currentLocale;
// Tried the same flow for the second time
// Open language selector
await tester.tap(userLanguageFinder);
await tester.pumpAndSettle();
// Select second option that isn't default
await tester.tap(find.byType(LanguageItem).at(2));
await tester.pumpAndSettle();
// Make sure the new locale is not the same as previous one
userLanguage = tester.widget<LanguageSelector>(userLanguageFinder);
expect(
userLanguage.currentLocale,
isNot(equals(currentLocale)),
reason: "new language shouldn't equal the previous selected language",
);
});
});
}
@@ -4,6 +4,7 @@ import 'package:appflowy/plugins/document/presentation/share/share_button.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:path/path.dart' as p;
import 'util/mock/mock_file_picker.dart';
import 'util/util.dart';
@@ -78,7 +79,7 @@ void main() {
});
}
const expectedMarkdown = r'''
const expectedMarkdown = '''
# Welcome to AppFlowy!
## Here are the basics
- [ ] Click anywhere and just start typing.
@@ -105,6 +106,15 @@ fn main() {
## Have a question❓
> Click `?` at the bottom right for help and support.
> 🥰
>
> Like AppFlowy? Follow us:
> [GitHub](https://github.com/AppFlowy-IO/AppFlowy)
> [Twitter](https://twitter.com/appflowy): @appflowy
> [Newsletter](https://blog-appflowy.ghost.io/)
>
''';
@@ -30,7 +30,7 @@ void main() {
LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
);
// and with one paragraph block
expect(find.byType(TextBlockComponentWidget), findsOneWidget);
expect(find.byType(ParagraphBlockComponentWidget), findsOneWidget);
});
testWidgets('create a new document, grid, board and calendar',
@@ -55,7 +55,7 @@ void main() {
switch (layout) {
case ViewLayoutPB.Document:
// and with one paragraph block
expect(find.byType(TextBlockComponentWidget), findsOneWidget);
expect(find.byType(ParagraphBlockComponentWidget), findsOneWidget);
break;
case ViewLayoutPB.Grid:
expect(find.byType(GridPage), findsOneWidget);
@@ -1,9 +1,12 @@
import 'dart:io';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/startup/tasks/prelude.dart';
import 'package:appflowy/workspace/application/settings/prelude.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:path/path.dart' as p;
import 'util/mock/mock_file_picker.dart';
import 'util/util.dart';
@@ -11,6 +14,10 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('customize the folder path', () {
if (Platform.isWindows) {
return;
}
testWidgets('switch to B from A, then switch to A again', (tester) async {
const userA = 'UserA';
const userB = 'UserB';
@@ -54,7 +54,8 @@ import 'package:appflowy/plugins/database_view/widgets/row/row_document.dart';
import 'package:appflowy/plugins/database_view/widgets/row/row_property.dart';
import 'package:appflowy/plugins/database_view/widgets/setting/database_setting.dart';
import 'package:appflowy/plugins/database_view/widgets/setting/setting_button.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/emoji_picker/emoji_menu_item.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_menu_item.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
import 'package:appflowy/workspace/presentation/widgets/toggle/toggle.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';
@@ -673,6 +674,31 @@ extension AppFlowyDatabaseTest on WidgetTester {
await pumpAndSettle();
}
void assertToggleShowHiddenFieldsVisibility(bool shown) {
final button = find.byType(ToggleHiddenFieldsVisibilityButton);
if (shown) {
expect(button, findsOneWidget);
} else {
expect(button, findsNothing);
}
}
Future<void> toggleShowHiddenFields() async {
final button = find.byType(ToggleHiddenFieldsVisibilityButton);
await tapButton(button);
}
Future<void> tapDeletePropertyInFieldEditor() async {
final deleteButton = find.byType(DeleteFieldButton);
await tapButton(deleteButton);
final confirmButton = find.descendant(
of: find.byType(NavigatorAlertDialog),
matching: find.byType(PrimaryTextButton),
);
await tapButton(confirmButton);
}
Future<void> scrollGridByOffset(Offset offset) async {
await drag(find.byType(GridPage), offset);
await pumpAndSettle();
@@ -746,7 +772,7 @@ extension AppFlowyDatabaseTest on WidgetTester {
}
Future<void> tapHidePropertyButtonInFieldEditor() async {
final button = find.byType(HideFieldButton);
final button = find.byType(FieldVisibilityToggleButton);
await tapButton(button);
}
@@ -899,7 +925,7 @@ extension AppFlowyDatabaseTest on WidgetTester {
}
Future<void> assertRowCountInGridPage(int num) async {
final text = find.text('${rowCountString()} $num',findRichText: true);
final text = find.text('${rowCountString()} $num', findRichText: true);
expect(text, findsOneWidget);
}
@@ -7,6 +7,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/header/cus
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/header/emoji_popover.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';
@@ -160,7 +161,7 @@ class EditorOperations {
/// Must call [showAtMenu] first.
Future<void> tapAtMenuItemWithName(String name) async {
final atMenuItem = find.descendant(
of: find.byType(SelectionMenuWidget),
of: find.byType(InlineActionsHandler),
matching: find.text(name, findRichText: true),
);
await tester.tapButton(atMenuItem);
@@ -1,5 +1,5 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/appearance.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/prelude.dart';
import 'package:appflowy/workspace/presentation/settings/settings_dialog.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/settings_menu_element.dart';
@@ -0,0 +1,19 @@
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/protobuf/flowy-date/entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:dartz/dartz.dart';
class DateService {
static Future<Either<FlowyError, DateTime>> queryDate(String search) async {
final query = DateQueryPB.create()..query = search;
final result = (await DateEventQueryDate(query).send()).swap();
return result.fold((l) => left(l), (r) {
final date = DateTime.tryParse(r.date);
if (date != null) {
return right(date);
}
return left(FlowyError(msg: 'Could not parse Date (NLP) from String'));
});
}
}
+82 -2
View File
@@ -1,5 +1,6 @@
// lib/env/env.dart
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy_backend/log.dart';
import 'package:envied/envied.dart';
part 'env.g.dart';
@@ -17,6 +18,36 @@ part 'env.g.dart';
///
@Envied(path: '.env')
abstract class Env {
@EnviedField(
obfuscate: true,
varName: 'CLOUD_TYPE',
defaultValue: '0',
)
static final int cloudType = _Env.cloudType;
/// AppFlowy Cloud Configuration
@EnviedField(
obfuscate: true,
varName: 'APPFLOWY_CLOUD_BASE_URL',
defaultValue: '',
)
static final String afCloudBaseUrl = _Env.afCloudBaseUrl;
@EnviedField(
obfuscate: true,
varName: 'APPFLOWY_CLOUD_WS_BASE_URL',
defaultValue: '',
)
static final String afCloudWSBaseUrl = _Env.afCloudWSBaseUrl;
@EnviedField(
obfuscate: true,
varName: 'APPFLOWY_CLOUD_GOTRUE_URL',
defaultValue: '',
)
static final String afCloudGoTrueUrl = _Env.afCloudGoTrueUrl;
// Supabase Configuration:
@EnviedField(
obfuscate: true,
varName: 'SUPABASE_URL',
@@ -31,11 +62,60 @@ abstract class Env {
static final String supabaseAnonKey = _Env.supabaseAnonKey;
}
bool get isSupabaseEnabled {
bool get isCloudEnabled {
// Only enable supabase in release and develop mode.
if (integrationMode().isRelease || integrationMode().isDevelop) {
return Env.supabaseUrl.isNotEmpty && Env.supabaseAnonKey.isNotEmpty;
return currentCloudType().isEnabled;
} else {
return false;
}
}
bool get isSupabaseEnabled {
// Only enable supabase in release and develop mode.
if (integrationMode().isRelease || integrationMode().isDevelop) {
return currentCloudType() == CloudType.supabase;
} else {
return false;
}
}
bool get isAppFlowyCloudEnabled {
// Only enable appflowy cloud in release and develop mode.
if (integrationMode().isRelease || integrationMode().isDevelop) {
return currentCloudType() == CloudType.appflowyCloud;
} else {
return false;
}
}
enum CloudType {
unknown,
supabase,
appflowyCloud;
bool get isEnabled => this != CloudType.unknown;
}
CloudType currentCloudType() {
final value = Env.cloudType;
if (value == 1) {
if (Env.supabaseUrl.isEmpty || Env.supabaseAnonKey.isEmpty) {
Log.error("Supabase is not configured");
return CloudType.unknown;
} else {
return CloudType.supabase;
}
}
if (value == 2) {
if (Env.afCloudBaseUrl.isEmpty || Env.afCloudWSBaseUrl.isEmpty) {
Log.error("AppFlowy cloud is not configured");
return CloudType.unknown;
} else {
return CloudType.appflowyCloud;
}
}
return CloudType.unknown;
}
@@ -23,7 +23,20 @@ ThemeData getMobileThemeData() {
primaryColor: mobileColorTheme.primary, //primary 100
primaryColorLight: const Color(0xFF57B5F8), //primary 80
dividerColor: mobileColorTheme.outline, //caption
scaffoldBackgroundColor: Colors.white,
scaffoldBackgroundColor: mobileColorTheme.background,
appBarTheme: AppBarTheme(
foregroundColor: mobileColorTheme.onBackground,
backgroundColor: mobileColorTheme.background,
elevation: 0,
centerTitle: false,
titleTextStyle: TextStyle(
fontFamily: 'Poppins',
color: mobileColorTheme.onBackground,
fontSize: 18,
fontWeight: FontWeight.w600,
letterSpacing: 0.05,
),
),
// button
elevatedButtonTheme: ElevatedButtonThemeData(
style: ButtonStyle(
@@ -72,7 +85,6 @@ ThemeData getMobileThemeData() {
displayLarge: TextStyle(
color: Color(0xFF57B5F8),
fontSize: 32,
fontFamily: 'Poppins',
fontWeight: FontWeight.w700,
height: 1.20,
letterSpacing: 0.16,
@@ -0,0 +1,99 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
// TODO(yijing): delete this after implementing the real screen inside bottom navigation bar.
/// For demonstration purposes
class DetailsPlaceholderScreen extends StatefulWidget {
/// Constructs a [DetailsScreen].
const DetailsPlaceholderScreen({
required this.label,
this.param,
this.extra,
this.withScaffold = true,
super.key,
});
/// The label to display in the center of the screen.
final String label;
/// Optional param
final String? param;
/// Optional extra object
final Object? extra;
/// Wrap in scaffold
final bool withScaffold;
@override
State<StatefulWidget> createState() => DetailsPlaceholderScreenState();
}
/// The state for DetailsScreen
class DetailsPlaceholderScreenState extends State<DetailsPlaceholderScreen> {
int _counter = 0;
@override
Widget build(BuildContext context) {
if (widget.withScaffold) {
return Scaffold(
appBar: AppBar(
title: Text('Details Screen - ${widget.label}'),
),
body: _build(context),
);
} else {
return Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: _build(context),
);
}
}
Widget _build(BuildContext context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Details for ${widget.label} - Counter: $_counter',
style: Theme.of(context).textTheme.titleLarge,
),
const Padding(padding: EdgeInsets.all(4)),
TextButton(
onPressed: () {
setState(() {
_counter++;
});
},
child: const Text('Increment counter'),
),
const Padding(padding: EdgeInsets.all(8)),
if (widget.param != null)
Text(
'Parameter: ${widget.param!}',
style: Theme.of(context).textTheme.titleMedium,
),
const Padding(padding: EdgeInsets.all(8)),
if (widget.extra != null)
Text(
'Extra: ${widget.extra!}',
style: Theme.of(context).textTheme.titleMedium,
),
if (!widget.withScaffold) ...<Widget>[
const Padding(padding: EdgeInsets.all(16)),
TextButton(
onPressed: () {
GoRouter.of(context).pop();
},
child: const Text(
'< Back',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
),
]
],
),
);
}
}
@@ -0,0 +1 @@
export 'mobile_home_page.dart';
@@ -0,0 +1,80 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/auth/auth_service.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/workspace.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:flutter/material.dart';
// TODO(yijing): This is just a placeholder for now.
class MobileHomeScreen extends StatelessWidget {
const MobileHomeScreen({super.key});
static const routeName = "/MobileHomeScreen";
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: Future.wait([
FolderEventGetCurrentWorkspace().send(),
getIt<AuthService>().getUser(),
]),
builder: (context, snapshots) {
if (!snapshots.hasData) {
return const Center(child: CircularProgressIndicator.adaptive());
}
final workspaceSetting = snapshots.data?[0].fold(
(workspaceSettingPB) {
return workspaceSettingPB as WorkspaceSettingPB?;
},
(error) => null,
);
final userProfile =
snapshots.data?[1].fold((error) => null, (userProfilePB) {
return userProfilePB as UserProfilePB?;
});
// TODO(yijing): implement home page later
return Scaffold(
key: ValueKey(userProfile?.id),
// TODO(yijing):Need to change to workspace when it is ready
appBar: AppBar(
title: Text(
userProfile?.email.toString() ?? 'No email found',
),
actions: [
IconButton(
onPressed: () {
// TODO(yijing): Navigate to setting page
},
icon: const FlowySvg(
FlowySvgs.m_setting_m,
),
)
],
),
body: Center(
child: Column(
children: [
const Text(
'User',
),
Text(
userProfile.toString(),
),
Text('Workspace name: ${workspaceSetting?.workspace.name}'),
ElevatedButton(
onPressed: () async {
await getIt<AuthService>().signOut();
runAppFlowy();
},
child: const Text('Logout'),
)
],
),
),
);
},
);
}
}
@@ -0,0 +1,94 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
/// Builds the "shell" for the app by building a Scaffold with a
/// BottomNavigationBar, where [child] is placed in the body of the Scaffold.
class MobileBottomNavigationBar extends StatelessWidget {
/// Constructs an [MobileBottomNavigationBar].
const MobileBottomNavigationBar({
required this.navigationShell,
super.key,
});
/// The navigation shell and container for the branch Navigators.
final StatefulNavigationShell navigationShell;
@override
Widget build(BuildContext context) {
final style = Theme.of(context);
return Scaffold(
body: navigationShell,
bottomNavigationBar: BottomNavigationBar(
showSelectedLabels: false,
showUnselectedLabels: false,
// Here, the items of BottomNavigationBar are hard coded. In a real
// world scenario, the items would most likely be generated from the
// branches of the shell route, which can be fetched using
// `navigationShell.route.branches`.
type: BottomNavigationBarType.fixed,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
// There is no text shown on the bottom navigation bar, but Exception will be thrown if label is null here.
label: 'home',
icon: const FlowySvg(FlowySvgs.m_home_unselected_lg),
activeIcon: FlowySvg(
FlowySvgs.m_home_selected_lg,
color: style.colorScheme.primary,
),
),
const BottomNavigationBarItem(
label: 'favorite',
icon: FlowySvg(FlowySvgs.m_favorite_unselected_lg),
activeIcon: FlowySvg(
FlowySvgs.m_favorite_selected_lg,
blendMode: null,
),
),
const BottomNavigationBarItem(
label: 'add',
icon: FlowySvg(
FlowySvgs.m_add_circle_xl,
blendMode: null,
),
),
BottomNavigationBarItem(
label: 'search',
icon: const FlowySvg(FlowySvgs.m_search_lg),
activeIcon: FlowySvg(
FlowySvgs.m_search_lg,
color: style.colorScheme.primary,
),
),
BottomNavigationBarItem(
label: 'notification',
icon: const FlowySvg(FlowySvgs.m_notification_unselected_lg),
activeIcon: FlowySvg(
FlowySvgs.m_notification_selected_lg,
color: style.colorScheme.primary,
),
),
],
currentIndex: navigationShell.currentIndex,
onTap: (int bottomBarIndex) => _onTap(context, bottomBarIndex),
),
);
}
/// Navigate to the current location of the branch at the provided index when
/// tapping an item in the BottomNavigationBar.
void _onTap(BuildContext context, int bottomBarIndex) {
// When navigating to a new branch, it's recommended to use the goBranch
// method, as doing so makes sure the last navigation state of the
// Navigator for the branch is restored.
navigationShell.goBranch(
bottomBarIndex,
// A common pattern when using bottom navigation bars is to support
// navigating to the initial location when tapping the item that is
// already active. This example demonstrates how to support this behavior,
// using the initialLocation parameter of goBranch.
initialLocation: bottomBarIndex == navigationShell.currentIndex,
);
}
}
@@ -1,47 +0,0 @@
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/auth/auth_service.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/workspace.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:flutter/material.dart';
class MobileHomeScreen extends StatelessWidget {
const MobileHomeScreen({
super.key,
required this.userProfile,
required this.workspaceSetting,
});
static const routeName = "/MobileHomeScreen";
final UserProfilePB userProfile;
final WorkspaceSettingPB workspaceSetting;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("MobileHomeScreen"),
),
// TODO(yijing): implement home page later
body: Center(
child: Column(
children: [
const Text(
'User',
),
Text(
userProfile.toString(),
),
Text('Workspace name: ${workspaceSetting.workspace.name}'),
ElevatedButton(
onPressed: () async {
await getIt<AuthService>().signOut();
runAppFlowy();
},
child: const Text('Logout'),
)
],
),
),
);
}
}
@@ -0,0 +1,4 @@
export 'home/home.dart';
export 'root_placeholder_page.dart';
export 'details_placeholder_page.dart';
export 'mobile_bottom_navigation_bar.dart';
@@ -0,0 +1,54 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
/// Widget for the root/initial pages in the bottom navigation bar.
class RootPlaceholderScreen extends StatelessWidget {
/// Creates a RootScreen
const RootPlaceholderScreen({
required this.label,
required this.detailsPath,
this.secondDetailsPath,
super.key,
});
/// The label
final String label;
/// The path to the detail page
final String detailsPath;
/// The path to another detail page
final String? secondDetailsPath;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Root of section $label'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('$label Page', style: Theme.of(context).textTheme.titleLarge),
const Padding(padding: EdgeInsets.all(4)),
TextButton(
onPressed: () {
context.go(detailsPath, extra: '$label-XYZ');
},
child: const Text('View details'),
),
const Padding(padding: EdgeInsets.all(4)),
if (secondDetailsPath != null)
TextButton(
onPressed: () {
context.go(secondDetailsPath!);
},
child: const Text('View more details'),
),
],
),
),
);
}
}
@@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:collection';
import 'package:appflowy_backend/protobuf/flowy-database2/checklist_entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/date_entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/field_settings_entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/row_entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/select_option.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/timestamp_entities.pb.dart';
@@ -73,4 +74,13 @@ class DatabaseCellContext with _$DatabaseCellContext {
/// Only the primary field can have an emoji.
String? get emoji => fieldInfo.field.isPrimary ? rowMeta.icon : null;
/// Determines whether a database cell context should be visible.
/// It will be visible when the field is not hidden or when hidden fields
/// should be shown.
bool isVisible({bool showHiddenFields = false}) {
return fieldInfo.visibility != null &&
(showHiddenFields ||
fieldInfo.visibility != FieldVisibility.AlwaysHidden);
}
}
@@ -15,16 +15,16 @@ class FieldActionSheetBloc
final FieldSettingsBackendService fieldSettingsService;
FieldActionSheetBloc({required FieldContext fieldCellContext})
: fieldId = fieldCellContext.field.id,
: fieldId = fieldCellContext.fieldInfo.id,
fieldService = FieldBackendService(
viewId: fieldCellContext.viewId,
fieldId: fieldCellContext.field.id,
fieldId: fieldCellContext.fieldInfo.id,
),
fieldSettingsService =
FieldSettingsBackendService(viewId: fieldCellContext.viewId),
super(
FieldActionSheetState.initial(
TypeOptionPB.create()..field_2 = fieldCellContext.field,
TypeOptionPB.create()..field_2 = fieldCellContext.fieldInfo.field,
),
) {
on<FieldActionSheetEvent>(
@@ -15,13 +15,14 @@ class FieldCellBloc extends Bloc<FieldCellEvent, FieldCellState> {
final FieldBackendService _fieldBackendSvc;
FieldCellBloc({
required FieldContext cellContext,
}) : _fieldListener = SingleFieldListener(fieldId: cellContext.field.id),
required FieldContext fieldContext,
}) : _fieldListener =
SingleFieldListener(fieldId: fieldContext.fieldInfo.id),
_fieldBackendSvc = FieldBackendService(
viewId: cellContext.viewId,
fieldId: cellContext.field.id,
viewId: fieldContext.viewId,
fieldId: fieldContext.fieldInfo.id,
),
super(FieldCellState.initial(cellContext)) {
super(FieldCellState.initial(fieldContext)) {
on<FieldCellEvent>(
(event, emit) async {
event.when(
@@ -29,7 +30,7 @@ class FieldCellBloc extends Bloc<FieldCellEvent, FieldCellState> {
_startListening();
},
didReceiveFieldUpdate: (field) {
emit(state.copyWith(field: cellContext.field));
emit(state.copyWith(field: fieldContext.fieldInfo.field));
},
onResizeStart: () {
emit(state.copyWith(resizeStart: state.width));
@@ -88,8 +89,8 @@ class FieldCellState with _$FieldCellState {
factory FieldCellState.initial(FieldContext cellContext) => FieldCellState(
viewId: cellContext.viewId,
field: cellContext.field,
width: cellContext.field.width.toDouble(),
field: cellContext.fieldInfo.field,
width: cellContext.fieldInfo.field.width.toDouble(),
resizeStart: 0,
);
}
@@ -367,28 +367,13 @@ class FieldController {
/// Listen for field changes in the backend.
void _listenOnFieldChanges() {
void deleteFields(List<FieldIdPB> deletedFields) {
if (deletedFields.isEmpty) {
return;
}
final List<FieldInfo> newFields = fieldInfos;
final Map<String, FieldIdPB> deletedFieldMap = {
for (var fieldOrder in deletedFields) fieldOrder.fieldId: fieldOrder
};
newFields.retainWhere((field) => (deletedFieldMap[field.id] == null));
_fieldNotifier.fieldInfos = newFields;
}
Future<FieldInfo> attachFieldSettings(FieldInfo fieldInfo) async {
return _fieldSettingsBackendSvc
.getFieldSettings(fieldInfo.id)
.then((result) {
final fieldSettings = result.fold(
(fieldSettings) => fieldSettings,
(err) {
return null;
},
(err) => null,
);
if (fieldSettings == null) {
return fieldInfo;
@@ -400,9 +385,25 @@ class FieldController {
});
}
Future<void> insertFields(List<IndexFieldPB> insertedFields) async {
List<FieldInfo> deleteFields(List<FieldIdPB> deletedFields) {
if (deletedFields.isEmpty) {
return fieldInfos;
}
final List<FieldInfo> newFields = fieldInfos;
final Map<String, FieldIdPB> deletedFieldMap = {
for (final fieldOrder in deletedFields) fieldOrder.fieldId: fieldOrder
};
newFields.retainWhere((field) => (deletedFieldMap[field.id] == null));
return newFields;
}
Future<List<FieldInfo>> insertFields(
List<IndexFieldPB> insertedFields,
List<FieldInfo> fieldInfos,
) async {
if (insertedFields.isEmpty) {
return;
return fieldInfos;
}
final List<FieldInfo> newFieldInfos = fieldInfos;
for (final indexField in insertedFields) {
@@ -414,32 +415,32 @@ class FieldController {
newFieldInfos.add(fieldInfo);
}
}
_fieldNotifier.fieldInfos = newFieldInfos;
return newFieldInfos;
}
Future<List<FieldInfo>> updateFields(List<FieldPB> updatedFieldPBs) async {
Future<(List<FieldInfo>, List<FieldInfo>)> updateFields(
List<FieldPB> updatedFieldPBs,
List<FieldInfo> fieldInfos,
) async {
if (updatedFieldPBs.isEmpty) {
return [];
return (<FieldInfo>[], fieldInfos);
}
final List<FieldInfo> newFields = fieldInfos;
final List<FieldInfo> newFieldInfo = fieldInfos;
final List<FieldInfo> updatedFields = [];
for (final updatedFieldPB in updatedFieldPBs) {
final index =
newFields.indexWhere((field) => field.id == updatedFieldPB.id);
newFieldInfo.indexWhere((field) => field.id == updatedFieldPB.id);
if (index != -1) {
newFields.removeAt(index);
newFieldInfo.removeAt(index);
final initial = FieldInfo.initial(updatedFieldPB);
final fieldInfo = await attachFieldSettings(initial);
newFields.insert(index, fieldInfo);
newFieldInfo.insert(index, fieldInfo);
updatedFields.add(fieldInfo);
}
}
if (updatedFields.isNotEmpty) {
_fieldNotifier.fieldInfos = newFields;
}
return updatedFields;
return (updatedFields, newFieldInfo);
}
// Listen on field's changes
@@ -450,10 +451,14 @@ class FieldController {
if (_isDisposed) {
return;
}
deleteFields(changeset.deletedFields);
insertFields(changeset.insertedFields);
List<FieldInfo> updatedFields;
List<FieldInfo> fieldInfos = deleteFields(changeset.deletedFields);
fieldInfos =
await insertFields(changeset.insertedFields, fieldInfos);
(updatedFields, fieldInfos) =
await updateFields(changeset.updatedFields, fieldInfos);
final updatedFields = await updateFields(changeset.updatedFields);
_fieldNotifier.fieldInfos = fieldInfos;
for (final listener in _updatedFieldCallbacks.values) {
listener(updatedFields);
}
@@ -1,3 +1,4 @@
import 'package:appflowy/plugins/database_view/application/field/field_info.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/database_entities.pb.dart';
import 'package:dartz/dartz.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
@@ -108,6 +109,6 @@ class FieldBackendService {
class FieldContext with _$FieldContext {
const factory FieldContext({
required String viewId,
required FieldPB field,
required FieldInfo fieldInfo,
}) = _FieldCellContext;
}
@@ -20,7 +20,14 @@ class FieldSettingsBackendService {
return DatabaseEventGetFieldSettings(payload).send().then((result) {
return result.fold(
(fieldSettings) => left(fieldSettings.items.first),
(repeatedFieldSettings) {
final fieldSetting = repeatedFieldSettings.items.first;
if (!fieldSetting.hasVisibility()) {
fieldSetting.visibility = FieldVisibility.AlwaysShown;
}
return left(fieldSetting);
},
(r) => right(r),
);
});
@@ -31,7 +38,18 @@ class FieldSettingsBackendService {
return DatabaseEventGetAllFieldSettings(payload).send().then((result) {
return result.fold(
(fieldSettings) => left(fieldSettings.items),
(repeatedFieldSettings) {
final fieldSettings = <FieldSettingsPB>[];
for (final fieldSetting in repeatedFieldSettings.items) {
if (!fieldSetting.hasVisibility()) {
fieldSetting.visibility = FieldVisibility.AlwaysShown;
}
fieldSettings.add(fieldSetting);
}
return left(fieldSettings);
},
(r) => right(r),
);
});
@@ -246,14 +246,11 @@ class RowCache {
// ignore: prefer_collection_literals
final cellContextMap = CellContextByFieldId();
for (final fieldInfo in _fieldDelegate.fieldInfos) {
if (fieldInfo.visibility != null &&
fieldInfo.visibility != FieldVisibility.AlwaysHidden) {
cellContextMap[fieldInfo.id] = DatabaseCellContext(
rowMeta: rowMeta,
viewId: viewId,
fieldInfo: fieldInfo,
);
}
cellContextMap[fieldInfo.id] = DatabaseCellContext(
rowMeta: rowMeta,
viewId: viewId,
fieldInfo: fieldInfo,
);
}
return cellContextMap;
}
@@ -381,14 +381,10 @@ Widget? _buildHeaderIcon(GroupData customData) {
switch (customData.fieldType) {
case FieldType.Checkbox:
final group = customData.asCheckboxGroup()!;
if (group.isCheck) {
widget = const FlowySvg(
FlowySvgs.check_filled_s,
blendMode: BlendMode.dst,
);
} else {
widget = const FlowySvg(FlowySvgs.uncheck_s);
}
widget = FlowySvg(
group.isCheck ? FlowySvgs.check_filled_s : FlowySvgs.uncheck_s,
blendMode: BlendMode.dst,
);
break;
case FieldType.DateTime:
case FieldType.LastEditedTime:
@@ -23,12 +23,14 @@ class CalendarEventEditorBloc
await event.when(
initial: () {
_startListening();
final cells = rowController.loadData();
final cells = rowController
.loadData()
.values
.where((cellContext) => cellContext.isVisible())
.toList();
if (!isClosed) {
add(
CalendarEventEditorEvent.didReceiveCellDatas(
cells.values.toList(),
),
CalendarEventEditorEvent.didReceiveCellDatas(cells),
);
}
},
@@ -47,8 +49,11 @@ class CalendarEventEditorBloc
rowController.addListener(
onRowChanged: (cells, reason) {
if (!isClosed) {
final cellData = cells.values
.where((cellContext) => cellContext.isVisible())
.toList();
add(
CalendarEventEditorEvent.didReceiveCellDatas(cells.values.toList()),
CalendarEventEditorEvent.didReceiveCellDatas(cellData),
);
}
},
@@ -249,8 +249,9 @@ class _PropertyCellState extends State<PropertyCell> {
cellPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
);
case FieldType.Checklist:
return SelectOptionCellStyle(
return ChecklistCellStyle(
placeholder: LocaleKeys.grid_row_textPlaceholder.tr(),
cellPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
);
case FieldType.Number:
return GridNumberCellStyle(
@@ -265,7 +266,6 @@ class _PropertyCellState extends State<PropertyCell> {
placeholder: LocaleKeys.grid_row_textPlaceholder.tr(),
cellPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
);
case FieldType.URL:
return GridURLCellStyle(
placeholder: LocaleKeys.grid_row_textPlaceholder.tr(),
@@ -39,6 +39,8 @@ class RowBloc extends Bloc<RowEvent, RowState> {
_rowBackendSvc.createRowAfterRow(rowId);
},
didReceiveCells: (cellByFieldId, reason) async {
cellByFieldId
.removeWhere((_, cellContext) => !cellContext.isVisible());
final cells = cellByFieldId.values
.map((e) => GridCellEquatable(e.fieldInfo))
.toList();
@@ -106,16 +108,18 @@ class RowState with _$RowState {
factory RowState.initial(
CellContextByFieldId cellByFieldId,
) =>
RowState(
cellByFieldId: cellByFieldId,
cells: UnmodifiableListView(
cellByFieldId.values
.map((e) => GridCellEquatable(e.fieldInfo))
.toList(),
),
rowSource: const RowSourece.disk(),
);
) {
cellByFieldId.removeWhere((_, cellContext) => !cellContext.isVisible());
return RowState(
cellByFieldId: cellByFieldId,
cells: UnmodifiableListView(
cellByFieldId.values
.map((e) => GridCellEquatable(e.fieldInfo))
.toList(),
),
rowSource: const RowSourece.disk(),
);
}
}
class GridCellEquatable extends Equatable {
@@ -14,49 +14,73 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
RowDetailBloc({
required this.rowController,
}) : super(RowDetailState.initial()) {
}) : super(RowDetailState.initial(rowController.loadData())) {
on<RowDetailEvent>(
(event, emit) async {
await event.when(
initial: () async {
await _startListening();
final cells = rowController.loadData();
if (!isClosed) {
add(RowDetailEvent.didReceiveCellDatas(cells.values.toList()));
}
},
didReceiveCellDatas: (cells) {
emit(state.copyWith(cells: cells));
didReceiveCellDatas: (visibleCells, allCells, numHiddenFields) {
emit(
state.copyWith(
visibleCells: visibleCells,
allCells: allCells,
numHiddenFields: numHiddenFields,
),
);
},
deleteField: (fieldId) {
_fieldBackendService(fieldId).deleteField();
final fieldService = FieldBackendService(
viewId: rowController.viewId,
fieldId: fieldId,
);
fieldService.deleteField();
},
showField: (fieldId) async {
toggleFieldVisibility: (fieldId) async {
final fieldInfo = state.allCells
.where((cellContext) => cellContext.fieldId == fieldId)
.first
.fieldInfo;
final fieldVisibility =
fieldInfo.visibility == FieldVisibility.AlwaysShown
? FieldVisibility.AlwaysHidden
: FieldVisibility.AlwaysShown;
final result =
await FieldSettingsBackendService(viewId: rowController.viewId)
.updateFieldSettings(
fieldId: fieldId,
fieldVisibility: FieldVisibility.AlwaysShown,
fieldVisibility: fieldVisibility,
);
result.fold(
(l) {},
(err) => Log.error(err),
);
},
hideField: (fieldId) async {
final result =
await FieldSettingsBackendService(viewId: rowController.viewId)
.updateFieldSettings(
fieldId: fieldId,
fieldVisibility: FieldVisibility.AlwaysHidden,
);
result.fold(
(l) {},
(err) => Log.error(err),
reorderField:
(reorderedFieldId, targetFieldId, fromIndex, toIndex) async {
await _reorderField(
reorderedFieldId,
targetFieldId,
fromIndex,
toIndex,
emit,
);
},
reorderField: (fieldId, fromIndex, toIndex) async {
await _reorderField(fieldId, fromIndex, toIndex, emit);
toggleHiddenFieldVisibility: () {
final showHiddenFields = !state.showHiddenFields;
final visibleCells = List<DatabaseCellContext>.from(state.allCells);
visibleCells.retainWhere(
(cellContext) =>
!cellContext.fieldInfo.isPrimary &&
cellContext.isVisible(showHiddenFields: showHiddenFields),
);
emit(
state.copyWith(
showHiddenFields: showHiddenFields,
visibleCells: visibleCells,
),
);
},
);
},
@@ -71,36 +95,60 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
Future<void> _startListening() async {
rowController.addListener(
onRowChanged: (cells, reason) {
if (!isClosed) {
add(RowDetailEvent.didReceiveCellDatas(cells.values.toList()));
onRowChanged: (cellMap, reason) {
if (isClosed) {
return;
}
final allCells = cellMap.values.toList();
int numHiddenFields = 0;
final visibleCells = <DatabaseCellContext>[];
for (final cell in allCells) {
final isPrimary = cell.fieldInfo.isPrimary;
if (cell.isVisible(showHiddenFields: state.showHiddenFields) &&
!isPrimary) {
visibleCells.add(cell);
}
if (!cell.isVisible() && !isPrimary) {
numHiddenFields++;
}
}
add(
RowDetailEvent.didReceiveCellDatas(
visibleCells,
allCells,
numHiddenFields,
),
);
},
);
}
FieldBackendService _fieldBackendService(String fieldId) {
return FieldBackendService(
viewId: rowController.viewId,
fieldId: fieldId,
);
}
Future<void> _reorderField(
String fieldId,
String reorderedFieldId,
String targetFieldId,
int fromIndex,
int toIndex,
Emitter<RowDetailState> emit,
) async {
final cells = List<DatabaseCellContext>.from(state.cells);
final cells = List<DatabaseCellContext>.from(state.visibleCells);
cells.insert(toIndex, cells.removeAt(fromIndex));
emit(state.copyWith(cells: cells));
emit(state.copyWith(visibleCells: cells));
final fieldService =
FieldBackendService(viewId: rowController.viewId, fieldId: fieldId);
final fromIndexInAllFields =
state.allCells.indexWhere((cell) => cell.fieldId == reorderedFieldId);
final toIndexInAllFields =
state.allCells.indexWhere((cell) => cell.fieldId == targetFieldId);
final fieldService = FieldBackendService(
viewId: rowController.viewId,
fieldId: reorderedFieldId,
);
final result = await fieldService.moveField(
fromIndex,
toIndex,
fromIndexInAllFields,
toIndexInAllFields,
);
result.fold((l) {}, (err) => Log.error(err));
}
@@ -110,25 +158,54 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
class RowDetailEvent with _$RowDetailEvent {
const factory RowDetailEvent.initial() = _Initial;
const factory RowDetailEvent.deleteField(String fieldId) = _DeleteField;
const factory RowDetailEvent.showField(String fieldId) = _ShowField;
const factory RowDetailEvent.hideField(String fieldId) = _HideField;
const factory RowDetailEvent.toggleFieldVisibility(String fieldId) =
_ToggleFieldVisibility;
const factory RowDetailEvent.reorderField(
String fieldId,
String reorderFieldID,
String targetFieldID,
int fromIndex,
int toIndex,
) = _ReorderField;
const factory RowDetailEvent.toggleHiddenFieldVisibility() =
_ToggleHiddenFieldVisibility;
const factory RowDetailEvent.didReceiveCellDatas(
List<DatabaseCellContext> gridCells,
List<DatabaseCellContext> visibleCells,
List<DatabaseCellContext> allCells,
int numHiddenFields,
) = _DidReceiveCellDatas;
}
@freezed
class RowDetailState with _$RowDetailState {
const factory RowDetailState({
required List<DatabaseCellContext> cells,
required List<DatabaseCellContext> visibleCells,
required List<DatabaseCellContext> allCells,
required bool showHiddenFields,
required int numHiddenFields,
}) = _RowDetailState;
factory RowDetailState.initial() => RowDetailState(
cells: List.empty(),
);
factory RowDetailState.initial(CellContextByFieldId cellByFieldId) {
final allCells = cellByFieldId.values.toList();
int numHiddenFields = 0;
final visibleCells = <DatabaseCellContext>[];
for (final cell in allCells) {
final isVisible = cell.isVisible();
final isPrimary = cell.fieldInfo.isPrimary;
if (isVisible && !isPrimary) {
visibleCells.add(cell);
}
if (!isVisible && !isPrimary) {
numHiddenFields++;
}
}
return RowDetailState(
visibleCells: visibleCells,
allCells: allCells,
showHiddenFields: false,
numHiddenFields: numHiddenFields,
);
}
}
@@ -40,7 +40,7 @@ class GridRowBottomBar extends StatelessWidget {
return Container(
padding: GridSize.footerContentInsets,
height: GridSize.footerHeight,
margin: const EdgeInsets.only(bottom: 200),
margin: const EdgeInsets.only(bottom: 200, top: 8),
child: const GridAddRowButton(),
);
}
@@ -38,7 +38,7 @@ class _GridFieldCellState extends State<GridFieldCell> {
Widget build(BuildContext context) {
return BlocProvider(
create: (context) {
return FieldCellBloc(cellContext: widget.cellContext);
return FieldCellBloc(fieldContext: widget.cellContext);
},
child: BlocBuilder<FieldCellBloc, FieldCellState>(
builder: (context, state) {
@@ -54,7 +54,7 @@ class _GridFieldCellState extends State<GridFieldCell> {
);
},
child: FieldCellButton(
field: widget.cellContext.field,
field: widget.cellContext.fieldInfo.field,
onTap: () => popoverController.show(),
),
);
@@ -34,14 +34,14 @@ class _GridFieldCellActionSheetState extends State<GridFieldCellActionSheet> {
@override
Widget build(BuildContext context) {
if (_showFieldEditor) {
final field = widget.cellContext.field;
return SizedBox(
width: 400,
child: FieldEditor(
viewId: widget.cellContext.viewId,
fieldInfo: widget.cellContext.fieldInfo,
typeOptionLoader: FieldTypeOptionLoader(
viewId: widget.cellContext.viewId,
field: field,
field: widget.cellContext.fieldInfo.field,
),
),
);
@@ -96,8 +96,8 @@ class _EditFieldButton extends StatelessWidget {
}
class _FieldOperationList extends StatelessWidget {
final FieldContext fieldInfo;
const _FieldOperationList(this.fieldInfo, {Key? key}) : super(key: key);
final FieldContext fieldContext;
const _FieldOperationList(this.fieldContext, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
@@ -128,7 +128,7 @@ class _FieldOperationList extends StatelessWidget {
bool enable = true;
// If the field is primary, delete and duplicate are disabled.
if (fieldInfo.field.isPrimary) {
if (fieldContext.fieldInfo.isPrimary) {
switch (action) {
case FieldAction.hide:
break;
@@ -145,7 +145,7 @@ class _FieldOperationList extends StatelessWidget {
child: SizedBox(
height: GridSize.popoverItemHeight,
child: FieldActionCell(
fieldInfo: fieldInfo,
fieldInfo: fieldContext,
action: action,
enable: enable,
),
@@ -217,7 +217,7 @@ extension _FieldActionExtension on FieldAction {
}
}
void run(BuildContext context, FieldContext fieldInfo) {
void run(BuildContext context, FieldContext fieldContext) {
switch (this) {
case FieldAction.hide:
context
@@ -228,8 +228,8 @@ extension _FieldActionExtension on FieldAction {
PopoverContainer.of(context).close();
FieldBackendService(
viewId: fieldInfo.viewId,
fieldId: fieldInfo.field.id,
viewId: fieldContext.viewId,
fieldId: fieldContext.fieldInfo.id,
).duplicateField();
break;
@@ -240,8 +240,8 @@ extension _FieldActionExtension on FieldAction {
title: LocaleKeys.grid_field_deleteFieldPromptMessage.tr(),
confirm: () {
FieldBackendService(
viewId: fieldInfo.viewId,
fieldId: fieldInfo.field.id,
viewId: fieldContext.viewId,
fieldId: fieldContext.fieldInfo.field.id,
).deleteField();
},
).show(context);
@@ -1,6 +1,8 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/plugins/database_view/application/field/field_editor_bloc.dart';
import 'package:appflowy/plugins/database_view/application/field/field_info.dart';
import 'package:appflowy/plugins/database_view/application/field/type_option/type_option_context.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/field_settings_entities.pb.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -19,17 +21,19 @@ class FieldEditor extends StatefulWidget {
final String viewId;
final bool isGroupingField;
final Function(String)? onDeleted;
final Function(String)? onHidden;
final Function(String)? onToggleVisibility;
final FieldTypeOptionLoader typeOptionLoader;
final FieldInfo? fieldInfo;
const FieldEditor({
required this.viewId,
required this.typeOptionLoader,
this.fieldInfo,
this.isGroupingField = false,
this.onDeleted,
this.onHidden,
Key? key,
}) : super(key: key);
this.onToggleVisibility,
super.key,
});
@override
State<StatefulWidget> createState() => _FieldEditorState();
@@ -53,14 +57,14 @@ class _FieldEditorState extends State<FieldEditor> {
@override
Widget build(BuildContext context) {
final bool requireSpace = widget.onDeleted != null ||
widget.onHidden != null ||
widget.onToggleVisibility != null ||
!widget.typeOptionLoader.field.isPrimary;
final List<Widget> children = [
FieldNameTextField(popoverMutex: popoverMutex),
if (requireSpace) const VSpace(4),
if (widget.onDeleted != null) _addDeleteFieldButton(),
if (widget.onHidden != null) _addHideFieldButton(),
if (widget.onToggleVisibility != null) _addHideFieldButton(),
if (!widget.typeOptionLoader.field.isPrimary)
FieldTypeOptionCell(popoverMutex: popoverMutex),
];
@@ -88,7 +92,7 @@ class _FieldEditorState extends State<FieldEditor> {
builder: (context, state) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: _DeleteFieldButton(
child: DeleteFieldButton(
popoverMutex: popoverMutex,
onDeleted: () {
state.field.fold(
@@ -107,12 +111,14 @@ class _FieldEditorState extends State<FieldEditor> {
builder: (context, state) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: HideFieldButton(
child: FieldVisibilityToggleButton(
isFieldHidden:
widget.fieldInfo!.visibility == FieldVisibility.AlwaysHidden,
popoverMutex: popoverMutex,
onHidden: () {
onTap: () {
state.field.fold(
() => Log.error('Can not hidden the field'),
(field) => widget.onHidden?.call(field.id),
(field) => widget.onToggleVisibility?.call(field.id),
);
},
),
@@ -218,15 +224,16 @@ class _FieldNameTextFieldState extends State<FieldNameTextField> {
}
}
class _DeleteFieldButton extends StatelessWidget {
@visibleForTesting
class DeleteFieldButton extends StatelessWidget {
final PopoverMutex popoverMutex;
final VoidCallback? onDeleted;
const _DeleteFieldButton({
const DeleteFieldButton({
required this.popoverMutex,
required this.onDeleted,
Key? key,
}) : super(key: key);
super.key,
});
@override
Widget build(BuildContext context) {
@@ -253,15 +260,17 @@ class _DeleteFieldButton extends StatelessWidget {
}
@visibleForTesting
class HideFieldButton extends StatelessWidget {
class FieldVisibilityToggleButton extends StatelessWidget {
final bool isFieldHidden;
final PopoverMutex popoverMutex;
final VoidCallback? onHidden;
final VoidCallback? onTap;
const HideFieldButton({
const FieldVisibilityToggleButton({
required this.isFieldHidden,
required this.popoverMutex,
required this.onHidden,
Key? key,
}) : super(key: key);
required this.onTap,
super.key,
});
@override
Widget build(BuildContext context) {
@@ -270,10 +279,13 @@ class HideFieldButton extends StatelessWidget {
builder: (context, state) {
final Widget button = FlowyButton(
text: FlowyText.medium(
LocaleKeys.grid_field_hide.tr(),
isFieldHidden
? LocaleKeys.grid_field_show.tr()
: LocaleKeys.grid_field_hide.tr(),
),
leftIcon: const FlowySvg(FlowySvgs.hide_s),
onTap: () => onHidden?.call(),
leftIcon:
FlowySvg(isFieldHidden ? FlowySvgs.show_m : FlowySvgs.hide_m),
onTap: onTap,
onHover: (_) => popoverMutex.close(),
);
return SizedBox(height: GridSize.popoverItemHeight, child: button);
@@ -98,12 +98,12 @@ class _GridHeaderState extends State<_GridHeader> {
.map(
(field) => FieldContext(
viewId: widget.viewId,
field: field.field,
fieldInfo: field,
),
)
.map(
(ctx) => GridFieldCell(
key: _getKeyById(ctx.field.id),
key: _getKeyById(ctx.fieldInfo.id),
cellContext: ctx,
),
)
@@ -136,7 +136,7 @@ class _GridHeaderState extends State<_GridHeader> {
int newIndex,
) {
if (cells.length > oldIndex) {
final field = cells[oldIndex].cellContext.field;
final field = cells[oldIndex].cellContext.fieldInfo.field;
context
.read<GridHeaderBloc>()
.add(GridHeaderEvent.moveField(field, oldIndex, newIndex));
@@ -73,6 +73,7 @@ class NumberTypeOptionWidget extends TypeOptionWidget {
height: GridSize.popoverItemHeight,
alignment: Alignment.centerLeft,
child: FlowyText.medium(
color: Theme.of(context).colorScheme.outline,
LocaleKeys.grid_field_numberFormat.tr(),
),
);
@@ -224,7 +224,7 @@ class _SelectOptionColorCell extends StatelessWidget {
final colorIcon = SizedBox.square(
dimension: 16,
child: Container(
child: DecoratedBox(
decoration: BoxDecoration(
color: color.toColor(context),
shape: BoxShape.circle,
@@ -230,7 +230,7 @@ class _RowMenuButtonState extends State<RowMenuButton> {
onPressed: () => widget.openMenu(),
iconPadding: const EdgeInsets.all(3),
icon: FlowySvg(
FlowySvgs.details_s,
FlowySvgs.drag_element_s,
color: Theme.of(context).colorScheme.tertiary,
),
);
@@ -93,6 +93,8 @@ List<DatabaseCellContext> _makeCells(
CellContextByFieldId originalCellMap,
) {
final List<DatabaseCellContext> cells = [];
originalCellMap
.removeWhere((fieldId, cellContext) => !cellContext.isVisible());
for (final entry in originalCellMap.entries) {
// Filter out the cell if it's fieldId equal to the groupFieldId
if (groupFieldId != null) {
@@ -39,12 +39,11 @@ class _CheckboxCellState extends State<CheckboxCardCell> {
buildWhen: (previous, current) =>
previous.isSelected != current.isSelected,
builder: (context, state) {
final icon = state.isSelected
? const FlowySvg(
FlowySvgs.check_filled_s,
blendMode: BlendMode.dst,
)
: const FlowySvg(FlowySvgs.uncheck_s);
final icon = FlowySvg(
state.isSelected ? FlowySvgs.check_filled_s : FlowySvgs.uncheck_s,
blendMode: BlendMode.dst,
);
return Align(
alignment: Alignment.centerLeft,
child: Padding(
@@ -151,6 +151,7 @@ class _GridPropertyCellState extends State<GridPropertyCell> {
popupBuilder: (BuildContext context) {
return FieldEditor(
viewId: widget.viewId,
fieldInfo: widget.fieldInfo,
typeOptionLoader: FieldTypeOptionLoader(
viewId: widget.viewId,
field: widget.fieldInfo.field,
@@ -3,6 +3,7 @@ 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/widget/flowy_tooltip.dart';
import 'package:flutter/material.dart';
import 'package:styled_widget/styled_widget.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
@@ -66,7 +67,7 @@ class _PrimaryCellAccessoryState extends State<PrimaryCellAccessory>
with GridCellAccessoryState {
@override
Widget build(BuildContext context) {
return Tooltip(
return FlowyTooltip(
message: LocaleKeys.tooltip_openAsPage.tr(),
child: SizedBox(
width: 26,
@@ -116,6 +116,9 @@ class CheckboxCellUncheck extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const FlowySvg(FlowySvgs.uncheck_s);
return const FlowySvg(
FlowySvgs.uncheck_s,
blendMode: BlendMode.dst,
);
}
}
@@ -86,15 +86,15 @@ class DateCellCalendarBloc
: (start, state.startDay!);
emit(state.copyWith(startDay: null, endDay: null));
await _updateDateData(
date: newStart.toLocal().date,
endDate: newEnd.toLocal().date,
date: newStart.date,
endDate: newEnd.date,
);
} else if (end == null) {
emit(state.copyWith(startDay: start, endDay: null));
} else {
await _updateDateData(
date: start!.toLocal().date,
endDate: end.toLocal().date,
date: start!.date,
endDate: end.date,
);
}
},
@@ -3,17 +3,16 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database_view/application/cell/cell_controller_builder.dart';
import 'package:appflowy/plugins/database_view/application/field/type_option/type_option_context.dart';
import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/type_option/timestamp.dart';
import 'package:appflowy/workspace/presentation/widgets/date_picker/appflowy_calendar.dart';
import 'package:appflowy/workspace/presentation/widgets/toggle/toggle.dart';
import 'package:appflowy/workspace/presentation/widgets/toggle/toggle_style.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/date_entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pbserver.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:dartz/dartz.dart' show Either;
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra/time/duration.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -24,9 +23,6 @@ import '../../../../grid/presentation/widgets/common/type_option_separator.dart'
import '../../../../grid/presentation/widgets/header/type_option/date.dart';
import 'date_cal_bloc.dart';
final kFirstDay = DateTime.utc(1970, 1, 1);
final kLastDay = DateTime.utc(2100, 1, 1);
class DateCellEditor extends StatefulWidget {
final VoidCallback onDismissed;
final DateCellController cellController;
@@ -51,9 +47,9 @@ class _DateCellEditor extends State<DateCellEditor> {
builder: (BuildContext context, snapshot) {
if (snapshot.hasData) {
return _buildWidget(snapshot);
} else {
return const SizedBox.shrink();
}
return const SizedBox.shrink();
},
);
}
@@ -81,22 +77,14 @@ class _CellCalendarWidget extends StatefulWidget {
const _CellCalendarWidget({
required this.cellContext,
required this.dateTypeOptionPB,
Key? key,
}) : super(key: key);
});
@override
State<_CellCalendarWidget> createState() => _CellCalendarWidgetState();
}
class _CellCalendarWidgetState extends State<_CellCalendarWidget> {
late PopoverMutex popoverMutex;
@override
void initState() {
popoverMutex = PopoverMutex();
super.initState();
}
final PopoverMutex popoverMutex = PopoverMutex();
@override
Widget build(BuildContext context) {
@@ -293,7 +281,7 @@ class _DatePickerState extends State<DatePicker> {
state.isRange ? false : isSameDay(state.dateTime, day),
onDaySelected: (selectedDay, focusedDay) {
context.read<DateCellCalendarBloc>().add(
DateCellCalendarEvent.selectDay(selectedDay.toLocal().date),
DateCellCalendarEvent.selectDay(selectedDay),
);
},
onRangeSelected: (start, end, focusedDay) {
@@ -378,6 +366,9 @@ class EndTimeButton extends StatelessWidget {
}
}
const _maxLengthTwelveHour = 8;
const _maxLengthTwentyFourHour = 5;
class _TimeTextField extends StatefulWidget {
final bool isEndTime;
final String? timeStr;
@@ -387,8 +378,7 @@ class _TimeTextField extends StatefulWidget {
required this.timeStr,
required this.popoverMutex,
required this.isEndTime,
Key? key,
}) : super(key: key);
});
@override
State<_TimeTextField> createState() => _TimeTextFieldState();
@@ -446,6 +436,11 @@ class _TimeTextFieldState extends State<_TimeTextField> {
errorText: widget.isEndTime
? state.parseEndTimeError
: state.parseTimeError,
maxLength:
state.dateTypeOptionPB.timeFormat == TimeFormatPB.TwelveHour
? _maxLengthTwelveHour
: _maxLengthTwentyFourHour,
showCounter: false,
onSubmitted: (timeStr) {
if (widget.isEndTime) {
context
@@ -24,7 +24,7 @@ class GridTextCellStyle extends GridCellStyle {
this.autofocus = false,
this.showEmoji = true,
this.emojiFontSize = 16,
this.emojiHPadding = 0,
this.emojiHPadding = 4,
this.useRoundedBorder = false,
});
}
@@ -144,8 +144,10 @@ class _GridURLCellState extends GridEditableTextCell<GridURLCell> {
_controller.text = state.content;
},
builder: (context, state) {
final style = widget.cellStyle?.textStyle ??
Theme.of(context).textTheme.bodyMedium!;
widget._cellDataNotifier.value = state.content;
final urlEditor = Padding(
return Padding(
padding: EdgeInsets.only(
left: GridSize.cellContentInsets.left,
right: GridSize.cellContentInsets.right,
@@ -154,9 +156,7 @@ class _GridURLCellState extends GridEditableTextCell<GridURLCell> {
controller: _controller,
focusNode: focusNode,
maxLines: null,
style: (widget.cellStyle?.textStyle ??
Theme.of(context).textTheme.bodyMedium)
?.copyWith(
style: style.copyWith(
color: Theme.of(context).colorScheme.primary,
decoration: TextDecoration.underline,
),
@@ -168,11 +168,11 @@ class _GridURLCellState extends GridEditableTextCell<GridURLCell> {
),
border: InputBorder.none,
hintText: widget.cellStyle?.placeholder,
hintStyle: style.copyWith(color: Theme.of(context).hintColor),
isDense: true,
),
),
);
return urlEditor;
},
),
);
@@ -5,8 +5,7 @@ import 'package:appflowy/plugins/database_view/application/field/field_info.dart
import 'package:appflowy/plugins/database_view/application/row/row_banner_bloc.dart';
import 'package:appflowy/plugins/database_view/application/row/row_controller.dart';
import 'package:appflowy/plugins/database_view/widgets/row/row_action.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/emoji_picker/emoji_picker.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_picker.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database_view/application/cell/cell_service.dart';
@@ -7,6 +9,7 @@ import 'package:appflowy/plugins/database_view/grid/application/row/row_detail_b
import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/field_cell.dart';
import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/field_editor.dart';
import 'package:appflowy/plugins/database_view/widgets/row/cells/cells.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/block_action_button.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pb.dart';
@@ -35,9 +38,8 @@ class RowPropertyList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder<RowDetailBloc, RowDetailState>(
buildWhen: (previous, current) => previous.cells != current.cells,
builder: (context, state) {
final children = state.cells
final children = state.visibleCells
.where((element) => !element.fieldInfo.field.isPrimary)
.mapIndexed(
(index, cell) => _PropertyCell(
@@ -48,18 +50,26 @@ class RowPropertyList extends StatelessWidget {
),
)
.toList();
return ReorderableListView(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
onReorder: (oldIndex, newIndex) {
final reorderedField = children[oldIndex].cellContext.fieldId;
_reorderField(
context,
state.cells,
reorderedField,
oldIndex,
newIndex,
);
// when reorderiing downwards, need to update index
if (oldIndex < newIndex) {
newIndex--;
}
final reorderedFieldId = children[oldIndex].cellContext.fieldId;
final targetFieldId = children[newIndex].cellContext.fieldId;
context.read<RowDetailBloc>().add(
RowDetailEvent.reorderField(
reorderedFieldId,
targetFieldId,
oldIndex,
newIndex,
),
);
},
buildDefaultDragHandles: false,
proxyDecorator: (child, index, animation) => Material(
@@ -67,52 +77,43 @@ class RowPropertyList extends StatelessWidget {
child: Stack(
children: [
child,
const MouseRegion(cursor: SystemMouseCursors.grabbing),
MouseRegion(
cursor: Platform.isWindows
? SystemMouseCursors.click
: SystemMouseCursors.grabbing,
child: const SizedBox(
width: 16,
height: 30,
child: FlowySvg(FlowySvgs.drag_element_s),
),
),
],
),
),
footer: Padding(
padding: const EdgeInsets.only(left: 20),
child: CreateRowFieldButton(viewId: viewId),
child: Column(
children: [
if (context.read<RowDetailBloc>().state.numHiddenFields != 0)
const Padding(
padding: EdgeInsets.only(bottom: 4.0),
child: ToggleHiddenFieldsVisibilityButton(),
),
CreateRowFieldButton(viewId: viewId),
],
),
),
children: children,
);
},
);
}
void _reorderField(
BuildContext context,
List<DatabaseCellContext> cells,
String reorderedFieldId,
int oldIndex,
int newIndex,
) {
// when reorderiing downwards, need to update index
if (oldIndex < newIndex) {
newIndex--;
}
// also update index when the index is after the index of the primary field
// in the original list of DatabaseCellContext's
final primaryFieldIndex =
cells.indexWhere((element) => element.fieldInfo.isPrimary);
if (oldIndex >= primaryFieldIndex) {
oldIndex++;
}
if (newIndex >= primaryFieldIndex) {
newIndex++;
}
context.read<RowDetailBloc>().add(
RowDetailEvent.reorderField(reorderedFieldId, oldIndex, newIndex),
);
}
}
class _PropertyCell extends StatefulWidget {
final DatabaseCellContext cellContext;
final GridCellBuilder cellBuilder;
final int index;
const _PropertyCell({
required this.cellContext,
@@ -127,6 +128,8 @@ class _PropertyCell extends StatefulWidget {
class _PropertyCellState extends State<_PropertyCell> {
final PopoverController _popoverController = PopoverController();
final PopoverController _fieldPopoverController = PopoverController();
bool _isFieldHover = false;
@override
@@ -135,11 +138,29 @@ class _PropertyCellState extends State<_PropertyCell> {
final cell = widget.cellBuilder.build(widget.cellContext, style: style);
final dragThumb = MouseRegion(
cursor: SystemMouseCursors.grab,
cursor: Platform.isWindows
? SystemMouseCursors.click
: SystemMouseCursors.grab,
child: SizedBox(
width: 16,
height: 30,
child: _isFieldHover ? const FlowySvg(FlowySvgs.drag_element_s) : null,
child: AppFlowyPopover(
controller: _fieldPopoverController,
constraints: BoxConstraints.loose(const Size(240, 600)),
margin: EdgeInsets.zero,
triggerActions: PopoverTriggerFlags.none,
direction: PopoverDirection.bottomWithLeftAligned,
popupBuilder: (popoverContext) => buildFieldEditor(),
child: _isFieldHover
? BlockActionButton(
onTap: () => _fieldPopoverController.show(),
svg: FlowySvgs.drag_element_s,
richMessage: TextSpan(
text: LocaleKeys.grid_rowPage_fieldDragEelementTooltip.tr(),
),
)
: const SizedBox.shrink(),
),
),
);
@@ -195,14 +216,17 @@ class _PropertyCellState extends State<_PropertyCell> {
Widget buildFieldEditor() {
return FieldEditor(
viewId: widget.cellContext.viewId,
fieldInfo: widget.cellContext.fieldInfo,
isGroupingField: widget.cellContext.fieldInfo.isGroupField,
typeOptionLoader: FieldTypeOptionLoader(
viewId: widget.cellContext.viewId,
field: widget.cellContext.fieldInfo.field,
),
onHidden: (fieldId) {
onToggleVisibility: (fieldId) {
_popoverController.close();
context.read<RowDetailBloc>().add(RowDetailEvent.hideField(fieldId));
context
.read<RowDetailBloc>()
.add(RowDetailEvent.toggleFieldVisibility(fieldId));
},
onDeleted: (fieldId) {
_popoverController.close();
@@ -275,6 +299,43 @@ GridCellStyle? _customCellStyle(FieldType fieldType) {
throw UnimplementedError;
}
class ToggleHiddenFieldsVisibilityButton extends StatelessWidget {
const ToggleHiddenFieldsVisibilityButton({super.key});
@override
Widget build(BuildContext context) {
return BlocBuilder<RowDetailBloc, RowDetailState>(
builder: (context, state) {
final text = switch (state.showHiddenFields) {
false => LocaleKeys.grid_rowPage_showHiddenFields
.plural(state.numHiddenFields),
true => LocaleKeys.grid_rowPage_hideHiddenFields
.plural(state.numHiddenFields),
};
return SizedBox(
height: 30,
child: FlowyButton(
text: FlowyText.medium(text, color: Theme.of(context).hintColor),
hoverColor: AFThemeExtension.of(context).lightGreyHover,
leftIcon: RotatedBox(
quarterTurns: state.showHiddenFields ? 1 : 3,
child: FlowySvg(
FlowySvgs.arrow_left_s,
color: Theme.of(context).hintColor,
),
),
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 6),
onTap: () => context.read<RowDetailBloc>().add(
const RowDetailEvent.toggleHiddenFieldVisibility(),
),
),
);
},
);
}
}
class CreateRowFieldButton extends StatefulWidget {
final String viewId;
@@ -104,6 +104,7 @@ class DatabaseShareActionListState extends State<DatabaseShareActionList> {
buildChild: (controller) {
return RoundedTextButton(
title: LocaleKeys.shareAction_buttonText.tr(),
textColor: Theme.of(context).colorScheme.onSurface,
onPressed: () => controller.show(),
);
},
@@ -10,6 +10,7 @@ import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/plugins/document/presentation/export_page_widget.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/base64_string.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-document2/protobuf.dart'
hide DocumentEvent;
@@ -17,7 +18,6 @@ import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/file_picker/file_picker_service.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/widget/error_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -145,18 +145,8 @@ class _DocumentPageState extends State<DocumentPage> {
const encoder = JsonEncoder.withIndent(' ');
final json = encoder.convert(data.toProto3Json());
await File(path).writeAsString(json.base64.base64);
_showMessage('Export success to $path');
}
void _showMessage(String message) {
if (!mounted) {
return;
if (mounted) {
showSnackBarMessage(context, 'Export success to $path');
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: FlowyText(message),
),
);
}
}
@@ -22,7 +22,7 @@ class DocumentBanner extends StatelessWidget {
constraints: const BoxConstraints(minHeight: 60),
child: Container(
width: double.infinity,
color: colorScheme.error,
color: colorScheme.surfaceVariant,
child: FittedBox(
alignment: Alignment.center,
fit: BoxFit.scaleDown,
@@ -30,7 +30,7 @@ class DocumentBanner extends StatelessWidget {
children: [
FlowyText.medium(
LocaleKeys.deletePagePrompt_text.tr(),
color: colorScheme.onError,
color: colorScheme.tertiary,
fontSize: 14,
),
const HSpace(20),
@@ -39,13 +39,13 @@ class DocumentBanner extends StatelessWidget {
minHeight: 40,
contentPadding: EdgeInsets.zero,
bgColor: Colors.transparent,
highlightColor: Theme.of(context).colorScheme.primaryContainer,
outlineColor: colorScheme.onError,
highlightColor: Theme.of(context).colorScheme.onErrorContainer,
outlineColor: colorScheme.tertiaryContainer,
borderRadius: Corners.s8Border,
onPressed: onRestore,
child: FlowyText.medium(
LocaleKeys.deletePagePrompt_restore.tr(),
color: colorScheme.onError,
color: colorScheme.tertiary,
fontSize: 13,
),
),
@@ -55,13 +55,13 @@ class DocumentBanner extends StatelessWidget {
minHeight: 40,
contentPadding: EdgeInsets.zero,
bgColor: Colors.transparent,
highlightColor: Theme.of(context).colorScheme.primary,
outlineColor: colorScheme.onError,
highlightColor: Theme.of(context).colorScheme.error,
outlineColor: colorScheme.tertiaryContainer,
borderRadius: Corners.s8Border,
onPressed: onDelete,
child: FlowyText.medium(
LocaleKeys.deletePagePrompt_deletePermanent.tr(),
color: colorScheme.onError,
color: colorScheme.tertiary,
fontSize: 13,
),
),
@@ -1,9 +1,16 @@
import 'package:appflowy/plugins/document/application/doc_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/inline_page/inline_page_reference.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/background_color/theme_background_color.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/workspace/application/appearance.dart';
import 'package:appflowy/plugins/inline_actions/handlers/date_reference.dart';
import 'package:appflowy/plugins/inline_actions/handlers/inline_page_reference.dart';
import 'package:appflowy/plugins/inline_actions/handlers/reminder_reference.dart';
import 'package:appflowy/plugins/inline_actions/inline_actions_command.dart';
import 'package:appflowy/plugins/inline_actions/inline_actions_service.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/shortcuts/settings_shortcuts_service.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_picker.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:collection/collection.dart';
import 'package:flowy_infra/theme_extension.dart';
@@ -11,6 +18,19 @@ import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
final List<CommandShortcutEvent> commandShortcutEvents = [
toggleToggleListCommand,
...codeBlockCommands,
customCopyCommand,
customPasteCommand,
customCutCommand,
...standardCommandShortcutEvents,
];
final List<CommandShortcutEvent> defaultCommandShortcutEvents = [
...commandShortcutEvents.map((e) => e.copyWith()).toList(),
];
/// Wrapper for the appflowy editor.
class AppFlowyEditorPage extends StatefulWidget {
const AppFlowyEditorPage({
@@ -34,27 +54,28 @@ class AppFlowyEditorPage extends StatefulWidget {
State<AppFlowyEditorPage> createState() => _AppFlowyEditorPageState();
}
final List<CommandShortcutEvent> commandShortcutEvents = [
...codeBlockCommands,
...standardCommandShortcutEvents,
];
final List<CommandShortcutEvent> defaultCommandShortcutEvents = [
...commandShortcutEvents.map((e) => e.copyWith()).toList(),
];
class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
late final ScrollController effectiveScrollController;
final inlinePageReferenceService = InlinePageReferenceService();
late final InlineActionsService inlineActionsService = InlineActionsService(
context: context,
handlers: [
InlinePageReferenceService(
currentViewId: documentBloc.view.id,
).inlinePageReferenceDelegate,
DateReferenceService(context).dateReferenceDelegate,
ReminderReferenceService(context).reminderReferenceDelegate,
],
);
final List<CommandShortcutEvent> commandShortcutEvents = [
late final List<CommandShortcutEvent> commandShortcutEvents = [
toggleToggleListCommand,
...codeBlockCommands,
customCopyCommand,
customPasteCommand,
customCutCommand,
...standardCommandShortcutEvents,
..._buildFindAndReplaceCommands(),
];
final List<ToolbarItem> toolbarItems = [
@@ -84,9 +105,6 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
_customAppFlowyBlockComponentBuilders();
List<CharacterShortcutEvent> get characterShortcutEvents => [
// inline page reference list
...inlinePageReferenceShortcuts,
// code block
...codeBlockCharacterEvents,
@@ -104,19 +122,15 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
..removeWhere(
(element) => element == slashCommand,
), // remove the default slash command.
];
late final inlinePageReferenceShortcuts = [
inlinePageReferenceService.customPageLinkMenu(
character: '@',
style: styleCustomizer.selectionMenuStyleBuilder(),
),
// uncomment this to enable the inline page reference list
// inlinePageReferenceService.customPageLinkMenu(
// character: '+',
// style: styleCustomizer.selectionMenuStyleBuilder(),
// ),
];
/// Inline Actions
/// - Reminder
/// - Inline-page reference
inlineActionsCommand(
inlineActionsService,
style: styleCustomizer.inlineActionsMenuStyleBuilder(),
),
];
late final showSlashMenu = customSlashCommand(
slashMenuItems,
@@ -138,7 +152,18 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
effectiveScrollController = widget.scrollController ?? ScrollController();
// keep the previous font style when typing new text.
supportSlashMenuNodeWhiteList.addAll([
ToggleListBlockKeys.type,
]);
toolbarItemWhiteList.addAll([
ToggleListBlockKeys.type,
CalloutBlockKeys.type,
TableBlockKeys.type,
]);
AppFlowyRichTextKeys.supportSliced.add(AppFlowyRichTextKeys.fontFamily);
// customize the dynamic theme color
_customizeBlockComponentBackgroundColorDecorator();
}
@override
@@ -146,6 +171,9 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
if (widget.scrollController == null) {
effectiveScrollController.dispose();
}
inlineActionsService.dispose();
widget.editorState.dispose();
super.dispose();
}
@@ -158,7 +186,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
final isRTL =
context.read<AppearanceSettingsCubit>().state.layoutDirection ==
LayoutDirection.rtlLayout;
final layoutDirection = isRTL ? TextDirection.rtl : TextDirection.ltr;
final textDirection = isRTL ? TextDirection.rtl : TextDirection.ltr;
_setRTLToolbarItems(isRTL);
@@ -195,8 +223,9 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
items: toolbarItems,
editorState: widget.editorState,
editorScrollController: editorScrollController,
textDirection: textDirection,
child: Directionality(
textDirection: layoutDirection,
textDirection: textDirection,
child: editor,
),
),
@@ -217,9 +246,10 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
final configuration = BlockComponentConfiguration(
padding: (_) => const EdgeInsets.symmetric(vertical: 5.0),
);
final customBlockComponentBuilderMap = {
PageBlockKeys.type: PageBlockComponentBuilder(),
ParagraphBlockKeys.type: TextBlockComponentBuilder(
ParagraphBlockKeys.type: ParagraphBlockComponentBuilder(
configuration: configuration,
),
TodoListBlockKeys.type: TodoListBlockComponentBuilder(
@@ -250,10 +280,11 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
),
textStyleBuilder: (level) => styleCustomizer.headingStyleBuilder(level),
),
ImageBlockKeys.type: ImageBlockComponentBuilder(
ImageBlockKeys.type: CustomImageBlockComponentBuilder(
configuration: configuration,
showMenu: true,
menuBuilder: (node, state) => Positioned(
menuBuilder: (Node node, CustomImageBlockComponentState state) =>
Positioned(
top: 0,
right: 10,
child: ImageMenu(
@@ -334,6 +365,11 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
styleCustomizer.outlineBlockPlaceholderStyleBuilder(),
),
),
errorBlockComponentBuilderKey: ErrorBlockComponentBuilder(
configuration: configuration.copyWith(
padding: (_) => const EdgeInsets.symmetric(vertical: 10),
),
),
};
final builders = {
@@ -458,13 +494,13 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
}
Future<void> _initializeShortcuts() async {
//TODO(Xazin): Refactor lazy initialization
// TODO(Xazin): Refactor lazy initialization
defaultCommandShortcutEvents;
final settingsShortcutService = SettingsShortcutService();
final customizeShortcuts =
await settingsShortcutService.getCustomizeShortcuts();
await settingsShortcutService.updateCommandShortcuts(
standardCommandShortcutEvents,
commandShortcutEvents,
customizeShortcuts,
);
}
@@ -480,4 +516,62 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
toolbarItems.addAll(textDirectionItems);
}
}
List<CommandShortcutEvent> _buildFindAndReplaceCommands() {
return findAndReplaceCommands(
context: context,
style: FindReplaceStyle(
findMenuBuilder: (
context,
editorState,
localizations,
style,
showReplaceMenu,
onDismiss,
) {
return Material(
child: DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant,
borderRadius: BorderRadius.circular(4),
),
child: FindAndReplaceMenuWidget(
editorState: editorState,
onDismiss: onDismiss,
),
),
);
},
),
);
}
void _customizeBlockComponentBackgroundColorDecorator() {
blockComponentBackgroundColorDecorator = (Node node, String colorString) {
// the color string is from FlowyTint.
final tintColor = FlowyTint.values.firstWhereOrNull(
(e) => e.id == colorString,
);
if (tintColor != null) {
return tintColor.color(context);
}
final themeColor = themeBackgroundColors[colorString];
if (themeColor != null) {
return themeColor.color(context);
}
if (colorString == optionActionColorDefaultColor) {
final defaultColor = node.type == CalloutBlockKeys.type
? AFThemeExtension.of(context).calloutBGColor
: Colors.transparent;
return defaultColor;
}
if (colorString == tableCellDefaultColor) {
return AFThemeExtension.of(context).tableCellBGColor;
}
return null;
};
}
}
@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flowy_infra_ui/widget/ignore_parent_gesture.dart';
import 'package:flutter/material.dart';
@@ -20,7 +21,7 @@ class BlockActionButton extends StatelessWidget {
Widget build(BuildContext context) {
return Align(
alignment: Alignment.center,
child: Tooltip(
child: FlowyTooltip(
preferBelow: false,
richMessage: richMessage,
child: MouseRegion(
@@ -2,7 +2,7 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/block_action_button.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/option_action.dart';
import 'package:appflowy/workspace/application/appearance.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
@@ -47,7 +47,7 @@ class BlockOptionButton extends StatelessWidget {
: PopoverDirection.leftWithCenterAligned,
actions: popoverActions,
onPopupBuilder: () {
keepEditorFocusNotifier.value += 1;
keepEditorFocusNotifier.increase();
blockComponentState.alwaysShowActions = true;
},
onClosed: () {
@@ -55,7 +55,7 @@ class BlockOptionButton extends StatelessWidget {
editorState.selectionType = null;
editorState.selection = null;
blockComponentState.alwaysShowActions = false;
keepEditorFocusNotifier.value -= 1;
keepEditorFocusNotifier.decrease();
});
},
onSelected: (action, controller) {
@@ -10,6 +10,8 @@ import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:styled_widget/styled_widget.dart';
const optionActionColorDefaultColor = 'appflowy_theme_default_color';
enum OptionAction {
delete,
duplicate,
@@ -251,12 +253,14 @@ class ColorOptionAction extends PopoverActionCell {
// reset to default background color
FlowyColorOption(
color: defaultColor,
name: LocaleKeys.document_plugins_optionAction_defaultColor.tr(),
i18n: LocaleKeys.document_plugins_optionAction_defaultColor.tr(),
id: optionActionColorDefaultColor,
),
...FlowyTint.values.map(
(e) => FlowyColorOption(
color: e.color(context),
name: e.tintName(AppFlowyEditorLocalizations.current),
i18n: e.tintName(AppFlowyEditorLocalizations.current),
id: e.id,
),
),
];
@@ -268,11 +272,10 @@ class ColorOptionAction extends PopoverActionCell {
color: Theme.of(context).colorScheme.onBackground,
width: 1,
),
onTap: (color, index) async {
onTap: (option, index) async {
final transaction = editorState.transaction;
final backgroundColor = color.toHex();
transaction.updateNode(node, {
blockComponentBackgroundColor: backgroundColor,
blockComponentBackgroundColor: option.id,
});
await editorState.apply(transaction);
@@ -3,7 +3,6 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/op
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:flowy_infra_ui/widget/ignore_parent_gesture.dart';
import 'package:flutter/material.dart';
@@ -112,32 +111,6 @@ class OptionActionList extends StatelessWidget {
}
}
class BlockComponentActionButton extends StatelessWidget {
const BlockComponentActionButton({
super.key,
required this.icon,
required this.onTap,
});
final bool isHovering = false;
final Widget icon;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return MouseRegion(
cursor: SystemMouseCursors.grab,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
onTapDown: (details) {},
onTapUp: (details) {},
child: icon,
),
);
}
}
class OptionActionButton extends StatelessWidget {
const OptionActionButton({
super.key,
@@ -4,13 +4,14 @@ 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/flowy_tooltip.dart';
import 'package:flutter/material.dart';
final alignToolbarItem = ToolbarItem(
id: 'editor.align',
group: 4,
isActive: onlyShowInTextType,
builder: (context, editorState, highlightColor) {
builder: (context, editorState, highlightColor, _) {
final selection = editorState.selection!;
final nodes = editorState.getNodesInSelection(selection);
@@ -88,11 +89,11 @@ class _AlignmentButtonsState extends State<_AlignmentButtons> {
borderRadius: const BorderRadius.all(Radius.circular(4)),
),
popupBuilder: (_) {
keepEditorFocusNotifier.value += 1;
keepEditorFocusNotifier.increase();
return _AlignButtons(onAlignChanged: widget.onAlignChanged);
},
onClose: () {
keepEditorFocusNotifier.value -= 1;
keepEditorFocusNotifier.decrease();
},
child: widget.child,
);
@@ -155,7 +156,7 @@ class _AlignButton extends StatelessWidget {
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: onTap,
child: Tooltip(
child: FlowyTooltip(
message: tooltips,
child: FlowySvg(
icon,
@@ -0,0 +1,15 @@
import 'package:flowy_infra/theme_extension.dart';
// DON'T MODIFY THIS KEY BECAUSE IT'S SAVED IN THE DATABASE!
// Used for the block component background color
const themeBackgroundColors = {
'appflowy_them_color_tint1': FlowyTint.tint1,
'appflowy_them_color_tint2': FlowyTint.tint2,
'appflowy_them_color_tint3': FlowyTint.tint3,
'appflowy_them_color_tint4': FlowyTint.tint4,
'appflowy_them_color_tint5': FlowyTint.tint5,
'appflowy_them_color_tint6': FlowyTint.tint6,
'appflowy_them_color_tint7': FlowyTint.tint7,
'appflowy_them_color_tint8': FlowyTint.tint8,
'appflowy_them_color_tint9': FlowyTint.tint9,
};
@@ -1,5 +1,4 @@
import 'package:appflowy/plugins/document/presentation/editor_plugins/emoji_picker/emoji_picker.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_picker.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
@@ -1,4 +1,5 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/base/insert_page_command.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/application/view/view_service.dart';
@@ -6,13 +7,12 @@ import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.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/error_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:easy_localization/easy_localization.dart';
void showLinkToPageMenu(
OverlayState container,
@@ -27,13 +27,13 @@ void showLinkToPageMenu(
final top = alignment == Alignment.bottomLeft ? offset.dy : null;
final bottom = alignment == Alignment.topLeft ? offset.dy : null;
keepEditorFocusNotifier.value += 1;
keepEditorFocusNotifier.increase();
late OverlayEntry linkToPageMenuEntry;
linkToPageMenuEntry = FullScreenOverlayEntry(
top: top,
bottom: bottom,
left: offset.dx,
dismissCallback: () => keepEditorFocusNotifier.value -= 1,
dismissCallback: () => keepEditorFocusNotifier.decrease(),
builder: (context) => Material(
color: Colors.transparent,
child: LinkToPageMenu(
@@ -225,11 +225,9 @@ class _LinkToPageMenuState extends State<LinkToPageMenu> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: children,
);
} else {
return const Center(
child: CircularProgressIndicator(),
);
}
return const Center(child: CircularProgressIndicator());
},
future: items,
);
@@ -88,8 +88,7 @@ class CalloutBlockComponentBuilder extends BlockComponentBuilder {
bool validate(Node node) =>
node.delta != null &&
node.children.isEmpty &&
node.attributes[CalloutBlockKeys.icon] is String &&
node.attributes[CalloutBlockKeys.backgroundColor] is String;
node.attributes[CalloutBlockKeys.icon] is String;
}
// the main widget for rendering the callout block
@@ -117,7 +116,8 @@ class _CalloutBlockComponentWidgetState
DefaultSelectableMixin,
BlockComponentConfigurable,
BlockComponentTextDirectionMixin,
BlockComponentAlignMixin {
BlockComponentAlignMixin,
BlockComponentBackgroundColorMixin {
// the key used to forward focus to the richtext child
@override
final forwardKey = GlobalKey(debugLabel: 'flowy_rich_text');
@@ -137,11 +137,13 @@ class _CalloutBlockComponentWidgetState
@override
Node get node => widget.node;
// get the background color of the note block from the node's attributes
@override
Color get backgroundColor {
final colorString =
node.attributes[CalloutBlockKeys.backgroundColor] as String;
return colorString.tryToColor() ?? Colors.transparent;
final color = super.backgroundColor;
if (color == Colors.transparent) {
return AFThemeExtension.of(context).calloutBGColor;
}
return color;
}
// get the emoji of the note block from the node's attributes or default to '📌'
@@ -4,6 +4,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/base/strin
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart' hide TextDirection;
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:highlight/highlight.dart' as highlight;
@@ -190,7 +191,7 @@ class _CodeBlockComponentWidgetState extends State<CodeBlockComponentWidget>
Widget child = Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
color: Colors.grey.withOpacity(0.1),
color: AFThemeExtension.of(context).calloutBGColor,
),
width: MediaQuery.of(context).size.width,
child: Column(
@@ -1,4 +0,0 @@
export 'src/config.dart';
export 'src/emoji_picker.dart';
export 'src/emoji_picker_builder.dart';
export 'src/models/emoji_model.dart';
@@ -1,165 +0,0 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'models/category_models.dart';
import 'emoji_picker.dart';
/// Config for customizations
class Config {
/// Constructor
const Config({
this.columns = 7,
this.emojiSizeMax = 32.0,
this.verticalSpacing = 0,
this.horizontalSpacing = 0,
this.initCategory = Category.RECENT,
this.bgColor = const Color(0xFFEBEFF2),
this.indicatorColor = Colors.blue,
this.iconColor = Colors.grey,
this.iconColorSelected = Colors.blue,
this.progressIndicatorColor = Colors.blue,
this.backspaceColor = Colors.blue,
this.showRecentsTab = true,
this.recentsLimit = 28,
this.noRecentsText = 'No Recents',
this.noRecentsStyle = const TextStyle(fontSize: 20, color: Colors.black26),
this.tabIndicatorAnimDuration = kTabScrollDuration,
this.categoryIcons = const CategoryIcons(),
this.buttonMode = ButtonMode.MATERIAL,
});
/// Number of emojis per row
final int columns;
/// Width and height the emoji will be maximal displayed
/// Can be smaller due to screen size and amount of columns
final double emojiSizeMax;
/// Vertical spacing between emojis
final double verticalSpacing;
/// Horizontal spacing between emojis
final double horizontalSpacing;
/// The initial [Category] that will be selected
/// This [Category] will have its button in the bottombar darkened
final Category initCategory;
/// The background color of the Widget
final Color bgColor;
/// The color of the category indicator
final Color indicatorColor;
/// The color of the category icons
final Color iconColor;
/// The color of the category icon when selected
final Color iconColorSelected;
/// The color of the loading indicator during initialization
final Color progressIndicatorColor;
/// The color of the backspace icon button
final Color backspaceColor;
/// Show extra tab with recently used emoji
final bool showRecentsTab;
/// Limit of recently used emoji that will be saved
final int recentsLimit;
/// The text to be displayed if no recent emojis to display
final String noRecentsText;
/// The text style for [noRecentsText]
final TextStyle noRecentsStyle;
/// Duration of tab indicator to animate to next category
final Duration tabIndicatorAnimDuration;
/// Determines the icon to display for each [Category]
final CategoryIcons categoryIcons;
/// Change between Material and Cupertino button style
final ButtonMode buttonMode;
/// Get Emoji size based on properties and screen width
double getEmojiSize(double width) {
final maxSize = width / columns;
return min(maxSize, emojiSizeMax);
}
/// Returns the icon for the category
IconData getIconForCategory(Category category) {
switch (category) {
case Category.RECENT:
return categoryIcons.recentIcon;
case Category.SMILEYS:
return categoryIcons.smileyIcon;
case Category.ANIMALS:
return categoryIcons.animalIcon;
case Category.FOODS:
return categoryIcons.foodIcon;
case Category.TRAVEL:
return categoryIcons.travelIcon;
case Category.ACTIVITIES:
return categoryIcons.activityIcon;
case Category.OBJECTS:
return categoryIcons.objectIcon;
case Category.SYMBOLS:
return categoryIcons.symbolIcon;
case Category.FLAGS:
return categoryIcons.flagIcon;
case Category.SEARCH:
return categoryIcons.searchIcon;
default:
throw Exception('Unsupported Category');
}
}
@override
bool operator ==(other) {
return (other is Config) &&
other.columns == columns &&
other.emojiSizeMax == emojiSizeMax &&
other.verticalSpacing == verticalSpacing &&
other.horizontalSpacing == horizontalSpacing &&
other.initCategory == initCategory &&
other.bgColor == bgColor &&
other.indicatorColor == indicatorColor &&
other.iconColor == iconColor &&
other.iconColorSelected == iconColorSelected &&
other.progressIndicatorColor == progressIndicatorColor &&
other.backspaceColor == backspaceColor &&
other.showRecentsTab == showRecentsTab &&
other.recentsLimit == recentsLimit &&
other.noRecentsText == noRecentsText &&
other.noRecentsStyle == noRecentsStyle &&
other.tabIndicatorAnimDuration == tabIndicatorAnimDuration &&
other.categoryIcons == categoryIcons &&
other.buttonMode == buttonMode;
}
@override
int get hashCode =>
columns.hashCode ^
emojiSizeMax.hashCode ^
verticalSpacing.hashCode ^
horizontalSpacing.hashCode ^
initCategory.hashCode ^
bgColor.hashCode ^
indicatorColor.hashCode ^
iconColor.hashCode ^
iconColorSelected.hashCode ^
progressIndicatorColor.hashCode ^
backspaceColor.hashCode ^
showRecentsTab.hashCode ^
recentsLimit.hashCode ^
noRecentsText.hashCode ^
noRecentsStyle.hashCode ^
tabIndicatorAnimDuration.hashCode ^
categoryIcons.hashCode ^
buttonMode.hashCode;
}
@@ -0,0 +1,100 @@
import 'dart:convert';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
class ErrorBlockComponentBuilder extends BlockComponentBuilder {
ErrorBlockComponentBuilder({
super.configuration,
});
@override
BlockComponentWidget build(BlockComponentContext blockComponentContext) {
final node = blockComponentContext.node;
return ErrorBlockComponentWidget(
key: node.key,
node: node,
configuration: configuration,
showActions: showActions(node),
actionBuilder: (context, state) => actionBuilder(
blockComponentContext,
state,
),
);
}
@override
bool validate(Node node) => true;
}
class ErrorBlockComponentWidget extends BlockComponentStatefulWidget {
const ErrorBlockComponentWidget({
super.key,
required super.node,
super.showActions,
super.actionBuilder,
super.configuration = const BlockComponentConfiguration(),
});
@override
State<ErrorBlockComponentWidget> createState() =>
_DividerBlockComponentWidgetState();
}
class _DividerBlockComponentWidgetState extends State<ErrorBlockComponentWidget>
with BlockComponentConfigurable {
@override
BlockComponentConfiguration get configuration => widget.configuration;
@override
Node get node => widget.node;
@override
Widget build(BuildContext context) {
Widget child = DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant,
borderRadius: BorderRadius.circular(4),
),
child: FlowyButton(
onTap: () async {
showSnackBarMessage(
context,
LocaleKeys.document_errorBlock_blockContentHasBeenCopied.tr(),
);
await getIt<ClipboardService>().setData(
ClipboardServiceData(plainText: jsonEncode(node.toJson())),
);
},
text: Container(
height: 48,
alignment: Alignment.center,
child: FlowyText(
LocaleKeys.document_errorBlock_theBlockIsNotSupported.tr(),
),
),
),
);
child = Padding(
padding: padding,
child: child,
);
if (widget.showActions && widget.actionBuilder != null) {
child = BlockComponentActionWrapper(
node: node,
actionBuilder: widget.actionBuilder!,
child: child,
);
}
return child;
}
}
@@ -0,0 +1,331 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart' hide WidgetBuilder;
import 'package:flowy_infra_ui/style_widget/text_input.dart';
import 'package:flutter/material.dart';
class FindAndReplaceMenuWidget extends StatefulWidget {
const FindAndReplaceMenuWidget({
super.key,
required this.onDismiss,
required this.editorState,
});
final EditorState editorState;
final VoidCallback onDismiss;
@override
State<FindAndReplaceMenuWidget> createState() =>
_FindAndReplaceMenuWidgetState();
}
class _FindAndReplaceMenuWidgetState extends State<FindAndReplaceMenuWidget> {
bool showReplaceMenu = false;
late SearchServiceV3 searchService = SearchServiceV3(
editorState: widget.editorState,
);
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: FindMenu(
onDismiss: widget.onDismiss,
editorState: widget.editorState,
searchService: searchService,
onShowReplace: (value) => setState(
() => showReplaceMenu = value,
),
),
),
showReplaceMenu
? Padding(
padding: const EdgeInsets.only(
bottom: 8.0,
),
child: ReplaceMenu(
editorState: widget.editorState,
searchService: searchService,
),
)
: const SizedBox.shrink(),
],
);
}
}
class FindMenu extends StatefulWidget {
const FindMenu({
super.key,
required this.onDismiss,
required this.editorState,
required this.searchService,
required this.onShowReplace,
});
final EditorState editorState;
final VoidCallback onDismiss;
final SearchServiceV3 searchService;
final void Function(bool value) onShowReplace;
@override
State<FindMenu> createState() => _FindMenuState();
}
class _FindMenuState extends State<FindMenu> {
late final FocusNode findTextFieldFocusNode;
final findTextEditingController = TextEditingController();
String queriedPattern = '';
bool showReplaceMenu = false;
bool caseSensitive = false;
@override
void initState() {
super.initState();
widget.searchService.matchWrappers.addListener(_setState);
widget.searchService.currentSelectedIndex.addListener(_setState);
findTextEditingController.addListener(_searchPattern);
WidgetsBinding.instance.addPostFrameCallback((_) {
findTextFieldFocusNode.requestFocus();
});
}
@override
void dispose() {
widget.searchService.matchWrappers.removeListener(_setState);
widget.searchService.currentSelectedIndex.removeListener(_setState);
widget.searchService.dispose();
findTextEditingController.removeListener(_searchPattern);
super.dispose();
}
@override
Widget build(BuildContext context) {
// the selectedIndex from searchService is 0-based
final selectedIndex = widget.searchService.selectedIndex + 1;
final matches = widget.searchService.matchWrappers.value;
return Row(
children: [
const HSpace(4.0),
// expand/collapse button
_FindAndReplaceIcon(
icon: showReplaceMenu
? FlowySvgs.drop_menu_show_s
: FlowySvgs.drop_menu_hide_s,
tooltipText: '',
onPressed: () {
widget.onShowReplace(!showReplaceMenu);
setState(
() => showReplaceMenu = !showReplaceMenu,
);
},
),
const HSpace(4.0),
// find text input
SizedBox(
width: 150,
height: 30,
child: FlowyFormTextInput(
onFocusCreated: (focusNode) {
findTextFieldFocusNode = focusNode;
},
onEditingComplete: () {
widget.searchService.navigateToMatch();
// after update selection or navigate to match, the editor
// will request focus, here's a workaround to request the
// focus back to the findTextField
Future.delayed(const Duration(milliseconds: 50), () {
FocusScope.of(context).requestFocus(
findTextFieldFocusNode,
);
});
},
controller: findTextEditingController,
hintText: LocaleKeys.findAndReplace_find.tr(),
textAlign: TextAlign.left,
),
),
// the count of matches
Container(
constraints: const BoxConstraints(minWidth: 80),
padding: const EdgeInsets.symmetric(horizontal: 8.0),
alignment: Alignment.centerLeft,
child: FlowyText(
matches.isEmpty
? LocaleKeys.findAndReplace_noResult.tr()
: '$selectedIndex of ${matches.length}',
),
),
const HSpace(4.0),
// case sensitive button
_FindAndReplaceIcon(
icon: FlowySvgs.text_s,
tooltipText: LocaleKeys.findAndReplace_caseSensitive.tr(),
onPressed: () => setState(() {
caseSensitive = !caseSensitive;
widget.searchService.caseSensitive = caseSensitive;
}),
isSelected: caseSensitive,
),
const HSpace(4.0),
// previous match button
_FindAndReplaceIcon(
onPressed: () => widget.searchService.navigateToMatch(moveUp: true),
icon: FlowySvgs.arrow_up_s,
tooltipText: LocaleKeys.findAndReplace_previousMatch.tr(),
),
const HSpace(4.0),
// next match button
_FindAndReplaceIcon(
onPressed: () => widget.searchService.navigateToMatch(),
icon: FlowySvgs.arrow_down_s,
tooltipText: LocaleKeys.findAndReplace_nextMatch.tr(),
),
const HSpace(4.0),
_FindAndReplaceIcon(
onPressed: widget.onDismiss,
icon: FlowySvgs.close_s,
tooltipText: LocaleKeys.findAndReplace_close.tr(),
),
const HSpace(4.0),
],
);
}
void _searchPattern() {
if (findTextEditingController.text.isEmpty) {
return;
}
widget.searchService.findAndHighlight(findTextEditingController.text);
setState(() => queriedPattern = findTextEditingController.text);
}
void _setState() {
setState(() {});
}
}
class ReplaceMenu extends StatefulWidget {
const ReplaceMenu({
super.key,
required this.editorState,
required this.searchService,
this.localizations,
});
final EditorState editorState;
/// The localizations of the find and replace menu
final FindReplaceLocalizations? localizations;
final SearchServiceV3 searchService;
@override
State<ReplaceMenu> createState() => _ReplaceMenuState();
}
class _ReplaceMenuState extends State<ReplaceMenu> {
late final FocusNode replaceTextFieldFocusNode;
final replaceTextEditingController = TextEditingController();
@override
Widget build(BuildContext context) {
return Row(
children: [
// placeholder for aligning the replace menu
const HSpace(30),
SizedBox(
width: 150,
height: 30,
child: FlowyFormTextInput(
onFocusCreated: (focusNode) {
replaceTextFieldFocusNode = focusNode;
},
onEditingComplete: () {
widget.searchService.navigateToMatch();
// after update selection or navigate to match, the editor
// will request focus, here's a workaround to request the
// focus back to the findTextField
Future.delayed(const Duration(milliseconds: 50), () {
FocusScope.of(context).requestFocus(
replaceTextFieldFocusNode,
);
});
},
controller: replaceTextEditingController,
hintText: LocaleKeys.findAndReplace_replace.tr(),
textAlign: TextAlign.left,
),
),
const HSpace(4.0),
_FindAndReplaceIcon(
onPressed: _replaceSelectedWord,
iconBuilder: (_) => const Icon(
Icons.find_replace_outlined,
size: 16,
),
tooltipText: LocaleKeys.findAndReplace_replace.tr(),
),
const HSpace(4.0),
_FindAndReplaceIcon(
iconBuilder: (_) => const Icon(
Icons.change_circle_outlined,
size: 16,
),
tooltipText: LocaleKeys.findAndReplace_replaceAll.tr(),
onPressed: () => widget.searchService.replaceAllMatches(
replaceTextEditingController.text,
),
),
],
);
}
void _replaceSelectedWord() {
widget.searchService.replaceSelectedWord(replaceTextEditingController.text);
}
}
class _FindAndReplaceIcon extends StatelessWidget {
const _FindAndReplaceIcon({
required this.onPressed,
required this.tooltipText,
this.icon,
this.iconBuilder,
this.isSelected,
});
final VoidCallback onPressed;
final FlowySvgData? icon;
final WidgetBuilder? iconBuilder;
final String tooltipText;
final bool? isSelected;
@override
Widget build(BuildContext context) {
return FlowyIconButton(
width: 24,
height: 24,
onPressed: onPressed,
icon: iconBuilder?.call(context) ??
(icon != null ? FlowySvg(icon!) : const Placeholder()),
tooltipText: tooltipText,
isSelected: isSelected,
iconColorOnHover: Theme.of(context).colorScheme.onSecondary,
);
}
}
@@ -9,7 +9,7 @@ final customizeFontToolbarItem = ToolbarItem(
id: 'editor.font',
group: 4,
isActive: onlyShowInTextType,
builder: (context, editorState, highlightColor) {
builder: (context, editorState, highlightColor, _) {
final selection = editorState.selection!;
final popoverController = PopoverController();
return MouseRegion(
@@ -18,11 +18,11 @@ final customizeFontToolbarItem = ToolbarItem(
currentFontFamily: '',
offset: const Offset(0, 12),
popoverController: popoverController,
onOpen: () => keepEditorFocusNotifier.value += 1,
onClose: () => keepEditorFocusNotifier.value -= 1,
onOpen: () => keepEditorFocusNotifier.increase(),
onClose: () => keepEditorFocusNotifier.decrease(),
showResetButton: true,
onFontFamilyChanged: (fontFamily) async {
await popoverController.close();
popoverController.close();
try {
await editorState.formatDelta(selection, {
AppFlowyRichTextKeys.fontFamily: fontFamily,
@@ -180,7 +180,7 @@ class _ChangeCoverPopoverState extends State<ChangeCoverPopover> {
builtInAssetImages[index],
);
},
child: Container(
child: DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(builtInAssetImages[index]),
@@ -299,7 +299,7 @@ class NewCustomCoverButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
return DecoratedBox(
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.primary,
@@ -484,14 +484,9 @@ class _ImageGridItemState extends State<ImageGridItem> {
children: [
InkWell(
onTap: widget.onImageSelect,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: FileImage(File(widget.imagePath)),
fit: BoxFit.cover,
),
borderRadius: Corners.s8Border,
),
child: ClipRRect(
borderRadius: Corners.s8Border,
child: Image.file(File(widget.imagePath), fit: BoxFit.cover),
),
),
if (showDeleteButton)
@@ -544,7 +539,7 @@ class ColorItem extends StatelessWidget {
padding: const EdgeInsets.only(right: 10.0),
child: SizedBox.square(
dimension: 25,
child: Container(
child: DecoratedBox(
decoration: BoxDecoration(
color: option.colorHex.tryToColor(),
shape: BoxShape.circle,
@@ -201,7 +201,7 @@ class CoverImagePreviewWidget extends StatefulWidget {
class _CoverImagePreviewWidgetState extends State<CoverImagePreviewWidget> {
_buildFilePickerWidget(BuildContext ctx) {
return Container(
return DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: Corners.s6Border,
@@ -263,7 +263,7 @@ class _CoverImagePreviewWidgetState extends State<CoverImagePreviewWidget> {
onTap: () {
ctx.read<CoverImagePickerBloc>().add(const DeleteImage());
},
child: Container(
child: DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.onPrimary,
@@ -2,7 +2,7 @@ import 'dart:io';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/presentation/widgets/emoji_picker/emoji_picker.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_picker.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -257,7 +257,7 @@ class _DocumentHeaderToolbarState extends State<DocumentHeaderToolbar> {
controller: _popoverController,
offset: const Offset(0, 8),
direction: PopoverDirection.bottomWithCenterAligned,
constraints: BoxConstraints.loose(const Size(320, 380)),
constraints: BoxConstraints.loose(const Size(300, 250)),
child: FlowyButton(
leftIconSize: const Size.square(18),
useIntrinsicWidth: true,
@@ -324,6 +324,7 @@ class DocumentCover extends StatefulWidget {
class DocumentCoverState extends State<DocumentCover> {
bool isOverlayButtonsHidden = true;
bool isPopoverOpen = false;
final PopoverController popoverController = PopoverController();
@override
Widget build(BuildContext context) {
@@ -382,12 +383,15 @@ class DocumentCoverState extends State<DocumentCover> {
mainAxisSize: MainAxisSize.min,
children: [
AppFlowyPopover(
controller: popoverController,
triggerActions: PopoverTriggerFlags.none,
offset: const Offset(0, 8),
direction: PopoverDirection.bottomWithCenterAligned,
constraints: BoxConstraints.loose(const Size(380, 450)),
margin: EdgeInsets.zero,
onClose: () => isPopoverOpen = false,
child: RoundedTextButton(
onPressed: () => popoverController.show(),
hoverColor: Theme.of(context).colorScheme.surface,
textColor: Theme.of(context).colorScheme.tertiary,
fillColor: Theme.of(context).colorScheme.surface.withOpacity(0.5),
@@ -1,6 +1,6 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/presentation/widgets/emoji_picker/emoji_picker.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_picker.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/button.dart';
@@ -8,6 +8,7 @@ import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter/material.dart';
/// Add icon menu in Header
class EmojiPopover extends StatefulWidget {
final EditorState editorState;
final Node node;
@@ -46,17 +47,7 @@ class _EmojiPopoverState extends State<EmojiPopover> {
onEmojiSelected: (category, emoji) {
widget.onEmojiChanged(emoji);
},
config: Config(
columns: 8,
emojiSizeMax: 28,
bgColor: Colors.transparent,
iconColor: Theme.of(context).iconTheme.color!,
iconColorSelected: Theme.of(context).colorScheme.onSurface,
selectedHoverColor: Theme.of(context).colorScheme.secondary,
progressIndicatorColor: Theme.of(context).iconTheme.color!,
buttonMode: ButtonMode.CUPERTINO,
initCategory: Category.RECENT,
),
config: buildFlowyEmojiPickerConfig(context),
),
),
],
@@ -0,0 +1,249 @@
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_placeholder.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
const kImagePlaceholderKey = 'imagePlaceholderKey';
typedef CustomImageBlockComponentMenuBuilder = Widget Function(
Node node,
CustomImageBlockComponentState state,
);
class CustomImageBlockComponentBuilder extends BlockComponentBuilder {
CustomImageBlockComponentBuilder({
super.configuration,
this.showMenu = false,
this.menuBuilder,
});
/// Whether to show the menu of this block component.
final bool showMenu;
///
final CustomImageBlockComponentMenuBuilder? menuBuilder;
@override
BlockComponentWidget build(BlockComponentContext blockComponentContext) {
final node = blockComponentContext.node;
return CustomImageBlockComponent(
key: node.key,
node: node,
showActions: showActions(node),
configuration: configuration,
actionBuilder: (context, state) => actionBuilder(
blockComponentContext,
state,
),
showMenu: showMenu,
menuBuilder: menuBuilder,
);
}
@override
bool validate(Node node) => node.delta == null && node.children.isEmpty;
}
class CustomImageBlockComponent extends BlockComponentStatefulWidget {
const CustomImageBlockComponent({
super.key,
required super.node,
super.showActions,
super.actionBuilder,
super.configuration = const BlockComponentConfiguration(),
this.showMenu = false,
this.menuBuilder,
});
/// Whether to show the menu of this block component.
final bool showMenu;
final CustomImageBlockComponentMenuBuilder? menuBuilder;
@override
State<CustomImageBlockComponent> createState() =>
CustomImageBlockComponentState();
}
class CustomImageBlockComponentState extends State<CustomImageBlockComponent>
with SelectableMixin, BlockComponentConfigurable {
@override
BlockComponentConfiguration get configuration => widget.configuration;
@override
Node get node => widget.node;
final imageKey = GlobalKey();
RenderBox? get _renderBox => context.findRenderObject() as RenderBox?;
late final editorState = Provider.of<EditorState>(context, listen: false);
final showActionsNotifier = ValueNotifier<bool>(false);
bool alwaysShowMenu = false;
@override
Widget build(BuildContext context) {
final node = widget.node;
final attributes = node.attributes;
final src = attributes[ImageBlockKeys.url];
final alignment = AlignmentExtension.fromString(
attributes[ImageBlockKeys.align] ?? 'center',
);
final width = attributes[ImageBlockKeys.width]?.toDouble() ??
MediaQuery.of(context).size.width;
final height = attributes[ImageBlockKeys.height]?.toDouble();
final imagePlaceholderKey = node.extraInfos?[kImagePlaceholderKey];
Widget child = src.isEmpty
? ImagePlaceholder(
key: imagePlaceholderKey is GlobalKey ? imagePlaceholderKey : null,
node: node,
)
: ResizableImage(
src: src,
width: width,
height: height,
editable: editorState.editable,
alignment: alignment,
onResize: (width) {
final transaction = editorState.transaction
..updateNode(node, {
ImageBlockKeys.width: width,
});
editorState.apply(transaction);
},
);
child = BlockSelectionContainer(
node: node,
delegate: this,
listenable: editorState.selectionNotifier,
blockColor: editorState.editorStyle.selectionColor,
supportTypes: const [
BlockSelectionType.block,
],
child: Padding(
key: imageKey,
padding: padding,
child: child,
),
);
if (widget.showActions && widget.actionBuilder != null) {
child = BlockComponentActionWrapper(
node: node,
actionBuilder: widget.actionBuilder!,
child: child,
);
}
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) {
final url = node.attributes[ImageBlockKeys.url];
return Stack(
children: [
BlockSelectionContainer(
node: node,
delegate: this,
listenable: editorState.selectionNotifier,
cursorColor: editorState.editorStyle.cursorColor,
selectionColor: editorState.editorStyle.selectionColor,
child: child!,
),
if (value && url.isNotEmpty == true)
widget.menuBuilder!(
widget.node,
this,
),
],
);
},
child: child,
),
);
}
return child;
}
@override
Position start() => Position(path: widget.node.path, offset: 0);
@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 = imageKey.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 = imageKey.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);
}
@@ -0,0 +1,46 @@
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:flutter/material.dart';
class EmbedImageUrlWidget extends StatefulWidget {
const EmbedImageUrlWidget({
super.key,
required this.onSubmit,
});
final void Function(String url) onSubmit;
@override
State<EmbedImageUrlWidget> createState() => _EmbedImageUrlWidgetState();
}
class _EmbedImageUrlWidgetState extends State<EmbedImageUrlWidget> {
String inputText = '';
@override
Widget build(BuildContext context) {
return Column(
children: [
FlowyTextField(
autoFocus: true,
hintText: LocaleKeys.document_imageBlock_embedLink_placeholder.tr(),
onChanged: (value) => inputText = value,
onEditingComplete: () => widget.onSubmit(inputText),
),
const VSpace(5),
SizedBox(
width: 160,
child: FlowyButton(
margin: const EdgeInsets.all(8.0),
text: FlowyText(
LocaleKeys.document_imageBlock_embedLink_label.tr(),
textAlign: TextAlign.center,
),
onTap: () => widget.onSubmit(inputText),
),
),
],
);
}
}
@@ -1,5 +1,7 @@
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/custom_image_block_component.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -17,7 +19,7 @@ class ImageMenu extends StatefulWidget {
});
final Node node;
final ImageBlockComponentWidgetState state;
final CustomImageBlockComponentState state;
@override
State<ImageMenu> createState() => _ImageMenuState();
@@ -65,12 +67,9 @@ class _ImageMenuState extends State<ImageMenu> {
final url = widget.node.attributes[ImageBlockKeys.url];
if (url != null) {
Clipboard.setData(ClipboardData(text: url));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: FlowyText(
LocaleKeys.document_plugins_image_copiedToPasteBoard.tr(),
),
),
showSnackBarMessage(
context,
LocaleKeys.document_plugins_image_copiedToPasteBoard.tr(),
);
}
}
@@ -111,7 +110,7 @@ class _ImageAlignButton extends StatefulWidget {
});
final Node node;
final ImageBlockComponentWidgetState state;
final CustomImageBlockComponentState state;
@override
State<_ImageAlignButton> createState() => _ImageAlignButtonState();
@@ -0,0 +1,191 @@
import 'dart:io';
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/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: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:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:http/http.dart';
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,
});
final Node node;
@override
State<ImagePlaceholder> createState() => ImagePlaceholderState();
}
class ImagePlaceholderState extends State<ImagePlaceholder> {
final controller = PopoverController();
late final editorState = context.read<EditorState>();
@override
Widget build(BuildContext context) {
return AppFlowyPopover(
controller: controller,
direction: PopoverDirection.bottomWithCenterAligned,
constraints: const BoxConstraints(
maxWidth: 540,
maxHeight: 360,
minHeight: 80,
),
clickHandler: PopoverClickHandler.gestureDetector,
popupBuilder: (context) {
return UploadImageMenu(
onSelectedLocalImage: (path) {
controller.close();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await insertLocalImage(path);
});
},
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: DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant,
borderRadius: BorderRadius.circular(4),
),
child: FlowyHover(
style: HoverStyle(
borderRadius: BorderRadius.circular(4),
),
child: SizedBox(
height: 48,
child: Row(
children: [
const HSpace(10),
const FlowySvg(
FlowySvgs.image_placeholder_s,
size: Size.square(24),
),
const HSpace(10),
FlowyText(
LocaleKeys.document_plugins_image_addAnImage.tr(),
),
],
),
),
),
),
);
}
Future<void> insertLocalImage(String? url) async {
if (url == null || url.isEmpty) {
controller.close();
return;
}
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 copyToPath = p.join(
imagePath,
'${uuid()}${p.extension(url)}',
);
await File(url).copy(
copyToPath,
);
final transaction = editorState.transaction;
transaction.updateNode(widget.node, {
ImageBlockKeys.url: copyToPath,
});
await editorState.apply(transaction);
} catch (e) {
Log.error('cannot copy image file', e);
}
}
Future<void> insertAIImage(String url) async {
if (url.isEmpty || !isURL(url)) {
// show error
showSnackBarMessage(
context,
LocaleKeys.document_imageBlock_error_invalidImage.tr(),
);
return;
}
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);
final transaction = editorState.transaction;
transaction.updateNode(widget.node, {
ImageBlockKeys.url: copyToPath,
});
await editorState.apply(transaction);
} catch (e) {
Log.error('cannot save image file', e);
}
}
Future<void> insertNetworkImage(String url) async {
if (url.isEmpty || !isURL(url)) {
// show error
showSnackBarMessage(
context,
LocaleKeys.document_imageBlock_error_invalidImage.tr(),
);
return;
}
final transaction = editorState.transaction;
transaction.updateNode(widget.node, {
ImageBlockKeys.url: url,
});
await editorState.apply(transaction);
}
}
@@ -1,12 +1,7 @@
import 'dart:io';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/settings/application_data_storage.dart';
import 'package:appflowy_backend/log.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_editor/appflowy_editor.dart' hide Log;
import 'package:flowy_infra/uuid.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
final customImageMenuItem = SelectionMenuItem(
name: AppFlowyEditorLocalizations.current.image,
@@ -16,44 +11,55 @@ final customImageMenuItem = SelectionMenuItem(
style: style,
),
keywords: ['image', 'picture', 'img', 'photo'],
handler: (editorState, menuService, context) {
final container = Overlay.of(context);
showImageMenu(
container,
editorState,
menuService,
onInsertImage: (url) async {
// if the url is http, we can insert it directly
// otherwise, if it's a file url, we need to copy the file to the app's document directory
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);
final regex = RegExp('^(http|https)://');
if (regex.hasMatch(url)) {
await editorState.insertImageNode(url);
} else {
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 copyToPath = p.join(
imagePath,
'${uuid()}${p.extension(url)}',
);
await File(url).copy(
copyToPath,
);
await editorState.insertImageNode(copyToPath);
} catch (e) {
Log.error('cannot copy image file', e);
}
}
},
);
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
imagePlaceholderKey.currentState?.controller.show();
});
},
);
extension InsertImage on EditorState {
Future<void> insertEmptyImageBlock(GlobalKey key) async {
final selection = this.selection;
if (selection == null || !selection.isCollapsed) {
return;
}
final node = getNodeAtPath(selection.end.path);
if (node == null) {
return;
}
final emptyImage = imageNode(url: '')
..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,
)
..deleteNode(node);
} else {
transaction.insertNode(
node.path.next,
emptyImage,
);
}
transaction.afterSelection = Selection.collapsed(
Position(
path: node.path.next,
offset: 0,
),
);
return apply(transaction);
}
}
@@ -0,0 +1,105 @@
import 'dart:async';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/error.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/openai_client.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:dartz/dartz.dart' hide State;
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
class OpenAIImageWidget extends StatefulWidget {
const OpenAIImageWidget({
super.key,
required this.onSelectNetworkImage,
});
final void Function(String url) onSelectNetworkImage;
@override
State<OpenAIImageWidget> createState() => _OpenAIImageWidgetState();
}
class _OpenAIImageWidgetState extends State<OpenAIImageWidget> {
Future<Either<OpenAIError, List<String>>>? future;
String query = '';
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: FlowyTextField(
autoFocus: true,
hintText: LocaleKeys.document_imageBlock_ai_placeholder.tr(),
onChanged: (value) => query = value,
onEditingComplete: _search,
),
),
const HSpace(4.0),
FlowyButton(
useIntrinsicWidth: true,
text: FlowyText(
LocaleKeys.search_label.tr(),
),
onTap: _search,
),
],
),
const VSpace(12.0),
if (future != null)
Expanded(
child: FutureBuilder(
future: future,
builder: (context, value) {
final data = value.data;
if (!value.hasData ||
value.connectionState != ConnectionState.done ||
data == null) {
return const CircularProgressIndicator.adaptive();
}
return data.fold(
(l) => Center(
child: FlowyText(
l.message,
maxLines: 3,
textAlign: TextAlign.center,
),
),
(r) => GridView.count(
crossAxisCount: 3,
mainAxisSpacing: 16.0,
crossAxisSpacing: 10.0,
childAspectRatio: 4 / 3,
children: r
.map(
(e) => GestureDetector(
onTap: () => widget.onSelectNetworkImage(e),
child: Image.network(e),
),
)
.toList(),
),
);
},
),
)
],
);
}
void _search() async {
final openAI = await getIt.getAsync<OpenAIRepository>();
setState(() {
future = openAI.generateImage(
prompt: query,
n: 6,
);
});
}
}
@@ -0,0 +1,121 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/stability_ai/stability_ai_client.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/stability_ai/stability_ai_error.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:dartz/dartz.dart' hide State;
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/uuid.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
class StabilityAIImageWidget extends StatefulWidget {
const StabilityAIImageWidget({
super.key,
required this.onSelectImage,
});
final void Function(String url) onSelectImage;
@override
State<StabilityAIImageWidget> createState() => _StabilityAIImageWidgetState();
}
class _StabilityAIImageWidgetState extends State<StabilityAIImageWidget> {
Future<Either<StabilityAIRequestError, List<String>>>? future;
String query = '';
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: FlowyTextField(
autoFocus: true,
hintText: LocaleKeys
.document_imageBlock_stability_ai_placeholder
.tr(),
onChanged: (value) => query = value,
onEditingComplete: _search,
),
),
const HSpace(4.0),
FlowyButton(
useIntrinsicWidth: true,
text: FlowyText(
LocaleKeys.search_label.tr(),
),
onTap: _search,
),
],
),
const VSpace(12.0),
if (future != null)
Expanded(
child: FutureBuilder(
future: future,
builder: (context, value) {
final data = value.data;
if (!value.hasData ||
value.connectionState != ConnectionState.done ||
data == null) {
return const CircularProgressIndicator.adaptive();
}
return data.fold(
(l) => Center(
child: FlowyText(
l.message,
maxLines: 3,
textAlign: TextAlign.center,
),
),
(r) => GridView.count(
crossAxisCount: 3,
mainAxisSpacing: 16.0,
crossAxisSpacing: 10.0,
childAspectRatio: 4 / 3,
children: r.map(
(e) {
final base64Image = base64Decode(e);
return GestureDetector(
onTap: () async {
final tempDirectory = await getTemporaryDirectory();
final path = p.join(
tempDirectory.path,
'${uuid()}.png',
);
File(path).writeAsBytesSync(base64Image);
widget.onSelectImage(path);
},
child: Image.memory(base64Image),
);
},
).toList(),
),
);
},
),
)
],
);
}
void _search() async {
final stabilityAI = await getIt.getAsync<StabilityAIRepository>();
setState(() {
future = stabilityAI.generateImage(
prompt: query,
n: 6,
);
});
}
}
@@ -0,0 +1,173 @@
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:flutter/material.dart';
import 'package:unsplash_client/unsplash_client.dart';
class UnsplashImageWidget extends StatefulWidget {
const UnsplashImageWidget({
super.key,
required this.onSelectUnsplashImage,
});
final void Function(String url) onSelectUnsplashImage;
@override
State<UnsplashImageWidget> createState() => _UnsplashImageWidgetState();
}
class _UnsplashImageWidgetState extends State<UnsplashImageWidget> {
final client = UnsplashClient(
settings: const ClientSettings(
credentials: AppCredentials(
// TODO: there're the demo keys, we should replace them with the production keys when releasing and inject them with env file.
accessKey: 'YyD-LbW5bVolHWZBq5fWRM_3ezkG2XchRFjhNTnK9TE',
secretKey: '5z4EnxaXjWjWMnuBhc0Ku0uYW2bsYCZlO-REZaqmV6A',
),
),
);
late Future<List<Photo>> randomPhotos;
String query = '';
@override
void initState() {
super.initState();
randomPhotos = client.photos
.random(count: 18, orientation: PhotoOrientation.landscape)
.goAndGet();
}
@override
void dispose() {
client.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: FlowyTextField(
autoFocus: true,
hintText: LocaleKeys.document_imageBlock_searchForAnImage.tr(),
onChanged: (value) => query = value,
onEditingComplete: _search,
),
),
const HSpace(4.0),
FlowyButton(
useIntrinsicWidth: true,
text: FlowyText(
LocaleKeys.search_label.tr(),
),
onTap: _search,
),
],
),
const VSpace(12.0),
Expanded(
child: FutureBuilder(
future: randomPhotos,
builder: (context, value) {
final data = value.data;
if (!value.hasData ||
value.connectionState != ConnectionState.done ||
data == null ||
data.isEmpty) {
return const CircularProgressIndicator.adaptive();
}
return GridView.count(
crossAxisCount: 3,
mainAxisSpacing: 16.0,
crossAxisSpacing: 10.0,
childAspectRatio: 4 / 3,
children: data
.map(
(photo) => _UnsplashImage(
photo: photo,
onTap: () => widget.onSelectUnsplashImage(
photo.urls.regular.toString(),
),
),
)
.toList(),
);
},
),
),
],
);
}
void _search() {
setState(() {
randomPhotos = client.photos
.random(
count: 18,
orientation: PhotoOrientation.landscape,
query: query,
)
.goAndGet();
});
}
}
class _UnsplashImage extends StatelessWidget {
const _UnsplashImage({
required this.photo,
required this.onTap,
});
final Photo photo;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Image.network(
photo.urls.thumb.toString(),
fit: BoxFit.cover,
),
),
const HSpace(2.0),
FlowyText(
'by ${photo.name}',
fontSize: 10.0,
),
],
),
);
}
}
extension on Photo {
String get name {
if (user.username.isNotEmpty) {
return user.username;
}
if (user.name.isNotEmpty) {
return user.name;
}
if (user.email?.isNotEmpty == true) {
return user.email!;
}
return user.id;
}
}
Loaded 100 of 530 files, more files were not shown because too many files have changed in this diff. Show more