Migrate to the new version of super clipboard

pull/1653/head v9.1.1
Ellet 1 year ago
parent 5e5544aab2
commit a15612f65a
  1. 5
      example/lib/screens/settings/cubit/settings_cubit.dart
  2. 3
      flutter_quill_extensions/lib/embeds/image/editor/image_menu.dart
  3. 26
      lib/src/l10n/generated/quill_localizations_ar.dart
  4. 15
      lib/src/l10n/quill_ar.arb
  5. 16
      lib/src/l10n/untranslated.json
  6. 116
      lib/src/widgets/raw_editor/raw_editor_state.dart

@ -1,13 +1,12 @@
import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart' show ThemeMode; import 'package:flutter/material.dart' show ThemeMode;
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart' show HydratedMixin; import 'package:hydrated_bloc/hydrated_bloc.dart' show HydratedCubit;
part 'settings_state.dart'; part 'settings_state.dart';
part 'settings_cubit.freezed.dart'; part 'settings_cubit.freezed.dart';
part 'settings_cubit.g.dart'; part 'settings_cubit.g.dart';
class SettingsCubit extends Cubit<SettingsState> with HydratedMixin { class SettingsCubit extends HydratedCubit<SettingsState> {
SettingsCubit() : super(const SettingsState()); SettingsCubit() : super(const SettingsState());
void updateSettings(SettingsState newSettingsState) { void updateSettings(SettingsState newSettingsState) {

@ -96,9 +96,10 @@ class ImageOptionsMenu extends StatelessWidget {
); );
final data = await convertImageToUint8List(image); final data = await convertImageToUint8List(image);
final clipboard = SystemClipboard.instance;
if (data != null) { if (data != null) {
final item = DataWriterItem()..add(Formats.png(data)); final item = DataWriterItem()..add(Formats.png(data));
await ClipboardWriter.instance.write([item]); await clipboard?.write([item]);
} }
navigator.pop(); navigator.pop();
}, },

@ -137,25 +137,25 @@ class FlutterQuillLocalizationsAr extends FlutterQuillLocalizations {
String get headerStyle => 'ستايل العنوان'; String get headerStyle => 'ستايل العنوان';
@override @override
String get normal => 'Normal'; String get normal => 'عادي';
@override @override
String get heading1 => 'Heading 1'; String get heading1 => 'ترويسة ١';
@override @override
String get heading2 => 'Heading 2'; String get heading2 => 'ترويسة ٢';
@override @override
String get heading3 => 'Heading 3'; String get heading3 => 'ترويسة ٣';
@override @override
String get heading4 => 'Heading 4'; String get heading4 => 'ترويسة ٤';
@override @override
String get heading5 => 'Heading 5'; String get heading5 => 'ترويسة ٥';
@override @override
String get heading6 => 'Heading 6'; String get heading6 => 'ترويسة ٦';
@override @override
String get numberedList => 'قائمة مرقمة'; String get numberedList => 'قائمة مرقمة';
@ -249,20 +249,20 @@ class FlutterQuillLocalizationsAr extends FlutterQuillLocalizations {
String get insertImage => 'إدراج صورة'; String get insertImage => 'إدراج صورة';
@override @override
String get pickAPhotoFromYourGallery => 'Pick a photo from your gallery'; String get pickAPhotoFromYourGallery => 'اختيار صورة من معرض الصور';
@override @override
String get takeAPhotoUsingYourCamera => 'Take a photo using your camera'; String get takeAPhotoUsingYourCamera => 'التقاط صورة باستخدام الكاميرا';
@override @override
String get pasteAPhotoUsingALink => 'Paste a photo using a link'; String get pasteAPhotoUsingALink => 'لصق صورة باستخدام رابط';
@override @override
String get pickAVideoFromYourGallery => 'Pick a video from your gallery'; String get pickAVideoFromYourGallery => 'اختيار فيديو من معرض الفيديو';
@override @override
String get recordAVideoUsingYourCamera => 'Record a video using your camera'; String get recordAVideoUsingYourCamera => 'تسجيل فيديو باستخدام الكاميرا';
@override @override
String get pasteAVideoUsingALink => 'Paste a video using a link'; String get pasteAVideoUsingALink => 'لصق فيديو باستخدام رابط';
} }

@ -73,6 +73,19 @@
"photo": "صورة", "photo": "صورة",
"image": "صورة", "image": "صورة",
"caseSensitivityAndWholeWordSearch": "حالة الحساسية والبحث عن كلمة كاملة", "caseSensitivityAndWholeWordSearch": "حالة الحساسية والبحث عن كلمة كاملة",
"insertImage": "إدراج صورة" "insertImage": "إدراج صورة",
"normal": "عادي",
"heading1": "ترويسة ١",
"heading2": "ترويسة ٢",
"heading3": "ترويسة ٣",
"heading4": "ترويسة ٤",
"heading5": "ترويسة ٥",
"heading6": "ترويسة ٦",
"pickAPhotoFromYourGallery": "اختيار صورة من معرض الصور",
"takeAPhotoUsingYourCamera": "التقاط صورة باستخدام الكاميرا",
"pasteAPhotoUsingALink": "لصق صورة باستخدام رابط",
"pickAVideoFromYourGallery": "اختيار فيديو من معرض الفيديو",
"recordAVideoUsingYourCamera": "تسجيل فيديو باستخدام الكاميرا",
"pasteAVideoUsingALink": "لصق فيديو باستخدام رابط"
} }

@ -1,20 +1,4 @@
{ {
"ar": [
"normal",
"heading1",
"heading2",
"heading3",
"heading4",
"heading5",
"heading6",
"pickAPhotoFromYourGallery",
"takeAPhotoUsingYourCamera",
"pasteAPhotoUsingALink",
"pickAVideoFromYourGallery",
"recordAVideoUsingYourCamera",
"pasteAVideoUsingALink"
],
"bg": [ "bg": [
"normal", "normal",
"heading1", "heading1",

@ -177,21 +177,22 @@ class QuillRawEditorState extends EditorState
return; return;
} }
if (controller.copiedImageUrl != null) { // When image copied internally in the editor
final copiedImageUrl = controller.copiedImageUrl;
if (copiedImageUrl != null) {
final index = textEditingValue.selection.baseOffset; final index = textEditingValue.selection.baseOffset;
final length = textEditingValue.selection.extentOffset - index; final length = textEditingValue.selection.extentOffset - index;
final copied = controller.copiedImageUrl!;
controller.replaceText( controller.replaceText(
index, index,
length, length,
BlockEmbed.image(copied.url), BlockEmbed.image(copiedImageUrl.url),
null, null,
); );
if (copied.styleString.isNotEmpty) { if (copiedImageUrl.styleString.isNotEmpty) {
controller.formatText( controller.formatText(
getEmbedNode(controller, index + 1).offset, getEmbedNode(controller, index + 1).offset,
1, 1,
StyleAttribute(copied.styleString), StyleAttribute(copiedImageUrl.styleString),
); );
} }
controller.copiedImageUrl = null; controller.copiedImageUrl = null;
@ -206,46 +207,49 @@ class QuillRawEditorState extends EditorState
return; return;
} }
// TODO: Bug, Doesn't replace the selected text, it just add a new one final clipboard = SystemClipboard.instance;
final reader = await ClipboardReader.readClipboard(); if (clipboard != null) {
if (reader.canProvide(Formats.htmlText)) { // TODO: Bug, Doesn't replace the selected text, it just add a new one
final html = await reader.readValue(Formats.htmlText); final reader = await clipboard.read();
if (html == null) { if (reader.canProvide(Formats.htmlText)) {
return; final html = await reader.readValue(Formats.htmlText);
} if (html == null) {
final deltaFromCliboard = Document.fromHtml(html); return;
var newDelta = Delta(); }
newDelta = newDelta.compose(deltaFromCliboard); final deltaFromClipboard = Document.fromHtml(html);
if (!controller.document.isEmpty()) { var newDelta = Delta();
newDelta = newDelta.compose(controller.document.toDelta()); newDelta = newDelta.compose(deltaFromClipboard);
} if (!controller.document.isEmpty()) {
newDelta = newDelta.compose(controller.document.toDelta());
}
controller controller
..setContents( ..setContents(
newDelta, newDelta,
) )
..updateSelection( ..updateSelection(
TextSelection.collapsed( TextSelection.collapsed(
offset: controller.document.length, offset: controller.document.length,
), ),
ChangeSource.local, ChangeSource.local,
); );
bringIntoView(textEditingValue.selection.extent); bringIntoView(textEditingValue.selection.extent);
// Collapse the selection and hide the toolbar and handles. // Collapse the selection and hide the toolbar and handles.
userUpdateTextEditingValue( userUpdateTextEditingValue(
TextEditingValue( TextEditingValue(
text: textEditingValue.text, text: textEditingValue.text,
selection: TextSelection.collapsed( selection: TextSelection.collapsed(
offset: textEditingValue.selection.end, offset: textEditingValue.selection.end,
),
), ),
), cause,
cause, );
);
return; return;
}
} }
// Snapshot the input before using `await`. // Snapshot the input before using `await`.
@ -279,25 +283,27 @@ class QuillRawEditorState extends EditorState
final onImagePaste = widget.configurations.onImagePaste; final onImagePaste = widget.configurations.onImagePaste;
if (onImagePaste != null) { if (onImagePaste != null) {
final reader = await ClipboardReader.readClipboard(); if (clipboard != null) {
if (!reader.canProvide(Formats.png)) { final reader = await clipboard.read();
return; if (!reader.canProvide(Formats.png)) {
}
reader.getFile(Formats.png, (value) async {
final image = value;
final imageUrl = await onImagePaste(await image.readAll());
if (imageUrl == null) {
return; return;
} }
reader.getFile(Formats.png, (value) async {
final image = value;
controller.replaceText( final imageUrl = await onImagePaste(await image.readAll());
textEditingValue.selection.end, if (imageUrl == null) {
0, return;
BlockEmbed.image(imageUrl), }
null,
); controller.replaceText(
}); textEditingValue.selection.end,
0,
BlockEmbed.image(imageUrl),
null,
);
});
}
} }
} }

Loading…
Cancel
Save