From 380ea156434f9cd0c4353f1b979a14f02e65560e Mon Sep 17 00:00:00 2001 From: Ellet Date: Sun, 10 Dec 2023 19:22:58 +0300 Subject: [PATCH] Update flutter quill extensions --- CHANGELOG.md | 7 ++ flutter_quill_extensions/CHANGELOG.md | 7 ++ .../lib/extensions/controller_ext.dart | 6 -- .../lib/utils/quill_image_utils.dart | 96 +++++++++---------- flutter_quill_extensions/pubspec.yaml | 2 +- flutter_quill_test/CHANGELOG.md | 7 ++ flutter_quill_test/pubspec.yaml | 2 +- pubspec.yaml | 2 +- quill_html_converter/CHANGELOG.md | 7 ++ quill_html_converter/pubspec.yaml | 2 +- version.dart | 2 +- 11 files changed, 80 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a0cead0..a4d0bba2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## 9.0.0 +* This version is quite stable but it's not how we wanted to be, because the lack of time and there are not too many maintainers active, we decided to publish it, we might make a new breaking changes verion + +## 9.0.1-dev.1 +* Flutter Quill Extensions: + * Update `QuillImageUtilities` and fixining some bugs + ## 9.0.1-dev * Test new GitHub workflows diff --git a/flutter_quill_extensions/CHANGELOG.md b/flutter_quill_extensions/CHANGELOG.md index 7a0cead0..a4d0bba2 100644 --- a/flutter_quill_extensions/CHANGELOG.md +++ b/flutter_quill_extensions/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## 9.0.0 +* This version is quite stable but it's not how we wanted to be, because the lack of time and there are not too many maintainers active, we decided to publish it, we might make a new breaking changes verion + +## 9.0.1-dev.1 +* Flutter Quill Extensions: + * Update `QuillImageUtilities` and fixining some bugs + ## 9.0.1-dev * Test new GitHub workflows diff --git a/flutter_quill_extensions/lib/extensions/controller_ext.dart b/flutter_quill_extensions/lib/extensions/controller_ext.dart index d1687ea7..ab04d04d 100644 --- a/flutter_quill_extensions/lib/extensions/controller_ext.dart +++ b/flutter_quill_extensions/lib/extensions/controller_ext.dart @@ -43,10 +43,4 @@ extension QuillControllerExt on QuillController { ..skipRequestKeyboard = true ..replaceText(index, length, BlockEmbed.video(videoUrl), null); } - - QuillImageUtilities get imageUtilities { - return QuillImageUtilities( - controller: this, - ); - } } diff --git a/flutter_quill_extensions/lib/utils/quill_image_utils.dart b/flutter_quill_extensions/lib/utils/quill_image_utils.dart index 4a366c09..e0e85b1d 100644 --- a/flutter_quill_extensions/lib/utils/quill_image_utils.dart +++ b/flutter_quill_extensions/lib/utils/quill_image_utils.dart @@ -2,10 +2,9 @@ import 'dart:io' show Directory, File, Platform; import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter_quill/flutter_quill.dart' as quill; +import 'package:flutter_quill/quill_delta.dart'; import 'package:path/path.dart' as path; -import 'utils.dart'; - typedef OnGenerateNewFileNameCallback = String Function( String currentFileName, String fileExt, @@ -13,10 +12,10 @@ typedef OnGenerateNewFileNameCallback = String Function( class QuillImageUtilities { const QuillImageUtilities({ - required this.controller, + required this.document, }); - final quill.QuillController controller; + final quill.Document document; /// Private function that is throw an error if the platform is web static void _webIsNotSupported(String functionName) { @@ -172,31 +171,49 @@ class QuillImageUtilities { required bool onlyLocalImages, }) { _webIsNotSupported('getImagesPathsFromDocument'); - final images = controller.document.root.children - .whereType() - .where((node) { - if (node.isEmpty) { - return false; - } - final firstNode = node.children.first; - if (firstNode is! quill.Embed) { - return false; - } + // final images = document.root.children + // .whereType() + // .where((node) { + // if (node.isEmpty) { + // return false; + // } + // final firstNode = node.children.first; + // if (firstNode is! quill.Embed) { + // return false; + // } + + // if (firstNode.value.type != quill.BlockEmbed.imageType) { + // return false; + // } + // final imageSource = firstNode.value.data; + // if (imageSource is! String) { + // return false; + // } + // if (onlyLocalImages && isHttpBasedUrl(imageSource)) { + // return false; + // } + // return imageSource.trim().isNotEmpty; + // }) + // .toList() + // .map((e) => (e.children.first as quill.Embed).value.data as String); + + final images = []; + for (final item in document.toDelta().toJson()) { + if (item is! Map) { + return []; + } + if (!item.containsKey(Operation.insertKey)) { + return []; + } + final insertValue = item[Operation.insertKey]; - if (firstNode.value.type != quill.BlockEmbed.imageType) { - return false; - } - final imageSource = firstNode.value.data; - if (imageSource is! String) { - return false; - } - if (onlyLocalImages && isHttpBasedUrl(imageSource)) { - return false; - } - return imageSource.trim().isNotEmpty; - }) - .toList() - .map((e) => (e.children.first as quill.Embed).value.data as String); + // Check if the insert value is a map with the "image" key + if (insertValue is Map && + insertValue.containsKey(quill.BlockEmbed.imageType)) { + final String imageUrl = insertValue[quill.BlockEmbed.imageType]; + images.add(imageUrl); + } + } return images; } @@ -249,9 +266,9 @@ class QuillImageUtilities { /// /// Returns a list of cached image paths found in the document. /// On non-mobile platforms, this function returns an empty list. - Future> getCachedImagePathsFromDocument({ + Iterable getCachedImagePathsFromDocument({ String? replaceUnexistentImagesWith, - }) async { + }) { _webIsNotSupported('getCachedImagePathsFromDocument'); final imagePaths = getImagesPathsFromDocument( onlyLocalImages: true, @@ -262,25 +279,6 @@ class QuillImageUtilities { final isCurrentImageCached = isImageCached(imagePath); return isCurrentImageCached; }).toList(); - - // Remove all the images that doesn't exists - for (final imagePath in cachesImagePaths) { - final file = File(imagePath); - final exists = await file.exists(); - if (!exists) { - final index = cachesImagePaths.indexOf(imagePath); - if (index == -1) { - continue; - } - cachesImagePaths.removeAt(index); - if (replaceUnexistentImagesWith != null) { - cachesImagePaths.insert( - index, - replaceUnexistentImagesWith, - ); - } - } - } return cachesImagePaths; } } diff --git a/flutter_quill_extensions/pubspec.yaml b/flutter_quill_extensions/pubspec.yaml index 87bbab80..634248e3 100644 --- a/flutter_quill_extensions/pubspec.yaml +++ b/flutter_quill_extensions/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill_extensions description: Embed extensions for flutter_quill including image, video, formula and etc. -version: 9.0.1-dev +version: 9.0.0 homepage: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_extensions/ repository: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_extensions/ issue_tracker: https://github.com/singerdmx/flutter-quill/issues/ diff --git a/flutter_quill_test/CHANGELOG.md b/flutter_quill_test/CHANGELOG.md index 7a0cead0..a4d0bba2 100644 --- a/flutter_quill_test/CHANGELOG.md +++ b/flutter_quill_test/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## 9.0.0 +* This version is quite stable but it's not how we wanted to be, because the lack of time and there are not too many maintainers active, we decided to publish it, we might make a new breaking changes verion + +## 9.0.1-dev.1 +* Flutter Quill Extensions: + * Update `QuillImageUtilities` and fixining some bugs + ## 9.0.1-dev * Test new GitHub workflows diff --git a/flutter_quill_test/pubspec.yaml b/flutter_quill_test/pubspec.yaml index d747f9d4..7b1a400f 100644 --- a/flutter_quill_test/pubspec.yaml +++ b/flutter_quill_test/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill_test description: Test utilities for flutter_quill which includes methods to simplify interacting with the editor in test cases. -version: 9.0.1-dev +version: 9.0.0 homepage: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_test/ repository: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_test/ issue_tracker: https://github.com/singerdmx/flutter-quill/issues/ diff --git a/pubspec.yaml b/pubspec.yaml index 5c5ff2a9..9b2dbf6e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: A rich text editor built for the modern Android, iOS, web and desktop platforms. It is the WYSIWYG editor and a Quill component for Flutter. -version: 9.0.1-dev +version: 9.0.0 homepage: https://1o24bbs.com/c/bulletjournal/108/ repository: https://github.com/singerdmx/flutter-quill/ issue_tracker: https://github.com/singerdmx/flutter-quill/issues/ diff --git a/quill_html_converter/CHANGELOG.md b/quill_html_converter/CHANGELOG.md index 7a0cead0..a4d0bba2 100644 --- a/quill_html_converter/CHANGELOG.md +++ b/quill_html_converter/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## 9.0.0 +* This version is quite stable but it's not how we wanted to be, because the lack of time and there are not too many maintainers active, we decided to publish it, we might make a new breaking changes verion + +## 9.0.1-dev.1 +* Flutter Quill Extensions: + * Update `QuillImageUtilities` and fixining some bugs + ## 9.0.1-dev * Test new GitHub workflows diff --git a/quill_html_converter/pubspec.yaml b/quill_html_converter/pubspec.yaml index e001077b..94f20e15 100644 --- a/quill_html_converter/pubspec.yaml +++ b/quill_html_converter/pubspec.yaml @@ -1,6 +1,6 @@ name: quill_html_converter description: A extension for flutter_quill package to add support for dealing with conversion to/from html -version: 9.0.1-dev +version: 9.0.0 homepage: https://github.com/singerdmx/flutter-quill/tree/master/quill_html_converter/ repository: https://github.com/singerdmx/flutter-quill/tree/master/quill_html_converter/ issue_tracker: https://github.com/singerdmx/flutter-quill/issues/ diff --git a/version.dart b/version.dart index 24b74937..44108adc 100644 --- a/version.dart +++ b/version.dart @@ -1 +1 @@ -const version = '9.0.1-dev'; +const version = '9.0.0';