Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: drag view into document to link to view (#6991)
Mathias Mogensen802a667907a5
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_handler.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_handler.dartindex af5031f5cc..443db069d1 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_handler.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_handler.dart@@ -1,11 +1,11 @@+import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';+import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';import 'package:flutter/material.dart';import 'package:appflowy/plugins/document/presentation/editor_drop_manager.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_file.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_image.dart';-import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_block_component.dart';-import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';-import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';import 'package:appflowy/shared/patterns/file_type_patterns.dart';import 'package:appflowy_editor/appflowy_editor.dart';import 'package:desktop_drop/desktop_drop.dart';@@ -37,12 +37,34 @@ class EditorDropHandler extends StatelessWidget {@overrideWidget build(BuildContext context) {final childWidget = Consumer<EditorDropManagerState>(- builder: (context, dropState, _) => DropTarget(- enable: dropState.isDropEnabled,- onDragExited: (_) => editorState.selectionService.removeDropTarget(),- onDragUpdated: _onDragUpdated,- onDragDone: _onDragDone,- child: child,+ builder: (context, dropState, _) => DragTarget<ViewPB>(+ onLeave: (_) => editorState.selectionService.removeDropTarget(),+ onMove: (details) {+ if (details.data.id == viewId) {+ return;+ }++ _onDragUpdated(details.offset);+ },+ onWillAcceptWithDetails: (details) {+ if (!dropState.isDropEnabled) {+ return false;+ }++ if (details.data.id == viewId) {+ return false;+ }++ return true;+ },+ onAcceptWithDetails: _onDragViewDone,+ builder: (context, _, __) => DropTarget(+ enable: dropState.isDropEnabled,+ onDragExited: (_) => editorState.selectionService.removeDropTarget(),+ onDragUpdated: (details) => _onDragUpdated(details.globalPosition),+ onDragDone: _onDragDone,+ child: child,+ ),),);@@ -68,9 +90,8 @@ class EditorDropHandler extends StatelessWidget {);}- void _onDragUpdated(DropEventDetails details) {- final data = editorState.selectionService- .getDropTargetRenderData(details.globalPosition);+ void _onDragUpdated(Offset position) {+ final data = editorState.selectionService.getDropTargetRenderData(position);if (data != null &&data.dropPath != null &&@@ -79,8 +100,7 @@ class EditorDropHandler extends StatelessWidget {// how we can exclude them from the Drop Target!_excludeFromDropTarget.contains(data.cursorNode?.type)) {// Render the drop target- editorState.selectionService- .renderDropTargetForOffset(details.globalPosition);+ editorState.selectionService.renderDropTargetForOffset(position);} else {editorState.selectionService.removeDropTarget();}@@ -113,4 +133,26 @@ class EditorDropHandler extends StatelessWidget {}}}++ void _onDragViewDone(DragTargetDetails<ViewPB> details) {+ editorState.selectionService.removeDropTarget();++ final data =+ editorState.selectionService.getDropTargetRenderData(details.offset);+ if (data != null) {+ final cursorNode = data.cursorNode;+ final dropPath = data.dropPath;++ if (cursorNode != null && dropPath != null) {+ if (_excludeFromDropTarget.contains(cursorNode.type)) {+ return;+ }++ final view = details.data;+ final node = pageMentionNode(view.id);+ final t = editorState.transaction..insertNode(dropPath, node);+ editorState.apply(t);+ }+ }+ }}diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/draggable_view_item.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/draggable_view_item.dartindex 7f46266a9a..2b27024cff 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/draggable_view_item.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/draggable_view_item.dart@@ -65,6 +65,11 @@ class _DraggableViewItemState extends State<DraggableViewItem> {onMove: (data) {final renderBox = context.findRenderObject() as RenderBox;final offset = renderBox.globalToLocal(data.offset);++ if (offset.dx > renderBox.size.width) {+ return;+ }+final position = _computeHoverPosition(offset, renderBox.size);if (!_shouldAccept(data.data, position)) {return;