Skip to content

Commit

Permalink
First step of improving flutter quill extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Dec 4, 2023
1 parent 7ccd61e commit 0d88c02
Show file tree
Hide file tree
Showing 61 changed files with 395 additions and 525 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@ pubspec.lock
# For local development
pubspec_overrides.yaml

old_example
old_example

# A directory where you put all of your local things that you don't want to push
.flutter-quill
4 changes: 2 additions & 2 deletions example/lib/presentation/quill/quill_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import 'package:desktop_drop/desktop_drop.dart' show DropTarget;
import 'package:flutter/material.dart';
import 'package:flutter_quill/extensions.dart' show isAndroid, isIOS, isWeb;
import 'package:flutter_quill/flutter_quill.dart';
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
import 'package:flutter_quill_extensions/presentation/embeds/widgets/image.dart'
import 'package:flutter_quill_extensions/embeds/widgets/image.dart'
show getImageProviderByImageSource, imageFileExtensions;
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
import 'package:path/path.dart' as path;

import '../extensions/scaffold_messenger.dart';
Expand Down
6 changes: 6 additions & 0 deletions flutter_quill_extensions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## 0.8.0
* **Breaking Change**: Completly change 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
* Add support for unoffical css property called `deletable` in the image embed, this won't affect how quill js work
* Improvemenets to the image embed

## 0.7.2
* Fix a bug when opening the link dialog for both video and image buttons
* Update `README.md`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';

import '../../models/config/toolbar/buttons/formula.dart';
import '../../../models/config/toolbar/buttons/formula.dart';

class QuillToolbarFormulaButton extends StatelessWidget {
const QuillToolbarFormulaButton({
Expand Down
86 changes: 86 additions & 0 deletions flutter_quill_extensions/lib/embeds/image/editor/image_embed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:flutter_quill/extensions.dart' as base;
import 'package:flutter_quill/flutter_quill.dart' hide OptionalSize;

import '../../../models/config/editor/image/image.dart';
import '../../../models/config/shared_configurations.dart';
import '../../../utils/element_utils/element_utils.dart';
import '../../widgets/image.dart';
import 'image_menu.dart';

class QuillEditorImageEmbedBuilder extends EmbedBuilder {
QuillEditorImageEmbedBuilder({
required this.configurations,
});
final QuillEditorImageEmbedConfigurations configurations;

@override
String get key => BlockEmbed.imageType;

@override
bool get expanded => false;

@override
Widget build(
BuildContext context,
QuillController controller,
base.Embed node,
bool readOnly,
bool inline,
TextStyle textStyle,
) {
assert(!kIsWeb, 'Please provide image EmbedBuilder for Web');

final imageSource = standardizeImageUrl(node.value.data);
final ((imageSize), margin, alignment) = getElementAttributes(node);

final width = imageSize.width;
final height = imageSize.height;

final image = getImageWidgetByImageSource(
imageSource,
imageProviderBuilder: configurations.imageProviderBuilder,
imageErrorWidgetBuilder: configurations.imageErrorWidgetBuilder,
alignment: alignment,
height: height,
width: width,
assetsPrefix: QuillSharedExtensionsConfigurations.get(context: context)
.assetsPrefix,
);

final imageSaverService =
QuillSharedExtensionsConfigurations.get(context: context)
.imageSaverService;
return GestureDetector(
onTap: configurations.onImageClicked ??
() => showDialog(
context: context,
builder: (_) => QuillProvider.value(
value: context.requireQuillProvider,
child: FlutterQuillLocalizationsWidget(
child: ImageOptionsMenu(
controller: controller,
configurations: configurations,
imageSource: imageSource,
imageSize: imageSize,
isReadOnly: readOnly,
imageSaverService: imageSaverService,
),
),
),
),
child: Builder(
builder: (context) {
if (margin != null) {
return Padding(
padding: EdgeInsets.all(margin),
child: image,
);
}
return image;
},
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:flutter/widgets.dart' show BuildContext;
import 'package:flutter_quill/flutter_quill.dart';
import 'package:meta/meta.dart' show immutable;

import '../../../logic/extensions/controller.dart';
import '../../../logic/services/image_picker/s_image_picker.dart';
import '../../../extensions/controller.dart';
import '../../../services/image_picker/s_image_picker.dart';

/// When request picking an image, for example when the image button toolbar
/// clicked, it should be null in case the user didn't choose any image or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import 'package:flutter_quill/flutter_quill.dart'
getEmbedNode;
import 'package:flutter_quill/translations.dart';

import '../../../../logic/models/config/shared_configurations.dart';
import '../../../../logic/services/image_saver/s_image_saver.dart';
import '../../../../logic/utils/string.dart';
import '../../../models/config/editor/image/image.dart';
import '../../../models/config/shared_configurations.dart';
import '../../../services/image_saver/s_image_saver.dart';
import '../../../utils/element_utils/element_utils.dart';
import '../../../utils/string.dart';
import '../../../utils/utils.dart';
import '../../widgets/image.dart' show ImageTapWrapper, getImageStyleString;
import '../../widgets/image_resizer.dart' show ImageResizer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import 'package:flutter_quill/flutter_quill.dart';
import 'package:universal_html/html.dart' as html;

import '../../../models/config/editor/image/image_web.dart';
import '../../../utils/dart_ui/dart_ui_fake.dart'
if (dart.library.html) '../../../utils/dart_ui/dart_ui_real.dart' as ui;
import '../../../utils/element_utils/element_web_utils.dart';
import '../../../utils/utils.dart';
import '../../../utils/web_utils.dart';
import '../shims/dart_ui_fake.dart'
if (dart.library.html) '../shims/dart_ui_real.dart' as ui;

class QuillEditorWebImageEmbedBuilder extends EmbedBuilder {
const QuillEditorWebImageEmbedBuilder({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';
import 'package:flutter_quill/translations.dart';

import '../../../../logic/models/config/shared_configurations.dart';
import '../../../../logic/services/image_picker/image_picker.dart';
import '../../../models/config/shared_configurations.dart';
import '../../../models/config/toolbar/buttons/image.dart';
import '../../embed_types/image.dart';
import '../utils/image_video_utils.dart';
import '../../../services/image_picker/image_picker.dart';
import '../../others/image_video_utils.dart';
import '../editor/image_embed_types.dart';
import 'select_image_source.dart';

class QuillToolbarImageButton extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_quill/extensions.dart' show isDesktop;

import '../../embed_types/image.dart';
import '../editor/image_embed_types.dart';

class SelectImageSourceDialog extends StatelessWidget {
const SelectImageSourceDialog({super.key});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import 'package:flutter_quill/flutter_quill.dart'
QuillToolbarIconButton;
import 'package:flutter_quill/translations.dart';

import '../../../../logic/models/config/shared_configurations.dart';
import '../../../../logic/services/image_picker/image_options.dart';
import '../../../models/config/shared_configurations.dart';
import '../../../models/config/toolbar/buttons/camera.dart';
import '../../embed_types/camera.dart';
import '../../../services/image_picker/image_options.dart';
import 'camera_types.dart';
import 'select_camera_action.dart';

class QuillToolbarCameraButton extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/widgets.dart' show BuildContext;
import 'package:meta/meta.dart' show immutable;

import 'image.dart';
import 'video.dart';
import '../../image/editor/image_embed_types.dart';
import '../../video/video.dart';

enum CameraAction {
video,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_quill/translations.dart';

import '../../embed_types/camera.dart';
import 'camera_types.dart';

class SelectCameraActionDialog extends StatelessWidget {
const SelectCameraActionDialog({super.key});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_quill/extensions.dart' as base;
import 'package:flutter_quill/flutter_quill.dart';

import '../../../models/config/editor/video/video.dart';
import '../../../utils/element_utils/element_utils.dart';
import '../../../utils/utils.dart';
import '../../widgets/video_app.dart';
import '../../widgets/youtube_video_app.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import 'package:youtube_player_flutter/youtube_player_flutter.dart'
show YoutubePlayer;

import '../../../models/config/editor/video/video_web.dart';
import '../../../utils/dart_ui/dart_ui_fake.dart'
if (dart.library.html) '../../../utils/dart_ui/dart_ui_real.dart' as ui;
import '../../../utils/element_utils/element_web_utils.dart';
import '../../../utils/utils.dart';
import '../../../utils/web_utils.dart';
import '../shims/dart_ui_fake.dart'
if (dart.library.html) '../shims/dart_ui_real.dart' as ui;

class QuillEditorWebVideoEmbedBuilder extends EmbedBuilder {
const QuillEditorWebVideoEmbedBuilder({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_quill/extensions.dart' show isDesktop;

import '../../embed_types/video.dart';
import '../video.dart';

class SelectVideoSourceDialog extends StatelessWidget {
const SelectVideoSourceDialog({super.key});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';

import '../../../../logic/models/config/shared_configurations.dart';
import '../../../../logic/services/image_picker/image_options.dart';
import '../../../models/config/shared_configurations.dart';
import '../../../models/config/toolbar/buttons/video.dart';
import '../../embed_types/video.dart';
import '../utils/image_video_utils.dart';
import '../../../services/image_picker/image_options.dart';
import '../../others/image_video_utils.dart';
import '../video.dart';
import 'select_video_source.dart';

class QuillToolbarVideoButton extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/widgets.dart' show BuildContext;
import 'package:flutter_quill/flutter_quill.dart';
import 'package:meta/meta.dart' show immutable;

import '../../../logic/extensions/controller.dart';
import '../../../logic/services/image_picker/s_image_picker.dart';
import '../../extensions/controller.dart';
import '../../services/image_picker/s_image_picker.dart';

/// When request picking an video, for example when the video button toolbar
/// clicked, it should be null in case the user didn't choose any video or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:photo_view/photo_view.dart';

import '../../models/config/editor/image/image.dart';
import '../../utils/utils.dart';
import '../embed_types/image.dart';
import '../image/editor/image_embed_types.dart';

const List<String> imageFileExtensions = [
'.jpeg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter_quill/flutter_quill.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:video_player/video_player.dart';

import '../../../flutter_quill_extensions.dart';
import '../../flutter_quill_extensions.dart';

/// Widget for playing back video
/// Refer to https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:flutter_quill/flutter_quill.dart';

// ignore: unused_import
import '../../presentation/embeds/editor/webview.dart';
import '../utils/quill_image_utils.dart';

/// Extension functions on [QuillController]
Expand All @@ -12,27 +10,6 @@ extension QuillControllerExt on QuillController {
int get index => selection.baseOffset;
int get length => selection.extentOffset - index;

/// Insert webview embed block, it requires [initialUrl] to load
/// the initial page
// void insertWebViewBlock({
// required String initialUrl,
// }) {
// final block = BlockEmbed.custom(
// QuillEditorWebViewBlockEmbed(
// initialUrl,
// ),
// );

// this
// ..skipRequestKeyboard = true
// ..replaceText(
// index,
// length,
// block,
// null,
// );
// }

/// Insert image embed block, it requires the [imageSource]
///
/// it could be local image on the system file
Expand Down
Loading

0 comments on commit 0d88c02

Please sign in to comment.