@@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react";
44import type { Editor } from "sketching-core" ;
55import { DRAG_KEY , EDITOR_EVENT } from "sketching-core" ;
66import type { DeltaLike } from "sketching-delta" ;
7- import { DEFAULT_BORDER_COLOR , RECT_ATTRS } from "sketching-plugin" ;
7+ import { DEFAULT_BORDER_COLOR , IMAGE_MODE , RECT_ATTRS } from "sketching-plugin" ;
88import { cs , TSON } from "sketching-utils" ;
99
1010import { CursorIcon } from "../../../static/cursor" ;
@@ -13,8 +13,7 @@ import { ImageIcon } from "../../../static/image";
1313import { RectIcon } from "../../../static/rect" ;
1414import { TextIcon } from "../../../static/text" ;
1515import styles from "../index.m.scss" ;
16- import { NAV_ENUM } from "../utils/constant" ;
17- import { uploadImage } from "../utils/upload" ;
16+ import { DEFAULT_IMAGE , NAV_ENUM } from "../utils/constant" ;
1817
1918export const Left : FC < {
2019 editor : Editor ;
@@ -44,11 +43,14 @@ export const Left: FC<{
4443 editor . canvas . insert . start ( deltaLike ) ;
4544 }
4645 if ( index === NAV_ENUM . IMAGE ) {
47- uploadImage ( ) . then ( src => {
48- const deltaLike : DeltaLike = { key : NAV_ENUM . IMAGE , ...empty } ;
49- deltaLike . attrs = { src } ;
50- editor . canvas . insert . start ( deltaLike ) ;
51- } ) ;
46+ const deltaLike : DeltaLike = { key : NAV_ENUM . IMAGE , ...empty } ;
47+ deltaLike . attrs = {
48+ src : DEFAULT_IMAGE ,
49+ mode : IMAGE_MODE . COVER ,
50+ [ RECT_ATTRS . BORDER_WIDTH ] : "1" ,
51+ [ RECT_ATTRS . BORDER_COLOR ] : "#DADADA" ,
52+ } ;
53+ editor . canvas . insert . start ( deltaLike ) ;
5254 }
5355 setActive ( index ) ;
5456 } ) ;
@@ -65,6 +67,24 @@ export const Left: FC<{
6567 e . dataTransfer . setData ( DRAG_KEY , TSON . encode ( deltaLike ) || "" ) ;
6668 } ;
6769
70+ const onDragImage = ( e : React . DragEvent < HTMLDivElement > ) => {
71+ if ( active !== NAV_ENUM . DEFAULT ) return false ;
72+ const deltaLike : DeltaLike = {
73+ key : NAV_ENUM . IMAGE ,
74+ x : 0 ,
75+ y : 0 ,
76+ width : 100 ,
77+ height : 100 ,
78+ attrs : {
79+ src : DEFAULT_IMAGE ,
80+ mode : IMAGE_MODE . COVER ,
81+ [ RECT_ATTRS . BORDER_WIDTH ] : "1" ,
82+ [ RECT_ATTRS . BORDER_COLOR ] : "#DADADA" ,
83+ } ,
84+ } ;
85+ e . dataTransfer . setData ( DRAG_KEY , TSON . encode ( deltaLike ) || "" ) ;
86+ } ;
87+
6888 const onDragText = ( e : React . DragEvent < HTMLDivElement > ) => {
6989 if ( active !== NAV_ENUM . DEFAULT ) return false ;
7090 const deltaLike : DeltaLike = {
@@ -115,6 +135,9 @@ export const Left: FC<{
115135 { RectIcon }
116136 </ div >
117137 < div
138+ draggable = { active === NAV_ENUM . DEFAULT }
139+ onDragStart = { onDragImage }
140+ onDragEnd = { onDragEnd }
118141 className = { cs ( styles . op , active === NAV_ENUM . IMAGE && styles . active ) }
119142 onClick = { ( ) => switchIndex ( NAV_ENUM . IMAGE ) }
120143 >
0 commit comments