diff --git a/.github/workflows/flowy_editor_test.yml b/.github/workflows/flowy_editor_test.yml index 892ca9899d..1bff599ace 100644 --- a/.github/workflows/flowy_editor_test.yml +++ b/.github/workflows/flowy_editor_test.yml @@ -30,7 +30,7 @@ jobs: cache: true - name: Run FlowyEditor tests - working-directory: frontend/app_flowy/packages/flowy_editor + working-directory: frontend/app_flowy/packages/appflowy_editor run: | flutter pub get flutter test diff --git a/frontend/app_flowy/analysis_options.yaml b/frontend/app_flowy/analysis_options.yaml index 5717d49105..e345c3da76 100644 --- a/frontend/app_flowy/analysis_options.yaml +++ b/frontend/app_flowy/analysis_options.yaml @@ -14,7 +14,7 @@ analyzer: exclude: - "**/*.g.dart" - "**/*.freezed.dart" - - "packages/flowy_editor/**" + - "packages/appflowy_editor/**" - "packages/editor/**" # - "packages/flowy_infra_ui/**" linter: diff --git a/frontend/app_flowy/linux/flutter/generated_plugin_registrant.cc b/frontend/app_flowy/linux/flutter/generated_plugin_registrant.cc index 9fdfa38294..ae6ec7ed89 100644 --- a/frontend/app_flowy/linux/flutter/generated_plugin_registrant.cc +++ b/frontend/app_flowy/linux/flutter/generated_plugin_registrant.cc @@ -7,6 +7,7 @@ #include "generated_plugin_registrant.h" #include +#include #include #include @@ -14,6 +15,9 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) flowy_infra_ui_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FlowyInfraUIPlugin"); flowy_infra_u_i_plugin_register_with_registrar(flowy_infra_ui_registrar); + g_autoptr(FlPluginRegistrar) rich_clipboard_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "RichClipboardPlugin"); + rich_clipboard_plugin_register_with_registrar(rich_clipboard_linux_registrar); g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); diff --git a/frontend/app_flowy/linux/flutter/generated_plugins.cmake b/frontend/app_flowy/linux/flutter/generated_plugins.cmake index c7ae414da2..3e0d068b6a 100644 --- a/frontend/app_flowy/linux/flutter/generated_plugins.cmake +++ b/frontend/app_flowy/linux/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST flowy_infra_ui + rich_clipboard_linux url_launcher_linux window_size ) diff --git a/frontend/app_flowy/macos/Flutter/GeneratedPluginRegistrant.swift b/frontend/app_flowy/macos/Flutter/GeneratedPluginRegistrant.swift index 8d97942332..60d2b8c792 100644 --- a/frontend/app_flowy/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/frontend/app_flowy/macos/Flutter/GeneratedPluginRegistrant.swift @@ -11,6 +11,7 @@ import flowy_infra_ui import flowy_sdk import package_info_plus_macos import path_provider_macos +import rich_clipboard_macos import shared_preferences_macos import url_launcher_macos import window_size @@ -22,6 +23,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FlowySdkPlugin.register(with: registry.registrar(forPlugin: "FlowySdkPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + RichClipboardPlugin.register(with: registry.registrar(forPlugin: "RichClipboardPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) WindowSizePlugin.register(with: registry.registrar(forPlugin: "WindowSizePlugin")) diff --git a/frontend/app_flowy/packages/flowy_editor/.gitignore b/frontend/app_flowy/packages/appflowy_editor/.gitignore similarity index 96% rename from frontend/app_flowy/packages/flowy_editor/.gitignore rename to frontend/app_flowy/packages/appflowy_editor/.gitignore index 96486fd930..7501b909b4 100644 --- a/frontend/app_flowy/packages/flowy_editor/.gitignore +++ b/frontend/app_flowy/packages/appflowy_editor/.gitignore @@ -19,7 +19,7 @@ migrate_working_dir/ # The .vscode folder contains launch configuration and tasks you configure in # VS Code which you may wish to be included in version control, so this line # is commented out by default. -#.vscode/ +.vscode/ # Flutter/Dart/Pub related # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. @@ -28,3 +28,4 @@ migrate_working_dir/ .dart_tool/ .packages build/ +coverage/ diff --git a/frontend/app_flowy/packages/flowy_editor/.metadata b/frontend/app_flowy/packages/appflowy_editor/.metadata similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/.metadata rename to frontend/app_flowy/packages/appflowy_editor/.metadata diff --git a/frontend/app_flowy/packages/appflowy_editor/CHANGELOG.md b/frontend/app_flowy/packages/appflowy_editor/CHANGELOG.md new file mode 100644 index 0000000000..52359537e2 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/CHANGELOG.md @@ -0,0 +1,11 @@ +## 0.0.1 + +* 实现基础的编辑器样式 + * heading + * bold / 斜体 / underline / 删除线 + * checkbox + * bulleted list +* 实现可扩展的编辑器框架 +* IME 的支持 +* 样式的复制粘贴 +* slash 快捷输入 diff --git a/frontend/app_flowy/packages/appflowy_editor/LICENSE b/frontend/app_flowy/packages/appflowy_editor/LICENSE new file mode 100644 index 0000000000..29ebfa545f --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. \ No newline at end of file diff --git a/frontend/app_flowy/packages/appflowy_editor/README.md b/frontend/app_flowy/packages/appflowy_editor/README.md new file mode 100644 index 0000000000..f00ce55bbd --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/README.md @@ -0,0 +1,93 @@ + + +

AppFlowy Editor

+ +

A highly customizable rich-text editor for Flutter

+ + +
+ +
+ +## Key Features + +* Allow you to build rich, intuitive editors +* Design and modify it your way by customizing components, shortcut events, and many more coming soon including menu options and themes +* [Test-covered](https://github.com/LucasXu0/AppFlowy/blob/documentation/appflowy_editor/frontend/app_flowy/packages/appflowy_editor/documentation/testing.md) and maintained by AppFlowy's core team along with a community of more than 1,000 builders + + +## Getting started + +```shell +flutter pub add appflowy_editor +flutter pub get +``` + +## How to use + +Let's create a new AppFlowyEditor object +```dart +final editorState = EditorState.empty(); // an empty state +final editor = AppFlowyEditor( + editorState: editorState, + keyEventHandlers: const [], + customBuilders: const {}, +); +``` + +You can also create an editor from a JSON file +```dart +final json = ...; +final editorState = EditorState(StateTree.fromJson(data)); +final editor = AppFlowyEditor( + editorState: editorState, + keyEventHandlers: const [], + customBuilders: const {}, +); +``` + +To get a sense for how you might use it, run this example: +```shell +git clone https://github.com/AppFlowy-IO/AppFlowy.git +cd frontend/app_flowy/packages/appflowy_editor/example +flutter run +``` + + +## How to customize +### Customize a component +Please refer to [customizing a component](documentation/customizing.md#customizing-a-custom-component) for more details. + + +### Customize a shortcut event +Please refer to [customizing a shortcut event](documentation/customizing.md#customizing-a-custom-shortcut-event) for more details. + +## More Examples +* Customize a component + * [Checkbox Text](https://github.com/LucasXu0/AppFlowy/blob/documentation/appflowy_editor/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/checkbox_text.dart) shows you how to extend new styles based on existing rich text components + * [Image](https://github.com/LucasXu0/AppFlowy/blob/documentation/appflowy_editor/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/image_node_widget.dart) teaches you how to extend a new node and render it + * And more examples on [rich-text plugins](https://github.com/LucasXu0/AppFlowy/tree/documentation/appflowy_editor/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text) +* Customize a shortcut event + * [BIUS](https://github.com/LucasXu0/AppFlowy/blob/documentation/appflowy_editor/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart) shows you how to make text bold/italic/underline/strikethrough through shortcut keys + * [Paste HTML](https://github.com/LucasXu0/AppFlowy/blob/documentation/appflowy_editor/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart) gives you an idea on how to handle pasted styles through shortcut keys + * Need more examples? Check out [Internal key event handlers](https://github.com/LucasXu0/AppFlowy/tree/documentation/appflowy_editor/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers) + +## Glossary +Please refer to the API documentation (link). + +## Contributing +Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated. Please look at [CONTRIBUTING.md](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/contributing-to-appflowy) for details. + +## License +Distributed under the AGPLv3 License. See LICENSE for more information. diff --git a/frontend/app_flowy/packages/flowy_editor/analysis_options.yaml b/frontend/app_flowy/packages/appflowy_editor/analysis_options.yaml similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/analysis_options.yaml rename to frontend/app_flowy/packages/appflowy_editor/analysis_options.yaml diff --git a/frontend/app_flowy/packages/flowy_editor/assets/document.json b/frontend/app_flowy/packages/appflowy_editor/assets/document.json similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/document.json rename to frontend/app_flowy/packages/appflowy_editor/assets/document.json diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/check.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/check.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/check.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/check.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/point.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/point.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/point.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/point.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/bullets.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/bullets.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/bullets.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/bullets.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/checkbox.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/checkbox.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/checkbox.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/checkbox.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/h1.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/h1.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/h1.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/h1.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/h2.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/h2.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/h2.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/h2.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/h3.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/h3.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/h3.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/h3.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/number.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/number.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/number.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/number.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/text.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/text.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/popup_list/text.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/popup_list/text.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/quote.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/quote.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/quote.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/quote.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/bold.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/bold.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/bold.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/bold.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/bulleted_list.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/bulleted_list.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/bulleted_list.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/bulleted_list.svg diff --git a/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/center.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/center.svg new file mode 100644 index 0000000000..ea834a35bd --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/center.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/code.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/code.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/code.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/code.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/divider.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/divider.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/divider.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/divider.svg diff --git a/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/h1.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/h1.svg new file mode 100644 index 0000000000..8a87ece4f0 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/h1.svg @@ -0,0 +1,4 @@ + + + + diff --git a/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/h2.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/h2.svg new file mode 100644 index 0000000000..9ce394b0b1 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/h2.svg @@ -0,0 +1,4 @@ + + + + diff --git a/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/h3.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/h3.svg new file mode 100644 index 0000000000..43af128937 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/h3.svg @@ -0,0 +1,4 @@ + + + + diff --git a/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/highlight.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/highlight.svg new file mode 100644 index 0000000000..697603a054 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/highlight.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/italic.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/italic.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/italic.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/italic.svg diff --git a/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/left.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/left.svg new file mode 100644 index 0000000000..b4f2d0101e --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/left.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/link.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/link.svg new file mode 100644 index 0000000000..612e8377b6 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/link.svg @@ -0,0 +1,4 @@ + + + + diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/number_list.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/number_list.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/number_list.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/number_list.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/quote.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/quote.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/quote.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/quote.svg diff --git a/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/right.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/right.svg new file mode 100644 index 0000000000..86a1facaac --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/right.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/strikethrough.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/strikethrough.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/strikethrough.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/strikethrough.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/underline.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/underline.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/toolbar/underline.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/toolbar/underline.svg diff --git a/frontend/app_flowy/packages/flowy_editor/assets/images/uncheck.svg b/frontend/app_flowy/packages/appflowy_editor/assets/images/uncheck.svg similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/assets/images/uncheck.svg rename to frontend/app_flowy/packages/appflowy_editor/assets/images/uncheck.svg diff --git a/frontend/app_flowy/packages/appflowy_editor/documentation/contributing.md b/frontend/app_flowy/packages/appflowy_editor/documentation/contributing.md new file mode 100644 index 0000000000..edf190eb2b --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/documentation/contributing.md @@ -0,0 +1,17 @@ +# Contributing + +## Reporting Bugs +Please click this [link](https://github.com/AppFlowy-IO/AppFlowy/issues/new?assignees=&labels=bug,editor&template=bug_report.md&title=%5BFlowyEditor%20Bug%5D+Untitled+Bug+Issue) to report bugs. + +![](../documentation/images/reporting_bugs.png) + +## Technical Discussion And Support +Discord link ... + +## Submitting Pull Request + +We welcome and appreciate your pull request submissions, and we have many good-first-issue-for-devs or help-wanted issues that we welcome you to implement. + +As [README](../README.md) said, we want to make sure that the code you submit will not affect the existing code logic and functionality, so please attach the corresponding test for each PR submission, and it is recommended to add a brief description of the test case and scope to the test. For more details, please see [TESTING.md](./testing.md) + +Finally, to repeat, since the AppFlowyEditor is a community-driven open source editor, we take every PR seriously and feel very much for everyone's contribution. diff --git a/frontend/app_flowy/packages/appflowy_editor/documentation/customizing.md b/frontend/app_flowy/packages/appflowy_editor/documentation/customizing.md new file mode 100644 index 0000000000..85fa195c96 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/documentation/customizing.md @@ -0,0 +1,286 @@ +# How to customize ... + +## Customize a shortcut event + +We will use a simple example to illustrate how to quickly add a shortcut event. + +For example, typing `_xxx_` will be converted into _xxx_. + +Let's start with a blank document. + +```dart +@override +Widget build(BuildContext context) { + return Scaffold( + body: Container( + alignment: Alignment.topCenter, + child: AppFlowyEditor( + editorState: EditorState.empty(), + keyEventHandlers: const [], + ), + ), + ); +} +``` + +At this point, nothing magic will happen after typing `_xxx_`. + +![Before](./images/customizing_a_shortcut_event_before.gif) + +Next, we will create a function to handle an underscore input. + +```dart +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) { + // Since we only need to handler the input of `underscore`. + // All inputs except `underscore` will be ignored directly. + if (event.logicalKey != LogicalKeyboardKey.underscore) { + return KeyEventResult.ignored; + } +}; +``` + +Then, we need to determine if the currently selected node is `TextNode` and the selection is collapsed. + +```dart +// ... +FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) { + // ... + + // Obtaining the selection and selected nodes of the current document through `selectionService`. + // And determine whether the selection is collapsed and whether the selected node is a text node. + final selectionService = editorState.service.selectionService; + final selection = selectionService.currentSelection.value; + final textNodes = selectionService.currentSelectedNodes.whereType(); + if (selection == null || !selection.isSingle || textNodes.length != 1) { + return KeyEventResult.ignored; + } +``` + +Now, we start dealing with underscore. + +Look for the position of the previous underscore and +1. return, if not found. +2. if found, the text wrapped in between two underscores will be displayed in italic. + +```dart +// ... +FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) { + // ... + + final textNode = textNodes.first; + final text = textNode.toRawString(); + // Determine if `underscore` already exists in the text node + final previousUnderscore = text.indexOf('_'); + if (previousUnderscore == -1) { + return KeyEventResult.ignored; + } + + // Delete the previous `underscore`, + // update the style of the text surrounded by two underscores to `italic`, + // and update the cursor position. + TransactionBuilder(editorState) + ..deleteText(textNode, previousUnderscore, 1) + ..formatText( + textNode, + previousUnderscore, + selection.end.offset - previousUnderscore - 1, + {'italic': true}, + ) + ..afterSelection = Selection.collapsed( + Position(path: textNode.path, offset: selection.end.offset - 1), + ) + ..commit(); + + return KeyEventResult.handled; +}; +``` + +So far, the 'underscore handler' function is done and the only task left is to inject it into the AppFlowyEditor. + +```dart +@override +Widget build(BuildContext context) { + return Scaffold( + body: Container( + alignment: Alignment.topCenter, + child: AppFlowyEditor( + editorState: EditorState.empty(), + keyEventHandlers: [ + underscoreToItalicHandler, + ], + ), + ), + ); +} +``` + +![After](./images/customizing_a_shortcut_event_after.gif) + +[Complete code example]() + +## Customize a component +We will use a simple example to showcase how to quickly add a custom component. + +For example, we want to render an image from the network. + +To start with, let's create an empty document by running commands as follows: + +```dart +@override +Widget build(BuildContext context) { + return Scaffold( + body: Container( + alignment: Alignment.topCenter, + child: AppFlowyEditor( + editorState: EditorState.empty(), + keyEventHandlers: const [], + ), + ), + ); +} +``` + +Next, we choose a unique string for your custom node's type. We use `network_image` in this case. And we add `network_image_src` to the `attributes` to describe the link of the image. + +> For the definition of the [Node](), please refer to this [link](). + +```JSON +{ + "type": "network_image", + "attributes": { + "network_image_src": "https://docs.flutter.dev/assets/images/dash/dash-fainting.gif" + } +} +``` + +Then, we create a class that inherits [NodeWidgetBuilder](). As shown in the autoprompt, we need to implement two functions: +1. one returns a widget +2. the other verifies the correctness of the [Node](). + + +```dart +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/material.dart'; + +class NetworkImageNodeWidgetBuilder extends NodeWidgetBuilder { + @override + Widget build(NodeWidgetContext context) { + throw UnimplementedError(); + } + + @override + NodeValidator get nodeValidator => throw UnimplementedError(); +} +``` + +Now, let's implement a simple image widget based on `Image`. + +**It is important to note that the `State` of the returned `Widget` must be with [Selectable]().** + +> For the definition of the [Selectable](), please refer to this [link](). + +```dart +class _NetworkImageNodeWidget extends StatefulWidget { + const _NetworkImageNodeWidget({ + Key? key, + required this.node, + }) : super(key: key); + + final Node node; + + @override + State<_NetworkImageNodeWidget> createState() => + __NetworkImageNodeWidgetState(); +} + +class __NetworkImageNodeWidgetState extends State<_NetworkImageNodeWidget> + with Selectable { + RenderBox get _renderBox => context.findRenderObject() as RenderBox; + + @override + Widget build(BuildContext context) { + return Image.network( + widget.node.attributes['network_image_src'], + height: 200, + loadingBuilder: (context, child, loadingProgress) => + loadingProgress == null ? child : const CircularProgressIndicator(), + ); + } + + @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 + List getRectsInSelection(Selection selection) => + [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) => _renderBox.localToGlobal(offset); +} +``` + +Finally, we return `_NetworkImageNodeWidget` in the `build` function of `NetworkImageNodeWidgetBuilder` and register `NetworkImageNodeWidgetBuilder` into `AppFlowyEditor`. + +```dart +class NetworkImageNodeWidgetBuilder extends NodeWidgetBuilder { + @override + Widget build(NodeWidgetContext context) { + return _NetworkImageNodeWidget( + key: context.node.key, + node: context.node, + ); + } + + @override + NodeValidator get nodeValidator => (node) { + return node.type == 'network_image' && + node.attributes['network_image_src'] is String; + }; +} +``` + +```dart +final editorState = EditorState( + document: StateTree.empty() + ..insert( + [0], + [ + TextNode.empty(), + Node.fromJson({ + 'type': 'network_image', + 'attributes': { + 'network_image_src': + 'https://docs.flutter.dev/assets/images/dash/dash-fainting.gif' + } + }) + ], + ), +); +return AppFlowyEditor( + editorState: editorState, + customBuilders: { + 'network_image': NetworkImageNodeWidgetBuilder(), + }, +); +``` + +![](./images/customizing_a_component.gif) + +[Here you can check out the complete code file of this example]() diff --git a/frontend/app_flowy/packages/appflowy_editor/documentation/images/customizing_a_component.gif b/frontend/app_flowy/packages/appflowy_editor/documentation/images/customizing_a_component.gif new file mode 100644 index 0000000000..d226d56d76 Binary files /dev/null and b/frontend/app_flowy/packages/appflowy_editor/documentation/images/customizing_a_component.gif differ diff --git a/frontend/app_flowy/packages/appflowy_editor/documentation/images/customizing_a_shortcut_event_after.gif b/frontend/app_flowy/packages/appflowy_editor/documentation/images/customizing_a_shortcut_event_after.gif new file mode 100644 index 0000000000..0637e9b916 Binary files /dev/null and b/frontend/app_flowy/packages/appflowy_editor/documentation/images/customizing_a_shortcut_event_after.gif differ diff --git a/frontend/app_flowy/packages/appflowy_editor/documentation/images/customizing_a_shortcut_event_before.gif b/frontend/app_flowy/packages/appflowy_editor/documentation/images/customizing_a_shortcut_event_before.gif new file mode 100644 index 0000000000..9d7dbc377e Binary files /dev/null and b/frontend/app_flowy/packages/appflowy_editor/documentation/images/customizing_a_shortcut_event_before.gif differ diff --git a/frontend/app_flowy/packages/appflowy_editor/documentation/images/example.png b/frontend/app_flowy/packages/appflowy_editor/documentation/images/example.png new file mode 100644 index 0000000000..1b1d439dbf Binary files /dev/null and b/frontend/app_flowy/packages/appflowy_editor/documentation/images/example.png differ diff --git a/frontend/app_flowy/packages/appflowy_editor/documentation/images/reporting_bugs.png b/frontend/app_flowy/packages/appflowy_editor/documentation/images/reporting_bugs.png new file mode 100644 index 0000000000..5d4d7f6150 Binary files /dev/null and b/frontend/app_flowy/packages/appflowy_editor/documentation/images/reporting_bugs.png differ diff --git a/frontend/app_flowy/packages/appflowy_editor/documentation/testing.md b/frontend/app_flowy/packages/appflowy_editor/documentation/testing.md new file mode 100644 index 0000000000..25d918c4b5 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/documentation/testing.md @@ -0,0 +1,128 @@ +# Testing + +> The directory structure of test files is consistent with the code files, making it easy for us to map a file with the corresponding test and check if the test is updated + +## Testing Functions + +**Construct a document for testing** +```dart +const text = 'Welcome to Appflowy 😁'; +// Get the instance of editor. +final editor = tester.editor; +// Insert empty text node. +editor.insertEmptyTextNode(); +// Insert text node with string. +editor.insertTextNode(text); +// Insert text node with heading style. +editor.insertTextNode(text, attributes: { + StyleKey.subtype: StyleKey.heading, + StyleKey.heading: StyleKey.h1, +}); +// Insert text node with bulleted list style and bold style. +editor.insertTextNode( + '', + attributes: { + StyleKey.subtype: StyleKey.bulletedList, + }, + delta: Delta([ + TextInsert(text, {StyleKey.bold: true}), + ]), +); +``` + +**The `startTesting` function must be called before testing**. +```dart +await editor.startTesting(); +``` + +**Get the number of nodes in the document** +```dart +final length = editor.documentLength; +print(length); +``` + +**Get the node of a defined path** +```dart +final firstTextNode = editor.nodeAtPath([0]) as TextNode; +``` + +**Update selection** +```dart +await editor.updateSelection( + Selection.single(path: firstTextNode.path, startOffset: 0), +); +``` + +**Get the selection** +```dart +final selection = editor.documentSelection; +print(selection); +``` + +**Simulate shortcut event inputs** +```dart +// Command + A. +await editor.pressLogicKey(LogicalKeyboardKey.keyA, isMetaPressed: true); +// Command + shift + S. +await editor.pressLogicKey( + LogicalKeyboardKey.keyS, + isMetaPressed: true, + isShiftPressed: true, +); +``` + +**Simulate a text input** +```dart +// Insert 'Hello World' at the beginning of the first node. +editor.insertText(firstTextNode, 'Hello World', 0); +``` + +**Get information about the text node** +```dart +// Get plain text. +final textAfterInserted = firstTextNode.toRawString(); +print(textAfterInserted); +// Get attributes. +final attributes = firstTextNode.attributes; +print(attributes); +``` + +## Example +For example, we are going to test `select_all_handler.dart` + + +```dart +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import '../../infra/test_editor.dart'; + +void main() async { + setUpAll(() { + TestWidgetsFlutterBinding.ensureInitialized(); + }); + + group('select_all_handler_test.dart', () { + testWidgets('Presses Command + A in the document', (tester) async { + const lines = 100; + const text = 'Welcome to Appflowy 😁'; + final editor = tester.editor; + for (var i = 0; i < lines; i++) { + editor.insertTextNode(text); + } + await editor.startTesting(); + await editor.pressLogicKey(LogicalKeyboardKey.keyA, isMetaPressed: true); + + expect( + editor.documentSelection, + Selection( + start: Position(path: [0], offset: 0), + end: Position(path: [lines - 1], offset: text.length), + ), + ); + }); + }); +} +``` + +For more information about testing, such as simulating a click, please refer to [An introduction to widget testing](https://docs.flutter.dev/cookbook/testing/widget/introduction) diff --git a/frontend/app_flowy/packages/flowy_editor/example/.gitignore b/frontend/app_flowy/packages/appflowy_editor/example/.gitignore similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/.gitignore rename to frontend/app_flowy/packages/appflowy_editor/example/.gitignore diff --git a/frontend/app_flowy/packages/flowy_editor/example/.metadata b/frontend/app_flowy/packages/appflowy_editor/example/.metadata similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/.metadata rename to frontend/app_flowy/packages/appflowy_editor/example/.metadata diff --git a/frontend/app_flowy/packages/flowy_editor/example/README.md b/frontend/app_flowy/packages/appflowy_editor/example/README.md similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/README.md rename to frontend/app_flowy/packages/appflowy_editor/example/README.md diff --git a/frontend/app_flowy/packages/flowy_editor/example/analysis_options.yaml b/frontend/app_flowy/packages/appflowy_editor/example/analysis_options.yaml similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/analysis_options.yaml rename to frontend/app_flowy/packages/appflowy_editor/example/analysis_options.yaml diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/.gitignore b/frontend/app_flowy/packages/appflowy_editor/example/android/.gitignore similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/.gitignore rename to frontend/app_flowy/packages/appflowy_editor/example/android/.gitignore diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/build.gradle b/frontend/app_flowy/packages/appflowy_editor/example/android/app/build.gradle similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/build.gradle rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/build.gradle diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/debug/AndroidManifest.xml b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/debug/AndroidManifest.xml similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/debug/AndroidManifest.xml rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/debug/AndroidManifest.xml diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/AndroidManifest.xml b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/AndroidManifest.xml similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/AndroidManifest.xml rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/AndroidManifest.xml diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/drawable-v21/launch_background.xml b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/drawable-v21/launch_background.xml similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/drawable-v21/launch_background.xml rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/drawable-v21/launch_background.xml diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/drawable/launch_background.xml b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/drawable/launch_background.xml similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/drawable/launch_background.xml rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/drawable/launch_background.xml diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/values-night/styles.xml b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/values-night/styles.xml similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/values-night/styles.xml rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/values-night/styles.xml diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/values/styles.xml b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/values/styles.xml similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/main/res/values/styles.xml rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/main/res/values/styles.xml diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/app/src/profile/AndroidManifest.xml b/frontend/app_flowy/packages/appflowy_editor/example/android/app/src/profile/AndroidManifest.xml similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/app/src/profile/AndroidManifest.xml rename to frontend/app_flowy/packages/appflowy_editor/example/android/app/src/profile/AndroidManifest.xml diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/build.gradle b/frontend/app_flowy/packages/appflowy_editor/example/android/build.gradle similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/build.gradle rename to frontend/app_flowy/packages/appflowy_editor/example/android/build.gradle diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/gradle.properties b/frontend/app_flowy/packages/appflowy_editor/example/android/gradle.properties similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/gradle.properties rename to frontend/app_flowy/packages/appflowy_editor/example/android/gradle.properties diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/gradle/wrapper/gradle-wrapper.properties b/frontend/app_flowy/packages/appflowy_editor/example/android/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/gradle/wrapper/gradle-wrapper.properties rename to frontend/app_flowy/packages/appflowy_editor/example/android/gradle/wrapper/gradle-wrapper.properties diff --git a/frontend/app_flowy/packages/flowy_editor/example/android/settings.gradle b/frontend/app_flowy/packages/appflowy_editor/example/android/settings.gradle similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/android/settings.gradle rename to frontend/app_flowy/packages/appflowy_editor/example/android/settings.gradle diff --git a/frontend/app_flowy/packages/flowy_editor/example/assets/big_document.json b/frontend/app_flowy/packages/appflowy_editor/example/assets/big_document.json similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/assets/big_document.json rename to frontend/app_flowy/packages/appflowy_editor/example/assets/big_document.json diff --git a/frontend/app_flowy/packages/flowy_editor/example/assets/example.json b/frontend/app_flowy/packages/appflowy_editor/example/assets/example.json similarity index 55% rename from frontend/app_flowy/packages/flowy_editor/example/assets/example.json rename to frontend/app_flowy/packages/appflowy_editor/example/assets/example.json index e6357d93f9..901e57f796 100644 --- a/frontend/app_flowy/packages/flowy_editor/example/assets/example.json +++ b/frontend/app_flowy/packages/appflowy_editor/example/assets/example.json @@ -6,7 +6,7 @@ { "type": "image", "attributes": { - "image_src": "https://s1.ax1x.com/2022/07/28/vCgz1x.png" + "image_src": "https://images.squarespace-cdn.com/content/v1/617f6f16b877c06711e87373/c3f23723-37f4-44d7-9c5d-6e2a53064ae7/Asset+10.png" } }, { @@ -25,7 +25,7 @@ "type": "text", "delta": [ { - "insert": "👋 Welcome to Appflowy" + "insert": "👋 Welcome to FlowyEditor" } ], "attributes": { @@ -37,11 +37,24 @@ "type": "text", "delta": [ { - "insert": "At " + "insert": "To be honest, we are still in the alpha stage. There are still many functions that need to be completed. And we are developing more features. Please give us a star if the " }, - { "insert": "AppFlowy", "attributes": { "code": true, "bold": true, "color": "0xFFED459C"} }, { - "insert": ", we embody what we value deep in our hearts, taking inspiration from other great companies while forging our own path. AppFlowy’s five core values are Mission Driven, Aim High & Iterate, Transparency, Collaboration, and Honesty. Together, they spell MATCH. We will continue to iterate and refine these values as we grow." + "insert": "FlowyEditor", + "attributes": { + "href": "https://github.com/AppFlowy-IO/AppFlowy" + } + }, + { + "insert": " helps you. 😊😊😊" + } + ] + }, + { + "type": "text", + "delta": [ + { + "insert": "Since the FlowyEditor are a community-driven open source editor, we very welcome and appreciate every pull request submissions from everyone.😄😄😄" } ] }, @@ -76,7 +89,7 @@ "attributes": { "backgroundColor": "0xFFFFFF00" } }, { - "insert": "to see all the types of content you can add - entity, headers, videos, sub pages, etc." + "insert": "to see all the types of content you can add - headers, bulleted lists, checkboxes, etc." } ] }, @@ -84,7 +97,11 @@ "type": "text", "delta": [ { - "insert": "Highlight any text, and use the menu that pops up to " + "insert": "Highlight", + "attributes": { "backgroundColor": "0xFF00BCFB" } + }, + { + "insert": " any text, and use the menu that pops up to " }, { "insert": "style", "attributes": { "bold": true } }, { "insert": " your ", "attributes": { "italic": true } }, @@ -245,62 +262,6 @@ "subtype": "number-list", "number": 3 } - }, - { - "type": "text", - "delta": [ - { - "insert": "At AppFlowy, we embody what we value deep in our hearts, taking inspiration from other great companies while forging our own path. AppFlowy’s five core values are Mission Driven, Aim High & Iterate, Transparency, Collaboration, and Honesty. Together, they spell MATCH. We will continue to iterate and refine these values as we grow." - } - ] - }, - { - "type": "text", - "delta": [ - { - "insert": "At AppFlowy, we embody what we value deep in our hearts, taking inspiration from other great companies while forging our own path. AppFlowy’s five core values are Mission Driven, Aim High & Iterate, Transparency, Collaboration, and Honesty. Together, they spell MATCH. We will continue to iterate and refine these values as we grow." - } - ] - }, - { - "type": "text", - "delta": [ - { - "insert": "At AppFlowy, we embody what we value deep in our hearts, taking inspiration from other great companies while forging our own path. AppFlowy’s five core values are Mission Driven, Aim High & Iterate, Transparency, Collaboration, and Honesty. Together, they spell MATCH. We will continue to iterate and refine these values as we grow." - } - ] - }, - { - "type": "text", - "delta": [ - { - "insert": "At AppFlowy, we embody what we value deep in our hearts, taking inspiration from other great companies while forging our own path. AppFlowy’s five core values are Mission Driven, Aim High & Iterate, Transparency, Collaboration, and Honesty. Together, they spell MATCH. We will continue to iterate and refine these values as we grow." - } - ] - }, - { - "type": "text", - "delta": [ - { - "insert": "At AppFlowy, we embody what we value deep in our hearts, taking inspiration from other great companies while forging our own path. AppFlowy’s five core values are Mission Driven, Aim High & Iterate, Transparency, Collaboration, and Honesty. Together, they spell MATCH. We will continue to iterate and refine these values as we grow." - } - ] - }, - { - "type": "text", - "delta": [ - { - "insert": "At AppFlowy, we embody what we value deep in our hearts, taking inspiration from other great companies while forging our own path. AppFlowy’s five core values are Mission Driven, Aim High & Iterate, Transparency, Collaboration, and Honesty. Together, they spell MATCH. We will continue to iterate and refine these values as we grow." - } - ] - }, - { - "type": "text", - "delta": [ - { - "insert": "At AppFlowy, we embody what we value deep in our hearts, taking inspiration from other great companies while forging our own path. AppFlowy’s five core values are Mission Driven, Aim High & Iterate, Transparency, Collaboration, and Honesty. Together, they spell MATCH. We will continue to iterate and refine these values as we grow." - } - ] } ] } diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/.gitignore b/frontend/app_flowy/packages/appflowy_editor/example/ios/.gitignore similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/.gitignore rename to frontend/app_flowy/packages/appflowy_editor/example/ios/.gitignore diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Flutter/AppFrameworkInfo.plist b/frontend/app_flowy/packages/appflowy_editor/example/ios/Flutter/AppFrameworkInfo.plist similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Flutter/AppFrameworkInfo.plist rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Flutter/AppFrameworkInfo.plist diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Flutter/Debug.xcconfig b/frontend/app_flowy/packages/appflowy_editor/example/ios/Flutter/Debug.xcconfig similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Flutter/Debug.xcconfig rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Flutter/Debug.xcconfig diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Flutter/Release.xcconfig b/frontend/app_flowy/packages/appflowy_editor/example/ios/Flutter/Release.xcconfig similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Flutter/Release.xcconfig rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Flutter/Release.xcconfig diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Podfile b/frontend/app_flowy/packages/appflowy_editor/example/ios/Podfile similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Podfile rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Podfile diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcodeproj/project.pbxproj b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcodeproj/project.pbxproj similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcodeproj/project.pbxproj rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcodeproj/project.pbxproj diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcworkspace/contents.xcworkspacedata rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcworkspace/contents.xcworkspacedata diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/AppDelegate.swift b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/AppDelegate.swift similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/AppDelegate.swift rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/AppDelegate.swift diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Base.lproj/LaunchScreen.storyboard rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Base.lproj/LaunchScreen.storyboard diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Base.lproj/Main.storyboard b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Base.lproj/Main.storyboard similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Base.lproj/Main.storyboard rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Base.lproj/Main.storyboard diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Info.plist b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Info.plist similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Info.plist rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Info.plist diff --git a/frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Runner-Bridging-Header.h b/frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Runner-Bridging-Header.h similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/ios/Runner/Runner-Bridging-Header.h rename to frontend/app_flowy/packages/appflowy_editor/example/ios/Runner/Runner-Bridging-Header.h diff --git a/frontend/app_flowy/packages/flowy_editor/example/lib/expandable_floating_action_button.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/expandable_floating_action_button.dart similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/lib/expandable_floating_action_button.dart rename to frontend/app_flowy/packages/appflowy_editor/example/lib/expandable_floating_action_button.dart diff --git a/frontend/app_flowy/packages/flowy_editor/example/lib/main.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart similarity index 72% rename from frontend/app_flowy/packages/flowy_editor/example/lib/main.dart rename to frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart index d33a010b55..8b00d936ee 100644 --- a/frontend/app_flowy/packages/flowy_editor/example/lib/main.dart +++ b/frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart @@ -1,14 +1,13 @@ -import 'dart:collection'; import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:example/expandable_floating_action_button.dart'; -import 'package:example/plugin/image_node_widget.dart'; -import 'package:example/plugin/youtube_link_node_widget.dart'; +import 'expandable_floating_action_button.dart'; +import 'plugin/image_node_widget.dart'; +import 'plugin/youtube_link_node_widget.dart'; -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; void main() { runApp(const MyApp()); @@ -33,7 +32,7 @@ class MyApp extends StatelessWidget { // is not restarted. primarySwatch: Colors.blue, ), - home: const MyHomePage(title: 'FlowyEditor Example'), + home: const MyHomePage(title: 'AppFlowyEditor Example'), ); } } @@ -73,13 +72,11 @@ class _MyHomePageState extends State { Widget _buildBody() { if (page == 0) { - return _buildFlowyEditorWithExample(); + return _buildAppFlowyEditorWithExample(); } else if (page == 1) { - return _buildFlowyEditorWithEmptyDocument(); + return _buildAppFlowyEditorWithEmptyDocument(); } else if (page == 2) { - return _buildTextField(); - } else if (page == 3) { - return _buildFlowyEditorWithBigDocument(); + return _buildAppFlowyEditorWithBigDocument(); } return Container(); } @@ -115,46 +112,27 @@ class _MyHomePageState extends State { }, icon: const Icon(Icons.text_fields), ), - ActionButton( - onPressed: () { - if (page == 3) return; - setState(() { - page = 3; - }); - }, - icon: const Icon(Icons.email), - ), ], ); } - Widget _buildFlowyEditorWithEmptyDocument() { - return _buildFlowyEditor( - EditorState( - document: StateTree( - root: Node( - type: 'editor', - children: LinkedList() - ..add( - TextNode.empty() - ..delta = Delta( - [TextInsert('')], - ), - ), - attributes: {}, - ), - ), - ), + Widget _buildAppFlowyEditorWithEmptyDocument() { + final editorState = EditorState.empty(); + final editor = AppFlowyEditor( + editorState: editorState, + keyEventHandlers: const [], + customBuilders: const {}, ); + return editor; } - Widget _buildFlowyEditorWithExample() { + Widget _buildAppFlowyEditorWithExample() { return FutureBuilder( future: rootBundle.loadString('assets/example.json'), builder: (context, snapshot) { if (snapshot.hasData) { final data = Map.from(json.decode(snapshot.data!)); - return _buildFlowyEditor(EditorState( + return _buildAppFlowyEditor(EditorState( document: StateTree.fromJson(data), )); } else { @@ -166,13 +144,13 @@ class _MyHomePageState extends State { ); } - Widget _buildFlowyEditorWithBigDocument() { + Widget _buildAppFlowyEditorWithBigDocument() { return FutureBuilder( future: rootBundle.loadString('assets/big_document.json'), builder: (context, snapshot) { if (snapshot.hasData) { final data = Map.from(json.decode(snapshot.data!)); - return _buildFlowyEditor(EditorState( + return _buildAppFlowyEditor(EditorState( document: StateTree.fromJson(data), )); } else { @@ -184,10 +162,10 @@ class _MyHomePageState extends State { ); } - Widget _buildFlowyEditor(EditorState editorState) { + Widget _buildAppFlowyEditor(EditorState editorState) { return Container( padding: const EdgeInsets.only(left: 20, right: 20), - child: FlowyEditor( + child: AppFlowyEditor( key: editorKey, editorState: editorState, keyEventHandlers: const [], @@ -198,10 +176,4 @@ class _MyHomePageState extends State { ), ); } - - Widget _buildTextField() { - return const Center( - child: TextField(), - ); - } } diff --git a/frontend/app_flowy/packages/flowy_editor/example/lib/plugin/image_node_widget.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/image_node_widget.dart similarity index 96% rename from frontend/app_flowy/packages/flowy_editor/example/lib/plugin/image_node_widget.dart rename to frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/image_node_widget.dart index 4270897397..c535bc6295 100644 --- a/frontend/app_flowy/packages/flowy_editor/example/lib/plugin/image_node_widget.dart +++ b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/image_node_widget.dart @@ -1,4 +1,4 @@ -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/material.dart'; /// 1. define your custom type in example.json @@ -15,7 +15,7 @@ import 'package:flutter/material.dart'; /// /// 4. override the getter `nodeValidator` /// to verify the data structure in [Node]. -/// 5. register the plugin with `type` to `flowy_editor` in `main.dart`. +/// 5. register the plugin with `type` to `AppFlowyEditor` in `main.dart`. /// 6. Congratulations! class ImageNodeBuilder extends NodeWidgetBuilder { diff --git a/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/network_image_node_widget.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/network_image_node_widget.dart new file mode 100644 index 0000000000..84d2e72918 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/network_image_node_widget.dart @@ -0,0 +1,69 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/material.dart'; + +class NetworkImageNodeWidgetBuilder extends NodeWidgetBuilder { + @override + Widget build(NodeWidgetContext context) { + return _NetworkImageNodeWidget( + key: context.node.key, + node: context.node, + ); + } + + @override + NodeValidator get nodeValidator => (node) { + return node.type == 'network_image' && + node.attributes['network_image_src'] is String; + }; +} + +class _NetworkImageNodeWidget extends StatefulWidget { + const _NetworkImageNodeWidget({ + Key? key, + required this.node, + }) : super(key: key); + + final Node node; + + @override + State<_NetworkImageNodeWidget> createState() => + __NetworkImageNodeWidgetState(); +} + +class __NetworkImageNodeWidgetState extends State<_NetworkImageNodeWidget> + with Selectable { + RenderBox get _renderBox => context.findRenderObject() as RenderBox; + + @override + Widget build(BuildContext context) { + return Image.network( + widget.node.attributes['network_image_src'], + height: 200, + loadingBuilder: (context, child, loadingProgress) => + loadingProgress == null ? child : const CircularProgressIndicator(), + ); + } + + @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 + List getRectsInSelection(Selection selection) => + [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) => _renderBox.localToGlobal(offset); +} diff --git a/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/underscore_to_italic_key_event_handler.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/underscore_to_italic_key_event_handler.dart new file mode 100644 index 0000000000..539a756e1f --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/underscore_to_italic_key_event_handler.dart @@ -0,0 +1,46 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +AppFlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) { + // Since we only need to handler the input of `underscore`. + // All inputs except `underscore` will be ignored directly. + if (event.logicalKey != LogicalKeyboardKey.underscore) { + return KeyEventResult.ignored; + } + + // Obtaining the selection and selected nodes of the current document through `selectionService`, + // and determine whether it is a single selection and whether the selected node is a text node. + final selectionService = editorState.service.selectionService; + final selection = selectionService.currentSelection.value; + final textNodes = selectionService.currentSelectedNodes.whereType(); + if (selection == null || !selection.isSingle || textNodes.length != 1) { + return KeyEventResult.ignored; + } + + final textNode = textNodes.first; + final text = textNode.toRawString(); + // Determine if `underscore` already exists in the text node + final previousUnderscore = text.indexOf('_'); + if (previousUnderscore == -1) { + return KeyEventResult.ignored; + } + + // Delete the previous `underscore`, + // update the style of the text surrounded by two underscores to `italic`, + // and update the cursor position. + TransactionBuilder(editorState) + ..deleteText(textNode, previousUnderscore, 1) + ..formatText( + textNode, + previousUnderscore, + selection.end.offset - previousUnderscore - 1, + {'italic': true}, + ) + ..afterSelection = Selection.collapsed( + Position(path: textNode.path, offset: selection.end.offset - 1), + ) + ..commit(); + + return KeyEventResult.handled; +}; diff --git a/frontend/app_flowy/packages/flowy_editor/example/lib/plugin/youtube_link_node_widget.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/youtube_link_node_widget.dart similarity index 97% rename from frontend/app_flowy/packages/flowy_editor/example/lib/plugin/youtube_link_node_widget.dart rename to frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/youtube_link_node_widget.dart index fd79077912..27bbe922e3 100644 --- a/frontend/app_flowy/packages/flowy_editor/example/lib/plugin/youtube_link_node_widget.dart +++ b/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/youtube_link_node_widget.dart @@ -1,4 +1,4 @@ -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/material.dart'; import 'package:pod_player/pod_player.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/example/linux/.gitignore b/frontend/app_flowy/packages/appflowy_editor/example/linux/.gitignore similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/linux/.gitignore rename to frontend/app_flowy/packages/appflowy_editor/example/linux/.gitignore diff --git a/frontend/app_flowy/packages/flowy_editor/example/linux/CMakeLists.txt b/frontend/app_flowy/packages/appflowy_editor/example/linux/CMakeLists.txt similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/linux/CMakeLists.txt rename to frontend/app_flowy/packages/appflowy_editor/example/linux/CMakeLists.txt diff --git a/frontend/app_flowy/packages/flowy_editor/example/linux/flutter/CMakeLists.txt b/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/CMakeLists.txt similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/linux/flutter/CMakeLists.txt rename to frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/CMakeLists.txt diff --git a/frontend/app_flowy/packages/flowy_editor/example/linux/flutter/generated_plugin_registrant.cc b/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugin_registrant.cc similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/linux/flutter/generated_plugin_registrant.cc rename to frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugin_registrant.cc diff --git a/frontend/app_flowy/packages/flowy_editor/example/linux/flutter/generated_plugin_registrant.h b/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugin_registrant.h similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/linux/flutter/generated_plugin_registrant.h rename to frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugin_registrant.h diff --git a/frontend/app_flowy/packages/flowy_editor/example/linux/flutter/generated_plugins.cmake b/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugins.cmake similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/linux/flutter/generated_plugins.cmake rename to frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugins.cmake diff --git a/frontend/app_flowy/packages/flowy_editor/example/linux/main.cc b/frontend/app_flowy/packages/appflowy_editor/example/linux/main.cc similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/linux/main.cc rename to frontend/app_flowy/packages/appflowy_editor/example/linux/main.cc diff --git a/frontend/app_flowy/packages/flowy_editor/example/linux/my_application.cc b/frontend/app_flowy/packages/appflowy_editor/example/linux/my_application.cc similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/linux/my_application.cc rename to frontend/app_flowy/packages/appflowy_editor/example/linux/my_application.cc diff --git a/frontend/app_flowy/packages/flowy_editor/example/linux/my_application.h b/frontend/app_flowy/packages/appflowy_editor/example/linux/my_application.h similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/linux/my_application.h rename to frontend/app_flowy/packages/appflowy_editor/example/linux/my_application.h diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/.gitignore b/frontend/app_flowy/packages/appflowy_editor/example/macos/.gitignore similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/.gitignore rename to frontend/app_flowy/packages/appflowy_editor/example/macos/.gitignore diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Flutter/Flutter-Debug.xcconfig b/frontend/app_flowy/packages/appflowy_editor/example/macos/Flutter/Flutter-Debug.xcconfig similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Flutter/Flutter-Debug.xcconfig rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Flutter/Flutter-Debug.xcconfig diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Flutter/Flutter-Release.xcconfig b/frontend/app_flowy/packages/appflowy_editor/example/macos/Flutter/Flutter-Release.xcconfig similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Flutter/Flutter-Release.xcconfig rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Flutter/Flutter-Release.xcconfig diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Flutter/GeneratedPluginRegistrant.swift b/frontend/app_flowy/packages/appflowy_editor/example/macos/Flutter/GeneratedPluginRegistrant.swift similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Flutter/GeneratedPluginRegistrant.swift rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Flutter/GeneratedPluginRegistrant.swift diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Podfile b/frontend/app_flowy/packages/appflowy_editor/example/macos/Podfile similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Podfile rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Podfile diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Podfile.lock b/frontend/app_flowy/packages/appflowy_editor/example/macos/Podfile.lock similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Podfile.lock rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Podfile.lock diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner.xcodeproj/project.pbxproj b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner.xcodeproj/project.pbxproj similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner.xcodeproj/project.pbxproj rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner.xcodeproj/project.pbxproj diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner.xcworkspace/contents.xcworkspacedata b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner.xcworkspace/contents.xcworkspacedata rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner.xcworkspace/contents.xcworkspacedata diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/AppDelegate.swift b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/AppDelegate.swift similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/AppDelegate.swift rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/AppDelegate.swift diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Base.lproj/MainMenu.xib b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Base.lproj/MainMenu.xib similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Base.lproj/MainMenu.xib rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Base.lproj/MainMenu.xib diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Configs/AppInfo.xcconfig b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Configs/AppInfo.xcconfig similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Configs/AppInfo.xcconfig rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Configs/AppInfo.xcconfig diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Configs/Debug.xcconfig b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Configs/Debug.xcconfig similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Configs/Debug.xcconfig rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Configs/Debug.xcconfig diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Configs/Release.xcconfig b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Configs/Release.xcconfig similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Configs/Release.xcconfig rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Configs/Release.xcconfig diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Configs/Warnings.xcconfig b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Configs/Warnings.xcconfig similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Configs/Warnings.xcconfig rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Configs/Warnings.xcconfig diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/DebugProfile.entitlements b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/DebugProfile.entitlements similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/DebugProfile.entitlements rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/DebugProfile.entitlements diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Info.plist b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Info.plist similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Info.plist rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Info.plist diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/MainFlutterWindow.swift b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/MainFlutterWindow.swift similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/MainFlutterWindow.swift rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/MainFlutterWindow.swift diff --git a/frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Release.entitlements b/frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Release.entitlements similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/macos/Runner/Release.entitlements rename to frontend/app_flowy/packages/appflowy_editor/example/macos/Runner/Release.entitlements diff --git a/frontend/app_flowy/packages/flowy_editor/example/pubspec.yaml b/frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml similarity index 99% rename from frontend/app_flowy/packages/flowy_editor/example/pubspec.yaml rename to frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml index a9b374af5c..4e2e2d68ab 100644 --- a/frontend/app_flowy/packages/flowy_editor/example/pubspec.yaml +++ b/frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml @@ -33,7 +33,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 - flowy_editor: + appflowy_editor: path: ../ provider: ^6.0.3 url_launcher: ^6.1.5 diff --git a/frontend/app_flowy/packages/flowy_editor/example/test/widget_test.dart b/frontend/app_flowy/packages/appflowy_editor/example/test/widget_test.dart similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/test/widget_test.dart rename to frontend/app_flowy/packages/appflowy_editor/example/test/widget_test.dart diff --git a/frontend/app_flowy/packages/flowy_editor/example/web/favicon.png b/frontend/app_flowy/packages/appflowy_editor/example/web/favicon.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/web/favicon.png rename to frontend/app_flowy/packages/appflowy_editor/example/web/favicon.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/web/icons/Icon-192.png b/frontend/app_flowy/packages/appflowy_editor/example/web/icons/Icon-192.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/web/icons/Icon-192.png rename to frontend/app_flowy/packages/appflowy_editor/example/web/icons/Icon-192.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/web/icons/Icon-512.png b/frontend/app_flowy/packages/appflowy_editor/example/web/icons/Icon-512.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/web/icons/Icon-512.png rename to frontend/app_flowy/packages/appflowy_editor/example/web/icons/Icon-512.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/web/icons/Icon-maskable-192.png b/frontend/app_flowy/packages/appflowy_editor/example/web/icons/Icon-maskable-192.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/web/icons/Icon-maskable-192.png rename to frontend/app_flowy/packages/appflowy_editor/example/web/icons/Icon-maskable-192.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/web/icons/Icon-maskable-512.png b/frontend/app_flowy/packages/appflowy_editor/example/web/icons/Icon-maskable-512.png similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/web/icons/Icon-maskable-512.png rename to frontend/app_flowy/packages/appflowy_editor/example/web/icons/Icon-maskable-512.png diff --git a/frontend/app_flowy/packages/flowy_editor/example/web/index.html b/frontend/app_flowy/packages/appflowy_editor/example/web/index.html similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/web/index.html rename to frontend/app_flowy/packages/appflowy_editor/example/web/index.html diff --git a/frontend/app_flowy/packages/flowy_editor/example/web/manifest.json b/frontend/app_flowy/packages/appflowy_editor/example/web/manifest.json similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/web/manifest.json rename to frontend/app_flowy/packages/appflowy_editor/example/web/manifest.json diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/.gitignore b/frontend/app_flowy/packages/appflowy_editor/example/windows/.gitignore similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/.gitignore rename to frontend/app_flowy/packages/appflowy_editor/example/windows/.gitignore diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/CMakeLists.txt b/frontend/app_flowy/packages/appflowy_editor/example/windows/CMakeLists.txt similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/CMakeLists.txt rename to frontend/app_flowy/packages/appflowy_editor/example/windows/CMakeLists.txt diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/flutter/CMakeLists.txt b/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/CMakeLists.txt similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/flutter/CMakeLists.txt rename to frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/CMakeLists.txt diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/flutter/generated_plugin_registrant.cc b/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugin_registrant.cc similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/flutter/generated_plugin_registrant.cc rename to frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugin_registrant.cc diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/flutter/generated_plugin_registrant.h b/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugin_registrant.h similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/flutter/generated_plugin_registrant.h rename to frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugin_registrant.h diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/flutter/generated_plugins.cmake b/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugins.cmake similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/flutter/generated_plugins.cmake rename to frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugins.cmake diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/CMakeLists.txt b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/CMakeLists.txt similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/CMakeLists.txt rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/CMakeLists.txt diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/Runner.rc b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/Runner.rc similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/Runner.rc rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/Runner.rc diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/flutter_window.cpp b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/flutter_window.cpp similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/flutter_window.cpp rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/flutter_window.cpp diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/flutter_window.h b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/flutter_window.h similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/flutter_window.h rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/flutter_window.h diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/main.cpp b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/main.cpp similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/main.cpp rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/main.cpp diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/resource.h b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/resource.h similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/resource.h rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/resource.h diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/resources/app_icon.ico b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/resources/app_icon.ico similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/resources/app_icon.ico rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/resources/app_icon.ico diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/runner.exe.manifest b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/runner.exe.manifest similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/runner.exe.manifest rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/runner.exe.manifest diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/utils.cpp b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/utils.cpp similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/utils.cpp rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/utils.cpp diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/utils.h b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/utils.h similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/utils.h rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/utils.h diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/win32_window.cpp b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/win32_window.cpp similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/win32_window.cpp rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/win32_window.cpp diff --git a/frontend/app_flowy/packages/flowy_editor/example/windows/runner/win32_window.h b/frontend/app_flowy/packages/appflowy_editor/example/windows/runner/win32_window.h similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/example/windows/runner/win32_window.h rename to frontend/app_flowy/packages/appflowy_editor/example/windows/runner/win32_window.h diff --git a/frontend/app_flowy/packages/flowy_editor/lib/flowy_editor.dart b/frontend/app_flowy/packages/appflowy_editor/lib/appflowy_editor.dart similarity index 93% rename from frontend/app_flowy/packages/flowy_editor/lib/flowy_editor.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/appflowy_editor.dart index f134d309b0..d44f1b3241 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/flowy_editor.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/appflowy_editor.dart @@ -1,4 +1,5 @@ -library flowy_editor; +/// AppFlowyEditor library +library appflowy_editor; export 'src/document/node.dart'; export 'src/document/path.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/document/attributes.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/attributes.dart similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/lib/src/document/attributes.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/document/attributes.dart diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/document/node.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/node.dart similarity index 96% rename from frontend/app_flowy/packages/flowy_editor/lib/src/document/node.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/document/node.dart index 5bf63e63a3..a0c4e33a70 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/document/node.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/node.dart @@ -1,6 +1,6 @@ import 'dart:collection'; -import 'package:flowy_editor/src/document/path.dart'; -import 'package:flowy_editor/src/document/text_delta.dart'; +import 'package:appflowy_editor/src/document/path.dart'; +import 'package:appflowy_editor/src/document/text_delta.dart'; import 'package:flutter/material.dart'; import './attributes.dart'; @@ -89,7 +89,7 @@ class Node extends ChangeNotifier with LinkedListEntry { bool shouldNotifyParent = _attributes['subtype'] != attributes['subtype']; _attributes = composeAttributes(_attributes, attributes) ?? {}; - // Notify the new attributes + // Notifies the new attributes // if attributes contains 'subtype', should notify parent to rebuild node // else, just notify current node. shouldNotifyParent ? parent?.notifyListeners() : notifyListeners(); @@ -137,7 +137,7 @@ class Node extends ChangeNotifier with LinkedListEntry { entry.parent = parent; super.insertAfter(entry); - // Notify the new node. + // Notifies the new node. parent?.notifyListeners(); } @@ -146,7 +146,7 @@ class Node extends ChangeNotifier with LinkedListEntry { entry.parent = parent; super.insertBefore(entry); - // Notify the new node. + // Notifies the new node. parent?.notifyListeners(); } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/document/node_iterator.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/node_iterator.dart similarity index 96% rename from frontend/app_flowy/packages/flowy_editor/lib/src/document/node_iterator.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/document/node_iterator.dart index c1349b7c4c..9c666bdfea 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/document/node_iterator.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/node_iterator.dart @@ -1,4 +1,4 @@ -import 'package:flowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/node.dart'; import './state_tree.dart'; import './node.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/document/path.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/path.dart similarity index 87% rename from frontend/app_flowy/packages/flowy_editor/lib/src/document/path.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/document/path.dart index 8f24947649..a8163f094d 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/document/path.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/path.dart @@ -1,5 +1,3 @@ -import 'dart:math'; - import 'package:flutter/foundation.dart'; typedef Path = List; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/document/position.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/position.dart similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/lib/src/document/position.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/document/position.dart diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/document/selection.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/selection.dart similarity index 93% rename from frontend/app_flowy/packages/flowy_editor/lib/src/document/selection.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/document/selection.dart index 3ac7293a2c..99a81c9273 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/document/selection.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/selection.dart @@ -1,6 +1,6 @@ -import 'package:flowy_editor/src/document/path.dart'; -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/extensions/path_extensions.dart'; +import 'package:appflowy_editor/src/document/path.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/extensions/path_extensions.dart'; /// Selection represents the selected area or the cursor area in the editor. /// diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/document/state_tree.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/state_tree.dart similarity index 83% rename from frontend/app_flowy/packages/flowy_editor/lib/src/document/state_tree.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/document/state_tree.dart index f1437fbaef..5bf49c0048 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/document/state_tree.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/state_tree.dart @@ -1,8 +1,8 @@ import 'dart:math'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/path.dart'; -import 'package:flowy_editor/src/document/text_delta.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/path.dart'; +import 'package:appflowy_editor/src/document/text_delta.dart'; import './attributes.dart'; class StateTree { @@ -12,6 +12,19 @@ class StateTree { required this.root, }); + factory StateTree.empty() { + return StateTree( + root: Node.fromJson({ + 'type': 'editor', + 'children': [ + { + 'type': 'text', + } + ] + }), + ); + } + factory StateTree.fromJson(Attributes json) { assert(json['document'] is Map); diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/text_delta.dart similarity index 96% rename from frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/document/text_delta.dart index 658114df7a..2e6fa82437 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/text_delta.dart @@ -1,7 +1,7 @@ import 'dart:collection'; import 'dart:math'; -import 'package:flowy_editor/src/document/attributes.dart'; +import 'package:appflowy_editor/src/document/attributes.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import './attributes.dart'; @@ -182,7 +182,7 @@ class _OpIterator { return _maxInt; } - TextOperation next([int? length]) { + TextOperation _next([int? length]) { length ??= _maxInt; if (_index >= _operations.length) { @@ -229,11 +229,11 @@ class _OpIterator { } else { final offset = _offset; final index = _index; - final _next = next(); + final next = _next(); final rest = _operations.sublist(_index); _offset = offset; _index = index; - return [_next] + rest; + return [next] + rest; } } } @@ -332,9 +332,9 @@ class Delta extends Iterable { while ((end == null || index < end) && iterator.hasNext) { TextOperation? nextOp; if (index < start) { - nextOp = iterator.next(start - index); + nextOp = iterator._next(start - index); } else { - nextOp = iterator.next(end == null ? null : end - index); + nextOp = iterator._next(end == null ? null : end - index); result.add(nextOp); } @@ -361,6 +361,7 @@ class Delta extends Iterable { void delete(int length) => add(TextDelete(length)); /// The length of the string fo the [Delta]. + @override int get length { return _operations.fold( 0, (previousValue, element) => previousValue + element.length); @@ -380,27 +381,27 @@ class Delta extends Iterable { while ( thisIter.peek() is TextInsert && thisIter.peekLength() <= firstLeft) { firstLeft -= thisIter.peekLength(); - final next = thisIter.next(); + final next = thisIter._next(); ops.add(next); } if (firstOther.length - firstLeft > 0) { - otherIter.next(firstOther.length - firstLeft); + otherIter._next(firstOther.length - firstLeft); } } final delta = Delta(ops); while (thisIter.hasNext || otherIter.hasNext) { if (otherIter.peek() is TextInsert) { - final next = otherIter.next(); + final next = otherIter._next(); delta.add(next); } else if (thisIter.peek() is TextDelete) { - final next = thisIter.next(); + final next = thisIter._next(); delta.add(next); } else { // otherIs final length = min(thisIter.peekLength(), otherIter.peekLength()); - final thisOp = thisIter.next(length); - final otherOp = otherIter.next(length); + final thisOp = thisIter._next(length); + final otherOp = otherIter._next(length); final attributes = composeAttributes( thisOp.attributes, otherOp.attributes, thisOp is TextRetain); if (otherOp is TextRetain && otherOp.length > 0) { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/editor_state.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/editor_state.dart similarity index 84% rename from frontend/app_flowy/packages/flowy_editor/lib/src/editor_state.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/editor_state.dart index 4452e92ed2..659e612645 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/editor_state.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/editor_state.dart @@ -1,17 +1,17 @@ import 'dart:async'; -import 'package:flowy_editor/src/service/service.dart'; +import 'package:appflowy_editor/src/service/service.dart'; import 'package:flutter/material.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/document/state_tree.dart'; -import 'package:flowy_editor/src/operation/operation.dart'; -import 'package:flowy_editor/src/operation/transaction.dart'; -import 'package:flowy_editor/src/undo_manager.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/document/state_tree.dart'; +import 'package:appflowy_editor/src/operation/operation.dart'; +import 'package:appflowy_editor/src/operation/transaction.dart'; +import 'package:appflowy_editor/src/undo_manager.dart'; class ApplyOptions { /// This flag indicates that /// whether the transaction should be recorded into - /// the undo stack. + /// the undo stack final bool recordUndo; final bool recordRedo; const ApplyOptions({ @@ -27,9 +27,9 @@ enum CursorUpdateReason { /// The state of the editor. /// -/// The state including: +/// The state includes: /// - The document to render -/// - The state of the selection. +/// - The state of the selection /// /// [EditorState] also includes the services of the editor: /// - Selection service @@ -38,8 +38,8 @@ enum CursorUpdateReason { /// - Input service /// - Toolbar service /// -/// In consideration of collaborative editing. -/// All the mutations should be applied through [Transaction]. +/// In consideration of collaborative editing, +/// all the mutations should be applied through [Transaction]. /// /// Mutating the document with document's API is not recommended. class EditorState { @@ -75,6 +75,10 @@ class EditorState { undoManager.state = this; } + factory EditorState.empty() { + return EditorState(document: StateTree.empty()); + } + /// Apply the transaction to the state. /// /// The options can be used to determine whether the editor diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/extensions/color_extension.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/color_extension.dart similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/lib/src/extensions/color_extension.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/color_extension.dart diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/extensions/node_extensions.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/node_extensions.dart similarity index 69% rename from frontend/app_flowy/packages/flowy_editor/lib/src/extensions/node_extensions.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/node_extensions.dart index db58f8a3db..5df8665a6b 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/extensions/node_extensions.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/node_extensions.dart @@ -1,8 +1,8 @@ -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/extensions/object_extensions.dart'; -import 'package:flowy_editor/src/extensions/path_extensions.dart'; -import 'package:flowy_editor/src/render/selection/selectable.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/extensions/object_extensions.dart'; +import 'package:appflowy_editor/src/extensions/path_extensions.dart'; +import 'package:appflowy_editor/src/render/selection/selectable.dart'; import 'package:flutter/material.dart'; extension NodeExtensions on Node { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/extensions/object_extensions.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/object_extensions.dart similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/lib/src/extensions/object_extensions.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/object_extensions.dart diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/extensions/path_extensions.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/path_extensions.dart similarity index 92% rename from frontend/app_flowy/packages/flowy_editor/lib/src/extensions/path_extensions.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/path_extensions.dart index 7f72444224..fb643443e4 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/extensions/path_extensions.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/path_extensions.dart @@ -1,4 +1,4 @@ -import 'package:flowy_editor/src/document/path.dart'; +import 'package:appflowy_editor/src/document/path.dart'; import 'dart:math'; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/extensions/text_node_extensions.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart similarity index 65% rename from frontend/app_flowy/packages/flowy_editor/lib/src/extensions/text_node_extensions.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart index 315f529710..1d7c68ab80 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/extensions/text_node_extensions.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart @@ -1,24 +1,28 @@ -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/path.dart'; -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/document/text_delta.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/path.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/document/text_delta.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; extension TextNodeExtension on TextNode { bool allSatisfyBoldInSelection(Selection selection) => - allSatisfyInSelection(StyleKey.bold, selection); + allSatisfyInSelection(StyleKey.bold, true, selection); bool allSatisfyItalicInSelection(Selection selection) => - allSatisfyInSelection(StyleKey.italic, selection); + allSatisfyInSelection(StyleKey.italic, true, selection); bool allSatisfyUnderlineInSelection(Selection selection) => - allSatisfyInSelection(StyleKey.underline, selection); + allSatisfyInSelection(StyleKey.underline, true, selection); bool allSatisfyStrikethroughInSelection(Selection selection) => - allSatisfyInSelection(StyleKey.strikethrough, selection); + allSatisfyInSelection(StyleKey.strikethrough, true, selection); - bool allSatisfyInSelection(String styleKey, Selection selection) { + bool allSatisfyInSelection( + String styleKey, + dynamic value, + Selection selection, + ) { final ops = delta.whereType(); final startOffset = selection.isBackward ? selection.start.offset : selection.end.offset; @@ -33,7 +37,7 @@ extension TextNodeExtension on TextNode { if (start < endOffset && start + length > startOffset) { if (op.attributes == null || !op.attributes!.containsKey(styleKey) || - op.attributes![styleKey] == false) { + op.attributes![styleKey] != value) { return false; } } @@ -42,7 +46,11 @@ extension TextNodeExtension on TextNode { return true; } - bool allNotSatisfyInSelection(String styleKey, Selection selection) { + bool allNotSatisfyInSelection( + String styleKey, + dynamic value, + Selection selection, + ) { final ops = delta.whereType(); final startOffset = selection.isBackward ? selection.start.offset : selection.end.offset; @@ -57,7 +65,7 @@ extension TextNodeExtension on TextNode { if (start < endOffset && start + length > startOffset) { if (op.attributes != null && op.attributes!.containsKey(styleKey) && - op.attributes![styleKey] == true) { + op.attributes![styleKey] == value) { return false; } } @@ -69,23 +77,27 @@ extension TextNodeExtension on TextNode { extension TextNodesExtension on List { bool allSatisfyBoldInSelection(Selection selection) => - allSatisfyInSelection(StyleKey.bold, selection); + allSatisfyInSelection(StyleKey.bold, selection, true); bool allSatisfyItalicInSelection(Selection selection) => - allSatisfyInSelection(StyleKey.italic, selection); + allSatisfyInSelection(StyleKey.italic, selection, true); bool allSatisfyUnderlineInSelection(Selection selection) => - allSatisfyInSelection(StyleKey.underline, selection); + allSatisfyInSelection(StyleKey.underline, selection, true); bool allSatisfyStrikethroughInSelection(Selection selection) => - allSatisfyInSelection(StyleKey.strikethrough, selection); + allSatisfyInSelection(StyleKey.strikethrough, selection, true); - bool allSatisfyInSelection(String styleKey, Selection selection) { + bool allSatisfyInSelection( + String styleKey, + Selection selection, + dynamic value, + ) { if (isEmpty) { return false; } if (length == 1) { - return first.allSatisfyInSelection(styleKey, selection); + return first.allSatisfyInSelection(styleKey, value, selection); } else { for (var i = 0; i < length; i++) { final node = this[i]; @@ -105,7 +117,7 @@ extension TextNodesExtension on List { end: Position(path: node.path, offset: node.toRawString().length), ); } - if (!node.allSatisfyInSelection(styleKey, newSelection)) { + if (!node.allSatisfyInSelection(styleKey, value, newSelection)) { return false; } } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/infra/flowy_svg.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/infra/flowy_svg.dart similarity index 96% rename from frontend/app_flowy/packages/flowy_editor/lib/src/infra/flowy_svg.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/infra/flowy_svg.dart index d40a198b1a..cb60addaff 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/infra/flowy_svg.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/infra/flowy_svg.dart @@ -32,7 +32,7 @@ class FlowySvg extends StatelessWidget { child: SvgPicture.asset( 'assets/images/$name.svg', color: color, - package: 'flowy_editor', + package: 'appflowy_editor', fit: BoxFit.fill, ), ); diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/infra/html_converter.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/infra/html_converter.dart similarity index 98% rename from frontend/app_flowy/packages/flowy_editor/lib/src/infra/html_converter.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/infra/html_converter.dart index f56184a57c..fa49ee2e54 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/infra/html_converter.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/infra/html_converter.dart @@ -1,11 +1,11 @@ import 'dart:collection'; import 'dart:ui'; -import 'package:flowy_editor/src/document/attributes.dart'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/text_delta.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/extensions/color_extension.dart'; +import 'package:appflowy_editor/src/document/attributes.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/text_delta.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/extensions/color_extension.dart'; import 'package:flutter/material.dart'; import 'package:html/parser.dart' show parse; import 'package:html/dom.dart' as html; @@ -290,10 +290,10 @@ class HTMLToNodesConverter { List _handleUnorderedList(html.Element element) { final result = []; - element.children.forEach((child) { + for (var child in element.children) { result.addAll( _handleListElement(child, {"subtype": StyleKey.bulletedList})); - }); + } return result; } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/operation/operation.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/operation.dart similarity index 98% rename from frontend/app_flowy/packages/flowy_editor/lib/src/operation/operation.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/operation/operation.dart index fc5e7c66a3..d1a0024a98 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/operation/operation.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/operation.dart @@ -1,5 +1,4 @@ -import 'package:flowy_editor/src/document/attributes.dart'; -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; abstract class Operation { factory Operation.fromJson(Map map) { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/operation/transaction.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/transaction.dart similarity index 95% rename from frontend/app_flowy/packages/flowy_editor/lib/src/operation/transaction.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/operation/transaction.dart index 76e375e5f8..8527e15325 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/operation/transaction.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/transaction.dart @@ -1,6 +1,6 @@ import 'dart:collection'; import 'package:flutter/material.dart'; -import 'package:flowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; import './operation.dart'; /// A [Transaction] has a list of [Operation] objects that will be applied diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/operation/transaction_builder.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/transaction_builder.dart similarity index 80% rename from frontend/app_flowy/packages/flowy_editor/lib/src/operation/transaction_builder.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/operation/transaction_builder.dart index 68a46d8a93..1cc1ebfd2e 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/operation/transaction_builder.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/transaction_builder.dart @@ -1,19 +1,19 @@ import 'dart:collection'; import 'dart:math'; -import 'package:flowy_editor/src/document/attributes.dart'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/path.dart'; -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/document/text_delta.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/operation/operation.dart'; -import 'package:flowy_editor/src/operation/transaction.dart'; +import 'package:appflowy_editor/src/document/attributes.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/path.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/document/text_delta.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/operation/operation.dart'; +import 'package:appflowy_editor/src/operation/transaction.dart'; /// A [TransactionBuilder] is used to build the transaction from the state. -/// It will save make a snapshot of the cursor selection state automatically. -/// The cursor can be resorted if the transaction is undo. +/// It will save a snapshot of the cursor selection state automatically. +/// The cursor can be restored if the transaction is undo. class TransactionBuilder { final List operations = []; EditorState state; @@ -22,24 +22,24 @@ class TransactionBuilder { TransactionBuilder(this.state); - /// Commit the operations to the state + /// Commits the operations to the state commit() { final transaction = finish(); state.apply(transaction); } - /// Insert the nodes at the position of path. + /// Inserts the nodes at the position of path. insertNode(Path path, Node node) { insertNodes(path, [node]); } - /// Insert a sequence of nodes at the position of path. + /// Inserts a sequence of nodes at the position of path. insertNodes(Path path, List nodes) { beforeSelection = state.cursorSelection; add(InsertOperation(path, nodes.map((node) => node.deepClone()).toList())); } - /// Update the attributes of nodes. + /// Updates the attributes of nodes. updateNode(Node node, Attributes attributes) { beforeSelection = state.cursorSelection; @@ -51,7 +51,7 @@ class TransactionBuilder { )); } - /// Delete a node in the document. + /// Deletes a node in the document. deleteNode(Node node) { deleteNodesAtPath(node.path); } @@ -60,8 +60,8 @@ class TransactionBuilder { nodes.forEach(deleteNode); } - /// Delete a sequence of nodes at the path of the document. - /// The length specific the length of the following nodes to delete( + /// Deletes a sequence of nodes at the path of the document. + /// The length specifies the length of the following nodes to delete( /// including the start one). deleteNodesAtPath(Path path, [int length = 1]) { if (path.isEmpty) { @@ -112,7 +112,7 @@ class TransactionBuilder { ); } - /// Insert content at a specified index. + /// Inserts content at a specified index. /// Optionally, you may specify formatting attributes that are applied to the inserted string. /// By default, the formatting attributes before the insert position will be used. insertText(TextNode node, int index, String content, @@ -135,7 +135,7 @@ class TransactionBuilder { Position(path: node.path, offset: index + content.length)); } - /// Assign formatting attributes to a range of text. + /// Assigns formatting attributes to a range of text. formatText(TextNode node, int index, int length, Attributes attributes) { textEdit( node, @@ -145,7 +145,7 @@ class TransactionBuilder { afterSelection = beforeSelection; } - /// Delete length characters starting from index. + /// Deletes length characters starting from index. deleteText(TextNode node, int index, int length) { textEdit( node, @@ -180,7 +180,7 @@ class TransactionBuilder { ); } - /// Add an operation to the transaction. + /// Adds an operation to the transaction. /// This method will merge operations if they are both TextEdits. /// /// Also, this method will transform the path of the operations @@ -209,7 +209,7 @@ class TransactionBuilder { operations.add(op); } - /// Generate a immutable [Transaction] to apply or transmit. + /// Generates a immutable [Transaction] to apply or transmit. Transaction finish() { return Transaction( operations: UnmodifiableListView(operations), diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/editor/editor_entry.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/editor/editor_entry.dart similarity index 88% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/editor/editor_entry.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/editor/editor_entry.dart index 90ee326e8b..e71dc7c79b 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/editor/editor_entry.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/editor/editor_entry.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/service/render_plugin_service.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/service/render_plugin_service.dart'; class EditorEntryWidgetBuilder extends NodeWidgetBuilder { @override diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/bulleted_list_text.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/bulleted_list_text.dart similarity index 79% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/bulleted_list_text.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/bulleted_list_text.dart index 9586f1192c..74ee29ed44 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/bulleted_list_text.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/bulleted_list_text.dart @@ -1,11 +1,11 @@ -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/infra/flowy_svg.dart'; -import 'package:flowy_editor/src/render/rich_text/default_selectable.dart'; -import 'package:flowy_editor/src/render/rich_text/flowy_rich_text.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/render/selection/selectable.dart'; -import 'package:flowy_editor/src/service/render_plugin_service.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/infra/flowy_svg.dart'; +import 'package:appflowy_editor/src/render/rich_text/default_selectable.dart'; +import 'package:appflowy_editor/src/render/rich_text/flowy_rich_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/render/selection/selectable.dart'; +import 'package:appflowy_editor/src/service/render_plugin_service.dart'; import 'package:flutter/material.dart'; class BulletedListTextNodeWidgetBuilder extends NodeWidgetBuilder { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/checkbox_text.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/checkbox_text.dart similarity index 65% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/checkbox_text.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/checkbox_text.dart index bfcc938b8b..646bd4d408 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/checkbox_text.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/checkbox_text.dart @@ -1,12 +1,12 @@ -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/infra/flowy_svg.dart'; -import 'package:flowy_editor/src/operation/transaction_builder.dart'; -import 'package:flowy_editor/src/render/rich_text/default_selectable.dart'; -import 'package:flowy_editor/src/render/rich_text/flowy_rich_text.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/render/selection/selectable.dart'; -import 'package:flowy_editor/src/service/render_plugin_service.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/infra/flowy_svg.dart'; +import 'package:appflowy_editor/src/operation/transaction_builder.dart'; +import 'package:appflowy_editor/src/render/rich_text/default_selectable.dart'; +import 'package:appflowy_editor/src/render/rich_text/flowy_rich_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/render/selection/selectable.dart'; +import 'package:appflowy_editor/src/service/render_plugin_service.dart'; import 'package:flutter/material.dart'; class CheckboxNodeWidgetBuilder extends NodeWidgetBuilder { @@ -65,42 +65,45 @@ class _CheckboxNodeWidgetState extends State final check = widget.textNode.attributes.check; final topPadding = RichTextStyle.fromTextNode(widget.textNode).topPadding; return SizedBox( - width: defaultMaxTextNodeWidth, - child: Padding( - padding: EdgeInsets.only(bottom: defaultLinePadding), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - GestureDetector( - key: iconKey, - child: FlowySvg( - size: Size.square(_iconSize), - padding: EdgeInsets.only( - top: topPadding, right: _iconRightPadding), - name: check ? 'check' : 'uncheck', + width: defaultMaxTextNodeWidth, + child: Padding( + padding: EdgeInsets.only(bottom: defaultLinePadding), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + GestureDetector( + key: iconKey, + child: FlowySvg( + size: Size.square(_iconSize), + padding: EdgeInsets.only( + top: topPadding, + right: _iconRightPadding, ), - onTap: () { - debugPrint('[Checkbox] onTap...'); - TransactionBuilder(widget.editorState) - ..updateNode(widget.textNode, { - StyleKey.checkbox: !check, - }) - ..commit(); - }, + name: check ? 'check' : 'uncheck', ), - Expanded( - child: FlowyRichText( - key: _richTextKey, - placeholderText: 'To-do', - textNode: widget.textNode, - textSpanDecorator: _textSpanDecorator, - placeholderTextSpanDecorator: _textSpanDecorator, - editorState: widget.editorState, - ), + onTap: () { + debugPrint('[Checkbox] onTap...'); + TransactionBuilder(widget.editorState) + ..updateNode(widget.textNode, { + StyleKey.checkbox: !check, + }) + ..commit(); + }, + ), + Expanded( + child: FlowyRichText( + key: _richTextKey, + placeholderText: 'To-do', + textNode: widget.textNode, + textSpanDecorator: _textSpanDecorator, + placeholderTextSpanDecorator: _textSpanDecorator, + editorState: widget.editorState, ), - ], - ), - )); + ), + ], + ), + ), + ); } Widget _buildWithChildren(BuildContext context) { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/default_selectable.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/default_selectable.dart similarity index 85% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/default_selectable.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/default_selectable.dart index 0a0ed09f05..91b9cbf981 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/default_selectable.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/default_selectable.dart @@ -1,6 +1,6 @@ -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/render/selection/selectable.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/render/selection/selectable.dart'; import 'package:flutter/material.dart'; mixin DefaultSelectable { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/flowy_rich_text.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/flowy_rich_text.dart similarity index 83% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/flowy_rich_text.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/flowy_rich_text.dart index e53222cf5b..fb4dbdc4a1 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/flowy_rich_text.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/flowy_rich_text.dart @@ -3,15 +3,14 @@ import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/path.dart'; -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/document/text_delta.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/render/selection/selectable.dart'; -import 'package:flowy_editor/src/service/render_plugin_service.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/path.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/document/text_delta.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/render/selection/selectable.dart'; typedef FlowyTextSpanDecorator = TextSpan Function(TextSpan textSpan); @@ -166,26 +165,26 @@ class _FlowyRichTextState extends State with Selectable { } // unused now. - Widget _buildRichTextWithChildren(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - _buildSingleRichText(context), - ...widget.textNode.children - .map( - (child) => widget.editorState.service.renderPluginService - .buildPluginWidget( - NodeWidgetContext( - context: context, - node: child, - editorState: widget.editorState, - ), - ), - ) - .toList() - ], - ); - } + // Widget _buildRichTextWithChildren(BuildContext context) { + // return Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // _buildSingleRichText(context), + // ...widget.textNode.children + // .map( + // (child) => widget.editorState.service.renderPluginService + // .buildPluginWidget( + // NodeWidgetContext( + // context: context, + // node: child, + // editorState: widget.editorState, + // ), + // ), + // ) + // .toList() + // ], + // ); + // } @override Offset localToGlobal(Offset offset) { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/heading_text.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/heading_text.dart similarity index 84% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/heading_text.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/heading_text.dart index ddc7537476..050b330f8b 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/heading_text.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/heading_text.dart @@ -1,10 +1,10 @@ -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/render/rich_text/default_selectable.dart'; -import 'package:flowy_editor/src/render/rich_text/flowy_rich_text.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/render/selection/selectable.dart'; -import 'package:flowy_editor/src/service/render_plugin_service.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/render/rich_text/default_selectable.dart'; +import 'package:appflowy_editor/src/render/rich_text/flowy_rich_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/render/selection/selectable.dart'; +import 'package:appflowy_editor/src/service/render_plugin_service.dart'; import 'package:flutter/material.dart'; class HeadingTextNodeWidgetBuilder extends NodeWidgetBuilder { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/number_list_text.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/number_list_text.dart similarity index 80% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/number_list_text.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/number_list_text.dart index bd08a30d80..836da9b69e 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/number_list_text.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/number_list_text.dart @@ -1,11 +1,11 @@ -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/infra/flowy_svg.dart'; -import 'package:flowy_editor/src/render/rich_text/default_selectable.dart'; -import 'package:flowy_editor/src/render/rich_text/flowy_rich_text.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/render/selection/selectable.dart'; -import 'package:flowy_editor/src/service/render_plugin_service.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/infra/flowy_svg.dart'; +import 'package:appflowy_editor/src/render/rich_text/default_selectable.dart'; +import 'package:appflowy_editor/src/render/rich_text/flowy_rich_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/render/selection/selectable.dart'; +import 'package:appflowy_editor/src/service/render_plugin_service.dart'; import 'package:flutter/material.dart'; class NumberListTextNodeWidgetBuilder extends NodeWidgetBuilder { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/quoted_text.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/quoted_text.dart similarity index 80% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/quoted_text.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/quoted_text.dart index 59cafd82af..aa43be053a 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/quoted_text.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/quoted_text.dart @@ -1,11 +1,11 @@ -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/infra/flowy_svg.dart'; -import 'package:flowy_editor/src/render/rich_text/default_selectable.dart'; -import 'package:flowy_editor/src/render/rich_text/flowy_rich_text.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/render/selection/selectable.dart'; -import 'package:flowy_editor/src/service/render_plugin_service.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/infra/flowy_svg.dart'; +import 'package:appflowy_editor/src/render/rich_text/default_selectable.dart'; +import 'package:appflowy_editor/src/render/rich_text/flowy_rich_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/render/selection/selectable.dart'; +import 'package:appflowy_editor/src/service/render_plugin_service.dart'; import 'package:flutter/material.dart'; class QuotedTextNodeWidgetBuilder extends NodeWidgetBuilder { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/rich_text.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text.dart similarity index 73% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/rich_text.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text.dart index 765c3b95d4..d8dcfb91f6 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/rich_text.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text.dart @@ -1,11 +1,10 @@ -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/infra/flowy_svg.dart'; -import 'package:flowy_editor/src/render/rich_text/default_selectable.dart'; -import 'package:flowy_editor/src/render/rich_text/flowy_rich_text.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/render/selection/selectable.dart'; -import 'package:flowy_editor/src/service/render_plugin_service.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/render/rich_text/default_selectable.dart'; +import 'package:appflowy_editor/src/render/rich_text/flowy_rich_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/render/selection/selectable.dart'; +import 'package:appflowy_editor/src/service/render_plugin_service.dart'; import 'package:flutter/material.dart'; class RichTextNodeWidgetBuilder extends NodeWidgetBuilder { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/rich_text_style.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text_style.dart similarity index 95% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/rich_text_style.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text_style.dart index 31cbafc18b..7bd68c45e7 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/rich_text/rich_text_style.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text_style.dart @@ -1,7 +1,8 @@ -import 'package:flowy_editor/src/document/attributes.dart'; -import 'package:flowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/attributes.dart'; +import 'package:appflowy_editor/src/document/node.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:url_launcher/url_launcher_string.dart'; /// /// Supported partial rendering types: @@ -65,6 +66,8 @@ class StyleKey { double defaultMaxTextNodeWidth = 780.0; double defaultLinePadding = 8.0; double baseFontSize = 16.0; +String defaultHighlightColor = '0x6000BCF0'; +String defaultBackgroundColor = '0x00000000'; // TODO: customize. Map headingToFontSize = { StyleKey.h1: baseFontSize + 15, @@ -235,7 +238,6 @@ class RichTextStyle { var decorations = [TextDecoration.none]; if (attributes.underline || attributes.href != null) { decorations.add(TextDecoration.underline); - // TextDecoration.underline; } if (attributes.strikethrough) { decorations.add(TextDecoration.lineThrough); @@ -275,7 +277,7 @@ class RichTextStyle { if (href != null) { return TapGestureRecognizer() ..onTap = () async { - // FIXME: launch the url + await launchUrlString(href); }; } return null; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/selection/cursor_widget.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/selection/cursor_widget.dart similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/selection/cursor_widget.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/selection/cursor_widget.dart diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/selection/selectable.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/selection/selectable.dart similarity index 56% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/selection/selectable.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/selection/selectable.dart index bdea01b895..1c0c5a5d19 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/selection/selectable.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/selection/selectable.dart @@ -1,34 +1,41 @@ -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; import 'package:flutter/material.dart'; +/// [Selectable] is used for the editor to calculate the position +/// and size of the selection. +/// +/// The widget returned by NodeWidgetBuilder must be with [Selectable], +/// otherwise the [FlowySelectionService] will not work properly. /// mixin Selectable on State { - /// Returns a [List] of the [Rect] selection surrounded by start and end + /// Returns the [Selection] surrounded by start and end /// in current widget. /// /// [start] and [end] are the offsets under the global coordinate system. /// - /// The return result must be a [List] of the [Rect] - /// under the local coordinate system. Selection getSelectionInRange(Offset start, Offset end); + /// Returns a [List] of the [Rect] area within selection + /// in current widget. + /// + /// The return result must be a [List] of the [Rect] + /// under the local coordinate system. List getRectsInSelection(Selection selection); - /// Returns a [Rect] for the offset in current widget. + /// Returns [Position] for the offset in current widget. /// /// [start] is the offset of the global coordination system. + Position getPositionInOffset(Offset start); + + /// Returns [Rect] for the position in current widget. /// /// The return result must be an offset of the local coordinate system. - Position getPositionInOffset(Offset start); - Selection? getWorldBoundaryInOffset(Offset start) { - return null; - } - Rect? getCursorRectInPosition(Position position) { return null; } + /// Return global offset from local offset. Offset localToGlobal(Offset offset); Position start(); @@ -36,9 +43,15 @@ mixin Selectable on State { /// For [TextNode] only. /// - /// Returns a [TextSelection] or [Null]. - /// /// Only the widget rendered by [TextNode] need to implement the detail, /// and the rest can return null. TextSelection? getTextSelectionInSelection(Selection selection) => null; + + /// For [TextNode] only. + /// + /// Only the widget rendered by [TextNode] need to implement the detail, + /// and the rest can return null. + Selection? getWorldBoundaryInOffset(Offset start) { + return null; + } } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/selection/selection_widget.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/selection/selection_widget.dart similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/lib/src/render/selection/selection_widget.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/render/selection/selection_widget.dart diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/selection/toolbar_widget.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/selection/toolbar_widget.dart new file mode 100644 index 0000000000..dfc5c5c971 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/selection/toolbar_widget.dart @@ -0,0 +1,217 @@ +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:flutter/material.dart'; + +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/infra/flowy_svg.dart'; +import 'package:appflowy_editor/src/service/default_text_operations/format_rich_text_style.dart'; + +typedef ToolbarEventHandler = void Function(EditorState editorState); + +typedef ToolbarEventHandlers = Map; + +ToolbarEventHandlers defaultToolbarEventHandlers = { + 'bold': (editorState) => formatBold(editorState), + 'italic': (editorState) => formatItalic(editorState), + 'strikethrough': (editorState) => formatStrikethrough(editorState), + 'underline': (editorState) => formatUnderline(editorState), + 'quote': (editorState) => formatQuote(editorState), + 'bulleted_list': (editorState) => formatBulletedList(editorState), + 'highlight': (editorState) => formatHighlight(editorState), + 'Text': (editorState) => formatText(editorState), + 'h1': (editorState) => formatHeading(editorState, StyleKey.h1), + 'h2': (editorState) => formatHeading(editorState, StyleKey.h2), + 'h3': (editorState) => formatHeading(editorState, StyleKey.h3), +}; + +List defaultListToolbarEventNames = [ + 'Text', + 'H1', + 'H2', + 'H3', +]; + +mixin ToolbarMixin on State { + void hide(); +} + +class ToolbarWidget extends StatefulWidget { + const ToolbarWidget({ + Key? key, + required this.editorState, + required this.layerLink, + required this.offset, + required this.handlers, + }) : super(key: key); + + final EditorState editorState; + final LayerLink layerLink; + final Offset offset; + final ToolbarEventHandlers handlers; + + @override + State createState() => _ToolbarWidgetState(); +} + +class _ToolbarWidgetState extends State with ToolbarMixin { + // final GlobalKey _listToolbarKey = GlobalKey(); + + final toolbarHeight = 32.0; + final topPadding = 5.0; + + final listToolbarWidth = 60.0; + final listToolbarHeight = 120.0; + + final cornerRadius = 8.0; + + OverlayEntry? _listToolbarOverlay; + + @override + Widget build(BuildContext context) { + return Positioned( + top: widget.offset.dx, + left: widget.offset.dy, + child: CompositedTransformFollower( + link: widget.layerLink, + showWhenUnlinked: true, + offset: widget.offset, + child: _buildToolbar(context), + ), + ); + } + + @override + void hide() { + _listToolbarOverlay?.remove(); + _listToolbarOverlay = null; + } + + Widget _buildToolbar(BuildContext context) { + return Material( + borderRadius: BorderRadius.circular(cornerRadius), + color: const Color(0xFF333333), + child: SizedBox( + height: toolbarHeight, + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // _listToolbar(context), + _centerToolbarIcon('h1', tooltipMessage: 'Heading 1'), + _centerToolbarIcon('h2', tooltipMessage: 'Heading 2'), + _centerToolbarIcon('h3', tooltipMessage: 'Heading 3'), + _centerToolbarIcon('divider', width: 2), + _centerToolbarIcon('bold', tooltipMessage: 'Bold'), + _centerToolbarIcon('italic', tooltipMessage: 'Italic'), + _centerToolbarIcon('strikethrough', + tooltipMessage: 'Strikethrough'), + _centerToolbarIcon('underline', tooltipMessage: 'Underline'), + _centerToolbarIcon('divider', width: 2), + _centerToolbarIcon('quote', tooltipMessage: 'Quote'), + // _centerToolbarIcon('number_list'), + _centerToolbarIcon('bulleted_list', + tooltipMessage: 'Bulleted List'), + _centerToolbarIcon('divider', width: 2), + _centerToolbarIcon('highlight', tooltipMessage: 'Highlight'), + ], + ), + ), + ); + } + + // Widget _listToolbar(BuildContext context) { + // return _centerToolbarIcon( + // 'quote', + // key: _listToolbarKey, + // width: listToolbarWidth, + // onTap: () => _onTapListToolbar(context), + // ); + // } + + Widget _centerToolbarIcon(String name, + {Key? key, String? tooltipMessage, double? width, VoidCallback? onTap}) { + return Tooltip( + key: key, + preferBelow: false, + message: tooltipMessage ?? '', + child: MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + onTap: onTap ?? () => _onTap(name), + child: SizedBox.fromSize( + size: + Size(toolbarHeight - (width != null ? 20 : 0), toolbarHeight), + child: Center( + child: FlowySvg( + size: Size(width ?? 20, 20), + name: 'toolbar/$name', + ), + ), + ), + ), + )); + } + + // void _onTapListToolbar(BuildContext context) { + // // TODO: implement more detailed UI. + // final items = defaultListToolbarEventNames; + // final renderBox = + // _listToolbarKey.currentContext?.findRenderObject() as RenderBox; + // final offset = renderBox + // .localToGlobal(Offset.zero) + // .translate(0, toolbarHeight - cornerRadius); + // final rect = offset & Size(listToolbarWidth, listToolbarHeight); + + // _listToolbarOverlay?.remove(); + // _listToolbarOverlay = OverlayEntry(builder: (context) { + // return Positioned.fromRect( + // rect: rect, + // child: Material( + // borderRadius: BorderRadius.only( + // bottomLeft: Radius.circular(cornerRadius), + // bottomRight: Radius.circular(cornerRadius), + // ), + // color: const Color(0xFF333333), + // child: SingleChildScrollView( + // child: ListView.builder( + // itemExtent: toolbarHeight, + // padding: const EdgeInsets.only(bottom: 10.0), + // shrinkWrap: true, + // itemCount: items.length, + // itemBuilder: ((context, index) { + // return ListTile( + // contentPadding: const EdgeInsets.only( + // left: 3.0, + // right: 3.0, + // ), + // minVerticalPadding: 0.0, + // title: FittedBox( + // fit: BoxFit.scaleDown, + // child: Text( + // items[index], + // textAlign: TextAlign.center, + // style: const TextStyle( + // color: Colors.white, + // ), + // ), + // ), + // onTap: () { + // _onTap(items[index]); + // }, + // ); + // }), + // ), + // ), + // ), + // ); + // }); + // // TODO: disable scrolling. + // Overlay.of(context)?.insert(_listToolbarOverlay!); + // } + + void _onTap(String eventName) { + if (defaultToolbarEventHandlers.containsKey(eventName)) { + defaultToolbarEventHandlers[eventName]!(widget.editorState); + return; + } + assert(false, 'Could not find the event handler for $eventName'); + } +} diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart similarity index 81% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart index 64cd4f332e..c4f765f2f4 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart @@ -1,12 +1,12 @@ -import 'package:flowy_editor/src/document/attributes.dart'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/extensions/text_node_extensions.dart'; -import 'package:flowy_editor/src/extensions/path_extensions.dart'; -import 'package:flowy_editor/src/operation/transaction_builder.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/document/attributes.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/extensions/text_node_extensions.dart'; +import 'package:appflowy_editor/src/extensions/path_extensions.dart'; +import 'package:appflowy_editor/src/operation/transaction_builder.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; void insertHeadingAfterSelection(EditorState editorState, String heading) { insertTextNodeAfterSelection(editorState, { @@ -139,7 +139,25 @@ bool formatStrikethrough(EditorState editorState) { return formatRichTextPartialStyle(editorState, StyleKey.strikethrough); } -bool formatRichTextPartialStyle(EditorState editorState, String styleKey) { +bool formatHighlight(EditorState editorState) { + bool value = _allSatisfyInSelection( + editorState, StyleKey.backgroundColor, defaultHighlightColor); + return formatRichTextPartialStyle(editorState, StyleKey.backgroundColor, + customValue: value ? defaultBackgroundColor : defaultHighlightColor); +} + +bool formatRichTextPartialStyle(EditorState editorState, String styleKey, + {Object? customValue}) { + Attributes attributes = { + styleKey: customValue ?? + !_allSatisfyInSelection(editorState, styleKey, customValue ?? true), + }; + + return formatRichTextStyle(editorState, attributes); +} + +bool _allSatisfyInSelection( + EditorState editorState, String styleKey, dynamic value) { final selection = editorState.service.selectionService.currentSelection.value; final nodes = editorState.service.selectionService.currentSelectedNodes; final textNodes = nodes.whereType().toList(growable: false); @@ -148,12 +166,7 @@ bool formatRichTextPartialStyle(EditorState editorState, String styleKey) { return false; } - bool value = !textNodes.allSatisfyInSelection(styleKey, selection); - Attributes attributes = { - styleKey: value, - }; - - return formatRichTextStyle(editorState, attributes); + return textNodes.allSatisfyInSelection(styleKey, selection, value); } bool formatRichTextStyle(EditorState editorState, Attributes attributes) { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/editor_service.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/editor_service.dart similarity index 59% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/editor_service.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/editor_service.dart index b2d649d246..89dba08f9e 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/editor_service.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/editor_service.dart @@ -1,20 +1,20 @@ -import 'package:flowy_editor/src/service/internal_key_event_handlers/default_key_event_handlers.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/default_key_event_handlers.dart'; import 'package:flutter/material.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/render/editor/editor_entry.dart'; -import 'package:flowy_editor/src/render/rich_text/bulleted_list_text.dart'; -import 'package:flowy_editor/src/render/rich_text/checkbox_text.dart'; -import 'package:flowy_editor/src/render/rich_text/heading_text.dart'; -import 'package:flowy_editor/src/render/rich_text/number_list_text.dart'; -import 'package:flowy_editor/src/render/rich_text/quoted_text.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text.dart'; -import 'package:flowy_editor/src/service/input_service.dart'; -import 'package:flowy_editor/src/service/keyboard_service.dart'; -import 'package:flowy_editor/src/service/render_plugin_service.dart'; -import 'package:flowy_editor/src/service/scroll_service.dart'; -import 'package:flowy_editor/src/service/selection_service.dart'; -import 'package:flowy_editor/src/service/toolbar_service.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/render/editor/editor_entry.dart'; +import 'package:appflowy_editor/src/render/rich_text/bulleted_list_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/checkbox_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/heading_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/number_list_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/quoted_text.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text.dart'; +import 'package:appflowy_editor/src/service/input_service.dart'; +import 'package:appflowy_editor/src/service/keyboard_service.dart'; +import 'package:appflowy_editor/src/service/render_plugin_service.dart'; +import 'package:appflowy_editor/src/service/scroll_service.dart'; +import 'package:appflowy_editor/src/service/selection_service.dart'; +import 'package:appflowy_editor/src/service/toolbar_service.dart'; NodeWidgetBuilders defaultBuilders = { 'editor': EditorEntryWidgetBuilder(), @@ -26,8 +26,8 @@ NodeWidgetBuilders defaultBuilders = { 'text/quote': QuotedTextNodeWidgetBuilder(), }; -class FlowyEditor extends StatefulWidget { - const FlowyEditor({ +class AppFlowyEditor extends StatefulWidget { + const AppFlowyEditor({ Key? key, required this.editorState, this.customBuilders = const {}, @@ -40,13 +40,13 @@ class FlowyEditor extends StatefulWidget { final NodeWidgetBuilders customBuilders; /// Keyboard event handlers. - final List keyEventHandlers; + final List keyEventHandlers; @override - State createState() => _FlowyEditorState(); + State createState() => _AppFlowyEditorState(); } -class _FlowyEditorState extends State { +class _AppFlowyEditorState extends State { EditorState get editorState => widget.editorState; @override @@ -57,7 +57,7 @@ class _FlowyEditorState extends State { } @override - void didUpdateWidget(covariant FlowyEditor oldWidget) { + void didUpdateWidget(covariant AppFlowyEditor oldWidget) { super.didUpdateWidget(oldWidget); if (editorState.service != oldWidget.editorState.service) { @@ -67,15 +67,15 @@ class _FlowyEditorState extends State { @override Widget build(BuildContext context) { - return FlowyScroll( + return AppFlowyScroll( key: editorState.service.scrollServiceKey, - child: FlowySelection( + child: AppFlowySelection( key: editorState.service.selectionServiceKey, editorState: editorState, - child: FlowyInput( + child: AppFlowyInput( key: editorState.service.inputServiceKey, editorState: editorState, - child: FlowyKeyboard( + child: AppFlowyKeyboard( key: editorState.service.keyboardServiceKey, handlers: [ ...defaultKeyEventHandlers, @@ -99,7 +99,7 @@ class _FlowyEditorState extends State { )); } - FlowyRenderPlugin _createRenderPlugin() => FlowyRenderPlugin( + AppFlowyRenderPlugin _createRenderPlugin() => AppFlowyRenderPlugin( editorState: editorState, builders: { ...defaultBuilders, diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/input_service.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/input_service.dart similarity index 83% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/input_service.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/input_service.dart index da755ab346..95ed3546b8 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/input_service.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/input_service.dart @@ -1,21 +1,46 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/extensions/node_extensions.dart'; -import 'package:flowy_editor/src/operation/transaction_builder.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/extensions/node_extensions.dart'; +import 'package:appflowy_editor/src/operation/transaction_builder.dart'; -abstract class FlowyInputService { +/// [AppFlowyInputService] is responsible for processing text input, +/// including text insertion, deletion and replacement. +/// +/// Usually, this service can be obtained by the following code. +/// ```dart +/// final inputService = editorState.service.inputService; +/// +/// /** update text editing value*/ +/// inputService?.attach(...); +/// +/// /** apply text editing deltas*/ +/// inputService?.apply(...); +/// ``` +/// +abstract class AppFlowyInputService { + /// Updates the [TextEditingValue] of the text currently being edited. + /// + /// Note that if there are IME-related requirements, + /// please config `composing` value within [TextEditingValue] void attach(TextEditingValue textEditingValue); + + /// Applies insertion, deletion and replacement + /// to the text currently being edited. + /// + /// For more information, please check [TextEditingDelta]. void apply(List deltas); + + /// Closes the editing state of the text currently being edited. void close(); } -/// process input -class FlowyInput extends StatefulWidget { - const FlowyInput({ +/// Processes text input +class AppFlowyInput extends StatefulWidget { + const AppFlowyInput({ Key? key, required this.editorState, required this.child, @@ -25,11 +50,11 @@ class FlowyInput extends StatefulWidget { final Widget child; @override - State createState() => _FlowyInputState(); + State createState() => _AppFlowyInputState(); } -class _FlowyInputState extends State - implements FlowyInputService, DeltaTextInputClient { +class _AppFlowyInputState extends State + implements AppFlowyInputService, DeltaTextInputClient { TextInputConnection? _textInputConnection; TextRange? _composingTextRange; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart similarity index 97% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart index 8820b4492f..e6f474668a 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/arrow_keys_handler.dart @@ -1,4 +1,4 @@ -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -103,7 +103,7 @@ KeyEventResult _handleShiftKey(EditorState editorState, RawKeyEvent event) { return KeyEventResult.ignored; } -FlowyKeyEventHandler arrowKeysHandler = (editorState, event) { +AppFlowyKeyEventHandler arrowKeysHandler = (editorState, event) { if (event.isShiftPressed) { return _handleShiftKey(editorState, event); } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart similarity index 97% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart index 00826e41f7..61f07fcf9f 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart @@ -1,6 +1,6 @@ -import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_editor/src/infra/html_converter.dart'; -import 'package:flowy_editor/src/document/node_iterator.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/infra/html_converter.dart'; +import 'package:appflowy_editor/src/document/node_iterator.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:rich_clipboard/rich_clipboard.dart'; @@ -106,7 +106,7 @@ _pasteMultipleLinesInText( if (tailNodes.last.type == "text") { final tailTextNode = tailNodes.last as TextNode; tailTextNode.delta = tailTextNode.delta + remain; - } else if (remain.length > 0) { + } else if (remain.isNotEmpty) { tailNodes.add(TextNode(type: "text", delta: remain)); } } else { @@ -304,7 +304,7 @@ _deleteSelectedContent(EditorState editorState) { tb.commit(); } -FlowyKeyEventHandler copyPasteKeysHandler = (editorState, event) { +AppFlowyKeyEventHandler copyPasteKeysHandler = (editorState, event) { if (event.isMetaPressed && event.logicalKey == LogicalKeyboardKey.keyC) { _handleCopy(editorState); return KeyEventResult.handled; diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart new file mode 100644 index 0000000000..468eda4e98 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart @@ -0,0 +1,24 @@ +import 'package:appflowy_editor/src/service/internal_key_event_handlers/arrow_keys_handler.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/copy_paste_handler.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/delete_text_handler.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/redo_undo_handler.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/slash_handler.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/whitespace_handler.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/select_all_handler.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/page_up_down_handler.dart'; +import 'package:appflowy_editor/src/service/keyboard_service.dart'; + +List defaultKeyEventHandlers = [ + deleteTextHandler, + slashShortcutHandler, + arrowKeysHandler, + copyPasteKeysHandler, + redoUndoKeysHandler, + enterWithoutShiftInTextNodesHandler, + updateTextStyleByCommandXHandler, + whiteSpaceHandler, + selectAllHandler, + pageUpDownHandler, +]; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/delete_text_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/delete_text_handler.dart similarity index 97% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/delete_text_handler.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/delete_text_handler.dart index ccddff27be..3accae0186 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/delete_text_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/delete_text_handler.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) { var selection = editorState.service.selectionService.currentSelection.value; @@ -150,7 +150,7 @@ void _deleteNodes(TransactionBuilder transactionBuilder, } // Handle delete text. -FlowyKeyEventHandler deleteTextHandler = (editorState, event) { +AppFlowyKeyEventHandler deleteTextHandler = (editorState, event) { if (event.logicalKey == LogicalKeyboardKey.backspace) { return _handleBackspace(editorState, event); } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart similarity index 87% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart index d58147f578..04540b8754 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart @@ -1,14 +1,14 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flowy_editor/src/document/attributes.dart'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/extensions/path_extensions.dart'; -import 'package:flowy_editor/src/operation/transaction_builder.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/service/keyboard_service.dart'; +import 'package:appflowy_editor/src/document/attributes.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/extensions/path_extensions.dart'; +import 'package:appflowy_editor/src/operation/transaction_builder.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/service/keyboard_service.dart'; /// Handle some cases where enter is pressed and shift is not pressed. /// @@ -18,7 +18,7 @@ import 'package:flowy_editor/src/service/keyboard_service.dart'; /// 2. Single selection and the selected node is [TextNode] /// 2.1 split the node into two nodes with style /// 2.2 or insert a empty text node before. -FlowyKeyEventHandler enterWithoutShiftInTextNodesHandler = +AppFlowyKeyEventHandler enterWithoutShiftInTextNodesHandler = (editorState, event) { if (event.logicalKey != LogicalKeyboardKey.enter || event.isShiftPressed) { return KeyEventResult.ignored; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/page_up_down_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/page_up_down_handler.dart similarity index 87% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/page_up_down_handler.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/page_up_down_handler.dart index 18ab2d23ee..d33e290d8e 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/page_up_down_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/page_up_down_handler.dart @@ -1,8 +1,8 @@ -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -FlowyKeyEventHandler pageUpDownHandler = (editorState, event) { +AppFlowyKeyEventHandler pageUpDownHandler = (editorState, event) { if (event.logicalKey == LogicalKeyboardKey.pageUp) { final scrollHeight = editorState.service.scrollService?.onePageHeight; final scrollService = editorState.service.scrollService; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/redo_undo_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/redo_undo_handler.dart similarity index 72% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/redo_undo_handler.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/redo_undo_handler.dart index 37892d9572..268697640a 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/redo_undo_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/redo_undo_handler.dart @@ -1,8 +1,8 @@ -import 'package:flowy_editor/src/service/keyboard_service.dart'; +import 'package:appflowy_editor/src/service/keyboard_service.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -FlowyKeyEventHandler redoUndoKeysHandler = (editorState, event) { +AppFlowyKeyEventHandler redoUndoKeysHandler = (editorState, event) { if (event.isMetaPressed && event.logicalKey == LogicalKeyboardKey.keyZ) { if (event.isShiftPressed) { editorState.undoManager.redo(); diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/select_all_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/select_all_handler.dart similarity index 86% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/select_all_handler.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/select_all_handler.dart index f99569218c..8ffd2d176e 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/select_all_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/select_all_handler.dart @@ -1,4 +1,4 @@ -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -18,7 +18,7 @@ KeyEventResult _selectAll(EditorState editorState) { return KeyEventResult.handled; } -FlowyKeyEventHandler selectAllHandler = (editorState, event) { +AppFlowyKeyEventHandler selectAllHandler = (editorState, event) { if (event.isMetaPressed && event.logicalKey == LogicalKeyboardKey.keyA) { return _selectAll(editorState); } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/slash_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/slash_handler.dart similarity index 95% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/slash_handler.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/slash_handler.dart index 093318813d..a13d203450 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/slash_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/slash_handler.dart @@ -1,13 +1,13 @@ import 'dart:math'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/infra/flowy_svg.dart'; -import 'package:flowy_editor/src/operation/transaction_builder.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/service/default_text_operations/format_rich_text_style.dart'; -import 'package:flowy_editor/src/service/keyboard_service.dart'; -import 'package:flowy_editor/src/extensions/node_extensions.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/infra/flowy_svg.dart'; +import 'package:appflowy_editor/src/operation/transaction_builder.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/service/default_text_operations/format_rich_text_style.dart'; +import 'package:appflowy_editor/src/service/keyboard_service.dart'; +import 'package:appflowy_editor/src/extensions/node_extensions.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -67,7 +67,7 @@ final List _popupListItems = [ OverlayEntry? _popupListOverlay; EditorState? _editorState; bool _selectionChangeBySlash = false; -FlowyKeyEventHandler slashShortcutHandler = (editorState, event) { +AppFlowyKeyEventHandler slashShortcutHandler = (editorState, event) { if (event.logicalKey != LogicalKeyboardKey.slash) { return KeyEventResult.ignored; } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart similarity index 69% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart index 4dab96e54a..0eb926525b 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart @@ -1,11 +1,12 @@ import 'package:flutter/material.dart'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/service/default_text_operations/format_rich_text_style.dart'; -import 'package:flowy_editor/src/service/keyboard_service.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/service/default_text_operations/format_rich_text_style.dart'; +import 'package:appflowy_editor/src/service/keyboard_service.dart'; import 'package:flutter/services.dart'; -FlowyKeyEventHandler updateTextStyleByCommandXHandler = (editorState, event) { +AppFlowyKeyEventHandler updateTextStyleByCommandXHandler = + (editorState, event) { if (!event.isMetaPressed) { return KeyEventResult.ignored; } @@ -31,6 +32,10 @@ FlowyKeyEventHandler updateTextStyleByCommandXHandler = (editorState, event) { event.isShiftPressed) { formatStrikethrough(editorState); return KeyEventResult.handled; + } else if (event.logicalKey == LogicalKeyboardKey.keyH && + event.isShiftPressed) { + formatHighlight(editorState); + return KeyEventResult.handled; } return KeyEventResult.ignored; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/whitespace_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/whitespace_handler.dart similarity index 87% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/whitespace_handler.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/whitespace_handler.dart index 0b0b834936..68e706128c 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/whitespace_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/whitespace_handler.dart @@ -1,13 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/operation/transaction_builder.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/service/keyboard_service.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/operation/transaction_builder.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/service/keyboard_service.dart'; @visibleForTesting List get checkboxListSymbols => _checkboxListSymbols; @@ -20,7 +20,7 @@ const _bulletedListSymbols = ['*', '-']; const _checkboxListSymbols = ['[x]', '-[x]']; const _unCheckboxListSymbols = ['[]', '-[]']; -FlowyKeyEventHandler whiteSpaceHandler = (editorState, event) { +AppFlowyKeyEventHandler whiteSpaceHandler = (editorState, event) { if (event.logicalKey != LogicalKeyboardKey.space) { return KeyEventResult.ignored; } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/keyboard_service.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/keyboard_service.dart similarity index 59% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/keyboard_service.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/keyboard_service.dart index b7573e4ed6..267cd782d8 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/keyboard_service.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/keyboard_service.dart @@ -1,22 +1,48 @@ -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; -abstract class FlowyKeyboardService { +/// [AppFlowyKeyboardService] is responsible for processing shortcut keys, +/// like command, shift, control keys. +/// +/// Usually, this service can be obtained by the following code. +/// ```dart +/// final keyboardService = editorState.service.keyboardService; +/// +/// /** Simulates shortcut key input*/ +/// keyboardService?.onKey(...); +/// +/// /** Enables or disables this service */ +/// keyboardService?.enable(); +/// keyboardService?.disable(); +/// ``` +/// +abstract class AppFlowyKeyboardService { + /// Processes shortcut key input. KeyEventResult onKey(RawKeyEvent event); + + /// Enables shortcuts service. void enable(); + + /// Disables shortcuts service. + /// + /// In some cases, if your custom component needs to monitor + /// keyboard events separately, + /// you can disable the keyboard service of flowy_editor. + /// But you need to call the `enable` function to restore after exiting + /// your custom component, otherwise the keyboard service will fails. void disable(); } -typedef FlowyKeyEventHandler = KeyEventResult Function( +typedef AppFlowyKeyEventHandler = KeyEventResult Function( EditorState editorState, RawKeyEvent event, ); /// Process keyboard events -class FlowyKeyboard extends StatefulWidget { - const FlowyKeyboard({ +class AppFlowyKeyboard extends StatefulWidget { + const AppFlowyKeyboard({ Key? key, required this.handlers, required this.editorState, @@ -25,14 +51,14 @@ class FlowyKeyboard extends StatefulWidget { final EditorState editorState; final Widget child; - final List handlers; + final List handlers; @override - State createState() => _FlowyKeyboardState(); + State createState() => _AppFlowyKeyboardState(); } -class _FlowyKeyboardState extends State - implements FlowyKeyboardService { +class _AppFlowyKeyboardState extends State + implements AppFlowyKeyboardService { final FocusNode _focusNode = FocusNode(debugLabel: 'flowy_keyboard_service'); bool isFocus = true; diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/render_plugin_service.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/render_plugin_service.dart similarity index 92% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/render_plugin_service.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/render_plugin_service.dart index b6f9414a9e..64b1a9c634 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/render_plugin_service.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/render_plugin_service.dart @@ -1,5 +1,5 @@ -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -13,11 +13,11 @@ abstract class NodeWidgetBuilder { typedef NodeWidgetBuilders = Map; -abstract class FlowyRenderPluginService { +abstract class AppFlowyRenderPluginService { /// Register render plugin with specified [name]. /// /// [name] should be [Node].type - /// or [Node].type + '/' + [Node].attributes['subtype']. + /// or `[Node].type + '/' + [Node].attributes['subtype']`. /// /// e.g. 'text', 'text/checkbox', or 'text/heading' /// @@ -55,8 +55,8 @@ class NodeWidgetContext { } } -class FlowyRenderPlugin extends FlowyRenderPluginService { - FlowyRenderPlugin({ +class AppFlowyRenderPlugin extends AppFlowyRenderPluginService { + AppFlowyRenderPlugin({ required this.editorState, required NodeWidgetBuilders builders, }) { diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/scroll_service.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/scroll_service.dart similarity index 59% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/scroll_service.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/scroll_service.dart index 199249b715..9fba0ec293 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/scroll_service.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/scroll_service.dart @@ -1,24 +1,51 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; -import 'package:flowy_editor/src/extensions/object_extensions.dart'; +import 'package:appflowy_editor/src/extensions/object_extensions.dart'; -abstract class FlowyScrollService { +/// [AppFlowyScrollService] is responsible for processing document scrolling. +/// +/// Usually, this service can be obtained by the following code. +/// ```dart +/// final keyboardService = editorState.service.scrollService; +/// ``` +/// +abstract class AppFlowyScrollService { + /// Returns the offset of the current document on the vertical axis. double get dy; + + /// Returns the height of the current document. double? get onePageHeight; + /// Returns the number of pages in the current document. int? get page; + /// Returns the maximum scroll height on the vertical axis. double get maxScrollExtent; + + /// Returns the minimum scroll height on the vertical axis. double get minScrollExtent; + /// Scrolls to the specified position. + /// + /// This function will filter illegal values. + /// Only within the range of minScrollExtent and maxScrollExtent are legal values. void scrollTo(double dy); + /// Enables scroll service. void enable(); + + /// Disables scroll service. + /// + /// In some cases, you can disable scroll service of flowy_editor + /// when your custom component appears, + /// + /// But you need to call the `enable` function to restore after exiting + /// your custom component, otherwise the scroll service will fails. void disable(); } -class FlowyScroll extends StatefulWidget { - const FlowyScroll({ +class AppFlowyScroll extends StatefulWidget { + const AppFlowyScroll({ Key? key, required this.child, }) : super(key: key); @@ -26,11 +53,11 @@ class FlowyScroll extends StatefulWidget { final Widget child; @override - State createState() => _FlowyScrollState(); + State createState() => _AppFlowyScrollState(); } -class _FlowyScrollState extends State - implements FlowyScrollService { +class _AppFlowyScrollState extends State + implements AppFlowyScrollService { final _scrollController = ScrollController(); final _scrollViewKey = GlobalKey(); diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/selection/selection_gesture.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/selection/selection_gesture.dart similarity index 100% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/selection/selection_gesture.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/selection/selection_gesture.dart diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/selection_service.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/selection_service.dart similarity index 83% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/selection_service.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/selection_service.dart index a256d71f03..bcce83a0c6 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/selection_service.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/selection_service.dart @@ -1,20 +1,19 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/node_iterator.dart'; -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/extensions/node_extensions.dart'; -import 'package:flowy_editor/src/extensions/object_extensions.dart'; -import 'package:flowy_editor/src/extensions/path_extensions.dart'; -import 'package:flowy_editor/src/render/selection/cursor_widget.dart'; -import 'package:flowy_editor/src/render/selection/selectable.dart'; -import 'package:flowy_editor/src/render/selection/selection_widget.dart'; -import 'package:flowy_editor/src/service/selection/selection_gesture.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/node_iterator.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/extensions/node_extensions.dart'; +import 'package:appflowy_editor/src/extensions/object_extensions.dart'; +import 'package:appflowy_editor/src/extensions/path_extensions.dart'; +import 'package:appflowy_editor/src/render/selection/cursor_widget.dart'; +import 'package:appflowy_editor/src/render/selection/selectable.dart'; +import 'package:appflowy_editor/src/render/selection/selection_widget.dart'; +import 'package:appflowy_editor/src/service/selection/selection_gesture.dart'; -/// [FlowySelectionService] is responsible for processing +/// [AppFlowySelectionService] is responsible for processing /// the [Selection] changes and updates. /// /// Usually, this service can be obtained by the following code. @@ -28,7 +27,7 @@ import 'package:flowy_editor/src/service/selection/selection_gesture.dart'; /// final nodes = selectionService.currentSelectedNodes; /// ``` /// -abstract class FlowySelectionService { +abstract class AppFlowySelectionService { /// The current [Selection] in editor. /// /// The value is null if there is no nodes are selected. @@ -40,9 +39,9 @@ abstract class FlowySelectionService { /// The result are ordered from back to front if the selection is forward. /// The result are ordered from front to back if the selection is backward. /// - /// For example, Here is an array of selected nodes, [n1, n2, n3]. - /// The result will be [n3, n2, n1] if the selection is forward, - /// and [n1, n2, n3] if the selection is backward. + /// For example, Here is an array of selected nodes, `[n1, n2, n3]`. + /// The result will be `[n3, n2, n1]` if the selection is forward, + /// and `[n1, n2, n3]` if the selection is backward. /// /// Returns empty result if there is no nodes are selected. List get currentSelectedNodes; @@ -76,11 +75,11 @@ abstract class FlowySelectionService { List get selectionRects; } -class FlowySelection extends StatefulWidget { - const FlowySelection({ +class AppFlowySelection extends StatefulWidget { + const AppFlowySelection({ Key? key, this.cursorColor = Colors.black, - this.selectionColor = const Color.fromARGB(60, 61, 61, 213), + this.selectionColor = const Color.fromARGB(53, 111, 201, 231), required this.editorState, required this.child, }) : super(key: key); @@ -91,12 +90,12 @@ class FlowySelection extends StatefulWidget { final Color selectionColor; @override - State createState() => _FlowySelectionState(); + State createState() => _AppFlowySelectionState(); } -class _FlowySelectionState extends State +class _AppFlowySelectionState extends State with WidgetsBindingObserver - implements FlowySelectionService { + implements AppFlowySelectionService { final _cursorKey = GlobalKey(debugLabel: 'cursor'); @override @@ -104,7 +103,7 @@ class _FlowySelectionState extends State final List _selectionAreas = []; final List _cursorAreas = []; - OverlayEntry? _debugOverlay; + // OverlayEntry? _debugOverlay; /// Pan Offset? _panStartOffset; @@ -456,8 +455,8 @@ class _FlowySelectionState extends State final topLimit = size * 0.3; final bottomLimit = size * 0.8; - /// TODO: It is necessary to calculate the relative speed - /// according to the gap and move forward more gently. + // TODO: It is necessary to calculate the relative speed + // according to the gap and move forward more gently. if (rect.top >= bottomLimit) { if (selection.isSingle) { editorState.service.scrollService?.scrollTo(dy + size * 0.2); @@ -517,38 +516,38 @@ class _FlowySelectionState extends State void _showDebugLayerIfNeeded({Offset? offset}) { // remove false to show debug overlay. - if (kDebugMode && false) { - _debugOverlay?.remove(); - if (offset != null) { - _debugOverlay = OverlayEntry( - builder: (context) => Positioned.fromRect( - rect: Rect.fromPoints(offset, offset.translate(20, 20)), - child: Container( - color: Colors.red.withOpacity(0.2), - ), - ), - ); - Overlay.of(context)?.insert(_debugOverlay!); - } else if (_panStartOffset != null) { - _debugOverlay = OverlayEntry( - builder: (context) => Positioned.fromRect( - rect: Rect.fromPoints( - _panStartOffset?.translate( - 0, - -(editorState.service.scrollService!.dy - - _panStartScrollDy!), - ) ?? - Offset.zero, - offset ?? Offset.zero), - child: Container( - color: Colors.red.withOpacity(0.2), - ), - ), - ); - Overlay.of(context)?.insert(_debugOverlay!); - } else { - _debugOverlay = null; - } - } + // if (kDebugMode && false) { + // _debugOverlay?.remove(); + // if (offset != null) { + // _debugOverlay = OverlayEntry( + // builder: (context) => Positioned.fromRect( + // rect: Rect.fromPoints(offset, offset.translate(20, 20)), + // child: Container( + // color: Colors.red.withOpacity(0.2), + // ), + // ), + // ); + // Overlay.of(context)?.insert(_debugOverlay!); + // } else if (_panStartOffset != null) { + // _debugOverlay = OverlayEntry( + // builder: (context) => Positioned.fromRect( + // rect: Rect.fromPoints( + // _panStartOffset?.translate( + // 0, + // -(editorState.service.scrollService!.dy - + // _panStartScrollDy!), + // ) ?? + // Offset.zero, + // offset ?? Offset.zero), + // child: Container( + // color: Colors.red.withOpacity(0.2), + // ), + // ), + // ); + // Overlay.of(context)?.insert(_debugOverlay!); + // } else { + // _debugOverlay = null; + // } + // } } } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/service.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/service.dart similarity index 55% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/service.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/service.dart index 158aab4615..e3436ea7ee 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/service.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/service.dart @@ -1,38 +1,38 @@ -import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_editor/src/service/toolbar_service.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/service/toolbar_service.dart'; import 'package:flutter/material.dart'; class FlowyService { // selection service final selectionServiceKey = GlobalKey(debugLabel: 'flowy_selection_service'); - FlowySelectionService get selectionService { + AppFlowySelectionService get selectionService { assert(selectionServiceKey.currentState != null && - selectionServiceKey.currentState is FlowySelectionService); - return selectionServiceKey.currentState! as FlowySelectionService; + selectionServiceKey.currentState is AppFlowySelectionService); + return selectionServiceKey.currentState! as AppFlowySelectionService; } // keyboard service final keyboardServiceKey = GlobalKey(debugLabel: 'flowy_keyboard_service'); - FlowyKeyboardService? get keyboardService { + AppFlowyKeyboardService? get keyboardService { if (keyboardServiceKey.currentState != null && - keyboardServiceKey.currentState is FlowyKeyboardService) { - return keyboardServiceKey.currentState! as FlowyKeyboardService; + keyboardServiceKey.currentState is AppFlowyKeyboardService) { + return keyboardServiceKey.currentState! as AppFlowyKeyboardService; } return null; } // input service final inputServiceKey = GlobalKey(debugLabel: 'flowy_input_service'); - FlowyInputService? get inputService { + AppFlowyInputService? get inputService { if (inputServiceKey.currentState != null && - inputServiceKey.currentState is FlowyInputService) { - return inputServiceKey.currentState! as FlowyInputService; + inputServiceKey.currentState is AppFlowyInputService) { + return inputServiceKey.currentState! as AppFlowyInputService; } return null; } // render plugin service - late FlowyRenderPlugin renderPluginService; + late AppFlowyRenderPlugin renderPluginService; // toolbar service final toolbarServiceKey = GlobalKey(debugLabel: 'flowy_toolbar_service'); @@ -46,10 +46,10 @@ class FlowyService { // scroll service final scrollServiceKey = GlobalKey(debugLabel: 'flowy_scroll_service'); - FlowyScrollService? get scrollService { + AppFlowyScrollService? get scrollService { if (scrollServiceKey.currentState != null && - scrollServiceKey.currentState is FlowyScrollService) { - return scrollServiceKey.currentState! as FlowyScrollService; + scrollServiceKey.currentState is AppFlowyScrollService) { + return scrollServiceKey.currentState! as AppFlowyScrollService; } return null; } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/toolbar_service.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/toolbar_service.dart similarity index 88% rename from frontend/app_flowy/packages/flowy_editor/lib/src/service/toolbar_service.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/service/toolbar_service.dart index fad7437b63..bf380290f9 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/toolbar_service.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/toolbar_service.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_editor/src/render/selection/toolbar_widget.dart'; -import 'package:flowy_editor/src/extensions/object_extensions.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/render/selection/toolbar_widget.dart'; +import 'package:appflowy_editor/src/extensions/object_extensions.dart'; abstract class FlowyToolbarService { /// Show the toolbar widget beside the offset. diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/undo_manager.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/undo_manager.dart similarity index 90% rename from frontend/app_flowy/packages/flowy_editor/lib/src/undo_manager.dart rename to frontend/app_flowy/packages/appflowy_editor/lib/src/undo_manager.dart index e49debdd09..43d0eeaa35 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/undo_manager.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/undo_manager.dart @@ -1,10 +1,10 @@ import 'dart:collection'; -import 'package:flowy_editor/src/document/selection.dart'; -import 'package:flowy_editor/src/operation/operation.dart'; -import 'package:flowy_editor/src/operation/transaction_builder.dart'; -import 'package:flowy_editor/src/operation/transaction.dart'; -import 'package:flowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/operation/operation.dart'; +import 'package:appflowy_editor/src/operation/transaction_builder.dart'; +import 'package:appflowy_editor/src/operation/transaction.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; import 'package:flutter/foundation.dart'; /// A [HistoryItem] contains list of operations committed by users. diff --git a/frontend/app_flowy/packages/flowy_editor/pubspec.yaml b/frontend/app_flowy/packages/appflowy_editor/pubspec.yaml similarity index 90% rename from frontend/app_flowy/packages/flowy_editor/pubspec.yaml rename to frontend/app_flowy/packages/appflowy_editor/pubspec.yaml index 05c87f8e33..56820bf316 100644 --- a/frontend/app_flowy/packages/flowy_editor/pubspec.yaml +++ b/frontend/app_flowy/packages/appflowy_editor/pubspec.yaml @@ -1,7 +1,7 @@ -name: flowy_editor -description: A new Flutter package project. +name: appflowy_editor +description: An easily extensible, test-covered rich text editing component for Flutter. version: 0.0.1 -homepage: +homepage: https://github.com/AppFlowy-IO/AppFlowy environment: sdk: ">=2.17.0 <3.0.0" @@ -15,6 +15,7 @@ dependencies: html: ^0.15.0 flutter_svg: ^1.1.1+1 provider: ^6.0.3 + url_launcher: ^6.1.5 dev_dependencies: flutter_test: diff --git a/frontend/app_flowy/packages/flowy_editor/test/infra/test_editor.dart b/frontend/app_flowy/packages/appflowy_editor/test/infra/test_editor.dart similarity index 97% rename from frontend/app_flowy/packages/flowy_editor/test/infra/test_editor.dart rename to frontend/app_flowy/packages/appflowy_editor/test/infra/test_editor.dart index 17b0a95318..dedc6bcc8f 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/infra/test_editor.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/infra/test_editor.dart @@ -1,6 +1,6 @@ import 'dart:collection'; -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -26,7 +26,7 @@ class EditorWidgetTester { await tester.pumpWidget( MaterialApp( home: Scaffold( - body: FlowyEditor( + body: AppFlowyEditor( editorState: _editorState, ), ), diff --git a/frontend/app_flowy/packages/flowy_editor/test/infra/test_raw_key_event.dart b/frontend/app_flowy/packages/appflowy_editor/test/infra/test_raw_key_event.dart similarity index 97% rename from frontend/app_flowy/packages/flowy_editor/test/infra/test_raw_key_event.dart rename to frontend/app_flowy/packages/appflowy_editor/test/infra/test_raw_key_event.dart index 04b5a11789..f54528064c 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/infra/test_raw_key_event.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/infra/test_raw_key_event.dart @@ -115,6 +115,9 @@ extension on LogicalKeyboardKey { if (this == LogicalKeyboardKey.keyU) { return PhysicalKeyboardKey.keyU; } + if (this == LogicalKeyboardKey.keyH) { + return PhysicalKeyboardKey.keyH; + } if (this == LogicalKeyboardKey.keyZ) { return PhysicalKeyboardKey.keyZ; } diff --git a/frontend/app_flowy/packages/flowy_editor/test/legacy/delta_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/legacy/delta_test.dart similarity index 98% rename from frontend/app_flowy/packages/flowy_editor/test/legacy/delta_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/legacy/delta_test.dart index a835471b55..1540b18a21 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/legacy/delta_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/legacy/delta_test.dart @@ -1,6 +1,6 @@ -import 'package:flowy_editor/src/document/attributes.dart'; +import 'package:appflowy_editor/src/document/attributes.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:flowy_editor/src/document/text_delta.dart'; +import 'package:appflowy_editor/src/document/text_delta.dart'; void main() { group('compose', () { diff --git a/frontend/app_flowy/packages/flowy_editor/test/legacy/flowy_editor_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/legacy/flowy_editor_test.dart similarity index 94% rename from frontend/app_flowy/packages/flowy_editor/test/legacy/flowy_editor_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/legacy/flowy_editor_test.dart index e070b7f820..5988c8fd1d 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/legacy/flowy_editor_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/legacy/flowy_editor_test.dart @@ -1,10 +1,10 @@ import 'dart:convert'; -import 'package:flowy_editor/src/document/node.dart'; -import 'package:flowy_editor/src/document/state_tree.dart'; -import 'package:flowy_editor/src/document/path.dart'; -import 'package:flowy_editor/src/document/position.dart'; -import 'package:flowy_editor/src/document/selection.dart'; +import 'package:appflowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/state_tree.dart'; +import 'package:appflowy_editor/src/document/path.dart'; +import 'package:appflowy_editor/src/document/position.dart'; +import 'package:appflowy_editor/src/document/selection.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/test/legacy/operation_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/legacy/operation_test.dart similarity index 92% rename from frontend/app_flowy/packages/flowy_editor/test/legacy/operation_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/legacy/operation_test.dart index 6e97ce9930..1f44ebfd3c 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/legacy/operation_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/legacy/operation_test.dart @@ -1,11 +1,11 @@ import 'dart:collection'; -import 'package:flowy_editor/src/document/node.dart'; +import 'package:appflowy_editor/src/document/node.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:flowy_editor/src/operation/operation.dart'; -import 'package:flowy_editor/src/operation/transaction_builder.dart'; -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/document/state_tree.dart'; +import 'package:appflowy_editor/src/operation/operation.dart'; +import 'package:appflowy_editor/src/operation/transaction_builder.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/document/state_tree.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); diff --git a/frontend/app_flowy/packages/flowy_editor/test/render/rich_text/checkbox_text_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart similarity index 89% rename from frontend/app_flowy/packages/flowy_editor/test/render/rich_text/checkbox_text_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart index 84f6b93990..f039c227d9 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/render/rich_text/checkbox_text_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart @@ -1,7 +1,7 @@ -import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_editor/src/render/rich_text/default_selectable.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/extensions/text_node_extensions.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/render/rich_text/default_selectable.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/extensions/text_node_extensions.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/delete_text_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/delete_text_handler_test.dart similarity index 98% rename from frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/delete_text_handler_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/delete_text_handler_test.dart index 15af27e7a4..1e7bf4e842 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/delete_text_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/delete_text_handler_test.dart @@ -1,5 +1,5 @@ -import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart similarity index 97% rename from frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart index 99d61ee6a6..ee21dfa455 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart @@ -1,5 +1,5 @@ -import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/page_up_down_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/page_up_down_handler_test.dart similarity index 97% rename from frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/page_up_down_handler_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/page_up_down_handler_test.dart index fe74e41efe..eb221ddf2c 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/page_up_down_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/page_up_down_handler_test.dart @@ -1,4 +1,4 @@ -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/redo_undo_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/redo_undo_handler_test.dart similarity index 96% rename from frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/redo_undo_handler_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/redo_undo_handler_test.dart index 3bd9a81c52..0f91e0b1d9 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/redo_undo_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/redo_undo_handler_test.dart @@ -1,4 +1,4 @@ -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart similarity index 94% rename from frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart index 53c13b7119..6f4f9d0ce6 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart @@ -1,4 +1,4 @@ -import 'package:flowy_editor/flowy_editor.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart similarity index 89% rename from frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart index a8d1cc36f1..9e9cff8ad5 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart @@ -1,5 +1,5 @@ -import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/slash_handler.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/slash_handler.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/update_text_style_by_command_x_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/update_text_style_by_command_x_handler_test.dart similarity index 69% rename from frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/update_text_style_by_command_x_handler_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/update_text_style_by_command_x_handler_test.dart index e91f089def..2e93d4c5f5 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/update_text_style_by_command_x_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/update_text_style_by_command_x_handler_test.dart @@ -1,6 +1,6 @@ -import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/extensions/text_node_extensions.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/extensions/text_node_extensions.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; @@ -15,6 +15,7 @@ void main() async { await _testUpdateTextStyleByCommandX( tester, StyleKey.bold, + true, LogicalKeyboardKey.keyB, ); }); @@ -22,6 +23,7 @@ void main() async { await _testUpdateTextStyleByCommandX( tester, StyleKey.italic, + true, LogicalKeyboardKey.keyI, ); }); @@ -29,21 +31,40 @@ void main() async { await _testUpdateTextStyleByCommandX( tester, StyleKey.underline, + true, LogicalKeyboardKey.keyU, ); }); - testWidgets('Presses Command + S to update text style', (tester) async { + testWidgets('Presses Command + Shift + S to update text style', + (tester) async { await _testUpdateTextStyleByCommandX( tester, StyleKey.strikethrough, + true, LogicalKeyboardKey.keyS, ); }); + + testWidgets('Presses Command + Shift + H to update text style', + (tester) async { + await _testUpdateTextStyleByCommandX( + tester, + StyleKey.backgroundColor, + defaultHighlightColor, + LogicalKeyboardKey.keyH, + ); + }); }); } Future _testUpdateTextStyleByCommandX( - WidgetTester tester, String matchStyle, LogicalKeyboardKey key) async { + WidgetTester tester, + String matchStyle, + dynamic matchValue, + LogicalKeyboardKey key, +) async { + final isShiftPressed = + key == LogicalKeyboardKey.keyS || key == LogicalKeyboardKey.keyH; const text = 'Welcome to Appflowy 😁'; final editor = tester.editor ..insertTextNode(text) @@ -56,31 +77,34 @@ Future _testUpdateTextStyleByCommandX( await editor.updateSelection(selection); await editor.pressLogicKey( key, - isShiftPressed: key == LogicalKeyboardKey.keyS, + isShiftPressed: isShiftPressed, isMetaPressed: true, ); var textNode = editor.nodeAtPath([1]) as TextNode; - expect(textNode.allSatisfyInSelection(matchStyle, selection), true); + expect( + textNode.allSatisfyInSelection(matchStyle, matchValue, selection), true); selection = Selection.single(path: [1], startOffset: 0, endOffset: text.length); await editor.updateSelection(selection); await editor.pressLogicKey( key, - isShiftPressed: key == LogicalKeyboardKey.keyS, + isShiftPressed: isShiftPressed, isMetaPressed: true, ); textNode = editor.nodeAtPath([1]) as TextNode; - expect(textNode.allSatisfyInSelection(matchStyle, selection), true); + expect( + textNode.allSatisfyInSelection(matchStyle, matchValue, selection), true); await editor.updateSelection(selection); await editor.pressLogicKey( key, - isShiftPressed: key == LogicalKeyboardKey.keyS, + isShiftPressed: isShiftPressed, isMetaPressed: true, ); textNode = editor.nodeAtPath([1]) as TextNode; - expect(textNode.allNotSatisfyInSelection(matchStyle, selection), true); + expect(textNode.allNotSatisfyInSelection(matchStyle, matchValue, selection), + true); selection = Selection( start: Position(path: [0], offset: 0), @@ -89,7 +113,7 @@ Future _testUpdateTextStyleByCommandX( await editor.updateSelection(selection); await editor.pressLogicKey( key, - isShiftPressed: key == LogicalKeyboardKey.keyS, + isShiftPressed: isShiftPressed, isMetaPressed: true, ); var nodes = editor.editorState.service.selectionService.currentSelectedNodes @@ -99,6 +123,7 @@ Future _testUpdateTextStyleByCommandX( expect( node.allSatisfyInSelection( matchStyle, + matchValue, Selection.single( path: node.path, startOffset: 0, endOffset: text.length), ), @@ -109,7 +134,7 @@ Future _testUpdateTextStyleByCommandX( await editor.updateSelection(selection); await editor.pressLogicKey( key, - isShiftPressed: key == LogicalKeyboardKey.keyS, + isShiftPressed: isShiftPressed, isMetaPressed: true, ); nodes = editor.editorState.service.selectionService.currentSelectedNodes @@ -119,6 +144,7 @@ Future _testUpdateTextStyleByCommandX( expect( node.allNotSatisfyInSelection( matchStyle, + matchValue, Selection.single( path: node.path, startOffset: 0, endOffset: text.length), ), diff --git a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/white_space_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/white_space_handler_test.dart similarity index 96% rename from frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/white_space_handler_test.dart rename to frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/white_space_handler_test.dart index fb4c187f0f..21f9a5eb65 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/white_space_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/white_space_handler_test.dart @@ -1,6 +1,6 @@ -import 'package:flowy_editor/flowy_editor.dart'; -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/whitespace_handler.dart'; +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart'; +import 'package:appflowy_editor/src/service/internal_key_event_handlers/whitespace_handler.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../infra/test_editor.dart'; diff --git a/frontend/app_flowy/packages/flowy_editor/.vscode/launch.json b/frontend/app_flowy/packages/flowy_editor/.vscode/launch.json deleted file mode 100644 index f27c363a13..0000000000 --- a/frontend/app_flowy/packages/flowy_editor/.vscode/launch.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "example", - "cwd": "example", - "request": "launch", - "type": "dart" - }, - { - "name": "example (profile mode)", - "cwd": "example", - "request": "launch", - "type": "dart", - "flutterMode": "profile" - }, - { - "name": "example (release mode)", - "cwd": "example", - "request": "launch", - "type": "dart", - "flutterMode": "release" - }, - { - "name": "flowy_editor", - "request": "launch", - "type": "dart" - }, - { - "name": "flowy_editor (profile mode)", - "request": "launch", - "type": "dart", - "flutterMode": "profile" - }, - { - "name": "flowy_editor (release mode)", - "request": "launch", - "type": "dart", - "flutterMode": "release" - }, - ] -} \ No newline at end of file diff --git a/frontend/app_flowy/packages/flowy_editor/CHANGELOG.md b/frontend/app_flowy/packages/flowy_editor/CHANGELOG.md deleted file mode 100644 index 41cc7d8192..0000000000 --- a/frontend/app_flowy/packages/flowy_editor/CHANGELOG.md +++ /dev/null @@ -1,3 +0,0 @@ -## 0.0.1 - -* TODO: Describe initial release. diff --git a/frontend/app_flowy/packages/flowy_editor/LICENSE b/frontend/app_flowy/packages/flowy_editor/LICENSE deleted file mode 100644 index ba75c69f7f..0000000000 --- a/frontend/app_flowy/packages/flowy_editor/LICENSE +++ /dev/null @@ -1 +0,0 @@ -TODO: Add your license here. diff --git a/frontend/app_flowy/packages/flowy_editor/README.md b/frontend/app_flowy/packages/flowy_editor/README.md deleted file mode 100644 index 8b55e735b5..0000000000 --- a/frontend/app_flowy/packages/flowy_editor/README.md +++ /dev/null @@ -1,39 +0,0 @@ - - -TODO: Put a short description of the package here that helps potential users -know whether this package might be useful for them. - -## Features - -TODO: List what your package can do. Maybe include images, gifs, or videos. - -## Getting started - -TODO: List prerequisites and provide or point to information on how to -start using the package. - -## Usage - -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. - -```dart -const like = 'sample'; -``` - -## Additional information - -TODO: Tell users more about the package: where to find more information, how to -contribute to the package, how to file issues, what response they can expect -from the package authors, and more. diff --git a/frontend/app_flowy/packages/flowy_editor/example/.vscode/launch.json b/frontend/app_flowy/packages/flowy_editor/example/.vscode/launch.json deleted file mode 100644 index 091adbfb6b..0000000000 --- a/frontend/app_flowy/packages/flowy_editor/example/.vscode/launch.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "example", - "request": "launch", - "type": "dart" - }, - { - "name": "example (profile mode)", - "request": "launch", - "type": "dart", - "flutterMode": "profile" - }, - { - "name": "example (release mode)", - "request": "launch", - "type": "dart", - "flutterMode": "release" - } - ] -} \ No newline at end of file diff --git a/frontend/app_flowy/packages/flowy_editor/example/pubspec.lock b/frontend/app_flowy/packages/flowy_editor/example/pubspec.lock deleted file mode 100644 index f86e34c312..0000000000 --- a/frontend/app_flowy/packages/flowy_editor/example/pubspec.lock +++ /dev/null @@ -1,551 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "3.3.1" - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.8.2" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - characters: - dependency: transitive - description: - name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.16.0" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.2" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.2" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.5" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" - ffi: - dependency: transitive - description: - name: ffi - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.1" - flowy_editor: - dependency: "direct main" - description: - path: ".." - relative: true - source: path - version: "0.0.1" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_inappwebview: - dependency: "direct main" - description: - name: flutter_inappwebview - url: "https://pub.dartlang.org" - source: hosted - version: "5.4.3+7" - flutter_lints: - dependency: "direct dev" - description: - name: flutter_lints - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" - flutter_svg: - dependency: transitive - description: - name: flutter_svg - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.1+1" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - flutter_web_plugins: - dependency: transitive - description: flutter - source: sdk - version: "0.0.0" - freezed_annotation: - dependency: transitive - description: - name: freezed_annotation - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - get: - dependency: transitive - description: - name: get - url: "https://pub.dartlang.org" - source: hosted - version: "4.6.5" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.15.0" - http: - dependency: transitive - description: - name: http - url: "https://pub.dartlang.org" - source: hosted - version: "0.13.5" - http_parser: - dependency: transitive - description: - name: http_parser - url: "https://pub.dartlang.org" - source: hosted - version: "4.0.1" - js: - dependency: transitive - description: - name: js - url: "https://pub.dartlang.org" - source: hosted - version: "0.6.4" - json_annotation: - dependency: transitive - description: - name: json_annotation - url: "https://pub.dartlang.org" - source: hosted - version: "4.6.0" - lints: - dependency: transitive - description: - name: lints - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" - lottie: - dependency: transitive - description: - name: lottie - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.1" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.11" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.4" - meta: - dependency: transitive - description: - name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.7.0" - nested: - dependency: transitive - description: - name: nested - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.1" - path_drawing: - dependency: transitive - description: - name: path_drawing - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - path_parsing: - dependency: transitive - description: - name: path_parsing - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "5.0.0" - plugin_platform_interface: - dependency: transitive - description: - name: plugin_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.2" - pod_player: - dependency: "direct main" - description: - name: pod_player - url: "https://pub.dartlang.org" - source: hosted - version: "0.0.8" - provider: - dependency: "direct main" - description: - name: provider - url: "https://pub.dartlang.org" - source: hosted - version: "6.0.3" - rich_clipboard: - dependency: transitive - description: - name: rich_clipboard - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - rich_clipboard_android: - dependency: transitive - description: - name: rich_clipboard_android - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - rich_clipboard_ios: - dependency: transitive - description: - name: rich_clipboard_ios - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - rich_clipboard_linux: - dependency: transitive - description: - name: rich_clipboard_linux - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - rich_clipboard_macos: - dependency: transitive - description: - name: rich_clipboard_macos - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.1" - rich_clipboard_platform_interface: - dependency: transitive - description: - name: rich_clipboard_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - rich_clipboard_web: - dependency: transitive - description: - name: rich_clipboard_web - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - rich_clipboard_windows: - dependency: transitive - description: - name: rich_clipboard_windows - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.2" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.10.0" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.4.9" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" - universal_html: - dependency: transitive - description: - name: universal_html - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.8" - universal_io: - dependency: transitive - description: - name: universal_io - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.4" - url_launcher: - dependency: "direct main" - description: - name: url_launcher - url: "https://pub.dartlang.org" - source: hosted - version: "6.1.5" - url_launcher_android: - dependency: transitive - description: - name: url_launcher_android - url: "https://pub.dartlang.org" - source: hosted - version: "6.0.17" - url_launcher_ios: - dependency: transitive - description: - name: url_launcher_ios - url: "https://pub.dartlang.org" - source: hosted - version: "6.0.17" - url_launcher_linux: - dependency: transitive - description: - name: url_launcher_linux - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.1" - url_launcher_macos: - dependency: transitive - description: - name: url_launcher_macos - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.1" - url_launcher_platform_interface: - dependency: transitive - description: - name: url_launcher_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - url_launcher_web: - dependency: transitive - description: - name: url_launcher_web - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.12" - url_launcher_windows: - dependency: transitive - description: - name: url_launcher_windows - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.1" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.2" - video_player: - dependency: "direct main" - description: - name: video_player - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.5" - video_player_android: - dependency: transitive - description: - name: video_player_android - url: "https://pub.dartlang.org" - source: hosted - version: "2.3.8" - video_player_avfoundation: - dependency: transitive - description: - name: video_player_avfoundation - url: "https://pub.dartlang.org" - source: hosted - version: "2.3.5" - video_player_platform_interface: - dependency: transitive - description: - name: video_player_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "5.1.3" - video_player_web: - dependency: transitive - description: - name: video_player_web - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.12" - wakelock: - dependency: transitive - description: - name: wakelock - url: "https://pub.dartlang.org" - source: hosted - version: "0.6.2" - wakelock_macos: - dependency: transitive - description: - name: wakelock_macos - url: "https://pub.dartlang.org" - source: hosted - version: "0.4.0" - wakelock_platform_interface: - dependency: transitive - description: - name: wakelock_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.0" - wakelock_web: - dependency: transitive - description: - name: wakelock_web - url: "https://pub.dartlang.org" - source: hosted - version: "0.4.0" - wakelock_windows: - dependency: transitive - description: - name: wakelock_windows - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.0" - win32: - dependency: transitive - description: - name: win32 - url: "https://pub.dartlang.org" - source: hosted - version: "2.6.1" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "6.1.0" - youtube_explode_dart: - dependency: transitive - description: - name: youtube_explode_dart - url: "https://pub.dartlang.org" - source: hosted - version: "1.12.0" -sdks: - dart: ">=2.17.0 <3.0.0" - flutter: ">=3.0.0" diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/render/selection/toolbar_widget.dart b/frontend/app_flowy/packages/flowy_editor/lib/src/render/selection/toolbar_widget.dart deleted file mode 100644 index 2c9fb9ad93..0000000000 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/render/selection/toolbar_widget.dart +++ /dev/null @@ -1,208 +0,0 @@ -import 'package:flowy_editor/src/render/rich_text/rich_text_style.dart'; -import 'package:flutter/material.dart'; - -import 'package:flowy_editor/src/editor_state.dart'; -import 'package:flowy_editor/src/infra/flowy_svg.dart'; -import 'package:flowy_editor/src/service/default_text_operations/format_rich_text_style.dart'; - -typedef ToolbarEventHandler = void Function(EditorState editorState); - -typedef ToolbarEventHandlers = Map; - -ToolbarEventHandlers defaultToolbarEventHandlers = { - 'bold': (editorState) => formatBold(editorState), - 'italic': (editorState) => formatItalic(editorState), - 'strikethrough': (editorState) => formatStrikethrough(editorState), - 'underline': (editorState) => formatUnderline(editorState), - 'quote': (editorState) => formatQuote(editorState), - 'number_list': (editorState) {}, - 'bulleted_list': (editorState) => formatBulletedList(editorState), - 'Text': (editorState) => formatText(editorState), - 'H1': (editorState) => formatHeading(editorState, StyleKey.h1), - 'H2': (editorState) => formatHeading(editorState, StyleKey.h2), - 'H3': (editorState) => formatHeading(editorState, StyleKey.h3), -}; - -List defaultListToolbarEventNames = [ - 'Text', - 'H1', - 'H2', - 'H3', -]; - -mixin ToolbarMixin on State { - void hide(); -} - -class ToolbarWidget extends StatefulWidget { - const ToolbarWidget({ - Key? key, - required this.editorState, - required this.layerLink, - required this.offset, - required this.handlers, - }) : super(key: key); - - final EditorState editorState; - final LayerLink layerLink; - final Offset offset; - final ToolbarEventHandlers handlers; - - @override - State createState() => _ToolbarWidgetState(); -} - -class _ToolbarWidgetState extends State with ToolbarMixin { - final GlobalKey _listToolbarKey = GlobalKey(); - - final toolbarHeight = 32.0; - final topPadding = 5.0; - - final listToolbarWidth = 60.0; - final listToolbarHeight = 120.0; - - final cornerRadius = 8.0; - - OverlayEntry? _listToolbarOverlay; - - @override - Widget build(BuildContext context) { - return Positioned( - top: widget.offset.dx, - left: widget.offset.dy, - child: CompositedTransformFollower( - link: widget.layerLink, - showWhenUnlinked: true, - offset: widget.offset, - child: _buildToolbar(context), - ), - ); - } - - @override - void hide() { - _listToolbarOverlay?.remove(); - _listToolbarOverlay = null; - } - - Widget _buildToolbar(BuildContext context) { - return Material( - borderRadius: BorderRadius.circular(cornerRadius), - color: const Color(0xFF333333), - child: SizedBox( - height: toolbarHeight, - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - _listToolbar(context), - _centerToolbarIcon('divider', width: 10), - _centerToolbarIcon('bold'), - _centerToolbarIcon('italic'), - _centerToolbarIcon('strikethrough'), - _centerToolbarIcon('underline'), - _centerToolbarIcon('divider', width: 10), - _centerToolbarIcon('quote'), - _centerToolbarIcon('number_list'), - _centerToolbarIcon('bulleted_list'), - ], - ), - ), - ); - } - - Widget _listToolbar(BuildContext context) { - return _centerToolbarIcon( - 'quote', - key: _listToolbarKey, - width: listToolbarWidth, - onTap: () => _onTapListToolbar(context), - ); - } - - Widget _centerToolbarIcon(String name, - {Key? key, double? width, VoidCallback? onTap}) { - return Tooltip( - key: key, - preferBelow: false, - message: name, - child: GestureDetector( - onTap: onTap ?? () => _onTap(name), - child: SizedBox.fromSize( - size: width != null - ? Size(width, toolbarHeight) - : Size.square(toolbarHeight), - child: Center( - child: FlowySvg( - name: 'toolbar/$name', - ), - ), - ), - ), - ); - } - - void _onTapListToolbar(BuildContext context) { - // TODO: implement more detailed UI. - final items = defaultListToolbarEventNames; - final renderBox = - _listToolbarKey.currentContext?.findRenderObject() as RenderBox; - final offset = renderBox - .localToGlobal(Offset.zero) - .translate(0, toolbarHeight - cornerRadius); - final rect = offset & Size(listToolbarWidth, listToolbarHeight); - - _listToolbarOverlay?.remove(); - _listToolbarOverlay = OverlayEntry(builder: (context) { - return Positioned.fromRect( - rect: rect, - child: Material( - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular(cornerRadius), - bottomRight: Radius.circular(cornerRadius), - ), - color: const Color(0xFF333333), - child: SingleChildScrollView( - child: ListView.builder( - itemExtent: toolbarHeight, - padding: const EdgeInsets.only(bottom: 10.0), - shrinkWrap: true, - itemCount: items.length, - itemBuilder: ((context, index) { - return ListTile( - contentPadding: const EdgeInsets.only( - left: 3.0, - right: 3.0, - ), - minVerticalPadding: 0.0, - title: FittedBox( - fit: BoxFit.scaleDown, - child: Text( - items[index], - textAlign: TextAlign.center, - style: const TextStyle( - color: Colors.white, - ), - ), - ), - onTap: () { - _onTap(items[index]); - }, - ); - }), - ), - ), - ), - ); - }); - // TODO: disable scrolling. - Overlay.of(context)?.insert(_listToolbarOverlay!); - } - - void _onTap(String eventName) { - if (defaultToolbarEventHandlers.containsKey(eventName)) { - defaultToolbarEventHandlers[eventName]!(widget.editorState); - return; - } - assert(false, 'Could not find the event handler for $eventName'); - } -} diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart b/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart deleted file mode 100644 index a327206c26..0000000000 --- a/frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:flowy_editor/src/service/internal_key_event_handlers/arrow_keys_handler.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/copy_paste_handler.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/delete_text_handler.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/redo_undo_handler.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/slash_handler.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/whitespace_handler.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/select_all_handler.dart'; -import 'package:flowy_editor/src/service/internal_key_event_handlers/page_up_down_handler.dart'; -import 'package:flowy_editor/src/service/keyboard_service.dart'; - -List defaultKeyEventHandlers = [ - deleteTextHandler, - slashShortcutHandler, - arrowKeysHandler, - copyPasteKeysHandler, - redoUndoKeysHandler, - enterWithoutShiftInTextNodesHandler, - updateTextStyleByCommandXHandler, - whiteSpaceHandler, - selectAllHandler, - pageUpDownHandler, -]; diff --git a/frontend/app_flowy/packages/flowy_infra/pubspec.yaml b/frontend/app_flowy/packages/flowy_infra/pubspec.yaml index e47fd1d58c..ebd7656af9 100644 --- a/frontend/app_flowy/packages/flowy_infra/pubspec.yaml +++ b/frontend/app_flowy/packages/flowy_infra/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: time: '>=2.0.0' uuid: ">=2.2.2" textstyle_extensions: '2.0.0-nullsafety' - flutter_svg: ^0.22.0 + flutter_svg: ^1.1.1 dev_dependencies: flutter_test: diff --git a/frontend/app_flowy/pubspec.lock b/frontend/app_flowy/pubspec.lock index c8ef9fe47a..0348536cb8 100644 --- a/frontend/app_flowy/pubspec.lock +++ b/frontend/app_flowy/pubspec.lock @@ -29,6 +29,13 @@ packages: relative: true source: path version: "0.0.4" + appflowy_editor: + dependency: "direct main" + description: + path: "packages/appflowy_editor" + relative: true + source: path + version: "0.0.1" args: dependency: transitive description: @@ -273,7 +280,7 @@ packages: name: dbus url: "https://pub.dartlang.org" source: hosted - version: "0.7.3" + version: "0.7.4" device_info_plus: dependency: "direct main" description: @@ -490,12 +497,12 @@ packages: source: git version: "2.0.13" flutter_svg: - dependency: "direct main" + dependency: transitive description: name: flutter_svg url: "https://pub.dartlang.org" source: hosted - version: "0.22.0" + version: "1.1.4" flutter_test: dependency: "direct dev" description: flutter @@ -827,14 +834,14 @@ packages: name: path_drawing url: "https://pub.dartlang.org" source: hosted - version: "0.5.1+1" + version: "1.0.1" path_parsing: dependency: transitive description: name: path_parsing url: "https://pub.dartlang.org" source: hosted - version: "0.2.1" + version: "1.0.1" path_provider: dependency: "direct main" description: @@ -975,6 +982,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.5.0" + rich_clipboard: + dependency: transitive + description: + name: rich_clipboard + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + rich_clipboard_android: + dependency: transitive + description: + name: rich_clipboard_android + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + rich_clipboard_ios: + dependency: transitive + description: + name: rich_clipboard_ios + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + rich_clipboard_linux: + dependency: transitive + description: + name: rich_clipboard_linux + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + rich_clipboard_macos: + dependency: transitive + description: + name: rich_clipboard_macos + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + rich_clipboard_platform_interface: + dependency: transitive + description: + name: rich_clipboard_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + rich_clipboard_web: + dependency: transitive + description: + name: rich_clipboard_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + rich_clipboard_windows: + dependency: transitive + description: + name: rich_clipboard_windows + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" shared_preferences: dependency: transitive description: @@ -1245,7 +1308,7 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.1.2" + version: "6.1.5" url_launcher_android: dependency: transitive description: @@ -1280,7 +1343,7 @@ packages: name: url_launcher_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.1.0" url_launcher_web: dependency: transitive description: @@ -1401,7 +1464,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "5.4.1" + version: "6.1.0" yaml: dependency: transitive description: diff --git a/frontend/app_flowy/pubspec.yaml b/frontend/app_flowy/pubspec.yaml index d04277a8b4..f713825a4f 100644 --- a/frontend/app_flowy/pubspec.yaml +++ b/frontend/app_flowy/pubspec.yaml @@ -39,6 +39,8 @@ dependencies: path: packages/flowy_infra appflowy_board: path: packages/appflowy_board + appflowy_editor: + path: packages/appflowy_editor flutter_quill: git: url: https://github.com/appflowy/flutter-quill.git @@ -61,7 +63,6 @@ dependencies: sized_context: ^1.0.0+1 styled_widget: "^0.3.1" expandable: ^5.0.1 - flutter_svg: ^0.22.0 flutter_colorpicker: ^0.6.0 package_info_plus: ^1.3.0 url_launcher: ^6.0.2