Skip to content

Commit

Permalink
New dev update (#1582)
Browse files Browse the repository at this point in the history
* Prepare to release
  • Loading branch information
EchoEllet authored Dec 10, 2023
1 parent 1d58185 commit e063afe
Show file tree
Hide file tree
Showing 40 changed files with 226 additions and 962 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
paths:
- 'pubspec.yaml'
- 'flutter_quill_extensions/pubspec.yaml'

jobs:
build_linux:
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

All notable changes to this project will be documented in this file.

## 9.0.0-dev-11
## 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

## 9.0.0-dev-10
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ it's in the GitHub repo instead.
- [Table of contents](#table-of-contents)
- [Screenshots](#screenshots)
- [Installation](#installation)
- [Platform Specific Configurations](#platform-specific-configurations)
- [Usage](#usage)
- [Migration](#migration)
- [Input / Output](#input--output)
Expand Down Expand Up @@ -102,7 +103,7 @@ dependencies:
These versions are tested and well-supported, you shouldn't get a build failure -->
## Usage
## Platform Specific Configurations
Before using the package, we must inform you the package use the following plugins:
```
Expand All @@ -112,7 +113,11 @@ Before using the package, we must inform you the package use the following plugi
super_clipboard
```

All of them doesn't require any platform spesefic setup, except [super_clipboard](https://pub.dev/packages/super_clipboard) which needs some setup on Android only, it's optional but to support copying images and pasting them into editor then you must setup it, open the page in pub.dev and read the `README.md` to get the instructions.
All of them doesn't require any platform specific setup, except [super_clipboard](https://pub.dev/packages/super_clipboard) which needs some setup on Android only, it's used to support copying images and pasting them into editor then you must setup it, open the page in pub.dev and read the `README.md` to get the instructions.

The minSdkVersion is `23` as `super_clipboard` requires it

## Usage

First, you need to instantiate a controller

Expand Down
9 changes: 8 additions & 1 deletion flutter_quill_extensions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

All notable changes to this project will be documented in this file.

## 9.0.0-dev-11
## 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

## 9.0.0-dev-10
Expand Down
8 changes: 0 additions & 8 deletions flutter_quill_extensions/lib/extensions/controller_ext.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:flutter_quill/flutter_quill.dart';

import '../utils/quill_image_utils.dart';

/// Extension functions on [QuillController]
/// that make it easier to insert the embed blocks
///
Expand Down Expand Up @@ -43,10 +41,4 @@ extension QuillControllerExt on QuillController {
..skipRequestKeyboard = true
..replaceText(index, length, BlockEmbed.video(videoUrl), null);
}

QuillImageUtilities get imageUtilities {
return QuillImageUtilities(
controller: this,
);
}
}
96 changes: 47 additions & 49 deletions flutter_quill_extensions/lib/utils/quill_image_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ 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,
);

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) {
Expand Down Expand Up @@ -172,31 +171,49 @@ class QuillImageUtilities {
required bool onlyLocalImages,
}) {
_webIsNotSupported('getImagesPathsFromDocument');
final images = controller.document.root.children
.whereType<quill.Line>()
.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<quill.Line>()
// .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 = <String>[];
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;
}

Expand Down Expand Up @@ -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<Iterable<String>> getCachedImagePathsFromDocument({
Iterable<String> getCachedImagePathsFromDocument({
String? replaceUnexistentImagesWith,
}) async {
}) {
_webIsNotSupported('getCachedImagePathsFromDocument');
final imagePaths = getImagesPathsFromDocument(
onlyLocalImages: true,
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions flutter_quill_extensions/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_quill_extensions
description: Embed extensions for flutter_quill including image, video, formula and etc.
version: 9.0.0-dev-11
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/
Expand Down Expand Up @@ -44,7 +44,7 @@ dependencies:
url_launcher: ^6.2.1
super_clipboard: ^0.7.3
gal: ^2.1.3
gal_linux: ^0.0.1-dev-3
gal_linux: ^0.0.1
image_picker: ^1.0.4

dev_dependencies:
Expand Down
9 changes: 8 additions & 1 deletion flutter_quill_test/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

All notable changes to this project will be documented in this file.

## 9.0.0-dev-11
## 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

## 9.0.0-dev-10
Expand Down
2 changes: 1 addition & 1 deletion flutter_quill_test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.0-dev-11
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/
Expand Down
3 changes: 1 addition & 2 deletions lib/flutter_quill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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/quill_delta.dart';
export 'src/models/structs/doc_change.dart';
export 'src/models/structs/image_url.dart';
export 'src/models/structs/link_dialog_action.dart';
Expand All @@ -33,6 +32,6 @@ 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/select_header_style_button.dart';
export 'src/widgets/toolbar/buttons/hearder_style/select_header_style_button.dart';
export 'src/widgets/toolbar/simple_toolbar.dart';
export 'src/widgets/utils/provider.dart';
2 changes: 1 addition & 1 deletion lib/quill_delta.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
library flutter_quill.delta;

export 'src/models/quill_delta.dart';
export 'package:dart_quill_delta/dart_quill_delta.dart';
30 changes: 17 additions & 13 deletions lib/src/models/documents/document.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async' show StreamController;

import '../../../quill_delta.dart';
import '../../widgets/quill/embeds.dart';
import '../quill_delta.dart';
import '../rules/rule.dart';
import '../structs/doc_change.dart';
import '../structs/history_changed.dart';
Expand Down Expand Up @@ -53,12 +53,13 @@ class Document {
_rules.setCustomRules(customRules);
}

final StreamController<DocChange> _observer = StreamController.broadcast();
final StreamController<DocChange> documentChangeObserver =
StreamController.broadcast();

final History _history = History();
final History history = History();

/// Stream of [DocChange]s applied to this document.
Stream<DocChange> get changes => _observer.stream;
Stream<DocChange> get changes => documentChangeObserver.stream;

/// Inserts [data] in this document at specified [index].
///
Expand Down Expand Up @@ -285,7 +286,7 @@ class Document {
///
/// In case the [change] is invalid, behavior of this method is unspecified.
void compose(Delta delta, ChangeSource changeSource) {
assert(!_observer.isClosed);
assert(!documentChangeObserver.isClosed);
delta.trim();
assert(delta.isNotEmpty);

Expand Down Expand Up @@ -320,21 +321,21 @@ class Document {
throw StateError('Compose failed');
}
final change = DocChange(originalDelta, delta, changeSource);
_observer.add(change);
_history.handleDocChange(change);
documentChangeObserver.add(change);
history.handleDocChange(change);
}

HistoryChanged undo() {
return _history.undo(this);
return history.undo(this);
}

HistoryChanged redo() {
return _history.redo(this);
return history.redo(this);
}

bool get hasUndo => _history.hasUndo;
bool get hasUndo => history.hasUndo;

bool get hasRedo => _history.hasRedo;
bool get hasRedo => history.hasRedo;

static Delta _transform(Delta delta) {
final res = Delta();
Expand Down Expand Up @@ -384,8 +385,8 @@ class Document {
}

void close() {
_observer.close();
_history.clear();
documentChangeObserver.close();
history.clear();
}

/// Returns plain text representation of this document.
Expand Down Expand Up @@ -450,4 +451,7 @@ enum ChangeSource {

/// Change originated from a remote action.
remote,

/// Silent change.
silent;
}
2 changes: 1 addition & 1 deletion lib/src/models/documents/history.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../quill_delta.dart';
import '../../../quill_delta.dart';
import '../structs/doc_change.dart';
import '../structs/history_changed.dart';
import 'document.dart';
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
@@ -1,4 +1,4 @@
import '../../quill_delta.dart';
import '../../../../quill_delta.dart';
import 'container.dart';
import 'line.dart';
import 'node.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/documents/nodes/leaf.dart
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 '../../quill_delta.dart';
import '../style.dart';
import 'embeddable.dart';
import 'line.dart';
Expand Down
Loading

0 comments on commit e063afe

Please sign in to comment.