@@ -6,16 +6,21 @@ import Ace (Annotation)
6
6
import Control.Monad.Except (runExceptT )
7
7
import Data.Array (fold )
8
8
import Data.Array as Array
9
- import Data.Either (Either (..))
9
+ import Data.Either (Either (..), either )
10
10
import Data.Foldable (for_ , oneOf )
11
11
import Data.FoldableWithIndex (foldMapWithIndex )
12
12
import Data.Maybe (Maybe (..), fromMaybe , isNothing )
13
13
import Data.Symbol (SProxy (..))
14
+ import Data.String as String
15
+ import Data.String (Pattern (..))
16
+ import Data.String.Regex as Regex
17
+ import Data.String.Regex.Flags as RegexFlags
14
18
import Effect (Effect )
15
19
import Effect.Aff (Aff , makeAff )
16
20
import Effect.Aff as Aff
17
21
import Effect.Class.Console (error )
18
22
import Effect.Uncurried (EffectFn3 , runEffectFn3 )
23
+ import Partial.Unsafe (unsafeCrashWith )
19
24
import Halogen as H
20
25
import Halogen.HTML as HH
21
26
import Halogen.HTML.Events as HE
@@ -187,7 +192,17 @@ component = H.mkComponent
187
192
_ <- H .query _editor unit $ H .tell $ Editor.SetAnnotations anns
188
193
pure unit
189
194
let
190
- eventData = { code: js }
195
+ importRegex :: Regex.Regex
196
+ importRegex = either (\_ -> unsafeCrashWith " Invalid regex" ) identity
197
+ $ Regex .regex """ ^import (.+) from "../([^"]+)";$""" RegexFlags .noFlags
198
+ replacement = " import $1 from \" " <> Config .loaderUrl <> " /$2\" ;"
199
+ codeWithRemappedImports = js
200
+ # String .split (Pattern " \n " )
201
+ # map (Regex .replace importRegex replacement)
202
+ # String .joinWith " \n "
203
+
204
+ -- Actually call the `main` function
205
+ eventData = { code: codeWithRemappedImports <> " \n\n " <> " main();" }
191
206
H .liftEffect teardownIFrame
192
207
H .liftAff $ makeAff \f -> do
193
208
runEffectFn3 setupIFrame eventData (f (Right unit)) (f (Left $ Aff .error " Could not load iframe" ))
0 commit comments