From 6066f2f7144622319d57e3fa975f9a59dfce7877 Mon Sep 17 00:00:00 2001 From: Ellet Date: Thu, 7 Dec 2023 13:54:29 +0300 Subject: [PATCH] Link pattern bug fixes --- CHANGELOG.md | 6 ++++ .../lib/presentation/quill/quill_screen.dart | 16 ++++----- .../lib/embeds/others/image_video_utils.dart | 36 +++++++++++++------ .../lib/utils/patterns.dart | 17 +++++++++ flutter_quill_extensions/lib/utils/utils.dart | 7 ++-- .../widgets/style_widgets/number_point.dart | 8 ++++- version.dart | 2 +- 7 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 flutter_quill_extensions/lib/utils/patterns.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 4102bf777..b52dd226b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## 9.0.0-dev-7 +* Fix a bug in chaning the background/font color of ol/ul list +* Flutter Quill Extensions: + * Fix link bug in the video url + * Fix patterns + ## 9.0.0-dev-6 * Move the `child` from `QuillToolbarConfigurations` into `QuillToolbar` directly * Bug fixes diff --git a/example/lib/presentation/quill/quill_screen.dart b/example/lib/presentation/quill/quill_screen.dart index e032cb446..712a334ab 100644 --- a/example/lib/presentation/quill/quill_screen.dart +++ b/example/lib/presentation/quill/quill_screen.dart @@ -119,14 +119,14 @@ class _QuillScreenState extends State { codeBlock: QuillEditorCodeBlockElementOptions( enableLineNumbers: true, ), - // orderedList: QuillEditorOrderedListElementOptions( - // backgroundColor: Colors.amber, - // fontColor: Colors.black, - // ), - // unorderedList: QuillEditorUnOrderedListElementOptions( - // backgroundColor: Colors.green, - // fontColor: Colors.red, - // ), + orderedList: QuillEditorOrderedListElementOptions( + backgroundColor: Colors.amber, + fontColor: Colors.black, + ), + unorderedList: QuillEditorUnOrderedListElementOptions( + backgroundColor: Colors.green, + fontColor: Colors.red, + ), ), ), scrollController: _editorScrollController, diff --git a/flutter_quill_extensions/lib/embeds/others/image_video_utils.dart b/flutter_quill_extensions/lib/embeds/others/image_video_utils.dart index 03514f1b3..808f7517f 100644 --- a/flutter_quill_extensions/lib/embeds/others/image_video_utils.dart +++ b/flutter_quill_extensions/lib/embeds/others/image_video_utils.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_quill/flutter_quill.dart' show QuillDialogTheme; import 'package:flutter_quill/translations.dart'; +import '../../utils/patterns.dart'; + enum LinkType { video, image, @@ -28,7 +30,7 @@ class TypeLinkDialog extends StatefulWidget { class TypeLinkDialogState extends State { late String _link; late TextEditingController _controller; - late RegExp _linkRegExp; + RegExp? _linkRegExp; @override void initState() { @@ -36,15 +38,7 @@ class TypeLinkDialogState extends State { _link = widget.link ?? ''; _controller = TextEditingController(text: _link); - final defaultLinkNonSecureRegExp = RegExp( - r'https?://.*?\.(?:png|jpe?g|gif|bmp|webp|tiff?)', - caseSensitive: false, - ); // Not secure - // final defaultLinkRegExp = RegExp( - // r'https://.*?\.(?:png|jpe?g|gif|bmp|webp|tiff?)', - // caseSensitive: false, - // ); // Secure - _linkRegExp = widget.linkRegExp ?? defaultLinkNonSecureRegExp; + _linkRegExp = widget.linkRegExp; } @override @@ -102,8 +96,28 @@ class TypeLinkDialogState extends State { Navigator.pop(context, _link.trim()); } + RegExp get linkRegExp { + final customRegExp = _linkRegExp; + if (customRegExp != null) { + return customRegExp; + } + switch (widget.linkType) { + case LinkType.video: + if (youtubeRegExp.hasMatch(_link)) { + return youtubeRegExp; + } + return videoRegExp; + case LinkType.image: + return imageRegExp; + } + } + bool _canPress() { - return _link.isNotEmpty && _linkRegExp.hasMatch(_link); + if (_link.isEmpty) { + return false; + } + if (widget.linkType == LinkType.image) {} + return _link.isNotEmpty && linkRegExp.hasMatch(_link); } } diff --git a/flutter_quill_extensions/lib/utils/patterns.dart b/flutter_quill_extensions/lib/utils/patterns.dart new file mode 100644 index 000000000..53c1650d6 --- /dev/null +++ b/flutter_quill_extensions/lib/utils/patterns.dart @@ -0,0 +1,17 @@ +RegExp base64RegExp = RegExp( + r'^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$', +); + +final imageRegExp = RegExp( + r'https?://.*?\.(?:png|jpe?g|gif|bmp|webp|tiff?)', + caseSensitive: false, +); + +final videoRegExp = RegExp( + r'\bhttps?://\S+\.(mp4|mov|avi|mkv|flv|wmv|webm)\b', + caseSensitive: false, +); +final youtubeRegExp = RegExp( + r'^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|live\/|v\/)?)([\w\-]+)(\S+)?$', + caseSensitive: false, +); diff --git a/flutter_quill_extensions/lib/utils/utils.dart b/flutter_quill_extensions/lib/utils/utils.dart index fc620e9b7..37f5f0205 100644 --- a/flutter_quill_extensions/lib/utils/utils.dart +++ b/flutter_quill_extensions/lib/utils/utils.dart @@ -6,13 +6,10 @@ import 'package:http/http.dart' as http; import '../embeds/widgets/image.dart'; import '../services/image_saver/s_image_saver.dart'; - -RegExp _base64 = RegExp( - r'^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$', -); +import 'patterns.dart'; bool isBase64(String str) { - return _base64.hasMatch(str); + return base64RegExp.hasMatch(str); } bool isHttpBasedUrl(String url) { diff --git a/lib/src/widgets/style_widgets/number_point.dart b/lib/src/widgets/style_widgets/number_point.dart index 307a8ebe2..398dd3945 100644 --- a/lib/src/widgets/style_widgets/number_point.dart +++ b/lib/src/widgets/style_widgets/number_point.dart @@ -37,7 +37,13 @@ class QuillEditorNumberPoint extends StatelessWidget { alignment: AlignmentDirectional.topEnd, width: width, padding: EdgeInsetsDirectional.only(end: padding), - child: Text(withDot ? '$s.' : s, style: style), + color: context.quillEditorElementOptions?.orderedList.backgroundColor, + child: Text( + withDot ? '$s.' : s, + style: style.copyWith( + color: context.quillEditorElementOptions?.orderedList.fontColor, + ), + ), ); } if (attrs.containsKey(Attribute.indent.key)) { diff --git a/version.dart b/version.dart index 123f4db07..78f02741d 100644 --- a/version.dart +++ b/version.dart @@ -1 +1 @@ -const version = '9.0.0-dev-6'; +const version = '9.0.0-dev-7';