Skip to content

Commit

Permalink
Code cleanup and fixes (#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoEllet authored Oct 31, 2023
1 parent 3e9ab4b commit f7528d3
Show file tree
Hide file tree
Showing 41 changed files with 772 additions and 446 deletions.
10 changes: 3 additions & 7 deletions .github/ISSUE_TEMPLATE/issue-template.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
---
name: Issue template
about: Common things to fill
title: "[Web] or [Mobile] or [Desktop]"
title: "Issue in [Mobile, Desktop, Web]"
labels: ''
assignees: ''

---

My issue is about [Web]
My issue is about [Mobile]
My issue is about [Desktop]

I have tried running `example` directory successfully before creating an issue here.

Please note that we are using <b>latest</b> flutter version in stable channel on branch master. If you are using beta or master channel, or you are not using <b>latest</b> flutter version in stable channel, you may experience error.

<!-- Did you try the running `example` directory?? How does it goes -->

<!-- Please explain how to encounter the issue in details if possible -->

<!-- Don't forgot to mention the platform you are testing in -->
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [8.1.2]
- Fix bug that is related to the regexp of the insert link dialog
- Require dart 3 as minimum
- Code cleanup
- Add spacer widget between each button in the `QuillToolbar`

## [8.1.1]
- Fix null error in line.dart [#1487](https://github.com/singerdmx/flutter-quill/issues/1487)

Expand Down
6 changes: 2 additions & 4 deletions lib/src/models/config/others/animations.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart' show immutable;

import '../../../utils/experimental.dart';
import 'package:meta/meta.dart' show experimental, immutable;

@immutable
@Experimental('This class might removed')
@experimental
class QuillAnimationConfigurations extends Equatable {
const QuillAnimationConfigurations({
required this.checkBoxPointItem,
Expand Down
63 changes: 63 additions & 0 deletions lib/src/models/config/toolbar/buttons/link_style2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter/widgets.dart';

import '../../../themes/quill_dialog_theme.dart';
import 'base.dart';

class QuillToolbarLinkStyleButton2ExtraOptions
extends QuillToolbarBaseButtonExtraOptions {
const QuillToolbarLinkStyleButton2ExtraOptions({
required super.controller,
required super.context,
required super.onPressed,
});
}

class QuillToolbarLinkStyleButton2Options extends QuillToolbarBaseButtonOptions<
QuillToolbarLinkStyleButton2Options,
QuillToolbarLinkStyleButton2ExtraOptions> {
const QuillToolbarLinkStyleButton2Options({
this.iconSize,
this.dialogTheme,
this.constraints,
this.addLinkLabel,
this.editLinkLabel,
this.linkColor,
this.validationMessage,
this.buttonSize,
this.dialogBarrierColor,
this.childrenSpacing = 16.0,
this.autovalidateMode = AutovalidateMode.disabled,
super.iconData,
super.afterButtonPressed,
super.tooltip,
super.iconTheme,
super.childBuilder,
super.controller,
});

final double? iconSize;
final QuillDialogTheme? dialogTheme;

/// The constrains for dialog.
final BoxConstraints? constraints;

/// The text of label in link add mode.
final String? addLinkLabel;

/// The text of label in link edit mode.
final String? editLinkLabel;

/// The color of URL.
final Color? linkColor;

/// The margin between child widgets in the dialog.
final double childrenSpacing;

final AutovalidateMode autovalidateMode;
final String? validationMessage;

/// The size of dialog buttons.
final Size? buttonSize;

final Color? dialogBarrierColor;
}
2 changes: 2 additions & 0 deletions lib/src/models/config/toolbar/buttons/select_alignment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class QuillToolbarSelectAlignmentButtonOptions
this.tooltips,
this.iconSize,
super.afterButtonPressed,

/// This will called on every select alignment button
super.childBuilder,
super.controller,
super.iconTheme,
Expand Down
17 changes: 9 additions & 8 deletions lib/src/models/config/toolbar/buttons/select_header_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ class QuillToolbarSelectHeaderStyleButtonsOptions
super.afterButtonPressed,
super.childBuilder,
super.controller,
super.iconData,
super.iconTheme,
super.tooltip,
this.axis,
this.attributes = const [
Attribute.header,
Attribute.h1,
Attribute.h2,
Attribute.h3,
],
this.attributes,
this.iconSize,
});

final List<Attribute> attributes;
/// Default value:
/// const [
/// Attribute.header,
/// Attribute.h1,
/// Attribute.h2,
/// Attribute.h3,
/// ]
final List<Attribute>? attributes;

/// By default we will the toolbar axis from [QuillToolbarConfigurations]
final Axis? axis;
Expand Down
12 changes: 11 additions & 1 deletion lib/src/models/config/toolbar/configurations.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart' show immutable;
import 'package:flutter/widgets.dart'
show Axis, Color, Decoration, WrapAlignment, WrapCrossAlignment;
show Axis, Color, Decoration, Widget, WrapAlignment, WrapCrossAlignment;
import '../../../widgets/embeds.dart';

import '../../structs/link_dialog_action.dart';
Expand Down Expand Up @@ -107,6 +107,7 @@ class QuillToolbarConfigurations extends Equatable {
this.color,
this.sectionDividerColor,
this.sectionDividerSpace,
this.spacerWidget,

/// By default it will calculated based on the [globalIconSize] from
/// [base] in [QuillToolbarButtonOptions]
Expand All @@ -130,6 +131,15 @@ class QuillToolbarConfigurations extends Equatable {
/// If you want change spesefic buttons or all of them
/// then you came to the right place
final QuillToolbarButtonOptions buttonOptions;

/// A widget that will placed between each button in the toolbar
/// can be used as a spacer
/// it will not used before the first button
/// it will not used after the last button
/// it will also not used in the toolbar dividers
/// Default value will be [SizedBox.shrink()]
/// some widgets like the header styles will be considered as one widget
final Widget? spacerWidget;
final bool multiRowsDisplay;

/// By default it will be
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/documents/nodes/block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'node.dart';
/// - Text Alignment
/// - Text Direction
/// - Code Block
class Block extends Container<Line?> {
base class Block extends Container<Line?> {
/// Creates new unmounted [Block].
@override
Node newInstance() => Block();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/documents/nodes/container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'node.dart';
///
/// Most of the operation handling logic is implemented by [Line]
/// and [QuillText].
abstract class Container<T extends Node?> extends Node {
abstract base class Container<T extends Node?> extends Node {
final LinkedList<Node> _children = LinkedList<Node>();

/// List of children.
Expand Down
6 changes: 3 additions & 3 deletions lib/src/models/documents/nodes/leaf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'line.dart';
import 'node.dart';

/// A leaf in Quill document tree.
abstract class Leaf extends Node {
abstract base class Leaf extends Node {
/// Creates a new [Leaf] with specified [data].
factory Leaf(Object data) {
if (data is Embeddable) {
Expand Down Expand Up @@ -216,7 +216,7 @@ abstract class Leaf extends Node {
/// The reason we are renamed quill Text to [QuillText] so it doesn't
/// conflict with the one from the widgets, material or cupertino library
///
class QuillText extends Leaf {
base class QuillText extends Leaf {
QuillText([String text = ''])
: assert(!text.contains('\n')),
super.val(text);
Expand Down Expand Up @@ -249,7 +249,7 @@ class QuillText extends Leaf {
/// necessarily mean the embed will look according to that style. For instance,
/// applying "bold" style to an image gives no effect, while adding a "link" to
/// an image actually makes the image react to user's action.
class Embed extends Leaf {
base class Embed extends Leaf {
Embed(Embeddable data) : super.val(data);

// Refer to https://www.fileformat.info/info/unicode/char/fffc/index.htm
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/documents/nodes/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'node.dart';
///
/// When a line contains an embed, it fully occupies the line, no other embeds
/// or text nodes are allowed.
class Line extends Container<Leaf?> {
base class Line extends Container<Leaf?> {
@override
Leaf get defaultChild => QuillText();

Expand Down
4 changes: 2 additions & 2 deletions lib/src/models/documents/nodes/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'line.dart';
///
/// The current parent node is exposed by the [parent] property. A node is
/// considered [mounted] when the [parent] property is not `null`.
abstract class Node extends LinkedListEntry<Node> {
abstract base class Node extends LinkedListEntry<Node> {
/// Current parent of this node. May be null if this node is not mounted.
Container? parent;

Expand Down Expand Up @@ -127,7 +127,7 @@ abstract class Node extends LinkedListEntry<Node> {
}

/// Root node of document tree.
class Root extends Container<Container<Node?>> {
base class Root extends Container<Container<Node?>> {
@override
Node newInstance() => Root();

Expand Down
14 changes: 7 additions & 7 deletions lib/src/models/rules/insert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@ class AutoFormatMultipleLinksRule extends InsertRule {
// TODO: You might want to rename those but everywhere even in
// flutter_quill_extensions

static const _oneLinePattern =
static const _oneLineLinkPattern =
r'^https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?(\/.*)?$';
static const _detectLinkPattern =
r'https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?(\/[^\s]*)?';

/// It requires a valid link in one link
static final oneLineRegExp = RegExp(
_oneLinePattern,
static final oneLineLinkRegExp = RegExp(
_oneLineLinkPattern,
caseSensitive: false,
);

Expand All @@ -375,10 +375,10 @@ class AutoFormatMultipleLinksRule extends InsertRule {
_detectLinkPattern,
caseSensitive: false,
);
@Deprecated(
'Please use [linkRegExp1] or [linkRegExp2]',
)
static final linkRegExp = oneLineRegExp;
// @Deprecated(
// 'Please use [linkRegExp1] or [linkRegExp2]',
// )
static final linkRegExp = oneLineLinkRegExp;

@override
Delta? applyRule(
Expand Down
8 changes: 4 additions & 4 deletions lib/src/test/widget_tester_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ extension QuillEnterText on WidgetTester {
return TestAsyncUtils.guard(() async {
final editor = state<QuillEditorState>(
find.descendant(
of: finder,
matching:
find.byType(QuillEditor, skipOffstage: finder.skipOffstage),
matchRoot: true),
of: finder,
matching: find.byType(QuillEditor, skipOffstage: finder.skipOffstage),
matchRoot: true,
),
);
editor.widget.focusNode.requestFocus();
await pump();
Expand Down
15 changes: 13 additions & 2 deletions lib/src/utils/delta.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import 'dart:math' as math;
import 'dart:ui';

import 'package:meta/meta.dart' show immutable;

import '../models/documents/attribute.dart';
import '../models/documents/nodes/node.dart';
import '../models/quill_delta.dart';

// Diff between two texts - old text and new text
@immutable
class Diff {
Diff(this.start, this.deleted, this.inserted);
const Diff({
required this.start,
required this.deleted,
required this.inserted,
});

// Start index in old text at which changes begin.
final int start;
Expand Down Expand Up @@ -37,7 +44,11 @@ Diff getDiff(String oldText, String newText, int cursorPosition) {
start++) {}
final deleted = (start >= end) ? '' : oldText.substring(start, end);
final inserted = newText.substring(start, end + delta);
return Diff(start, deleted, inserted);
return Diff(
start: start,
deleted: deleted,
inserted: inserted,
);
}

int getPositionDelta(Delta user, Delta actual) {
Expand Down
7 changes: 0 additions & 7 deletions lib/src/utils/experimental.dart

This file was deleted.

14 changes: 0 additions & 14 deletions lib/src/utils/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ Map<String, String> parseKeyValuePairs(String s, Set<String> targetKeys) {
return result;
}

@Deprecated('Use replaceStyleStringWithSize instead')
String replaceStyleString(
String s,
double width,
double height,
) {
return replaceStyleStringWithSize(
s,
width: width,
height: height,
isMobile: true,
);
}

String replaceStyleStringWithSize(
String s, {
required double width,
Expand Down
Loading

0 comments on commit f7528d3

Please sign in to comment.