From 9764f7500658a2d6f1bb23fb238e2cce7eedec4a Mon Sep 17 00:00:00 2001 From: Ellet Date: Wed, 17 Jul 2024 16:48:44 -0700 Subject: [PATCH] refactor: restructure project into modular architecture for flutter_quill (#2032) * refactor: restructure project into modular architecture for flutter_quill * refactor: move LineHeightAttribute class to custom_attributes.dart * chore: remove nullable controller extension --- README.md | 2 +- analysis_options.yaml | 1 - .../lib/flutter_quill_extensions.dart | 5 +- .../clipboard/super_clipboard_service.dart | 3 +- lib/extensions.dart | 10 +- lib/flutter_quill.dart | 76 ++++---- lib/markdown_quill.dart | 2 + lib/src/{ => common}/extensions/uri_ext.dart | 0 .../{models => common}/structs/image_url.dart | 0 .../structs/offset_value.dart | 0 .../structs/optional_size.dart | 0 .../structs/segment_leaf_node.dart | 4 +- .../structs/vertical_spacing.dart | 0 lib/src/{ => common}/utils/cast.dart | 0 lib/src/{ => common}/utils/color.dart | 0 lib/src/{ => common}/utils/embeds.dart | 6 +- lib/src/{ => common}/utils/font.dart | 2 +- lib/src/{ => common}/utils/platform.dart | 0 lib/src/{ => common}/utils/string.dart | 0 lib/src/{ => common}/utils/widgets.dart | 0 lib/src/controller/provider.dart | 19 ++ .../quill_controller.dart | 18 +- .../quill_controller_configurations.dart | 0 .../delta.dart => delta/delta_diff.dart} | 6 +- .../{models/documents => delta}/delta_x.dart | 4 +- .../documents => document}/attribute.dart | 24 +-- lib/src/document/custom_attributes.dart | 25 +++ .../documents => document}/document.dart | 19 +- .../documents => document}/history.dart | 6 +- .../documents => document}/nodes/block.dart | 0 .../nodes/container.dart | 4 +- .../nodes/embeddable.dart | 0 .../documents => document}/nodes/leaf.dart | 5 +- .../documents => document}/nodes/line.dart | 4 +- .../documents => document}/nodes/node.dart | 2 +- .../structs/doc_change.dart | 2 +- .../structs/history_changed.dart | 0 .../{models/documents => document}/style.dart | 0 .../config}/editor_configurations.dart | 18 +- .../config}/element_options.dart | 0 .../config}/elements/code_block.dart | 0 .../config}/elements/list/ordered_list.dart | 0 .../config}/elements/list/unordered_list.dart | 0 lib/src/{widgets => }/editor/editor.dart | 30 +-- .../{widgets => }/editor/editor_builder.dart | 4 +- .../embed/embed_editor_builder.dart} | 15 +- lib/src/editor/provider.dart | 78 ++++++++ .../config}/raw_editor_configurations.dart | 17 +- .../quill_single_child_scroll_view.dart | 0 .../raw_editor/raw_editor.dart | 10 +- .../raw_editor/raw_editor_actions.dart | 10 +- .../raw_editor/raw_editor_render_object.dart | 6 +- .../raw_editor/raw_editor_state.dart | 50 +++-- ...editor_state_selection_delegate_mixin.dart | 4 +- ..._editor_state_text_input_client_mixin.dart | 6 +- .../raw_editor_text_boundaries.dart | 6 +- .../raw_editor/scribble_focusable.dart | 0 .../style_widgets/bullet_point.dart | 2 +- .../style_widgets/checkbox_point.dart | 0 .../style_widgets/number_point.dart | 4 +- .../style_widgets/style_widgets.dart | 0 .../others => editor/widgets}/box.dart | 2 +- .../others => editor/widgets}/cursor.dart | 2 +- .../widgets}/default_styles.dart | 8 +- .../others => editor/widgets}/delegate.dart | 13 +- .../widgets}/float_cursor.dart | 0 .../widgets}/keyboard_listener.dart | 0 .../others => editor/widgets}/link.dart | 8 +- .../others => editor/widgets}/proxy.dart | 0 .../widgets/text}/text_block.dart | 39 ++-- .../widgets/text}/text_line.dart | 38 ++-- .../widgets/text}/text_selection.dart | 4 +- .../clipboard/clipboard_service.dart | 0 .../clipboard/clipboard_service_provider.dart | 0 .../clipboard/default_clipboard_service.dart | 0 .../quill_configurations.dart | 5 + .../config/quill_shared_configurations.dart | 12 +- .../quill_configurations_ext.dart | 13 ++ .../extensions/quill_configurations_ext.dart | 84 -------- lib/src/extensions/quill_controller_ext.dart | 17 -- ...alizations.dart => localizations_ext.dart} | 0 lib/src/l10n/widgets/localizations.dart | 4 +- lib/src/models/config/others/animations.dart | 28 --- .../models/config/quill_configurations.dart | 4 - .../custom_quill_attributes.dart | 2 +- .../quill_markdown/delta_to_markdown.dart | 11 +- lib/src/{models => }/rules/delete.dart | 8 +- lib/src/{models => }/rules/format.dart | 6 +- lib/src/{models => }/rules/insert.dart | 12 +- lib/src/{models => }/rules/rule.dart | 6 +- .../base_button/base_value_button.dart | 2 +- .../base_button/stateless_base_button.dart | 10 +- .../{widgets => }/toolbar/base_toolbar.dart | 12 +- .../alignment/select_alignment_button.dart | 4 +- .../alignment/select_alignment_buttons.dart | 4 +- .../buttons/arrow_indicated_list_button.dart | 0 .../toolbar/buttons/clear_format_button.dart | 4 +- .../toolbar/buttons/clipboard_button.dart | 8 +- .../toolbar/buttons/color/color_button.dart | 15 +- .../toolbar/buttons/color/color_dialog.dart | 4 +- .../toolbar/buttons/custom_button_button.dart | 6 +- .../toolbar/buttons/font_family_button.dart | 8 +- .../toolbar/buttons/font_size_button.dart | 11 +- .../select_header_style_buttons.dart | 12 +- .../select_header_style_dropdown_button.dart | 9 +- .../toolbar/buttons/history_button.dart | 2 +- .../toolbar/buttons/indent_button.dart | 4 +- .../toolbar/buttons/link_style2_button.dart | 17 +- .../toolbar/buttons/link_style_button.dart | 14 +- .../toolbar/buttons/quill_icon_button.dart | 2 +- .../search/legacy/legacy_search_button.dart | 13 +- .../search/legacy/legacy_search_dialog.dart | 8 +- .../toolbar/buttons/search/search_button.dart | 15 +- .../toolbar/buttons/search/search_dialog.dart | 12 +- .../select_line_height_dropdown_button.dart | 10 +- .../buttons/toggle_check_list_button.dart | 8 +- .../toolbar/buttons/toggle_style_button.dart | 12 +- .../config}/base_button_configurations.dart | 6 +- .../buttons/clear_format_configurations.dart | 2 +- .../config}/buttons/color_configurations.dart | 5 +- .../buttons/custom_button_configurations.dart | 0 .../buttons/font_family_configurations.dart | 2 +- .../buttons/font_size_configurations.dart | 4 +- .../buttons/history_configurations.dart | 2 +- .../buttons/indent_configurations.dart | 0 .../buttons/link_style2_configurations.dart | 2 +- .../buttons/link_style_configurations.dart | 6 +- .../buttons/search_configurations.dart | 2 +- .../select_alignment_configurations.dart | 2 +- ...t_header_style_buttons_configurations.dart | 4 +- ..._style_dropdown_button_configurations.dart | 6 +- ..._style_dropdown_button_configurations.dart | 6 +- .../toggle_check_list_configurations.dart | 4 +- .../buttons/toggle_style_configurations.dart | 0 .../simple_toolbar_button_options.dart | 2 +- .../simple_toolbar_configurations.dart | 22 +-- .../config}/toolbar_configurations.dart | 0 .../toolbar_shared_configurations.dart | 6 +- .../toolbar/embed/embed_button_builder.dart | 12 ++ lib/src/toolbar/provider.dart | 74 ++++++++ .../{widgets => }/toolbar/simple_toolbar.dart | 7 +- lib/src/toolbar/simple_toolbar_provider.dart | 77 ++++++++ .../structs/link_dialog_action.dart | 0 .../theme}/quill_dialog_theme.dart | 0 .../theme}/quill_icon_theme.dart | 1 - lib/src/widgets/utils/provider.dart | 179 ------------------ lib/translations.dart | 2 +- test/bug_fix_test.dart | 10 - test/{ => common}/utils/platform_test.dart | 2 +- .../controller_test.dart | 0 test/{utils => document}/attributes_test.dart | 0 test/{utils => document}/document_test.dart | 0 test/{widgets => editor}/editor_test.dart | 0 153 files changed, 747 insertions(+), 761 deletions(-) rename lib/src/{ => common}/extensions/uri_ext.dart (100%) rename lib/src/{models => common}/structs/image_url.dart (100%) rename lib/src/{models => common}/structs/offset_value.dart (100%) rename lib/src/{models => common}/structs/optional_size.dart (100%) rename lib/src/{models => common}/structs/segment_leaf_node.dart (68%) rename lib/src/{models => common}/structs/vertical_spacing.dart (100%) rename lib/src/{ => common}/utils/cast.dart (100%) rename lib/src/{ => common}/utils/color.dart (100%) rename lib/src/{ => common}/utils/embeds.dart (77%) rename lib/src/{ => common}/utils/font.dart (96%) rename lib/src/{ => common}/utils/platform.dart (100%) rename lib/src/{ => common}/utils/string.dart (100%) rename lib/src/{ => common}/utils/widgets.dart (100%) create mode 100644 lib/src/controller/provider.dart rename lib/src/{widgets/quill => controller}/quill_controller.dart (97%) rename lib/src/{models/config => controller}/quill_controller_configurations.dart (100%) rename lib/src/{utils/delta.dart => delta/delta_diff.dart} (96%) rename lib/src/{models/documents => delta}/delta_x.dart (95%) rename lib/src/{models/documents => document}/attribute.dart (94%) create mode 100644 lib/src/document/custom_attributes.dart rename lib/src/{models/documents => document}/document.dart (97%) rename lib/src/{models/documents => document}/history.dart (96%) rename lib/src/{models/documents => document}/nodes/block.dart (100%) rename lib/src/{models/documents => document}/nodes/container.dart (98%) rename lib/src/{models/documents => document}/nodes/embeddable.dart (100%) rename lib/src/{models/documents => document}/nodes/leaf.dart (99%) rename lib/src/{models/documents => document}/nodes/line.dart (99%) rename lib/src/{models/documents => document}/nodes/node.dart (98%) rename lib/src/{models => document}/structs/doc_change.dart (91%) rename lib/src/{models => document}/structs/history_changed.dart (100%) rename lib/src/{models/documents => document}/style.dart (100%) rename lib/src/{models/config/editor => editor/config}/editor_configurations.dart (97%) rename lib/src/{models/config/editor => editor/config}/element_options.dart (100%) rename lib/src/{models/config/editor => editor/config}/elements/code_block.dart (100%) rename lib/src/{models/config/editor => editor/config}/elements/list/ordered_list.dart (100%) rename lib/src/{models/config/editor => editor/config}/elements/list/unordered_list.dart (100%) rename lib/src/{widgets => }/editor/editor.dart (98%) rename lib/src/{widgets => }/editor/editor_builder.dart (87%) rename lib/src/{widgets/quill/embeds.dart => editor/embed/embed_editor_builder.dart} (53%) create mode 100644 lib/src/editor/provider.dart rename lib/src/{models/config/raw_editor => editor/raw_editor/config}/raw_editor_configurations.dart (95%) rename lib/src/{widgets => editor}/raw_editor/quill_single_child_scroll_view.dart (100%) rename lib/src/{widgets => editor}/raw_editor/raw_editor.dart (92%) rename lib/src/{widgets => editor}/raw_editor/raw_editor_actions.dart (98%) rename lib/src/{widgets => editor}/raw_editor/raw_editor_render_object.dart (95%) rename lib/src/{widgets => editor}/raw_editor/raw_editor_state.dart (98%) rename lib/src/{widgets => editor}/raw_editor/raw_editor_state_selection_delegate_mixin.dart (98%) rename lib/src/{widgets => editor}/raw_editor/raw_editor_state_text_input_client_mixin.dart (99%) rename lib/src/{widgets => editor}/raw_editor/raw_editor_text_boundaries.dart (98%) rename lib/src/{widgets => editor}/raw_editor/scribble_focusable.dart (100%) rename lib/src/{widgets => editor}/style_widgets/bullet_point.dart (93%) rename lib/src/{widgets => editor}/style_widgets/checkbox_point.dart (100%) rename lib/src/{widgets => editor}/style_widgets/number_point.dart (97%) rename lib/src/{widgets => editor}/style_widgets/style_widgets.dart (100%) rename lib/src/{widgets/others => editor/widgets}/box.dart (98%) rename lib/src/{widgets/others => editor/widgets}/cursor.dart (99%) rename lib/src/{widgets/others => editor/widgets}/default_styles.dart (98%) rename lib/src/{widgets/others => editor/widgets}/delegate.dart (97%) rename lib/src/{widgets/others => editor/widgets}/float_cursor.dart (100%) rename lib/src/{widgets/others => editor/widgets}/keyboard_listener.dart (100%) rename lib/src/{widgets/others => editor/widgets}/link.dart (97%) rename lib/src/{widgets/others => editor/widgets}/proxy.dart (100%) rename lib/src/{widgets/quill => editor/widgets/text}/text_block.dart (96%) rename lib/src/{widgets/quill => editor/widgets/text}/text_line.dart (98%) rename lib/src/{widgets/others => editor/widgets/text}/text_selection.dart (99%) rename lib/src/{services => editor_toolbar_controller_shared}/clipboard/clipboard_service.dart (100%) rename lib/src/{services => editor_toolbar_controller_shared}/clipboard/clipboard_service_provider.dart (100%) rename lib/src/{services => editor_toolbar_controller_shared}/clipboard/default_clipboard_service.dart (100%) create mode 100644 lib/src/editor_toolbar_controller_shared/quill_configurations.dart rename lib/src/{models => editor_toolbar_shared}/config/quill_shared_configurations.dart (82%) create mode 100644 lib/src/editor_toolbar_shared/quill_configurations_ext.dart delete mode 100644 lib/src/extensions/quill_configurations_ext.dart delete mode 100644 lib/src/extensions/quill_controller_ext.dart rename lib/src/l10n/extensions/{localizations.dart => localizations_ext.dart} (100%) delete mode 100644 lib/src/models/config/others/animations.dart delete mode 100644 lib/src/models/config/quill_configurations.dart rename lib/src/{models => }/rules/delete.dart (96%) rename lib/src/{models => }/rules/format.dart (97%) rename lib/src/{models => }/rules/insert.dart (98%) rename lib/src/{models => }/rules/rule.dart (95%) rename lib/src/{widgets => }/toolbar/base_button/base_value_button.dart (98%) rename lib/src/{widgets => }/toolbar/base_button/stateless_base_button.dart (91%) rename lib/src/{widgets => }/toolbar/base_toolbar.dart (85%) rename lib/src/{widgets => }/toolbar/buttons/alignment/select_alignment_button.dart (90%) rename lib/src/{widgets => }/toolbar/buttons/alignment/select_alignment_buttons.dart (93%) rename lib/src/{widgets => }/toolbar/buttons/arrow_indicated_list_button.dart (100%) rename lib/src/{widgets => }/toolbar/buttons/clear_format_button.dart (94%) rename lib/src/{widgets => }/toolbar/buttons/clipboard_button.dart (94%) rename lib/src/{widgets => }/toolbar/buttons/color/color_button.dart (94%) rename lib/src/{widgets => }/toolbar/buttons/color/color_dialog.dart (98%) rename lib/src/{widgets => }/toolbar/buttons/custom_button_button.dart (92%) rename lib/src/{widgets => }/toolbar/buttons/font_family_button.dart (97%) rename lib/src/{widgets => }/toolbar/buttons/font_size_button.dart (96%) rename lib/src/{widgets => }/toolbar/buttons/hearder_style/select_header_style_buttons.dart (93%) rename lib/src/{widgets => }/toolbar/buttons/hearder_style/select_header_style_dropdown_button.dart (95%) rename lib/src/{widgets => }/toolbar/buttons/history_button.dart (98%) rename lib/src/{widgets => }/toolbar/buttons/indent_button.dart (94%) rename lib/src/{widgets => }/toolbar/buttons/link_style2_button.dart (96%) rename lib/src/{widgets => }/toolbar/buttons/link_style_button.dart (95%) rename lib/src/{widgets => }/toolbar/buttons/quill_icon_button.dart (98%) rename lib/src/{widgets => }/toolbar/buttons/search/legacy/legacy_search_button.dart (90%) rename lib/src/{widgets => }/toolbar/buttons/search/legacy/legacy_search_dialog.dart (96%) rename lib/src/{widgets => }/toolbar/buttons/search/search_button.dart (89%) rename lib/src/{widgets => }/toolbar/buttons/search/search_dialog.dart (96%) rename lib/src/{widgets => }/toolbar/buttons/select_line_height_dropdown_button.dart (95%) rename lib/src/{widgets => }/toolbar/buttons/toggle_check_list_button.dart (93%) rename lib/src/{widgets => }/toolbar/buttons/toggle_style_button.dart (94%) rename lib/src/{models/config/toolbar => toolbar/config}/base_button_configurations.dart (94%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/clear_format_configurations.dart (89%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/color_configurations.dart (88%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/custom_button_configurations.dart (100%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/font_family_configurations.dart (98%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/font_size_configurations.dart (96%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/history_configurations.dart (94%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/indent_configurations.dart (100%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/link_style2_configurations.dart (96%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/link_style_configurations.dart (85%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/search_configurations.dart (97%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/select_alignment_configurations.dart (98%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/select_header_style_buttons_configurations.dart (91%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/select_header_style_dropdown_button_configurations.dart (93%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/select_line_height_style_dropdown_button_configurations.dart (93%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/toggle_check_list_configurations.dart (90%) rename lib/src/{models/config/toolbar => toolbar/config}/buttons/toggle_style_configurations.dart (100%) rename lib/src/{models/config/toolbar => toolbar/config}/simple_toolbar_button_options.dart (99%) rename lib/src/{models/config/toolbar => toolbar/config}/simple_toolbar_configurations.dart (91%) rename lib/src/{models/config/toolbar => toolbar/config}/toolbar_configurations.dart (100%) rename lib/src/{models/config/toolbar => toolbar/config}/toolbar_shared_configurations.dart (92%) create mode 100644 lib/src/toolbar/embed/embed_button_builder.dart create mode 100644 lib/src/toolbar/provider.dart rename lib/src/{widgets => }/toolbar/simple_toolbar.dart (98%) create mode 100644 lib/src/toolbar/simple_toolbar_provider.dart rename lib/src/{models => toolbar}/structs/link_dialog_action.dart (100%) rename lib/src/{models/themes => toolbar/theme}/quill_dialog_theme.dart (100%) rename lib/src/{models/themes => toolbar/theme}/quill_icon_theme.dart (97%) delete mode 100644 lib/src/widgets/utils/provider.dart rename test/{ => common}/utils/platform_test.dart (98%) rename test/{widgets => controller}/controller_test.dart (100%) rename test/{utils => document}/attributes_test.dart (100%) rename test/{utils => document}/document_test.dart (100%) rename test/{widgets => editor}/editor_test.dart (100%) diff --git a/README.md b/README.md index 04790d13..15447bbc 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ dependencies: ## 🛠 Platform Specific Configurations -Before using the package, we must inform you the package uses the following plugins: +The `flutter_quill` package uses the following plugins: 1. [`url_launcher`](https://pub.dev/packages/url_launcher) to open links. 2. [`device_info_plus`](https://pub.dev/packages/device_info_plus) to view info about the current device. diff --git a/analysis_options.yaml b/analysis_options.yaml index f1a38172..91ce6469 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -12,7 +12,6 @@ linter: avoid_empty_else: true avoid_escaping_inner_quotes: true avoid_print: true - avoid_redundant_argument_values: true avoid_types_on_closure_parameters: true avoid_void_async: true cascade_invocations: true diff --git a/flutter_quill_extensions/lib/flutter_quill_extensions.dart b/flutter_quill_extensions/lib/flutter_quill_extensions.dart index e9b55328..3e55369b 100644 --- a/flutter_quill_extensions/lib/flutter_quill_extensions.dart +++ b/flutter_quill_extensions/lib/flutter_quill_extensions.dart @@ -1,7 +1,7 @@ library flutter_quill_extensions; // ignore: implementation_imports -import 'package:flutter_quill/src/services/clipboard/clipboard_service_provider.dart'; +import 'package:flutter_quill/src/editor_toolbar_controller_shared/clipboard/clipboard_service_provider.dart'; import 'package:meta/meta.dart' show immutable; import 'services/clipboard/super_clipboard_service.dart'; @@ -38,6 +38,9 @@ export 'models/config/video/editor/video_web_configurations.dart'; export 'models/config/video/toolbar/video_configurations.dart'; export 'utils/utils.dart'; +// TODO: Refactor flutter_quill_extensions to match the structure of flutter_quill +// Also avoid exposing all APIs as public. Use `src` as directory name + @immutable class FlutterQuillExtensions { const FlutterQuillExtensions._(); diff --git a/flutter_quill_extensions/lib/services/clipboard/super_clipboard_service.dart b/flutter_quill_extensions/lib/services/clipboard/super_clipboard_service.dart index 2514f7a8..cd83b410 100644 --- a/flutter_quill_extensions/lib/services/clipboard/super_clipboard_service.dart +++ b/flutter_quill_extensions/lib/services/clipboard/super_clipboard_service.dart @@ -3,7 +3,8 @@ import 'dart:convert' show utf8; import 'package:flutter/foundation.dart'; // ignore: implementation_imports -import 'package:flutter_quill/src/services/clipboard/clipboard_service.dart'; +import 'package:flutter_quill/src/editor_toolbar_controller_shared/clipboard/clipboard_service.dart'; + import 'package:super_clipboard/super_clipboard.dart'; /// Implementation based on https://pub.dev/packages/super_clipboard diff --git a/lib/extensions.dart b/lib/extensions.dart index 79f53845..99e6194f 100644 --- a/lib/extensions.dart +++ b/lib/extensions.dart @@ -1,7 +1,7 @@ library flutter_quill.extensions; -export 'src/models/documents/nodes/leaf.dart'; -export 'src/models/rules/insert.dart'; -export 'src/utils/platform.dart'; -export 'src/utils/string.dart'; -export 'src/utils/widgets.dart'; +export 'src/common/utils/platform.dart'; +export 'src/common/utils/string.dart'; +export 'src/common/utils/widgets.dart'; +export 'src/document/nodes/leaf.dart'; +export 'src/rules/insert.dart'; diff --git a/lib/flutter_quill.dart b/lib/flutter_quill.dart index a2719729..efac79a0 100644 --- a/lib/flutter_quill.dart +++ b/lib/flutter_quill.dart @@ -1,38 +1,42 @@ library flutter_quill; -export '/src/widgets/raw_editor/quill_single_child_scroll_view.dart'; -export 'src/extensions/quill_configurations_ext.dart'; -export 'src/models/config/quill_configurations.dart'; -export 'src/models/config/raw_editor/raw_editor_configurations.dart'; -export 'src/models/config/toolbar/toolbar_configurations.dart'; -export 'src/models/documents/attribute.dart'; -export 'src/models/documents/document.dart'; -export 'src/models/documents/nodes/block.dart'; -export 'src/models/documents/nodes/embeddable.dart'; -export 'src/models/documents/nodes/leaf.dart'; -export 'src/models/documents/nodes/line.dart'; -export 'src/models/documents/nodes/node.dart'; -export 'src/models/documents/style.dart'; -export 'src/models/structs/doc_change.dart'; -export 'src/models/structs/image_url.dart'; -export 'src/models/structs/link_dialog_action.dart'; -export 'src/models/structs/offset_value.dart'; -export 'src/models/structs/optional_size.dart'; -export 'src/models/structs/vertical_spacing.dart'; -export 'src/models/themes/quill_dialog_theme.dart'; -export 'src/models/themes/quill_icon_theme.dart'; -export 'src/utils/embeds.dart'; -export 'src/widgets/editor/editor.dart'; -export 'src/widgets/others/cursor.dart'; -export 'src/widgets/others/default_styles.dart'; -export 'src/widgets/others/link.dart'; -export 'src/widgets/quill/embeds.dart'; -export 'src/widgets/quill/quill_controller.dart'; -export 'src/widgets/raw_editor/raw_editor.dart'; -export 'src/widgets/raw_editor/raw_editor_state.dart'; -export 'src/widgets/style_widgets/style_widgets.dart'; -export 'src/widgets/toolbar/base_toolbar.dart'; -export 'src/widgets/toolbar/buttons/alignment/select_alignment_button.dart'; -export 'src/widgets/toolbar/buttons/hearder_style/select_header_style_dropdown_button.dart'; -export 'src/widgets/toolbar/simple_toolbar.dart'; -export 'src/widgets/utils/provider.dart'; +export 'src/common/structs/image_url.dart'; +export 'src/common/structs/offset_value.dart'; +export 'src/common/structs/optional_size.dart'; +export 'src/common/structs/vertical_spacing.dart'; +export 'src/common/utils/embeds.dart'; +export 'src/controller/provider.dart'; +export 'src/controller/quill_controller.dart'; +export 'src/document/attribute.dart'; +export 'src/document/document.dart'; +export 'src/document/nodes/block.dart'; +export 'src/document/nodes/embeddable.dart'; +export 'src/document/nodes/leaf.dart'; +export 'src/document/nodes/line.dart'; +export 'src/document/nodes/node.dart'; +export 'src/document/structs/doc_change.dart'; +export 'src/document/style.dart'; +export 'src/editor/editor.dart'; +export 'src/editor/embed/embed_editor_builder.dart'; +export 'src/editor/provider.dart'; +export 'src/editor/raw_editor/config/raw_editor_configurations.dart'; +export 'src/editor/raw_editor/quill_single_child_scroll_view.dart'; +export 'src/editor/raw_editor/raw_editor.dart'; +export 'src/editor/raw_editor/raw_editor_state.dart'; +export 'src/editor/style_widgets/style_widgets.dart'; +export 'src/editor/widgets/cursor.dart'; +export 'src/editor/widgets/default_styles.dart'; +export 'src/editor/widgets/link.dart'; +export 'src/editor_toolbar_controller_shared/quill_configurations.dart'; +export 'src/editor_toolbar_shared/quill_configurations_ext.dart'; +export 'src/toolbar/base_toolbar.dart'; +export 'src/toolbar/buttons/alignment/select_alignment_button.dart'; +export 'src/toolbar/buttons/hearder_style/select_header_style_dropdown_button.dart'; +export 'src/toolbar/config/toolbar_configurations.dart'; +export 'src/toolbar/embed/embed_button_builder.dart'; +export 'src/toolbar/provider.dart'; +export 'src/toolbar/simple_toolbar.dart'; +export 'src/toolbar/simple_toolbar_provider.dart'; +export 'src/toolbar/structs/link_dialog_action.dart'; +export 'src/toolbar/theme/quill_dialog_theme.dart'; +export 'src/toolbar/theme/quill_icon_theme.dart'; diff --git a/lib/markdown_quill.dart b/lib/markdown_quill.dart index cca0aa1c..50e11442 100644 --- a/lib/markdown_quill.dart +++ b/lib/markdown_quill.dart @@ -1,5 +1,7 @@ library quill_markdown; +// TODO: Might avoid exposing the quill_markdown package + export 'src/packages/quill_markdown/delta_to_markdown.dart'; export 'src/packages/quill_markdown/embeddable_table_syntax.dart'; export 'src/packages/quill_markdown/markdown_to_delta.dart'; diff --git a/lib/src/extensions/uri_ext.dart b/lib/src/common/extensions/uri_ext.dart similarity index 100% rename from lib/src/extensions/uri_ext.dart rename to lib/src/common/extensions/uri_ext.dart diff --git a/lib/src/models/structs/image_url.dart b/lib/src/common/structs/image_url.dart similarity index 100% rename from lib/src/models/structs/image_url.dart rename to lib/src/common/structs/image_url.dart diff --git a/lib/src/models/structs/offset_value.dart b/lib/src/common/structs/offset_value.dart similarity index 100% rename from lib/src/models/structs/offset_value.dart rename to lib/src/common/structs/offset_value.dart diff --git a/lib/src/models/structs/optional_size.dart b/lib/src/common/structs/optional_size.dart similarity index 100% rename from lib/src/models/structs/optional_size.dart rename to lib/src/common/structs/optional_size.dart diff --git a/lib/src/models/structs/segment_leaf_node.dart b/lib/src/common/structs/segment_leaf_node.dart similarity index 68% rename from lib/src/models/structs/segment_leaf_node.dart rename to lib/src/common/structs/segment_leaf_node.dart index 880dd912..2b014cf8 100644 --- a/lib/src/models/structs/segment_leaf_node.dart +++ b/lib/src/common/structs/segment_leaf_node.dart @@ -1,7 +1,7 @@ import 'package:meta/meta.dart' show immutable; -import '../documents/nodes/leaf.dart'; -import '../documents/nodes/line.dart'; +import '../../document/nodes/leaf.dart'; +import '../../document/nodes/line.dart'; @immutable class SegmentLeafNode { diff --git a/lib/src/models/structs/vertical_spacing.dart b/lib/src/common/structs/vertical_spacing.dart similarity index 100% rename from lib/src/models/structs/vertical_spacing.dart rename to lib/src/common/structs/vertical_spacing.dart diff --git a/lib/src/utils/cast.dart b/lib/src/common/utils/cast.dart similarity index 100% rename from lib/src/utils/cast.dart rename to lib/src/common/utils/cast.dart diff --git a/lib/src/utils/color.dart b/lib/src/common/utils/color.dart similarity index 100% rename from lib/src/utils/color.dart rename to lib/src/common/utils/color.dart diff --git a/lib/src/utils/embeds.dart b/lib/src/common/utils/embeds.dart similarity index 77% rename from lib/src/utils/embeds.dart rename to lib/src/common/utils/embeds.dart index 4b3e2de3..2c423970 100644 --- a/lib/src/utils/embeds.dart +++ b/lib/src/common/utils/embeds.dart @@ -1,8 +1,8 @@ import 'dart:math'; -import '../models/documents/nodes/leaf.dart'; -import '../models/structs/offset_value.dart'; -import '../widgets/quill/quill_controller.dart'; +import '../../controller/quill_controller.dart'; +import '../../document/nodes/leaf.dart'; +import '../structs/offset_value.dart'; OffsetValue getEmbedNode(QuillController controller, int offset) { var offset = controller.selection.start; diff --git a/lib/src/utils/font.dart b/lib/src/common/utils/font.dart similarity index 96% rename from lib/src/utils/font.dart rename to lib/src/common/utils/font.dart index 423c9581..d12ffd00 100644 --- a/lib/src/utils/font.dart +++ b/lib/src/common/utils/font.dart @@ -1,4 +1,4 @@ -import '../../flutter_quill.dart'; +import '../../../flutter_quill.dart'; dynamic getFontSize(dynamic sizeValue) { if (sizeValue is String && diff --git a/lib/src/utils/platform.dart b/lib/src/common/utils/platform.dart similarity index 100% rename from lib/src/utils/platform.dart rename to lib/src/common/utils/platform.dart diff --git a/lib/src/utils/string.dart b/lib/src/common/utils/string.dart similarity index 100% rename from lib/src/utils/string.dart rename to lib/src/common/utils/string.dart diff --git a/lib/src/utils/widgets.dart b/lib/src/common/utils/widgets.dart similarity index 100% rename from lib/src/utils/widgets.dart rename to lib/src/common/utils/widgets.dart diff --git a/lib/src/controller/provider.dart b/lib/src/controller/provider.dart new file mode 100644 index 00000000..45ed01aa --- /dev/null +++ b/lib/src/controller/provider.dart @@ -0,0 +1,19 @@ +import 'package:flutter/widgets.dart' show BuildContext; + +import '../editor/provider.dart'; +import '../toolbar/simple_toolbar_provider.dart'; +import 'quill_controller.dart'; + +extension QuillControllerExt on BuildContext { + QuillController? get quilController { + return quillSimpleToolbarConfigurations?.controller ?? + quillEditorConfigurations?.controller; + } + + QuillController get requireQuillController { + return quillSimpleToolbarConfigurations?.controller ?? + quillEditorConfigurations?.controller ?? + (throw ArgumentError( + 'The quill provider is required, you must only call requireQuillController inside the QuillToolbar and QuillEditor')); + } +} diff --git a/lib/src/widgets/quill/quill_controller.dart b/lib/src/controller/quill_controller.dart similarity index 97% rename from lib/src/widgets/quill/quill_controller.dart rename to lib/src/controller/quill_controller.dart index bf21c8f4..c31290bb 100644 --- a/lib/src/widgets/quill/quill_controller.dart +++ b/lib/src/controller/quill_controller.dart @@ -5,11 +5,19 @@ import 'package:flutter/widgets.dart'; import 'package:html/parser.dart' as html_parser; import 'package:meta/meta.dart'; -import '../../../flutter_quill.dart'; -import '../../../quill_delta.dart'; -import '../../models/documents/delta_x.dart'; -import '../../services/clipboard/clipboard_service_provider.dart'; -import '../../utils/delta.dart'; +import '../../quill_delta.dart'; +import '../common/structs/image_url.dart'; +import '../common/structs/offset_value.dart'; +import '../delta/delta_diff.dart'; +import '../delta/delta_x.dart'; +import '../document/attribute.dart'; +import '../document/document.dart'; +import '../document/nodes/embeddable.dart'; +import '../document/nodes/leaf.dart'; +import '../document/structs/doc_change.dart'; +import '../document/style.dart'; +import '../editor_toolbar_controller_shared/clipboard/clipboard_service_provider.dart'; +import 'quill_controller_configurations.dart'; typedef ReplaceTextCallback = bool Function(int index, int len, Object? data); typedef DeleteCallback = void Function(int cursorPosition, bool forward); diff --git a/lib/src/models/config/quill_controller_configurations.dart b/lib/src/controller/quill_controller_configurations.dart similarity index 100% rename from lib/src/models/config/quill_controller_configurations.dart rename to lib/src/controller/quill_controller_configurations.dart diff --git a/lib/src/utils/delta.dart b/lib/src/delta/delta_diff.dart similarity index 96% rename from lib/src/utils/delta.dart rename to lib/src/delta/delta_diff.dart index da6cf545..a3c2c4ad 100644 --- a/lib/src/utils/delta.dart +++ b/lib/src/delta/delta_diff.dart @@ -1,11 +1,11 @@ import 'dart:math' as math; -import 'dart:ui'; +import 'dart:ui' show TextDirection; import 'package:meta/meta.dart' show immutable; import '../../quill_delta.dart'; -import '../models/documents/attribute.dart'; -import '../models/documents/nodes/node.dart'; +import '../document/attribute.dart'; +import '../document/nodes/node.dart'; // Diff between two texts - old text and new text @immutable diff --git a/lib/src/models/documents/delta_x.dart b/lib/src/delta/delta_x.dart similarity index 95% rename from lib/src/models/documents/delta_x.dart rename to lib/src/delta/delta_x.dart index 370b8b39..ab05f44b 100644 --- a/lib/src/models/documents/delta_x.dart +++ b/lib/src/delta/delta_x.dart @@ -1,8 +1,8 @@ import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart'; import 'package:markdown/markdown.dart' as md; import 'package:meta/meta.dart'; -import '../../../markdown_quill.dart'; -import '../../../quill_delta.dart'; +import '../../markdown_quill.dart'; +import '../../quill_delta.dart'; @immutable @experimental diff --git a/lib/src/models/documents/attribute.dart b/lib/src/document/attribute.dart similarity index 94% rename from lib/src/models/documents/attribute.dart rename to lib/src/document/attribute.dart index deea5a15..1590adc5 100644 --- a/lib/src/models/documents/attribute.dart +++ b/lib/src/document/attribute.dart @@ -4,6 +4,9 @@ import 'package:equatable/equatable.dart'; import 'package:meta/meta.dart' show immutable; import 'package:quiver/core.dart'; +import 'custom_attributes.dart'; +export 'custom_attributes.dart'; + enum AttributeScope { inline, // refer to https://quilljs.com/docs/formats/#inline block, // refer to https://quilljs.com/docs/formats/#block @@ -354,27 +357,6 @@ class HeaderAttribute extends Attribute { : super('header', AttributeScope.block, level); } -/// This attribute represents the space between text lines. The line height can be -/// adjusted using predefined constants or custom values -/// -/// The attribute at the json looks like: "attributes":{"line-height": 1.5 } -class LineHeightAttribute extends Attribute { - const LineHeightAttribute({double? lineHeight}) - : super('line-height', AttributeScope.block, lineHeight); - - static const Attribute lineHeightNormal = - LineHeightAttribute(lineHeight: 1); - - static const Attribute lineHeightTight = - LineHeightAttribute(lineHeight: 1.15); - - static const Attribute lineHeightOneAndHalf = - LineHeightAttribute(lineHeight: 1.5); - - static const Attribute lineHeightDouble = - LineHeightAttribute(lineHeight: 2); -} - class IndentAttribute extends Attribute { const IndentAttribute({int? level}) : super('indent', AttributeScope.block, level); diff --git a/lib/src/document/custom_attributes.dart b/lib/src/document/custom_attributes.dart new file mode 100644 index 00000000..625dab1d --- /dev/null +++ b/lib/src/document/custom_attributes.dart @@ -0,0 +1,25 @@ +import 'attribute.dart'; + +// Attributes that don't conform to standard Quill Delta +// and are not compatible with https://quilljs.com/docs/delta/ + +/// This attribute represents the space between text lines. The line height can be +/// adjusted using predefined constants or custom values +/// +/// The attribute at the json looks like: "attributes":{"line-height": 1.5 } +class LineHeightAttribute extends Attribute { + const LineHeightAttribute({double? lineHeight}) + : super('line-height', AttributeScope.block, lineHeight); + + static const Attribute lineHeightNormal = + LineHeightAttribute(lineHeight: 1); + + static const Attribute lineHeightTight = + LineHeightAttribute(lineHeight: 1.15); + + static const Attribute lineHeightOneAndHalf = + LineHeightAttribute(lineHeight: 1.5); + + static const Attribute lineHeightDouble = + LineHeightAttribute(lineHeight: 2); +} diff --git a/lib/src/models/documents/document.dart b/lib/src/document/document.dart similarity index 97% rename from lib/src/models/documents/document.dart rename to lib/src/document/document.dart index c20ab27d..e1f75575 100644 --- a/lib/src/models/documents/document.dart +++ b/lib/src/document/document.dart @@ -1,16 +1,14 @@ import 'dart:async' show StreamController; -import 'package:meta/meta.dart'; +import 'package:meta/meta.dart' show experimental; -import '../../../quill_delta.dart'; -import '../../widgets/quill/embeds.dart'; +import '../../quill_delta.dart'; +import '../common/structs/offset_value.dart'; +import '../common/structs/segment_leaf_node.dart'; +import '../delta/delta_x.dart'; +import '../editor/embed/embed_editor_builder.dart'; import '../rules/rule.dart'; -import '../structs/doc_change.dart'; -import '../structs/history_changed.dart'; -import '../structs/offset_value.dart'; -import '../structs/segment_leaf_node.dart'; import 'attribute.dart'; -import 'delta_x.dart'; import 'history.dart'; import 'nodes/block.dart'; import 'nodes/container.dart'; @@ -18,6 +16,8 @@ import 'nodes/embeddable.dart'; import 'nodes/leaf.dart'; import 'nodes/line.dart'; import 'nodes/node.dart'; +import 'structs/doc_change.dart'; +import 'structs/history_changed.dart'; import 'style.dart'; /// The rich text document @@ -251,7 +251,8 @@ class Document { if (res.node is Line) { return res; } - final block = res.node as Block; // TODO: Can be nullable, handle this case + final block = res.node + as Block; // TODO: Can be nullable, handle this case to avoid cast exception return block.queryChild(res.offset, true); } diff --git a/lib/src/models/documents/history.dart b/lib/src/document/history.dart similarity index 96% rename from lib/src/models/documents/history.dart rename to lib/src/document/history.dart index 39173783..2721e83b 100644 --- a/lib/src/models/documents/history.dart +++ b/lib/src/document/history.dart @@ -1,7 +1,7 @@ -import '../../../quill_delta.dart'; -import '../structs/doc_change.dart'; -import '../structs/history_changed.dart'; +import '../../quill_delta.dart'; import 'document.dart'; +import 'structs/doc_change.dart'; +import 'structs/history_changed.dart'; class History { History({ diff --git a/lib/src/models/documents/nodes/block.dart b/lib/src/document/nodes/block.dart similarity index 100% rename from lib/src/models/documents/nodes/block.dart rename to lib/src/document/nodes/block.dart diff --git a/lib/src/models/documents/nodes/container.dart b/lib/src/document/nodes/container.dart similarity index 98% rename from lib/src/models/documents/nodes/container.dart rename to lib/src/document/nodes/container.dart index 7b5bb551..acc2f8d5 100644 --- a/lib/src/models/documents/nodes/container.dart +++ b/lib/src/document/nodes/container.dart @@ -1,6 +1,6 @@ -import 'dart:collection'; +import 'dart:collection' show LinkedList; -import '../../../widgets/quill/embeds.dart'; +import '../../editor/embed/embed_editor_builder.dart'; import '../style.dart'; import 'leaf.dart'; import 'line.dart'; diff --git a/lib/src/models/documents/nodes/embeddable.dart b/lib/src/document/nodes/embeddable.dart similarity index 100% rename from lib/src/models/documents/nodes/embeddable.dart rename to lib/src/document/nodes/embeddable.dart diff --git a/lib/src/models/documents/nodes/leaf.dart b/lib/src/document/nodes/leaf.dart similarity index 99% rename from lib/src/models/documents/nodes/leaf.dart rename to lib/src/document/nodes/leaf.dart index 43a5e1ff..15c0aeb9 100644 --- a/lib/src/models/documents/nodes/leaf.dart +++ b/lib/src/document/nodes/leaf.dart @@ -1,7 +1,7 @@ import 'dart:math' as math; import '../../../../quill_delta.dart'; -import '../../../widgets/quill/embeds.dart'; +import '../../editor/embed/embed_editor_builder.dart'; import '../style.dart'; import 'embeddable.dart'; import 'line.dart'; @@ -154,7 +154,8 @@ abstract base class Leaf extends Node { } /// Splits this leaf node at [index] and returns new node. - /// + ///import '../style.dart'; + /// If this is the last node in its list and [index] equals this node's /// length then this method returns `null` as there is nothing left to split. /// If there is another leaf node after this one and [index] equals this diff --git a/lib/src/models/documents/nodes/line.dart b/lib/src/document/nodes/line.dart similarity index 99% rename from lib/src/models/documents/nodes/line.dart rename to lib/src/document/nodes/line.dart index ee467d4e..d442cde6 100644 --- a/lib/src/models/documents/nodes/line.dart +++ b/lib/src/document/nodes/line.dart @@ -3,8 +3,8 @@ import 'dart:math' as math; import 'package:collection/collection.dart'; import '../../../../quill_delta.dart'; -import '../../../widgets/quill/embeds.dart'; -import '../../structs/offset_value.dart'; +import '../../common/structs/offset_value.dart'; +import '../../editor/embed/embed_editor_builder.dart'; import '../attribute.dart'; import '../style.dart'; import 'block.dart'; diff --git a/lib/src/models/documents/nodes/node.dart b/lib/src/document/nodes/node.dart similarity index 98% rename from lib/src/models/documents/nodes/node.dart rename to lib/src/document/nodes/node.dart index 0287dc4d..947d3f1d 100644 --- a/lib/src/models/documents/nodes/node.dart +++ b/lib/src/document/nodes/node.dart @@ -1,7 +1,7 @@ import 'dart:collection'; import '../../../../quill_delta.dart'; -import '../../../widgets/quill/embeds.dart'; +import '../../editor/embed/embed_editor_builder.dart'; import '../attribute.dart'; import '../style.dart'; import 'container.dart'; diff --git a/lib/src/models/structs/doc_change.dart b/lib/src/document/structs/doc_change.dart similarity index 91% rename from lib/src/models/structs/doc_change.dart rename to lib/src/document/structs/doc_change.dart index 50453995..dbe31e7a 100644 --- a/lib/src/models/structs/doc_change.dart +++ b/lib/src/document/structs/doc_change.dart @@ -1,7 +1,7 @@ import 'package:meta/meta.dart' show immutable; import '../../../quill_delta.dart'; -import '../documents/document.dart'; +import '../document.dart'; @immutable class DocChange { diff --git a/lib/src/models/structs/history_changed.dart b/lib/src/document/structs/history_changed.dart similarity index 100% rename from lib/src/models/structs/history_changed.dart rename to lib/src/document/structs/history_changed.dart diff --git a/lib/src/models/documents/style.dart b/lib/src/document/style.dart similarity index 100% rename from lib/src/models/documents/style.dart rename to lib/src/document/style.dart diff --git a/lib/src/models/config/editor/editor_configurations.dart b/lib/src/editor/config/editor_configurations.dart similarity index 97% rename from lib/src/models/config/editor/editor_configurations.dart rename to lib/src/editor/config/editor_configurations.dart index 98219fa5..2c4b1ae4 100644 --- a/lib/src/models/config/editor/editor_configurations.dart +++ b/lib/src/editor/config/editor_configurations.dart @@ -6,15 +6,15 @@ import 'package:flutter/material.dart' import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart' show experimental; -import '../../../widgets/editor/editor_builder.dart'; -import '../../../widgets/others/default_styles.dart'; -import '../../../widgets/others/delegate.dart'; -import '../../../widgets/others/link.dart'; -import '../../../widgets/quill/embeds.dart'; -import '../../../widgets/quill/quill_controller.dart'; -import '../../../widgets/raw_editor/raw_editor.dart'; -import '../../themes/quill_dialog_theme.dart'; -import '../quill_shared_configurations.dart'; +import '../../controller/quill_controller.dart'; +import '../../editor_toolbar_shared/config/quill_shared_configurations.dart'; +import '../../toolbar/theme/quill_dialog_theme.dart'; +import '../editor_builder.dart'; +import '../embed/embed_editor_builder.dart'; +import '../raw_editor/raw_editor.dart'; +import '../widgets/default_styles.dart'; +import '../widgets/delegate.dart'; +import '../widgets/link.dart'; import 'element_options.dart'; export 'element_options.dart'; diff --git a/lib/src/models/config/editor/element_options.dart b/lib/src/editor/config/element_options.dart similarity index 100% rename from lib/src/models/config/editor/element_options.dart rename to lib/src/editor/config/element_options.dart diff --git a/lib/src/models/config/editor/elements/code_block.dart b/lib/src/editor/config/elements/code_block.dart similarity index 100% rename from lib/src/models/config/editor/elements/code_block.dart rename to lib/src/editor/config/elements/code_block.dart diff --git a/lib/src/models/config/editor/elements/list/ordered_list.dart b/lib/src/editor/config/elements/list/ordered_list.dart similarity index 100% rename from lib/src/models/config/editor/elements/list/ordered_list.dart rename to lib/src/editor/config/elements/list/ordered_list.dart diff --git a/lib/src/models/config/editor/elements/list/unordered_list.dart b/lib/src/editor/config/elements/list/unordered_list.dart similarity index 100% rename from lib/src/models/config/editor/elements/list/unordered_list.dart rename to lib/src/editor/config/elements/list/unordered_list.dart diff --git a/lib/src/widgets/editor/editor.dart b/lib/src/editor/editor.dart similarity index 98% rename from lib/src/widgets/editor/editor.dart rename to lib/src/editor/editor.dart index 4be76e54..b0347b29 100644 --- a/lib/src/widgets/editor/editor.dart +++ b/lib/src/editor/editor.dart @@ -9,22 +9,22 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; -import '../../l10n/widgets/localizations.dart'; -import '../../models/config/editor/editor_configurations.dart'; -import '../../models/config/raw_editor/raw_editor_configurations.dart'; -import '../../models/documents/document.dart'; -import '../../models/documents/nodes/container.dart' as container_node; -import '../../models/documents/nodes/leaf.dart'; -import '../../utils/platform.dart'; -import '../others/box.dart'; -import '../others/cursor.dart'; -import '../others/delegate.dart'; -import '../others/float_cursor.dart'; -import '../others/text_selection.dart'; -import '../quill/embeds.dart'; -import '../raw_editor/raw_editor.dart'; -import '../utils/provider.dart'; +import '../common/utils/platform.dart'; +import '../document/document.dart'; +import '../document/nodes/container.dart' as container_node; +import '../document/nodes/leaf.dart'; +import '../l10n/widgets/localizations.dart'; +import 'config/editor_configurations.dart'; import 'editor_builder.dart'; +import 'embed/embed_editor_builder.dart'; +import 'provider.dart'; +import 'raw_editor/config/raw_editor_configurations.dart'; +import 'raw_editor/raw_editor.dart'; +import 'widgets/box.dart'; +import 'widgets/cursor.dart'; +import 'widgets/delegate.dart'; +import 'widgets/float_cursor.dart'; +import 'widgets/text/text_selection.dart'; /// Base interface for editable render objects. abstract class RenderAbstractEditor implements TextLayoutMetrics { diff --git a/lib/src/widgets/editor/editor_builder.dart b/lib/src/editor/editor_builder.dart similarity index 87% rename from lib/src/widgets/editor/editor_builder.dart rename to lib/src/editor/editor_builder.dart index 926af254..95195cbf 100644 --- a/lib/src/widgets/editor/editor_builder.dart +++ b/lib/src/editor/editor_builder.dart @@ -1,6 +1,6 @@ -import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; -import '../raw_editor/raw_editor.dart'; +import 'raw_editor/raw_editor.dart'; typedef QuillEditorBuilder = Widget Function( BuildContext context, diff --git a/lib/src/widgets/quill/embeds.dart b/lib/src/editor/embed/embed_editor_builder.dart similarity index 53% rename from lib/src/widgets/quill/embeds.dart rename to lib/src/editor/embed/embed_editor_builder.dart index d575f2fe..3710db91 100644 --- a/lib/src/widgets/quill/embeds.dart +++ b/lib/src/editor/embed/embed_editor_builder.dart @@ -1,10 +1,8 @@ -import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import '../../../extensions.dart'; -import '../../models/documents/nodes/leaf.dart' as leaf; -import '../../models/themes/quill_dialog_theme.dart'; -import '../../models/themes/quill_icon_theme.dart'; -import 'quill_controller.dart'; +import '../../controller/quill_controller.dart'; +import '../../document/nodes/leaf.dart' as leaf; abstract class EmbedBuilder { const EmbedBuilder(); @@ -28,9 +26,4 @@ abstract class EmbedBuilder { ); } -typedef EmbedButtonBuilder = Widget Function( - QuillController controller, - double toolbarIconSize, - QuillIconTheme? iconTheme, - QuillDialogTheme? dialogTheme, -); +typedef EmbedsBuilder = EmbedBuilder Function(Embed node); diff --git a/lib/src/editor/provider.dart b/lib/src/editor/provider.dart new file mode 100644 index 00000000..159ce1ea --- /dev/null +++ b/lib/src/editor/provider.dart @@ -0,0 +1,78 @@ +import 'package:flutter/foundation.dart' show debugPrint, kDebugMode; +import 'package:flutter/widgets.dart' + show BuildContext, InheritedWidget, Widget; + +import 'config/editor_configurations.dart'; + +class QuillEditorProvider extends InheritedWidget { + const QuillEditorProvider({ + required super.child, + required this.editorConfigurations, + super.key, + }); + + final QuillEditorConfigurations editorConfigurations; + + @override + bool updateShouldNotify(covariant QuillEditorProvider oldWidget) { + return oldWidget.editorConfigurations != editorConfigurations; + } + + static QuillEditorProvider? maybeOf(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType(); + } + + static QuillEditorProvider of(BuildContext context) { + final provider = maybeOf(context); + if (provider == null) { + if (kDebugMode) { + debugPrint( + 'The quill editor provider must be provided in the widget tree.', + ); + } + throw ArgumentError.checkNotNull( + 'You are using a widget in the Flutter quill library that require ' + 'The Quill editor provider widget to be in the parent widget tree ' + 'because ' + 'The provider is $provider. Please make sure to wrap this widget' + ' with' + ' QuillEditorProvider widget. ' + 'You might using QuillEditor so make sure to' + ' wrap them with the quill provider widget and setup the required ' + 'configurations', + 'QuillEditorProvider', + ); + } + return provider; + } + + /// To pass the [QuillEditorProvider] instance as value instead of creating + /// new widget + static QuillEditorProvider value({ + required QuillEditorProvider value, + required Widget child, + }) { + return QuillEditorProvider( + editorConfigurations: value.editorConfigurations, + child: child, + ); + } +} + +extension QuillEditorExt on BuildContext { + QuillEditorConfigurations get requireQuillEditorConfigurations { + return QuillEditorProvider.of(this).editorConfigurations; + } + + QuillEditorConfigurations? get quillEditorConfigurations { + return QuillEditorProvider.maybeOf(this)?.editorConfigurations; + } + + QuillEditorElementOptions? get quillEditorElementOptions { + return quillEditorConfigurations?.elementOptions; + } + + QuillEditorElementOptions get requireQuillEditorElementOptions { + return requireQuillEditorConfigurations.elementOptions; + } +} diff --git a/lib/src/models/config/raw_editor/raw_editor_configurations.dart b/lib/src/editor/raw_editor/config/raw_editor_configurations.dart similarity index 95% rename from lib/src/models/config/raw_editor/raw_editor_configurations.dart rename to lib/src/editor/raw_editor/config/raw_editor_configurations.dart index 7683fc18..4c8bb96e 100644 --- a/lib/src/models/config/raw_editor/raw_editor_configurations.dart +++ b/lib/src/editor/raw_editor/config/raw_editor_configurations.dart @@ -28,14 +28,15 @@ import 'package:flutter/widgets.dart' SystemMouseCursors; import 'package:meta/meta.dart' show immutable; -import '../../../widgets/others/cursor.dart'; -import '../../../widgets/others/default_styles.dart'; -import '../../../widgets/others/delegate.dart'; -import '../../../widgets/others/link.dart'; -import '../../../widgets/quill/quill_controller.dart'; -import '../../../widgets/raw_editor/raw_editor.dart'; -import '../../../widgets/raw_editor/raw_editor_state.dart'; -import '../../themes/quill_dialog_theme.dart'; +import '../../../controller/quill_controller.dart'; +import '../../../editor/embed/embed_editor_builder.dart'; +import '../../../editor/raw_editor/raw_editor.dart'; +import '../../../editor/raw_editor/raw_editor_state.dart'; +import '../../../editor/widgets/cursor.dart'; +import '../../../editor/widgets/default_styles.dart'; +import '../../../editor/widgets/delegate.dart'; +import '../../../editor/widgets/link.dart'; +import '../../../toolbar/theme/quill_dialog_theme.dart'; @immutable class QuillRawEditorConfigurations extends Equatable { diff --git a/lib/src/widgets/raw_editor/quill_single_child_scroll_view.dart b/lib/src/editor/raw_editor/quill_single_child_scroll_view.dart similarity index 100% rename from lib/src/widgets/raw_editor/quill_single_child_scroll_view.dart rename to lib/src/editor/raw_editor/quill_single_child_scroll_view.dart diff --git a/lib/src/widgets/raw_editor/raw_editor.dart b/lib/src/editor/raw_editor/raw_editor.dart similarity index 92% rename from lib/src/widgets/raw_editor/raw_editor.dart rename to lib/src/editor/raw_editor/raw_editor.dart index 65d095b1..d748ba84 100644 --- a/lib/src/widgets/raw_editor/raw_editor.dart +++ b/lib/src/editor/raw_editor/raw_editor.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'dart:ui' show Offset; import 'package:flutter/widgets.dart' show @@ -11,10 +11,10 @@ import 'package:flutter/widgets.dart' Widget; import 'package:meta/meta.dart' show immutable; -import '../../models/config/raw_editor/raw_editor_configurations.dart'; -import '../../models/structs/offset_value.dart'; -import '../editor/editor.dart'; -import '../others/text_selection.dart'; +import '../../common/structs/offset_value.dart'; +import '../editor.dart'; +import '../widgets/text/text_selection.dart'; +import 'config/raw_editor_configurations.dart'; import 'raw_editor_state.dart'; class QuillRawEditor extends StatefulWidget { diff --git a/lib/src/widgets/raw_editor/raw_editor_actions.dart b/lib/src/editor/raw_editor/raw_editor_actions.dart similarity index 98% rename from lib/src/widgets/raw_editor/raw_editor_actions.dart rename to lib/src/editor/raw_editor/raw_editor_actions.dart index a6e3fb2f..1fba4318 100644 --- a/lib/src/widgets/raw_editor/raw_editor_actions.dart +++ b/lib/src/editor/raw_editor/raw_editor_actions.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import '../../../translations.dart'; -import '../../models/documents/attribute.dart'; -import '../editor/editor.dart'; -import '../others/link.dart'; -import '../toolbar/buttons/link_style2_button.dart'; -import '../toolbar/buttons/search/search_dialog.dart'; +import '../../document/attribute.dart'; +import '../../toolbar/buttons/link_style2_button.dart'; +import '../../toolbar/buttons/search/search_dialog.dart'; +import '../editor.dart'; +import '../widgets/link.dart'; import 'raw_editor_state.dart'; import 'raw_editor_text_boundaries.dart'; diff --git a/lib/src/widgets/raw_editor/raw_editor_render_object.dart b/lib/src/editor/raw_editor/raw_editor_render_object.dart similarity index 95% rename from lib/src/widgets/raw_editor/raw_editor_render_object.dart rename to lib/src/editor/raw_editor/raw_editor_render_object.dart index ec9fb2cd..d7953621 100644 --- a/lib/src/widgets/raw_editor/raw_editor_render_object.dart +++ b/lib/src/editor/raw_editor/raw_editor_render_object.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart' show ViewportOffset; -import '../../models/documents/document.dart'; -import '../editor/editor.dart'; -import '../others/cursor.dart'; +import '../../document/document.dart'; +import '../editor.dart'; +import '../widgets/cursor.dart'; class QuillRawEditorMultiChildRenderObject extends MultiChildRenderObjectWidget { diff --git a/lib/src/widgets/raw_editor/raw_editor_state.dart b/lib/src/editor/raw_editor/raw_editor_state.dart similarity index 98% rename from lib/src/widgets/raw_editor/raw_editor_state.dart rename to lib/src/editor/raw_editor/raw_editor_state.dart index 25be9499..91774bc1 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state.dart +++ b/lib/src/editor/raw_editor/raw_editor_state.dart @@ -20,30 +20,30 @@ import 'package:flutter/services.dart' import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart' show KeyboardVisibilityController; -import '../../models/documents/attribute.dart'; -import '../../models/documents/document.dart'; -import '../../models/documents/nodes/block.dart'; -import '../../models/documents/nodes/embeddable.dart'; -import '../../models/documents/nodes/leaf.dart' as leaf; -import '../../models/documents/nodes/line.dart'; -import '../../models/documents/nodes/node.dart'; -import '../../models/structs/offset_value.dart'; -import '../../models/structs/vertical_spacing.dart'; -import '../../services/clipboard/clipboard_service_provider.dart'; -import '../../utils/cast.dart'; -import '../../utils/delta.dart'; -import '../../utils/embeds.dart'; -import '../../utils/platform.dart'; -import '../editor/editor.dart'; -import '../others/cursor.dart'; -import '../others/default_styles.dart'; -import '../others/keyboard_listener.dart'; -import '../others/link.dart'; -import '../others/proxy.dart'; -import '../others/text_selection.dart'; -import '../quill/quill_controller.dart'; -import '../quill/text_block.dart'; -import '../quill/text_line.dart'; +import '../../common/structs/offset_value.dart'; +import '../../common/structs/vertical_spacing.dart'; +import '../../common/utils/cast.dart'; +import '../../common/utils/embeds.dart'; +import '../../common/utils/platform.dart'; +import '../../controller/quill_controller.dart'; +import '../../delta/delta_diff.dart'; +import '../../document/attribute.dart'; +import '../../document/document.dart'; +import '../../document/nodes/block.dart'; +import '../../document/nodes/embeddable.dart'; +import '../../document/nodes/leaf.dart' as leaf; +import '../../document/nodes/line.dart'; +import '../../document/nodes/node.dart'; +import '../../editor_toolbar_controller_shared/clipboard/clipboard_service_provider.dart'; +import '../editor.dart'; +import '../widgets/cursor.dart'; +import '../widgets/default_styles.dart'; +import '../widgets/keyboard_listener.dart'; +import '../widgets/link.dart'; +import '../widgets/proxy.dart'; +import '../widgets/text/text_block.dart'; +import '../widgets/text/text_line.dart'; +import '../widgets/text/text_selection.dart'; import 'quill_single_child_scroll_view.dart'; import 'raw_editor.dart'; import 'raw_editor_actions.dart'; @@ -1774,8 +1774,6 @@ class QuillRawEditorState extends EditorState } } - // TODO: Review those - @override bool get liveTextInputEnabled => false; diff --git a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart b/lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart similarity index 98% rename from lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart rename to lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart index 3956a0ac..55cda637 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart +++ b/lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart @@ -3,8 +3,8 @@ import 'dart:math' as math; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; -import '../../models/documents/document.dart'; -import '../../utils/delta.dart'; +import '../../delta/delta_diff.dart'; +import '../../document/document.dart'; import 'raw_editor.dart'; mixin RawEditorStateSelectionDelegateMixin on EditorState diff --git a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart b/lib/src/editor/raw_editor/raw_editor_state_text_input_client_mixin.dart similarity index 99% rename from lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart rename to lib/src/editor/raw_editor/raw_editor_state_text_input_client_mixin.dart index 2c792741..5eb38892 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart +++ b/lib/src/editor/raw_editor/raw_editor_state_text_input_client_mixin.dart @@ -7,9 +7,9 @@ import 'package:flutter/material.dart' show Theme; import 'package:flutter/scheduler.dart' show SchedulerBinding; import 'package:flutter/services.dart'; -import '../../models/documents/document.dart'; -import '../../utils/delta.dart'; -import '../editor/editor.dart'; +import '../../delta/delta_diff.dart'; +import '../../document/document.dart'; +import '../editor.dart'; import 'raw_editor.dart'; mixin RawEditorStateTextInputClientMixin on EditorState diff --git a/lib/src/widgets/raw_editor/raw_editor_text_boundaries.dart b/lib/src/editor/raw_editor/raw_editor_text_boundaries.dart similarity index 98% rename from lib/src/widgets/raw_editor/raw_editor_text_boundaries.dart rename to lib/src/editor/raw_editor/raw_editor_text_boundaries.dart index d89d0665..f15fd8e0 100644 --- a/lib/src/widgets/raw_editor/raw_editor_text_boundaries.dart +++ b/lib/src/editor/raw_editor/raw_editor_text_boundaries.dart @@ -135,8 +135,7 @@ class QuillEditorWordBoundary extends QuillEditorTextBoundary { return TextPosition( offset: textLayout.getWordBoundary(position).start, // Word boundary seems to always report downstream on many platforms. - affinity: - TextAffinity.downstream, // ignore: avoid_redundant_argument_values + affinity: TextAffinity.downstream, ); } @@ -145,8 +144,7 @@ class QuillEditorWordBoundary extends QuillEditorTextBoundary { return TextPosition( offset: textLayout.getWordBoundary(position).end, // Word boundary seems to always report downstream on many platforms. - affinity: - TextAffinity.downstream, // ignore: avoid_redundant_argument_values + affinity: TextAffinity.downstream, ); } } diff --git a/lib/src/widgets/raw_editor/scribble_focusable.dart b/lib/src/editor/raw_editor/scribble_focusable.dart similarity index 100% rename from lib/src/widgets/raw_editor/scribble_focusable.dart rename to lib/src/editor/raw_editor/scribble_focusable.dart diff --git a/lib/src/widgets/style_widgets/bullet_point.dart b/lib/src/editor/style_widgets/bullet_point.dart similarity index 93% rename from lib/src/widgets/style_widgets/bullet_point.dart rename to lib/src/editor/style_widgets/bullet_point.dart index 2b20d7a7..7872d58e 100644 --- a/lib/src/widgets/style_widgets/bullet_point.dart +++ b/lib/src/editor/style_widgets/bullet_point.dart @@ -1,6 +1,6 @@ import 'package:flutter/widgets.dart'; -import '../../extensions/quill_configurations_ext.dart'; +import '../provider.dart'; class QuillEditorBulletPoint extends StatelessWidget { const QuillEditorBulletPoint({ diff --git a/lib/src/widgets/style_widgets/checkbox_point.dart b/lib/src/editor/style_widgets/checkbox_point.dart similarity index 100% rename from lib/src/widgets/style_widgets/checkbox_point.dart rename to lib/src/editor/style_widgets/checkbox_point.dart diff --git a/lib/src/widgets/style_widgets/number_point.dart b/lib/src/editor/style_widgets/number_point.dart similarity index 97% rename from lib/src/widgets/style_widgets/number_point.dart rename to lib/src/editor/style_widgets/number_point.dart index 33029841..7064da01 100644 --- a/lib/src/widgets/style_widgets/number_point.dart +++ b/lib/src/editor/style_widgets/number_point.dart @@ -1,7 +1,7 @@ -import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import '../../../flutter_quill.dart'; -import '../quill/text_block.dart'; +import '../widgets/text/text_block.dart'; class QuillEditorNumberPoint extends StatelessWidget { const QuillEditorNumberPoint({ diff --git a/lib/src/widgets/style_widgets/style_widgets.dart b/lib/src/editor/style_widgets/style_widgets.dart similarity index 100% rename from lib/src/widgets/style_widgets/style_widgets.dart rename to lib/src/editor/style_widgets/style_widgets.dart diff --git a/lib/src/widgets/others/box.dart b/lib/src/editor/widgets/box.dart similarity index 98% rename from lib/src/widgets/others/box.dart rename to lib/src/editor/widgets/box.dart index 8787763d..cb790027 100644 --- a/lib/src/widgets/others/box.dart +++ b/lib/src/editor/widgets/box.dart @@ -1,6 +1,6 @@ import 'package:flutter/rendering.dart'; -import '../../models/documents/nodes/container.dart'; +import '../../document/nodes/container.dart'; /// A common interface to render boxes which represent a piece of rich text /// content. diff --git a/lib/src/widgets/others/cursor.dart b/lib/src/editor/widgets/cursor.dart similarity index 99% rename from lib/src/widgets/others/cursor.dart rename to lib/src/editor/widgets/cursor.dart index c9daeb0b..5b2fa21e 100644 --- a/lib/src/widgets/others/cursor.dart +++ b/lib/src/editor/widgets/cursor.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:flutter/widgets.dart'; -import '../../utils/platform.dart'; +import '../../common/utils/platform.dart'; import 'box.dart'; /// Style properties of editing cursor. diff --git a/lib/src/widgets/others/default_styles.dart b/lib/src/editor/widgets/default_styles.dart similarity index 98% rename from lib/src/widgets/others/default_styles.dart rename to lib/src/editor/widgets/default_styles.dart index e01408b0..65af37d6 100644 --- a/lib/src/widgets/others/default_styles.dart +++ b/lib/src/editor/widgets/default_styles.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; -import '../../models/documents/attribute.dart'; -import '../../models/documents/style.dart'; -import '../../models/structs/vertical_spacing.dart'; -import '../../utils/platform.dart'; +import '../../common/structs/vertical_spacing.dart'; +import '../../common/utils/platform.dart'; +import '../../document/attribute.dart'; +import '../../document/style.dart'; import '../style_widgets/checkbox_point.dart'; class QuillStyles extends InheritedWidget { diff --git a/lib/src/widgets/others/delegate.dart b/lib/src/editor/widgets/delegate.dart similarity index 97% rename from lib/src/widgets/others/delegate.dart rename to lib/src/editor/widgets/delegate.dart index 64ccd21b..90f1fee3 100644 --- a/lib/src/widgets/others/delegate.dart +++ b/lib/src/editor/widgets/delegate.dart @@ -3,15 +3,12 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -import '../../models/documents/attribute.dart'; -import '../../models/documents/nodes/leaf.dart'; -import '../../utils/platform.dart'; -import '../editor/editor.dart'; -import '../quill/embeds.dart'; +import '../../common/utils/platform.dart'; +import '../../document/attribute.dart'; +import '../../document/nodes/leaf.dart'; +import '../editor.dart'; import '../raw_editor/raw_editor.dart'; -import 'text_selection.dart'; - -typedef EmbedsBuilder = EmbedBuilder Function(Embed node); +import 'text/text_selection.dart'; typedef CustomStyleBuilder = TextStyle Function(Attribute attribute); diff --git a/lib/src/widgets/others/float_cursor.dart b/lib/src/editor/widgets/float_cursor.dart similarity index 100% rename from lib/src/widgets/others/float_cursor.dart rename to lib/src/editor/widgets/float_cursor.dart diff --git a/lib/src/widgets/others/keyboard_listener.dart b/lib/src/editor/widgets/keyboard_listener.dart similarity index 100% rename from lib/src/widgets/others/keyboard_listener.dart rename to lib/src/editor/widgets/keyboard_listener.dart diff --git a/lib/src/widgets/others/link.dart b/lib/src/editor/widgets/link.dart similarity index 97% rename from lib/src/widgets/others/link.dart rename to lib/src/editor/widgets/link.dart index b94b6993..f6b9f755 100644 --- a/lib/src/widgets/others/link.dart +++ b/lib/src/editor/widgets/link.dart @@ -2,10 +2,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import '../../l10n/extensions/localizations.dart'; -import '../../models/documents/attribute.dart'; -import '../../models/documents/nodes/node.dart'; -import '../../widgets/quill/quill_controller.dart'; +import '../../controller/quill_controller.dart'; +import '../../document/attribute.dart'; +import '../../document/nodes/node.dart'; +import '../../l10n/extensions/localizations_ext.dart'; const linkPrefixes = [ 'mailto:', // email diff --git a/lib/src/widgets/others/proxy.dart b/lib/src/editor/widgets/proxy.dart similarity index 100% rename from lib/src/widgets/others/proxy.dart rename to lib/src/editor/widgets/proxy.dart diff --git a/lib/src/widgets/quill/text_block.dart b/lib/src/editor/widgets/text/text_block.dart similarity index 96% rename from lib/src/widgets/quill/text_block.dart rename to lib/src/editor/widgets/text/text_block.dart index e3de668c..5ebb361f 100644 --- a/lib/src/widgets/quill/text_block.dart +++ b/lib/src/editor/widgets/text/text_block.dart @@ -1,26 +1,27 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; -import '../../extensions/quill_configurations_ext.dart'; -import '../../models/documents/attribute.dart'; -import '../../models/documents/nodes/block.dart'; -import '../../models/documents/nodes/line.dart'; -import '../../models/structs/vertical_spacing.dart'; -import '../../utils/delta.dart'; -import '../../utils/font.dart'; -import '../editor/editor.dart'; -import '../others/box.dart'; -import '../others/cursor.dart'; -import '../others/default_styles.dart'; -import '../others/delegate.dart'; -import '../others/link.dart'; -import '../others/text_selection.dart'; -import '../style_widgets/bullet_point.dart'; -import '../style_widgets/checkbox_point.dart'; -import '../style_widgets/number_point.dart'; -import '../toolbar/base_toolbar.dart'; -import 'quill_controller.dart'; +import '../../../common/structs/vertical_spacing.dart'; +import '../../../common/utils/font.dart'; +import '../../../controller/quill_controller.dart'; +import '../../../delta/delta_diff.dart'; +import '../../../document/attribute.dart'; +import '../../../document/nodes/block.dart'; +import '../../../document/nodes/line.dart'; +import '../../../toolbar/base_toolbar.dart'; +import '../../editor.dart'; +import '../../embed/embed_editor_builder.dart'; +import '../../provider.dart'; +import '../../style_widgets/bullet_point.dart'; +import '../../style_widgets/checkbox_point.dart'; +import '../../style_widgets/number_point.dart'; +import '../box.dart'; +import '../cursor.dart'; +import '../default_styles.dart'; +import '../delegate.dart'; +import '../link.dart'; import 'text_line.dart'; +import 'text_selection.dart'; const List arabianRomanNumbers = [ 1000, diff --git a/lib/src/widgets/quill/text_line.dart b/lib/src/editor/widgets/text/text_line.dart similarity index 98% rename from lib/src/widgets/quill/text_line.dart rename to lib/src/editor/widgets/text/text_line.dart index f8224505..7cd8061b 100644 --- a/lib/src/widgets/quill/text_line.dart +++ b/lib/src/editor/widgets/text/text_line.dart @@ -1,24 +1,26 @@ import 'dart:collection'; import 'dart:math' as math; -import 'package:flutter/foundation.dart'; -import 'package:flutter/gestures.dart'; +import 'package:flutter/foundation.dart' show kIsWeb; +import 'package:flutter/gestures.dart' + show GestureRecognizer, LongPressGestureRecognizer, TapGestureRecognizer; import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; -import 'package:flutter/services.dart'; -import 'package:url_launcher/url_launcher.dart'; - -import '../../../flutter_quill.dart'; -import '../../models/documents/nodes/container.dart' as container_node; -import '../../models/documents/nodes/leaf.dart' as leaf; -import '../../utils/color.dart'; -import '../../utils/font.dart'; -import '../../utils/platform.dart'; -import '../others/box.dart'; -import '../others/delegate.dart'; -import '../others/keyboard_listener.dart'; -import '../others/proxy.dart'; -import '../others/text_selection.dart'; +import 'package:flutter/rendering.dart' + show BoxParentData, PipelineOwner, BoxHitTestResult, RenderObjectVisitor; +import 'package:flutter/services.dart' show ClipboardData, Clipboard; +import 'package:url_launcher/url_launcher_string.dart' show launchUrlString; + +import '../../../../flutter_quill.dart'; +import '../../../common/utils/color.dart'; +import '../../../common/utils/font.dart'; +import '../../../common/utils/platform.dart'; +import '../../../document/nodes/container.dart' as container_node; +import '../../../document/nodes/leaf.dart' as leaf; +import '../box.dart'; +import '../delegate.dart'; +import '../keyboard_listener.dart'; +import '../proxy.dart'; +import 'text_selection.dart'; class TextLine extends StatefulWidget { const TextLine({ @@ -536,7 +538,7 @@ class _TextLineState extends State { } Future _launchUrl(String url) async { - await launchUrl(Uri.parse(url)); + await launchUrlString(url); } void _tapNodeLink(Node node) { diff --git a/lib/src/widgets/others/text_selection.dart b/lib/src/editor/widgets/text/text_selection.dart similarity index 99% rename from lib/src/widgets/others/text_selection.dart rename to lib/src/editor/widgets/text/text_selection.dart index d66ff8f0..fc527f5d 100644 --- a/lib/src/widgets/others/text_selection.dart +++ b/lib/src/editor/widgets/text/text_selection.dart @@ -6,8 +6,8 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -import '../../models/documents/nodes/node.dart'; -import '../editor/editor.dart'; +import '../../../document/nodes/node.dart'; +import '../../editor.dart'; TextSelection localSelection(Node node, TextSelection selection, fromParent) { final base = fromParent ? node.offset : node.documentOffset; diff --git a/lib/src/services/clipboard/clipboard_service.dart b/lib/src/editor_toolbar_controller_shared/clipboard/clipboard_service.dart similarity index 100% rename from lib/src/services/clipboard/clipboard_service.dart rename to lib/src/editor_toolbar_controller_shared/clipboard/clipboard_service.dart diff --git a/lib/src/services/clipboard/clipboard_service_provider.dart b/lib/src/editor_toolbar_controller_shared/clipboard/clipboard_service_provider.dart similarity index 100% rename from lib/src/services/clipboard/clipboard_service_provider.dart rename to lib/src/editor_toolbar_controller_shared/clipboard/clipboard_service_provider.dart diff --git a/lib/src/services/clipboard/default_clipboard_service.dart b/lib/src/editor_toolbar_controller_shared/clipboard/default_clipboard_service.dart similarity index 100% rename from lib/src/services/clipboard/default_clipboard_service.dart rename to lib/src/editor_toolbar_controller_shared/clipboard/default_clipboard_service.dart diff --git a/lib/src/editor_toolbar_controller_shared/quill_configurations.dart b/lib/src/editor_toolbar_controller_shared/quill_configurations.dart new file mode 100644 index 00000000..bb5b5d1f --- /dev/null +++ b/lib/src/editor_toolbar_controller_shared/quill_configurations.dart @@ -0,0 +1,5 @@ +export '../controller/quill_controller_configurations.dart'; +export '../editor/config/editor_configurations.dart'; +export '../editor_toolbar_shared/config/quill_shared_configurations.dart'; +export '../toolbar/config/simple_toolbar_configurations.dart'; +export '../toolbar/config/toolbar_configurations.dart'; diff --git a/lib/src/models/config/quill_shared_configurations.dart b/lib/src/editor_toolbar_shared/config/quill_shared_configurations.dart similarity index 82% rename from lib/src/models/config/quill_shared_configurations.dart rename to lib/src/editor_toolbar_shared/config/quill_shared_configurations.dart index beadc432..173461a8 100644 --- a/lib/src/models/config/quill_shared_configurations.dart +++ b/lib/src/editor_toolbar_shared/config/quill_shared_configurations.dart @@ -1,12 +1,11 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart' show Color, Colors, Locale; -import '../themes/quill_dialog_theme.dart'; -import 'editor/editor_configurations.dart' show QuillEditorConfigurations; -import 'toolbar/simple_toolbar_configurations.dart' +import '../../editor/config/editor_configurations.dart' + show QuillEditorConfigurations; +import '../../toolbar/config/simple_toolbar_configurations.dart' show QuillSimpleToolbarConfigurations; - -export './others/animations.dart'; +import '../../toolbar/theme/quill_dialog_theme.dart'; /// The shared configurations between [QuillEditorConfigurations] and /// [QuillSimpleToolbarConfigurations] so we don't duplicate things @@ -34,7 +33,8 @@ class QuillSharedConfigurations extends Equatable { /// `MaterialApp` or `WidgetsApp` final Locale? locale; - /// Store custom configurations in here and use it in the widget tree + /// Store custom configurations in here and use it in the widget tree. + /// Useful for `flutter_quill_extensions` to store additional configurations. final Map extraConfigurations; @override diff --git a/lib/src/editor_toolbar_shared/quill_configurations_ext.dart b/lib/src/editor_toolbar_shared/quill_configurations_ext.dart new file mode 100644 index 00000000..64c0691f --- /dev/null +++ b/lib/src/editor_toolbar_shared/quill_configurations_ext.dart @@ -0,0 +1,13 @@ +import 'package:flutter/widgets.dart' show BuildContext; + +import '../editor/provider.dart'; +import '../toolbar/simple_toolbar_provider.dart'; +import 'config/quill_shared_configurations.dart'; + +extension QuillSharedExt on BuildContext { + /// return nullable [QuillSharedConfigurations] + QuillSharedConfigurations? get quillSharedConfigurations { + return quillSimpleToolbarConfigurations?.sharedConfigurations ?? + quillEditorConfigurations?.sharedConfigurations; + } +} diff --git a/lib/src/extensions/quill_configurations_ext.dart b/lib/src/extensions/quill_configurations_ext.dart deleted file mode 100644 index 7abfbda9..00000000 --- a/lib/src/extensions/quill_configurations_ext.dart +++ /dev/null @@ -1,84 +0,0 @@ -import 'package:flutter/widgets.dart' show BuildContext; - -import '../../flutter_quill.dart'; - -extension QuillControllerExt on BuildContext { - /// return nullable [QuillController] - QuillController? get quilController { - return quillSimpleToolbarConfigurations?.controller ?? - quillEditorConfigurations?.controller; - } - - /// return [QuillController] as not null - QuillController get requireQuillController { - return quillSimpleToolbarConfigurations?.controller ?? - quillEditorConfigurations?.controller ?? - (throw ArgumentError( - 'The quill provider is required, you must only call requireQuillController inside the QuillToolbar and QuillEditor')); - } -} - -extension QuillSharedExt on BuildContext { - /// return nullable [QuillSharedConfigurations] - QuillSharedConfigurations? get quillSharedConfigurations { - return quillSimpleToolbarConfigurations?.sharedConfigurations ?? - quillEditorConfigurations?.sharedConfigurations; - } -} - -extension QuillEditorExt on BuildContext { - /// return [QuillEditorConfigurations] as not null - QuillEditorConfigurations get requireQuillEditorConfigurations { - return QuillEditorProvider.of(this).editorConfigurations; - } - - /// return nullable [QuillEditorConfigurations] - QuillEditorConfigurations? get quillEditorConfigurations { - return QuillEditorProvider.maybeOf(this)?.editorConfigurations; - } - - /// return nullable [QuillToolbarBaseButtonOptions]. Since the quill - /// quill editor block options is in the [QuillEditorProvider] then we need to - /// get the provider widget first and then we will return block options - /// throw exception if [QuillEditorProvider] is not in the widget tree - QuillEditorElementOptions? get quillEditorElementOptions { - return quillEditorConfigurations?.elementOptions; - } - - /// return [QuillToolbarBaseButtonOptions] as not null. Since the quill - /// quill editor block options is in the [QuillEditorProvider] then we need to - /// get the provider widget first and then we will return block options - /// don't throw exception if [QuillEditorProvider] is not in the widget tree - QuillEditorElementOptions get requireQuillEditorElementOptions { - return requireQuillEditorConfigurations.elementOptions; - } -} - -extension QuillSimpleToolbarExt on BuildContext { - /// return [QuillSimpleToolbarConfigurations] as not null - QuillSimpleToolbarConfigurations get requireQuillSimpleToolbarConfigurations { - return QuillSimpleToolbarProvider.of(this).toolbarConfigurations; - } - - /// return nullable [QuillSimpleToolbarConfigurations] - QuillSimpleToolbarConfigurations? get quillSimpleToolbarConfigurations { - return QuillSimpleToolbarProvider.maybeOf(this)?.toolbarConfigurations; - } - - /// return nullable [QuillToolbarBaseButtonOptions]. - QuillToolbarBaseButtonOptions? get quillToolbarBaseButtonOptions { - return quillSimpleToolbarConfigurations?.buttonOptions.base; - } -} - -extension QuillToolbarExt on BuildContext { - /// return [QuillToolbarConfigurations] as not null - QuillToolbarConfigurations get requireQuillToolbarConfigurations { - return QuillToolbarProvider.of(this).toolbarConfigurations; - } - - /// return nullable [QuillToolbarConfigurations]. - QuillToolbarConfigurations? get quillToolbarConfigurations { - return QuillToolbarProvider.maybeOf(this)?.toolbarConfigurations; - } -} diff --git a/lib/src/extensions/quill_controller_ext.dart b/lib/src/extensions/quill_controller_ext.dart deleted file mode 100644 index 49c09f97..00000000 --- a/lib/src/extensions/quill_controller_ext.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:flutter/widgets.dart' show BuildContext; - -import '../../flutter_quill.dart' show QuillController; -import 'quill_configurations_ext.dart'; - -extension QuillControllerNullableExt on QuillController? { - /// Simple logic to use the current passed controller if not null - /// if null then we will have to use the default one - /// using the [context] - QuillController notNull(BuildContext context) { - final controller = this; - if (controller != null) { - return controller; - } - return context.requireQuillController; - } -} diff --git a/lib/src/l10n/extensions/localizations.dart b/lib/src/l10n/extensions/localizations_ext.dart similarity index 100% rename from lib/src/l10n/extensions/localizations.dart rename to lib/src/l10n/extensions/localizations_ext.dart diff --git a/lib/src/l10n/widgets/localizations.dart b/lib/src/l10n/widgets/localizations.dart index 874ffd47..ad27179d 100644 --- a/lib/src/l10n/widgets/localizations.dart +++ b/lib/src/l10n/widgets/localizations.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import '../../extensions/quill_configurations_ext.dart'; -import '../extensions/localizations.dart'; +import '../../editor_toolbar_shared/quill_configurations_ext.dart'; +import '../extensions/localizations_ext.dart'; /// A widget that check if [FlutterQuillLocalizations.delegate] is provided /// in the widgets app (e.g, [MaterialApp] or [WidgetsApp]). diff --git a/lib/src/models/config/others/animations.dart b/lib/src/models/config/others/animations.dart deleted file mode 100644 index 42e08279..00000000 --- a/lib/src/models/config/others/animations.dart +++ /dev/null @@ -1,28 +0,0 @@ -// import 'package:equatable/equatable.dart'; -// import 'package:meta/meta.dart' show experimental, immutable; - -// @immutable -// @experimental -// class QuillAnimationConfigurations extends Equatable { -// const QuillAnimationConfigurations({ -// required this.checkBoxPointItem, -// }); - -// factory QuillAnimationConfigurations.disableAll() => -// const QuillAnimationConfigurations( -// checkBoxPointItem: false, -// ); - -// factory QuillAnimationConfigurations.enableAll() => -// const QuillAnimationConfigurations( -// checkBoxPointItem: true, -// ); - -// /// This currently has issue which the whole checkbox list will rebuilt -// /// and the animation will replay when some value changes -// /// which is why disabled by default -// final bool checkBoxPointItem; - -// @override -// List get props => []; -// } diff --git a/lib/src/models/config/quill_configurations.dart b/lib/src/models/config/quill_configurations.dart deleted file mode 100644 index a07ecf1e..00000000 --- a/lib/src/models/config/quill_configurations.dart +++ /dev/null @@ -1,4 +0,0 @@ -export 'editor/editor_configurations.dart'; -export 'quill_controller_configurations.dart'; -export 'quill_shared_configurations.dart'; -export 'toolbar/simple_toolbar_configurations.dart'; diff --git a/lib/src/packages/quill_markdown/custom_quill_attributes.dart b/lib/src/packages/quill_markdown/custom_quill_attributes.dart index fef8a953..687ba2c9 100644 --- a/lib/src/packages/quill_markdown/custom_quill_attributes.dart +++ b/lib/src/packages/quill_markdown/custom_quill_attributes.dart @@ -1,4 +1,4 @@ -import '../../../flutter_quill.dart'; +import '../../document/attribute.dart'; /// Custom attribute to save the language of codeblock class CodeBlockLanguageAttribute extends Attribute { diff --git a/lib/src/packages/quill_markdown/delta_to_markdown.dart b/lib/src/packages/quill_markdown/delta_to_markdown.dart index d3e7a33b..b414ee94 100644 --- a/lib/src/packages/quill_markdown/delta_to_markdown.dart +++ b/lib/src/packages/quill_markdown/delta_to_markdown.dart @@ -1,9 +1,16 @@ import 'dart:convert'; import 'dart:ui'; -import 'package:collection/collection.dart'; -import '../../../flutter_quill.dart'; +import 'package:collection/collection.dart' show IterableExtension; + import '../../../quill_delta.dart'; +import '../../document/attribute.dart'; +import '../../document/document.dart'; +import '../../document/nodes/block.dart'; +import '../../document/nodes/embeddable.dart'; +import '../../document/nodes/leaf.dart'; +import '../../document/nodes/line.dart'; +import '../../document/nodes/node.dart'; import './custom_quill_attributes.dart'; import './utils.dart'; diff --git a/lib/src/models/rules/delete.dart b/lib/src/rules/delete.dart similarity index 96% rename from lib/src/models/rules/delete.dart rename to lib/src/rules/delete.dart index 2f36f76d..e63e1633 100644 --- a/lib/src/models/rules/delete.dart +++ b/lib/src/rules/delete.dart @@ -1,9 +1,9 @@ import 'package:meta/meta.dart' show immutable; -import '../../../quill_delta.dart'; -import '../../models/documents/document.dart'; -import '../documents/attribute.dart'; -import '../documents/nodes/embeddable.dart'; +import '../../quill_delta.dart'; +import '../document/attribute.dart'; +import '../document/document.dart'; +import '../document/nodes/embeddable.dart'; import 'rule.dart'; /// A heuristic rule for delete operations. diff --git a/lib/src/models/rules/format.dart b/lib/src/rules/format.dart similarity index 97% rename from lib/src/models/rules/format.dart rename to lib/src/rules/format.dart index f1e1b804..f3c87ffb 100644 --- a/lib/src/models/rules/format.dart +++ b/lib/src/rules/format.dart @@ -1,8 +1,8 @@ import 'package:meta/meta.dart' show immutable; -import '../../../quill_delta.dart'; -import '../../models/documents/document.dart'; -import '../documents/attribute.dart'; +import '../../quill_delta.dart'; +import '../document/attribute.dart'; +import '../document/document.dart'; import 'rule.dart'; /// A heuristic rule for format (retain) operations. diff --git a/lib/src/models/rules/insert.dart b/lib/src/rules/insert.dart similarity index 98% rename from lib/src/models/rules/insert.dart rename to lib/src/rules/insert.dart index d09bb452..a4e8e425 100644 --- a/lib/src/models/rules/insert.dart +++ b/lib/src/rules/insert.dart @@ -1,11 +1,11 @@ import 'package:meta/meta.dart' show immutable; -import '../../../quill_delta.dart'; -import '../../extensions/uri_ext.dart'; -import '../../models/documents/document.dart'; -import '../documents/attribute.dart'; -import '../documents/nodes/embeddable.dart'; -import '../documents/style.dart'; +import '../../quill_delta.dart'; +import '../common/extensions/uri_ext.dart'; +import '../document/attribute.dart'; +import '../document/document.dart'; +import '../document/nodes/embeddable.dart'; +import '../document/style.dart'; import 'rule.dart'; /// A heuristic rule for insert operations. diff --git a/lib/src/models/rules/rule.dart b/lib/src/rules/rule.dart similarity index 95% rename from lib/src/models/rules/rule.dart rename to lib/src/rules/rule.dart index fd319bb5..63c5fbc8 100644 --- a/lib/src/models/rules/rule.dart +++ b/lib/src/rules/rule.dart @@ -1,8 +1,8 @@ import 'package:meta/meta.dart' show immutable; -import '../../../quill_delta.dart'; -import '../documents/attribute.dart'; -import '../documents/document.dart'; +import '../../quill_delta.dart'; +import '../document/attribute.dart'; +import '../document/document.dart'; import 'delete.dart'; import 'format.dart'; import 'insert.dart'; diff --git a/lib/src/widgets/toolbar/base_button/base_value_button.dart b/lib/src/toolbar/base_button/base_value_button.dart similarity index 98% rename from lib/src/widgets/toolbar/base_button/base_value_button.dart rename to lib/src/toolbar/base_button/base_value_button.dart index 24cf993d..d05a72f2 100644 --- a/lib/src/widgets/toolbar/base_button/base_value_button.dart +++ b/lib/src/toolbar/base_button/base_value_button.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import '../../../../flutter_quill.dart'; +import '../../../flutter_quill.dart'; /// The [T] is the options for the button /// The [E] is the extra options for the button diff --git a/lib/src/widgets/toolbar/base_button/stateless_base_button.dart b/lib/src/toolbar/base_button/stateless_base_button.dart similarity index 91% rename from lib/src/widgets/toolbar/base_button/stateless_base_button.dart rename to lib/src/toolbar/base_button/stateless_base_button.dart index 10039383..65289d3e 100644 --- a/lib/src/widgets/toolbar/base_button/stateless_base_button.dart +++ b/lib/src/toolbar/base_button/stateless_base_button.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; -import '../../../extensions/quill_configurations_ext.dart'; -import '../../../models/themes/quill_icon_theme.dart'; -import '../../quill/quill_controller.dart'; -import '../base_toolbar.dart'; +import '../../controller/quill_controller.dart'; +import '../config/simple_toolbar_configurations.dart'; +import '../simple_toolbar_provider.dart'; +import '../theme/quill_icon_theme.dart'; + +// TODO: Use this later or remove it /// The [T] is the options for the button, usually should refresnce itself /// it's used in [childBuilder] so the developer can custmize this when using it diff --git a/lib/src/widgets/toolbar/base_toolbar.dart b/lib/src/toolbar/base_toolbar.dart similarity index 85% rename from lib/src/widgets/toolbar/base_toolbar.dart rename to lib/src/toolbar/base_toolbar.dart index 572e844f..72636f73 100644 --- a/lib/src/widgets/toolbar/base_toolbar.dart +++ b/lib/src/toolbar/base_toolbar.dart @@ -1,14 +1,12 @@ import 'package:flutter/material.dart'; -import '../../../flutter_quill.dart' +import '../../flutter_quill.dart' show QuillToolbarProvider, kDefaultToolbarSize; -import '../../l10n/widgets/localizations.dart'; -import '../../models/config/toolbar/simple_toolbar_configurations.dart'; -import '../../models/config/toolbar/toolbar_configurations.dart'; +import '../l10n/widgets/localizations.dart'; +import 'config/simple_toolbar_configurations.dart'; +import 'config/toolbar_configurations.dart'; import 'simple_toolbar.dart'; -export '../../models/config/toolbar/base_button_configurations.dart'; -export '../../models/config/toolbar/simple_toolbar_configurations.dart'; export 'buttons/clear_format_button.dart'; export 'buttons/clipboard_button.dart'; export 'buttons/color/color_button.dart'; @@ -27,6 +25,8 @@ export 'buttons/search/search_button.dart'; export 'buttons/select_line_height_dropdown_button.dart'; export 'buttons/toggle_check_list_button.dart'; export 'buttons/toggle_style_button.dart'; +export 'config/base_button_configurations.dart'; +export 'config/simple_toolbar_configurations.dart'; typedef QuillBaseToolbarChildrenBuilder = List Function( BuildContext context, diff --git a/lib/src/widgets/toolbar/buttons/alignment/select_alignment_button.dart b/lib/src/toolbar/buttons/alignment/select_alignment_button.dart similarity index 90% rename from lib/src/widgets/toolbar/buttons/alignment/select_alignment_button.dart rename to lib/src/toolbar/buttons/alignment/select_alignment_button.dart index b3931394..0acbe45d 100644 --- a/lib/src/widgets/toolbar/buttons/alignment/select_alignment_button.dart +++ b/lib/src/toolbar/buttons/alignment/select_alignment_button.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import '../../../../models/documents/attribute.dart'; -import '../../../quill/quill_controller.dart'; +import '../../../controller/quill_controller.dart'; +import '../../../document/attribute.dart'; enum _AlignmentOptions { left(attribute: Attribute.leftAlignment), diff --git a/lib/src/widgets/toolbar/buttons/alignment/select_alignment_buttons.dart b/lib/src/toolbar/buttons/alignment/select_alignment_buttons.dart similarity index 93% rename from lib/src/widgets/toolbar/buttons/alignment/select_alignment_buttons.dart rename to lib/src/toolbar/buttons/alignment/select_alignment_buttons.dart index ff7fca68..a301b1a4 100644 --- a/lib/src/widgets/toolbar/buttons/alignment/select_alignment_buttons.dart +++ b/lib/src/toolbar/buttons/alignment/select_alignment_buttons.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import '../../../../models/documents/attribute.dart'; -import '../../../quill/quill_controller.dart'; +import '../../../controller/quill_controller.dart'; +import '../../../document/attribute.dart'; import '../../base_toolbar.dart'; class QuillToolbarSelectAlignmentButtons extends StatelessWidget { diff --git a/lib/src/widgets/toolbar/buttons/arrow_indicated_list_button.dart b/lib/src/toolbar/buttons/arrow_indicated_list_button.dart similarity index 100% rename from lib/src/widgets/toolbar/buttons/arrow_indicated_list_button.dart rename to lib/src/toolbar/buttons/arrow_indicated_list_button.dart diff --git a/lib/src/widgets/toolbar/buttons/clear_format_button.dart b/lib/src/toolbar/buttons/clear_format_button.dart similarity index 94% rename from lib/src/widgets/toolbar/buttons/clear_format_button.dart rename to lib/src/toolbar/buttons/clear_format_button.dart index 1c7de128..920a14c3 100644 --- a/lib/src/widgets/toolbar/buttons/clear_format_button.dart +++ b/lib/src/toolbar/buttons/clear_format_button.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import '../../../l10n/extensions/localizations.dart'; -import '../../../models/documents/attribute.dart'; +import '../../document/attribute.dart'; +import '../../l10n/extensions/localizations_ext.dart'; import '../base_button/stateless_base_button.dart'; import '../base_toolbar.dart'; diff --git a/lib/src/widgets/toolbar/buttons/clipboard_button.dart b/lib/src/toolbar/buttons/clipboard_button.dart similarity index 94% rename from lib/src/widgets/toolbar/buttons/clipboard_button.dart rename to lib/src/toolbar/buttons/clipboard_button.dart index 6ded65f4..2c2be1ec 100644 --- a/lib/src/widgets/toolbar/buttons/clipboard_button.dart +++ b/lib/src/toolbar/buttons/clipboard_button.dart @@ -3,10 +3,10 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import '../../../../extensions.dart'; -import '../../../../flutter_quill.dart'; -import '../../../l10n/extensions/localizations.dart'; -import '../../../services/clipboard/clipboard_service_provider.dart'; +import '../../../extensions.dart'; +import '../../../flutter_quill.dart'; +import '../../editor_toolbar_controller_shared/clipboard/clipboard_service_provider.dart'; +import '../../l10n/extensions/localizations_ext.dart'; import '../base_button/base_value_button.dart'; enum ClipboardAction { cut, copy, paste } diff --git a/lib/src/widgets/toolbar/buttons/color/color_button.dart b/lib/src/toolbar/buttons/color/color_button.dart similarity index 94% rename from lib/src/widgets/toolbar/buttons/color/color_button.dart rename to lib/src/toolbar/buttons/color/color_button.dart index 308c74c4..c430582e 100644 --- a/lib/src/widgets/toolbar/buttons/color/color_button.dart +++ b/lib/src/toolbar/buttons/color/color_button.dart @@ -1,13 +1,14 @@ import 'package:flutter/material.dart'; -import '../../../../extensions/quill_configurations_ext.dart'; -import '../../../../l10n/extensions/localizations.dart'; -import '../../../../l10n/widgets/localizations.dart'; -import '../../../../models/documents/attribute.dart'; -import '../../../../models/documents/style.dart'; -import '../../../../utils/color.dart'; +import '../../../common/utils/color.dart'; +import '../../../document/attribute.dart'; +import '../../../document/style.dart'; +import '../../../editor_toolbar_shared/quill_configurations_ext.dart'; +import '../../../l10n/extensions/localizations_ext.dart'; +import '../../../l10n/widgets/localizations.dart'; import '../../base_button/base_value_button.dart'; -import '../../base_toolbar.dart'; +import '../../config/buttons/color_configurations.dart'; +import '../quill_icon_button.dart'; import 'color_dialog.dart'; typedef QuillToolbarColorBaseButton = QuillToolbarBaseButton< diff --git a/lib/src/widgets/toolbar/buttons/color/color_dialog.dart b/lib/src/toolbar/buttons/color/color_dialog.dart similarity index 98% rename from lib/src/widgets/toolbar/buttons/color/color_dialog.dart rename to lib/src/toolbar/buttons/color/color_dialog.dart index 5f0d7985..dc15c868 100644 --- a/lib/src/widgets/toolbar/buttons/color/color_dialog.dart +++ b/lib/src/toolbar/buttons/color/color_dialog.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_colorpicker/flutter_colorpicker.dart' show ColorPicker, MaterialPicker, colorToHex; -import '../../../../../translations.dart'; -import '../../../../models/documents/style.dart'; +import '../../../../translations.dart'; +import '../../../document/style.dart'; import 'color_button.dart' show hexToColor; enum _PickerType { diff --git a/lib/src/widgets/toolbar/buttons/custom_button_button.dart b/lib/src/toolbar/buttons/custom_button_button.dart similarity index 92% rename from lib/src/widgets/toolbar/buttons/custom_button_button.dart rename to lib/src/toolbar/buttons/custom_button_button.dart index f2ec87ba..78f85ee9 100644 --- a/lib/src/widgets/toolbar/buttons/custom_button_button.dart +++ b/lib/src/toolbar/buttons/custom_button_button.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; -import '../../../extensions/quill_configurations_ext.dart'; -import '../../../models/themes/quill_icon_theme.dart'; -import '../../quill/quill_controller.dart'; +import '../../controller/quill_controller.dart'; import '../base_toolbar.dart'; +import '../simple_toolbar_provider.dart'; +import '../theme/quill_icon_theme.dart'; class QuillToolbarCustomButton extends StatelessWidget { const QuillToolbarCustomButton({ diff --git a/lib/src/widgets/toolbar/buttons/font_family_button.dart b/lib/src/toolbar/buttons/font_family_button.dart similarity index 97% rename from lib/src/widgets/toolbar/buttons/font_family_button.dart rename to lib/src/toolbar/buttons/font_family_button.dart index d9001748..f759383c 100644 --- a/lib/src/widgets/toolbar/buttons/font_family_button.dart +++ b/lib/src/toolbar/buttons/font_family_button.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; -import '../../../../extensions.dart'; -import '../../../extensions/quill_configurations_ext.dart'; -import '../../../l10n/extensions/localizations.dart'; -import '../../../models/documents/attribute.dart'; +import '../../../extensions.dart'; +import '../../document/attribute.dart'; +import '../../l10n/extensions/localizations_ext.dart'; import '../base_button/base_value_button.dart'; import '../base_toolbar.dart'; +import '../simple_toolbar_provider.dart'; class QuillToolbarFontFamilyButton extends QuillToolbarBaseButton< QuillToolbarFontFamilyButtonOptions, diff --git a/lib/src/widgets/toolbar/buttons/font_size_button.dart b/lib/src/toolbar/buttons/font_size_button.dart similarity index 96% rename from lib/src/widgets/toolbar/buttons/font_size_button.dart rename to lib/src/toolbar/buttons/font_size_button.dart index effb85c4..bf94591d 100644 --- a/lib/src/widgets/toolbar/buttons/font_size_button.dart +++ b/lib/src/toolbar/buttons/font_size_button.dart @@ -1,13 +1,12 @@ import 'package:flutter/material.dart'; -import '../../../../extensions.dart'; - -import '../../../extensions/quill_configurations_ext.dart'; -import '../../../l10n/extensions/localizations.dart'; -import '../../../models/documents/attribute.dart'; -import '../../../utils/font.dart'; +import '../../../extensions.dart'; +import '../../common/utils/font.dart'; +import '../../document/attribute.dart'; +import '../../l10n/extensions/localizations_ext.dart'; import '../base_button/base_value_button.dart'; import '../base_toolbar.dart'; +import '../simple_toolbar_provider.dart'; class QuillToolbarFontSizeButton extends QuillToolbarBaseButton< QuillToolbarFontSizeButtonOptions, QuillToolbarFontSizeButtonExtraOptions> { diff --git a/lib/src/widgets/toolbar/buttons/hearder_style/select_header_style_buttons.dart b/lib/src/toolbar/buttons/hearder_style/select_header_style_buttons.dart similarity index 93% rename from lib/src/widgets/toolbar/buttons/hearder_style/select_header_style_buttons.dart rename to lib/src/toolbar/buttons/hearder_style/select_header_style_buttons.dart index c18577e1..bd082f63 100644 --- a/lib/src/widgets/toolbar/buttons/hearder_style/select_header_style_buttons.dart +++ b/lib/src/toolbar/buttons/hearder_style/select_header_style_buttons.dart @@ -1,12 +1,14 @@ import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/material.dart'; -import '../../../../extensions/quill_configurations_ext.dart'; -import '../../../../l10n/extensions/localizations.dart'; -import '../../../../models/documents/attribute.dart'; -import '../../../../models/documents/style.dart'; +import '../../../document/attribute.dart'; +import '../../../document/style.dart'; +import '../../../l10n/extensions/localizations_ext.dart'; import '../../base_button/base_value_button.dart'; -import '../../base_toolbar.dart'; +import '../../config/buttons/select_header_style_buttons_configurations.dart'; +import '../../provider.dart'; +import '../../simple_toolbar_provider.dart'; +import '../quill_icon_button.dart'; typedef QuillToolbarSelectHeaderStyleBaseButtons = QuillToolbarBaseButton< QuillToolbarSelectHeaderStyleButtonsOptions, diff --git a/lib/src/widgets/toolbar/buttons/hearder_style/select_header_style_dropdown_button.dart b/lib/src/toolbar/buttons/hearder_style/select_header_style_dropdown_button.dart similarity index 95% rename from lib/src/widgets/toolbar/buttons/hearder_style/select_header_style_dropdown_button.dart rename to lib/src/toolbar/buttons/hearder_style/select_header_style_dropdown_button.dart index cff72714..7696bb17 100644 --- a/lib/src/widgets/toolbar/buttons/hearder_style/select_header_style_dropdown_button.dart +++ b/lib/src/toolbar/buttons/hearder_style/select_header_style_dropdown_button.dart @@ -1,10 +1,11 @@ import 'package:flutter/material.dart'; -import '../../../../../translations.dart'; -import '../../../../extensions/quill_configurations_ext.dart'; -import '../../../../models/documents/attribute.dart'; +import '../../../../translations.dart'; +import '../../../document/attribute.dart'; import '../../base_button/base_value_button.dart'; -import '../../base_toolbar.dart'; +import '../../config/buttons/select_header_style_dropdown_button_configurations.dart'; +import '../../simple_toolbar_provider.dart'; +import '../quill_icon_button.dart'; typedef QuillToolbarSelectHeaderStyleDropdownBaseButton = QuillToolbarBaseButton; diff --git a/lib/src/widgets/toolbar/buttons/link_style2_button.dart b/lib/src/toolbar/buttons/link_style2_button.dart similarity index 96% rename from lib/src/widgets/toolbar/buttons/link_style2_button.dart rename to lib/src/toolbar/buttons/link_style2_button.dart index 42d04cac..69528532 100644 --- a/lib/src/widgets/toolbar/buttons/link_style2_button.dart +++ b/lib/src/toolbar/buttons/link_style2_button.dart @@ -2,17 +2,18 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:url_launcher/link.dart'; -import '../../../../extensions.dart' +import '../../../extensions.dart' show UtilityWidgets, AutoFormatMultipleLinksRule; -import '../../../extensions/quill_configurations_ext.dart'; -import '../../../l10n/extensions/localizations.dart'; -import '../../../l10n/widgets/localizations.dart'; -import '../../../models/themes/quill_dialog_theme.dart'; -import '../../../models/themes/quill_icon_theme.dart'; -import '../../others/link.dart'; -import '../../quill/quill_controller.dart'; +import '../../controller/quill_controller.dart'; +import '../../editor/widgets/link.dart'; +import '../../editor_toolbar_shared/quill_configurations_ext.dart'; +import '../../l10n/extensions/localizations_ext.dart'; +import '../../l10n/widgets/localizations.dart'; import '../base_button/base_value_button.dart'; import '../base_toolbar.dart'; +import '../simple_toolbar_provider.dart'; +import '../theme/quill_dialog_theme.dart'; +import '../theme/quill_icon_theme.dart'; typedef QuillToolbarLinkStyleBaseButton2 = QuillToolbarBaseButton< QuillToolbarLinkStyleButton2Options, diff --git a/lib/src/widgets/toolbar/buttons/link_style_button.dart b/lib/src/toolbar/buttons/link_style_button.dart similarity index 95% rename from lib/src/widgets/toolbar/buttons/link_style_button.dart rename to lib/src/toolbar/buttons/link_style_button.dart index 5284cb68..8868c1a2 100644 --- a/lib/src/widgets/toolbar/buttons/link_style_button.dart +++ b/lib/src/toolbar/buttons/link_style_button.dart @@ -1,14 +1,14 @@ import 'package:flutter/material.dart'; -import '../../../extensions/quill_configurations_ext.dart'; -import '../../../l10n/extensions/localizations.dart'; -import '../../../l10n/widgets/localizations.dart'; -import '../../../models/rules/insert.dart'; -import '../../../models/structs/link_dialog_action.dart'; -import '../../../models/themes/quill_dialog_theme.dart'; -import '../../others/link.dart'; +import '../../editor/widgets/link.dart'; +import '../../editor_toolbar_shared/quill_configurations_ext.dart'; +import '../../l10n/extensions/localizations_ext.dart'; +import '../../l10n/widgets/localizations.dart'; +import '../../rules/insert.dart'; import '../base_button/base_value_button.dart'; import '../base_toolbar.dart'; +import '../structs/link_dialog_action.dart'; +import '../theme/quill_dialog_theme.dart'; typedef QuillToolbarLinkStyleBaseButton = QuillToolbarBaseButton< QuillToolbarLinkStyleButtonOptions, diff --git a/lib/src/widgets/toolbar/buttons/quill_icon_button.dart b/lib/src/toolbar/buttons/quill_icon_button.dart similarity index 98% rename from lib/src/widgets/toolbar/buttons/quill_icon_button.dart rename to lib/src/toolbar/buttons/quill_icon_button.dart index 5cc759e0..71b3fecb 100644 --- a/lib/src/widgets/toolbar/buttons/quill_icon_button.dart +++ b/lib/src/toolbar/buttons/quill_icon_button.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import '../../../models/themes/quill_icon_theme.dart'; +import '../theme/quill_icon_theme.dart'; class QuillToolbarIconButton extends StatelessWidget { const QuillToolbarIconButton({ diff --git a/lib/src/widgets/toolbar/buttons/search/legacy/legacy_search_button.dart b/lib/src/toolbar/buttons/search/legacy/legacy_search_button.dart similarity index 90% rename from lib/src/widgets/toolbar/buttons/search/legacy/legacy_search_button.dart rename to lib/src/toolbar/buttons/search/legacy/legacy_search_button.dart index fd86303d..1ba6c5ab 100644 --- a/lib/src/widgets/toolbar/buttons/search/legacy/legacy_search_button.dart +++ b/lib/src/toolbar/buttons/search/legacy/legacy_search_button.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; -import '../../../../../extensions/quill_configurations_ext.dart'; -import '../../../../../l10n/extensions/localizations.dart'; -import '../../../../../l10n/widgets/localizations.dart'; -import '../../../../../models/themes/quill_dialog_theme.dart'; -import '../../../../../models/themes/quill_icon_theme.dart'; -import '../../../../quill/quill_controller.dart'; +import '../../../../controller/quill_controller.dart'; +import '../../../../editor_toolbar_shared/quill_configurations_ext.dart'; +import '../../../../l10n/extensions/localizations_ext.dart'; +import '../../../../l10n/widgets/localizations.dart'; import '../../../base_toolbar.dart'; +import '../../../simple_toolbar_provider.dart'; +import '../../../theme/quill_dialog_theme.dart'; +import '../../../theme/quill_icon_theme.dart'; import 'legacy_search_dialog.dart'; /// We suggest to see [QuillToolbarSearchButton] before using this widget. diff --git a/lib/src/widgets/toolbar/buttons/search/legacy/legacy_search_dialog.dart b/lib/src/toolbar/buttons/search/legacy/legacy_search_dialog.dart similarity index 96% rename from lib/src/widgets/toolbar/buttons/search/legacy/legacy_search_dialog.dart rename to lib/src/toolbar/buttons/search/legacy/legacy_search_dialog.dart index de92e27f..6ed453fb 100644 --- a/lib/src/widgets/toolbar/buttons/search/legacy/legacy_search_dialog.dart +++ b/lib/src/toolbar/buttons/search/legacy/legacy_search_dialog.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; -import '../../../../../../translations.dart'; -import '../../../../../models/documents/document.dart'; -import '../../../../../models/themes/quill_dialog_theme.dart'; -import '../../../../quill/quill_controller.dart'; +import '../../../../../translations.dart'; +import '../../../../controller/quill_controller.dart'; +import '../../../../document/document.dart'; +import '../../../theme/quill_dialog_theme.dart'; class QuillToolbarLegacySearchDialog extends StatefulWidget { const QuillToolbarLegacySearchDialog({ diff --git a/lib/src/widgets/toolbar/buttons/search/search_button.dart b/lib/src/toolbar/buttons/search/search_button.dart similarity index 89% rename from lib/src/widgets/toolbar/buttons/search/search_button.dart rename to lib/src/toolbar/buttons/search/search_button.dart index 05f7779b..05ec648a 100644 --- a/lib/src/widgets/toolbar/buttons/search/search_button.dart +++ b/lib/src/toolbar/buttons/search/search_button.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; -import '../../../../extensions/quill_configurations_ext.dart'; -import '../../../../l10n/extensions/localizations.dart'; -import '../../../../l10n/widgets/localizations.dart'; -import '../../../../models/themes/quill_dialog_theme.dart'; -import '../../../../models/themes/quill_icon_theme.dart'; -import '../../../quill/quill_controller.dart'; +import '../../../controller/quill_controller.dart'; +import '../../../editor_toolbar_shared/quill_configurations_ext.dart'; +import '../../../l10n/extensions/localizations_ext.dart'; +import '../../../l10n/widgets/localizations.dart'; import '../../base_toolbar.dart'; +import '../../simple_toolbar_provider.dart'; +import '../../theme/quill_dialog_theme.dart'; +import '../../theme/quill_icon_theme.dart'; class QuillToolbarSearchButton extends StatelessWidget { const QuillToolbarSearchButton({ @@ -22,7 +23,7 @@ class QuillToolbarSearchButton extends StatelessWidget { return _controller; } - // TODO: The logic is common and can be extracted + // TODO: Extract the common duplicated methods double _iconSize(BuildContext context) { final baseFontSize = baseButtonExtraOptions(context)?.iconSize; diff --git a/lib/src/widgets/toolbar/buttons/search/search_dialog.dart b/lib/src/toolbar/buttons/search/search_dialog.dart similarity index 96% rename from lib/src/widgets/toolbar/buttons/search/search_dialog.dart rename to lib/src/toolbar/buttons/search/search_dialog.dart index 19e041ef..780ac380 100644 --- a/lib/src/widgets/toolbar/buttons/search/search_dialog.dart +++ b/lib/src/toolbar/buttons/search/search_dialog.dart @@ -2,12 +2,12 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import '../../../../../extensions.dart'; -import '../../../../l10n/extensions/localizations.dart'; -import '../../../../l10n/widgets/localizations.dart'; -import '../../../../models/documents/document.dart'; -import '../../../../models/themes/quill_dialog_theme.dart'; -import '../../../quill/quill_controller.dart'; +import '../../../../extensions.dart'; +import '../../../controller/quill_controller.dart'; +import '../../../document/document.dart'; +import '../../../l10n/extensions/localizations_ext.dart'; +import '../../../l10n/widgets/localizations.dart'; +import '../../theme/quill_dialog_theme.dart'; @immutable class QuillToolbarSearchDialogChildBuilderExtraOptions { diff --git a/lib/src/widgets/toolbar/buttons/select_line_height_dropdown_button.dart b/lib/src/toolbar/buttons/select_line_height_dropdown_button.dart similarity index 95% rename from lib/src/widgets/toolbar/buttons/select_line_height_dropdown_button.dart rename to lib/src/toolbar/buttons/select_line_height_dropdown_button.dart index 6bb6c375..19f9728c 100644 --- a/lib/src/widgets/toolbar/buttons/select_line_height_dropdown_button.dart +++ b/lib/src/toolbar/buttons/select_line_height_dropdown_button.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; -import '../../../../translations.dart'; -import '../../../extensions/quill_configurations_ext.dart'; -import '../../../models/config/toolbar/buttons/select_line_height_style_dropdown_button_configurations.dart'; -import '../../../models/documents/attribute.dart'; -import '../../../models/themes/quill_icon_theme.dart'; +import '../../../translations.dart'; +import '../../document/attribute.dart'; import '../base_button/base_value_button.dart'; import '../base_toolbar.dart'; +import '../config/buttons/select_line_height_style_dropdown_button_configurations.dart'; +import '../simple_toolbar_provider.dart'; +import '../theme/quill_icon_theme.dart'; typedef QuillToolbarSelectLineHeightStyleDropdownBaseButton = QuillToolbarBaseButton< diff --git a/lib/src/widgets/toolbar/buttons/toggle_check_list_button.dart b/lib/src/toolbar/buttons/toggle_check_list_button.dart similarity index 93% rename from lib/src/widgets/toolbar/buttons/toggle_check_list_button.dart rename to lib/src/toolbar/buttons/toggle_check_list_button.dart index 7d79f815..77571d03 100644 --- a/lib/src/widgets/toolbar/buttons/toggle_check_list_button.dart +++ b/lib/src/toolbar/buttons/toggle_check_list_button.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; -import '../../../l10n/extensions/localizations.dart'; -import '../../../models/documents/attribute.dart'; -import '../../../models/documents/style.dart'; -import '../../../utils/widgets.dart'; +import '../../common/utils/widgets.dart'; +import '../../document/attribute.dart'; +import '../../document/style.dart'; +import '../../l10n/extensions/localizations_ext.dart'; import '../base_button/base_value_button.dart'; import '../base_toolbar.dart'; diff --git a/lib/src/widgets/toolbar/buttons/toggle_style_button.dart b/lib/src/toolbar/buttons/toggle_style_button.dart similarity index 94% rename from lib/src/widgets/toolbar/buttons/toggle_style_button.dart rename to lib/src/toolbar/buttons/toggle_style_button.dart index aad3b3fb..896c5678 100644 --- a/lib/src/widgets/toolbar/buttons/toggle_style_button.dart +++ b/lib/src/toolbar/buttons/toggle_style_button.dart @@ -1,13 +1,13 @@ import 'package:flutter/material.dart'; -import '../../../extensions/quill_configurations_ext.dart'; -import '../../../l10n/extensions/localizations.dart'; -import '../../../models/documents/attribute.dart'; -import '../../../models/documents/style.dart'; -import '../../../models/themes/quill_icon_theme.dart'; -import '../../../utils/widgets.dart'; +import '../../common/utils/widgets.dart'; +import '../../document/attribute.dart'; +import '../../document/style.dart'; +import '../../l10n/extensions/localizations_ext.dart'; import '../base_button/base_value_button.dart'; import '../base_toolbar.dart'; +import '../simple_toolbar_provider.dart'; +import '../theme/quill_icon_theme.dart'; typedef ToggleStyleButtonBuilder = Widget Function( BuildContext context, diff --git a/lib/src/models/config/toolbar/base_button_configurations.dart b/lib/src/toolbar/config/base_button_configurations.dart similarity index 94% rename from lib/src/models/config/toolbar/base_button_configurations.dart rename to lib/src/toolbar/config/base_button_configurations.dart index 36057a4c..1c2acf54 100644 --- a/lib/src/models/config/toolbar/base_button_configurations.dart +++ b/lib/src/toolbar/config/base_button_configurations.dart @@ -2,10 +2,10 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/foundation.dart' show VoidCallback, immutable; import 'package:flutter/widgets.dart' show BuildContext, IconData, Widget; -import '../../../../flutter_quill.dart' show QuillController; -import '../../themes/quill_icon_theme.dart' show QuillIconTheme; -import '../quill_configurations.dart' +import '../../../flutter_quill.dart' show QuillController; +import '../../editor_toolbar_controller_shared/quill_configurations.dart' show kDefaultIconSize, kDefaultIconButtonFactor; +import '../theme/quill_icon_theme.dart' show QuillIconTheme; class QuillToolbarBaseButtonExtraOptionsIsToggled extends Equatable { const QuillToolbarBaseButtonExtraOptionsIsToggled(this.isToggled); diff --git a/lib/src/models/config/toolbar/buttons/clear_format_configurations.dart b/lib/src/toolbar/config/buttons/clear_format_configurations.dart similarity index 89% rename from lib/src/models/config/toolbar/buttons/clear_format_configurations.dart rename to lib/src/toolbar/config/buttons/clear_format_configurations.dart index a1abb018..85f4a6d9 100644 --- a/lib/src/models/config/toolbar/buttons/clear_format_configurations.dart +++ b/lib/src/toolbar/config/buttons/clear_format_configurations.dart @@ -1,4 +1,4 @@ -import '../../quill_configurations.dart'; +import '../../../editor_toolbar_controller_shared/quill_configurations.dart'; class QuillToolbarClearFormatButtonExtraOptions extends QuillToolbarBaseButtonExtraOptions { diff --git a/lib/src/models/config/toolbar/buttons/color_configurations.dart b/lib/src/toolbar/config/buttons/color_configurations.dart similarity index 88% rename from lib/src/models/config/toolbar/buttons/color_configurations.dart rename to lib/src/toolbar/config/buttons/color_configurations.dart index 8361a0cc..2b9f2b40 100644 --- a/lib/src/models/config/toolbar/buttons/color_configurations.dart +++ b/lib/src/toolbar/config/buttons/color_configurations.dart @@ -1,7 +1,8 @@ import 'package:flutter/widgets.dart' show Color; -import '../../../../widgets/quill/quill_controller.dart'; -import '../../quill_shared_configurations.dart' show QuillSharedConfigurations; +import '../../../controller/quill_controller.dart'; +import '../../../editor_toolbar_shared/config/quill_shared_configurations.dart' + show QuillSharedConfigurations; import '../base_button_configurations.dart'; class QuillToolbarColorButtonExtraOptions diff --git a/lib/src/models/config/toolbar/buttons/custom_button_configurations.dart b/lib/src/toolbar/config/buttons/custom_button_configurations.dart similarity index 100% rename from lib/src/models/config/toolbar/buttons/custom_button_configurations.dart rename to lib/src/toolbar/config/buttons/custom_button_configurations.dart diff --git a/lib/src/models/config/toolbar/buttons/font_family_configurations.dart b/lib/src/toolbar/config/buttons/font_family_configurations.dart similarity index 98% rename from lib/src/models/config/toolbar/buttons/font_family_configurations.dart rename to lib/src/toolbar/config/buttons/font_family_configurations.dart index 10ef5efc..2f754938 100644 --- a/lib/src/models/config/toolbar/buttons/font_family_configurations.dart +++ b/lib/src/toolbar/config/buttons/font_family_configurations.dart @@ -11,7 +11,7 @@ import 'package:flutter/widgets.dart' ValueChanged, VoidCallback; -import '../../../../../flutter_quill.dart'; +import '../../../../flutter_quill.dart'; @immutable class QuillToolbarFontFamilyButtonExtraOptions diff --git a/lib/src/models/config/toolbar/buttons/font_size_configurations.dart b/lib/src/toolbar/config/buttons/font_size_configurations.dart similarity index 96% rename from lib/src/models/config/toolbar/buttons/font_size_configurations.dart rename to lib/src/toolbar/config/buttons/font_size_configurations.dart index e351387c..c326a5e1 100644 --- a/lib/src/models/config/toolbar/buttons/font_size_configurations.dart +++ b/lib/src/toolbar/config/buttons/font_size_configurations.dart @@ -12,8 +12,8 @@ import 'package:flutter/widgets.dart' TextOverflow, TextStyle; -import '../../../documents/attribute.dart'; -import '../../quill_configurations.dart'; +import '../../../document/attribute.dart'; +import '../../../editor_toolbar_controller_shared/quill_configurations.dart'; class QuillToolbarFontSizeButtonExtraOptions extends QuillToolbarBaseButtonExtraOptions { diff --git a/lib/src/models/config/toolbar/buttons/history_configurations.dart b/lib/src/toolbar/config/buttons/history_configurations.dart similarity index 94% rename from lib/src/models/config/toolbar/buttons/history_configurations.dart rename to lib/src/toolbar/config/buttons/history_configurations.dart index 000ccc86..48bfbcb0 100644 --- a/lib/src/models/config/toolbar/buttons/history_configurations.dart +++ b/lib/src/toolbar/config/buttons/history_configurations.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart' show immutable; -import '../../../../../flutter_quill.dart'; +import '../../../../flutter_quill.dart'; @immutable class QuillToolbarHistoryButtonExtraOptions diff --git a/lib/src/models/config/toolbar/buttons/indent_configurations.dart b/lib/src/toolbar/config/buttons/indent_configurations.dart similarity index 100% rename from lib/src/models/config/toolbar/buttons/indent_configurations.dart rename to lib/src/toolbar/config/buttons/indent_configurations.dart diff --git a/lib/src/models/config/toolbar/buttons/link_style2_configurations.dart b/lib/src/toolbar/config/buttons/link_style2_configurations.dart similarity index 96% rename from lib/src/models/config/toolbar/buttons/link_style2_configurations.dart rename to lib/src/toolbar/config/buttons/link_style2_configurations.dart index 0a00bd55..849d97a0 100644 --- a/lib/src/models/config/toolbar/buttons/link_style2_configurations.dart +++ b/lib/src/toolbar/config/buttons/link_style2_configurations.dart @@ -1,6 +1,6 @@ import 'package:flutter/widgets.dart'; -import '../../../themes/quill_dialog_theme.dart'; +import '../../theme/quill_dialog_theme.dart'; import '../base_button_configurations.dart'; class QuillToolbarLinkStyleButton2ExtraOptions diff --git a/lib/src/models/config/toolbar/buttons/link_style_configurations.dart b/lib/src/toolbar/config/buttons/link_style_configurations.dart similarity index 85% rename from lib/src/models/config/toolbar/buttons/link_style_configurations.dart rename to lib/src/toolbar/config/buttons/link_style_configurations.dart index bc8b2dc2..f1adc247 100644 --- a/lib/src/models/config/toolbar/buttons/link_style_configurations.dart +++ b/lib/src/toolbar/config/buttons/link_style_configurations.dart @@ -1,8 +1,8 @@ import 'package:flutter/widgets.dart' show Color; -import '../../../../widgets/toolbar/base_toolbar.dart'; -import '../../../structs/link_dialog_action.dart'; -import '../../../themes/quill_dialog_theme.dart'; +import '../../base_toolbar.dart'; +import '../../structs/link_dialog_action.dart'; +import '../../theme/quill_dialog_theme.dart'; class QuillToolbarLinkStyleButtonExtraOptions extends QuillToolbarBaseButtonExtraOptions { diff --git a/lib/src/models/config/toolbar/buttons/search_configurations.dart b/lib/src/toolbar/config/buttons/search_configurations.dart similarity index 97% rename from lib/src/models/config/toolbar/buttons/search_configurations.dart rename to lib/src/toolbar/config/buttons/search_configurations.dart index 8d791fcc..6bdbfdf7 100644 --- a/lib/src/models/config/toolbar/buttons/search_configurations.dart +++ b/lib/src/toolbar/config/buttons/search_configurations.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import '../../../../../flutter_quill.dart'; +import '../../../../flutter_quill.dart'; class QuillToolbarSearchButtonExtraOptions extends QuillToolbarBaseButtonExtraOptions { diff --git a/lib/src/models/config/toolbar/buttons/select_alignment_configurations.dart b/lib/src/toolbar/config/buttons/select_alignment_configurations.dart similarity index 98% rename from lib/src/models/config/toolbar/buttons/select_alignment_configurations.dart rename to lib/src/toolbar/config/buttons/select_alignment_configurations.dart index e5282855..1e90a302 100644 --- a/lib/src/models/config/toolbar/buttons/select_alignment_configurations.dart +++ b/lib/src/toolbar/config/buttons/select_alignment_configurations.dart @@ -1,7 +1,7 @@ // ignore_for_file: public_member_api_docs, sort_constructors_first import 'package:flutter/widgets.dart' show IconData, immutable; -import '../../../documents/attribute.dart'; +import '../../../document/attribute.dart'; import '../base_button_configurations.dart'; class QuillToolbarSelectAlignmentButtonExtraOptions diff --git a/lib/src/models/config/toolbar/buttons/select_header_style_buttons_configurations.dart b/lib/src/toolbar/config/buttons/select_header_style_buttons_configurations.dart similarity index 91% rename from lib/src/models/config/toolbar/buttons/select_header_style_buttons_configurations.dart rename to lib/src/toolbar/config/buttons/select_header_style_buttons_configurations.dart index da3d7e1c..6177c4cf 100644 --- a/lib/src/models/config/toolbar/buttons/select_header_style_buttons_configurations.dart +++ b/lib/src/toolbar/config/buttons/select_header_style_buttons_configurations.dart @@ -1,7 +1,7 @@ import 'package:flutter/widgets.dart' show Axis; -import '../../../../widgets/toolbar/base_toolbar.dart'; -import '../../../documents/attribute.dart'; +import '../../../document/attribute.dart'; +import '../../base_toolbar.dart'; class QuillToolbarSelectHeaderStyleButtonsExtraOptions extends QuillToolbarBaseButtonExtraOptions { diff --git a/lib/src/models/config/toolbar/buttons/select_header_style_dropdown_button_configurations.dart b/lib/src/toolbar/config/buttons/select_header_style_dropdown_button_configurations.dart similarity index 93% rename from lib/src/models/config/toolbar/buttons/select_header_style_dropdown_button_configurations.dart rename to lib/src/toolbar/config/buttons/select_header_style_dropdown_button_configurations.dart index 22df0a33..37fc1522 100644 --- a/lib/src/models/config/toolbar/buttons/select_header_style_dropdown_button_configurations.dart +++ b/lib/src/toolbar/config/buttons/select_header_style_dropdown_button_configurations.dart @@ -1,9 +1,9 @@ import 'package:flutter/widgets.dart' show IconData, TextStyle, ValueChanged, VoidCallback; -import '../../../../widgets/toolbar/base_toolbar.dart'; -import '../../../documents/attribute.dart'; -import '../../../themes/quill_icon_theme.dart'; +import '../../../document/attribute.dart'; +import '../../base_toolbar.dart'; +import '../../theme/quill_icon_theme.dart'; class QuillToolbarSelectHeaderStyleDropdownButtonExtraOptions extends QuillToolbarBaseButtonExtraOptions { diff --git a/lib/src/models/config/toolbar/buttons/select_line_height_style_dropdown_button_configurations.dart b/lib/src/toolbar/config/buttons/select_line_height_style_dropdown_button_configurations.dart similarity index 93% rename from lib/src/models/config/toolbar/buttons/select_line_height_style_dropdown_button_configurations.dart rename to lib/src/toolbar/config/buttons/select_line_height_style_dropdown_button_configurations.dart index 169e9659..a190dd55 100644 --- a/lib/src/models/config/toolbar/buttons/select_line_height_style_dropdown_button_configurations.dart +++ b/lib/src/toolbar/config/buttons/select_line_height_style_dropdown_button_configurations.dart @@ -1,9 +1,9 @@ import 'package:flutter/widgets.dart' show IconData, TextStyle, ValueChanged, VoidCallback; -import '../../../../widgets/toolbar/base_toolbar.dart'; -import '../../../documents/attribute.dart'; -import '../../../themes/quill_icon_theme.dart'; +import '../../../document/attribute.dart'; +import '../../base_toolbar.dart'; +import '../../theme/quill_icon_theme.dart'; class QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions extends QuillToolbarBaseButtonExtraOptions { diff --git a/lib/src/models/config/toolbar/buttons/toggle_check_list_configurations.dart b/lib/src/toolbar/config/buttons/toggle_check_list_configurations.dart similarity index 90% rename from lib/src/models/config/toolbar/buttons/toggle_check_list_configurations.dart rename to lib/src/toolbar/config/buttons/toggle_check_list_configurations.dart index c73275c6..13539f45 100644 --- a/lib/src/models/config/toolbar/buttons/toggle_check_list_configurations.dart +++ b/lib/src/toolbar/config/buttons/toggle_check_list_configurations.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart' show immutable; -import '../../../documents/attribute.dart'; -import '../../quill_configurations.dart'; +import '../../../document/attribute.dart'; +import '../../../editor_toolbar_controller_shared/quill_configurations.dart'; class QuillToolbarToggleCheckListButtonExtraOptions extends QuillToolbarBaseButtonExtraOptions { diff --git a/lib/src/models/config/toolbar/buttons/toggle_style_configurations.dart b/lib/src/toolbar/config/buttons/toggle_style_configurations.dart similarity index 100% rename from lib/src/models/config/toolbar/buttons/toggle_style_configurations.dart rename to lib/src/toolbar/config/buttons/toggle_style_configurations.dart diff --git a/lib/src/models/config/toolbar/simple_toolbar_button_options.dart b/lib/src/toolbar/config/simple_toolbar_button_options.dart similarity index 99% rename from lib/src/models/config/toolbar/simple_toolbar_button_options.dart rename to lib/src/toolbar/config/simple_toolbar_button_options.dart index 0777701f..7da8da34 100644 --- a/lib/src/models/config/toolbar/simple_toolbar_button_options.dart +++ b/lib/src/toolbar/config/simple_toolbar_button_options.dart @@ -20,7 +20,7 @@ import 'buttons/select_line_height_style_dropdown_button_configurations.dart'; import 'buttons/toggle_check_list_configurations.dart'; import 'buttons/toggle_style_configurations.dart'; -export './../../../widgets/toolbar/buttons/search/search_dialog.dart'; +export '../buttons/search/search_dialog.dart'; export 'base_button_configurations.dart'; export 'buttons/clear_format_configurations.dart'; export 'buttons/color_configurations.dart'; diff --git a/lib/src/models/config/toolbar/simple_toolbar_configurations.dart b/lib/src/toolbar/config/simple_toolbar_configurations.dart similarity index 91% rename from lib/src/models/config/toolbar/simple_toolbar_configurations.dart rename to lib/src/toolbar/config/simple_toolbar_configurations.dart index 9701bd90..71e44119 100644 --- a/lib/src/models/config/toolbar/simple_toolbar_configurations.dart +++ b/lib/src/toolbar/config/simple_toolbar_configurations.dart @@ -2,20 +2,20 @@ import 'package:flutter/foundation.dart' show immutable; import 'package:flutter/widgets.dart' show Axis, WrapAlignment, WrapCrossAlignment; -import '../../../widgets/quill/embeds.dart'; -import '../../../widgets/quill/quill_controller.dart'; -import '../../../widgets/toolbar/buttons/hearder_style/select_header_style_buttons.dart'; -import '../../../widgets/toolbar/buttons/hearder_style/select_header_style_dropdown_button.dart'; -import '../../../widgets/toolbar/buttons/link_style2_button.dart'; -import '../../../widgets/toolbar/buttons/link_style_button.dart'; -import '../../../widgets/toolbar/buttons/search/legacy/legacy_search_button.dart'; -import '../../../widgets/toolbar/buttons/search/search_button.dart'; -import '../../themes/quill_dialog_theme.dart'; -import '../../themes/quill_icon_theme.dart'; +import '../../controller/quill_controller.dart'; +import '../buttons/hearder_style/select_header_style_buttons.dart'; +import '../buttons/hearder_style/select_header_style_dropdown_button.dart'; +import '../buttons/link_style2_button.dart'; +import '../buttons/link_style_button.dart'; +import '../buttons/search/legacy/legacy_search_button.dart'; +import '../buttons/search/search_button.dart'; +import '../embed/embed_button_builder.dart'; +import '../theme/quill_dialog_theme.dart'; +import '../theme/quill_icon_theme.dart'; import 'simple_toolbar_button_options.dart'; import 'toolbar_shared_configurations.dart'; -export './../../../widgets/toolbar/buttons/search/search_dialog.dart'; +export '../buttons/search/search_dialog.dart'; export 'base_button_configurations.dart'; export 'buttons/clear_format_configurations.dart'; export 'buttons/color_configurations.dart'; diff --git a/lib/src/models/config/toolbar/toolbar_configurations.dart b/lib/src/toolbar/config/toolbar_configurations.dart similarity index 100% rename from lib/src/models/config/toolbar/toolbar_configurations.dart rename to lib/src/toolbar/config/toolbar_configurations.dart diff --git a/lib/src/models/config/toolbar/toolbar_shared_configurations.dart b/lib/src/toolbar/config/toolbar_shared_configurations.dart similarity index 92% rename from lib/src/models/config/toolbar/toolbar_shared_configurations.dart rename to lib/src/toolbar/config/toolbar_shared_configurations.dart index 041592a8..8f1d57f6 100644 --- a/lib/src/models/config/toolbar/toolbar_shared_configurations.dart +++ b/lib/src/toolbar/config/toolbar_shared_configurations.dart @@ -2,9 +2,9 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/widgets.dart' show Axis, Color, Decoration, WrapAlignment, WrapCrossAlignment; -import '../../../widgets/toolbar/base_toolbar.dart'; -import '../../structs/link_dialog_action.dart'; -import '../quill_shared_configurations.dart'; +import '../../editor_toolbar_shared/config/quill_shared_configurations.dart'; +import '../base_toolbar.dart'; +import '../structs/link_dialog_action.dart'; abstract class QuillSharedToolbarProperties extends Equatable { const QuillSharedToolbarProperties({ diff --git a/lib/src/toolbar/embed/embed_button_builder.dart b/lib/src/toolbar/embed/embed_button_builder.dart new file mode 100644 index 00000000..c46c2f86 --- /dev/null +++ b/lib/src/toolbar/embed/embed_button_builder.dart @@ -0,0 +1,12 @@ +import 'package:flutter/widgets.dart' show Widget; + +import '../../controller/quill_controller.dart'; +import '../theme/quill_dialog_theme.dart'; +import '../theme/quill_icon_theme.dart'; + +typedef EmbedButtonBuilder = Widget Function( + QuillController controller, + double toolbarIconSize, + QuillIconTheme? iconTheme, + QuillDialogTheme? dialogTheme, +); diff --git a/lib/src/toolbar/provider.dart b/lib/src/toolbar/provider.dart new file mode 100644 index 00000000..146fe174 --- /dev/null +++ b/lib/src/toolbar/provider.dart @@ -0,0 +1,74 @@ +import 'package:flutter/foundation.dart' show debugPrint, kDebugMode; +import 'package:flutter/widgets.dart' + show BuildContext, InheritedWidget, Widget; + +import 'config/toolbar_configurations.dart'; + +class QuillToolbarProvider extends InheritedWidget { + const QuillToolbarProvider({ + required super.child, + required this.toolbarConfigurations, + super.key, + }); + + /// The configurations for the toolbar widget of flutter quill + final QuillToolbarConfigurations toolbarConfigurations; + + @override + bool updateShouldNotify(covariant QuillToolbarProvider oldWidget) { + return oldWidget.toolbarConfigurations != toolbarConfigurations; + } + + static QuillToolbarProvider? maybeOf(BuildContext context) { + /// The configurations for the quill editor widget of flutter quill + return context.dependOnInheritedWidgetOfExactType(); + } + + static QuillToolbarProvider of(BuildContext context) { + final provider = maybeOf(context); + if (provider == null) { + if (kDebugMode) { + debugPrint( + 'The quill toolbar provider must be provided in the widget tree.', + ); + } + throw ArgumentError.checkNotNull( + 'You are using a widget in the Flutter quill library that require ' + 'The Quill toolbar provider widget to be in the parent widget tree ' + 'because ' + 'The provider is $provider. Please make sure to wrap this widget' + ' with' + ' QuillBaseToolbarProvider widget. ' + 'You might using QuillBaseToolbar so make sure to' + ' wrap them with the quill provider widget and setup the required ' + 'configurations', + 'QuillToolbarProvider', + ); + } + return provider; + } + + /// To pass the [QuillToolbarConfigurations] instance as value + /// instead of creating new widget + static QuillToolbarProvider value({ + required QuillToolbarConfigurations value, + required Widget child, + }) { + return QuillToolbarProvider( + toolbarConfigurations: value, + child: child, + ); + } +} + +extension QuillToolbarExt on BuildContext { + /// return [QuillToolbarConfigurations] as not null + QuillToolbarConfigurations get requireQuillToolbarConfigurations { + return QuillToolbarProvider.of(this).toolbarConfigurations; + } + + /// return nullable [QuillToolbarConfigurations]. + QuillToolbarConfigurations? get quillToolbarConfigurations { + return QuillToolbarProvider.maybeOf(this)?.toolbarConfigurations; + } +} diff --git a/lib/src/widgets/toolbar/simple_toolbar.dart b/lib/src/toolbar/simple_toolbar.dart similarity index 98% rename from lib/src/widgets/toolbar/simple_toolbar.dart rename to lib/src/toolbar/simple_toolbar.dart index a95b17de..a210c824 100644 --- a/lib/src/widgets/toolbar/simple_toolbar.dart +++ b/lib/src/toolbar/simple_toolbar.dart @@ -1,12 +1,11 @@ import 'package:flutter/material.dart'; -import '../../extensions/quill_configurations_ext.dart'; -import '../../models/config/toolbar/toolbar_configurations.dart'; -import '../../models/documents/attribute.dart'; -import '../utils/provider.dart'; +import '../document/attribute.dart'; import 'base_toolbar.dart'; import 'buttons/alignment/select_alignment_buttons.dart'; import 'buttons/arrow_indicated_list_button.dart'; +import 'config/toolbar_configurations.dart'; +import 'simple_toolbar_provider.dart'; class QuillSimpleToolbar extends StatelessWidget implements PreferredSizeWidget { diff --git a/lib/src/toolbar/simple_toolbar_provider.dart b/lib/src/toolbar/simple_toolbar_provider.dart new file mode 100644 index 00000000..ad845e8b --- /dev/null +++ b/lib/src/toolbar/simple_toolbar_provider.dart @@ -0,0 +1,77 @@ +import 'package:flutter/foundation.dart' show debugPrint, kDebugMode; +import 'package:flutter/widgets.dart' + show BuildContext, InheritedWidget, Widget; + +import 'config/simple_toolbar_configurations.dart'; + +class QuillSimpleToolbarProvider extends InheritedWidget { + const QuillSimpleToolbarProvider({ + required super.child, + required this.toolbarConfigurations, + super.key, + }); + + /// The configurations for the toolbar widget of flutter quill + final QuillSimpleToolbarConfigurations toolbarConfigurations; + + @override + bool updateShouldNotify(covariant QuillSimpleToolbarProvider oldWidget) { + return oldWidget.toolbarConfigurations != toolbarConfigurations; + } + + static QuillSimpleToolbarProvider? maybeOf(BuildContext context) { + /// The configurations for the quill editor widget of flutter quill + return context + .dependOnInheritedWidgetOfExactType(); + } + + static QuillSimpleToolbarProvider of(BuildContext context) { + final provider = maybeOf(context); + if (provider == null) { + if (kDebugMode) { + debugPrint( + 'The quill toolbar provider must be provided in the widget tree.', + ); + } + throw ArgumentError.checkNotNull( + 'You are using a widget in the Flutter quill library that require ' + 'The Quill toolbar provider widget to be in the parent widget tree ' + 'because ' + 'The provider is $provider. Please make sure to wrap this widget' + ' with' + ' QuillToolbarProvider widget. ' + 'You might using QuillToolbar so make sure to' + ' wrap them with the quill provider widget and setup the required ' + 'configurations', + 'QuillSimpleToolbarProvider', + ); + } + return provider; + } + + /// To pass the [QuillSimpleToolbarProvider] instance as value instead of creating + /// new widget + static QuillSimpleToolbarProvider value({ + required QuillSimpleToolbarProvider value, + required Widget child, + }) { + return QuillSimpleToolbarProvider( + toolbarConfigurations: value.toolbarConfigurations, + child: child, + ); + } +} + +extension QuillSimpleToolbarExt on BuildContext { + QuillSimpleToolbarConfigurations get requireQuillSimpleToolbarConfigurations { + return QuillSimpleToolbarProvider.of(this).toolbarConfigurations; + } + + QuillSimpleToolbarConfigurations? get quillSimpleToolbarConfigurations { + return QuillSimpleToolbarProvider.maybeOf(this)?.toolbarConfigurations; + } + + QuillToolbarBaseButtonOptions? get quillToolbarBaseButtonOptions { + return quillSimpleToolbarConfigurations?.buttonOptions.base; + } +} diff --git a/lib/src/models/structs/link_dialog_action.dart b/lib/src/toolbar/structs/link_dialog_action.dart similarity index 100% rename from lib/src/models/structs/link_dialog_action.dart rename to lib/src/toolbar/structs/link_dialog_action.dart diff --git a/lib/src/models/themes/quill_dialog_theme.dart b/lib/src/toolbar/theme/quill_dialog_theme.dart similarity index 100% rename from lib/src/models/themes/quill_dialog_theme.dart rename to lib/src/toolbar/theme/quill_dialog_theme.dart diff --git a/lib/src/models/themes/quill_icon_theme.dart b/lib/src/toolbar/theme/quill_icon_theme.dart similarity index 97% rename from lib/src/models/themes/quill_icon_theme.dart rename to lib/src/toolbar/theme/quill_icon_theme.dart index 9dedee8b..99923542 100644 --- a/lib/src/models/themes/quill_icon_theme.dart +++ b/lib/src/toolbar/theme/quill_icon_theme.dart @@ -1,4 +1,3 @@ -// ignore_for_file: public_member_api_docs, sort_constructors_first import 'package:flutter/material.dart'; @immutable diff --git a/lib/src/widgets/utils/provider.dart b/lib/src/widgets/utils/provider.dart deleted file mode 100644 index c0d40e73..00000000 --- a/lib/src/widgets/utils/provider.dart +++ /dev/null @@ -1,179 +0,0 @@ -import 'package:flutter/foundation.dart' show debugPrint, kDebugMode; -import 'package:flutter/widgets.dart' - show BuildContext, InheritedWidget, Widget; - -import '../../models/config/quill_configurations.dart'; -import '../../models/config/toolbar/toolbar_configurations.dart'; - -class QuillSimpleToolbarProvider extends InheritedWidget { - const QuillSimpleToolbarProvider({ - required super.child, - required this.toolbarConfigurations, - super.key, - }); - - /// The configurations for the toolbar widget of flutter quill - final QuillSimpleToolbarConfigurations toolbarConfigurations; - - @override - bool updateShouldNotify(covariant QuillSimpleToolbarProvider oldWidget) { - return oldWidget.toolbarConfigurations != toolbarConfigurations; - } - - static QuillSimpleToolbarProvider? maybeOf(BuildContext context) { - /// The configurations for the quill editor widget of flutter quill - return context - .dependOnInheritedWidgetOfExactType(); - } - - static QuillSimpleToolbarProvider of(BuildContext context) { - final provider = maybeOf(context); - if (provider == null) { - if (kDebugMode) { - debugPrint( - 'The quill toolbar provider must be provided in the widget tree.', - ); - } - throw ArgumentError.checkNotNull( - 'You are using a widget in the Flutter quill library that require ' - 'The Quill toolbar provider widget to be in the parent widget tree ' - 'because ' - 'The provider is $provider. Please make sure to wrap this widget' - ' with' - ' QuillToolbarProvider widget. ' - 'You might using QuillToolbar so make sure to' - ' wrap them with the quill provider widget and setup the required ' - 'configurations', - 'QuillSimpleToolbarProvider', - ); - } - return provider; - } - - /// To pass the [QuillSimpleToolbarProvider] instance as value instead of creating - /// new widget - static QuillSimpleToolbarProvider value({ - required QuillSimpleToolbarProvider value, - required Widget child, - }) { - return QuillSimpleToolbarProvider( - toolbarConfigurations: value.toolbarConfigurations, - child: child, - ); - } -} - -// Not really needed -class QuillToolbarProvider extends InheritedWidget { - const QuillToolbarProvider({ - required super.child, - required this.toolbarConfigurations, - super.key, - }); - - /// The configurations for the toolbar widget of flutter quill - final QuillToolbarConfigurations toolbarConfigurations; - - @override - bool updateShouldNotify(covariant QuillToolbarProvider oldWidget) { - return oldWidget.toolbarConfigurations != toolbarConfigurations; - } - - static QuillToolbarProvider? maybeOf(BuildContext context) { - /// The configurations for the quill editor widget of flutter quill - return context.dependOnInheritedWidgetOfExactType(); - } - - static QuillToolbarProvider of(BuildContext context) { - final provider = maybeOf(context); - if (provider == null) { - if (kDebugMode) { - debugPrint( - 'The quill toolbar provider must be provided in the widget tree.', - ); - } - throw ArgumentError.checkNotNull( - 'You are using a widget in the Flutter quill library that require ' - 'The Quill toolbar provider widget to be in the parent widget tree ' - 'because ' - 'The provider is $provider. Please make sure to wrap this widget' - ' with' - ' QuillBaseToolbarProvider widget. ' - 'You might using QuillBaseToolbar so make sure to' - ' wrap them with the quill provider widget and setup the required ' - 'configurations', - 'QuillToolbarProvider', - ); - } - return provider; - } - - /// To pass the [QuillToolbarConfigurations] instance as value - /// instead of creating new widget - static QuillToolbarProvider value({ - required QuillToolbarConfigurations value, - required Widget child, - }) { - return QuillToolbarProvider( - toolbarConfigurations: value, - child: child, - ); - } -} - -class QuillEditorProvider extends InheritedWidget { - const QuillEditorProvider({ - required super.child, - required this.editorConfigurations, - super.key, - }); - - /// The configurations for the quill editor widget of flutter quill - final QuillEditorConfigurations editorConfigurations; - - @override - bool updateShouldNotify(covariant QuillEditorProvider oldWidget) { - return oldWidget.editorConfigurations != editorConfigurations; - } - - static QuillEditorProvider? maybeOf(BuildContext context) { - /// The configurations for the quill editor widget of flutter quill - return context.dependOnInheritedWidgetOfExactType(); - } - - static QuillEditorProvider of(BuildContext context) { - final provider = maybeOf(context); - if (provider == null) { - if (kDebugMode) { - debugPrint( - 'The quill editor provider must be provided in the widget tree.', - ); - } - throw ArgumentError.checkNotNull( - 'You are using a widget in the Flutter quill library that require ' - 'The Quill editor provider widget to be in the parent widget tree ' - 'because ' - 'The provider is $provider. Please make sure to wrap this widget' - ' with' - ' QuillEditorProvider widget. ' - 'You might using QuillEditor so make sure to' - ' wrap them with the quill provider widget and setup the required ' - 'configurations', - 'QuillEditorProvider', - ); - } - return provider; - } - - /// To pass the [QuillEditorProvider] instance as value instead of creating - /// new widget - static QuillEditorProvider value({ - required QuillEditorProvider value, - required Widget child, - }) { - return QuillEditorProvider( - editorConfigurations: value.editorConfigurations, - child: child, - ); - } -} diff --git a/lib/translations.dart b/lib/translations.dart index 002a538f..2906e16c 100644 --- a/lib/translations.dart +++ b/lib/translations.dart @@ -1,4 +1,4 @@ library flutter_quill.translations; -export 'src/l10n/extensions/localizations.dart'; +export 'src/l10n/extensions/localizations_ext.dart'; export 'src/l10n/widgets/localizations.dart'; diff --git a/test/bug_fix_test.dart b/test/bug_fix_test.dart index 0be8a1e0..5834b714 100644 --- a/test/bug_fix_test.dart +++ b/test/bug_fix_test.dart @@ -39,8 +39,6 @@ void main() { matchRoot: true, ); expect(builtinFinder, findsOneWidget); - // final builtinButton = - // builtinFinder.evaluate().first.widget as QuillToolbarIconButton; final customFinder = find.descendant( of: find.byType(QuillToolbar), @@ -48,10 +46,6 @@ void main() { widget is QuillToolbarIconButton && widget.tooltip == tooltip), matchRoot: true); expect(customFinder, findsOneWidget); - // final customButton = - // customFinder.evaluate().first.widget as QuillToolbarIconButton; - - // expect(customButton.fillColor, equals(builtinButton.fillColor)); }); }); @@ -62,10 +56,8 @@ void main() { setUp(() { controller = QuillController.basic(); editor = QuillEditor.basic( - // ignore: avoid_redundant_argument_values configurations: QuillEditorConfigurations( controller: controller, - // ignore: avoid_redundant_argument_values ), ); }); @@ -150,10 +142,8 @@ void main() { home: QuillEditor( focusNode: FocusNode(), scrollController: ScrollController(), - // ignore: avoid_redundant_argument_values configurations: QuillEditorConfigurations( controller: controller, - // ignore: avoid_redundant_argument_values autoFocus: true, expands: true, ), diff --git a/test/utils/platform_test.dart b/test/common/utils/platform_test.dart similarity index 98% rename from test/utils/platform_test.dart rename to test/common/utils/platform_test.dart index db4ee75a..49651404 100644 --- a/test/utils/platform_test.dart +++ b/test/common/utils/platform_test.dart @@ -1,5 +1,5 @@ import 'package:flutter/foundation.dart' show TargetPlatform; -import 'package:flutter_quill/src/utils/platform.dart'; +import 'package:flutter_quill/src/common/utils/platform.dart'; import 'package:test/test.dart'; void main() { diff --git a/test/widgets/controller_test.dart b/test/controller/controller_test.dart similarity index 100% rename from test/widgets/controller_test.dart rename to test/controller/controller_test.dart diff --git a/test/utils/attributes_test.dart b/test/document/attributes_test.dart similarity index 100% rename from test/utils/attributes_test.dart rename to test/document/attributes_test.dart diff --git a/test/utils/document_test.dart b/test/document/document_test.dart similarity index 100% rename from test/utils/document_test.dart rename to test/document/document_test.dart diff --git a/test/widgets/editor_test.dart b/test/editor/editor_test.dart similarity index 100% rename from test/widgets/editor_test.dart rename to test/editor/editor_test.dart