@@ -37,14 +37,48 @@ struct SieveScriptView: View {
3737 ZStack ( alignment: . center) {
3838 HStack {
3939 Spacer ( )
40- scriptList
41- . frame ( maxWidth: 1000 )
40+ if viewModel. rowTokens. isEmpty {
41+ emptyDropArea
42+ . frame ( maxWidth: 1000 )
43+ } else {
44+ scriptList
45+ . frame ( maxWidth: 1000 )
46+ }
4247 Spacer ( )
4348 }
4449 . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . top)
4550 }
4651 . frame ( maxWidth: . infinity, maxHeight: . infinity)
4752 }
53+
54+ @ViewBuilder
55+ private var emptyDropArea : some View {
56+ VStack ( spacing: 12 ) {
57+ if dropGapIndex != nil || draggedRange != nil {
58+ PlaceholderRowView ( )
59+ . padding ( . leading, 0 )
60+ . transition ( . opacity)
61+ } else {
62+ Text ( " Drag a command from the sidebar to start writing your script. " )
63+ . font ( . title2)
64+ . foregroundStyle ( Color . secondary)
65+ . multilineTextAlignment ( . center)
66+ . padding ( . horizontal, 24 )
67+ }
68+ }
69+ . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . top)
70+ . contentShape ( Rectangle ( ) )
71+ . onDrop (
72+ of: [ UTType . utf8PlainText] ,
73+ delegate: UnifiedDropDelegate (
74+ target: . fixedGap( 0 ) ,
75+ draggedRange: $draggedRange,
76+ dropGapIndex: $dropGapIndex,
77+ rowHeights: $rowHeights,
78+ viewModel: viewModel
79+ )
80+ )
81+ }
4882
4983 @ViewBuilder
5084 var scriptList : some View {
@@ -151,7 +185,32 @@ struct SieveScriptView: View {
151185 }
152186}
153187
154- #Preview {
188+ #Preview( " Not empty " ) {
189+ @Previewable @State var viewModel = SieveScriptViewModel ( script: [
190+ AddFlagCommand ( tag: " Spam " ) ,
191+ IfCommand (
192+ quantifier: . any,
193+ tests: [
194+ . header
( [ " from " ] , match
: . contains
, keys
: [ " [email protected] " ] ) , 195+ . exists( [ " x-marked-spam " ] )
196+ ] ,
197+ thenChildren: [
198+ AddFlagCommand ( tag: " Label 1 " ) ,
199+ AddFlagCommand ( tag: " Label 2 " )
200+ ] ,
201+ elseChildren: [
202+ AddFlagCommand ( tag: " Tag 1 " )
203+ ]
204+ ) ,
205+ FileIntoCommand ( mailbox: " Social " ) ,
206+ AddFlagCommand ( tag: " Tag 1 " ) ,
207+ AddFlagCommand ( tag: " Tag 2 " ) ,
208+ StopCommand ( )
209+ ] )
210+ SieveScriptView ( viewModel: $viewModel)
211+ }
212+
213+ #Preview( " Empty " ) {
155214 @Previewable @State var viewModel = SieveScriptViewModel ( )
156215 SieveScriptView ( viewModel: $viewModel)
157216}
0 commit comments