Skip to content

Commit

Permalink
refactor: restructure project into modular architecture for flutter_q…
Browse files Browse the repository at this point in the history
…uill (#2032)

* refactor: restructure project into modular architecture for flutter_quill

* refactor: move LineHeightAttribute class to custom_attributes.dart

* chore: remove nullable controller extension
  • Loading branch information
EchoEllet authored Jul 17, 2024
1 parent af36798 commit 9764f75
Show file tree
Hide file tree
Showing 153 changed files with 747 additions and 761 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion flutter_quill_extensions/lib/flutter_quill_extensions.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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._();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/extensions.dart
Original file line number Diff line number Diff line change
@@ -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';
76 changes: 40 additions & 36 deletions lib/flutter_quill.dart
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 2 additions & 0 deletions lib/markdown_quill.dart
Original file line number Diff line number Diff line change
@@ -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';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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<Embed> getEmbedNode(QuillController controller, int offset) {
var offset = controller.selection.start;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/font.dart → lib/src/common/utils/font.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../flutter_quill.dart';
import '../../../flutter_quill.dart';

dynamic getFontSize(dynamic sizeValue) {
if (sizeValue is String &&
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions lib/src/controller/provider.dart
Original file line number Diff line number Diff line change
@@ -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'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/src/utils/delta.dart → lib/src/delta/delta_diff.dart
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -354,27 +357,6 @@ class HeaderAttribute extends Attribute<int?> {
: 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<double?> {
const LineHeightAttribute({double? lineHeight})
: super('line-height', AttributeScope.block, lineHeight);

static const Attribute<double?> lineHeightNormal =
LineHeightAttribute(lineHeight: 1);

static const Attribute<double?> lineHeightTight =
LineHeightAttribute(lineHeight: 1.15);

static const Attribute<double?> lineHeightOneAndHalf =
LineHeightAttribute(lineHeight: 1.5);

static const Attribute<double?> lineHeightDouble =
LineHeightAttribute(lineHeight: 2);
}

class IndentAttribute extends Attribute<int?> {
const IndentAttribute({int? level})
: super('indent', AttributeScope.block, level);
Expand Down
25 changes: 25 additions & 0 deletions lib/src/document/custom_attributes.dart
Original file line number Diff line number Diff line change
@@ -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<double?> {
const LineHeightAttribute({double? lineHeight})
: super('line-height', AttributeScope.block, lineHeight);

static const Attribute<double?> lineHeightNormal =
LineHeightAttribute(lineHeight: 1);

static const Attribute<double?> lineHeightTight =
LineHeightAttribute(lineHeight: 1.15);

static const Attribute<double?> lineHeightOneAndHalf =
LineHeightAttribute(lineHeight: 1.5);

static const Attribute<double?> lineHeightDouble =
LineHeightAttribute(lineHeight: 2);
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
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';
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
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9764f75

Please sign in to comment.