Skip to content

Commit

Permalink
4++
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Dec 6, 2023
1 parent c5c8083 commit 21a192f
Show file tree
Hide file tree
Showing 23 changed files with 576 additions and 491 deletions.
431 changes: 4 additions & 427 deletions doc/migration.md

Large diffs are not rendered by default.

429 changes: 429 additions & 0 deletions doc/migration/7_8.md

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions doc/migration/8_9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
1. Removing the `QuillProvider`

We got a lot of feedbacks about `QuillProvider`, while the provider help removing duplicate lines for simple usage, for more advance usage it become very messy
So from now on we will use providers for the `QuillToolbar` and `QuillEditor` only internally, you don't need it anymore

Instead you will need to pass the configurations directly in the `QuillToolbar` and `QuillEditor`

**Old code**:

```dart
QuillProvider(
configurations: QuillConfigurations(
controller: _controller,
sharedConfigurations: const QuillSharedConfigurations(),
),
child: Column(
children: [
const QuillToolbar(),
Expanded(
child: QuillEditor.basic(
configurations: const QuillEditorConfigurations(
readOnly: false, // true for view only mode
),
),
)
],
),
)
```

**New code**:

```dart
Column(
children: [
QuillToolbar.simple(
QuillSimpleToolbarConfigurations(controller: _controller)),
Expanded(
child: QuillEditor.basic(
configurations: QuillEditorConfigurations(controller: _controller),
),
)
],
)
```

2. Refactoring the Base Toolbar

From now on, the `QuillToolbar` will be a widget that only provides the things that the buttons needs like localizations and `QuillToolbarProvider`
So you can define your own toolbar from scratch just like in Quill JS

The `QuillToolbar` is now accepting only `child` with no configurations so you can customize everything you wants, the `QuillToolbar.simple()` or `QuillSimpleToolbar` implements a simple toolbar that is based on `QuillToolbar`, you are free to use it but it just an example and not standard

1. Source Code Structure

Completly changed the way how the source code structured to more basic and simple way, organize folders and file names, if you use the library
from `flutter_quill_extensions.dart` then there is nothing you need to do, but if you are using any other import then you need to re-imports

4. Change the version system

For [more details](https://github.com/singerdmx/flutter-quill/discussions/1560)

5. Dependencies changes

1. Add `gal_linux` in `flutter_quill_extensions`
2. Replace `pasteboard` with `rich_cliboard`
3. Remove `flutter_animate`

6. Optional options for the buttons

All the buttons from now on, have optional options parameter

7. Improve Flutter Quill Extensions

Bug fixes and new features, the extensions package keep getting better thanks to the community.

8. Migrate to Material 3

We have migrated all of the buttons to material 3, removed a lot of old parameters, if you want to customize one or all the buttons to replacing it with completly different widget with the same state use the `base` in the button options for all or the button name for one

We have also replaced the header style buttons with one dropdown button as a default, replaced the alignment buttons with less code and a lot more
11 changes: 11 additions & 0 deletions example/lib/presentation/simple/simple_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ class _SimpleScreenState extends State<SimpleScreen> {

@override
Widget build(BuildContext context) {
return Column(
children: [
QuillToolbar.simple(
QuillSimpleToolbarConfigurations(controller: _controller)),
Expanded(
child: QuillEditor.basic(
configurations: QuillEditorConfigurations(controller: _controller),
),
)
],
);
return Scaffold(
appBar: AppBar(),
body: Column(
Expand Down
1 change: 0 additions & 1 deletion flutter_quill_extensions/lib/embeds/widgets/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ ImageProvider getImageProviderByImageSource(
}

if (imageSource.startsWith(assetsPrefix)) {
// TODO: This impl could be improved
return AssetImage(imageSource);
}
return FileImage(File(imageSource));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ enum ExtraElementProperties {

final cssAttrs = parseCssString(cssStyle.value.toString());

// todo: This could be improved much better
final cssHeightValue = parseCssPropertyAsDouble(
(cssAttrs[Attribute.height.key]) ?? '',
context: context,
Expand Down
2 changes: 1 addition & 1 deletion lib/flutter_quill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ library flutter_quill;

export 'src/extensions/quill_configurations_ext.dart';
export 'src/models/config/quill_configurations.dart';
export 'src/models/config/raw_editor/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';
Expand Down
8 changes: 4 additions & 4 deletions lib/src/extensions/quill_configurations_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ extension QuillEditorExt on BuildContext {
extension QuillSimpleToolbarExt on BuildContext {
/// return [QuillSimpleToolbarConfigurations] as not null
QuillSimpleToolbarConfigurations get requireQuillSimpleToolbarConfigurations {
return QuillToolbarProvider.ofNotNull(this).toolbarConfigurations;
return QuillSimpleToolbarProvider.ofNotNull(this).toolbarConfigurations;
}

/// return nullable [QuillSimpleToolbarConfigurations]
QuillSimpleToolbarConfigurations? get quillSimpleToolbarConfigurations {
return QuillToolbarProvider.of(this)?.toolbarConfigurations;
return QuillSimpleToolbarProvider.of(this)?.toolbarConfigurations;
}

/// return nullable [QuillToolbarBaseButtonOptions].
Expand All @@ -83,11 +83,11 @@ extension QuillSimpleToolbarExt on BuildContext {
extension QuillToolbarExt on BuildContext {
/// return [QuillToolbarConfigurations] as not null
QuillToolbarConfigurations get requireQuillToolbarConfigurations {
return QuillBaseToolbarProvider.ofNotNull(this).toolbarConfigurations;
return QuillToolbarProvider.ofNotNull(this).toolbarConfigurations;
}

/// return nullable [QuillToolbarConfigurations].
QuillToolbarConfigurations? get quillToolbarConfigurations {
return QuillBaseToolbarProvider.of(this)?.toolbarConfigurations;
return QuillToolbarProvider.of(this)?.toolbarConfigurations;
}
}
11 changes: 11 additions & 0 deletions lib/src/extensions/uri_ext.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extension UriExt on Uri {
bool isHttpBasedUrl() {
final uri = this;
return uri.isScheme('HTTP') || uri.isScheme('HTTPS');
}

bool isHttpsBasedUrl() {
final uri = this;
return uri.isScheme('HTTPS');
}
}
2 changes: 1 addition & 1 deletion lib/src/models/config/quill_configurations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/foundation.dart' show immutable;

import '../../../flutter_quill.dart';

export './editor/configurations.dart';
export 'editor/editor_configurations.dart';
export 'quill_shared_configurations.dart';
export 'toolbar/simple_toolbar_configurations.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/config/quill_shared_configurations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart' show Color, Colors, Locale;

import '../themes/quill_dialog_theme.dart';
import './editor/configurations.dart' show QuillEditorConfigurations;
import 'editor/editor_configurations.dart' show QuillEditorConfigurations;
import 'toolbar/simple_toolbar_configurations.dart'
show QuillSimpleToolbarConfigurations;

Expand Down
4 changes: 2 additions & 2 deletions lib/src/models/rules/insert.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:meta/meta.dart' show immutable;

import '../../extensions/uri_ext.dart';
import '../../models/documents/document.dart';
import '../documents/attribute.dart';
import '../documents/nodes/embeddable.dart';
Expand Down Expand Up @@ -520,8 +521,7 @@ class AutoFormatLinksRule extends InsertRule {
try {
final cand = (prev.data as String).split('\n').last.split(' ').last;
final link = Uri.parse(cand);
// TODO: Can be improved a little
if (!['https', 'http'].contains(link.scheme)) {
if (!link.isHttpBasedUrl()) {
return null;
}
final attributes = prev.attributes ?? <String, dynamic>{};
Expand Down
26 changes: 2 additions & 24 deletions lib/src/widgets/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';

import '../../l10n/widgets/localizations.dart';
import '../../models/config/editor/configurations.dart';
import '../../models/config/raw_editor/configurations.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';
Expand Down Expand Up @@ -1209,28 +1209,6 @@ class RenderEditor extends RenderEditableContainerBox
@override
Rect getLocalRectForCaret(TextPosition position) {
final targetChild = childAtPosition(position);
// TODO: There is a bug here
// The provided text position is not in the current node
// 'package:flutter_quill/src/widgets/text_block.dart':
// text_block.dart:1
// Failed assertion: line 604 pos 12:
// 'container.containsOffset(position.offset)'
// When the exception was thrown, this was the stack
// #2 RenderEditableTextBlock.globalToLocalPosition
// text_block.dart:604
// #3 RenderEditor.getLocalRectForCaret
// editor.dart:1230
// #4 RawEditorStateTextInputClientMixin._updateComposingRectIfNeeded
// raw_editor_state_text_input_client_mixin.dart:85
// #5 RawEditorStateTextInputClientMixin.openConnectionIfNeeded
// raw_editor_state_text_input_client_mixin.dart:70
// #6 RawEditorState.requestKeyboard
// raw_editor.dart:1428
// #7 QuillEditorState._requestKeyboard
// editor.dart:379
// #8 _QuillEditorSelectionGestureDetectorBuilder.onSingleTapUp
// editor.dart:538
// #9 _EditorTextSelectionGestureDetectorState._handleTapUp
final localPosition = targetChild.globalToLocalPosition(position);

final childLocalRect = targetChild.getLocalRectForCaret(localPosition);
Expand Down
2 changes: 0 additions & 2 deletions lib/src/widgets/others/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ class EditorTextSelectionGestureDetectorBuilder {
@protected
void onDragSelectionEnd(DragEndDetails details) {
renderEditor!.handleDragEnd(details);
// TODO: Should we care if the platform is desktop using native desktop app
// or the flutter app is running using web app??
if (isDesktop(supportWeb: true) &&
delegate.selectionEnabled &&
shouldShowSelectionToolbar) {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/widgets/others/proxy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ class RichTextProxy extends SingleChildRenderObjectWidget {
required this.textDirection,
required this.locale,
required this.strutStyle,
// TODO: This might needs to be updated, previous value was 1.0 using `textScaleFactor`
this.textScaler = const TextScaler.linear(1),
required this.textScaler,
this.textWidthBasis = TextWidthBasis.parent,
this.textHeightBehavior,
super.key,
Expand Down
3 changes: 2 additions & 1 deletion lib/src/widgets/others/text_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ class _TextLineState extends State<TextLine> {
textScaler: MediaQuery.textScalerOf(context),
);
return RichTextProxy(
textStyle: textSpan.style!,
textStyle: textSpan.style ?? const TextStyle(),
textAlign: textAlign,
textDirection: widget.textDirection!,
strutStyle: strutStyle,
locale: Localizations.localeOf(context),
textScaler: MediaQuery.textScalerOf(context),
child: child,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/raw_editor/raw_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:flutter/widgets.dart'
Widget;
import 'package:meta/meta.dart' show immutable;

import '../../models/config/raw_editor/configurations.dart';
import '../../models/config/raw_editor/raw_editor_configurations.dart';
import '../../models/structs/offset_value.dart';
import '../editor/editor.dart';
import '../others/text_selection.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/src/widgets/toolbar/base_toolbar.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

import '../../../flutter_quill.dart'
show QuillBaseToolbarProvider, defaultToolbarSize;
show QuillToolbarProvider, defaultToolbarSize;
import '../../l10n/widgets/localizations.dart';
import '../../models/config/toolbar/simple_toolbar_configurations.dart';
import '../../models/config/toolbar/toolbar_configurations.dart';
Expand Down Expand Up @@ -55,7 +55,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
@override
Widget build(BuildContext context) {
return FlutterQuillLocalizationsWidget(
child: QuillBaseToolbarProvider(
child: QuillToolbarProvider(
toolbarConfigurations: configurations,
child: configurations.child,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/toolbar/buttons/link_style_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class QuillToolbarLinkStyleButtonState
}

Future<void> _openLinkDialog(BuildContext context) async {
// TODO: Add a custom call back to customize this just like in the search
// TODO: Add a custom call back to customize this just like in the search dialog
// button
final value = await showDialog<_TextLink>(
context: context,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/toolbar/simple_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class QuillSimpleToolbar extends StatelessWidget
];
}

return QuillToolbarProvider(
return QuillSimpleToolbarProvider(
toolbarConfigurations: configurations,
child: QuillToolbar(
configurations: QuillToolbarConfigurations(
Expand Down
Loading

0 comments on commit 21a192f

Please sign in to comment.