@@ -72,9 +72,9 @@ import Yoga.React.Native.MacOS.QuickLook (macosQuickLook)
7272import Yoga.React.Native.MacOS.SpeechSynthesizer (macosSay, macosStopSpeaking)
7373import Yoga.React.Native.MacOS.ColorPanel (macosShowColorPanel)
7474import Yoga.React.Native.MacOS.FontPanel (macosShowFontPanel)
75−import Yoga.React.Native.MacOS.OCR (macosOCR)
76−import Yoga.React.Native.MacOS.SpeechRecognition (macosStartListening, macosStopListening, macosGetTranscript)
77−import Yoga.React.Native.MacOS.NaturalLanguage (macosDetectLanguage, macosAnalyzeSentiment, macosTokenize)
75+import Yoga.React.Native.MacOS.OCR (recognizeText)
76+import Yoga.React.Native.MacOS.SpeechRecognition (useSpeechRecognition)
77+import Yoga.React.Native.MacOS.NaturalLanguage (detectLanguage, analyzeSentiment, tokenize)
7878import Yoga.React.Native.MacOS.Types as T
7979import Yoga.React.Native.Matrix as Matrix
8080import Yoga.React.Native.Style as Style
@@ -1075,16 +1075,9 @@ aiTab :: AIProps -> JSX
10751075aiTab = component "AITab" \p -> React.do
10761076 speechText /\ setSpeechText <- useState' "Hello from PureScript React Native on macOS!"
10771077 ocrResult /\ setOcrResult <- useState' ""
1078− listening /\ setListening <- useState' false
1079− transcript /\ setTranscript <- useState' ""
1078+ speech <- useSpeechRecognition
10801079 nlText /\ setNlText <- useState' "I love this amazing app! C'est magnifique."
10811080 nlResult /\ setNlResult <- useState' ""
1082− useEffect listening do
1083− if listening then do
1084− timerId <- setInterval 500 do
1085− macosGetTranscript \t -> setTranscript t
1086− pure (clearInterval timerId)
1087− else pure (pure unit)
10881081 pure do
10891082 nativeScrollView { style: tw "flex-1" <> Style.style { backgroundColor: "transparent" } }
10901083 ( view { style: tw "px-4 pb-4" }
@@ -1096,14 +1089,12 @@ aiTab = component "AITab" \p -> React.do
10961089 , longitude: -122.4194
10971090 , latitudeDelta: 0.05
10981091 , longitudeDelta: 0.05
1099− , mapType: "standard"
1092+ , mapType: T.standardMap
11001093 , showsUserLocation: false
1101− , annotations: unsafeToForeign
1094+ , annotations:
11021095 [ { latitude: 37.7749, longitude: -122.4194, title: "San Francisco", subtitle: "California" }
11031096 , { latitude: 37.8199, longitude: -122.4783, title: "Golden Gate Bridge", subtitle: "" }
11041097 ]
1105− , onRegionChange: handler_ (pure unit)
1106− , onSelectAnnotation: handler_ (pure unit)
11071098 , style: Style.style { height: 250.0 }
11081099 }
11091100 , sectionTitle p.fg "PDF Viewer"
@@ -1112,8 +1103,7 @@ aiTab = component "AITab" \p -> React.do
11121103 , nativePDFView
11131104 { source: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
11141105 , autoScales: true
1115− , displayMode: "singlePageContinuous"
1116− , onPageChange: handler_ (pure unit)
1106+ , displayMode: T.singlePageContinuous
11171107 , style: Style.style { height: 300.0 }
11181108 }
11191109 , sectionTitle p.fg "Quick Look"
@@ -1190,8 +1180,9 @@ aiTab = component "AITab" \p -> React.do
11901180 (nativeEvent >>> unsafeEventFn \e -> getFieldArray "files" e)
11911181 \paths -> for_ paths \path -> do
11921182 setOcrResult "Recognizing..."
1193− macosOCR path \result -> setOcrResult result
1194− , onCancel: handler_ (pure unit)
1183+ launchAff_ do
1184+ result <- recognizeText path
1185+ liftEffect (setOcrResult result)
11951186 , style: Style.style { height: 24.0, width: 140.0 }
11961187 }
11971188 ]
@@ -1203,28 +1194,22 @@ aiTab = component "AITab" \p -> React.do
12031194 "Live microphone-to-text (click Start, speak, click Stop)"
12041195 , view { style: tw "flex-row items-center mb-2" }
12051196 [ nativeButton
1206− { title: if listening then "Listening..." else "Start"
1207− , sfSymbol: if listening then "mic.fill" else "mic"
1197+ { title: if speech.listening then "Listening..." else "Start"
1198+ , sfSymbol: if speech.listening then "mic.fill" else "mic"
12081199 , bezelStyle: T.push
1209− , onPress: handler_ do
1210− setListening true
1211− setTranscript ""
1212− macosStartListening
1200+ , onPress: handler_ speech.start
12131201 , style: Style.style { height: 24.0, width: 130.0 }
12141202 }
12151203 , nativeButton
12161204 { title: "Stop"
12171205 , sfSymbol: "stop.circle"
12181206 , bezelStyle: T.push
1219− , onPress: handler_ do
1220− setListening false
1221− macosStopListening \finalText -> do
1222− setTranscript finalText
1207+ , onPress: handler_ speech.stop
12231208 , style: Style.style { height: 24.0, width: 80.0, marginLeft: 8.0 }
12241209 }
12251210 ]
1226− , if transcript /= "" then view { style: tw "p-2 rounded mb-4" <> Style.style { backgroundColor: p.cardBg } }
1227− [ text { style: tw "text-xs font-mono" <> Style.style { color: p.fg } } transcript ]
1211+ , if speech.transcript /= "" then view { style: tw "p-2 rounded mb-4" <> Style.style { backgroundColor: p.cardBg } }
1212+ [ text { style: tw "text-xs font-mono" <> Style.style { color: p.fg } } speech.transcript ]
12281213 else view {} []
12291214 , sectionTitle p.fg "Natural Language"
12301215 , text { style: tw "text-xs mb-2" <> Style.style { color: p.dimFg } }
@@ -1240,27 +1225,27 @@ aiTab = component "AITab" \p -> React.do
12401225 { title: "Language"
12411226 , sfSymbol: "globe"
12421227 , bezelStyle: T.push
1243− , onPress: handler_ do
1244− macosDetectLanguage nlText \lang ->
1245− setNlResult ("Language: " <> lang)
1228+ , onPress: handler_ $ launchAff_ do
1229+ lang <- detectLanguage nlText
1230+ liftEffect (setNlResult ("Language: " <> lang))
12461231 , style: Style.style { height: 24.0, width: 110.0 }
12471232 }
12481233 , nativeButton
12491234 { title: "Sentiment"
12501235 , sfSymbol: "face.smiling"
12511236 , bezelStyle: T.push
1252− , onPress: handler_ do
1253− macosAnalyzeSentiment nlText \score ->
1254− setNlResult ("Sentiment: " <> show score)
1237+ , onPress: handler_ $ launchAff_ do
1238+ score <- analyzeSentiment nlText
1239+ liftEffect (setNlResult ("Sentiment: " <> show score))
12551240 , style: Style.style { height: 24.0, width: 110.0, marginLeft: 8.0 }
12561241 }
12571242 , nativeButton
12581243 { title: "Tokenize"
12591244 , sfSymbol: "text.word.spacing"
12601245 , bezelStyle: T.push
1261− , onPress: handler_ do
1262− macosTokenize nlText \tokens ->
1263− setNlResult ("Tokens: " <> joinWith ", " tokens)
1246+ , onPress: handler_ $ launchAff_ do
1247+ tokens <- tokenize nlText
1248+ liftEffect (setNlResult ("Tokens: " <> joinWith ", " tokens))
12641249 , style: Style.style { height: 24.0, width: 110.0, marginLeft: 8.0 }
12651250 }
12661251 ]