File tree Expand file tree Collapse file tree 3 files changed +20
-14
lines changed
DragonFly.BlockField.Client
DragonFly.BlockField.Core/Json Expand file tree Collapse file tree 3 files changed +20
-14
lines changed Original file line number Diff line number Diff line change @@ -10,15 +10,18 @@ public static class BlockClipboard
1010
1111 public static bool HasData ( ) => Data != null ;
1212
13- public static async Task CopyAsync ( Block block )
13+ public static async Task CopyAsync ( IEnumerable < Block > block )
1414 {
1515 Data = await BlockFieldSerializer . SerializeBlockAsync ( block ) ;
1616 }
1717
1818 public static async Task PasteAsync ( int index , IList < Block > blocks )
1919 {
20- Block innerBlock = await BlockFieldSerializer . DeserializeBlockAsync ( Data ) ;
20+ Block [ ] innerBlock = await BlockFieldSerializer . DeserializeBlockAsync ( Data ) ;
2121
22- blocks . Insert ( index , innerBlock ) ;
22+ for ( int i = 0 ; i < innerBlock . Length ; i ++ )
23+ {
24+ blocks . Insert ( index + i , innerBlock [ i ] ) ;
25+ }
2326 }
2427}
Original file line number Diff line number Diff line change 1717{
1818 <div class =" block-field-view" >
1919 <div style =" display : flex ;gap :0.25rem " >
20- <BSButton Color =" BSColor.Light" class =" block-field-add-btn" OnClick =" e => BlockClipboard.PasteAsync(0, Blocks)" title =" Paste" style =" flex :0 " ><i class =" fa-solid fa-paste" ></i ></BSButton >
21-
22- <BSButton Color =" BSColor.Light" class =" block-field-add-btn" OnClick =" e => OpenModal(0)" title =" Insert block" style =" flex :1 " >
23- <i class =" fas fa-plus" ></i >
24- </BSButton >
20+ <BSButton Color =" BSColor.Light" class =" block-field-add-btn" OnClick =" e => BlockClipboard.CopyAsync(Blocks)" title =" Copy all" ><i class =" fa-solid fa-copy" ></i ></BSButton >
21+ <BSButton Color =" BSColor.Light" class =" block-field-add-btn" OnClick =" e => BlockClipboard.PasteAsync(0, Blocks)" title =" Paste" style =" flex :0 " ><i class =" fa-solid fa-paste" ></i ></BSButton >
22+ <BSButton Color =" BSColor.Light" class =" block-field-add-btn" OnClick =" e => OpenModal(0)" title =" Insert block" style =" flex :1 " ><i class =" fas fa-plus" ></i ></BSButton >
2523 </div >
2624
2725 @for ( int i = 0 ; i < Blocks .Count ; i ++ )
3533 <BSButton Color =" BSColor.Light" OnClick =" e => Blocks.MoveUp(block)" title =" Up" ><i class =" fas fa-arrow-up" ></i ></BSButton >
3634 <BSButton Color =" BSColor.Light" OnClick =" e => Blocks.MoveDown(block)" title =" Down" ><i class =" fas fa-arrow-down" ></i ></BSButton >
3735 <BSButton Color =" BSColor.Light" OnClick =" e => Blocks.Remove(block)" title =" Remove" ><i class =" fa-solid fa-times" ></i ></BSButton >
38- <BSButton Color =" BSColor.Light" OnClick =" e => BlockClipboard.CopyAsync(block)" title =" Copy" ><i class =" fa-solid fa-copy" ></i ></BSButton >
36+ <BSButton Color =" BSColor.Light" OnClick =" e => BlockClipboard.CopyAsync(new[] { block } )" title =" Copy" ><i class =" fa-solid fa-copy" ></i ></BSButton >
3937 </div >
4038 <div class =" block-field-content" >
4139 @ComponentManager.CreateComponent(block)
Original file line number Diff line number Diff line change @@ -47,20 +47,25 @@ static BlockFieldSerializer()
4747 /// </summary>
4848 private static JsonSerializerOptions Options { get ; }
4949
50- public static async Task < byte [ ] > SerializeBlockAsync ( Block block )
50+ public static async Task < byte [ ] > SerializeBlockAsync ( IEnumerable < Block > blocks )
5151 {
5252 MemoryStream jsonStream = new MemoryStream ( ) ;
5353
54- await JsonSerializer . SerializeAsync ( jsonStream , block , Options ) ;
54+ await JsonSerializer . SerializeAsync ( jsonStream , blocks , Options ) ;
5555
5656 return jsonStream . ToArray ( ) ;
5757 }
5858
59- public static async Task < Block ? > DeserializeBlockAsync ( byte [ ] buffer )
59+ public static async Task < Block [ ] > DeserializeBlockAsync ( byte [ ] buffer )
6060 {
61- Block ? block = await JsonSerializer . DeserializeAsync < Block > ( new MemoryStream ( buffer ) , Options ) ;
61+ Block [ ] ? blocks = await JsonSerializer . DeserializeAsync < Block [ ] > ( new MemoryStream ( buffer ) , Options ) ;
6262
63- return block ;
63+ if ( blocks == null )
64+ {
65+ return Array . Empty < Block > ( ) ;
66+ }
67+
68+ return blocks ;
6469 }
6570
6671 public static async Task < string ? > SerializeAsync ( Document document )
You can’t perform that action at this time.
0 commit comments