mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: support pasting image from Slack (#5864)
This commit is contained in:
parent
393850ae4b
commit
0abf916796
@ -1,11 +1,10 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
|
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
||||||
import 'package:appflowy/startup/startup.dart';
|
import 'package:appflowy/startup/startup.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:integration_test/integration_test.dart';
|
import 'package:integration_test/integration_test.dart';
|
||||||
|
|
||||||
@ -246,10 +245,6 @@ void main() {
|
|||||||
expect(editorState.document.root.children.length, 2);
|
expect(editorState.document.root.children.length, 2);
|
||||||
final node = editorState.getNodeAtPath([0])!;
|
final node = editorState.getNodeAtPath([0])!;
|
||||||
expect(node.type, ImageBlockKeys.type);
|
expect(node.type, ImageBlockKeys.type);
|
||||||
expect(
|
|
||||||
node.attributes[ImageBlockKeys.url],
|
|
||||||
'https://user-images.githubusercontent.com/9403740/262918875-603f4adb-58dd-49b5-8201-341d354935fd.png',
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:appflowy/plugins/document/application/document_bloc.dart';
|
import 'package:appflowy/plugins/document/application/document_bloc.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/editor_state_paste_node_extension.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/editor_state_paste_node_extension.dart';
|
||||||
@ -8,8 +6,10 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_p
|
|||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_in_app_json.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_in_app_json.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_plain_text.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_plain_text.dart';
|
||||||
import 'package:appflowy/startup/startup.dart';
|
import 'package:appflowy/startup/startup.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_backend/log.dart';
|
||||||
|
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
|
||||||
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:string_validator/string_validator.dart';
|
import 'package:string_validator/string_validator.dart';
|
||||||
|
|
||||||
@ -43,6 +43,7 @@ CommandShortcutEventHandler _pasteCommandHandler = (editorState) {
|
|||||||
|
|
||||||
// paste as link preview
|
// paste as link preview
|
||||||
if (await _pasteAsLinkPreview(editorState, plainText)) {
|
if (await _pasteAsLinkPreview(editorState, plainText)) {
|
||||||
|
Log.info('Pasted as link preview');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,17 +57,14 @@ CommandShortcutEventHandler _pasteCommandHandler = (editorState) {
|
|||||||
if (inAppJson != null && inAppJson.isNotEmpty) {
|
if (inAppJson != null && inAppJson.isNotEmpty) {
|
||||||
await editorState.deleteSelectionIfNeeded();
|
await editorState.deleteSelectionIfNeeded();
|
||||||
if (await editorState.pasteInAppJson(inAppJson)) {
|
if (await editorState.pasteInAppJson(inAppJson)) {
|
||||||
|
Log.info('Pasted in app json');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (html != null && html.isNotEmpty) {
|
// if the image data is not null, we should handle it first
|
||||||
await editorState.deleteSelectionIfNeeded();
|
// because the image URL in the HTML may not be reachable due to permission issues
|
||||||
if (await editorState.pasteHtml(html)) {
|
// For example, when pasting an image from Slack, the image URL provided is not public.
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (image != null && image.$2?.isNotEmpty == true) {
|
if (image != null && image.$2?.isNotEmpty == true) {
|
||||||
final documentBloc =
|
final documentBloc =
|
||||||
editorState.document.root.context?.read<DocumentBloc>();
|
editorState.document.root.context?.read<DocumentBloc>();
|
||||||
@ -81,11 +79,21 @@ CommandShortcutEventHandler _pasteCommandHandler = (editorState) {
|
|||||||
documentId,
|
documentId,
|
||||||
);
|
);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
Log.info('Pasted image');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (html != null && html.isNotEmpty) {
|
||||||
|
await editorState.deleteSelectionIfNeeded();
|
||||||
|
if (await editorState.pasteHtml(html)) {
|
||||||
|
Log.info('Pasted html');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plainText != null && plainText.isNotEmpty) {
|
if (plainText != null && plainText.isNotEmpty) {
|
||||||
|
Log.info('Pasted plain text');
|
||||||
await editorState.pastePlainText(plainText);
|
await editorState.pastePlainText(plainText);
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
|
Loading…
Reference in New Issue
Block a user